def load_chest(chest, from_save, gap_x, gap_y): # Static data x = int(chest.find('position/x').text) * TILE_SIZE + gap_x y = int(chest.find('position/y').text) * TILE_SIZE + gap_y pos = (x, y) sprite_closed = chest.find('closed/sprite').text.strip() sprite_opened = chest.find('opened/sprite').text.strip() # Dynamic data potential_items = [] if from_save: opened = chest.find('state').text.strip() == "True" it_name = chest.find('contains/item').text.strip() it = parse_item_file(it_name) potential_items.append((it, 1.0)) else: for item in chest.xpath("contains/item"): it_name = item.find('name').text.strip() it = parse_item_file(it_name) probability = float(item.find('probability').text) potential_items.append((it, probability)) opened = False loaded_chest = Chest(pos, sprite_closed, sprite_opened, potential_items) if opened: loaded_chest.open() return loaded_chest
def __init__(self): self.driver = load_driver() self.login() self.Outland = Outland(self.driver) self.Chest = Chest(self.driver) self.Gifts = Gifts(self.driver) self.AirShip = AirShip(self.driver) self.Tower = Tower(self.driver) self.run()
def test_init_chest(self): pos = (0, 0) sprite_close = 'imgs/dungeon_crawl/dungeon/chest_2_closed.png' sprite_open = 'imgs/dungeon_crawl/dungeon/chest_2_open.png' item = Item("TestItem", 'imgs/dungeon_crawl/item/potion/yellow_new.png', "This is a desc", 50) potential_items = [(item, 1.0)] chest = Chest(pos, sprite_close, sprite_open, potential_items) self.assertEqual(pos, chest.pos) self.assertEqual(sprite_close, chest.sprite_close_link) self.assertEqual(sprite_open, chest.sprite_open_link) self.assertEqual(chest.item, item) self.assertFalse(chest.opened) self.assertFalse(chest.pick_lock_initiated) # Chest's current sprite should be the closed one self.assertNotEqual(chest.sprite_open, chest.sprite)
def random_chest(item_set=None, nb_items=None, equal_probs=False, gold_proportion=0.3): pos = random_pos() sprite_close = 'imgs/dungeon_crawl/dungeon/chest_2_closed.png' sprite_open = 'imgs/dungeon_crawl/dungeon/chest_2_open.png' if item_set: potential_items = item_set else: potential_items = [] if not nb_items: nb_items = rd.randint(1, 10) for i in range(nb_items): item = random_item_or_gold(gold_proportion) if not equal_probs: prob = rd.random() else: prob = 1 / nb_items potential_items.append((item, prob)) return Chest(pos, sprite_close, sprite_open, potential_items)