Skip to content

Commit

Permalink
Elite ants
Browse files Browse the repository at this point in the history
  • Loading branch information
Mezeman1 committed Sep 11, 2024
1 parent cd4c045 commit 1914e44
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion src/stores/gameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const useGameStore = defineStore('gameStore', {
loggedIn: false,
larvae: 0,
ants: 0,
eliteAnts: 0,

eliteAntsUnlocked: false,

larvaeAccumulator: 0, // To accumulate fractional larvae production
seedAccumulator: 0, // To accumulate fractional seed production
Expand All @@ -27,12 +30,14 @@ export const useGameStore = defineStore('gameStore', {
maxLarvae: 10, // Initial larvae storage capacity
maxAnts: 100, // Initial ant storage capacity
maxQueens: 2, // Initial queen storage capacity
maxEliteAnts: 1,

// Initial resource caps
initialMaxSeeds: 1000,
initialMaxLarvae: 10,
initialMaxAnts: 100,
initialMaxQueens: 2,
initialMaxEliteAnts: 1,

// Upgrade variables
seedStorageUpgradeCost: 500, // Initial cost to upgrade seed storage
Expand All @@ -47,10 +52,14 @@ export const useGameStore = defineStore('gameStore', {
collectionRatePerAnt: 60, // Seeds collected per ant per minute
seedCostPerLarva: 100, // Cost in seeds to create one larva
seedCostPerAnt: 50, // Cost in seeds to create one ant
seedCostPerEliteAnt: 100,
larvaCostPerAnt: 1, // Cost in larvae to create one ant
larvaCostPerEliteAnt: 5,
antCostPerQueen: 100, // Ants required to buy one queen
seedCostPerQueen: 250, // Seeds required to buy one queen

multiplierPerEliteAnt: 1.5,

// Adventure-related variables
attackPerAnt: 2, // Attack value per ant
healthPerAnt: 10, // Health value per ant
Expand All @@ -67,7 +76,7 @@ export const useGameStore = defineStore('gameStore', {
// Calculate larvae production per second for real-time updates
larvaePerSecond: (state) => (state.queens * state.larvaeProductionRate) / 60,
// Calculate seed production per second based on ants
seedsPerSecond: (state) => (state.collectionRatePerAnt * state.ants) / 60,
seedsPerSecond: (state) => (state.collectionRatePerAnt * state.ants * (state.eliteAnts * state.multiplierPerEliteAnt)) / 60,
},

actions: {
Expand Down Expand Up @@ -111,6 +120,21 @@ export const useGameStore = defineStore('gameStore', {
this.ants += maxAntsToCreate
}
},
// Function to create ants using larvae and seeds
createEliteAnts() {
if (this.larvae >= this.larvaCostPerEliteAnt && this.seeds >= this.seedCostPerEliteAnt && this.eliteAnts < this.maxEliteAnts) {
this.eliteAnts += 1
this.larvae -= this.larvaCostPerEliteAnt
this.seeds -= this.seedCostPerEliteAnt
return true
}

return false
},
// Create max ants based on available larvae and seeds
createEliteMaxAnts() {
while (this.createEliteAnts()) {}
},
// Function to buy more queens
buyQueen() {
if (this.ants >= this.antCostPerQueen && this.seeds >= this.seedCostPerQueen && this.queens < this.maxQueens) {
Expand Down Expand Up @@ -446,12 +470,14 @@ export const useGameStore = defineStore('gameStore', {
const prestigeStore = usePrestigeStore()
return {
ants: this.ants,
eliteAnts: this.eliteAnts,
seeds: this.seeds,
queens: this.queens,
larvae: this.larvae,
maxSeeds: this.maxSeeds,
maxLarvae: this.maxLarvae,
maxAnts: this.maxAnts,
maxEliteAnts: this.maxEliteAnts,
maxQueens: this.maxQueens,
seedStorageUpgradeCost: this.seedStorageUpgradeCost,
larvaeStorageUpgradeCost: this.larvaeStorageUpgradeCost,
Expand Down Expand Up @@ -519,12 +545,14 @@ export const useGameStore = defineStore('gameStore', {

loadStateFromFirebase(savedState) {
this.ants = savedState.ants ?? this.ants
this.eliteAnts = savedState.eliteAnts ?? this.eliteAnts
this.seeds = savedState.seeds ?? this.seeds
this.queens = savedState.queens ?? this.queens
this.larvae = savedState.larvae ?? this.larvae
this.maxSeeds = savedState.maxSeeds ?? this.maxSeeds
this.maxLarvae = savedState.maxLarvae ?? this.maxLarvae
this.maxAnts = savedState.maxAnts ?? this.maxAnts
this.maxEliteAnts = savedState.maxEliteAnts ?? this.maxEliteAnts
this.maxQueens = savedState.maxQueens ?? this.maxQueens
this.seedStorageUpgradeCost = savedState.seedStorageUpgradeCost ?? this.seedStorageUpgradeCost
this.larvaeStorageUpgradeCost = savedState.larvaeStorageUpgradeCost ?? this.larvaeStorageUpgradeCost
Expand All @@ -537,6 +565,8 @@ export const useGameStore = defineStore('gameStore', {

const prestigeStore = usePrestigeStore()
prestigeStore.loadPrestigeState(savedState)

this.eliteAntsUnlocked = prestigeStore.upgradePurchased('eliteAnts')
},

async loadOtherStoreStates() {
Expand Down Expand Up @@ -594,13 +624,15 @@ export const useGameStore = defineStore('gameStore', {
this.ants = 0
this.seeds = 10
this.queens = 1
this.eliteAnts = 0

this.larvaeProductionRate = 1
this.collectionRatePerAnt = 60

this.maxSeeds = this.initialMaxSeeds
this.maxLarvae = this.initialMaxLarvae
this.maxAnts = this.initialMaxAnts
this.maxEliteAnts = this.initialMaxEliteAnts
this.maxQueens = this.initialMaxQueens

this.seedStorageUpgradeCost = 500
Expand All @@ -626,6 +658,7 @@ export const useGameStore = defineStore('gameStore', {
resetDebugState() {
const prestigeStore = usePrestigeStore()
prestigeStore.prestigePoints = 0
prestigeStore.timesPrestiged = 0
prestigeStore.purchasedUpgrades = []

this.healthPerAnt = 10
Expand Down
79 changes: 68 additions & 11 deletions src/stores/prestigeStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {defineStore} from 'pinia'
import {useGameStore} from './gameStore'
import {useInventoryStore} from './inventoryStore'
import {useToast} from 'vue-toast-notification'


interface PrestigeShopItem {
Expand All @@ -10,7 +11,8 @@ interface PrestigeShopItem {
cost: number
oneTimePurchase?: boolean
applyOnPrestige?: boolean
category?: 'auto' | 'production' | 'storage' | 'combat' | 'expansion'
category?: 'auto' | 'production' | 'storage' | 'combat' | 'expansion',
unlockedWhen?: () => boolean // Function to determine if the upgrade is unlocked
}

export const usePrestigeStore = defineStore('prestige', {
Expand Down Expand Up @@ -58,7 +60,15 @@ export const usePrestigeStore = defineStore('prestige', {
{
id: 'betterAnts',
name: 'Stronger Ants',
description: 'Increase ant strength by 10%',
description: 'Increase ants army strength by 10%',
cost: 50,
applyOnPrestige: false,
category: 'combat',
},
{
id: 'betterAntsDefense',
name: 'Stronger Ants Defense',
description: 'Increase ants army defense by 10%',
cost: 50,
applyOnPrestige: false,
category: 'combat',
Expand All @@ -71,13 +81,36 @@ export const usePrestigeStore = defineStore('prestige', {
applyOnPrestige: true,
category: 'expansion',
},
{
id: 'eliteAnts',
name: 'Elite Ants',
description: 'Unlock elite ants',
cost: 2500,
applyOnPrestige: true,
oneTimePurchase: true,
category: 'expansion',
unlockedWhen: () => {
return usePrestigeStore().timesPrestiged >= 5
},
},
{
id: 'storageUpgrade',
name: 'Storage Upgrade',
description: 'Increase seed and larvae storage by 20% <br> Increase ant storage by 100% and queen storage by 50%',
cost: 5,
category: 'storage',
},
{
id: 'eliteAntsStoreUpgrade',
name: 'Elite Ants Store Upgrade',
description: 'Increase the amount of elite ants you can store by 100%',
cost: 100,
applyOnPrestige: false,
category: 'storage',
unlockedWhen: () => {
return usePrestigeStore().timesPrestiged >= 5
},
},
{
id: 'productionBoost',
name: 'Production Boost',
Expand Down Expand Up @@ -154,6 +187,11 @@ export const usePrestigeStore = defineStore('prestige', {
this.prestigePoints += earnedPrestigePoints
this.timesPrestiged += 1

if (this.timesPrestiged === 5) {
const $toast = useToast()
$toast.info('You have unlocked the Elite Ants upgrade in the prestige shop!')
}

// Reset the game state for prestige without deleting the Firestore doc
gameStore.resetLocalGameState({isDebug: false})

Expand Down Expand Up @@ -186,9 +224,10 @@ export const usePrestigeStore = defineStore('prestige', {
return false
},
buyMaxUpgrade(upgradeId: string): boolean {
while (this.buyUpgrade(upgradeId)) {}
while (this.buyUpgrade(upgradeId)) {
}

return true
return true
},
// Apply a purchased upgrade
applyPrestigeUpgrade(upgradeId, fromPrestige = false) {
Expand All @@ -210,6 +249,9 @@ export const usePrestigeStore = defineStore('prestige', {
gameStore.maxAnts *= 2 // Increase ant storage
gameStore.maxQueens *= 1.5 // Increase queen storage
},
eliteAntsStoreUpgrade: () => {
gameStore.maxEliteAnts *= 2 // Increase elite ant storage
},
productionBoost: () => {
gameStore.larvaeProductionRate *= 1.2
gameStore.collectionRatePerAnt *= 1.2
Expand All @@ -224,6 +266,10 @@ export const usePrestigeStore = defineStore('prestige', {
gameStore.attackPerAnt *= 1.1
gameStore.setupAdventureStats()
},
betterAntsDefense: () => {
gameStore.defensePerAnt *= 1.1
gameStore.setupAdventureStats()
},
autoAnts: () => {
this.autoAntCreation = true
},
Expand All @@ -237,6 +283,9 @@ export const usePrestigeStore = defineStore('prestige', {
gameStore.ants += 1
this.antsFromPrestigeShop += 1
},
eliteAnts: () => {
gameStore.eliteAntsUnlocked = true
},
}

// Execute the appropriate upgrade or log an error if the upgrade ID is invalid
Expand All @@ -258,23 +307,28 @@ export const usePrestigeStore = defineStore('prestige', {
getPrestigeState() {
return {
prestigePoints: this.prestigePoints,
timesPrestiged: this.timesPrestiged,
purchasedUpgrades: this.purchasedUpgrades,

storagePrestigeCost: this.prestigeShop.find(u => u.id === 'storageUpgrade')?.cost ?? 5,
eliteAntsStoreUpgradeCost: this.prestigeShop.find(u => u.id === 'eliteAntsStoreUpgrade')?.cost ?? 100,
productionPrestigeCost: this.prestigeShop.find(u => u.id === 'productionBoost')?.cost ?? 10,
queenPrestigeCost: this.prestigeShop.find(u => u.id === 'queenEfficiency')?.cost ?? 15,
betterAntsPrestigeCost: this.prestigeShop.find(u => u.id === 'betterAnts')?.cost ?? 50,
betterAntsDefensePrestigeCost: this.prestigeShop.find(u => u.id === 'betterAntsDefense')?.cost ?? 50,
startWithAntsPrestigeCost: this.prestigeShop.find(u => u.id === 'startWithAnts')?.cost ?? 15,

autoLarvaeCreation: this.autoLarvaeCreation,
autoAntCreation: this.autoAntCreation,
autoQueenCreation: this.autoQueenCreation,
autoSeedStorageUpgrade: this.autoSeedStorageUpgrade,
eliteAntsUnlocked: this.upgradePurchased('eliteAnts'),
}
},

loadPrestigeState(savedState) {
this.prestigePoints = savedState.prestigePoints ?? this.prestigePoints
this.timesPrestiged = savedState.timesPrestiged ?? this.timesPrestiged
this.purchasedUpgrades = savedState.purchasedUpgrades ?? this.purchasedUpgrades

this.autoLarvaeCreation = savedState.autoLarvaeCreation ?? this.autoLarvaeCreation
Expand All @@ -284,27 +338,30 @@ export const usePrestigeStore = defineStore('prestige', {

// Load prestige shop costs
this.prestigeShop.forEach(shop => {
if (shop.id === 'storageUpgrade') shop.cost = savedState.storagePrestigeCost
if (shop.id === 'productionBoost') shop.cost = savedState.productionPrestigeCost
if (shop.id === 'queenEfficiency') shop.cost = savedState.queenPrestigeCost
if (shop.id === 'betterAnts') shop.cost = savedState.betterAntsPrestigeCost
if (shop.id === 'startWithAnts') shop.cost = savedState.startWithAntsPrestigeCost
if (shop.id === 'storageUpgrade') shop.cost = savedState.storagePrestigeCost ?? 5
if (shop.id === 'eliteAntsStoreUpgrade') shop.cost = savedState.eliteAntsStoreUpgradeCost ?? 100
if (shop.id === 'productionBoost') shop.cost = savedState.productionPrestigeCost ?? 10
if (shop.id === 'queenEfficiency') shop.cost = savedState.queenPrestigeCost ?? 15
if (shop.id === 'betterAnts') shop.cost = savedState.betterAntsPrestigeCost ?? 50
if (shop.id === 'betterAntsDefense') shop.cost = savedState.betterAntsDefensePrestigeCost ?? 50
if (shop.id === 'startWithAnts') shop.cost = savedState.startWithAntsPrestigeCost ?? 15
})
},

resetPrestigeShopCosts() {
this.prestigeShop.forEach(shop => {
if (shop.id === 'storageUpgrade') shop.cost = 5
if (shop.id === 'eliteAntsStoreUpgrade') shop.cost = 100
if (shop.id === 'productionBoost') shop.cost = 10
if (shop.id === 'queenEfficiency') shop.cost = 15
if (shop.id === 'autoLarvae') shop.cost = 10
if (shop.id === 'betterAnts') shop.cost = 50
if (shop.id === 'betterAntsDefense') shop.cost = 50
if (shop.id === 'autoAnts') shop.cost = 20
if (shop.id === 'autoQueens') shop.cost = 20
if (shop.id === 'startWithAnts') shop.cost = 15
if (shop.id === 'eliteAnts') shop.cost = 2500
})
},


},
})
51 changes: 50 additions & 1 deletion src/views/AntResources.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br>
I will be adding more features and balancing the game over time.
<br>
Also, any progress made may be reset at any time.
Also, any progress made may be reset at any time during current development stage.
</p>
<div class="grid sm:grid-cols-2 lg:grid-cols-3 grid-cols-1 gap-4 p-4">
<!-- Seeds Section -->
Expand Down Expand Up @@ -240,6 +240,55 @@
</div>
</div>

<!-- Elite Ant Section -->
<div
v-if="gameStore.eliteAntsUnlocked"
class="bg-white bg-opacity-50 p-4 rounded-lg shadow-md flex flex-col space-y-2"
>
<div>
<p class="font-bold text-lg">
Elite Ants
</p>
<p class="text-2xs">
Elite Ants help the ants to collect resources faster.
</p>
</div>
<div class="flex flex-wrap items-start justify-between w-full space-y-2">
<div class="flex flex-col gap-2 w-full">
<p class="text-sm">
Count: {{ formatNumber(gameStore.eliteAnts, 0) }}/{{ formatNumber(gameStore.maxEliteAnts, 0) }}
</p>
</div>
<div class="w-full flex flex-wrap gap-2">
<button
:disabled="gameStore.larvae < gameStore.larvaCostPerEliteAnt || gameStore.seeds < gameStore.seedCostPerEliteAnt"
class="flex-1 bg-blue-500 hover:bg-blue-600 text-white px-2 py-1 rounded shadow disabled:bg-gray-400 disabled:cursor-not-allowed text-xs"
@click="gameStore.createEliteAnts"
>
Create Ant <br>({{ formatNumber(gameStore.seedCostPerEliteAnt) }} seeds, {{
formatNumber(gameStore.larvaCostPerEliteAnt)
}} larvae)
</button>
<button
:disabled="gameStore.larvae < gameStore.larvaCostPerEliteAnt || gameStore.seeds < gameStore.seedCostPerEliteAnt"
class="flex-1 bg-green-500 hover:bg-green-600 text-white px-2 py-1 rounded shadow disabled:bg-gray-400 disabled:cursor-not-allowed text-xs"
@click="gameStore.createEliteMaxAnts()"
>
Max
</button>
</div>
</div>
</div>
<div
v-else
v-tooltip="'Maybe it has something to do with how many times we\'ve prestiged?'"
class="bg-gray-300 bg-opacity-50 p-4 rounded-lg shadow-md flex flex-col justify-center items-center select-none"
>
<h2>
LOCKED
</h2>
</div>

<!-- Queen Section -->
<div class="bg-white bg-opacity-50 p-4 rounded-lg shadow-md flex flex-col space-y-2">
<div>
Expand Down
Loading

0 comments on commit 1914e44

Please sign in to comment.