mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:30:43 +00:00
64e8733132
## Description: - Move the Delete button to where the Boat button is otherwise. The Boat and Delete button already mutually exclude eachother anyway; boat button is only visible on other's tiles, delete button is only visible on your own tiles. Evan agreed to this new position: https://discord.com/channels/1359946986937258015/1381293863712591872/1429147325049077860 - Increase the cooldown between deletions from 5 to 15 seconds. PR #2216 introduced a destruction time (deletionMarkDuration) making it take 15s to delete a building. With the cooldown of 15s between clicking the Delete button (deleteUnitCooldown) on top of that, you can actually only delete a building every 15 seconds while it also takes that same time to destruct it. Players have voiced between 10s to 30s or more so 15s is still a reasonable time, keeping deletion of mistakenly placed buildings still possible, while also keeping a small 'scorched earth' option during an attack but probably only being able to delete 1-2 units in an attack. Evan and Vivacious Box agreed with the mentioned 10-15s cooldown too: https://discord.com/channels/1359946986937258015/1381293863712591872/1429103999088459897 **Video: Delete button new location and 15s cooldown:** https://github.com/user-attachments/assets/b0b13fc1-1e50-4a7a-8f32-55f7891f9945 **Delete button new location disabled:** <img width="310" height="316" alt="Delete button disabled new location radial menu" src="https://github.com/user-attachments/assets/f65b88ad-5859-4982-be53-8f2f693f5767" /> **Delete button new location enabled:** <img width="332" height="305" alt="Delete button enabled new location radial menu" src="https://github.com/user-attachments/assets/037f07c5-622a-4857-9ab8-fc20981de816" /> **Radial menu unchanged on others' tiles:** <img width="346" height="307" alt="Radial menu unchanged on other territory" src="https://github.com/user-attachments/assets/085b2043-096f-4c44-8917-467adb8a7213" /> ## 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: tryout33 --------- Co-authored-by: Vivacious Box <jon@rouillard.org>
146 lines
4.3 KiB
TypeScript
146 lines
4.3 KiB
TypeScript
import { DeleteUnitExecution } from "../src/core/execution/DeleteUnitExecution";
|
|
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
|
import {
|
|
Game,
|
|
Player,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
Unit,
|
|
UnitType,
|
|
} from "../src/core/game/Game";
|
|
import { TileRef } from "../src/core/game/GameMap";
|
|
import { setup } from "./util/Setup";
|
|
import { executeTicks } from "./util/utils";
|
|
|
|
describe("DeleteUnitExecution Security Tests", () => {
|
|
let game: Game;
|
|
let player: Player;
|
|
let enemyPlayer: Player;
|
|
let unit: Unit;
|
|
|
|
beforeEach(async () => {
|
|
game = await setup("plains", {
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
infiniteTroops: true,
|
|
});
|
|
|
|
const player1Info = new PlayerInfo(
|
|
"TestPlayer",
|
|
PlayerType.Human,
|
|
null,
|
|
"TestPlayer",
|
|
);
|
|
const player2Info = new PlayerInfo(
|
|
"EnemyPlayer",
|
|
PlayerType.Human,
|
|
null,
|
|
"EnemyPlayer",
|
|
);
|
|
|
|
game.addPlayer(player1Info);
|
|
game.addPlayer(player2Info);
|
|
|
|
const playerSpawn: TileRef = game.ref(0, 10);
|
|
const enemySpawn: TileRef = game.ref(0, 15);
|
|
|
|
game.addExecution(
|
|
new SpawnExecution(game.player(player1Info.id).info(), playerSpawn),
|
|
new SpawnExecution(game.player(player2Info.id).info(), enemySpawn),
|
|
);
|
|
|
|
while (game.inSpawnPhase()) {
|
|
game.executeNextTick();
|
|
}
|
|
|
|
executeTicks(game, game.config().deleteUnitCooldown() + 1);
|
|
|
|
player = game.player(player1Info.id);
|
|
enemyPlayer = game.player(player2Info.id);
|
|
|
|
const playerTiles = Array.from(player.tiles());
|
|
if (playerTiles.length === 0) {
|
|
throw new Error("Player has no tiles");
|
|
}
|
|
const spawnTile = playerTiles[0];
|
|
unit = player.buildUnit(UnitType.City, spawnTile, {});
|
|
|
|
const tileOwner = game.owner(unit.tile());
|
|
if (!tileOwner.isPlayer() || tileOwner.id() !== player.id()) {
|
|
throw new Error("Unit is not on player's territory");
|
|
}
|
|
});
|
|
|
|
describe("Security Validations", () => {
|
|
it("should prevent deleting units not owned by player", () => {
|
|
const enemyUnit = enemyPlayer.buildUnit(
|
|
UnitType.City,
|
|
Array.from(enemyPlayer.tiles())[0],
|
|
{},
|
|
);
|
|
const execution = new DeleteUnitExecution(player, enemyUnit.id());
|
|
execution.init(game, 0);
|
|
|
|
expect(execution.isActive()).toBe(false);
|
|
expect(enemyUnit.isMarkedForDeletion()).toBe(false);
|
|
});
|
|
|
|
it("should prevent deleting units on enemy territory", () => {
|
|
const enemyTiles = Array.from(enemyPlayer.tiles());
|
|
if (enemyTiles.length > 0) {
|
|
unit.move(enemyTiles[0]);
|
|
|
|
const execution = new DeleteUnitExecution(player, unit.id());
|
|
execution.init(game, 0);
|
|
|
|
expect(execution.isActive()).toBe(false);
|
|
expect(unit.isMarkedForDeletion()).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("should prevent deleting units during spawn phase", () => {
|
|
jest.spyOn(game, "inSpawnPhase").mockReturnValue(true);
|
|
|
|
const execution = new DeleteUnitExecution(player, unit.id());
|
|
execution.init(game, 0);
|
|
|
|
expect(execution.isActive()).toBe(false);
|
|
expect(unit.isMarkedForDeletion()).toBe(false);
|
|
});
|
|
|
|
it("should allow deleting units when all conditions are met", () => {
|
|
jest.spyOn(game, "inSpawnPhase").mockReturnValue(false);
|
|
|
|
const execution = new DeleteUnitExecution(player, unit.id());
|
|
execution.init(game, 0);
|
|
|
|
expect(unit.isMarkedForDeletion()).toBe(true);
|
|
});
|
|
|
|
it("should delete after deletion delay", () => {
|
|
jest.spyOn(game, "inSpawnPhase").mockReturnValue(false);
|
|
|
|
const execution = new DeleteUnitExecution(player, unit.id());
|
|
game.addExecution(execution);
|
|
|
|
game.executeNextTick();
|
|
expect(unit.isMarkedForDeletion()).toBe(true);
|
|
expect(unit.isOverdueDeletion()).toBe(false);
|
|
executeTicks(game, game.config().deletionMarkDuration() + 1);
|
|
expect(unit.isActive()).toBe(false);
|
|
});
|
|
|
|
it("should reset deletion if captured", () => {
|
|
jest.spyOn(game, "inSpawnPhase").mockReturnValue(false);
|
|
|
|
const execution = new DeleteUnitExecution(player, unit.id());
|
|
game.addExecution(execution);
|
|
game.executeNextTick();
|
|
expect(unit.isMarkedForDeletion()).toBe(true);
|
|
unit.setOwner(enemyPlayer);
|
|
expect(unit.isMarkedForDeletion()).toBe(false);
|
|
expect(unit.isActive()).toBe(true);
|
|
});
|
|
});
|
|
});
|