mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 13:53:57 -07:00
Experience trickle
Implement support for experience trickle. Provide 1 experience trickle when unit is garrisoned in barracks. Differential Revision: https://code.wildfiregames.com/D1245 Patch by: @temple Reviewed by: @wraitii Comments by: mimo, elexis, Freagarach, Stan This was SVN commit r23541.
This commit is contained in:
parent
f5589fe1a9
commit
d392472d44
3 changed files with 54 additions and 2 deletions
|
|
@ -4,6 +4,11 @@ Promotion.prototype.Schema =
|
|||
"<element name='Entity'>" +
|
||||
"<text/>" +
|
||||
"</element>" +
|
||||
"<optional>" +
|
||||
"<element name='TrickleRate' a:help='Trickle of XP gained each second.'>" +
|
||||
"<ref name='nonNegativeDecimal'/>" +
|
||||
"</element>" +
|
||||
"</optional>" +
|
||||
"<element name='RequiredXp'>" +
|
||||
"<data type='positiveInteger'/>" +
|
||||
"</element>";
|
||||
|
|
@ -11,6 +16,7 @@ Promotion.prototype.Schema =
|
|||
Promotion.prototype.Init = function()
|
||||
{
|
||||
this.currentXp = 0;
|
||||
this.ComputeTrickleRate();
|
||||
};
|
||||
|
||||
Promotion.prototype.GetRequiredXp = function()
|
||||
|
|
@ -91,10 +97,44 @@ Promotion.prototype.IncreaseXp = function(amount)
|
|||
Engine.PostMessage(this.entity, MT_ExperienceChanged, {});
|
||||
};
|
||||
|
||||
Promotion.prototype.ComputeTrickleRate = function()
|
||||
{
|
||||
this.trickleRate = ApplyValueModificationsToEntity("Promotion/TrickleRate", +(this.template.TrickleRate || 0), this.entity);
|
||||
this.CheckTrickleTimer();
|
||||
};
|
||||
|
||||
Promotion.prototype.CheckTrickleTimer = function()
|
||||
{
|
||||
if (!this.trickleRate)
|
||||
{
|
||||
if (this.trickleTimer)
|
||||
{
|
||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
cmpTimer.CancelTimer(this.trickleTimer);
|
||||
delete this.trickleTimer;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.trickleTimer)
|
||||
return;
|
||||
|
||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
this.trickleTimer = cmpTimer.SetInterval(this.entity, IID_Promotion, "TrickleTick", 1000, 1000, null);
|
||||
};
|
||||
|
||||
Promotion.prototype.TrickleTick = function()
|
||||
{
|
||||
this.IncreaseXp(this.trickleRate);
|
||||
};
|
||||
|
||||
Promotion.prototype.OnValueModification = function(msg)
|
||||
{
|
||||
if (msg.component == "Promotion")
|
||||
this.IncreaseXp(0);
|
||||
if (msg.component != "Promotion")
|
||||
return;
|
||||
|
||||
this.ComputeTrickleRate();
|
||||
this.IncreaseXp(0);
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_Promotion, "Promotion", Promotion);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type": "garrisonedUnits",
|
||||
"affects": ["Unit"],
|
||||
"modifications": [
|
||||
{ "value": "Promotion/TrickleRate", "add": 1 }
|
||||
],
|
||||
"auraName": "Rigorous Training",
|
||||
"auraDescription": "Units gain experience while garrisoned in barracks."
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Entity parent="template_structure_military">
|
||||
<Auras datatype="tokens">
|
||||
structures/barracks_xp_trickle
|
||||
</Auras>
|
||||
<Cost>
|
||||
<BuildTime>150</BuildTime>
|
||||
<Resources>
|
||||
|
|
|
|||
Loading…
Reference in a new issue