added right click option break alliance

This commit is contained in:
evanpelle
2024-09-21 09:42:43 -07:00
parent 6600c4cbe0
commit 5f38d2a544
8 changed files with 106 additions and 18 deletions
@@ -0,0 +1,37 @@
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestExecution implements Execution {
private active = true
private mg: MutableGame = null
private requestor: MutablePlayer;
private recipient: MutablePlayer
constructor(private requestorID: PlayerID, private recipientID: PlayerID) { }
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.requestor = mg.player(this.requestorID)
this.recipient = mg.player(this.recipientID)
}
tick(ticks: number): void {
if (this.requestor.alliedWith(this.recipient)) {
console.warn('already allied')
} else {
this.requestor.createAllianceRequest(this.recipient)
}
this.active = false
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
@@ -0,0 +1,46 @@
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestReplyExecution implements Execution {
private active = true
private mg: MutableGame = null
private requestor: MutablePlayer;
private recipient: MutablePlayer
constructor(private requestorID: PlayerID, private recipientID: PlayerID, private accept: boolean) { }
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.requestor = mg.player(this.requestorID)
this.recipient = mg.player(this.recipientID)
}
tick(ticks: number): void {
if (this.requestor.alliedWith(this.recipient)) {
console.warn('already allied')
} else {
const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient)
if (request == null) {
console.warn('no alliance request found')
} else {
if (this.accept) {
request.accept()
} else {
request.reject()
}
}
}
this.active = false
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
@@ -0,0 +1,35 @@
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class BreakAllianceExecution implements Execution {
private active = true
private requestor: MutablePlayer;
private recipient: MutablePlayer
constructor(private requestorID: PlayerID, private recipientID: PlayerID) { }
init(mg: MutableGame, ticks: number): void {
this.requestor = mg.player(this.requestorID)
this.recipient = mg.player(this.recipientID)
}
tick(ticks: number): void {
if (!this.requestor.alliedWith(this.recipient)) {
console.warn('cant break alliance, not allied')
} else {
this.requestor.breakAllianceWith(this.recipient)
}
this.active = false
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}