-
Notifications
You must be signed in to change notification settings - Fork 707
Configurable ceasefire time #2460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bfd6741
be6a1e6
b777bcf
8f999ac
eb5d5bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| 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("ceasefire-timer") | ||
| export class CeasefireTimer 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 ceasefireDuration = this.game.config().spawnImmunityDuration(); | ||
| const spawnPhaseTurns = this.game.config().numSpawnPhaseTurns(); | ||
|
|
||
| if (ceasefireDuration <= 5 * 10 || this.game.inSpawnPhase()) { | ||
| this.setInactive(); | ||
| return; | ||
| } | ||
|
|
||
| const ceasefireEnd = spawnPhaseTurns + ceasefireDuration; | ||
| const ticks = this.game.ticks(); | ||
|
|
||
| if (ticks >= ceasefireEnd || ticks < spawnPhaseTurns) { | ||
| this.setInactive(); | ||
| return; | ||
| } | ||
|
|
||
| const elapsedTicks = Math.max(0, ticks - spawnPhaseTurns); | ||
| this.progressRatio = Math.min( | ||
| 1, | ||
| Math.max(0, elapsedTicks / ceasefireDuration), | ||
| ); | ||
| 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> | ||
| `; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,9 @@ export const GameConfigSchema = z.object({ | |
| randomSpawn: z.boolean(), | ||
| maxPlayers: z.number().optional(), | ||
| maxTimerValue: z.number().int().min(1).max(120).optional(), | ||
| // startingGold: z.number().int().min(0).max(10*1000*1000), // maybe in steps instead? good way of setting max? default 0? | ||
| // incomeMultiplier: z.number().min(0).max(10), | ||
|
Comment on lines
+173
to
+174
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove these comments |
||
| spawnImmunityDuration: z.number().int().min(0).max(3000), // In ticks (10 per second) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make optional, do we need a max? |
||
| disabledUnits: z.enum(UnitType).array().optional(), | ||
| playerTeams: TeamCountConfigSchema.optional(), | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,10 +91,12 @@ export class AttackExecution implements Execution { | |
| } | ||
|
|
||
| if (this.target.isPlayer()) { | ||
| const targetPlayer = this.target as Player; | ||
| if ( | ||
| targetPlayer.type() === PlayerType.Human && | ||
| this.mg.config().numSpawnPhaseTurns() + | ||
| this.mg.config().spawnImmunityDuration() > | ||
| this.mg.ticks() | ||
| this.mg.ticks() | ||
|
Comment on lines
93
to
+99
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead i think we should do: if(!this.player.canAttack(targetPlayer) { |
||
| ) { | ||
| console.warn("cannot attack player during immunity phase"); | ||
| this.active = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| MessageType, | ||
| Player, | ||
| PlayerID, | ||
| PlayerType, | ||
| TerraNullius, | ||
| Unit, | ||
| UnitType, | ||
|
|
@@ -94,6 +95,19 @@ export class TransportShipExecution implements Execution { | |
| this.target = mg.player(this.targetID); | ||
| } | ||
|
|
||
| if ( | ||
| this.target.isPlayer() && | ||
| this.mg.config().numSpawnPhaseTurns() + | ||
| this.mg.config().spawnImmunityDuration() > | ||
| this.mg.ticks() | ||
| ) { | ||
| const targetPlayer = this.target as Player; | ||
| if (targetPlayer.type() === PlayerType.Human) { | ||
| this.active = false; | ||
| return; | ||
| } | ||
| } | ||
|
Comment on lines
+98
to
+109
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, use canAttack. so we keep all the logic in one place |
||
|
|
||
| this.startTroops ??= this.mg | ||
| .config() | ||
| .boatAttackAmount(this.attacker, this.target); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,15 +61,20 @@ export class WarshipExecution implements Execution { | |
| this.warship.modifyHealth(1); | ||
| } | ||
|
|
||
| this.warship.setTargetUnit(this.findTargetUnit()); | ||
| if (this.warship.targetUnit()?.type() === UnitType.TradeShip) { | ||
| this.huntDownTradeShip(); | ||
| return; | ||
| const spawnImmunityActive = this.isSpawnImmunityActive(); | ||
| if (spawnImmunityActive) { | ||
| this.warship.setTargetUnit(undefined); | ||
| } else { | ||
| this.warship.setTargetUnit(this.findTargetUnit()); | ||
| if (this.warship.targetUnit()?.type() === UnitType.TradeShip) { | ||
| this.huntDownTradeShip(); | ||
| return; | ||
| } | ||
|
Comment on lines
+64
to
+72
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, we should be using canAttack
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the current implementation, warships are completely passive, even in regards to warships / transports from nations, but attacking nations is possible. if we move the check into canAttack for warships, that changes. fine for me if that's what we want, pls confirm |
||
| } | ||
|
|
||
| this.patrol(); | ||
|
|
||
| if (this.warship.targetUnit() !== undefined) { | ||
| if (!spawnImmunityActive && this.warship.targetUnit() !== undefined) { | ||
| this.shootTarget(); | ||
| return; | ||
| } | ||
|
|
@@ -279,4 +284,12 @@ export class WarshipExecution implements Execution { | |
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| private isSpawnImmunityActive(): boolean { | ||
| return ( | ||
| this.mg.config().numSpawnPhaseTurns() + | ||
| this.mg.config().spawnImmunityDuration() > | ||
| this.mg.ticks() | ||
| ); | ||
| } | ||
|
Comment on lines
+288
to
+294
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be moved to Game i think. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this have a checkbox, like game timer?
also i think minutes is a better unit than seconds
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the issue with that is that it would be checked by default, and might be confusing to users a little bit because the 5 sec spawn immunity was not exposed in any UI previously
in the follow up PR for the other options, the card in the host modal is changed to have a slider

if the slider is kept, a max value or individiual step sizes are required. or i revert to number input and go for minutes, your call