Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CmdTakeFrom(Command):
- """
- Usage:
- take <item> from <container>
- Gets an item from the container, if it's in there.
- """
- key = 'take'
- def parse(self):
- # get args into 2 variables
- self.item_arg, self.container_arg = self.args.split("from")
- self.item_arg = self.item_arg.strip()
- self.container_arg = self.container_arg.strip()
- def func(self):
- caller = self.caller
- container_arg = self.container_arg
- item_arg = self.item_arg
- container = caller.search(container_arg, location=caller.location, quiet=True) # Check if container is in the room.
- if container:
- if len(container):
- container = container[0]
- item = caller.search(item_arg, location=container, quiet=True) # Check if the item is in the container.
- if item:
- if len(item):
- item = item[0]
- item.move_to(caller, quiet=True) #move the item to the caller inventory
- caller.msg(f"You take {item} from {container}.")
- caller.location.msg_contents(f"{caller.name} takes {item} from {container}.", exclude=caller)
- else:
- caller.msg(f"{item_arg} isn't in {container}!")
- else:
- caller.msg(f"{container_arg} doesn't exist!")
- return
- class CmdPut(Command):
- """
- Usage:
- put <item> in <container>
- Finds an item around the character and puts it in a container.
- """
- key = 'put'
- def parse(self):
- self.item_arg, self.container_arg = self.args.split('in')
- self.item_arg = self.item_arg.strip()
- self.container_arg = self.container_arg.strip()
- def func(self):
- caller = self.caller
- item_arg = self.item_arg
- container_arg = self.container_arg
- # Find the item.
- # Location unset, search conducted within the character and its location.
- item = caller.search(item_arg, quiet=True)
- if item:
- if len(item):
- item = item[0]
- container = caller.search(container_arg, quiet=True)
- if container:
- if len(container):
- container = container[0]
- if item.location == caller:
- caller.msg(f"You place {item.name} in {container.name}.")
- caller.msg_contents(f"{caller.name} places {item.name} in {container.name}.", exclude=caller)
- elif item.location == caller.location:
- caller.msg(f"You pick up {item.name} and place it in {container.name}.")
- caller.msg_contents(f"{caller.name} picks up {item.name} and places it in {container.name}.", exclude=caller)
- item.move_to(container, quiet=True)
- else:
- caller.msg(f"Could not find {container_arg}!")
- else:
- caller.msg(f"Could not find {item_arg}!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement