def exec_purchase_equipment(caller, caller_input): if caller.db.xp >= caller_input.get("cost"): caller.db.xp = caller.db.xp - caller_input.get("cost") caller_input["location"] = caller.dbref spawner.spawn(caller_input) else: caller.msg("|rERROR:|n You cannot afford that piece of equipment.")
def test_spawn(self): obj1 = spawner.spawn(self.prot1) # check spawned objects have the right tag self.assertEqual( list(protlib.search_objects_with_prototype("testprototype")), obj1) self.assertEqual([ o.key for o in spawner.spawn(_PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"], prototype_parents=_PROTPARENTS) ], ['goblin grunt', 'goblin archwizard'])
def test_spawn_from_str(self): protlib.save_prototype(self.prot1) obj1 = spawner.spawn(self.prot1['prototype_key']) self.assertEqual( list(protlib.search_objects_with_prototype("testprototype")), obj1) self.assertEqual([ o.key for o in spawner.spawn(_PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"], prototype_parents=_PROTPARENTS) ], ['goblin grunt', 'goblin archwizard'])
def basetype_posthook_setup(self): # overriding this so we can do some post-init # after spawning, as BaseObject.at_first_save() applies _create_dict field values # *after* calling at_object_creation() super().basetype_posthook_setup() for key in self.db.for_sale_keys: spawn(key)[0].location = self
def assign_room(self): """ Spawn a new home room for this character. Set locks: set "owner" to edit/control lock, set owner's home there, (self.home = there) set owner's home room there. (self.db.objects['home'] = there) Move owner there? """ # Spawn a new room with locks: home_room_name = self.name + "'s place" home_room_desc = settings.HOME_ROOM_DESC home_room_locks = 'control:id({0}) or perm(wizard);edit:id({0}) ' \ 'or perm(helpstaff)'.format(self.id) home_room_tags = [('private', 'flags', True)] home_room = { 'typeclass': 'typeclasses.rooms.Room', 'key': home_room_name, 'desc': home_room_desc, 'locks': home_room_locks, 'tags': home_room_tags } # from evennia.utils.spawner import spawn # Import the spawn utility just before using it. from evennia.prototypes.spawner import spawn room = spawn( home_room) # Calling spawn utility to create the home room. return room[0] # Return the first (and only) object created, the room.
def generate_equipment(self): ''' Head - Crown/Helmet/Hat Neck - Necklace/Amulet Shoulders - Shoulder Pads Chest - Chest Armor Arms - Sleeves Hands - Pair of Gloves Fingers - Up to 4 Rings Waist - Belt/Sash Thighs - Greaves Calves - Greaves Feet - Boots/Shoes/Sandals Bag - Satchel/Backpack/Sack/Bag - Determines maximum inventory slots. Weapons - Any weapon can be wielded from the inventory or the ground Equipped weapons are used automatically if no other is wielded. Shields and other offhands can also be equipped. Equipped weapons have 1 slot per type of 2H and 1 slot per offhand type. 2 slots for 1H weapons for dual wielding. ''' owner = self.owner if owner.attributes.has('equipment'): if owner.db.equipment['inventory_container'] == None: basic_bag = spawn('inventory_bag') if basic_bag: basic_bag = basic_bag[0] basic_bag.move_to(owner) owner.db.equipment['inventory_container'] = basic_bag owner.db.inventory_slots[ 'max_slots'] = basic_bag.db.max_slots
def func(self): caller = self.caller if self.args is None or not utils.dbref(self.args): caller.msg("A puzzle recipe's #dbref must be specified") return puzzle = search.search_script(self.args) if not puzzle or not inherits_from(puzzle[0], PuzzleRecipe): caller.msg("Invalid puzzle %r" % (self.args)) return puzzle = puzzle[0] caller.msg("Puzzle Recipe %s(%s) '%s' found.\nSpawning %d parts ..." % (puzzle.name, puzzle.dbref, puzzle.db.puzzle_name, len(puzzle.db.parts))) for proto_part in puzzle.db.parts: part = spawn(proto_part)[0] caller.msg( "Part %s(%s) spawned and placed at %s(%s)" % (part.name, part.dbref, part.location, part.location.dbref)) part.tags.add(puzzle.db.puzzle_name, category=_PUZZLES_TAG_CATEGORY) part.db.puzzle_name = puzzle.db.puzzle_name caller.msg("Puzzle armed |gsuccessfully|n.")
def mob_death(mob, killer=None): if killer: killer.msg(f"You killed {mob.key}!") xp = calculate_kill_xp(killer.db.xp, mob.db.xp) gain_xp(killer, xp) if mob.db.drop_gold: gold = create_object("typeclasses.objects.Gold", key="gold") gold.add(mob.db.drop_gold) # use move_to() so we invoke StackableObject accumulation gold.move_to(mob.location, quiet=True) mob.location.msg_contents(f"{mob.key} drops {mob.db.drop_gold} gold.") if mob.db.drop_object_id: tags = ["object", f"record_id_{mob.db.drop_object_id}"] prototypes = protlib.search_prototype(tags=tags) if prototypes: obj = spawner.spawn(prototypes[0]["prototype_key"])[0] obj.location = mob.location mob.location.msg_contents(f"{mob.key} drops {obj.name}.") mob.location.msg_contents( f"{mob.key} disappears in a cloud of greasy black smoke.", exclude=[mob]) mob.location = None mob.delete()
def setUp(self): settings.PROTOTYPE_MODULES = ainneve_settings.PROTOTYPE_MODULES self.character_typeclass = Character self.object_typeclass = NPC self.room_typeclass = Room self.script_typeclass = CombatHandler super(AinneveCombatTest, self).setUp() # create weapons for the fight self.melee = spawn({'prototype': 'SHORT_SWORD', 'location': self.room1}, prototype_modules=('world.content.prototypes_weapons',))[0] self.reach = spawn({'prototype': 'PIKE_POLEARM', 'location': self.room1}, prototype_modules=('world.content.prototypes_weapons',))[0] self.ranged = spawn({'prototype': 'LONG_BOW', 'location': self.room1}, prototype_modules=('world.content.prototypes_weapons',))[0] self.arrows = spawn({'prototype': 'ARROW_BUNDLE', 'location': self.room1}, prototype_modules=('world.content.prototypes_weapons',))[0] # set up chars sample_char(self.char1, 'warrior', 'human', 'cunning') self.char1.traits.ATKM.base = self.char1.traits.ATKR.base = self.char1.traits.ATKU.base = 5 sample_char(self.char2, 'warrior', 'human', 'cunning') self.char2.traits.HP.base = self.char2.traits.HP.current = 10 # one additional NPC self.obj3 = create.create_object(self.object_typeclass, key="Obj3", location=self.room1, home=self.room1) # set sdescs to key for testing self.char1.sdesc.add(self.char1.key) self.char2.sdesc.add(self.char2.key) self.obj1.sdesc.add(self.obj1.key) self.obj2.sdesc.add(self.obj2.key) self.obj3.sdesc.add(self.obj3.key) # use mock msg methods self.char1.msg = Mock() self.char2.msg = Mock() self.obj1.msg = Mock() self.obj2.msg = Mock() self.obj3.msg = Mock() # add combatants self.script.add_character(self.char1) self.script.add_character(self.char2) self.script.add_character(self.obj1) self.script.add_character(self.obj2) self.script.add_character(self.obj3)
def generate_mob(location, level): tags = [f"min_level_{x}" for x in range(level + 1)] mob_prototypes = protlib.search_prototype(tags=tags) if not mob_prototypes: # no valid prototypes found return proto_choice = random.choice(mob_prototypes) mob = spawner.spawn(proto_choice['prototype_key'])[0] mob.location = location location.msg_contents(f"A {mob.key} appears!")
def produce_weapon(self, caller): """ This will produce a new weapon from the rack, assuming the caller hasn't already gotten one. When doing so, the caller will get Tagged with the id of this rack, to make sure they cannot keep pulling weapons from it indefinitely. """ rack_id = self.db.rack_id if caller.tags.get(rack_id, category="tutorial_world"): caller.msg(self.db.no_more_weapons_msg) else: prototype = random.choice(self.db.available_weapons) # use the spawner to create a new Weapon from the # spawner dictionary, tag the caller wpn = spawn(WEAPON_PROTOTYPES[prototype], prototype_parents=WEAPON_PROTOTYPES)[0] caller.tags.add(rack_id, category="tutorial_world") wpn.location = caller caller.msg(self.db.get_weapon_msg % wpn.key)
def maybe_spawn_mob_in_lair(location): if not location.is_special_kind(SpecialRoomKind.MONSTER_LAIR): # not a lair return if has_players_or_mobs(location): # only spawn a new mob in a room devoid of players or mobs return mob_id = location.magnitude(SpecialRoomKind.MONSTER_LAIR) record_id_tag = f"record_id_{mob_id}" mob_prototypes = protlib.search_prototype(tags=[record_id_tag]) if not mob_prototypes: return proto_choice = mob_prototypes[0] mob = spawner.spawn(proto_choice['prototype_key'])[0] # stay in the lair mob.location = location mob.db.moves_between_rooms = False
def inner_func(self): if not self.args: self.caller.msg("Make what?") return prototypes = protlib.search_prototype(key=self.args.strip()) if not prototypes: self.caller.msg("No such object.") return prototype = prototypes[0] components = find_attr_value(prototype, "components") if not components: self.caller.msg("You can't make that.") return if not has_components(self.caller, components): self.caller.msg("You don't have all the components.") return consume_components(self.caller, components) obj = spawner.spawn(prototype['prototype_key'])[0] obj.location = self.caller self.caller.msg(f"You created {prototype['key']}.")
def func(self): newItem = Item() item_proto = newItem.generateItem() if not self.args: self.caller.msg("What do you want to activate?") return obj = self.caller.search(self.args.strip()) if not obj: return if obj != self.obj: self.caller.msg("It doesn't seem to be functioning.") return # incinerator = search_object("incinerator") #not working real_item = spawn(item_proto) # self.caller.msg(real_item) real_item[0].location = self.caller.location # incinerator.db.itemcounter += 1 #not working self.caller.msg( "The object womb heats up tremendously and then excretes one " + real_item[0].name)
def sell_item(self, buyer, item, quantity=1): owner = self.owner if owner.attributes.has('stock'): stocked_items = owner.attributes.get('stock') if item not in stocked_items.keys(): msg = f"{owner.name} is not selling {item}!" elif stocked_items[item] <= 0: msg = f"{item} is out of stock!" elif stocked_items[item] < quantity: msg = f"{owner.name} does haven't {quantity} of {item} in stock!" else: # get the price of the item item_dic = gen_mec.return_proto_dic(item) price = item_dic['price'] # multiply it by the quantity total_price = price * quantity # Check if the player has enough money coin_shortage = f"You do not possess {total_price}c to make that purchase!" if buyer.attributes.has('coin'): buyer_coin = buyer.attributes.get('coin') buyer_copper = buyer_coin.get('copper', 0) if buyer_copper < total_price: return coin_shortage else: buyer_coin['copper'] -= total_price else: return coin_shortage stocked_items[item] -= quantity msg = f"You buy {quantity} of {item} for a total of {total_price}. {owner.name} places them in the room." for _ in range(quantity): spawned_item = spawn(item)[0] spawned_item.move_to(owner.location, quiet=True) return msg
def chop(self, amount): """ Chop a tree by a specified amount of 'hp'. If hp drops at or below 0, spawn appropriate stack of logs and delete the tree. Return True if tree is completed destroyed, False if otherwise. """ self.db.hp -= amount if self.db.hp <= 0: # spawn logs self.location.msg_contents( "{0} makes a loud cracking sound and falls to the ground.". format(self.name)) drop = spawn(COMPONENT_PROTOTYPES[self.db.component_drop], prototype_parents=COMPONENT_PROTOTYPES)[0] drop.stack.count = self.db.component_dropamt drop.move_to(self.location, quiet=True) self.delete() return True else: return False
def func(self): caller = self.caller if not self.lhs: caller.msg("Use what?") return many = "these" if len(self.lhslist) > 1 else "this" # either all are parts, or abort finding matching puzzles parts = [] partnames = self.lhslist[:] for partname in partnames: part = caller.search( partname, multimatch_string="Which %s. There are many.\n" % (partname), nofound_string="There is no %s around." % (partname), ) if not part: return if not part.tags.get(_PUZZLES_TAG_MEMBER, category=_PUZZLES_TAG_CATEGORY): # not a puzzle part ... abort caller.msg("You have no idea how %s can be used" % (many)) return # a valid part parts.append(part) # Create lookup dicts by part's dbref and by puzzle_name(tags) parts_dict, puzzlename_tags_dict, puzzle_ingredients = _lookups_parts_puzzlenames_protodefs( parts) # Find all puzzles by puzzle name (i.e. tag name) puzzles = _puzzles_by_names(puzzlename_tags_dict.keys()) logger.log_info("PUZZLES %r" % ([(p.dbref, p.db.puzzle_name) for p in puzzles])) # Create lookup dict of puzzles by dbref puzzles_dict = dict((puzzle.dbref, puzzle) for puzzle in puzzles) # Check if parts can be combined to solve a puzzle matched_puzzles = _matching_puzzles(puzzles, puzzlename_tags_dict, puzzle_ingredients) if len(matched_puzzles) == 0: # TODO: we could use part.fail_message instead, if there was one # random part falls and lands on your feet # random part hits you square on the face caller.msg(_PUZZLE_DEFAULT_FAIL_USE_MESSAGE % (many)) return puzzletuples = sorted(matched_puzzles.items(), key=lambda t: len(t[1]), reverse=True) logger.log_info("MATCHED PUZZLES %r" % (puzzletuples)) # sort all matched puzzles and pick largest one(s) puzzledbref, matched_dbrefparts = puzzletuples[0] nparts = len(matched_dbrefparts) puzzle = puzzles_dict[puzzledbref] largest_puzzles = list( itertools.takewhile(lambda t: len(t[1]) == nparts, puzzletuples)) # if there are more than one, choose one at random. # we could show the names of all those that can be resolved # but that would give away that there are other puzzles that # can be resolved with the same parts. # just hint how many. if len(largest_puzzles) > 1: caller.msg( "Your gears start turning and %d different ideas come to your mind ...\n" % (len(largest_puzzles))) puzzletuple = choice(largest_puzzles) puzzle = puzzles_dict[puzzletuple[0]] caller.msg("You try %s ..." % (puzzle.db.puzzle_name)) # got one, spawn its results result_names = [] for proto_result in puzzle.db.results: result = spawn(proto_result)[0] result.tags.add(puzzle.db.puzzle_name, category=_PUZZLES_TAG_CATEGORY) result.db.puzzle_name = puzzle.db.puzzle_name result_names.append(result.name) # Destroy all parts used for dbref in matched_dbrefparts: parts_dict[dbref].delete() result_names = ", ".join(result_names) caller.msg(puzzle.db.use_success_message) caller.location.msg_contents( puzzle.db.use_success_location_message.format( caller=caller, result_names=result_names), exclude=(caller, ), )
def spawn_loot(self, cardstring): carddata = helper.get_card_data(cardstring) if loot := carddata.get("Loot"): loot['location'] = self spawner.spawn(loot)
def expand(self): """Expands a bundle into its component items.""" for i in list(range(self.db.quantity)): p = self.db.prototype_name spawn(dict(prototype=p, location=self.location)) self.delete()