From a159c5016093dd7188b5260de0227025e9fbeb16 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 27 Dec 2024 20:56:07 -0800 Subject: [PATCH] bugfix: NPCs not reseting enemy correctly, don't flip off NPCs, NPCs send messages to enemy --- .../graphics/layers/radial/EmojiTable.ts | 2 +- src/core/execution/EmojiExecution.ts | 5 ++- src/core/execution/FakeHumanExecution.ts | 38 +++++++++++++------ src/core/execution/NukeExecution.ts | 2 +- .../alliance/AllianceRequestReplyExecution.ts | 2 + .../alliance/BreakAllianceExecution.ts | 3 +- src/core/game/PlayerImpl.ts | 5 ++- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/client/graphics/layers/radial/EmojiTable.ts b/src/client/graphics/layers/radial/EmojiTable.ts index 7d516f94f..a5d8c1dd5 100644 --- a/src/client/graphics/layers/radial/EmojiTable.ts +++ b/src/client/graphics/layers/radial/EmojiTable.ts @@ -7,7 +7,7 @@ const emojiTable: string[][] = [ ["🤙", "🥰", "😇", "😊", "🔥"], ["💪", "🏳️", "💀", "😭", "🤦‍♂️"], ["😎", "👎", "👍", "🥱", "💔"], - ["❤️", "💰", "🤝", "🛡️", "💥"], + ["❤️", "💰", "🤝", "🖕", "💥"], ["🆘", "🕊️", "➡️", "⬅️", "↙️"], ["↖️", "↗️", "⬆️", "↘️", "⬇️"] ]; diff --git a/src/core/execution/EmojiExecution.ts b/src/core/execution/EmojiExecution.ts index 89146ec8d..e5dbcb782 100644 --- a/src/core/execution/EmojiExecution.ts +++ b/src/core/execution/EmojiExecution.ts @@ -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}`) } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index c0d30c315..edaaad30d 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -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 diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 45045f15b..c3fbafe09 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -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) } } } diff --git a/src/core/execution/alliance/AllianceRequestReplyExecution.ts b/src/core/execution/alliance/AllianceRequestReplyExecution.ts index 62c7a8430..fd24fbd3d 100644 --- a/src/core/execution/alliance/AllianceRequestReplyExecution.ts +++ b/src/core/execution/alliance/AllianceRequestReplyExecution.ts @@ -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() } diff --git a/src/core/execution/alliance/BreakAllianceExecution.ts b/src/core/execution/alliance/BreakAllianceExecution.ts index 2e383a6d4..a8529bfce 100644 --- a/src/core/execution/alliance/BreakAllianceExecution.ts +++ b/src/core/execution/alliance/BreakAllianceExecution.ts @@ -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 } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 604863588..fab9a6987 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -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() {