Add bounty pay-off and daily decay; fix restart countdown toast.
Players can clear their own bounty at the office (10 coins → 1), bounty falls by 1 per calendar day, and the deploy update timer uses remaining ms instead of a raw timestamp.
@@ -526,6 +526,14 @@
526
526
<section class="bounty-pane" data-pane="mine" hidden>
527
527
<p class="hint">Coin currently on your head:</p>
528
528
<p id="bounty-my-amount" class="bounty-my-amount">None</p>
529
<p id="bounty-decay-hint" class="hint">Your bounty drops by 1 coin each day at midnight.</p>
530
<div id="bounty-payoff" class="bounty-payoff" hidden>
531
<p class="hint" id="bounty-payoff-rate">Every 10 coins paid clears 1 coin of bounty.</p>
532
<label class="bounty-amount-label">Coins to pay
533
<input id="bounty-pay-amount" type="number" min="10" step="10" value="100">
534
</label>
535
<button id="bounty-pay" type="button">Pay toward bounty</button>
536
</div>
529
537
</section>
530
538
</aside>
531
539
@@ -526,6 +526,14 @@526
<section class="bounty-pane" data-pane="mine" hidden>526
<section class="bounty-pane" data-pane="mine" hidden>527
<p class="hint">Coin currently on your head:</p>527
<p class="hint">Coin currently on your head:</p>528
<p id="bounty-my-amount" class="bounty-my-amount">None</p>528
<p id="bounty-my-amount" class="bounty-my-amount">None</p>529
<p id="bounty-decay-hint" class="hint">Your bounty drops by 1 coin each day at midnight.</p>530
<div id="bounty-payoff" class="bounty-payoff" hidden>531
<p class="hint" id="bounty-payoff-rate">Every 10 coins paid clears 1 coin of bounty.</p>532
<label class="bounty-amount-label">Coins to pay533
<input id="bounty-pay-amount" type="number" min="10" step="10" value="100">534
</label>535
<button id="bounty-pay" type="button">Pay toward bounty</button>536
</div>529
</section>537
</section>530
</aside>538
</aside>531
539
@@ -1,4 +1,6 @@
1
1
import { mountLayerPreview } from "./characterPreview.js";
2
import { formatRestartCountdown } from "/shared/deploy/schedule.js";
3
import { BOUNTY_PAYOFF_COINS_PER_POINT } from "/shared/bounty/pricing.js";
2
4
3
5
export function initBounty ({
4
6
socket,
@@ -12,6 +14,10 @@ export function initBounty ({
12
14
const panel = document.getElementById("bounty-panel");
13
15
const statusEl = document.getElementById("bounty-status");
14
16
const myAmountEl = document.getElementById("bounty-my-amount");
17
const payoffBox = document.getElementById("bounty-payoff");
18
const payoffRateEl = document.getElementById("bounty-payoff-rate");
19
const payAmountInput = document.getElementById("bounty-pay-amount");
20
const decayHintEl = document.getElementById("bounty-decay-hint");
15
21
const previewEl = document.getElementById("bounty-preview");
16
22
const targetLabel = document.getElementById("bounty-target-label");
17
23
const targetAmount = document.getElementById("bounty-target-amount");
@@ -25,6 +31,10 @@ export function initBounty ({
25
31
/** @type {null | { characterId: number, firstName: string, lastName: string, amountCopper: number }} */
26
32
let target = null;
27
33
let activeTab = "place";
34
let myAmountCopper = 0;
35
let payoffCoinsPerPoint = BOUNTY_PAYOFF_COINS_PER_POINT;
36
let nextDecayAt = null;
37
let decayTick = null;
28
38
29
39
function suppressWorldClick ()
30
40
{
@@ -40,6 +50,56 @@ export function initBounty ({
40
50
{ pane.hidden = pane.dataset.pane !== tab; }
41
51
}
42
52
53
function syncPayoffUi ()
54
{
55
const rate = Math.max(1, payoffCoinsPerPoint | 0);
56
if (payoffRateEl)
57
{
58
payoffRateEl.textContent = `Every ${rate} coins paid clears 1 coin of bounty.`;
59
}
60
if (payAmountInput)
61
{
62
payAmountInput.min = String(rate);
63
payAmountInput.step = String(rate);
64
}
65
if (payoffBox)
66
{ payoffBox.hidden = !(myAmountCopper > 0); }
67
syncDecayHint();
68
}
69
70
function syncDecayHint ()
71
{
72
if (!decayHintEl)
73
{ return; }
74
if (!(myAmountCopper > 0) || !nextDecayAt)
75
{
76
decayHintEl.textContent = "Your bounty drops by 1 coin each day at midnight.";
77
return;
78
}
79
const remaining = Math.max(0, nextDecayAt - Date.now());
80
decayHintEl.textContent = remaining > 0
81
? `Drops by 1 coin in ${formatRestartCountdown(remaining)} (daily at midnight).`
82
: "Drops by 1 coin at midnight.";
83
}
84
85
function startDecayTick ()
86
{
87
stopDecayTick();
88
syncDecayHint();
89
if (!(myAmountCopper > 0) || !nextDecayAt)
90
{ return; }
91
decayTick = window.setInterval(syncDecayHint, 1000);
92
}
93
94
function stopDecayTick ()
95
{
96
if (decayTick != null)
97
{
98
clearInterval(decayTick);
99
decayTick = null;
100
}
101
}
102
43
103
for (const button of tabs)
44
104
{ button.addEventListener("click", () => setTab(button.dataset.tab)); }
45
105
@@ -91,6 +151,23 @@ export function initBounty ({
91
151
});
92
152
});
93
153
154
document.getElementById("bounty-pay")?.addEventListener("click", () =>
155
{
156
if (!(myAmountCopper > 0))
157
{
158
statusEl.textContent = "There is no bounty on your head.";
159
return;
160
}
161
const amountCopper = Math.floor(Number(payAmountInput?.value) || 0);
162
if (amountCopper <= 0)
163
{
164
statusEl.textContent = "Enter a positive coin amount.";
165
return;
166
}
167
statusEl.textContent = "Paying bounty…";
168
socket.send({ type: MessageType.payBounty, amountCopper });
169
});
170
94
171
function clearTarget ()
95
172
{
96
173
target = null;
@@ -141,6 +218,7 @@ export function initBounty ({
141
218
backdrop.hidden = true;
142
219
clearTarget();
143
220
statusEl.textContent = "";
221
stopDecayTick();
144
222
socket.send({ type: MessageType.closeBounty });
145
223
}
146
224
@@ -154,10 +232,17 @@ export function initBounty ({
154
232
panel.hidden = false;
155
233
backdrop.hidden = false;
156
234
setTab(activeTab);
157
myAmountEl.textContent = (message.myAmountCopper | 0) > 0
158
? message.myAmountLabel || String(message.myAmountCopper)
235
myAmountCopper = message.myAmountCopper | 0;
236
payoffCoinsPerPoint = message.payoffCoinsPerPoint | 0 || BOUNTY_PAYOFF_COINS_PER_POINT;
237
nextDecayAt = Number(message.nextDecayAt) || null;
238
myAmountEl.textContent = myAmountCopper > 0
239
? message.myAmountLabel || String(myAmountCopper)
159
240
: "None";
160
if (message.raised)
241
syncPayoffUi();
242
startDecayTick();
243
if (message.paidOff)
244
{ statusEl.textContent = message.paidOff.message ?? "Bounty updated."; }
245
else if (message.raised)
161
246
{
162
247
statusEl.textContent = message.raised.message ?? "Bounty updated.";
163
248
if (target && target.characterId === message.raised.characterId)
@@ -180,6 +265,7 @@ export function initBounty ({
180
265
open = false;
181
266
panel.hidden = true;
182
267
backdrop.hidden = true;
268
stopDecayTick();
183
269
}
184
270
};
185
271
}
@@ -1,4 +1,6 @@1
import { mountLayerPreview } from "./characterPreview.js";1
import { mountLayerPreview } from "./characterPreview.js";2
import { formatRestartCountdown } from "/shared/deploy/schedule.js";3
import { BOUNTY_PAYOFF_COINS_PER_POINT } from "/shared/bounty/pricing.js";2
4
3
export function initBounty ({5
export function initBounty ({4
socket,6
socket,@@ -12,6 +14,10 @@ export function initBounty ({12
const panel = document.getElementById("bounty-panel");14
const panel = document.getElementById("bounty-panel");13
const statusEl = document.getElementById("bounty-status");15
const statusEl = document.getElementById("bounty-status");14
const myAmountEl = document.getElementById("bounty-my-amount");16
const myAmountEl = document.getElementById("bounty-my-amount");17
const payoffBox = document.getElementById("bounty-payoff");18
const payoffRateEl = document.getElementById("bounty-payoff-rate");19
const payAmountInput = document.getElementById("bounty-pay-amount");20
const decayHintEl = document.getElementById("bounty-decay-hint");15
const previewEl = document.getElementById("bounty-preview");21
const previewEl = document.getElementById("bounty-preview");16
const targetLabel = document.getElementById("bounty-target-label");22
const targetLabel = document.getElementById("bounty-target-label");17
const targetAmount = document.getElementById("bounty-target-amount");23
const targetAmount = document.getElementById("bounty-target-amount");@@ -25,6 +31,10 @@ export function initBounty ({25
/** @type {null | { characterId: number, firstName: string, lastName: string, amountCopper: number }} */31
/** @type {null | { characterId: number, firstName: string, lastName: string, amountCopper: number }} */26
let target = null;32
let target = null;27
let activeTab = "place";33
let activeTab = "place";34
let myAmountCopper = 0;35
let payoffCoinsPerPoint = BOUNTY_PAYOFF_COINS_PER_POINT;36
let nextDecayAt = null;37
let decayTick = null;28
38
29
function suppressWorldClick ()39
function suppressWorldClick ()30
{40
{@@ -40,6 +50,56 @@ export function initBounty ({40
{ pane.hidden = pane.dataset.pane !== tab; }50
{ pane.hidden = pane.dataset.pane !== tab; }41
}51
}42
52
53
function syncPayoffUi ()54
{55
const rate = Math.max(1, payoffCoinsPerPoint | 0);56
if (payoffRateEl)57
{58
payoffRateEl.textContent = `Every ${rate} coins paid clears 1 coin of bounty.`;59
}60
if (payAmountInput)61
{62
payAmountInput.min = String(rate);63
payAmountInput.step = String(rate);64
}65
if (payoffBox)66
{ payoffBox.hidden = !(myAmountCopper > 0); }67
syncDecayHint();68
}69
70
function syncDecayHint ()71
{72
if (!decayHintEl)73
{ return; }74
if (!(myAmountCopper > 0) || !nextDecayAt)75
{76
decayHintEl.textContent = "Your bounty drops by 1 coin each day at midnight.";77
return;78
}79
const remaining = Math.max(0, nextDecayAt - Date.now());80
decayHintEl.textContent = remaining > 081
? `Drops by 1 coin in ${formatRestartCountdown(remaining)} (daily at midnight).`82
: "Drops by 1 coin at midnight.";83
}84
85
function startDecayTick ()86
{87
stopDecayTick();88
syncDecayHint();89
if (!(myAmountCopper > 0) || !nextDecayAt)90
{ return; }91
decayTick = window.setInterval(syncDecayHint, 1000);92
}93
94
function stopDecayTick ()95
{96
if (decayTick != null)97
{98
clearInterval(decayTick);99
decayTick = null;100
}101
}102
43
for (const button of tabs)103
for (const button of tabs)44
{ button.addEventListener("click", () => setTab(button.dataset.tab)); }104
{ button.addEventListener("click", () => setTab(button.dataset.tab)); }45
105
@@ -91,6 +151,23 @@ export function initBounty ({91
});151
});92
});152
});93
153
154
document.getElementById("bounty-pay")?.addEventListener("click", () =>155
{156
if (!(myAmountCopper > 0))157
{158
statusEl.textContent = "There is no bounty on your head.";159
return;160
}161
const amountCopper = Math.floor(Number(payAmountInput?.value) || 0);162
if (amountCopper <= 0)163
{164
statusEl.textContent = "Enter a positive coin amount.";165
return;166
}167
statusEl.textContent = "Paying bounty…";168
socket.send({ type: MessageType.payBounty, amountCopper });169
});170
94
function clearTarget ()171
function clearTarget ()95
{172
{96
target = null;173
target = null;@@ -141,6 +218,7 @@ export function initBounty ({141
backdrop.hidden = true;218
backdrop.hidden = true;142
clearTarget();219
clearTarget();143
statusEl.textContent = "";220
statusEl.textContent = "";221
stopDecayTick();144
socket.send({ type: MessageType.closeBounty });222
socket.send({ type: MessageType.closeBounty });145
}223
}146
224
@@ -154,10 +232,17 @@ export function initBounty ({154
panel.hidden = false;232
panel.hidden = false;155
backdrop.hidden = false;233
backdrop.hidden = false;156
setTab(activeTab);234
setTab(activeTab);157
myAmountEl.textContent = (message.myAmountCopper | 0) > 0235
myAmountCopper = message.myAmountCopper | 0;158
? message.myAmountLabel || String(message.myAmountCopper)236
payoffCoinsPerPoint = message.payoffCoinsPerPoint | 0 || BOUNTY_PAYOFF_COINS_PER_POINT;237
nextDecayAt = Number(message.nextDecayAt) || null;238
myAmountEl.textContent = myAmountCopper > 0239
? message.myAmountLabel || String(myAmountCopper)159
: "None";240
: "None";160
if (message.raised)241
syncPayoffUi();242
startDecayTick();243
if (message.paidOff)244
{ statusEl.textContent = message.paidOff.message ?? "Bounty updated."; }245
else if (message.raised)161
{246
{162
statusEl.textContent = message.raised.message ?? "Bounty updated.";247
statusEl.textContent = message.raised.message ?? "Bounty updated.";163
if (target && target.characterId === message.raised.characterId)248
if (target && target.characterId === message.raised.characterId)@@ -180,6 +265,7 @@ export function initBounty ({180
open = false;265
open = false;181
panel.hidden = true;266
panel.hidden = true;182
backdrop.hidden = true;267
backdrop.hidden = true;268
stopDecayTick();183
}269
}184
};270
};185
}271
}@@ -162,7 +162,10 @@ export function initToasts ({ onSuppressWorldClick } = {})
162
162
restartScheduledAt = scheduledAt;
163
163
const tick = () =>
164
164
{
165
showPersistent(PERSISTENT_RESTART_ID, restartCountdownMessage(restartScheduledAt, Date.now()));
165
showPersistent(
166
PERSISTENT_RESTART_ID,
167
restartCountdownMessage(Math.max(0, restartScheduledAt - Date.now()))
168
);
166
169
};
167
170
tick();
168
171
if (restartTick == null)
@@ -162,7 +162,10 @@ export function initToasts ({ onSuppressWorldClick } = {})162
restartScheduledAt = scheduledAt;162
restartScheduledAt = scheduledAt;163
const tick = () =>163
const tick = () =>164
{164
{165
showPersistent(PERSISTENT_RESTART_ID, restartCountdownMessage(restartScheduledAt, Date.now()));165
showPersistent(166
PERSISTENT_RESTART_ID,167
restartCountdownMessage(Math.max(0, restartScheduledAt - Date.now()))168
);166
};169
};167
tick();170
tick();168
if (restartTick == null)171
if (restartTick == null)@@ -2694,6 +2694,15 @@ button.friend-account-name:hover {
2694
2694
margin: 0.5rem 0 0;
2695
2695
}
2696
2696
2697
.bounty-payoff {
2698
display: flex;
2699
flex-direction: column;
2700
gap: 0.5rem;
2701
margin-top: 0.85rem;
2702
padding-top: 0.75rem;
2703
border-top: 1px solid #2c3340;
2704
}
2705
2697
2706
.toast.toast-clickable:hover {
2698
2707
border-color: #7a889c;
2699
2708
background: rgba(22, 26, 34, 0.96);
@@ -2694,6 +2694,15 @@ button.friend-account-name:hover {2694
margin: 0.5rem 0 0;2694
margin: 0.5rem 0 0;2695
}2695
}2696
2696
2697
.bounty-payoff {2698
display: flex;2699
flex-direction: column;2700
gap: 0.5rem;2701
margin-top: 0.85rem;2702
padding-top: 0.75rem;2703
border-top: 1px solid #2c3340;2704
}2705
2697
.toast.toast-clickable:hover {2706
.toast.toast-clickable:hover {2698
border-color: #7a889c;2707
border-color: #7a889c;2699
background: rgba(22, 26, 34, 0.96);2708
background: rgba(22, 26, 34, 0.96);@@ -347,8 +347,8 @@ Use later when deciding which ingredients fit which potions. Tiers: **2 / 3 / 3
347
347
**Status:** full
348
348
**Spec:** Placeable **Bounty Office** blocks. Interacting opens a modal with two tabs:
349
349
350
1. **Place / raise bounty** — Search a character by first + last name. If found, show a small character preview and the **current bounty** already on that head. The player may spend **coins** from inventory to add any positive amount to that bounty (server-authoritative; coins consumed only on success).
351
2. **My bounty** — Shows how much coin is currently on **your** head.
350
1. **Place / raise bounty** — Search a character by first + last name. If found, show a small character preview and the **current bounty** already on that head. The player may spend **coins** from inventory to add any positive amount to that bounty (server-authoritative; coins consumed only on success). You cannot place a bounty on yourself.
351
2. **My bounty** — Shows how much coin is currently on **your** head. You may **pay toward** that bounty from inventory at **10 coins paid → 1 bounty coin cleared** (capped at the remaining bounty; only complete 10-coin multiples are spent). Bounty also **decays by 1 coin per calendar day** at local midnight (lazy apply when read).
352
352
353
353
**Payout on kill:** When a player who still has bounty \> 0 is **killed by another player** (attacker dealt the killing blow / engaged death), a **carrier pigeon** is dispatched from the **nearest bounty office** to the **killer's bank**, delivering a letter stating they received a bounty of **N** coins, where **N** is the **full sum** of all coin placed on the victim. Those **N** coins are **deposited immediately into the killer's bank vault** (not inventory). The victim's bounty is then reset to **0**.
354
354
@@ -347,8 +347,8 @@ Use later when deciding which ingredients fit which potions. Tiers: **2 / 3 / 3347
**Status:** full
347
**Status:** full
348
**Spec:** Placeable **Bounty Office** blocks. Interacting opens a modal with two tabs:
348
**Spec:** Placeable **Bounty Office** blocks. Interacting opens a modal with two tabs:
349
349
350
1. **Place / raise bounty** — Search a character by first + last name. If found, show a small character preview and the **current bounty** already on that head. The player may spend **coins** from inventory to add any positive amount to that bounty (server-authoritative; coins consumed only on success).
350
1. **Place / raise bounty** — Search a character by first + last name. If found, show a small character preview and the **current bounty** already on that head. The player may spend **coins** from inventory to add any positive amount to that bounty (server-authoritative; coins consumed only on success). You cannot place a bounty on yourself.
351
2. **My bounty** — Shows how much coin is currently on **your** head.
351
2. **My bounty** — Shows how much coin is currently on **your** head. You may **pay toward** that bounty from inventory at **10 coins paid → 1 bounty coin cleared** (capped at the remaining bounty; only complete 10-coin multiples are spent). Bounty also **decays by 1 coin per calendar day** at local midnight (lazy apply when read).
352
352
353
**Payout on kill:** When a player who still has bounty \> 0 is **killed by another player** (attacker dealt the killing blow / engaged death), a **carrier pigeon** is dispatched from the **nearest bounty office** to the **killer's bank**, delivering a letter stating they received a bounty of **N** coins, where **N** is the **full sum** of all coin placed on the victim. Those **N** coins are **deposited immediately into the killer's bank vault** (not inventory). The victim's bounty is then reset to **0**.
353
**Payout on kill:** When a player who still has bounty \> 0 is **killed by another player** (attacker dealt the killing blow / engaged death), a **carrier pigeon** is dispatched from the **nearest bounty office** to the **killer's bank**, delivering a letter stating they received a bounty of **N** coins, where **N** is the **full sum** of all coin placed on the victim. Those **N** coins are **deposited immediately into the killer's bank vault** (not inventory). The victim's bounty is then reset to **0**.
354
354
@@ -1,5 +1,11 @@
1
import { ItemId, formatQuantity } from "../../../shared/definitions/items.js";
2
import { bountyPayoutLetterBody, formatBountyCopper } from "../../../shared/bounty/pricing.js";
1
import { formatQuantity } from "../../../shared/definitions/items.js";
2
import {
3
bountyPayoutLetterBody,
4
formatBountyCopper,
5
bountyPayoffFromCoins,
6
BOUNTY_PAYOFF_COINS_PER_POINT,
7
bountyNextDecayAt
8
} from "../../../shared/bounty/pricing.js";
3
9
import { BOUNTY_OFFICE_AUTHOR } from "../../../shared/courier/systemLetters.js";
4
10
import { layersFromBag } from "../../../shared/appearance/layers.js";
5
11
import { hairFromCharacterRow } from "../../../shared/appearance/hair.js";
@@ -8,6 +14,7 @@ import {
8
14
normalizeVault,
9
15
takeCoinsFromSlots
10
16
} from "../../../shared/items/inventory.js";
17
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
11
18
12
19
function userError (message)
13
20
{
@@ -16,8 +23,6 @@ function userError (message)
16
23
return error;
17
24
}
18
25
19
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
20
21
26
/**
22
27
* Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.
23
28
*/
@@ -44,6 +49,8 @@ export class BountyService
44
49
command.lastName,
45
50
command.amountCopper
46
51
);
52
case "pay-bounty":
53
return this.payOff(sessionId, command.characterId, command.amountCopper);
47
54
case "get-character-bounty":
48
55
return this.lookup(
49
56
sessionId,
@@ -91,7 +98,7 @@ export class BountyService
91
98
if (!row)
92
99
{ throw userError("No adventurer by that name."); }
93
100
94
const amountCopper = this.stateDb.getCharacterBounty(row.character_id);
101
const amountCopper = this.stateDb.getCharacterBounty(row.character_id, this.#now());
95
102
const bag = this.#loadBagQuiet(row.character_id);
96
103
return {
97
104
events: [{
@@ -129,7 +136,7 @@ export class BountyService
129
136
if (targetId === (placerCharacterId | 0))
130
137
{ throw userError("You cannot place a bounty on yourself."); }
131
138
132
const previous = this.stateDb.getCharacterBounty(targetId);
139
const previous = this.stateDb.getCharacterBounty(targetId, this.#now());
133
140
const bag = this.#loadBag(placerCharacterId);
134
141
const paid = takeCoinsFromSlots(bag.inventory ?? [], copper);
135
142
if (!paid.ok)
@@ -137,7 +144,7 @@ export class BountyService
137
144
bag.inventory = paid.slots;
138
145
this.#persistBag(placerCharacterId, bag);
139
146
140
const nextAmount = this.stateDb.addCharacterBounty(targetId, copper);
147
const nextAmount = this.stateDb.addCharacterBounty(targetId, copper, this.#now());
141
148
this.simulation.refreshCharacterSkull?.(targetId, { force: true });
142
149
this.simulation.pendingPrivate.push({
143
150
type: "toast",
@@ -168,6 +175,57 @@ export class BountyService
168
175
};
169
176
}
170
177
178
/**
179
* Pay inventory coins to reduce your own bounty (10 coins → 1 bounty cleared).
180
*/
181
payOff (sessionId, characterId, amountCopper)
182
{
183
this.#requireNearOffice(characterId);
184
const offered = Math.floor(Number(amountCopper) || 0);
185
if (!Number.isFinite(offered) || offered <= 0)
186
{ throw userError("Enter a positive coin amount."); }
187
188
const current = this.stateDb.getCharacterBounty(characterId, this.#now());
189
if (current <= 0)
190
{ throw userError("There is no bounty on your head."); }
191
192
const { reduce, costCopper } = bountyPayoffFromCoins(offered, current);
193
if (reduce <= 0)
194
{
195
throw userError(
196
`Need at least ${formatQuantity(BOUNTY_PAYOFF_COINS_PER_POINT)} to clear 1 bounty coin.`
197
);
198
}
199
200
const bag = this.#loadBag(characterId);
201
const paid = takeCoinsFromSlots(bag.inventory ?? [], costCopper);
202
if (!paid.ok)
203
{ throw userError(`Need ${formatQuantity(costCopper)} in your inventory.`); }
204
bag.inventory = paid.slots;
205
this.#persistBag(characterId, bag);
206
207
const nextAmount = this.stateDb.reduceCharacterBounty(characterId, reduce, this.#now());
208
this.simulation.refreshCharacterSkull?.(characterId, { force: true });
209
210
return {
211
events: [{
212
type: "bounty-snapshot",
213
sessionId,
214
characterId,
215
...this.#myBountyPayload(characterId),
216
paidOff: {
217
spentCopper: costCopper,
218
clearedCopper: reduce,
219
amountCopper: nextAmount,
220
amountLabel: formatBountyCopper(nextAmount),
221
message: nextAmount > 0
222
? `Paid ${formatQuantity(costCopper)} to clear ${formatBountyCopper(reduce)}. Remaining: ${formatBountyCopper(nextAmount)}.`
223
: `Paid ${formatQuantity(costCopper)} — your bounty is cleared.`
224
}
225
}]
226
};
227
}
228
171
229
/**
172
230
* Called when a player dies. Non-friend PvP killer collects full bounty into vault + office letter.
173
231
* Friend / same-account / mob kills leave the bounty untouched.
@@ -186,7 +244,7 @@ export class BountyService
186
244
if (this.stateDb.areFriends(victimCharacterId, killerCharacterId))
187
245
{ return null; }
188
246
189
const paidCopper = this.stateDb.takeCharacterBounty(victimCharacterId);
247
const paidCopper = this.stateDb.takeCharacterBounty(victimCharacterId, this.#now());
190
248
if (paidCopper <= 0)
191
249
{ return null; }
192
250
@@ -230,12 +288,20 @@ export class BountyService
230
288
return { paidCopper, victimName };
231
289
}
232
290
291
#now ()
292
{
293
return typeof this.simulation?.now === "number" ? this.simulation.now : Date.now();
294
}
295
233
296
#myBountyPayload (characterId)
234
297
{
235
const amountCopper = this.stateDb.getCharacterBounty(characterId);
298
const now = this.#now();
299
const amountCopper = this.stateDb.getCharacterBounty(characterId, now);
236
300
return {
237
301
myAmountCopper: amountCopper,
238
302
myAmountLabel: formatBountyCopper(amountCopper),
303
nextDecayAt: bountyNextDecayAt(now),
304
payoffCoinsPerPoint: BOUNTY_PAYOFF_COINS_PER_POINT,
239
305
message: amountCopper > 0
240
306
? `Bounty on your head: ${formatBountyCopper(amountCopper)}.`
241
307
: "No bounty on your head."
@@ -1,5 +1,11 @@1
import { ItemId, formatQuantity } from "../../../shared/definitions/items.js";1
import { formatQuantity } from "../../../shared/definitions/items.js";2
import { bountyPayoutLetterBody, formatBountyCopper } from "../../../shared/bounty/pricing.js";2
import {3
bountyPayoutLetterBody,4
formatBountyCopper,5
bountyPayoffFromCoins,6
BOUNTY_PAYOFF_COINS_PER_POINT,7
bountyNextDecayAt8
} from "../../../shared/bounty/pricing.js";3
import { BOUNTY_OFFICE_AUTHOR } from "../../../shared/courier/systemLetters.js";9
import { BOUNTY_OFFICE_AUTHOR } from "../../../shared/courier/systemLetters.js";4
import { layersFromBag } from "../../../shared/appearance/layers.js";10
import { layersFromBag } from "../../../shared/appearance/layers.js";5
import { hairFromCharacterRow } from "../../../shared/appearance/hair.js";11
import { hairFromCharacterRow } from "../../../shared/appearance/hair.js";@@ -8,6 +14,7 @@ import {8
normalizeVault,14
normalizeVault,9
takeCoinsFromSlots15
takeCoinsFromSlots10
} from "../../../shared/items/inventory.js";16
} from "../../../shared/items/inventory.js";17
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";11
18
12
function userError (message)19
function userError (message)13
{20
{@@ -16,8 +23,6 @@ function userError (message)16
return error;23
return error;17
}24
}18
25
19
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";20
21
/**26
/**22
* Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.27
* Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.23
*/28
*/@@ -44,6 +49,8 @@ export class BountyService44
command.lastName,49
command.lastName,45
command.amountCopper50
command.amountCopper46
);51
);52
case "pay-bounty":53
return this.payOff(sessionId, command.characterId, command.amountCopper);47
case "get-character-bounty":54
case "get-character-bounty":48
return this.lookup(55
return this.lookup(49
sessionId,56
sessionId,@@ -91,7 +98,7 @@ export class BountyService91
if (!row)98
if (!row)92
{ throw userError("No adventurer by that name."); }99
{ throw userError("No adventurer by that name."); }93
100
94
const amountCopper = this.stateDb.getCharacterBounty(row.character_id);101
const amountCopper = this.stateDb.getCharacterBounty(row.character_id, this.#now());95
const bag = this.#loadBagQuiet(row.character_id);102
const bag = this.#loadBagQuiet(row.character_id);96
return {103
return {97
events: [{104
events: [{@@ -129,7 +136,7 @@ export class BountyService129
if (targetId === (placerCharacterId | 0))136
if (targetId === (placerCharacterId | 0))130
{ throw userError("You cannot place a bounty on yourself."); }137
{ throw userError("You cannot place a bounty on yourself."); }131
138
132
const previous = this.stateDb.getCharacterBounty(targetId);139
const previous = this.stateDb.getCharacterBounty(targetId, this.#now());133
const bag = this.#loadBag(placerCharacterId);140
const bag = this.#loadBag(placerCharacterId);134
const paid = takeCoinsFromSlots(bag.inventory ?? [], copper);141
const paid = takeCoinsFromSlots(bag.inventory ?? [], copper);135
if (!paid.ok)142
if (!paid.ok)@@ -137,7 +144,7 @@ export class BountyService137
bag.inventory = paid.slots;144
bag.inventory = paid.slots;138
this.#persistBag(placerCharacterId, bag);145
this.#persistBag(placerCharacterId, bag);139
146
140
const nextAmount = this.stateDb.addCharacterBounty(targetId, copper);147
const nextAmount = this.stateDb.addCharacterBounty(targetId, copper, this.#now());141
this.simulation.refreshCharacterSkull?.(targetId, { force: true });148
this.simulation.refreshCharacterSkull?.(targetId, { force: true });142
this.simulation.pendingPrivate.push({149
this.simulation.pendingPrivate.push({143
type: "toast",150
type: "toast",@@ -168,6 +175,57 @@ export class BountyService168
};175
};169
}176
}170
177
178
/**179
* Pay inventory coins to reduce your own bounty (10 coins → 1 bounty cleared).180
*/181
payOff (sessionId, characterId, amountCopper)182
{183
this.#requireNearOffice(characterId);184
const offered = Math.floor(Number(amountCopper) || 0);185
if (!Number.isFinite(offered) || offered <= 0)186
{ throw userError("Enter a positive coin amount."); }187
188
const current = this.stateDb.getCharacterBounty(characterId, this.#now());189
if (current <= 0)190
{ throw userError("There is no bounty on your head."); }191
192
const { reduce, costCopper } = bountyPayoffFromCoins(offered, current);193
if (reduce <= 0)194
{195
throw userError(196
`Need at least ${formatQuantity(BOUNTY_PAYOFF_COINS_PER_POINT)} to clear 1 bounty coin.`197
);198
}199
200
const bag = this.#loadBag(characterId);201
const paid = takeCoinsFromSlots(bag.inventory ?? [], costCopper);202
if (!paid.ok)203
{ throw userError(`Need ${formatQuantity(costCopper)} in your inventory.`); }204
bag.inventory = paid.slots;205
this.#persistBag(characterId, bag);206
207
const nextAmount = this.stateDb.reduceCharacterBounty(characterId, reduce, this.#now());208
this.simulation.refreshCharacterSkull?.(characterId, { force: true });209
210
return {211
events: [{212
type: "bounty-snapshot",213
sessionId,214
characterId,215
...this.#myBountyPayload(characterId),216
paidOff: {217
spentCopper: costCopper,218
clearedCopper: reduce,219
amountCopper: nextAmount,220
amountLabel: formatBountyCopper(nextAmount),221
message: nextAmount > 0222
? `Paid ${formatQuantity(costCopper)} to clear ${formatBountyCopper(reduce)}. Remaining: ${formatBountyCopper(nextAmount)}.`223
: `Paid ${formatQuantity(costCopper)} — your bounty is cleared.`224
}225
}]226
};227
}228
171
/**229
/**172
* Called when a player dies. Non-friend PvP killer collects full bounty into vault + office letter.230
* Called when a player dies. Non-friend PvP killer collects full bounty into vault + office letter.173
* Friend / same-account / mob kills leave the bounty untouched.231
* Friend / same-account / mob kills leave the bounty untouched.@@ -186,7 +244,7 @@ export class BountyService186
if (this.stateDb.areFriends(victimCharacterId, killerCharacterId))244
if (this.stateDb.areFriends(victimCharacterId, killerCharacterId))187
{ return null; }245
{ return null; }188
246
189
const paidCopper = this.stateDb.takeCharacterBounty(victimCharacterId);247
const paidCopper = this.stateDb.takeCharacterBounty(victimCharacterId, this.#now());190
if (paidCopper <= 0)248
if (paidCopper <= 0)191
{ return null; }249
{ return null; }192
250
@@ -230,12 +288,20 @@ export class BountyService230
return { paidCopper, victimName };288
return { paidCopper, victimName };231
}289
}232
290
291
#now ()292
{293
return typeof this.simulation?.now === "number" ? this.simulation.now : Date.now();294
}295
233
#myBountyPayload (characterId)296
#myBountyPayload (characterId)234
{297
{235
const amountCopper = this.stateDb.getCharacterBounty(characterId);298
const now = this.#now();299
const amountCopper = this.stateDb.getCharacterBounty(characterId, now);236
return {300
return {237
myAmountCopper: amountCopper,301
myAmountCopper: amountCopper,238
myAmountLabel: formatBountyCopper(amountCopper),302
myAmountLabel: formatBountyCopper(amountCopper),303
nextDecayAt: bountyNextDecayAt(now),304
payoffCoinsPerPoint: BOUNTY_PAYOFF_COINS_PER_POINT,239
message: amountCopper > 0305
message: amountCopper > 0240
? `Bounty on your head: ${formatBountyCopper(amountCopper)}.`306
? `Bounty on your head: ${formatBountyCopper(amountCopper)}.`241
: "No bounty on your head."307
: "No bounty on your head."@@ -328,6 +328,14 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
328
328
amountCopper: message.amountCopper
329
329
});
330
330
break;
331
case MessageType.payBounty:
332
requirePlaying(session);
333
simulation.enqueue(session.id, {
334
type: "pay-bounty",
335
characterId: session.characterId,
336
amountCopper: message.amountCopper
337
});
338
break;
331
339
case MessageType.getCharacterBounty:
332
340
requirePlaying(session);
333
341
simulation.enqueue(session.id, {
@@ -2001,8 +2009,11 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2001
2009
type: MessageType.bountySnapshot,
2002
2010
myAmountCopper: event.myAmountCopper | 0,
2003
2011
myAmountLabel: event.myAmountLabel ?? "",
2012
nextDecayAt: event.nextDecayAt ?? null,
2013
payoffCoinsPerPoint: event.payoffCoinsPerPoint ?? 10,
2004
2014
message: event.message ?? "",
2005
raised: event.raised ?? null
2015
raised: event.raised ?? null,
2016
paidOff: event.paidOff ?? null
2006
2017
});
2007
2018
}
2008
2019
continue;
@@ -328,6 +328,14 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,328
amountCopper: message.amountCopper328
amountCopper: message.amountCopper329
});329
});330
break;330
break;331
case MessageType.payBounty:332
requirePlaying(session);333
simulation.enqueue(session.id, {334
type: "pay-bounty",335
characterId: session.characterId,336
amountCopper: message.amountCopper337
});338
break;331
case MessageType.getCharacterBounty:339
case MessageType.getCharacterBounty:332
requirePlaying(session);340
requirePlaying(session);333
simulation.enqueue(session.id, {341
simulation.enqueue(session.id, {@@ -2001,8 +2009,11 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2001
type: MessageType.bountySnapshot,2009
type: MessageType.bountySnapshot,2002
myAmountCopper: event.myAmountCopper | 0,2010
myAmountCopper: event.myAmountCopper | 0,2003
myAmountLabel: event.myAmountLabel ?? "",2011
myAmountLabel: event.myAmountLabel ?? "",2012
nextDecayAt: event.nextDecayAt ?? null,2013
payoffCoinsPerPoint: event.payoffCoinsPerPoint ?? 10,2004
message: event.message ?? "",2014
message: event.message ?? "",2005
raised: event.raised ?? null2015
raised: event.raised ?? null,2016
paidOff: event.paidOff ?? null2006
});2017
});2007
}2018
}2008
continue;2019
continue;@@ -6,6 +6,11 @@ import { buildStarterBagContents } from "../../../shared/items/starterLoadout.js
6
6
import { normalizePlayerSkills, defaultPlayerSkills, storedSkillXp } from "../../../shared/skills/state.js";
7
7
import { normalizePlayerSpells, defaultPlayerSpells, storedPlayerSpells } from "../../../shared/spells/state.js";
8
8
import { decayKillCounter } from "../../../shared/combat/skull.js";
9
import {
10
applyBountyDailyDecay,
11
bountyDecayDayKey,
12
bountyDecayDaysBetween
13
} from "../../../shared/bounty/pricing.js";
9
14
10
15
const STATE_SCHEMA = `
11
16
CREATE TABLE IF NOT EXISTS accounts (
@@ -162,7 +167,8 @@ CREATE TABLE IF NOT EXISTS held_courier_deliveries (
162
167
163
168
CREATE TABLE IF NOT EXISTS character_bounties (
164
169
character_id INTEGER PRIMARY KEY,
165
amount INTEGER NOT NULL DEFAULT 0
170
amount INTEGER NOT NULL DEFAULT 0,
171
last_decay_day TEXT
166
172
);
167
173
168
174
CREATE TABLE IF NOT EXISTS character_quest_state (
@@ -265,6 +271,9 @@ export class StateDatabase
265
271
const marketColumns = this.db.prepare("PRAGMA table_info(market_orders)").all();
266
272
if (!marketColumns.some((column) => column.name === "listing_key"))
267
273
{ this.db.exec("ALTER TABLE market_orders ADD COLUMN listing_key TEXT"); }
274
const bountyColumns = this.db.prepare("PRAGMA table_info(character_bounties)").all();
275
if (!bountyColumns.some((column) => column.name === "last_decay_day"))
276
{ this.db.exec("ALTER TABLE character_bounties ADD COLUMN last_decay_day TEXT"); }
268
277
this.db.exec(`
269
278
CREATE TABLE IF NOT EXISTS account_friend_requests (
270
279
request_id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -802,39 +811,93 @@ export class StateDatabase
802
811
`).all(needle, needle, needle, needle, cap);
803
812
}
804
813
805
getCharacterBounty (characterId)
814
getCharacterBounty (characterId, now = Date.now())
806
815
{
816
return this.applyCharacterBountyDecay(characterId, now);
817
}
818
819
/**
820
* Daily −1 bounty decay (lazy). First touch after migration stamps today without retroactive decay.
821
* Never moves `last_decay_day` backward (simulation clocks in tests can be epoch-relative).
822
*/
823
applyCharacterBountyDecay (characterId, now = Date.now())
824
{
825
const id = characterId | 0;
807
826
const row = this.db.prepare(`
808
SELECT amount FROM character_bounties WHERE character_id = ?
809
`).get(characterId | 0);
810
return Math.max(0, row?.amount | 0);
827
SELECT amount, last_decay_day FROM character_bounties WHERE character_id = ?
828
`).get(id);
829
if (!row)
830
{ return 0; }
831
const day = bountyDecayDayKey(now);
832
let amount = Math.max(0, row.amount | 0);
833
const last = row.last_decay_day ? String(row.last_decay_day) : "";
834
if (!last)
835
{
836
this.db.prepare(`
837
UPDATE character_bounties SET last_decay_day = ? WHERE character_id = ?
838
`).run(day, id);
839
return amount;
840
}
841
if (last === day)
842
{ return amount; }
843
const days = bountyDecayDaysBetween(last, day);
844
if (days <= 0)
845
{
846
// `now` is on/before the stamped day (clock skew / harness) — leave the stamp alone.
847
return amount;
848
}
849
amount = applyBountyDailyDecay(amount, days);
850
this.db.prepare(`
851
UPDATE character_bounties SET amount = ?, last_decay_day = ? WHERE character_id = ?
852
`).run(amount, day, id);
853
return amount;
811
854
}
812
855
813
856
/** Add coins to a bounty; returns the new total. */
814
addCharacterBounty (characterId, amount)
857
addCharacterBounty (characterId, amount, now = Date.now())
815
858
{
816
859
const id = characterId | 0;
817
860
const add = Math.max(0, amount | 0);
818
861
if (add <= 0)
819
{ return this.getCharacterBounty(id); }
862
{ return this.getCharacterBounty(id, now); }
863
const day = bountyDecayDayKey(now);
864
this.applyCharacterBountyDecay(id, now);
820
865
this.db.prepare(`
821
INSERT INTO character_bounties (character_id, amount) VALUES (?, ?)
866
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, ?, ?)
822
867
ON CONFLICT(character_id) DO UPDATE SET amount = amount + excluded.amount
823
`).run(id, add);
824
return this.getCharacterBounty(id);
868
`).run(id, add, day);
869
return this.getCharacterBounty(id, now);
870
}
871
872
/** Reduce bounty by up to `amount`; returns the new total. */
873
reduceCharacterBounty (characterId, amount, now = Date.now())
874
{
875
const id = characterId | 0;
876
const cut = Math.max(0, amount | 0);
877
const current = this.getCharacterBounty(id, now);
878
if (cut <= 0)
879
{ return current; }
880
const next = Math.max(0, current - cut);
881
const day = bountyDecayDayKey(now);
882
this.db.prepare(`
883
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, ?, ?)
884
ON CONFLICT(character_id) DO UPDATE SET amount = excluded.amount
885
`).run(id, next, day);
886
return next;
825
887
}
826
888
827
889
/** Zero out and return the previous bounty amount. */
828
takeCharacterBounty (characterId)
890
takeCharacterBounty (characterId, now = Date.now())
829
891
{
830
892
const id = characterId | 0;
831
const amount = this.getCharacterBounty(id);
893
const amount = this.getCharacterBounty(id, now);
832
894
if (amount <= 0)
833
895
{ return 0; }
896
const day = bountyDecayDayKey(now);
834
897
this.db.prepare(`
835
INSERT INTO character_bounties (character_id, amount) VALUES (?, 0)
898
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, 0, ?)
836
899
ON CONFLICT(character_id) DO UPDATE SET amount = 0
837
`).run(id);
900
`).run(id, day);
838
901
return amount;
839
902
}
840
903
@@ -6,6 +6,11 @@ import { buildStarterBagContents } from "../../../shared/items/starterLoadout.js6
import { normalizePlayerSkills, defaultPlayerSkills, storedSkillXp } from "../../../shared/skills/state.js";6
import { normalizePlayerSkills, defaultPlayerSkills, storedSkillXp } from "../../../shared/skills/state.js";7
import { normalizePlayerSpells, defaultPlayerSpells, storedPlayerSpells } from "../../../shared/spells/state.js";7
import { normalizePlayerSpells, defaultPlayerSpells, storedPlayerSpells } from "../../../shared/spells/state.js";8
import { decayKillCounter } from "../../../shared/combat/skull.js";8
import { decayKillCounter } from "../../../shared/combat/skull.js";9
import {10
applyBountyDailyDecay,11
bountyDecayDayKey,12
bountyDecayDaysBetween13
} from "../../../shared/bounty/pricing.js";9
14
10
const STATE_SCHEMA = `15
const STATE_SCHEMA = `11
CREATE TABLE IF NOT EXISTS accounts (16
CREATE TABLE IF NOT EXISTS accounts (@@ -162,7 +167,8 @@ CREATE TABLE IF NOT EXISTS held_courier_deliveries (162
167
163
CREATE TABLE IF NOT EXISTS character_bounties (168
CREATE TABLE IF NOT EXISTS character_bounties (164
character_id INTEGER PRIMARY KEY,169
character_id INTEGER PRIMARY KEY,165
amount INTEGER NOT NULL DEFAULT 0170
amount INTEGER NOT NULL DEFAULT 0,171
last_decay_day TEXT166
);172
);167
173
168
CREATE TABLE IF NOT EXISTS character_quest_state (174
CREATE TABLE IF NOT EXISTS character_quest_state (@@ -265,6 +271,9 @@ export class StateDatabase265
const marketColumns = this.db.prepare("PRAGMA table_info(market_orders)").all();271
const marketColumns = this.db.prepare("PRAGMA table_info(market_orders)").all();266
if (!marketColumns.some((column) => column.name === "listing_key"))272
if (!marketColumns.some((column) => column.name === "listing_key"))267
{ this.db.exec("ALTER TABLE market_orders ADD COLUMN listing_key TEXT"); }273
{ this.db.exec("ALTER TABLE market_orders ADD COLUMN listing_key TEXT"); }274
const bountyColumns = this.db.prepare("PRAGMA table_info(character_bounties)").all();275
if (!bountyColumns.some((column) => column.name === "last_decay_day"))276
{ this.db.exec("ALTER TABLE character_bounties ADD COLUMN last_decay_day TEXT"); }268
this.db.exec(`277
this.db.exec(`269
CREATE TABLE IF NOT EXISTS account_friend_requests (278
CREATE TABLE IF NOT EXISTS account_friend_requests (270
request_id INTEGER PRIMARY KEY AUTOINCREMENT,279
request_id INTEGER PRIMARY KEY AUTOINCREMENT,@@ -802,39 +811,93 @@ export class StateDatabase802
`).all(needle, needle, needle, needle, cap);811
`).all(needle, needle, needle, needle, cap);803
}812
}804
813
805
getCharacterBounty (characterId)814
getCharacterBounty (characterId, now = Date.now())806
{815
{816
return this.applyCharacterBountyDecay(characterId, now);817
}818
819
/**820
* Daily −1 bounty decay (lazy). First touch after migration stamps today without retroactive decay.821
* Never moves `last_decay_day` backward (simulation clocks in tests can be epoch-relative).822
*/823
applyCharacterBountyDecay (characterId, now = Date.now())824
{825
const id = characterId | 0;807
const row = this.db.prepare(`826
const row = this.db.prepare(`808
SELECT amount FROM character_bounties WHERE character_id = ?827
SELECT amount, last_decay_day FROM character_bounties WHERE character_id = ?809
`).get(characterId | 0);828
`).get(id);810
return Math.max(0, row?.amount | 0);829
if (!row)830
{ return 0; }831
const day = bountyDecayDayKey(now);832
let amount = Math.max(0, row.amount | 0);833
const last = row.last_decay_day ? String(row.last_decay_day) : "";834
if (!last)835
{836
this.db.prepare(`837
UPDATE character_bounties SET last_decay_day = ? WHERE character_id = ?838
`).run(day, id);839
return amount;840
}841
if (last === day)842
{ return amount; }843
const days = bountyDecayDaysBetween(last, day);844
if (days <= 0)845
{846
// `now` is on/before the stamped day (clock skew / harness) — leave the stamp alone.847
return amount;848
}849
amount = applyBountyDailyDecay(amount, days);850
this.db.prepare(`851
UPDATE character_bounties SET amount = ?, last_decay_day = ? WHERE character_id = ?852
`).run(amount, day, id);853
return amount;811
}854
}812
855
813
/** Add coins to a bounty; returns the new total. */856
/** Add coins to a bounty; returns the new total. */814
addCharacterBounty (characterId, amount)857
addCharacterBounty (characterId, amount, now = Date.now())815
{858
{816
const id = characterId | 0;859
const id = characterId | 0;817
const add = Math.max(0, amount | 0);860
const add = Math.max(0, amount | 0);818
if (add <= 0)861
if (add <= 0)819
{ return this.getCharacterBounty(id); }862
{ return this.getCharacterBounty(id, now); }863
const day = bountyDecayDayKey(now);864
this.applyCharacterBountyDecay(id, now);820
this.db.prepare(`865
this.db.prepare(`821
INSERT INTO character_bounties (character_id, amount) VALUES (?, ?)866
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, ?, ?)822
ON CONFLICT(character_id) DO UPDATE SET amount = amount + excluded.amount867
ON CONFLICT(character_id) DO UPDATE SET amount = amount + excluded.amount823
`).run(id, add);868
`).run(id, add, day);824
return this.getCharacterBounty(id);869
return this.getCharacterBounty(id, now);870
}871
872
/** Reduce bounty by up to `amount`; returns the new total. */873
reduceCharacterBounty (characterId, amount, now = Date.now())874
{875
const id = characterId | 0;876
const cut = Math.max(0, amount | 0);877
const current = this.getCharacterBounty(id, now);878
if (cut <= 0)879
{ return current; }880
const next = Math.max(0, current - cut);881
const day = bountyDecayDayKey(now);882
this.db.prepare(`883
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, ?, ?)884
ON CONFLICT(character_id) DO UPDATE SET amount = excluded.amount885
`).run(id, next, day);886
return next;825
}887
}826
888
827
/** Zero out and return the previous bounty amount. */889
/** Zero out and return the previous bounty amount. */828
takeCharacterBounty (characterId)890
takeCharacterBounty (characterId, now = Date.now())829
{891
{830
const id = characterId | 0;892
const id = characterId | 0;831
const amount = this.getCharacterBounty(id);893
const amount = this.getCharacterBounty(id, now);832
if (amount <= 0)894
if (amount <= 0)833
{ return 0; }895
{ return 0; }896
const day = bountyDecayDayKey(now);834
this.db.prepare(`897
this.db.prepare(`835
INSERT INTO character_bounties (character_id, amount) VALUES (?, 0)898
INSERT INTO character_bounties (character_id, amount, last_decay_day) VALUES (?, 0, ?)836
ON CONFLICT(character_id) DO UPDATE SET amount = 0899
ON CONFLICT(character_id) DO UPDATE SET amount = 0837
`).run(id);900
`).run(id, day);838
return amount;901
return amount;839
}902
}840
903
@@ -544,7 +544,7 @@ export class Simulation
544
544
545
545
characterSkullValue (characterId, now = this.now)
546
546
{
547
const bounty = this.stateDb.getCharacterBounty(characterId);
547
const bounty = this.stateDb.getCharacterBounty(characterId, now);
548
548
const killCounter = this.stateDb.peekKillCounter(characterId, now);
549
549
return skullValue(bounty, killCounter);
550
550
}
@@ -1498,6 +1498,7 @@ export class Simulation
1498
1498
if (
1499
1499
item.command.type === "open-bounty"
1500
1500
|| item.command.type === "raise-bounty"
1501
|| item.command.type === "pay-bounty"
1501
1502
|| item.command.type === "get-character-bounty"
1502
1503
|| item.command.type === "close-bounty"
1503
1504
)
@@ -544,7 +544,7 @@ export class Simulation544
544
545
characterSkullValue (characterId, now = this.now)545
characterSkullValue (characterId, now = this.now)546
{546
{547
const bounty = this.stateDb.getCharacterBounty(characterId);547
const bounty = this.stateDb.getCharacterBounty(characterId, now);548
const killCounter = this.stateDb.peekKillCounter(characterId, now);548
const killCounter = this.stateDb.peekKillCounter(characterId, now);549
return skullValue(bounty, killCounter);549
return skullValue(bounty, killCounter);550
}550
}@@ -1498,6 +1498,7 @@ export class Simulation1498
if (1498
if (1499
item.command.type === "open-bounty"1499
item.command.type === "open-bounty"1500
|| item.command.type === "raise-bounty"1500
|| item.command.type === "raise-bounty"1501
|| item.command.type === "pay-bounty"1501
|| item.command.type === "get-character-bounty"1502
|| item.command.type === "get-character-bounty"1502
|| item.command.type === "close-bounty"1503
|| item.command.type === "close-bounty"1503
)1504
)@@ -77,7 +77,7 @@ test("raise bounty spends inventory coins and tracks ledger", () =>
77
77
const snap = result.events.find((event) => event.type === "bounty-snapshot");
78
78
assert.ok(snap?.raised);
79
79
assert.equal(snap.raised.amountCopper, 250);
80
assert.equal(harness.stateDb.getCharacterBounty(target.character_id), 250);
80
assert.equal(harness.stateDb.getCharacterBounty(target.character_id, harness.now()), 250);
81
81
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 250);
82
82
83
83
harness.simulation.enqueue(1, {
@@ -88,7 +88,7 @@ test("raise bounty spends inventory coins and tracks ledger", () =>
88
88
amountCopper: 100
89
89
});
90
90
harness.simulation.step();
91
assert.equal(harness.stateDb.getCharacterBounty(target.character_id), 350);
91
assert.equal(harness.stateDb.getCharacterBounty(target.character_id, harness.now()), 350);
92
92
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 150);
93
93
}
94
94
finally
@@ -150,7 +150,7 @@ test("PvP kill pays bounty into killer vault and clears ledger", () =>
150
150
9
151
151
);
152
152
assert.equal(settled?.paidCopper, 400);
153
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id), 0);
153
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id, harness.now()), 0);
154
154
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 400);
155
155
156
156
harness.stateDb.addKillCounter(killer.character_id, 500, harness.now());
@@ -197,10 +197,97 @@ test("friend PvP kill does not pay or clear bounty", () =>
197
197
9
198
198
);
199
199
assert.equal(settled, null);
200
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id), 400);
200
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id, harness.now()), 400);
201
201
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 0);
202
202
assert.equal(harness.simulation.directory.get(victimId).skullValue, 400);
203
203
}
204
204
finally
205
205
{ harness.close(); }
206
206
});
207
208
test("pay off own bounty spends 10 coins per 1 bounty cleared", () =>
209
{
210
const harness = makeSimulation({ workerCount: 1 });
211
try
212
{
213
placeBlock(harness.worldDb, 8, 8, BlockType.bountyOffice);
214
harness.simulation.reloadWorld();
215
const character = makeCharacter(harness.stateDb, {
216
firstName: "Self",
217
lastName: "Pay",
218
tileX: 8,
219
tileY: 9
220
});
221
harness.stateDb.addCharacterBounty(character.character_id, 25);
222
const entityId = harness.simulation.spawnCharacter(1, character);
223
giveCoins(harness, entityId, 100);
224
225
harness.simulation.enqueue(1, {
226
type: "pay-bounty",
227
characterId: character.character_id,
228
amountCopper: 100
229
});
230
const result = harness.simulation.step();
231
const snap = result.events.find((event) => event.type === "bounty-snapshot");
232
assert.ok(snap?.paidOff);
233
assert.equal(snap.paidOff.clearedCopper, 10);
234
assert.equal(snap.paidOff.spentCopper, 100);
235
assert.equal(snap.myAmountCopper, 15);
236
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, harness.now()), 15);
237
assert.equal(countCoins(harness.simulation.bagOf(entityId).inventory), 0);
238
assert.equal(harness.simulation.directory.get(entityId).skullValue, 15);
239
}
240
finally
241
{ harness.close(); }
242
});
243
244
test("pay off caps at remaining bounty and spends only matching tens", () =>
245
{
246
const harness = makeSimulation({ workerCount: 1 });
247
try
248
{
249
placeBlock(harness.worldDb, 8, 8, BlockType.bountyOffice);
250
harness.simulation.reloadWorld();
251
const character = makeCharacter(harness.stateDb, {
252
firstName: "Cap",
253
lastName: "Pay",
254
tileX: 8,
255
tileY: 9
256
});
257
harness.stateDb.addCharacterBounty(character.character_id, 3);
258
const entityId = harness.simulation.spawnCharacter(1, character);
259
giveCoins(harness, entityId, 100);
260
261
harness.simulation.enqueue(1, {
262
type: "pay-bounty",
263
characterId: character.character_id,
264
amountCopper: 100
265
});
266
harness.simulation.step();
267
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, harness.now()), 0);
268
assert.equal(countCoins(harness.simulation.bagOf(entityId).inventory), 70);
269
}
270
finally
271
{ harness.close(); }
272
});
273
274
test("bounty decays one coin per calendar day", () =>
275
{
276
const harness = makeSimulation({ workerCount: 1 });
277
try
278
{
279
const character = makeCharacter(harness.stateDb, {
280
firstName: "Decay",
281
lastName: "Ing",
282
tileX: 5,
283
tileY: 5
284
});
285
const dayA = Date.parse("2026-03-01T12:00:00");
286
const dayC = Date.parse("2026-03-03T12:00:00");
287
harness.stateDb.addCharacterBounty(character.character_id, 10, dayA);
288
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, dayA), 10);
289
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, dayC), 8);
290
}
291
finally
292
{ harness.close(); }
293
});
@@ -77,7 +77,7 @@ test("raise bounty spends inventory coins and tracks ledger", () =>77
const snap = result.events.find((event) => event.type === "bounty-snapshot");77
const snap = result.events.find((event) => event.type === "bounty-snapshot");78
assert.ok(snap?.raised);78
assert.ok(snap?.raised);79
assert.equal(snap.raised.amountCopper, 250);79
assert.equal(snap.raised.amountCopper, 250);80
assert.equal(harness.stateDb.getCharacterBounty(target.character_id), 250);80
assert.equal(harness.stateDb.getCharacterBounty(target.character_id, harness.now()), 250);81
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 250);81
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 250);82
82
83
harness.simulation.enqueue(1, {83
harness.simulation.enqueue(1, {@@ -88,7 +88,7 @@ test("raise bounty spends inventory coins and tracks ledger", () =>88
amountCopper: 10088
amountCopper: 10089
});89
});90
harness.simulation.step();90
harness.simulation.step();91
assert.equal(harness.stateDb.getCharacterBounty(target.character_id), 350);91
assert.equal(harness.stateDb.getCharacterBounty(target.character_id, harness.now()), 350);92
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 150);92
assert.equal(countCoins(harness.simulation.bagOf(placerId).inventory), 150);93
}93
}94
finally94
finally@@ -150,7 +150,7 @@ test("PvP kill pays bounty into killer vault and clears ledger", () =>150
9150
9151
);151
);152
assert.equal(settled?.paidCopper, 400);152
assert.equal(settled?.paidCopper, 400);153
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id), 0);153
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id, harness.now()), 0);154
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 400);154
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 400);155
155
156
harness.stateDb.addKillCounter(killer.character_id, 500, harness.now());156
harness.stateDb.addKillCounter(killer.character_id, 500, harness.now());@@ -197,10 +197,97 @@ test("friend PvP kill does not pay or clear bounty", () =>197
9197
9198
);198
);199
assert.equal(settled, null);199
assert.equal(settled, null);200
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id), 400);200
assert.equal(harness.stateDb.getCharacterBounty(victim.character_id, harness.now()), 400);201
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 0);201
assert.equal(countCoins(harness.simulation.bagOf(killerId).vault), 0);202
assert.equal(harness.simulation.directory.get(victimId).skullValue, 400);202
assert.equal(harness.simulation.directory.get(victimId).skullValue, 400);203
}203
}204
finally204
finally205
{ harness.close(); }205
{ harness.close(); }206
});206
});207
208
test("pay off own bounty spends 10 coins per 1 bounty cleared", () =>209
{210
const harness = makeSimulation({ workerCount: 1 });211
try212
{213
placeBlock(harness.worldDb, 8, 8, BlockType.bountyOffice);214
harness.simulation.reloadWorld();215
const character = makeCharacter(harness.stateDb, {216
firstName: "Self",217
lastName: "Pay",218
tileX: 8,219
tileY: 9220
});221
harness.stateDb.addCharacterBounty(character.character_id, 25);222
const entityId = harness.simulation.spawnCharacter(1, character);223
giveCoins(harness, entityId, 100);224
225
harness.simulation.enqueue(1, {226
type: "pay-bounty",227
characterId: character.character_id,228
amountCopper: 100229
});230
const result = harness.simulation.step();231
const snap = result.events.find((event) => event.type === "bounty-snapshot");232
assert.ok(snap?.paidOff);233
assert.equal(snap.paidOff.clearedCopper, 10);234
assert.equal(snap.paidOff.spentCopper, 100);235
assert.equal(snap.myAmountCopper, 15);236
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, harness.now()), 15);237
assert.equal(countCoins(harness.simulation.bagOf(entityId).inventory), 0);238
assert.equal(harness.simulation.directory.get(entityId).skullValue, 15);239
}240
finally241
{ harness.close(); }242
});243
244
test("pay off caps at remaining bounty and spends only matching tens", () =>245
{246
const harness = makeSimulation({ workerCount: 1 });247
try248
{249
placeBlock(harness.worldDb, 8, 8, BlockType.bountyOffice);250
harness.simulation.reloadWorld();251
const character = makeCharacter(harness.stateDb, {252
firstName: "Cap",253
lastName: "Pay",254
tileX: 8,255
tileY: 9256
});257
harness.stateDb.addCharacterBounty(character.character_id, 3);258
const entityId = harness.simulation.spawnCharacter(1, character);259
giveCoins(harness, entityId, 100);260
261
harness.simulation.enqueue(1, {262
type: "pay-bounty",263
characterId: character.character_id,264
amountCopper: 100265
});266
harness.simulation.step();267
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, harness.now()), 0);268
assert.equal(countCoins(harness.simulation.bagOf(entityId).inventory), 70);269
}270
finally271
{ harness.close(); }272
});273
274
test("bounty decays one coin per calendar day", () =>275
{276
const harness = makeSimulation({ workerCount: 1 });277
try278
{279
const character = makeCharacter(harness.stateDb, {280
firstName: "Decay",281
lastName: "Ing",282
tileX: 5,283
tileY: 5284
});285
const dayA = Date.parse("2026-03-01T12:00:00");286
const dayC = Date.parse("2026-03-03T12:00:00");287
harness.stateDb.addCharacterBounty(character.character_id, 10, dayA);288
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, dayA), 10);289
assert.equal(harness.stateDb.getCharacterBounty(character.character_id, dayC), 8);290
}291
finally292
{ harness.close(); }293
});@@ -46,6 +46,11 @@ test("countdown formatting", () =>
46
46
assert.equal(formatRestartCountdown(45_000), "45s");
47
47
assert.equal(formatRestartCountdown(125_000), "2m 05s");
48
48
assert.match(restartCountdownMessage(3_600_000), /1h 00m 00s/);
49
const scheduledAt = Date.now() + 90_000;
50
assert.match(
51
restartCountdownMessage(Math.max(0, scheduledAt - Date.now())),
52
/1m \d{2}s/
53
);
49
54
});
50
55
51
56
test("restart manifest write read consume is atomic-ish", () =>
@@ -46,6 +46,11 @@ test("countdown formatting", () =>46
assert.equal(formatRestartCountdown(45_000), "45s");46
assert.equal(formatRestartCountdown(45_000), "45s");47
assert.equal(formatRestartCountdown(125_000), "2m 05s");47
assert.equal(formatRestartCountdown(125_000), "2m 05s");48
assert.match(restartCountdownMessage(3_600_000), /1h 00m 00s/);48
assert.match(restartCountdownMessage(3_600_000), /1h 00m 00s/);49
const scheduledAt = Date.now() + 90_000;50
assert.match(51
restartCountdownMessage(Math.max(0, scheduledAt - Date.now())),52
/1m \d{2}s/53
);49
});54
});50
55
51
test("restart manifest write read consume is atomic-ish", () =>56
test("restart manifest write read consume is atomic-ish", () =>