42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { Hex } from "../../Util/index.js";
|
|
import { ECellType, SimTower } from "../index.js";
|
|
export class SimCommandCreateTower {
|
|
_hex;
|
|
_simLevel;
|
|
_index;
|
|
_gdRoot;
|
|
constructor(game, level, hex, index) {
|
|
this._gdRoot = game;
|
|
this._hex = hex;
|
|
this._simLevel = level;
|
|
this._index = index;
|
|
}
|
|
execute() {
|
|
const level = this._simLevel;
|
|
const cellIndex = level.getCellIndex(this._hex);
|
|
const cell = level.simCells[cellIndex];
|
|
const towerData = this._gdRoot.towers[this._index];
|
|
if (cell.type != ECellType.Free) {
|
|
return;
|
|
}
|
|
if (cell.simTower != null) {
|
|
return;
|
|
}
|
|
level.simEnemies.forEach((enemy) => {
|
|
const hex = Hex.fromWorld(enemy.position);
|
|
const enemyCellIndex = level.getCellIndex(hex);
|
|
if (cellIndex == enemyCellIndex) {
|
|
return;
|
|
}
|
|
});
|
|
if (level.currency < towerData.cost) {
|
|
return;
|
|
}
|
|
if (level.reservePaths(this._hex)) {
|
|
level.currency -= towerData.cost;
|
|
cell.simTower = new SimTower(this._gdRoot, level, this._index, this._hex);
|
|
level.updatePaths();
|
|
}
|
|
}
|
|
}
|
|
//# sourceMappingURL=SimCommandCreateTower.js.map
|