fix: split bullet tax credit update into standalone call (v1.4.4)

Foundry v14 rejects actor.update() silently when one field in the payload
has a schema conflict. The combined update (credits + finances nested paths)
was being dropped entirely, so credits never changed.

Fix: two separate actor.update() calls
1. Credit deduction: update("system.details.credits") alone — critical
2. Finances tracking: update(finances paths) — non-critical, caught silently

Added console.log so GMs can confirm credit deductions in browser console:
  Zero Engine | Bullet Tax: Joe credits 500c -> 440c (-60c)
This commit is contained in:
2026-06-02 22:40:17 +01:00
parent 86df96132e
commit 7de21e290d
2 changed files with 21 additions and 9 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"id": "zero-engine",
"title": "Zero Engine (SLA Industries)",
"description": "A basic game system for SLA Industries using the Zero Engine rules.",
"version": "1.4.3",
"version": "1.4.4",
"compatibility": {
"minimum": 13,
"verified": "14.359"
+20 -8
View File
@@ -5999,6 +5999,7 @@ function _getAmmoModifiers(weaponData) {
* Deduct bullet tax from actor credits and update session ammo log.
* Bullet tax = 2× the base round cost (ammo purchase price + field levy).
* Called immediately when a weapon fires.
* Two separate update() calls so a finances schema issue never blocks the credit deduction.
*/
async function _applyBulletTax(actor, weaponData, roundsFired) {
if (!actor || roundsFired <= 0) return 0;
@@ -6010,15 +6011,26 @@ async function _applyBulletTax(actor, weaponData, roundsFired) {
const currentCredits = Number(actor.system?.details?.credits ?? 0);
const newCredits = Math.max(0, currentCredits - totalCost);
// Deduct from credits; track session bullet tax
const sessionSpent = Number(actor.system?.finances?.ammoSpentSession ?? 0) + totalCost;
const bulletTaxTotal = Number(actor.system?.finances?.expenses?.bulletTax ?? 0) + totalCost;
// ── Credit deduction — critical, standalone update ──────────────────────
try {
await actor.update({ "system.details.credits": newCredits });
console.log(`Zero Engine | Bullet Tax: ${actor.name} credits ${currentCredits}¢ → ${newCredits}¢ (−${totalCost}¢)`);
} catch (err) {
console.error("Zero Engine | Bullet Tax credit deduction failed:", err);
return 0;
}
await actor.update({
"system.details.credits": newCredits,
"system.finances.ammoSpentSession": sessionSpent,
"system.finances.expenses.bulletTax": bulletTaxTotal
});
// ── Finances tracking — non-critical, separate update ───────────────────
try {
const sessionSpent = Number(actor.system?.finances?.ammoSpentSession ?? 0) + totalCost;
const bulletTaxRun = Number(actor.system?.finances?.expenses?.bulletTax ?? 0) + totalCost;
await actor.update({
"system.finances.ammoSpentSession": sessionSpent,
"system.finances.expenses.bulletTax": bulletTaxRun
});
} catch (_) {
// Finances tracking is optional — ignore failures silently
}
return totalCost;
}