XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: improve distribution of rewardSeed (#1831)

This was previously not ideal due to float imprecision, but now it's 64 bits and there's enough entropy for all of them. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1831 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

0b757572
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +12 -7
Modified src/models/inventoryModels/inventoryModel.ts +1 -1
@@ -390,7 +390,7 @@ MailboxSchema.set("toJSON", {
390 390
391 391 const DuviriInfoSchema = new Schema<IDuviriInfo>(
392 392 {
393 Seed: Number,
393 Seed: BigInt,
394 394 NumCompletions: { type: Number, default: 0 }
395 395 },
396 396 {
Modified src/services/inventoryService.ts +9 -4
@@ -120,10 +120,15 @@ export const createInventory = async (
120 120 }
121 121 };
122 122
123 export const generateRewardSeed = (): number => {
124 const min = -Number.MAX_SAFE_INTEGER;
125 const max = Number.MAX_SAFE_INTEGER;
126 return Math.floor(Math.random() * (max - min + 1)) + min;
123 export const generateRewardSeed = (): bigint => {
124 const hiDword = getRandomInt(0, 0x7fffffff);
125 const loDword = getRandomInt(0, 0xffffffff);
126 let seed = (BigInt(hiDword) << 32n) | BigInt(loDword);
127 if (Math.random() < 0.5) {
128 seed *= -1n;
129 seed -= 1n;
130 }
131 return seed;
127 132 };
128 133
129 134 //TODO: RawUpgrades might need to return a LastAdded
Modified src/types/inventoryTypes/inventoryTypes.ts +2 -2
@@ -134,7 +134,7 @@ export const equipmentKeys = [
134 134 export type TEquipmentKey = (typeof equipmentKeys)[number];
135 135
136 136 export interface IDuviriInfo {
137 Seed: number;
137 Seed: bigint;
138 138 NumCompletions: number;
139 139 }
140 140
@@ -202,7 +202,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
202 202 Mailbox?: IMailboxClient;
203 203 SubscribedToEmails: number;
204 204 Created: IMongoDate;
205 RewardSeed: number | bigint;
205 RewardSeed: bigint;
206 206 RegularCredits: number;
207 207 PremiumCredits: number;
208 208 PremiumCreditsFree: number;