fix(server): persist squadrons and align inventory wire formats
Read squadron action parameters from the request headers and persist squadron state on profile refresh. Use floating-point trophy weights to match the client probability display and assign unique log IDs when opening multiple chests. Tighten shop, marketplace, squadron, and cloud settings validation. Move PBBD and inventory encoding into the protocol modules and share CSV reading. Update the research and acceptance instructions. Type checking and all eight executable patch checks passed. In-game acceptance is pending.
This commit is contained in:
1 parent
b68f321b84
commit
29e5cf2bd8
40 files changed
+1347
-1248
No files matched your search
@@ -7,12 +7,17 @@
|
||||
* - `cln_clan_get_log` paginated clan event log (`clanRequests.nut`)
|
||||
*/
|
||||
import type { BlkBlock, BlkParam } from '@wto/blk';
|
||||
import type { ClanLogEntry, ClanMemberRecord, ClanRecord, ClanStats } from './clan-types.ts';
|
||||
|
||||
export const MAX_ACTIVITY_PER_PERIOD = 360;
|
||||
export const MAX_CLAN_ACTIVITY = 20000;
|
||||
export const REWARD_PERIOD_DAYS = 3;
|
||||
export const HISTORY_DEPTH_DAYS = 14;
|
||||
import {
|
||||
HISTORY_DEPTH_DAYS,
|
||||
MAX_ACTIVITY_PER_PERIOD,
|
||||
MAX_CLAN_ACTIVITY,
|
||||
REWARD_PERIOD_DAYS,
|
||||
totalPeriodActivityOf,
|
||||
type ClanLogEntry,
|
||||
type ClanMemberRecord,
|
||||
type ClanRecord,
|
||||
type ClanStats,
|
||||
} from './clan-types.ts';
|
||||
|
||||
const CLAN_STAT_KEYS: ReadonlyArray<keyof ClanStats> = [
|
||||
'dr_era5_arc', 'dr_era5_hist', 'dr_era5_sim',
|
||||
@@ -26,11 +31,6 @@ const OPTIONAL_LOG_STRING_KEYS: ReadonlyArray<keyof Omit<ClanLogEntry, 'id' | 'e
|
||||
'uid', 'nick', 'role', 'old', 'new', 'name', 'type', 'tag', 'desc', 'slogan', 'region', 'announcement', 'status', 'comments',
|
||||
];
|
||||
|
||||
export function totalPeriodActivityOf(clan: ClanRecord): number {
|
||||
const sum = clan.members.reduce((acc, m) => acc + m.curActivity, 0);
|
||||
return Math.min(MAX_CLAN_ACTIVITY * 5, sum * 10);
|
||||
}
|
||||
|
||||
export function toClanInfoBlk(clan: ClanRecord, nowSec = Math.floor(Date.now() / 1000)): BlkBlock {
|
||||
const todayDay = Math.floor(nowSec / 86400);
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Squadron lifecycle rules: creation, info editing, upgrading from training battalion to
|
||||
* full squadron, member-limit expansion, and disbanding.
|
||||
* full squadron, member-limit expansion, requirements, and disbanding.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { Account } from '../accounts/account-store.ts';
|
||||
@@ -10,7 +10,14 @@ import { canAfford, pay, type Price } from '../profile/profile-currency.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
import { appendClanLog, clearCandidateEverywhere, hasClanManageRight } from './clan-membership.ts';
|
||||
import { buildDefaultPeriods } from './clan-seeds.ts';
|
||||
import { ClanRole, type ClanMemberRecord, type ClanRecord } from './clan-types.ts';
|
||||
import {
|
||||
BATTALION_INITIAL_MEMBER_LIMIT,
|
||||
ClanRole,
|
||||
MAX_ACTIVITY_PER_PERIOD,
|
||||
NORMAL_CLAN_MEMBER_LIMIT,
|
||||
type ClanMemberRecord,
|
||||
type ClanRecord,
|
||||
} from './clan-types.ts';
|
||||
|
||||
export interface StoredClansState {
|
||||
nextClanId: number;
|
||||
@@ -39,7 +46,7 @@ export interface ClanInfoChanges {
|
||||
}
|
||||
|
||||
export function stripClanDecorators(tag: string): string {
|
||||
return tag.replace(/^[\[\-\.\=\^\*]+|[\]\-\.\=\^\*]+$/g, '');
|
||||
return tag.replace(/^[^\p{L}\p{N}_]+|[^\p{L}\p{N}_]+$/gu, '');
|
||||
}
|
||||
|
||||
export function createClanInState(
|
||||
@@ -53,12 +60,8 @@ export function createClanInState(
|
||||
if (state.clans.some((c) => c.members.some((m) => m.uid === account.userId))) return refused('NOT_AVAILABLE');
|
||||
const name = input.name.trim();
|
||||
const tag = input.tag.trim();
|
||||
if (!name || !tag) return refused('BAD_PARAMS');
|
||||
|
||||
const coreTag = stripClanDecorators(tag).toLowerCase();
|
||||
if (state.clans.some((c) => c.name.toLowerCase() === name.toLowerCase() || stripClanDecorators(c.tag).toLowerCase() === coreTag)) {
|
||||
return refused('NOT_AVAILABLE');
|
||||
}
|
||||
if (!name || !tag || !stripClanDecorators(tag)) return refused('BAD_PARAMS');
|
||||
if (hasConflictingClan(state.clans, undefined, name, tag)) return refused('NOT_AVAILABLE');
|
||||
|
||||
const expectedPrice: Price = input.type === 'battalion'
|
||||
? { silverLions: economy.battalionCreateSilver, goldenEagles: economy.battalionCreateGold }
|
||||
@@ -71,14 +74,12 @@ export function createClanInState(
|
||||
|
||||
clearCandidateEverywhere(state.clans, account.userId);
|
||||
pay(profile, expectedPrice);
|
||||
|
||||
const id = String(state.nextClanId++);
|
||||
const created = buildCreatedClanRecord(id, account, name, tag, input, nowSec);
|
||||
state.clans.unshift(created);
|
||||
state.clans.unshift(buildCreatedClanRecord(String(state.nextClanId++), account, name, tag, input, nowSec));
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function editClanInfoInState(
|
||||
clans: readonly ClanRecord[],
|
||||
clan: ClanRecord | undefined,
|
||||
profile: BlkBlock,
|
||||
account: Account,
|
||||
@@ -88,50 +89,21 @@ export function editClanInfoInState(
|
||||
): RuleOutcome {
|
||||
if (!clan || !hasClanManageRight(clan, account.userId)) return refused('NOT_AVAILABLE');
|
||||
|
||||
if (clan.type === 'battalion') {
|
||||
const isNameChanged = changes.name !== undefined && changes.name !== clan.name;
|
||||
const isCoreTagChanged = changes.tag !== undefined && stripClanDecorators(changes.tag) !== stripClanDecorators(clan.tag);
|
||||
if (isNameChanged || isCoreTagChanged) {
|
||||
const editCost: Price = { silverLions: economy.battalionPrimaryEditSilver, goldenEagles: economy.battalionPrimaryEditGold };
|
||||
if (!canAfford(profile, editCost)) return refused('NOT_ENOUGH_MONEY');
|
||||
pay(profile, editCost);
|
||||
}
|
||||
}
|
||||
const nextName = changes.name !== undefined && changes.name.trim() ? changes.name.trim() : clan.name;
|
||||
const nextTag = changes.tag !== undefined && changes.tag.trim() ? changes.tag.trim() : clan.tag;
|
||||
if (!stripClanDecorators(nextTag)) return refused('BAD_PARAMS');
|
||||
if (hasConflictingClan(clans, clan.id, nextName, nextTag)) return refused('NOT_AVAILABLE');
|
||||
|
||||
if (changes.name !== undefined && changes.name.trim()) clan.name = changes.name.trim();
|
||||
if (changes.tag !== undefined && changes.tag.trim()) {
|
||||
clan.tag = changes.tag.trim();
|
||||
clan.lastPaidTag = clan.tag;
|
||||
}
|
||||
if (changes.desc !== undefined) clan.desc = changes.desc;
|
||||
if (changes.slogan !== undefined) clan.slogan = changes.slogan;
|
||||
if (changes.announcement !== undefined) clan.announcement = changes.announcement;
|
||||
if (changes.region !== undefined && changes.region !== clan.region) {
|
||||
clan.region = changes.region;
|
||||
clan.regionLastUpdatedSec = nowSec;
|
||||
}
|
||||
if (changes.status !== undefined) clan.status = changes.status;
|
||||
const editPrice = computeInfoEditPrice(clan, economy, nextName, nextTag, changes);
|
||||
if (!canAfford(profile, editPrice)) return refused('NOT_ENOUGH_MONEY');
|
||||
pay(profile, editPrice);
|
||||
|
||||
clan.changedByUid = account.userId;
|
||||
clan.changedByNick = account.nick;
|
||||
clan.changedTimeSec = nowSec;
|
||||
appendClanLog(clan, {
|
||||
ev: 'info',
|
||||
timeSec: nowSec,
|
||||
uId: account.userId,
|
||||
uN: account.nick,
|
||||
name: clan.name,
|
||||
tag: clan.tag,
|
||||
desc: clan.desc,
|
||||
slogan: clan.slogan,
|
||||
region: clan.region,
|
||||
announcement: clan.announcement,
|
||||
status: clan.status,
|
||||
});
|
||||
applyInfoFieldUpdates(clan, account, nextName, nextTag, changes, nowSec);
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function upgradeClanToNormalInState(
|
||||
clans: readonly ClanRecord[],
|
||||
clan: ClanRecord | undefined,
|
||||
profile: BlkBlock,
|
||||
account: Account,
|
||||
@@ -140,6 +112,10 @@ export function upgradeClanToNormalInState(
|
||||
nowSec: number,
|
||||
): RuleOutcome {
|
||||
if (!clan || clan.type !== 'battalion' || !hasClanManageRight(clan, account.userId)) return refused('NOT_AVAILABLE');
|
||||
const nextTag = input.tag.trim() || clan.tag;
|
||||
if (!stripClanDecorators(nextTag) || hasConflictingClan(clans, clan.id, clan.name, nextTag)) {
|
||||
return refused('NOT_AVAILABLE');
|
||||
}
|
||||
|
||||
const goldCost = Math.max(0, economy.upgradeBattalionToNormalGold - clan.mspent);
|
||||
const price: Price = { silverLions: economy.upgradeBattalionToNormalSilver, goldenEagles: goldCost };
|
||||
@@ -147,11 +123,9 @@ export function upgradeClanToNormalInState(
|
||||
|
||||
pay(profile, price);
|
||||
clan.type = 'normal';
|
||||
clan.mlimit = 128;
|
||||
if (input.tag.trim()) {
|
||||
clan.tag = input.tag.trim();
|
||||
clan.lastPaidTag = clan.tag;
|
||||
}
|
||||
clan.mlimit = NORMAL_CLAN_MEMBER_LIMIT;
|
||||
clan.tag = nextTag;
|
||||
clan.lastPaidTag = nextTag;
|
||||
clan.desc = input.desc;
|
||||
clan.announcement = input.announcement;
|
||||
clan.changedByUid = account.userId;
|
||||
@@ -159,13 +133,8 @@ export function upgradeClanToNormalInState(
|
||||
clan.changedTimeSec = nowSec;
|
||||
|
||||
appendClanLog(clan, {
|
||||
ev: 'upgrade',
|
||||
timeSec: nowSec,
|
||||
uId: account.userId,
|
||||
uN: account.nick,
|
||||
type: 'normal',
|
||||
tag: clan.tag,
|
||||
desc: clan.desc,
|
||||
ev: 'upgrade', timeSec: nowSec, uId: account.userId, uN: account.nick,
|
||||
type: 'normal', tag: clan.tag, desc: clan.desc,
|
||||
});
|
||||
return ACCEPTED;
|
||||
}
|
||||
@@ -189,16 +158,93 @@ export function upgradeMembersLimitInState(
|
||||
clan.mspent += economy.battalionMembersUpgradeGold;
|
||||
|
||||
appendClanLog(clan, {
|
||||
ev: 'upgrade_members',
|
||||
timeSec: nowSec,
|
||||
uId: account.userId,
|
||||
uN: account.nick,
|
||||
old: String(oldLimit),
|
||||
new: String(clan.mlimit),
|
||||
ev: 'upgrade_members', timeSec: nowSec, uId: account.userId, uN: account.nick,
|
||||
old: String(oldLimit), new: String(clan.mlimit),
|
||||
});
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function disbandClanInState(state: StoredClansState, clan: ClanRecord | undefined, account: Account): RuleOutcome {
|
||||
const role = clan?.members.find((m) => m.uid === account.userId)?.role;
|
||||
if (!clan || (role !== ClanRole.LEADER && role !== ClanRole.CLANADMIN)) return refused('NOT_AVAILABLE');
|
||||
state.clans = state.clans.filter((c) => c.id !== clan.id);
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
function hasConflictingClan(clans: readonly ClanRecord[], excludeId: string | undefined, name: string, tag: string): boolean {
|
||||
const lowerName = name.toLowerCase();
|
||||
const coreTag = stripClanDecorators(tag).toLowerCase();
|
||||
return clans.some((c) => c.id !== excludeId && (c.name.toLowerCase() === lowerName || stripClanDecorators(c.tag).toLowerCase() === coreTag));
|
||||
}
|
||||
|
||||
function computeInfoEditPrice(
|
||||
clan: ClanRecord,
|
||||
economy: ClanEconomy,
|
||||
nextName: string,
|
||||
nextTag: string,
|
||||
changes: ClanInfoChanges,
|
||||
): Price {
|
||||
const nameChanged = nextName !== clan.name;
|
||||
const coreTagChanged = stripClanDecorators(nextTag) !== stripClanDecorators(clan.tag);
|
||||
const paidDecorChanged = nextTag !== clan.tag && nextTag !== clan.lastPaidTag && !isFreeDecorator(clan.type, nextTag, economy);
|
||||
const primaryChanged = nameChanged || coreTagChanged || paidDecorChanged;
|
||||
const secondaryChanged = (changes.desc !== undefined && changes.desc !== clan.desc)
|
||||
|| (changes.slogan !== undefined && changes.slogan !== clan.slogan)
|
||||
|| (changes.announcement !== undefined && changes.announcement !== clan.announcement)
|
||||
|| (changes.region !== undefined && changes.region !== clan.region);
|
||||
|
||||
const primaryGold = clan.type === 'battalion' ? economy.battalionPrimaryEditGold : economy.normalPrimaryEditGold;
|
||||
const primarySilver = clan.type === 'battalion' ? economy.battalionPrimaryEditSilver : economy.normalPrimaryEditSilver;
|
||||
const secondaryGold = clan.type === 'battalion' ? economy.battalionSecondaryEditGold : economy.normalSecondaryEditGold;
|
||||
const secondarySilver = clan.type === 'battalion' ? economy.battalionSecondaryEditSilver : economy.normalSecondaryEditSilver;
|
||||
|
||||
return {
|
||||
silverLions: (primaryChanged ? primarySilver : 0) + (!primaryChanged && secondaryChanged ? secondarySilver : 0),
|
||||
goldenEagles: (primaryChanged ? primaryGold : 0) + (!primaryChanged && secondaryChanged ? secondaryGold : 0),
|
||||
};
|
||||
}
|
||||
|
||||
function isFreeDecorator(clanType: ClanKind, tag: string, economy: ClanEconomy): boolean {
|
||||
const freeList = clanType === 'battalion' ? economy.battalionFreeDecorators : economy.normalFreeDecorators;
|
||||
return freeList.some((decor) => {
|
||||
const half = Math.floor(decor.length / 2);
|
||||
const start = decor.slice(0, half);
|
||||
const end = decor.slice(half);
|
||||
return tag.startsWith(start) && tag.endsWith(end);
|
||||
});
|
||||
}
|
||||
|
||||
function applyInfoFieldUpdates(
|
||||
clan: ClanRecord,
|
||||
account: Account,
|
||||
nextName: string,
|
||||
nextTag: string,
|
||||
changes: ClanInfoChanges,
|
||||
nowSec: number,
|
||||
): void {
|
||||
clan.name = nextName;
|
||||
if (nextTag !== clan.tag) {
|
||||
clan.tag = nextTag;
|
||||
clan.lastPaidTag = nextTag;
|
||||
}
|
||||
if (changes.desc !== undefined) clan.desc = changes.desc;
|
||||
if (changes.slogan !== undefined) clan.slogan = changes.slogan;
|
||||
if (changes.announcement !== undefined) clan.announcement = changes.announcement;
|
||||
if (changes.region !== undefined && changes.region !== clan.region) {
|
||||
clan.region = changes.region;
|
||||
clan.regionLastUpdatedSec = nowSec;
|
||||
}
|
||||
if (changes.status !== undefined) clan.status = changes.status;
|
||||
clan.changedByUid = account.userId;
|
||||
clan.changedByNick = account.nick;
|
||||
clan.changedTimeSec = nowSec;
|
||||
appendClanLog(clan, {
|
||||
ev: 'info', timeSec: nowSec, uId: account.userId, uN: account.nick,
|
||||
name: clan.name, tag: clan.tag, desc: clan.desc, slogan: clan.slogan,
|
||||
region: clan.region, announcement: clan.announcement, status: clan.status,
|
||||
});
|
||||
}
|
||||
|
||||
function buildCreatedClanRecord(
|
||||
id: string,
|
||||
account: Account,
|
||||
@@ -207,13 +253,13 @@ function buildCreatedClanRecord(
|
||||
input: CreateClanInput,
|
||||
nowSec: number,
|
||||
): ClanRecord {
|
||||
const periods = buildDefaultPeriods(Math.floor(nowSec / 86400), 360);
|
||||
const leaderMember: ClanMemberRecord = {
|
||||
const periods = buildDefaultPeriods(Math.floor(nowSec / 86400), MAX_ACTIVITY_PER_PERIOD);
|
||||
const leader: ClanMemberRecord = {
|
||||
uid: account.userId,
|
||||
nick: account.nick,
|
||||
role: ClanRole.LEADER,
|
||||
joinDateSec: nowSec,
|
||||
curActivity: 360,
|
||||
curActivity: MAX_ACTIVITY_PER_PERIOD,
|
||||
totalActivity: periods.reduce((s, p) => s + p.activity, 0),
|
||||
earnedSquadronExp: periods.reduce((s, p) => s + p.exp, 0),
|
||||
ratingArc: 1500,
|
||||
@@ -223,23 +269,12 @@ function buildCreatedClanRecord(
|
||||
};
|
||||
const desc = input.type === 'normal' ? input.desc : '';
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
tag,
|
||||
lastPaidTag: tag,
|
||||
type: input.type,
|
||||
slogan: input.slogan,
|
||||
desc,
|
||||
announcement: input.announcement,
|
||||
region: input.region,
|
||||
status: 'open',
|
||||
autoaccept: true,
|
||||
mlimit: input.type === 'battalion' ? 10 : 128,
|
||||
mspent: 0,
|
||||
cdateSec: nowSec,
|
||||
changedByUid: account.userId,
|
||||
changedByNick: account.nick,
|
||||
changedTimeSec: nowSec,
|
||||
id, name, tag, lastPaidTag: tag, type: input.type,
|
||||
slogan: input.slogan, desc, announcement: input.announcement, region: input.region,
|
||||
status: 'open', autoaccept: true,
|
||||
mlimit: input.type === 'battalion' ? BATTALION_INITIAL_MEMBER_LIMIT : NORMAL_CLAN_MEMBER_LIMIT,
|
||||
mspent: 0, cdateSec: nowSec,
|
||||
changedByUid: account.userId, changedByNick: account.nick, changedTimeSec: nowSec,
|
||||
regionLastUpdatedSec: input.region ? nowSec : 0,
|
||||
stats: {
|
||||
dr_era5_arc: 1500, dr_era5_hist: 1500, dr_era5_sim: 1500,
|
||||
@@ -248,22 +283,12 @@ function buildCreatedClanRecord(
|
||||
deaths_arc: 0, deaths_hist: 0, deaths_sim: 0,
|
||||
ftime_arc: 0, ftime_hist: 0, ftime_sim: 0,
|
||||
},
|
||||
members: [leaderMember],
|
||||
members: [leader],
|
||||
candidates: [],
|
||||
blacklist: [],
|
||||
logs: [{
|
||||
id: 1,
|
||||
ev: 'create',
|
||||
timeSec: nowSec,
|
||||
uId: account.userId,
|
||||
uN: account.nick,
|
||||
name,
|
||||
type: input.type,
|
||||
tag,
|
||||
desc,
|
||||
slogan: input.slogan,
|
||||
region: input.region,
|
||||
announcement: input.announcement,
|
||||
id: 1, ev: 'create', timeSec: nowSec, uId: account.userId, uN: account.nick,
|
||||
name, type: input.type, tag, desc, slogan: input.slogan, region: input.region, announcement: input.announcement,
|
||||
}],
|
||||
bestRewards: [],
|
||||
};
|
||||
|
||||
@@ -5,7 +5,14 @@
|
||||
import type { Account } from '../accounts/account-store.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
import { buildDefaultPeriods } from './clan-seeds.ts';
|
||||
import { ClanRole, roleNameOf, type ClanLogEntry, type ClanRecord } from './clan-types.ts';
|
||||
import {
|
||||
ClanRole,
|
||||
isAssignableClanRole,
|
||||
MAX_ACTIVITY_PER_PERIOD,
|
||||
roleNameOf,
|
||||
type ClanLogEntry,
|
||||
type ClanRecord,
|
||||
} from './clan-types.ts';
|
||||
|
||||
export interface MembershipRequestQuery {
|
||||
readonly clanId?: string | undefined;
|
||||
@@ -46,13 +53,13 @@ export function addMemberToClan(
|
||||
nowSec: number,
|
||||
): void {
|
||||
if (clan.members.some((m) => m.uid === uid)) return;
|
||||
const periods = buildDefaultPeriods(Math.floor(nowSec / 86400), 360);
|
||||
const periods = buildDefaultPeriods(Math.floor(nowSec / 86400), MAX_ACTIVITY_PER_PERIOD);
|
||||
clan.members.push({
|
||||
uid,
|
||||
nick,
|
||||
role,
|
||||
joinDateSec: nowSec,
|
||||
curActivity: 360,
|
||||
curActivity: MAX_ACTIVITY_PER_PERIOD,
|
||||
totalActivity: periods.reduce((s, p) => s + p.activity, 0),
|
||||
earnedSquadronExp: periods.reduce((s, p) => s + p.exp, 0),
|
||||
ratingArc: 1450,
|
||||
@@ -131,6 +138,7 @@ export function leaveClanInState(
|
||||
}
|
||||
|
||||
export function acceptCandidateOnClan(
|
||||
allClans: readonly ClanRecord[],
|
||||
clan: ClanRecord | undefined,
|
||||
initiator: Account,
|
||||
targetUid: string,
|
||||
@@ -140,8 +148,11 @@ export function acceptCandidateOnClan(
|
||||
): boolean {
|
||||
if (!clan || !hasClanOfficerRight(clan, initiator.userId) || clan.members.length >= clan.mlimit) return false;
|
||||
const cand = clan.candidates.find((c) => c.uid === targetUid);
|
||||
clan.candidates = clan.candidates.filter((c) => c.uid !== targetUid);
|
||||
addMemberToClan(clan, targetUid, cand?.nick ?? targetNick, role || ClanRole.REGULAR, initiator.userId, initiator.nick, nowSec);
|
||||
if (!cand) return false;
|
||||
if (allClans.some((c) => c.members.some((m) => m.uid === targetUid))) return false;
|
||||
const assignedRole = isAssignableClanRole(clan.type, role) ? role : ClanRole.REGULAR;
|
||||
clearCandidateEverywhere(allClans, targetUid);
|
||||
addMemberToClan(clan, targetUid, cand.nick || targetNick, assignedRole, initiator.userId, initiator.nick, nowSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -199,10 +210,23 @@ export function changeMemberRoleOnClan(
|
||||
nowSec: number,
|
||||
): boolean {
|
||||
if (!clan || !hasClanManageRight(clan, initiator.userId) || targetUid === initiator.userId) return false;
|
||||
const idx = clan.members.findIndex((m) => m.uid === targetUid);
|
||||
if (idx < 0) return false;
|
||||
const prev = clan.members[idx]!;
|
||||
clan.members[idx] = { ...prev, role: newRole };
|
||||
const initiatorIdx = clan.members.findIndex((m) => m.uid === initiator.userId);
|
||||
const targetIdx = clan.members.findIndex((m) => m.uid === targetUid);
|
||||
if (initiatorIdx < 0 || targetIdx < 0) return false;
|
||||
|
||||
const initiatorMember = clan.members[initiatorIdx]!;
|
||||
const prev = clan.members[targetIdx]!;
|
||||
|
||||
if (newRole === ClanRole.LEADER) {
|
||||
if (initiatorMember.role !== ClanRole.LEADER) return false;
|
||||
const demotedRole = clan.type === 'battalion' ? ClanRole.OFFICER : ClanRole.DEPUTY;
|
||||
clan.members[initiatorIdx] = { ...initiatorMember, role: demotedRole };
|
||||
clan.members[targetIdx] = { ...prev, role: ClanRole.LEADER };
|
||||
} else {
|
||||
if (prev.role === ClanRole.LEADER || !isAssignableClanRole(clan.type, newRole)) return false;
|
||||
clan.members[targetIdx] = { ...prev, role: newRole };
|
||||
}
|
||||
|
||||
appendClanLog(clan, {
|
||||
ev: 'role',
|
||||
timeSec: nowSec,
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
* Read-only search and leaderboard queries over the local squadron directory
|
||||
*.
|
||||
*/
|
||||
import { totalPeriodActivityOf } from './clan-blk.ts';
|
||||
import { stripClanDecorators } from './clan-lifecycle.ts';
|
||||
import type { ClanRecord } from './clan-types.ts';
|
||||
import { totalPeriodActivityOf, type ClanRecord } from './clan-types.ts';
|
||||
|
||||
export interface LeaderboardQuery {
|
||||
readonly start: number;
|
||||
|
||||
@@ -1,129 +1,27 @@
|
||||
/**
|
||||
* Default offline squadron directory seeded on first creation of `<data>/clans.json`
|
||||
* (implementation notes section I). Includes open auto-accept squadrons for instant offline
|
||||
* joining, a manual-review squadron for testing candidate requests, a battalion squadron,
|
||||
* and rich NPC member profiles so player cards work for every member.
|
||||
* (implementation notes section I; implementation notes).
|
||||
*/
|
||||
import { ClanRole, type ClanActivityPeriodEntry, type ClanMemberRecord, type ClanRecord } from './clan-types.ts';
|
||||
import {
|
||||
BATTALION_INITIAL_MEMBER_LIMIT,
|
||||
ClanRole,
|
||||
MAX_ACTIVITY_PER_PERIOD,
|
||||
MAX_CLAN_ACTIVITY,
|
||||
NORMAL_CLAN_MEMBER_LIMIT,
|
||||
REWARD_PERIOD_DAYS,
|
||||
type ClanActivityPeriodEntry,
|
||||
type ClanMemberRecord,
|
||||
type ClanRecord,
|
||||
} from './clan-types.ts';
|
||||
|
||||
export function createDefaultClans(nowSec = Math.floor(Date.now() / 1000)): ClanRecord[] {
|
||||
const todayDay = Math.floor(nowSec / 86400);
|
||||
const createdBase = nowSec - 180 * 86400;
|
||||
|
||||
return [
|
||||
buildSeededClan({
|
||||
id: '500001',
|
||||
tag: '[WTOF]',
|
||||
name: 'War Thunder Offline Guard',
|
||||
type: 'normal',
|
||||
slogan: '离线天空与钢铁防线 · 自由研发全部联队载具',
|
||||
desc: 'War Thunder Offline 官方预置主力联队。开启自动审批,加入即可获得完整联队活跃度与联队研发点支持。',
|
||||
announcement: '欢迎加入 [WTOF]!可在联队页面右上角点击「联队载具」或「活跃度」查看研发进度。',
|
||||
region: 'CN / Global',
|
||||
autoaccept: true,
|
||||
mlimit: 128,
|
||||
cdateSec: createdBase,
|
||||
todayDay,
|
||||
eloArc: 1840,
|
||||
eloHist: 2150,
|
||||
eloSim: 1620,
|
||||
npcs: [
|
||||
{ uid: '900001001', nick: 'Lin_Wei', role: ClanRole.LEADER, title: 'title_marshall', icon: 'cardicon_28', unit: 'cn_ztz_99a', activity: 360 },
|
||||
{ uid: '900001002', nick: 'Elena_Valkyrie', role: ClanRole.DEPUTY, title: 'title_ace', icon: 'cardicon_fem_01', unit: 'su_27sm', activity: 360 },
|
||||
{ uid: '900001003', nick: 'iron_tiger_88', role: ClanRole.OFFICER, title: 'title_tank_destroyer', icon: 'cardicon_14', unit: 'germ_leopard_2a7v', activity: 360 },
|
||||
{ uid: '900001004', nick: 'Tomcat_Actual', role: ClanRole.OFFICER, title: 'title_jet_powered', icon: 'cardicon_07', unit: 'f_14b', activity: 345 },
|
||||
{ uid: '900001005', nick: 'Kuroshio_DD', role: ClanRole.SERGEANT, title: 'title_sea_wolf', icon: 'cardicon_19', unit: 'jp_destroyer_shimakaze', activity: 330 },
|
||||
{ uid: '900001006', nick: 'Northern_Fox', role: ClanRole.REGULAR, title: 'title_sniper', icon: 'cardicon_11', unit: 'sw_strv_122b_plus', activity: 310 },
|
||||
],
|
||||
}),
|
||||
buildSeededClan({
|
||||
id: '500002',
|
||||
tag: '=PLAF=',
|
||||
name: 'Red Falcon Aviation Wing',
|
||||
type: 'normal',
|
||||
slogan: '鹰击长空 · 现代喷气空战与陆空协同联队',
|
||||
desc: '专注于高阶喷气机与现代主战坦克联合作战的离线联队,支持自动入队与高活跃度加成。',
|
||||
announcement: '本期联队研发推荐:F-16A OCU、苏-33、豹 2PL、M1A1 AIM。',
|
||||
region: 'Asia',
|
||||
autoaccept: true,
|
||||
mlimit: 128,
|
||||
cdateSec: createdBase + 86400 * 12,
|
||||
todayDay,
|
||||
eloArc: 1690,
|
||||
eloHist: 2040,
|
||||
eloSim: 1780,
|
||||
npcs: [
|
||||
{ uid: '900002001', nick: 'SkyDragon_J20', role: ClanRole.LEADER, title: 'title_ace', icon: 'cardicon_25', unit: 'j_11a', activity: 360 },
|
||||
{ uid: '900002002', nick: 'Thunderbolt_CN', role: ClanRole.DEPUTY, title: 'title_pilot', icon: 'cardicon_09', unit: 'jh_7a', activity: 360 },
|
||||
{ uid: '900002003', nick: 'SteelWall_99', role: ClanRole.OFFICER, title: 'title_unstoppable', icon: 'cardicon_16', unit: 'cn_vt_4a1', activity: 350 },
|
||||
{ uid: '900002004', nick: 'NightHawk_04', role: ClanRole.REGULAR, title: 'title_eagle', icon: 'cardicon_05', unit: 'f_15j_kai', activity: 300 },
|
||||
],
|
||||
}),
|
||||
buildSeededClan({
|
||||
id: '500003',
|
||||
tag: '-1STG-',
|
||||
name: '1st Armored Guards Division',
|
||||
type: 'normal',
|
||||
slogan: 'Steel & Fire — Heavy Armor Historical Squadron',
|
||||
desc: 'Classic and modern armored warfare squadron. Open auto-accept recruitment for all tank commanders.',
|
||||
announcement: 'Squadron vehicles ready for research at full 20,000 RP per period.',
|
||||
region: 'EU / Global',
|
||||
autoaccept: true,
|
||||
mlimit: 128,
|
||||
cdateSec: createdBase + 86400 * 24,
|
||||
todayDay,
|
||||
eloArc: 1920,
|
||||
eloHist: 1980,
|
||||
eloSim: 1510,
|
||||
npcs: [
|
||||
{ uid: '900003001', nick: 'Kommissar_KVs', role: ClanRole.LEADER, title: 'title_hero', icon: 'cardicon_22', unit: 'ussr_t_90m', activity: 360 },
|
||||
{ uid: '900003002', nick: 'PanzerMeyer_IV', role: ClanRole.OFFICER, title: 'title_tankman', icon: 'cardicon_12', unit: 'germ_pzkpfw_VI_ausf_h1_tiger', activity: 340 },
|
||||
{ uid: '900003003', nick: 'DesertRat_UK', role: ClanRole.REGULAR, title: 'title_conqueror', icon: 'cardicon_18', unit: 'uk_challenger_2_black_night', activity: 290 },
|
||||
],
|
||||
}),
|
||||
buildSeededClan({
|
||||
id: '500004',
|
||||
tag: '^82AB^',
|
||||
name: '82nd Combined Task Force',
|
||||
type: 'normal',
|
||||
slogan: 'All The Way — Air, Ground & Naval Task Force',
|
||||
desc: '需要审批模式的示例联队(用于测试发送与撤回入队申请流程)。若想立即加入联队,请选择 [WTOF]、=PLAF= 或 -1STG-。',
|
||||
announcement: 'Manual application review enabled for testing request/cancel workflow.',
|
||||
region: 'NA',
|
||||
autoaccept: false,
|
||||
mlimit: 128,
|
||||
cdateSec: createdBase + 86400 * 35,
|
||||
todayDay,
|
||||
eloArc: 1550,
|
||||
eloHist: 1760,
|
||||
eloSim: 1490,
|
||||
npcs: [
|
||||
{ uid: '900004001', nick: 'Major_Winters', role: ClanRole.LEADER, title: 'title_brother_in_arms', icon: 'cardicon_03', unit: 'us_m1a2_sep2_abrams', activity: 360 },
|
||||
{ uid: '900004002', nick: 'Mustang_Lead', role: ClanRole.OFFICER, title: 'title_ace', icon: 'cardicon_08', unit: 'p-51d-30_usaaf_korea', activity: 315 },
|
||||
],
|
||||
}),
|
||||
buildSeededClan({
|
||||
id: '500005',
|
||||
tag: '**RCON**',
|
||||
name: 'Reconnaissance Battalion Alpha',
|
||||
type: 'battalion',
|
||||
slogan: '轻量级战术分队 · 侦察与快速反应',
|
||||
desc: '战斗群(Battalion)类型预置联队,开启自动加入,支持体验战斗群架构与联队扩编。',
|
||||
announcement: '轻装侦察分队常驻开放。',
|
||||
region: 'Global',
|
||||
autoaccept: true,
|
||||
mlimit: 10,
|
||||
cdateSec: createdBase + 86400 * 48,
|
||||
todayDay,
|
||||
eloArc: 1410,
|
||||
eloHist: 1610,
|
||||
eloSim: 1320,
|
||||
npcs: [
|
||||
{ uid: '900005001', nick: 'Ghost_Scout', role: ClanRole.LEADER, title: 'title_scout', icon: 'cardicon_15', unit: 'us_hstvl', activity: 360 },
|
||||
{ uid: '900005002', nick: 'Lynx_Spotter', role: ClanRole.REGULAR, title: 'title_sniper', icon: 'cardicon_20', unit: 'it_centauro_rgo_120', activity: 280 },
|
||||
],
|
||||
}),
|
||||
];
|
||||
interface NpcSpec {
|
||||
readonly uid: string;
|
||||
readonly nick: string;
|
||||
readonly role: number;
|
||||
readonly title: string;
|
||||
readonly icon: string;
|
||||
readonly unit: string;
|
||||
readonly activity: number;
|
||||
}
|
||||
|
||||
interface SeedSpec {
|
||||
@@ -137,45 +35,140 @@ interface SeedSpec {
|
||||
readonly region: string;
|
||||
readonly autoaccept: boolean;
|
||||
readonly mlimit: number;
|
||||
readonly cdateSec: number;
|
||||
readonly todayDay: number;
|
||||
readonly dayOffset: number;
|
||||
readonly eloArc: number;
|
||||
readonly eloHist: number;
|
||||
readonly eloSim: number;
|
||||
readonly npcs: ReadonlyArray<{
|
||||
readonly uid: string;
|
||||
readonly nick: string;
|
||||
readonly role: number;
|
||||
readonly title: string;
|
||||
readonly icon: string;
|
||||
readonly unit: string;
|
||||
readonly activity: number;
|
||||
}>;
|
||||
readonly npcs: readonly NpcSpec[];
|
||||
}
|
||||
|
||||
function buildSeededClan(spec: SeedSpec): ClanRecord {
|
||||
const members: ClanMemberRecord[] = spec.npcs.map((npc, idx) => {
|
||||
const periods = buildDefaultPeriods(spec.todayDay, npc.activity);
|
||||
return {
|
||||
uid: npc.uid,
|
||||
nick: npc.nick,
|
||||
role: npc.role,
|
||||
joinDateSec: spec.cdateSec + idx * 3600,
|
||||
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(800, spec.eloArc - idx * 45),
|
||||
ratingHist: Math.max(850, spec.eloHist - idx * 50),
|
||||
ratingSim: Math.max(700, spec.eloSim - idx * 40),
|
||||
periods,
|
||||
};
|
||||
});
|
||||
const SEED_SPECS: readonly SeedSpec[] = [
|
||||
{
|
||||
id: '500001',
|
||||
tag: '[WTOF]',
|
||||
name: 'War Thunder Offline Guard',
|
||||
type: 'normal',
|
||||
slogan: '离线天空与钢铁防线 · 自由研发全部联队载具',
|
||||
desc: 'War Thunder Offline 官方预置主力联队。开启自动审批,加入即可获得完整联队活跃度与联队研发点支持。',
|
||||
announcement: '欢迎加入 [WTOF]!可在联队页面右上角点击「联队载具」或「活跃度」查看研发进度。',
|
||||
region: 'CN / Global',
|
||||
autoaccept: true,
|
||||
mlimit: NORMAL_CLAN_MEMBER_LIMIT,
|
||||
dayOffset: 0,
|
||||
eloArc: 1840,
|
||||
eloHist: 2150,
|
||||
eloSim: 1620,
|
||||
npcs: [
|
||||
{ uid: '900001001', nick: 'Lin_Wei', role: ClanRole.LEADER, title: 'title_marshall', icon: 'cardicon_28', unit: 'cn_ztz_99a', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900001002', nick: 'Elena_Valkyrie', role: ClanRole.DEPUTY, title: 'title_ace', icon: 'cardicon_fem_01', unit: 'su_27sm', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900001003', nick: 'iron_tiger_88', role: ClanRole.OFFICER, title: 'title_tank_destroyer', icon: 'cardicon_14', unit: 'germ_leopard_2a7v', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900001004', nick: 'Tomcat_Actual', role: ClanRole.OFFICER, title: 'title_jet_powered', icon: 'cardicon_07', unit: 'f_14b', activity: 345 },
|
||||
{ uid: '900001005', nick: 'Kuroshio_DD', role: ClanRole.SERGEANT, title: 'title_sea_wolf', icon: 'cardicon_19', unit: 'jp_destroyer_shimakaze', activity: 330 },
|
||||
{ uid: '900001006', nick: 'Northern_Fox', role: ClanRole.REGULAR, title: 'title_sniper', icon: 'cardicon_11', unit: 'sw_strv_122b_plus', activity: 310 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: '500002',
|
||||
tag: '=PLAF=',
|
||||
name: 'Red Falcon Aviation Wing',
|
||||
type: 'normal',
|
||||
slogan: '鹰击长空 · 现代喷气空战与陆空协同联队',
|
||||
desc: '专注于高阶喷气机与现代主战坦克联合作战的离线联队,支持自动入队与高活跃度加成。',
|
||||
announcement: '本期联队研发推荐:F-16A OCU、苏-33、豹 2PL、M1A1 AIM。',
|
||||
region: 'Asia',
|
||||
autoaccept: true,
|
||||
mlimit: NORMAL_CLAN_MEMBER_LIMIT,
|
||||
dayOffset: 12,
|
||||
eloArc: 1690,
|
||||
eloHist: 2040,
|
||||
eloSim: 1780,
|
||||
npcs: [
|
||||
{ uid: '900002001', nick: 'SkyDragon_J20', role: ClanRole.LEADER, title: 'title_ace', icon: 'cardicon_25', unit: 'j_11a', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900002002', nick: 'Thunderbolt_CN', role: ClanRole.DEPUTY, title: 'title_pilot', icon: 'cardicon_09', unit: 'jh_7a', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900002003', nick: 'SteelWall_99', role: ClanRole.OFFICER, title: 'title_unstoppable', icon: 'cardicon_16', unit: 'cn_vt_4a1', activity: 350 },
|
||||
{ uid: '900002004', nick: 'NightHawk_04', role: ClanRole.REGULAR, title: 'title_eagle', icon: 'cardicon_05', unit: 'f_15j_kai', activity: 300 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: '500003',
|
||||
tag: '-1STG-',
|
||||
name: '1st Armored Guards Division',
|
||||
type: 'normal',
|
||||
slogan: 'Steel & Fire — Heavy Armor Historical Squadron',
|
||||
desc: 'Classic and modern armored warfare squadron. Open auto-accept recruitment for all tank commanders.',
|
||||
announcement: 'Squadron vehicles ready for research at full 20,000 RP per period.',
|
||||
region: 'EU / Global',
|
||||
autoaccept: true,
|
||||
mlimit: NORMAL_CLAN_MEMBER_LIMIT,
|
||||
dayOffset: 24,
|
||||
eloArc: 1920,
|
||||
eloHist: 1980,
|
||||
eloSim: 1510,
|
||||
npcs: [
|
||||
{ uid: '900003001', nick: 'Kommissar_KVs', role: ClanRole.LEADER, title: 'title_hero', icon: 'cardicon_22', unit: 'ussr_t_90m', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900003002', nick: 'PanzerMeyer_IV', role: ClanRole.OFFICER, title: 'title_tankman', icon: 'cardicon_12', unit: 'germ_pzkpfw_VI_ausf_h1_tiger', activity: 340 },
|
||||
{ uid: '900003003', nick: 'DesertRat_UK', role: ClanRole.REGULAR, title: 'title_conqueror', icon: 'cardicon_18', unit: 'uk_challenger_2_black_night', activity: 290 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: '500004',
|
||||
tag: '^82AB^',
|
||||
name: '82nd Combined Task Force',
|
||||
type: 'normal',
|
||||
slogan: 'All The Way — Air, Ground & Naval Task Force',
|
||||
desc: '需要审批模式的示例联队(用于测试发送与撤回入队申请流程)。若想立即加入联队,请选择 [WTOF]、=PLAF= 或 -1STG-。',
|
||||
announcement: 'Manual application review enabled for testing request/cancel workflow.',
|
||||
region: 'NA',
|
||||
autoaccept: false,
|
||||
mlimit: NORMAL_CLAN_MEMBER_LIMIT,
|
||||
dayOffset: 35,
|
||||
eloArc: 1550,
|
||||
eloHist: 1760,
|
||||
eloSim: 1490,
|
||||
npcs: [
|
||||
{ uid: '900004001', nick: 'Major_Winters', role: ClanRole.LEADER, title: 'title_brother_in_arms', icon: 'cardicon_03', unit: 'us_m1a2_sep2_abrams', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900004002', nick: 'Mustang_Lead', role: ClanRole.OFFICER, title: 'title_ace', icon: 'cardicon_08', unit: 'p-51d-30_usaaf_korea', activity: 315 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: '500005',
|
||||
tag: '**RCON**',
|
||||
name: 'Reconnaissance Battalion Alpha',
|
||||
type: 'battalion',
|
||||
slogan: '轻量级战术分队 · 侦察与快速反应',
|
||||
desc: '战斗群(Battalion)类型预置联队,开启自动加入,支持体验战斗群架构与联队扩编。',
|
||||
announcement: '轻装侦察分队常驻开放。',
|
||||
region: 'Global',
|
||||
autoaccept: true,
|
||||
mlimit: BATTALION_INITIAL_MEMBER_LIMIT,
|
||||
dayOffset: 48,
|
||||
eloArc: 1410,
|
||||
eloHist: 1610,
|
||||
eloSim: 1320,
|
||||
npcs: [
|
||||
{ uid: '900005001', nick: 'Ghost_Scout', role: ClanRole.LEADER, title: 'title_scout', icon: 'cardicon_15', unit: 'us_hstvl', activity: MAX_ACTIVITY_PER_PERIOD },
|
||||
{ uid: '900005002', nick: 'Lynx_Spotter', role: ClanRole.REGULAR, title: 'title_sniper', icon: 'cardicon_20', unit: 'it_centauro_rgo_120', activity: 280 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export function createDefaultClans(nowSec = Math.floor(Date.now() / 1000)): ClanRecord[] {
|
||||
const todayDay = Math.floor(nowSec / 86400);
|
||||
const createdBase = nowSec - 180 * 86400;
|
||||
return SEED_SPECS.map((spec) => buildSeededClan(spec, createdBase + spec.dayOffset * 86400, todayDay));
|
||||
}
|
||||
|
||||
export function buildDefaultPeriods(todayDay: number, periodActivity = MAX_ACTIVITY_PER_PERIOD): ClanActivityPeriodEntry[] {
|
||||
const expPerPeriod = Math.round((periodActivity / MAX_ACTIVITY_PER_PERIOD) * MAX_CLAN_ACTIVITY);
|
||||
return [0, 1, 2].map((idx) => ({
|
||||
day: todayDay - idx * REWARD_PERIOD_DAYS,
|
||||
activity: periodActivity,
|
||||
exp: expPerPeriod,
|
||||
}));
|
||||
}
|
||||
|
||||
function buildSeededClan(spec: SeedSpec, cdateSec: number, todayDay: number): ClanRecord {
|
||||
const members = spec.npcs.map((npc, idx) => buildSeededMember(spec, npc, idx, cdateSec, todayDay));
|
||||
const leader = spec.npcs[0]!;
|
||||
return {
|
||||
id: spec.id,
|
||||
@@ -191,56 +184,48 @@ function buildSeededClan(spec: SeedSpec): ClanRecord {
|
||||
autoaccept: spec.autoaccept,
|
||||
mlimit: spec.mlimit,
|
||||
mspent: 0,
|
||||
cdateSec: spec.cdateSec,
|
||||
cdateSec,
|
||||
changedByUid: leader.uid,
|
||||
changedByNick: leader.nick,
|
||||
changedTimeSec: spec.cdateSec,
|
||||
changedTimeSec: cdateSec,
|
||||
regionLastUpdatedSec: 0,
|
||||
stats: {
|
||||
dr_era5_arc: spec.eloArc,
|
||||
dr_era5_hist: spec.eloHist,
|
||||
dr_era5_sim: spec.eloSim,
|
||||
akills_arc: 4280,
|
||||
akills_hist: 6150,
|
||||
akills_sim: 1420,
|
||||
gkills_arc: 7890,
|
||||
gkills_hist: 11240,
|
||||
gkills_sim: 2680,
|
||||
deaths_arc: 5120,
|
||||
deaths_hist: 6890,
|
||||
deaths_sim: 1950,
|
||||
ftime_arc: 18400,
|
||||
ftime_hist: 32600,
|
||||
ftime_sim: 8900,
|
||||
dr_era5_arc: spec.eloArc, dr_era5_hist: spec.eloHist, dr_era5_sim: spec.eloSim,
|
||||
akills_arc: 4280, akills_hist: 6150, akills_sim: 1420,
|
||||
gkills_arc: 7890, gkills_hist: 11240, gkills_sim: 2680,
|
||||
deaths_arc: 5120, deaths_hist: 6890, deaths_sim: 1950,
|
||||
ftime_arc: 18400, ftime_hist: 32600, ftime_sim: 8900,
|
||||
},
|
||||
members,
|
||||
candidates: [],
|
||||
blacklist: [],
|
||||
logs: [
|
||||
{
|
||||
id: 1,
|
||||
ev: 'create',
|
||||
timeSec: spec.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,
|
||||
},
|
||||
],
|
||||
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: [],
|
||||
};
|
||||
}
|
||||
|
||||
export function buildDefaultPeriods(todayDay: number, periodActivity = 360): ClanActivityPeriodEntry[] {
|
||||
const expPerPeriod = Math.round((periodActivity / 360) * 20000);
|
||||
return [
|
||||
{ day: todayDay, activity: periodActivity, exp: expPerPeriod },
|
||||
{ day: todayDay - 3, activity: periodActivity, exp: expPerPeriod },
|
||||
{ day: todayDay - 6, activity: Math.max(180, periodActivity - 30), exp: Math.round((Math.max(180, periodActivity - 30) / 360) * 20000) },
|
||||
];
|
||||
function buildSeededMember(spec: SeedSpec, npc: NpcSpec, idx: number, cdateSec: number, todayDay: number): ClanMemberRecord {
|
||||
const periods = buildDefaultPeriods(todayDay, npc.activity);
|
||||
return {
|
||||
uid: npc.uid,
|
||||
nick: npc.nick,
|
||||
role: npc.role,
|
||||
joinDateSec: cdateSec + idx * 3600,
|
||||
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(800, spec.eloArc - idx * 45),
|
||||
ratingHist: Math.max(850, spec.eloHist - idx * 50),
|
||||
ratingSim: Math.max(700, spec.eloSim - idx * 40),
|
||||
periods,
|
||||
};
|
||||
}
|
||||
@@ -15,10 +15,11 @@ import {
|
||||
setPendingClanRequest,
|
||||
syncStoredClanEarnedExp,
|
||||
} from '../profile/profile-clan.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
import type { RuleOutcome } from '../research/rule-outcome.ts';
|
||||
import { writeFileAtomic } from '../storage/atomic-file.ts';
|
||||
import {
|
||||
createClanInState,
|
||||
disbandClanInState,
|
||||
editClanInfoInState,
|
||||
upgradeClanToNormalInState,
|
||||
upgradeMembersLimitInState,
|
||||
@@ -39,7 +40,7 @@ import {
|
||||
} from './clan-membership.ts';
|
||||
import { findClanInList, queryClanLeaderboard, type LeaderboardQuery } from './clan-queries.ts';
|
||||
import { createDefaultClans } from './clan-seeds.ts';
|
||||
import { ClanRole, type ClanBestReward, type ClanMemberRecord, type ClanRecord } from './clan-types.ts';
|
||||
import type { ClanBestReward, ClanMemberRecord, ClanRecord } from './clan-types.ts';
|
||||
|
||||
export type { LeaderboardQuery };
|
||||
|
||||
@@ -140,7 +141,7 @@ export class ClanStore {
|
||||
}
|
||||
|
||||
editClanInfo(profile: BlkBlock, account: Account, economy: ClanEconomy, clanId: string, changes: ClanInfoChanges, nowSec = nowSeconds()): RuleOutcome {
|
||||
const outcome = editClanInfoInState(this.#resolveClan(clanId, account.userId), profile, account, economy, changes, nowSec);
|
||||
const outcome = editClanInfoInState(this.#state.clans, this.#resolveClan(clanId, account.userId), profile, account, economy, changes, nowSec);
|
||||
if (outcome.ok) {
|
||||
this.#save();
|
||||
this.syncProfile(profile, account);
|
||||
@@ -156,7 +157,7 @@ export class ClanStore {
|
||||
input: { readonly tag: string; readonly desc: string; readonly announcement: string },
|
||||
nowSec = nowSeconds(),
|
||||
): RuleOutcome {
|
||||
const outcome = upgradeClanToNormalInState(this.#resolveClan(clanId, account.userId), profile, account, economy, input, nowSec);
|
||||
const outcome = upgradeClanToNormalInState(this.#state.clans, this.#resolveClan(clanId, account.userId), profile, account, economy, input, nowSec);
|
||||
if (outcome.ok) {
|
||||
this.#save();
|
||||
this.syncProfile(profile, account);
|
||||
@@ -203,17 +204,16 @@ export class ClanStore {
|
||||
}
|
||||
|
||||
disbandClan(profile: BlkBlock, account: Account, clanId?: string): RuleOutcome {
|
||||
const clan = this.#resolveClan(clanId, account.userId);
|
||||
const role = clan?.members.find((m) => m.uid === account.userId)?.role;
|
||||
if (!clan || (role !== ClanRole.LEADER && role !== ClanRole.CLANADMIN)) return refused('NOT_AVAILABLE');
|
||||
this.#state.clans = this.#state.clans.filter((c) => c.id !== clan.id);
|
||||
this.#save();
|
||||
this.syncProfile(profile, account);
|
||||
return ACCEPTED;
|
||||
const outcome = disbandClanInState(this.#state, this.#resolveClan(clanId, account.userId), account);
|
||||
if (outcome.ok) {
|
||||
this.#save();
|
||||
this.syncProfile(profile, account);
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
|
||||
acceptCandidate(initiator: Account, clanId: string | undefined, targetUid: string, targetNick: string, role: number, nowSec = nowSeconds()): boolean {
|
||||
if (!acceptCandidateOnClan(this.#resolveClan(clanId, initiator.userId), initiator, targetUid, targetNick, role, nowSec)) return false;
|
||||
if (!acceptCandidateOnClan(this.#state.clans, this.#resolveClan(clanId, initiator.userId), initiator, targetUid, targetNick, role, nowSec)) return false;
|
||||
this.#save();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
/**
|
||||
* Types and binary enum constants for the local squadron (clan) system
|
||||
* Types, binary enum constants, and shared squadron domain constants
|
||||
*.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { ClanKind } from '../profile/profile-clan.ts';
|
||||
|
||||
export const MAX_ACTIVITY_PER_PERIOD = 360;
|
||||
export const MAX_CLAN_ACTIVITY = 20_000;
|
||||
export const REWARD_PERIOD_DAYS = 3;
|
||||
export const HISTORY_DEPTH_DAYS = 14;
|
||||
export const NORMAL_CLAN_MEMBER_LIMIT = 128;
|
||||
export const BATTALION_INITIAL_MEMBER_LIMIT = 10;
|
||||
|
||||
/** Exact `ECMR_*` role codes registered at aces.exe 0x2986a0..0x298802 (table 0x7ba87e8). */
|
||||
export const ClanRole = {
|
||||
LEADER: 1,
|
||||
@@ -32,6 +39,39 @@ export function roleNameOf(role: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function roleCodeFromString(name: string): number | undefined {
|
||||
switch (name.trim().toUpperCase()) {
|
||||
case 'LEADER':
|
||||
return ClanRole.LEADER;
|
||||
case 'DEPUTY':
|
||||
return ClanRole.DEPUTY;
|
||||
case 'OFFICER':
|
||||
return ClanRole.OFFICER;
|
||||
case 'SERGEANT':
|
||||
return ClanRole.SERGEANT;
|
||||
case 'REGULAR':
|
||||
return ClanRole.REGULAR;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether a non-leader member role is valid for the given squadron type (0x2986a0 table). */
|
||||
export function isAssignableClanRole(clanType: ClanKind, role: number): boolean {
|
||||
if (clanType === 'battalion') {
|
||||
return role === ClanRole.OFFICER || role === ClanRole.REGULAR;
|
||||
}
|
||||
return role === ClanRole.DEPUTY
|
||||
|| role === ClanRole.OFFICER
|
||||
|| role === ClanRole.SERGEANT
|
||||
|| role === ClanRole.REGULAR;
|
||||
}
|
||||
|
||||
export function totalPeriodActivityOf(clan: ClanRecord): number {
|
||||
const sum = clan.members.reduce((acc, m) => acc + m.curActivity, 0);
|
||||
return Math.min(MAX_CLAN_ACTIVITY * 5, sum * 10);
|
||||
}
|
||||
|
||||
export interface ClanStats {
|
||||
readonly dr_era5_arc: number;
|
||||
readonly dr_era5_hist: number;
|
||||
|
||||
Reference in new issue
Block a user