Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Damage.js
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | function TestLinearSplashDamage() | ||||
const origin = new Vector2D(0, 0); | const origin = new Vector2D(0, 0); | ||||
let data = { | let data = { | ||||
"type": "Ranged", | "type": "Ranged", | ||||
"attackData": { "Damage": { "Hack": 100, "Pierce": 0, "Crush": 0 } }, | "attackData": { "Damage": { "Hack": 100, "Pierce": 0, "Crush": 0 } }, | ||||
"attacker": attacker, | "attacker": attacker, | ||||
"attackerOwner": attackerOwner, | "attackerOwner": attackerOwner, | ||||
"origin": origin, | "origin": origin, | ||||
"radius": 10, | "minRange": 0, | ||||
"maxRange": 10, | |||||
"shape": "Linear", | "shape": "Linear", | ||||
"direction": new Vector3D(1, 747, 0), | "direction": new Vector3D(1, 747, 0), | ||||
"friendlyFire": false, | "friendlyFire": false, | ||||
}; | }; | ||||
let fallOff = function(x, y) | let fallOff = function(x, y) | ||||
{ | { | ||||
return (1 - x * x / (data.radius * data.radius)) * (1 - 25 * y * y / (data.radius * data.radius)); | return (1 - x * x / (data.maxRange * data.maxRange)) * (1 - 25 * y * y / (data.maxRange * data.maxRange)); | ||||
}; | }; | ||||
let hitEnts = new Set(); | let hitEnts = new Set(); | ||||
AddMock(attackerOwner, IID_Player, { | AddMock(attackerOwner, IID_Player, { | ||||
"GetEnemies": () => [2] | "GetEnemies": () => [2] | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | function TestCircularSplashDamage() | ||||
ResetState(); | ResetState(); | ||||
Engine.PostMessage = (ent, iid, message) => {}; | Engine.PostMessage = (ent, iid, message) => {}; | ||||
const radius = 10; | const radius = 10; | ||||
let attackerOwner = 1; | let attackerOwner = 1; | ||||
let fallOff = function(r) | let fallOff = function(r) | ||||
{ | { | ||||
return 1 - r * r / (radius * radius); | return 1 - r * r / (radius * radius); | ||||
bb: no need to call the square function twice
(Do note that calling extra function can have… | |||||
}; | }; | ||||
AddMock(attackerOwner, IID_Player, { | AddMock(attackerOwner, IID_Player, { | ||||
"GetEnemies": () => [2] | "GetEnemies": () => [2] | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => attackerOwner, | "GetPlayerByID": id => attackerOwner, | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | function TestCircularSplashDamage() | ||||
}); | }); | ||||
Attacking.CauseDamageOverArea({ | Attacking.CauseDamageOverArea({ | ||||
"type": "Ranged", | "type": "Ranged", | ||||
"attackData": { "Damage": { "Hack": 100, "Pierce": 0, "Crush": 0 } }, | "attackData": { "Damage": { "Hack": 100, "Pierce": 0, "Crush": 0 } }, | ||||
"attacker": 50, | "attacker": 50, | ||||
"attackerOwner": attackerOwner, | "attackerOwner": attackerOwner, | ||||
"origin": new Vector2D(3, 4), | "origin": new Vector2D(3, 4), | ||||
"radius": radius, | "minRange": 0, | ||||
"maxRange": radius, | |||||
"shape": "Circular", | "shape": "Circular", | ||||
"friendlyFire": false, | "friendlyFire": false, | ||||
}); | }); | ||||
} | } | ||||
TestCircularSplashDamage(); | TestCircularSplashDamage(); | ||||
function Test_MissileHit() | function Test_MissileHit() | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | function Test_MissileHit() | ||||
cmpDelayedDamage.MissileHit(data, 0); | cmpDelayedDamage.MissileHit(data, 0); | ||||
TS_ASSERT(hitEnts.has(61)); | TS_ASSERT(hitEnts.has(61)); | ||||
hitEnts.clear(); | hitEnts.clear(); | ||||
// Add a splash damage. | // Add a splash damage. | ||||
data.splash = {}; | data.splash = {}; | ||||
data.splash.friendlyFire = false; | data.splash.friendlyFire = false; | ||||
data.splash.radius = 10; | data.splash.minRange = 0; | ||||
data.splash.maxRange = 10; | |||||
data.splash.shape = "Circular"; | data.splash.shape = "Circular"; | ||||
data.splash.attackData = { "Damage": { "Hack": 0, "Pierce": 0, "Crush": 200 } }; | data.splash.attackData = { "Damage": { "Hack": 0, "Pierce": 0, "Crush": 200 } }; | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
"ExecuteQueryAroundPos": () => [61, 62] | "ExecuteQueryAroundPos": () => [61, 62] | ||||
}); | }); | ||||
let dealtDamage = 0; | let dealtDamage = 0; | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | function Test_MissileHit() | ||||
TS_ASSERT(hitEnts.has(61)); | TS_ASSERT(hitEnts.has(61)); | ||||
TS_ASSERT_EQUALS(dealtDamage, 100 + 10000 * 200); | TS_ASSERT_EQUALS(dealtDamage, 100 + 10000 * 200); | ||||
dealtDamage = 0; | dealtDamage = 0; | ||||
hitEnts.clear(); | hitEnts.clear(); | ||||
// Test splash damage with friendly fire. | // Test splash damage with friendly fire. | ||||
data.splash = {}; | data.splash = {}; | ||||
data.splash.friendlyFire = true; | data.splash.friendlyFire = true; | ||||
data.splash.radius = 10; | data.splash.minRange = 10; | ||||
data.splash.maxRange = 10; | |||||
data.splash.shape = "Circular"; | data.splash.shape = "Circular"; | ||||
data.splash.attackData = { "Damage": { "Pierce": 0, "Crush": 200 } }; | data.splash.attackData = { "Damage": { "Pierce": 0, "Crush": 200 } }; | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
"ExecuteQueryAroundPos": () => [61, 62] | "ExecuteQueryAroundPos": () => [61, 62] | ||||
}); | }); | ||||
dealtDamage = 0; | dealtDamage = 0; | ||||
Show All 36 Lines |
Wildfire Games · Phabricator
no need to call the square function twice
(Do note that calling extra function can have performance influence, ofc these are tests so who cares and probably the best in this case too)