mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 00:28:14 +00:00
Simple Upgradable Structures (Cities, Ports, SAMs and Silos) (#1012)
## 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>
This commit is contained in:
co-authored by
Scott Anderson
parent
9c3b828fc8
commit
9b2c6cc1f6
@@ -400,7 +400,8 @@
|
|||||||
"sams": "SAMs",
|
"sams": "SAMs",
|
||||||
"warships": "Warships",
|
"warships": "Warships",
|
||||||
"health": "Health",
|
"health": "Health",
|
||||||
"attitude": "Attitude"
|
"attitude": "Attitude",
|
||||||
|
"levels": "Levels"
|
||||||
},
|
},
|
||||||
"events_display": {
|
"events_display": {
|
||||||
"retreating": "retreating",
|
"retreating": "retreating",
|
||||||
@@ -411,7 +412,9 @@
|
|||||||
"unit_type_unknown": "Unknown",
|
"unit_type_unknown": "Unknown",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"cooldown": "Cooldown",
|
"cooldown": "Cooldown",
|
||||||
"type": "Type"
|
"type": "Type",
|
||||||
|
"upgrade": "Upgrade",
|
||||||
|
"level": "Level"
|
||||||
},
|
},
|
||||||
"relation": {
|
"relation": {
|
||||||
"hostile": "Hostile",
|
"hostile": "Hostile",
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ export class SendBreakAllianceIntentEvent implements GameEvent {
|
|||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SendUpgradeStructureIntentEvent implements GameEvent {
|
||||||
|
constructor(
|
||||||
|
public readonly unitId: number,
|
||||||
|
public readonly unitType: UnitType,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
export class SendAllianceReplyIntentEvent implements GameEvent {
|
export class SendAllianceReplyIntentEvent implements GameEvent {
|
||||||
constructor(
|
constructor(
|
||||||
// The original alliance requestor
|
// The original alliance requestor
|
||||||
@@ -187,6 +194,9 @@ export class Transport {
|
|||||||
this.onSendSpawnIntentEvent(e),
|
this.onSendSpawnIntentEvent(e),
|
||||||
);
|
);
|
||||||
this.eventBus.on(SendAttackIntentEvent, (e) => this.onSendAttackIntent(e));
|
this.eventBus.on(SendAttackIntentEvent, (e) => this.onSendAttackIntent(e));
|
||||||
|
this.eventBus.on(SendUpgradeStructureIntentEvent, (e) =>
|
||||||
|
this.onSendUpgradeStructureIntent(e),
|
||||||
|
);
|
||||||
this.eventBus.on(SendBoatAttackIntentEvent, (e) =>
|
this.eventBus.on(SendBoatAttackIntentEvent, (e) =>
|
||||||
this.onSendBoatAttackIntent(e),
|
this.onSendBoatAttackIntent(e),
|
||||||
);
|
);
|
||||||
@@ -427,6 +437,15 @@ export class Transport {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onSendUpgradeStructureIntent(event: SendUpgradeStructureIntentEvent) {
|
||||||
|
this.sendIntent({
|
||||||
|
type: "upgrade_structure",
|
||||||
|
unit: event.unitType,
|
||||||
|
clientID: this.lobbyConfig.clientID,
|
||||||
|
unitId: event.unitId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private onSendTargetPlayerIntent(event: SendTargetPlayerIntentEvent) {
|
private onSendTargetPlayerIntent(event: SendTargetPlayerIntentEvent) {
|
||||||
this.sendIntent({
|
this.sendIntent({
|
||||||
type: "targetPlayer",
|
type: "targetPlayer",
|
||||||
|
|||||||
@@ -240,18 +240,58 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
|
|||||||
<div class="text-sm opacity-80" translate="no">
|
<div class="text-sm opacity-80" translate="no">
|
||||||
${translateText("player_info_overlay.ports")}:
|
${translateText("player_info_overlay.ports")}:
|
||||||
${player.units(UnitType.Port).length}
|
${player.units(UnitType.Port).length}
|
||||||
|
${player
|
||||||
|
.units(UnitType.Port)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0) > 1
|
||||||
|
? html`(${translateText("player_info_overlay.levels")}:
|
||||||
|
${player
|
||||||
|
.units(UnitType.Port)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0)})`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm opacity-80" translate="no">
|
<div class="text-sm opacity-80" translate="no">
|
||||||
${translateText("player_info_overlay.cities")}:
|
${translateText("player_info_overlay.cities")}:
|
||||||
${player.units(UnitType.City).length}
|
${player.units(UnitType.City).length}
|
||||||
|
${player
|
||||||
|
.units(UnitType.City)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0) > 1
|
||||||
|
? html`(${translateText("player_info_overlay.levels")}:
|
||||||
|
${player
|
||||||
|
.units(UnitType.City)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0)})`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm opacity-80" translate="no">
|
<div class="text-sm opacity-80" translate="no">
|
||||||
${translateText("player_info_overlay.missile_launchers")}:
|
${translateText("player_info_overlay.missile_launchers")}:
|
||||||
${player.units(UnitType.MissileSilo).length}
|
${player.units(UnitType.MissileSilo).length}
|
||||||
|
${player
|
||||||
|
.units(UnitType.MissileSilo)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0) > 1
|
||||||
|
? html`(${translateText("player_info_overlay.levels")}:
|
||||||
|
${player
|
||||||
|
.units(UnitType.MissileSilo)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0)})`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm opacity-80" translate="no">
|
<div class="text-sm opacity-80" translate="no">
|
||||||
${translateText("player_info_overlay.sams")}:
|
${translateText("player_info_overlay.sams")}:
|
||||||
${player.units(UnitType.SAMLauncher).length}
|
${player.units(UnitType.SAMLauncher).length}
|
||||||
|
${player
|
||||||
|
.units(UnitType.SAMLauncher)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0) > 1
|
||||||
|
? html`(${translateText("player_info_overlay.levels")}:
|
||||||
|
${player
|
||||||
|
.units(UnitType.SAMLauncher)
|
||||||
|
.map((unit) => unit.level())
|
||||||
|
.reduce((a, b) => a + b, 0)})`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm opacity-80" translate="no">
|
<div class="text-sm opacity-80" translate="no">
|
||||||
${translateText("player_info_overlay.warships")}:
|
${translateText("player_info_overlay.warships")}:
|
||||||
|
|||||||
@@ -242,13 +242,13 @@ export class StructureLayer implements Layer {
|
|||||||
const config = this.unitConfigs[unitType];
|
const config = this.unitConfigs[unitType];
|
||||||
let icon: ImageData | undefined;
|
let icon: ImageData | undefined;
|
||||||
|
|
||||||
if (unitType === UnitType.SAMLauncher && unit.isCooldown()) {
|
if (unitType === UnitType.SAMLauncher && unit.isInCooldown()) {
|
||||||
icon = this.unitIcons.get("reloadingSam");
|
icon = this.unitIcons.get("reloadingSam");
|
||||||
} else {
|
} else {
|
||||||
icon = this.unitIcons.get(iconType);
|
icon = this.unitIcons.get(iconType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitType === UnitType.MissileSilo && unit.isCooldown()) {
|
if (unitType === UnitType.MissileSilo && unit.isInCooldown()) {
|
||||||
icon = this.unitIcons.get("reloadingSilo");
|
icon = this.unitIcons.get("reloadingSilo");
|
||||||
} else {
|
} else {
|
||||||
icon = this.unitIcons.get(iconType);
|
icon = this.unitIcons.get(iconType);
|
||||||
@@ -268,13 +268,13 @@ export class StructureLayer implements Layer {
|
|||||||
if (!unit.isActive()) return;
|
if (!unit.isActive()) return;
|
||||||
|
|
||||||
let borderColor = this.theme.borderColor(unit.owner());
|
let borderColor = this.theme.borderColor(unit.owner());
|
||||||
if (unitType === UnitType.SAMLauncher && unit.isCooldown()) {
|
if (unitType === UnitType.SAMLauncher && unit.isInCooldown()) {
|
||||||
borderColor = reloadingColor;
|
borderColor = reloadingColor;
|
||||||
} else if (unit.type() === UnitType.Construction) {
|
} else if (unit.type() === UnitType.Construction) {
|
||||||
borderColor = underConstructionColor;
|
borderColor = underConstructionColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitType === UnitType.MissileSilo && unit.isCooldown()) {
|
if (unitType === UnitType.MissileSilo && unit.isInCooldown()) {
|
||||||
borderColor = reloadingColor;
|
borderColor = reloadingColor;
|
||||||
} else if (unit.type() === UnitType.Construction) {
|
} else if (unit.type() === UnitType.Construction) {
|
||||||
borderColor = underConstructionColor;
|
borderColor = underConstructionColor;
|
||||||
@@ -391,6 +391,7 @@ export class StructureLayer implements Layer {
|
|||||||
const screenPos = this.transformHandler.worldToScreenCoordinates(cell);
|
const screenPos = this.transformHandler.worldToScreenCoordinates(cell);
|
||||||
const unitTile = clickedUnit.tile();
|
const unitTile = clickedUnit.tile();
|
||||||
this.unitInfoModal?.onOpenStructureModal({
|
this.unitInfoModal?.onOpenStructureModal({
|
||||||
|
eventBus: this.eventBus,
|
||||||
unit: clickedUnit,
|
unit: clickedUnit,
|
||||||
x: screenPos.x,
|
x: screenPos.x,
|
||||||
y: screenPos.y,
|
y: screenPos.y,
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export class UILayer implements Layer {
|
|||||||
}
|
}
|
||||||
case UnitType.SAMLauncher:
|
case UnitType.SAMLauncher:
|
||||||
case UnitType.MissileSilo:
|
case UnitType.MissileSilo:
|
||||||
if (unit.isActive() && unit.isCooldown()) {
|
if (unit.isActive() && unit.isInCooldown()) {
|
||||||
const endTick = unit.ticksLeftInCooldown() || 0;
|
const endTick = unit.ticksLeftInCooldown() || 0;
|
||||||
this.drawLoadingBar(unit, endTick);
|
this.drawLoadingBar(unit, endTick);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { LitElement, css, html } from "lit";
|
import { LitElement, css, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators.js";
|
import { customElement, property } from "lit/decorators.js";
|
||||||
import { translateText } from "../../../client/Utils";
|
import { translateText } from "../../../client/Utils";
|
||||||
|
import { EventBus } from "../../../core/EventBus";
|
||||||
import { UnitType } from "../../../core/game/Game";
|
import { UnitType } from "../../../core/game/Game";
|
||||||
import { GameView, UnitView } from "../../../core/game/GameView";
|
import { GameView, UnitView } from "../../../core/game/GameView";
|
||||||
|
import { SendUpgradeStructureIntentEvent } from "../../Transport";
|
||||||
import { Layer } from "./Layer";
|
import { Layer } from "./Layer";
|
||||||
import { StructureLayer } from "./StructureLayer";
|
import { StructureLayer } from "./StructureLayer";
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
|
|
||||||
public game: GameView;
|
public game: GameView;
|
||||||
public structureLayer: StructureLayer | null = null;
|
public structureLayer: StructureLayer | null = null;
|
||||||
|
private eventBus: EventBus;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -29,12 +32,14 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onOpenStructureModal = ({
|
public onOpenStructureModal = ({
|
||||||
|
eventBus,
|
||||||
unit,
|
unit,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
tileX,
|
tileX,
|
||||||
tileY,
|
tileY,
|
||||||
}: {
|
}: {
|
||||||
|
eventBus: EventBus;
|
||||||
unit: UnitView;
|
unit: UnitView;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -44,6 +49,7 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
if (!this.game) return;
|
if (!this.game) return;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
this.eventBus = eventBus;
|
||||||
const targetRef = this.game.ref(tileX, tileY);
|
const targetRef = this.game.ref(tileX, tileY);
|
||||||
|
|
||||||
const allUnitTypes = Object.values(UnitType);
|
const allUnitTypes = Object.values(UnitType);
|
||||||
@@ -119,12 +125,44 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
.close-button:hover {
|
.close-button:hover {
|
||||||
background: #a00;
|
background: #a00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.upgrade-button {
|
||||||
|
background: #3a0;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
line-height: 1;
|
||||||
|
padding: 6px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upgrade-button:hover {
|
||||||
|
background: #0a0;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.unit) return null;
|
if (!this.unit) return null;
|
||||||
|
|
||||||
const cooldown = this.unit.ticksLeftInCooldown() ?? 0;
|
const ticksLeftInCooldown = this.unit.ticksLeftInCooldown();
|
||||||
|
let configTimer;
|
||||||
|
switch (this.unit.type()) {
|
||||||
|
case UnitType.MissileSilo:
|
||||||
|
configTimer = this.game.config().SiloCooldown();
|
||||||
|
break;
|
||||||
|
case UnitType.SAMLauncher:
|
||||||
|
configTimer = this.game.config().SAMCooldown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let cooldown = 0;
|
||||||
|
if (ticksLeftInCooldown !== undefined && configTimer !== undefined) {
|
||||||
|
cooldown = configTimer - (this.game.ticks() - ticksLeftInCooldown);
|
||||||
|
}
|
||||||
const secondsLeft = Math.ceil(cooldown / 10);
|
const secondsLeft = Math.ceil(cooldown / 10);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@@ -140,6 +178,16 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
<strong>${translateText("unit_info_modal.type")}:</strong>
|
<strong>${translateText("unit_info_modal.type")}:</strong>
|
||||||
${translateText(+"unit_type." + this.unit.type?.().toLowerCase()) ??
|
${translateText(+"unit_type." + this.unit.type?.().toLowerCase()) ??
|
||||||
translateText("unit_info_modal.unit_type_unknown")}
|
translateText("unit_info_modal.unit_type_unknown")}
|
||||||
|
<strong
|
||||||
|
style="display: ${this.game.unitInfo(this.unit.type()).upgradable
|
||||||
|
? "inline"
|
||||||
|
: "none"};"
|
||||||
|
>${translateText("unit_info_modal.level")}:</strong
|
||||||
|
>
|
||||||
|
${this.game.unitInfo(this.unit.type()).upgradable &&
|
||||||
|
this.unit.level?.()
|
||||||
|
? this.unit.level?.()
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
${secondsLeft > 0
|
${secondsLeft > 0
|
||||||
? html`<div style="margin-bottom: 4px;">
|
? html`<div style="margin-bottom: 4px;">
|
||||||
@@ -147,7 +195,30 @@ export class UnitInfoModal extends LitElement implements Layer {
|
|||||||
${secondsLeft}s
|
${secondsLeft}s
|
||||||
</div>`
|
</div>`
|
||||||
: ""}
|
: ""}
|
||||||
<div style="margin-top: 14px; display: flex; justify-content: center;">
|
<div
|
||||||
|
style="margin-top: 14px; display: flex; justify-content: space-between;"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
@click=${() => {
|
||||||
|
if (this.unit) {
|
||||||
|
this.eventBus.emit(
|
||||||
|
new SendUpgradeStructureIntentEvent(
|
||||||
|
this.unit.id(),
|
||||||
|
this.unit.type(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
class="upgrade-button"
|
||||||
|
title="${translateText("unit_info_modal.upgrade")}"
|
||||||
|
style="width: 100px; height: 32px; display: ${this.game.unitInfo(
|
||||||
|
this.unit.type(),
|
||||||
|
).upgradable
|
||||||
|
? "block"
|
||||||
|
: "none"};"
|
||||||
|
>
|
||||||
|
${translateText("unit_info_modal.upgrade")}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
@click=${() => {
|
@click=${() => {
|
||||||
this.onCloseStructureModal();
|
this.onCloseStructureModal();
|
||||||
|
|||||||
+13
-1
@@ -34,7 +34,8 @@ export type Intent =
|
|||||||
| EmbargoIntent
|
| EmbargoIntent
|
||||||
| QuickChatIntent
|
| QuickChatIntent
|
||||||
| MoveWarshipIntent
|
| MoveWarshipIntent
|
||||||
| MarkDisconnectedIntent;
|
| MarkDisconnectedIntent
|
||||||
|
| UpgradeStructureIntent;
|
||||||
|
|
||||||
export type AttackIntent = z.infer<typeof AttackIntentSchema>;
|
export type AttackIntent = z.infer<typeof AttackIntentSchema>;
|
||||||
export type CancelAttackIntent = z.infer<typeof CancelAttackIntentSchema>;
|
export type CancelAttackIntent = z.infer<typeof CancelAttackIntentSchema>;
|
||||||
@@ -55,6 +56,9 @@ export type TargetTroopRatioIntent = z.infer<
|
|||||||
typeof TargetTroopRatioIntentSchema
|
typeof TargetTroopRatioIntentSchema
|
||||||
>;
|
>;
|
||||||
export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>;
|
export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>;
|
||||||
|
export type UpgradeStructureIntent = z.infer<
|
||||||
|
typeof UpgradeStructureIntentSchema
|
||||||
|
>;
|
||||||
export type MoveWarshipIntent = z.infer<typeof MoveWarshipIntentSchema>;
|
export type MoveWarshipIntent = z.infer<typeof MoveWarshipIntentSchema>;
|
||||||
export type QuickChatIntent = z.infer<typeof QuickChatIntentSchema>;
|
export type QuickChatIntent = z.infer<typeof QuickChatIntentSchema>;
|
||||||
export type MarkDisconnectedIntent = z.infer<
|
export type MarkDisconnectedIntent = z.infer<
|
||||||
@@ -178,6 +182,7 @@ const BaseIntentSchema = z.object({
|
|||||||
"emoji",
|
"emoji",
|
||||||
"troop_ratio",
|
"troop_ratio",
|
||||||
"build_unit",
|
"build_unit",
|
||||||
|
"upgrade_structure",
|
||||||
"embargo",
|
"embargo",
|
||||||
"move_warship",
|
"move_warship",
|
||||||
]),
|
]),
|
||||||
@@ -266,6 +271,12 @@ export const BuildUnitIntentSchema = BaseIntentSchema.extend({
|
|||||||
y: z.number(),
|
y: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const UpgradeStructureIntentSchema = BaseIntentSchema.extend({
|
||||||
|
type: z.literal("upgrade_structure"),
|
||||||
|
unit: z.nativeEnum(UnitType),
|
||||||
|
unitId: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
export const CancelAttackIntentSchema = BaseIntentSchema.extend({
|
export const CancelAttackIntentSchema = BaseIntentSchema.extend({
|
||||||
type: z.literal("cancel_attack"),
|
type: z.literal("cancel_attack"),
|
||||||
attackID: z.string(),
|
attackID: z.string(),
|
||||||
@@ -316,6 +327,7 @@ const IntentSchema = z.union([
|
|||||||
DonateTroopIntentSchema,
|
DonateTroopIntentSchema,
|
||||||
TargetTroopRatioIntentSchema,
|
TargetTroopRatioIntentSchema,
|
||||||
BuildUnitIntentSchema,
|
BuildUnitIntentSchema,
|
||||||
|
UpgradeStructureIntentSchema,
|
||||||
EmbargoIntentSchema,
|
EmbargoIntentSchema,
|
||||||
MoveWarshipIntentSchema,
|
MoveWarshipIntentSchema,
|
||||||
QuickChatIntentSchema,
|
QuickChatIntentSchema,
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export const OTHER_INDEX_BUILT = 0; // Structures and warships built
|
|||||||
export const OTHER_INDEX_DESTROY = 1; // Structures and warships destroyed
|
export const OTHER_INDEX_DESTROY = 1; // Structures and warships destroyed
|
||||||
export const OTHER_INDEX_CAPTURE = 2; // Structures captured
|
export const OTHER_INDEX_CAPTURE = 2; // Structures captured
|
||||||
export const OTHER_INDEX_LOST = 3; // Structures/warships destroyed/captured by others
|
export const OTHER_INDEX_LOST = 3; // Structures/warships destroyed/captured by others
|
||||||
|
export const OTHER_INDEX_UPGRADE = 4; // Structures upgraded
|
||||||
|
|
||||||
const BigIntStringSchema = z.preprocess((val) => {
|
const BigIntStringSchema = z.preprocess((val) => {
|
||||||
if (typeof val === "string" && /^\d+$/.test(val)) return BigInt(val);
|
if (typeof val === "string" && /^\d+$/.test(val)) return BigInt(val);
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ export class DefaultConfig implements Config {
|
|||||||
),
|
),
|
||||||
territoryBound: true,
|
territoryBound: true,
|
||||||
constructionDuration: this.instantBuild() ? 0 : 2 * 10,
|
constructionDuration: this.instantBuild() ? 0 : 2 * 10,
|
||||||
|
upgradable: true,
|
||||||
};
|
};
|
||||||
case UnitType.AtomBomb:
|
case UnitType.AtomBomb:
|
||||||
return {
|
return {
|
||||||
@@ -390,6 +391,7 @@ export class DefaultConfig implements Config {
|
|||||||
: 1_000_000n,
|
: 1_000_000n,
|
||||||
territoryBound: true,
|
territoryBound: true,
|
||||||
constructionDuration: this.instantBuild() ? 0 : 10 * 10,
|
constructionDuration: this.instantBuild() ? 0 : 10 * 10,
|
||||||
|
upgradable: true,
|
||||||
};
|
};
|
||||||
case UnitType.DefensePost:
|
case UnitType.DefensePost:
|
||||||
return {
|
return {
|
||||||
@@ -406,6 +408,7 @@ export class DefaultConfig implements Config {
|
|||||||
),
|
),
|
||||||
territoryBound: true,
|
territoryBound: true,
|
||||||
constructionDuration: this.instantBuild() ? 0 : 5 * 10,
|
constructionDuration: this.instantBuild() ? 0 : 5 * 10,
|
||||||
|
upgradable: true,
|
||||||
};
|
};
|
||||||
case UnitType.SAMLauncher:
|
case UnitType.SAMLauncher:
|
||||||
return {
|
return {
|
||||||
@@ -422,6 +425,7 @@ export class DefaultConfig implements Config {
|
|||||||
),
|
),
|
||||||
territoryBound: true,
|
territoryBound: true,
|
||||||
constructionDuration: this.instantBuild() ? 0 : 30 * 10,
|
constructionDuration: this.instantBuild() ? 0 : 30 * 10,
|
||||||
|
upgradable: true,
|
||||||
};
|
};
|
||||||
case UnitType.City:
|
case UnitType.City:
|
||||||
return {
|
return {
|
||||||
@@ -439,6 +443,7 @@ export class DefaultConfig implements Config {
|
|||||||
),
|
),
|
||||||
territoryBound: true,
|
territoryBound: true,
|
||||||
constructionDuration: this.instantBuild() ? 0 : 2 * 10,
|
constructionDuration: this.instantBuild() ? 0 : 2 * 10,
|
||||||
|
upgradable: true,
|
||||||
};
|
};
|
||||||
case UnitType.Construction:
|
case UnitType.Construction:
|
||||||
return {
|
return {
|
||||||
@@ -666,7 +671,11 @@ export class DefaultConfig implements Config {
|
|||||||
player.type() === PlayerType.Human && this.infiniteTroops()
|
player.type() === PlayerType.Human && this.infiniteTroops()
|
||||||
? 1_000_000_000
|
? 1_000_000_000
|
||||||
: 2 * (Math.pow(player.numTilesOwned(), 0.6) * 1000 + 50000) +
|
: 2 * (Math.pow(player.numTilesOwned(), 0.6) * 1000 + 50000) +
|
||||||
player.units(UnitType.City).length * this.cityPopulationIncrease();
|
player
|
||||||
|
.units(UnitType.City)
|
||||||
|
.map((city) => city.level())
|
||||||
|
.reduce((a, b) => a + b, 0) *
|
||||||
|
this.cityPopulationIncrease();
|
||||||
|
|
||||||
if (player.type() === PlayerType.Bot) {
|
if (player.type() === PlayerType.Bot) {
|
||||||
return maxPop / 2;
|
return maxPop / 2;
|
||||||
@@ -761,8 +770,7 @@ export class DefaultConfig implements Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
structureMinDist(): number {
|
structureMinDist(): number {
|
||||||
// TODO: Increase this to ~15 once upgradable structures are implemented.
|
return 15;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shellLifetime(): number {
|
shellLifetime(): number {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
|
|||||||
import { SpawnExecution } from "./SpawnExecution";
|
import { SpawnExecution } from "./SpawnExecution";
|
||||||
import { TargetPlayerExecution } from "./TargetPlayerExecution";
|
import { TargetPlayerExecution } from "./TargetPlayerExecution";
|
||||||
import { TransportShipExecution } from "./TransportShipExecution";
|
import { TransportShipExecution } from "./TransportShipExecution";
|
||||||
|
import { UpgradeStructureExecution } from "./UpgradeStructureExecution";
|
||||||
|
|
||||||
export class Executor {
|
export class Executor {
|
||||||
// private random = new PseudoRandom(999)
|
// private random = new PseudoRandom(999)
|
||||||
@@ -114,6 +115,8 @@ export class Executor {
|
|||||||
this.mg.ref(intent.x, intent.y),
|
this.mg.ref(intent.x, intent.y),
|
||||||
intent.unit,
|
intent.unit,
|
||||||
);
|
);
|
||||||
|
case "upgrade_structure":
|
||||||
|
return new UpgradeStructureExecution(player, intent.unitId);
|
||||||
case "quick_chat":
|
case "quick_chat":
|
||||||
return new QuickChatExecution(
|
return new QuickChatExecution(
|
||||||
player,
|
player,
|
||||||
|
|||||||
@@ -34,10 +34,20 @@ export class MissileSiloExecution implements Execution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cooldown = this.silo.ticksLeftInCooldown();
|
const frontTime = this.silo.ticksLeftInCooldown();
|
||||||
|
if (frontTime === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cooldown =
|
||||||
|
this.mg.config().SiloCooldown() - (this.mg.ticks() - frontTime);
|
||||||
if (typeof cooldown === "number" && cooldown >= 0) {
|
if (typeof cooldown === "number" && cooldown >= 0) {
|
||||||
this.silo.touch();
|
this.silo.touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cooldown <= 0) {
|
||||||
|
this.silo.reloadMissile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive(): boolean {
|
isActive(): boolean {
|
||||||
|
|||||||
@@ -155,11 +155,6 @@ export class SAMLauncherExecution implements Execution {
|
|||||||
target = this.getSingleTarget();
|
target = this.getSingleTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
const cooldown = this.sam.ticksLeftInCooldown();
|
|
||||||
if (typeof cooldown === "number" && cooldown >= 0) {
|
|
||||||
this.sam.touch();
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSingleTarget = target && !target.targetedBySAM();
|
const isSingleTarget = target && !target.targetedBySAM();
|
||||||
if (
|
if (
|
||||||
(isSingleTarget || mirvWarheadTargets.length > 0) &&
|
(isSingleTarget || mirvWarheadTargets.length > 0) &&
|
||||||
@@ -204,6 +199,21 @@ export class SAMLauncherExecution implements Execution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const frontTime = this.sam.ticksLeftInCooldown();
|
||||||
|
if (frontTime === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cooldown =
|
||||||
|
this.mg.config().SAMCooldown() - (this.mg.ticks() - frontTime);
|
||||||
|
if (typeof cooldown === "number" && cooldown >= 0) {
|
||||||
|
this.sam.touch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cooldown <= 0) {
|
||||||
|
this.sam.reloadMissile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive(): boolean {
|
isActive(): boolean {
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -130,6 +130,7 @@ export interface UnitInfo {
|
|||||||
maxHealth?: number;
|
maxHealth?: number;
|
||||||
damage?: number;
|
damage?: number;
|
||||||
constructionDuration?: number;
|
constructionDuration?: number;
|
||||||
|
upgradable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UnitType {
|
export enum UnitType {
|
||||||
@@ -385,8 +386,9 @@ export interface Unit {
|
|||||||
|
|
||||||
// SAMs & Missile Silos
|
// SAMs & Missile Silos
|
||||||
launch(): void;
|
launch(): void;
|
||||||
ticksLeftInCooldown(): Tick | undefined;
|
reloadMissile(): void;
|
||||||
isInCooldown(): boolean;
|
isInCooldown(): boolean;
|
||||||
|
ticksLeftInCooldown(): Tick | undefined;
|
||||||
|
|
||||||
// Trade Ships
|
// Trade Ships
|
||||||
setSafeFromPirates(): void; // Only for trade ships
|
setSafeFromPirates(): void; // Only for trade ships
|
||||||
@@ -396,6 +398,10 @@ export interface Unit {
|
|||||||
constructionType(): UnitType | null;
|
constructionType(): UnitType | null;
|
||||||
setConstructionType(type: UnitType): void;
|
setConstructionType(type: UnitType): void;
|
||||||
|
|
||||||
|
// Upgradable Structures
|
||||||
|
level(): number;
|
||||||
|
increaseLevel(): void;
|
||||||
|
|
||||||
// Warships
|
// Warships
|
||||||
setPatrolTile(tile: TileRef): void;
|
setPatrolTile(tile: TileRef): void;
|
||||||
patrolTile(): TileRef | undefined;
|
patrolTile(): TileRef | undefined;
|
||||||
@@ -471,6 +477,7 @@ export interface Player {
|
|||||||
spawnTile: TileRef,
|
spawnTile: TileRef,
|
||||||
params: UnitParams<T>,
|
params: UnitParams<T>,
|
||||||
): Unit;
|
): Unit;
|
||||||
|
upgradeUnit(unit: Unit): void;
|
||||||
|
|
||||||
captureUnit(unit: Unit): void;
|
captureUnit(unit: Unit): void;
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ export interface UnitUpdate {
|
|||||||
targetTile?: TileRef; // Only for nukes
|
targetTile?: TileRef; // Only for nukes
|
||||||
health?: number;
|
health?: number;
|
||||||
constructionType?: UnitType;
|
constructionType?: UnitType;
|
||||||
ticksLeftInCooldown?: Tick;
|
missileTimerQueue: number[];
|
||||||
|
readyMissileCount: number;
|
||||||
|
level: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AttackUpdate {
|
export interface AttackUpdate {
|
||||||
|
|||||||
@@ -112,11 +112,13 @@ export class UnitView {
|
|||||||
return this.data.targetTile;
|
return this.data.targetTile;
|
||||||
}
|
}
|
||||||
ticksLeftInCooldown(): Tick | undefined {
|
ticksLeftInCooldown(): Tick | undefined {
|
||||||
return this.data.ticksLeftInCooldown;
|
return this.data.missileTimerQueue?.[0];
|
||||||
}
|
}
|
||||||
isCooldown(): boolean {
|
isInCooldown(): boolean {
|
||||||
if (this.data.ticksLeftInCooldown === undefined) return false;
|
return this.data.readyMissileCount === 0;
|
||||||
return this.data.ticksLeftInCooldown > 0;
|
}
|
||||||
|
level(): number {
|
||||||
|
return this.data.level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -754,6 +754,12 @@ export class PlayerImpl implements Player {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upgradeUnit(unit: Unit) {
|
||||||
|
const cost = this.mg.unitInfo(unit.type()).cost(this);
|
||||||
|
this.removeGold(cost);
|
||||||
|
unit.increaseLevel();
|
||||||
|
}
|
||||||
|
|
||||||
public buildableUnits(tile: TileRef): BuildableUnit[] {
|
public buildableUnits(tile: TileRef): BuildableUnit[] {
|
||||||
const validTiles = this.validStructureSpawnTiles(tile);
|
const validTiles = this.validStructureSpawnTiles(tile);
|
||||||
return Object.values(UnitType).map((u) => {
|
return Object.values(UnitType).map((u) => {
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ export interface Stats {
|
|||||||
// Player captures a unit of type
|
// Player captures a unit of type
|
||||||
unitCapture(player: Player, type: OtherUnitType): void;
|
unitCapture(player: Player, type: OtherUnitType): void;
|
||||||
|
|
||||||
|
// Player upgrades a unit of type
|
||||||
|
unitUpgrade(player: Player, type: OtherUnitType): void;
|
||||||
|
|
||||||
// Player destroys a unit of type
|
// Player destroys a unit of type
|
||||||
unitDestroy(player: Player, type: OtherUnitType): void;
|
unitDestroy(player: Player, type: OtherUnitType): void;
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
OTHER_INDEX_CAPTURE,
|
OTHER_INDEX_CAPTURE,
|
||||||
OTHER_INDEX_DESTROY,
|
OTHER_INDEX_DESTROY,
|
||||||
OTHER_INDEX_LOST,
|
OTHER_INDEX_LOST,
|
||||||
|
OTHER_INDEX_UPGRADE,
|
||||||
OtherUnitType,
|
OtherUnitType,
|
||||||
PlayerStats,
|
PlayerStats,
|
||||||
unitTypeToBombUnit,
|
unitTypeToBombUnit,
|
||||||
@@ -234,6 +235,10 @@ export class StatsImpl implements Stats {
|
|||||||
this._addOtherUnit(player, type, OTHER_INDEX_CAPTURE, 1);
|
this._addOtherUnit(player, type, OTHER_INDEX_CAPTURE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unitUpgrade(player: Player, type: OtherUnitType): void {
|
||||||
|
this._addOtherUnit(player, type, OTHER_INDEX_UPGRADE, 1);
|
||||||
|
}
|
||||||
|
|
||||||
unitDestroy(player: Player, type: OtherUnitType): void {
|
unitDestroy(player: Player, type: OtherUnitType): void {
|
||||||
this._addOtherUnit(player, type, OTHER_INDEX_DESTROY, 1);
|
this._addOtherUnit(player, type, OTHER_INDEX_DESTROY, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-19
@@ -26,8 +26,10 @@ export class UnitImpl implements Unit {
|
|||||||
private _constructionType: UnitType | undefined;
|
private _constructionType: UnitType | undefined;
|
||||||
private _lastOwner: PlayerImpl | null = null;
|
private _lastOwner: PlayerImpl | null = null;
|
||||||
private _troops: number;
|
private _troops: number;
|
||||||
private _cooldownStartTick: Tick | null = null;
|
private _missileTimerQueue: number[] = [];
|
||||||
|
private _readyMissileCount: number = 1;
|
||||||
private _patrolTile: TileRef | undefined;
|
private _patrolTile: TileRef | undefined;
|
||||||
|
private _level: number = 1;
|
||||||
constructor(
|
constructor(
|
||||||
private _type: UnitType,
|
private _type: UnitType,
|
||||||
private mg: GameImpl,
|
private mg: GameImpl,
|
||||||
@@ -104,7 +106,9 @@ export class UnitImpl implements Unit {
|
|||||||
constructionType: this._constructionType,
|
constructionType: this._constructionType,
|
||||||
targetUnitId: this._targetUnit?.id() ?? undefined,
|
targetUnitId: this._targetUnit?.id() ?? undefined,
|
||||||
targetTile: this.targetTile() ?? undefined,
|
targetTile: this.targetTile() ?? undefined,
|
||||||
ticksLeftInCooldown: this.ticksLeftInCooldown() ?? undefined,
|
missileTimerQueue: this._missileTimerQueue,
|
||||||
|
readyMissileCount: this._readyMissileCount,
|
||||||
|
level: this.level(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,30 +271,23 @@ export class UnitImpl implements Unit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
launch(): void {
|
launch(): void {
|
||||||
this._cooldownStartTick = this.mg.ticks();
|
this._missileTimerQueue.push(this.mg.ticks());
|
||||||
|
this._readyMissileCount--;
|
||||||
this.mg.addUpdate(this.toUpdate());
|
this.mg.addUpdate(this.toUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
ticksLeftInCooldown(): Tick | undefined {
|
ticksLeftInCooldown(): Tick | undefined {
|
||||||
let cooldownDuration = 0;
|
return this._missileTimerQueue[0];
|
||||||
if (this.type() === UnitType.SAMLauncher) {
|
|
||||||
cooldownDuration = this.mg.config().SAMCooldown();
|
|
||||||
} else if (this.type() === UnitType.MissileSilo) {
|
|
||||||
cooldownDuration = this.mg.config().SiloCooldown();
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this._cooldownStartTick) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cooldownDuration - (this.mg.ticks() - this._cooldownStartTick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isInCooldown(): boolean {
|
isInCooldown(): boolean {
|
||||||
const ticksLeft = this.ticksLeftInCooldown();
|
return this._readyMissileCount === 0;
|
||||||
return ticksLeft !== undefined && ticksLeft > 0;
|
}
|
||||||
|
|
||||||
|
reloadMissile(): void {
|
||||||
|
this._missileTimerQueue.shift();
|
||||||
|
this._readyMissileCount++;
|
||||||
|
this.mg.addUpdate(this.toUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
setTargetTile(targetTile: TileRef | undefined) {
|
setTargetTile(targetTile: TileRef | undefined) {
|
||||||
@@ -335,4 +332,16 @@ export class UnitImpl implements Unit {
|
|||||||
this.mg.config().safeFromPiratesCooldownMax()
|
this.mg.config().safeFromPiratesCooldownMax()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
level(): number {
|
||||||
|
return this._level;
|
||||||
|
}
|
||||||
|
|
||||||
|
increaseLevel(): void {
|
||||||
|
this._level++;
|
||||||
|
if ([UnitType.MissileSilo, UnitType.SAMLauncher].includes(this.type())) {
|
||||||
|
this._readyMissileCount++;
|
||||||
|
}
|
||||||
|
this.mg.addUpdate(this.toUpdate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
||||||
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
||||||
|
import { UpgradeStructureExecution } from "../src/core/execution/UpgradeStructureExecution";
|
||||||
import {
|
import {
|
||||||
Game,
|
Game,
|
||||||
Player,
|
Player,
|
||||||
@@ -9,7 +10,7 @@ import {
|
|||||||
} from "../src/core/game/Game";
|
} from "../src/core/game/Game";
|
||||||
import { TileRef } from "../src/core/game/GameMap";
|
import { TileRef } from "../src/core/game/GameMap";
|
||||||
import { setup } from "./util/Setup";
|
import { setup } from "./util/Setup";
|
||||||
import { constructionExecution } from "./util/utils";
|
import { constructionExecution, executeTicks } from "./util/utils";
|
||||||
|
|
||||||
let game: Game;
|
let game: Game;
|
||||||
let attacker: Player;
|
let attacker: Player;
|
||||||
@@ -85,7 +86,21 @@ describe("MissileSilo", () => {
|
|||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
}
|
}
|
||||||
|
|
||||||
game.executeNextTick();
|
executeTicks(game, 2);
|
||||||
|
|
||||||
expect(attacker.units(UnitType.MissileSilo)[0].isInCooldown()).toBeFalsy();
|
expect(attacker.units(UnitType.MissileSilo)[0].isInCooldown()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("missilesilo should have increased level after upgrade", async () => {
|
||||||
|
expect(attacker.units(UnitType.MissileSilo)[0].level()).toEqual(1);
|
||||||
|
|
||||||
|
const upgradeStructureExecution = new UpgradeStructureExecution(
|
||||||
|
attacker,
|
||||||
|
attacker.units(UnitType.MissileSilo)[0].id(),
|
||||||
|
);
|
||||||
|
game.addExecution(upgradeStructureExecution);
|
||||||
|
executeTicks(game, 2);
|
||||||
|
|
||||||
|
expect(attacker.units(UnitType.MissileSilo)[0].level()).toEqual(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
||||||
import { SAMLauncherExecution } from "../src/core/execution/SAMLauncherExecution";
|
import { SAMLauncherExecution } from "../src/core/execution/SAMLauncherExecution";
|
||||||
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
||||||
|
import { UpgradeStructureExecution } from "../src/core/execution/UpgradeStructureExecution";
|
||||||
import {
|
import {
|
||||||
Game,
|
Game,
|
||||||
Player,
|
Player,
|
||||||
@@ -94,6 +95,7 @@ describe("SAM", () => {
|
|||||||
|
|
||||||
test("sam should cooldown as long as configured", async () => {
|
test("sam should cooldown as long as configured", async () => {
|
||||||
const sam = defender.buildUnit(UnitType.SAMLauncher, game.ref(1, 1), {});
|
const sam = defender.buildUnit(UnitType.SAMLauncher, game.ref(1, 1), {});
|
||||||
|
|
||||||
game.addExecution(new SAMLauncherExecution(defender, null, sam));
|
game.addExecution(new SAMLauncherExecution(defender, null, sam));
|
||||||
expect(sam.isInCooldown()).toBeFalsy();
|
expect(sam.isInCooldown()).toBeFalsy();
|
||||||
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 2), {
|
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 2), {
|
||||||
@@ -103,6 +105,7 @@ describe("SAM", () => {
|
|||||||
executeTicks(game, 3);
|
executeTicks(game, 3);
|
||||||
|
|
||||||
expect(nuke.isActive()).toBeFalsy();
|
expect(nuke.isActive()).toBeFalsy();
|
||||||
|
|
||||||
for (let i = 0; i < game.config().SAMCooldown() - 3; i++) {
|
for (let i = 0; i < game.config().SAMCooldown() - 3; i++) {
|
||||||
game.executeNextTick();
|
game.executeNextTick();
|
||||||
expect(sam.isInCooldown()).toBeTruthy();
|
expect(sam.isInCooldown()).toBeTruthy();
|
||||||
@@ -161,4 +164,18 @@ describe("SAM", () => {
|
|||||||
expect(sam1.isInCooldown()).toBeFalsy();
|
expect(sam1.isInCooldown()).toBeFalsy();
|
||||||
expect(sam2.isInCooldown()).toBeTruthy();
|
expect(sam2.isInCooldown()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("SAM should have increased level after upgrade", async () => {
|
||||||
|
defender.buildUnit(UnitType.SAMLauncher, game.ref(1, 1), {});
|
||||||
|
expect(defender.units(UnitType.SAMLauncher)[0].level()).toEqual(1);
|
||||||
|
|
||||||
|
const upgradeStructureExecution = new UpgradeStructureExecution(
|
||||||
|
defender,
|
||||||
|
defender.units(UnitType.SAMLauncher)[0].id(),
|
||||||
|
);
|
||||||
|
game.addExecution(upgradeStructureExecution);
|
||||||
|
executeTicks(game, 2);
|
||||||
|
|
||||||
|
expect(defender.units(UnitType.SAMLauncher)[0].level()).toEqual(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user