Skip to content

Commit

Permalink
Merge pull request #504 from BibliothecaDAO/feat/vit-fix
Browse files Browse the repository at this point in the history
Modify VIT removal to be player side
  • Loading branch information
starknetdev authored Jan 17, 2024
2 parents e2994c9 + b53abaf commit 7ee6283
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ account
loot-survivor.pem
contracts/game_entropy/target/CACHEDIR.TAG
contracts/game_entropy/target/dev/game_entropy.sierra

scripts/stress_test.py
18 changes: 14 additions & 4 deletions ui/src/app/components/upgrade/PurchaseHealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface PurchaseHealthProps {
items?: any[]
) => void;
totalVitality: number;
vitBoostRemoved: number;
}

const PurchaseHealth = ({
Expand All @@ -25,6 +26,7 @@ const PurchaseHealth = ({
setPotionAmount,
totalCharisma,
upgradeHandler,
vitBoostRemoved,
}: PurchaseHealthProps) => {
const adventurer = useAdventurerStore((state) => state.adventurer);
const prevAmountRef = useRef<number | undefined>(0);
Expand All @@ -37,7 +39,9 @@ const PurchaseHealth = ({
const maxHealth = 100 + (adventurer?.vitality ?? 0) * 10;

const max = Math.min(
Math.ceil((maxHealth - (adventurer?.health ?? 0)) / 10),
Math.ceil(
(maxHealth - (adventurer?.health ?? 0) - vitBoostRemoved * 10) / 10
),
Math.floor(
(adventurer?.gold! - (upgradeTotalCost - potionAmount * potionCost)) /
potionCost
Expand Down Expand Up @@ -109,9 +113,15 @@ const PurchaseHealth = ({
Fill to Max
</Button>
<div className="flex flex-col gap-2 sm:flex-row items-center p-4">
<p className="text-center">
You can only buy up to Max Health! 1 Potion = 10 Health
</p>
{!vitBoostRemoved ? (
<p className="text-center">
You can only buy up to Max Health! 1 Potion = 10 Health
</p>
) : (
<p className="text-center">
You are removing VIT boost so max potions are lower than usual!
</p>
)}
</div>
</div>
);
Expand Down
58 changes: 31 additions & 27 deletions ui/src/app/containers/UpgradeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,34 +279,37 @@ export default function UpgradeScreen({
return upgradeTx;
};

const adventurerItems = useQueriesStore(
(state) => state.data.itemsByAdventurerQuery?.items || []
);

const vitBoostRemoved = calculateVitBoostRemoved(
purchaseItems,
adventurer!,
adventurerItems
);

const maxHealth = Math.min(100 + totalVitality * 10, 511);
const newMaxHealth = 100 + (totalVitality - vitBoostRemoved) * 10;
const currentHealth = adventurer?.health! + selectedVitality * 10;
const healthPlusPots = Math.min(
currentHealth! + potionAmount * 10,
maxHealth
);
const healthOverflow = healthPlusPots > newMaxHealth;

const handleSubmitUpgradeTx = async () => {
renderSummary();
resetNotification();
// Handle for vitBoostRemoval
const vitBoostRemoved = calculateVitBoostRemoved(
purchaseItems,
adventurer!,
adventurerItems
);
let upgradeTx: any;
if (potionAmount > 0) {
// Check whether health + pots is within vitBoostRemoved of the maxHealth
const maxHealth = 100 + totalVitality * 10;
const newMaxHealth = 100 + (totalVitality - vitBoostRemoved) * 10;
const currentHealth = adventurer?.health! + selectedVitality * 10;
const healthPlusPots = Math.min(
currentHealth! + potionAmount * 10,
maxHealth
if (healthOverflow) {
const newUpgradeTx = handleAddUpgradeTx(
undefined,
Math.max(potionAmount - vitBoostRemoved, 0),
undefined
);
const healthOverflow = healthPlusPots > newMaxHealth;
if (healthOverflow) {
const newUpgradeTx = handleAddUpgradeTx(
undefined,
Math.max(potionAmount - vitBoostRemoved, 0),
undefined
);
upgradeTx = newUpgradeTx;
}
upgradeTx = newUpgradeTx;
}
try {
await upgrade(
Expand Down Expand Up @@ -345,8 +348,6 @@ export default function UpgradeScreen({

const totalStatUpgrades = (adventurer?.statUpgrades ?? 0) - upgradesTotal;

const maxHealth = Math.min(100 + totalVitality * 10, 720);

const healthPlus = Math.min(
(selectedVitality + potionAmount) * 10,
maxHealth - (adventurer?.health ?? 0)
Expand All @@ -371,9 +372,11 @@ export default function UpgradeScreen({
getNoBoostedStats();
}, []);

const adventurerItems = useQueriesStore(
(state) => state.data.itemsByAdventurerQuery?.items || []
);
useEffect(() => {
if (healthOverflow) {
setPotionAmount(Math.max(potionAmount - vitBoostRemoved, 0));
}
}, [newMaxHealth]);

return (
<>
Expand Down Expand Up @@ -538,6 +541,7 @@ export default function UpgradeScreen({
totalCharisma={totalCharisma}
upgradeHandler={handleAddUpgradeTx}
totalVitality={totalVitality}
vitBoostRemoved={vitBoostRemoved}
/>
</div>
)}
Expand Down

1 comment on commit 7ee6283

@vercel
Copy link

@vercel vercel bot commented on 7ee6283 Jan 17, 2024

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.