refactored alliance

This commit is contained in:
evanpelle
2024-09-22 13:38:43 -07:00
parent e746ea35e3
commit d874392467
15 changed files with 79 additions and 48 deletions
+5 -4
View File
@@ -86,7 +86,7 @@ export class AttackExecution implements Execution {
}
if (this.target.isPlayer()) {
if (this._owner.alliedWith(this.target)) {
if (this._owner.isAlliedWith(this.target)) {
// No updates should happen in init.
this.breakAlliance = true
}
@@ -109,11 +109,12 @@ export class AttackExecution implements Execution {
if (ticks < this.mg.config().numSpawnPhaseTurns()) {
return
}
if (this.breakAlliance && this._owner.alliedWith(this.target as Player)) {
const alliance = this._owner.allianceWith(this.target as Player)
if (this.breakAlliance && alliance != null) {
this.breakAlliance = false
this._owner.breakAllianceWith(this.target as Player)
this._owner.breakAlliance(alliance)
}
if (this.target.isPlayer() && this._owner.alliedWith(this.target)) {
if (this.target.isPlayer() && this._owner.isAlliedWith(this.target)) {
// In this case a new alliance was created AFTER the attack started.
this._owner.addTroops(this.troops)
this.active = false
+2 -2
View File
@@ -51,7 +51,7 @@ export class BotExecution implements Execution {
const traitors = this.bot.neighbors().filter(n => n.isPlayer() && n.isTraitor()) as Player[]
if (traitors.length > 0) {
const toAttack = this.random.randElement(traitors)
const odds = this.bot.alliedWith(toAttack) ? 6 : 3
const odds = this.bot.isAlliedWith(toAttack) ? 6 : 3
if (this.random.chance(odds)) {
this.sendAttack(toAttack)
return
@@ -80,7 +80,7 @@ export class BotExecution implements Execution {
const owner = toAttack.owner()
if (owner.isPlayer()) {
if (this.bot.alliedWith(owner)) {
if (this.bot.isAlliedWith(owner)) {
return
}
if (owner.type() == PlayerType.FakeHuman) {
+3 -3
View File
@@ -100,17 +100,17 @@ export class FakeHumanExecution implements Execution {
if (this.random.chance(10)) {
const toAlly = this.random.randElement(enemies)
if (!this.player.alliedWith(toAlly)) {
if (!this.player.isAlliedWith(toAlly)) {
this.player.createAllianceRequest(toAlly)
}
}
if (this.random.chance(2)) {
if (!this.player.alliedWith(enemies[0]) || this.random.chance(30)) {
if (!this.player.isAlliedWith(enemies[0]) || this.random.chance(30)) {
this.sendAttack(enemies[0])
}
} else {
if (!this.player.alliedWith(enemies[0]) || this.random.chance(60)) {
if (!this.player.isAlliedWith(enemies[0]) || this.random.chance(60)) {
this.sendAttack(this.random.randElement(enemies))
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ export class PlayerExecution implements Execution {
const main = clusters.shift()
const surroundedBy = this.surroundedBySamePlayer(main)
if (surroundedBy && !this.player.alliedWith(surroundedBy)) {
if (surroundedBy && !this.player.isAlliedWith(surroundedBy)) {
this.removeCluster(main)
}
@@ -15,7 +15,7 @@ export class AllianceRequestExecution implements Execution {
}
tick(ticks: number): void {
if (this.requestor.alliedWith(this.recipient)) {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
} else {
this.requestor.createAllianceRequest(this.recipient)
@@ -15,7 +15,7 @@ export class AllianceRequestReplyExecution implements Execution {
}
tick(ticks: number): void {
if (this.requestor.alliedWith(this.recipient)) {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
} else {
const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient)
@@ -13,10 +13,11 @@ export class BreakAllianceExecution implements Execution {
}
tick(ticks: number): void {
if (!this.requestor.alliedWith(this.recipient)) {
const alliance = this.requestor.allianceWith(this.recipient)
if (alliance == null) {
console.warn('cant break alliance, not allied')
} else {
this.requestor.breakAllianceWith(this.recipient)
this.requestor.breakAlliance(alliance)
}
this.active = false
}