Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Attacking.js
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
* @param {number} data.radius - The radius of the splash damage. | * @param {number} data.radius - The radius of the splash damage. | ||||
* @param {string} data.shape - The shape of the radius. | * @param {string} data.shape - The shape of the radius. | ||||
* @param {Vector3D} [data.direction] - The unit vector defining the direction. Needed for linear splash damage. | * @param {Vector3D} [data.direction] - The unit vector defining the direction. Needed for linear splash damage. | ||||
* @param {boolean} data.friendlyFire - A flag indicating if allied entities also ought to be damaged. | * @param {boolean} data.friendlyFire - A flag indicating if allied entities also ought to be damaged. | ||||
*/ | */ | ||||
Attacking.prototype.CauseDamageOverArea = function(data) | Attacking.prototype.CauseDamageOverArea = function(data) | ||||
{ | { | ||||
let nearEnts = this.EntitiesNearPoint(data.origin, data.radius, | let nearEnts = this.EntitiesNearPoint(data.origin, data.radius, | ||||
this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire)); | this.GetPlayersToDamage(data.attackerData.owner, data.friendlyFire)); | ||||
let damageMultiplier = 1; | let damageMultiplier = 1; | ||||
// Cycle through all the nearby entities and damage it appropriately based on its distance from the origin. | // Cycle through all the nearby entities and damage it appropriately based on its distance from the origin. | ||||
for (let ent of nearEnts) | for (let ent of nearEnts) | ||||
{ | { | ||||
let entityPosition = Engine.QueryInterface(ent, IID_Position).GetPosition2D(); | let entityPosition = Engine.QueryInterface(ent, IID_Position).GetPosition2D(); | ||||
if (data.shape == 'Circular') // circular effect with quadratic falloff in every direction | if (data.shape == 'Circular') // circular effect with quadratic falloff in every direction | ||||
damageMultiplier = 1 - data.origin.distanceToSquared(entityPosition) / (data.radius * data.radius); | damageMultiplier = 1 - data.origin.distanceToSquared(entityPosition) / (data.radius * data.radius); | ||||
Show All 18 Lines | else if (data.shape == 'Linear') // linear effect with quadratic falloff in two directions (only used for certain missiles) | ||||
else | else | ||||
damageMultiplier = 0; | damageMultiplier = 0; | ||||
} | } | ||||
else // In case someone calls this function with an invalid shape. | else // In case someone calls this function with an invalid shape. | ||||
{ | { | ||||
warn("The " + data.shape + " splash damage shape is not implemented!"); | warn("The " + data.shape + " splash damage shape is not implemented!"); | ||||
} | } | ||||
this.HandleAttackEffects(data.type + ".Splash", data.attackData, ent, data.attacker, data.attackerOwner, damageMultiplier); | this.HandleAttackEffects(data.type + ".Splash", data.attackData, ent, data.attackerData, damageMultiplier); | ||||
} | } | ||||
}; | }; | ||||
Attacking.prototype.HandleAttackEffects = function(attackType, attackData, target, attacker, attackerOwner, bonusMultiplier = 1) | Attacking.prototype.HandleAttackEffects = function(attackType, attackData, target, attackerData, bonusMultiplier = 1) | ||||
{ | { | ||||
let targetState = {}; | let targetState = {}; | ||||
for (let effectType of g_EffectTypes) | for (let effectType of g_EffectTypes) | ||||
{ | { | ||||
if (!attackData[effectType]) | if (!attackData[effectType]) | ||||
continue; | continue; | ||||
bonusMultiplier *= !attackData.Bonuses ? 1 : GetAttackBonus(attacker, target, attackType, attackData.Bonuses); | bonusMultiplier *= !attackData.Bonuses ? 1 : GetAttackBonus(attackerData.entity, 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) | ||||
continue; | continue; | ||||
Object.assign(targetState, cmpReceiver[receiver.method](attackData[effectType], attacker, attackerOwner, bonusMultiplier)); | Object.assign(targetState, cmpReceiver[receiver.method](attackData[effectType], attackerData.entity, attackerData.owner, bonusMultiplier)); | ||||
} | } | ||||
let cmpPromotion = Engine.QueryInterface(attacker, IID_Promotion); | let cmpPromotion = Engine.QueryInterface(attackerData.entity, IID_Promotion); | ||||
if (cmpPromotion && targetState.xp) | if (cmpPromotion && targetState.xp) | ||||
cmpPromotion.IncreaseXp(targetState.xp); | cmpPromotion.IncreaseXp(targetState.xp); | ||||
if (targetState.killed) | if (targetState.killed) | ||||
this.TargetKilled(attacker, target, attackerOwner); | this.TargetKilled(attackerData.entity, target, attackerData.owner); | ||||
Engine.PostMessage(target, MT_Attacked, { | Engine.PostMessage(target, MT_Attacked, { | ||||
"type": attackType, | "type": attackType, | ||||
"target": target, | "target": target, | ||||
"attacker": attacker, | "attacker": attackerData.entity, | ||||
"attackerOwner": attackerOwner, | "attackerOwner": attackerData.owner, | ||||
"damage": -(targetState.HPchange || 0), | "damage": -(targetState.HPchange || 0), | ||||
"capture": targetState.captureChange || 0, | "capture": targetState.captureChange || 0, | ||||
"statusEffects": targetState.inflictedStatuses || [], | "statusEffects": targetState.inflictedStatuses || [], | ||||
}); | }); | ||||
}; | }; | ||||
/** | /** | ||||
* Gets entities near a give point for given players. | * Gets entities near a give point for given players. | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator