bugfix: NPCs not reseting enemy correctly, don't flip off NPCs, NPCs send messages to enemy

This commit is contained in:
Evan
2024-12-27 20:56:07 -08:00
parent ac1d0c0378
commit a159c50160
7 changed files with 40 additions and 17 deletions
@@ -7,7 +7,7 @@ const emojiTable: string[][] = [
["🤙", "🥰", "😇", "😊", "🔥"],
["💪", "🏳️", "💀", "😭", "🤦‍♂️"],
["😎", "👎", "👍", "🥱", "💔"],
["❤️", "💰", "🤝", "🛡️", "💥"],
["❤️", "💰", "🤝", "🖕", "💥"],
["🆘", "🕊️", "➡️", "⬅️", "↙️"],
["↖️", "↗️", "⬆️", "↘️", "⬇️"]
];
+4 -1
View File
@@ -1,5 +1,5 @@
import { consolex } from "../Consolex";
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
import { AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID, PlayerType, UnitType } from "../game/Game";
export class EmojiExecution implements Execution {
@@ -23,6 +23,9 @@ export class EmojiExecution implements Execution {
tick(ticks: number): void {
if (this.requestor.canSendEmoji(this.recipient)) {
this.requestor.sendEmoji(this.recipient, this.emoji)
if (this.emoji == "🖕" && this.recipient != AllPlayers && this.recipient.type() == PlayerType.FakeHuman) {
this.recipient.updateRelation(this.requestor, -10000)
}
} else {
consolex.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`)
}
+27 -11
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile, UnitType } from "../game/Game"
import { AllianceRequest, Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile, UnitType } from "../game/Game"
import { PseudoRandom } from "../PseudoRandom"
import { and, bfs, calculateBoundingBox, dist, euclDist, manhattanDist, simpleHash } from "../Util";
import { AttackExecution } from "./AttackExecution";
@@ -15,6 +15,7 @@ import { CityExecution } from "./CityExecution";
import { NukeExecution } from "./NukeExecution";
import { MissileSiloExecution } from "./MissileSiloExecution";
import { EmojiExecution } from "./EmojiExecution";
import { AllianceRequestReplyExecution } from "./alliance/AllianceRequestReplyExecution";
export class FakeHumanExecution implements Execution {
@@ -27,6 +28,8 @@ export class FakeHumanExecution implements Execution {
private enemy: Player | null = null
private lastEnemyUpdateTick: number = 0
constructor(gameID: GameID, private worker: WorkerClient, private playerInfo: PlayerInfo, private cell: Cell, private strength: number) {
this.random = new PseudoRandom(simpleHash(playerInfo.id) + simpleHash(gameID))
@@ -86,7 +89,6 @@ export class FakeHumanExecution implements Execution {
this.handleEnemies()
this.handleUnits()
const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.isLand() && t.owner() != this.player)
if (enemyborder.length == 0) {
@@ -137,7 +139,7 @@ export class FakeHumanExecution implements Execution {
}
handleEnemies() {
if (this.mg.ticks() % 100 == 0) {
if (this.mg.ticks() - this.lastEnemyUpdateTick > 100) {
this.enemy = null
}
@@ -149,13 +151,22 @@ export class FakeHumanExecution implements Execution {
if (target != null) {
this.player.updateRelation(target.ally, -2000)
this.enemy = target.t[0]
this.lastEnemyUpdateTick = this.mg.ticks()
this.mg.addExecution(new EmojiExecution(this.player.id(), target.ally.id(), "👍"))
}
if (this.enemy == null) {
const mostHated = this.player.allRelationsSorted()[0] ?? null
if (mostHated != null && mostHated.relation < - 500) {
if (mostHated != null && mostHated.relation < - 2000) {
this.enemy = mostHated.player
this.lastEnemyUpdateTick = this.mg.ticks()
this.mg.addExecution(
new EmojiExecution(
this.player.id(),
this.enemy.id(),
this.random.randElement(["🤡", "😡"])
)
)
}
}
@@ -181,7 +192,7 @@ export class FakeHumanExecution implements Execution {
}
for (const t of bfs(tile, dist(tile, 15))) {
// Make sure we nuke at least 15 tiles in border
if (t.owner() != other) {
if (t.hasOwner() && t.owner() != other) {
continue outer
}
}
@@ -309,23 +320,28 @@ export class FakeHumanExecution implements Execution {
handleAllianceRequests() {
for (const req of this.player.incomingAllianceRequests()) {
if (req.requestor().isTraitor()) {
req.reject()
this.replyToAllianceRequest(req, false)
continue
}
if (this.player.relation(req.requestor()) < 0) {
req.reject()
this.replyToAllianceRequest(req, false)
continue
}
const requestorIsMuchLarger = req.requestor().numTilesOwned() > this.player.numTilesOwned() * 3
if (!requestorIsMuchLarger && req.requestor().alliances().length >= 3) {
req.reject()
this.replyToAllianceRequest(req, false)
continue
}
req.accept()
req.requestor().updateRelation(this.player, 10000)
this.player.updateRelation(req.requestor(), 10000)
this.replyToAllianceRequest(req, true)
}
}
private replyToAllianceRequest(req: AllianceRequest, accept: boolean): void {
this.mg.addExecution(
new AllianceRequestReplyExecution(req.requestor().id(), this.player.id(), accept)
)
}
sendBoat(tries: number = 0, oceanShore: Tile[] = null) {
if (tries > 10) {
return
+1 -1
View File
@@ -103,7 +103,7 @@ export class NukeExecution implements Execution {
this.player.breakAlliance(alliance)
}
if (other != this.player) {
other.updateRelation(this.player, -10000)
other.updateRelation(this.player, -5000)
}
}
}
@@ -25,6 +25,8 @@ export class AllianceRequestReplyExecution implements Execution {
} else {
if (this.accept) {
request.accept()
this.requestor.updateRelation(this.recipient, 5000)
this.recipient.updateRelation(this.requestor, 5000)
} else {
request.reject()
}
@@ -1,5 +1,5 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
import { AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID } from "../../game/Game";
export class BreakAllianceExecution implements Execution {
private active = true
@@ -19,6 +19,7 @@ export class BreakAllianceExecution implements Execution {
consolex.warn('cant break alliance, not allied')
} else {
this.requestor.breakAlliance(alliance)
this.recipient.updateRelation(this.requestor, -5000)
}
this.active = false
}
+3 -2
View File
@@ -1,6 +1,6 @@
import { MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, EmojiMessage, EmojiMessageEvent, AllPlayers, Gold, UnitType, Unit, MutableUnit } from "./Game";
import { ClientID } from "../Schemas";
import { assertNever, bfs, closestOceanShoreFromPlayer, dist, distSortUnit, manhattanDist, manhattanDistWrapped, processName, simpleHash, sourceDstOceanShore } from "../Util";
import { assertNever, bfs, closestOceanShoreFromPlayer, dist, distSortUnit, manhattanDist, manhattanDistWrapped, processName, simpleHash, sourceDstOceanShore, within } from "../Util";
import { CellString, GameImpl } from "./GameImpl";
import { UnitImpl } from "./UnitImpl";
import { TileImpl } from "./TileImpl";
@@ -223,7 +223,8 @@ export class PlayerImpl implements MutablePlayer {
if (this.relations.has(other)) {
relation = this.relations.get(other)
}
this.relations.set(other, relation + delta)
const newRelation = within(relation + delta, -10000, 10000)
this.relations.set(other, newRelation)
}
decayRelations() {