Advertisement
Kovitikus

Take from and Put in Commands

Apr 8th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.02 KB | None | 0 0
  1. class CmdTakeFrom(Command):
  2.     """
  3.    Usage:
  4.  
  5.        take <item> from <container>
  6.    
  7.    Gets an item from the container, if it's in there.
  8.    """
  9.     key = 'take'
  10.  
  11.     def parse(self):
  12.         # get args into 2 variables
  13.         self.item_arg, self.container_arg = self.args.split("from")
  14.         self.item_arg = self.item_arg.strip()
  15.         self.container_arg = self.container_arg.strip()
  16.      
  17.            
  18.  
  19.     def func(self):
  20.         caller = self.caller
  21.         container_arg = self.container_arg
  22.         item_arg = self.item_arg
  23.  
  24.         container = caller.search(container_arg, location=caller.location, quiet=True) # Check if container is in the room.
  25.         if container:
  26.             if len(container):
  27.                 container = container[0]
  28.             item = caller.search(item_arg, location=container, quiet=True) # Check if the item is in the container.
  29.             if item:
  30.                 if len(item):
  31.                     item = item[0]
  32.                 item.move_to(caller, quiet=True) #move the item to the caller inventory
  33.                 caller.msg(f"You take {item} from {container}.")
  34.                 caller.location.msg_contents(f"{caller.name} takes {item} from {container}.", exclude=caller)
  35.             else:
  36.                 caller.msg(f"{item_arg} isn't in {container}!")
  37.         else:
  38.             caller.msg(f"{container_arg} doesn't exist!")
  39.             return
  40.  
  41. class CmdPut(Command):
  42.     """
  43.    Usage:
  44.        put <item> in <container>
  45.    
  46.    Finds an item around the character and puts it in a container.
  47.    """
  48.     key = 'put'
  49.  
  50.     def parse(self):
  51.         self.item_arg, self.container_arg = self.args.split('in')
  52.         self.item_arg = self.item_arg.strip()
  53.         self.container_arg = self.container_arg.strip()
  54.  
  55.     def func(self):
  56.         caller = self.caller
  57.         item_arg = self.item_arg
  58.         container_arg = self.container_arg
  59.  
  60.         # Find the item.
  61.         # Location unset, search conducted within the character and its location.
  62.         item = caller.search(item_arg, quiet=True)
  63.         if item:
  64.             if len(item):
  65.                 item = item[0]
  66.             container = caller.search(container_arg, quiet=True)
  67.             if container:
  68.                 if len(container):
  69.                     container = container[0]
  70.                 if item.location == caller:
  71.                     caller.msg(f"You place {item.name} in {container.name}.")
  72.                     caller.msg_contents(f"{caller.name} places {item.name} in {container.name}.", exclude=caller)
  73.                 elif item.location == caller.location:
  74.                     caller.msg(f"You pick up {item.name} and place it in {container.name}.")
  75.                     caller.msg_contents(f"{caller.name} picks up {item.name} and places it in {container.name}.", exclude=caller)
  76.                 item.move_to(container, quiet=True)
  77.             else:
  78.                 caller.msg(f"Could not find {container_arg}!")
  79.         else:
  80.             caller.msg(f"Could not find {item_arg}!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement