Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ModifiersManager.js
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | ModifiersManager.prototype.ModifiersChanged = function(propertyName, entity) | ||||
if (playerCache) | if (playerCache) | ||||
{ | { | ||||
let cmpPlayer = Engine.QueryInterface(entity, IID_Player); | let cmpPlayer = Engine.QueryInterface(entity, IID_Player); | ||||
if (cmpPlayer) | if (cmpPlayer) | ||||
this.SendPlayerModifierMessages(propertyName, cmpPlayer.GetPlayerID()); | this.SendPlayerModifierMessages(propertyName, cmpPlayer.GetPlayerID()); | ||||
} | } | ||||
else | else | ||||
Engine.PostMessage(entity, MT_ValueModification, { "entities": [entity], "component": propertyName.split("/")[0], "valueNames": [propertyName] }); | Engine.PostValueModification(entity, { "entities": [entity], "component": propertyName.split("/")[0], "valueNames": [propertyName] }) | ||||
}; | }; | ||||
ModifiersManager.prototype.SendPlayerModifierMessages = function(propertyName, player) | ModifiersManager.prototype.SendPlayerModifierMessages = function(propertyName, player) | ||||
{ | { | ||||
// TODO: it would be preferable to be able to batch this (i.e. one message for several properties) | // TODO: it would be preferable to be able to batch this (i.e. one message for several properties) | ||||
Engine.PostMessage(SYSTEM_ENTITY, MT_TemplateModification, { "player": player, "component": propertyName.split("/")[0], "valueNames": [propertyName] }); | Engine.PostMessage(SYSTEM_ENTITY, MT_TemplateModification, { "player": player, "component": propertyName.split("/")[0], "valueNames": [propertyName] }); | ||||
// AIInterface wants the entities potentially affected. | // AIInterface wants the entities potentially affected. | ||||
// TODO: improve on this | // TODO: improve on this | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
let ents = cmpRangeManager.GetEntitiesByPlayer(player); | let ents = cmpRangeManager.GetEntitiesByPlayer(player); | ||||
Engine.BroadcastMessage(MT_ValueModification, { "entities": ents, "component": propertyName.split("/")[0], "valueNames": [propertyName] }); | ents.forEach(ent => Engine.PostValueModification(ent, { "entities": [ent], "component": propertyName.split("/")[0], "valueNames": [propertyName] })); | ||||
Stan: Could probably save some cycles by creating the object once and then just changing the contents… | |||||
}; | }; | ||||
ModifiersManager.prototype.InvalidatePlayerEntCache = function(valueCache, propertyName, entsMap) | ModifiersManager.prototype.InvalidatePlayerEntCache = function(valueCache, propertyName, entsMap) | ||||
{ | { | ||||
entsMap = entsMap.get(propertyName); | entsMap = entsMap.get(propertyName); | ||||
if (entsMap) | if (entsMap) | ||||
{ | { | ||||
// Invalidate all local caches directly (for simplicity in ApplyModifiers). | // Invalidate all local caches directly (for simplicity in ApplyModifiers). | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | playerModifs[propertyName].forEach(item => item.value.forEach(modif => { | ||||
return; | return; | ||||
if (!modifiedComponents[component]) | if (!modifiedComponents[component]) | ||||
modifiedComponents[component] = []; | modifiedComponents[component] = []; | ||||
modifiedComponents[component].push(propertyName); | modifiedComponents[component].push(propertyName); | ||||
})); | })); | ||||
} | } | ||||
for (let component in modifiedComponents) | for (let component in modifiedComponents) | ||||
Engine.PostMessage(msg.entity, MT_ValueModification, { "entities": [msg.entity], "component": component, "valueNames": modifiedComponents[component] }); | Engine.PostValueModification(msg.entity, { "entities": [msg.entity], "component": component, "valueNames": modifiedComponents[component] }); | ||||
}; | }; | ||||
/** | /** | ||||
* The following functions simply proxy MultiKeyMap's interface. | * The following functions simply proxy MultiKeyMap's interface. | ||||
*/ | */ | ||||
ModifiersManager.prototype.AddModifier = function(propName, ModifID, Modif, entity, stackable = false) { | ModifiersManager.prototype.AddModifier = function(propName, ModifID, Modif, entity, stackable = false) { | ||||
return this.modifiersStorage.AddItem(propName, ModifID, Modif, entity, stackable); | return this.modifiersStorage.AddItem(propName, ModifID, Modif, entity, stackable); | ||||
}; | }; | ||||
Show All 30 Lines |
Wildfire Games · Phabricator
Could probably save some cycles by creating the object once and then just changing the contents of entity[0]