Skip to content
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

min troops #2424

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading