Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | this.CauseDamage({ | ||||
"multiplier": damageMultiplier, | "multiplier": damageMultiplier, | ||||
"type": data.type + ".Splash", | "type": data.type + ".Splash", | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Damages units around a given entity. | |||||
* @param {Object} data - the data sent by the caller. | |||||
bb: Should be a cap (fixed the rest of the file in rP22461) | |||||
* @param {number} data.attacker - the entity id of the attacker. | |||||
* @param {Vector2D} data.origin - the origin of the attacker. | |||||
* @param {number} data.radius - the radius of the proximity damage. | |||||
* @param {string} data.shape - the shape of the radius. | |||||
* @param {Object} data.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | |||||
Done Inline ActionsI guess you could write data.strength.hack Number Stan: I guess you could write data.strength.hack Number
| |||||
Done Inline ActionsYou mean: * @param {Object} data.strengths - data of the form { data.strengths.hack: number, data.strengths.pierce: number, data.strengths.crush: number } ? Or something else? Freagarach: You mean:
```
* @param {Object} data.strengths - data of the form { data.strengths.hack… | |||||
Done Inline Actions* @param {number} data.strengths.hack - * @param {number} data.strengths.crush - * @param {number} data.strengths.pierce - But I think that's a bit too verbose. Stan: ```
* @param {number} data.strengths.hack -
* @param {number} data.strengths.crush -
*… | |||||
* @param {string} data.type - the type of damage. | |||||
* @param {number} data.attackerOwner - the player id of the attacker. | |||||
* @param {Object} data.proximityBonus - the attack bonus template from the attacker. | |||||
* @param {number[]} data.playersToDamage - the array of player id's to damage. | |||||
*/ | |||||
Damage.prototype.CauseProximityDamage = function(data) | |||||
Done Inline ActionsIt appears to me that this function is just a copy of the splash code except for the restricted classes, wouldn't it just be better to add that to the splash code too, and reuse that function? One could add a template entry Attack[type].Splash.RestrictedClasses or so. bb: It appears to me that this function is just a copy of the splash code except for the restricted… | |||||
Done Inline ActionsJust keep the name causeSplashDamage then? Or make it more generic? Freagarach: Just keep the name `causeSplashDamage` then? Or make it more generic? | |||||
Done Inline ActionsLike causeAreaDamage? Freagarach: Like `causeAreaDamage`? | |||||
{ | |||||
Done Inline ActionsMTM: Check if the entity causing proximity damage has a position and is in world. Freagarach: MTM: Check if the entity causing proximity damage has a position and is in world. | |||||
// Get nearby entities and define variables | |||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | |||||
let nearEnts; | |||||
if (cmpRangeManager) | |||||
Done Inline Actionssystem component, no need to check bb: system component, no need to check | |||||
Done Inline ActionsDidn't know that :) Freagarach: Didn't know that :) | |||||
nearEnts = cmpRangeManager.ExecuteQuery(data.attacker, 0, data.radius, data.playersToDamage, IID_DamageReceiver); | |||||
let cmpProximityDamage = Engine.QueryInterface(data.attacker, IID_ProximityDamage); | |||||
let restrictedClasses = cmpProximityDamage.GetRestrictedClasses(); | |||||
Done Inline Actionscalling back to the component we just got called from? better add it in the arguments bb: calling back to the component we just got called from? better add it in the arguments | |||||
let damageMultiplier = 1; | |||||
Done Inline ActionsComments on top, start with caps :) Stan: Comments on top, start with caps :) | |||||
// Cycle through all the nearby entities and damage it appropriately based on its distance from the origin. | |||||
for (let ent of nearEnts) | |||||
{ | |||||
// Do not damage restricted classes | |||||
Done Inline ActionsMove out of loop unless you mean ent instead of data.attacker. Stan: Move out of loop unless you mean ent instead of data.attacker. | |||||
let cmpIdentity = QueryMiragedInterface(ent, IID_Identity); | |||||
Done Inline ActionsSame here. Stan: Same here. | |||||
let targetClasses = cmpIdentity.GetClassesList(); | |||||
if (restrictedClasses.length && MatchesClassList(targetClasses, restrictedClasses)) | |||||
continue; | |||||
// Calculate distance effects | |||||
let cmpPosition = Engine.QueryInterface(ent, IID_Position); | |||||
if (!cmpPosition || !cmpPosition.IsInWorld()) | |||||
Done Inline ActionsCheck component, and is in world maybe ? Stan: Check component, and is in world maybe ? | |||||
Done Inline ActionsWhere should I check for the component? In the line "if (data.shape ...)'? Or should I split this line into: let cmpPosition = Engine.QueryInterface(ent, IID_Position); if (cmpPosition) { cmpPosition.GetPosition2D(); } Shouldn't the entity be in the world to be returned by EntitiesNearPoint? Freagarach: Where should I check for the component? In the line "if (data.shape ...)'? Or should I split… | |||||
Done Inline ActionsYou should split the line like your example. Maybe early return instead false. If the unit isnt in the world its likely not moving. The only units that do are planes. cmpPosition.IsInWorld() Stan: You should split the line like your example. Maybe early return instead false. If the unit isnt… | |||||
Done Inline ActionsOff-topic: Are flying objects considered to be not in the world? Freagarach: Off-topic: Are flying objects considered to be not in the world? | |||||
Done Inline ActionsI don't think so but they have their own unit motion. Stan: I don't think so but they have their own unit motion. | |||||
Done Inline ActionsAh I see, thanks! Freagarach: Ah I see, thanks! | |||||
continue; | |||||
let entityPosition = cmpPosition.GetPosition2D(); | |||||
if (data.shape == 'Circular') | |||||
damageMultiplier = 1 - data.origin.distanceToSquared(entityPosition) / (data.radius * data.radius); | |||||
Done Inline ActionsDoes anyone have a use case for proximity damage without distance falloff? So that the value at 10 m is the same as at 1 m? Freagarach: Does anyone have a use case for proximity damage without distance falloff? So that the value at… | |||||
else | |||||
warn("The " + data.shape + " proximity damage shape is not implemented!"); | |||||
// Apply bonusses | |||||
if (data.proximityBonus) | |||||
damageMultiplier *= GetDamageBonus(ent, data.proximityBonus); | |||||
// Call CauseDamage which reduces the hitpoints, posts network command, plays sounds.... | |||||
this.CauseDamage({ | |||||
"strengths": data.strengths, | |||||
"target": ent, | |||||
"attacker": data.attacker, | |||||
"multiplier": damageMultiplier, | |||||
"type": data.type, | |||||
"attackerOwner": data.attackerOwner | |||||
}); | |||||
} | |||||
}; | |||||
/** | |||||
* Causes damage on a given unit. | * Causes damage on a given unit. | ||||
* @param {Object} data - the data passed by the caller. | * @param {Object} data - the data passed by the caller. | ||||
* @param {Object} data.strengths - data in the form of { 'hack': number, 'pierce': number, 'crush': number }. | * @param {Object} data.strengths - data in the form of { 'hack': number, 'pierce': number, 'crush': number }. | ||||
* @param {number} data.target - the entity id of the target. | * @param {number} data.target - the entity id of the target. | ||||
* @param {number} data.attacker - the entity id og the attacker. | * @param {number} data.attacker - the entity id og the attacker. | ||||
* @param {number} data.multiplier - the damage multiplier. | * @param {number} data.multiplier - the damage multiplier. | ||||
* @param {string} data.type - the type of damage. | * @param {string} data.type - the type of damage. | ||||
* @param {number} data.attackerOwner - the player id of the attacker. | * @param {number} data.attackerOwner - the player id of the attacker. | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
Should be a cap (fixed the rest of the file in rP22461)