@civ-clone/core-treasury 0.1.4 → 0.1.6
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/PlayerTreasury.d.ts +6 -1
- package/PlayerTreasury.js +17 -33
- package/PlayerTreasury.js.map +1 -1
- package/PlayerTreasury.ts +22 -21
- package/SpendCost.d.ts +2 -1
- package/SpendCost.js +4 -19
- package/SpendCost.js.map +1 -1
- package/SpendCost.ts +6 -6
- package/package.json +2 -2
package/PlayerTreasury.d.ts
CHANGED
|
@@ -18,7 +18,12 @@ export declare class PlayerTreasury
|
|
|
18
18
|
extends DataObject
|
|
19
19
|
implements IPlayerTreasury
|
|
20
20
|
{
|
|
21
|
-
|
|
21
|
+
static readonly transient: string[];
|
|
22
|
+
private _cityBuildRegistry;
|
|
23
|
+
private _player;
|
|
24
|
+
private _ruleRegistry;
|
|
25
|
+
private _value;
|
|
26
|
+
private _yield;
|
|
22
27
|
constructor(
|
|
23
28
|
player: Player,
|
|
24
29
|
YieldType: typeof Yield,
|
package/PlayerTreasury.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _PlayerTreasury_cityBuildRegistry, _PlayerTreasury_player, _PlayerTreasury_ruleRegistry, _PlayerTreasury_value, _PlayerTreasury_yield;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.PlayerTreasury = void 0;
|
|
16
4
|
const CityBuildRegistry_1 = require("@civ-clone/core-city-build/CityBuildRegistry");
|
|
@@ -22,43 +10,39 @@ const Rush_1 = require("./Rules/Rush");
|
|
|
22
10
|
class PlayerTreasury extends DataObject_1.default {
|
|
23
11
|
constructor(player, YieldType, cityBuildRegistry = CityBuildRegistry_1.instance, ruleRegistry = RuleRegistry_1.instance) {
|
|
24
12
|
super();
|
|
25
|
-
|
|
26
|
-
_PlayerTreasury_player.set(this, void 0);
|
|
27
|
-
_PlayerTreasury_ruleRegistry.set(this, void 0);
|
|
28
|
-
_PlayerTreasury_value.set(this, 0);
|
|
29
|
-
_PlayerTreasury_yield.set(this, void 0);
|
|
13
|
+
this._value = 0;
|
|
30
14
|
this.addKey('value', 'yield');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
this._cityBuildRegistry = cityBuildRegistry;
|
|
16
|
+
this._player = player;
|
|
17
|
+
this._ruleRegistry = ruleRegistry;
|
|
18
|
+
this._yield = YieldType;
|
|
35
19
|
}
|
|
36
20
|
add(value) {
|
|
37
21
|
if (value instanceof Yield_1.default) {
|
|
38
22
|
this.add(value.value());
|
|
39
23
|
return;
|
|
40
24
|
}
|
|
41
|
-
|
|
25
|
+
this._value += value;
|
|
42
26
|
}
|
|
43
27
|
buy(city) {
|
|
44
|
-
const cityBuild =
|
|
45
|
-
if (city.player() !==
|
|
28
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city), [spendCost] = this.cost(city).filter((spendCost) => spendCost.resource() === this._yield), cost = spendCost.value();
|
|
29
|
+
if (city.player() !== this._player || this.value() < cost) {
|
|
46
30
|
return;
|
|
47
31
|
}
|
|
48
|
-
|
|
32
|
+
this._ruleRegistry.process(Rush_1.default, cityBuild, spendCost);
|
|
49
33
|
// TODO: do this via Rules and then use Production
|
|
50
34
|
cityBuild.add(new Yield_1.default(cityBuild.remaining()));
|
|
51
35
|
this.subtract(cost);
|
|
52
36
|
}
|
|
53
37
|
cost(city) {
|
|
54
|
-
const cityBuild =
|
|
55
|
-
return
|
|
38
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city);
|
|
39
|
+
return this._ruleRegistry.process(Spend_1.default, cityBuild);
|
|
56
40
|
}
|
|
57
41
|
player() {
|
|
58
|
-
return
|
|
42
|
+
return this._player;
|
|
59
43
|
}
|
|
60
44
|
set(value) {
|
|
61
|
-
|
|
45
|
+
this._value = 0;
|
|
62
46
|
this.add(value);
|
|
63
47
|
}
|
|
64
48
|
subtract(value) {
|
|
@@ -66,16 +50,16 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
66
50
|
this.add(value.value());
|
|
67
51
|
return;
|
|
68
52
|
}
|
|
69
|
-
|
|
53
|
+
this._value -= value;
|
|
70
54
|
}
|
|
71
55
|
value() {
|
|
72
|
-
return
|
|
56
|
+
return this._value;
|
|
73
57
|
}
|
|
74
58
|
yield() {
|
|
75
|
-
return
|
|
59
|
+
return this._yield;
|
|
76
60
|
}
|
|
77
61
|
}
|
|
78
62
|
exports.PlayerTreasury = PlayerTreasury;
|
|
79
|
-
|
|
63
|
+
PlayerTreasury.transient = ['_cityBuildRegistry', '_ruleRegistry'];
|
|
80
64
|
exports.default = PlayerTreasury;
|
|
81
65
|
//# sourceMappingURL=PlayerTreasury.js.map
|
package/PlayerTreasury.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["PlayerTreasury.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Play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CAAC,cAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACvD,kDAAkD;QAClD,SAAS,CAAC,GAAG,CAAC,IAAI,eAAK,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,IAAU;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAE1D,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,eAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,KAAqB;QACvB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAEhB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,KAAqB;QAC5B,IAAI,KAAK,YAAY,eAAK,EAAE;YAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAExB,OAAO;SACR;QAED,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;IACvB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;;AApFH,wCAqFC;AApFiB,wBAAS,GAAG,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAsFtE,kBAAe,cAAc,CAAC"}
|
package/PlayerTreasury.ts
CHANGED
|
@@ -25,11 +25,12 @@ export interface IPlayerTreasury {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
static readonly transient = ['_cityBuildRegistry', '_ruleRegistry'];
|
|
29
|
+
private _cityBuildRegistry: CityBuildRegistry;
|
|
30
|
+
private _player: Player;
|
|
31
|
+
private _ruleRegistry: RuleRegistry;
|
|
32
|
+
private _value: number = 0;
|
|
33
|
+
private _yield: typeof Yield;
|
|
33
34
|
|
|
34
35
|
constructor(
|
|
35
36
|
player: Player,
|
|
@@ -41,10 +42,10 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
41
42
|
|
|
42
43
|
this.addKey('value', 'yield');
|
|
43
44
|
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
47
|
-
this
|
|
45
|
+
this._cityBuildRegistry = cityBuildRegistry;
|
|
46
|
+
this._player = player;
|
|
47
|
+
this._ruleRegistry = ruleRegistry;
|
|
48
|
+
this._yield = YieldType;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
add(value: Yield | number): void {
|
|
@@ -54,21 +55,21 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
this
|
|
58
|
+
this._value += value;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
buy(city: City): void {
|
|
61
|
-
const cityBuild = this
|
|
62
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city),
|
|
62
63
|
[spendCost] = this.cost(city).filter(
|
|
63
|
-
(spendCost) => spendCost.resource() === this
|
|
64
|
+
(spendCost) => spendCost.resource() === this._yield
|
|
64
65
|
),
|
|
65
66
|
cost = spendCost.value();
|
|
66
67
|
|
|
67
|
-
if (city.player() !== this
|
|
68
|
+
if (city.player() !== this._player || this.value() < cost) {
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
this
|
|
72
|
+
this._ruleRegistry.process(Rush, cityBuild, spendCost);
|
|
72
73
|
// TODO: do this via Rules and then use Production
|
|
73
74
|
cityBuild.add(new Yield(cityBuild.remaining()));
|
|
74
75
|
|
|
@@ -76,17 +77,17 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
cost(city: City): SpendCost[] {
|
|
79
|
-
const cityBuild = this
|
|
80
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city);
|
|
80
81
|
|
|
81
|
-
return this
|
|
82
|
+
return this._ruleRegistry.process(Spend, cityBuild);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
player(): Player {
|
|
85
|
-
return this
|
|
86
|
+
return this._player;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
set(value: Yield | number): void {
|
|
89
|
-
this
|
|
90
|
+
this._value = 0;
|
|
90
91
|
|
|
91
92
|
this.add(value);
|
|
92
93
|
}
|
|
@@ -98,15 +99,15 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
this
|
|
102
|
+
this._value -= value;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
value(): number {
|
|
105
|
-
return this
|
|
106
|
+
return this._value;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
yield(): typeof Yield {
|
|
109
|
-
return this
|
|
110
|
+
return this._yield;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
package/SpendCost.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ interface ISpend {
|
|
|
5
5
|
value(): number;
|
|
6
6
|
}
|
|
7
7
|
export declare class SpendCost extends DataObject implements ISpend {
|
|
8
|
-
|
|
8
|
+
private _resource;
|
|
9
|
+
private _value;
|
|
9
10
|
constructor(resource: typeof Yield, value: number);
|
|
10
11
|
resource(): typeof Yield;
|
|
11
12
|
value(): number;
|
package/SpendCost.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _SpendCost_resource, _SpendCost_value;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.SpendCost = void 0;
|
|
16
4
|
const DataObject_1 = require("@civ-clone/core-data-object/DataObject");
|
|
17
5
|
class SpendCost extends DataObject_1.default {
|
|
18
6
|
constructor(resource, value) {
|
|
19
7
|
super();
|
|
20
|
-
_SpendCost_resource.set(this, void 0);
|
|
21
|
-
_SpendCost_value.set(this, void 0);
|
|
22
8
|
this.addKey('resource', 'value');
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
this._resource = resource;
|
|
10
|
+
this._value = value;
|
|
25
11
|
}
|
|
26
12
|
resource() {
|
|
27
|
-
return
|
|
13
|
+
return this._resource;
|
|
28
14
|
}
|
|
29
15
|
value() {
|
|
30
|
-
return
|
|
16
|
+
return this._value;
|
|
31
17
|
}
|
|
32
18
|
}
|
|
33
19
|
exports.SpendCost = SpendCost;
|
|
34
|
-
_SpendCost_resource = new WeakMap(), _SpendCost_value = new WeakMap();
|
|
35
20
|
exports.default = SpendCost;
|
|
36
21
|
//# sourceMappingURL=SpendCost.js.map
|
package/SpendCost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpendCost.js","sourceRoot":"","sources":["SpendCost.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpendCost.js","sourceRoot":"","sources":["SpendCost.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAQhE,MAAa,SAAU,SAAQ,oBAAU;IAIvC,YAAY,QAAsB,EAAE,KAAa;QAC/C,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAEjC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AApBD,8BAoBC;AAED,kBAAe,SAAS,CAAC"}
|
package/SpendCost.ts
CHANGED
|
@@ -7,24 +7,24 @@ interface ISpend {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export class SpendCost extends DataObject implements ISpend {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
private _resource: typeof Yield;
|
|
11
|
+
private _value: number;
|
|
12
12
|
|
|
13
13
|
constructor(resource: typeof Yield, value: number) {
|
|
14
14
|
super();
|
|
15
15
|
|
|
16
16
|
this.addKey('resource', 'value');
|
|
17
17
|
|
|
18
|
-
this
|
|
19
|
-
this
|
|
18
|
+
this._resource = resource;
|
|
19
|
+
this._value = value;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
resource(): typeof Yield {
|
|
23
|
-
return this
|
|
23
|
+
return this._resource;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
value(): number {
|
|
27
|
-
return this
|
|
27
|
+
return this._value;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civ-clone/core-treasury",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "git@github.com:civ-clone/core-treasury.git",
|
|
6
6
|
"keywords": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@civ-clone/core-city": "^0.1.0",
|
|
25
25
|
"@civ-clone/core-city-build": "^0.1.0",
|
|
26
|
-
"@civ-clone/core-data-object": "^0.1.
|
|
26
|
+
"@civ-clone/core-data-object": "^0.1.15",
|
|
27
27
|
"@civ-clone/core-player": "^0.1.0",
|
|
28
28
|
"@civ-clone/core-registry": "^0.1.0",
|
|
29
29
|
"@civ-clone/core-rule": "^0.1.0",
|