From 92efe4be9115e6410494ecc6681a3b6debb21c0d Mon Sep 17 00:00:00 2001 From: aymericdelab Date: Wed, 11 Dec 2024 14:53:06 +0100 Subject: [PATCH] min troops --- client/src/dojo/modelManager/BattleManager.ts | 20 ++++++++++++++++++- .../military/battle-view/BattleActions.tsx | 13 +++++++++--- sdk/packages/eternum/src/constants/global.ts | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/client/src/dojo/modelManager/BattleManager.ts b/client/src/dojo/modelManager/BattleManager.ts index 4c3b75851..34bd883aa 100644 --- a/client/src/dojo/modelManager/BattleManager.ts +++ b/client/src/dojo/modelManager/BattleManager.ts @@ -3,7 +3,7 @@ import { ArmyInfo } from "@/hooks/helpers/useArmies"; import { Structure } from "@/hooks/helpers/useStructures"; import { Health } from "@/types"; import { multiplyByPrecision } from "@/ui/utils/utils"; -import { BattleSide, EternumGlobalConfig, ID } from "@bibliothecadao/eternum"; +import { BattleSide, EternumGlobalConfig, ID, MIN_TROOPS_BATTLE } from "@bibliothecadao/eternum"; import { ComponentValue, Components, @@ -38,6 +38,7 @@ export enum RaidStatus { OwnStructure = "Can't raid your own structure", NoArmy = "No army selected", ArmyNotInBattle = "Selected army not in this battle", + MinTroops = "Minimum 100 troops required", } export enum LeaveStatus { @@ -48,6 +49,7 @@ export enum LeaveStatus { } export enum BattleStartStatus { + MinTroops = "Minimum 100 troops required", BattleStart = "Start battle", ForceStart = "Force start", NothingToAttack = "Nothing to attack", @@ -312,6 +314,13 @@ export class BattleManager { if (structure.isMine) return RaidStatus.OwnStructure; + // Calculate total troops + const totalTroops = selectedArmy.troops + ? Object.values(selectedArmy.troops).reduce((sum, count) => sum + Number(count), 0) + : 0; + + if (totalTroops < MIN_TROOPS_BATTLE) return RaidStatus.MinTroops; + const staminaManager = new StaminaManager(this.dojo.setup, selectedArmy.entity_id); if (staminaManager.getStamina(currentArmiesTick).amount === 0) return RaidStatus.NoStamina; @@ -323,6 +332,15 @@ export class BattleManager { defender: ArmyInfo | undefined, currentTimestamp: number, ): BattleStartStatus { + if (!selectedArmy) return BattleStartStatus.NothingToAttack; + + // Calculate total troops + const totalTroops = selectedArmy.troops + ? Object.values(selectedArmy.troops).reduce((sum, count) => sum + Number(count), 0) + : 0; + + if (totalTroops < MIN_TROOPS_BATTLE) return BattleStartStatus.MinTroops; + if (!defender) return BattleStartStatus.NothingToAttack; if (!this.isBattle() && defender.health.current > 0n) return BattleStartStatus.BattleStart; diff --git a/client/src/ui/modules/military/battle-view/BattleActions.tsx b/client/src/ui/modules/military/battle-view/BattleActions.tsx index 4acc8eb3b..1e9a87ff1 100644 --- a/client/src/ui/modules/military/battle-view/BattleActions.tsx +++ b/client/src/ui/modules/military/battle-view/BattleActions.tsx @@ -248,9 +248,16 @@ export const BattleActions = ({ ]; if (raidStatus !== RaidStatus.isRaidable) { - setTooltip({ content:
{raidStatus}
, position: "top" }); - } else if (selectedArmy?.battle_id !== 0) { - content.push(
Raiding will make you leave and lose 25% of your army
); + setTooltip({ content:
{raidStatus}
, position: "top" }); + return; + } + + if (selectedArmy?.battle_id !== 0) { + content.push( +
+ Raiding will make you leave and lose 25% of your army +
, + ); } setTooltip({ diff --git a/sdk/packages/eternum/src/constants/global.ts b/sdk/packages/eternum/src/constants/global.ts index 6ee8d4d17..3a7721bfe 100644 --- a/sdk/packages/eternum/src/constants/global.ts +++ b/sdk/packages/eternum/src/constants/global.ts @@ -14,6 +14,7 @@ import { TROOPS_FOOD_CONSUMPTION, TROOPS_STAMINAS } from "./troops"; import { ResourcesIds } from "."; +export const MIN_TROOPS_BATTLE = 100_000; export const FELT_CENTER = 2147483646; export const WORLD_CONFIG_ID = 999999999n; export const HYPERSTRUCTURE_CONFIG_ID = 999999992n;