토너먼트 준비
This commit is contained in:
@@ -8,6 +8,7 @@ export * from './util/JosaUtil.js';
|
||||
export * from './util/RNG.js';
|
||||
export * from './util/RandUtil.js';
|
||||
export * from './util/TestRNG.js';
|
||||
export * from './util/TournamentRNG.js';
|
||||
export * from './util/sha512.js';
|
||||
export * from './util/parse.js';
|
||||
export * from './turnDaemon/types.js';
|
||||
|
||||
@@ -85,7 +85,17 @@ export type TurnDaemonCommand =
|
||||
destGeneralId: number;
|
||||
destCityId: number;
|
||||
officerLevel: number;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: 'tournamentRefund';
|
||||
requestId?: string;
|
||||
bettingId?: number;
|
||||
reason?: string;
|
||||
refunds: Array<{
|
||||
generalId: number;
|
||||
amount: number;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type TurnDaemonCommandResult =
|
||||
| {
|
||||
@@ -132,7 +142,21 @@ export type TurnDaemonCommandResult =
|
||||
| { type: 'dropItem'; ok: boolean; generalId: number; reason?: string }
|
||||
| { type: 'changePermission'; ok: boolean; generalId: number; reason?: string }
|
||||
| { type: 'kick'; ok: boolean; generalId: number; reason?: string }
|
||||
| { type: 'appoint'; ok: boolean; generalId: number; reason?: string };
|
||||
| { type: 'appoint'; ok: boolean; generalId: number; reason?: string }
|
||||
| {
|
||||
type: 'tournamentRefund';
|
||||
ok: true;
|
||||
bettingId?: number;
|
||||
processed: number;
|
||||
missing: number;
|
||||
totalRefund: number;
|
||||
}
|
||||
| {
|
||||
type: 'tournamentRefund';
|
||||
ok: false;
|
||||
bettingId?: number;
|
||||
reason: string;
|
||||
};
|
||||
|
||||
export type TurnDaemonEvent =
|
||||
| { type: 'status'; requestId?: string; status: TurnDaemonStatus }
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { LiteHashDRBG } from './LiteHashDRBG.js';
|
||||
import { RandUtil } from './RandUtil.js';
|
||||
|
||||
export interface TournamentRngContext {
|
||||
openYear: number;
|
||||
openMonth: number;
|
||||
stage: number;
|
||||
phase: number;
|
||||
matchIndex: number;
|
||||
participantIndex: number;
|
||||
gameIndex?: number;
|
||||
extraSeed?: string | number;
|
||||
}
|
||||
|
||||
const buildTournamentSeedKey = (baseSeed: string, context: TournamentRngContext): string => {
|
||||
const gameIndex = context.gameIndex !== undefined ? `|game:${context.gameIndex}` : '';
|
||||
const extraSeed = context.extraSeed !== undefined ? `|extra:${context.extraSeed}` : '';
|
||||
return [
|
||||
'Tournament',
|
||||
`open:${context.openYear}-${context.openMonth}`,
|
||||
`stage:${context.stage}`,
|
||||
`phase:${context.phase}`,
|
||||
`match:${context.matchIndex}`,
|
||||
`participant:${context.participantIndex}`,
|
||||
gameIndex,
|
||||
extraSeed,
|
||||
`seed:${baseSeed}`,
|
||||
]
|
||||
.filter((value) => value.length > 0)
|
||||
.join('|');
|
||||
};
|
||||
|
||||
export const createTournamentRng = (baseSeed: string, context: TournamentRngContext): RandUtil =>
|
||||
new RandUtil(LiteHashDRBG.build(buildTournamentSeedKey(baseSeed, context)));
|
||||
|
||||
export const createTournamentSeedKey = (baseSeed: string, context: TournamentRngContext): string =>
|
||||
buildTournamentSeedKey(baseSeed, context);
|
||||
Reference in New Issue
Block a user