@civ-clone/base-unit-action-steal-technology 0.0.0-stage → 0.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.
- package/.gitattributes +2 -0
- package/.github/workflows/build-on-push.yml +39 -0
- package/.prettierrc +4 -0
- package/AdvanceStolen.d.ts +25 -0
- package/AdvanceStolen.js +31 -0
- package/AdvanceStolen.js.map +1 -0
- package/AdvanceStolen.ts +51 -0
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/Rules/TechnologyStolen.d.ts +9 -0
- package/Rules/TechnologyStolen.js +13 -0
- package/Rules/TechnologyStolen.js.map +1 -0
- package/Rules/TechnologyStolen.ts +11 -0
- package/SneakStealTechnology.d.ts +22 -0
- package/SneakStealTechnology.js +23 -0
- package/SneakStealTechnology.js.map +1 -0
- package/SneakStealTechnology.ts +48 -0
- package/StealTechnology.d.ts +19 -0
- package/StealTechnology.js +32 -0
- package/StealTechnology.js.map +1 -0
- package/StealTechnology.ts +59 -0
- package/package.json +31 -4
- package/tsconfig.json +16 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Build and test application on push to remote
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v4
|
|
10
|
+
- uses: pnpm/action-setup@v4
|
|
11
|
+
with:
|
|
12
|
+
version: 11
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 22
|
|
16
|
+
# No lock file, so this tests what a consumer resolves. The settings match
|
|
17
|
+
# web-renderer's pnpm-workspace.yaml: several @civ-clone packages depend on
|
|
18
|
+
# each other as `github:` URLs, this project's own releases are often only
|
|
19
|
+
# minutes old, and nothing here needs a dependency's build script.
|
|
20
|
+
- run: >-
|
|
21
|
+
pnpm install --no-frozen-lockfile
|
|
22
|
+
--config.block-exotic-subdeps=false
|
|
23
|
+
--config.minimum-release-age=0
|
|
24
|
+
--config.strict-dep-builds=false
|
|
25
|
+
- run: npm run --if-present prettier:check
|
|
26
|
+
# The tests load the committed `.js`, so compile to prove the source
|
|
27
|
+
# type-checks, and fail if the committed output is stale. `--force`
|
|
28
|
+
# because a fresh checkout's timestamps can make `tsc --build` treat the
|
|
29
|
+
# committed output as up to date and skip the compile entirely.
|
|
30
|
+
- run: npm run --if-present ts:compile -- --force
|
|
31
|
+
- run: npm run --if-present prettier:format
|
|
32
|
+
# Stale *or never committed* output fails: `git diff` alone misses a new
|
|
33
|
+
# module whose `.js` was never added, which the published package would
|
|
34
|
+
# then omit. Only the compiled extensions, so the lock file the install
|
|
35
|
+
# writes cannot fail it; `node_modules` is ignored, so it stays out.
|
|
36
|
+
- run: |
|
|
37
|
+
git status --short --untracked-files=all -- '*.js' '*.d.ts' '*.js.map'
|
|
38
|
+
test -z "$(git status --porcelain --untracked-files=all -- '*.js' '*.d.ts' '*.js.map')"
|
|
39
|
+
- run: npm run --if-present test
|
package/.prettierrc
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
2
|
+
import { Turn } from '@civ-clone/core-turn-based-game/Turn';
|
|
3
|
+
import City from '@civ-clone/core-city/City';
|
|
4
|
+
import Interaction from '@civ-clone/core-diplomacy/Interaction';
|
|
5
|
+
import Player from '@civ-clone/core-player/Player';
|
|
6
|
+
/**
|
|
7
|
+
* A record that `thief()` stole an advance from `victim()` in `city()`, so a city can be robbed only once. What
|
|
8
|
+
* clears it (v474.05: the city changing hands) is up to the ruleset.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AdvanceStolen extends Interaction {
|
|
11
|
+
private _city;
|
|
12
|
+
private _thief;
|
|
13
|
+
private _victim;
|
|
14
|
+
constructor(
|
|
15
|
+
thief: Player,
|
|
16
|
+
victim: Player,
|
|
17
|
+
city: City,
|
|
18
|
+
ruleRegistry?: RuleRegistry,
|
|
19
|
+
turn?: Turn
|
|
20
|
+
);
|
|
21
|
+
city(): City;
|
|
22
|
+
thief(): Player;
|
|
23
|
+
victim(): Player;
|
|
24
|
+
}
|
|
25
|
+
export default AdvanceStolen;
|
package/AdvanceStolen.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdvanceStolen = void 0;
|
|
4
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
5
|
+
const Turn_1 = require("@civ-clone/core-turn-based-game/Turn");
|
|
6
|
+
const Interaction_1 = require("@civ-clone/core-diplomacy/Interaction");
|
|
7
|
+
/**
|
|
8
|
+
* A record that `thief()` stole an advance from `victim()` in `city()`, so a city can be robbed only once. What
|
|
9
|
+
* clears it (v474.05: the city changing hands) is up to the ruleset.
|
|
10
|
+
*/
|
|
11
|
+
class AdvanceStolen extends Interaction_1.default {
|
|
12
|
+
constructor(thief, victim, city, ruleRegistry = RuleRegistry_1.instance, turn = Turn_1.instance) {
|
|
13
|
+
super(thief, victim, ruleRegistry, turn);
|
|
14
|
+
this._city = city;
|
|
15
|
+
this._thief = thief;
|
|
16
|
+
this._victim = victim;
|
|
17
|
+
this.addKey('city', 'thief', 'victim');
|
|
18
|
+
}
|
|
19
|
+
city() {
|
|
20
|
+
return this._city;
|
|
21
|
+
}
|
|
22
|
+
thief() {
|
|
23
|
+
return this._thief;
|
|
24
|
+
}
|
|
25
|
+
victim() {
|
|
26
|
+
return this._victim;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AdvanceStolen = AdvanceStolen;
|
|
30
|
+
exports.default = AdvanceStolen;
|
|
31
|
+
//# sourceMappingURL=AdvanceStolen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdvanceStolen.js","sourceRoot":"","sources":["AdvanceStolen.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,+DAG8C;AAE9C,uEAAgE;AAGhE;;;GAGG;AACH,MAAa,aAAc,SAAQ,qBAAW;IAK5C,YACE,KAAa,EACb,MAAc,EACd,IAAU,EACV,eAA6B,uBAAoB,EACjD,OAAa,eAAY;QAEzB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QAEzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAhCD,sCAgCC;AAED,kBAAe,aAAa,CAAC"}
|
package/AdvanceStolen.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuleRegistry,
|
|
3
|
+
instance as ruleRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-rule/RuleRegistry';
|
|
5
|
+
import {
|
|
6
|
+
Turn,
|
|
7
|
+
instance as turnInstance,
|
|
8
|
+
} from '@civ-clone/core-turn-based-game/Turn';
|
|
9
|
+
import City from '@civ-clone/core-city/City';
|
|
10
|
+
import Interaction from '@civ-clone/core-diplomacy/Interaction';
|
|
11
|
+
import Player from '@civ-clone/core-player/Player';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A record that `thief()` stole an advance from `victim()` in `city()`, so a city can be robbed only once. What
|
|
15
|
+
* clears it (v474.05: the city changing hands) is up to the ruleset.
|
|
16
|
+
*/
|
|
17
|
+
export class AdvanceStolen extends Interaction {
|
|
18
|
+
private _city: City;
|
|
19
|
+
private _thief: Player;
|
|
20
|
+
private _victim: Player;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
thief: Player,
|
|
24
|
+
victim: Player,
|
|
25
|
+
city: City,
|
|
26
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance,
|
|
27
|
+
turn: Turn = turnInstance
|
|
28
|
+
) {
|
|
29
|
+
super(thief, victim, ruleRegistry, turn);
|
|
30
|
+
|
|
31
|
+
this._city = city;
|
|
32
|
+
this._thief = thief;
|
|
33
|
+
this._victim = victim;
|
|
34
|
+
|
|
35
|
+
this.addKey('city', 'thief', 'victim');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
city(): City {
|
|
39
|
+
return this._city;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
thief(): Player {
|
|
43
|
+
return this._thief;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
victim(): Player {
|
|
47
|
+
return this._victim;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default AdvanceStolen;
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dom Hastings
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# base-unit-action-steal-technology
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `StealTechnology` and `SneakStealTechnology` unit actions, and the `AdvanceStolen` interaction that records a theft. See civ-clone/web-renderer#58.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import City from '@civ-clone/core-city/City';
|
|
2
|
+
import Rule from '@civ-clone/core-rule/Rule';
|
|
3
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
4
|
+
/**
|
|
5
|
+
* Processed when a Diplomat (`Unit`) steals an advance from `City`'s owner. `true` when something was stolen, which
|
|
6
|
+
* uses the Diplomat up.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TechnologyStolen extends Rule<[Unit, City], boolean> {}
|
|
9
|
+
export default TechnologyStolen;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TechnologyStolen = void 0;
|
|
4
|
+
const Rule_1 = require("@civ-clone/core-rule/Rule");
|
|
5
|
+
/**
|
|
6
|
+
* Processed when a Diplomat (`Unit`) steals an advance from `City`'s owner. `true` when something was stolen, which
|
|
7
|
+
* uses the Diplomat up.
|
|
8
|
+
*/
|
|
9
|
+
class TechnologyStolen extends Rule_1.default {
|
|
10
|
+
}
|
|
11
|
+
exports.TechnologyStolen = TechnologyStolen;
|
|
12
|
+
exports.default = TechnologyStolen;
|
|
13
|
+
//# sourceMappingURL=TechnologyStolen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TechnologyStolen.js","sourceRoot":"","sources":["TechnologyStolen.ts"],"names":[],"mappings":";;;AACA,oDAA6C;AAG7C;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,cAA2B;CAAG;AAApE,4CAAoE;AAEpE,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import City from '@civ-clone/core-city/City';
|
|
2
|
+
import Rule from '@civ-clone/core-rule/Rule';
|
|
3
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Processed when a Diplomat (`Unit`) steals an advance from `City`'s owner. `true` when something was stolen, which
|
|
7
|
+
* uses the Diplomat up.
|
|
8
|
+
*/
|
|
9
|
+
export class TechnologyStolen extends Rule<[Unit, City], boolean> {}
|
|
10
|
+
|
|
11
|
+
export default TechnologyStolen;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
2
|
+
import Action from '@civ-clone/core-unit/Action';
|
|
3
|
+
import City from '@civ-clone/core-city/City';
|
|
4
|
+
import Player from '@civ-clone/core-player/Player';
|
|
5
|
+
import StealTechnology from './StealTechnology';
|
|
6
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
7
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
8
|
+
/** Stealing from a civilization the thief is at peace with, which ends the peace. */
|
|
9
|
+
export declare class SneakStealTechnology extends StealTechnology {
|
|
10
|
+
private _enemy;
|
|
11
|
+
constructor(
|
|
12
|
+
from: Tile,
|
|
13
|
+
to: Tile,
|
|
14
|
+
unit: Unit,
|
|
15
|
+
city: City,
|
|
16
|
+
enemy: Player,
|
|
17
|
+
ruleRegistry?: RuleRegistry
|
|
18
|
+
);
|
|
19
|
+
enemy(): Player;
|
|
20
|
+
forUnit(unit: Unit): Action;
|
|
21
|
+
}
|
|
22
|
+
export default SneakStealTechnology;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SneakStealTechnology = void 0;
|
|
4
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
5
|
+
const StealTechnology_1 = require("./StealTechnology");
|
|
6
|
+
/** Stealing from a civilization the thief is at peace with, which ends the peace. */
|
|
7
|
+
class SneakStealTechnology extends StealTechnology_1.default {
|
|
8
|
+
constructor(from, to, unit, city, enemy, ruleRegistry = RuleRegistry_1.instance) {
|
|
9
|
+
super(from, to, unit, city, ruleRegistry);
|
|
10
|
+
this._enemy = enemy;
|
|
11
|
+
this.addKey('enemy');
|
|
12
|
+
}
|
|
13
|
+
enemy() {
|
|
14
|
+
return this._enemy;
|
|
15
|
+
}
|
|
16
|
+
// Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
|
|
17
|
+
forUnit(unit) {
|
|
18
|
+
return new SneakStealTechnology(this.from(), this.to(), unit, this._city, this._enemy, this.ruleRegistry());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.SneakStealTechnology = SneakStealTechnology;
|
|
22
|
+
exports.default = SneakStealTechnology;
|
|
23
|
+
//# sourceMappingURL=SneakStealTechnology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SneakStealTechnology.js","sourceRoot":"","sources":["SneakStealTechnology.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAI3C,uDAAgD;AAIhD,qFAAqF;AACrF,MAAa,oBAAqB,SAAQ,yBAAe;IAGvD,YACE,IAAU,EACV,EAAQ,EACR,IAAU,EACV,IAAU,EACV,KAAa,EACb,eAA6B,uBAAoB;QAEjD,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,6GAA6G;IAC7G,OAAO,CAAC,IAAU;QAChB,OAAO,IAAI,oBAAoB,CAC7B,IAAI,CAAC,IAAI,EAAE,EACX,IAAI,CAAC,EAAE,EAAE,EACT,IAAI,EACJ,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,YAAY,EAAE,CACC,CAAC;IACzB,CAAC;CACF;AAjCD,oDAiCC;AAED,kBAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuleRegistry,
|
|
3
|
+
instance as ruleRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-rule/RuleRegistry';
|
|
5
|
+
import Action from '@civ-clone/core-unit/Action';
|
|
6
|
+
import City from '@civ-clone/core-city/City';
|
|
7
|
+
import Player from '@civ-clone/core-player/Player';
|
|
8
|
+
import StealTechnology from './StealTechnology';
|
|
9
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
10
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
11
|
+
|
|
12
|
+
/** Stealing from a civilization the thief is at peace with, which ends the peace. */
|
|
13
|
+
export class SneakStealTechnology extends StealTechnology {
|
|
14
|
+
private _enemy: Player;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
from: Tile,
|
|
18
|
+
to: Tile,
|
|
19
|
+
unit: Unit,
|
|
20
|
+
city: City,
|
|
21
|
+
enemy: Player,
|
|
22
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance
|
|
23
|
+
) {
|
|
24
|
+
super(from, to, unit, city, ruleRegistry);
|
|
25
|
+
|
|
26
|
+
this._enemy = enemy;
|
|
27
|
+
|
|
28
|
+
this.addKey('enemy');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
enemy(): Player {
|
|
32
|
+
return this._enemy;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
|
|
36
|
+
forUnit(unit: Unit): Action {
|
|
37
|
+
return new SneakStealTechnology(
|
|
38
|
+
this.from(),
|
|
39
|
+
this.to(),
|
|
40
|
+
unit,
|
|
41
|
+
this._city,
|
|
42
|
+
this._enemy,
|
|
43
|
+
this.ruleRegistry()
|
|
44
|
+
) as unknown as Action;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default SneakStealTechnology;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
2
|
+
import Action from '@civ-clone/core-unit/Action';
|
|
3
|
+
import City from '@civ-clone/core-city/City';
|
|
4
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
5
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
6
|
+
/** A Diplomat steals an advance from `city()`'s owner. Which one, and whether there's anything to take, is up to the `TechnologyStolen` rules. The Diplomat is used up when something is stolen. */
|
|
7
|
+
export declare class StealTechnology extends Action {
|
|
8
|
+
protected _city: City;
|
|
9
|
+
constructor(
|
|
10
|
+
from: Tile,
|
|
11
|
+
to: Tile,
|
|
12
|
+
unit: Unit,
|
|
13
|
+
city: City,
|
|
14
|
+
ruleRegistry?: RuleRegistry
|
|
15
|
+
);
|
|
16
|
+
forUnit(unit: Unit): Action;
|
|
17
|
+
perform(): void;
|
|
18
|
+
}
|
|
19
|
+
export default StealTechnology;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StealTechnology = void 0;
|
|
4
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
5
|
+
const Action_1 = require("@civ-clone/core-unit/Action");
|
|
6
|
+
const Moved_1 = require("@civ-clone/core-unit/Rules/Moved");
|
|
7
|
+
const TechnologyStolen_1 = require("./Rules/TechnologyStolen");
|
|
8
|
+
/** A Diplomat steals an advance from `city()`'s owner. Which one, and whether there's anything to take, is up to the `TechnologyStolen` rules. The Diplomat is used up when something is stolen. */
|
|
9
|
+
class StealTechnology extends Action_1.default {
|
|
10
|
+
constructor(from, to, unit, city, ruleRegistry = RuleRegistry_1.instance) {
|
|
11
|
+
super(from, to, unit, ruleRegistry);
|
|
12
|
+
this._city = city;
|
|
13
|
+
}
|
|
14
|
+
// `Action.forUnit` rebuilds an action from `(from, to, unit, ruleRegistry)`, which would put the `RuleRegistry` where
|
|
15
|
+
// the `City` goes.
|
|
16
|
+
// Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
|
|
17
|
+
forUnit(unit) {
|
|
18
|
+
return new StealTechnology(this.from(), this.to(), unit, this._city, this.ruleRegistry());
|
|
19
|
+
}
|
|
20
|
+
perform() {
|
|
21
|
+
const results = this.ruleRegistry().process(TechnologyStolen_1.default, this.unit(), this._city);
|
|
22
|
+
// Nothing new to steal leaves the Diplomat where it is.
|
|
23
|
+
if (!results.includes(true)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.ruleRegistry().process(Moved_1.default, this.unit(), this);
|
|
27
|
+
this.unit().destroy();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.StealTechnology = StealTechnology;
|
|
31
|
+
exports.default = StealTechnology;
|
|
32
|
+
//# sourceMappingURL=StealTechnology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StealTechnology.js","sourceRoot":"","sources":["StealTechnology.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,wDAAiD;AAEjD,4DAAqD;AACrD,+DAAwD;AAIxD,oMAAoM;AACpM,MAAa,eAAgB,SAAQ,gBAAM;IAGzC,YACE,IAAU,EACV,EAAQ,EACR,IAAU,EACV,IAAU,EACV,eAA6B,uBAAoB;QAEjD,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAEpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,sHAAsH;IACtH,mBAAmB;IACnB,6GAA6G;IAC7G,OAAO,CAAC,IAAU;QAChB,OAAO,IAAI,eAAe,CACxB,IAAI,CAAC,IAAI,EAAE,EACX,IAAI,CAAC,EAAE,EAAE,EACT,IAAI,EACJ,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,YAAY,EAAE,CACC,CAAC;IACzB,CAAC;IAED,OAAO;QACL,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,OAAO,CACzC,0BAAgB,EAChB,IAAI,CAAC,IAAI,EAAE,EACX,IAAI,CAAC,KAAK,CACX,CAAC;QAEF,wDAAwD;QACxD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC3B,OAAO;SACR;QAED,IAAI,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,eAAK,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,IAAyB,CAAC,CAAC;QAE3E,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;CACF;AA5CD,0CA4CC;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuleRegistry,
|
|
3
|
+
instance as ruleRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-rule/RuleRegistry';
|
|
5
|
+
import Action from '@civ-clone/core-unit/Action';
|
|
6
|
+
import City from '@civ-clone/core-city/City';
|
|
7
|
+
import Moved from '@civ-clone/core-unit/Rules/Moved';
|
|
8
|
+
import TechnologyStolen from './Rules/TechnologyStolen';
|
|
9
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
10
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
11
|
+
|
|
12
|
+
/** A Diplomat steals an advance from `city()`'s owner. Which one, and whether there's anything to take, is up to the `TechnologyStolen` rules. The Diplomat is used up when something is stolen. */
|
|
13
|
+
export class StealTechnology extends Action {
|
|
14
|
+
protected _city: City;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
from: Tile,
|
|
18
|
+
to: Tile,
|
|
19
|
+
unit: Unit,
|
|
20
|
+
city: City,
|
|
21
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance
|
|
22
|
+
) {
|
|
23
|
+
super(from, to, unit, ruleRegistry);
|
|
24
|
+
|
|
25
|
+
this._city = city;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// `Action.forUnit` rebuilds an action from `(from, to, unit, ruleRegistry)`, which would put the `RuleRegistry` where
|
|
29
|
+
// the `City` goes.
|
|
30
|
+
// Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
|
|
31
|
+
forUnit(unit: Unit): Action {
|
|
32
|
+
return new StealTechnology(
|
|
33
|
+
this.from(),
|
|
34
|
+
this.to(),
|
|
35
|
+
unit,
|
|
36
|
+
this._city,
|
|
37
|
+
this.ruleRegistry()
|
|
38
|
+
) as unknown as Action;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
perform(): void {
|
|
42
|
+
const results = this.ruleRegistry().process(
|
|
43
|
+
TechnologyStolen,
|
|
44
|
+
this.unit(),
|
|
45
|
+
this._city
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Nothing new to steal leaves the Diplomat where it is.
|
|
49
|
+
if (!results.includes(true)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.ruleRegistry().process(Moved, this.unit(), this as unknown as Action);
|
|
54
|
+
|
|
55
|
+
this.unit().destroy();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default StealTechnology;
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civ-clone/base-unit-action-steal-technology",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "StealTechnology.js",
|
|
5
|
+
"repository": "git@github.com:civ-clone/base-unit-action-steal-technology.git",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"typescript",
|
|
8
|
+
"civilization"
|
|
9
|
+
],
|
|
10
|
+
"author": "dom111 <dom111@users.noreply.github.com>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"private": false,
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "npm run ts:compile && npm run prettier:format",
|
|
15
|
+
"prettier:check": "prettier --config .prettierrc --check '**/*.ts'",
|
|
16
|
+
"prettier:format": "prettier --config .prettierrc '**/*.ts' --write",
|
|
17
|
+
"ts:compile": "tsc --build tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^14.18.63",
|
|
21
|
+
"prettier": "^2.8.8",
|
|
22
|
+
"typescript": "^4.9.5"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@civ-clone/core-city": "^0.1.19",
|
|
26
|
+
"@civ-clone/core-diplomacy": "^0.1.6",
|
|
27
|
+
"@civ-clone/core-player": "^0.1.8",
|
|
28
|
+
"@civ-clone/core-rule": "^0.1.6",
|
|
29
|
+
"@civ-clone/core-turn-based-game": "^0.1.6",
|
|
30
|
+
"@civ-clone/core-unit": "^0.1.25",
|
|
31
|
+
"@civ-clone/core-world": "^0.1.14"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/tsconfig.json
ADDED