Differential D767 Diff 3019 binaries/data/mods/public/simulation/components/tests/test_DamageLinearSplash.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_DamageLinearSplash.js
Engine.LoadHelperScript("Sound.js"); | |||||
Engine.LoadComponentScript("interfaces/Attack.js"); | |||||
Engine.LoadComponentScript("interfaces/AttackDetection.js"); | |||||
Engine.LoadComponentScript("interfaces/Damage.js"); | |||||
Engine.LoadComponentScript("interfaces/DamageReceiver.js"); | |||||
Engine.LoadComponentScript("interfaces/Health.js"); | |||||
Engine.LoadComponentScript("interfaces/Loot.js"); | |||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | |||||
Engine.LoadComponentScript("interfaces/Sound.js"); | |||||
Engine.LoadComponentScript("interfaces/Timer.js"); | |||||
Engine.LoadComponentScript("Damage.js"); | |||||
const attacker = 50; | |||||
const attackerOwner = 1; | |||||
const origin = new Vector2D(0, 0); | |||||
let data = { | |||||
"attacker": attacker, | |||||
"origin": origin, | |||||
"radius": 10, | |||||
"shape": "Linear", | |||||
"strengths": { "hack" : 100, "pierce" : 0, "crush": 0 }, | |||||
"direction": new Vector3D(1, 747, 0), | |||||
"playersToDamage": [2], | |||||
"type": "Ranged", | |||||
"attackerOwner": attackerOwner | |||||
}; | |||||
let fallOff = function(x,y) | |||||
{ | |||||
return (1 - x * x / (data.radius * data.radius)) * (1 - 25 * y * y / (data.radius * data.radius)); | |||||
} | |||||
let cmpDamage = ConstructComponent(SYSTEM_ENTITY, "Damage"); | |||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | |||||
ExecuteQueryAroundPos: () => [60, 61, 62], | |||||
}); | |||||
AddMock(60, IID_Position, { | |||||
GetPosition2D: () => new Vector2D(2.2, -0.4), | |||||
}); | |||||
AddMock(61, IID_Position, { | |||||
GetPosition2D: () => new Vector2D(0, 0), | |||||
}); | |||||
AddMock(62, IID_Position, { | |||||
GetPosition2D: () => new Vector2D(5, 2), | |||||
}); | |||||
AddMock(60, IID_DamageReceiver, { | |||||
TakeDamage: (hack, pierce, crush) => { | |||||
TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(2.2, -0.4)); | |||||
return { "killed": false, "change": -(hack + pierce + crush) }; | |||||
} | |||||
}); | |||||
AddMock(61, IID_DamageReceiver, { | |||||
TakeDamage: (hack, pierce, crush) => { | |||||
TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(0, 0)); | |||||
return { "killed": false, "change": -(hack + pierce + crush) }; | |||||
} | |||||
}); | |||||
AddMock(62, IID_DamageReceiver, { | |||||
TakeDamage: (hack, pierce, crush) => { | |||||
TS_ASSERT_EQUALS(hack + pierce + crush, 0); | |||||
return { "killed": false, "change": -(hack + pierce + crush) }; | |||||
} | |||||
}); | |||||
cmpDamage.CauseSplashDamage(data); | |||||
data.direction = new Vector3D(0.6, 747, 0.8); | |||||
AddMock(60, IID_DamageReceiver, { | |||||
TakeDamage: (hack, pierce, crush) => { | |||||
TS_ASSERT_EQUALS(hack + pierce + crush, 100 * fallOff(1, 2)); | |||||
return { "killed": false, "change": -(hack + pierce + crush) }; | |||||
} | |||||
}); | |||||
cmpDamage.CauseSplashDamage(data); |
Wildfire Games · Phabricator