@opfr/entities 1.4.0 → 1.5.1
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 +50 -50
- package/dist/index.umd.js +1 -1
- package/dist/utils.js +9 -9
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
package/dist/index.es.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { entityService as
|
|
1
|
+
import d from "i18next";
|
|
2
|
+
import { entityService as a, userMetaService as m, userOrnamentService as E, userInventoryService as $, userStatsInventoryService as I } from "@opfr/services";
|
|
3
3
|
import { isString as A, mergeObjects as f, randomBetween as g, pickFrom as _ } from "@opfr/utils-lang";
|
|
4
|
-
const C = async (t,
|
|
5
|
-
const e = A(t) ? await
|
|
4
|
+
const C = async (t, n = 0) => {
|
|
5
|
+
const e = A(t) ? await a.get(t) : t;
|
|
6
6
|
if (!e) return "";
|
|
7
|
-
const
|
|
8
|
-
return d(
|
|
9
|
-
ns:
|
|
10
|
-
count:
|
|
7
|
+
const r = a.isItem(e) ? `${e.type}.${e.category}.${e.entityId}.name` : a.isEquipment(e) ? `${e.type}.${e.panoply}.${e.category}.name` : "";
|
|
8
|
+
return d.t(r, {
|
|
9
|
+
ns: e.type,
|
|
10
|
+
count: n
|
|
11
11
|
});
|
|
12
|
-
}, N = async (t,
|
|
13
|
-
const e = A(t) ? await
|
|
12
|
+
}, N = async (t, n = 0) => {
|
|
13
|
+
const e = A(t) ? await a.get(t) : t;
|
|
14
14
|
if (!e) return "";
|
|
15
|
-
const
|
|
16
|
-
return d(
|
|
17
|
-
ns:
|
|
18
|
-
count:
|
|
15
|
+
const r = a.isItem(e) ? `${e.type}.${e.category}.${e.entityId}.description` : a.isEquipment(e) ? `${e.type}.${e.panoply}.${e.category}.description` : "";
|
|
16
|
+
return d.t(r, {
|
|
17
|
+
ns: e.type,
|
|
18
|
+
count: n
|
|
19
19
|
});
|
|
20
|
-
}, O = (t,
|
|
21
|
-
const e =
|
|
22
|
-
return d(e, {
|
|
23
|
-
ns:
|
|
24
|
-
count:
|
|
20
|
+
}, O = (t, n = 0) => {
|
|
21
|
+
const e = a.isItem(t) ? `${t.type}.${t.category}.${t.entityId}.name` : a.isEquipment(t) ? `${t.type}.${t.panoply}.${t.category}.name` : "";
|
|
22
|
+
return d.t(e, {
|
|
23
|
+
ns: t.type,
|
|
24
|
+
count: n
|
|
25
25
|
});
|
|
26
|
-
}, H = (t,
|
|
27
|
-
const e =
|
|
28
|
-
return d(e, {
|
|
29
|
-
ns:
|
|
30
|
-
count:
|
|
26
|
+
}, H = (t, n = 0) => {
|
|
27
|
+
const e = a.isItem(t) ? `${t.type}.${t.category}.${t.entityId}.description` : a.isEquipment(t) ? `${t.type}.${t.panoply}.${t.category}.description` : "";
|
|
28
|
+
return d.t(e, {
|
|
29
|
+
ns: t.type,
|
|
30
|
+
count: n
|
|
31
31
|
});
|
|
32
32
|
}, P = {
|
|
33
|
-
OPEN_CHEST: async (t,
|
|
33
|
+
OPEN_CHEST: async (t, n, e, r) => {
|
|
34
34
|
const s = {
|
|
35
35
|
berry: 0,
|
|
36
36
|
items: {}
|
|
37
37
|
};
|
|
38
|
-
for (let y = 0; y <
|
|
39
|
-
const [
|
|
40
|
-
s.berry += g(
|
|
41
|
-
for (const c of
|
|
38
|
+
for (let y = 0; y < r; y++) {
|
|
39
|
+
const [i, o] = e.berry, p = e.items;
|
|
40
|
+
s.berry += g(i, o + 1);
|
|
41
|
+
for (const c of p) {
|
|
42
42
|
let w = function(u) {
|
|
43
|
-
return
|
|
43
|
+
return a.isItem(u) && u.rankId === c.rank;
|
|
44
44
|
}, l;
|
|
45
45
|
do {
|
|
46
|
-
const u = await
|
|
46
|
+
const u = await a.getAllItemsBy(w);
|
|
47
47
|
l = _(u);
|
|
48
48
|
} while (l.entityId in s.items);
|
|
49
49
|
s.items[l.entityId] = Array.isArray(c.quantity) ? g(c.quantity[0], c.quantity[1]) : c.quantity;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
return await $.addItems(t, s.items), await I.incrementChestOpenedTotal(t,
|
|
52
|
+
return await $.addItems(t, s.items), await I.incrementChestOpenedTotal(t, r), s;
|
|
53
53
|
},
|
|
54
|
-
APPLY_BUFF: async (t,
|
|
55
|
-
for (let s = 0; s <
|
|
56
|
-
await
|
|
54
|
+
APPLY_BUFF: async (t, n, e, r) => {
|
|
55
|
+
for (let s = 0; s < r; s++)
|
|
56
|
+
await m.updateBuff(t, e);
|
|
57
57
|
},
|
|
58
|
-
HEAL_HP: async (t,
|
|
59
|
-
await
|
|
58
|
+
HEAL_HP: async (t, n, { amount: e }, r) => {
|
|
59
|
+
await m.gainHp(t, e * r);
|
|
60
60
|
},
|
|
61
|
-
GAIN_XP: async (t,
|
|
62
|
-
GAIN_RANDOM_XP: async (t,
|
|
63
|
-
let
|
|
61
|
+
GAIN_XP: async (t, n, { amount: e }, r) => await m.updateUserXp(t, e * r),
|
|
62
|
+
GAIN_RANDOM_XP: async (t, n, { amounts: [e, r], odd: s }, y) => {
|
|
63
|
+
let i = 0;
|
|
64
64
|
for (let o = 0; o < y; o++)
|
|
65
|
-
|
|
66
|
-
return await
|
|
65
|
+
i += Math.random() < s ? e : r;
|
|
66
|
+
return await m.updateUserXp(t, i);
|
|
67
67
|
},
|
|
68
|
-
DROP: async (t,
|
|
68
|
+
DROP: async (t, n, e, r) => {
|
|
69
69
|
const s = [];
|
|
70
|
-
for (let
|
|
70
|
+
for (let i = 0; i < r; i++) {
|
|
71
71
|
const o = {};
|
|
72
|
-
for (const
|
|
72
|
+
for (const p in e) {
|
|
73
73
|
const c = Math.random();
|
|
74
|
-
o[
|
|
74
|
+
o[p] = +(c < e[p]);
|
|
75
75
|
}
|
|
76
76
|
s.push(o);
|
|
77
77
|
}
|
|
78
78
|
const y = s.reduce(
|
|
79
|
-
(
|
|
79
|
+
(i, o) => f(i, o, (p, c) => p + c)
|
|
80
80
|
);
|
|
81
81
|
return await $.addItems(t, {
|
|
82
82
|
...y
|
|
@@ -85,12 +85,12 @@ const C = async (t, r = 0) => {
|
|
|
85
85
|
CLEAR_HANGOVER: (t) => {
|
|
86
86
|
console.log(t);
|
|
87
87
|
},
|
|
88
|
-
UNLOCK_ASSET: async (t,
|
|
88
|
+
UNLOCK_ASSET: async (t, n, e) => {
|
|
89
89
|
await E.unlockProfileAsset(t, e.assetId);
|
|
90
90
|
},
|
|
91
|
-
ADD_SCROLL_CHARAC: async (t,
|
|
91
|
+
ADD_SCROLL_CHARAC: async (t, n, e) => (await m.addScrollCharacteristic(t, e), e),
|
|
92
92
|
RESET_CHARAC: async (t) => {
|
|
93
|
-
await
|
|
93
|
+
await m.resetCharacteristics(t);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
export {
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("i18next"),require("@opfr/services"),require("@opfr/utils-lang")):typeof define=="function"&&define.amd?define(["exports","i18next","@opfr/services","@opfr/utils-lang"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.entities={},a.i18next,a["@opfr/services"],a["@opfr/utils-lang"]))})(this,(function(a,u,n,m){"use strict";const l=async(t,
|
|
1
|
+
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("i18next"),require("@opfr/services"),require("@opfr/utils-lang")):typeof define=="function"&&define.amd?define(["exports","i18next","@opfr/services","@opfr/utils-lang"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.entities={},a.i18next,a["@opfr/services"],a["@opfr/utils-lang"]))})(this,(function(a,u,n,m){"use strict";const l=async(t,i=0)=>{const e=m.isString(t)?await n.entityService.get(t):t;if(!e)return"";const r=n.entityService.isItem(e)?`${e.type}.${e.category}.${e.entityId}.name`:n.entityService.isEquipment(e)?`${e.type}.${e.panoply}.${e.category}.name`:"";return u.t(r,{ns:e.type,count:i})},$=async(t,i=0)=>{const e=m.isString(t)?await n.entityService.get(t):t;if(!e)return"";const r=n.entityService.isItem(e)?`${e.type}.${e.category}.${e.entityId}.description`:n.entityService.isEquipment(e)?`${e.type}.${e.panoply}.${e.category}.description`:"";return u.t(r,{ns:e.type,count:i})},A=(t,i=0)=>{const e=n.entityService.isItem(t)?`${t.type}.${t.category}.${t.entityId}.name`:n.entityService.isEquipment(t)?`${t.type}.${t.panoply}.${t.category}.name`:"";return u.t(e,{ns:t.type,count:i})},g=(t,i=0)=>{const e=n.entityService.isItem(t)?`${t.type}.${t.category}.${t.entityId}.description`:n.entityService.isEquipment(t)?`${t.type}.${t.panoply}.${t.category}.description`:"";return u.t(e,{ns:t.type,count:i})},E={OPEN_CHEST:async(t,i,e,r)=>{const o={berry:0,items:{}};for(let p=0;p<r;p++){const[y,c]=e.berry,d=e.items;o.berry+=m.randomBetween(y,c+1);for(const s of d){let w=function(S){return n.entityService.isItem(S)&&S.rankId===s.rank},f;do{const S=await n.entityService.getAllItemsBy(w);f=m.pickFrom(S)}while(f.entityId in o.items);o.items[f.entityId]=Array.isArray(s.quantity)?m.randomBetween(s.quantity[0],s.quantity[1]):s.quantity}}return await n.userInventoryService.addItems(t,o.items),await n.userStatsInventoryService.incrementChestOpenedTotal(t,r),o},APPLY_BUFF:async(t,i,e,r)=>{for(let o=0;o<r;o++)await n.userMetaService.updateBuff(t,e)},HEAL_HP:async(t,i,{amount:e},r)=>{await n.userMetaService.gainHp(t,e*r)},GAIN_XP:async(t,i,{amount:e},r)=>await n.userMetaService.updateUserXp(t,e*r),GAIN_RANDOM_XP:async(t,i,{amounts:[e,r],odd:o},p)=>{let y=0;for(let c=0;c<p;c++)y+=Math.random()<o?e:r;return await n.userMetaService.updateUserXp(t,y)},DROP:async(t,i,e,r)=>{const o=[];for(let y=0;y<r;y++){const c={};for(const d in e){const s=Math.random();c[d]=+(s<e[d])}o.push(c)}const p=o.reduce((y,c)=>m.mergeObjects(y,c,(d,s)=>d+s));return await n.userInventoryService.addItems(t,{...p}),p},CLEAR_HANGOVER:t=>{console.log(t)},UNLOCK_ASSET:async(t,i,e)=>{await n.userOrnamentService.unlockProfileAsset(t,e.assetId)},ADD_SCROLL_CHARAC:async(t,i,e)=>(await n.userMetaService.addScrollCharacteristic(t,e),e),RESET_CHARAC:async t=>{await n.userMetaService.resetCharacteristics(t)}};a.HANDLERS=E,a.getEntityDescription=g,a.getEntityDescriptionAsync=$,a.getEntityName=A,a.getEntityNameAsync=l,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i18next from 'i18next';
|
|
2
2
|
import { entityService } from '@opfr/services';
|
|
3
3
|
import { isString } from '@opfr/utils-lang';
|
|
4
4
|
export const getEntityNameAsync = async (entityId, count = 0) => {
|
|
@@ -12,8 +12,8 @@ export const getEntityNameAsync = async (entityId, count = 0) => {
|
|
|
12
12
|
: entityService.isEquipment(entity)
|
|
13
13
|
? `${entity.type}.${entity.panoply}.${entity.category}.name`
|
|
14
14
|
: '';
|
|
15
|
-
return t(key, {
|
|
16
|
-
ns:
|
|
15
|
+
return i18next.t(key, {
|
|
16
|
+
ns: entity.type,
|
|
17
17
|
count,
|
|
18
18
|
});
|
|
19
19
|
};
|
|
@@ -28,8 +28,8 @@ export const getEntityDescriptionAsync = async (entityId, count = 0) => {
|
|
|
28
28
|
: entityService.isEquipment(entity)
|
|
29
29
|
? `${entity.type}.${entity.panoply}.${entity.category}.description`
|
|
30
30
|
: '';
|
|
31
|
-
return t(key, {
|
|
32
|
-
ns:
|
|
31
|
+
return i18next.t(key, {
|
|
32
|
+
ns: entity.type,
|
|
33
33
|
count,
|
|
34
34
|
});
|
|
35
35
|
};
|
|
@@ -39,8 +39,8 @@ export const getEntityName = (entity, count = 0) => {
|
|
|
39
39
|
: entityService.isEquipment(entity)
|
|
40
40
|
? `${entity.type}.${entity.panoply}.${entity.category}.name`
|
|
41
41
|
: '';
|
|
42
|
-
return t(key, {
|
|
43
|
-
ns:
|
|
42
|
+
return i18next.t(key, {
|
|
43
|
+
ns: entity.type,
|
|
44
44
|
count,
|
|
45
45
|
});
|
|
46
46
|
};
|
|
@@ -50,8 +50,8 @@ export const getEntityDescription = (entity, count = 0) => {
|
|
|
50
50
|
: entityService.isEquipment(entity)
|
|
51
51
|
? `${entity.type}.${entity.panoply}.${entity.category}.description`
|
|
52
52
|
: '';
|
|
53
|
-
return t(key, {
|
|
54
|
-
ns:
|
|
53
|
+
return i18next.t(key, {
|
|
54
|
+
ns: entity.type,
|
|
55
55
|
count,
|
|
56
56
|
});
|
|
57
57
|
};
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,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,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,OAAO;QAC7D,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,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CAAC,QAAQ,OAAO;QAC7D,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC;YACjC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,OAAO;YAC5D,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE;QACpB,EAAE,EAAE,MAAM,CAAC,IAAI;QACf,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,QAAgB,CAAC,EAAE,EAAE;IACxE,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,cAAc;QACpE,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC;YACjC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,cAAc;YACnE,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE;QACpB,EAAE,EAAE,MAAM,CAAC,IAAI;QACf,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opfr/entities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "OPFR entities manager",
|
|
6
6
|
"author": "Matthieu VEIGA",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"build": "vite build && tsc"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@opfr/definitions": "^1.
|
|
12
|
+
"@opfr/definitions": "^1.9.0",
|
|
13
13
|
"@opfr/emojis": "^1.1.0",
|
|
14
|
-
"@opfr/services": "^1.
|
|
14
|
+
"@opfr/services": "^1.8.0",
|
|
15
15
|
"@opfr/utils-lang": "^1.1.1",
|
|
16
16
|
"@opfr/utils-type": "^1.1.0",
|
|
17
17
|
"i18next": "23.16.8"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"node_modules",
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "e4c39f2901e6edcf98fac781214afbd547972e5a"
|
|
45
45
|
}
|