mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-26 19:13:40 +00:00
fd27f39c20
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
binaries/data/mods/public/simulation/components/[H-P]*
Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
function Looter() {}
|
|
|
|
Looter.prototype.Schema =
|
|
"<empty/>";
|
|
|
|
Looter.prototype.Serialize = null; // We have no dynamic state to save
|
|
|
|
/**
|
|
* Try to collect loot from target entity
|
|
*/
|
|
Looter.prototype.Collect = function(targetEntity)
|
|
{
|
|
var cmpLoot = Engine.QueryInterface(targetEntity, IID_Loot);
|
|
if (!cmpLoot)
|
|
return;
|
|
|
|
// Collect resources carried by workers and traders
|
|
var cmpResourceGatherer = Engine.QueryInterface(targetEntity, IID_ResourceGatherer);
|
|
var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader);
|
|
|
|
const resourcesCarried = calculateCarriedResources(
|
|
cmpResourceGatherer && cmpResourceGatherer.GetCarryingStatus(),
|
|
cmpTrader && cmpTrader.GetGoods()
|
|
);
|
|
|
|
// Loot resources as defined in the templates
|
|
const lootTemplate = cmpLoot.GetResources();
|
|
const resources = {};
|
|
for (const type of Resources.GetCodes())
|
|
resources[type] =
|
|
ApplyValueModificationsToEntity(
|
|
"Looter/Resource/"+type, lootTemplate[type] || 0, this.entity) +
|
|
(resourcesCarried[type] || 0);
|
|
|
|
// Transfer resources
|
|
var cmpPlayer = QueryOwnerInterface(this.entity);
|
|
if (cmpPlayer)
|
|
cmpPlayer.AddResources(resources);
|
|
|
|
// Update statistics
|
|
var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
|
|
if (cmpStatisticsTracker)
|
|
cmpStatisticsTracker.IncreaseLootCollectedCounter(resources);
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_Looter, "Looter", Looter);
|