/** * The preset squadron directory written on first creation of `/clans.json` * (implementation notes section I; implementation notes), and the activity periods a member * starts with. Both are tuning (tuning/clans.jsonc). */ import type { ClanTuning, PresetClan, PresetMember } from './clan-tuning.ts'; import type { ClanActivityPeriodEntry, ClanMemberRecord, ClanRecord } from './clan-types.ts'; const SECONDS_PER_DAY = 86400; export function createDefaultClans(tuning: ClanTuning, nowSec = Math.floor(Date.now() / 1000)): ClanRecord[] { const todayDay = Math.floor(nowSec / SECONDS_PER_DAY); const createdBase = nowSec - tuning.presetClans.createdDaysAgo * SECONDS_PER_DAY; return tuning.presetClans.clans.map((spec) => buildSeededClan(spec, createdBase + spec.createdAfterDays * SECONDS_PER_DAY, todayDay, tuning)); } /** The activity periods a member starts with: startingPeriods periods, each with the given activity and the squadron RP it earns. */ export function buildDefaultPeriods(todayDay: number, tuning: ClanTuning, periodActivity = tuning.activity.maxPerPeriod): ClanActivityPeriodEntry[] { const { maxPerPeriod, squadronRpPerFullPeriod, rewardPeriodDays, startingPeriods } = tuning.activity; const exp = Math.round((periodActivity / maxPerPeriod) * squadronRpPerFullPeriod); return Array.from({ length: startingPeriods }, (_, idx) => ({ day: todayDay - idx * rewardPeriodDays, activity: periodActivity, exp })); } function buildSeededClan(spec: PresetClan, cdateSec: number, todayDay: number, tuning: ClanTuning): ClanRecord { const members = spec.members.map((npc, idx) => buildSeededMember(spec, npc, idx, cdateSec, todayDay, tuning)); const leader = spec.members[0]!; return { id: spec.id, name: spec.name, tag: spec.tag, lastPaidTag: spec.tag, type: spec.type, slogan: spec.slogan, desc: spec.desc, announcement: spec.announcement, region: spec.region, status: 'open', autoaccept: spec.autoAccept, mlimit: spec.type === 'battalion' ? tuning.memberLimits.battalionInitial : tuning.memberLimits.normal, mspent: 0, cdateSec, changedByUid: leader.uid, changedByNick: leader.nick, changedTimeSec: cdateSec, regionLastUpdatedSec: 0, stats: { dr_era5_arc: spec.rating.arc, dr_era5_hist: spec.rating.hist, dr_era5_sim: spec.rating.sim, ...tuning.presetClans.stats }, members, candidates: [], blacklist: [], logs: [{ id: 1, ev: 'create', timeSec: cdateSec, uId: leader.uid, uN: leader.nick, name: spec.name, type: spec.type, tag: spec.tag, desc: spec.desc, slogan: spec.slogan, region: spec.region, announcement: spec.announcement, }], bestRewards: [], }; } function buildSeededMember(spec: PresetClan, npc: PresetMember, idx: number, cdateSec: number, todayDay: number, tuning: ClanTuning): ClanMemberRecord { const periods = buildDefaultPeriods(todayDay, tuning, npc.activity); const { step, floor } = tuning.presetClans.memberRating; return { uid: npc.uid, nick: npc.nick, role: npc.role, joinDateSec: cdateSec + idx * tuning.presetClans.memberJoinSpacingMinutes * 60, isNpc: true, npcTitle: npc.title, npcPilotIcon: npc.icon, npcFrame: '', npcShowcaseUnit: npc.unit, curActivity: npc.activity, totalActivity: periods.reduce((sum, p) => sum + p.activity, 0), earnedSquadronExp: periods.reduce((sum, p) => sum + p.exp, 0), ratingArc: Math.max(floor.arc, spec.rating.arc - idx * step.arc), ratingHist: Math.max(floor.hist, spec.rating.hist - idx * step.hist), ratingSim: Math.max(floor.sim, spec.rating.sim - idx * step.sim), periods, }; }