Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Attacking.js
Show First 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
let cmpResistance = Engine.QueryInterface(target, IID_Resistance); | let cmpResistance = Engine.QueryInterface(target, IID_Resistance); | ||||
if (cmpResistance && cmpResistance.IsInvulnerable()) | if (cmpResistance && cmpResistance.IsInvulnerable()) | ||||
return false; | return false; | ||||
bonusMultiplier *= !attackData.Bonuses ? 1 : this.GetAttackBonus(attacker, target, attackType, attackData.Bonuses); | bonusMultiplier *= !attackData.Bonuses ? 1 : this.GetAttackBonus(attacker, target, attackType, attackData.Bonuses); | ||||
let targetState = {}; | let targetState = {}; | ||||
for (let effectType of g_EffectTypes) | for (let effectType of AttackEffects.GetTypes()) | ||||
bb: One can reduce a function call be getting an array here with for all AttackEffects the `type`… | |||||
{ | { | ||||
if (!attackData[effectType]) | if (!attackData[effectType]) | ||||
continue; | continue; | ||||
let receiver = g_EffectReceiver[effectType]; | let receiver = AttackEffects.GetReceiver(effectType); | ||||
let cmpReceiver = Engine.QueryInterface(target, global[receiver.IID]); | let cmpReceiver = Engine.QueryInterface(target, global[receiver.IID]); | ||||
if (!cmpReceiver) | if (!cmpReceiver) | ||||
continue; | continue; | ||||
Object.assign(targetState, cmpReceiver[receiver.method](this.GetTotalAttackEffects(target, attackData, effectType, bonusMultiplier, cmpResistance), attacker, attackerOwner)); | Object.assign(targetState, cmpReceiver[receiver.method](this.GetTotalAttackEffects(target, attackData, effectType, bonusMultiplier, cmpResistance), attacker, attackerOwner)); | ||||
} | } | ||||
if (!Object.keys(targetState).length) | if (!Object.keys(targetState).length) | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (!bonus.Classes || MatchesClassList(targetClasses, bonus.Classes)) | ||||
attackBonus *= ApplyValueModificationsToEntity("Attack/" + type + "/Bonuses/" + key + "/Multiplier", +bonus.Multiplier, source); | attackBonus *= ApplyValueModificationsToEntity("Attack/" + type + "/Bonuses/" + key + "/Multiplier", +bonus.Multiplier, source); | ||||
} | } | ||||
return attackBonus; | return attackBonus; | ||||
}; | }; | ||||
var AttackingInstance = new Attacking(); | var AttackingInstance = new Attacking(); | ||||
Engine.RegisterGlobal("Attacking", AttackingInstance); | Engine.RegisterGlobal("Attacking", AttackingInstance); | ||||
AttackEffects = new AttackEffects(); | |||||
Done Inline Actionswanna put var ? Silier: wanna put var ? | |||||
Done Inline ActionsSure, should I also register it as a global? Freagarach: Sure, should I also register it as a global? | |||||
Done Inline Actionsvar cannot be used here, apparently. Freagarach: `var` cannot be used here, apparently. | |||||
Done Inline Actionsvar g_Foo would be good (var probably doesn't work since AttackEffects is already defined as that class) bb: `var g_Foo` would be good (`var` probably doesn't work since AttackEffects is already defined… | |||||
Done Inline Actionsg_AttackEffects imo bb: g_AttackEffects imo | |||||
Done Inline ActionsI'd like that also, but I tried that, but it keeps complaining in the tests. Is it blocking? Freagarach: I'd like that also, but I tried that, but it keeps complaining in the tests. Is it blocking? | |||||
Done Inline ActionsYou need to Engine.RegisterGlobal wraitii: You need to `Engine.RegisterGlobal` |
Wildfire Games · Phabricator
One can reduce a function call be getting an array here with for all AttackEffects the type, IID and method