mirror of
https://github.com/evennia/evennia.git
synced 2026-04-04 06:57:16 +02:00
Unit tests for tb_range added
This commit is contained in:
parent
1fe9bf3dce
commit
9bc3fcf486
2 changed files with 111 additions and 5 deletions
|
|
@ -907,7 +907,7 @@ class TestTutorialWorldRooms(CommandTest):
|
|||
|
||||
|
||||
# test turnbattle
|
||||
from evennia.contrib.turnbattle import tb_basic, tb_equip
|
||||
from evennia.contrib.turnbattle import tb_basic, tb_equip, tb_range
|
||||
from evennia.objects.objects import DefaultRoom
|
||||
|
||||
|
||||
|
|
@ -939,11 +939,25 @@ class TestTurnBattleCmd(CommandTest):
|
|||
self.call(tb_equip.CmdDisengage(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_equip.CmdRest(), "", "Char rests to recover HP.")
|
||||
|
||||
# Test range commands
|
||||
def test_turnbattlerangecmd(self):
|
||||
# Start with range module specific commands.
|
||||
self.call(tb_range.CmdShoot(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdApproach(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdWithdraw(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdStatus(), "", "HP Remaining: 100 / 100")
|
||||
# Also test the commands that are the same in the basic module
|
||||
self.call(tb_range.CmdFight(), "", "There's nobody here to fight!")
|
||||
self.call(tb_range.CmdAttack(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdPass(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdDisengage(), "", "You can only do that in combat. (see: help fight)")
|
||||
self.call(tb_range.CmdRest(), "", "Char rests to recover HP.")
|
||||
|
||||
|
||||
class TestTurnBattleFunc(EvenniaTest):
|
||||
|
||||
# Test combat functions
|
||||
def test_turnbattlefunc(self):
|
||||
def test_tbbasicfunc(self):
|
||||
attacker = create_object(tb_basic.TBBasicCharacter, key="Attacker")
|
||||
defender = create_object(tb_basic.TBBasicCharacter, key="Defender")
|
||||
testroom = create_object(DefaultRoom, key="Test Room")
|
||||
|
|
@ -1020,7 +1034,7 @@ class TestTurnBattleFunc(EvenniaTest):
|
|||
turnhandler.stop()
|
||||
|
||||
# Test the combat functions in tb_equip too. They work mostly the same.
|
||||
def test_turnbattlefunc(self):
|
||||
def test_tbequipfunc(self):
|
||||
attacker = create_object(tb_equip.TBEquipCharacter, key="Attacker")
|
||||
defender = create_object(tb_equip.TBEquipCharacter, key="Defender")
|
||||
testroom = create_object(DefaultRoom, key="Test Room")
|
||||
|
|
@ -1095,6 +1109,96 @@ class TestTurnBattleFunc(EvenniaTest):
|
|||
self.assertTrue(turnhandler.db.fighters == [joiner, attacker, defender])
|
||||
# Remove the script at the end
|
||||
turnhandler.stop()
|
||||
|
||||
# Test combat functions in tb_range too.
|
||||
def test_tbrangefunc(self):
|
||||
testroom = create_object(DefaultRoom, key="Test Room")
|
||||
attacker = create_object(tb_range.TBRangeCharacter, key="Attacker", location=testroom)
|
||||
defender = create_object(tb_range.TBRangeCharacter, key="Defender", location=testroom)
|
||||
# Initiative roll
|
||||
initiative = tb_range.roll_init(attacker)
|
||||
self.assertTrue(initiative >= 0 and initiative <= 1000)
|
||||
# Attack roll
|
||||
attack_roll = tb_range.get_attack(attacker, defender, "test")
|
||||
self.assertTrue(attack_roll >= 0 and attack_roll <= 100)
|
||||
# Defense roll
|
||||
defense_roll = tb_range.get_defense(attacker, defender, "test")
|
||||
self.assertTrue(defense_roll == 50)
|
||||
# Damage roll
|
||||
damage_roll = tb_range.get_damage(attacker, defender)
|
||||
self.assertTrue(damage_roll >= 15 and damage_roll <= 25)
|
||||
# Apply damage
|
||||
defender.db.hp = 10
|
||||
tb_range.apply_damage(defender, 3)
|
||||
self.assertTrue(defender.db.hp == 7)
|
||||
# Resolve attack
|
||||
defender.db.hp = 40
|
||||
tb_range.resolve_attack(attacker, defender, "test", attack_value=20, defense_value=10)
|
||||
self.assertTrue(defender.db.hp < 40)
|
||||
# Combat cleanup
|
||||
attacker.db.Combat_attribute = True
|
||||
tb_range.combat_cleanup(attacker)
|
||||
self.assertFalse(attacker.db.combat_attribute)
|
||||
# Is in combat
|
||||
self.assertFalse(tb_range.is_in_combat(attacker))
|
||||
# Set up turn handler script for further tests
|
||||
attacker.location.scripts.add(tb_range.TBRangeTurnHandler)
|
||||
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(tb_range.is_turn(attacker))
|
||||
# Spend actions
|
||||
attacker.db.Combat_ActionsLeft = 1
|
||||
tb_range.spend_action(attacker, 1, action_name="Test")
|
||||
self.assertTrue(attacker.db.Combat_ActionsLeft == 0)
|
||||
self.assertTrue(attacker.db.Combat_LastAction == "Test")
|
||||
# Initialize for combat
|
||||
attacker.db.Combat_ActionsLeft = 983
|
||||
turnhandler.initialize_for_combat(attacker)
|
||||
self.assertTrue(attacker.db.Combat_ActionsLeft == 0)
|
||||
self.assertTrue(attacker.db.Combat_LastAction == "null")
|
||||
# Set up ranges again, since initialize_for_combat clears them
|
||||
attacker.db.combat_range = {}
|
||||
attacker.db.combat_range[attacker] = 0
|
||||
attacker.db.combat_range[defender] = 1
|
||||
defender.db.combat_range = {}
|
||||
defender.db.combat_range[defender] = 0
|
||||
defender.db.combat_range[attacker] = 1
|
||||
# Start turn
|
||||
defender.db.Combat_ActionsLeft = 0
|
||||
turnhandler.start_turn(defender)
|
||||
self.assertTrue(defender.db.Combat_ActionsLeft == 2)
|
||||
# Next turn
|
||||
turnhandler.db.fighters = [attacker, defender]
|
||||
turnhandler.db.turn = 0
|
||||
turnhandler.next_turn()
|
||||
self.assertTrue(turnhandler.db.turn == 1)
|
||||
# Turn end check
|
||||
turnhandler.db.fighters = [attacker, defender]
|
||||
turnhandler.db.turn = 0
|
||||
attacker.db.Combat_ActionsLeft = 0
|
||||
turnhandler.turn_end_check(attacker)
|
||||
self.assertTrue(turnhandler.db.turn == 1)
|
||||
# Join fight
|
||||
joiner = create_object(tb_range.TBRangeCharacter, key="Joiner", location=testroom)
|
||||
turnhandler.db.fighters = [attacker, defender]
|
||||
turnhandler.db.turn = 0
|
||||
turnhandler.join_fight(joiner)
|
||||
self.assertTrue(turnhandler.db.turn == 1)
|
||||
self.assertTrue(turnhandler.db.fighters == [joiner, attacker, defender])
|
||||
# Now, test for approach/withdraw functions
|
||||
self.assertTrue(tb_range.get_range(attacker, defender) == 1)
|
||||
# Approach
|
||||
tb_range.approach(attacker, defender)
|
||||
self.assertTrue(tb_range.get_range(attacker, defender) == 0)
|
||||
# Withdraw
|
||||
tb_range.withdraw(attacker, defender)
|
||||
self.assertTrue(tb_range.get_range(attacker, defender) == 1)
|
||||
# Remove the script at the end
|
||||
turnhandler.stop()
|
||||
|
||||
|
||||
# Test of the unixcommand module
|
||||
|
|
|
|||
|
|
@ -474,7 +474,10 @@ def combat_status_message(fighter):
|
|||
distances to other fighters and objects. Called at turn
|
||||
start and by the 'status' command.
|
||||
"""
|
||||
|
||||
if not fighter.db.max_hp:
|
||||
fighter.db.hp = 100
|
||||
fighter.db.max_hp = 100
|
||||
|
||||
status_msg = ("HP Remaining: %i / %i" % (fighter.db.hp, fighter.db.max_hp))
|
||||
|
||||
if not is_in_combat(fighter):
|
||||
|
|
@ -1326,7 +1329,6 @@ class CmdStatus(Command):
|
|||
|
||||
def func(self):
|
||||
"This performs the actual command."
|
||||
|
||||
combat_status_message(self.caller)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue