diff --git a/docs/source/Howtos/Beginner-Tutorial/Part3/Beginner-Tutorial-Combat-Turnbased.md b/docs/source/Howtos/Beginner-Tutorial/Part3/Beginner-Tutorial-Combat-Turnbased.md index fef9a3b05d..f6bbf8ba95 100644 --- a/docs/source/Howtos/Beginner-Tutorial/Part3/Beginner-Tutorial-Combat-Turnbased.md +++ b/docs/source/Howtos/Beginner-Tutorial/Part3/Beginner-Tutorial-Combat-Turnbased.md @@ -292,7 +292,7 @@ class CombatActionFlee(CombatAction): current_turn = combathandler.turn started_fleeing = combathandler.fleeing_combatants[self.combatant] 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: self.msg( @@ -372,7 +372,6 @@ class EvadventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler): action.execute() action.post_execute() - self.check_stop_combat() 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. -- **Lines 29-34**: 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. +- **Lines 28-33**: In this example, we have no internal order between actions. So we simply randomize in which order they fire. +- **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 @@ -457,7 +456,7 @@ class EvadventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler): # check if anyone managed to flee flee_timeout = self.flee_timeout 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 self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant) self.remove_combatant(combatant) diff --git a/evennia/contrib/tutorials/evadventure/combat_turnbased.py b/evennia/contrib/tutorials/evadventure/combat_turnbased.py index 4f422dc6a9..989ef965c0 100644 --- a/evennia/contrib/tutorials/evadventure/combat_turnbased.py +++ b/evennia/contrib/tutorials/evadventure/combat_turnbased.py @@ -61,7 +61,7 @@ class CombatActionFlee(CombatAction): current_turn = combathandler.turn started_fleeing = combathandler.fleeing_combatants[self.combatant] 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: self.msg( @@ -306,7 +306,6 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler): action.execute() action.post_execute() - self.check_stop_combat() def check_stop_combat(self): """Check if it's time to stop combat""" @@ -326,7 +325,7 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler): # check if anyone managed to flee flee_timeout = self.flee_timeout 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 self.msg("|y$You() successfully $conj(flee) from combat.|n", combatant=combatant) self.remove_combatant(combatant) diff --git a/evennia/contrib/tutorials/evadventure/combat_twitch.py b/evennia/contrib/tutorials/evadventure/combat_twitch.py index 88c1c9b1f8..a53cccfbda 100644 --- a/evennia/contrib/tutorials/evadventure/combat_twitch.py +++ b/evennia/contrib/tutorials/evadventure/combat_twitch.py @@ -501,7 +501,7 @@ class CmdUseItem(_BaseTwitchCombatCommand): if not target: 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.msg( f"$You() prepare to use {item.get_display_name(self.caller)}!", self.caller diff --git a/evennia/contrib/tutorials/evadventure/commands.py b/evennia/contrib/tutorials/evadventure/commands.py index 01383fb20c..9ead281bb1 100644 --- a/evennia/contrib/tutorials/evadventure/commands.py +++ b/evennia/contrib/tutorials/evadventure/commands.py @@ -5,7 +5,6 @@ are in additional to normal Evennia commands and should be added to the CharacterCmdSet New commands: - attack/hit [,...] inventory wield/wear unwield/remove @@ -33,7 +32,6 @@ from evennia import CmdSet, Command, InterruptCommand from evennia.utils.evmenu import EvMenu from evennia.utils.utils import inherits_from -from .combat import CombatFailure, join_combat from .enums import WieldLocation from .equipment import EquipmentError from .npcs import EvAdventureTalkativeNPC @@ -54,51 +52,6 @@ class EvAdventureCommand(Command): self.args = self.args.strip() -class CmdAttackTurnBased(EvAdventureCommand): - """ - Attack a target or join an existing combat. - - Usage: - attack - attack , , ... - - 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): """ 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") except EquipmentError: 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 " - "inventory is full.", + ( + f"$You({giver.key.key}) $conj(try) to give " + 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}, ) else: 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}, ) giver.ndb._evmenu.close_menu() @@ -455,7 +412,6 @@ class EvAdventureCmdSet(CmdSet): key = "evadventure" def at_cmdset_creation(self): - self.add(CmdAttackTurnBased()) self.add(CmdInventory()) self.add(CmdWieldOrWear()) self.add(CmdRemove()) diff --git a/evennia/contrib/tutorials/evadventure/tests/test_combat.py b/evennia/contrib/tutorials/evadventure/tests/test_combat.py index afc4be73bb..1df39859a0 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_combat.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_combat.py @@ -236,7 +236,7 @@ class TestCombatActionsBase(_CombatTestBase): runestone = create.create_object(EvAdventureRunestone, key="ice rune") # 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.TWO_HANDS], None) @@ -505,8 +505,8 @@ class EvAdventureTurnbasedCombatHandlerTest(_CombatTestBase): action_dict = {"key": "flee"} # first flee records the fleeing state + self.combathandler.flee_timeout = 2 # to make sure self._run_actions(action_dict) - self.combathandler.flee_timeout = 1 # to make sure self.assertEqual(self.combathandler.turn, 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.check_stop_combat() 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()) @@ -628,7 +628,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas self.call(combat_twitch.CmdAttack(), self.target.key, "You attack testmonster!") self.assertEqual( 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()) @@ -641,6 +641,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas "advantage": True, "stunt_type": Ability.STR, "defense_type": Ability.STR, + "dt": 3, } foil_result = { "key": "stunt", @@ -649,6 +650,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas "advantage": False, "stunt_type": Ability.STR, "defense_type": Ability.STR, + "dt": 3, } self.call( @@ -693,7 +695,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas self.call(combat_twitch.CmdUseItem(), "potion", "You prepare to use potion!") self.assertEqual( self.combatant_combathandler.action_dict, - {"key": "use", "item": item, "target": self.combatant}, + {"key": "use", "item": item, "target": self.combatant, "dt": 3}, ) self.call( @@ -703,7 +705,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas ) self.assertEqual( 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()) @@ -715,9 +717,11 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas ) 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.assertEqual( - self.combatant_combathandler.action_dict, {"key": "wield", "item": runestone} + self.combatant_combathandler.action_dict, {"key": "wield", "item": runestone, "dt": 3} ) diff --git a/evennia/contrib/tutorials/evadventure/tests/test_commands.py b/evennia/contrib/tutorials/evadventure/tests/test_commands.py index 05f4d1fb58..f669665c9a 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_commands.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_commands.py @@ -6,7 +6,6 @@ Test the EvAdventure commands. from unittest.mock import call, patch from anything import Something - from evennia.utils.create import create_object from evennia.utils.test_resources import BaseEvenniaCommandTest @@ -34,18 +33,6 @@ You use 0/11 equipment slots. """.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): self.char1.equipment.add(self.helmet) self.char1.equipment.add(self.weapon) @@ -85,7 +72,6 @@ You use 0/11 equipment slots. @patch("evennia.contrib.tutorials.evadventure.commands.EvMenu") def test_give__item(self, mock_EvMenu): - self.char1.equipment.add(self.helmet) recipient = create_object(EvAdventureCharacter, key="Friend", location=self.location) diff --git a/evennia/contrib/tutorials/evadventure/tests/test_npcs.py b/evennia/contrib/tutorials/evadventure/tests/test_npcs.py index 124c48b218..b79058e7e7 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_npcs.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_npcs.py @@ -18,6 +18,6 @@ class TestNPCBase(EvenniaTest): ) 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.charisma, 4) diff --git a/evennia/scripts/scripts.py b/evennia/scripts/scripts.py index 1b8b459b96..7abd589c34 100644 --- a/evennia/scripts/scripts.py +++ b/evennia/scripts/scripts.py @@ -128,7 +128,6 @@ class ExtendedLoopingCall(LoopingCall): if self.running and self.interval > 0: total_runtime = self.clock.seconds() - self.starttime 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))