Index: binaries/data/mods/public/simulation/components/AuraManager.js =================================================================== --- binaries/data/mods/public/simulation/components/AuraManager.js +++ binaries/data/mods/public/simulation/components/AuraManager.js @@ -1,3 +1,6 @@ +/** + * This system component keeps a cache of entities and templates affected by auras and the according value modifications. + */ function AuraManager() {} AuraManager.prototype.Schema = @@ -26,6 +29,16 @@ this.globalAuraSources.splice(idx, 1); }; +/** + * This function ensures that the given keys exist in the given cache. + * + * @param {string} name - Either "modifications" or "templateModifications". + * @param {string} value - Path to a component property that can be affected, for example "TerritoryInfluence/Radius". + * @param {number} id - Affected entity or player ID. + * @param {string} key - Aura name, appended by the entity ID that gives the Aura bonus in case of a stackable aura. + * For example "structures/theatron1284". + * @param {object} defaultData - Value to be assigned if the entry does not exist yet. + */ AuraManager.prototype.ensureExists = function(name, value, id, key, defaultData) { var cacheName = name + "Cache"; @@ -54,6 +67,12 @@ return k; }; +/** + * This function stores the given aura bonus and entity IDs in the cache. + * + * @param {array} ents - Affected entity IDs, for example [123, 456]. + * @param {object} newData - Holds add and multiply values of the aura bonus, for example { "add": 2, "multiply": 1.1 }. + */ AuraManager.prototype.ApplyBonus = function(value, ents, newData, key) { for (let ent of ents) @@ -87,6 +106,12 @@ } }; +/** + * This function stores the given aura bonus and template property in the cache. + * + * @param {number} player - Affected player ID, for example 2. + * @param {array} classes - An Array containing Identity classes describing which entities are affected, for example ["House", "Barracks"]. + */ AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, newData, key) { var data = this.ensureExists("templateModifications", value, player, key, new Map()); @@ -123,6 +148,9 @@ }); }; +/** + * This function removes the given aura bonus and entity IDs from the cache. + */ AuraManager.prototype.RemoveBonus = function(value, ents, key) { var v = this.modifications.get(value); @@ -164,6 +192,9 @@ } }; +/** + * This function removes the given aura bonus and template names from the cache. + */ AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key) { var v = this.templateModifications.get(value); @@ -197,6 +228,9 @@ }); }; +/** + * This function computes the value of a component property of the given entity after all applicable aura bonuses stored in the cache were added. + */ AuraManager.prototype.ApplyModifications = function(valueName, value, ent) { var v = this.modificationsCache.get(valueName); @@ -211,6 +245,9 @@ return value; }; +/** + * This function computes the value of a component property after all applicable aura bonuses stored in the cache were added. + */ AuraManager.prototype.ApplyTemplateModifications = function(valueName, value, player, template) { var v = this.templateModificationsCache.get(valueName);