Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Damage.js
Show All 10 Lines | AttackEffects = class AttackEffects | ||||
} | } | ||||
}; | }; | ||||
Engine.LoadHelperScript("Attack.js"); | Engine.LoadHelperScript("Attack.js"); | ||||
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("Position.js"); | Engine.LoadHelperScript("Position.js"); | ||||
Engine.LoadHelperScript("ValueModification.js"); | Engine.LoadHelperScript("ValueModification.js"); | ||||
Engine.LoadComponentScript("interfaces/DelayedDamage.js"); | Engine.LoadComponentScript("interfaces/DelayedDamage.js"); | ||||
Engine.LoadComponentScript("interfaces/Formation.js"); | |||||
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/Loot.js"); | Engine.LoadComponentScript("interfaces/Loot.js"); | ||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | Engine.LoadComponentScript("interfaces/Promotion.js"); | ||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | ||||
Engine.LoadComponentScript("interfaces/Resistance.js"); | Engine.LoadComponentScript("interfaces/Resistance.js"); | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); | Engine.LoadComponentScript("interfaces/Timer.js"); | ||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Attack.js"); | Engine.LoadComponentScript("Attack.js"); | ||||
Engine.LoadComponentScript("DelayedDamage.js"); | Engine.LoadComponentScript("DelayedDamage.js"); | ||||
Engine.LoadComponentScript("Timer.js"); | Engine.LoadComponentScript("Timer.js"); | ||||
function Test_Generic() | function Test_Generic() | ||||
{ | { | ||||
ResetState(); | ResetState(); | ||||
let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer"); | let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer"); | ||||
cmpTimer.OnUpdate({ "turnLength": 1 }); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
AddMock(SYSTEM_ENTITY, IID_ObstructionManager, { | |||||
"IsInTargetRange": () => true | |||||
}); | |||||
let attacker = 11; | let attacker = 11; | ||||
let atkPlayerEntity = 1; | let atkPlayerEntity = 1; | ||||
let attackerOwner = 6; | let attackerOwner = 6; | ||||
let cmpAttack = ConstructComponent(attacker, "Attack", | let cmpAttack = ConstructComponent(attacker, "Attack", | ||||
{ | { | ||||
"Ranged": { | "Ranged": { | ||||
"Damage": { | "Damage": { | ||||
"Crush": 5, | "Crush": 5, | ||||
Show All 29 Lines | let data = { | ||||
"attacker": attacker, | "attacker": attacker, | ||||
"attackerOwner": attackerOwner, | "attackerOwner": attackerOwner, | ||||
"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], | ||||
"GetPlayerID": () => atkPlayerEntity | |||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": id => atkPlayerEntity, | "GetPlayerByID": id => atkPlayerEntity, | ||||
"GetAllPlayers": () => [0, 1, 2, 3, 4] | "GetAllPlayers": () => [0, 1, 2, 3, 4] | ||||
}); | }); | ||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => [] | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_ProjectileManager, { | AddMock(SYSTEM_ENTITY, IID_ProjectileManager, { | ||||
"RemoveProjectile": () => {}, | "RemoveProjectile": () => {}, | ||||
"LaunchProjectileAtPoint": (ent, pos, speed, gravity) => {}, | "LaunchProjectileAtPoint": (ent, pos, speed, gravity) => {}, | ||||
}); | }); | ||||
AddMock(target, IID_Position, { | AddMock(target, IID_Position, { | ||||
"GetPosition": () => targetPos, | "GetPosition": () => targetPos, | ||||
"GetPreviousPosition": () => targetPos, | "GetPreviousPosition": () => targetPos, | ||||
"GetPosition2D": () => Vector2D.From(targetPos), | "GetPosition2D": () => Vector2D.From(targetPos), | ||||
"GetHeightAt": () => 0, | "GetHeightAt": () => 0, | ||||
"IsInWorld": () => true, | "IsInWorld": () => true, | ||||
"GetHeightOffset": () => 0 | |||||
}); | }); | ||||
AddMock(target, IID_Health, { | AddMock(target, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
damageTaken = true; | damageTaken = true; | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
}, | }, | ||||
"GetRelativeDamage": () => 1 | |||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_DelayedDamage, { | AddMock(SYSTEM_ENTITY, IID_DelayedDamage, { | ||||
"Hit": () => { | "Hit": () => { | ||||
damageTaken = true; | damageTaken = true; | ||||
}, | }, | ||||
}); | }); | ||||
Show All 18 Lines | function Test_Generic() | ||||
AddMock(attacker, IID_Ownership, { | AddMock(attacker, IID_Ownership, { | ||||
"GetOwner": () => attackerOwner, | "GetOwner": () => attackerOwner, | ||||
}); | }); | ||||
AddMock(attacker, IID_Position, { | AddMock(attacker, IID_Position, { | ||||
"GetPosition": () => new Vector3D(2, 0, 3), | "GetPosition": () => new Vector3D(2, 0, 3), | ||||
"GetRotation": () => new Vector3D(1, 2, 3), | "GetRotation": () => new Vector3D(1, 2, 3), | ||||
"IsInWorld": () => true, | "IsInWorld": () => true, | ||||
"GetTurretParent": () => INVALID_ENTITY, | |||||
"GetHeightOffset": () => 0 | |||||
}); | }); | ||||
function TestDamage() | function TestDamage() | ||||
{ | { | ||||
cmpTimer.OnUpdate({ "turnLength": 1 }); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
TS_ASSERT(damageTaken); | TS_ASSERT(damageTaken); | ||||
damageTaken = false; | damageTaken = false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 559 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator