@civ-clone/core-treasury 0.1.7 → 0.1.9
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/AdditionalData/sale-value.d.ts +6 -0
- package/AdditionalData/sale-value.js +13 -0
- package/AdditionalData/sale-value.js.map +1 -0
- package/AdditionalData/sale-value.ts +20 -0
- package/PlayerTreasury.d.ts +5 -0
- package/PlayerTreasury.js +22 -2
- package/PlayerTreasury.js.map +1 -1
- package/PlayerTreasury.ts +39 -3
- package/Rules/Sell.d.ts +5 -0
- package/Rules/Sell.js +10 -0
- package/Rules/Sell.js.map +1 -0
- package/Rules/Sell.ts +8 -0
- package/Rules/Sold.d.ts +8 -0
- package/Rules/Sold.js +9 -0
- package/Rules/Sold.js.map +1 -0
- package/Rules/Sold.ts +7 -0
- package/package.json +2 -1
- package/registerAdditionalData.js +2 -1
- package/registerAdditionalData.js.map +1 -1
- package/registerAdditionalData.ts +6 -1
- package/tests/PlayerTreasury.test.ts +134 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
2
|
+
import AdditionalData from '@civ-clone/core-data-object/AdditionalData';
|
|
3
|
+
export declare const getAdditionalData: (
|
|
4
|
+
ruleRegistry?: RuleRegistry
|
|
5
|
+
) => AdditionalData[];
|
|
6
|
+
export default getAdditionalData;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAdditionalData = void 0;
|
|
4
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
5
|
+
const AdditionalData_1 = require("@civ-clone/core-data-object/AdditionalData");
|
|
6
|
+
const CityImprovement_1 = require("@civ-clone/core-city-improvement/CityImprovement");
|
|
7
|
+
const Sell_1 = require("../Rules/Sell");
|
|
8
|
+
const getAdditionalData = (ruleRegistry = RuleRegistry_1.instance) => [
|
|
9
|
+
new AdditionalData_1.default(CityImprovement_1.default, 'saleValue', (cityImprovement) => ruleRegistry.process(Sell_1.default, cityImprovement)),
|
|
10
|
+
];
|
|
11
|
+
exports.getAdditionalData = getAdditionalData;
|
|
12
|
+
exports.default = exports.getAdditionalData;
|
|
13
|
+
//# sourceMappingURL=sale-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sale-value.js","sourceRoot":"","sources":["sale-value.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,+EAAwE;AACxE,sFAA+E;AAC/E,wCAAiC;AAE1B,MAAM,iBAAiB,GAAG,CAC/B,eAA6B,uBAAoB,EACjD,EAAE,CAAC;IACH,IAAI,wBAAc,CAChB,yBAAe,EACf,WAAW,EACX,CAAC,eAAgC,EAAE,EAAE,CACnC,YAAY,CAAC,OAAO,CAAC,cAAI,EAAE,eAAe,CAAC,CAC9C;CACF,CAAC;AATW,QAAA,iBAAiB,qBAS5B;AAEF,kBAAe,yBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuleRegistry,
|
|
3
|
+
instance as ruleRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-rule/RuleRegistry';
|
|
5
|
+
import AdditionalData from '@civ-clone/core-data-object/AdditionalData';
|
|
6
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
7
|
+
import Sell from '../Rules/Sell';
|
|
8
|
+
|
|
9
|
+
export const getAdditionalData = (
|
|
10
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance
|
|
11
|
+
) => [
|
|
12
|
+
new AdditionalData(
|
|
13
|
+
CityImprovement,
|
|
14
|
+
'saleValue',
|
|
15
|
+
(cityImprovement: CityImprovement) =>
|
|
16
|
+
ruleRegistry.process(Sell, cityImprovement)
|
|
17
|
+
),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export default getAdditionalData;
|
package/PlayerTreasury.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CityBuildRegistry } from '@civ-clone/core-city-build/CityBuildRegistry';
|
|
2
2
|
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
3
3
|
import City from '@civ-clone/core-city/City';
|
|
4
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
4
5
|
import DataObject from '@civ-clone/core-data-object/DataObject';
|
|
5
6
|
import Player from '@civ-clone/core-player/Player';
|
|
6
7
|
import SpendCost from './SpendCost';
|
|
@@ -10,6 +11,8 @@ export interface IPlayerTreasury {
|
|
|
10
11
|
buy(city: City): void;
|
|
11
12
|
cost(city: City): SpendCost[];
|
|
12
13
|
player(): Player;
|
|
14
|
+
saleValue(cityImprovement: CityImprovement): SpendCost[];
|
|
15
|
+
sell(cityImprovement: CityImprovement): void;
|
|
13
16
|
set(value: Yield | number, provider: string): void;
|
|
14
17
|
subtract(value: Yield | number, provider: string): void;
|
|
15
18
|
yield(): typeof Yield;
|
|
@@ -34,6 +37,8 @@ export declare class PlayerTreasury
|
|
|
34
37
|
buy(city: City): void;
|
|
35
38
|
cost(city: City): SpendCost[];
|
|
36
39
|
player(): Player;
|
|
40
|
+
saleValue(cityImprovement: CityImprovement): SpendCost[];
|
|
41
|
+
sell(cityImprovement: CityImprovement): void;
|
|
37
42
|
set(value: Yield | number): void;
|
|
38
43
|
subtract(value: Yield | number): void;
|
|
39
44
|
value(): number;
|
package/PlayerTreasury.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.PlayerTreasury = void 0;
|
|
|
4
4
|
const CityBuildRegistry_1 = require("@civ-clone/core-city-build/CityBuildRegistry");
|
|
5
5
|
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
6
6
|
const DataObject_1 = require("@civ-clone/core-data-object/DataObject");
|
|
7
|
+
const Sell_1 = require("./Rules/Sell");
|
|
8
|
+
const Sold_1 = require("./Rules/Sold");
|
|
7
9
|
const Spend_1 = require("./Rules/Spend");
|
|
8
10
|
const Yield_1 = require("@civ-clone/core-yield/Yield");
|
|
9
11
|
const Rush_1 = require("./Rules/Rush");
|
|
@@ -25,8 +27,11 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
25
27
|
this._value += value;
|
|
26
28
|
}
|
|
27
29
|
buy(city) {
|
|
28
|
-
const cityBuild = this._cityBuildRegistry.getByCity(city), [spendCost] = this.cost(city).filter((spendCost) => spendCost.resource() === this._yield), cost = spendCost.value();
|
|
29
|
-
|
|
30
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city), [spendCost] = this.cost(city).filter((spendCost) => spendCost.resource() === this._yield), cost = spendCost === null || spendCost === void 0 ? void 0 : spendCost.value();
|
|
31
|
+
// Nothing to buy when the rules give no price in this treasury's yield.
|
|
32
|
+
if (cost === undefined ||
|
|
33
|
+
city.player() !== this._player ||
|
|
34
|
+
this.value() < cost) {
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
37
|
this._ruleRegistry.process(Rush_1.default, cityBuild, spendCost);
|
|
@@ -41,6 +46,21 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
41
46
|
player() {
|
|
42
47
|
return this._player;
|
|
43
48
|
}
|
|
49
|
+
saleValue(cityImprovement) {
|
|
50
|
+
return this._ruleRegistry.process(Sell_1.default, cityImprovement);
|
|
51
|
+
}
|
|
52
|
+
sell(cityImprovement) {
|
|
53
|
+
const [spendCost] = this.saleValue(cityImprovement).filter((spendCost) => spendCost.resource() === this._yield), value = spendCost === null || spendCost === void 0 ? void 0 : spendCost.value();
|
|
54
|
+
// Nothing to sell when the rules give no value in this treasury's yield.
|
|
55
|
+
if (value === undefined ||
|
|
56
|
+
cityImprovement.city().player() !== this._player ||
|
|
57
|
+
cityImprovement.destroyed()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
cityImprovement.destroy();
|
|
61
|
+
this.add(value);
|
|
62
|
+
this._ruleRegistry.process(Sold_1.default, cityImprovement, this);
|
|
63
|
+
}
|
|
44
64
|
set(value) {
|
|
45
65
|
this._value = 0;
|
|
46
66
|
this.add(value);
|
package/PlayerTreasury.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["PlayerTreasury.ts"],"names":[],"mappings":";;;AAAA,oFAGsD;AACtD,oEAG2C;
|
|
1
|
+
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["PlayerTreasury.ts"],"names":[],"mappings":"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"}
|
package/PlayerTreasury.ts
CHANGED
|
@@ -7,8 +7,11 @@ import {
|
|
|
7
7
|
instance as ruleRegistryInstance,
|
|
8
8
|
} from '@civ-clone/core-rule/RuleRegistry';
|
|
9
9
|
import City from '@civ-clone/core-city/City';
|
|
10
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
10
11
|
import DataObject from '@civ-clone/core-data-object/DataObject';
|
|
11
12
|
import Player from '@civ-clone/core-player/Player';
|
|
13
|
+
import Sell from './Rules/Sell';
|
|
14
|
+
import Sold from './Rules/Sold';
|
|
12
15
|
import Spend from './Rules/Spend';
|
|
13
16
|
import SpendCost from './SpendCost';
|
|
14
17
|
import Yield from '@civ-clone/core-yield/Yield';
|
|
@@ -19,6 +22,8 @@ export interface IPlayerTreasury {
|
|
|
19
22
|
buy(city: City): void;
|
|
20
23
|
cost(city: City): SpendCost[];
|
|
21
24
|
player(): Player;
|
|
25
|
+
saleValue(cityImprovement: CityImprovement): SpendCost[];
|
|
26
|
+
sell(cityImprovement: CityImprovement): void;
|
|
22
27
|
set(value: Yield | number, provider: string): void;
|
|
23
28
|
subtract(value: Yield | number, provider: string): void;
|
|
24
29
|
yield(): typeof Yield;
|
|
@@ -63,9 +68,14 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
63
68
|
[spendCost] = this.cost(city).filter(
|
|
64
69
|
(spendCost) => spendCost.resource() === this._yield
|
|
65
70
|
),
|
|
66
|
-
cost = spendCost
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
cost = spendCost?.value();
|
|
72
|
+
|
|
73
|
+
// Nothing to buy when the rules give no price in this treasury's yield.
|
|
74
|
+
if (
|
|
75
|
+
cost === undefined ||
|
|
76
|
+
city.player() !== this._player ||
|
|
77
|
+
this.value() < cost
|
|
78
|
+
) {
|
|
69
79
|
return;
|
|
70
80
|
}
|
|
71
81
|
|
|
@@ -86,6 +96,32 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
86
96
|
return this._player;
|
|
87
97
|
}
|
|
88
98
|
|
|
99
|
+
saleValue(cityImprovement: CityImprovement): SpendCost[] {
|
|
100
|
+
return this._ruleRegistry.process(Sell, cityImprovement);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
sell(cityImprovement: CityImprovement): void {
|
|
104
|
+
const [spendCost] = this.saleValue(cityImprovement).filter(
|
|
105
|
+
(spendCost) => spendCost.resource() === this._yield
|
|
106
|
+
),
|
|
107
|
+
value = spendCost?.value();
|
|
108
|
+
|
|
109
|
+
// Nothing to sell when the rules give no value in this treasury's yield.
|
|
110
|
+
if (
|
|
111
|
+
value === undefined ||
|
|
112
|
+
cityImprovement.city().player() !== this._player ||
|
|
113
|
+
cityImprovement.destroyed()
|
|
114
|
+
) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
cityImprovement.destroy();
|
|
119
|
+
|
|
120
|
+
this.add(value);
|
|
121
|
+
|
|
122
|
+
this._ruleRegistry.process(Sold, cityImprovement, this);
|
|
123
|
+
}
|
|
124
|
+
|
|
89
125
|
set(value: Yield | number): void {
|
|
90
126
|
this._value = 0;
|
|
91
127
|
|
package/Rules/Sell.d.ts
ADDED
package/Rules/Sell.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sell = void 0;
|
|
4
|
+
const Rule_1 = require("@civ-clone/core-rule/Rule");
|
|
5
|
+
// What a `CityImprovement` sells for. No result means it can't be sold now.
|
|
6
|
+
class Sell extends Rule_1.default {
|
|
7
|
+
}
|
|
8
|
+
exports.Sell = Sell;
|
|
9
|
+
exports.default = Sell;
|
|
10
|
+
//# sourceMappingURL=Sell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sell.js","sourceRoot":"","sources":["Sell.ts"],"names":[],"mappings":";;;AACA,oDAA6C;AAG7C,4EAA4E;AAC5E,MAAa,IAAK,SAAQ,cAAkC;CAAG;AAA/D,oBAA+D;AAE/D,kBAAe,IAAI,CAAC"}
|
package/Rules/Sell.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
2
|
+
import Rule from '@civ-clone/core-rule/Rule';
|
|
3
|
+
import SpendCost from '../SpendCost';
|
|
4
|
+
|
|
5
|
+
// What a `CityImprovement` sells for. No result means it can't be sold now.
|
|
6
|
+
export class Sell extends Rule<[CityImprovement], SpendCost> {}
|
|
7
|
+
|
|
8
|
+
export default Sell;
|
package/Rules/Sold.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
2
|
+
import PlayerTreasury from '../PlayerTreasury';
|
|
3
|
+
import Rule from '@civ-clone/core-rule/Rule';
|
|
4
|
+
export declare class Sold extends Rule<
|
|
5
|
+
[CityImprovement, PlayerTreasury],
|
|
6
|
+
void
|
|
7
|
+
> {}
|
|
8
|
+
export default Sold;
|
package/Rules/Sold.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sold = void 0;
|
|
4
|
+
const Rule_1 = require("@civ-clone/core-rule/Rule");
|
|
5
|
+
class Sold extends Rule_1.default {
|
|
6
|
+
}
|
|
7
|
+
exports.Sold = Sold;
|
|
8
|
+
exports.default = Sold;
|
|
9
|
+
//# sourceMappingURL=Sold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sold.js","sourceRoot":"","sources":["Sold.ts"],"names":[],"mappings":";;;AAEA,oDAA6C;AAE7C,MAAa,IAAK,SAAQ,cAA6C;CAAG;AAA1E,oBAA0E;AAE1E,kBAAe,IAAI,CAAC"}
|
package/Rules/Sold.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
2
|
+
import PlayerTreasury from '../PlayerTreasury';
|
|
3
|
+
import Rule from '@civ-clone/core-rule/Rule';
|
|
4
|
+
|
|
5
|
+
export class Sold extends Rule<[CityImprovement, PlayerTreasury], void> {}
|
|
6
|
+
|
|
7
|
+
export default Sold;
|
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.9",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "git@github.com:civ-clone/core-treasury.git",
|
|
6
6
|
"keywords": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@civ-clone/core-city": "^0.1.0",
|
|
34
34
|
"@civ-clone/core-city-build": "^0.1.0",
|
|
35
|
+
"@civ-clone/core-city-improvement": "^0.1.0",
|
|
35
36
|
"@civ-clone/core-data-object": "^0.1.15",
|
|
36
37
|
"@civ-clone/core-player": "^0.1.0",
|
|
37
38
|
"@civ-clone/core-registry": "^0.1.0",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const AdditionalDataRegistry_1 = require("@civ-clone/core-data-object/AdditionalDataRegistry");
|
|
4
|
+
const sale_value_1 = require("./AdditionalData/sale-value");
|
|
4
5
|
const spend_cost_1 = require("./AdditionalData/spend-cost");
|
|
5
6
|
const treasuries_1 = require("./AdditionalData/treasuries");
|
|
6
|
-
AdditionalDataRegistry_1.instance.register(...(0, spend_cost_1.default)(), ...(0, treasuries_1.default)());
|
|
7
|
+
AdditionalDataRegistry_1.instance.register(...(0, sale_value_1.default)(), ...(0, spend_cost_1.default)(), ...(0, treasuries_1.default)());
|
|
7
8
|
//# sourceMappingURL=registerAdditionalData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerAdditionalData.js","sourceRoot":"","sources":["registerAdditionalData.ts"],"names":[],"mappings":";;AAAA,+FAAgH;AAChH,4DAAoD;AACpD,4DAAmD;AAEnD,iCAA8B,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"registerAdditionalData.js","sourceRoot":"","sources":["registerAdditionalData.ts"],"names":[],"mappings":";;AAAA,+FAAgH;AAChH,4DAAoD;AACpD,4DAAoD;AACpD,4DAAmD;AAEnD,iCAA8B,CAAC,QAAQ,CACrC,GAAG,IAAA,oBAAS,GAAE,EACd,GAAG,IAAA,oBAAS,GAAE,EACd,GAAG,IAAA,oBAAQ,GAAE,CACd,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { instance as additionalDataRegistryInstance } from '@civ-clone/core-data-object/AdditionalDataRegistry';
|
|
2
|
+
import saleValue from './AdditionalData/sale-value';
|
|
2
3
|
import spendCost from './AdditionalData/spend-cost';
|
|
3
4
|
import treasury from './AdditionalData/treasuries';
|
|
4
5
|
|
|
5
|
-
additionalDataRegistryInstance.register(
|
|
6
|
+
additionalDataRegistryInstance.register(
|
|
7
|
+
...saleValue(),
|
|
8
|
+
...spendCost(),
|
|
9
|
+
...treasury()
|
|
10
|
+
);
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import City from '@civ-clone/core-city/City';
|
|
2
|
+
import CityBuild from '@civ-clone/core-city-build/CityBuild';
|
|
3
|
+
import CityBuildRegistry from '@civ-clone/core-city-build/CityBuildRegistry';
|
|
4
|
+
import CityImprovement from '@civ-clone/core-city-improvement/CityImprovement';
|
|
5
|
+
import Criterion from '@civ-clone/core-rule/Criterion';
|
|
6
|
+
import Effect from '@civ-clone/core-rule/Effect';
|
|
1
7
|
import Player from '@civ-clone/core-player/Player';
|
|
2
8
|
import PlayerTreasury from '../PlayerTreasury';
|
|
9
|
+
import RuleRegistry from '@civ-clone/core-rule/RuleRegistry';
|
|
10
|
+
import Sell from '../Rules/Sell';
|
|
11
|
+
import Sold from '../Rules/Sold';
|
|
12
|
+
import SpendCost from '../SpendCost';
|
|
3
13
|
import Yield from '@civ-clone/core-yield/Yield';
|
|
4
14
|
import { expect } from 'chai';
|
|
5
15
|
|
|
@@ -44,4 +54,128 @@ describe('PlayerTreasury', () => {
|
|
|
44
54
|
expect(fromNumber.value()).to.equal(5);
|
|
45
55
|
expect(fromYield.value()).to.equal(5);
|
|
46
56
|
});
|
|
57
|
+
|
|
58
|
+
it("doesn't buy, or throw, when the rules give no price", () => {
|
|
59
|
+
const player = new Player(),
|
|
60
|
+
city = { player: () => player } as unknown as City;
|
|
61
|
+
let added = false;
|
|
62
|
+
|
|
63
|
+
const cityBuild = {
|
|
64
|
+
city: () => city,
|
|
65
|
+
remaining: () => 10,
|
|
66
|
+
add: () => (added = true),
|
|
67
|
+
} as unknown as CityBuild,
|
|
68
|
+
cityBuildRegistry = {
|
|
69
|
+
getByCity: () => cityBuild,
|
|
70
|
+
} as unknown as CityBuildRegistry,
|
|
71
|
+
playerTreasury = new PlayerTreasury(
|
|
72
|
+
player,
|
|
73
|
+
Yield,
|
|
74
|
+
cityBuildRegistry,
|
|
75
|
+
new RuleRegistry()
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
playerTreasury.set(100);
|
|
79
|
+
|
|
80
|
+
expect(() => playerTreasury.buy(city)).not.to.throw();
|
|
81
|
+
expect(playerTreasury.value()).to.equal(100);
|
|
82
|
+
expect(added).to.equal(false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('sell', () => {
|
|
86
|
+
class Temple extends CityImprovement {}
|
|
87
|
+
class Wonder extends CityImprovement {}
|
|
88
|
+
|
|
89
|
+
const setup = () => {
|
|
90
|
+
const player = new Player(),
|
|
91
|
+
city = { player: () => player } as unknown as City,
|
|
92
|
+
ruleRegistry = new RuleRegistry(),
|
|
93
|
+
sold: CityImprovement[] = [];
|
|
94
|
+
|
|
95
|
+
ruleRegistry.register(
|
|
96
|
+
new Sell(
|
|
97
|
+
new Criterion(
|
|
98
|
+
(cityImprovement: CityImprovement): boolean =>
|
|
99
|
+
!(cityImprovement instanceof Wonder)
|
|
100
|
+
),
|
|
101
|
+
new Effect((): SpendCost => new SpendCost(Yield, 40))
|
|
102
|
+
),
|
|
103
|
+
new Sold(
|
|
104
|
+
new Effect((cityImprovement: CityImprovement): void => {
|
|
105
|
+
sold.push(cityImprovement);
|
|
106
|
+
})
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const playerTreasury = new PlayerTreasury(
|
|
111
|
+
player,
|
|
112
|
+
Yield,
|
|
113
|
+
new CityBuildRegistry(),
|
|
114
|
+
ruleRegistry
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
playerTreasury.set(10);
|
|
118
|
+
|
|
119
|
+
return { city, playerTreasury, ruleRegistry, sold };
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
it('gives the value the rules give', () => {
|
|
123
|
+
const { city, playerTreasury, ruleRegistry } = setup(),
|
|
124
|
+
[spendCost] = playerTreasury.saleValue(new Temple(city, ruleRegistry));
|
|
125
|
+
|
|
126
|
+
expect(spendCost.resource()).to.equal(Yield);
|
|
127
|
+
expect(spendCost.value()).to.equal(40);
|
|
128
|
+
expect(
|
|
129
|
+
playerTreasury.saleValue(new Wonder(city, ruleRegistry))
|
|
130
|
+
).to.have.length(0);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('destroys the improvement, adds its value and processes Sold', () => {
|
|
134
|
+
const { city, playerTreasury, ruleRegistry, sold } = setup(),
|
|
135
|
+
temple = new Temple(city, ruleRegistry);
|
|
136
|
+
|
|
137
|
+
playerTreasury.sell(temple);
|
|
138
|
+
|
|
139
|
+
expect(temple.destroyed()).to.equal(true);
|
|
140
|
+
expect(playerTreasury.value()).to.equal(50);
|
|
141
|
+
expect(sold).to.deep.equal([temple]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("doesn't sell what the rules give no value for", () => {
|
|
145
|
+
const { city, playerTreasury, ruleRegistry, sold } = setup(),
|
|
146
|
+
wonder = new Wonder(city, ruleRegistry);
|
|
147
|
+
|
|
148
|
+
playerTreasury.sell(wonder);
|
|
149
|
+
|
|
150
|
+
expect(wonder.destroyed()).to.equal(false);
|
|
151
|
+
expect(playerTreasury.value()).to.equal(10);
|
|
152
|
+
expect(sold).to.have.length(0);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("doesn't sell another player's improvement", () => {
|
|
156
|
+
const { playerTreasury, ruleRegistry, sold } = setup(),
|
|
157
|
+
other = new Player(),
|
|
158
|
+
temple = new Temple(
|
|
159
|
+
{ player: () => other } as unknown as City,
|
|
160
|
+
ruleRegistry
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
playerTreasury.sell(temple);
|
|
164
|
+
|
|
165
|
+
expect(temple.destroyed()).to.equal(false);
|
|
166
|
+
expect(playerTreasury.value()).to.equal(10);
|
|
167
|
+
expect(sold).to.have.length(0);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("doesn't sell an improvement twice", () => {
|
|
171
|
+
const { city, playerTreasury, ruleRegistry, sold } = setup(),
|
|
172
|
+
temple = new Temple(city, ruleRegistry);
|
|
173
|
+
|
|
174
|
+
playerTreasury.sell(temple);
|
|
175
|
+
playerTreasury.sell(temple);
|
|
176
|
+
|
|
177
|
+
expect(playerTreasury.value()).to.equal(50);
|
|
178
|
+
expect(sold).to.have.length(1);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
47
181
|
});
|