-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrades.js
More file actions
378 lines (337 loc) · 14 KB
/
upgrades.js
File metadata and controls
378 lines (337 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// Upgrades system
// Upgrade definitions
const UPGRADES = {
drillPower: {
name: "Drill Power",
description: "Increases drilling efficiency",
basePrice: 50,
priceMultiplier: 1.5,
maxLevel: 10,
effect: level => ({ drillPower: 1 + level * 0.5 }),
icon: "🔨"
},
drillSpeed: {
name: "Drill Speed",
description: "Decreases time between drilling operations",
basePrice: 100,
priceMultiplier: 1.6,
maxLevel: 10,
effect: level => ({ drillSpeed: 1000 - level * 75 }),
icon: "⚡"
},
energyCapacity: {
name: "Energy Capacity",
description: "Increases maximum energy",
basePrice: 75,
priceMultiplier: 1.4,
maxLevel: 10,
effect: level => ({ maxEnergy: 100 + level * 25 }),
icon: "🔋"
},
energyRecharge: {
name: "Energy Recharge",
description: "Increases energy recharge rate",
basePrice: 125,
priceMultiplier: 1.5,
maxLevel: 10,
effect: level => ({ energyRechargeRate: 0.5 + level * 0.2 }),
icon: "⚡"
},
storage: {
name: "Storage Capacity",
description: "Increases maximum storage capacity",
basePrice: 80,
priceMultiplier: 1.3,
maxLevel: 10,
effect: level => ({ maxStorage: 100 + level * 50 }),
icon: "📦"
},
drillDepth: {
name: "Drill Depth",
description: "Allows drilling deeper into the earth",
basePrice: 200,
priceMultiplier: 2,
maxLevel: 5,
effect: level => ({ maxDepth: 100 + level * 200 }),
icon: "🧭"
},
luckyDrill: {
name: "Lucky Drill",
description: "Increases chance of finding rare resources",
basePrice: 150,
priceMultiplier: 1.7,
maxLevel: 5,
effect: level => ({ luckyChance: level * 0.05 }),
icon: "🍀"
},
autoSell: {
name: "Auto-Seller",
description: "Automatically sells resources when storage is full",
basePrice: 300,
priceMultiplier: 2,
maxLevel: 1,
effect: level => ({ autoSell: level > 0 }),
icon: "💰"
},
doubleDrill: {
name: "Double Drill",
description: "Chance to get double resources when drilling",
basePrice: 250,
priceMultiplier: 1.8,
maxLevel: 5,
effect: level => ({ doubleChance: level * 0.1 }),
icon: "✌️"
},
rainbowDrill: {
name: "Rainbow Drill",
description: "Makes drilling more colorful and fun!",
basePrice: 100,
priceMultiplier: 1.3,
maxLevel: 3,
effect: level => ({ rainbowEffect: level }),
icon: "🌈"
},
treasureHunter: {
name: "Treasure Hunter",
description: "Chance to find special treasures while drilling",
basePrice: 500,
priceMultiplier: 2,
maxLevel: 3,
effect: level => ({ treasureChance: level * 0.02 }),
icon: "🗝️"
},
drillMaster: {
name: "Drill Master",
description: "Ultimate upgrade that boosts all drilling abilities",
basePrice: 1000,
priceMultiplier: 3,
maxLevel: 1,
effect: level => ({
drillPower: level > 0 ? 2 : 1,
energyRechargeRate: level > 0 ? 2 : 1,
luckyChance: level > 0 ? 0.1 : 0
}),
icon: "👑"
}
};
// Upgrade Manager class
class UpgradeManager {
constructor(resourceManager, gameManager) {
this.resourceManager = resourceManager;
this.gameManager = gameManager;
this.upgradeLevels = {};
// Initialize all upgrades at level 0
Object.keys(UPGRADES).forEach(upgrade => {
this.upgradeLevels[upgrade] = 0;
});
}
// Calculate price for the next level of an upgrade
getUpgradePrice(upgradeId) {
const upgrade = UPGRADES[upgradeId];
const currentLevel = this.upgradeLevels[upgradeId];
return Math.floor(upgrade.basePrice * Math.pow(upgrade.priceMultiplier, currentLevel));
}
// Purchase an upgrade
purchaseUpgrade(upgradeId) {
const upgrade = UPGRADES[upgradeId];
const currentLevel = this.upgradeLevels[upgradeId];
const price = this.getUpgradePrice(upgradeId);
// Check if max level reached
if (currentLevel >= upgrade.maxLevel) {
showNotification("Maximum level reached for this upgrade!", true);
return false;
}
// Check if player has enough money
if (this.resourceManager.money < price) {
showNotification("Not enough money for this upgrade!", true);
return false;
}
// Purchase the upgrade
this.resourceManager.money -= price;
this.upgradeLevels[upgradeId]++;
// Apply upgrade effects
this.applyUpgradeEffects();
// Update displays
this.resourceManager.updateDisplay();
this.updateUpgradesDisplay();
// Show notification
showNotification(`Upgraded ${upgrade.name} to level ${this.upgradeLevels[upgradeId]}!`);
// Play upgrade sound
if (window.gameManager && window.gameManager.soundEnabled) {
window.gameManager.playSound('upgrade');
}
// Add visual effects
if (window.gameManager && window.gameManager.visualEffectsEnabled) {
// Create particles at the upgrade button
const button = document.querySelector(`button[data-upgrade="${upgradeId}"]`);
if (button) {
const rect = button.getBoundingClientRect();
const canvasRect = window.gameManager.canvas.getBoundingClientRect();
const x = rect.left - canvasRect.left + rect.width / 2;
const y = rect.top - canvasRect.top + rect.height / 2;
window.gameManager.particleSystem.createStarParticles(x, y, 15);
// Add floating text
window.gameManager.addFloatingText(
`Level Up!`,
x,
y - 20,
'#4CAF50',
18
);
}
}
// Check if this was a storage upgrade and we were at max capacity
if (upgradeId === 'storage' && this.resourceManager.storage === this.resourceManager.maxStorage - 50) {
// We just upgraded storage, so update the display
this.resourceManager.updateDisplay();
}
return true;
}
// Apply all upgrade effects to the game
applyUpgradeEffects() {
// Reset to base values
this.gameManager.drillPower = 1;
this.gameManager.drillSpeed = 1000;
this.resourceManager.maxEnergy = 100;
this.resourceManager.maxStorage = 100;
this.gameManager.energyRechargeRate = 0.5;
this.gameManager.maxDepth = 100;
this.gameManager.luckyChance = 0;
this.gameManager.doubleChance = 0;
this.gameManager.autoSell = false;
this.gameManager.rainbowEffect = 0;
this.gameManager.treasureChance = 0;
// Apply all upgrade effects
Object.keys(this.upgradeLevels).forEach(upgradeId => {
const level = this.upgradeLevels[upgradeId];
if (level > 0) {
const effects = UPGRADES[upgradeId].effect(level);
// Apply each effect
Object.keys(effects).forEach(effect => {
if (effect === 'maxEnergy' || effect === 'maxStorage') {
this.resourceManager[effect] = effects[effect];
} else {
this.gameManager[effect] = effects[effect];
}
});
}
});
// Make sure energy doesn't exceed max after upgrade
if (this.resourceManager.energy > this.resourceManager.maxEnergy) {
this.resourceManager.energy = this.resourceManager.maxEnergy;
}
// Update the UI to reflect the new values
this.updateUpgradeEffectsDisplay();
}
// Update the display to show active upgrade effects
updateUpgradeEffectsDisplay() {
// Update any UI elements that need to reflect the current upgrade state
// For example, if we want to show the auto-sell status somewhere
// We'll keep this minimal to avoid cluttering the UI
}
// Update the upgrades display
updateUpgradesDisplay() {
const upgradesList = document.getElementById("upgrades-list");
upgradesList.innerHTML = "";
// Sort upgrades by price
const sortedUpgrades = Object.keys(UPGRADES).sort((a, b) => {
const priceA = this.getUpgradePrice(a);
const priceB = this.getUpgradePrice(b);
return priceA - priceB;
});
sortedUpgrades.forEach(upgradeId => {
const upgrade = UPGRADES[upgradeId];
const currentLevel = this.upgradeLevels[upgradeId] || 0;
const price = this.getUpgradePrice(upgradeId);
const maxReached = currentLevel >= upgrade.maxLevel;
// Check if player can afford this upgrade - FIXED: Force re-evaluation
const canAfford = this.resourceManager.money >= price;
const item = document.createElement("div");
item.className = `upgrade-item ${maxReached ? 'max-level' : ''} ${canAfford && !maxReached ? 'can-afford' : ''}`;
// Create effect description
let effectDesc = "";
const effects = upgrade.effect(currentLevel + 1);
// Create simplified effect description
Object.keys(effects).forEach(effect => {
switch(effect) {
case 'drillPower':
effectDesc += `Drill power: +${(effects[effect] - 1) * 100}%`;
break;
case 'drillSpeed':
effectDesc += `Drill speed: ${Math.floor(1000 / effects[effect] * 100) / 100}/s`;
break;
case 'maxEnergy':
effectDesc += `Energy: ${effects[effect]}`;
break;
case 'energyRechargeRate':
effectDesc += `Recharge: ${effects[effect]}/s`;
break;
case 'maxStorage':
effectDesc += `Storage: ${effects[effect]}`;
break;
case 'maxDepth':
effectDesc += `Depth: ${effects[effect]}m`;
break;
case 'luckyChance':
effectDesc += `Lucky: +${effects[effect] * 100}%`;
break;
case 'doubleChance':
effectDesc += `Double: ${effects[effect] * 100}%`;
break;
case 'treasureChance':
effectDesc += `Treasure: ${effects[effect] * 100}%`;
break;
case 'autoSell':
effectDesc += effects[effect] ? `Auto-sell` : '';
break;
case 'rainbowEffect':
effectDesc += effects[effect] > 0 ? `Rainbow drill` : '';
break;
default:
// Skip showing this effect
}
});
item.innerHTML = `
<div class="upgrade-info">
<div class="upgrade-header">
<span class="upgrade-icon">${upgrade.icon || '🔧'}</span>
<strong>${upgrade.name}</strong>
<span class="upgrade-level">Level ${currentLevel}/${upgrade.maxLevel}</span>
</div>
<p>${upgrade.description}</p>
<div class="upgrade-effect">${effectDesc}</div>
</div>
<button data-upgrade="${upgradeId}" ${maxReached || !canAfford ? 'disabled' : ''} class="${maxReached ? 'max' : !canAfford ? 'cant-afford' : ''}">
${maxReached ? 'MAX' : `Upgrade ($${price})`}
</button>
`;
upgradesList.appendChild(item);
// Add event listener to the button - FIXED: Use direct function reference
const button = item.querySelector(`button[data-upgrade="${upgradeId}"]`);
if (button) {
button.addEventListener('click', () => {
this.purchaseUpgrade(upgradeId);
});
// FIXED: Make sure button is properly enabled/disabled based on current money
button.disabled = maxReached || !canAfford;
}
// Add hover effect
item.addEventListener('mouseenter', () => {
if (!maxReached && canAfford) {
item.classList.add('hover');
// Add sparkle effect
if (window.gameManager && window.gameManager.visualEffectsEnabled) {
const rect = item.getBoundingClientRect();
const canvasRect = window.gameManager.canvas.getBoundingClientRect();
const x = rect.left - canvasRect.left + rect.width / 2;
const y = rect.top - canvasRect.top + rect.height / 2;
window.gameManager.particleSystem.createStarParticles(x, y, 5);
}
}
});
item.addEventListener('mouseleave', () => {
item.classList.remove('hover');
});
});
}
}