Ticket #3424: t3424_cleanup_looting_v1.patch
File t3424_cleanup_looting_v1.patch, 3.1 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Looter.js
5 5 6 6 /** 7 7 * Try to collect loot from target entity 8 8 */ 9 9 Looter.prototype.Collect = function(targetEntity) 10 10 { 11 11 var cmpLoot = Engine.QueryInterface(targetEntity, IID_Loot); 12 12 if (!cmpLoot) 13 13 return; 14 14 15 // Loot experience points as defined in the template 15 16 var xp = cmpLoot.GetXp(); 16 17 if (xp > 0) 17 18 { 18 varcmpPromotion = Engine.QueryInterface(this.entity, IID_Promotion);19 let cmpPromotion = Engine.QueryInterface(this.entity, IID_Promotion); 19 20 if (cmpPromotion) 20 21 cmpPromotion.IncreaseXp(xp); 21 22 } 22 var cmpPlayer = QueryOwnerInterface(this.entity);23 var resources = cmpLoot.GetResources();24 for (var type in resources)25 {26 resources[type] = ApplyValueModificationsToEntity("Looter/Resource/"+type, resources[type], this.entity);27 }28 cmpPlayer.AddResources(resources);29 23 30 let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 31 if (cmpStatisticsTracker) 32 cmpStatisticsTracker.IncreaseLootCollectedCounter(resources); 24 // Loot resources as defined in the templates 25 var resources = cmpLoot.GetResources(); 26 for (let type in resources) 27 ApplyValueModificationsToEntity("Looter/Resource/"+type, resources[type], this.entity); 33 28 34 // If target entity has trader component, add carried goods to loot too29 // Loot resources traders carry 35 30 var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader); 36 31 if (cmpTrader) 37 32 { 38 varcarriedGoods = cmpTrader.GetGoods();39 if (carriedGoods.amount && carriedGoods.amount.traderGain)33 let carriedGoods = cmpTrader.GetGoods(); 34 if (carriedGoods.amount) 40 35 { 41 // Convert from {type:<type>,amount:<amount>} to {<type>:<amount>} 42 var resourcesToAdd = {}; 43 resourcesToAdd[carriedGoods.type] = carriedGoods.amount.traderGain; 44 if (carriedGoods.amount.market1Gain) 45 resourcesToAdd[carriedGoods.type] += carriedGoods.amount.market1Gain; 46 if (carriedGoods.amount.market2Gain) 47 resourcesToAdd[carriedGoods.type] += carriedGoods.amount.market2Gain; 48 cmpPlayer.AddResources(resourcesToAdd); 49 50 let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 51 if (cmpStatisticsTracker) 52 cmpStatisticsTracker.IncreaseLootCollectedCounter(resourcesToAdd); 36 resources[carriedGoods.type] += carriedGoods.amount.traderGain ? carriedGoods.amount.traderGain : 0; 37 resources[carriedGoods.type] += carriedGoods.amount.market1Gain ? carriedGoods.amount.market1Gain : 0; 38 resources[carriedGoods.type] += carriedGoods.amount.market2Gain ? carriedGoods.amount.market2Gain : 0; 53 39 } 54 40 } 41 42 // Transfer resources 43 var cmpPlayer = QueryOwnerInterface(this.entity); 44 cmpPlayer.AddResources(resources); 45 46 // Update statistics 47 var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 48 if (cmpStatisticsTracker) 49 cmpStatisticsTracker.IncreaseLootCollectedCounter(resources); 55 50 }; 56 51 57 52 Engine.RegisterComponentType(IID_Looter, "Looter", Looter);