Fix unit tests
This commit is contained in:
parent
09253dce31
commit
d13ac065c7
8 changed files with 29 additions and 86 deletions
|
|
@ -292,7 +292,7 @@ class CombatActionFlee(CombatAction):
|
||||||
current_turn = combathandler.turn
|
current_turn = combathandler.turn
|
||||||
started_fleeing = combathandler.fleeing_combatants[self.combatant]
|
started_fleeing = combathandler.fleeing_combatants[self.combatant]
|
||||||
flee_timeout = combathandler.flee_timeout
|
flee_timeout = combathandler.flee_timeout
|
||||||
time_left = flee_timeout - (current_turn - started_fleeing)
|
time_left = flee_timeout - (current_turn - started_fleeing) - 1
|
||||||
|
|
||||||
if time_left > 0:
|
if time_left > 0:
|
||||||
self.msg(
|
self.msg(
|
||||||
|
|
@ -372,7 +372,6 @@ class EvadventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
||||||
|
|
||||||
action.execute()
|
action.execute()
|
||||||
action.post_execute()
|
action.post_execute()
|
||||||
self.check_stop_combat()
|
|
||||||
|
|
||||||
def at_repeat(self):
|
def at_repeat(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -406,8 +405,8 @@ For `execute_next_action` :
|
||||||
|
|
||||||
The `at_repeat` is called repeatedly every `interval` seconds that the Script fires. This is what we use to track when each round ends.
|
The `at_repeat` is called repeatedly every `interval` seconds that the Script fires. This is what we use to track when each round ends.
|
||||||
|
|
||||||
- **Lines 29-34**: In this example, we have no internal order between actions. So we simply randomize in which order they fire.
|
- **Lines 28-33**: In this example, we have no internal order between actions. So we simply randomize in which order they fire.
|
||||||
- **Line 36**: We set this `set` in the `queue_action` to know when everyone submitted a new action. We must make sure to unset it here before the next round.
|
- **Line 35**: We set this `set` in the `queue_action` to know when everyone submitted a new action. We must make sure to unset it here before the next round.
|
||||||
|
|
||||||
### Check and stop combat
|
### Check and stop combat
|
||||||
|
|
||||||
|
|
@ -457,7 +456,7 @@ class EvadventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
||||||
# check if anyone managed to flee
|
# check if anyone managed to flee
|
||||||
flee_timeout = self.flee_timeout
|
flee_timeout = self.flee_timeout
|
||||||
for combatant, started_fleeing in self.fleeing_combatants.items():
|
for combatant, started_fleeing in self.fleeing_combatants.items():
|
||||||
if self.turn - started_fleeing >= flee_timeout:
|
if self.turn - started_fleeing >= flee_timeout - 1:
|
||||||
# if they are still alive/fleeing and have been fleeing long enough, escape
|
# if they are still alive/fleeing and have been fleeing long enough, escape
|
||||||
self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant)
|
self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant)
|
||||||
self.remove_combatant(combatant)
|
self.remove_combatant(combatant)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class CombatActionFlee(CombatAction):
|
||||||
current_turn = combathandler.turn
|
current_turn = combathandler.turn
|
||||||
started_fleeing = combathandler.fleeing_combatants[self.combatant]
|
started_fleeing = combathandler.fleeing_combatants[self.combatant]
|
||||||
flee_timeout = combathandler.flee_timeout
|
flee_timeout = combathandler.flee_timeout
|
||||||
time_left = flee_timeout - (current_turn - started_fleeing)
|
time_left = flee_timeout - (current_turn - started_fleeing) - 1
|
||||||
|
|
||||||
if time_left > 0:
|
if time_left > 0:
|
||||||
self.msg(
|
self.msg(
|
||||||
|
|
@ -306,7 +306,6 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
||||||
|
|
||||||
action.execute()
|
action.execute()
|
||||||
action.post_execute()
|
action.post_execute()
|
||||||
self.check_stop_combat()
|
|
||||||
|
|
||||||
def check_stop_combat(self):
|
def check_stop_combat(self):
|
||||||
"""Check if it's time to stop combat"""
|
"""Check if it's time to stop combat"""
|
||||||
|
|
@ -326,7 +325,7 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
||||||
# check if anyone managed to flee
|
# check if anyone managed to flee
|
||||||
flee_timeout = self.flee_timeout
|
flee_timeout = self.flee_timeout
|
||||||
for combatant, started_fleeing in self.fleeing_combatants.items():
|
for combatant, started_fleeing in self.fleeing_combatants.items():
|
||||||
if self.turn - started_fleeing >= flee_timeout:
|
if self.turn - started_fleeing >= flee_timeout - 1:
|
||||||
# if they are still alive/fleeing and have been fleeing long enough, escape
|
# if they are still alive/fleeing and have been fleeing long enough, escape
|
||||||
self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant)
|
self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant)
|
||||||
self.remove_combatant(combatant)
|
self.remove_combatant(combatant)
|
||||||
|
|
|
||||||
|
|
@ -501,7 +501,7 @@ class CmdUseItem(_BaseTwitchCombatCommand):
|
||||||
if not target:
|
if not target:
|
||||||
return
|
return
|
||||||
|
|
||||||
combathandler = self.get_or_create_combathandler(self.target)
|
combathandler = self.get_or_create_combathandler(target)
|
||||||
combathandler.queue_action({"key": "use", "item": item, "target": target, "dt": 3})
|
combathandler.queue_action({"key": "use", "item": item, "target": target, "dt": 3})
|
||||||
combathandler.msg(
|
combathandler.msg(
|
||||||
f"$You() prepare to use {item.get_display_name(self.caller)}!", self.caller
|
f"$You() prepare to use {item.get_display_name(self.caller)}!", self.caller
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ are in additional to normal Evennia commands and should be added
|
||||||
to the CharacterCmdSet
|
to the CharacterCmdSet
|
||||||
|
|
||||||
New commands:
|
New commands:
|
||||||
attack/hit <target>[,...]
|
|
||||||
inventory
|
inventory
|
||||||
wield/wear <item>
|
wield/wear <item>
|
||||||
unwield/remove <item>
|
unwield/remove <item>
|
||||||
|
|
@ -33,7 +32,6 @@ from evennia import CmdSet, Command, InterruptCommand
|
||||||
from evennia.utils.evmenu import EvMenu
|
from evennia.utils.evmenu import EvMenu
|
||||||
from evennia.utils.utils import inherits_from
|
from evennia.utils.utils import inherits_from
|
||||||
|
|
||||||
from .combat import CombatFailure, join_combat
|
|
||||||
from .enums import WieldLocation
|
from .enums import WieldLocation
|
||||||
from .equipment import EquipmentError
|
from .equipment import EquipmentError
|
||||||
from .npcs import EvAdventureTalkativeNPC
|
from .npcs import EvAdventureTalkativeNPC
|
||||||
|
|
@ -54,51 +52,6 @@ class EvAdventureCommand(Command):
|
||||||
self.args = self.args.strip()
|
self.args = self.args.strip()
|
||||||
|
|
||||||
|
|
||||||
class CmdAttackTurnBased(EvAdventureCommand):
|
|
||||||
"""
|
|
||||||
Attack a target or join an existing combat.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
attack <target>
|
|
||||||
attack <target>, <target>, ...
|
|
||||||
|
|
||||||
If the target is involved in combat already, you'll join combat with
|
|
||||||
the first target you specify. Attacking multiple will draw them all into
|
|
||||||
combat.
|
|
||||||
|
|
||||||
This will start/join turn-based, combat, where you have a limited
|
|
||||||
time to decide on your next action from a menu of options.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
key = "attack"
|
|
||||||
aliases = ("hit",)
|
|
||||||
|
|
||||||
def parse(self):
|
|
||||||
super().parse()
|
|
||||||
self.targets = [name.strip() for name in self.args.split(",")]
|
|
||||||
|
|
||||||
def func(self):
|
|
||||||
|
|
||||||
# find if
|
|
||||||
|
|
||||||
target_objs = []
|
|
||||||
for target in self.targets:
|
|
||||||
target_obj = self.caller.search(target)
|
|
||||||
if not target_obj:
|
|
||||||
# show a warning but don't abort
|
|
||||||
continue
|
|
||||||
target_objs.append(target_obj)
|
|
||||||
|
|
||||||
if target_objs:
|
|
||||||
try:
|
|
||||||
join_combat(self.caller, *target_objs, session=self.session)
|
|
||||||
except CombatFailure as err:
|
|
||||||
self.caller.msg(f"|r{err}|n")
|
|
||||||
else:
|
|
||||||
self.caller.msg("|rFound noone to attack.|n")
|
|
||||||
|
|
||||||
|
|
||||||
class CmdInventory(EvAdventureCommand):
|
class CmdInventory(EvAdventureCommand):
|
||||||
"""
|
"""
|
||||||
View your inventory
|
View your inventory
|
||||||
|
|
@ -269,15 +222,19 @@ def _accept_or_reject_gift(caller, raw_string, **kwargs):
|
||||||
item.move_to(caller, quiet=True, move_type="give")
|
item.move_to(caller, quiet=True, move_type="give")
|
||||||
except EquipmentError:
|
except EquipmentError:
|
||||||
caller.location.msg_contents(
|
caller.location.msg_contents(
|
||||||
f"$You({giver.key.key}) $conj(try) to give "
|
(
|
||||||
f"{item.key} to $You({caller.key}), but they can't accept it since their "
|
f"$You({giver.key.key}) $conj(try) to give "
|
||||||
"inventory is full.",
|
f"{item.key} to $You({caller.key}), but they can't accept it since their "
|
||||||
|
"inventory is full."
|
||||||
|
),
|
||||||
mapping={giver.key: giver, caller.key: caller},
|
mapping={giver.key: giver, caller.key: caller},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
caller.location.msg_contents(
|
caller.location.msg_contents(
|
||||||
f"$You({giver.key}) $conj(give) {item.key} to $You({caller.key}), "
|
(
|
||||||
"and they accepted the offer.",
|
f"$You({giver.key}) $conj(give) {item.key} to $You({caller.key}), "
|
||||||
|
"and they accepted the offer."
|
||||||
|
),
|
||||||
mapping={giver.key: giver, caller.key: caller},
|
mapping={giver.key: giver, caller.key: caller},
|
||||||
)
|
)
|
||||||
giver.ndb._evmenu.close_menu()
|
giver.ndb._evmenu.close_menu()
|
||||||
|
|
@ -455,7 +412,6 @@ class EvAdventureCmdSet(CmdSet):
|
||||||
key = "evadventure"
|
key = "evadventure"
|
||||||
|
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
self.add(CmdAttackTurnBased())
|
|
||||||
self.add(CmdInventory())
|
self.add(CmdInventory())
|
||||||
self.add(CmdWieldOrWear())
|
self.add(CmdWieldOrWear())
|
||||||
self.add(CmdRemove())
|
self.add(CmdRemove())
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ class TestCombatActionsBase(_CombatTestBase):
|
||||||
runestone = create.create_object(EvAdventureRunestone, key="ice rune")
|
runestone = create.create_object(EvAdventureRunestone, key="ice rune")
|
||||||
|
|
||||||
# check hands are empty
|
# check hands are empty
|
||||||
self.assertEqual(self.combatant.weapon.key, "Empty Fists")
|
self.assertEqual(self.combatant.weapon.key, "Bare hands")
|
||||||
self.assertEqual(self.combatant.equipment.slots[WieldLocation.WEAPON_HAND], None)
|
self.assertEqual(self.combatant.equipment.slots[WieldLocation.WEAPON_HAND], None)
|
||||||
self.assertEqual(self.combatant.equipment.slots[WieldLocation.TWO_HANDS], None)
|
self.assertEqual(self.combatant.equipment.slots[WieldLocation.TWO_HANDS], None)
|
||||||
|
|
||||||
|
|
@ -505,8 +505,8 @@ class EvAdventureTurnbasedCombatHandlerTest(_CombatTestBase):
|
||||||
action_dict = {"key": "flee"}
|
action_dict = {"key": "flee"}
|
||||||
|
|
||||||
# first flee records the fleeing state
|
# first flee records the fleeing state
|
||||||
|
self.combathandler.flee_timeout = 2 # to make sure
|
||||||
self._run_actions(action_dict)
|
self._run_actions(action_dict)
|
||||||
self.combathandler.flee_timeout = 1 # to make sure
|
|
||||||
self.assertEqual(self.combathandler.turn, 1)
|
self.assertEqual(self.combathandler.turn, 1)
|
||||||
self.assertEqual(self.combathandler.fleeing_combatants[self.combatant], 1)
|
self.assertEqual(self.combathandler.fleeing_combatants[self.combatant], 1)
|
||||||
|
|
||||||
|
|
@ -612,7 +612,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
self.combatant_combathandler.get_sides = Mock(return_value=([], []))
|
self.combatant_combathandler.get_sides = Mock(return_value=([], []))
|
||||||
self.combatant_combathandler.check_stop_combat()
|
self.combatant_combathandler.check_stop_combat()
|
||||||
self.combatant.msg.assert_called_with(
|
self.combatant.msg.assert_called_with(
|
||||||
text=("The combat is over. Still standing: You.", {}), from_obj=self.combatant
|
text=("The combat is over.", {}), from_obj=self.combatant
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
||||||
|
|
@ -628,7 +628,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
self.call(combat_twitch.CmdAttack(), self.target.key, "You attack testmonster!")
|
self.call(combat_twitch.CmdAttack(), self.target.key, "You attack testmonster!")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.combatant_combathandler.action_dict,
|
self.combatant_combathandler.action_dict,
|
||||||
{"key": "attack", "target": self.target, "dt": 3},
|
{"key": "attack", "target": self.target, "dt": 3, "repeat": True},
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
||||||
|
|
@ -641,6 +641,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
"advantage": True,
|
"advantage": True,
|
||||||
"stunt_type": Ability.STR,
|
"stunt_type": Ability.STR,
|
||||||
"defense_type": Ability.STR,
|
"defense_type": Ability.STR,
|
||||||
|
"dt": 3,
|
||||||
}
|
}
|
||||||
foil_result = {
|
foil_result = {
|
||||||
"key": "stunt",
|
"key": "stunt",
|
||||||
|
|
@ -649,6 +650,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
"advantage": False,
|
"advantage": False,
|
||||||
"stunt_type": Ability.STR,
|
"stunt_type": Ability.STR,
|
||||||
"defense_type": Ability.STR,
|
"defense_type": Ability.STR,
|
||||||
|
"dt": 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.call(
|
self.call(
|
||||||
|
|
@ -693,7 +695,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
self.call(combat_twitch.CmdUseItem(), "potion", "You prepare to use potion!")
|
self.call(combat_twitch.CmdUseItem(), "potion", "You prepare to use potion!")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.combatant_combathandler.action_dict,
|
self.combatant_combathandler.action_dict,
|
||||||
{"key": "use", "item": item, "target": self.combatant},
|
{"key": "use", "item": item, "target": self.combatant, "dt": 3},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.call(
|
self.call(
|
||||||
|
|
@ -703,7 +705,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.combatant_combathandler.action_dict,
|
self.combatant_combathandler.action_dict,
|
||||||
{"key": "use", "item": item, "target": self.target},
|
{"key": "use", "item": item, "target": self.target, "dt": 3},
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
@patch("evennia.contrib.tutorials.evadventure.combat_twitch.unrepeat", new=Mock())
|
||||||
|
|
@ -715,9 +717,11 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
||||||
)
|
)
|
||||||
|
|
||||||
self.call(combat_twitch.CmdWield(), "sword", "You reach for sword!")
|
self.call(combat_twitch.CmdWield(), "sword", "You reach for sword!")
|
||||||
self.assertEqual(self.combatant_combathandler.action_dict, {"key": "wield", "item": sword})
|
self.assertEqual(
|
||||||
|
self.combatant_combathandler.action_dict, {"key": "wield", "item": sword, "dt": 3}
|
||||||
|
)
|
||||||
|
|
||||||
self.call(combat_twitch.CmdWield(), "runestone", "You reach for runestone!")
|
self.call(combat_twitch.CmdWield(), "runestone", "You reach for runestone!")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.combatant_combathandler.action_dict, {"key": "wield", "item": runestone}
|
self.combatant_combathandler.action_dict, {"key": "wield", "item": runestone, "dt": 3}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ Test the EvAdventure commands.
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
from anything import Something
|
from anything import Something
|
||||||
|
|
||||||
from evennia.utils.create import create_object
|
from evennia.utils.create import create_object
|
||||||
from evennia.utils.test_resources import BaseEvenniaCommandTest
|
from evennia.utils.test_resources import BaseEvenniaCommandTest
|
||||||
|
|
||||||
|
|
@ -34,18 +33,6 @@ You use 0/11 equipment slots.
|
||||||
""".strip(),
|
""".strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("evennia.contrib.tutorials.evadventure.commands.join_combat")
|
|
||||||
def test_attack(self, mock_join_combat):
|
|
||||||
self.location.allow_combat = True
|
|
||||||
|
|
||||||
target = create_object(EvAdventureMob, key="Ogre", location=self.location)
|
|
||||||
|
|
||||||
self.call(commands.CmdAttackTurnBased(), "ogre", "")
|
|
||||||
|
|
||||||
mock_join_combat.assert_called_with(self.char1, target, session=Something)
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
|
|
||||||
def test_wield_or_wear(self):
|
def test_wield_or_wear(self):
|
||||||
self.char1.equipment.add(self.helmet)
|
self.char1.equipment.add(self.helmet)
|
||||||
self.char1.equipment.add(self.weapon)
|
self.char1.equipment.add(self.weapon)
|
||||||
|
|
@ -85,7 +72,6 @@ You use 0/11 equipment slots.
|
||||||
|
|
||||||
@patch("evennia.contrib.tutorials.evadventure.commands.EvMenu")
|
@patch("evennia.contrib.tutorials.evadventure.commands.EvMenu")
|
||||||
def test_give__item(self, mock_EvMenu):
|
def test_give__item(self, mock_EvMenu):
|
||||||
|
|
||||||
self.char1.equipment.add(self.helmet)
|
self.char1.equipment.add(self.helmet)
|
||||||
recipient = create_object(EvAdventureCharacter, key="Friend", location=self.location)
|
recipient = create_object(EvAdventureCharacter, key="Friend", location=self.location)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ class TestNPCBase(EvenniaTest):
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(npc.hp_multiplier, 4)
|
self.assertEqual(npc.hp_multiplier, 4)
|
||||||
self.assertEqual(npc.hp, 16)
|
self.assertEqual(npc.hp_max, 16)
|
||||||
self.assertEqual(npc.strength, 4)
|
self.assertEqual(npc.strength, 4)
|
||||||
self.assertEqual(npc.charisma, 4)
|
self.assertEqual(npc.charisma, 4)
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ class ExtendedLoopingCall(LoopingCall):
|
||||||
if self.running and self.interval > 0:
|
if self.running and self.interval > 0:
|
||||||
total_runtime = self.clock.seconds() - self.starttime
|
total_runtime = self.clock.seconds() - self.starttime
|
||||||
interval = self.start_delay or self.interval
|
interval = self.start_delay or self.interval
|
||||||
print("next_call_time:", total_runtime, interval, self.clock.seconds(), self.starttime)
|
|
||||||
return max(0, interval - (total_runtime % self.interval))
|
return max(0, interval - (total_runtime % self.interval))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue