Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
// Convenient container abstraction for storing items referenced by a 3-tuple.
|
|
|
|
|
// Used by the ModifiersManager to store items by (property Name, entity, item ID).
|
|
|
|
|
// Methods starting with an underscore are private to the storage.
|
|
|
|
|
// This supports stackable items as it stores count for each 3-tuple.
|
|
|
|
|
// It is designed to be as fast as can be for a JS container.
|
|
|
|
|
function MultiKeyMap()
|
|
|
|
|
{
|
|
|
|
|
this.items = new Map();
|
|
|
|
|
// Keys are referred to as 'primaryKey', 'secondaryKey', 'itemID'.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MultiKeyMap.prototype.Serialize = function()
|
|
|
|
|
{
|
2025-05-06 05:16:13 -07:00
|
|
|
const ret = [];
|
|
|
|
|
for (const primary of this.items.keys())
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
{
|
|
|
|
|
// Keys of a Map can be arbitrary types whereas objects only support string, so use a list.
|
2025-05-06 05:16:13 -07:00
|
|
|
const vals = [primary, []];
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
ret.push(vals);
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const secondary of this.items.get(primary).keys())
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
vals[1].push([secondary, this.items.get(primary).get(secondary)]);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MultiKeyMap.prototype.Deserialize = function(data)
|
|
|
|
|
{
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const primary in data)
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
{
|
|
|
|
|
this.items.set(data[primary][0], new Map());
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const secondary in data[primary][1])
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
this.items.get(data[primary][0]).set(data[primary][1][secondary][0], data[primary][1][secondary][1]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a single item.
|
|
|
|
|
* NB: if you add an item with a different value but the same itemID, the original value remains.
|
|
|
|
|
* @param item - an object.
|
|
|
|
|
* @param itemID - internal ID of this item, for later removal and/or updating
|
|
|
|
|
* @param stackable - if stackable, changing the count of items invalides, otherwise not.
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.AddItem = function(primaryKey, itemID, item, secondaryKey, stackable = false)
|
|
|
|
|
{
|
|
|
|
|
if (!this._AddItem(primaryKey, itemID, item, secondaryKey, stackable))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
this._OnItemModified(primaryKey, secondaryKey, itemID);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add items to multiple properties at once (only one item per property)
|
|
|
|
|
* @param items - Dictionnary of { primaryKey: item }
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.AddItems = function(itemID, items, secondaryKey, stackable = false)
|
|
|
|
|
{
|
|
|
|
|
let modified = false;
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const primaryKey in items)
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
modified = this.AddItem(primaryKey, itemID, items[primaryKey], secondaryKey, stackable) || modified;
|
|
|
|
|
return modified;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a item on a property.
|
|
|
|
|
* @param primaryKey - property to change (e.g. "Health/Max")
|
|
|
|
|
* @param itemID - internal ID of the item to remove
|
|
|
|
|
* @param secondaryKey - secondaryKey ID
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.RemoveItem = function(primaryKey, itemID, secondaryKey, stackable = false)
|
|
|
|
|
{
|
|
|
|
|
if (!this._RemoveItem(primaryKey, itemID, secondaryKey, stackable))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
this._OnItemModified(primaryKey, secondaryKey, itemID);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes items with this ID for any property name.
|
|
|
|
|
* Naively iterates all property names.
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.RemoveAllItems = function(itemID, secondaryKey, stackable = false)
|
|
|
|
|
{
|
|
|
|
|
let modified = false;
|
|
|
|
|
// Map doesn't implement some so use a for-loop here.
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const primaryKey of this.items.keys())
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
modified = this.RemoveItem(primaryKey, itemID, secondaryKey, stackable) || modified;
|
|
|
|
|
return modified;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param itemID - internal ID of the item to try and find.
|
|
|
|
|
* @returns true if there is at least one item with that itemID
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.HasItem = function(primaryKey, itemID, secondaryKey)
|
|
|
|
|
{
|
|
|
|
|
// some() returns false for an empty list which is wanted here.
|
|
|
|
|
return this._getItems(primaryKey, secondaryKey).some(item => item._ID === itemID);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if we have a item for any property name.
|
|
|
|
|
* Naively iterates all property names.
|
|
|
|
|
* @returns true if there is at least one item with that itemID
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.HasAnyItem = function(itemID, secondaryKey)
|
|
|
|
|
{
|
|
|
|
|
// Map doesn't implement some so use for loops instead.
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const primaryKey of this.items.keys())
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
if (this.HasItem(primaryKey, itemID, secondaryKey))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns A list of items (references to stored items to avoid copying)
|
|
|
|
|
* (these need to be treated as constants to not break the map)
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.GetItems = function(primaryKey, secondaryKey)
|
|
|
|
|
{
|
|
|
|
|
return this._getItems(primaryKey, secondaryKey);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns A dictionary of { Property Name: items } for the secondary Key.
|
|
|
|
|
* Naively iterates all property names.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype.GetAllItems = function(secondaryKey)
|
|
|
|
|
{
|
2025-05-06 05:16:13 -07:00
|
|
|
const items = {};
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
|
|
|
|
|
// Map doesn't implement filter so use a for loop.
|
2025-05-06 05:16:13 -07:00
|
|
|
for (const primaryKey of this.items.keys())
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
{
|
|
|
|
|
if (!this.items.get(primaryKey).has(secondaryKey))
|
|
|
|
|
continue;
|
|
|
|
|
items[primaryKey] = this.GetItems(primaryKey, secondaryKey);
|
|
|
|
|
}
|
|
|
|
|
return items;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns a list of items.
|
|
|
|
|
* This does not necessarily return a reference to items' list, use _getItemsOrInit for that.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype._getItems = function(primaryKey, secondaryKey)
|
|
|
|
|
{
|
|
|
|
|
let cache = this.items.get(primaryKey);
|
|
|
|
|
if (cache)
|
|
|
|
|
cache = cache.get(secondaryKey);
|
|
|
|
|
return cache ? cache : [];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns a reference to the list of items for that property name and secondaryKey.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype._getItemsOrInit = function(primaryKey, secondaryKey)
|
|
|
|
|
{
|
|
|
|
|
let cache = this.items.get(primaryKey);
|
|
|
|
|
if (!cache)
|
|
|
|
|
cache = this.items.set(primaryKey, new Map()).get(primaryKey);
|
|
|
|
|
|
|
|
|
|
let cache2 = cache.get(secondaryKey);
|
|
|
|
|
if (!cache2)
|
|
|
|
|
cache2 = cache.set(secondaryKey, []).get(secondaryKey);
|
|
|
|
|
return cache2;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype._AddItem = function(primaryKey, itemID, item, secondaryKey, stackable)
|
|
|
|
|
{
|
2025-05-06 05:16:13 -07:00
|
|
|
const items = this._getItemsOrInit(primaryKey, secondaryKey);
|
|
|
|
|
for (const it of items)
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
if (it._ID == itemID)
|
|
|
|
|
{
|
|
|
|
|
it._count++;
|
|
|
|
|
return stackable;
|
|
|
|
|
}
|
2019-09-22 05:05:04 -07:00
|
|
|
items.push({ "_ID": itemID, "_count": 1, "value": item });
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns true if the items list changed in such a way that cached values are possibly invalidated.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype._RemoveItem = function(primaryKey, itemID, secondaryKey, stackable)
|
|
|
|
|
{
|
2025-05-06 05:16:13 -07:00
|
|
|
const items = this._getItems(primaryKey, secondaryKey);
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
|
2025-05-06 05:16:13 -07:00
|
|
|
const existingItem = items.filter(item => { return item._ID == itemID; });
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
if (!existingItem.length)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (--existingItem[0]._count > 0)
|
|
|
|
|
return stackable;
|
|
|
|
|
|
2025-05-06 05:16:13 -07:00
|
|
|
const stilValidItems = items.filter(item => item._count > 0);
|
Add a system component to handle stat modifiers, make technologies and auras use this common interface.
The ModifiersManager system component provides an interface to add and
remove modifiers, and get modified stats.
The goal is to merge all the different stat-modifying systems 0 A.D. has
implemented over the years.
This commit makes technologies and auras use ModifiersManager. Some
cheats and AI bonuses also have a similar stat-modifying effect that
have not yet been updated.
Further, this system component makes it possible for e.g. triggers to
easily add modifiers, enabling the writing of Castle Blood Automatic,
RPG or Tower Defense maps without the need for mods or hacks.
The 'Modifier' name was preferred over 'Modification' as it is shorter
and more readable, along with the logic that 'modifiers' store
'modifications' and this stores modifiers. Renaming of other functions
and classes has been left for future work for now.
Internally, this uses a JS data structure. If performance issues arise
with it in the future, this data structure or the whole component could
be moved to C++.
The performance has been tested to be about as fast as the current
implementations (and specifically much faster for global auras with no
icons). Testing showed that sending value modification messages was by
far the slowest part.
Comments by: leper, Stan, elexis
Differential Revision: https://code.wildfiregames.com/D274
This was SVN commit r22767.
2019-08-24 00:37:07 -07:00
|
|
|
|
|
|
|
|
// Delete entries from the map if necessary to clean up.
|
|
|
|
|
if (!stilValidItems.length)
|
|
|
|
|
{
|
|
|
|
|
this.items.get(primaryKey).delete(secondaryKey);
|
|
|
|
|
if (!this.items.get(primaryKey).size)
|
|
|
|
|
this.items.delete(primaryKey);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.items.get(primaryKey).set(secondaryKey, stilValidItems);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stub method, to overload.
|
|
|
|
|
*/
|
|
|
|
|
MultiKeyMap.prototype._OnItemModified = function(primaryKey, secondaryKey, itemID) {};
|