feat: remove daily character seed from environment and implement random seed generation for selection

This commit is contained in:
2026-03-02 12:41:18 +01:00
parent b70e47b0d6
commit d78a70c473
2 changed files with 5 additions and 22 deletions

View File

@@ -2,21 +2,8 @@ import { db } from '$lib/server/db';
import { arc, character, characterHistory, characterOverride, devilFruit } from '$lib/server/db/schema';
import { desc, eq, inArray, and } from 'drizzle-orm';
// Get daily character seed from environment or use default
const DAILY_CHARACTER_SEED_STRING = process.env.DAILY_CHARACTER_SEED || 'onepiecedle';
// Convert string seed to number using a simple hash function
function hashString(str: string): number {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
return Math.abs(hash);
}
const DAILY_CHARACTER_SEED = hashString(DAILY_CHARACTER_SEED_STRING);
// Generate or get random seed for daily character selection
const RANDOM_SEED = Math.random();
const characterWithRelationsSelect = {
id: character.id,
@@ -168,8 +155,9 @@ export function normalizeDay(date: Date = new Date()): Date {
function pickDailyCharacter(characters: CharacterWithRelations[], date: Date): CharacterWithRelations {
const timestamp = getDateKey(date);
const daysSinceEpoch = Math.floor(timestamp / 1000 / 60 / 60 / 24);
const seed = (daysSinceEpoch + DAILY_CHARACTER_SEED) % characters.length;
return characters[seed];
// Combine timestamp with random seed to avoid predictable results
const combinedSeed = (daysSinceEpoch + Math.floor(RANDOM_SEED * 1000000)) % characters.length;
return characters[combinedSeed];
}
export async function getDailyModeCharacters(): Promise<CharacterWithRelations[]> {