Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Damage.js
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | function Test_Generic() | ||||
let data = { | let data = { | ||||
"type": "Melee", | "type": "Melee", | ||||
"attackData": { | "attackData": { | ||||
"Damage": { "Hack": 0, "Pierce": 0, "Crush": damage }, | "Damage": { "Hack": 0, "Pierce": 0, "Crush": damage }, | ||||
}, | }, | ||||
"target": target, | "target": target, | ||||
"attacker": attacker, | "attacker": attacker, | ||||
"attackerOwner": attackerOwner, | "attackerOwner": attackerOwner, | ||||
"attackerPosition": targetPos, | |||||
"attackHeightOffset": 0, | |||||
"position": targetPos, | "position": targetPos, | ||||
"projectileId": 9, | "projectileId": 9, | ||||
"direction": new Vector3D(1, 0, 0) | "direction": new Vector3D(1, 0, 0) | ||||
}; | }; | ||||
AddMock(atkPlayerEntity, IID_Player, { | AddMock(atkPlayerEntity, IID_Player, { | ||||
"GetEnemies": () => [targetOwner] | "GetEnemies": () => [targetOwner] | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 97 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, | ||||
"attackerPosition": new Vector3D(0, 0, 0), | |||||
"attackHeightOffset": 0, | |||||
"origin": origin, | "origin": origin, | ||||
"radius": 10, | "radius": 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) | ||||
Show All 21 Lines | "DistanceToPoint": (ent) => ({ | ||||
"60": Math.sqrt(9.25), | "60": Math.sqrt(9.25), | ||||
"61": 0, | "61": 0, | ||||
"62": Math.sqrt(29) | "62": Math.sqrt(29) | ||||
}[ent]) | }[ent]) | ||||
}); | }); | ||||
AddMock(60, IID_Position, { | AddMock(60, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(3, -0.5), | "GetPosition2D": () => new Vector2D(3, -0.5), | ||||
"GetPosition": () => new Vector3D(3, 0, -0.5), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(61, IID_Position, { | AddMock(61, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(0, 0), | "GetPosition2D": () => new Vector2D(0, 0), | ||||
"GetPosition": () => new Vector3D(0, 0, 0), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(62, IID_Position, { | AddMock(62, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(5, 2), | "GetPosition2D": () => new Vector2D(5, 2), | ||||
"GetPosition": () => new Vector3D(5, 0, 2), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(60, IID_Health, { | AddMock(60, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
hitEnts.add(60); | hitEnts.add(60); | ||||
TS_ASSERT_EQUALS(amount, 100 * fallOff(3, -0.5)); | TS_ASSERT_EQUALS(amount, 100 * fallOff(3, -0.5)); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | "DistanceToPoint": (ent, x, z) => ({ | ||||
"63": Math.sqrt(85), | "63": Math.sqrt(85), | ||||
"64": 10, | "64": 10, | ||||
"65": 2 | "65": 2 | ||||
}[ent]) | }[ent]) | ||||
}); | }); | ||||
AddMock(60, IID_Position, { | AddMock(60, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(3, 4), | "GetPosition2D": () => new Vector2D(3, 4), | ||||
"GetPosition": () => new Vector3D(3, 0, 4), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(61, IID_Position, { | AddMock(61, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(0, 0), | "GetPosition2D": () => new Vector2D(0, 0), | ||||
"GetPosition": () => new Vector3D(0, 0, 0), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(62, IID_Position, { | AddMock(62, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(3.6, 3.2), | "GetPosition2D": () => new Vector2D(3.6, 3.2), | ||||
"GetPosition": () => new Vector3D(3.6, 0, 3.2), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(63, IID_Position, { | AddMock(63, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(10, -10), | "GetPosition2D": () => new Vector2D(10, -10), | ||||
"GetPosition": () => new Vector3D(10, 0, -10), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
// Target on the frontier of the shape (see distance above). | // Target on the frontier of the shape (see distance above). | ||||
AddMock(64, IID_Position, { | AddMock(64, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(9, -4), | "GetPosition2D": () => new Vector2D(9, -4), | ||||
"GetPosition": () => new Vector3D(9, 0, -4), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
// Big target far away (see distance above). | // Big target far away (see distance above). | ||||
AddMock(65, IID_Position, { | AddMock(65, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(23, 4), | "GetPosition2D": () => new Vector2D(23, 4), | ||||
"GetPosition": () => new Vector3D(23, 0, 4), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(60, IID_Health, { | AddMock(60, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, 100 * fallOff(0)); | TS_ASSERT_EQUALS(amount, 100 * fallOff(0)); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
}); | }); | ||||
Show All 34 Lines | function TestCircularSplashDamage() | ||||
}); | }); | ||||
let spy65 = new Spy(cmpHealth65, "TakeDamage"); | let spy65 = new Spy(cmpHealth65, "TakeDamage"); | ||||
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, | ||||
"attackerPosition": new Vector3D(0, 0, 0), | |||||
"attackHeightOffset": 0, | |||||
"origin": new Vector2D(3, 4), | "origin": new Vector2D(3, 4), | ||||
"radius": radius, | "radius": radius, | ||||
"shape": "Circular", | "shape": "Circular", | ||||
"friendlyFire": false, | "friendlyFire": false, | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(spy64._called, 1); | TS_ASSERT_EQUALS(spy64._called, 1); | ||||
TS_ASSERT_EQUALS(spy65._called, 1); | TS_ASSERT_EQUALS(spy65._called, 1); | ||||
Show All 20 Lines | function Test_MissileHit() | ||||
const radius = 10; | const radius = 10; | ||||
let data = { | let data = { | ||||
"type": "Ranged", | "type": "Ranged", | ||||
"attackData": { "Damage": { "Hack": 0, "Pierce": 100, "Crush": 0 } }, | "attackData": { "Damage": { "Hack": 0, "Pierce": 100, "Crush": 0 } }, | ||||
"target": 60, | "target": 60, | ||||
"attacker": 70, | "attacker": 70, | ||||
"attackerOwner": 1, | "attackerOwner": 1, | ||||
"attackerPosition": new Vector3D(0, 10, 0), | |||||
"attackHeightOffset": 0, | |||||
"position": targetPos, | "position": targetPos, | ||||
"direction": new Vector3D(1, 0, 0), | "direction": new Vector3D(1, 0, 0), | ||||
"projectileId": 9, | "projectileId": 9, | ||||
"friendlyFire": "false", | "friendlyFire": "false", | ||||
}; | }; | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => id == 1 ? 10 : 11, | "GetPlayerByID": id => id == 1 ? 10 : 11, | ||||
▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator