mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-02 00:28:07 +00:00
Target player creates target icon
This commit is contained in:
@@ -10,6 +10,13 @@ export class AllianceImpl implements MutableAlliance {
|
||||
readonly createdAtTick_: Tick,
|
||||
) { }
|
||||
|
||||
other(player: Player): PlayerImpl {
|
||||
if (this.requestor_ == player) {
|
||||
return this.recipient_
|
||||
}
|
||||
return this.requestor_
|
||||
}
|
||||
|
||||
requestor(): MutablePlayer {
|
||||
return this.requestor_
|
||||
}
|
||||
|
||||
@@ -64,10 +64,12 @@ export interface Alliance {
|
||||
requestor(): Player
|
||||
recipient(): Player
|
||||
createdAt(): Tick
|
||||
other(player: Player): Player
|
||||
}
|
||||
|
||||
export interface MutableAlliance extends Alliance {
|
||||
expire(): void
|
||||
other(player: Player): MutablePlayer
|
||||
}
|
||||
|
||||
export class PlayerInfo {
|
||||
@@ -148,6 +150,11 @@ export interface Player {
|
||||
// Includes recent requests that are in cooldown
|
||||
recentOrPendingAllianceRequestWith(other: Player): boolean
|
||||
isTraitor(): boolean
|
||||
canTarget(other: Player): boolean
|
||||
// Targets for this player
|
||||
targets(): Player[]
|
||||
// Targets of player and all allies.
|
||||
transitiveTargets(): Player[]
|
||||
toString(): string
|
||||
}
|
||||
|
||||
@@ -168,6 +175,9 @@ export interface MutablePlayer extends Player {
|
||||
breakAlliance(alliance: Alliance): void
|
||||
createAllianceRequest(recipient: Player): MutableAllianceRequest
|
||||
addBoat(troops: number, tile: Tile, target: Player | TerraNullius): MutableBoat
|
||||
target(other: Player): void
|
||||
targets(): MutablePlayer[]
|
||||
transitiveTargets(): MutablePlayer[]
|
||||
}
|
||||
|
||||
export interface Game {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance} from "./Game";
|
||||
import {MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, MutableGame, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick} from "./Game";
|
||||
import {ClientID} from "../Schemas";
|
||||
import {simpleHash} from "../Util";
|
||||
import {CellString, GameImpl} from "./GameImpl";
|
||||
@@ -7,6 +7,10 @@ import {TileImpl} from "./TileImpl";
|
||||
import {TerraNulliusImpl} from "./TerraNulliusImpl";
|
||||
import {threadId} from "worker_threads";
|
||||
|
||||
interface Target {
|
||||
tick: Tick
|
||||
target: Player
|
||||
}
|
||||
|
||||
export class PlayerImpl implements MutablePlayer {
|
||||
isTraitor_ = false
|
||||
@@ -20,6 +24,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
|
||||
public pastOutgoingAllianceRequests: AllianceRequest[] = []
|
||||
|
||||
private targets_: Target[] = []
|
||||
|
||||
constructor(private gs: GameImpl, private readonly playerInfo: PlayerInfo, private _troops) {
|
||||
this._name = playerInfo.name;
|
||||
}
|
||||
@@ -172,6 +178,33 @@ export class PlayerImpl implements MutablePlayer {
|
||||
return this.gs.createAllianceRequest(this, recipient)
|
||||
}
|
||||
|
||||
canTarget(other: Player): boolean {
|
||||
for (const t of this.targets_) {
|
||||
if (t.target == other) {
|
||||
if (this.gs.ticks() - t.tick < this.gs.config().targetCooldown()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
target(other: Player): void {
|
||||
this.targets_.push({tick: this.gs.ticks(), target: other})
|
||||
}
|
||||
|
||||
targets(): PlayerImpl[] {
|
||||
return this.targets_
|
||||
.filter(t => this.gs.ticks() - t.tick < this.gs.config().targetDuration())
|
||||
.map(t => t.target as PlayerImpl)
|
||||
}
|
||||
|
||||
transitiveTargets(): MutablePlayer[] {
|
||||
const ts = this.alliances().map(a => a.other(this)).flatMap(ally => ally.targets())
|
||||
ts.push(...this.targets())
|
||||
return [...new Set(ts)]
|
||||
}
|
||||
|
||||
hash(): number {
|
||||
return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user