Advertisement
Kovitikus

Working Stock Command

Nov 30th, 2020 (edited)
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.79 KB | None | 0 0
  1. # Results
  2. """
  3. =========[Stock]===============
  4. crudely-made torch    10
  5. foul-smelling bait    2
  6. ===============================
  7. """
  8.  
  9. # MerchantHandler
  10. from world.items.item_prototypes import ITEMS
  11.  
  12. class MerchantHandler:
  13.     def __init__(self, owner):
  14.         self.owner = owner
  15.  
  16.     def return_stock(self):
  17.         owner = self.owner
  18.         if owner.attributes.has('stock'):
  19.             stocked_items = owner.attributes.get('stock')
  20.  
  21.         header = "=========[Stock]==============="
  22.         body = []
  23.         footer = "==============================="
  24.         item = None
  25.         name = None
  26.         price = None
  27.  
  28.         for i in stocked_items:
  29.             item = ITEMS[i]
  30.             name = item['key']
  31.             price = item['price']
  32.             body.append(f"{name}    {price}\n")
  33.  
  34.         msg = f"{header}\n{''.join(body)}{footer}"
  35.         return msg
  36.  
  37.  
  38.  
  39. # Stock Command
  40. class CmdStock(Command):
  41.     key = 'stock'
  42.     def func(self):
  43.         room_contents = self.caller.location.contents
  44.         for i in room_contents:
  45.             if i.is_typeclass('typeclasses.characters.Merchant'):
  46.                 self.caller.msg(i.merch.return_stock())
  47.  
  48.  
  49.  
  50. # NPC Prototypes
  51. MERCHANT = {
  52.     'prototype_key': 'merchant',
  53.     'key': 'merchant',
  54.     'typeclass': 'typeclasses.characters.Merchant',
  55.     'tags': ('merchant', 'npc')
  56. }
  57.  
  58. BASIC_SUPPLIES = {
  59.     'prototype_parent': 'merchant',
  60.     'key': 'basic supplies merchant',
  61.     'stock': ['crudely_made_torch', 'foul_smelling_bait']
  62. }
  63.  
  64.  
  65.  
  66. # Item Prototypes
  67. from evennia.utils.utils import random
  68.  
  69. ITEMS = {
  70.     'food': {
  71.         'prototype_key': 'food',
  72.         'prototype_desc': 'Food items.',
  73.         'prototype_tags': 'food',
  74.         'typeclass': 'typeclasses.objects.Object',
  75.         'tags': ('food', 'consumable')
  76.     },
  77.  
  78.     'raspbery_cake': {
  79.         'prototype_parent': 'food',
  80.         'key': 'raspberry cake',
  81.         'price': 10,
  82.         'hunger': 10
  83.     },
  84.  
  85.     'beef_steak': {
  86.         'prototype_parent': 'food',
  87.         'key': 'beef steak',
  88.         'price': 50,
  89.         'hunger': 25
  90.     },
  91.  
  92.     'millet_porridge': {
  93.         'prototype_parent': 'food',
  94.         'key': 'millet porridge',
  95.         'price': 4,
  96.         'hunger': 15
  97.     },
  98.  
  99.     'barley_porridge': {
  100.         'prototype_parent': 'food',
  101.         'key': 'barley porridge',
  102.         'price': 4,
  103.         'hunger': 15
  104.     },
  105.  
  106.     'stewed_beetroot': {
  107.         'prototype_parent': 'food',
  108.         'key': 'stewed beetroot',
  109.         'price': 4,
  110.         'hunger': 15
  111.     },
  112.  
  113.     'boiled_mutton_and_peas': {
  114.         'prototype_parent': 'food',
  115.         'key': 'boiled mutton and peas',
  116.         'price': 11,
  117.         'hunger': 25
  118.     },
  119.  
  120.     'drink': {
  121.         'prototype_key': 'drink',
  122.         'prototype_desc': 'Drink items.',
  123.         'prototype_tags': 'drink',
  124.         'typeclass': 'typeclasses.objects.Object',
  125.         'tags': ('drink', 'consumable')
  126.     },
  127.  
  128.     'black_tea': {
  129.         'prototype_parent': 'drink',
  130.         'key': 'black tea',
  131.         'price': 3,
  132.         'thirst': 5
  133.     },
  134.  
  135.     'water': {
  136.         'prototype_parent': 'drink',
  137.         'key': 'water',
  138.         'price': 1,
  139.         'thirst': 5
  140.     },
  141.  
  142.     'lighting': {
  143.         'prototype_key': 'lighting',
  144.         'key': 'lighting',
  145.         'typeclass': 'typeclasses.objects.Lighting'
  146.     },
  147.  
  148.     'torch': {
  149.         'prototype_parent': 'lighting',
  150.         'key': 'torch',
  151.         'typeclass': 'typeclasses.objects.Torch'
  152.     },
  153.  
  154.     'crudely_made_torch': {
  155.         'prototype_parent': 'lighting',
  156.         'prototype_key': 'CRUDELY_MADE_TORCH',
  157.         'key': 'crudely-made torch',
  158.         'typeclass': 'typeclasses.objects.Torch',
  159.         'price': 10,
  160.         'fuel': 90,
  161.         'burn_rate': 30
  162.     },
  163.  
  164.     'inventory_container': {
  165.         'prototype_key': 'inventory_container',
  166.         'key': 'inventory_container',
  167.         'typeclass': 'typeclasses.objects.InventoryContainer'
  168.     },
  169.  
  170.     'inventory_bag': {
  171.         'prototype_parent': 'inventory_container',
  172.         'key': lambda: generate_random_bag_key()
  173.     },
  174.  
  175.     'bait': {
  176.         'prototype_key': 'bait',
  177.         'prototype_desc': 'Fishing bait',
  178.         'prototype_tags': 'bait',
  179.         'typeclass': 'typeclasses.objects.Object',
  180.         'tags': ('bait', 'fishing')
  181.     },
  182.  
  183.     'foul_smelling_bait': {
  184.         'prototype_parent': 'bait',
  185.         'prototype_key': 'FOUL_SMELLING_BAIT',
  186.         'key': 'foul-smelling bait',
  187.         'lure': 1,
  188.         'price': 2,
  189.     }
  190. }
  191.  
  192. def generate_random_bag_key():
  193.     color = ('red', 'blue', 'green', 'yellow', 'black')
  194.     adjective = ('tattered', 'worn', 'pristine', 'well-crafted', 'frayed')
  195.     # a tattered red bag
  196.     # a pristine yellow bag
  197.     bag_key = f"a {random.choice(adjective)} {random.choice(color)} bag"
  198.     return bag_key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement