1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/components/AuraManager.js
Mythos_Ruler 4658cfa775 Mythos_Ruler's Christmas update for SVN users!
Includes:

- Unit rank upgrades, based on a patch by Sanderd. Not all civs get all
rank upgrades. For instance, Spartans get the Infantry rank upgrades,
but not the cavalry rank upgrades. Conversely, the Persians get the
cavalry rank upgrades, but not the infantry rank upgrades. Carthaginians
get rank upgrades for their mercenaries, but not their native units.
etc.

- Updated and tweaked many of the skirmish maps. Too many tweaks to
mention. But I did add Iberian circuit walls to many of them! New
"Bactria" Skirmish Map. Will continue to tweak this one to make it more
unique. It's based on modern-day Afghanistan, which the ancients called
"Bactria." A 2nd Ptolemies sandbox demo map.

- Moved the Ptolemaic Lighthouse to Town Phase to have more impact for
the Ptolemy player on maps with water.

- New Thureos shield patterns by Enrique for a NEW unit: Mercenary
Thureos Spearman.

- TECHNOLOGIES: Some techs renamed and tweaked. Plus, a new "Iron Armor"
tech for Heroes. A new "Roman Logistics" tech for the Roman Army Camp
and Siege Walls. A new "Battlefield Medics" tech for the temple that
unlocks (slow) health regeneration for units. The portrait for this tech
is placeholder and needs replaced ASAP.

- Cavalry now have oval selection rings. Eventually I will implement a
selection ring system where the citizen-soldiers and support units have
round rings, while champions have arrows, and heroes have stars. This
helps visually differentiate the roles of these 3 classes of units. Not
yet implemented.

- Vision radius for infantry slightly reduced.

- Fixed sounds for Persian Wonder.

- Fixed footprint sizes for a few buildings and Ptolemaic walls.

- Ptolemies now have the "Military Settlement" system in place. But this
system might go to the Seleucids instead later for historical reasons.

- Cost of fields reduced. Gathering rates for grain reduced.

- Fixed some selection group names for some templates. (Double clicking
didn't select them all as it should have).

- Fixed/Changed/Added some unit and building names, specifically for the
Ptolemies, but for some others as well.

- Some new temp portraits for Ptolemaic units. Ongoing task.

Lastly, I hope these changes don't break anything. They are heavily
tested on my end, but I can't promise I caught all bugs.

This was SVN commit r14388.
2013-12-25 15:49:49 +00:00

172 lines
4.8 KiB
JavaScript

function AuraManager() {}
AuraManager.prototype.Schema =
"<a:component type='system'/><empty/>";
AuraManager.prototype.Init = function()
{
this.modificationsCache = {};
this.modifications = {};
this.templateModificationsCache = {};
this.templateModifications = {};
};
AuraManager.prototype.ensureExists = function(name, value, id, key, defaultData)
{
if (!this[name][value])
{
this[name][value] = {};
this[name+'Cache'][value] = {};
}
if (!this[name][value][id])
{
this[name][value][id] = {};
this[name+'Cache'][value][id] = defaultData;
}
if (!this[name][value][id][key])
this[name][value][id][key] = [];
}
AuraManager.prototype.ApplyBonus = function(value, ent, data, key)
{
this.ensureExists("modifications", value, ent, key, {"add":0, "multiply":1});
this.modifications[value][ent][key].push(data);
if (this.modifications[value][ent][key].length > 1)
return;
// first time added this aura
if (data.multiply)
this.modificationsCache[value][ent].multiply *= data.multiply;
if (data.add)
this.modificationsCache[value][ent].add += data.add;
// post message to the entity to notify it about the change
Engine.PostMessage(ent, MT_ValueModification, { "component": value.split("/")[0] });
};
AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, data, key)
{
this.ensureExists("templateModifications", value, player, key, {});
this.templateModifications[value][player][key].push(data);
if (this.templateModifications[value][player][key].length > 1)
return;
// first time added this aura
for each (var c in classes)
{
if (!this.templateModificationsCache[value][player][c])
this.templateModificationsCache[value][player][c] = [];
if (!this.templateModificationsCache[value][player][c][key])
this.templateModificationsCache[value][player][c][key] = { "add": 0, "multiply": 1};
if (data.multiply)
this.templateModificationsCache[value][player][c][key].multiply *= data.multiply;
if (data.add)
this.templateModificationsCache[value][player][c][key].add += data.add;
}
};
AuraManager.prototype.RemoveBonus = function(value, ent, key)
{
if (!this.modifications[value] ||
!this.modifications[value][ent] ||
!this.modifications[value][ent][key] ||
!this.modifications[value][ent][key].length)
return;
// get the applied data to remove again
var data = this.modifications[value][ent][key].pop();
if (this.modifications[value][ent][key].length > 0)
return;
// out of last aura of this kind, remove modifications
if (data.add)
this.modificationsCache[value][ent].add -= data.add;
if (data.multiply)
this.modificationsCache[value][ent].multiply /= data.multiply;
// post message to the entity to notify it about the change
Engine.PostMessage(ent, MT_ValueModification, { "component": value.split("/")[0] });
};
AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key)
{
if (!this.templateModifications[value] ||
!this.templateModifications[value][player] ||
!this.templateModifications[value][player][key] ||
!this.templateModifications[value][player][key].length)
return;
this.templateModifications[value][player][key].pop();
if (this.templateModifications[value][player][key].length > 0)
return;
for each (var c in classes)
{
this.templateModificationsCache[value][player][c][key].multiply = 1;
this.templateModificationsCache[value][player][c][key].add = 0;
}
};
AuraManager.prototype.ApplyModifications = function(valueName, value, ent)
{
if (!this.modificationsCache[valueName] || !this.modificationsCache[valueName][ent])
return value;
value *= this.modificationsCache[valueName][ent].multiply;
value += this.modificationsCache[valueName][ent].add;
return value;
};
AuraManager.prototype.ApplyTemplateModifications = function(valueName, value, player, template)
{
if (!this.templateModificationsCache[valueName] || !this.templateModificationsCache[valueName][player])
return value;
var rawClasses;
if (template && template.Identity)
{
rawClasses = template.Identity.Classes;
rawClasses = "_string" in rawClasses ? rawClasses._string : "";
if (template.Identity.Rank)
rawClasses += " " + template.Identity.Rank;
}
var classes = rawClasses && rawClasses.length ? rawClasses.split(/\s+/) : [];
var keyList = [];
for (var c in this.templateModificationsCache[valueName][player])
{
if (classes.indexOf(c) == -1)
continue;
for (var key in this.templateModificationsCache[valueName][player][c])
{
// don't add an aura with the same key twice
if (keyList.indexOf(key) != -1)
continue;
value *= this.templateModificationsCache[valueName][player][c][key].multiply;
value += this.templateModificationsCache[valueName][player][c][key].add;
keyList.push(key);
}
}
return value;
};
Engine.RegisterComponentType(IID_AuraManager, "AuraManager", AuraManager);