Skip to content

Commit

Permalink
fix bugs (#2659)
Browse files Browse the repository at this point in the history
* fix quests

* fix army input

* fix resource precision

* fxied number
  • Loading branch information
aymericdelab authored Jan 22, 2025
1 parent c7d9bf0 commit 5a4783a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 753 deletions.
2 changes: 1 addition & 1 deletion client/apps/game/src/hooks/helpers/use-quests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useQuests = () => {
...QUEST_DETAILS[type],
status: questStatus.questClaimStatus[type] ? QuestStatus.Claimed : QuestStatus.InProgress,
}));
}, []);
}, [questStatus]);

return quests;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QuestStatus, QuestType } from "@bibliothecadao/eternum";
import { useUIStore } from "@/hooks/store/use-ui-store";
import { QuestStatus, QuestType } from "@bibliothecadao/eternum";
import { useEffect } from "react";
import { useQuests } from "./use-quests";
import { questSteps, useTutorial } from "./use-tutorial";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@ import {
getEntityIdFromKeys,
multiplyByPrecision,
} from "@/ui/utils/utils";
import {
ArmyInfo,
ArmyManager,
configManager,
getBalance,
ID,
Position,
ResourcesIds,
U32_MAX,
} from "@bibliothecadao/eternum";
import { ArmyInfo, ArmyManager, configManager, getBalance, ID, Position, ResourcesIds } from "@bibliothecadao/eternum";
import { useDojo, useQuery } from "@bibliothecadao/react";
import { useComponentValue } from "@dojoengine/react";
import clsx from "clsx";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useEffect, useState } from "react";

type ArmyManagementCardProps = {
owner_entity: ID;
Expand Down Expand Up @@ -81,29 +72,6 @@ export const ArmyManagementCard = ({ owner_entity, army, setSelectedEntity }: Ar
[ResourcesIds.Paladin]: 0,
});

const remainingTroops = useMemo(() => {
return (
Math.max(0, maxTroopCountPerArmy - Object.values(troopCounts).reduce((a, b) => a + b, 0)) -
Number(army?.quantity.value)
);
}, [troopCounts]);

const getMaxTroopCount = useCallback(
(balance: number, troopName: number) => {
const balanceFloor = Math.floor(divideByPrecision(balance));
if (!balance) return 0;

const maxFromBalance = Math.min(balanceFloor, divideByPrecision(U32_MAX));

if (isDefendingArmy) {
return maxFromBalance;
} else {
return Math.min(maxFromBalance, remainingTroops + troopCounts[troopName]);
}
},
[isDefendingArmy, remainingTroops, troopCounts],
);

const handleTroopCountChange = (troopName: number, count: number) => {
setTroopCounts((prev) => ({ ...prev, [troopName]: count }));
};
Expand Down Expand Up @@ -273,7 +241,7 @@ export const ArmyManagementCard = ({ owner_entity, army, setSelectedEntity }: Ar
Avail. [{currencyFormat(balance ? Number(balance) : 0, 0)}]
</div>
<NumberInput
max={getMaxTroopCount(balance, troop.name)}
max={divideByPrecision(balance)}
min={0}
step={100}
value={troopCounts[troop.name]}
Expand Down
2 changes: 1 addition & 1 deletion client/apps/game/src/ui/elements/number-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const NumberInput = ({
if (match) {
const parsedValue = parseNumber(match[0]);
const maxValue = Math.min(Math.max(Math.floor(parsedValue), min), max);
setDisplayValue(match[0]);
setDisplayValue(formatNumber(maxValue));
onChange(maxValue);
} else {
setDisplayValue(formatNumber(min));
Expand Down
8 changes: 4 additions & 4 deletions config/deployer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,10 @@ export const setupGlobals = async (config: Config) => {
signer: config.account,
config_id: 0,
unit_type,
explore_wheat_burn_amount: costs.explore_wheat_burn_amount * config.config.resources.resourcePrecision,
explore_fish_burn_amount: costs.explore_fish_burn_amount * config.config.resources.resourcePrecision,
travel_wheat_burn_amount: costs.travel_wheat_burn_amount * config.config.resources.resourcePrecision,
travel_fish_burn_amount: costs.travel_fish_burn_amount * config.config.resources.resourcePrecision,
explore_wheat_burn_amount: costs.explore_wheat_burn_amount,
explore_fish_burn_amount: costs.explore_fish_burn_amount,
travel_wheat_burn_amount: costs.travel_wheat_burn_amount,
travel_fish_burn_amount: costs.travel_fish_burn_amount,
};
});
console.log(
Expand Down
3 changes: 0 additions & 3 deletions config/environments/_shared_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export const MAX_BANK_FEE_ON_WITHDRAWAL = 0; // 10%
export const SEASON_START_AFTER_SECONDS = 60 * 60 * 26; // 1 day
export const SEASON_BRIDGE_CLOSE_AFTER_END_SECONDS = 48 * 60 * 60; // 2 days

console.log("helloooo1");
export const EternumGlobalConfig: Config = {
stamina: {
travelCost: STAMINA_TRAVEL_COST,
Expand Down Expand Up @@ -287,5 +286,3 @@ export const EternumGlobalConfig: Config = {
manifest: manifest,
},
};

console.log("helloooo2");
Loading

0 comments on commit 5a4783a

Please sign in to comment.