Index: ps/trunk/binaries/data/mods/public/simulation/components/Treasure.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Treasure.js (revision 25823) +++ ps/trunk/binaries/data/mods/public/simulation/components/Treasure.js (revision 25824) @@ -1,111 +1,111 @@ function Treasure() {} Treasure.prototype.Schema = "Provides a bonus when taken. E.g. a supply of resources." + "" + "1000" + "" + "1000" + "" + "" + "" + "" + "" + "" + "" + Resources.BuildSchema("positiveDecimal") + "" + ""; Treasure.prototype.Init = function() { }; Treasure.prototype.ComputeReward = function() { for (let resource in this.template.Resources) { let amount = ApplyValueModificationsToEntity("Treasure/Resources/" + resource, this.template.Resources[resource], this.entity); if (!amount) continue; if (!this.resources) this.resources = {}; this.resources[resource] = amount; } }; /** * @return {Object} - The resources given by this treasure. */ Treasure.prototype.Resources = function() { return this.resources || {}; }; /** * @return {number} - The time in miliseconds it takes to collect this treasure. */ Treasure.prototype.CollectionTime = function() { return +this.template.CollectTime; }; /** * @param {number} entity - The entity collecting us. * @return {boolean} - Whether the reward was granted. */ Treasure.prototype.Reward = function(entity) { if (this.isTaken) return false; let cmpPlayer = QueryOwnerInterface(entity); if (!cmpPlayer) return false; let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); if (cmpFogging) cmpFogging.Activate(); if (this.resources) cmpPlayer.AddResources(this.resources); - let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); + let cmpStatisticsTracker = QueryOwnerInterface(entity, IID_StatisticsTracker); if (cmpStatisticsTracker) cmpStatisticsTracker.IncreaseTreasuresCollectedCounter(); let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); cmpTrigger.CallEvent("OnTreasureCollected", { "player": cmpPlayer.GetPlayerID(), "treasure": this.entity }); this.isTaken = true; Engine.DestroyEntity(this.entity); return true; }; /** * We might live long enough for a collecting entity * to find us again after taking us. * @return {boolean} - Whether we are taken already. */ Treasure.prototype.IsAvailable = function() { return !this.isTaken; }; Treasure.prototype.OnOwnershipChanged = function(msg) { if (msg.to != INVALID_PLAYER) this.ComputeReward(); }; Treasure.prototype.OnValueModification = function(msg) { if (msg.component != "Treasure") return; this.ComputeReward(); }; Engine.RegisterComponentType(IID_Treasure, "Treasure", Treasure);