Skip to content

Commit

Permalink
min troops
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Dec 11, 2024
1 parent d2c70a7 commit 92efe4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
20 changes: 19 additions & 1 deletion client/src/dojo/modelManager/BattleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions client/src/ui/modules/military/battle-view/BattleActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,16 @@ export const BattleActions = ({
];

if (raidStatus !== RaidStatus.isRaidable) {
setTooltip({ content: <div className="">{raidStatus}</div>, position: "top" });
} else if (selectedArmy?.battle_id !== 0) {
content.push(<div>Raiding will make you leave and lose 25% of your army</div>);
setTooltip({ content: <div className="text-center">{raidStatus}</div>, position: "top" });
return;
}

if (selectedArmy?.battle_id !== 0) {
content.push(
<div key="warning" className="text-center text-red mt-2">
Raiding will make you leave and lose 25% of your army
</div>,
);
}

setTooltip({
Expand Down
1 change: 1 addition & 0 deletions sdk/packages/eternum/src/constants/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 92efe4b

Please sign in to comment.