Differential D2229 Diff 13277 binaries/data/mods/public/simulation/components/tests/test_Resistance.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Resistance.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
Engine.LoadHelperScript("Attacking.js"); | |||||
Engine.LoadHelperScript("DamageBonus.js"); | |||||
Engine.LoadHelperScript("Player.js"); | |||||
Engine.LoadHelperScript("ValueModification.js"); | |||||
Engine.LoadComponentScript("interfaces/Capturable.js"); | |||||
Engine.LoadComponentScript("interfaces/Foundation.js"); | |||||
Engine.LoadComponentScript("interfaces/Health.js"); | |||||
Engine.LoadComponentScript("interfaces/Looter.js"); | |||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | |||||
Engine.LoadComponentScript("interfaces/PlayerManager.js"); | |||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | |||||
Engine.LoadComponentScript("interfaces/Resistance.js"); | |||||
Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); | |||||
Engine.LoadComponentScript("Resistance.js"); | |||||
class testResistance | |||||
{ | |||||
constructor() | |||||
{ | |||||
this.cmpResistance = null; | |||||
this.PLAYER_ID = 1; | |||||
this.ENEMY_ID = 2; | |||||
bb: `this.PlayerID` ?
same for the others | |||||
this.ENTITY_ID = 3; | |||||
this.ATTACKER_ID = 4; | |||||
} | |||||
Reset(schema = {}) | |||||
{ | |||||
this.cmpResistance = ConstructComponent(this.ENTITY_ID, "Resistance", schema); | |||||
DeleteMock(this.ENTITY_ID, IID_Health); | |||||
DeleteMock(this.ENTITY_ID, IID_Capturable); | |||||
DeleteMock(this.ENTITY_ID, IID_Identity); | |||||
} | |||||
TestInvulnerability() | |||||
{ | |||||
this.Reset(); | |||||
let damage = 5; | |||||
let attackData = { "Damage": { "Name": damage } }; | |||||
let attackType = "Test"; | |||||
TS_ASSERT(!this.cmpResistance.IsInvulnerable()); | |||||
let cmpHealth = AddMock(this.ENTITY_ID, IID_Health, { | |||||
"TakeDamage": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage); | |||||
return { "healthChange": -amount }; | |||||
} | |||||
}); | |||||
let spy = new Spy(cmpHealth, "TakeDamage"); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, attackType, attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
this.cmpResistance.SetInvulnerability(true); | |||||
TS_ASSERT(this.cmpResistance.IsInvulnerable()); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, attackType, attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
} | |||||
TestBonus() | |||||
{ | |||||
this.Reset(); | |||||
let damage = 5; | |||||
let bonus = 2; | |||||
let classes = "Entity"; | |||||
let attackData = { | |||||
"Damage": { "Name": damage }, | |||||
"Bonuses": { | |||||
"bonus": { | |||||
"Classes": classes, | |||||
"Multiplier": bonus | |||||
} | |||||
} | |||||
}; | |||||
AddMock(this.ENTITY_ID, IID_Identity, { | |||||
"GetClassesList": () => [classes] | |||||
}); | |||||
let cmpHealth = AddMock(this.ENTITY_ID, IID_Health, { | |||||
"TakeDamage": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * bonus); | |||||
return { "healthChange": -amount }; | |||||
} | |||||
}); | |||||
let spy = new Spy(cmpHealth, "TakeDamage"); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, "Test", attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
} | |||||
TestDamageResistanceApplies() | |||||
{ | |||||
let resistanceValue = 2; | |||||
let damageType = "Name"; | |||||
this.Reset({ | |||||
"Entity": { | |||||
"Damage": { | |||||
[damageType]: resistanceValue | |||||
} | |||||
} | |||||
}); | |||||
let damage = 5; | |||||
let attackData = { | |||||
"Damage": { "Name": damage } | |||||
}; | |||||
let cmpHealth = AddMock(this.ENTITY_ID, IID_Health, { | |||||
"TakeDamage": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | |||||
return { "healthChange": -amount }; | |||||
} | |||||
}); | |||||
let spy = new Spy(cmpHealth, "TakeDamage"); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, "Test", attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
} | |||||
TestCaptureResistanceApplies() | |||||
{ | |||||
let resistanceValue = 2; | |||||
this.Reset({ | |||||
"Entity": { | |||||
"Capture": resistanceValue | |||||
} | |||||
}); | |||||
let damage = 5; | |||||
let attackData = { | |||||
"Capture": damage | |||||
}; | |||||
let cmpCapturable = AddMock(this.ENTITY_ID, IID_Capturable, { | |||||
"Capture": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * Math.pow(0.9, resistanceValue)); | |||||
return { "captureChange": amount }; | |||||
} | |||||
}); | |||||
let spy = new Spy(cmpCapturable, "Capture"); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, "Test", attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
} | |||||
TestResistanceAndBonus() | |||||
{ | |||||
let resistanceValue = 2; | |||||
let damageType = "Name"; | |||||
this.Reset({ | |||||
"Entity": { | |||||
"Damage": { | |||||
[damageType]: resistanceValue | |||||
} | |||||
} | |||||
}); | |||||
let damage = 5; | |||||
let bonus = 2; | |||||
let classes = "Entity"; | |||||
let attackData = { | |||||
"Damage": { "Name": damage }, | |||||
"Bonuses": { | |||||
"bonus": { | |||||
"Classes": classes, | |||||
"Multiplier": bonus | |||||
} | |||||
} | |||||
}; | |||||
AddMock(this.ENTITY_ID, IID_Identity, { | |||||
"GetClassesList": () => [classes] | |||||
}); | |||||
let cmpHealth = AddMock(this.ENTITY_ID, IID_Health, { | |||||
"TakeDamage": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * bonus * Math.pow(0.9, resistanceValue)); | |||||
return { "healthChange": -amount }; | |||||
} | |||||
}); | |||||
let spy = new Spy(cmpHealth, "TakeDamage"); | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, "Test", attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(spy._called, 1); | |||||
} | |||||
TestMultipleEffects() | |||||
{ | |||||
let captureResistanceValue = 2; | |||||
this.Reset({ | |||||
"Entity": { | |||||
"Capture": captureResistanceValue | |||||
} | |||||
}); | |||||
let damage = 5; | |||||
let bonus = 2; | |||||
let classes = "Entity"; | |||||
let attackData = { | |||||
"Damage": { "Name": damage }, | |||||
"Capture": damage, | |||||
"Bonuses": { | |||||
"bonus": { | |||||
"Classes": classes, | |||||
"Multiplier": bonus | |||||
} | |||||
} | |||||
}; | |||||
AddMock(this.ENTITY_ID, IID_Identity, { | |||||
"GetClassesList": () => [classes] | |||||
}); | |||||
let cmpCapturable = AddMock(this.ENTITY_ID, IID_Capturable, { | |||||
"Capture": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * bonus * Math.pow(0.9, captureResistanceValue)); | |||||
return { "captureChange": amount }; | |||||
} | |||||
}); | |||||
let cmpHealth = AddMock(this.ENTITY_ID, IID_Health, { | |||||
"TakeDamage": (amount, __, ___) => { | |||||
TS_ASSERT_EQUALS(amount, damage * bonus); | |||||
return { "healthChange": -amount }; | |||||
}, | |||||
"GetHitpoints": () => 1, | |||||
"GetMaxHitpoints": () => 1 | |||||
}); | |||||
let healthSpy = new Spy(cmpHealth, "TakeDamage"); | |||||
let captureSpy = new Spy(cmpCapturable, "Capture"); | |||||
Done Inline ActionsOne could name them captureSpy and damageSpy if interested bb: One could name them `captureSpy` and `damageSpy` if interested | |||||
Attacking.HandleAttackEffects(this.ENTITY_ID, "Test", attackData, this.ATTACKER_ID, this.ENEMY_ID); | |||||
TS_ASSERT_EQUALS(healthSpy._called, 1); | |||||
TS_ASSERT_EQUALS(captureSpy._called, 1); | |||||
} | |||||
} | |||||
let cmp = new testResistance(); | |||||
cmp.TestInvulnerability(); | |||||
cmp.TestBonus(); | |||||
cmp.TestDamageResistanceApplies(); | |||||
cmp.TestCaptureResistanceApplies(); | |||||
cmp.TestResistanceAndBonus(); | |||||
cmp.TestMultipleEffects(); | |||||
Done Inline Actions- Freagarach: -` ` |
Wildfire Games · Phabricator
this.PlayerID ?
same for the others