@opfr/entities 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.
package/dist/index.es.js CHANGED
@@ -1,14 +1,18 @@
1
- import { t as H } from "i18next";
2
- import { entityService as p, userCrewService as N, crewService as F, crewMetaService as G, userCooldownService as K, userMetaService as _, userOrnamentService as h, userInventoryService as g, userStatsInventoryService as A, panoplyService as V, ornamentService as u } from "@opfr/services";
1
+ import { t as L } from "i18next";
2
+ import { entityService as p, userCrewService as X, crewService as F, crewMetaService as G, userCooldownService as K, userMetaService as _, userOrnamentService as h, userInventoryService as g, userStatsInventoryService as A, panoplyService as V, ornamentService as u } from "@opfr/services";
3
3
  import { isString as J, pickFromNth as O, recordToArray as Y, groupBy as y, mergeObjects as $, randomBetween as d, pickFrom as T, includeArrayIf as M, includeIf as v, filterNullAndUndefined as S } from "@opfr/utils-lang";
4
4
  const rt = async (e, a = 0) => {
5
5
  const r = J(e) ? await p.get(e) : e;
6
- return r ? H(r.name.key, {
6
+ return r ? L(r.name.key, {
7
7
  ns: "entities",
8
8
  count: a,
9
9
  context: r.name.context
10
10
  }) : "";
11
- }, z = (e) => O(
11
+ }, at = (e, a = 0) => e ? L(e.name.key, {
12
+ ns: "entities",
13
+ count: a,
14
+ context: e.name.context
15
+ }) : "", z = (e) => O(
12
16
  ["bottle_xp_2_berry", "bottle_xp_2_casino", "bottle_xp_2_work"],
13
17
  e
14
18
  ), Q = (e) => O(
@@ -33,7 +37,7 @@ const rt = async (e, a = 0) => {
33
37
  0.15: [],
34
38
  0.04: [],
35
39
  0.01: []
36
- }, at = {
40
+ }, ot = {
37
41
  OPEN_CHEST: async (e, a, r, o) => {
38
42
  const t = {
39
43
  berry: 0,
@@ -63,17 +67,17 @@ const rt = async (e, a = 0) => {
63
67
  p.isRepairItem
64
68
  ), b = await p.getAllEntitiesBy(
65
69
  p.isStoreItem
66
- ), x = await V.getPopulated("adventurer"), L = await u.getAllTitles(), U = await u.getAllBackgrounds();
70
+ ), x = await V.getPopulated("adventurer"), U = await u.getAllTitles(), W = await u.getAllBackgrounds();
67
71
  for (let m = 0; m < o; m++) {
68
- const [B, W] = r.berry, { bottle_xp_1: w, bottle_xp_2: k, bottle_xp_3: j } = r.xp, { odds: s } = r, D = L.filter(
72
+ const [B, j] = r.berry, { bottle_xp_1: w, bottle_xp_2: k, bottle_xp_3: H } = r.xp, { odds: s } = r, D = U.filter(
69
73
  (n) => !l.unlockedTitles.includes(n.ornamentId)
70
- ), X = U.filter(
74
+ ), N = W.filter(
71
75
  (n) => !l.unlockedBackgrounds.includes(n.ornamentId)
72
76
  );
73
- t.berry += d(B, W + 1), t.xp.bottle_xp_1 += w ? Array.isArray(w) ? d(w[0], w[1] + 1) : w : 0;
77
+ t.berry += d(B, j + 1), t.xp.bottle_xp_1 += w ? Array.isArray(w) ? d(w[0], w[1] + 1) : w : 0;
74
78
  const C = z(
75
79
  k ? Array.isArray(k) ? d(k[0], k[1]) : k : 0
76
- ), R = Q(j ?? 0);
80
+ ), R = Q(H ?? 0);
77
81
  t.xp.bottle_xp_2_berry += C.bottle_xp_2_berry ?? 0, t.xp.bottle_xp_2_work += C.bottle_xp_2_work ?? 0, t.xp.bottle_xp_2_casino += C.bottle_xp_2_casino ?? 0, t.xp.bottle_xp_3_berry += R.bottle_xp_3_berry ?? 0, t.xp.bottle_xp_3_work += R.bottle_xp_3_work ?? 0, t.xp.bottle_xp_3_casino += R.bottle_xp_3_casino ?? 0;
78
82
  const { sugar_cane: f } = r;
79
83
  t.sugar_cane = f ? Array.isArray(f) ? d(f[0], f[1]) : f : 0, s.essence > 1 ? t.essence.push(
@@ -109,7 +113,7 @@ const rt = async (e, a = 0) => {
109
113
  ), t.background = Array.isArray(s.background) ? M(
110
114
  t.background,
111
115
  u.pickEachRarityOrnament(
112
- y(X, (n) => n.rankId),
116
+ y(N, (n) => n.rankId),
113
117
  s.background
114
118
  ),
115
119
  !0
@@ -117,7 +121,7 @@ const rt = async (e, a = 0) => {
117
121
  t.background,
118
122
  u.pickOrnament({
119
123
  ...P,
120
- ...y(X, (n) => n.odd ?? 0)
124
+ ...y(N, (n) => n.odd ?? 0)
121
125
  }),
122
126
  Math.random() < s.background
123
127
  );
@@ -260,19 +264,20 @@ const rt = async (e, a = 0) => {
260
264
  await K.reduceRaidCooldown(e, r.hours);
261
265
  },
262
266
  CREW_XP_BUFF: async (e, a, { hours: r }, o) => {
263
- const t = await N.get(e);
267
+ const t = await X.get(e);
264
268
  if (!t)
265
269
  throw new Error("no crew");
266
270
  await G.addXpBuff(t.crew._id, r * o);
267
271
  },
268
272
  CREW_REPAIR: async (e, a, { amount: r }, o) => {
269
- const t = await N.get(e);
273
+ const t = await X.get(e);
270
274
  if (!t)
271
275
  throw new Error("no crew");
272
276
  return await F.repair(t.crew._id, r * o), r * o;
273
277
  }
274
278
  };
275
279
  export {
276
- at as HANDLERS,
277
- rt as getEntityName
280
+ ot as HANDLERS,
281
+ at as getEntityName,
282
+ rt as getEntityNameAsync
278
283
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("i18next"),require("@opfr/services"),require("@opfr/utils-lang")):typeof define=="function"&&define.amd?define(["exports","i18next","@opfr/services","@opfr/utils-lang"],y):(s=typeof globalThis<"u"?globalThis:s||self,y(s.entities={},s.i18next,s["@opfr/services"],s["@opfr/utils-lang"]))})(this,(function(s,y,r,a){"use strict";const M=async(t,n=0)=>{const o=a.isString(t)?await r.entityService.get(t):t;return o?y.t(o.name.key,{ns:"entities",count:n,context:o.name.context}):""},C=t=>a.pickFromNth(["bottle_xp_2_berry","bottle_xp_2_casino","bottle_xp_2_work"],t),N=t=>a.pickFromNth(["bottle_xp_3_berry","bottle_xp_3_casino","bottle_xp_3_work"],t),g=t=>Promise.all(a.recordToArray(a.pickFromNth(["anchor","sailing_boat","rescue_boat","rudder","hammock"],t)).reduce((n,[o,i])=>n.concat(new Array(i).fill(o)),[]).map(n=>r.entityService.get(n))),S=t=>{const n=a.groupBy(t,([o])=>o.entityId);return Object.values(n).map(o=>[o[0][0],o.reduce((i,[,e])=>i+e,0)])},k=t=>t.map(([{entityId:n},o])=>[n,o]),B={.5:[],.3:[],.15:[],.04:[],.01:[]},R={OPEN_CHEST:async(t,n,o,i)=>{const e={berry:0,xp:{bottle_xp_1:0,bottle_xp_2_berry:0,bottle_xp_2_casino:0,bottle_xp_2_work:0,bottle_xp_3_berry:0,bottle_xp_3_casino:0,bottle_xp_3_work:0},sugar_cane:0,title:[],background:[],boostXpWeek:0,boostXpDay:0,emptyChest:0,repairItem:[],shopItem:[],raidItem:[],adventurer:[],essence:[]},d=await r.userOrnamentService.get(t),_=await r.entityService.getAllEntitiesBy(r.entityService.isObjectItem),l=await r.entityService.getAllEntitiesBy(r.entityService.isRepairItem),m=await r.entityService.getAllEntitiesBy(r.entityService.isStoreItem),u=await r.panoplyService.getPopulated("adventurer"),v=await r.ornamentService.getAllTitles(),D=await r.ornamentService.getAllBackgrounds();for(let b=0;b<i;b++){const[h,T]=o.berry,{bottle_xp_1:w,bottle_xp_2:x,bottle_xp_3:X}=o.xp,{odds:p}=o,O=v.filter(c=>!d.unlockedTitles.includes(c.ornamentId)),E=D.filter(c=>!d.unlockedBackgrounds.includes(c.ornamentId));e.berry+=a.randomBetween(h,T+1),e.xp.bottle_xp_1+=w?Array.isArray(w)?a.randomBetween(w[0],w[1]+1):w:0;const A=C(x?Array.isArray(x)?a.randomBetween(x[0],x[1]):x:0),I=N(X??0);e.xp.bottle_xp_2_berry+=A.bottle_xp_2_berry??0,e.xp.bottle_xp_2_work+=A.bottle_xp_2_work??0,e.xp.bottle_xp_2_casino+=A.bottle_xp_2_casino??0,e.xp.bottle_xp_3_berry+=I.bottle_xp_3_berry??0,e.xp.bottle_xp_3_work+=I.bottle_xp_3_work??0,e.xp.bottle_xp_3_casino+=I.bottle_xp_3_casino??0;const{sugar_cane:f}=o;e.sugar_cane=f?Array.isArray(f)?a.randomBetween(f[0],f[1]):f:0,p.essence>1?e.essence.push(...await r.entityService.recordToEntityTuple(a.pickFromNth(_.map(({entityId:c})=>c).filter(c=>c.startsWith("essence_")),p.essence))):Math.random()<p.essence&&e.essence.push([a.pickFrom(_.filter(({entityId:c})=>c.startsWith("essence_"))),1]);try{e.title=Array.isArray(p.title)?a.includeArrayIf(e.title,r.ornamentService.pickEachRarityOrnament(a.groupBy(O,c=>c.rankId),p.title),!0):a.includeIf(e.title,r.ornamentService.pickOrnament({...B,...a.groupBy(O,c=>c.odd??0)}),Math.random()<p.title),e.background=Array.isArray(p.background)?a.includeArrayIf(e.background,r.ornamentService.pickEachRarityOrnament(a.groupBy(E,c=>c.rankId),p.background),!0):a.includeIf(e.background,r.ornamentService.pickOrnament({...B,...a.groupBy(E,c=>c.odd??0)}),Math.random()<p.background)}catch{console.warn(`<@${t}> can no longer obtain titles/backgrounds`)}e.boostXpWeek+=Array.isArray(p.boostXpWeek)?a.randomBetween(p.boostXpWeek[0],p.boostXpWeek[1]+1):+(Math.random()<p.boostXpWeek),e.boostXpDay+=+(Math.random()<p.boostXpDay),e.emptyChest+=+(Math.random()<p.emptyChest),e.repairItem=a.includeIf(e.repairItem,[l.filter(c=>c.entityId!=="repair_kit")[a.randomBetween(0,l.length-1)],a.randomBetween(1,o.tier*2+2)],Math.random()<p.repairItem),e.shopItem=e.shopItem.concat(r.ornamentService.pickEachRarityOrnament(a.groupBy(m,c=>c.rankId),p.shopItem).map(c=>[c,1])),e.raidItem=e.raidItem.concat(a.filterNullAndUndefined(await g(p.raidItem??0)).map(c=>[c,1])),p.adventurer&&e.adventurer.push(...Array.from({length:p.adventurer}).map(()=>r.entityService.seedEquipment(a.pickFrom(u?.equipments??[]),Date.now()-Math.round(Math.random()*1e3))))}return e.title=a.filterNullAndUndefined(e.title),e.background=a.filterNullAndUndefined(e.background),e.berry=await r.userMetaService.updateUserBerry(t,e.berry,!1),e.repairItem=S(e.repairItem),e.shopItem=S(e.shopItem),e.essence=S(e.essence),e.raidItem=S(e.raidItem),await r.userInventoryService.addItems(t,{bottle_xp_1:e.xp.bottle_xp_1,bottle_xp_2_berry:e.xp.bottle_xp_2_berry,bottle_xp_2_work:e.xp.bottle_xp_2_work,bottle_xp_2_casino:e.xp.bottle_xp_2_casino,bottle_xp_3_berry:e.xp.bottle_xp_3_berry,bottle_xp_3_work:e.xp.bottle_xp_3_work,bottle_xp_3_casino:e.xp.bottle_xp_3_casino,boost_xp_day:e.boostXpDay,boost_xp_week:e.boostXpWeek,sugar_cane_christmas:e.sugar_cane,empty_chest:e.emptyChest,...Object.fromEntries(k(e.repairItem)),...Object.fromEntries(k(e.shopItem)),...Object.fromEntries(k(e.essence)),...Object.fromEntries(k(e.raidItem))}),await r.userOrnamentService.unlockTitles(t,e.title.map(b=>b.ornamentId)),await r.userOrnamentService.unlockBackgrounds(t,e.background.map(b=>b.ornamentId)),await r.userInventoryService.addEquipments(t,e.adventurer.map(({entityId:b,seed:h})=>({entityId:b,seed:h}))),await r.userStatsInventoryService.incrementChestOpenedTotal(t,i),e},APPLY_BUFF:async(t,n,o,i)=>{for(let e=0;e<i;e++)await r.userMetaService.updateBuff(t,o)},ALCOHOL_DRINK:async(t,n,o,i)=>{await r.userStatsInventoryService.incrementAlcoholDrink(t,n.entityId,i)},BOOST:async(t,n,o,i)=>await r.userMetaService.updateBoost(t,(n.ms??0)*i)??new Date,DRINK_BOTTLE:async(t,n,o,i)=>{if(!r.entityService.isBottleItem(n))return;const e={buffs:[],xp:0,hp:0};n.bottle.tier===2&&await r.userMetaService.gainHp(t,50),n.bottle.tier===3&&await r.userMetaService.gainHp(t,100);for(let d=0;d<i;d++){const _=await r.userInventoryService.calcBottleMultiplier(t,n);if(e.buffs.push(..._),await r.userMetaService.updateBuff(t,_),Array.isArray(n.bottle.xp)){const[l,m]=n.bottle.xp;e.xp+=a.randomBetween(l,m+1)}else e.xp+=n.bottle.xp;e.hp+=n.bottle.hp??0}return await r.userStatsInventoryService.incrementBottleUsedToday(t,i),await r.userStatsInventoryService.incrementBottleUsedTotal(t,i),{xp:await r.userMetaService.updateUserXp(t,e.xp),buffs:e.buffs,hp:e.hp}},HEAL_HP:async(t,n,{amount:o},i)=>{await r.userMetaService.gainHp(t,o*i)},GAIN_XP:async(t,n,{amount:o},i)=>await r.userMetaService.updateUserXp(t,o*i),GAIN_RANDOM_XP:async(t,n,{amounts:[o,i],odd:e},d)=>{let _=0;for(let l=0;l<d;l++)_+=Math.random()<e?o:i;return await r.userMetaService.updateUserXp(t,_)},DROP:async(t,n,o,i)=>{const e=[];for(let _=0;_<i;_++){const l={};for(const m in o){const u=Math.random();l[m]=+(u<o[m])}e.push(l)}const d=e.reduce((_,l)=>a.mergeObjects(_,l,(m,u)=>m+u));return await r.userInventoryService.addItems(t,{...d}),d},CLEAR_HANGOVER:t=>{console.log(t)},UNLOCK_ASSET:async(t,n,o)=>{await r.userOrnamentService.unlockProfileAsset(t,o.assetId)},ADD_SCROLL_CHARAC:async(t,n,o)=>(await r.userMetaService.addScrollCharacteristic(t,o),o),RAID_REDUCE_COOLDOWN:async(t,n,o)=>{await r.userCooldownService.reduceRaidCooldown(t,o.hours)},CREW_XP_BUFF:async(t,n,{hours:o},i)=>{const e=await r.userCrewService.get(t);if(!e)throw new Error("no crew");await r.crewMetaService.addXpBuff(e.crew._id,o*i)},CREW_REPAIR:async(t,n,{amount:o},i)=>{const e=await r.userCrewService.get(t);if(!e)throw new Error("no crew");return await r.crewService.repair(e.crew._id,o*i),o*i}};s.HANDLERS=R,s.getEntityName=M,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(l,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("i18next"),require("@opfr/services"),require("@opfr/utils-lang")):typeof define=="function"&&define.amd?define(["exports","i18next","@opfr/services","@opfr/utils-lang"],y):(l=typeof globalThis<"u"?globalThis:l||self,y(l.entities={},l.i18next,l["@opfr/services"],l["@opfr/utils-lang"]))})(this,(function(l,y,r,a){"use strict";const M=async(t,n=0)=>{const o=a.isString(t)?await r.entityService.get(t):t;return o?y.t(o.name.key,{ns:"entities",count:n,context:o.name.context}):""},N=(t,n=0)=>t?y.t(t.name.key,{ns:"entities",count:n,context:t.name.context}):"",g=t=>a.pickFromNth(["bottle_xp_2_berry","bottle_xp_2_casino","bottle_xp_2_work"],t),C=t=>a.pickFromNth(["bottle_xp_3_berry","bottle_xp_3_casino","bottle_xp_3_work"],t),R=t=>Promise.all(a.recordToArray(a.pickFromNth(["anchor","sailing_boat","rescue_boat","rudder","hammock"],t)).reduce((n,[o,i])=>n.concat(new Array(i).fill(o)),[]).map(n=>r.entityService.get(n))),S=t=>{const n=a.groupBy(t,([o])=>o.entityId);return Object.values(n).map(o=>[o[0][0],o.reduce((i,[,e])=>i+e,0)])},k=t=>t.map(([{entityId:n},o])=>[n,o]),B={.5:[],.3:[],.15:[],.04:[],.01:[]},v={OPEN_CHEST:async(t,n,o,i)=>{const e={berry:0,xp:{bottle_xp_1:0,bottle_xp_2_berry:0,bottle_xp_2_casino:0,bottle_xp_2_work:0,bottle_xp_3_berry:0,bottle_xp_3_casino:0,bottle_xp_3_work:0},sugar_cane:0,title:[],background:[],boostXpWeek:0,boostXpDay:0,emptyChest:0,repairItem:[],shopItem:[],raidItem:[],adventurer:[],essence:[]},m=await r.userOrnamentService.get(t),_=await r.entityService.getAllEntitiesBy(r.entityService.isObjectItem),s=await r.entityService.getAllEntitiesBy(r.entityService.isRepairItem),d=await r.entityService.getAllEntitiesBy(r.entityService.isStoreItem),u=await r.panoplyService.getPopulated("adventurer"),D=await r.ornamentService.getAllTitles(),T=await r.ornamentService.getAllBackgrounds();for(let b=0;b<i;b++){const[h,X]=o.berry,{bottle_xp_1:w,bottle_xp_2:x,bottle_xp_3:P}=o.xp,{odds:p}=o,E=D.filter(c=>!m.unlockedTitles.includes(c.ornamentId)),O=T.filter(c=>!m.unlockedBackgrounds.includes(c.ornamentId));e.berry+=a.randomBetween(h,X+1),e.xp.bottle_xp_1+=w?Array.isArray(w)?a.randomBetween(w[0],w[1]+1):w:0;const A=g(x?Array.isArray(x)?a.randomBetween(x[0],x[1]):x:0),I=C(P??0);e.xp.bottle_xp_2_berry+=A.bottle_xp_2_berry??0,e.xp.bottle_xp_2_work+=A.bottle_xp_2_work??0,e.xp.bottle_xp_2_casino+=A.bottle_xp_2_casino??0,e.xp.bottle_xp_3_berry+=I.bottle_xp_3_berry??0,e.xp.bottle_xp_3_work+=I.bottle_xp_3_work??0,e.xp.bottle_xp_3_casino+=I.bottle_xp_3_casino??0;const{sugar_cane:f}=o;e.sugar_cane=f?Array.isArray(f)?a.randomBetween(f[0],f[1]):f:0,p.essence>1?e.essence.push(...await r.entityService.recordToEntityTuple(a.pickFromNth(_.map(({entityId:c})=>c).filter(c=>c.startsWith("essence_")),p.essence))):Math.random()<p.essence&&e.essence.push([a.pickFrom(_.filter(({entityId:c})=>c.startsWith("essence_"))),1]);try{e.title=Array.isArray(p.title)?a.includeArrayIf(e.title,r.ornamentService.pickEachRarityOrnament(a.groupBy(E,c=>c.rankId),p.title),!0):a.includeIf(e.title,r.ornamentService.pickOrnament({...B,...a.groupBy(E,c=>c.odd??0)}),Math.random()<p.title),e.background=Array.isArray(p.background)?a.includeArrayIf(e.background,r.ornamentService.pickEachRarityOrnament(a.groupBy(O,c=>c.rankId),p.background),!0):a.includeIf(e.background,r.ornamentService.pickOrnament({...B,...a.groupBy(O,c=>c.odd??0)}),Math.random()<p.background)}catch{console.warn(`<@${t}> can no longer obtain titles/backgrounds`)}e.boostXpWeek+=Array.isArray(p.boostXpWeek)?a.randomBetween(p.boostXpWeek[0],p.boostXpWeek[1]+1):+(Math.random()<p.boostXpWeek),e.boostXpDay+=+(Math.random()<p.boostXpDay),e.emptyChest+=+(Math.random()<p.emptyChest),e.repairItem=a.includeIf(e.repairItem,[s.filter(c=>c.entityId!=="repair_kit")[a.randomBetween(0,s.length-1)],a.randomBetween(1,o.tier*2+2)],Math.random()<p.repairItem),e.shopItem=e.shopItem.concat(r.ornamentService.pickEachRarityOrnament(a.groupBy(d,c=>c.rankId),p.shopItem).map(c=>[c,1])),e.raidItem=e.raidItem.concat(a.filterNullAndUndefined(await R(p.raidItem??0)).map(c=>[c,1])),p.adventurer&&e.adventurer.push(...Array.from({length:p.adventurer}).map(()=>r.entityService.seedEquipment(a.pickFrom(u?.equipments??[]),Date.now()-Math.round(Math.random()*1e3))))}return e.title=a.filterNullAndUndefined(e.title),e.background=a.filterNullAndUndefined(e.background),e.berry=await r.userMetaService.updateUserBerry(t,e.berry,!1),e.repairItem=S(e.repairItem),e.shopItem=S(e.shopItem),e.essence=S(e.essence),e.raidItem=S(e.raidItem),await r.userInventoryService.addItems(t,{bottle_xp_1:e.xp.bottle_xp_1,bottle_xp_2_berry:e.xp.bottle_xp_2_berry,bottle_xp_2_work:e.xp.bottle_xp_2_work,bottle_xp_2_casino:e.xp.bottle_xp_2_casino,bottle_xp_3_berry:e.xp.bottle_xp_3_berry,bottle_xp_3_work:e.xp.bottle_xp_3_work,bottle_xp_3_casino:e.xp.bottle_xp_3_casino,boost_xp_day:e.boostXpDay,boost_xp_week:e.boostXpWeek,sugar_cane_christmas:e.sugar_cane,empty_chest:e.emptyChest,...Object.fromEntries(k(e.repairItem)),...Object.fromEntries(k(e.shopItem)),...Object.fromEntries(k(e.essence)),...Object.fromEntries(k(e.raidItem))}),await r.userOrnamentService.unlockTitles(t,e.title.map(b=>b.ornamentId)),await r.userOrnamentService.unlockBackgrounds(t,e.background.map(b=>b.ornamentId)),await r.userInventoryService.addEquipments(t,e.adventurer.map(({entityId:b,seed:h})=>({entityId:b,seed:h}))),await r.userStatsInventoryService.incrementChestOpenedTotal(t,i),e},APPLY_BUFF:async(t,n,o,i)=>{for(let e=0;e<i;e++)await r.userMetaService.updateBuff(t,o)},ALCOHOL_DRINK:async(t,n,o,i)=>{await r.userStatsInventoryService.incrementAlcoholDrink(t,n.entityId,i)},BOOST:async(t,n,o,i)=>await r.userMetaService.updateBoost(t,(n.ms??0)*i)??new Date,DRINK_BOTTLE:async(t,n,o,i)=>{if(!r.entityService.isBottleItem(n))return;const e={buffs:[],xp:0,hp:0};n.bottle.tier===2&&await r.userMetaService.gainHp(t,50),n.bottle.tier===3&&await r.userMetaService.gainHp(t,100);for(let m=0;m<i;m++){const _=await r.userInventoryService.calcBottleMultiplier(t,n);if(e.buffs.push(..._),await r.userMetaService.updateBuff(t,_),Array.isArray(n.bottle.xp)){const[s,d]=n.bottle.xp;e.xp+=a.randomBetween(s,d+1)}else e.xp+=n.bottle.xp;e.hp+=n.bottle.hp??0}return await r.userStatsInventoryService.incrementBottleUsedToday(t,i),await r.userStatsInventoryService.incrementBottleUsedTotal(t,i),{xp:await r.userMetaService.updateUserXp(t,e.xp),buffs:e.buffs,hp:e.hp}},HEAL_HP:async(t,n,{amount:o},i)=>{await r.userMetaService.gainHp(t,o*i)},GAIN_XP:async(t,n,{amount:o},i)=>await r.userMetaService.updateUserXp(t,o*i),GAIN_RANDOM_XP:async(t,n,{amounts:[o,i],odd:e},m)=>{let _=0;for(let s=0;s<m;s++)_+=Math.random()<e?o:i;return await r.userMetaService.updateUserXp(t,_)},DROP:async(t,n,o,i)=>{const e=[];for(let _=0;_<i;_++){const s={};for(const d in o){const u=Math.random();s[d]=+(u<o[d])}e.push(s)}const m=e.reduce((_,s)=>a.mergeObjects(_,s,(d,u)=>d+u));return await r.userInventoryService.addItems(t,{...m}),m},CLEAR_HANGOVER:t=>{console.log(t)},UNLOCK_ASSET:async(t,n,o)=>{await r.userOrnamentService.unlockProfileAsset(t,o.assetId)},ADD_SCROLL_CHARAC:async(t,n,o)=>(await r.userMetaService.addScrollCharacteristic(t,o),o),RAID_REDUCE_COOLDOWN:async(t,n,o)=>{await r.userCooldownService.reduceRaidCooldown(t,o.hours)},CREW_XP_BUFF:async(t,n,{hours:o},i)=>{const e=await r.userCrewService.get(t);if(!e)throw new Error("no crew");await r.crewMetaService.addXpBuff(e.crew._id,o*i)},CREW_REPAIR:async(t,n,{amount:o},i)=>{const e=await r.userCrewService.get(t);if(!e)throw new Error("no crew");return await r.crewService.repair(e.crew._id,o*i),o*i}};l.HANDLERS=v,l.getEntityName=N,l.getEntityNameAsync=M,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { Entity } from '@opfr/definitions';
2
- export declare const getEntityName: (entityId: string | Entity, count?: number) => Promise<string>;
2
+ export declare const getEntityNameAsync: (entityId: string | Entity, count?: number) => Promise<string>;
3
+ export declare const getEntityName: (entity: Entity, count?: number) => string;
3
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,GAAG,MAAM,EACzB,QAAO,MAAU,oBAalB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,GAAG,MAAM,EACzB,QAAO,MAAU,oBAalB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,QAAO,MAAU,WAQ9D,CAAC"}
package/dist/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t } from 'i18next';
2
2
  import { entityService } from '@opfr/services';
3
3
  import { isString } from '@opfr/utils-lang';
4
- export const getEntityName = async (entityId, count = 0) => {
4
+ export const getEntityNameAsync = async (entityId, count = 0) => {
5
5
  const entity = isString(entityId)
6
6
  ? await entityService.get(entityId)
7
7
  : entityId;
@@ -13,4 +13,13 @@ export const getEntityName = async (entityId, count = 0) => {
13
13
  })
14
14
  : '';
15
15
  };
16
+ export const getEntityName = (entity, count = 0) => {
17
+ return entity
18
+ ? t(entity.name.key, {
19
+ ns: 'entities',
20
+ count,
21
+ context: entity.name.context,
22
+ })
23
+ : '';
24
+ };
16
25
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,SAAS,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,QAAyB,EACzB,QAAgB,CAAC,EACjB,EAAE;IACF,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAC/B,CAAC,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnC,CAAC,CAAC,QAAQ,CAAC;IAEb,OAAO,MAAM;QACX,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YACjB,EAAE,EAAE,UAAU;YACd,KAAK;YACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;SAC7B,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;AACT,CAAC,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,SAAS,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,QAAyB,EACzB,QAAgB,CAAC,EACjB,EAAE;IACF,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAC/B,CAAC,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnC,CAAC,CAAC,QAAQ,CAAC;IAEb,OAAO,MAAM;QACX,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YACjB,EAAE,EAAE,UAAU;YACd,KAAK;YACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;SAC7B,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,QAAgB,CAAC,EAAE,EAAE;IACjE,OAAO,MAAM;QACX,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YACjB,EAAE,EAAE,UAAU;YACd,KAAK;YACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;SAC7B,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;AACT,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opfr/entities",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "description": "OPFR entities manager",
6
6
  "author": "Matthieu VEIGA",
@@ -40,5 +40,6 @@
40
40
  "eslintIgnore": [
41
41
  "node_modules",
42
42
  "dist"
43
- ]
43
+ ],
44
+ "gitHead": "2fb74c32079607d9d87455a6148c9c84f194f6b8"
44
45
  }