Example #1
0
 def make_equipment(self):
     prototype = prototypes.search_prototype("hardened_iron_large_weapon", require_single=True)
     armor_prototype = prototypes.search_prototype("hardened_iron_coat_of_plates", require_single=True)
     # Get prototype data
     large_data = prototype[0]
     armor_data = armor_prototype[0]
     # Spawn item using data
     weapon_item = spawn(large_data)
     armor_item = spawn(armor_data)
     # Move item to caller's inventory
     weapon_item[0].move_to(self, quiet=True)
     armor_item[0].move_to(self, quiet=True)
     # Equip items
     self.execute_cmd('equip hardened iron large weapon')
     self.execute_cmd('equip hardened iron coat of plates')
Example #2
0
def menunode_equipment_list(caller, raw_string):
    """Initial equipment "shopping" - list items in a category"""
    text = "You currently have {}.\n".format(as_price(caller.new_char.db.wallet))
    text += "Select an item to view details and buy:"
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(_CATEGORY_LIST):
        caller.ndb._menutree.item_category = _CATEGORY_LIST[int(raw_string) - 1]

    category = (caller.ndb._menutree.item_category
                if hasattr(caller.ndb._menutree, 'item_category')
                else '')

    help = _CATEGORY_HELP[category]
    prototypes = spawn(return_parents=True)
    options = []
    for proto in _EQUIPMENT_CATEGORIES[category][1:]:
        options.append({
            "desc": _format_menuitem_desc(prototypes[proto.lower()]),
            "goto": "menunode_examine_and_buy"
        })
    options.append({
        "key": ("Back", "_default"),
        "desc": "to category list",
        "goto": "menunode_equipment_cats",
    })
    return (text, help), options
Example #3
0
def menunode_equipment_list(caller, raw_string):
    """Initial equipment "shopping" - list items in a category"""
    text = "You currently have {}.\n".format(
        as_price(caller.new_char.db.wallet))
    text += "Select an item to view details and buy:"
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(_CATEGORY_LIST):
        caller.ndb._menutree.item_category = _CATEGORY_LIST[int(raw_string) -
                                                            1]

    category = (caller.ndb._menutree.item_category if hasattr(
        caller.ndb._menutree, 'item_category') else '')

    help = _CATEGORY_HELP[category]
    prototypes = spawn(return_prototypes=True)
    options = []
    for proto in _EQUIPMENT_CATEGORIES[category][1:]:
        options.append({
            "desc": _format_menuitem_desc(prototypes[proto]),
            "goto": "menunode_examine_and_buy"
        })
    options.append({
        "key": ("Back", "_default"),
        "desc": "to category list",
        "goto": "menunode_equipment_cats",
    })
    return (text, help), options
Example #4
0
 def make_equipment(self):
     prototype = prototypes.search_prototype("iron_medium_weapon", require_single=True)
     armor_prototype = prototypes.search_prototype("iron_coat_of_plates", require_single=True)
     shield_prototype = prototypes.search_prototype("iron_shield", require_single=True)
     # Get prototype data
     longsword_data = prototype[0]
     armor_data = armor_prototype[0]
     shield_data = shield_prototype[0]
     # Spawn item using data
     weapon_item = spawn(longsword_data)
     armor_item = spawn(armor_data)
     shield_item = spawn(shield_data)
     # Move item to caller's inventory
     weapon_item[0].move_to(self, quiet=True)
     armor_item[0].move_to(self, quiet=True)
     shield_item[0].move_to(self, quiet=True)
     # Equip items
     self.execute_cmd('equip iron medium weapon')
     self.execute_cmd('equip iron coat of plates')
     self.execute_cmd('equip iron shield')
Example #5
0
 def make_equipment(self):
     prototype = prototypes.search_prototype("bow", require_single=True)
     armor_prototype = prototypes.search_prototype("iron_coat_of_plates", require_single=True)
     arrow_prototype = prototypes.search_prototype("arrows", require_single=True)
     # Get prototype data
     bow_data = prototype[0]
     armor_data = armor_prototype[0]
     arrow_data = arrow_prototype[0]
     # Spawn item using data
     weapon_item = spawn(bow_data)
     armor_item = spawn(armor_data)
     arrow_item = spawn(arrow_data)
     # Move item to caller's inventory
     weapon_item[0].move_to(self, quiet=True)
     armor_item[0].move_to(self, quiet=True)
     arrow_item[0].move_to(self, quiet=True)
     # Equip items
     self.execute_cmd('equip bow')
     self.execute_cmd('equip iron coat of plates')
     self.execute_cmd('equip arrows')
