Can target other players

This commit is contained in:
evanpelle
2024-10-02 16:39:15 -07:00
parent 2223e40d53
commit 4aae657690
8 changed files with 34 additions and 10 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export class DefaultConfig implements Config {
return 10 * 10
}
targetCooldown(): Tick {
return 30 * 10
return 15 * 10
}
allianceRequestCooldown(): Tick {
return 30 * 10
+4
View File
@@ -237,4 +237,8 @@ export class BrokeAllianceEvent implements GameEvent {
export class AllianceExpiredEvent implements GameEvent {
constructor(public readonly player1: Player, public readonly player2: Player) { }
}
export class TargetPlayerEvent implements GameEvent {
constructor(public readonly player: Player, public readonly target: Player) { }
}
+1 -1
View File
@@ -34,7 +34,7 @@ export class GameImpl implements MutableGame {
allianceRequests: AllianceRequestImpl[] = []
alliances_: AllianceImpl[] = []
constructor(terrainMap: TerrainMap, private eventBus: EventBus, private _config: Config) {
constructor(terrainMap: TerrainMap, public eventBus: EventBus, private _config: Config) {
this._terraNullius = new TerraNulliusImpl(this)
this._width = terrainMap.width();
this._height = terrainMap.height();
+7 -5
View File
@@ -1,4 +1,4 @@
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick} from "./Game";
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent} from "./Game";
import {ClientID} from "../Schemas";
import {simpleHash} from "../Util";
import {CellString, GameImpl} from "./GameImpl";
@@ -179,11 +179,12 @@ export class PlayerImpl implements MutablePlayer {
}
canTarget(other: Player): boolean {
if (this.isAlliedWith(other)) {
return false
}
for (const t of this.targets_) {
if (t.target == other) {
if (this.gs.ticks() - t.tick < this.gs.config().targetCooldown()) {
return false
}
if (this.gs.ticks() - t.tick < this.gs.config().targetCooldown()) {
return false
}
}
return true
@@ -191,6 +192,7 @@ export class PlayerImpl implements MutablePlayer {
target(other: Player): void {
this.targets_.push({tick: this.gs.ticks(), target: other})
this.gs.eventBus.emit(new TargetPlayerEvent(this, other))
}
targets(): PlayerImpl[] {