mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 13:18:10 +00:00
Can target other players
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) { }
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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[] {
|
||||
|
||||
Reference in New Issue
Block a user