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

fix army weight when exploring, add weigh + capacity in UI #1117

Merged
merged 11 commits into from
Aug 2, 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
1 change: 1 addition & 0 deletions client/src/dojo/modelManager/__tests__/__mock__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const generateMockArmyInfo = (alive?: boolean, isMine?: boolean, battleEn
intermediate_coord_y: 0,
},
capacity: { entity_id: ARMY_ENTITY_ID, weight_gram: 10n },
weight: { entity_id: ARMY_ENTITY_ID, value: 0n },
arrivalTime: { entity_id: ARMY_ENTITY_ID, arrives_at: 0n },
stamina: { entity_id: ARMY_ENTITY_ID, amount: 1, last_refill_tick: 0n },
realm: {
Expand Down
62 changes: 59 additions & 3 deletions client/src/hooks/helpers/useArmies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export type ArmyInfo = ComponentValue<ClientComponents["Army"]["schema"]> & {
owner: ComponentValue<ClientComponents["Owner"]["schema"]>;
entityOwner: ComponentValue<ClientComponents["EntityOwner"]["schema"]>;
protectee: ComponentValue<ClientComponents["Protectee"]["schema"]> | undefined;
quantity: ComponentValue<ClientComponents["Quantity"]["schema"]> | undefined;
quantity: ComponentValue<ClientComponents["Quantity"]["schema"]>;
movable: ComponentValue<ClientComponents["Movable"]["schema"]> | undefined;
capacity: ComponentValue<ClientComponents["Capacity"]["schema"]> | undefined;
capacity: ComponentValue<ClientComponents["Capacity"]["schema"]>;
weight: ComponentValue<ClientComponents["Weight"]["schema"]>;
arrivalTime: ComponentValue<ClientComponents["ArrivalTime"]["schema"]> | undefined;
stamina: ComponentValue<ClientComponents["Stamina"]["schema"]> | undefined;
realm: ComponentValue<ClientComponents["Realm"]["schema"]> | undefined;
Expand All @@ -48,6 +49,7 @@ const formatArmies = (
Quantity: Component<ClientComponents["Quantity"]["schema"]>,
Movable: Component<ClientComponents["Movable"]["schema"]>,
Capacity: Component<ClientComponents["Capacity"]["schema"]>,
Weight: Component<ClientComponents["Weight"]["schema"]>,
ArrivalTime: Component<ClientComponents["ArrivalTime"]["schema"]>,
Position: Component<ClientComponents["Position"]["schema"]>,
EntityOwner: Component<ClientComponents["EntityOwner"]["schema"]>,
Expand Down Expand Up @@ -89,9 +91,42 @@ const formatArmies = (
};
}
const protectee = getComponentValue(Protectee, armyEntityId);

const quantity = getComponentValue(Quantity, armyEntityId);
let quantityClone = structuredClone(quantity);
if (quantityClone) {
quantityClone.value = BigInt(quantityClone.value) / BigInt(EternumGlobalConfig.resources.resourcePrecision);
} else {
quantityClone = {
entity_id: army.entity_id,
value: 0n,
};
}

const movable = getComponentValue(Movable, armyEntityId);

const capacity = getComponentValue(Capacity, armyEntityId);
let capacityClone = structuredClone(capacity);
if (capacityClone) {
capacityClone.weight_gram = capacityClone.weight_gram * quantityClone.value;
} else {
capacityClone = {
entity_id: army.entity_id,
weight_gram: BigInt(EternumGlobalConfig.carryCapacity.army) * quantityClone.value,
};
}

const weight = getComponentValue(Weight, armyEntityId);
let weightClone = structuredClone(weight);
if (weightClone) {
weightClone.value = weightClone.value / BigInt(EternumGlobalConfig.resources.resourcePrecision);
} else {
weightClone = {
entity_id: army.entity_id,
value: 0n,
};
}

const arrivalTime = getComponentValue(ArrivalTime, armyEntityId);
const stamina = getComponentValue(Stamina, armyEntityId);
const name = getComponentValue(Name, armyEntityId);
Expand All @@ -111,7 +146,8 @@ const formatArmies = (
health: healthClone,
quantity,
movable,
capacity,
capacity: capacityClone,
weight: weightClone,
arrivalTime,
position,
entityOwner,
Expand Down Expand Up @@ -142,6 +178,7 @@ export const useMovableArmies = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand Down Expand Up @@ -174,6 +211,7 @@ export const useMovableArmies = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -195,6 +233,7 @@ export const useArmiesByEntityOwner = ({ entity_owner_entity_id }: { entity_owne
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand All @@ -219,6 +258,7 @@ export const useArmiesByEntityOwner = ({ entity_owner_entity_id }: { entity_owne
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -244,6 +284,7 @@ export const getArmiesByBattleId = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand All @@ -267,6 +308,7 @@ export const getArmiesByBattleId = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -289,6 +331,7 @@ export const useArmyByArmyEntityId = (entityId: ID) => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand All @@ -311,6 +354,7 @@ export const useArmyByArmyEntityId = (entityId: ID) => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -332,6 +376,7 @@ export const getUserArmyInBattle = (battle_id: ID) => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand Down Expand Up @@ -360,6 +405,7 @@ export const getUserArmyInBattle = (battle_id: ID) => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -385,6 +431,7 @@ export const useOwnArmiesByPosition = ({ position, inBattle }: { position: Posit
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand Down Expand Up @@ -414,6 +461,7 @@ export const useOwnArmiesByPosition = ({ position, inBattle }: { position: Posit
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -440,6 +488,7 @@ export const useEnemyArmiesByPosition = ({ position }: { position: Position }) =
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand Down Expand Up @@ -468,6 +517,7 @@ export const useEnemyArmiesByPosition = ({ position }: { position: Position }) =
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -492,6 +542,7 @@ export const getArmyByEntityId = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand All @@ -516,6 +567,7 @@ export const getArmyByEntityId = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -538,6 +590,7 @@ export const getArmyByEntityId = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -561,6 +614,7 @@ export const getArmiesAtPosition = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Realm,
Army,
Expand Down Expand Up @@ -598,6 +652,7 @@ export const getArmiesAtPosition = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand All @@ -616,6 +671,7 @@ export const getArmiesAtPosition = () => {
Quantity,
Movable,
Capacity,
Weight,
ArrivalTime,
Position,
EntityOwner,
Expand Down
2 changes: 2 additions & 0 deletions client/src/ui/components/entities/Entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import clsx from "clsx";
import React, { useMemo, useState } from "react";
import { DepositResources } from "../resources/DepositResources";
import { TravelEntityPopup } from "./TravelEntityPopup";
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity";

const entityIcon: Record<EntityType, string> = {
[EntityType.DONKEY]: "🫏",
Expand Down Expand Up @@ -123,6 +124,7 @@ export const Entity = ({ entityId, ...props }: EntityProps) => {
<div className="flex items-center gap-1 self-center">{renderEntityStatus()}</div>
</div>
</div>
{entity.entityType === EntityType.TROOP && <ArmyCapacity army={army} className="my-2 ml-5" />}
edisontim marked this conversation as resolved.
Show resolved Hide resolved
<div className="flex items-center gap-2 flex-wrap my-2">{renderResources()}</div>
{entityState !== EntityState.Traveling && (
<DepositResources
Expand Down
2 changes: 2 additions & 0 deletions client/src/ui/components/military/ArmyChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useMemo, useState } from "react";
import { InventoryResources } from "../resources/InventoryResources";
import { ArmyManagementCard, ViewOnMapIcon } from "./ArmyManagementCard";
import { TroopMenuRow } from "./TroopChip";
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity";

export const ArmyChip = ({
army,
Expand Down Expand Up @@ -81,6 +82,7 @@ export const ArmyChip = ({
</div>
<div className="font-bold text-xs">
<StaminaResource entityId={updatedArmy!.entity_id} />
<ArmyCapacity army={updatedArmy} />
</div>
</div>
<div className="flex flex-col content-center w-[55%]">
Expand Down
7 changes: 5 additions & 2 deletions client/src/ui/components/military/ArmyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, { useMemo, useState } from "react";
import { EntityList } from "../list/EntityList";
import { InventoryResources } from "../resources/InventoryResources";
import { ArmyManagementCard } from "./ArmyManagementCard";
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity";

const MAX_AMOUNT_OF_DEFENSIVE_ARMIES = 1;

Expand Down Expand Up @@ -75,7 +76,6 @@ export const EntityArmyList = ({ structure }: { structure: PlayerStructure }) =>
is_defensive_army,
}).finally(() => setLoading(Loading.None));
};

return (
<>
<EntityList
Expand Down Expand Up @@ -128,7 +128,10 @@ export const EntityArmyList = ({ structure }: { structure: PlayerStructure }) =>
}
title="armies"
panel={({ entity, setSelectedEntity }) => (
<ArmyItem entity={entity} setSelectedEntity={setSelectedEntity} structure={structure} />
<>
<ArmyItem entity={entity} setSelectedEntity={setSelectedEntity} structure={structure} />
<ArmyCapacity army={entity} className="my-2 ml-5" />
</>
)}
questing={selectedQuest?.id === QuestId.CreateArmy}
/>
Expand Down
11 changes: 9 additions & 2 deletions client/src/ui/components/quest/QuestInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ export const QuestInfo = ({ quest, entityId }: { quest: Quest; entityId: ID }) =
};

const QuestRewards = ({ prizes }: { prizes: Prize[] }) => {
const [showRewards, setShowRewards] = useState(false);
const { getQuestResources } = useRealm();

return (
<div className="w-full">
<div className="mb-1 font-bold">Quest Rewards</div>
{prizes &&
<div className="flex flex-row items-baseline mb-1 ">
<div className="font-bold mr-5">Quest Rewards</div>
<Button size="xs" onClick={() => setShowRewards(!showRewards)}>
{showRewards ? "Hide" : "Show"}
</Button>
</div>
{showRewards &&
prizes &&
prizes.map((prize, index) => (
<div key={index} className="grid grid-cols-3 gap-3">
{getQuestResources()[prize.id].map((resource, i) => (
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/components/trading/MarketOrderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const OrderCreation = ({

const orderWeight = useMemo(() => {
const totalWeight = getTotalResourceWeight([
{ resourceId: isBuy ? resourceId : ResourcesIds.Lords, amount: resource },
{ resourceId: isBuy ? resourceId : ResourcesIds.Lords, amount: isBuy ? resource : lords },
]);
return multiplyByPrecision(totalWeight);
}, [resource, lords]);
Expand Down
5 changes: 3 additions & 2 deletions client/src/ui/components/worldmap/armies/ArmyInfoLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useBlockchainStore from "../../../../hooks/store/useBlockchainStore";
import { currencyFormat } from "../../../utils/utils";

import { ArmyInfo } from "@/hooks/helpers/useArmies";
import { ArmyInfo, useArmyByArmyEntityId } from "@/hooks/helpers/useArmies";
import { BaseThreeTooltip, Position } from "@/ui/elements/BaseThreeTooltip";
import { Headline } from "@/ui/elements/Headline";
import { ResourceIcon } from "@/ui/elements/ResourceIcon";
Expand All @@ -12,6 +12,7 @@ import { useMemo } from "react";
import { useRealm } from "../../../../hooks/helpers/useRealm";
import { getRealmNameById } from "../../../utils/realms";
import { InventoryResources } from "../../resources/InventoryResources";
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity";

interface ArmyInfoLabelProps {
army: ArmyInfo;
Expand Down Expand Up @@ -104,7 +105,7 @@ const RaiderInfo = ({ army }: ArmyInfoLabelProps) => {
<div className="text-green text-xs self-center">{currencyFormat(troops.paladin_count, 0)}</div>
</div>
</div>

<ArmyCapacity army={army} />
<div className="flex flex-row justify-between">
<InventoryResources max={2} entityIds={[entity_id]} />
</div>
Expand Down
16 changes: 16 additions & 0 deletions client/src/ui/components/worldmap/hexagon/ActionInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Headline } from "@/ui/elements/Headline";
import { ResourceCost } from "@/ui/elements/ResourceCost";
import { StaminaResourceCost } from "@/ui/elements/StaminaResourceCost";
import { getUIPositionFromColRow } from "@/ui/utils/utils";
import { BuildingThumbs } from "@/ui/modules/navigation/LeftNavigationModule";
import { EternumGlobalConfig, ResourcesIds } from "@bibliothecadao/eternum";
import { useMemo } from "react";

Expand Down Expand Up @@ -54,6 +55,21 @@ export const ActionInfo = () => {
isExplored={isExplored}
travelLength={travelPath.path.length - 1}
/>
<div className="flex flex-row text-xs">
<div
style={{
backgroundImage: `url(${BuildingThumbs.resources})`,
backgroundSize: "calc(100% - 10px)",
backgroundPosition: "center",
}}
className="w-8 h-8 bg-no-repeat"
></div>

<div className="flex flex-col p-1 text-xs">
<div>+{EternumGlobalConfig.exploration.reward}</div>
<div>Reward</div>
</div>
</div>
</BaseThreeTooltip>
</group>
)}
Expand Down
Loading
Loading