Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Damage.js
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | function Test_Generic() | ||||
cmpAttack.GetAttackStrengths = attackType => ({ "Hack": 0, "Pierce": 0, "Crush": damage }); | cmpAttack.GetAttackStrengths = attackType => ({ "Hack": 0, "Pierce": 0, "Crush": damage }); | ||||
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, | "attackerData": { | ||||
"attackerOwner": attackerOwner, | "entity": attacker, | ||||
"owner": attackerOwner, | |||||
"position": new Vector3D(3, 0, 3), | |||||
"elevationBonus": 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 49 Lines • ▼ Show 20 Lines | function Test_Generic() | ||||
function TestDamage() | function TestDamage() | ||||
{ | { | ||||
cmpTimer.OnUpdate({ "turnLength": 1 }); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
TS_ASSERT(damageTaken); | TS_ASSERT(damageTaken); | ||||
damageTaken = false; | damageTaken = false; | ||||
} | } | ||||
Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attacker, data.attackerOwner); | Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attackerData); | ||||
TestDamage(); | TestDamage(); | ||||
data.type = "Ranged"; | data.type = "Ranged"; | ||||
type = data.type; | type = data.type; | ||||
Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attacker, data.attackerOwner); | Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attackerData); | ||||
TestDamage(); | TestDamage(); | ||||
// Check for damage still being dealt if the attacker dies | // Check for damage still being dealt if the attacker dies | ||||
cmpAttack.PerformAttack("Ranged", target); | cmpAttack.PerformAttack("Ranged", target); | ||||
Engine.DestroyEntity(attacker); | Engine.DestroyEntity(attacker); | ||||
TestDamage(); | TestDamage(); | ||||
atkPlayerEntity = 1; | atkPlayerEntity = 1; | ||||
Show All 14 Lines | function TestLinearSplashDamage() | ||||
const attacker = 50; | const attacker = 50; | ||||
const attackerOwner = 1; | const attackerOwner = 1; | ||||
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, | "attackerData": { | ||||
"attackerOwner": attackerOwner, | "entity": attacker, | ||||
"owner": attackerOwner, | |||||
"position": new Vector3D(3, 0, 3), | |||||
"elevationBonus": 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), | ||||
"playersToDamage": [2], | "playersToDamage": [2], | ||||
}; | }; | ||||
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.radius * data.radius)) * (1 - 25 * y * y / (data.radius * data.radius)); | ||||
}; | }; | ||||
let hitEnts = new Set(); | let hitEnts = new Set(); | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
"ExecuteQueryAroundPos": () => [60, 61, 62], | "ExecuteQueryAroundPos": () => [60, 61, 62], | ||||
}); | }); | ||||
AddMock(60, IID_Position, { | AddMock(60, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(2.2, -0.4), | "GetPosition2D": () => new Vector2D(2.2, -0.4), | ||||
"GetPosition": () => new Vector2D(2.2, 0, -0.4), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(61, IID_Position, { | AddMock(61, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(0, 0), | "GetPosition2D": () => new Vector2D(0, 0), | ||||
"GetPosition": () => new Vector2D(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 Vector2D(5, 0, 2), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(60, IID_Health, { | AddMock(60, IID_Health, { | ||||
"TakeDamage": (effectData, __, ___, mult) => { | "TakeDamage": (effectData, __, ___, mult) => { | ||||
hitEnts.add(60); | hitEnts.add(60); | ||||
TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 100 * fallOff(2.2, -0.4)); | TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 100 * fallOff(2.2, -0.4)); | ||||
return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | function TestCircularSplashDamage() | ||||
}; | }; | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
"ExecuteQueryAroundPos": () => [60, 61, 62, 64], | "ExecuteQueryAroundPos": () => [60, 61, 62, 64], | ||||
}); | }); | ||||
AddMock(60, IID_Position, { | AddMock(60, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(3, 4), | "GetPosition2D": () => new Vector2D(3, 4), | ||||
"GetPosition": () => new Vector2D(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 Vector2D(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 Vector2D(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 Vector2D(10, 0, -10), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
// Target on the frontier of the shape | // Target on the frontier of the shape | ||||
AddMock(64, IID_Position, { | AddMock(64, IID_Position, { | ||||
"GetPosition2D": () => new Vector2D(9, -4), | "GetPosition2D": () => new Vector2D(9, -4), | ||||
"GetPosition": () => new Vector2D(9, 0, -4), | |||||
"IsInWorld": () => true | |||||
}); | }); | ||||
AddMock(60, IID_Resistance, { | AddMock(60, IID_Resistance, { | ||||
"TakeDamage": (effectData, __, ___, mult) => { | "TakeDamage": (effectData, __, ___, mult) => { | ||||
TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 100 * fallOff(0)); | TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 100 * fallOff(0)); | ||||
return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | ||||
} | } | ||||
}); | }); | ||||
Show All 23 Lines | "TakeDamage": (effectData, __, ___, mult) => { | ||||
TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 0); | TS_ASSERT_EQUALS(mult * (effectData.Hack + effectData.Pierce + effectData.Crush), 0); | ||||
return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | return { "killed": false, "change": -mult * (effectData.Hack + effectData.Pierce + effectData.Crush) }; | ||||
} | } | ||||
}); | }); | ||||
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, | "attackerData": { | ||||
"attackerOwner": 1, | "entity": 50, | ||||
"owner": 1, | |||||
"position": new Vector3D(3, 0, 3), | |||||
"elevationBonus": 0 | |||||
}, | |||||
"origin": new Vector2D(3, 4), | "origin": new Vector2D(3, 4), | ||||
"radius": radius, | "radius": radius, | ||||
"shape": "Circular", | "shape": "Circular", | ||||
"playersToDamage": [2], | "playersToDamage": [2], | ||||
}); | }); | ||||
} | } | ||||
TestCircularSplashDamage(); | TestCircularSplashDamage(); | ||||
Show All 15 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, | "attackerData": { | ||||
"attackerOwner": 1, | "entity": 70, | ||||
"owner": 1, | |||||
"position": new Vector3D(3, 10, 3), | |||||
"elevationBonus": 0 | |||||
}, | |||||
"position": targetPos, | "position": targetPos, | ||||
"direction": new Vector3D(1, 0, 0), | "direction": new Vector3D(1, 0, 0), | ||||
"projectileId": 9, | "projectileId": 9, | ||||
}; | }; | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => id == 1 ? 10 : 11, | "GetPlayerByID": id => id == 1 ? 10 : 11, | ||||
"GetAllPlayers": () => [0, 1] | "GetAllPlayers": () => [0, 1] | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator