Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (targetShape.type == "square") | ||||
return Math.abs(distance.x) < targetShape.width / 2 && Math.abs(distance.y) < targetShape.depth / 2; | return Math.abs(distance.x) < targetShape.width / 2 && Math.abs(distance.y) < targetShape.depth / 2; | ||||
} | } | ||||
warn("TestCollision called with an invalid footprint shape"); | warn("TestCollision called with an invalid footprint shape"); | ||||
return false; | return false; | ||||
}; | }; | ||||
/** | /** | ||||
* Get the list of players affected by the damage. | |||||
* @param {number} attackerOwner - the player id of the attacker. | |||||
* @param {boolean} friendlyFire - a flag indicating if allied entities are also damaged. | |||||
* @return {array.number} - the ids of players need to be damaged | |||||
bb: list of number not a JsDOc type (afaiks) => array | |||||
fatherbushidoUnsubmitted Done Inline ActionsI would use number[] for the array for consistency. fatherbushido: I would use number[] for the array for consistency. | |||||
*/ | |||||
Damage.prototype.GetPlayersToDamage = function(attackerOwner, friendlyFire) | |||||
Done Inline ActionsIMO the order of the argument should be inverted bb: IMO the order of the argument should be inverted | |||||
{ | |||||
let cmpPlayer = QueryPlayerIDInterface(attackerOwner); | |||||
Done Inline ActionscmpPlayer leper: `cmpPlayer` | |||||
Done Inline ActionsAdding neutrals here leads to some spurious attack detection messages which might needs to be fixed after, also not convinced of adding them here since neutral is sorta friendly, so i don't expect them to be hit by some splash attack. bb: Adding neutrals here leads to some spurious attack detection messages which might needs to be… | |||||
Done Inline ActionsThis solution was proposed by @vladislavbelov I can change it of course if needed. Mate-86: This solution was proposed by @vladislavbelov
https://trac.wildfiregames. | |||||
Done Inline ActionsPerhaps, yes, neutrals could be together with allies, the main point from me is don't forget about neutrals. vladislavbelov: Perhaps, yes, neutrals could be together with allies, the main point from me is don't forget… | |||||
if (!friendlyFire) | |||||
return cmpPlayer.GetEnemies(); | |||||
return cmpPlayer.GetAllPlayers(); | |||||
} | |||||
Done Inline ActionsIt looks tremendously hardcodish to say that Enemy +neutral+allies == all players (also not sure if the player self and gaia are included in this, need to check that), better make some global function to get all playerIds bb: It looks tremendously hardcodish to say that Enemy +neutral+allies == all players (also not… | |||||
Done Inline ActionsGetAllPlayers would be good, also gaia and self are included in diplomacy. vladislavbelov: `GetAllPlayers` would be good, also gaia and self are included in diplomacy. | |||||
fatherbushidoUnsubmitted Done Inline ActionsI would instead just move the old block from Damage.js here and use the for loop on the number of players instead of that new GetAllPlayers method which has imo nothing to do in the Player component (or I miss some elements). fatherbushido: I would instead just move the old block from Damage.js here and use the for loop on the number… | |||||
/** | |||||
* Handles hit logic after the projectile travel time has passed. | * Handles hit logic after the projectile travel time has passed. | ||||
* @param {Object} data - the data sent by the caller. | * @param {Object} data - the data sent by the caller. | ||||
* @param {number} data.attacker - the entity id of the attacker. | * @param {number} data.attacker - the entity id of the attacker. | ||||
* @param {number} data.target - the entity id of the target. | * @param {number} data.target - the entity id of the target. | ||||
* @param {Vector2D} data.origin - the origin of the projectile hit. | * @param {Vector2D} data.origin - the origin of the projectile hit. | ||||
* @param {Object} data.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | * @param {Object} data.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | ||||
* @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 owner of the attacker. | * @param {number} data.attackerOwner - the player id of the owner of the attacker. | ||||
Show All 9 Lines | |||||
Damage.prototype.MissileHit = function(data, lateness) | Damage.prototype.MissileHit = function(data, lateness) | ||||
{ | { | ||||
if (!data.position) | if (!data.position) | ||||
return; | return; | ||||
// Do this first in case the direct hit kills the target | // Do this first in case the direct hit kills the target | ||||
if (data.isSplash) | if (data.isSplash) | ||||
{ | { | ||||
let playersToDamage = []; | |||||
if (!data.friendlyFire) | |||||
playersToDamage = QueryPlayerIDInterface(data.attackerOwner).GetEnemies(); | |||||
else | |||||
{ | |||||
let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); | |||||
for (let i = 0; i < numPlayers; ++i) | |||||
playersToDamage.push(i); | |||||
} | |||||
this.CauseSplashDamage({ | this.CauseSplashDamage({ | ||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||
"origin": Vector2D.from3D(data.position), | "origin": Vector2D.from3D(data.position), | ||||
"radius": data.radius, | "radius": data.radius, | ||||
"shape": data.shape, | "shape": data.shape, | ||||
"strengths": data.splashStrengths, | "strengths": data.splashStrengths, | ||||
"direction": data.direction, | "direction": data.direction, | ||||
"playersToDamage": playersToDamage, | "playersToDamage": this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire), | ||||
"type": data.type, | "type": data.type, | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
} | } | ||||
let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | ||||
// Deal direct damage if we hit the main target | // Deal direct damage if we hit the main target | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |
list of number not a JsDOc type (afaiks) => array