Example #6
0
def menunode_examine_and_buy(caller, raw_string):
    """Examine and buy an item."""
    char = caller.new_char
    prototypes = spawn(return_parents=True)
    items, item = _EQUIPMENT_CATEGORIES[caller.ndb._menutree.item_category][1:], None
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(items):
        item = prototypes[items[int(raw_string) - 1].lower()]
    if item:
        text = _format_item_details(item)
        text += "You currently have {}. Purchase |w{}|n?".format(
                    as_price(char.db.wallet),
                    item['key']
                )
        help = "Choose carefully. Purchases are final."

        def purchase_item(session):
            """Process item purchase."""
            try:
                # this will raise exception if caller doesn't
                # have enough funds in their `db.wallet`
                print(item)
                transfer_funds(char, None, item['value'])
                ware = spawn(item).pop()
                ware.move_to(char, quiet=True)
                ware.at_get(char)
                rtext = "You pay {} and purchase {}".format(
                            as_price(ware.db.value),
                            ware.key
                         )
            except InsufficientFunds:
                rtext = "You do not have enough money to buy {}.".format(
                            item['key'])
            session.msg(rtext)

        options = ({"key": ("Yes", "ye", "y"),
                    "desc": "Purchase {} for {}".format(
                               item['key'],
                               as_price(item['value'])
                            ),
                    "exec": purchase_item,
                    "goto": "menunode_equipment_cats"},
                   {"key": ("No", "n", "_default"),
                    "desc": "Go back to category list",
                    "goto": "menunode_equipment_list"}
                   )

        return (text, help), options
    else:
        assert False
Example #7
0
 def purchase_item(session):
     """Process item purchase."""
     try:
         # this will raise exception if caller doesn't
         # have enough funds in their `db.wallet`
         print(item)
         transfer_funds(char, None, item_value)
         ware = spawn(item).pop()
         ware.move_to(char, quiet=True)
         ware.at_get(char)
         rtext = f"You pay {as_price(ware.db.value)} and purchase {ware.key}"
     except InsufficientFunds:
         rtext = f"You do not have enough money to buy {item_key}."
     session.msg(rtext)
Example #8
0
def menunode_examine_and_buy(caller, raw_string):
    """Examine and buy an item."""
    char = caller.new_char
    prototypes = spawn(return_parents=True)
    items, item = _EQUIPMENT_CATEGORIES[caller.ndb._menutree.item_category][1:], None
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(items):
        item = prototypes[items[int(raw_string) - 1].lower()]
    if item:
        text = _format_item_details(item)
        text += "You currently have {}. Purchase |w{}|n?".format(
                    as_price(char.db.wallet),
                    item['key']
                )
        help = "Choose carefully. Purchases are final."

        def purchase_item(session):
            """Process item purchase."""
            try:
                # this will raise exception if caller doesn't
                # have enough funds in their `db.wallet`
                print(item)
                transfer_funds(char, None, item['value'])
                ware = spawn(item).pop()
                ware.move_to(char, quiet=True)
                ware.at_get(char)
                rtext = "You pay {} and purchase {}".format(
                            as_price(ware.db.value),
                            ware.key
                         )
            except InsufficientFunds:
                rtext = "You do not have enough money to buy {}.".format(
                            item['key'])
            session.msg(rtext)

        options = ({"key": ("Yes", "ye", "y"),
                    "desc": "Purchase {} for {}".format(
                               item['key'],
                               as_price(item['value'])
                            ),
                    "exec": purchase_item,
                    "goto": "menunode_equipment_cats"},
                   {"key": ("No", "n", "_default"),
                    "desc": "Go back to category list",
                    "goto": "menunode_equipment_list"}
                   )

        return (text, help), options
    else:
        assert False
Example #9
0
 def purchase_item(session):
     """Process item purchase."""
     try:
         # this will raise exception if caller doesn't
         # have enough funds in their `db.wallet`
         transfer_funds(char, None, item['value'])
         ware = spawn(item).pop()
         ware.move_to(char, quiet=True)
         ware.at_get(char)
         rtext = "You pay {} and purchase {}".format(
             as_price(ware.db.value), ware.key)
     except InsufficientFunds:
         rtext = "You do not have enough money to buy {}.".format(
             item['key'])
     session.msg(rtext)
Example #10
0
 def purchase_item(s):
     """Process item purchase."""
     try:
         # this will raise exception if caller doesn't
         # have enough funds in their `db.wallet`
         transfer_funds(char, None, item['value'])
         ware = spawn(item).pop()
         ware.move_to(char, quiet=True)
         ware.at_get(char)
         rtext = "You pay {} and purchase {}".format(
                     as_price(ware.db.value),
                     ware.key
                  )
     except InsufficientFunds:
         rtext = "You do not have enough money to buy {}.".format(
                     item['key'])
     s.msg(rtext)
