Skip to content

Commit

Permalink
Fix donkeys burned in order book, amm & bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
bob0005 committed Dec 13, 2024
1 parent 0f6fcc3 commit f51fe06
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
23 changes: 13 additions & 10 deletions client/src/dojo/modelManager/ConfigManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { divideByPrecision } from "@/ui/utils/utils";
import {
ADMIN_BANK_ENTITY_ID,
BUILDING_CATEGORY_POPULATION_CONFIG_ID,
Expand Down Expand Up @@ -78,7 +77,7 @@ export class ClientConfigManager {

// if (productionInput) {
// const resource = productionInput.input_resource_type;
// const amount = divideByPrecision(Number(productionInput.input_resource_amount));
// const amount = this.divideByPrecision(Number(productionInput.input_resource_amount));
// inputs.push({ resource, amount });
// }
// }
Expand Down Expand Up @@ -108,7 +107,7 @@ export class ClientConfigManager {

this.resourceOutput[Number(resourceType)] = {
resource: Number(resourceType) as ResourcesIds,
amount: divideByPrecision(Number(productionConfig?.amount)),
amount: this.divideByPrecision(Number(productionConfig?.amount)),
};
}
}
Expand Down Expand Up @@ -156,7 +155,7 @@ export class ClientConfigManager {
// );
// if (resource) {
// const resourceId = resource.resource_type;
// const amount = divideByPrecision(Number(resource.resource_amount));
// const amount = this.divideByPrecision(Number(resource.resource_amount));
// resources.push({ resource: resourceId, amount });
// }
// }
Expand Down Expand Up @@ -254,7 +253,7 @@ export class ClientConfigManager {
);

return {
amount: divideByPrecision(Number(hyperstructureResourceConfig?.min_amount) ?? 0),
amount: this.divideByPrecision(Number(hyperstructureResourceConfig?.min_amount) ?? 0),
resource: ResourcesIds.AncientFragment,
};
}
Expand Down Expand Up @@ -293,7 +292,7 @@ export class ClientConfigManager {
return this.getValueOrDefault(() => {
const exploreConfig = getComponentValue(this.components.MapConfig, getEntityIdFromKeys([WORLD_CONFIG_ID]));

return divideByPrecision(Number(exploreConfig?.reward_resource_amount ?? 0));
return this.divideByPrecision(Number(exploreConfig?.reward_resource_amount ?? 0));
}, 0);
}

Expand All @@ -309,7 +308,7 @@ export class ClientConfigManager {
crossbowmanStrength: troopConfig?.crossbowman_strength ?? 0,
advantagePercent: troopConfig?.advantage_percent ?? 0,
disadvantagePercent: troopConfig?.disadvantage_percent ?? 0,
maxTroopCount: divideByPrecision(troopConfig?.max_troop_count ?? 0),
maxTroopCount: this.divideByPrecision(troopConfig?.max_troop_count ?? 0),
pillageHealthDivisor: troopConfig?.pillage_health_divisor ?? 0,
baseArmyNumberForStructure: troopConfig?.army_free_per_structure ?? 0,
armyExtraPerMilitaryBuilding: troopConfig?.army_extra_per_building ?? 0,
Expand Down Expand Up @@ -414,7 +413,7 @@ export class ClientConfigManager {
const bankConfig = getComponentValue(this.components.BankConfig, getEntityIdFromKeys([WORLD_CONFIG_ID]));

return {
lordsCost: divideByPrecision(Number(bankConfig?.lords_cost)),
lordsCost: this.divideByPrecision(Number(bankConfig?.lords_cost)),
lpFeesNumerator: Number(bankConfig?.lp_fee_num ?? 0),
lpFeesDenominator: Number(bankConfig?.lp_fee_denom ?? 0),
};
Expand Down Expand Up @@ -557,11 +556,11 @@ export class ClientConfigManager {
const maxAmount = Number(hyperstructureResourceConfig.max_amount);

if (minAmount === maxAmount) {
return divideByPrecision(minAmount);
return this.divideByPrecision(minAmount);
}

const additionalAmount = Number(randomness % BigInt(maxAmount - minAmount));
return divideByPrecision(minAmount + Number(additionalAmount));
return this.divideByPrecision(minAmount + Number(additionalAmount));
}

getBasePopulationCapacity(): number {
Expand Down Expand Up @@ -626,6 +625,10 @@ export class ClientConfigManager {
return EternumGlobalConfig.resources.resourcePrecision;
}

divideByPrecision(value: number) {
return value / EternumGlobalConfig.resources.resourcePrecision;
}

getResourceMultiplier() {
return EternumGlobalConfig.resources.resourceMultiplier;
}
Expand Down
6 changes: 2 additions & 4 deletions client/src/ui/components/resources/TravelInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { configManager } from "@/dojo/setup";
import { useResourceBalance } from "@/hooks/helpers/useResources";
import { GRAMS_PER_KG } from "@/ui/constants";
import { ResourceIcon } from "@/ui/elements/ResourceIcon";
import { currencyFormat, divideByPrecision, getTotalResourceWeight, multiplyByPrecision } from "@/ui/utils/utils";
import { calculateDonkeysNeeded, currencyFormat, divideByPrecision, getTotalResourceWeight, multiplyByPrecision } from "@/ui/utils/utils";
import { CapacityConfigCategory, ResourcesIds, type ID, type Resource } from "@bibliothecadao/eternum";
import { useEffect, useState } from "react";

Expand All @@ -21,9 +21,7 @@ export const TravelInfo = ({
}) => {
const [resourceWeight, setResourceWeight] = useState(0);
const [donkeyBalance, setDonkeyBalance] = useState(0);
const neededDonkeys = Math.ceil(
divideByPrecision(resourceWeight) / configManager.getCapacityConfig(CapacityConfigCategory.Donkey),
);
const neededDonkeys = calculateDonkeysNeeded(resourceWeight)

const { getBalance } = useResourceBalance();

Expand Down
7 changes: 2 additions & 5 deletions client/src/ui/components/trading/MarketOrderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Button from "@/ui/elements/Button";
import { NumberInput } from "@/ui/elements/NumberInput";
import { ResourceIcon } from "@/ui/elements/ResourceIcon";
import {
calculateDonkeysNeeded,
currencyFormat,
divideByPrecision,
formatNumber,
Expand Down Expand Up @@ -691,8 +692,4 @@ const OrderCreation = ({
</div>
</div>
);
};

const calculateDonkeysNeeded = (orderWeight: number): number => {
return Math.ceil(divideByPrecision(orderWeight) / configManager.getCapacityConfig(CapacityConfigCategory.Donkey));
};
};
15 changes: 11 additions & 4 deletions client/src/ui/utils/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { type ClientComponents } from "@/dojo/createClientComponents";
import { ClientConfigManager } from "@/dojo/modelManager/ConfigManager";
import { HEX_SIZE } from "@/three/scenes/constants";
import { type HexPosition, ResourceMiningTypes } from "@/types";
import { ResourceMiningTypes, type HexPosition } from "@/types";
import {
BuildingType,
CapacityConfigCategory,
ContractAddress,
EternumGlobalConfig,
type ID,
type Position,
type Resource,
ResourceCost,
ResourcesIds,
TickIds,
type ID,
type Position,
type Resource,
} from "@bibliothecadao/eternum";
import { type ComponentValue } from "@dojoengine/recs";
import { getEntityIdFromKeys } from "@dojoengine/utils";
Expand Down Expand Up @@ -499,3 +500,9 @@ export const getRandomBackgroundImage = () => {
export const adjustWonderLordsCost = (cost: ResourceCost[]): ResourceCost[] => {
return cost.map((item) => (item.resource === ResourcesIds.Lords ? { ...item, amount: item.amount * 0.1 } : item));
};

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

return Math.ceil(orderWeight / configManager.getCapacityConfig(CapacityConfigCategory.Donkey));
};
4 changes: 2 additions & 2 deletions landing/src/components/modules/bridge-out-step-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Button } from "../ui/button";
import { ResourceIcon } from "../ui/elements/ResourceIcon";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
import { Tooltip, TooltipProvider } from "../ui/tooltip";
import { calculateDonkeysNeeded, getSeasonAddresses, getTotalResourceWeight } from "../ui/utils/utils";
import { calculateDonkeysNeeded, divideByPrecision, getSeasonAddresses, getTotalResourceWeight } from "../ui/utils/utils";
import { BridgeFees } from "./bridge-fees";

function formatFee(fee: number) {
Expand Down Expand Up @@ -210,7 +210,7 @@ export const BridgeOutStep1 = () => {
</TooltipProvider>
</div>
<div className="flex items-center gap-2">
{donkeysNeeded} / {donkeyBalance.balance} <ResourceIcon resource={"Donkey"} size="md" />
{donkeysNeeded} / {divideByPrecision(donkeyBalance.balance)} <ResourceIcon resource={"Donkey"} size="md" />
</div>
</div>
<BridgeFees
Expand Down

0 comments on commit f51fe06

Please sign in to comment.