Skip to content

Commit

Permalink
Merge pull request #2498 from BibliothecaDAO/next
Browse files Browse the repository at this point in the history
donkey fix
  • Loading branch information
ponderingdemocritus authored Dec 14, 2024
2 parents fd49384 + f5b372a commit 5ef1746
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions client/src/ui/components/resources/TravelInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getTotalResourceWeight,
multiplyByPrecision,
} from "@/ui/utils/utils";
import { CapacityConfigCategory, ResourcesIds, type ID, type Resource } from "@bibliothecadao/eternum";
import { useEffect, useState } from "react";
import { ResourcesIds, type ID, type Resource } from "@bibliothecadao/eternum";
import { useEffect, useMemo, useState } from "react";

export const TravelInfo = ({
entityId,
Expand All @@ -27,18 +27,22 @@ export const TravelInfo = ({
}) => {
const [resourceWeight, setResourceWeight] = useState(0);
const [donkeyBalance, setDonkeyBalance] = useState(0);
const neededDonkeys = calculateDonkeysNeeded(resourceWeight);
const neededDonkeys = useMemo(() => calculateDonkeysNeeded(resourceWeight), [resourceWeight]);

const { getBalance } = useResourceBalance();

useEffect(() => {
const totalWeight = getTotalResourceWeight(resources);

const multipliedWeight = multiplyByPrecision(totalWeight);
setResourceWeight(multipliedWeight);

const { balance } = getBalance(entityId, ResourcesIds.Donkey);

const currentDonkeyAmount = isAmm ? 0 : resources.find((r) => r.resourceId === ResourcesIds.Donkey)?.amount || 0;

const calculatedDonkeyBalance = divideByPrecision(balance) - currentDonkeyAmount;

setDonkeyBalance(calculatedDonkeyBalance);

if (setCanCarry) {
Expand Down
5 changes: 3 additions & 2 deletions client/src/ui/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ export const adjustWonderLordsCost = (cost: ResourceCost[]): ResourceCost[] => {

export const calculateDonkeysNeeded = (orderWeight: number): number => {
const configManager = ClientConfigManager.instance();
const donkeyCapacityGrams = configManager.getCapacityConfig(CapacityConfigCategory.Donkey);

return Math.ceil(orderWeight / configManager.getCapacityConfig(CapacityConfigCategory.Donkey));
};
return Math.ceil((orderWeight / 1000) / donkeyCapacityGrams);
};

0 comments on commit 5ef1746

Please sign in to comment.