mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:51:30 +00:00
9b2c6cc1f6
## Description: https://github.com/openfrontio/OpenFrontIO/issues/776 I've implemented upgradable structures for cities and ports. As of right now this is just meant as a QOL change for structure stacking that currently happens and no gameplay changes are intended. Structure upgrades cost the same as making a new structure of that type and function the same as making a new structure of that type. I'm putting up a draft PR for this now since adding support for SAMs and Silos will take more time to handle the cooldowns and I want to make sure I'm on the right track for getting this merged. I also still need to add bot behavior for this and re-enable min distance for structures. I didn't see translations for the UnitInfoModal so I've left that out for now. I've tested locally in a single player game so far but will document and test more thoroughly before merging.   ## 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 - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: # Poutine --------- Co-authored-by: Scott Anderson <scottanderson@users.noreply.github.com>
45 lines
985 B
TypeScript
45 lines
985 B
TypeScript
import { Execution, Game, Player, Unit } from "../game/Game";
|
|
|
|
export class UpgradeStructureExecution implements Execution {
|
|
private structure: Unit | undefined;
|
|
private cost: bigint;
|
|
|
|
constructor(
|
|
private player: Player,
|
|
private unitId: number,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.structure = this.player
|
|
.units()
|
|
.find((unit) => unit.id() === this.unitId);
|
|
|
|
if (this.structure === undefined) {
|
|
console.warn(`structure is undefined`);
|
|
return;
|
|
}
|
|
if (!this.structure.info().upgradable) {
|
|
console.warn(`unit type ${this.structure} cannot be upgraded`);
|
|
return;
|
|
}
|
|
this.cost = this.structure.info().cost(this.player);
|
|
if (this.player.gold() < this.cost) {
|
|
return;
|
|
}
|
|
this.player.upgradeUnit(this.structure);
|
|
return;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
return;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return false;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|