mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 02:06:32 +01:00
Added tests for combat functions
All the tests are in for the combat functions! I think I just have to test the turn handler script's methods, and then I'll have full coverage.
This commit is contained in:
parent
32dbe4b396
commit
96ccfde9de
1 changed files with 53 additions and 1 deletions
|
|
@ -757,8 +757,9 @@ class TestTutorialWorldRooms(CommandTest):
|
|||
|
||||
# test turnbattle
|
||||
from evennia.contrib import turnbattle
|
||||
from evennia.objects.objects import DefaultRoom
|
||||
|
||||
class TestTurnBattle(CommandTest):
|
||||
class TestTurnBattleCmd(CommandTest):
|
||||
|
||||
# Test combat commands
|
||||
def test_turnbattlecmd(self):
|
||||
|
|
@ -767,3 +768,54 @@ class TestTurnBattle(CommandTest):
|
|||
self.call(turnbattle.CmdPass(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(turnbattle.CmdDisengage(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(turnbattle.CmdRest(), "", "Char rests to recover HP.")
|
||||
|
||||
class TestTurnBattleFunc(EvenniaTest):
|
||||
|
||||
# Test combat functions
|
||||
def test_turnbattlefunc(self):
|
||||
attacker = create_object(turnbattle.BattleCharacter, key="Attacker")
|
||||
defender = create_object(turnbattle.BattleCharacter, key="Defender")
|
||||
testroom = create_object(DefaultRoom, key="Test Room")
|
||||
attacker.location = testroom
|
||||
defender.loaction = testroom
|
||||
# Initiative roll
|
||||
initiative = turnbattle.roll_init(attacker)
|
||||
self.assertTrue(initiative >= 0 and initiative <= 1000)
|
||||
# Attack roll
|
||||
attack_roll = turnbattle.get_attack(attacker, defender)
|
||||
self.assertTrue(attack_roll >= 0 and attack_roll <= 100)
|
||||
# Defense roll
|
||||
defense_roll = turnbattle.get_defense(attacker, defender)
|
||||
self.assertTrue(defense_roll == 50)
|
||||
# Damage roll
|
||||
damage_roll = turnbattle.get_damage(attacker, defender)
|
||||
self.assertTrue(damage_roll >= 15 and damage_roll <= 25)
|
||||
# Apply damage
|
||||
defender.db.hp = 10
|
||||
turnbattle.apply_damage(defender, 3)
|
||||
self.assertTrue(defender.db.hp == 7)
|
||||
# Resolve attack
|
||||
defender.db.hp = 40
|
||||
turnbattle.resolve_attack(attacker, defender, attack_value=20, defense_value=10)
|
||||
self.assertTrue(defender.db.hp < 40)
|
||||
# Combat cleanup
|
||||
attacker.db.combat_attribute = True
|
||||
turnbattle.combat_cleanup(attacker)
|
||||
self.assertFalse(attacker.db.combat_attribute)
|
||||
# Is in combat
|
||||
self.assertFalse(turnbattle.is_in_combat(attacker))
|
||||
# Set up turn handler script for further tests
|
||||
attacker.location.scripts.add(turnbattle.TurnHandler)
|
||||
turnhandler = attacker.db.combat_TurnHandler
|
||||
self.assertTrue(attacker.db.combat_TurnHandler)
|
||||
# Force turn order
|
||||
turnhandler.db.fighters = [attacker, defender]
|
||||
turnhandler.db.turn = 0
|
||||
# Test is turn
|
||||
self.assertTrue(turnbattle.is_turn(attacker))
|
||||
# Spend actions
|
||||
attacker.db.combat_ActionsLeft = 1
|
||||
turnbattle.spend_action(attacker, 1, action_name="Test")
|
||||
self.assertTrue(attacker.db.combat_ActionsLeft == 0)
|
||||
self.assertTrue(attacker.db.combat_LastAction == "Test")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue