implement ptol civ bonus and optimization of ResourceTrickle component, refs #4082

This was SVN commit r18920.
This commit is contained in:
mimo 2016-11-11 12:46:25 +00:00
parent e55ee5048e
commit fe01a710a5
5 changed files with 53 additions and 11 deletions

View File

@ -210,6 +210,17 @@ Auras.prototype.Clean = function()
continue;
}
// When only Player class affected, we do not need a rangeQuery as applicable only to player entity
// and templates TODO maybe add a new type "player"
if (this.IsGlobalAura(name) && this.GetClasses(name).length == 1 && this.GetClasses(name)[0] == "Player")
{
this.ApplyTemplateBonus(name, affectedPlayers);
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
let playerEnts = affectedPlayers.map(player => cmpPlayerManager.GetPlayerByID(player));
this.ApplyBonus(name, playerEnts);
continue;
}
this[name].rangeQuery = cmpRangeManager.CreateActiveQuery(
this.entity,
0,

View File

@ -32,36 +32,47 @@ ResourceTrickle.prototype.Schema =
ResourceTrickle.prototype.Init = function()
{
this.ComputeRates();
// Call the timer
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", this.GetTimer(), this.GetTimer(), undefined);
};
ResourceTrickle.prototype.GetTimer = function()
{
var interval = +this.template.Interval;
return interval;
return +this.template.Interval;
};
ResourceTrickle.prototype.GetRates = function()
{
var rates = {};
for (var resource in this.template.Rates)
rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);
return this.rates;
};
return rates;
ResourceTrickle.prototype.ComputeRates = function()
{
this.rates = {};
for (let resource in this.template.Rates)
this.rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);
};
// Do the actual work here
ResourceTrickle.prototype.Trickle = function(data, lateness)
{
var cmpPlayer = QueryOwnerInterface(this.entity);
// The player entity may also have a ResourceTrickle component
let cmpPlayer = QueryOwnerInterface(this.entity) || Engine.QueryInterface(this.entity, IID_Player);
if (!cmpPlayer)
return;
var rates = this.GetRates();
for (var resource in rates)
cmpPlayer.AddResource(resource, rates[resource]);
for (let resource in this.rates)
cmpPlayer.AddResource(resource, this.rates[resource]);
};
ResourceTrickle.prototype.OnValueModification = function(msg)
{
if (msg.component != "ResourceTrickle")
return;
this.ComputeRates();
};
Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle);

View File

@ -0,0 +1,10 @@
{
"type": "global",
"affects": ["Player"],
"affectedPlayers": ["ExclusiveMutualAlly"],
"modifications": [
{ "value": "ResourceTrickle/Rates/food", "add": 1.0 }
],
"auraName": "Breadbasket of the Mediterranean",
"auraDescription": "All allies automatically gain a slow trickle of food income."
}

View File

@ -60,6 +60,15 @@
<SharedLosTech>unlock_shared_los</SharedLosTech>
<SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
</Player>
<ResourceTrickle>
<Rates>
<food>0.0</food>
<wood>0.0</wood>
<stone>0.0</stone>
<metal>0.0</metal>
</Rates>
<Interval>1000</Interval>
</ResourceTrickle>
<StatisticsTracker/>
<TechnologyManager/>
</Entity>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Entity parent="special/player">
<Auras datatype="tokens">teambonuses/ptol_player_teambonus</Auras>
<EntityLimits>
<LimitRemovers>
<CivilCentre>