mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 11:53:29 +00:00
6cc0ef7d14
## Description: Adds 30 seconds of PVP immunity to 5M starting gold modifier games. So you cannot insta-nuke other players. Because I'm sure people would be confused "I cannot attack!!!!" I added a HeadsUpMessage which informs about the PVP immunity. We already have a ImmunityTimer progress bar but I don't think its enough. <img width="1270" height="745" alt="image" src="https://github.com/user-attachments/assets/0ee23dc4-1c7b-4d62-8b3d-8de214f03c2b" /> I had a second count in the HeadsUpMessage (seconds until PVP immunity is over) but it felt too busy. So I removed it. You can tell when PVP immunity is over by looking at the progress bar. ## 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: FloPinguin --------- Co-authored-by: Evan <evanpelle@gmail.com>
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement } from "lit/decorators.js";
|
|
import { GameMode } from "../../../core/game/Game";
|
|
import { GameView } from "../../../core/game/GameView";
|
|
import { Layer } from "./Layer";
|
|
|
|
@customElement("immunity-timer")
|
|
export class ImmunityTimer extends LitElement implements Layer {
|
|
public game: GameView;
|
|
|
|
private isVisible = false;
|
|
private isActive = false;
|
|
private progressRatio = 0;
|
|
|
|
createRenderRoot() {
|
|
this.style.position = "fixed";
|
|
this.style.top = "0";
|
|
this.style.left = "0";
|
|
this.style.width = "100%";
|
|
this.style.height = "7px";
|
|
this.style.zIndex = "1000";
|
|
this.style.pointerEvents = "none";
|
|
return this;
|
|
}
|
|
|
|
init() {
|
|
this.isVisible = true;
|
|
}
|
|
|
|
tick() {
|
|
if (!this.game || !this.isVisible) {
|
|
return;
|
|
}
|
|
|
|
const showTeamOwnershipBar =
|
|
this.game.config().gameConfig().gameMode === GameMode.Team &&
|
|
!this.game.inSpawnPhase();
|
|
|
|
this.style.top = showTeamOwnershipBar ? "7px" : "0px";
|
|
|
|
const immunityDuration = this.game.config().spawnImmunityDuration();
|
|
const spawnPhaseTurns = this.game.config().numSpawnPhaseTurns();
|
|
|
|
if (
|
|
!this.game.config().hasExtendedSpawnImmunity() ||
|
|
this.game.inSpawnPhase()
|
|
) {
|
|
this.setInactive();
|
|
return;
|
|
}
|
|
|
|
const immunityEnd = spawnPhaseTurns + immunityDuration;
|
|
const ticks = this.game.ticks();
|
|
|
|
if (ticks >= immunityEnd || ticks < spawnPhaseTurns) {
|
|
this.setInactive();
|
|
return;
|
|
}
|
|
|
|
const elapsedTicks = Math.max(0, ticks - spawnPhaseTurns);
|
|
this.progressRatio = Math.min(
|
|
1,
|
|
Math.max(0, elapsedTicks / immunityDuration),
|
|
);
|
|
this.isActive = true;
|
|
this.requestUpdate();
|
|
}
|
|
|
|
private setInactive() {
|
|
if (this.isActive) {
|
|
this.isActive = false;
|
|
this.requestUpdate();
|
|
}
|
|
}
|
|
|
|
shouldTransform(): boolean {
|
|
return false;
|
|
}
|
|
|
|
render() {
|
|
if (!this.isVisible || !this.isActive) {
|
|
return html``;
|
|
}
|
|
|
|
const widthPercent = this.progressRatio * 100;
|
|
|
|
return html`
|
|
<div class="w-full h-full flex z-999">
|
|
<div
|
|
class="h-full transition-all duration-100 ease-in-out"
|
|
style="width: ${widthPercent}%; background-color: rgba(255, 165, 0, 0.9);"
|
|
></div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|