Example #11
0
    def func(self):

        if self.caller.db.blacksmith:
            pass
        elif self.caller.db.bowyer:
            pass
        elif self.caller.db.artificer:
            pass
        elif self.caller.db.gunsmith:
            pass
        else:
            self.msg(
                f"|400You don't have the proper skills to create a {self.item}.|n"
            )
            return

        use_err_msg = "|430Usage: craft <item>|n"

        if not self.item:
            self.msg(use_err_msg)
            return

        # Search for designated prototypes
        try:
            prototype = prototypes.search_prototype(self.item,
                                                    require_single=True)
        except KeyError:
            self.msg(
                "|430Item not found, or more than one match. Please try again.|n"
            )
        else:
            # Get search response
            prototype_data = prototype[0]

            # Get item attributes and who makes it.
            item_data = prototype_data['attrs']
            craft_source = item_data[0][1]

            # Check for correct kit in caller kit slot.
            kit = self.caller.db.kit_slot[0] if self.caller.db.kit_slot else []
            kit_type = kit.db.type if kit else []
            kit_uses = kit.db.uses if kit else 0

            if not kit:
                self.msg(
                    f"|430Please equip the kit needed to craft a {self.item}.")
                return

            if kit_uses <= 0 and (craft_source == kit_type):
                self.msg(f"|400Your {kit} is out of uses.|n")
                return

            # Passed checks. Make item.
            # Check for items in callers inventory.
            if craft_source == kit_type:
                character_resources = {
                    "iron_ingots": self.caller.db.iron_ingots,
                    "cloth": self.caller.db.cloth,
                    "refined_wood": self.caller.db.refined_wood,
                    "leather": self.caller.db.leather
                }

                # Get item requirements
                item_requirements = {
                    "iron_ingots": item_data[2][1],
                    "refined_wood": item_data[3][1],
                    "leather": item_data[4][1],
                    "cloth": item_data[5][1]
                }

                requirements_checker = [
                    character_resources["iron_ingots"] >=
                    item_requirements["iron_ingots"],
                    character_resources["refined_wood"] >=
                    item_requirements["refined_wood"],
                    character_resources["leather"] >=
                    item_requirements["leather"],
                    character_resources["cloth"] >= item_requirements["cloth"]
                ]

                # Check that all conditions in above list are true.

                if all(requirements_checker) or self.caller.is_superuser:
                    self.msg(f"You craft a {self.item}")
                    # Get required resources and decrement from player totals.
                    self.caller.db.iron_ingots -= item_requirements[
                        "iron_ingots"]
                    self.caller.db.refined_wood -= item_requirements[
                        "refined_wood"]
                    self.caller.db.leather -= item_requirements["leather"]
                    self.caller.db.cloth -= item_requirements["cloth"]
                    #
                    item = spawn(prototype[0])
                    item[0].move_to(self.caller, quiet=True)

                    # Decrement the kit of one use.
                    # kit.db.uses -= 1

                else:
                    self.msg(f"|400You don't have the required resources.|n")
            else:
                self.msg(
                    f"|430Please equip the correct kit before attempting to craft your item.|n"
                )
                return
Example #12
0
    def func(self):
        use_err_msg = "|540Usage: forge <item>|n"

        # Do all checks
        if not self.caller.db.blacksmith:
            self.msg(
                "|400You are not trained in how to properly utilze a forge. Please find a blacksmith.|n"
            )
            return

        if not self.item:
            self.msg(use_err_msg)
            return

        # Search for designated prototypes
        try:
            prototype = prototypes.search_prototype(self.item,
                                                    require_single=True)
        except KeyError:
            self.msg(
                "Item not found, or more than one match. Please try again.")
        else:
            # Get search response
            prototype_data = prototype[0]

            # Check for items in callers inventory.
            character_resources = {
                "iron_ingots": self.caller.db.iron_ingots,
                "cloth": self.caller.db.cloth,
                "refined_wood": self.caller.db.refined_wood,
                "leather": self.caller.db.leather
            }

            # Get item requirements
            item_data = prototype_data['attrs']
            item_requirements = {
                "iron_ingots": item_data[1][1],
                "refined_wood": item_data[2][1],
                "leather": item_data[3][1],
                "cloth": item_data[4][1]
            }

            requirements_checker = [
                character_resources["iron_ingots"] >=
                item_requirements["iron_ingots"],
                character_resources["refined_wood"] >=
                item_requirements["refined_wood"],
                character_resources["leather"] >= item_requirements["leather"],
                character_resources["cloth"] >= item_requirements["cloth"]
            ]

            # Check that all conditions in above list are true.

            if all(requirements_checker) or self.caller.is_superuser:
                self.msg(f"You forge a {self.item}")
                # Get required resources and decrement from player totals.
                self.caller.db.iron_ingots -= item_requirements["iron_ingots"]
                self.caller.db.refined_wood -= item_requirements[
                    "refined_wood"]
                self.caller.db.leather -= item_requirements["leather"]
                self.caller.db.cloth -= item_requirements["cloth"]

                blacksmith_item = spawn(prototype[0])
                blacksmith_item[0].move_to(self.caller, quiet=True)

            else:
                self.msg(f"|400You don't have the required resources.|n")