Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from evennia.utils import evmenu
- def menunode_shopfront(caller):
- "This is the top-menu screen."
- shopname = caller.location.key
- wares = caller.location.db.storeroom.contents
- # Wares includes all items inside the storeroom, including the
- # door! Let's remove that from our for sale list.
- wares = [ware for ware in wares if ware.key.lower() != "door"]
- text = "*** Welcome to %s! ***\n" % shopname
- if wares:
- text += " Things for sale (choose 1-%i to inspect);" \
- " quit to exit:" % len(wares)
- else:
- text += " There is nothing for sale; quit to exit."
- options = []
- for ware in wares:
- # add an option for every ware in store
- options.append({"desc": "%s (%s money)" %
- (ware.key, ware.db.money_value or 1),
- "goto": "menunode_inspect_and_buy"})
- return text, options
- def menunode_inspect_and_buy(caller, raw_string):
- "Sets up the buy menu screen."
- wares = caller.location.db.storeroom.contents
- # Don't forget, we will need to remove that pesky door again!
- wares = [ware for ware in wares if ware.key.lower() != "door"]
- iware = int(raw_string) - 1
- ware = wares[iware]
- value = ware.db.money_value or 1
- wealth = caller.db.money or 0
- text = "You inspect %s:\n\n%s" % (ware.key, ware.db.desc)
- def buy_ware_result(caller):
- "This will be executed first when choosing to buy."
- if wealth >= value:
- rtext = "You pay %i money and purchase %s!" % \
- (value, ware.key)
- caller.db.money -= value
- ware.move_to(caller, quiet=True)
- else:
- rtext = "You cannot afford %i money for %s!" % \
- (value, ware.key)
- caller.msg(rtext)
- options = ({"desc": "Buy %s for %s money" % \
- (ware.key, ware.db.money_value or 1),
- "goto": "menunode_shopfront",
- "exec": buy_ware_result},
- {"desc": "Look for something else",
- "goto": "menunode_shopfront"})
- return text, options
- from evennia import Command
- class CmdBuy(Command):
- """
- Start to do some shopping
- Usage:
- buy
- shop
- browse
- This will allow you to browse the wares of the
- current shop and buy items you want.
- """
- key = "buy"
- aliases = ("shop", "browse")
- def func(self):
- "Starts the shop EvMenu instance"
- evmenu.EvMenu(self.caller,
- "typeclasses.npcshop",
- startnode="menunode_shopfront")
- #----------------------------------------------------------------------
- #
- # Builder code for ease of use
- #
- #
- #----------------------------------------------------------------------
- from evennia import DefaultRoom, DefaultExit, DefaultObject
- from evennia.utils.create import create_object
- from typeclasses.rooms import Room
- # class for our front shop room
- class NPCShop(DefaultRoom):
- def at_object_creation(self):
- # we could also use add(ShopCmdSet, permanent=True)
- self.cmdset.add_default(ShopCmdSet)
- self.db.storeroom = None
- # command to build a complete shop (the Command base class
- # should already have been imported earlier in this file)
- class CmdBuildShop(Command):
- """
- Build a new shop
- Usage:
- @buildshop shopname
- This will create a new NPCshop room
- as well as a linked store room (named
- simply <storename>-storage) for the
- wares on sale. The store room will be
- accessed through a locked door in
- the shop.
- """
- key = "@buildshop"
- locks = "cmd:perm(Builders)"
- help_category = "Builders"
- def func(self):
- "Create the shop rooms"
- if not self.args:
- self.msg("Usage: @buildshop <storename>")
- return
- # create the shop and storeroom
- shopname = self.args.strip()
- shop = create_object(NPCShop,
- key=shopname,
- location=None)
- storeroom = create_object(DefaultRoom,
- key="%s-storage" % shopname,
- location=None)
- shop.db.storeroom = storeroom
- # create a door between the two
- shop_exit = create_object(DefaultExit,
- key="back door",
- aliases=["storage", "store room"],
- location=shop,
- destination=storeroom)
- storeroom_exit = create_object(DefaultExit,
- key="door",
- location=storeroom,
- destination=shop)
- # make a key for accessing the store room
- storeroom_key_name = "%s-storekey" % shopname
- storeroom_key = create_object(DefaultObject,
- key=storeroom_key_name,
- location=shop)
- # only allow chars with this key to enter the store room
- shop_exit.locks.add("traverse:holds(%s)" % storeroom_key_name)
- # inform the builder about progress
- self.caller.msg("The shop %s was created!" % shop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement