Skip to content

Commit

Permalink
feat: add procentage buttons to prestigeshop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mees committed Nov 2, 2024
1 parent 7ac3618 commit fd691b8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/stores/prestigeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface PrestigeShopItem {

export const usePrestigeStore = defineStore('prestige', {
state: () => ({
buyLimit: 1,
prestigePoints: 0, // New prestige currency
timesPrestiged: 0, // Number of times prestiged
lastPrestige: Date.now(), // Timestamp of the last prestige
Expand Down Expand Up @@ -420,6 +421,9 @@ export const usePrestigeStore = defineStore('prestige', {
},
},
actions: {
setBuyLimit(limit: number) {
this.buyLimit = limit
},
timeSinceLastPrestigeFormatted(){
const timeSinceLastPrestige = Date.now() - this.lastPrestige
if (timeSinceLastPrestige < 0) {
Expand Down Expand Up @@ -571,20 +575,27 @@ export const usePrestigeStore = defineStore('prestige', {
return false
}

// Keep buying the upgrade until you can't afford the next one
while (this.prestigePoints >= upgrade.cost) {
this.prestigePoints -= upgrade.cost
// Calculate max affordable purchases based on buyLimit
const maxAffordable = Math.floor(this.prestigePoints * this.buyLimit / upgrade.cost)
let purchased = 0
let currentCost = upgrade.cost

while (purchased < maxAffordable) {
if (upgrade.maxPurchases && this.amountOfUpgrade(upgradeId) >= upgrade.maxPurchases) {
break
}

this.prestigePoints -= currentCost
this.purchasedUpgrades.push(upgradeId)
this.applyPrestigeUpgrade(upgradeId)

// Increase the cost for the next purchase
upgrade.cost *= this.getCostMultiplier(upgrade)
upgrade.cost = Math.floor(upgrade.cost) // Round down to the nearest integer
currentCost *= this.getCostMultiplier(upgrade)
currentCost = Math.floor(currentCost)
upgrade.cost = currentCost
purchased++
}

return true
},
// Apply a purchased upgrade
Expand Down
1 change: 1 addition & 0 deletions src/types/trainingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum Skill {
Attack = 'attack',
Defense = 'defense',
Hitpoints = 'hitpoints',
Farming = 'farming',
}

export enum ForagingArea {
Expand Down
48 changes: 44 additions & 4 deletions src/views/PrestigeShop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,49 @@

<!-- Fixed prestige points display -->
<div class="bg-purple-100 border-l-4 border-purple-500 text-purple-700 p-4 sticky top-0 z-10 shadow-md">
<p class="font-bold">
Prestige Points: {{ formatNumber(prestigeStore.prestigePoints) }}
</p>
<div class="flex justify-between items-center">
<p class="font-bold">
Prestige Points: {{ formatNumber(prestigeStore.prestigePoints) }}
</p>
<div class="flex gap-2">
<button
:class="[
'px-2 py-1 text-sm text-white rounded hover:bg-purple-600',
prestigeStore.buyLimit === 0.1 ? 'bg-purple-700' : 'bg-purple-500'
]"
@click="prestigeStore.setBuyLimit(0.1)"
>
10%
</button>
<button
:class="[
'px-2 py-1 text-sm text-white rounded hover:bg-purple-600',
prestigeStore.buyLimit === 0.25 ? 'bg-purple-700' : 'bg-purple-500'
]"
@click="prestigeStore.setBuyLimit(0.25)"
>
25%
</button>
<button
:class="[
'px-2 py-1 text-sm text-white rounded hover:bg-purple-600',
prestigeStore.buyLimit === 0.5 ? 'bg-purple-700' : 'bg-purple-500'
]"
@click="prestigeStore.setBuyLimit(0.5)"
>
50%
</button>
<button
:class="[
'px-2 py-1 text-sm text-white rounded hover:bg-purple-600',
prestigeStore.buyLimit === 1 ? 'bg-purple-700' : 'bg-purple-500'
]"
@click="prestigeStore.setBuyLimit(1)"
>
100%
</button>
</div>
</div>
</div>

<div class="bg-white bg-opacity-50 p-4 rounded-lg shadow-md flex flex-col space-y-4 flex-grow">
Expand Down Expand Up @@ -149,7 +189,7 @@
class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded-md shadow-sm text-sm transition duration-300 ease-in-out disabled:bg-gray-400 disabled:cursor-not-allowed"
@click="prestigeStore.buyMaxUpgrade(upgrade.id)"
>
Buy max
Buy {{ prestigeStore.buyLimit * 100 }}%
</button>
</div>
</div>
Expand Down

0 comments on commit fd691b8

Please sign in to comment.