@civ-clone/base-unit-action-goto 0.1.0 → 0.1.2
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/Busy/GoTo.d.ts +3 -0
- package/Busy/GoTo.js +9 -0
- package/Busy/GoTo.js.map +1 -0
- package/Busy/GoTo.ts +5 -0
- package/Errors/NoPathAvailable.d.ts +2 -0
- package/Errors/NoPathAvailable.js +8 -0
- package/Errors/NoPathAvailable.js.map +1 -0
- package/Errors/NoPathAvailable.ts +3 -0
- package/Errors/NoPathFinderAvailable.d.ts +2 -0
- package/Errors/NoPathFinderAvailable.js +8 -0
- package/Errors/NoPathFinderAvailable.js.map +1 -0
- package/Errors/NoPathFinderAvailable.ts +3 -0
- package/GoTo.js +14 -4
- package/GoTo.js.map +1 -1
- package/GoTo.ts +22 -4
- package/README.md +1 -1
- package/Rules/Player/turn-start.d.ts +8 -0
- package/Rules/Player/turn-start.js +31 -0
- package/Rules/Player/turn-start.js.map +1 -0
- package/Rules/Player/turn-start.ts +48 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/index.js.map +1 -0
- package/index.ts +1 -0
- package/lib/moveAlongPath.d.ts +6 -1
- package/lib/moveAlongPath.js +12 -2
- package/lib/moveAlongPath.js.map +1 -1
- package/lib/moveAlongPath.ts +22 -2
- package/package.json +3 -1
- package/registerRules.d.ts +1 -0
- package/registerRules.js +6 -0
- package/registerRules.js.map +1 -0
- package/registerRules.ts +4 -0
package/Busy/GoTo.d.ts
ADDED
package/Busy/GoTo.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoTo = void 0;
|
|
4
|
+
const Busy_1 = require("@civ-clone/core-unit/Rules/Busy");
|
|
5
|
+
class GoTo extends Busy_1.default {
|
|
6
|
+
}
|
|
7
|
+
exports.GoTo = GoTo;
|
|
8
|
+
exports.default = GoTo;
|
|
9
|
+
//# sourceMappingURL=GoTo.js.map
|
package/Busy/GoTo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoTo.js","sourceRoot":"","sources":["GoTo.ts"],"names":[],"mappings":";;;AAAA,0DAAmD;AAEnD,MAAa,IAAK,SAAQ,cAAI;CAAG;AAAjC,oBAAiC;AAEjC,kBAAe,IAAI,CAAC"}
|
package/Busy/GoTo.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoPathAvailable = void 0;
|
|
4
|
+
class NoPathAvailable extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.NoPathAvailable = NoPathAvailable;
|
|
7
|
+
exports.default = NoPathAvailable;
|
|
8
|
+
//# sourceMappingURL=NoPathAvailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoPathAvailable.js","sourceRoot":"","sources":["NoPathAvailable.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C;AAE7C,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoPathFinderAvailable = void 0;
|
|
4
|
+
class NoPathFinderAvailable extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.NoPathFinderAvailable = NoPathFinderAvailable;
|
|
7
|
+
exports.default = NoPathFinderAvailable;
|
|
8
|
+
//# sourceMappingURL=NoPathFinderAvailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoPathFinderAvailable.js","sourceRoot":"","sources":["NoPathFinderAvailable.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD;AAEnD,kBAAe,qBAAqB,CAAC"}
|
package/GoTo.js
CHANGED
|
@@ -18,6 +18,12 @@ const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
|
18
18
|
const StrategyNote_1 = require("@civ-clone/core-strategy/StrategyNote");
|
|
19
19
|
const StrategyNoteRegistry_1 = require("@civ-clone/core-strategy/StrategyNoteRegistry");
|
|
20
20
|
const Action_1 = require("@civ-clone/core-unit/Action");
|
|
21
|
+
const GoTo_1 = require("./Busy/GoTo");
|
|
22
|
+
const Criterion_1 = require("@civ-clone/core-rule/Criterion");
|
|
23
|
+
const Effect_1 = require("@civ-clone/core-rule/Effect");
|
|
24
|
+
const Moved_1 = require("@civ-clone/core-unit/Rules/Moved");
|
|
25
|
+
const NoPathAvailable_1 = require("./Errors/NoPathAvailable");
|
|
26
|
+
const NoPathFinderAvailable_1 = require("./Errors/NoPathFinderAvailable");
|
|
21
27
|
const moveAlongPath_1 = require("./lib/moveAlongPath");
|
|
22
28
|
const generateKey = (unit) => (0, StrategyNote_1.generateKey)(unit, 'currentPath');
|
|
23
29
|
exports.generateKey = generateKey;
|
|
@@ -32,18 +38,22 @@ class GoTo extends Action_1.default {
|
|
|
32
38
|
perform() {
|
|
33
39
|
const [PathFinder] = __classPrivateFieldGet(this, _GoTo_pathFinderRegistry, "f").entries();
|
|
34
40
|
if (!PathFinder) {
|
|
35
|
-
|
|
36
|
-
return;
|
|
41
|
+
throw new NoPathFinderAvailable_1.default();
|
|
37
42
|
}
|
|
38
43
|
const path = new PathFinder(this.unit(), this.unit().tile(), this.to()).generate();
|
|
39
44
|
if (!path) {
|
|
40
|
-
|
|
41
|
-
return;
|
|
45
|
+
throw new NoPathAvailable_1.default();
|
|
42
46
|
}
|
|
47
|
+
this.unit().setBusy();
|
|
43
48
|
// remove the current `Tile` so that the next shift will be the target.
|
|
44
49
|
path.shift();
|
|
45
50
|
__classPrivateFieldGet(this, _GoTo_strategyNoteRegistry, "f").replace(new StrategyNote_1.StrategyNote((0, exports.generateKey)(this.unit()), path));
|
|
46
51
|
(0, moveAlongPath_1.default)(this.unit(), path);
|
|
52
|
+
this.unit().setBusy(new GoTo_1.default(new Criterion_1.default(() => this.unit().tile() === path.end()), new Effect_1.default(() => {
|
|
53
|
+
this.unit().setActive();
|
|
54
|
+
this.unit().setBusy();
|
|
55
|
+
})));
|
|
56
|
+
this.ruleRegistry().process(Moved_1.default, this.unit(), this);
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
exports.GoTo = GoTo;
|
package/GoTo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTo.js","sourceRoot":"","sources":["GoTo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sFAGuD;AACvD,oEAG2C;AAC3C,wEAG+C;AAC/C,wFAGuD;AACvD,wDAAiD;
|
|
1
|
+
{"version":3,"file":"GoTo.js","sourceRoot":"","sources":["GoTo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sFAGuD;AACvD,oEAG2C;AAC3C,wEAG+C;AAC/C,wFAGuD;AACvD,wDAAiD;AACjD,sCAAmC;AACnC,8DAAuD;AACvD,wDAAiD;AACjD,4DAAqD;AACrD,8DAAuD;AACvD,0EAAmE;AAGnE,uDAAgD;AAEzC,MAAM,WAAW,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAA,0BAAc,EAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AAAlE,QAAA,WAAW,eAAuD;AAE/E,MAAa,IAAK,SAAQ,gBAAM;IAI9B,YACE,IAAU,EACV,EAAQ,EACR,IAAU,EACV,eAA6B,uBAAoB,EACjD,qBAAyC,6BAA0B,EACnE,uBAA6C,+BAA4B;QAEzE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAXtC,2CAAwC;QACxC,6CAA4C;QAY1C,uBAAA,IAAI,4BAAuB,kBAAkB,MAAA,CAAC;QAC9C,uBAAA,IAAI,8BAAyB,oBAAoB,MAAA,CAAC;IACpD,CAAC;IAED,OAAO;QACL,MAAM,CAAC,UAAU,CAAC,GAAG,uBAAA,IAAI,gCAAoB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,+BAAqB,EAAE,CAAC;SACnC;QAED,MAAM,IAAI,GAAG,IAAI,UAAU,CACzB,IAAI,CAAC,IAAI,EAAE,EACX,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAClB,IAAI,CAAC,EAAE,EAAE,CACV,CAAC,QAAQ,EAAE,CAAC;QAEb,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,yBAAe,EAAE,CAAC;SAC7B;QAED,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAEtB,uEAAuE;QACvE,IAAI,CAAC,KAAK,EAAE,CAAC;QAEb,uBAAA,IAAI,kCAAsB,CAAC,OAAO,CAChC,IAAI,2BAAY,CAAC,IAAA,mBAAW,EAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CACjD,CAAC;QAEF,IAAA,uBAAa,EAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;QAEjC,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CACjB,IAAI,cAAQ,CACV,IAAI,mBAAS,CAAC,GAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,EAC/D,IAAI,gBAAM,CAAC,GAAS,EAAE;YACpB,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC,CAAC,CACH,CACF,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,eAAK,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;CACF;AA1DD,oBA0DC;;AAED,kBAAe,IAAI,CAAC"}
|
package/GoTo.ts
CHANGED
|
@@ -15,6 +15,12 @@ import {
|
|
|
15
15
|
instance as strategyNoteRegistryInstance,
|
|
16
16
|
} from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
17
17
|
import Action from '@civ-clone/core-unit/Action';
|
|
18
|
+
import BusyGoTo from './Busy/GoTo';
|
|
19
|
+
import Criterion from '@civ-clone/core-rule/Criterion';
|
|
20
|
+
import Effect from '@civ-clone/core-rule/Effect';
|
|
21
|
+
import Moved from '@civ-clone/core-unit/Rules/Moved';
|
|
22
|
+
import NoPathAvailable from './Errors/NoPathAvailable';
|
|
23
|
+
import NoPathFinderAvailable from './Errors/NoPathFinderAvailable';
|
|
18
24
|
import Tile from '@civ-clone/core-world/Tile';
|
|
19
25
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
20
26
|
import moveAlongPath from './lib/moveAlongPath';
|
|
@@ -43,8 +49,7 @@ export class GoTo extends Action {
|
|
|
43
49
|
const [PathFinder] = this.#pathFinderRegistry.entries();
|
|
44
50
|
|
|
45
51
|
if (!PathFinder) {
|
|
46
|
-
|
|
47
|
-
return;
|
|
52
|
+
throw new NoPathFinderAvailable();
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
const path = new PathFinder(
|
|
@@ -54,10 +59,11 @@ export class GoTo extends Action {
|
|
|
54
59
|
).generate();
|
|
55
60
|
|
|
56
61
|
if (!path) {
|
|
57
|
-
|
|
58
|
-
return;
|
|
62
|
+
throw new NoPathAvailable();
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
this.unit().setBusy();
|
|
66
|
+
|
|
61
67
|
// remove the current `Tile` so that the next shift will be the target.
|
|
62
68
|
path.shift();
|
|
63
69
|
|
|
@@ -66,6 +72,18 @@ export class GoTo extends Action {
|
|
|
66
72
|
);
|
|
67
73
|
|
|
68
74
|
moveAlongPath(this.unit(), path);
|
|
75
|
+
|
|
76
|
+
this.unit().setBusy(
|
|
77
|
+
new BusyGoTo(
|
|
78
|
+
new Criterion((): boolean => this.unit().tile() === path.end()),
|
|
79
|
+
new Effect((): void => {
|
|
80
|
+
this.unit().setActive();
|
|
81
|
+
this.unit().setBusy();
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
this.ruleRegistry().process(Moved, this.unit(), this);
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
89
|
|
package/README.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StrategyNoteRegistry } from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
2
|
+
import { UnitRegistry } from '@civ-clone/core-unit/UnitRegistry';
|
|
3
|
+
import TurnStart from '@civ-clone/core-player/Rules/TurnStart';
|
|
4
|
+
export declare const getRules: (
|
|
5
|
+
strategyNoteRegistry?: StrategyNoteRegistry,
|
|
6
|
+
unitRegistry?: UnitRegistry
|
|
7
|
+
) => TurnStart[];
|
|
8
|
+
export default getRules;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRules = void 0;
|
|
4
|
+
const StrategyNoteRegistry_1 = require("@civ-clone/core-strategy/StrategyNoteRegistry");
|
|
5
|
+
const UnitRegistry_1 = require("@civ-clone/core-unit/UnitRegistry");
|
|
6
|
+
const Effect_1 = require("@civ-clone/core-rule/Effect");
|
|
7
|
+
const GoTo_1 = require("../../Busy/GoTo");
|
|
8
|
+
const Low_1 = require("@civ-clone/core-rule/Priorities/Low");
|
|
9
|
+
const TurnStart_1 = require("@civ-clone/core-player/Rules/TurnStart");
|
|
10
|
+
const GoTo_2 = require("../../GoTo");
|
|
11
|
+
const moveAlongPath_1 = require("../../lib/moveAlongPath");
|
|
12
|
+
const getRules = (strategyNoteRegistry = StrategyNoteRegistry_1.instance, unitRegistry = UnitRegistry_1.instance) => [
|
|
13
|
+
new TurnStart_1.default(
|
|
14
|
+
// This needs to have happened after the `Unit`s `Yield`s have been reset.
|
|
15
|
+
new Low_1.default(), new Effect_1.default((player) => unitRegistry.getByPlayer(player).forEach((unit) => {
|
|
16
|
+
if (!(unit.busy() instanceof GoTo_1.default)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const note = strategyNoteRegistry.getByKey((0, GoTo_2.generateKey)(unit));
|
|
20
|
+
if (!note) {
|
|
21
|
+
unit.setBusy();
|
|
22
|
+
unit.setActive();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const path = note.value();
|
|
26
|
+
(0, moveAlongPath_1.default)(unit, path);
|
|
27
|
+
}))),
|
|
28
|
+
];
|
|
29
|
+
exports.getRules = getRules;
|
|
30
|
+
exports.default = exports.getRules;
|
|
31
|
+
//# sourceMappingURL=turn-start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-start.js","sourceRoot":"","sources":["turn-start.ts"],"names":[],"mappings":";;;AAAA,wFAGuD;AACvD,oEAG2C;AAC3C,wDAAiD;AACjD,0CAAmC;AACnC,6DAAsD;AAGtD,sEAA+D;AAC/D,qCAAyC;AACzC,2DAAoD;AAE7C,MAAM,QAAQ,GAAG,CACtB,uBAA6C,+BAA4B,EACzE,eAA6B,uBAAoB,EACpC,EAAE,CAAC;IAChB,IAAI,mBAAS;IACX,0EAA0E;IAC1E,IAAI,aAAG,EAAE,EACT,IAAI,gBAAM,CAAC,CAAC,MAAc,EAAE,EAAE,CAC5B,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChD,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,cAAI,CAAC,EAAE;YAClC,OAAO;SACR;QAED,MAAM,IAAI,GAAG,oBAAoB,CAAC,QAAQ,CAAO,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;QAEpE,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,SAAS,EAAE,CAAC;YAEjB,OAAO;SACR;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAE1B,IAAA,uBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CACH,CACF;CACF,CAAC;AA5BW,QAAA,QAAQ,YA4BnB;AAEF,kBAAe,gBAAQ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StrategyNoteRegistry,
|
|
3
|
+
instance as strategyNoteRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
5
|
+
import {
|
|
6
|
+
UnitRegistry,
|
|
7
|
+
instance as unitRegistryInstance,
|
|
8
|
+
} from '@civ-clone/core-unit/UnitRegistry';
|
|
9
|
+
import Effect from '@civ-clone/core-rule/Effect';
|
|
10
|
+
import GoTo from '../../Busy/GoTo';
|
|
11
|
+
import Low from '@civ-clone/core-rule/Priorities/Low';
|
|
12
|
+
import Path from '@civ-clone/core-world-path/Path';
|
|
13
|
+
import Player from '@civ-clone/core-player/Player';
|
|
14
|
+
import TurnStart from '@civ-clone/core-player/Rules/TurnStart';
|
|
15
|
+
import { generateKey } from '../../GoTo';
|
|
16
|
+
import moveAlongPath from '../../lib/moveAlongPath';
|
|
17
|
+
|
|
18
|
+
export const getRules = (
|
|
19
|
+
strategyNoteRegistry: StrategyNoteRegistry = strategyNoteRegistryInstance,
|
|
20
|
+
unitRegistry: UnitRegistry = unitRegistryInstance
|
|
21
|
+
): TurnStart[] => [
|
|
22
|
+
new TurnStart(
|
|
23
|
+
// This needs to have happened after the `Unit`s `Yield`s have been reset.
|
|
24
|
+
new Low(),
|
|
25
|
+
new Effect((player: Player) =>
|
|
26
|
+
unitRegistry.getByPlayer(player).forEach((unit) => {
|
|
27
|
+
if (!(unit.busy() instanceof GoTo)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const note = strategyNoteRegistry.getByKey<Path>(generateKey(unit));
|
|
32
|
+
|
|
33
|
+
if (!note) {
|
|
34
|
+
unit.setBusy();
|
|
35
|
+
unit.setActive();
|
|
36
|
+
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const path = note.value();
|
|
41
|
+
|
|
42
|
+
moveAlongPath(unit, path);
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export default getRules;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './registerRules';
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAAA,2BAAyB"}
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './registerRules';
|
package/lib/moveAlongPath.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { StrategyNoteRegistry } from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
1
2
|
import Path from '@civ-clone/core-world-path/Path';
|
|
2
3
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
3
|
-
export declare const moveAlongPath: (
|
|
4
|
+
export declare const moveAlongPath: (
|
|
5
|
+
unit: Unit,
|
|
6
|
+
path: Path,
|
|
7
|
+
strategyNoteRegistry?: StrategyNoteRegistry
|
|
8
|
+
) => void;
|
|
4
9
|
export default moveAlongPath;
|
package/lib/moveAlongPath.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.moveAlongPath = void 0;
|
|
4
|
+
const StrategyNoteRegistry_1 = require("@civ-clone/core-strategy/StrategyNoteRegistry");
|
|
4
5
|
const Move_1 = require("@civ-clone/base-unit-action-move/Move");
|
|
5
6
|
const NoOrders_1 = require("@civ-clone/base-unit-action-no-orders/NoOrders");
|
|
6
|
-
const
|
|
7
|
+
const GoTo_1 = require("../GoTo");
|
|
8
|
+
const moveAlongPath = (unit, path, strategyNoteRegistry = StrategyNoteRegistry_1.instance) => {
|
|
7
9
|
while (unit.moves().value() > 0.25) {
|
|
8
10
|
const [move] = unit
|
|
9
11
|
.actions(path.shift())
|
|
@@ -13,7 +15,15 @@ const moveAlongPath = (unit, path) => {
|
|
|
13
15
|
}
|
|
14
16
|
move.perform();
|
|
15
17
|
}
|
|
16
|
-
if (
|
|
18
|
+
if (path.length === 0) {
|
|
19
|
+
unit.setBusy();
|
|
20
|
+
unit.setActive();
|
|
21
|
+
const note = strategyNoteRegistry.getByKey((0, GoTo_1.generateKey)(unit));
|
|
22
|
+
if (note) {
|
|
23
|
+
strategyNoteRegistry.unregister(note);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (unit.moves().value() > 0.25) {
|
|
17
27
|
return;
|
|
18
28
|
}
|
|
19
29
|
const [noOrders] = unit
|
package/lib/moveAlongPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moveAlongPath.js","sourceRoot":"","sources":["moveAlongPath.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"moveAlongPath.js","sourceRoot":"","sources":["moveAlongPath.ts"],"names":[],"mappings":";;;AAAA,wFAGuD;AAEvD,gEAAyD;AACzD,6EAAsE;AAGtE,kCAAsC;AAE/B,MAAM,aAAa,GAAG,CAC3B,IAAU,EACV,IAAU,EACV,uBAA6C,+BAA4B,EACnE,EAAE;IACR,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE;QAClC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI;aAChB,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;aACrB,MAAM,CACL,CAAC,MAAqB,EAAkB,EAAE,CAAC,MAAM,YAAY,cAAI,CAClE,CAAC;QAEJ,IAAI,CAAC,IAAI,EAAE;YACT,MAAM;SACP;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;KAChB;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,MAAM,IAAI,GAAG,oBAAoB,CAAC,QAAQ,CAAC,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;QAE9D,IAAI,IAAI,EAAE;YACR,oBAAoB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SACvC;KACF;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE;QAC/B,OAAO;KACR;IAED,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI;SACpB,OAAO,EAAE;SACT,MAAM,CAAC,CAAC,MAAM,EAAsB,EAAE,CAAC,MAAM,YAAY,kBAAQ,CAAC,CAAC;IAEtE,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,OAAO,EAAE,CAAC;QAEnB,OAAO;KACR;IAED,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC,CAAC;AA9CW,QAAA,aAAa,iBA8CxB;AAEF,kBAAe,qBAAa,CAAC"}
|
package/lib/moveAlongPath.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StrategyNoteRegistry,
|
|
3
|
+
instance as strategyNoteRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
1
5
|
import Action from '@civ-clone/core-unit/Action';
|
|
2
6
|
import Move from '@civ-clone/base-unit-action-move/Move';
|
|
3
7
|
import NoOrders from '@civ-clone/base-unit-action-no-orders/NoOrders';
|
|
4
8
|
import Path from '@civ-clone/core-world-path/Path';
|
|
5
9
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
10
|
+
import { generateKey } from '../GoTo';
|
|
6
11
|
|
|
7
|
-
export const moveAlongPath = (
|
|
12
|
+
export const moveAlongPath = (
|
|
13
|
+
unit: Unit,
|
|
14
|
+
path: Path,
|
|
15
|
+
strategyNoteRegistry: StrategyNoteRegistry = strategyNoteRegistryInstance
|
|
16
|
+
): void => {
|
|
8
17
|
while (unit.moves().value() > 0.25) {
|
|
9
18
|
const [move] = unit
|
|
10
19
|
.actions(path.shift())
|
|
@@ -19,7 +28,18 @@ export const moveAlongPath = (unit: Unit, path: Path): void => {
|
|
|
19
28
|
move.perform();
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
if (
|
|
31
|
+
if (path.length === 0) {
|
|
32
|
+
unit.setBusy();
|
|
33
|
+
unit.setActive();
|
|
34
|
+
|
|
35
|
+
const note = strategyNoteRegistry.getByKey(generateKey(unit));
|
|
36
|
+
|
|
37
|
+
if (note) {
|
|
38
|
+
strategyNoteRegistry.unregister(note);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (unit.moves().value() > 0.25) {
|
|
23
43
|
return;
|
|
24
44
|
}
|
|
25
45
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civ-clone/base-unit-action-goto",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"main": "index.js",
|
|
4
5
|
"repository": "git@github.com:civ-clone/base-unit-action-goto.git",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"typescript",
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@civ-clone/base-unit-action-move": "^0.1.1",
|
|
25
26
|
"@civ-clone/base-unit-action-no-orders": "^0.1.0",
|
|
27
|
+
"@civ-clone/core-player": "^0.1.0",
|
|
26
28
|
"@civ-clone/core-rule": "^0.1.2",
|
|
27
29
|
"@civ-clone/core-strategy": "^0.1.0",
|
|
28
30
|
"@civ-clone/core-unit": "^0.1.13",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/registerRules.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
4
|
+
const turn_start_1 = require("./Rules/Player/turn-start");
|
|
5
|
+
RuleRegistry_1.instance.register(...(0, turn_start_1.default)());
|
|
6
|
+
//# sourceMappingURL=registerRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerRules.js","sourceRoot":"","sources":["registerRules.ts"],"names":[],"mappings":";;AAAA,oEAAqF;AACrF,0DAAkD;AAElD,uBAAoB,CAAC,QAAQ,CAAC,GAAG,IAAA,oBAAS,GAAE,CAAC,CAAC"}
|
package/registerRules.ts
ADDED