Differential D2269 Diff 16298 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Resistance.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Resistance.js
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | TestInvulnerability() | ||||
let cmpHealth = AddMock(this.EntityID, IID_Health, { | let cmpHealth = AddMock(this.EntityID, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, damage); | TS_ASSERT_EQUALS(amount, damage); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpHealth, "TakeDamage"); | let spy = new Spy(cmpHealth, "TakeDamage"); | ||||
let data = { | |||||
"type": attackType, | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}; | |||||
Attacking.HandleAttackEffects(this.EntityID, attackType, attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, data); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
this.cmpResistance.SetInvulnerability(true); | this.cmpResistance.SetInvulnerability(true); | ||||
TS_ASSERT(this.cmpResistance.IsInvulnerable()); | TS_ASSERT(this.cmpResistance.IsInvulnerable()); | ||||
Attacking.HandleAttackEffects(this.EntityID, attackType, attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, data); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestBonus() | TestBonus() | ||||
{ | { | ||||
this.Reset(); | this.Reset(); | ||||
let damage = 5; | let damage = 5; | ||||
Show All 17 Lines | TestBonus() | ||||
let cmpHealth = AddMock(this.EntityID, IID_Health, { | let cmpHealth = AddMock(this.EntityID, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, damage * bonus); | TS_ASSERT_EQUALS(amount, damage * bonus); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpHealth, "TakeDamage"); | let spy = new Spy(cmpHealth, "TakeDamage"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestDamageResistanceApplies() | TestDamageResistanceApplies() | ||||
{ | { | ||||
let resistanceValue = 2; | let resistanceValue = 2; | ||||
let damageType = "Name"; | let damageType = "Name"; | ||||
this.Reset({ | this.Reset({ | ||||
Show All 12 Lines | TestDamageResistanceApplies() | ||||
let cmpHealth = AddMock(this.EntityID, IID_Health, { | let cmpHealth = AddMock(this.EntityID, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpHealth, "TakeDamage"); | let spy = new Spy(cmpHealth, "TakeDamage"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestCaptureResistanceApplies() | TestCaptureResistanceApplies() | ||||
{ | { | ||||
let resistanceValue = 2; | let resistanceValue = 2; | ||||
this.Reset({ | this.Reset({ | ||||
"Entity": { | "Entity": { | ||||
Show All 9 Lines | TestCaptureResistanceApplies() | ||||
let cmpCapturable = AddMock(this.EntityID, IID_Capturable, { | let cmpCapturable = AddMock(this.EntityID, IID_Capturable, { | ||||
"Capture": (amount, __, ___) => { | "Capture": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | ||||
return { "captureChange": amount }; | return { "captureChange": amount }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpCapturable, "Capture"); | let spy = new Spy(cmpCapturable, "Capture"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestStatusEffectsResistancesApplies() | TestStatusEffectsResistancesApplies() | ||||
{ | { | ||||
// Test duration reduction. | // Test duration reduction. | ||||
let durationFactor = 0.5; | let durationFactor = 0.5; | ||||
let statusName = "statusName"; | let statusName = "statusName"; | ||||
Show All 19 Lines | TestStatusEffectsResistancesApplies() | ||||
let cmpStatusEffectsReceiver = AddMock(this.EntityID, IID_StatusEffectsReceiver, { | let cmpStatusEffectsReceiver = AddMock(this.EntityID, IID_StatusEffectsReceiver, { | ||||
"ApplyStatus": (effectData, __, ___) => { | "ApplyStatus": (effectData, __, ___) => { | ||||
TS_ASSERT_EQUALS(effectData[statusName].Duration, duration * durationFactor); | TS_ASSERT_EQUALS(effectData[statusName].Duration, duration * durationFactor); | ||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | let spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
// Test blocking. | // Test blocking. | ||||
this.Reset({ | this.Reset({ | ||||
"Entity": { | "Entity": { | ||||
"ApplyStatus": { | "ApplyStatus": { | ||||
[statusName]: { | [statusName]: { | ||||
"BlockChance": "1" | "BlockChance": "1" | ||||
} | } | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
cmpStatusEffectsReceiver = AddMock(this.EntityID, IID_StatusEffectsReceiver, { | cmpStatusEffectsReceiver = AddMock(this.EntityID, IID_StatusEffectsReceiver, { | ||||
"ApplyStatus": (effectData, __, ___) => { | "ApplyStatus": (effectData, __, ___) => { | ||||
TS_ASSERT_UNEVAL_EQUALS(effectData, {}); | TS_ASSERT_UNEVAL_EQUALS(effectData, {}); | ||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
} | } | ||||
}); | }); | ||||
spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
// Test multiple resistances. | // Test multiple resistances. | ||||
let reducedStatusName = "reducedStatus"; | let reducedStatusName = "reducedStatus"; | ||||
let blockedStatusName = "blockedStatus"; | let blockedStatusName = "blockedStatus"; | ||||
this.Reset({ | this.Reset({ | ||||
"Entity": { | "Entity": { | ||||
"ApplyStatus": { | "ApplyStatus": { | ||||
Show All 22 Lines | cmpStatusEffectsReceiver = AddMock(this.EntityID, IID_StatusEffectsReceiver, { | ||||
"ApplyStatus": (effectData, __, ___) => { | "ApplyStatus": (effectData, __, ___) => { | ||||
TS_ASSERT_EQUALS(effectData[reducedStatusName].Duration, duration * durationFactor); | TS_ASSERT_EQUALS(effectData[reducedStatusName].Duration, duration * durationFactor); | ||||
TS_ASSERT_UNEVAL_EQUALS(Object.keys(effectData), [reducedStatusName]); | TS_ASSERT_UNEVAL_EQUALS(Object.keys(effectData), [reducedStatusName]); | ||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
} | } | ||||
}); | }); | ||||
spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | spy = new Spy(cmpStatusEffectsReceiver, "ApplyStatus"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestResistanceAndBonus() | TestResistanceAndBonus() | ||||
{ | { | ||||
let resistanceValue = 2; | let resistanceValue = 2; | ||||
let damageType = "Name"; | let damageType = "Name"; | ||||
this.Reset({ | this.Reset({ | ||||
Show All 25 Lines | TestResistanceAndBonus() | ||||
let cmpHealth = AddMock(this.EntityID, IID_Health, { | let cmpHealth = AddMock(this.EntityID, IID_Health, { | ||||
"TakeDamage": (amount, __, ___) => { | "TakeDamage": (amount, __, ___) => { | ||||
TS_ASSERT_EQUALS(amount, damage * bonus * Math.pow(0.9, resistanceValue)); | TS_ASSERT_EQUALS(amount, damage * bonus * Math.pow(0.9, resistanceValue)); | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
} | } | ||||
}); | }); | ||||
let spy = new Spy(cmpHealth, "TakeDamage"); | let spy = new Spy(cmpHealth, "TakeDamage"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
} | } | ||||
TestMultipleEffects() | TestMultipleEffects() | ||||
{ | { | ||||
let captureResistanceValue = 2; | let captureResistanceValue = 2; | ||||
this.Reset({ | this.Reset({ | ||||
"Entity": { | "Entity": { | ||||
Show All 32 Lines | let cmpHealth = AddMock(this.EntityID, IID_Health, { | ||||
return { "healthChange": -amount }; | return { "healthChange": -amount }; | ||||
}, | }, | ||||
"GetHitpoints": () => 1, | "GetHitpoints": () => 1, | ||||
"GetMaxHitpoints": () => 1 | "GetMaxHitpoints": () => 1 | ||||
}); | }); | ||||
let healthSpy = new Spy(cmpHealth, "TakeDamage"); | let healthSpy = new Spy(cmpHealth, "TakeDamage"); | ||||
let captureSpy = new Spy(cmpCapturable, "Capture"); | let captureSpy = new Spy(cmpCapturable, "Capture"); | ||||
Attacking.HandleAttackEffects(this.EntityID, "Test", attackData, this.AttackerID, this.EnemyID); | Attacking.HandleAttackEffects(this.EntityID, { | ||||
"type": "Test", | |||||
"attackData": attackData, | |||||
"attacker": this.AttackerID, | |||||
"attackerOwner": this.EnemyID | |||||
}); | |||||
TS_ASSERT_EQUALS(healthSpy._called, 1); | TS_ASSERT_EQUALS(healthSpy._called, 1); | ||||
TS_ASSERT_EQUALS(captureSpy._called, 1); | TS_ASSERT_EQUALS(captureSpy._called, 1); | ||||
} | } | ||||
} | } | ||||
let cmp = new testResistance(); | let cmp = new testResistance(); | ||||
cmp.TestInvulnerability(); | cmp.TestInvulnerability(); | ||||
cmp.TestBonus(); | cmp.TestBonus(); | ||||
cmp.TestDamageResistanceApplies(); | cmp.TestDamageResistanceApplies(); | ||||
cmp.TestCaptureResistanceApplies(); | cmp.TestCaptureResistanceApplies(); | ||||
cmp.TestStatusEffectsResistancesApplies(); | cmp.TestStatusEffectsResistancesApplies(); | ||||
cmp.TestResistanceAndBonus(); | cmp.TestResistanceAndBonus(); | ||||
cmp.TestMultipleEffects(); | cmp.TestMultipleEffects(); |
Wildfire Games · Phabricator