alert when unit is destroyed

This commit is contained in:
evanpelle
2024-12-10 15:45:17 -08:00
committed by Evan
parent 67288cb49f
commit f34a8dca13
4 changed files with 24 additions and 19 deletions
+2 -1
View File
@@ -11,7 +11,8 @@ import {
Game,
Player,
PlayerID,
TargetPlayerEvent
TargetPlayerEvent,
UnitEvent
} from "../../../core/game/Game";
import { ClientID } from "../../../core/Schemas";
import { Layer } from "./Layer";
+9 -12
View File
@@ -31,18 +31,15 @@ export const devConfig = new class extends DefaultConfig {
tradeShipSpawnRate(): number {
return 10
}
// boatMaxDistance(): number {
// return 5000
// }
boatMaxDistance(): number {
return 5000
}
// numBots(): number {
// return 0
// }
// spawnNPCs(): boolean {
// return false
// }
numBots(): number {
return 0
}
spawnNPCs(): boolean {
return false
}
// boatMaxDistance(): number {
// return 2000
// }
}
@@ -28,12 +28,6 @@ export class MissileSiloExecution implements Execution {
}
this.silo = this.player.buildUnit(UnitType.MissileSilo, 0, tile)
}
if (!this.silo.tile().hasOwner()) {
this.silo.delete()
this.active = false
return
}
}
owner(): MutablePlayer {
+13
View File
@@ -1,3 +1,4 @@
import { MessageType } from "../../client/graphics/layers/EventsDisplay";
import { simpleHash } from "../Util";
import { MutableUnit, Tile, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
import { GameImpl } from "./GameImpl";
@@ -46,14 +47,26 @@ export class UnitImpl implements MutableUnit {
}
setOwner(newOwner: Player): void {
const oldOwner = this._owner
this._owner = newOwner as PlayerImpl
this.g.fireUnitUpdateEvent(this, this.tile())
this.g.displayMessage(
`Your ${this.type()} was captured by ${newOwner.displayName()}`,
MessageType.ERROR,
oldOwner.id()
)
}
delete(): void {
if (!this.isActive()) {
throw new Error(`cannot delete ${this} not active`)
}
this._owner._units = this._owner._units.filter(b => b != this);
this._active = false;
this.g.fireUnitUpdateEvent(this, this._tile);
if (this.type() != UnitType.AtomBomb && this.type() != UnitType.HydrogenBomb) {
this.g.displayMessage(`Your ${this.type()} was destroyed`, MessageType.ERROR, this.owner().id())
}
}
isActive(): boolean {
return this._active;