User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.y += dy / distance * villager.speed;' Line Number: 1996
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1887
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1997
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1882
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1877
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1872
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.y += dy / distance * villager.speed;' Line Number: 1871
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1872
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1862
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1857
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1857
User prompt
improve the framerate
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1807
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1787
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.x = villager.targetX;' Line Number: 1777
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1772
User prompt
improve the framerate a lot
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1762
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1762
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1772
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1767
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1762
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1757
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1757
User prompt
Please fix the bug: 'TypeError: villager.initiateConversation is not a function' in or related to this line: 'villager.initiateConversation(otherVillager);' Line Number: 1757
/**** * Classes ****/ var Alchemist = Container.expand(function (resources) { var self = Container.call(this); self.alchemistGraphics = self.attachAsset('alchemist', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.potionPower = 10; self.createPotion = function (villager) { if (villager.iq < 200) { villager.iq += self.potionPower; if (villager.iq > 200) { villager.iq = 200; } } }; }); var Apothecary = Container.expand(function () { var self = Container.call(this); self.apothecaryGraphics = self.attachAsset('apothecary', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.apothecaryGraphics.width, self.apothecaryGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.provideMedicine = function (villager) { if (villager.gameResources.food.amount >= 2) { villager.gameResources.food.amount -= 2; villager.health += 10; if (villager.health > 100) { villager.health = 100; } } }; }); var Architect = Container.expand(function () { var self = Container.call(this); self.architectGraphics = self.attachAsset('architect', { anchorX: 0.5, anchorY: 0.5 }); self.designStructure = function (structureType) { var structure = new structureType(); structure.x = Math.random() * 2048; structure.y = Math.random() * 2732; if (self.parent) { self.parent.addChild(structure); } }; LK.setInterval(function () { self.designStructure(Tavern); }, 60000); }); var Bakery = Container.expand(function () { var self = Container.call(this); self.bakeryGraphics = self.attachAsset('bakery', { anchorX: 0.5, anchorY: 0.5 }); self.initializeRandomPosition = function () { do { self.x = Math.random() * (2048 - self.bakeryGraphics.width) + self.bakeryGraphics.width / 2; self.y = Math.random() * (2732 - self.bakeryGraphics.height) + self.bakeryGraphics.height / 2; } while (self.parent && self.checkOverlapWithOtherBuildings()); }; self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 650 + Math.max(self.bakeryGraphics.width, self.bakeryGraphics.height) / 2 + Math.max(building.width, building.height) / 2; }); }; self.bakeBread = function (villager) { if (villager.gameResources.wood.amount >= 5 && villager.gameResources.food.amount >= 2) { villager.gameResources.wood.amount -= 5; villager.gameResources.food.amount -= 2; villager.gameResources.food.amount += 10; if (villager.gameResources.food.amount > 100) { villager.gameResources.food.amount = 100; } } }; }); var Barracks = Container.expand(function () { var self = Container.call(this); self.barracksGraphics = self.attachAsset('barracks', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.barracksGraphics.width, self.barracksGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.trainSoldiers = function (villagers) { villagers.forEach(function (villager) { villager.strength += 1; if (villager.strength > 100) { villager.strength = 100; } }); }; }); var Blacksmith = Container.expand(function (resources) { var self = Container.call(this); self.blacksmithGraphics = self.attachAsset('blacksmith', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.forgeTool = function () {}; self.forgeWeapon = function () {}; }); var BlacksmithShop = Container.expand(function () { var self = Container.call(this); self.shopGraphics = self.attachAsset('blacksmithShop', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.shopGraphics.width, self.shopGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.forgeWeapon = function (villager) { if (villager.gameResources.wood.amount >= 5 && villager.gameResources.rock.amount >= 5) { villager.gameResources.wood.amount -= 5; villager.gameResources.rock.amount -= 5; villager.gameResources.weapon.amount += 1; } }; }); var BrewMaster = Container.expand(function () { var self = Container.call(this); self.brewMasterGraphics = self.attachAsset('brewmaster', { anchorX: 0.5, anchorY: 0.5 }); self.distributeBeverage = function () { self.parent.villagers.forEach(function (villager) { villager.happiness += 10; if (villager.happiness > 100) { villager.happiness = 100; } }); }; LK.setInterval(self.distributeBeverage, 30000); }); var Brewery = Container.expand(function () { var self = Container.call(this); self.breweryGraphics = self.attachAsset('brewery', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.breweryGraphics.width, self.breweryGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.produceBeverage = function () { LK.setTimeout(function () { self.parent.villagers.forEach(function (villager) { villager.happiness += 5; if (villager.happiness > 100) { villager.happiness = 100; } }); }, 30000); }; self.produceBeverage(); }); var Builder = Container.expand(function () { var self = Container.call(this); self.builderGraphics = self.attachAsset('builder', { anchorX: 0.5, anchorY: 0.5 }); self.buildingProgress = 0; self.build = function (building) { if (!building.isComplete) { self.buildingProgress += 1; if (self.buildingProgress >= 100) { building.isComplete = true; self.buildingProgress = 0; } } }; }); var Building = Container.expand(function (assetName) { var self = Container.call(this); Building.prototype.initializeRandomPosition = function () { var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(this, this.graphics.width, this.graphics.height, this.checkOverlapWithOtherBuildings); }; self.graphics = self.createAsset(assetName.toLowerCase(), { anchorX: 0.5, anchorY: 0.5 }); self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 550 + Math.max(self.graphics.width, self.graphics.height) / 2 + Math.max(building.graphics.width, building.graphics.height) / 2; }); }; self.initializeRandomPosition(); }); var School = Building.expand(function () { var self = Building.call(this, 'School'); return self; self.isTeaching = false; self.teach = function (villager) { if (!self.isTeaching) { return; } villager.iq += 10; }; self.startTeaching = function () { self.isTeaching = true; LK.setTimeout(function () { self.isTeaching = false; }, 20000); }; }); var Church = Container.expand(function () { var self = Container.call(this); self.churchGraphics = self.attachAsset('church', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.churchGraphics.width, self.churchGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.holdService = function (villagers) { villagers.forEach(function (villager) { villager.faith += 1; if (villager.faith > 100) { villager.faith = 100; } }); }; }); var Cloud = Container.expand(function () { var self = Container.call(this); self.initializeMovement = function (speed) { self.speed = speed * 1.5; self.cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(self.cloudGraphics); self._move_migrated = function () { self.x += self.speed; if (self.x > 2048) { self.x = -self.cloudGraphics.width; } }; LK.on('tick', self._move_migrated); }; }); var DayNightCycleManager = Container.expand(function () { var self = Container.call(this); self.cycleDuration = 24000; self.startTime = Date.now(); self.timeOfDayText = self.createTimeOfDayText(); LK.gui.top.addChild(self.timeOfDayText); LK.on('tick', function () { var currentTime = Date.now(); var elapsedTime = (currentTime - self.startTime) / 1000; var hours = Math.floor(elapsedTime % 24); var minutes = Math.floor(elapsedTime % 1 * 60); self.timeOfDayText.setText(hours + ':' + (minutes < 10 ? '0' : '') + minutes); self.updateVillagerBehaviorBasedOnTime(hours); }); self.updateVillagerBehaviorBasedOnTime = function (hours) { var isDaytime = hours >= 6 && hours < 18; self.parent.villagers.forEach(function (villager) { villager.isDaytime = isDaytime; }); }; }); var EmployingWorkPlace = Container.expand(function () { var self = Container.call(this); }); var Enemy = Container.expand(function () { var self = Container.call(this); self.enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.attackPower = 10; self.attackVillager = function (villager) { if (villager instanceof Villager) { villager.health -= self.attackPower; if (villager.health <= 0) { villager.destroy(); } } }; }); var Entertainer = Container.expand(function () { var self = Container.call(this); self.entertainerGraphics = self.attachAsset('entertainer', { anchorX: 0.5, anchorY: 0.5 }); self.entertain = function (villager) { if (villager.happiness < 100) { villager.happiness += 1; if (villager.happiness > 100) { villager.happiness = 100; } } }; LK.on('tick', function () { self.parent.villagers.forEach(self.entertain); }); }); var Explorer = Container.expand(function () { var self = Container.call(this); self.explorerGraphics = self.attachAsset('explorer', { anchorX: 0.5, anchorY: 0.5 }); self.discoverNewArea = function () { var discoveredResources = []; var resourceTypes = ['Wood', 'Rock', 'Food']; resourceTypes.forEach(function (type) { var resource = new window[type](); resource.x = Math.random() * 2048; resource.y = Math.random() * 2732; discoveredResources.push(resource); if (self.parent) { self.parent.addChild(resource); } }); return discoveredResources; }; }); var Farm = Container.expand(function () { var self = Container.call(this); self.farmGraphics = self.attachAsset('farm', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.farmGraphics.width, self.farmGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.plantCrops = function () {}; }); var Farmer = Container.expand(function (resources) { var self = Container.call(this); self.farmerGraphics = self.attachAsset('farmer', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.plantCrops = function () {}; self.harvestCrops = function () {}; }); var Festival = Container.expand(function () { var self = Container.call(this); self.festivalGraphics = self.attachAsset('festival', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 / 2; self.y = 2732 / 2 - 800; self.isActive = false; self.activateFestival = function () { self.isActive = true; LK.setTimeout(function () { self.parent.villagers.forEach(function (villager) { villager.happiness += 20; if (villager.happiness > 100) { villager.happiness = 100; } }); LK.setTimeout(function () { self.isActive = false; self.parent.villagers.forEach(function (villager) { villager.happiness -= 20; if (villager.happiness < 0) { villager.happiness = 0; } }); }, 30000); }, 60000); }; LK.setInterval(self.activateFestival, 120000); }); var Fisherman = Container.expand(function (resources) { var self = Container.call(this); self.fishermanGraphics = self.attachAsset('fisherman', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.fishingPower = 5; self.catchFish = function () {}; }); var FishingHut = Container.expand(function () { var self = Container.call(this); self.hutGraphics = self.attachAsset('fishingHut', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.hutGraphics.width, self.hutGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.storeCatch = function (villager) {}; }); var FoodDisplay = Container.expand(function (foodResource) { var self = Container.call(this); self.foodResource = foodResource; var foodGraphics = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(foodGraphics); self.foodText = new Text2(foodResource && foodResource.amount !== undefined ? foodResource.amount.toString() : '0', { size: 50, fill: 0xFFFFFF }); self.foodText.x = foodGraphics.width / 2; self.foodText.y = foodGraphics.height + 20; self.addChild(self.foodText); }); var Forester = Container.expand(function () { var self = Container.call(this); self.foresterGraphics = self.attachAsset('forester', { anchorX: 0.5, anchorY: 0.5 }); self.plantTree = function () { var tree = new Tree(); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; if (self.parent) { self.parent.addChild(tree); } }; LK.setInterval(self.plantTree, 30000); }); var Gardener = Container.expand(function () { var self = Container.call(this); self.homeGraphics = self.attachAsset('home', { anchorX: 0.5, anchorY: 0.5 }); do { self.x = Math.random() * (2048 - self.homeGraphics.width) + self.homeGraphics.width / 2; self.y = Math.random() * (2732 - self.homeGraphics.height) + self.homeGraphics.height / 2; } while (self.parent && self.checkOverlapWithOtherBuildings()); self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 200 + Math.max(self.homeGraphics.width, self.homeGraphics.height) / 2 + Math.max(building.width, building.height) / 2; }); }; self.tendPlants = function () {}; self.plantNewTree = function () { var newTree = new Tree(); newTree.x = Math.random() * 2048; newTree.y = Math.random() * 2732; if (self.parent) { self.parent.addChild(newTree); } }; }); var Granary = Container.expand(function () { var self = Container.call(this); self.granaryGraphics = self.attachAsset('granary', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.granaryGraphics.width, self.granaryGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.storeFood = function (amount) { self.gameResources.food.amount += amount; if (self.gameResources.food.amount > 1000) { self.gameResources.food.amount = 1000; } }; }); var Guard = Container.expand(function () { var self = Container.call(this); self.guardGraphics = self.attachAsset('guard', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(self.guardGraphics); self.x = Math.random() * 2048; self.y = Math.random() * 2732; self.speed = 2; self.isDaytime = true; self.patrolArea = function () { if (!self.isDaytime) { var patrolX = Math.random() * 2048; var patrolY = Math.random() * 2732; self.moveTo(patrolX, patrolY, self.speed); } }; self.sleep = function () { if (self.isDaytime && self.home) { self.x = self.home.x; self.y = self.home.y; } }; }); var GuardTower = Container.expand(function () { var self = Container.call(this); self.towerGraphics = self.attachAsset('guardTower', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.towerGraphics.width, self.towerGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.watch = function () {}; }); var Guardian = Container.expand(function () { var self = Container.call(this); self.guardianGraphics = self.attachAsset('guardian', { anchorX: 0.5, anchorY: 0.5 }); self.protect = function (villager) {}; LK.on('tick', function () {}); }); var Healer = Container.expand(function (resources) { var self = Container.call(this); self.healerGraphics = self.attachAsset('healer', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.healingPower = 5; self.heal = function (villager) { if (villager.health < 100) { villager.health += self.healingPower; if (villager.health > 100) { villager.health = 100; } } }; LK.on('tick', function () { self.parent.villagers.forEach(self.heal); }); }); var Heart = Container.expand(function () { var self = Container.call(this); self.showAbove = function (villager) { self.x = villager.x; self.y = villager.y - villager.height; self.alpha = 1; self.follow = function () { if (villager) { self.x = villager.x; self.y = villager.y - villager.height; } }; LK.on('tick', self.follow); LK.setTimeout(function () { LK.off('tick', self.follow); self.alpha = 1; self.destroy(); }, 1000); }; }); var Herbalist = Container.expand(function () { var self = Container.call(this); self.herbalistGraphics = self.attachAsset('herbalist', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.herbalistGraphics.width, self.herbalistGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.provideHerbs = function (villager) { if (villager.gameResources.food.amount >= 1) { villager.gameResources.food.amount -= 1; villager.health += 5; if (villager.health > 100) { villager.health = 100; } } }; }); var Home = Container.expand(function () { var self = Container.call(this); self.homeGraphics = self.attachAsset('home', { anchorX: 0.5, anchorY: 0.5 }); self.initializeRandomPosition = function () { do { self.x = Math.random() * (2048 - self.homeGraphics.width) + self.homeGraphics.width / 2; self.y = Math.random() * (2732 - self.homeGraphics.height) + self.homeGraphics.height / 2; } while (self.parent && self.checkOverlapWithOtherBuildings()); }; self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 650 + Math.max(self.homeGraphics.width, self.homeGraphics.height) / 2 + Math.max(building.width, building.height) / 2; }); }; var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.width, self.height, function () { return self.checkOverlapWithOtherBuildings(); }); }); var Inn = Container.expand(function () { var self = Container.call(this); self.innGraphics = self.attachAsset('inn', { anchorX: 0.5, anchorY: 0.5 }); self.initializeRandomPosition = function () { do { self.x = Math.random() * (2048 - self.innGraphics.width) + self.innGraphics.width / 2; self.y = Math.random() * (2732 - self.innGraphics.height) + self.innGraphics.height / 2; } while (self.parent && self.checkOverlapWithOtherBuildings()); }; self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 650 + Math.max(self.innGraphics.width, self.innGraphics.height) / 2 + Math.max(building.width, building.height) / 2; }); }; self.initializeRandomPosition(); self.isOccupiable = true; self.occupy = function (villager) { if (!self.isOccupiable) { return; } self.isOccupiable = false; villager.state = 'restingAtInn'; villager.tiredness = Math.max(villager.tiredness - 20, 0); LK.setTimeout(function () { self.isOccupiable = true; }, 10000); }; }); var Library = Container.expand(function () { var self = Container.call(this); self.libraryGraphics = self.attachAsset('library', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.libraryGraphics.width, self.libraryGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.study = function (villager) { if (villager.gameResources.wood.amount >= 1) { villager.gameResources.wood.amount -= 1; villager.iq += 5; if (villager.iq > 200) { villager.iq = 200; } } }; }); var Lumberjack = Container.expand(function (resources) { var self = Container.call(this); self.lumberjackGraphics = self.attachAsset('lumberjack', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.choppingPower = 5; self.targetX = Math.random() * 2048; self.targetY = Math.random() * 2732; self.speed = 6; self._move_migrated = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 5) { self.targetX = Math.random() * 2048; self.targetY = Math.random() * 2732; } else if (distance < 500) { self.x += dx / distance * self.speed * 2.5; self.y += dy / distance * self.speed * 2.5; } else { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; self.chopTree = function (tree) { if (tree instanceof Tree) { self.gameResources.wood.amount += self.choppingPower; tree.amount -= self.choppingPower; if (tree.amount <= 0) { tree.destroy(); } } }; self.conversationStarters = { 'flirty': ['Hey there, good lookin". Wanna go on an adventure together?', 'Is it hot out here, or is it just you?', 'You must be a magician, because whenever I look at you, everyone else disappears.', 'Do you have a map? I just keep getting lost in your eyes.', 'If beauty were a grain of sand, you’d be a million beaches.'], 'flirty2': ['Did the sun come out or did you just smile at me?', 'Do you have a Band-Aid? Because I just scraped my knee falling for you.', 'Do you have a name or can I call you mine?', 'Is there an airport nearby or is it my heart taking off?', 'Are you an enchantment? Because my world is brighter with you in it.'], 'flirty3': ['Are you a camera? Because every time I look at you, I smile.', 'Do you have a sunburn, or are you always this hot?', 'Can I follow you? Because my mom told me to follow my dreams.', 'Is your name Google? Because you have everything I’ve been searching for.', 'Do you like Star Wars? Because Yoda one for me.'], 'flirty4': ['If you were a vegetable, you’d be a cute-cumber!', 'Do you have a pencil? Because I want to erase your past and write our future.', 'Are you a parking ticket? Because you’ve got FINE written all over you.', 'If you were a fruit, you’d be a fineapple.', 'Is this the Hogwarts Express? Because it feels like you and I are headed somewhere magical.'], 'flirty5': ['Are you a magician? Because whenever I look at you, everyone else disappears.', 'Do you have a map? I keep getting lost in your eyes.', 'Do you believe in love at first sight, or should I walk by again?', 'Are you a loan? Because you have my interest!', 'Are you a time traveler? Because I see you in my future.'], 'flirty6': ['If I could rearrange the alphabet, I’d put U and I together.', 'Are you a dictionary? Because you add meaning to my life.', 'Is it okay if I follow you home? Cause my parents always told me to follow my dreams.', 'Do you have a Band-Aid? I just hurt my knee falling for you.', 'Do you have a map? I just got lost in your eyes.'] }; }); var Marketplace = Container.expand(function () { var self = Container.call(this); self.marketplaceGraphics = self.attachAsset('marketplace', { anchorX: 0.5, anchorY: 0.5 }); self.availableResources = { wood: 0, rock: 0, food: 0 }; self.trade = function (villager, resourceType, amount) { if (self.availableResources[resourceType] >= amount) { self.availableResources[resourceType] -= amount; villager.gameResources[resourceType].amount += amount; } }; self.addResource = function (resourceType, amount) { self.availableResources[resourceType] += amount; }; self.initializePosition = function () { if (!self.parent) { return; } if (self.parent) { self.x = Math.random() * 2048; self.y = Math.random() * 2732; } }; self.initializePosition(); }); var Merchant = Container.expand(function (resources) { var self = Container.call(this); self.merchantGraphics = self.attachAsset('merchant', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.tradeWithMarketplace = function (marketplace, resourceType, amount) { if (marketplace.availableResources[resourceType] >= amount) { marketplace.availableResources[resourceType] -= amount; self.gameResources[resourceType].amount += amount; } }; self.tradeWithVillager = function (villager, resourceType, amount) { if (self.gameResources[resourceType].amount >= amount) { self.gameResources[resourceType].amount -= amount; villager.gameResources[resourceType].amount += amount; } }; }); var MerchantShip = Container.expand(function (resources) { var self = Container.call(this); self.shipGraphics = self.attachAsset('merchantShip', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.tradeWithVillage = function (village, resourceType, amount) { if (self.gameResources[resourceType].amount >= amount) { self.gameResources[resourceType].amount -= amount; village.resources[resourceType].amount += amount; } }; }); var Miner = Container.expand(function (resources) { var self = Container.call(this); self.minerGraphics = self.attachAsset('miner', { anchorX: 0.5, anchorY: 0.5 }); self.gameResources = resources; self.miningPower = 5; self.mineRock = function (rock) { if (rock instanceof Rock) { self.gameResources.rock.amount += self.miningPower; if (self.gameResources.rock.amount > 100) { self.gameResources.rock.amount = 100; } } }; }); var MoodManager = Container.expand(function () { var self = Container.call(this); self.changeMood = function (villager, newMood) { villager.mood = newMood; }; }); var PositionInitializer = Container.expand(function () { var self = Container.call(this); self.initializeRandomPosition = function (entity, width, height, overlapCheckCallback) { do { entity.x = Math.random() * (2048 - width - 1000) + width / 2 + 500; entity.y = Math.random() * (2732 - height - 1000) + height / 2 + 500; } while (entity.parent && overlapCheckCallback(entity)); }; }); var Priest = Container.expand(function () { var self = Container.call(this); self.priestGraphics = self.attachAsset('priest', { anchorX: 0.5, anchorY: 0.5 }); self.holdMass = function () { var villagers = self.parent.villagers.filter(function (villager) { return self.intersects(villager); }); villagers.forEach(function (villager) { villager.faith += 5; if (villager.faith > 100) { villager.faith = 100; } }); }; LK.setInterval(self.holdMass, 30000); }); var Quarry = Container.expand(function () { var self = Container.call(this); self.quarryGraphics = self.attachAsset('quarry', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.quarryGraphics.width, self.quarryGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.extractStone = function (villager) {}; }); var Resource = Container.expand(function (type, amount) { var self = Container.call(this); self.type = type; self.resourceGraphics = self.createAsset(type.toLowerCase(), { anchorX: 0.5, anchorY: 0.5 }); self.amount = amount; self.collectResource = function (villager) { if (self.amount > 0) { var collectedAmount = Math.min(villager.collectingPower, self.amount); villager.gameResources[self.type.toLowerCase()].amount += collectedAmount; self.amount -= collectedAmount; if (self.amount <= 0) { self.destroy(); } } }; }); var Wood = Resource.expand(function () { var self = Resource.call(this, 'Wood', 100); }); var Rock = Resource.expand(function () { var self = Resource.call(this, 'Rock', 100); }); var GoldResource = Resource.expand(function () { var self = Resource.call(this, 'Gold', 50); self.collectResource = function (villager) { if (self.amount > 0) { var collectedAmount = Math.min(villager.collectingPower, self.amount); villager.gameResources.gold.amount += collectedAmount; self.amount -= collectedAmount; if (self.amount <= 0) { self.destroy(); } } }; }); var FoodResource = Resource.expand(function () { var self = Resource.call(this, 'Food', 100); }); var Food = Resource.expand(function () { var self = Resource.call(this, 'Food', 100); }); var ResourceDisplay = Container.expand(function (resources) { var self = Container.call(this); self.woodDisplay = self.addChild(new WoodDisplay(game.resourceManager.getResourceAmount('wood'))); self.rockDisplay = self.addChild(new RockDisplay(game.resourceManager.resources.rock)); self.foodDisplay = self.addChild(new FoodDisplay(game.resourceManager.resources.food)); self.positionDisplays(); }); var ResourceManager = Container.expand(function () { var self = Container.call(this); self.resources = { wood: 0, rock: 0, food: 0, gold: 0 }; self.addResource = function (type, amount) { if (self.resources.hasOwnProperty(type)) { self.resources[type] += amount; } }; self.consumeResource = function (type, amount) { if (self.resources[type] >= amount) { self.resources[type] -= amount; return true; } return false; }; self.getResourceAmount = function (type) { return self.resources[type] || 0; }; }); var RockDisplay = Container.expand(function (rockResource) { var self = Container.call(this); self.rockResource = rockResource; var rockGraphics = self.attachAsset('rock', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(rockGraphics); self.rockText = new Text2(rockResource && rockResource.amount !== undefined ? rockResource.amount.toString() : '0', { size: 50, fill: 0xFFFFFF }); self.rockText.x = rockGraphics.width / 2; self.rockText.y = rockGraphics.height + 20; self.addChild(self.rockText); }); var RockResource = Container.expand(function (amount) { var self = Container.call(this); self.type = 'Rock'; self.amount = amount; self.collect = function (villager) {}; }); var Smithy = Container.expand(function () { var self = Container.call(this); self.smithyGraphics = self.attachAsset('smithy', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.smithyGraphics.width, self.smithyGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.forgeTools = function (villager) { if (villager.gameResources.rock.amount >= 3) { villager.gameResources.rock.amount -= 3; villager.tools += 1; if (villager.tools > 10) { villager.tools = 10; } } }; }); var Stable = Container.expand(function () { var self = Container.call(this); self.stableGraphics = self.attachAsset('stable', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.stableGraphics.width, self.stableGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.provideHorse = function (villager) { if (villager.gameResources.food.amount >= 5) { villager.gameResources.food.amount -= 5; villager.speed += 5; if (villager.speed > 20) { villager.speed = 20; } } }; }); var StoneMason = Container.expand(function () { var self = Container.call(this); self.stoneMasonGraphics = self.attachAsset('stonemason', { anchorX: 0.5, anchorY: 0.5 }); self.constructStructure = function (structureType) { var structure = new structureType(); structure.x = Math.random() * 2048; structure.y = Math.random() * 2732; if (self.parent) { self.parent.addChild(structure); } }; LK.setInterval(function () { self.constructStructure(Quarry); }, 60000); }); var Tavern = Container.expand(function () { var self = Container.call(this); self.tavernGraphics = self.attachAsset('tavern', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.tavernGraphics.width, self.tavernGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.serveDrinks = function (villagers) { villagers.forEach(function (villager) { villager.happiness += 5; if (villager.happiness > 100) { villager.happiness = 100; } }); }; }); var Teacher = Container.expand(function () { var self = Container.call(this); self.teacherGraphics = self.attachAsset('teacher', { anchorX: 0.5, anchorY: 0.5 }); self.educate = function (villager) { if (villager.iq < 200) { villager.iq += 0.1; if (villager.iq > 200) { villager.iq = 200; } } }; LK.on('tick', function () { self.parent.villagers.forEach(self.educate); }); }); var TownCrier = Container.expand(function () { var self = Container.call(this); self.crierGraphics = self.attachAsset('townCrier', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 / 2; self.y = 2732 / 2; self.announce = function (message) { var announcement = new Text2(message, { size: 100, fill: 0xFFFFFF }); announcement.x = self.x; announcement.y = self.y - 200; self.addChild(announcement); LK.setTimeout(function () { announcement.destroy(); }, 5000); }; }); var TownHall = Container.expand(function () { var self = Container.call(this); self.townHallGraphics = self.attachAsset('townHall', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.townHallGraphics.width, self.townHallGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.hostMeeting = function () { var villagers = self.parent.villagers.filter(function (villager) { return self.intersects(villager); }); villagers.forEach(function (villager) { villager.happiness += 2; if (villager.happiness > 100) { villager.happiness = 100; } }); }; LK.on('tick', function () { self.hostMeeting(); }); }); var Trader = Container.expand(function (resources) { var self = Container.call(this); self.traderGraphics = self.attachAsset('trader', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(self.traderGraphics); self.gameResources = resources; self.trade = function (resourceType, amount, targetResourceType) { if (self.gameResources[resourceType].amount >= amount) { self.gameResources[resourceType].amount -= amount; self.gameResources[targetResourceType].amount += amount * self.getExchangeRate(resourceType, targetResourceType); } }; self.getExchangeRate = function (resourceType, targetResourceType) { return 1; }; }); var Tree = Container.expand(function () { var self = Container.call(this); self.resourceType = 'food'; self.amount = 100; self.collectResource = function (villager) { if (self.amount > 0) { var collectedAmount = Math.min(50, self.amount); villager.gameResources.food.amount += collectedAmount; villager.carriedFood += collectedAmount; self.amount -= collectedAmount; if (self.amount <= 0) { self.destroy(); } } }; }); var Villager = Container.expand(function (resources, iq) { var self = Container.call(this); self._update_migrated = function () { // Update villager position based on target coordinates if (this.targetX === null || this.targetY === null) { this.targetX = Math.random() * 2048; this.targetY = Math.random() * 2732; } this.moveTowardsTarget(this.targetX, this.targetY); // Decide on the next action for the villager this.behaviorManager.decideNextAction(); }; // Move villager towards a target position self.moveTowardsTarget = function (targetX, targetY) { var dx = targetX - this.x; var dy = targetY - this.y; var distanceSquared = dx * dx + dy * dy; if (distanceSquared > 0) { var distance = Math.sqrt(distanceSquared); var speed = Math.min(this.speed, distance); this.x += dx / distance * speed; this.y += dy / distance * speed; } }; // Initialize the behavior manager for the villager self.behaviorManager = new VillagerBehaviorManager(self); self.gameResources = resources; self.iq = iq; self.mood = 'flirty'; self.flirtiness = 0; self.psychopathy = 0; self.moveTowardsTarget = function (targetX, targetY) { var dx = targetX - this.x; var dy = targetY - this.y; var distance = Math.hypot(dx, dy); if (distance > this.speed) { this.x += dx / distance * this.speed; this.y += dy / distance * this.speed; } else { this.x = targetX; this.y = targetY; } }; LK.on('tick', function () { game.villagers.forEach(function (villager) { if (villager.behaviorManager && villager.behaviorManager instanceof VillagerBehaviorManager) { villager.behaviorManager._update_migrated(); } }); }); self.behavior = new VillagerBehavior(self); self.buildHome = function () { if (!self.home && self.gameResources && self.gameResources.wood && self.gameResources.wood.amount >= 5) { self.gameResources.wood.amount -= 5; var newHome = new Home(); newHome.x = self.x; newHome.y = self.y; self.parent.addChild(newHome); self.home = newHome; } }; self.initiateConversation = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { self.talkTo(otherVillager); } }; Villager.prototype.initiateConversation = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { this.talkTo(otherVillager); } }; Villager.prototype.initiateConversation = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { this.talkTo(otherVillager); } }; Villager.prototype.initiateConversation = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { this.talkTo(otherVillager); } }; Villager.prototype.talkTo = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { var message = this.conversationStarters['flirty'][Math.floor(Math.random() * this.conversationStarters['flirty'].length)]; var speechBubble = new Text2(message, { size: 50, fill: 0xFFFFFF }); speechBubble.x = (this.x + otherVillager.x) / 2; speechBubble.y = (this.y + otherVillager.y) / 2; this.parent.addChild(speechBubble); LK.setTimeout(function () { speechBubble.destroy(); }, 3000); } }; Villager.prototype.talkTo = function (otherVillager) { if (otherVillager && otherVillager instanceof Villager) { var message = this.conversationStarters['flirty'][Math.floor(Math.random() * this.conversationStarters['flirty'].length)]; var speechBubble = new Text2(message, { size: 50, fill: 0xFFFFFF }); speechBubble.x = (this.x + otherVillager.x) / 2; speechBubble.y = (this.y + otherVillager.y) / 2; this.parent.addChild(speechBubble); LK.setTimeout(function () { speechBubble.destroy(); }, 3000); } }; }); var VillagerBehavior = Container.expand(function (villager) { var self = Container.call(this); self.villager = villager; self.decideNextAction = function () { if (!self.cachedNeeds || !self.cachedActions) { self.cachedNeeds = self.calculateNeeds(); self.cachedActions = self.defineActions(); } var needs = self.cachedNeeds; var actions = self.cachedActions; var highestPriorityAction = Object.entries(needs).filter(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), _ = _ref2[0], needMet = _ref2[1]; return needMet; }).map(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 2), need = _ref4[0], _ = _ref4[1]; return need; }).shift(); // Get the first true need based on priority order defined in calculateNeeds if (highestPriorityAction) { var _self$villager$speech; (_self$villager$speech = self.villager.speechBubble) === null || _self$villager$speech === void 0 || _self$villager$speech.destroy(); self.villager.speechBubble = null; actions[highestPriorityAction](); } else { actions['wander'](); } }; self.calculateNeeds = function () { return { 'rest': self.villager.energy < 20 || self.villager.tiredness >= 80, 'work': self.villager.energy >= 20 && self.villager.workplace && self.villager.tiredness < 80, 'food': self.villager.gameResources.food.amount < 20, 'wood': self.villager.gameResources.wood.amount < 20, 'rock': self.villager.gameResources.rock.amount < 20 }; }; self.defineActions = function () { return { 'rest': function rest() { self.villager.targetX = self.villager.home.x; self.villager.targetY = self.villager.home.y; self.villager.state = 'goingHomeToRest'; }, 'work': function work() { self.villager.targetX = self.villager.workplace.x; self.villager.targetY = self.villager.workplace.y; self.villager.state = 'goingToWork'; }, 'food': function food() { self.villager.state = 'seekingFood'; }, 'wood': function wood() { self.villager.state = 'seekingWood'; }, 'rock': function rock() { self.villager.state = 'seekingRock'; }, 'trade': function trade() { self.villager.state = 'trading'; self.villager.targetX = self.villager.marketplace.x; self.villager.targetY = self.villager.marketplace.y; }, 'wander': function wander() { self.villager.targetX = Math.random() * 2048; self.villager.targetY = Math.random() * 2732; self.villager.state = 'wandering'; } }; }; }); var VillagerBehaviorManager = Container.expand(function (villager) { var self = Container.call(this); self.villager = villager; self.decideNextAction = function () { self.villager.behavior.decideNextAction(); }; self.setRandomTarget = function () { self.villager.targetX = Math.random() * 2048; self.villager.targetY = Math.random() * 2732; }; self._update_migrated = function () { self.villager.buildHome(); }; }); var VillagerConversation = Container.expand(function () { var self = Container.call(this); self.conversationStarters = ['Hey there, good lookin". Wanna go on an adventure together?', 'Is it hot out here, or is it just you?', 'You must be a magician, because whenever I look at you, everyone else disappears.', 'Do you have a map? I just keep getting lost in your eyes.', 'If beauty were a grain of sand, you’d be a million beaches.']; }); var VillagerFactory = Container.expand(function (resources) { var self = Container.call(this); self.resources = resources; self.createVillager = function (iq) { return new Villager(self.resources, iq); }; self.initializeAndAddVillager = function (isBaby, iq, x, y) { var villager = this.createVillager(iq); villager.setAge(isBaby); if (this.parent) { this.parent.addChild(villager); } return villager; }; }); var Warrior = Container.expand(function () { var self = Container.call(this); self.warriorGraphics = self.attachAsset('warrior', { anchorX: 0.5, anchorY: 0.5 }); self.defendVillage = function (enemy) { if (enemy instanceof Enemy) { enemy.health -= self.strength; if (enemy.health <= 0) { enemy.destroy(); } } }; self.strength = 20; }); var Watchtower = Container.expand(function () { var self = Container.call(this); self.watchtowerGraphics = self.attachAsset('watchtower', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.watchtowerGraphics.width, self.watchtowerGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.lookout = function () {}; }); var WeatherSystem = Container.expand(function (gameInstance) { var self = Container.call(this); self.gameInstance = gameInstance; self.currentWeather = 'sunny'; self.changeWeather = function () { var weathers = ['sunny', 'rainy', 'windy', 'snowy']; self.currentWeather = weathers[Math.floor(Math.random() * weathers.length)]; self.applyWeatherEffects(); }; self.applyWeatherEffects = function () { if (self.gameInstance && self.gameInstance.villagers) { self.gameInstance.villagers.forEach(function (villager) { switch (self.currentWeather) { case 'rainy': villager.speed *= 0.9; break; case 'windy': villager.speed *= 1.1; break; case 'snowy': villager.speed *= 0.8; break; default: villager.speed = villager.baseSpeed; break; } }); } }; LK.setInterval(self.changeWeather, 120000); }); var Well = Container.expand(function () { var self = Container.call(this); self.wellGraphics = self.attachAsset('well', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.wellGraphics.width, self.wellGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.checkOverlapWithOtherBuildings = function () { var buildings = self.parent.children.filter(function (child) { return child !== self && child instanceof Building; }); return buildings.some(function (building) { var dx = self.x - building.x; var dy = self.y - building.y; return Math.sqrt(dx * dx + dy * dy) < 650 + Math.max(self.wellGraphics.width, self.wellGraphics.height) / 2 + Math.max(building.width, building.height) / 2; }); }; positionInitializer.initializeRandomPosition(self, self.wellGraphics.width, self.wellGraphics.height, self.checkOverlapWithOtherBuildings); self.drinkWater = function (villager) { villager.tiredness -= 5; if (villager.tiredness < 0) { villager.tiredness = 0; } }; }); var Windmill = Container.expand(function () { var self = Container.call(this); self.windmillGraphics = self.attachAsset('windmill', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.windmillGraphics.width, self.windmillGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.boostFarmProduction = function () { var farms = self.parent.children.filter(function (child) { return child instanceof Farm && self.intersects(child); }); farms.forEach(function (farm) { farm.productionMultiplier = (farm.productionMultiplier || 1) * 1.2; }); }; LK.on('tick', self.boostFarmProduction); }); var WoodDisplay = Container.expand(function (woodResource) { var self = Container.call(this); self.woodResource = woodResource; var woodGraphics = self.attachAsset('wood', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(woodGraphics); self.woodText = new Text2(woodResource && woodResource.amount !== undefined ? woodResource.amount.toString() : '0', { size: 50, fill: 0xFFFFFF }); self.woodText.position.set(woodGraphics.width / 2, woodGraphics.height + 20); self.addChild(self.woodText); }); var Workshop = Container.expand(function () { var self = Container.call(this); self.workshopGraphics = self.attachAsset('workshop', { anchorX: 0.5, anchorY: 0.5 }); var positionInitializer = new PositionInitializer(); positionInitializer.initializeRandomPosition(self, self.workshopGraphics.width, self.workshopGraphics.height, function () { return self.checkOverlapWithOtherBuildings(); }); self.craftItem = function (villager, item) {}; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) { return; } if (typeof o === "string") { return _arrayLikeToArray(o, minLen); } var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) { n = o.constructor.name; } if (n === "Map" || n === "Set") { return Array.from(o); } if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) { return _arrayLikeToArray(o, minLen); } } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) { len = arr.length; } for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) { return; } f = !1; } else { for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) { return; } } finally { if (o) { throw n; } } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) { return arr; } } VillagerConversation.prototype.initiateConversation = function (villager, otherVillager) { villager.speed = 0; LK.setTimeout(function () { villager.speed = villager.baseSpeed; }, 1000); }; Lumberjack.prototype.talkTo = function (otherLumberjack) { var currentTime = Date.now(); if (!this.speechBubble && (!this.lastTalkTime || currentTime - this.lastTalkTime >= 10000)) { this.lastTalkTime = currentTime; var message = this.conversationStarters['flirty'][Math.floor(Math.random() * this.conversationStarters['flirty'].length)]; this.speechBubble = new Text2(message, { size: 50, fill: 0xFFFFFF }); var midX = (this.x + otherLumberjack.x) / 2; var midY = (this.y + otherLumberjack.y) / 2; var offsetX = this.x < otherLumberjack.x ? -300 : 300; var offsetY = this.y < otherLumberjack.y ? -300 : 300; this.speechBubble.x = midX + offsetX; this.speechBubble.y = midY + offsetY; this.parent.addChild(this.speechBubble); var that = this; LK.setTimeout(function () { that.speechBubble.destroy(); that.speechBubble = null; that.speed = that.baseSpeed; }, 3000); } }; Lumberjack.prototype.initiateConversation = function (message, otherLumberjack) {}; game.weatherSystem = new WeatherSystem(); ResourceDisplay.prototype.positionDisplays = function () { this.woodDisplay.position.set(100, 50); this.rockDisplay.position.set(300, 50); this.foodDisplay.position.set(500, 50); }; Bakery.prototype.sellBread = function (villager) { if (villager.gameResources.food.amount >= 5) { villager.gameResources.food.amount -= 5; villager.energy += 10; if (villager.energy > 100) { villager.energy = 100; } } }; DayNightCycleManager.prototype.createTimeOfDayText = function () { var text = new Text2('', { size: 50, fill: 0xFFFFFF }); text.anchor.set(0.5, 0); text.x = 2048 / 2; text.y = 100; return text; }; var villagerGraphics = LK.getAsset('villager', { anchorX: 0.5, anchorY: 0.5 }); var villager = game.addChildAt(villagerGraphics, game.children.length); villager.x = 1024; villager.y = 1366; game.createBackground = function () { var background = this.createAsset('background', 'Game Background', 0, 0); background.width = 2048 * 1.5; background.height = 2732 * 1.5; background.anchor.set(0.5, 0.5); background.x = 2048 / 2; background.y = 2732 / 2; this.addChildAt(background, 0); }; game.createBackground(); game.executeCurrentAction = function (villager) {}; game.createAndAddVillagerIfPossible = function () { if (this.resources && this.resources.food.amount >= 10) { var home = new Home(); home.x = Math.random() * 2048; home.y = Math.random() * 2732; game.addChild(home); this.resources.food.amount -= 10; } }; game.zoomOnVillagers = function (villagerA, villagerB) { var zoomLevel = 2; var centerX = (villagerA.x + villagerB.x) / 2; var centerY = (villagerA.y + villagerB.y) / 2; game.scale.x = zoomLevel; game.scale.y = zoomLevel; game.pivot.x = centerX; game.pivot.y = centerY; game.x = game.width / 2; game.y = game.height / 2; LK.setTimeout(function () { game.scale.x = 1; game.scale.y = 1; game.pivot.x = 0; game.pivot.y = 0; game.x = 0; game.y = 0; }, 3000); }; game.makeVillagerDecisions = function (villager) { if (!villager.currentAction) { if (typeof villager.decideNextAction === 'function') { villager.decideNextAction(); } } }; LK.on('tick', function () { var currentTime = Date.now(); var elapsedTime = Math.floor((currentTime - game.startTime) / 1000); game.timerText.setText('Time: ' + elapsedTime); game.villagers.forEach(function (villager) { if (villager.behaviorManager && villager.behaviorManager instanceof VillagerBehaviorManager) { villager.behaviorManager._update_migrated(); } // Removed moveTo method call and replaced with direct property assignment if (villager.targetX !== null && villager.targetY !== null) { var dx = villager.targetX - villager.x; var dy = villager.targetY - villager.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 5) { villager.x = villager.targetX; villager.y = villager.targetY; } else { villager.x += dx / distance * villager.speed; villager.y += dy / distance * villager.speed; } } // Check for collision with other villagers game.villagers.forEach(function (otherVillager) { if (villager !== otherVillager && villager.intersects(otherVillager)) { villager.initiateConversation(otherVillager); } }); // Check for collision with buildings if (game.buildings && Array.isArray(game.buildings)) { game.buildings.forEach(function (building) { if (villager.intersects(building)) { building.interactWithVillager(villager); } }); } // Check for collision with resources if (game.resources && Array.isArray(game.resources)) { game.resources.forEach(function (resource) { if (villager.intersects(resource)) { resource.collectResource(villager); } }); } }); game.handleVillagersFallingInLove(); }); game.framerateDisplay = new Text2('FPS: 0', { size: 100, fill: 0xFFFFFF }); game.framerateDisplay.anchor.set(1, 0); game.framerateDisplay.x = 2048; game.framerateDisplay.y = 0; LK.gui.topRight.addChild(game.framerateDisplay); game.timerText = new Text2('Time: 0', { size: 50, fill: 0xFFFFFF }); game.timerText.anchor.set(0.5, 0); game.timerText.x = 2048 / 2; game.timerText.y = 100; LK.gui.top.addChild(game.timerText); game.startTime = Date.now(); var brewery = new Brewery(); game.addChild(brewery); var bakery = new Bakery(); game.addChild(bakery); var well = new Well(); game.addChild(well); game.resourceManager = game.addChild(new ResourceManager()); game.resourceManager.addResource('wood', 100); game.resourceManager.addResource('rock', 100); game.resourceManager.addResource('food', 100); game.resourceManager.addResource('gold', 50); game.resourceDisplay = new ResourceDisplay(game.resources); LK.gui.topLeft.addChild(game.resourceDisplay); game.handleVillagersFallingInLove = function () { for (var i = 0; i < this.villagers.length; i++) { for (var j = i + 1; j < this.villagers.length; j++) { var villagerA = this.villagers[i]; var villagerB = this.villagers[j]; } } }; function createResources() { return { wood: new Wood(100), rock: new RockResource(100), food: new FoodResource(100) }; } Villager.prototype.setAge = function (isBaby) { if (isBaby) { this.scale.x = 0.5; this.scale.y = 0.5; } else { this.scale.x = 1; this.scale.y = 1; } }; game.addVillager = function (isBaby, iq, x, y) { var villager = this.villagerFactory.initializeAndAddVillager(isBaby, iq, x, y); this.initializeVillagerProperties(villager); this.registerVillager(villager); }; game.initializeVillagerProperties = function (villager) { villager.speed = 6; villager.energy = 100; villager.tiredness = 0; villager.state = 'idle'; villager.home = null; villager.workplace = null; villager.currentAction = null; villager.targetX = null; villager.targetY = null; }; game.villagers = []; game.houses = []; game.createClouds = function (count, speed) { for (var i = 0; i < count; i++) { var cloud = new Cloud(); cloud.initializeMovement(speed); game.cloudLayer.addChild(cloud); game.clouds.push(cloud); } }; game.cloudLayer = new Container(); game.clouds = []; game.createClouds(10, 1); game.villagerFactory = new VillagerFactory(game.resources); game.createVillagers = function (villagerTypes, count) { villagerTypes.forEach(function (villagerType) { for (var i = 0; i < count; i++) { var iq = Math.random() * 50 + 50; var x = Math.random() * 2048; var y = Math.random() * 2732; var villager = new Villager(game.resources, iq); villager.x = x; villager.y = y; game.addChild(villager); game.villagers.push(villager); } }); }; game.createVillagers(['Miner', 'Fisherman', 'Guard', 'Farmer', 'Blacksmith', 'Merchant', 'Gardener'], 4); // Spawn one of each villager type var villagerTypes = [Miner, Fisherman, Guard, Farmer, Blacksmith, Merchant, Gardener, Lumberjack]; villagerTypes.forEach(function (VillagerType) { var iq = Math.random() * 50 + 50; var x = Math.random() * 2048; var y = Math.random() * 2732; var villager = new VillagerType(game.resources, iq); villager.x = x; villager.y = y; game.addChild(villager); game.villagers.push(villager); }); game.market = new Marketplace(); game.addChild(game.market); game.createHouse = function (x, y) { var house = new Home(); house.x = x; house.y = y; return house; }; game.addHouse = function (house) { this.addChild(house); this.houses.push(house); }; game.createHouse = function () { var x = Math.random() * 2048; var y = Math.random() * 2732; var house = new Home(); house.x = x; house.y = y; game.addChild(house); game.houses.push(house); }; game.houses = []; game.createHouse(); game.createWorkplace = function () { var workplace = new EmployingWorkPlace(); workplace.x = Math.random() * 2048; workplace.y = Math.random() * 2732; return workplace; }; game.addWorkplace = function (workplace) { this.addChild(workplace); this.workplaces.push(workplace); }; game.createWorkplaces = function (count) { for (var i = 0; i < count; i++) { var workplace = new EmployingWorkPlace(); workplace.x = Math.random() * 2048; workplace.y = Math.random() * 2732; game.addChild(workplace); game.workplaces.push(workplace); } }; game.workplaces = []; game.createWorkplaces(5); var wood = new Wood(); wood.x = 2048 / 2; wood.y = 2732 / 2 - 400; game.addChild(wood); var rock = new Rock(); rock.x = 2048 / 2 + 100; rock.y = 2732 / 2 - 300; game.addChild(rock); var workplace = new EmployingWorkPlace(); workplace.x = Math.random() * 2048; workplace.y = Math.random() * 2732; game.workplaces.push(workplace); game.addChild(workplace); var initialRock = new Rock(); initialRock.x = 1024; initialRock.y = 1366; game.addChild(initialRock); var initialFood = new Food(); initialFood.x = 1024; initialFood.y = 1566; game.addChild(initialFood); var villager1 = new Villager(game.resources, 100); villager1.x = 500; villager1.y = 500; game.addChild(villager1); game.villagers.push(villager1); var villager2 = new Villager(game.resources, 100); villager2.x = 600; villager2.y = 600; game.addChild(villager2); game.villagers.push(villager2); var home = new Home(); home.x = 700; home.y = 700; game.addChild(home); var inn = new Inn(); inn.x = 900; inn.y = 900; game.addChild(inn); var bakery = new Bakery(); bakery.x = 1000; bakery.y = 1000; game.addChild(bakery); var well = new Well(); well.x = 1100; well.y = 1100; game.addChild(well); var gardener = new Gardener(); gardener.x = 1200; gardener.y = 1200; game.addChild(gardener); var festival = new Festival(); festival.x = 1300; festival.y = 1300; game.addChild(festival); var BuildingFactory = { createBuilding: function createBuilding(BuildingType) { var building = new BuildingType(); building.x = Math.random() * 2048; building.y = Math.random() * 2732; return building; }, addBuildingsToGame: function addBuildingsToGame(buildingTypes) { buildingTypes.forEach(function (BuildingType) { var building = this.createBuilding(BuildingType); game.addChild(building); }, this); } }; BuildingFactory.addBuildingsToGame([Quarry, Windmill, Smithy, Herbalist, Watchtower, Tavern, Church, Barracks, Farm, Workshop, FishingHut, GuardTower, Library, Stable, TownHall, Apothecary, BlacksmithShop, Brewery, School, Granary, Well, Inn, Forester, Gardener, Festival, Marketplace]); var employingWorkPlace = new EmployingWorkPlace(); employingWorkPlace.x = 1500; employingWorkPlace.y = 1500; game.addChild(employingWorkPlace);
===================================================================
--- original.js
+++ change.js
@@ -1209,8 +1209,13 @@
if (otherVillager && otherVillager instanceof Villager) {
this.talkTo(otherVillager);
}
};
+ Villager.prototype.initiateConversation = function (otherVillager) {
+ if (otherVillager && otherVillager instanceof Villager) {
+ this.talkTo(otherVillager);
+ }
+ };
Villager.prototype.talkTo = function (otherVillager) {
if (otherVillager && otherVillager instanceof Villager) {
var message = this.conversationStarters['flirty'][Math.floor(Math.random() * this.conversationStarters['flirty'].length)];
var speechBubble = new Text2(message, {
A background of a paysage with plain and without tree or montainbut no water see from the top in the air 100m by 100m Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
One human medieval villager in a warcraft 2 style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a house in a warcraft 2 style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tree a rock and crambery in a RTS style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A heart comic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cloud in a comic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A market in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An Inn in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An school in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An bakery in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A well in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tree in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An apple in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A rock in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A home in a RTS and fantasy style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A brewery in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A lumberjack in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a marketplace in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a festival in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.