From 798d5b3059e272412ded2de0e785497b927819b9 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 1 Apr 2024 20:16:40 +0200 Subject: [PATCH] Update Changelog --- CHANGELOG.md | 3 +++ evennia/commands/default/general.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c7be3c330..12d9de3e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ - [Feature][pull3466]: Add optional `no_article` kwarg to `DefaultObject.get_numbered_name` for the system to skip adding automatic articles. (chiizujin) +- [Feature][pull3433]: Add ability to default get/drop to affect stacks of + items, such as `get/drop 3 rock` by a custom class parent (InspectorCaracal) - Feature: Clean up the default Command variable list shown when a command has no `func()` defined (Griatch) - [Feature][issue3461]: Add `DefaultObject.filter_display_visible` helper method @@ -61,6 +63,7 @@ [pull3464]: https://github.com/evennia/evennia/pull/3464 [pull3466]: https://github.com/evennia/evennia/pull/3466 [pull3467]: https://github.com/evennia/evennia/pull/3467 +[pull3433]: https://github.com/evennia/evennia/pull/3433 [issue3450]: https://github.com/evennia/evennia/issues/3450 [issue3462]: https://github.com/evennia/evennia/issues/3462 [issue3460]: https://github.com/evennia/evennia/issues/3460 diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index d91b6b6b83..55099423f9 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -379,6 +379,7 @@ class CmdInventory(COMMAND_DEFAULT_CLASS): string = f"|wYou are carrying:\n{table}" self.msg(text=(string, {"type": "inventory"})) + class NumberedTargetCommand(COMMAND_DEFAULT_CLASS): """ A class that parses out an optional number component from the input string. This @@ -386,8 +387,9 @@ class NumberedTargetCommand(COMMAND_DEFAULT_CLASS): than used on its own. Note that the class's __doc__ string (this text) is used by Evennia to create the - automatic help entry for the command, so make sure to document consistently here. + automatic help entry for the command, so make sure to document consistently here. """ + def parse(self): """ This method is called by the cmdhandler once the command name @@ -417,13 +419,13 @@ class NumberedTargetCommand(COMMAND_DEFAULT_CLASS): storing the results in the following variables: self.number = an integer representing the amount, or 0 if none was given self.args = the re-defined input with the leading number removed - + Optionally, if COMMAND_DEFAULT_CLASS is a MuxCommand, it applies the same parsing to self.lhs """ super().parse() self.number = 0 - if hasattr(self, 'lhs'): + if hasattr(self, "lhs"): # handle self.lhs but don't require it count, *args = self.lhs.split(maxsplit=1) # we only use the first word as a count if it's a number and @@ -458,7 +460,6 @@ class CmdGet(NumberedTargetCommand): locks = "cmd:all()" arg_regex = r"\s|$" - def func(self): """implements the command.""" @@ -498,7 +499,7 @@ class CmdGet(NumberedTargetCommand): moved.append(obj) # calling at_get hook method obj.at_get(caller) - + if not moved: # none of the objects were successfully moved self.msg("That can't be picked up.") @@ -558,7 +559,7 @@ class CmdDrop(NumberedTargetCommand): moved.append(obj) # Call the object's at_drop() method. obj.at_drop(caller) - + if not moved: # none of the objects were successfully moved self.msg("That can't be dropped.") @@ -583,7 +584,6 @@ class CmdGive(NumberedTargetCommand): locks = "cmd:all()" arg_regex = r"\s|$" - def func(self): """Implement give""" @@ -610,7 +610,6 @@ class CmdGive(NumberedTargetCommand): # NOTE: this behavior may be a bug, see issue #3432 to_give = utils.make_iter(to_give) - singular, plural = to_give[0].get_numbered_name(len(to_give), caller) if target == caller: caller.msg(f"You keep {plural if len(to_give) > 1 else singular} to yourself.") @@ -629,7 +628,7 @@ class CmdGive(NumberedTargetCommand): moved.append(obj) # Call the object's at_give() method. obj.at_give(caller, target) - + if not moved: caller.msg(f"You could not give that to {target.get_display_name(caller)}.") else: