magpie-digital-pet 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ import { fileURLToPath } from "node:url";
24
24
  import { Database } from "bun:sqlite";
25
25
  import { plugin as createOpenCodePetPlugin, DIGIMON_DATA } from "@jcendal/opencode-digital-pet";
26
26
  import { DIFFICULTY_KNOWN } from "./pet.care-store.mjs";
27
- import { decayCareState, evaluatePetStatuses } from "./pet.care-rules.mjs";
27
+ import { createDefaultCareState, decayCareState, evaluatePetStatuses } from "./pet.care-rules.mjs";
28
28
 
29
29
  export { DIGIMON_DATA };
30
30
 
@@ -185,33 +185,48 @@ export function createPetAdapter({ databasePath, dbPath, notifyGate } = {}) {
185
185
  const row = roDb
186
186
  .query("SELECT * FROM magpie_pet_care_state WHERE partner_id = ?")
187
187
  .get(partner.partner_id);
188
- if (!row) return 1;
189
- const decayed = decayCareState(
190
- {
191
- partnerId: row.partner_id,
192
- satiety: row.satiety,
193
- mood: row.mood,
194
- energy: row.energy,
195
- hygiene: row.hygiene,
196
- bond: row.bond,
197
- cooldowns: {
198
- snack: row.cooldown_snack ?? 0,
199
- play: row.cooldown_play ?? 0,
200
- clean: row.cooldown_clean ?? 0,
201
- rest: row.cooldown_rest ?? 0,
202
- petEgg: row.cooldown_pet_egg ?? 0,
203
- pet: row.cooldown_pet ?? 0,
204
- },
205
- burstUses: {
206
- snack: row.snack_burst_used ?? 0,
207
- play: row.play_burst_used ?? 0,
208
- },
209
- lastDecayAt: row.last_decay_at,
210
- updatedAt: row.updated_at,
211
- },
212
- Date.now(),
213
- );
214
- return evaluatePetStatuses(decayed).xpMultiplier;
188
+ const nowMs = Date.now();
189
+ const decayed = row
190
+ ? decayCareState(
191
+ {
192
+ partnerId: row.partner_id,
193
+ satiety: row.satiety,
194
+ mood: row.mood,
195
+ energy: row.energy,
196
+ hygiene: row.hygiene,
197
+ bond: row.bond,
198
+ cooldowns: {
199
+ snack: row.cooldown_snack ?? 0,
200
+ play: row.cooldown_play ?? 0,
201
+ clean: row.cooldown_clean ?? 0,
202
+ rest: row.cooldown_rest ?? 0,
203
+ petEgg: row.cooldown_pet_egg ?? 0,
204
+ pet: row.cooldown_pet ?? 0,
205
+ },
206
+ burstUses: {
207
+ snack: row.snack_burst_used ?? 0,
208
+ play: row.play_burst_used ?? 0,
209
+ },
210
+ lastDecayAt: row.last_decay_at,
211
+ updatedAt: row.updated_at,
212
+ },
213
+ nowMs,
214
+ )
215
+ : createDefaultCareState(partner.partner_id, nowMs);
216
+ let activeBuffs = [];
217
+ try {
218
+ activeBuffs = roDb
219
+ .query(
220
+ `SELECT buff_id AS id, label, xp_multiplier AS xpMultiplier,
221
+ expedition_bonus AS expeditionBonus, tip, granted_at AS grantedAt, expires_at AS expiresAt
222
+ FROM magpie_pet_buffs
223
+ WHERE partner_id = ? AND expires_at > ?`,
224
+ )
225
+ .all(partner.partner_id, nowMs);
226
+ } catch {
227
+ activeBuffs = [];
228
+ }
229
+ return evaluatePetStatuses(decayed, activeBuffs, nowMs).xpMultiplier;
215
230
  } catch {
216
231
  return 1;
217
232
  }