mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 07:50:45 +00:00
destroyer moves upwards
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Colord } from "colord";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Unit, UnitEvent, Cell, Game, Tile, UnitType } from "../../../core/game/Game";
|
||||
import { bfs, dist } from "../../../core/Util";
|
||||
import { bfs, dist, euclDist } from "../../../core/Util";
|
||||
import { Layer } from "./Layer";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
|
||||
@@ -72,7 +72,13 @@ export class UnitLayer implements Layer {
|
||||
}
|
||||
|
||||
private handleDestroyerEvent(event: UnitEvent) {
|
||||
|
||||
bfs(event.oldTile, euclDist(event.oldTile, 3)).forEach(t => {
|
||||
this.clearCell(t.cell())
|
||||
})
|
||||
bfs(event.unit.tile(), euclDist(event.unit.tile(), 3))
|
||||
.forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.unit.owner().info()), 255))
|
||||
bfs(event.unit.tile(), euclDist(event.unit.tile(), 2))
|
||||
.forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.unit.owner().info()), 180))
|
||||
}
|
||||
|
||||
private handleBoatEvent(event: UnitEvent) {
|
||||
|
||||
@@ -30,6 +30,10 @@ export function within(value: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
export function euclDist(root: Tile, dist: number): (tile: Tile) => boolean {
|
||||
return (n: Tile) => euclideanDist(root.cell(), n.cell()) <= dist;
|
||||
}
|
||||
|
||||
export function dist(root: Tile, dist: number): (tile: Tile) => boolean {
|
||||
return (n: Tile) => manhattanDist(root.cell(), n.cell()) <= dist;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ export class DestroyerExecution implements Execution {
|
||||
tick(ticks: number): void {
|
||||
if (this.destroyer == null) {
|
||||
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell))
|
||||
return
|
||||
}
|
||||
this.destroyer.move(this.destroyer.tile().neighbors()[0])
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { EmojiExecution } from "./EmojiExecution";
|
||||
import { DonateExecution } from "./DonateExecution";
|
||||
import { NukeExecution } from "./NukeExecution";
|
||||
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
|
||||
import { DestroyerExecution } from "./DestroyerExecution";
|
||||
|
||||
|
||||
|
||||
@@ -36,50 +37,57 @@ export class Executor {
|
||||
}
|
||||
|
||||
createExec(intent: Intent): Execution {
|
||||
if (intent.type == "attack") {
|
||||
const source: Cell | null = intent.sourceX != null && intent.sourceY != null ? new Cell(intent.sourceX, intent.sourceY) : null
|
||||
const target: Cell | null = intent.targetX != null && intent.targetY != null ? new Cell(intent.targetX, intent.targetY) : null
|
||||
return new AttackExecution(
|
||||
intent.troops,
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
source,
|
||||
target,
|
||||
)
|
||||
} else if (intent.type == "spawn") {
|
||||
return new SpawnExecution(
|
||||
new PlayerInfo(sanitize(intent.name), intent.playerType, intent.clientID, intent.playerID),
|
||||
new Cell(intent.x, intent.y)
|
||||
)
|
||||
} else if (intent.type == "boat") {
|
||||
return new TransportShipExecution(
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
new Cell(intent.x, intent.y),
|
||||
intent.troops
|
||||
)
|
||||
} else if (intent.type == "allianceRequest") {
|
||||
return new AllianceRequestExecution(intent.requestor, intent.recipient)
|
||||
} else if (intent.type == "allianceRequestReply") {
|
||||
return new AllianceRequestReplyExecution(intent.requestor, intent.recipient, intent.accept)
|
||||
} else if (intent.type == "breakAlliance") {
|
||||
return new BreakAllianceExecution(intent.requestor, intent.recipient)
|
||||
} else if (intent.type == "targetPlayer") {
|
||||
return new TargetPlayerExecution(intent.requestor, intent.target)
|
||||
} else if (intent.type == "emoji") {
|
||||
return new EmojiExecution(intent.sender, intent.recipient, intent.emoji)
|
||||
} else if (intent.type == "donate") {
|
||||
return new DonateExecution(intent.sender, intent.recipient, intent.troops)
|
||||
} else if (intent.type == "nuke") {
|
||||
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude)
|
||||
} else if (intent.type == "troop_ratio") {
|
||||
return new SetTargetTroopRatioExecution(intent.player, intent.ratio)
|
||||
} else {
|
||||
throw new Error(`intent type ${intent} not found`)
|
||||
switch (intent.type) {
|
||||
case "attack": {
|
||||
const source: Cell | null = intent.sourceX != null && intent.sourceY != null
|
||||
? new Cell(intent.sourceX, intent.sourceY)
|
||||
: null;
|
||||
const target: Cell | null = intent.targetX != null && intent.targetY != null
|
||||
? new Cell(intent.targetX, intent.targetY)
|
||||
: null;
|
||||
return new AttackExecution(
|
||||
intent.troops,
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
source,
|
||||
target,
|
||||
);
|
||||
}
|
||||
case "spawn":
|
||||
return new SpawnExecution(
|
||||
new PlayerInfo(sanitize(intent.name), intent.playerType, intent.clientID, intent.playerID),
|
||||
new Cell(intent.x, intent.y)
|
||||
);
|
||||
case "boat":
|
||||
return new TransportShipExecution(
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
new Cell(intent.x, intent.y),
|
||||
intent.troops
|
||||
);
|
||||
case "allianceRequest":
|
||||
return new AllianceRequestExecution(intent.requestor, intent.recipient);
|
||||
case "allianceRequestReply":
|
||||
return new AllianceRequestReplyExecution(intent.requestor, intent.recipient, intent.accept);
|
||||
case "breakAlliance":
|
||||
return new BreakAllianceExecution(intent.requestor, intent.recipient);
|
||||
case "targetPlayer":
|
||||
return new TargetPlayerExecution(intent.requestor, intent.target);
|
||||
case "emoji":
|
||||
return new EmojiExecution(intent.sender, intent.recipient, intent.emoji);
|
||||
case "donate":
|
||||
return new DonateExecution(intent.sender, intent.recipient, intent.troops);
|
||||
case "nuke":
|
||||
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude);
|
||||
case "troop_ratio":
|
||||
return new SetTargetTroopRatioExecution(intent.player, intent.ratio);
|
||||
case "create_destroyer":
|
||||
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
default:
|
||||
throw new Error(`intent type ${intent} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
spawnBots(numBots: number): Execution[] {
|
||||
return new BotSpawner(this.gs, this.gameID).spawnBots(numBots).map(i => this.createExec(i))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class Item {
|
||||
|
||||
export const Items = {
|
||||
Nuke: new Item("Nuke", 1_000_000),
|
||||
Destroyer: new Item("Destroyer", 100_000)
|
||||
Destroyer: new Item("Destroyer", 10)
|
||||
} as const;
|
||||
|
||||
export class Nation {
|
||||
|
||||
Reference in New Issue
Block a user