Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Attacking.js
/** | /** | ||||||||
* Provides attack and damage-related helpers under the Attacking umbrella (to avoid name ambiguity with the component). | * Provides attack and damage-related helpers under the Attacking umbrella (to avoid name ambiguity with the component). | ||||||||
*/ | */ | ||||||||
function Attacking() {} | function Attacking() {} | ||||||||
/** | /** | ||||||||
* Builds a RelaxRNG schema of possible attack effects. | * Builds a RelaxRNG schema of possible attack effects. | ||||||||
* Currently harcoded to "Damage", "Capture" and "StatusEffects". | * Currently harcoded to "Damage", "Capture" and "StatusEffects". | ||||||||
* Attacks may also have a "Bonuses" element. | |||||||||
* | * | ||||||||
* @return {string} - RelaxNG schema string | * @return {string} - RelaxNG schema string | ||||||||
*/ | */ | ||||||||
Attacking.prototype.BuildAttackEffectsSchema = function() | Attacking.prototype.BuildAttackEffectsSchema = function() | ||||||||
{ | { | ||||||||
return "" + | return "" + | ||||||||
"<oneOrMore>" + | "<oneOrMore>" + | ||||||||
"<choice>" + | "<choice>" + | ||||||||
"<element name='Damage'>" + | "<element name='Damage'>" + | ||||||||
"<oneOrMore>" + | "<oneOrMore>" + | ||||||||
"<element a:help='One or more elements describing damage types'>" + | "<element a:help='One or more elements describing damage types'>" + | ||||||||
"<anyName>" + | "<anyName/>" + | ||||||||
// Armour requires Foundation to not be a damage type. | |||||||||
"<except><name>Foundation</name></except>" + | |||||||||
"</anyName>" + | |||||||||
"<ref name='nonNegativeDecimal' />" + | "<ref name='nonNegativeDecimal' />" + | ||||||||
"</element>" + | "</element>" + | ||||||||
"</oneOrMore>" + | "</oneOrMore>" + | ||||||||
"</element>" + | "</element>" + | ||||||||
"<element name='Capture' a:help='Capture points value'>" + | "<element name='Capture' a:help='Capture points value'>" + | ||||||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||||||
"</element>" + | "</element>" + | ||||||||
"<element name='StatusEffects' a:help='Effects like poisoning or burning a unit.'>" + | "<element name='StatusEffects' a:help='Effects like poisoning or burning a unit.'>" + | ||||||||
"<oneOrMore>" + | "<oneOrMore>" + | ||||||||
"<element>" + | "<element>" + | ||||||||
"<anyName/>" + | "<anyName/>" + | ||||||||
"<interleave>" + | "<interleave>" + | ||||||||
"<element name='Duration' a:help='The duration of the status while the effect occurs.'><ref name='nonNegativeDecimal'/></element>" + | "<element name='Duration' a:help='The duration of the status while the effect occurs.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||
"<element name='Interval' a:help='Interval between the occurances of the effect.'><ref name='nonNegativeDecimal'/></element>" + | "<element name='Interval' a:help='Interval between the occurances of the effect.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||
"<element name='Damage' a:help='Damage caused by the effect.'><ref name='nonNegativeDecimal'/></element>" + | "<element name='Damage' a:help='Damage caused by the effect.'><ref name='nonNegativeDecimal'/></element>" + | ||||||||
"</interleave>" + | "</interleave>" + | ||||||||
"</element>" + | "</element>" + | ||||||||
"</oneOrMore>" + | "</oneOrMore>" + | ||||||||
"</element>" + | "</element>" + | ||||||||
"</choice>" + | "</choice>" + | ||||||||
"</oneOrMore>" + | "</oneOrMore>"; | ||||||||
}; | |||||||||
/** | |||||||||
* Builds a RelaxRNG schema of possible bonuses. | |||||||||
* Attacks may also have a "Bonuses" element. | |||||||||
* | |||||||||
* @return {string} - RelaxNG schema string | |||||||||
*/ | |||||||||
Attacking.prototype.BuildBonusSchema = function() | |||||||||
{ | |||||||||
return "" + | |||||||||
"<optional>" + | "<optional>" + | ||||||||
"<element name='Bonuses'>" + | "<element name='Bonuses'>" + | ||||||||
"<zeroOrMore>" + | "<zeroOrMore>" + | ||||||||
"<element>" + | "<element>" + | ||||||||
"<anyName/>" + | "<anyName/>" + | ||||||||
"<interleave>" + | "<interleave>" + | ||||||||
"<optional>" + | "<optional>" + | ||||||||
"<element name='Civ' a:help='If an entity has this civ then the bonus is applied'><text/></element>" + | "<element name='Civ' a:help='If an entity has this civ then the bonus is applied'><text/></element>" + | ||||||||
Show All 29 Lines | if (template.StatusEffects) | ||||||||
ret.StatusEffects = template.StatusEffects; | ret.StatusEffects = template.StatusEffects; | ||||||||
if (template.Bonuses) | if (template.Bonuses) | ||||||||
ret.Bonuses = template.Bonuses; | ret.Bonuses = template.Bonuses; | ||||||||
return ret; | return ret; | ||||||||
}; | }; | ||||||||
Attacking.prototype.GetTotalAttackEffects = function(effectData, effectType, cmpResistance) | Attacking.prototype.GetTotalAttackEffects = function(effectData, effectType, target) | ||||||||
{ | { | ||||||||
let cmpResistance = Engine.QueryInterface(target, IID_Resistance); | |||||||||
let total = 0; | let total = 0; | ||||||||
let armourStrengths = cmpResistance ? cmpResistance.GetArmourStrengths(effectType) : {}; | let armourStrengths = {}; | ||||||||
if (cmpResistance) | |||||||||
bbUnsubmitted Done Inline Actions
bb: | |||||||||
{ | |||||||||
if (effectType == "Capture") | |||||||||
armourStrengths = cmpResistance.GetArmourStrengths(effectType); | |||||||||
else | |||||||||
armourStrengths = cmpResistance.GetArmourStrengths(effectType)[effectType]; | |||||||||
} | |||||||||
for (let type in effectData) | for (let type in effectData) | ||||||||
total += effectData[type] * Math.pow(0.9, armourStrengths[type] || 0); | total += effectData[type] * Math.pow(0.9, armourStrengths[type] || 0); | ||||||||
Done Inline ActionsresistanceStrengths ? resistanceStrengths[type] || 0 : 0 Freagarach: `resistanceStrengths ? resistanceStrengths[type] || 0 : 0` | |||||||||
return total; | return total; | ||||||||
}; | }; | ||||||||
/** | /** | ||||||||
* Gives the position of the given entity, taking the lateness into account. | * Gives the position of the given entity, taking the lateness into account. | ||||||||
* @param {number} ent - Entity id of the entity we are finding the location for. | * @param {number} ent - Entity id of the entity we are finding the location for. | ||||||||
* @param {number} lateness - The time passed since the expected time to fire the function. | * @param {number} lateness - The time passed since the expected time to fire the function. | ||||||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | for (let ent of nearEnts) | ||||||||
this.HandleAttackEffects(data.type + ".Splash", data.attackData, ent, data.attacker, data.attackerOwner, damageMultiplier); | this.HandleAttackEffects(data.type + ".Splash", data.attackData, ent, data.attacker, data.attackerOwner, damageMultiplier); | ||||||||
} | } | ||||||||
}; | }; | ||||||||
Attacking.prototype.HandleAttackEffects = function(attackType, attackData, target, attacker, attackerOwner, bonusMultiplier = 1) | Attacking.prototype.HandleAttackEffects = function(attackType, attackData, target, attacker, attackerOwner, bonusMultiplier = 1) | ||||||||
{ | { | ||||||||
let targetState = {}; | let targetState = {}; | ||||||||
for (let effectType of g_EffectTypes) | for (let effectType of g_EffectTypes) | ||||||||
{ | { | ||||||||
Done Inline Actions
bb: | |||||||||
if (!attackData[effectType]) | if (!attackData[effectType]) | ||||||||
continue; | continue; | ||||||||
bonusMultiplier *= !attackData.Bonuses ? 1 : GetAttackBonus(attacker, target, attackType, attackData.Bonuses); | bonusMultiplier *= !attackData.Bonuses ? 1 : GetAttackBonus(attacker, target, attackType, attackData.Bonuses); | ||||||||
let receiver = g_EffectReceiver[effectType]; | let receiver = g_EffectReceiver[effectType]; | ||||||||
let cmpReceiver = Engine.QueryInterface(target, global[receiver.IID]); | let cmpReceiver = Engine.QueryInterface(target, global[receiver.IID]); | ||||||||
if (!cmpReceiver) | if (!cmpReceiver) | ||||||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator