Deliver gift letters by pigeon to the character on login.
System letters were held as bank destinations while offline, so login deposited them in the vault instead of flying to the player.
@@ -177,34 +177,24 @@ export class CourierService
177
177
}
178
178
179
179
/**
180
* System letters (CE / bank / bounty): to inventory while online (bank if full),
181
* or straight to the bank vault while offline.
180
* System letters (gift / CE / bounty): pigeon to the player (inventory; bank if full).
181
* While offline, hold with player destination so login flies from the bank to the character
182
* — never deposit the letter straight into the vault.
182
183
*/
183
184
dispatchSystemLetter ({ characterId, originTileX, originTileY, stack })
184
185
{
185
186
const recipientId = characterId | 0;
186
187
const cargo = { kind: "item", stack };
187
if (this.simulation.isCharacterOnline(recipientId))
188
{
189
const row = this.stateDb.getCharacter(recipientId);
190
return this.dispatchHeldCargo({
191
senderCharacterId: recipientId,
192
originTileX,
193
originTileY,
194
destination: {
195
kind: "player",
196
firstName: row?.first_name ?? "Unknown",
197
lastName: row?.last_name ?? ""
198
},
199
cargo,
200
vaultCharacterId: recipientId
201
});
202
}
188
const row = this.stateDb.getCharacter(recipientId);
203
189
return this.dispatchHeldCargo({
204
190
senderCharacterId: recipientId,
205
191
originTileX,
206
192
originTileY,
207
destination: { kind: "bank" },
193
destination: {
194
kind: "player",
195
firstName: row?.first_name ?? "Unknown",
196
lastName: row?.last_name ?? ""
197
},
208
198
cargo,
209
199
vaultCharacterId: recipientId
210
200
});
@@ -213,6 +203,8 @@ export class CourierService
213
203
/**
214
204
* Market / system dispatch already holding cargo (no bag take).
215
205
* When the recipient is offline, holds delivery until login (CE letters, etc.).
206
* Player-bound holds keep destinationKind "player" even though resolve would route to bank
207
* while offline — on login the pigeon then delivers to the character, not the vault.
216
208
*/
217
209
dispatchHeldCargo ({ senderCharacterId, originTileX, originTileY, destination, cargo, vaultCharacterId = null })
218
210
{
@@ -220,12 +212,13 @@ export class CourierService
220
212
if (!this.simulation.isCharacterOnline(recipientId))
221
213
{
222
214
const dest = this.#resolveDestination(destination, originTileX, originTileY);
215
const intendedKind = destination?.kind === "player" ? "player" : dest.kind;
223
216
this.stateDb.insertHeldCourierDelivery({
224
217
characterId: recipientId,
225
218
senderCharacterId,
226
219
originTileX,
227
220
originTileY,
228
destinationKind: dest.kind,
221
destinationKind: intendedKind,
229
222
destinationCharacterId: dest.characterId ?? recipientId,
230
223
vaultCharacterId: vaultCharacterId ?? dest.vaultCharacterId ?? recipientId,
231
224
cargo
@@ -177,34 +177,24 @@ export class CourierService177
}177
}178
178
179
/**179
/**180
* System letters (CE / bank / bounty): to inventory while online (bank if full),180
* System letters (gift / CE / bounty): pigeon to the player (inventory; bank if full).181
* or straight to the bank vault while offline.181
* While offline, hold with player destination so login flies from the bank to the character182
* — never deposit the letter straight into the vault.182
*/183
*/183
dispatchSystemLetter ({ characterId, originTileX, originTileY, stack })184
dispatchSystemLetter ({ characterId, originTileX, originTileY, stack })184
{185
{185
const recipientId = characterId | 0;186
const recipientId = characterId | 0;186
const cargo = { kind: "item", stack };187
const cargo = { kind: "item", stack };187
if (this.simulation.isCharacterOnline(recipientId))188
const row = this.stateDb.getCharacter(recipientId);188
{189
const row = this.stateDb.getCharacter(recipientId);190
return this.dispatchHeldCargo({191
senderCharacterId: recipientId,192
originTileX,193
originTileY,194
destination: {195
kind: "player",196
firstName: row?.first_name ?? "Unknown",197
lastName: row?.last_name ?? ""198
},199
cargo,200
vaultCharacterId: recipientId201
});202
}203
return this.dispatchHeldCargo({189
return this.dispatchHeldCargo({204
senderCharacterId: recipientId,190
senderCharacterId: recipientId,205
originTileX,191
originTileX,206
originTileY,192
originTileY,207
destination: { kind: "bank" },193
destination: {194
kind: "player",195
firstName: row?.first_name ?? "Unknown",196
lastName: row?.last_name ?? ""197
},208
cargo,198
cargo,209
vaultCharacterId: recipientId199
vaultCharacterId: recipientId210
});200
});@@ -213,6 +203,8 @@ export class CourierService213
/**203
/**214
* Market / system dispatch already holding cargo (no bag take).204
* Market / system dispatch already holding cargo (no bag take).215
* When the recipient is offline, holds delivery until login (CE letters, etc.).205
* When the recipient is offline, holds delivery until login (CE letters, etc.).206
* Player-bound holds keep destinationKind "player" even though resolve would route to bank207
* while offline — on login the pigeon then delivers to the character, not the vault.216
*/208
*/217
dispatchHeldCargo ({ senderCharacterId, originTileX, originTileY, destination, cargo, vaultCharacterId = null })209
dispatchHeldCargo ({ senderCharacterId, originTileX, originTileY, destination, cargo, vaultCharacterId = null })218
{210
{@@ -220,12 +212,13 @@ export class CourierService220
if (!this.simulation.isCharacterOnline(recipientId))212
if (!this.simulation.isCharacterOnline(recipientId))221
{213
{222
const dest = this.#resolveDestination(destination, originTileX, originTileY);214
const dest = this.#resolveDestination(destination, originTileX, originTileY);215
const intendedKind = destination?.kind === "player" ? "player" : dest.kind;223
this.stateDb.insertHeldCourierDelivery({216
this.stateDb.insertHeldCourierDelivery({224
characterId: recipientId,217
characterId: recipientId,225
senderCharacterId,218
senderCharacterId,226
originTileX,219
originTileX,227
originTileY,220
originTileY,228
destinationKind: dest.kind,221
destinationKind: intendedKind,229
destinationCharacterId: dest.characterId ?? recipientId,222
destinationCharacterId: dest.characterId ?? recipientId,230
vaultCharacterId: vaultCharacterId ?? dest.vaultCharacterId ?? recipientId,223
vaultCharacterId: vaultCharacterId ?? dest.vaultCharacterId ?? recipientId,231
cargo224
cargo@@ -18,7 +18,7 @@ import { originLabel, ItemOriginKind, CraftOriginVerb, GatherOriginVerb } from "
18
18
import { BlockType } from "../../shared/definitions/tiles.js";
19
19
import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";
20
20
import { GiftService } from "../src/gifts/service.js";
21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
21
import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";
22
22
23
23
function placeBank (worldDb, tileX, tileY)
24
24
{
@@ -124,6 +124,12 @@ test("admin gift credits bank and queues a system letter", () =>
124
124
{
125
125
placeBank(harness.worldDb, 8, 8);
126
126
harness.simulation.courier.refreshBankIndex();
127
harness.simulation.applySettings({
128
pigeonTakeoffTilesPerSec: 40,
129
pigeonCruiseTilesPerSec: 40,
130
pigeonLandingTilesPerSec: 40,
131
simulationTickHz: 20
132
});
127
133
128
134
const character = makeCharacter(harness.stateDb, {
129
135
tileX: 8,
@@ -152,12 +158,38 @@ test("admin gift credits bank and queues a system letter", () =>
152
158
originLabel(stickStack?.origins?.[0]?.origin),
153
159
"Carved by John Questward"
154
160
);
161
assert.equal(
162
(after.vault ?? []).some((slot) => slot?.itemId === ItemId.letter),
163
false,
164
"gift letter must not be deposited in the bank"
165
);
155
166
156
167
const held = harness.stateDb.listHeldCourierDeliveries(character.character_id);
157
const foundHeld = held.some((row) =>
168
const giftHold = held.find((row) =>
158
169
row.cargo?.stack?.instance?.authorDisplayName === QUESTWARD_GIFT_AUTHOR
159
170
);
160
assert.ok(foundHeld, "expected a held gift letter for the offline character");
171
assert.ok(giftHold, "expected a held gift letter for the offline character");
172
assert.equal(giftHold.destinationKind, "player");
173
174
const entityId = harness.simulation.spawnCharacter(1, character);
175
const active = harness.stateDb.listActiveCourierTransits();
176
assert.equal(active.length, 1);
177
assert.equal(active[0].destinationKind, "player");
178
assert.equal(active[0].cargo.stack.instance.authorDisplayName, QUESTWARD_GIFT_AUTHOR);
179
180
stepTimes(harness.simulation, 40);
181
182
const bag = harness.simulation.bagOf(entityId);
183
const letter = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.letter);
184
assert.ok(letter, "gift letter should arrive in inventory via pigeon");
185
assert.equal(letter.instance.authorDisplayName, QUESTWARD_GIFT_AUTHOR);
186
assert.equal(letter.instance.authorOrganization, QUESTWARD_GIFT_ORG);
187
assert.match(letter.instance.body, /A small thank-you/);
188
assert.equal(
189
(harness.stateDb.getBag(character.character_id).vault ?? [])
190
.some((slot) => slot?.itemId === ItemId.letter),
191
false
192
);
161
193
}
162
194
finally
163
195
{ harness.close(); }
@@ -18,7 +18,7 @@ import { originLabel, ItemOriginKind, CraftOriginVerb, GatherOriginVerb } from "18
import { BlockType } from "../../shared/definitions/tiles.js";18
import { BlockType } from "../../shared/definitions/tiles.js";19
import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";19
import { createEmptyChunkData, encodeChunkBlob, decodeChunkBlob } from "../src/world/chunkData.js";20
import { GiftService } from "../src/gifts/service.js";20
import { GiftService } from "../src/gifts/service.js";21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";21
import { makeCharacter, makeSimulation, stepTimes } from "./helpers/simulationHarness.js";22
22
23
function placeBank (worldDb, tileX, tileY)23
function placeBank (worldDb, tileX, tileY)24
{24
{@@ -124,6 +124,12 @@ test("admin gift credits bank and queues a system letter", () =>124
{124
{125
placeBank(harness.worldDb, 8, 8);125
placeBank(harness.worldDb, 8, 8);126
harness.simulation.courier.refreshBankIndex();126
harness.simulation.courier.refreshBankIndex();127
harness.simulation.applySettings({128
pigeonTakeoffTilesPerSec: 40,129
pigeonCruiseTilesPerSec: 40,130
pigeonLandingTilesPerSec: 40,131
simulationTickHz: 20132
});127
133
128
const character = makeCharacter(harness.stateDb, {134
const character = makeCharacter(harness.stateDb, {129
tileX: 8,135
tileX: 8,@@ -152,12 +158,38 @@ test("admin gift credits bank and queues a system letter", () =>152
originLabel(stickStack?.origins?.[0]?.origin),158
originLabel(stickStack?.origins?.[0]?.origin),153
"Carved by John Questward"159
"Carved by John Questward"154
);160
);161
assert.equal(162
(after.vault ?? []).some((slot) => slot?.itemId === ItemId.letter),163
false,164
"gift letter must not be deposited in the bank"165
);155
166
156
const held = harness.stateDb.listHeldCourierDeliveries(character.character_id);167
const held = harness.stateDb.listHeldCourierDeliveries(character.character_id);157
const foundHeld = held.some((row) =>168
const giftHold = held.find((row) =>158
row.cargo?.stack?.instance?.authorDisplayName === QUESTWARD_GIFT_AUTHOR169
row.cargo?.stack?.instance?.authorDisplayName === QUESTWARD_GIFT_AUTHOR159
);170
);160
assert.ok(foundHeld, "expected a held gift letter for the offline character");171
assert.ok(giftHold, "expected a held gift letter for the offline character");172
assert.equal(giftHold.destinationKind, "player");173
174
const entityId = harness.simulation.spawnCharacter(1, character);175
const active = harness.stateDb.listActiveCourierTransits();176
assert.equal(active.length, 1);177
assert.equal(active[0].destinationKind, "player");178
assert.equal(active[0].cargo.stack.instance.authorDisplayName, QUESTWARD_GIFT_AUTHOR);179
180
stepTimes(harness.simulation, 40);181
182
const bag = harness.simulation.bagOf(entityId);183
const letter = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.letter);184
assert.ok(letter, "gift letter should arrive in inventory via pigeon");185
assert.equal(letter.instance.authorDisplayName, QUESTWARD_GIFT_AUTHOR);186
assert.equal(letter.instance.authorOrganization, QUESTWARD_GIFT_ORG);187
assert.match(letter.instance.body, /A small thank-you/);188
assert.equal(189
(harness.stateDb.getBag(character.character_id).vault ?? [])190
.some((slot) => slot?.itemId === ItemId.letter),191
false192
);161
}193
}162
finally194
finally163
{ harness.close(); }195
{ harness.close(); }