feat(equipment): persist custom weapon presets and correct decal research
Save revisions to custom weapon presets and return the full profile. Keep an empty top-level weaponPresets block after the final deletion so the client clears its cached presets. Treat the tier-zero allowPremDecals modification as researchable. Type checking passed. In-game acceptance is pending.
This commit is contained in:
1 parent
71ba962e75
commit
f829c9a45f
6 files changed
+168
-6
No files matched your search
@@ -54,7 +54,14 @@ import {
|
|||||||
recycleItemsAction,
|
recycleItemsAction,
|
||||||
} from './inventory-actions.ts';
|
} from './inventory-actions.ts';
|
||||||
import { activateBoosterAction, activateDiscountAction, applySpareItemAction, buyItemAction, startWagerAction } from './item-actions.ts';
|
import { activateBoosterAction, activateDiscountAction, applySpareItemAction, buyItemAction, startWagerAction } from './item-actions.ts';
|
||||||
import { buyAllModificationsAction, buyModificationAction, buySparesAction, buyWeaponsAction, enableModificationsAction } from './modification-actions.ts';
|
import {
|
||||||
|
buyAllModificationsAction,
|
||||||
|
buyModificationAction,
|
||||||
|
buySparesAction,
|
||||||
|
buyWeaponsAction,
|
||||||
|
enableModificationsAction,
|
||||||
|
saveWeaponPresetsAction,
|
||||||
|
} from './modification-actions.ts';
|
||||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||||
import { savePilotAppearanceAction, saveShowcaseAction, selectTitleAction, showcasesAction, usersTerseInfoAction } from './player-card-actions.ts';
|
import { savePilotAppearanceAction, saveShowcaseAction, selectTitleAction, showcasesAction, usersTerseInfoAction } from './player-card-actions.ts';
|
||||||
import { priceEx } from './price-actions.ts';
|
import { priceEx } from './price-actions.ts';
|
||||||
@@ -119,6 +126,7 @@ function coreActionEntries(deps: ActionDependencies): Array<[string, CharActionH
|
|||||||
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.equipment)],
|
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.unlocks)],
|
['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.unlocks)],
|
||||||
['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.equipment)],
|
['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
|
['cln_save_weapon_presets', saveWeaponPresetsAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts, deps.equipment)],
|
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_upgrade_crew', upgradeCrewAction(deps.profiles, deps.accounts, deps.crew)],
|
['cln_upgrade_crew', upgradeCrewAction(deps.profiles, deps.accounts, deps.crew)],
|
||||||
['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.crew)],
|
['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.crew)],
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import type { AccountStore } from '../../accounts/account-store.ts';
|
|||||||
import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts';
|
import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts';
|
||||||
import { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts';
|
import { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts';
|
||||||
import { buySpares } from '../../modifications/spare-purchase.ts';
|
import { buySpares } from '../../modifications/spare-purchase.ts';
|
||||||
|
import { saveWeaponPresets } from '../../modifications/weapon-presets.ts';
|
||||||
import { buyWeapons } from '../../modifications/weapon-purchase.ts';
|
import { buyWeapons } from '../../modifications/weapon-purchase.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
@@ -76,6 +77,10 @@ export function enableModificationsAction(profiles: PlayerProfiles, accounts: Ac
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function saveWeaponPresetsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler {
|
||||||
|
return ruleAction(profiles, accounts, (payload) => (profile) => saveWeaponPresets(profile, equipment, payload));
|
||||||
|
}
|
||||||
|
|
||||||
function offeredPrice(payload: BlkBlock) {
|
function offeredPrice(payload: BlkBlock) {
|
||||||
return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
||||||
}
|
}
|
||||||
@@ -38,17 +38,18 @@ export function isFreeWeapon(weapon: WeaponFacts): boolean {
|
|||||||
return weapon.silverLions === 0 && weapon.goldenEagles === 0;
|
return weapon.silverLions === 0 && weapon.goldenEagles === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Has to be researched before it can be bought (tier 1 and up, with research points). */
|
/** Has to be researched before it can be bought (`reqExp > 0`, including tier-0 `allowPremDecals`). */
|
||||||
export function isResearchable(modification: ModificationFacts): boolean {
|
export function isResearchable(modification: ModificationFacts): boolean {
|
||||||
return modification.tier >= 1 && modification.researchPoints > 0;
|
return modification.researchPoints > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts towards opening the next tier: the client's isModificationInTree (scripts
|
* Counts towards opening the next tier: the client's isModificationInTree (scripts
|
||||||
* weaponry/modsTree.nut) leaves out hidden, golden-eagle and ammunition modifications.
|
* weaponry/modsTree.nut) leaves out tier-0 (`allowPremDecals`), hidden, golden-eagle and
|
||||||
|
* ammunition modifications.
|
||||||
*/
|
*/
|
||||||
export function countsForTier(modification: ModificationFacts): boolean {
|
export function countsForTier(modification: ModificationFacts): boolean {
|
||||||
return isResearchable(modification) && modification.goldenEagles === 0 && !modification.ammunition;
|
return modification.tier >= 1 && isResearchable(modification) && modification.goldenEagles === 0 && !modification.ammunition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ function regularPurchase(profile: BlkBlock, vehicle: string, modification: Modif
|
|||||||
}
|
}
|
||||||
|
|
||||||
function outrightPurchase(profile: BlkBlock, vehicle: string, modification: ModificationFacts, catalogue: EquipmentCatalogue): Purchase | undefined {
|
function outrightPurchase(profile: BlkBlock, vehicle: string, modification: ModificationFacts, catalogue: EquipmentCatalogue): Purchase | undefined {
|
||||||
if (!isResearchable(modification)) return undefined;
|
if (!isResearchable(modification) || modification.openGoldenEagles <= 0) return undefined;
|
||||||
const status = currentModuleStatus(profile, catalogue, vehicle, modification.name);
|
const status = currentModuleStatus(profile, catalogue, vehicle, modification.name);
|
||||||
if (status !== ModuleStatus.CAN_RESEARCH && status !== ModuleStatus.CAN_BUY) return undefined;
|
if (status !== ModuleStatus.CAN_RESEARCH && status !== ModuleStatus.CAN_BUY) return undefined;
|
||||||
return { price: { silverLions: 0, goldenEagles: outrightPrice(profile, vehicle, modification) }, amount: 1 };
|
return { price: { silverLions: 0, goldenEagles: outrightPrice(profile, vehicle, modification) }, amount: 1 };
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/**
|
||||||
|
* Saving, renaming and deleting custom secondary weapon presets (`cln_save_weapon_presets`,
|
||||||
|
* scripts/unit/unitWeaponryCustomPresets.nut `savePresetInProfile`; implementation notes).
|
||||||
|
*
|
||||||
|
* Sent via `charSendBlk` (job type 13 -> full profile update). Request payload:
|
||||||
|
* <vehicle>{ <presetId>{ name:t="..." Weapon{ preset:t="..." slot:i=... } ... } }
|
||||||
|
* - Add / copy / edit / rename: `<presetId>` (`custom0`, `custom1`, ...) carries `name:t` and
|
||||||
|
* zero or more `Weapon{ preset:t, slot:i }` (or infantry `soldier{ index:i, weapon{...} }`)
|
||||||
|
* blocks -> upserts that single preset under `weaponPresets/<vehicle>`.
|
||||||
|
* - Delete (`deleteCustomPreset`): `<presetId>{}` is an empty block -> removes that preset.
|
||||||
|
*/
|
||||||
|
import { findParam, type BlkBlock } from '@wto/blk';
|
||||||
|
import { ownsVehicle } from '../profile/profile-hangar.ts';
|
||||||
|
import {
|
||||||
|
clearVehicleWeaponPresets,
|
||||||
|
deleteVehicleWeaponPreset,
|
||||||
|
upsertVehicleWeaponPreset,
|
||||||
|
vehicleWeaponPresets,
|
||||||
|
} from '../profile/profile-weapon-presets.ts';
|
||||||
|
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||||
|
import type { EquipmentCatalogue } from './equipment-catalogue.ts';
|
||||||
|
|
||||||
|
/** Client limit (`scripts/weaponry/weaponryPresets.nut` line 7 `MAX_PRESETS_NUM = 20`). */
|
||||||
|
export const MAX_CUSTOM_PRESETS = 20;
|
||||||
|
|
||||||
|
const CUSTOM_PRESET_ID = /^custom\d+$/;
|
||||||
|
|
||||||
|
export function saveWeaponPresets(profile: BlkBlock, catalogue: EquipmentCatalogue, request: BlkBlock): RuleOutcome {
|
||||||
|
if (request.params.length > 0 || request.blocks.length === 0) return refused('BAD_PARAMS');
|
||||||
|
for (const vehicleBlock of request.blocks) {
|
||||||
|
const check = validateVehiclePresets(profile, catalogue, vehicleBlock);
|
||||||
|
if (!check.ok) return check;
|
||||||
|
}
|
||||||
|
for (const vehicleBlock of request.blocks) applyVehiclePresets(profile, vehicleBlock);
|
||||||
|
return ACCEPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateVehiclePresets(profile: BlkBlock, catalogue: EquipmentCatalogue, vehicleBlock: BlkBlock): RuleOutcome {
|
||||||
|
if (!vehicleBlock.name || vehicleBlock.params.length > 0 || !catalogue.vehicle(vehicleBlock.name)) {
|
||||||
|
return refused('BAD_PARAMS');
|
||||||
|
}
|
||||||
|
if (!ownsVehicle(profile, vehicleBlock.name) || !catalogue.weapon(vehicleBlock.name, 'custom_presets')) {
|
||||||
|
return refused('NOT_AVAILABLE');
|
||||||
|
}
|
||||||
|
const projected = new Set(vehicleWeaponPresets(profile, vehicleBlock.name).map((preset) => preset.name));
|
||||||
|
if (vehicleBlock.blocks.length === 0) return ACCEPTED;
|
||||||
|
for (const presetBlock of vehicleBlock.blocks) {
|
||||||
|
if (!CUSTOM_PRESET_ID.test(presetBlock.name)) return refused('BAD_PARAMS');
|
||||||
|
if (isEmptyBlock(presetBlock)) {
|
||||||
|
projected.delete(presetBlock.name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isValidPresetPayload(presetBlock)) return refused('BAD_PARAMS');
|
||||||
|
projected.add(presetBlock.name);
|
||||||
|
}
|
||||||
|
return projected.size <= MAX_CUSTOM_PRESETS ? ACCEPTED : refused('NOT_AVAILABLE');
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyVehiclePresets(profile: BlkBlock, vehicleBlock: BlkBlock): void {
|
||||||
|
if (vehicleBlock.blocks.length === 0) {
|
||||||
|
clearVehicleWeaponPresets(profile, vehicleBlock.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const presetBlock of vehicleBlock.blocks) {
|
||||||
|
if (isEmptyBlock(presetBlock)) deleteVehicleWeaponPreset(profile, vehicleBlock.name, presetBlock.name);
|
||||||
|
else upsertVehicleWeaponPreset(profile, vehicleBlock.name, presetBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEmptyBlock(block: BlkBlock): boolean {
|
||||||
|
return block.params.length === 0 && block.blocks.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidPresetPayload(preset: BlkBlock): boolean {
|
||||||
|
if (preset.params.length !== 1 || findParam(preset, 'name')?.value.type !== 'string') return false;
|
||||||
|
return preset.blocks.every((sub) => isValidWeaponSlot(sub) || isValidInfantrySoldier(sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidWeaponSlot(block: BlkBlock): boolean {
|
||||||
|
return block.name === 'Weapon'
|
||||||
|
&& block.blocks.length === 0
|
||||||
|
&& block.params.length === 2
|
||||||
|
&& findParam(block, 'preset')?.value.type === 'string'
|
||||||
|
&& findParam(block, 'slot')?.value.type === 'int';
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidInfantrySoldier(block: BlkBlock): boolean {
|
||||||
|
if (block.name !== 'soldier' || block.params.length !== 1 || findParam(block, 'index')?.value.type !== 'int') return false;
|
||||||
|
return block.blocks.every((weapon) =>
|
||||||
|
weapon.name === 'weapon'
|
||||||
|
&& weapon.blocks.length === 0
|
||||||
|
&& weapon.params.length === 2
|
||||||
|
&& findParam(weapon, 'slot')?.value.type === 'int'
|
||||||
|
&& findParam(weapon, 'preset')?.value.type === 'string');
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* Custom weapon presets in the profile:
|
||||||
|
*
|
||||||
|
* weaponPresets{
|
||||||
|
* fa_18d_late{
|
||||||
|
* custom0{
|
||||||
|
* name:t="编组方案 #1"
|
||||||
|
* Weapon{ preset:t="aim_120_default_slot4" slot:i=4 }
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* `EconomicState::serialize` (aces.exe 0x937a50 at 0x93e62e) delegates top-level `weaponPresets`
|
||||||
|
* to 0x9675e0 (`GameSaveData + 0x1a0`), which calls `DataBlock::setFrom` (0x30934e0) in client
|
||||||
|
* read mode (0x8) ONLY when a `weaponPresets` sub-block is present in `profile.blk`; if the
|
||||||
|
* sub-block is absent, 0x9675e0 returns without clearing `GameSaveData + 0x1a0`. Keeping the
|
||||||
|
* top-level `weaponPresets{}` block present even after the last preset is deleted ensures the
|
||||||
|
* client clears its in-memory custom preset table on profile update.
|
||||||
|
*/
|
||||||
|
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
|
||||||
|
|
||||||
|
const WEAPON_PRESETS = 'weaponPresets';
|
||||||
|
|
||||||
|
export function vehicleWeaponPresets(profile: BlkBlock, vehicle: string): readonly BlkBlock[] {
|
||||||
|
const root = findBlock(profile, WEAPON_PRESETS);
|
||||||
|
const unitBlock = root && findBlock(root, vehicle);
|
||||||
|
return unitBlock?.blocks ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function upsertVehicleWeaponPreset(profile: BlkBlock, vehicle: string, preset: BlkBlock): void {
|
||||||
|
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||||
|
const unitBlock = ensureBlock(root, vehicle);
|
||||||
|
const copy = structuredClone(preset);
|
||||||
|
const existingIndex = unitBlock.blocks.findIndex((entry) => entry.name === preset.name);
|
||||||
|
if (existingIndex >= 0) unitBlock.blocks[existingIndex] = copy;
|
||||||
|
else unitBlock.blocks.push(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteVehicleWeaponPreset(profile: BlkBlock, vehicle: string, presetName: string): void {
|
||||||
|
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||||
|
const unitBlock = findBlock(root, vehicle);
|
||||||
|
if (!unitBlock) return;
|
||||||
|
unitBlock.blocks = unitBlock.blocks.filter((entry) => entry.name !== presetName);
|
||||||
|
if (unitBlock.blocks.length === 0 && unitBlock.params.length === 0) {
|
||||||
|
root.blocks = root.blocks.filter((entry) => entry !== unitBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearVehicleWeaponPresets(profile: BlkBlock, vehicle: string): void {
|
||||||
|
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||||
|
root.blocks = root.blocks.filter((entry) => entry.name !== vehicle);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user