LCOV - code coverage report
Current view: top level - simulation/components - Looter.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 20 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 2 0.0 %

          Line data    Source code
       1             : function Looter() {}
       2             : 
       3           0 : Looter.prototype.Schema =
       4             :         "<empty/>";
       5             : 
       6           0 : Looter.prototype.Serialize = null; // We have no dynamic state to save
       7             : 
       8             : /**
       9             :  * Try to collect loot from target entity
      10             :  */
      11           0 : Looter.prototype.Collect = function(targetEntity)
      12             : {
      13           0 :         var cmpLoot = Engine.QueryInterface(targetEntity, IID_Loot);
      14           0 :         if (!cmpLoot)
      15           0 :                 return;
      16             : 
      17             :         // Collect resources carried by workers and traders
      18           0 :         var cmpResourceGatherer = Engine.QueryInterface(targetEntity, IID_ResourceGatherer);
      19           0 :         var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader);
      20             : 
      21           0 :         let resourcesCarried = calculateCarriedResources(
      22             :                 cmpResourceGatherer && cmpResourceGatherer.GetCarryingStatus(),
      23             :                 cmpTrader && cmpTrader.GetGoods()
      24             :         );
      25             : 
      26             :         // Loot resources as defined in the templates
      27           0 :         let lootTemplate = cmpLoot.GetResources();
      28           0 :         let resources = {};
      29           0 :         for (let type of Resources.GetCodes())
      30           0 :                 resources[type] =
      31             :                         ApplyValueModificationsToEntity(
      32             :                                 "Looter/Resource/"+type, lootTemplate[type] || 0, this.entity) +
      33             :                         (resourcesCarried[type] || 0);
      34             : 
      35             :         // Transfer resources
      36           0 :         var cmpPlayer = QueryOwnerInterface(this.entity);
      37           0 :         if (cmpPlayer)
      38           0 :                 cmpPlayer.AddResources(resources);
      39             : 
      40             :         // Update statistics
      41           0 :         var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
      42           0 :         if (cmpStatisticsTracker)
      43           0 :                 cmpStatisticsTracker.IncreaseLootCollectedCounter(resources);
      44             : };
      45             : 
      46           0 : Engine.RegisterComponentType(IID_Looter, "Looter", Looter);

Generated by: LCOV version 1.14