def itemstash_search_test(): # Test ItemStash.search method hidden = [] # generate weapon 1 w1 = items.new_weapon() w1.desc['name'] = "Weapon 1" w1.desc['rarity'] = 0 # generate weapon 2 w2 = items.new_weapon() w2.desc['name'] = "Weapon 2" w2.desc['rarity'] = 0 # generate weapon 3 w3 = items.new_weapon() w3.desc['name'] = "Weapon 3" w3.desc['rarity'] = 100 # more than max find chance possible # test no items stash = map_.ItemStash([]) ok_(stash.search() == []) ok_(stash.hidden_items == []) # test one item with lowest rarity hidden = [w1] stash = map_.ItemStash(hidden) discovered = stash.search() ok_(w1 in discovered) ok_(stash.hidden_items == []) # test two items with lowest rarity hidden = [w1, w2] stash = map_.ItemStash(hidden) discovered = stash.search() ok_(w1 in discovered and w2 in discovered) ok_(stash.hidden_items == []) # test two items, one is not discoverable hidden = [w1, w3] stash = map_.ItemStash(hidden) discovered = stash.search() ok_(w1 in discovered and w3 not in discovered) ok_(stash.hidden_items == [w3])
def add_item_stash(scene): """ Add an item stash to a scene.""" # Create pool of items to choose from # 1. Take 2 weapons, put in pool pool = [] for i in range(2): pool.append(items.new_weapon()) # 2. Take 1 armor, put in pool for i in range(1): pool.append(items.new_armor()) # 3. Randomly pick 1-2 items from pool shuffle(pool) final = [] for i in range(randint(1, 2)): final.append(pool.pop()) # Create item stash and add to scene stash = map_.ItemStash(final) scene.features.append(stash)
def new_weapon_test(): # Tests if new weapons are created properly. weapon = items.new_weapon() ok_(weapon is not None)