mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-12-05 11:40:31 -06:00
index.ts now only registers settings and routes. Handlers are grouped by part of the game (version, card, key, print, play, item, gift), the stored documents live in models/, and the closet, player creation, db access, game data and helpers each have their own file. No behavior change: the test flow gives the same results.
32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
// The key card (ニャンドラのカギ): a second printed card tied to the player.
|
|
import { accessoryNode, EMPTY_ACCESSORY, makeAccessory } from '../closet';
|
|
import { FIRST_KEY_ACCESSORY } from '../data';
|
|
import { getUser, newId, saveUser } from '../db';
|
|
import { log } from '../utils';
|
|
|
|
export const checkKeyUser: EPR = async (info, data, send) => {
|
|
const u = await getUser($(data).number('user_seq'));
|
|
const keycard_id = $(data).str('keycard_id', '');
|
|
if (!u || !u.keycard_id || u.keycard_id !== keycard_id) {
|
|
log('checkKeyUser: not this user\'s key', { keycard_id, bound: u && u.keycard_id });
|
|
return send.status(10); // the game shows "key does not match" and lets the player rescan
|
|
}
|
|
send.object({ keycard_id: K.ITEM('str', u.keycard_id), key_inquire_id: K.ITEM('str', u.key_inquire_id) });
|
|
};
|
|
|
|
// A new key replaces the old one (first key or "remake"). The id goes into the key card's QR.
|
|
export const bindKeyUser: EPR = async (info, data, send) => {
|
|
const u = await getUser($(data).number('user_seq'));
|
|
if (!u) return send.deny();
|
|
u.keycard_id = await newId();
|
|
u.key_inquire_id = await newId();
|
|
// the first key comes with the tailor tutorial's result; the game adds it only when is_first is set
|
|
const bonus = $(data).bool('is_first') ? makeAccessory(u, FIRST_KEY_ACCESSORY, 0) : EMPTY_ACCESSORY;
|
|
await saveUser(u);
|
|
send.object({
|
|
keycard_id: K.ITEM('str', u.keycard_id),
|
|
key_inquire_id: K.ITEM('str', u.key_inquire_id),
|
|
accessory: accessoryNode(bonus),
|
|
});
|
|
};
|