📚 DOCUMENTATION COMPLETE: AUDIO_ASSET_MANIFEST.md (61 files detailed) and VFX_IMPLEMENTATION_GUIDE.md (6 systems with code examples). Ready for asset production phase.
This commit is contained in:
331
src/systems/CityGratitudeSystem.js
Normal file
331
src/systems/CityGratitudeSystem.js
Normal file
@@ -0,0 +1,331 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
341
src/systems/NPCSettlementSystem.js
Normal file
341
src/systems/NPCSettlementSystem.js
Normal file
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
* NPC SETTLEMENT SYSTEM (Magic Helpers)
|
||||
* NPCs auto-assist with tasks
|
||||
* Worker efficiency, happiness, housing
|
||||
*/
|
||||
|
||||
export class NPCSettlementSystem {
|
||||
constructor(scene) {
|
||||
this.scene = scene;
|
||||
|
||||
// Settled NPCs
|
||||
this.settledNPCs = new Map();
|
||||
|
||||
// Worker assignments
|
||||
this.assignments = new Map(); // npcId → task
|
||||
|
||||
// NPC stats
|
||||
this.npcHappiness = new Map(); // npcId → happiness (0-100)
|
||||
this.npcEfficiency = new Map(); // npcId → efficiency (0.5-2.0)
|
||||
|
||||
// Housing
|
||||
this.npcHomes = new Map(); // npcId → buildingId
|
||||
this.housingCapacity = 0;
|
||||
|
||||
// Task types
|
||||
this.taskTypes = ['farming', 'building', 'crafting', 'defense', 'gathering'];
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
// Update worker tasks periodically
|
||||
this.scene.time.addEvent({
|
||||
delay: 5000, // Every 5s
|
||||
callback: () => this.updateWorkers(),
|
||||
loop: true
|
||||
});
|
||||
|
||||
// Update happiness hourly
|
||||
this.scene.time.addEvent({
|
||||
delay: 3600000, // 1 hour
|
||||
callback: () => this.updateHappiness(),
|
||||
loop: true
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Settle an NPC (they join the town)
|
||||
*/
|
||||
settleNPC(npcId, npcData) {
|
||||
if (this.settledNPCs.has(npcId)) return false;
|
||||
|
||||
//Check housing availability
|
||||
if (this.settledNPCs.size >= this.housingCapacity) {
|
||||
console.warn('No housing available');
|
||||
return false;
|
||||
}
|
||||
|
||||
this.settledNPCs.set(npcId, {
|
||||
id: npcId,
|
||||
name: npcData.name,
|
||||
skills: npcData.skills || [],
|
||||
assignedTask: null,
|
||||
...npcData
|
||||
});
|
||||
|
||||
// Initial stats
|
||||
this.npcHappiness.set(npcId, 75); // Start at 75% happiness
|
||||
this.npcEfficiency.set(npcId, 1.0); // Base efficiency
|
||||
|
||||
// Notification
|
||||
this.scene.uiSystem?.showNotification(
|
||||
`${npcData.name} has joined the settlement!`,
|
||||
'success',
|
||||
{ icon: 'npc_join' }
|
||||
);
|
||||
|
||||
console.log(`🏘️ ${npcData.name} settled in town`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign NPC to task
|
||||
*/
|
||||
assignTask(npcId, taskType, taskData) {
|
||||
const npc = this.settledNPCs.get(npcId);
|
||||
if (!npc) return false;
|
||||
|
||||
// Check if NPC has skill for task
|
||||
if (!npc.skills.includes(taskType)) {
|
||||
console.warn(`${npc.name} lacks skill: ${taskType}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assign
|
||||
npc.assignedTask = taskType;
|
||||
this.assignments.set(npcId, {
|
||||
type: taskType,
|
||||
data: taskData,
|
||||
startTime: Date.now()
|
||||
});
|
||||
|
||||
console.log(`👷 ${npc.name} assigned to ${taskType}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign NPC from task
|
||||
*/
|
||||
unassignTask(npcId) {
|
||||
const npc = this.settledNPCs.get(npcId);
|
||||
if (!npc) return false;
|
||||
|
||||
npc.assignedTask = null;
|
||||
this.assignments.delete(npcId);
|
||||
|
||||
console.log(`${npc.name} unassigned`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all worker tasks
|
||||
*/
|
||||
updateWorkers() {
|
||||
this.assignments.forEach((assignment, npcId) => {
|
||||
const npc = this.settledNPCs.get(npcId);
|
||||
const efficiency = this.npcEfficiency.get(npcId) || 1.0;
|
||||
|
||||
switch (assignment.type) {
|
||||
case 'farming':
|
||||
this.performFarming(npc, efficiency, assignment.data);
|
||||
break;
|
||||
case 'building':
|
||||
this.performBuilding(npc, efficiency, assignment.data);
|
||||
break;
|
||||
case 'crafting':
|
||||
this.performCrafting(npc, efficiency, assignment.data);
|
||||
break;
|
||||
case 'defense':
|
||||
this.performDefense(npc, efficiency);
|
||||
break;
|
||||
case 'gathering':
|
||||
this.performGathering(npc, efficiency);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* WORKER TASKS
|
||||
*/
|
||||
|
||||
performFarming(npc, efficiency, data) {
|
||||
// Auto-tend crops
|
||||
const crops = this.scene.crops || [];
|
||||
const tendsPerCycle = Math.floor(2 * efficiency);
|
||||
|
||||
for (let i = 0; i < tendsPerCycle && i < crops.length; i++) {
|
||||
const crop = crops[i];
|
||||
crop.water?.();
|
||||
crop.fertilize?.();
|
||||
}
|
||||
|
||||
// Chance to auto-harvest
|
||||
if (Math.random() < 0.1 * efficiency) {
|
||||
const harvestable = crops.find(c => c.isHarvestable);
|
||||
if (harvestable) {
|
||||
this.scene.farmingSystem?.harvestCrop(harvestable);
|
||||
console.log(`${npc.name} harvested crop`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
performBuilding(npc, efficiency, data) {
|
||||
// Speed up construction
|
||||
const building = data.buildingId ? this.scene.buildingSystem?.getBuilding(data.buildingId) : null;
|
||||
|
||||
if (building && building.isUnderConstruction) {
|
||||
const progressBonus = 5 * efficiency;
|
||||
building.constructionProgress += progressBonus;
|
||||
|
||||
if (building.constructionProgress >= 100) {
|
||||
this.scene.buildingSystem?.completeConstruction(building.id);
|
||||
console.log(`${npc.name} completed building: ${building.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
performCrafting(npc, efficiency, data) {
|
||||
// Auto-craft items
|
||||
if (data.recipe) {
|
||||
const canCraft = this.scene.craftingSystem?.canCraft(data.recipe);
|
||||
if (canCraft && Math.random() < 0.2 * efficiency) {
|
||||
this.scene.craftingSystem?.craft(data.recipe);
|
||||
console.log(`${npc.name} crafted ${data.recipe}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
performDefense(npc, efficiency) {
|
||||
// Patrol and defend
|
||||
// Increased detection range for raids
|
||||
this.scene.gameState.buffs.raid_detection_range = (this.scene.gameState.buffs.raid_detection_range || 1.0) + (0.1 * efficiency);
|
||||
|
||||
// Auto-repair walls/defenses
|
||||
const defenses = this.scene.defenseSystem?.getAllDefenses() || [];
|
||||
defenses.forEach(defense => {
|
||||
if (defense.health < defense.maxHealth && Math.random() < 0.05 * efficiency) {
|
||||
defense.health = Math.min(defense.maxHealth, defense.health + 10);
|
||||
console.log(`${npc.name} repaired ${defense.name}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
performGathering(npc, efficiency) {
|
||||
// Auto-gather resources
|
||||
const gatherChance = 0.15 * efficiency;
|
||||
|
||||
if (Math.random() < gatherChance) {
|
||||
const resources = ['wood', 'stone', 'berries', 'herbs'];
|
||||
const resource = Phaser.Utils.Array.GetRandom(resources);
|
||||
const amount = Math.floor(Phaser.Math.Between(1, 3) * efficiency);
|
||||
|
||||
this.scene.inventorySystem?.addItem(resource, amount);
|
||||
console.log(`${npc.name} gathered ${amount} ${resource}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update NPC happiness
|
||||
*/
|
||||
updateHappiness() {
|
||||
this.settledNPCs.forEach((npc, npcId) => {
|
||||
let happiness = this.npcHappiness.get(npcId) || 50;
|
||||
|
||||
// Factors affecting happiness
|
||||
const hasHome = this.npcHomes.has(npcId);
|
||||
const hasTask = npc.assignedTask !== null;
|
||||
const isOverworked = hasTask && this.assignments.get(npcId)?.overworked;
|
||||
|
||||
// Adjustments
|
||||
if (hasHome) happiness += 5;
|
||||
if (hasTask) happiness += 2;
|
||||
if (isOverworked) happiness -= 10;
|
||||
if (!hasHome && this.settledNPCs.size > this.housingCapacity) happiness -= 15;
|
||||
|
||||
// Natural decay
|
||||
happiness -= 1;
|
||||
|
||||
// Clamp
|
||||
happiness = Math.max(0, Math.min(100, happiness));
|
||||
this.npcHappiness.set(npcId, happiness);
|
||||
|
||||
// Update efficiency based on happiness
|
||||
const efficiency = 0.5 + (happiness / 100) * 1.5; // 0.5-2.0
|
||||
this.npcEfficiency.set(npcId, efficiency);
|
||||
|
||||
// Low happiness warning
|
||||
if (happiness < 30) {
|
||||
this.scene.uiSystem?.showNotification(
|
||||
`${npc.name} is unhappy!`,
|
||||
'warning'
|
||||
);
|
||||
console.warn(`${npc.name} happiness: ${happiness}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign NPC to home
|
||||
*/
|
||||
assignHome(npcId, buildingId) {
|
||||
this.npcHomes.set(npcId, buildingId);
|
||||
|
||||
// Happiness boost
|
||||
const happiness = this.npcHappiness.get(npcId) || 50;
|
||||
this.npcHappiness.set(npcId, Math.min(100, happiness + 20));
|
||||
|
||||
console.log(`${this.settledNPCs.get(npcId).name} moved into home`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase housing capacity
|
||||
*/
|
||||
addHousing(capacity) {
|
||||
this.housingCapacity += capacity;
|
||||
console.log(`Housing capacity: ${this.housingCapacity}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settlement statistics
|
||||
*/
|
||||
getSettlementStats() {
|
||||
const npcs = Array.from(this.settledNPCs.values());
|
||||
const avgHappiness = npcs.reduce((sum, npc) => sum + (this.npcHappiness.get(npc.id) || 0), 0) / npcs.length || 0;
|
||||
const avgEfficiency = npcs.reduce((sum, npc) => sum + (this.npcEfficiency.get(npc.id) || 1), 0) / npcs.length || 1;
|
||||
|
||||
return {
|
||||
population: npcs.length,
|
||||
housingCapacity: this.housingCapacity,
|
||||
averageHappiness: Math.round(avgHappiness),
|
||||
averageEfficiency: avgEfficiency.toFixed(2),
|
||||
assignedWorkers: this.assignments.size,
|
||||
unemployed: npcs.length - this.assignments.size
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NPCs by skill
|
||||
*/
|
||||
getNPCsBySkill(skill) {
|
||||
return Array.from(this.settledNPCs.values()).filter(npc => npc.skills.includes(skill));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save/Load
|
||||
*/
|
||||
getSaveData() {
|
||||
return {
|
||||
settledNPCs: Array.from(this.settledNPCs.entries()),
|
||||
assignments: Array.from(this.assignments.entries()),
|
||||
npcHappiness: Array.from(this.npcHappiness.entries()),
|
||||
npcHomes: Array.from(this.npcHomes.entries()),
|
||||
housingCapacity: this.housingCapacity
|
||||
};
|
||||
}
|
||||
|
||||
loadSaveData(data) {
|
||||
this.settledNPCs = new Map(data.settledNPCs || []);
|
||||
this.assignments = new Map(data.assignments || []);
|
||||
this.npcHappiness = new Map(data.npcHappiness || []);
|
||||
this.npcHomes = new Map(data.npcHomes || []);
|
||||
this.housingCapacity = data.housingCapacity || 0;
|
||||
|
||||
// Recalculate efficiency
|
||||
this.npcHappiness.forEach((happiness, npcId) => {
|
||||
const efficiency = 0.5 + (happiness / 100) * 1.5;
|
||||
this.npcEfficiency.set(npcId, efficiency);
|
||||
});
|
||||
}
|
||||
}
|
||||
316
src/systems/SchoolBuffSystem.js
Normal file
316
src/systems/SchoolBuffSystem.js
Normal file
@@ -0,0 +1,316 @@
|
||||
/**
|
||||
* SCHOOL BUFF SYSTEM
|
||||
* Learning skills from Teacher NPC
|
||||
* Temporary and permanent buffs
|
||||
*/
|
||||
|
||||
export class SchoolBuffSystem {
|
||||
constructor(scene) {
|
||||
this.scene = scene;
|
||||
|
||||
// Available lessons
|
||||
this.lessons = new Map();
|
||||
this.learnedSkills = new Set();
|
||||
|
||||
// Active buffs
|
||||
this.activeBuffs = new Map();
|
||||
|
||||
// Teacher NPC reference
|
||||
this.teacher = null;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.initializeLessons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all available lessons
|
||||
*/
|
||||
initializeLessons() {
|
||||
// FARMING LESSONS
|
||||
this.registerLesson({
|
||||
id: 'basic_farming',
|
||||
name: 'Basic Farming',
|
||||
category: 'farming',
|
||||
cost: 100,
|
||||
duration: 'permanent',
|
||||
description: '+10% crop yield',
|
||||
effect: () => this.scene.gameState.buffs.crop_yield = (this.scene.gameState.buffs.crop_yield || 1.0) * 1.1
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'advanced_farming',
|
||||
name: 'Advanced Farming',
|
||||
category: 'farming',
|
||||
cost: 500,
|
||||
requires: 'basic_farming',
|
||||
duration: 'permanent',
|
||||
description: '+20% crop growth speed',
|
||||
effect: () => this.scene.gameState.buffs.crop_growth_speed = (this.scene.gameState.buffs.crop_growth_speed || 1.0) * 1.2
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'fertilizer_mastery',
|
||||
name: 'Fertilizer Mastery',
|
||||
category: 'farming',
|
||||
cost: 300,
|
||||
duration: 'permanent',
|
||||
description: 'Fertilizer lasts 2x longer',
|
||||
effect: () => this.scene.gameState.buffs.fertilizer_duration = 2.0
|
||||
});
|
||||
|
||||
// COMBAT LESSONS
|
||||
this.registerLesson({
|
||||
id: 'basic_combat',
|
||||
name: 'Basic Combat',
|
||||
category: 'combat',
|
||||
cost: 200,
|
||||
duration: 'permanent',
|
||||
description: '+5 damage to all attacks',
|
||||
effect: () => this.scene.player.attackDamage += 5
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'defense_training',
|
||||
name: 'Defense Training',
|
||||
category: 'combat',
|
||||
cost: 400,
|
||||
duration: 'permanent',
|
||||
description: '+15% damage resistance',
|
||||
effect: () => this.scene.player.damageResistance = (this.scene.player.damageResistance || 0) + 0.15
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'weapon_mastery',
|
||||
name: 'Weapon Mastery',
|
||||
category: 'combat',
|
||||
cost: 800,
|
||||
requires: 'basic_combat',
|
||||
duration: 'permanent',
|
||||
description: '+20% critical hit chance',
|
||||
effect: () => this.scene.player.critChance = (this.scene.player.critChance || 0) + 0.2
|
||||
});
|
||||
|
||||
// SURVIVAL LESSONS
|
||||
this.registerLesson({
|
||||
id: 'herbalism',
|
||||
name: 'Herbalism',
|
||||
category: 'survival',
|
||||
cost: 250,
|
||||
duration: 'permanent',
|
||||
description: 'Healing items restore 50% more HP',
|
||||
effect: () => this.scene.gameState.buffs.healing_bonus = 1.5
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'scavenging',
|
||||
name: 'Scavenging',
|
||||
category: 'survival',
|
||||
cost: 350,
|
||||
duration: 'permanent',
|
||||
description: '+25% loot from containers',
|
||||
effect: () => this.scene.gameState.buffs.loot_bonus = 1.25
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'endurance',
|
||||
name: 'Endurance Training',
|
||||
category: 'survival',
|
||||
cost: 600,
|
||||
duration: 'permanent',
|
||||
description: '+20 max stamina',
|
||||
effect: () => this.scene.player.maxStamina += 20
|
||||
});
|
||||
|
||||
// TEMPORARY BUFFS (Study Sessions)
|
||||
this.registerLesson({
|
||||
id: 'focus_boost',
|
||||
name: 'Focus Boost',
|
||||
category: 'temporary',
|
||||
cost: 50,
|
||||
duration: 300000, // 5 minutes
|
||||
description: '+50% XP gain for 5 minutes',
|
||||
effect: () => this.applyTemporaryBuff('xp_boost', 1.5, 300000)
|
||||
});
|
||||
|
||||
this.registerLesson({
|
||||
id: 'energy_surge',
|
||||
name: 'Energy Surge',
|
||||
category: 'temporary',
|
||||
cost: 75,
|
||||
duration: 180000, // 3 minutes
|
||||
description: '+100% stamina regen for 3 minutes',
|
||||
effect: () => this.applyTemporaryBuff('stamina_regen', 2.0, 180000)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a lesson
|
||||
*/
|
||||
registerLesson(lessonData) {
|
||||
this.lessons.set(lessonData.id, {
|
||||
...lessonData,
|
||||
learned: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Learn a skill from Teacher
|
||||
*/
|
||||
learnSkill(lessonId) {
|
||||
const lesson = this.lessons.get(lessonId);
|
||||
if (!lesson) return false;
|
||||
|
||||
// Check if already learned (permanent skills only)
|
||||
if (lesson.duration === 'permanent' && lesson.learned) {
|
||||
console.warn(`Already learned: ${lesson.name}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check prerequisites
|
||||
if (lesson.requires && !this.learnedSkills.has(lesson.requires)) {
|
||||
const required = this.lessons.get(lesson.requires);
|
||||
console.warn(`Must learn ${required.name} first`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check cost
|
||||
const currency = this.scene.economySystem?.getCurrency() || 0;
|
||||
if (currency < lesson.cost) {
|
||||
console.warn(`Insufficient funds: need ${lesson.cost}, have ${currency}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pay cost
|
||||
this.scene.economySystem.addCurrency(-lesson.cost);
|
||||
|
||||
// Apply effect
|
||||
lesson.effect();
|
||||
|
||||
// Mark as learned
|
||||
if (lesson.duration === 'permanent') {
|
||||
lesson.learned = true;
|
||||
this.learnedSkills.add(lessonId);
|
||||
}
|
||||
|
||||
// Notification
|
||||
this.scene.uiSystem?.showNotification(
|
||||
`Learned: ${lesson.name}!`,
|
||||
'success',
|
||||
{ description: lesson.description }
|
||||
);
|
||||
|
||||
// Teacher dialogue
|
||||
this.scene.dialogueSystem?.startDialogue('teacher', 'lesson_complete', { skill: lesson.name });
|
||||
|
||||
console.log(`📚 Learned: ${lesson.name} (-${lesson.cost} coins)`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply temporary buff
|
||||
*/
|
||||
applyTemporaryBuff(buffId, multiplier, duration) {
|
||||
// Store buff
|
||||
this.activeBuffs.set(buffId, {
|
||||
multiplier,
|
||||
expiresAt: Date.now() + duration
|
||||
});
|
||||
|
||||
// VFX
|
||||
this.scene.vfxSystem?.playEffect('buff_applied', this.scene.player.x, this.scene.player.y);
|
||||
|
||||
// Remove after duration
|
||||
this.scene.time.delayedCall(duration, () => {
|
||||
this.activeBuffs.delete(buffId);
|
||||
this.scene.uiSystem?.showNotification(`${buffId} expired`, 'info');
|
||||
console.log(`⏱️ Buff expired: ${buffId}`);
|
||||
});
|
||||
|
||||
console.log(`✨ Applied buff: ${buffId} (${duration / 1000}s)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if buff is active
|
||||
*/
|
||||
hasActiveBuff(buffId) {
|
||||
const buff = this.activeBuffs.get(buffId);
|
||||
if (!buff) return false;
|
||||
|
||||
const now = Date.now();
|
||||
if (now > buff.expiresAt) {
|
||||
this.activeBuffs.delete(buffId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buff multiplier
|
||||
*/
|
||||
getBuffMultiplier(buffId) {
|
||||
const buff = this.activeBuffs.get(buffId);
|
||||
return buff ? buff.multiplier : 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lessons by category
|
||||
*/
|
||||
getLessonsByCategory(category) {
|
||||
return Array.from(this.lessons.values()).filter(l => l.category === category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available lessons (can be learned now)
|
||||
*/
|
||||
getAvailableLessons() {
|
||||
return Array.from(this.lessons.values()).filter(l => {
|
||||
if (l.duration === 'permanent' && l.learned) return false;
|
||||
if (l.requires && !this.learnedSkills.has(l.requires)) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get learned skills
|
||||
*/
|
||||
getLearnedSkills() {
|
||||
return Array.from(this.lessons.values()).filter(l => l.learned);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save/Load
|
||||
*/
|
||||
getSaveData() {
|
||||
return {
|
||||
learnedSkills: Array.from(this.learnedSkills),
|
||||
activeBuffs: Array.from(this.activeBuffs.entries())
|
||||
};
|
||||
}
|
||||
|
||||
loadSaveData(data) {
|
||||
this.learnedSkills = new Set(data.learnedSkills || []);
|
||||
|
||||
// Mark lessons as learned
|
||||
this.learnedSkills.forEach(skillId => {
|
||||
const lesson = this.lessons.get(skillId);
|
||||
if (lesson) {
|
||||
lesson.learned = true;
|
||||
lesson.effect(); // Re-apply permanent effects
|
||||
}
|
||||
});
|
||||
|
||||
// Restore active buffs
|
||||
if (data.activeBuffs) {
|
||||
data.activeBuffs.forEach(([buffId, buffData]) => {
|
||||
const remaining = buffData.expiresAt - Date.now();
|
||||
if (remaining > 0) {
|
||||
this.applyTemporaryBuff(buffId, buffData.multiplier, remaining);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user