Apply per-vehicle free repairs after local battles
This commit is contained in:
1 parent
8ee5ca66b2
commit
b63b45fabd
3 files changed
+33
-4
No files matched your search
@@ -17,6 +17,9 @@
|
|||||||
* - Several lives of one vehicle add up, at most the full cost (offline design).
|
* - Several lives of one vehicle add up, at most the full cost (offline design).
|
||||||
* - The cost becomes damage: hp = 1 - cost / full cost, so that the client's own repair cost
|
* - The cost becomes damage: hp = 1 - cost / full cost, so that the client's own repair cost
|
||||||
* (1 - hp) x full cost (repair/repair-rules.ts) is that cost.
|
* (1 - hp) x full cost (repair/repair-rules.ts) is that cost.
|
||||||
|
* - One available free repair covers the vehicle's new damage at settlement. Consuming it
|
||||||
|
* once per damaged vehicle per battle, regardless of the paid auto-repair setting, is inferred.
|
||||||
|
* Reserve vehicles have no repair cost, so they never need to spend an allowance.
|
||||||
* - "Automatically repair all vehicles after the battle" (autoRepairAircrafts, on by default,
|
* - "Automatically repair all vehicles after the battle" (autoRepairAircrafts, on by default,
|
||||||
* aces.exe 0x90b6a0) repairs the vehicles damaged in the battle when the Silver Lions suffice.
|
* aces.exe 0x90b6a0) repairs the vehicles damaged in the battle when the Silver Lions suffice.
|
||||||
* - Premium account insurance: with automatic repair and automatic ammunition purchase on, when
|
* - Premium account insurance: with automatic repair and automatic ammunition purchase on, when
|
||||||
@@ -27,6 +30,7 @@ import type { BlkBlock } from '@wto/blk';
|
|||||||
import type { RepairMode } from '../game-data/datasets/vehicle-repair.ts';
|
import type { RepairMode } from '../game-data/datasets/vehicle-repair.ts';
|
||||||
import { canAfford, pay } from '../profile/profile-currency.ts';
|
import { canAfford, pay } from '../profile/profile-currency.ts';
|
||||||
import { clearVehicleDamage, setVehicleDamage, vehicleCondition } from '../profile/profile-vehicle-condition.ts';
|
import { clearVehicleDamage, setVehicleDamage, vehicleCondition } from '../profile/profile-vehicle-condition.ts';
|
||||||
|
import { consumeFreeRepair } from '../profile/profile-vehicle-state.ts';
|
||||||
import type { ServerTime } from '../profile/server-time.ts';
|
import type { ServerTime } from '../profile/server-time.ts';
|
||||||
import { gameModeIndexOf, type RepairRules } from '../repair/repair-rules.ts';
|
import { gameModeIndexOf, type RepairRules } from '../repair/repair-rules.ts';
|
||||||
import type { BattleReport } from './battle-report.ts';
|
import type { BattleReport } from './battle-report.ts';
|
||||||
@@ -38,7 +42,7 @@ const BATTLE_END_TOLERANCE_SEC = 1;
|
|||||||
|
|
||||||
export interface VehicleDamage {
|
export interface VehicleDamage {
|
||||||
readonly vehicle: string;
|
readonly vehicle: string;
|
||||||
/** Condition after the battle, before any repair. */
|
/** Condition after the battle and any free repair, before a paid repair. */
|
||||||
readonly hp: number;
|
readonly hp: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +69,14 @@ export function damageBattleVehicles(
|
|||||||
const full = rules.fullCost(profile, vehicle, mode);
|
const full = rules.fullCost(profile, vehicle, mode);
|
||||||
const before = vehicleCondition(profile, vehicle)?.hp ?? 1;
|
const before = vehicleCondition(profile, vehicle)?.hp ?? 1;
|
||||||
const hp = full > 0 ? Math.max(0, before - Math.min(full, cost) / full) : before;
|
const hp = full > 0 ? Math.max(0, before - Math.min(full, cost) / full) : before;
|
||||||
if (hp < before) setVehicleDamage(profile, vehicle, hp, gameModeIndexOf(mode), now);
|
if (hp < before) {
|
||||||
|
if (consumeFreeRepair(profile, vehicle, rules.vehicle(vehicle)?.freeRepairs ?? 0)) {
|
||||||
|
clearVehicleDamage(profile, vehicle);
|
||||||
|
damages.push({ vehicle, hp: 1 });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
setVehicleDamage(profile, vehicle, hp, gameModeIndexOf(mode), now);
|
||||||
|
}
|
||||||
damages.push({ vehicle, hp });
|
damages.push({ vehicle, hp });
|
||||||
}
|
}
|
||||||
return damages;
|
return damages;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* repairCostPerMin<Mode>:i repair cost per minute of the vehicle's lifetime in a battle
|
* repairCostPerMin<Mode>:i repair cost per minute of the vehicle's lifetime in a battle
|
||||||
* repairTimeHrs<Mode>:r full repair time in hours with a crew
|
* repairTimeHrs<Mode>:r full repair time in hours with a crew
|
||||||
* repairTimeHrsNoCrew<Mode>:r full repair time in hours when no crew has the vehicle
|
* repairTimeHrsNoCrew<Mode>:r full repair time in hours when no crew has the vehicle
|
||||||
|
* freeRepairs:i free repair allowance (falls back to warpoints.blk, then 0)
|
||||||
* modifications{ <mod>{ repairCostCoef:r repairCostCoef<Mode>:r } } added to the cost factor
|
* modifications{ <mod>{ repairCostCoef:r repairCostCoef<Mode>:r } } added to the cost factor
|
||||||
* char.vromfs.bin config/warpoints.blk: rTimeNoCrewMul:r (no-crew time = repairTimeHrs x it when
|
* char.vromfs.bin config/warpoints.blk: rTimeNoCrewMul:r (no-crew time = repairTimeHrs x it when
|
||||||
* repairTimeHrsNoCrew<Mode> is missing).
|
* repairTimeHrsNoCrew<Mode> is missing).
|
||||||
@@ -30,6 +31,8 @@ export interface VehicleRepair {
|
|||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly cost: PerRepairMode;
|
readonly cost: PerRepairMode;
|
||||||
readonly costPerMin: PerRepairMode;
|
readonly costPerMin: PerRepairMode;
|
||||||
|
/** Allowance shown by scripts/unit/unit.nut and scripts/airinfo.nut. */
|
||||||
|
readonly freeRepairs: number;
|
||||||
/** Hours; 0 when the data has none. */
|
/** Hours; 0 when the data has none. */
|
||||||
readonly timeHours: PerRepairMode;
|
readonly timeHours: PerRepairMode;
|
||||||
/** Hours; -1 when the data has none (the client's default, 0x964e30). */
|
/** Hours; -1 when the data has none (the client's default, 0x964e30). */
|
||||||
@@ -61,8 +64,10 @@ const SPECIALIZATION_ADDS = 4;
|
|||||||
|
|
||||||
export const vehicleRepair: Dataset<VehicleRepairData> = {
|
export const vehicleRepair: Dataset<VehicleRepairData> = {
|
||||||
id: 'vehicle-repair',
|
id: 'vehicle-repair',
|
||||||
version: 2,
|
version: 3,
|
||||||
extract: (source) => {
|
extract: (source) => {
|
||||||
|
const warpoints = source.readBlk('char.vromfs.bin', 'config/warpoints.blk');
|
||||||
|
const defaultFreeRepairs = numberField(warpoints, 'freeRepairs') ?? 0;
|
||||||
const vehicles = source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.flatMap((vehicle): VehicleRepair[] => {
|
const vehicles = source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.flatMap((vehicle): VehicleRepair[] => {
|
||||||
const cost = perMode(vehicle, 'repairCost', 0);
|
const cost = perMode(vehicle, 'repairCost', 0);
|
||||||
if (REPAIR_MODES.every((mode) => cost[mode] <= 0)) return [];
|
if (REPAIR_MODES.every((mode) => cost[mode] <= 0)) return [];
|
||||||
@@ -76,12 +81,12 @@ export const vehicleRepair: Dataset<VehicleRepairData> = {
|
|||||||
name: vehicle.name,
|
name: vehicle.name,
|
||||||
cost,
|
cost,
|
||||||
costPerMin: perMode(vehicle, 'repairCostPerMin', 0),
|
costPerMin: perMode(vehicle, 'repairCostPerMin', 0),
|
||||||
|
freeRepairs: Math.max(0, Math.trunc(numberField(vehicle, 'freeRepairs') ?? defaultFreeRepairs)),
|
||||||
timeHours: perMode(vehicle, 'repairTimeHrs', 0),
|
timeHours: perMode(vehicle, 'repairTimeHrs', 0),
|
||||||
noCrewTimeHours: perMode(vehicle, 'repairTimeHrsNoCrew', -1),
|
noCrewTimeHours: perMode(vehicle, 'repairTimeHrsNoCrew', -1),
|
||||||
modCoefs,
|
modCoefs,
|
||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
const warpoints = source.readBlk('char.vromfs.bin', 'config/warpoints.blk');
|
|
||||||
return {
|
return {
|
||||||
vehicles,
|
vehicles,
|
||||||
noCrewTimeMul: numberField(warpoints, 'rTimeNoCrewMul') ?? 1,
|
noCrewTimeMul: numberField(warpoints, 'rTimeNoCrewMul') ?? 1,
|
||||||
|
|||||||
@@ -7,10 +7,13 @@
|
|||||||
* tierNumber:i the highest open modification tier (script is_tier_available)
|
* tierNumber:i the highest open modification tier (script is_tier_available)
|
||||||
* spareAircraftsCount:i spares the player has for this vehicle
|
* spareAircraftsCount:i spares the player has for this vehicle
|
||||||
* excessExp:i64 banked modification research points (+0x70)
|
* excessExp:i64 banked modification research points (+0x70)
|
||||||
|
* freeRepairs:i64 free repairs used (0x941cef; shop_get_free_repairs_used at 0x17a4b80)
|
||||||
*/
|
*/
|
||||||
import { findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
import { findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||||
|
import { intField } from './blk-fields.ts';
|
||||||
|
|
||||||
const HANGAR = 'hangar';
|
const HANGAR = 'hangar';
|
||||||
|
const FREE_REPAIRS = 'freeRepairs';
|
||||||
const RESEARCH_TARGET = 'investMode';
|
const RESEARCH_TARGET = 'investMode';
|
||||||
const FINISHED_TARGET = 'investModePrev';
|
const FINISHED_TARGET = 'investModePrev';
|
||||||
const OPEN_TIER = 'tierNumber';
|
const OPEN_TIER = 'tierNumber';
|
||||||
@@ -52,6 +55,16 @@ export function setSpareCount(profile: BlkBlock, vehicle: string, count: number)
|
|||||||
if (entry) setParam(entry, SPARES, { type: 'int', value: count });
|
if (entry) setParam(entry, SPARES, { type: 'int', value: count });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Uses one free repair on an owned vehicle if it still has an allowance. */
|
||||||
|
export function consumeFreeRepair(profile: BlkBlock, vehicle: string, allowance: number): boolean {
|
||||||
|
const entry = vehicleEntry(profile, vehicle);
|
||||||
|
if (!entry) return false;
|
||||||
|
const used = Math.max(0, intField(entry, FREE_REPAIRS));
|
||||||
|
if (used >= allowance) return false;
|
||||||
|
setParam(entry, FREE_REPAIRS, { type: 'int64', value: BigInt(used + 1) });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function vehicleExcessRp(profile: BlkBlock, vehicle: string): number {
|
export function vehicleExcessRp(profile: BlkBlock, vehicle: string): number {
|
||||||
const value = fieldOf(profile, vehicle, EXCESS_EXP);
|
const value = fieldOf(profile, vehicle, EXCESS_EXP);
|
||||||
if (value?.type === 'int64') return Math.max(0, Number(value.value));
|
if (value?.type === 'int64') return Math.max(0, Number(value.value));
|
||||||
|
|||||||
Reference in new issue
Block a user