Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/data/abilities/effects/Hospital.js
- This file was added.
function Hospital() | |||||
{ | |||||
this.name = "Hospital"; | |||||
this.schema = | |||||
"<element name='HealRate' a:help='The healing rate when the hospital is active'>" + | |||||
"<ref name='nonNegativeDecimal'/>" + | |||||
"</element>" + | |||||
"<element name='Requires' a:help='This hospital requires the following class garrisoned in to work.'>" + | |||||
"<attribute name='datatype'>" + | |||||
"<value>tokens</value>" + | |||||
"</attribute>" + | |||||
"<text/>" + | |||||
"</element>"; | |||||
} | |||||
Hospital.prototype.SetupData = function(entity, templateData) | |||||
{ | |||||
return templateData; | |||||
} | |||||
Hospital.prototype.GetIcon = function(entity, templateData) | |||||
{ | |||||
return "portraits/technologies/healing_rate.png"; | |||||
} | |||||
Hospital.prototype.GetTooltip = function(entity, templateData) | |||||
{ | |||||
return "This hospital, if garrisoned with a unit of class " + templateData.Hospital.Requires._string + ", will heal other garrisoned units by " + templateData.Hospital.HealRate + " HP per second."; | |||||
} | |||||
Hospital.prototype.OnFire = function(entity, templateData, commandData) | |||||
{ | |||||
let cmpModManager = QueryOwnerInterface(entity, IID_ModifiersManager); | |||||
if (!cmpModManager) | |||||
return; | |||||
cmpModManager.AddLocalModifiers(entity, "Hospital_Ability", 1000, { | |||||
"TerritoryDecay/DecayRate": {"affects": ["Structure"], "replace": 0}, | |||||
"GarrisonHolder/BuffHeal": {"affects": ["Structure"], "replace": +templateData.Hospital.HealRate}, | |||||
}); | |||||
} | |||||
Hospital.prototype.OnFinished = function(entity, templateData, commandData) | |||||
{ | |||||
let cmpModManager = QueryOwnerInterface(entity, IID_ModifiersManager); | |||||
if (!cmpModManager) | |||||
return; | |||||
cmpModManager.RemoveLocalModifier(entity, "TerritoryDecay/DecayRate", "Hospital_Ability"); | |||||
cmpModManager.RemoveLocalModifier(entity, "GarrisonHolder/BuffHeal", "Hospital_Ability"); | |||||
} | |||||
Hospital.prototype.IsFinished = function(entity, templateData, commandData) | |||||
{ | |||||
return !this.Validate(entity, templateData, false); | |||||
} | |||||
Hospital.prototype.Validate = function(entity, templateData, sendMessages) | |||||
{ | |||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | |||||
let entities = cmpGarrisonHolder.GetEntities(); | |||||
for (let ent of entities) | |||||
{ | |||||
let Identity = Engine.QueryInterface(ent, IID_Identity); | |||||
if (MatchesClassList(Identity.GetClassesList(), templateData.Hospital.Requires._string)) | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
var Hospital = new Hospital(); | |||||
AbilityEffects.RegisterEffect(Hospital); |
Wildfire Games · Phabricator