From 9304c8ea29942ed8ee41f24d85cc54912cc1fca8 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Sat, 6 May 2023 17:42:20 -0600 Subject: [PATCH] messages, test additions --- .../contrib/game_systems/containers/containers.py | 10 ++++++---- evennia/contrib/game_systems/containers/tests.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/evennia/contrib/game_systems/containers/containers.py b/evennia/contrib/game_systems/containers/containers.py index 8e0c70579e..27024a62ad 100644 --- a/evennia/contrib/game_systems/containers/containers.py +++ b/evennia/contrib/game_systems/containers/containers.py @@ -190,7 +190,9 @@ class CmdContainerGet(CmdGet): if caller == obj: self.msg("You can't get yourself.") return - if not obj.access(caller, "get"): + + # check if this object can be gotten + if not obj.access(caller, "get") or not obj.at_pre_get(caller): if obj.db.get_err_msg: self.msg(obj.db.get_err_msg) else: @@ -199,9 +201,7 @@ class CmdContainerGet(CmdGet): # calling possible at_pre_get_from hook on location if hasattr(location, "at_pre_get_from") and not location.at_pre_get_from(caller, obj): - return - # calling at_pre_get hook method - if not obj.at_pre_get(caller): + self.msg("You can't get that.") return success = obj.move_to(caller, quiet=True, move_type="get") @@ -270,10 +270,12 @@ class CmdPut(CmdDrop): # Call the object script's at_pre_drop() method. if not obj.at_pre_drop(caller): + self.msg("You can't put that down.") return # Call the container's possible at_pre_put_in method. if hasattr(container, "at_pre_put_in") and not container.at_pre_put_in(caller, obj): + self.msg("You can't put that there.") return success = obj.move_to(container, quiet=True, move_type="drop") diff --git a/evennia/contrib/game_systems/containers/tests.py b/evennia/contrib/game_systems/containers/tests.py index d52022f3c2..aab8f631b2 100644 --- a/evennia/contrib/game_systems/containers/tests.py +++ b/evennia/contrib/game_systems/containers/tests.py @@ -28,6 +28,9 @@ class TestContainerCmds(BaseEvenniaCommandTest): # make sure the object is in the container so we can look at it self.obj1.location = self.container self.call(CmdContainerLook(), "obj in box", "Obj") + # move it into a non-container object and look at it there too + self.obj1.location = self.obj2 + self.call(CmdContainerLook(), "obj in obj2", "Obj") def test_get_and_put(self): # get normally @@ -47,5 +50,13 @@ class TestContainerCmds(BaseEvenniaCommandTest): self.obj1.location = self.char1 self.call(CmdPut(), "obj in box", "You can't put things in that.") - + def test_at_capacity_put(self): + # set container capacity + self.container.capacity = 1 + # move object to container to fill capacity + self.obj2.location = self.container + # move object to character to try putting + self.obj1.location = self.char1 + self.call(CmdPut(), "obj in box", "You can't fit anything else in a Box.") + \ No newline at end of file