Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Cost.js
Show All 17 Lines | Cost.prototype.Schema = | ||||
"</element>" + | "</element>" + | ||||
"<element name='PopulationBonus' a:help='Population cap increase while this entity exists'>" + | "<element name='PopulationBonus' a:help='Population cap increase while this entity exists'>" + | ||||
"<data type='nonNegativeInteger'/>" + | "<data type='nonNegativeInteger'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" + | "<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Resources' a:help='Resource costs to construct/train this entity'>" + | "<element name='Resources' a:help='Resource costs to construct/train this entity'>" + | ||||
Resources.BuildSchema("nonNegativeDecimal") + | Resources.BuildSchema("nonNegativeInteger") + | ||||
"</element>"; | "</element>"; | ||||
Cost.prototype.Init = function() | Cost.prototype.Init = function() | ||||
{ | { | ||||
this.populationCost = +this.template.Population; | this.populationCost = +this.template.Population; | ||||
this.populationBonus = +this.template.PopulationBonus; | this.populationBonus = +this.template.PopulationBonus; | ||||
}; | }; | ||||
Cost.prototype.GetPopCost = function() | Cost.prototype.GetPopCost = function() | ||||
{ | { | ||||
return this.populationCost; | return this.populationCost; | ||||
}; | }; | ||||
Cost.prototype.GetPopBonus = function() | Cost.prototype.GetPopBonus = function() | ||||
{ | { | ||||
return this.populationBonus; | return this.populationBonus; | ||||
}; | }; | ||||
Cost.prototype.GetBuildTime = function() | Cost.prototype.GetBuildTime = function() | ||||
{ | { | ||||
var cmpPlayer = QueryOwnerInterface(this.entity); | var cmpPlayer = QueryOwnerInterface(this.entity); | ||||
var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier; | var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier; | ||||
return ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity); | return Math.floor(ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity)); | ||||
}; | }; | ||||
Cost.prototype.GetResourceCosts = function(owner) | Cost.prototype.GetResourceCosts = function(owner) | ||||
{ | { | ||||
if (!owner) | if (!owner) | ||||
{ | { | ||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
if (!cmpOwnership) | if (!cmpOwnership) | ||||
error("GetResourceCosts called without valid ownership"); | error("GetResourceCosts called without valid ownership"); | ||||
else | else | ||||
owner = cmpOwnership.GetOwner(); | owner = cmpOwnership.GetOwner(); | ||||
} | } | ||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | ||||
let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName); | let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName); | ||||
let costs = {}; | let costs = {}; | ||||
for (let res in this.template.Resources) | for (let res in this.template.Resources) | ||||
costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate); | costs[res] = Math.floor(ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate)); | ||||
return costs; | return costs; | ||||
}; | }; | ||||
Cost.prototype.OnOwnershipChanged = function(msg) | Cost.prototype.OnOwnershipChanged = function(msg) | ||||
{ | { | ||||
if (msg.from != -1) | if (msg.from != -1) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator