Skip to content

Commit

Permalink
Merge pull request #402 from BibliothecaDAO/feat/stat-maxes
Browse files Browse the repository at this point in the history
Fix contract errors when upgrading stats above 15
  • Loading branch information
starknetdev authored Oct 12, 2023
2 parents e5ae1a8 + d9d642a commit e543038
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
40 changes: 25 additions & 15 deletions ui/src/app/components/upgrade/StatAttribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ interface StatAttributeProps {
potions?: number,
items?: any[]
) => void;
nonBoostedStat: any;
}

export const StatAttribute = ({
name,
icon,
description,
upgradeHandler,
nonBoostedStat,
}: StatAttributeProps) => {
const adventurer = useAdventurerStore((state) => state.adventurer);
const prevAmountRef = useRef<{ [key: string]: number }>({ ...ZeroUpgrade });
Expand All @@ -42,6 +44,8 @@ export const StatAttribute = ({
const newUpgradeTotal =
amount + ((adventurer?.statUpgrades ?? 0) - upgradesTotal);

const maxNonBoosted = nonBoostedStat + BigInt(amount) >= BigInt(15);

useEffect(() => {
if (buttonClicked) {
if (prevAmountRef.current !== undefined) {
Expand All @@ -67,21 +71,27 @@ export const StatAttribute = ({
return (
<div className="flex flex-col gap-1 sm:gap-3 items-center">
<span className="hidden sm:block w-10 h-10">{icon}</span>
<p className="sm:text-[28px] xl:text-2xl text-center h-2/3">
{description}
</p>
<span className="flex flex-row items-center">
<QuantityButtons
amount={amount}
min={0}
max={newUpgradeTotal}
setAmount={(value) => {
upgrades[name] = value;
setUpgrades(upgrades);
setButtonClicked(true);
}}
/>
</span>
{maxNonBoosted ? (
<p className="sm:text-4xl text-center">Base Stat Maxed Out</p>
) : (
<>
<p className="sm:text-[28px] xl:text-2xl text-center h-2/3">
{description}
</p>
<span className="flex flex-row items-center">
<QuantityButtons
amount={amount}
min={0}
max={newUpgradeTotal}
setAmount={(value) => {
upgrades[name] = value;
setUpgrades(upgrades);
setButtonClicked(true);
}}
/>
</span>
</>
)}
</div>
);
};
20 changes: 20 additions & 0 deletions ui/src/app/containers/UpgradeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import useUIStore from "../hooks/useUIStore";
import { UpgradeStats, ZeroUpgrade, UpgradeSummary } from "../types";
import Summary from "../components/upgrade/Summary";
import { HealthCountDown } from "../components/CountDown";
import { CallData } from "starknet";

interface UpgradeScreenProps {
upgrade: (...args: any[]) => any;
Expand All @@ -54,6 +55,7 @@ export default function UpgradeScreen({ upgrade }: UpgradeScreenProps) {
(state) => state.computed.hasStatUpgrades
);
const [selected, setSelected] = useState("");
const [nonBoostedStats, setNonBoostedStats] = useState<any | null>(null);
const upgradeScreen = useUIStore((state) => state.upgradeScreen);
const setUpgradeScreen = useUIStore((state) => state.setUpgradeScreen);
const potionAmount = useUIStore((state) => state.potionAmount);
Expand Down Expand Up @@ -82,13 +84,15 @@ export default function UpgradeScreen({ upgrade }: UpgradeScreenProps) {
description: "Strength increases attack damage by 10%",
buttonText: "Upgrade Strength",
abbrev: "STR",
nonBoostedStat: nonBoostedStats?.strength,
},
{
name: "Dexterity",
icon: <CatIcon />,
description: "Dexterity increases chance of fleeing Beasts",
buttonText: "Upgrade Dexterity",
abbrev: "DEX",
nonBoostedStat: nonBoostedStats?.dexterity,
},
{
name: "Vitality",
Expand All @@ -97,27 +101,31 @@ export default function UpgradeScreen({ upgrade }: UpgradeScreenProps) {
description: "Vitality increases max health and gives +10hp ",
buttonText: "Upgrade Vitality",
abbrev: "VIT",
nonBoostedStat: nonBoostedStats?.vitality,
},
{
name: "Intelligence",
icon: <LightbulbIcon />,
description: "Intelligence increases chance of avoiding Obstacles",
buttonText: "Upgrade Intelligence",
abbrev: "INT",
nonBoostedStat: nonBoostedStats?.intelligence,
},
{
name: "Wisdom",
icon: <ScrollIcon />,
description: "Wisdom increases chance of avoiding a Beast ambush",
buttonText: "Upgrade Wisdom",
abbrev: "WIS",
nonBoostedStat: nonBoostedStats?.wisdom,
},
{
name: "Charisma",
icon: <CoinCharismaIcon />,
description: "Charisma provides discounts on the marketplace and potions",
buttonText: "Upgrade Charisma",
abbrev: "CHA",
nonBoostedStat: nonBoostedStats?.charisma,
},
];

Expand Down Expand Up @@ -299,6 +307,18 @@ export default function UpgradeScreen({ upgrade }: UpgradeScreenProps) {
maxHealth
);

const getNoBoostedStats = async () => {
const stats = await gameContract?.call(
"get_base_stats",
CallData.compile({ token_id: adventurer?.id! })
); // check whether player can use the current token
setNonBoostedStats(stats);
};

useEffect(() => {
getNoBoostedStats();
}, []);

return (
<>
{hasStatUpgrades ? (
Expand Down

1 comment on commit e543038

@vercel
Copy link

@vercel vercel bot commented on e543038 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.