Skip to content

Commit

Permalink
Merge pull request #537 from BibliothecaDAO/feat/late-game-fixes
Browse files Browse the repository at this point in the history
Bug fixes from swapping items
  • Loading branch information
starknetdev authored Jan 17, 2024
2 parents 7ee6283 + 937e410 commit 03f6843
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
18 changes: 18 additions & 0 deletions ui/src/app/components/beast/BattleDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ export const NotificationBattleDisplay = ({
) &&
(battleData[1]?.adventurerHealth ?? 0) == 0;
const Attacked =
isArray &&
battleData.some(
(data) => data.attacker === "Beast" && (data.adventurerHealth ?? 0) > 0
) &&
battleData.some((data) => data.attacker === "Adventurer");
const AttackedFromEquipping =
isArray &&
battleData.some(
(data) => data.attacker === "Beast" && (data.adventurerHealth ?? 0) > 0
Expand Down Expand Up @@ -283,6 +289,18 @@ export const NotificationBattleDisplay = ({
<GiBattleGearIcon />
</span>
);
} else if (AttackedFromEquipping) {
return (
<span className="flex flex-row items-center justify-between w-full">
<p>
{beastName || ""} attacked for {battleData[0]?.damageTaken} damage
to {battleData[0]?.damageLocation} from swapping item
{battleData[0]?.criticalHit && ", a critical hit"}!
</p>
;
<GiBattleGearIcon />
</span>
);
} else if (KilledByBeast) {
return (
<span className="flex flex-row items-center justify-between w-full">
Expand Down
16 changes: 13 additions & 3 deletions ui/src/app/components/beast/BeastDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import EfficacyIcon from "@/app/components/icons/EfficacyIcon";
import { processBeastName } from "@/app/lib/utils";
import { Beast } from "@/app/types";
import { HealthCountDown } from "@/app/components/CountDown";
import { getKeyFromValue } from "@/app/lib/utils";
import { GameData } from "@/app/lib/data/GameData";

interface BeastDisplayProps {
beastData: Beast;
Expand All @@ -27,13 +29,21 @@ export const BeastDisplay = ({

const namedBeast = beastData?.special2 ? true : false;

const gameData = new GameData();

const handleIsMinted = async () => {
const minted = await beastsContract.call(
"isMinted",
CallData.compile({
beast: beastData?.beast ?? "",
prefix: beastData?.special2 ?? "",
suffix: beastData?.special3 ?? "",
beast: getKeyFromValue(gameData.BEASTS, beastData?.beast ?? "")!,
prefix: getKeyFromValue(
gameData.ITEM_NAME_PREFIXES,
beastData?.special2 ?? ""
)!,
suffix: getKeyFromValue(
gameData.ITEM_NAME_SUFFIXES,
beastData?.special3 ?? ""
)!,
})
);
if (minted == "1") {
Expand Down
29 changes: 28 additions & 1 deletion ui/src/app/components/notifications/NotificationHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,34 @@ export const processNotifications = (
),
});
} else if ((type == "Attack" || type == "Flee") && isArray) {
const battleScenarios = chunkArray(notificationData as Battle[], 2);
// Here we need to check whether there is a single attack (from equip) and chunk that by 1, otherwise chunk it by 2
const battleScenarios: Battle[][] = [];
let currentChunk: Battle[] = [];
let chunkingByOne = true;

for (let i = 0; i < notificationData.length; i++) {
const battle = notificationData[i];
if (chunkingByOne) {
if (battle.attacker === "Beast") {
// Chunk by one
battleScenarios.push([battle]);
} else if (battle.attacker === "Adventurer") {
// Switch to different chunking strategy
chunkingByOne = false;
currentChunk.push(battle);
}
} else {
currentChunk.push(battle);
if (currentChunk.length === 2) {
battleScenarios.push(currentChunk);
currentChunk = []; // Reset currentChunk after adding it to battleScenarios
}
}
}
// Handle any remaining battles in currentChunk
if (currentChunk.length > 0) {
battleScenarios.push(currentChunk);
}
for (let i = 0; i < battleScenarios.length; i++) {
const animation = handleAnimation(battleScenarios[i] as Battle[]);
notifications.push({
Expand Down
10 changes: 6 additions & 4 deletions ui/src/app/lib/utils/syscalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,19 @@ function handleEquip(
(item: Item) => item.item == equippedItem
);
if (ownedItem) {
ownedItem.equipped = true;
equippedItems.push(ownedItem);
const modifiedItem = { ...ownedItem };
modifiedItem.equipped = true;
equippedItems.push(modifiedItem);
}
}
for (let unequippedItem of equippedItemsEvent.data[2]) {
const ownedItem = queryData.itemsByAdventurerQuery?.items.find(
(item: Item) => item.item == unequippedItem
);
if (ownedItem) {
ownedItem.equipped = false;
unequippedItems.push(ownedItem);
const modifiedItem = { ...ownedItem };
modifiedItem.equipped = false;
unequippedItems.push(modifiedItem);
}
}
}
Expand Down

0 comments on commit 03f6843

Please sign in to comment.