mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 22:34:36 +00:00
feat(PlayerExecution): downgrade defense posts on capture (#1957)
## Description: Closes https://github.com/openfrontio/OpenFrontIO/issues/1619. On capture, defense posts will be downgraded. On the live version this means defense posts will be destroyed, as defense posts can only be level 1. Misc. changes: - added `decreaserLevel` helper - cleaned up if/else in tick unit loop for clarity to avoid yet another nested layer Continuation of the stale PR, https://github.com/openfrontio/OpenFrontIO/pull/1622. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: Discord username: `seekerreturns`
This commit is contained in:
@@ -30,9 +30,14 @@ export class PlayerExecution implements Execution {
|
||||
this.player.units().forEach((u) => {
|
||||
const tileOwner = this.mg!.owner(u.tile());
|
||||
if (u.info().territoryBound) {
|
||||
if (tileOwner.isPlayer()) {
|
||||
if (tileOwner?.isPlayer()) {
|
||||
if (tileOwner !== this.player) {
|
||||
this.mg!.player(tileOwner.id()).captureUnit(u);
|
||||
if (u.type() === UnitType.DefensePost) {
|
||||
this.mg!.player(tileOwner.id()).captureUnit(u);
|
||||
u.decreaseLevel(this.mg!.player(tileOwner.id()));
|
||||
} else {
|
||||
this.mg!.player(tileOwner.id()).captureUnit(u);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u.delete();
|
||||
|
||||
@@ -494,6 +494,7 @@ export interface Unit {
|
||||
// Upgradable Structures
|
||||
level(): number;
|
||||
increaseLevel(): void;
|
||||
decreaseLevel(destroyer?: Player): void;
|
||||
|
||||
// Warships
|
||||
setPatrolTile(tile: TileRef): void;
|
||||
|
||||
@@ -397,6 +397,18 @@ export class UnitImpl implements Unit {
|
||||
this.mg.addUpdate(this.toUpdate());
|
||||
}
|
||||
|
||||
decreaseLevel(destroyer?: Player): void {
|
||||
this._level--;
|
||||
if ([UnitType.MissileSilo, UnitType.SAMLauncher].includes(this.type())) {
|
||||
this._missileTimerQueue.pop();
|
||||
}
|
||||
if (this._level <= 0) {
|
||||
this.delete(true, destroyer);
|
||||
return;
|
||||
}
|
||||
this.mg.addUpdate(this.toUpdate());
|
||||
}
|
||||
|
||||
trainType(): TrainType | undefined {
|
||||
return this._trainType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user