Refactored turn based combat tutorial
This commit is contained in:
parent
39a827b139
commit
cbaf9151c2
3 changed files with 634 additions and 168 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -16,6 +16,7 @@ class EvAdventureTurnbasedCombatHandlerTest(EvAdventureMixin, BaseEvenniaTest):
|
||||||
Test the turn-based combat-handler implementation.
|
Test the turn-based combat-handler implementation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
maxDiff = None
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"evennia.contrib.tutorials.evadventure.combat_turnbased"
|
"evennia.contrib.tutorials.evadventure.combat_turnbased"
|
||||||
|
|
@ -24,29 +25,40 @@ class EvAdventureTurnbasedCombatHandlerTest(EvAdventureMixin, BaseEvenniaTest):
|
||||||
)
|
)
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.combathandler = combat_turnbased.EvAdventureCombatHandler.objects.create()
|
|
||||||
self.combatant = self.character
|
self.combatant = self.character
|
||||||
self.target = create.create_object(EvAdventureCharacter, key="testchar2")
|
self.target = create.create_object(EvAdventureCharacter, key="testchar2")
|
||||||
self.combathandler.add_combatant(self.combatant)
|
|
||||||
self.combathandler.add_combatant(self.target)
|
# this already starts turn 1
|
||||||
|
self.combathandler = combat_turnbased.join_combat(self.combatant, self.target)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.combathandler.delete()
|
||||||
|
|
||||||
def test_remove_combatant(self):
|
def test_remove_combatant(self):
|
||||||
self.combathandler.remove_combatant(self.character)
|
self.combathandler.remove_combatant(self.character)
|
||||||
|
|
||||||
def test_start_turn(self):
|
def test_start_turn(self):
|
||||||
self.combathandler._start_turn()
|
|
||||||
self.assertEqual(self.combathandler.turn, 1)
|
|
||||||
self.combathandler._start_turn()
|
self.combathandler._start_turn()
|
||||||
self.assertEqual(self.combathandler.turn, 2)
|
self.assertEqual(self.combathandler.turn, 2)
|
||||||
|
self.combathandler._start_turn()
|
||||||
|
self.assertEqual(self.combathandler.turn, 3)
|
||||||
|
|
||||||
def test_end_of_turn__empty(self):
|
def test_end_of_turn__empty(self):
|
||||||
self.combathandler._end_turn()
|
self.combathandler._end_turn()
|
||||||
|
|
||||||
def test_register_and_run_action(self):
|
def test_register_and_run_action(self):
|
||||||
action = combat_turnbased.CombatActionAttack
|
action_class = combat_turnbased.CombatActionAttack
|
||||||
|
action = self.combathandler.combatant_actions[self.combatant][action_class.key]
|
||||||
|
|
||||||
|
self.combathandler.register_action(self.combatant, action.key)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.combathandler.action_queue[self.combatant],
|
||||||
|
(action, (), {})
|
||||||
|
)
|
||||||
|
|
||||||
action.use = MagicMock()
|
action.use = MagicMock()
|
||||||
|
|
||||||
self.combathandler.register_action(action, self.combatant)
|
|
||||||
self.combathandler._end_turn()
|
self.combathandler._end_turn()
|
||||||
action.use.assert_called_once()
|
action.use.assert_called_once()
|
||||||
|
|
||||||
|
|
@ -54,6 +66,6 @@ class EvAdventureTurnbasedCombatHandlerTest(EvAdventureMixin, BaseEvenniaTest):
|
||||||
def test_attack(self, mock_randint):
|
def test_attack(self, mock_randint):
|
||||||
mock_randint.return_value = 8
|
mock_randint.return_value = 8
|
||||||
self.combathandler.register_action(
|
self.combathandler.register_action(
|
||||||
combat_turnbased.CombatActionAttack, self.combatant, self.target
|
combat_turnbased.CombatActionAttack.key, self.combatant, self.target
|
||||||
)
|
)
|
||||||
self.combathandler._end_turn()
|
self.combathandler._end_turn()
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ class TaskHandler(object):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
TaskHandlerTask: An object to represent a task.
|
TaskHandlerTask: An object to represent a task.
|
||||||
Reference evennia.scripts.taskhandler.TaskHandlerTask for complete details.
|
Reference `evennia.scripts.taskhandler.TaskHandlerTask` for complete details.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# set the completion time
|
# set the completion time
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue