fix(modifications): emit RESEARCHED status and align buy-all pricing

Add ModuleStatus.RESEARCHED (0x40, ES_ITEM_STATUS_RESEARCHED) for modifications that have reached their RP requirement while a reqModification prerequisite is not yet owned, and keep unresearched modifications locked until their prerequisites are researched.

Update buyAllModifications / buyAllEntry to accept both CAN_BUY and RESEARCHED so the server matches client getAllModsCost (canBuyMod || isModStatusResearched) instead of rejecting cln_buy_all_modification with PRICE_CHANGED (shown as Internal character server error).

Verified: root and launcher typecheck, and runtime check against 2.61.0.58 wpcost.blk chained modifications. Pending in-game acceptance.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 06:38:15 +08:00
1 parent 638bc75724
commit f6b00bc787
2 files changed
+41 -9

No files matched your search

@@ -21,7 +21,7 @@ import { moduleResearchTarget, setModuleResearchTarget } from '../profile/profil
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import { isCounted, isResearchable, type EquipmentCatalogue } from './equipment-catalogue.ts';
import { currentModuleStatus } from './module-state.ts';
import { ModuleStatus } from './module-status.ts';
import { ModuleStatus, vehicleModuleState } from './module-status.ts';
export interface ModificationOrder {
readonly vehicle: string;
@@ -48,8 +48,9 @@ export function buyModification(profile: BlkBlock, catalogue: EquipmentCatalogue
export function buyAllModifications(profile: BlkBlock, catalogue: EquipmentCatalogue, vehicle: string, outright: boolean, offered: Price): RuleOutcome {
const equipment = catalogue.vehicle(vehicle);
if (!equipment || !ownsVehicle(profile, vehicle)) return refused('BAD_PARAMS');
const { statuses } = vehicleModuleState(profile, equipment);
const purchases = equipment.modifications.flatMap((modification) => {
const purchase = buyAllEntry(profile, vehicle, modification, catalogue, outright);
const purchase = buyAllEntry(profile, vehicle, modification, statuses.get(modification.name), outright);
return purchase ? [{ modification, purchase }] : [];
});
const price = purchases.reduce<Price>((sum, { purchase }) => ({
@@ -114,17 +115,24 @@ function outrightPurchase(profile: BlkBlock, vehicle: string, modification: Modi
/**
* One entry of "buy all", as the client sums it (scripts weaponry/itemInfo.nut getAllModsCost):
* skip what is at its maximum; with forceOpen every modification starts at its outright price
* (whatever its status); a buyable one (canBuyMod) with a non-zero price takes its own price
* instead, and is skipped altogether when counted or priced in golden eagles.
* (whatever its status); a buyable or researched one (canBuyMod || isModStatusResearched) with a
* non-zero price takes its own price instead, and is skipped altogether when counted or priced in
* golden eagles.
*/
function buyAllEntry(profile: BlkBlock, vehicle: string, modification: ModificationFacts, catalogue: EquipmentCatalogue, outright: boolean): Purchase | undefined {
function buyAllEntry(
profile: BlkBlock,
vehicle: string,
modification: ModificationFacts,
status: ModuleStatus | undefined,
outright: boolean,
): Purchase | undefined {
const record = modificationRecord(profile, vehicle, modification.name);
const maxAmount = Math.max(1, modification.maxCount);
if ((record?.count ?? 0) >= maxAmount) return undefined;
let purchase: Purchase | undefined;
const openPrice = outright && isResearchable(modification) ? outrightPrice(profile, vehicle, modification) : 0;
if (openPrice > 0) purchase = { price: { silverLions: 0, goldenEagles: openPrice }, amount: 1 };
const buyable = record !== undefined || currentModuleStatus(profile, catalogue, vehicle, modification.name) === ModuleStatus.CAN_BUY;
const buyable = record !== undefined || status === ModuleStatus.CAN_BUY || status === ModuleStatus.RESEARCHED;
if (buyable && (modification.silverLions > 0 || modification.goldenEagles > 0)) {
if (isCounted(modification) || modification.goldenEagles > 0) return undefined;
purchase = { price: { silverLions: modification.silverLions, goldenEagles: 0 }, amount: 1 };
+27 -3
View File
@@ -10,11 +10,12 @@ import { moduleResearchPoints } from '../profile/profile-module-research.ts';
import { countsForTier, isResearchable } from './equipment-catalogue.ts';
import type { ProfileEquipmentIndex } from './profile-equipment-index.ts';
/** shopItemConsts ES_ITEM_STATUS_*; the same values as the vehicle statuses. */
/** shopItemConsts ES_ITEM_STATUS_* (aces.exe 2.61.0.58 0x17e2894..0x17e294b); same values as VehicleStatus. */
export const ModuleStatus = {
LOCKED: 1,
CAN_RESEARCH: 2,
CAN_BUY: 8,
RESEARCHED: 0x40,
} as const;
export type ModuleStatus = (typeof ModuleStatus)[keyof typeof ModuleStatus];
@@ -32,10 +33,11 @@ export function vehicleModuleState(
index?: ProfileEquipmentIndex,
): VehicleModuleState {
const openTier = openTierOf(profile, equipment, index);
const byName = new Map(equipment.modifications.map((mod) => [mod.name, mod]));
const statuses = new Map<string, ModuleStatus>();
for (const modification of equipment.modifications) {
if (isOwned(profile, equipment.vehicle, modification.name, index)) continue;
statuses.set(modification.name, statusOf(profile, equipment.vehicle, modification, openTier, index));
statuses.set(modification.name, statusOf(profile, equipment.vehicle, modification, openTier, byName, index));
}
return { openTier, statuses };
}
@@ -80,16 +82,38 @@ function openTierOf(profile: BlkBlock, equipment: VehicleEquipment, index?: Prof
return tier;
}
function arePrerequisitesResearched(
profile: BlkBlock,
vehicle: string,
requires: readonly string[],
byName: ReadonlyMap<string, ModificationFacts>,
index?: ProfileEquipmentIndex,
): boolean {
return requires.every((required) => {
if (isOwned(profile, vehicle, required, index)) return true;
const mod = byName.get(required);
return mod !== undefined && isResearchable(mod) && isModuleResearched(profile, vehicle, mod, index);
});
}
function statusOf(
profile: BlkBlock,
vehicle: string,
modification: ModificationFacts,
openTier: number,
byName: ReadonlyMap<string, ModificationFacts>,
index?: ProfileEquipmentIndex,
): ModuleStatus {
if (isResearchable(modification)) {
if (modification.tier > openTier) return ModuleStatus.LOCKED;
return isModuleResearched(profile, vehicle, modification, index) ? ModuleStatus.CAN_BUY : ModuleStatus.CAN_RESEARCH;
if (isModuleResearched(profile, vehicle, modification, index)) {
return arePrerequisitesOwned(profile, vehicle, modification.requires, index)
? ModuleStatus.CAN_BUY
: ModuleStatus.RESEARCHED;
}
return arePrerequisitesResearched(profile, vehicle, modification.requires, byName, index)
? ModuleStatus.CAN_RESEARCH
: ModuleStatus.LOCKED;
}
return arePrerequisitesOwned(profile, vehicle, modification.requires, index) ? ModuleStatus.CAN_BUY : ModuleStatus.LOCKED;
}