332 lines
9.4 KiB
JavaScript
332 lines
9.4 KiB
JavaScript
/**
|
|
* CITY GRATITUDE GIFT SYSTEM
|
|
* Population milestone rewards
|
|
* Unique equipment and bonuses
|
|
*/
|
|
|
|
export class CityGratitudeSystem {
|
|
constructor(scene) {
|
|
this.scene = scene;
|
|
|
|
// Milestone tracking
|
|
this.milestones = new Map();
|
|
this.claimedMilestones = new Set();
|
|
|
|
// City reputation
|
|
this.reputation = 0;
|
|
|
|
this.init();
|
|
}
|
|
|
|
init() {
|
|
this.initializeMilestones();
|
|
|
|
// Check milestones when population changes
|
|
this.scene.events.on('population_changed', () => this.checkMilestones());
|
|
}
|
|
|
|
/**
|
|
* Initialize population milestones
|
|
*/
|
|
initializeMilestones() {
|
|
this.registerMilestone({
|
|
population: 10,
|
|
name: 'Small Community',
|
|
rewards: {
|
|
items: [{ id: 'starter_hoe', name: 'Community Hoe', rarity: 'uncommon' }],
|
|
currency: 500,
|
|
reputation: 50
|
|
},
|
|
description: '10 settlers joined your farm!'
|
|
});
|
|
|
|
this.registerMilestone({
|
|
population: 25,
|
|
name: 'Growing Village',
|
|
rewards: {
|
|
items: [
|
|
{ id: 'village_axe', name: 'Village Axe', rarity: 'rare' },
|
|
{ id: 'mayor_blessing', name: 'Mayor\'s Blessing', rarity: 'rare', type: 'buff' }
|
|
],
|
|
currency: 1500,
|
|
reputation: 100,
|
|
unlock: 'town_hall'
|
|
},
|
|
description: '25 settlers! The village recognizes your leadership.'
|
|
});
|
|
|
|
this.registerMilestone({
|
|
population: 50,
|
|
name: 'Thriving Town',
|
|
rewards: {
|
|
items: [
|
|
{ id: 'master_scythe', name: 'Master Scythe', rarity: 'epic' },
|
|
{ id: 'town_armor', name: 'Town Guardian Armor', rarity: 'epic' }
|
|
],
|
|
currency: 5000,
|
|
reputation: 250,
|
|
unlock: 'advanced_workshop'
|
|
},
|
|
description: '50 settlers! Your town flourishes.'
|
|
});
|
|
|
|
this.registerMilestone({
|
|
population: 100,
|
|
name: 'Major City',
|
|
rewards: {
|
|
items: [
|
|
{ id: 'legendary_pickaxe', name: 'Pickaxe of Prosperity', rarity: 'legendary' },
|
|
{ id: 'city_crown', name: 'Crown of the People', rarity: 'legendary' },
|
|
{ id: 'citizens_gratitude', name: 'Citizens\' Eternal Gratitude', rarity: 'legendary', type: 'permanent_buff' }
|
|
],
|
|
currency: 15000,
|
|
reputation: 500,
|
|
unlock: 'city_monument'
|
|
},
|
|
description: '100 settlers! You\'ve built a magnificent city!'
|
|
});
|
|
|
|
this.registerMilestone({
|
|
population: 200,
|
|
name: 'Metropolis',
|
|
rewards: {
|
|
items: [
|
|
{ id: 'omega_tool_set', name: 'Omega Tool Set', rarity: 'mythic' },
|
|
{ id: 'metropolis_throne', name: 'Throne of Dominion', rarity: 'mythic' }
|
|
],
|
|
currency: 50000,
|
|
reputation: 1000,
|
|
unlock: 'palace',
|
|
specialBonus: 'All workers +100% efficiency'
|
|
},
|
|
description: '200 settlers! Your metropolis is legendary!'
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Register a milestone
|
|
*/
|
|
registerMilestone(milestoneData) {
|
|
this.milestones.set(milestoneData.population, {
|
|
...milestoneData,
|
|
claimed: false
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Check if any milestones reached
|
|
*/
|
|
checkMilestones() {
|
|
const currentPopulation = this.scene.gameState?.population || 0;
|
|
|
|
this.milestones.forEach((milestone, requiredPop) => {
|
|
if (currentPopulation >= requiredPop && !this.claimedMilestones.has(requiredPop)) {
|
|
this.triggerMilestone(requiredPop);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Trigger milestone reward
|
|
*/
|
|
triggerMilestone(population) {
|
|
const milestone = this.milestones.get(population);
|
|
if (!milestone) return;
|
|
|
|
// Mark as claimed
|
|
this.claimedMilestones.add(population);
|
|
milestone.claimed = true;
|
|
|
|
// Grant rewards
|
|
this.grantRewards(milestone.rewards);
|
|
|
|
// Special bonuses
|
|
if (milestone.specialBonus) {
|
|
this.applySpecialBonus(milestone.specialBonus);
|
|
}
|
|
|
|
// Reputation
|
|
this.reputation += milestone.rewards.reputation || 0;
|
|
|
|
// Cinematic notification
|
|
this.scene.uiSystem?.showMilestoneNotification(
|
|
milestone.name,
|
|
milestone.description,
|
|
milestone.rewards
|
|
);
|
|
|
|
// VFX: Celebration
|
|
this.scene.vfxSystem?.playEffect('city_celebration', 400, 300);
|
|
this.scene.cameras.main.flash(2000, 255, 215, 0);
|
|
|
|
// SFX
|
|
this.scene.soundSystem?.play('milestone_fanfare');
|
|
|
|
console.log(`🎉 MILESTONE REACHED: ${milestone.name} (${population} population)`);
|
|
}
|
|
|
|
/**
|
|
* Grant milestone rewards
|
|
*/
|
|
grantRewards(rewards) {
|
|
// Currency
|
|
if (rewards.currency) {
|
|
this.scene.economySystem?.addCurrency(rewards.currency);
|
|
console.log(`+${rewards.currency} coins`);
|
|
}
|
|
|
|
// Items
|
|
if (rewards.items) {
|
|
rewards.items.forEach(item => {
|
|
this.scene.inventorySystem?.addItem(item.id, 1);
|
|
console.log(`Received: ${item.name} (${item.rarity})`);
|
|
|
|
// Special item effects
|
|
if (item.type === 'buff') {
|
|
this.applyItemBuff(item);
|
|
} else if (item.type === 'permanent_buff') {
|
|
this.applyPermanentBuff(item);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Unlocks
|
|
if (rewards.unlock) {
|
|
this.scene.gameState.unlocks[rewards.unlock] = true;
|
|
console.log(`Unlocked: ${rewards.unlock}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Apply item buff
|
|
*/
|
|
applyItemBuff(item) {
|
|
switch (item.id) {
|
|
case 'mayor_blessing':
|
|
this.scene.gameState.buffs.mayor_blessing = {
|
|
crop_yield: 1.25,
|
|
building_speed: 1.25,
|
|
duration: Infinity // Permanent
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Apply permanent buff
|
|
*/
|
|
applyPermanentBuff(item) {
|
|
switch (item.id) {
|
|
case 'citizens_gratitude':
|
|
// Permanent +25% to all production
|
|
this.scene.gameState.buffs.citizens_gratitude = {
|
|
all_production: 1.25,
|
|
all_efficiency: 1.25
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Apply special bonus
|
|
*/
|
|
applySpecialBonus(bonus) {
|
|
if (bonus === 'All workers +100% efficiency') {
|
|
this.scene.npcSettlementSystem?.settledNPCs.forEach((npc, npcId) => {
|
|
const currentEff = this.scene.npcSettlementSystem.npcEfficiency.get(npcId) || 1.0;
|
|
this.scene.npcSettlementSystem.npcEfficiency.set(npcId, currentEff * 2.0);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get next milestone
|
|
*/
|
|
getNextMilestone() {
|
|
const currentPopulation = this.scene.gameState?.population || 0;
|
|
|
|
for (const [reqPop, milestone] of this.milestones.entries()) {
|
|
if (reqPop > currentPopulation) {
|
|
return {
|
|
population: reqPop,
|
|
...milestone,
|
|
progress: Math.min(100, (currentPopulation / reqPop) * 100)
|
|
};
|
|
}
|
|
}
|
|
|
|
return null; // All milestones claimed
|
|
}
|
|
|
|
/**
|
|
* Get all milestones
|
|
*/
|
|
getAllMilestones() {
|
|
return Array.from(this.milestones.entries()).map(([pop, milestone]) => ({
|
|
population: pop,
|
|
...milestone,
|
|
claimed: this.claimedMilestones.has(pop)
|
|
}));
|
|
}
|
|
|
|
/**
|
|
* Get claimed milestones
|
|
*/
|
|
getClaimedMilestones() {
|
|
return this.getAllMilestones().filter(m => m.claimed);
|
|
}
|
|
|
|
/**
|
|
* Get city reputation
|
|
*/
|
|
getReputation() {
|
|
return this.reputation;
|
|
}
|
|
|
|
/**
|
|
* Get reputation tier
|
|
*/
|
|
getReputationTier() {
|
|
if (this.reputation >= 1000) return 'Legendary';
|
|
if (this.reputation >= 500) return 'Renowned';
|
|
if (this.reputation >= 250) return 'Well-Known';
|
|
if (this.reputation >= 100) return 'Respected';
|
|
if (this.reputation >= 50) return 'Known';
|
|
return 'Unknown';
|
|
}
|
|
|
|
/**
|
|
* Manual milestone trigger (for testing)
|
|
*/
|
|
triggerMilestoneManual(population) {
|
|
if (!this.claimedMilestones.has(population)) {
|
|
this.triggerMilestone(population);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save/Load
|
|
*/
|
|
getSaveData() {
|
|
return {
|
|
claimedMilestones: Array.from(this.claimedMilestones),
|
|
reputation: this.reputation
|
|
};
|
|
}
|
|
|
|
loadSaveData(data) {
|
|
this.claimedMilestones = new Set(data.claimedMilestones || []);
|
|
this.reputation = data.reputation || 0;
|
|
|
|
// Mark milestones as claimed
|
|
this.claimedMilestones.forEach(pop => {
|
|
const milestone = this.milestones.get(pop);
|
|
if (milestone) {
|
|
milestone.claimed = true;
|
|
// Re-apply permanent buffs
|
|
this.grantRewards(milestone.rewards);
|
|
}
|
|
});
|
|
}
|
|
}
|