@opfr/entities 1.1.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.
@@ -0,0 +1,8 @@
1
+ import type { EffectKey, EffectParams, EffectReturn, Entity } from '@opfr/definitions';
2
+ import { type ObjectId } from '@opfr/services';
3
+ type Handler<K extends EffectKey> = (userId: ObjectId, entity: Entity, params: EffectParams<K>, quantity: number) => Promise<EffectReturn<K>> | EffectReturn<K>;
4
+ export declare const HANDLERS: {
5
+ [K in EffectKey]?: Handler<K>;
6
+ };
7
+ export {};
8
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/effects/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,MAAM,EAEP,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,QAAQ,EAUd,MAAM,gBAAgB,CAAC;AAsBxB,KAAK,OAAO,CAAC,CAAC,SAAS,SAAS,IAAI,CAClC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAEhD,eAAO,MAAM,QAAQ,EAAE;KAAG,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;CAoYrD,CAAC"}
@@ -0,0 +1,248 @@
1
+ import { crewMetaService, crewService, ornamentService, panoplyService, userCooldownService, userCrewService, userInventoryService, userOrnamentService, userStatsInventoryService, } from '@opfr/services';
2
+ import { entityService, userMetaService } from '@opfr/services';
3
+ import { filterNullAndUndefined, groupBy, includeArrayIf, includeIf, mergeObjects, pickFrom, pickFromNth, randomBetween, } from '@opfr/utils-lang';
4
+ import { DEFAULT_ODD_OBJECT, bottleVariant2, bottleVariant3, mapArrayForEntries, pickRaidItems, reduceItemsArray, } from './utils';
5
+ export const HANDLERS = {
6
+ OPEN_CHEST: async (userId, entity, params, quantity) => {
7
+ const rewards = {
8
+ berry: 0,
9
+ xp: {
10
+ bottle_xp_1: 0,
11
+ bottle_xp_2_berry: 0,
12
+ bottle_xp_2_casino: 0,
13
+ bottle_xp_2_work: 0,
14
+ bottle_xp_3_berry: 0,
15
+ bottle_xp_3_casino: 0,
16
+ bottle_xp_3_work: 0,
17
+ },
18
+ sugar_cane: 0,
19
+ title: [],
20
+ background: [],
21
+ boostXpWeek: 0,
22
+ boostXpDay: 0,
23
+ emptyChest: 0,
24
+ repairItem: [],
25
+ shopItem: [],
26
+ raidItem: [],
27
+ adventurer: [],
28
+ essence: [],
29
+ };
30
+ const userOrnaments = await userOrnamentService.get(userId);
31
+ const objectItems = await entityService.getAllEntitiesBy(entityService.isObjectItem);
32
+ const repairItems = await entityService.getAllEntitiesBy(entityService.isRepairItem);
33
+ const storeItems = await entityService.getAllEntitiesBy(entityService.isStoreItem);
34
+ const adventurerPanoply = await panoplyService.getPopulated('adventurer');
35
+ const titles = await ornamentService.getAllTitles();
36
+ const backgrounds = await ornamentService.getAllBackgrounds();
37
+ for (let i = 0; i < quantity; i++) {
38
+ const [minBerry, maxBerry] = params.berry;
39
+ const { bottle_xp_1, bottle_xp_2, bottle_xp_3 } = params.xp;
40
+ const { odds } = params;
41
+ const filteredTitles = titles.filter(item => !userOrnaments.unlockedTitles.includes(item.ornamentId));
42
+ const filteredBackgrounds = backgrounds.filter(item => !userOrnaments.unlockedBackgrounds.includes(item.ornamentId));
43
+ rewards.berry += randomBetween(minBerry, maxBerry + 1);
44
+ rewards.xp.bottle_xp_1 += bottle_xp_1
45
+ ? Array.isArray(bottle_xp_1)
46
+ ? randomBetween(bottle_xp_1[0], bottle_xp_1[1] + 1)
47
+ : bottle_xp_1
48
+ : 0;
49
+ const objBottle2 = bottleVariant2(bottle_xp_2
50
+ ? Array.isArray(bottle_xp_2)
51
+ ? randomBetween(bottle_xp_2[0], bottle_xp_2[1])
52
+ : bottle_xp_2
53
+ : 0);
54
+ const objBottle3 = bottleVariant3(bottle_xp_3 ?? 0);
55
+ rewards.xp['bottle_xp_2_berry'] += objBottle2.bottle_xp_2_berry ?? 0;
56
+ rewards.xp['bottle_xp_2_work'] += objBottle2.bottle_xp_2_work ?? 0;
57
+ rewards.xp['bottle_xp_2_casino'] += objBottle2.bottle_xp_2_casino ?? 0;
58
+ rewards.xp['bottle_xp_3_berry'] += objBottle3.bottle_xp_3_berry ?? 0;
59
+ rewards.xp['bottle_xp_3_work'] += objBottle3.bottle_xp_3_work ?? 0;
60
+ rewards.xp['bottle_xp_3_casino'] += objBottle3.bottle_xp_3_casino ?? 0;
61
+ const { sugar_cane } = params;
62
+ rewards.sugar_cane = sugar_cane
63
+ ? Array.isArray(sugar_cane)
64
+ ? randomBetween(sugar_cane[0], sugar_cane[1])
65
+ : sugar_cane
66
+ : 0;
67
+ if (odds.essence > 1) {
68
+ rewards.essence.push(...(await entityService.recordToEntityTuple(pickFromNth(objectItems
69
+ .map(({ entityId }) => entityId)
70
+ .filter(id => id.startsWith('essence_')), odds.essence))));
71
+ }
72
+ else if (Math.random() < odds.essence) {
73
+ rewards.essence.push([
74
+ pickFrom(objectItems.filter(({ entityId }) => entityId.startsWith('essence_'))),
75
+ 1,
76
+ ]);
77
+ }
78
+ try {
79
+ rewards.title = Array.isArray(odds.title)
80
+ ? includeArrayIf(rewards.title, ornamentService.pickEachRarityOrnament(groupBy(filteredTitles, item => item.rankId), odds.title), true)
81
+ : includeIf(rewards.title, ornamentService.pickOrnament({
82
+ ...DEFAULT_ODD_OBJECT,
83
+ ...groupBy(filteredTitles, item => item.odd ?? 0),
84
+ }), Math.random() < odds.title);
85
+ rewards.background = Array.isArray(odds.background)
86
+ ? includeArrayIf(rewards.background, ornamentService.pickEachRarityOrnament(groupBy(filteredBackgrounds, item => item.rankId), odds.background), true)
87
+ : includeIf(rewards.background, ornamentService.pickOrnament({
88
+ ...DEFAULT_ODD_OBJECT,
89
+ ...groupBy(filteredBackgrounds, item => item.odd ?? 0),
90
+ }), Math.random() < odds.background);
91
+ }
92
+ catch (e) {
93
+ console.warn(`<@${userId}> can no longer obtain titles/backgrounds`);
94
+ }
95
+ rewards.boostXpWeek += Array.isArray(odds.boostXpWeek)
96
+ ? randomBetween(odds.boostXpWeek[0], odds.boostXpWeek[1] + 1)
97
+ : Number(Math.random() < odds.boostXpWeek);
98
+ rewards.boostXpDay += Number(Math.random() < odds.boostXpDay);
99
+ rewards.emptyChest += Number(Math.random() < odds.emptyChest);
100
+ rewards.repairItem = includeIf(rewards.repairItem, [
101
+ repairItems.filter(item => item.entityId !== 'repair_kit')[randomBetween(0, repairItems.length - 1)],
102
+ randomBetween(1, params.tier * 2 + 2),
103
+ ], Math.random() < odds.repairItem);
104
+ rewards.shopItem = rewards.shopItem.concat(ornamentService
105
+ .pickEachRarityOrnament(groupBy(storeItems, item => item.rankId), odds.shopItem)
106
+ .map(item => [item, 1]));
107
+ rewards.raidItem = rewards.raidItem.concat(filterNullAndUndefined(await pickRaidItems(odds.raidItem ?? 0)).map(entity => [entity, 1]));
108
+ if (odds.adventurer) {
109
+ rewards.adventurer.push(...Array.from({ length: odds.adventurer }).map(() => entityService.seedEquipment(pickFrom(adventurerPanoply?.equipments ?? []), Date.now() - Math.round(Math.random() * 1000))));
110
+ }
111
+ }
112
+ rewards.title = filterNullAndUndefined(rewards.title);
113
+ rewards.background = filterNullAndUndefined(rewards.background);
114
+ rewards.berry = await userMetaService.updateUserBerry(userId, rewards.berry, false);
115
+ rewards.repairItem = reduceItemsArray(rewards.repairItem);
116
+ rewards.shopItem = reduceItemsArray(rewards.shopItem);
117
+ rewards.essence = reduceItemsArray(rewards.essence);
118
+ rewards.raidItem = reduceItemsArray(rewards.raidItem);
119
+ await userInventoryService.addItems(userId, {
120
+ bottle_xp_1: rewards.xp.bottle_xp_1,
121
+ bottle_xp_2_berry: rewards.xp.bottle_xp_2_berry,
122
+ bottle_xp_2_work: rewards.xp.bottle_xp_2_work,
123
+ bottle_xp_2_casino: rewards.xp.bottle_xp_2_casino,
124
+ bottle_xp_3_berry: rewards.xp.bottle_xp_3_berry,
125
+ bottle_xp_3_work: rewards.xp.bottle_xp_3_work,
126
+ bottle_xp_3_casino: rewards.xp.bottle_xp_3_casino,
127
+ boost_xp_day: rewards.boostXpDay,
128
+ boost_xp_week: rewards.boostXpWeek,
129
+ sugar_cane_christmas: rewards.sugar_cane,
130
+ empty_chest: rewards.emptyChest,
131
+ ...Object.fromEntries(mapArrayForEntries(rewards.repairItem)),
132
+ ...Object.fromEntries(mapArrayForEntries(rewards.shopItem)),
133
+ ...Object.fromEntries(mapArrayForEntries(rewards.essence)),
134
+ ...Object.fromEntries(mapArrayForEntries(rewards.raidItem)),
135
+ });
136
+ await userOrnamentService.unlockTitles(userId, rewards.title.map(item => item.ornamentId));
137
+ await userOrnamentService.unlockBackgrounds(userId, rewards.background.map(item => item.ornamentId));
138
+ await userInventoryService.addEquipments(userId, rewards.adventurer.map(({ entityId, seed }) => ({ entityId, seed })));
139
+ await userStatsInventoryService.incrementChestOpenedTotal(userId, quantity);
140
+ return rewards;
141
+ },
142
+ APPLY_BUFF: async (userId, entity, params, quantity) => {
143
+ for (let i = 0; i < quantity; i++) {
144
+ await userMetaService.updateBuff(userId, params);
145
+ }
146
+ },
147
+ ALCOHOL_DRINK: async (userId, entity, _params, quantity) => {
148
+ await userStatsInventoryService.incrementAlcoholDrink(userId, entity.entityId, quantity);
149
+ },
150
+ BOOST: async (userId, entity, _params, quantity) => {
151
+ return ((await userMetaService.updateBoost(userId, (entity.ms ?? 0) * quantity)) ?? new Date());
152
+ },
153
+ DRINK_BOTTLE: async (userId, entity, _params, quantity) => {
154
+ if (!entityService.isBottleItem(entity)) {
155
+ return;
156
+ }
157
+ const stats = {
158
+ buffs: [],
159
+ xp: 0,
160
+ hp: 0,
161
+ };
162
+ if (entity.bottle.tier === 2) {
163
+ await userMetaService.gainHp(userId, 50);
164
+ }
165
+ if (entity.bottle.tier === 3) {
166
+ await userMetaService.gainHp(userId, 100);
167
+ }
168
+ for (let i = 0; i < quantity; i++) {
169
+ const buffs = await userInventoryService.calcBottleMultiplier(userId, entity);
170
+ stats.buffs.push(...buffs);
171
+ await userMetaService.updateBuff(userId, buffs);
172
+ if (Array.isArray(entity.bottle.xp)) {
173
+ const [min, max] = entity.bottle.xp;
174
+ stats.xp += randomBetween(min, max + 1);
175
+ }
176
+ else {
177
+ stats.xp += entity.bottle.xp;
178
+ }
179
+ stats.hp += entity.bottle.hp ?? 0;
180
+ }
181
+ await userStatsInventoryService.incrementBottleUsedToday(userId, quantity);
182
+ await userStatsInventoryService.incrementBottleUsedTotal(userId, quantity);
183
+ return {
184
+ xp: await userMetaService.updateUserXp(userId, stats.xp),
185
+ buffs: stats.buffs,
186
+ hp: stats.hp,
187
+ };
188
+ },
189
+ HEAL_HP: async (userId, _entity, { amount }, quantity) => {
190
+ await userMetaService.gainHp(userId, amount * quantity);
191
+ },
192
+ GAIN_XP: async (userId, _entity, { amount }, quantity) => {
193
+ return await userMetaService.updateUserXp(userId, amount * quantity);
194
+ },
195
+ GAIN_RANDOM_XP: async (userId, _entity, { amounts: [min, max], odd }, quantity) => {
196
+ let result = 0;
197
+ for (let i = 0; i < quantity; i++) {
198
+ result += Math.random() < odd ? min : max;
199
+ }
200
+ return await userMetaService.updateUserXp(userId, result);
201
+ },
202
+ DROP: async (userId, entity, params, quantity) => {
203
+ const results = [];
204
+ for (let i = 0; i < quantity; i++) {
205
+ const result = {};
206
+ for (const key in params) {
207
+ const prob = Math.random();
208
+ result[key] = Number(prob < params[key]);
209
+ }
210
+ results.push(result);
211
+ }
212
+ const reducedResults = results.reduce((acc, e) => mergeObjects(acc, e, (o1, o2) => o1 + o2));
213
+ await userInventoryService.addItems(userId, {
214
+ ...reducedResults,
215
+ });
216
+ return reducedResults;
217
+ },
218
+ CLEAR_HANGOVER: userId => {
219
+ // TODO @col_chopper
220
+ console.log(userId);
221
+ },
222
+ UNLOCK_ASSET: async (userId, _entity, params) => {
223
+ await userOrnamentService.unlockProfileAsset(userId, params.assetId);
224
+ },
225
+ ADD_SCROLL_CHARAC: async (userId, _entity, params) => {
226
+ await userMetaService.addScrollCharacteristic(userId, params);
227
+ return params;
228
+ },
229
+ RAID_REDUCE_COOLDOWN: async (userId, _entity, params) => {
230
+ await userCooldownService.reduceRaidCooldown(userId, params.hours);
231
+ },
232
+ CREW_XP_BUFF: async (userId, _entity, { hours }, quantity) => {
233
+ const userCrew = await userCrewService.get(userId);
234
+ if (!userCrew) {
235
+ throw new Error('no crew');
236
+ }
237
+ await crewMetaService.addXpBuff(userCrew.crew._id, hours * quantity);
238
+ },
239
+ CREW_REPAIR: async (userId, _entity, { amount }, quantity) => {
240
+ const userCrew = await userCrewService.get(userId);
241
+ if (!userCrew) {
242
+ throw new Error('no crew');
243
+ }
244
+ await crewService.repair(userCrew.crew._id, amount * quantity);
245
+ return amount * quantity;
246
+ },
247
+ };
248
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/effects/handlers.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,eAAe,EACf,WAAW,EACX,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,OAAO,EACP,cAAc,EACd,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GAC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record<"bottle_xp_2_berry" | "bottle_xp_2_casino" | "bottle_xp_2_work", number>>;
3
+ export declare const bottleVariant3: (quantity: number) => Partial<Record<"bottle_xp_3_berry" | "bottle_xp_3_casino" | "bottle_xp_3_work", number>>;
4
+ export declare const pickRaidItems: (quantity: number) => Promise<((import("mongoose").FlattenMaps<import("@opfr/services").EntityDocument> & Required<{
5
+ _id: import("mongoose").Types.ObjectId;
6
+ }> & {
7
+ __v: number;
8
+ }) | null)[]>;
9
+ export declare const reduceItemsArray: (array: [Entity, number][]) => [Entity, number][];
10
+ export declare const mapArrayForEntries: (array: [Entity, number][]) => [string, number][];
11
+ export declare const DEFAULT_ODD_OBJECT: {
12
+ 0.5: never[];
13
+ 0.3: never[];
14
+ 0.15: never[];
15
+ 0.04: never[];
16
+ 0.01: never[];
17
+ };
18
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/effects/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,6FAI5C,CAAC;AAEJ,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,6FAI5C,CAAC;AAEJ,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM;;;;aAY3C,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAC3B,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KACxB,CAAC,MAAM,EAAE,MAAM,CAAC,EAOlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KACxB,CAAC,MAAM,EAAE,MAAM,CAAC,EAElB,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;CAM9B,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { entityService } from '@opfr/services';
2
+ import { groupBy, pickFromNth, recordToArray } from '@opfr/utils-lang';
3
+ export const bottleVariant2 = (quantity) => pickFromNth(['bottle_xp_2_berry', 'bottle_xp_2_casino', 'bottle_xp_2_work'], quantity);
4
+ export const bottleVariant3 = (quantity) => pickFromNth(['bottle_xp_3_berry', 'bottle_xp_3_casino', 'bottle_xp_3_work'], quantity);
5
+ export const pickRaidItems = (quantity) => Promise.all(recordToArray(pickFromNth(['anchor', 'sailing_boat', 'rescue_boat', 'rudder', 'hammock'], quantity))
6
+ .reduce((acc, [id, n]) => {
7
+ return acc.concat(new Array(n).fill(id));
8
+ }, [])
9
+ .map(id => entityService.get(id)));
10
+ export const reduceItemsArray = (array) => {
11
+ const groupedByEntity = groupBy(array, ([item]) => item.entityId);
12
+ return Object.values(groupedByEntity).map(oneEntityArray => [
13
+ oneEntityArray[0][0],
14
+ oneEntityArray.reduce((acc, [, quantity]) => acc + quantity, 0),
15
+ ]);
16
+ };
17
+ export const mapArrayForEntries = (array) => {
18
+ return array.map(([{ entityId }, quantity]) => [entityId, quantity]);
19
+ };
20
+ export const DEFAULT_ODD_OBJECT = {
21
+ 0.5: [],
22
+ 0.3: [],
23
+ 0.15: [],
24
+ 0.04: [],
25
+ 0.01: [],
26
+ };
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/effects/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE,CACjD,WAAW,CACT,CAAC,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,CAAU,EACxE,QAAQ,CACT,CAAC;AAEJ,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE,CACjD,WAAW,CACT,CAAC,mBAAmB,EAAE,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,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './utils';
2
+ export * from './effects/handlers';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,278 @@
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";
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
+ const rt = async (e, a = 0) => {
5
+ const r = J(e) ? await p.get(e) : e;
6
+ return r ? H(r.name.key, {
7
+ ns: "entities",
8
+ count: a,
9
+ context: r.name.context
10
+ }) : "";
11
+ }, z = (e) => O(
12
+ ["bottle_xp_2_berry", "bottle_xp_2_casino", "bottle_xp_2_work"],
13
+ e
14
+ ), Q = (e) => O(
15
+ ["bottle_xp_3_berry", "bottle_xp_3_casino", "bottle_xp_3_work"],
16
+ e
17
+ ), Z = (e) => Promise.all(
18
+ Y(
19
+ O(
20
+ ["anchor", "sailing_boat", "rescue_boat", "rudder", "hammock"],
21
+ e
22
+ )
23
+ ).reduce((a, [r, o]) => a.concat(new Array(o).fill(r)), []).map((a) => p.get(a))
24
+ ), I = (e) => {
25
+ const a = y(e, ([r]) => r.entityId);
26
+ return Object.values(a).map((r) => [
27
+ r[0][0],
28
+ r.reduce((o, [, t]) => o + t, 0)
29
+ ]);
30
+ }, E = (e) => e.map(([{ entityId: a }, r]) => [a, r]), P = {
31
+ 0.5: [],
32
+ 0.3: [],
33
+ 0.15: [],
34
+ 0.04: [],
35
+ 0.01: []
36
+ }, at = {
37
+ OPEN_CHEST: async (e, a, r, o) => {
38
+ const t = {
39
+ berry: 0,
40
+ xp: {
41
+ bottle_xp_1: 0,
42
+ bottle_xp_2_berry: 0,
43
+ bottle_xp_2_casino: 0,
44
+ bottle_xp_2_work: 0,
45
+ bottle_xp_3_berry: 0,
46
+ bottle_xp_3_casino: 0,
47
+ bottle_xp_3_work: 0
48
+ },
49
+ sugar_cane: 0,
50
+ title: [],
51
+ background: [],
52
+ boostXpWeek: 0,
53
+ boostXpDay: 0,
54
+ emptyChest: 0,
55
+ repairItem: [],
56
+ shopItem: [],
57
+ raidItem: [],
58
+ adventurer: [],
59
+ essence: []
60
+ }, l = await h.get(e), i = await p.getAllEntitiesBy(
61
+ p.isObjectItem
62
+ ), c = await p.getAllEntitiesBy(
63
+ p.isRepairItem
64
+ ), b = await p.getAllEntitiesBy(
65
+ p.isStoreItem
66
+ ), x = await V.getPopulated("adventurer"), L = await u.getAllTitles(), U = await u.getAllBackgrounds();
67
+ 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(
69
+ (n) => !l.unlockedTitles.includes(n.ornamentId)
70
+ ), X = U.filter(
71
+ (n) => !l.unlockedBackgrounds.includes(n.ornamentId)
72
+ );
73
+ t.berry += d(B, W + 1), t.xp.bottle_xp_1 += w ? Array.isArray(w) ? d(w[0], w[1] + 1) : w : 0;
74
+ const C = z(
75
+ k ? Array.isArray(k) ? d(k[0], k[1]) : k : 0
76
+ ), R = Q(j ?? 0);
77
+ 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
+ const { sugar_cane: f } = r;
79
+ t.sugar_cane = f ? Array.isArray(f) ? d(f[0], f[1]) : f : 0, s.essence > 1 ? t.essence.push(
80
+ ...await p.recordToEntityTuple(
81
+ O(
82
+ i.map(({ entityId: n }) => n).filter((n) => n.startsWith("essence_")),
83
+ s.essence
84
+ )
85
+ )
86
+ ) : Math.random() < s.essence && t.essence.push([
87
+ T(
88
+ i.filter(
89
+ ({ entityId: n }) => n.startsWith("essence_")
90
+ )
91
+ ),
92
+ 1
93
+ ]);
94
+ try {
95
+ t.title = Array.isArray(s.title) ? M(
96
+ t.title,
97
+ u.pickEachRarityOrnament(
98
+ y(D, (n) => n.rankId),
99
+ s.title
100
+ ),
101
+ !0
102
+ ) : v(
103
+ t.title,
104
+ u.pickOrnament({
105
+ ...P,
106
+ ...y(D, (n) => n.odd ?? 0)
107
+ }),
108
+ Math.random() < s.title
109
+ ), t.background = Array.isArray(s.background) ? M(
110
+ t.background,
111
+ u.pickEachRarityOrnament(
112
+ y(X, (n) => n.rankId),
113
+ s.background
114
+ ),
115
+ !0
116
+ ) : v(
117
+ t.background,
118
+ u.pickOrnament({
119
+ ...P,
120
+ ...y(X, (n) => n.odd ?? 0)
121
+ }),
122
+ Math.random() < s.background
123
+ );
124
+ } catch {
125
+ console.warn(`<@${e}> can no longer obtain titles/backgrounds`);
126
+ }
127
+ t.boostXpWeek += Array.isArray(s.boostXpWeek) ? d(s.boostXpWeek[0], s.boostXpWeek[1] + 1) : +(Math.random() < s.boostXpWeek), t.boostXpDay += +(Math.random() < s.boostXpDay), t.emptyChest += +(Math.random() < s.emptyChest), t.repairItem = v(
128
+ t.repairItem,
129
+ [
130
+ c.filter((n) => n.entityId !== "repair_kit")[d(0, c.length - 1)],
131
+ d(1, r.tier * 2 + 2)
132
+ ],
133
+ Math.random() < s.repairItem
134
+ ), t.shopItem = t.shopItem.concat(
135
+ u.pickEachRarityOrnament(
136
+ y(b, (n) => n.rankId),
137
+ s.shopItem
138
+ ).map((n) => [n, 1])
139
+ ), t.raidItem = t.raidItem.concat(
140
+ S(await Z(s.raidItem ?? 0)).map(
141
+ (n) => [n, 1]
142
+ )
143
+ ), s.adventurer && t.adventurer.push(
144
+ ...Array.from({ length: s.adventurer }).map(
145
+ () => p.seedEquipment(
146
+ T(x?.equipments ?? []),
147
+ Date.now() - Math.round(Math.random() * 1e3)
148
+ )
149
+ )
150
+ );
151
+ }
152
+ return t.title = S(t.title), t.background = S(t.background), t.berry = await _.updateUserBerry(
153
+ e,
154
+ t.berry,
155
+ !1
156
+ ), t.repairItem = I(t.repairItem), t.shopItem = I(t.shopItem), t.essence = I(t.essence), t.raidItem = I(t.raidItem), await g.addItems(e, {
157
+ bottle_xp_1: t.xp.bottle_xp_1,
158
+ bottle_xp_2_berry: t.xp.bottle_xp_2_berry,
159
+ bottle_xp_2_work: t.xp.bottle_xp_2_work,
160
+ bottle_xp_2_casino: t.xp.bottle_xp_2_casino,
161
+ bottle_xp_3_berry: t.xp.bottle_xp_3_berry,
162
+ bottle_xp_3_work: t.xp.bottle_xp_3_work,
163
+ bottle_xp_3_casino: t.xp.bottle_xp_3_casino,
164
+ boost_xp_day: t.boostXpDay,
165
+ boost_xp_week: t.boostXpWeek,
166
+ sugar_cane_christmas: t.sugar_cane,
167
+ empty_chest: t.emptyChest,
168
+ ...Object.fromEntries(E(t.repairItem)),
169
+ ...Object.fromEntries(E(t.shopItem)),
170
+ ...Object.fromEntries(E(t.essence)),
171
+ ...Object.fromEntries(E(t.raidItem))
172
+ }), await h.unlockTitles(
173
+ e,
174
+ t.title.map((m) => m.ornamentId)
175
+ ), await h.unlockBackgrounds(
176
+ e,
177
+ t.background.map((m) => m.ornamentId)
178
+ ), await g.addEquipments(
179
+ e,
180
+ t.adventurer.map(({ entityId: m, seed: B }) => ({ entityId: m, seed: B }))
181
+ ), await A.incrementChestOpenedTotal(e, o), t;
182
+ },
183
+ APPLY_BUFF: async (e, a, r, o) => {
184
+ for (let t = 0; t < o; t++)
185
+ await _.updateBuff(e, r);
186
+ },
187
+ ALCOHOL_DRINK: async (e, a, r, o) => {
188
+ await A.incrementAlcoholDrink(
189
+ e,
190
+ a.entityId,
191
+ o
192
+ );
193
+ },
194
+ BOOST: async (e, a, r, o) => await _.updateBoost(
195
+ e,
196
+ (a.ms ?? 0) * o
197
+ ) ?? /* @__PURE__ */ new Date(),
198
+ DRINK_BOTTLE: async (e, a, r, o) => {
199
+ if (!p.isBottleItem(a))
200
+ return;
201
+ const t = {
202
+ buffs: [],
203
+ xp: 0,
204
+ hp: 0
205
+ };
206
+ a.bottle.tier === 2 && await _.gainHp(e, 50), a.bottle.tier === 3 && await _.gainHp(e, 100);
207
+ for (let l = 0; l < o; l++) {
208
+ const i = await g.calcBottleMultiplier(
209
+ e,
210
+ a
211
+ );
212
+ if (t.buffs.push(...i), await _.updateBuff(e, i), Array.isArray(a.bottle.xp)) {
213
+ const [c, b] = a.bottle.xp;
214
+ t.xp += d(c, b + 1);
215
+ } else
216
+ t.xp += a.bottle.xp;
217
+ t.hp += a.bottle.hp ?? 0;
218
+ }
219
+ return await A.incrementBottleUsedToday(e, o), await A.incrementBottleUsedTotal(e, o), {
220
+ xp: await _.updateUserXp(e, t.xp),
221
+ buffs: t.buffs,
222
+ hp: t.hp
223
+ };
224
+ },
225
+ HEAL_HP: async (e, a, { amount: r }, o) => {
226
+ await _.gainHp(e, r * o);
227
+ },
228
+ GAIN_XP: async (e, a, { amount: r }, o) => await _.updateUserXp(e, r * o),
229
+ GAIN_RANDOM_XP: async (e, a, { amounts: [r, o], odd: t }, l) => {
230
+ let i = 0;
231
+ for (let c = 0; c < l; c++)
232
+ i += Math.random() < t ? r : o;
233
+ return await _.updateUserXp(e, i);
234
+ },
235
+ DROP: async (e, a, r, o) => {
236
+ const t = [];
237
+ for (let i = 0; i < o; i++) {
238
+ const c = {};
239
+ for (const b in r) {
240
+ const x = Math.random();
241
+ c[b] = +(x < r[b]);
242
+ }
243
+ t.push(c);
244
+ }
245
+ const l = t.reduce(
246
+ (i, c) => $(i, c, (b, x) => b + x)
247
+ );
248
+ return await g.addItems(e, {
249
+ ...l
250
+ }), l;
251
+ },
252
+ CLEAR_HANGOVER: (e) => {
253
+ console.log(e);
254
+ },
255
+ UNLOCK_ASSET: async (e, a, r) => {
256
+ await h.unlockProfileAsset(e, r.assetId);
257
+ },
258
+ ADD_SCROLL_CHARAC: async (e, a, r) => (await _.addScrollCharacteristic(e, r), r),
259
+ RAID_REDUCE_COOLDOWN: async (e, a, r) => {
260
+ await K.reduceRaidCooldown(e, r.hours);
261
+ },
262
+ CREW_XP_BUFF: async (e, a, { hours: r }, o) => {
263
+ const t = await N.get(e);
264
+ if (!t)
265
+ throw new Error("no crew");
266
+ await G.addXpBuff(t.crew._id, r * o);
267
+ },
268
+ CREW_REPAIR: async (e, a, { amount: r }, o) => {
269
+ const t = await N.get(e);
270
+ if (!t)
271
+ throw new Error("no crew");
272
+ return await F.repair(t.crew._id, r * o), r * o;
273
+ }
274
+ };
275
+ export {
276
+ at as HANDLERS,
277
+ rt as getEntityName
278
+ };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './utils';
2
+ export * from './effects/handlers';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
@@ -0,0 +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"})}));
@@ -0,0 +1,3 @@
1
+ import type { Entity } from '@opfr/definitions';
2
+ export declare const getEntityName: (entityId: string | Entity, count?: number) => Promise<string>;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +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"}
package/dist/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ import { t } from 'i18next';
2
+ import { entityService } from '@opfr/services';
3
+ import { isString } from '@opfr/utils-lang';
4
+ export const getEntityName = async (entityId, count = 0) => {
5
+ const entity = isString(entityId)
6
+ ? await entityService.get(entityId)
7
+ : entityId;
8
+ return entity
9
+ ? t(entity.name.key, {
10
+ ns: 'entities',
11
+ count,
12
+ context: entity.name.context,
13
+ })
14
+ : '';
15
+ };
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +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"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@opfr/entities",
3
+ "version": "1.1.0",
4
+ "private": false,
5
+ "description": "OPFR entities manager",
6
+ "author": "Matthieu VEIGA",
7
+ "scripts": {
8
+ "prepublish": "npm run build",
9
+ "build": "vite build && tsc -p tsconfig.build.json"
10
+ },
11
+ "devDependencies": {
12
+ "@opfr/definitions": "^1.1.0",
13
+ "@opfr/emojis": "^1.0.1",
14
+ "@opfr/services": "^1.0.2",
15
+ "@opfr/utils-lang": "^1.0.1",
16
+ "@opfr/utils-type": "^1.0.1",
17
+ "i18next": "23.16.8"
18
+ },
19
+ "peerDependencies": {
20
+ "@opfr/definitions": "^1.0.0",
21
+ "@opfr/emojis": "^1.0.0",
22
+ "@opfr/services": "^1.0.0",
23
+ "@opfr/utils-lang": "^1.0.0",
24
+ "@opfr/utils-type": "^1.0.0",
25
+ "i18next": "^23"
26
+ },
27
+ "main": "./dist/index.umd.js",
28
+ "module": "./dist/index.es.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.es.js",
34
+ "require": "./dist/index.umd.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "eslintIgnore": [
41
+ "node_modules",
42
+ "dist"
43
+ ]
44
+ }