def place_entities(self, room: Rect, entities, item_components): # Get a random number of monsters max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x: int = randint(room.x1 + 1, room.x2 - 1) y: int = randint(room.y1 + 1, room.y2 - 1) pos_comp = Position(x, y) if not any([ entity for entity in entities if entity.pos.x == x and entity.pos.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity('o', tcod.desaturated_green, 'Orc', blocks=True, position=pos_comp, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity('T', tcod.darker_green, 'Troll', blocks=True, position=pos_comp, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) pos_comp = Position(x, y) if not any([ entity for entity in entities if entity.pos.x == x and entity.pos.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = item_components['HealingPotion'](1) item = Entity('!', tcod.violet, 'Healing Potion', position=pos_comp, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity('/', tcod.sky, 'Sword', position=pos_comp, equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity('[', tcod.darker_orange, 'Shield', position=pos_comp, equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = item_components['FireballScroll'](1) item = Entity('#', tcod.red, 'Fireball Scroll', position=pos_comp, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = item_components['ConfuseScroll'](1) item = Entity('#', tcod.light_pink, 'Confusion Scroll', position=pos_comp, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lightning_scroll': item_component = item_components['LightningScroll'](1) item = Entity('#', tcod.yellow, 'Lightning Scroll', position=pos_comp, render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'rat': from_dungeon_level([[80, 1], [40, 3], [15, 5]], self.dungeon_level), 'goblin': from_dungeon_level([[15, 1], [40, 3], [15, 5]], self.dungeon_level), 'orc': from_dungeon_level([[20, 2], [30, 4], [60, 6]], self.dungeon_level), 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'torch': 10, 'healing_potion': 35, 'dagger': from_dungeon_level([[7, 1]], self.dungeon_level), 'buckler': from_dungeon_level([[7, 2]], self.dungeon_level), 'sword': from_dungeon_level([[35, 4]], self.dungeon_level), 'shield': from_dungeon_level([[35, 8]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'rat': level_component = Level(current_level=1, current_xp=0, level_up_base=100, level_up_factor=100) fighter_component = Fighter(hp=5, defense=0, power=1, body=monster_choice, xp=10, will_power=0) ai_component = BasicMonster() monster = Entity(x, y, 'r', libtcod.dark_amber, 'Rat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'goblin': level_component = Level(current_level=1, current_xp=0, level_up_base=40, level_up_factor=150) fighter_component = Fighter(hp=10, defense=0, power=2, body=monster_choice, fov=7, xp=20, level=level_component, will_power=1) ai_component = BasicMonster() monster = Entity(x, y, 'g', libtcod.dark_green, 'Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component, inventory=Inventory(2), equipment=Equipment()) elif monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, body=monster_choice, fov=4, xp=35, will_power=2) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.darker_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component, inventory=Inventory(10), equipment=Equipment()) else: fighter_component = Fighter(hp=30, defense=2, power=8, body=monster_choice, xp=100, will_power=3) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darkest_green, 'Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component, inventory=Inventory(15), equipment=Equipment()) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'torch': equippable_component = Equippable(EquipmentSlots.OFF_HAND, fov_bonus=5) item = Entity(x, y, 't', libtcod.yellow, 'Torch', equippable=equippable_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', libtcod.sky, 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=2) item = Entity(x, y, '[', libtcod.darker_orange, 'Shield', equippable=equippable_component) elif item_choice == 'dagger': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.red, 'Small Dagger', equippable=equippable_component) elif item_choice == 'buckler': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', libtcod.red, 'Rotten Buckler', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def from_json(json_data): x = json_data.get('x') y = json_data.get('y') char = json_data.get('char') color_o = json_data.get('color') color = libtcod.Color(color_o[0], color_o[1], color_o[2]) name = json_data.get('name') blocks = json_data.get('blocks', False) render_order = RenderOrder(json_data.get('render_order')) fighter_json = json_data.get('fighter') ai_json = json_data.get('ai') item_json = json_data.get('item') inventory_json = json_data.get('inventory') stairs_json = json_data.get('stairs') level_json = json_data.get('level') equipment_json = json_data.get('equipment') equippable_json = json_data.get('equippable') uID_data = json_data.get('uID') quickuse_json = json_data.get('quick_use') entity = Entity(x, y, char, color, name, blocks, render_order, uID=uID_data) if fighter_json: entity.fighter = Fighter.from_json(fighter_json) entity.fighter.owner = entity if ai_json: name = ai_json.get('name') if name == BasicMonster.__name__: ai = BasicMonster.from_json() elif name == ConfusedMonster.__name__: ai = ConfusedMonster.from_json(ai_json, entity) else: ai = None if ai: entity.ai = ai entity.ai.owner = entity if item_json: entity.item = Item.from_json(item_json) entity.item.owner = entity if inventory_json: entity.inventory = Inventory.from_json(inventory_json) entity.inventory.owner = entity if stairs_json: entity.stairs = Stairs.from_json(stairs_json) entity.stairs.owner = entity if level_json: entity.level = Level.from_json(level_json) entity.level.owner = entity if equipment_json: entity.equipment = Equipment.from_json(equipment_json) entity.equipment.owner = entity if equippable_json: entity.equippable = Equippable.from_json(equippable_json) entity.equippable.owner = entity if quickuse_json: entity.quick_use = Quickuse.from_json(quickuse_json) entity.quick_use.owner = entity return entity
def equipable_factory(equipable_name: dict): if 'MAIN_HAND' == equipable_name['slot']: slot = EquipmentSlots.MAIN_HAND if 'OFF_HAND' == equipable_name['slot']: slot = EquipmentSlots.OFF_HAND equipable_name.pop('slot') return Equippable(slot, **equipable_name)
def place_entities_at_nook(self, entities, min_monsters, max_monsters, max_items): # 벽 지도 생성 wall_map = np.zeros((self.height, self.width), dtype='uint8') for y in range(self.height): for x in range(self.width): wall_map[y, x] = 1 if self.tiles[y, x].blocked else 0 # 구석 개수 설정 nooks = find_nook(wall_map) monster_num = randint(min_monsters, max_monsters) # 몬스터 배치 monster_chance = {'CI': 80, 'GS': 20, "FA": 10} for j in range(monster_num): ai_comp = BasicAi() choice = random_choice_from_dict(monster_chance) if j < len(nooks): mx = nooks[j][1] my = nooks[j][0] else: # 구석진 곳이 모자르면 지도에서 무작위로 좌표를 뽑아옴 my, mx = self.np_find_empty_cell(entities, wall_map) if choice == 'CI': f_comp = Fighter(hp=10, defense=0, power=3) monster = self.create_monster(mx, my, '~', tcod.flame, '기어다니는 내장', f_comp, ai_comp) elif choice == 'GS': f_comp = Fighter(hp=16, defense=1, power=4) monster = self.create_monster(mx, my, 'S', tcod.dark_green, '거대 거미', f_comp, ai_comp) elif choice == 'FA': f_comp = Fighter(hp=20, defense=0, power=7) monster = self.create_monster(mx, my, '@', tcod.Color(128, 5, 5), '사람을 닮은 무언가', f_comp, ai_comp) entities.append(monster) self.monsters += 1 #계산용 # 아이템 배치, 아직 임시 shuffle(nooks) #item_chance = {'FB':5} item_chance = { 'FJ': 60, 'REG': 30, 'FB': 10, "SC": 10, 'FLW': 10, 'SCF': 5, 'SWD': 5, 'SLD': 5, 'AM': 1 } #'BK': 20 # # for i in range(len(nooks)): kinds = random_choice_from_dict(item_chance) if j < len(nooks): ix = nooks[i][1] iy = nooks[i][0] else: # 구석진 곳이 모자르면 지도에서 무작위로 좌표를 뽑아옴 ix, iy = self.np_find_empty_cell(entities, wall_map) if kinds == 'REG': i_comp = Item(use_function=heal, amount=10) item = self.create_item(ix, iy, '!', tcod.violet, '재생 물약', item=i_comp) elif kinds == 'FJ': i_comp = Item(use_function=heal, amount=15, which='sanity') item = self.create_item(ix, iy, '!', tcod.orange, '과일 주스', item=i_comp) elif kinds == 'SC': i_comp = Item(use_function=cast_spell, damage=(1, 30), maximum_range=8) item = self.create_item(ix, iy, '?', tcod.green, '마법 불꽃의 주문서', item=i_comp) elif kinds == 'FB': i_comp = Item(use_function=cast_fireball, targeting=True, targeting_message=Message( SYS_LOG['target_message'], tcod.light_cyan), damage=(3, 8, 5), radius=3) item = self.create_item(ix, iy, '?', tcod.red, '화염 폭발의 주문서', item=i_comp) elif kinds == 'SCF': scarfs_list = { '보라': tcod.violet, '빨강': tcod.dark_red, '초록': tcod.green, '파랑': tcod.blue } from random import sample pick = sample(list(scarfs_list), 1)[0] if pick == '초록': resist = 60 else: resist = 50 e_comp = Equippable(EquipmentSlots.SCARF, sanity_resistance=resist) item = Entity(ix, iy, '>', scarfs_list[pick], f"{pick}색 목도리", _Equippable=e_comp) elif kinds == 'SWD': e_comp = Equippable(EquipmentSlots.WIELD, attack_power=5) item = Entity(ix, iy, '/', tcod.gray, "검", _Equippable=e_comp) elif kinds == 'SLD': e_comp = Equippable(EquipmentSlots.OUTFIT, defense_power=5) item = Entity(ix, iy, '}', tcod.lighter_gray, "방패", _Equippable=e_comp) elif kinds == 'FLW': e_comp = Equippable(EquipmentSlots.JEWELLERY, sanity_resistance=20) item = Entity(ix, iy, '*', tcod.white, "국화꽃 팔찌", _Equippable=e_comp) elif kinds == "AM": e_comp = Equippable(EquipmentSlots.JEWELLERY, sanity_resistance=-80, attack_power=10) item = Entity(ix, iy, '&', tcod.white, "어딘가 잘못된 목걸이", _Equippable=e_comp) entities.append(item) """
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Get random # monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level), 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'breastplate': from_dungeon_level([[10, 6]], self.dungeon_level), 'pantaloons': from_dungeon_level([[8, 5]], self.dungeon_level), 'helmet': from_dungeon_level([[4, 3]], self.dungeon_level) } for i in range(number_of_monsters): # choose rand location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component: Fighter = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() inventory_component = Inventory(3) monster = Entity(x, y, 'o', tcod.desaturated_green, 'Orc', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR, inventory=inventory_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() inventory_component = Inventory(5) monster = Entity(x, y, 'T', tcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR, inventory=inventory_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', tcod.violet, 'Health Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=fireball, damage=25, radius=3, targeting=True, targeting_message=Message( 'Click a target tile to cast a Fireball\ , or right-click to cancel.', tcod.light_cyan)) item = Entity(x, y, '#', tcod.orange, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item(use_function=confusion, targeting=True, targeting_message=Message( 'Click an enemy to confuse them!\ Right-click/escape to cancel.', tcod.cyan)) item = Entity(x, y, '#', tcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lightning_scroll': item_component = Item(use_function=lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', tcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', tcod.sky, 'Greatsword', render_order=RenderOrder.ITEM, equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=3) item = Entity(x, y, '[', tcod.darker_orange, 'Kite Shield', render_order=RenderOrder.ITEM, equippable=equippable_component) elif item_choice == 'breastplate': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, hp_bonus=3) item = Entity(x, y, 'M', tcod.dark_azure, 'Plate Mail Armor', render_order=RenderOrder.ITEM, equippable=equippable_component) elif item_choice == 'helmet': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, defense_bonus=2) item = Entity(x, y, '0', tcod.dark_gray, 'Bucket Helmet', render_order=RenderOrder.ITEM, equippable=equippable_component) elif item_choice == 'pantaloons': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, hp_bonus=2, power_bonus=2) item = Entity(x, y, 'n', tcod.dark_gray, 'Harlequin Pantaloons', render_order=RenderOrder.ITEM, equippable=equippable_component) entities.append(item)
def monster_stats(self, x, y, sect=monster_all): selector = sect.ret_mon() # This should be moved to a class that indexes all "entities" and copies out the needed entity if selector == monster_all.KOBOLD: monster = Entity(x, y, 'k', libtcod.desaturated_green, 'Kobold', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=10, defense=0, power=1, xp=35), ai=BasicMonster(), inventory=Inventory(5)) if selector == monster_all.RAZORTOOTH: monster = Entity(x, y, 'k', libtcod.desaturated_green, 'Kolbold Razortooth', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=20, defense=0, power=2, xp=45), ai=BasicMonster(), inventory=Inventory(5)) if selector == monster_all.KHUNTER: monster = Entity(x, y, 'k', libtcod.desaturated_green, 'Kolbold Hunter', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=25, defense=1, power=3, xp=50), ai=BasicMonster(), inventory=Inventory(5)) if selector == monster_all.KGLASSMITH: monster = Entity(x, y, 'k', libtcod.desaturated_green, 'Kolbold Glasssmith', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=30, defense=1, power=2, xp=50), ai=BasicMonster(), inventory=Inventory(5)) monster.inventory.add_item( Entity(0, 0, '/', libtcod.sky, 'Handfull of glass shards', equippable=Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2))) elif selector == monster_all.GOBLIN: monster = Entity(x, y, 'g', libtcod.green, 'Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=15, defense=0, power=2, xp=40), ai=BasicMonster(), inventory=Inventory(5)) elif selector == monster_all.C_GOBLIN: monster = Entity(x, y, 'g', libtcod.green, 'Clanfear Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=15, defense=1, power=2, xp=45), ai=BasicMonster(), inventory=Inventory(5)) elif selector == monster_all.CB_GOBLIN: monster = Entity(x, y, 'g', libtcod.green, 'Clanfear Goblin Brawler', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=15, defense=2, power=3, xp=60), ai=BasicMonster(), inventory=Inventory(5)) monster.inventory.add_item( Entity(0, 0, '-', libtcod.sky, 'Rusty Dagger', equippable=Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.brown, 'Ratty Peasant Shirt', equippable=Equippable(EquipmentSlots.CHEST, defense_bonus=1))) elif selector == monster_all.CO_GOBLIN: monster = Entity(x, y, 'g', libtcod.green, 'Clanfear Goblin Organizer', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=25, defense=2, power=3, xp=80), ai=BasicMonster(), inventory=Inventory(5)) monster.inventory.add_item( Entity(0, 0, '-', libtcod.sky, 'Rusty Dagger', equippable=Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.brown, 'Ratty Peasant Shirt', equippable=Equippable(EquipmentSlots.CHEST, defense_bonus=1))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.brown, 'Ratty Cloth Toque', equippable=Equippable(EquipmentSlots.HELMET, max_hp_bonus=10))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.grey, 'Rusty Iron Ring', equippable=Equippable(EquipmentSlots.RING_R, max_blood_bonus=10))) elif selector == monster_all.CS_GOBLIN: monster = Entity(x, y, 'g', libtcod.light_green, 'Clanfear Goblin Shaman', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=45, defense=2, power=3, xp=100), ai=BasicShaman(), inventory=Inventory(5)) monster.inventory.add_item( Entity(0, 0, '-', libtcod.sky, 'Staff of Impovrished Lightning', item=Item(use_function=cast_lightning_chance, damage=20, maximum_range=6))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.brown, 'Ratty Peasant Shirt', equippable=Equippable(EquipmentSlots.CHEST, defense_bonus=1))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.brown, 'Ratty Cloth Toque', equippable=Equippable(EquipmentSlots.HELMET, max_hp_bonus=10))) monster.inventory.add_item( Entity(0, 0, '#', libtcod.grey, 'Rusty Iron Ring', equippable=Equippable(EquipmentSlots.RING_R, max_blood_bonus=10))) elif selector == monster_all.ORC: monster = Entity(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=25, defense=1, power=2, xp=45), ai=BasicMonster(), inventory=Inventory(5)) elif selector == monster_all.TROLL: monster = Entity(x, y, 'T', libtcod.green, 'Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=30, defense=2, power=6, xp=80), ai=BasicMonster(), inventory=Inventory(5))
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) """ダンジョンに敵を配置する機能""" # モンスターを何体部屋に配置するかランダムに決める number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { "orc": 80, "troll": from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { "healing_potion": 35, "stone_sword": from_dungeon_level([[5, 4]], self.dungeon_level), "wood_shield": from_dungeon_level([[15, 8]], self.dungeon_level), "lightning_scroll": from_dungeon_level([[25, 4]], self.dungeon_level), "fireball_scroll": from_dungeon_level([[25, 6]], self.dungeon_level), "confusion_scroll": from_dungeon_level([[10, 2]], self.dungeon_level) } for _ in range(number_of_monsters): # 部屋のどのあたりにmonsterを配置するかランダムに決める x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # ランダムな場所を選びそこにモンスターとかアイテムとかがなければ配置する if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == "orc": fighter_component = Fighter(hp=10, defense=0, power=3, xp=35) ai_component = BasicMonster() monster = Entity(x, y, "o", libtcod.desaturated_green, "Orc", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=26, defense=1, power=4, xp=100) ai_component = BasicMonster() monster = Entity(x, y, "T", libtcod.dark_green, "Troll", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) # entitiesに格納する entities.append(monster) for _ in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == "healing_potion": item_component = Item(use_function=heal, amount=40) item = Entity(x, y, "!", libtcod.violet, "Healing Potion", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "stone_sword": equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, "/", libtcod.sky, "Stone_Sword", equippable=equippable_component) elif item_choice == "wood_shield": equippable_component = Equippable(EquipmentSlots.OFF_HAMD, defense_bones=1) item = Entity(x, y, "[", libtcod.darker_orange, "Wood_Shield", equippable=equippable_component) elif item_choice == "fireball_scroll": item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "lift-click a target tile for the fireball, or right-click to cancel.", libtcod.light_cyan), damage=22, radius=3) item = Entity(x, y, "#", libtcod.red, "Fireball Scroll", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "confusion_scroll": item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( "Left-click an enemy to confuse it, or right-click to cansel.", libtcod.light_cyan)) item = Entity(x, y, "#", libtcod.light_pink, "Confusion Scroll", render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=30, maximum_range=5) item = Entity(x, y, "#", libtcod.yellow, "Lightning Scroll", render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities, graphics): """ Place les monstres et les objets dans la room en cours de construction, en veillant à ne pas superposer des entités, puis ajoute le tout à la liste des entités. Le nombre de monstres et d'ojbets dépend de l'étage du donjon Parametres: ---------- room : Rect entities : list graphics : dict Renvoi: ------- entities : list """ # monster_chances et item_chances définissent les entités à faire apparaître # avec leurs chances d'apparition et leurs poids respectifs monster_chances = [('orc', 80, 1), ('troll', 20, 3)] monsters_to_pop = monsters_per_room(self.dungeon_level, monster_chances, room) item_chances = [('healing_potion', 45, 1), ('confusion_scroll', 20, 2), ('lightning_scroll', 18, 4), ('fireball_scroll', 7, 5), ('sword', 5, 1), ('shield', 5, 1)] items_to_pop = items_per_room(self.dungeon_level, item_chances) for monster_choice in monsters_to_pop: x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, graphics.get(monster_choice), libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=30, defense=1, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, graphics.get(monster_choice), libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) entities.append(monster) for item_choice in items_to_pop: x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): if item_choice == 'healing_potion': item_component = Item(use_function=heal) item = Entity(x, y, graphics.get(item_choice), libtcod.white, 'Potion de soin', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, graphics.get(item_choice), libtcod.sky, 'Epee', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, graphics.get(item_choice), libtcod.darker_orange, 'Bouclier', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item(use_function=cast_fireball, targeting=True, targeting_message=Message( 'Clic gauche sur une case pour ' 'y envoyer une fireball', libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, graphics.get('fireball_scroll'), libtcod.dark_orange, 'Parchemin de boule de feu', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Clic gauche pour rendre un enemi ' 'confus', libtcod.light_cyan)) item = Entity(x, y, graphics.get('confusion_scroll'), libtcod.lighter_pink, 'Parchemin de confusion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lightning_scroll': item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, graphics.get('lightning_scroll'), libtcod.yellow, 'Parchemin de foudre', render_order=RenderOrder.ITEM, item=item_component) entities.append(item) return entities
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Tileset wall_tile = 256 floor_tile = 257 player_tile = 258 orc_tile = 259 troll_tile = 260 scroll_tile = 261 healingpotion_tile = 262 sword_tile = 263 shield_tile = 264 stairsdown_tile = 265 dagger_tile = 266 # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) # Get a random number of items number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, orc_tile, libtcod.desaturated_green, 'Orc', blocks=True, fighter=fighter_component, ai=ai_component) elif monster_choice == 'Archer': fighter_component = Fighter(hp=10, defense=0, power=3, xp=70) ai_component = RangedMonster() monster = Entity(x, y, 'A', libtcod.darker_green, 'Archer', blocks=True, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, troll_tile, libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, healingpotion_tile, libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, sword_tile, libtcod.sky, 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, shield_tile, libtcod.darker_orange, 'Shield', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item(use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, scroll_tile, libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item(use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, scroll_tile, libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'heal_scroll': item_component = Item(use_function=cast_heal, targeting=True, targeting_message=Message( 'Left-click a friend to heal it, or right-click to cancel.', libtcod.light_cyan), amount=10) item = Entity(x, y, scroll_tile, libtcod.blue, 'Healing Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'ice_bolt': item_component = Item(use_function=cast_freezeray, targeting=True, targeting_message=Message( 'Left-click an enemy to freeze it, or right-click to cancel.', libtcod.light_cyan), damage=2) item = Entity(x, y, scroll_tile, libtcod.dark_blue, 'Ice Bolt', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, scroll_tile, libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) #Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) #Get a random number of items to place number_of_items = randint(0, max_items_per_room) monster_choices = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_choices = { 'healing_potion': 35, 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'lighning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } #Place our random monsters for i in range(number_of_monsters): #Choose location in room x = randint(room.x + 1, room.x2 - 1) y = randint(room.y + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_choices) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_green, "Orc", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, "Troll", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x + 1, room.x2 - 1) y = randint(room.y + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item = None item_choice = random_choice_from_dict(item_choices) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, radius=3, damage=25, targeting=True, targeting_message=Message( "Left-Click a target tile for the fireball or right-click to cancel", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confusion, radius=3, damage=12, targeting=True, targeting_message=Message( "Left-Click an enemy to confuse it right-click to cancel", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lighning_scroll': item_component = Item(use_function=cast_lightning, maximum_range=5, damage=40) item = Entity(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', libtcod.sky, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, ']', libtcod.darker_orange, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): # Get a random number of monsters number_of_monsters = from_dungeon_level([[2,1], [3,4], [5,6], [7,8]], self.dungeon_level) number_of_items = from_dungeon_level([[1,1], [2,4], [3,6], [4,8]], self.dungeon_level) monster_chances = { 'bat': from_dungeon_level([[20,1], [10,2], [5,3], [0,4]], self.dungeon_level), 'demon': from_dungeon_level([[10,12], [10,15]], self.dungeon_level), 'ghost': from_dungeon_level([[10,9], [30,11], [15,13]], self.dungeon_level), 'goblin': from_dungeon_level([[10,3], [30,5], [15,8], [0,10]], self.dungeon_level), 'hound': from_dungeon_level([[13,20]], self.dungeon_level), 'infernal_skeleton': from_dungeon_level([[10,13]], self.dungeon_level), 'skeleton': from_dungeon_level([[5,6], [10,7], [30,8], [15,11], [0,13]], self.dungeon_level), 'slime': from_dungeon_level([[60,1], [30,5], [15,7], [0,9]], self.dungeon_level), 'witch': from_dungeon_level([[5,9], [10,11], [0,13]], self.dungeon_level) } item_chances = { 'arrow': from_dungeon_level([[20,2], [15,4], [10,7]], self.dungeon_level), 'confusion_rune': from_dungeon_level([[10,2]], self.dungeon_level), 'fireball_rune': from_dungeon_level([[15,8]], self.dungeon_level), 'freezing_rune': from_dungeon_level([[15,8]], self.dungeon_level), 'healing_potion': 35, 'lightning_rune': from_dungeon_level([[20,5]], self.dungeon_level), 'none': from_dungeon_level([[60,1], [65,4], [50,7], [45,10]], self.dungeon_level), 'buckler': from_dungeon_level([[5,4]], self.dungeon_level), 'round_shield': from_dungeon_level([[5,7]], self.dungeon_level), 'kite_shield': from_dungeon_level([[5,10]], self.dungeon_level), 'tower_shield': from_dungeon_level([[5,13]], self.dungeon_level), 'short_sword': from_dungeon_level([[5,5]], self.dungeon_level), 'scimitar': from_dungeon_level([[5,8]], self.dungeon_level), 'long_sword': from_dungeon_level([[5,11]], self.dungeon_level), 'claymore': from_dungeon_level([[5,14]], self.dungeon_level) } for i in range(number_of_monsters): #Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y ==y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'skeleton': level_bonus = from_dungeon_level([[0,6], [1,10]], self.dungeon_level) fighter_component = Fighter(hp=40 + 10 * level_bonus, defense=4, strength=10 + level_bonus, attack=10 + level_bonus, xp=200 + 25 * level_bonus) ai_component = BasicMonster() monster = Entity(x, y, 'S', tc.lightest_sepia, 'skeleton', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'slime': level_bonus = from_dungeon_level([[0,1], [1,4], [2,7]], self.dungeon_level) fighter_component = Fighter(hp = 20 + 10 * level_bonus, defense = 0 + level_bonus // 2, strength = 4 + level_bonus, attack = 4 + level_bonus, xp = 35 + 25 * level_bonus) ai_component = BasicMonster() monster = Entity(x, y, 's', tc.desaturated_green, 'slime', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'bat': fighter_component = Fighter(hp = 10, defense = 1, strength = 1, attack = 1, xp = 5) ai_component = ConfusedMonster() monster = Entity(x, y, 'b', tc.darker_azure, 'bat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'goblin': level_bonus = from_dungeon_level([[0,3], [1,7], [2,10]], self.dungeon_level) fighter_component = Fighter(hp = 30 + 10 * level_bonus, defense = 2 + level_bonus // 2, strength = 8 + level_bonus, attack = 8 + level_bonus, xp = 100 + 25 * level_bonus) ai_component = BasicMonster() monster = Entity(x, y, 'G', tc.darker_green, 'goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'ghost': level_bonus = from_dungeon_level([[0,9], [1,13]], self.dungeon_level) fighter_component = Fighter(hp = 20 + 10 * level_bonus, defense = 2, strength = 9 + level_bonus, attack = 9 + level_bonus, xp = 85 + 25 * level_bonus) ai_component = BasicMonster() monster = Entity(x, y, 'g', tc.lightest_grey, 'ghost', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'witch': fighter_component = Fighter(hp = 40, defense = 4, strength = 10, attack = 12, xp = 150 + 25) ai_component = BasicRangedMonster(attack_roll=3) monster = Entity(x, y, 'W', tc.darker_purple, 'witch', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'hound': fighter_component = Fighter(hp = 40, defense = 4, strength = 10, attack = 10, xp = 125) ai_component = BasicMonster() monster = Entity(x, y, 'h', tc.dark_sepia, 'hellhound', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'infernal_skeleton': fighter_component = Fighter(hp = 60, defense = 6, strength = 18, attack = 18, xp = 300) ai_component = BasicMonster() monster = Entity(x, y, 'S', tc.dark_amber, 'infernal skeleton', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp = 80, defense = 8, strength = 24, attack = 24, xp = 600) ai_component = BasicMonster() monster = Entity(x, y, 'D', tc.dark_crimson, 'demon', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', tc.celadon, 'Potion of Healing', render_order = RenderOrder.ITEM, item=item_component) elif item_choice == 'arrow': item_component = Item(use_function=cast_projectile, targeting=True, targeting_message=Message( 'Left-click a target to fire at, or right-click to cancel.', tc.light_cyan), damage=15) item = Entity(x, y, '^', tc.gray, 'Arrow', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'short_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, str_bonus=3, att_bonus=2) item = Entity(x, y, '/', tc.dark_orange, 'Short Sword', equippable=equippable_component) elif item_choice == 'scimitar': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, str_bonus=4, att_bonus=3) item = Entity(x, y, '/', tc.dark_yellow, 'Scimitar', equippable=equippable_component) elif item_choice == 'long_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, str_bonus=5, att_bonus=4) item = Entity(x, y, '/', tc.dark_sky, 'Long Sword', equippable=equippable_component) elif item_choice == 'claymore': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, str_bonus=6, att_bonus=5) item = Entity(x, y, '/', tc.gold, 'Claymore', equippable=equippable_component) elif item_choice == 'buckler': equippable_component = Equippable(EquipmentSlots.OFF_HAND, def_bonus=1) item = Entity(x, y, '[', tc.darker_orange, 'Buckler', equippable=equippable_component) elif item_choice == 'round_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, def_bonus=2) item = Entity(x, y, '[', tc.darker_yellow, 'Round Shield', equippable=equippable_component) elif item_choice == 'kite_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, def_bonus=3) item = Entity(x, y, '[', tc.darker_sky, 'Kite Shield', equippable=equippable_component) elif item_choice == 'tower_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, def_bonus=4) item = Entity(x, y, '[', tc.brass, 'Tower Shield', equippable=equippable_component) elif item_choice == 'fireball_rune': item_component = Item(game_map=self, use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-cick a target to fire at, or right-click to cancel.', tc.light_cyan), damage=25, radius=3) item = Entity(x, y, '<', tc.red, 'Rune of Fireball', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'freezing_rune': item_component = Item(use_function=cast_freezing, targeting=True, targeting_message=Message( 'Left-click an enemy to freeze it, or right-click to cancel.', tc.light_cyan)) item = Entity(x, y, '<', tc.cyan, 'Rune of Freezing', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_rune': item_component = Item(use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-cick an enemy to confuse it, or right-click to cancel.', tc.light_cyan)) item = Entity(x, y, '<', tc.light_pink, 'Rune of Confusion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lightning_rune': item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '<', tc.yellow, 'Rune of Lightning', render_order=RenderOrder.ITEM, item=item_component) else: continue entities.append(item)
def get_game_variables(constants, fighter_component, character, equip_component, wear_component): #fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, character, libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(equip_component['hand'], power_bonus=equip_component['power'], defense_bonus=equip_component['defense'], range=equip_component['range']) arm = Entity(0, 0, '-', libtcod.sky, equip_component['name'], equippable=equippable_component) player.inventory.add_item(arm) player.equipment.toggle_equip(arm) wearable_component = Wearable(wear_component['wearing'], power_bonus=wear_component['power'], defense_bonus=wear_component['defense'], max_hp_bonus=wear_component['hp']) wearing = Entity(0, 0, '-', libtcod.sky, wear_component['name'], wearable=wearable_component) player.inventory.add_item(wearing) player.equipment.toggle_wearing(wearing) player.fighter.heal(wear_component['hp']) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def place_entities(room, entities, dungeon_level, colors): #Get a random number of monsters max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], dungeon_level) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': from_dungeon_level([[10, 1], [90, 2]], dungeon_level), 'rat': from_dungeon_level([[60, 1]], dungeon_level), 'snake': from_dungeon_level([[50, 5], [60, 6], [70, 8]], dungeon_level), 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], dungeon_level), 'death_knight': from_dungeon_level([[10, 5], [50, 7], [80, 10]], dungeon_level) } item_chances = { 'healing_potion': 35, 'mega_potion': from_dungeon_level([[25, 5]], dungeon_level), 'hard_shell': from_dungeon_level([[10, 4]], dungeon_level), 'sword': from_dungeon_level([[5, 4]], dungeon_level), 'shield': from_dungeon_level([[15, 8]], dungeon_level), 'chest_armor': from_dungeon_level([[10, 9]], dungeon_level), 'shoulder_armor': from_dungeon_level([[10, 6]], dungeon_level), 'leg_armor': from_dungeon_level([[10, 5]], dungeon_level), 'ligtning_scroll': from_dungeon_level([[25, 4]], dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], dungeon_level), 'freeze_scroll': from_dungeon_level([[10, 2]], dungeon_level), 'mysterious_bottle': from_dungeon_level([[1, 1]], dungeon_level) } for i in range(number_of_monsters): #Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any( [entity for entity in entities if entity.x == x and entity.y == y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35, gold=2) ai_component = BasicMonster() monster = Entity(x, y, 'o', colors.get('desaturated_green'), 'Orc', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR) elif monster_choice == 'rat': fighter_component = Fighter(hp=10, defense=0, power=2, xp=10, gold=1) ai_component = BasicMonster() monster = Entity(x, y, '.', colors.get('black'), 'Rat', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR) elif monster_choice == 'death_knight': fighter_component = Fighter(hp=60, defense=4, power=13, xp=200, gold=10) ai_component = BasicMonster() monster = Entity(x, y, '@', colors.get('black'), 'Death Knight', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR) else: fighter_component = Fighter(hp=30, defense=2, power=8, xp=100, gold=5) ai_component = BasicMonster() monster = Entity(x, y, 'T', colors.get('darker_green'), 'Troll', blocks=True, fighter=fighter_component, ai=ai_component, render_order=RenderOrder.ACTOR) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any( [entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', colors.get('violet'), 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'mega_potion': item_component = Item(use_function=heal, amount=80) item = Entity(x, y, '!', colors.get('gold'), 'Mega Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'hard_shell': item_component = Item(use_function=hard_shell, amount=1) item = Entity(x, y, '!', colors.get('yellow'), 'Hard Shell Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '|', colors.get('sky'), 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', colors.get('darker_orange'), 'Shield', equippable=equippable_component) elif item_choice == 'chest_armor': equippable_component = Equippable(EquipmentSlots.CHEST_ARMOR, defense_bonus=4, max_hp_bonus=20) item = Entity(x, y, '/', colors.get('black'), 'Chest Armor', equippable=equippable_component) elif item_choice == 'shoulder_armor': equippable_component = Equippable( EquipmentSlots.SHOULDER_ARMOR, defense_bonus=3, power_bonus=3) item = Entity(x, y, '}', colors.get('black'), 'Shoulder Armor', equippable=equippable_component) elif item_choice == 'leg_armor': equippable_component = Equippable(EquipmentSlots.LEG_ARMOR, defense_bonus=2, power_bonus=3) item = Entity(x, y, '{', colors.get('black'), 'Leg Armor', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', colors.get('light_cyan')), damage=25, radius=3) item = Entity(x, y, '#', colors.get('red'), 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', colors.get('light_cyan'))) item = Entity(x, y, '#', colors.get('light_pink'), 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'freeze_scroll': item_component = Item(use_function=cast_freeze, maximum_range=5, damage=1) item = Entity(x, y, '#', colors.get('gold'), 'Freeze Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'mysterious_bottle': item_component = Item(use_function=xp_boost, amount=randint(30, 100)) item = Entity(x, y, '?', colors.get('red'), 'Mystery Bottle', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', colors.get('yellow'), 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) #get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 10, 'sword': from_dungeon_level([[900, 1]], self.dungeon_level), 'shield': from_dungeon_level([[900, 1]], self.dungeon_level), 'lightning_scrool': from_dungeon_level([[25, 1]], self.dungeon_level), 'fireball_spell': from_dungeon_level([[25, 1]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 1]], self.dungeon_level) } #Creating MONSTERS for i in range(number_of_monsters): #choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': figther_component = Fighter(hp=10, defense=0, power=3, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'o', lbtc.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=figther_component, ai=ai_component) else: figther_component = Fighter(hp=16, defense=1, power=4, xp=200) ai_component = BasicMonster() monster = Entity(x, y, 'T', lbtc.darker_green, 'Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=figther_component, ai=ai_component) entities.append(monster) #Creating Items for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) #Just an item randomizer for making it if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=4) item = Entity(x, y, '!', lbtc.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', lbtc.sky, 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', lbtc.darker_orange, 'Shield', equippable=equippable_component) elif item_choice == 'lightning_scroll': item_component = Item(use_function=cast_lightning, damage=20, maximum_range=5) item = Entity(x, y, '#', lbtc.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', lbtc.light_cyan), damage=12, radius=3) item = Entity(x, y, '#', lbtc.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', lbtc.light_cyan)) item = Entity(x, y, '#', lbtc.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def populate_shop(self): items = [] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=STICK_POWER) items.append( Entity(0, 0, '/', libtcod.red, STICK_NAME, equippable=equippable_component, price=STICK_PRICE)) equippable_component = Equippable( EquipmentSlots.OFF_HAND, defence_bonus=CARDBOARD_SHIELD_DEFENCE) items.append( Entity(0, 0, ']', libtcod.red, CARDBOARD_SHIELD_NAME, equippable=equippable_component, price=CARDBOARD_SHIELD_PRICE)) equippable_component = Equippable(EquipmentSlots.HEAD, max_hp_bonus=LEATHER_HELMET_HP) items.append( Entity(0, 0, 'h', libtcod.red, LEATHER_HELMET_NAME, equippable=equippable_component, price=LEATHER_HELMET_PRICE)) equippable_component = Equippable(EquipmentSlots.BODY, max_hp_bonus=LEATHER_CHEST_PLATE_HP) items.append( Entity(0, 0, 'c', libtcod.red, LEATHER_CHEST_PLATE_NAME, equippable=equippable_component, price=LEATHER_CHEST_PLATE_PRICE)) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=WOODEN_SWORD_POWER) items.append( Entity(0, 0, '/', libtcod.red, WOODEN_SWORD_NAME, equippable=equippable_component, price=WOODEN_SWORD_PRICE)) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defence_bonus=WOODEN_SHIELD_DEFENCE) items.append( Entity(0, 0, ']', libtcod.red, WOODEN_SHIELD_NAME, equippable=equippable_component, price=WOODEN_SHIELD_PRICE)) equippable_component = Equippable(EquipmentSlots.HEAD, max_hp_bonus=WOODEN_HELMET_HP, defence_bonus=WOODEN_HELMET_DEFENCE) items.append( Entity(0, 0, 'h', libtcod.red, WOODEN_HELMET_NAME, equippable=equippable_component, price=WOODEN_HELMET_PRICE)) equippable_component = Equippable( EquipmentSlots.BODY, max_hp_bonus=WOODEN_CHEST_PLATE_HP, defence_bonus=WOODEN_CHEST_PLATE_DEFENCE) items.append( Entity(0, 0, 'c', libtcod.red, WOODEN_CHEST_PLATE_NAME, equippable=equippable_component, price=WOODEN_CHEST_PLATE_PRICE)) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=IRON_SWORD_POWER) items.append( Entity(0, 0, '/', libtcod.red, IRON_SWORD_NAME, equippable=equippable_component, price=IRON_SWORD_PRICE)) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defence_bonus=IRON_SHIELD_DEFENCE) items.append( Entity(0, 0, ']', libtcod.red, IRON_SHIELD_NAME, equippable=equippable_component, price=IRON_SHIELD_PRICE)) equippable_component = Equippable(EquipmentSlots.HEAD, max_hp_bonus=IRON_HELMET_HP, defence_bonus=IRON_HELMET_DEFENCE) items.append( Entity(0, 0, 'h', libtcod.red, IRON_HELMET_NAME, equippable=equippable_component, price=IRON_HELMET_PRICE)) equippable_component = Equippable( EquipmentSlots.BODY, max_hp_bonus=IRON_CHEST_PLATE_HP, defence_bonus=IRON_CHEST_PLATE_DEFENCE) items.append( Entity(0, 0, 'c', libtcod.red, IRON_CHEST_PLATE_NAME, equippable=equippable_component, price=IRON_CHEST_PLATE_PRICE)) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=STING_POWER) items.append( Entity(0, 0, '/', libtcod.red, STING_NAME, equippable=equippable_component, price=STING_PRICE)) equippable_component = Equippable( EquipmentSlots.HEAD, max_hp_bonus=CROWN_OF_GONDOR_HP, defence_bonus=CROWN_OF_GONDOR_DEFENCE) items.append( Entity(0, 0, 'h', libtcod.red, CROWN_OF_GONDOR_NAME, equippable=equippable_component, price=CROWN_OF_GONDOR_PRICE)) equippable_component = Equippable( EquipmentSlots.BODY, max_hp_bonus=MITHRIL_MAIL_SHIRT_HP, defence_bonus=MITHRIL_MAIL_SHIRT_DEFENCE) items.append( Entity(0, 0, 'c', libtcod.red, MITHRIL_MAIL_SHIRT_NAME, equippable=equippable_component, price=MITHRIL_MAIL_SHIRT_PRICE)) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=SAURONS_SWORD_POWER) items.append( Entity(0, 0, '/', libtcod.red, SAURONS_SWORD_NAME, equippable=equippable_component, price=SAURONS_SWORD_PRICE)) return items
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [4, 4], [6, 6], [8, 10]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 8]], self.dungeon_level) max_equipment_items_per_room = from_dungeon_level([[1, 4]], self.dungeon_level) number_of_equipment_items = randint(0, max_equipment_items_per_room) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'goblin': from_dungeon_level([[80, 1], [60, 3], [30, 5], [0, 7]], self.dungeon_level), 'orc': from_dungeon_level([[40, 2], [50, 3], [20, 10]], self.dungeon_level), 'troll': from_dungeon_level([[20, 3], [40, 5], [60, 7]], self.dungeon_level), 'basilisk': from_dungeon_level([[20, 7], [30, 9], [40, 11]], self.dungeon_level) } item_chances = { 'healing_potion': from_dungeon_level([[15, 1], [10, 8]], self.dungeon_level), 'greater_healing_potion': from_dungeon_level([[30, 8]], self.dungeon_level), 'terrium_sword': from_dungeon_level([[15, 3], [0, 10]], self.dungeon_level), 'terrium_shield': from_dungeon_level([[15, 3], [0, 10]], self.dungeon_level), 'terrium_chestplate': from_dungeon_level([[15, 4], [0, 10]], self.dungeon_level), 'terrium_leg_armor': from_dungeon_level([[15, 4], [0, 10]], self.dungeon_level), 'terrium_helmet': from_dungeon_level([[20, 3], [0, 10]], self.dungeon_level), 'terrium_amulet': from_dungeon_level([[10, 5], [0, 10]], self.dungeon_level), 'ferrium_sword': from_dungeon_level([[15, 10], [0, 20]], self.dungeon_level), 'ferrium_shield': from_dungeon_level([[15, 10], [0, 20]], self.dungeon_level), 'ferrium_chestplate': from_dungeon_level([[15, 10], [0, 20]], self.dungeon_level), 'ferrium_leg_armor': from_dungeon_level([[15, 10], [0, 20]], self.dungeon_level), 'ferrium_helmet': from_dungeon_level([[20, 10], [0, 20]], self.dungeon_level), 'ferrium_amulet': from_dungeon_level([[10, 10], [0, 20]], self.dungeon_level), 'aurium_sword': from_dungeon_level([[15, 20]], self.dungeon_level), 'aurium_shield': from_dungeon_level([[15, 20]], self.dungeon_level), 'aurium_chestplate': from_dungeon_level([[15, 20]], self.dungeon_level), 'aurium_leg_armor': from_dungeon_level([[15, 20]], self.dungeon_level), 'aurium_helmet': from_dungeon_level([[20, 20]], self.dungeon_level), 'aurium_amulet': from_dungeon_level([[10, 20]], self.dungeon_level), 'lightning_spell': from_dungeon_level([[25, 3]], self.dungeon_level), 'fireball_spell': from_dungeon_level([[25, 4]], self.dungeon_level), 'confusion_spell': from_dungeon_level([[25, 2]], self.dungeon_level), 'sleep_spell': from_dungeon_level([[25, 4]], self.dungeon_level), 'sleep_aura': from_dungeon_level([[25, 5]], self.dungeon_level), 'health_talisman': from_dungeon_level([[50, 10]], self.dungeon_level) } equipment_item_chances = { 'equipment_health_potion': from_dungeon_level([[25, 4]], self.dungeon_level) } for i in range(number_of_monsters): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'goblin': fighter_component = Fighter(hp=4, defense=0, power=2, magic=0, xp=20, talismanhp=0, gold=randint(0, 2)) ai_component = BasicMonster() monster = Entity(x, y, 'g', libtcod.darker_chartreuse, 'Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'orc': fighter_component = Fighter(hp=10, defense=0, power=3, magic=0, xp=40, talismanhp=0, gold=randint(1, 5)) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=14, defense=2, power=5, magic=0, xp=100, talismanhp=0, gold=randint(3, 7)) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) else: fighter_component = Fighter(hp=40, defense=3, power=8, magic=0, xp=200, talismanhp=0, gold=randint(10, 20)) ai_component = BasicMonster() monster = Entity(x, y, 'B', libtcod.darker_red, 'Basilisk', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': heal1_amount = 20 item_component = Item(use_function=heal, amount=heal1_amount) item = Entity(x, y, '&', libtcod.violet, "health potion" + " (+" + str(heal1_amount) + " HP)", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'greater_healing_potion': heal2_amount = 40 item_component = Item(use_function=heal, amount=heal2_amount) item = Entity(x, y, '&', libtcod.red, "greater healing potion" + " (+" + str(heal2_amount) + " HP)", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'terrium_sword': sword_amount = randint(2, 4) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount) item = Entity(x, y, '/', libtcod.darker_grey, "terrium sword" + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) elif item_choice == 'terrium_shield': shield_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount) item = Entity(x, y, '[', libtcod.darker_grey, "terrium shield" + " (+" + str(shield_amount) + " def)", equippable=equippable_component) elif item_choice == 'terrium_chestplate': chestplate_amount = randint(2, 3) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount) item = Entity(x, y, 'M', libtcod.darker_grey, "terrium chestplate" + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) elif item_choice == 'terrium_leg_armor': leg_amount = randint(1, 3) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount) item = Entity(x, y, 'H', libtcod.darker_grey, "terrium leg armor" + " (+" + str(leg_amount) + " def)", equippable=equippable_component) elif item_choice == 'terrium_helmet': helmet_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount) item = Entity(x, y, '^', libtcod.darker_grey, "terrium helmet" + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) elif item_choice == 'terrium_amulet': amulet_amount = randint(1, 4) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount) item = Entity(x, y, '*', libtcod.darker_grey, "terrium amulet" + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) elif item_choice == 'ferrium_sword': sword_amount = randint(6, 10) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount) item = Entity(x, y, '/', libtcod.darker_orange, "ferrium sword" + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) elif item_choice == 'ferrium_shield': shield_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount) item = Entity(x, y, '[', libtcod.darker_orange, "ferrium shield" + " (+" + str(shield_amount) + " def)", equippable=equippable_component) elif item_choice == 'ferrium_chestplate': chestplate_amount = randint(5, 7) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount) item = Entity(x, y, 'M', libtcod.darker_orange, "ferrium chestplate" + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) elif item_choice == 'ferrium_leg_armor': leg_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount) item = Entity(x, y, 'H', libtcod.darker_orange, "ferrium leg armor" + " (+" + str(leg_amount) + " def)", equippable=equippable_component) elif item_choice == 'ferrium_helmet': helmet_amount = randint(4, 5) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount) item = Entity(x, y, '^', libtcod.darker_orange, "ferrium helmet" + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) elif item_choice == 'ferrium_amulet': amulet_amount = randint(5, 9) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount) item = Entity(x, y, '*', libtcod.darker_orange, "ferrium amulet" + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) elif item_choice == 'aurium_sword': sword_amount = randint(15, 20) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount) item = Entity(x, y, '/', libtcod.crimson, "aurium sword" + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) elif item_choice == 'aurium_shield': shield_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount) item = Entity(x, y, '[', libtcod.crimson, "aurium shield" + " (+" + str(shield_amount) + " def)", equippable=equippable_component) elif item_choice == 'aurium_chestplate': chestplate_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount) item = Entity(x, y, 'M', libtcod.crimson, "aurium chestplate" + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) elif item_choice == 'aurium_leg_armor': leg_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount) item = Entity(x, y, 'H', libtcod.crimson, "aurium leg armor" + " (+" + str(leg_amount) + " def)", equippable=equippable_component) elif item_choice == 'aurium_helmet': helmet_amount = randint(8, 12) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount) item = Entity(x, y, '^', libtcod.crimson, "aurium helmet" + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) elif item_choice == 'aurium_amulet': amulet_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount) item = Entity(x, y, '*', libtcod.crimson, "aurium amulet" + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) elif item_choice == 'fireball_spell': item_component = Item(use_function=cast_fireball, targeting=True, targeting_message=Message("Left click a target tile for the fireball, or right click to cancel.", libtcod.light_cyan), damage=15, radius=3) item = Entity(x, y, '#', libtcod.red, "Fireball Spell", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_spell': item_component = Item(use_function=cast_confusion, targeting=True, targeting_message=Message("Left click an enemy to confuse it, or right click to cancel.", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, "Confusion Spell", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sleep_spell': item_component = Item(use_function=cast_sleep, targeting=True, targeting_message=Message("Left click an enemy to make it fall asleep, or right click to cancel.", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_azure, "Sleep Spell", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sleep_aura': item_component = Item(use_function=cast_sleep_aura, targeting=True, targeting_message=Message("Left click a target tile to cast the sleep aura, or right click to cancel.", libtcod.light_cyan), radius=3) item = Entity(x, y, '#', libtcod.light_azure, "Sleep Aura Spell", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'health_talisman': item_component = Item(use_function=health_talisman_sacrifice, amount=5) item = Entity(x, y, '?', libtcod.darker_orange, "Health Talisman", render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=30, maximum_range=5) item = Entity(x, y, '#', libtcod.blue, "Lightning Spell", render_order=RenderOrder.ITEM, item=item_component) entities.append(item) '''
def place_entities(room, entities, dungeon_level, colors): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'Small kobold': 80, 'Kobold': from_dungeon_level([[15, 3], [30, 5], [60, 7]], dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level([[5, 4]], dungeon_level), 'shield': from_dungeon_level([[15, 8]], dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'Small kobold': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'o', colors.get('desaturated_green'), 'Small Kobold', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'T', colors.get('darker_green'), 'Kobold', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', colors.get('violet'), 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', colors.get('sky'), 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', colors.get('darker_orange'), 'Shield', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item(use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', colors.get('light_cyan')), damage=25, radius=3) item = Entity(x, y, '#', colors.get('red'), 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item(use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', colors.get('light_cyan'))) item = Entity(x, y, '#', colors.get('light_pink'), 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=20, maximum_range=5) item = Entity(x, y, '#', colors.get('yellow'), 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): # Get a random number of monsters max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_stream = open( os.path.join(definitions.ROOT_DIR, 'data', 'objects', 'monsters.yaml'), 'r') monster_list = yaml.load(monster_stream) monster_chances = [] for i in monster_list: monster_chances.append([ 'monster', from_dungeon_level(monster_list[i].get('spawn_chance'), self.dungeon_level), i ]) # Load item list so it can be used to generate items item_stream = open( os.path.join(definitions.ROOT_DIR, 'data', 'objects', 'items.yaml'), 'r') item_list = yaml.load(item_stream) equipment_stream = open( os.path.join(definitions.ROOT_DIR, 'data', 'objects', 'equipment.yaml'), 'r') equipment_list = yaml.load(equipment_stream) item_chances = [] item_index = 0 for i in item_list: item_chances.append([ 'item', from_dungeon_level(item_list[i].get('loot_chance'), self.dungeon_level), i ]) item_index += 1 for i in equipment_list: item_chances.append([ 'equipment', from_dungeon_level(equipment_list[i].get('loot_chance'), self.dungeon_level), i ]) item_index += 1 for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_roll = random_choice_from_dict(monster_chances) monster_object = monster_list[monster_roll[2]] fighter_component = Fighter(monster_object.get('hp'), monster_object.get('defense'), monster_object.get('power'), monster_object.get('xp'), dmg=monster_object.get('dmg')) ai_component = BasicMonster() monster = Entity(x, y, monster_object.get('char'), eval(monster_object.get('color')), monster_object.get('name'), monster_object.get('description'), blocks=True, render_order=eval( monster_object.get('render_order')), fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_roll = random_choice_from_dict(item_chances) if item_roll[0] == 'item': item_object = item_list[item_roll[2]] args = {} kwargs = {} for k, v in item_object['args'].items(): args[k] = eval(v) for k, v in item_object['kwargs'].items(): kwargs[k] = v item_component = Item(**args, **kwargs) item = Entity(x, y, item_object.get('char'), eval(item_object.get('color')), item_object.get('name'), item_object.get('description'), render_order=eval( item_object.get('render_order')), item=item_component) entities.append(item) # # #Need to add code that spawns equipement items, I then need to convert the monster_chance variable to a list and update the monster spwan code accordingly. # # if item_roll[0] == 'equipment': item_object = equipment_list[item_roll[2]] kwargs = {} for k, v in item_object['kwargs'].items(): kwargs[k] = v equippable_component = Equippable( eval(item_object.get('slot')), **kwargs) item = Entity(x, y, item_object.get('char'), eval(item_object.get('color')), item_object.get('name'), item_object.get('description'), render_order=eval( item_object.get('render_order')), equippable=equippable_component) entities.append(item)
def get_finger_choice(item_choice, x, y): suffix = '-finger' display_icon = 'o' display_color = libtcod.darker_amber equipment_slot = EquipmentSlots.FINGERS disp_name = item_choice.replace(suffix, "") item = None if item_choice == 'Ring of Hunger' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=3) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Adornment' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Levitation' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Invisibility' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of See Invisible' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Gain Strength' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Gain Constitution' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Fire Resistance' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Magic Regeneration' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Polymorph' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Polymorph Control' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Teleport' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Teleport Control' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) elif item_choice == 'Ring of Regeneration' + suffix: equippable_component = Equippable(equipment_slot, power_bonus=1) item = Entity(x, y, display_icon, display_color, disp_name, equippable=equippable_component) return item
def place_entities_in_room(self, room_rect, entities): max_monsters_per_room = weight_from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = weight_from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # get random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { "orc": 80, "troll": weight_from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level), } item_chances = { "healing_potion": 35, "sword": weight_from_dungeon_level([[5, 4]], self.dungeon_level), "shield": weight_from_dungeon_level([[15, 8]], self.dungeon_level), "lightning_scroll": weight_from_dungeon_level([[25, 4]], self.dungeon_level), "fireball_scroll": weight_from_dungeon_level([[25, 6]], self.dungeon_level), "confusion_scroll": weight_from_dungeon_level([[10, 2]], self.dungeon_level), } for i in range(number_of_monsters): # choose random location in room x = randint(room_rect.x1 + 1, room_rect.x2 - 1) y = randint(room_rect.y1 + 1, room_rect.y2 - 1) # make sure no monster is already in spot if not any([entity for entity in entities if entity.x == x and entity.y == y]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == "orc": fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity( x, y, 'o', libtcod.desaturated_green, "Orc", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component ) else: # Place troll fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity( x, y, 'T', libtcod.darker_green, "Troll", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component ) entities.append(monster) for i in range(number_of_items): x = randint(room_rect.x1 + 1, room_rect.x2 - 1) y = randint(room_rect.y1 + 1, room_rect.y2 - 1) if not any([entity for entity in entities if entity.x == x and entity.y == y]): item_choice = random_choice_from_dict(item_chances) if item_choice == "healing_potion": item_component = Item(use_function=heal, amount=40) item = Entity( x, y, '!', libtcod.violet, "Potion of Healing", render_order=RenderOrder.ITEM, item=item_component ) elif item_choice == "sword": equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity( x, y, '/', libtcod.sky, "Sword", equippable=equippable_component ) elif item_choice == "shield": equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity( x, y, '[', libtcod.darker_orange, "Shield", equippable=equippable_component ) elif item_choice == "fireball_scroll": item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message("Left-click a target tile for fireball. Right-click or Esc to cancel.", libtcod.light_cyan), damage=25, radius=3 ) item = Entity( x, y, '#', libtcod.red, "Scroll of Fireball", render_order=RenderOrder.ITEM, item=item_component ) elif item_choice == "confusion_scroll": item_component = Item( use_function=cast_confusion, targeting=True, targeting_message=Message("Left-click a target tile for fireball. Right-click or Esc to cancel.", libtcod.light_cyan) ) item = Entity( x, y, '#', libtcod.light_green, "Scroll of Confusion", render_order=RenderOrder.ITEM, item=item_component ) else: # Place lightning scroll item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity( x, y, '#', libtcod.yellow, "Lightning Scroll", render_order=RenderOrder.ITEM, item=item_component ) entities.append(item)
from entity import Entity from components.item import Item from components.equipment import EquipmentSlots from components.equippable import Equippable from item_functions import paralyse, cast_fireball from game_messages import Message artifact_1_component = Item( use_function=paralyse, mana_cost=15, targeting=True, targeting_message=Message( 'Left-click a target tile for paralysing, or right-click to cancel.', libtcod.light_cyan)) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, minimum_hit_dice=2, maximum_hit_dice=8) honey_blade = Entity(0, 0, '/', libtcod.yellow, 'Honey Blade', item=artifact_1_component, equippable=equippable_component) artifact_2_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the ball of honey, or right-click to cancel.', libtcod.light_cyan),
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'quiz': 80, 'exam': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level), 'final': from_dungeon_level([[10, 3], [20, 5], [30, 7]], self.dungeon_level) } # Define chance for each type monster_type_chances = { 'art': 25, 'math': 25, 'science': 25, 'english': 25, } item_chances = { 'healing_potion': 50, 'art_sword': from_dungeon_level([[5, 1]], self.dungeon_level), 'art_shield': from_dungeon_level([[5, 1]], self.dungeon_level), 'math_sword': from_dungeon_level([[5, 1]], self.dungeon_level), 'math_shield': from_dungeon_level([[5, 1]], self.dungeon_level), 'science_sword': from_dungeon_level([[5, 1]], self.dungeon_level), 'science_shield': from_dungeon_level([[5, 1]], self.dungeon_level), 'english_sword': from_dungeon_level([[5, 1]], self.dungeon_level), 'english_shield': from_dungeon_level([[5, 1]], self.dungeon_level), #'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), #'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), #'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) monster_type_choice = random_choice_from_dict( monster_type_chances) # Get random type of monsters if monster_choice == 'quiz': if monster_type_choice == 'art': fighter_component = Fighter(hp=20, defense=0, power=4, name='Art Quiz', xp=0, subject='art') ai_component = BasicMonster() monster = Entity(x, y, 275, libtcod.white, 'Art Quiz', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'math': fighter_component = Fighter(hp=20, defense=0, power=4, name='Math Quiz', xp=0, subject='math') ai_component = BasicMonster() monster = Entity(x, y, 278, libtcod.white, 'Math Quiz', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'science': fighter_component = Fighter(hp=20, defense=0, power=4, name='Science Quiz', xp=0, subject='science') ai_component = BasicMonster() monster = Entity(x, y, 281, libtcod.white, 'Science Quiz', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'english': fighter_component = Fighter(hp=20, defense=0, power=4, name='English Quiz', xp=0, subject='english') ai_component = BasicMonster() monster = Entity(x, y, 284, libtcod.white, 'English Quiz', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'exam': if monster_type_choice == 'art': fighter_component = Fighter(hp=35, defense=1, power=6, name='Art Exam', xp=0, subject='art') ai_component = BasicMonster() monster = Entity(x, y, 276, libtcod.white, 'Art Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'math': fighter_component = Fighter(hp=35, defense=1, power=6, name='Math Exam', xp=0, subject='math') ai_component = BasicMonster() monster = Entity(x, y, 279, libtcod.white, 'Math Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'science': fighter_component = Fighter(hp=35, defense=1, power=6, name='Science Exam', xp=0, subject='science') ai_component = BasicMonster() monster = Entity(x, y, 282, libtcod.white, 'Science Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'english': fighter_component = Fighter(hp=35, defense=1, power=6, name='English Exam', xp=0, subject='english') ai_component = BasicMonster() monster = Entity(x, y, 285, libtcod.white, 'English Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'final': if monster_type_choice == 'art': fighter_component = Fighter(hp=50, defense=2, power=8, name='Art Final Exam', xp=4, subject='art') ai_component = BasicMonster() monster = Entity(x, y, 277, libtcod.white, 'Art Final Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'math': fighter_component = Fighter(hp=50, defense=2, power=8, name='Math Final Exam', xp=4, subject='math') ai_component = BasicMonster() monster = Entity(x, y, 280, libtcod.white, 'Math Final Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'science': fighter_component = Fighter(hp=50, defense=2, power=8, name='Science Final Exam', xp=4, subject='science') ai_component = BasicMonster() monster = Entity(x, y, 283, libtcod.white, 'Science Final Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_type_choice == 'english': fighter_component = Fighter(hp=50, defense=2, power=8, name='English Final Exam', xp=4, subject='english') ai_component = BasicMonster() monster = Entity(x, y, 286, libtcod.white, 'English Final Exam', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, 262, libtcod.white, 'Relaxing Tea', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'art_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, art_power_bonus=5) item = Entity(x, y, 267, libtcod.white, 'Paintbrush', equippable=equippable_component) elif item_choice == 'art_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, art_defense_bonus=4) item = Entity(x, y, 268, libtcod.white, 'Pallete Clipboard', equippable=equippable_component) elif item_choice == 'math_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, math_power_bonus=5) item = Entity(x, y, 269, libtcod.white, 'Ruler', equippable=equippable_component) elif item_choice == 'math_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, math_defense_bonus=4) item = Entity(x, y, 270, libtcod.white, 'Measuring Clipboard', equippable=equippable_component) elif item_choice == 'science_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, science_power_bonus=5) item = Entity(x, y, 271, libtcod.white, 'Calculator', equippable=equippable_component) elif item_choice == 'science_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, science_defense_bonus=4) item = Entity(x, y, 272, libtcod.white, 'Vial Clipboard', equippable=equippable_component) elif item_choice == 'english_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, english_power_bonus=5) item = Entity(x, y, 273, libtcod.white, 'Dictionary', equippable=equippable_component) elif item_choice == 'english_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, english_defense_bonus=4) item = Entity(x, y, 274, libtcod.white, 'Report Clipboard', equippable=equippable_component) entities.append(item)
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0, mana=100) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants['player_tile'], libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] gold_value = 1 equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=gold_value) dagger = Entity(0, 0, constants['dagger_tile'], libtcod.white, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) gold_value = 2 item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=gold_value) magic_wand = Entity(0, 0, constants['magic_wand_tile'], libtcod.white, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map( constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants['orc_tile'], constants['healing_potion_tile'], constants['scroll_tile'], constants['troll_tile'], constants['stairs_tile'], constants['sword_tile'], constants['shield_tile'], constants['dagger_tile'], constants['magic_wand_tile'], constants['greater_healing_potion_tile'], constants['ghost_tile'], constants['slime_tile'], constants['corpse_tile'], constants['goblin_tile'], constants['baby_slime_tile'], constants['skeleton_tile'], constants['slime_corpse_tile'], constants['baby_slime_corpse_tile'], constants['skeleton_corpse_tile'], constants['mana_potion_tile'], constants['wizard_staff_tile'], constants['health_talisman_tile'], constants['basilisk_tile'], constants['treasure_tile'], constants['chestplate_tile'], constants['leg_armor_tile'], constants['helmet_tile'], constants['amulet_tile']) item_descriptors = [ 'Valor', 'Power', 'Ingenuity', 'Glory', 'Strength', 'Speed', 'Wealth', 'Divinity', 'Energy', 'Honor', 'Resistance', 'Greatness', 'Courage', 'Intelligence' ] all_shop_equipment = [] sword_amount = randint(2, 4) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=10) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Terrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=7) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Terrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(2, 3) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=20) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_grey, "Terrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(1, 3) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=15) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_grey, "Terrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=5) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_grey, "Terrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(1, 4) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=6) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_grey, "Terrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) sword_amount = randint(6, 10) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=35) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Ferrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=30) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Ferrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(5, 7) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=50) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_orange, "Ferrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=40) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_orange, "Ferrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(4, 5) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=15) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_orange, "Ferrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(5, 9) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=25) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_orange, "Ferrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) sword_amount = randint(15, 20) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=100) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Aurium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=80) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Aurium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=120) item = Entity(0, 0, constants['chestplate_tile'], libtcod.crimson, "Aurium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=100) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.crimson, "Aurium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(8, 12) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=90) item = Entity(0, 0, constants['helmet_tile'], libtcod.crimson, "Aurium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=70) item = Entity(0, 0, constants['amulet_tile'], libtcod.crimson, "Aurium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) all_shop_items = [] item_component = Item(use_function=heal, amount=20, gold=20) item = Entity(0, 0, constants['healing_potion_tile'], libtcod.white, "Health Potion (+20 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=heal, amount=40, gold=40) item = Entity(0, 0, constants['greater_healing_potion_tile'], libtcod.white, "Greater Healing Potion (+40 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "Left click a target tile for the fireball, or right click to cancel.", libtcod.light_cyan), damage=15, radius=3, mana_cost=20, gold=70) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Fireball Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_confusion, targeting=True, targeting_message=Message( "Left click an enemy to confuse it, or right click to cancel.", libtcod.light_cyan), mana_cost=10, gold=30) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Confusion Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_sleep, targeting=True, targeting_message=Message( "Left click an enemy to make it fall asleep, or right click to cancel.", libtcod.light_cyan), mana_cost=10, gold=30) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Sleep Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_sleep_aura, targeting=True, targeting_message=Message( "Left click a target tile to cast the sleep aura, or right click to cancel.", libtcod.light_cyan), radius=3, mana_cost=20, gold=80) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Sleep Aura Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_mind_control, targeting=True, targeting_message=Message( "Left click a target tile to cast mind control, or right click to cancel.", libtcod.light_cyan), radius=3, mana_cost=15, gold=100) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Mind Control Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=health_talisman_sacrifice, amount=5, gold=200) item = Entity(0, 0, constants['health_talisman_tile'], libtcod.darker_orange, "Health Talisman", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=cast_magic, damage=5, maximum_range=5, gold=200) item = Entity(0, 0, constants['wizard_staff_tile'], libtcod.white, "Wizard Staff", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=necromancy, number_of_monsters=5, mana_cost=20, gold=200) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Necromancy Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=recover_mana, amount=20, gold=10) item = Entity(0, 0, constants['mana_potion_tile'], libtcod.white, "Mana Potion (+20 MANA)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=cast_lightning, damage=30, maximum_range=5, mana_cost=15, gold=50) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Lightning Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) number_of_shop_items = randint(3, 5) for i in range(number_of_shop_items): random_item = randint(0, len(all_shop_items) - 1) game_map.shop_items.append(all_shop_items[random_item]) number_of_shop_equipment = randint(3, 5) for i in range(number_of_shop_equipment): random_equipment = randint(0, len(all_shop_equipment) - 1) game_map.shop_equipment_items.append( all_shop_equipment[random_equipment]) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # gets random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { "orc": 80, "troll": from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level), "dragon": from_dungeon_level([[10, 7], [20, 10], [30, 14]], self.dungeon_level) } item_chances = { "health_potion": 35, "lightning_scroll": from_dungeon_level([[25, 4]], self.dungeon_level), "fireball_scroll": from_dungeon_level([[25, 6]], self.dungeon_level), "confusion_scroll": from_dungeon_level([[10, 2]], self.dungeon_level), "betrayal_scroll": from_dungeon_level([[10, 5]], self.dungeon_level), "iron_sword": from_dungeon_level([[5, 4]], self.dungeon_level), "wooden_shield": from_dungeon_level([[15, 8]], self.dungeon_level) } for i in range(number_of_monsters): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == "orc": fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, "o", libtcod.desaturated_green, "Orc", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == "troll": fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, "T", libtcod.darker_green, "Troll", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == "dragon": fighter_component = Fighter(hp=40, defense=2, power=12, xp=500) ai_component = BasicMonster() monster = Entity(x, y, "D", libtcod.dark_red, "Dragon", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == "health_potion": item_component = Item(use_function=heal, amount=40) item = Entity(x, y, "!", libtcod.violet, "Health Potion", False, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "fireball_scroll": item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "Left-click a tile to target, or right-click to cancel.", libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, "#", libtcod.red, "Fireball Scroll", False, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "confusion_scroll": item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( "Left-click a tile to target, or right-click to cancel", libtcod.light_cyan)) item = Entity(x, y, "#", libtcod.light_pink, "Confusion Scroll", False, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "betrayal_scroll": item_component = Item( use_function=cast_betrayal, targeting=True, targeting_message=Message( "Left-click a tile to target, or right-click to cancel", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.black, "Betrayal Scroll", False, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "lightning_scroll": item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, "#", libtcod.yellow, "Lightning Scroll", False, render_order=RenderOrder.ITEM, item=item_component) elif item_choice == "iron_sword": equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, "/", libtcod.silver, "Iron Sword", False, render_order=RenderOrder.ITEM, equippable=equippable_component) elif item_choice == "wooden_shield": equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, "[", libtcod.darker_orange, "Wooden Shield", False, render_order=RenderOrder.ITEM, equippable=equippable_component) entities.append(item)
def main(): constants = get_constants() libtcod.console_set_custom_font( 'tiledfont.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) # load the custom font rows load_customfont() # assign the custom font rows numbers to text (for easier calling when defining entities with custom tiles) # defining tiles (rather than numbers) wall_tile = 256 floor_tile = 257 player_tile = 258 quiz_tile = 259 exam_tile = 260 healingpotion_tile = 261 sword_tile = 263 shield_tile = 264 stairsdown_tile = 265 dagger_tile = 266 fighter_component = Fighter(hp=100, defense=1, power=3, name='Student') inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, player_tile, libtcod.white, 'Student', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) dagger = Entity(0, 0, dagger_tile, libtcod.white, 'Pencil', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) con = libtcod.console.Console(constants['screen_width'], constants['screen_height']) panel = libtcod.console.Console(constants['screen_width'], constants['panel_height']) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) fov_recompute = True fov_map = initialize_fov(game_map) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state # Welcome the player message_log.add_message( Message( 'Welcome, Student, to the College of Doom! Aquire 180 credits to graduate...or die trying!', libtcod.white)) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, constants['colors'], game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) move = action.get('move') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') wait = action.get('wait') exit = action.get('exit') fullscreen = action.get('fullscreen') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) fov_recompute = True else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend(player.inventory.use(item)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True con.clear() break else: message_log.add_message( Message( 'You search around, but Summer break is nowhere to be seen.', libtcod.yellow)) if level_up: if level_up == 'hp': player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if wait == True: game_state = GameStates.ENEMY_TURN fov_recompute = True if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state else: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') equip = player_turn_result.get('equip') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message( Message('You equipped the {0}.'.format( equipped.name))) if dequipped: message_log.add_message( Message('You dequipped the {0}.'.format( dequipped.name))) game_state = GameStates.ENEMY_TURN xp = player_turn_result.get('xp') if xp: leveled_up = player.level.add_xp(xp) message_log.add_message( Message( 'You passed the Final Exam and gained {0} credits!'. format(xp))) if leveled_up: if player.level.current_level == 5: previous_game_state = game_state game_state = GameStates.WIN message_log.add_message( Message( 'You have completed 180 credits at the College of Doom! You graduated!', libtcod.yellow)) else: message_log.add_message( Message( 'You made it through another year of school! You move on to school year {0}' .format(player.level.current_level) + '!', libtcod.yellow)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN fov_recompute = True
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) max_equipment_items_per_room = from_dungeon_level([[2, 1]], self.dungeon_level) number_of_equipment_items = randint(0, max_equipment_items_per_room) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'goblin': from_dungeon_level([[80, 1], [60, 3], [30, 5], [0, 7]], self.dungeon_level), 'orc': from_dungeon_level([[40, 2], [50, 3], [30, 7]], self.dungeon_level), 'troll': from_dungeon_level([[20, 3], [40, 5], [60, 7]], self.dungeon_level), 'Balrog': from_dungeon_level([[20, 7], [30, 9], [80, 11]], self.dungeon_level) } #Terrium, Ferrium, Aurium item_chances = { 'healing_potion': from_dungeon_level([[15, 1], [10, 8]], self.dungeon_level), 'greater_healing_potion': from_dungeon_level([[30, 8]], self.dungeon_level), 'terrium_sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'terrium_shield': from_dungeon_level([[15, 4]], self.dungeon_level), 'terrium_chestplate': from_dungeon_level([[15, 5]], self.dungeon_level), 'terrium_leg_armor': from_dungeon_level([[15, 4]], self.dungeon_level), 'terrium_helmet': from_dungeon_level([[20, 3]], self.dungeon_level), 'terrium_amulet': from_dungeon_level([[10, 7]], self.dungeon_level), 'lightning_spell': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_spell': from_dungeon_level([[25, 5]], self.dungeon_level), 'confusion_spell': from_dungeon_level([[10, 2]], self.dungeon_level) } equipment_item_chances = { 'equipment_health_potion': from_dungeon_level([[90, 1]], self.dungeon_level) } for i in range(number_of_monsters): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'goblin': fighter_component = Fighter(hp=5, defense=0, power=2, magic=0, xp=10) ai_component = BasicMonster() monster = Entity(x, y, 'g', libtcod.darker_chartreuse, 'Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'orc': fighter_component = Fighter(hp=12, defense=0, power=4, magic=0, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=18, defense=2, power=8, magic=0, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) else: fighter_component = Fighter(hp=60, defense=5, power=16, magic=0, xp=200) ai_component = BasicMonster() monster = Entity(x, y, 'B', libtcod.darker_red, 'Balrog', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=20) item = Entity(x, y, '&', libtcod.violet, "health potion", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'greater_healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '&', libtcod.red, "greater healing potion", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'terrium_sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=randint( 2, 4)) item = Entity(x, y, '/', libtcod.darker_orange, "terrium sword", equippable=equippable_component) elif item_choice == 'terrium_shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=randint( 1, 2)) item = Entity(x, y, '[', libtcod.darker_orange, "terrium shield", equippable=equippable_component) elif item_choice == 'terrium_chestplate': equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=randint( 2, 3)) item = Entity(x, y, 'M', libtcod.darker_orange, "terrium chestplate", equippable=equippable_component) elif item_choice == 'terrium_leg_armor': equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=randint( 1, 2)) item = Entity(x, y, 'H', libtcod.darker_orange, "terrium leg armor", equippable=equippable_component) elif item_choice == 'terrium_helmet': equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=randint( 1, 2)) item = Entity(x, y, '^', libtcod.darker_orange, "terrium helmet", equippable=equippable_component) elif item_choice == 'terrium_amulet': equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=randint( 1, 4)) item = Entity(x, y, '*', libtcod.darker_orange, "terrium amulet", equippable=equippable_component) elif item_choice == 'fireball_spell': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "Left click a target tile for the fireball, or right click to cancel.", libtcod.light_cyan), damage=15, radius=3) item = Entity(x, y, '#', libtcod.red, "Fireball Spell", render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_spell': item_component = Item( use_function=cast_confusion, targeting=True, targeting_message=Message( "Left click an enemy to confuse it, or right click to cancel.", libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, "Confusion Spell", render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=30, maximum_range=5) item = Entity(x, y, '#', libtcod.blue, "Lightning Spell", render_order=RenderOrder.ITEM, item=item_component) entities.append(item) '''
def get_sword_choices(item_choice,wp_en,x,y,disp_name): item = None if item_choice == 'Orcish Shortsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Shortsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Gladius'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Dwarvish Shortsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Broadsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Elven Shortsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Longsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Tsurugi'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Elven Broadsword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Bastard Sword'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Excalibur'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) elif item_choice == 'Tsurugi of Muramasa'+wp_en: equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(x, y, '/', libtcod.black, disp_name, equippable=equippable_component) return item
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) # Get a random number of items number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'lightning_scroll': 35, 'fireball_scroll': 35, 'teleport_scroll': 35, 'confusion_scroll': 35, 'polymorph_scroll': 35 } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # Check if an entity is already in that location if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, '/', libtcod.sky, 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', libtcod.darker_orange, 'Shield', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the spell or right-click to cancel.', libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'teleport_scroll': item_component = Item( use_function=cast_teleport, targeting=True, targeting_message=Message( 'Left-click an entity to cast the spell, or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.orange, 'Teleport Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an entity to cast the spell or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'polymorph_scroll': item_component = Item( use_function=cast_polymorph, targeting=True, targeting_message=Message( 'Left-click an entity to cast the spell or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.blue, 'Polymorph Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level([[10, 5]], self.dungeon_level), 'shield': from_dungeon_level([[10, 6]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # Check if an entity is already in that location if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component = Fighter(hp=20, defense=0, power=4, xp=35) ai_component = BasicMonster() monster = Entity(x, y, tiles.get('orc_tile'), libtcod.white, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=30, defense=2, power=8, xp=100) ai_component = BasicMonster() monster = Entity(x, y, tiles.get('troll_tile'), libtcod.white, 'Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, tiles.get('healingpotion_tile'), libtcod.white, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, tiles.get('sword_tile'), libtcod.white, 'Sword', render_order=RenderOrder.ITEM, equippable=equippable_component, sprite_main_shift=576) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, tiles.get('shield_tile'), libtcod.white, 'Shield', render_order=RenderOrder.ITEM, equippable=equippable_component, sprite_off_shift=320) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', colors.get('dark')), targeting_radius=3, damage=25, radius=3) item = Entity(x, y, tiles.get('scroll_tile'), libtcod.white, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', colors.get('dark')), targeting_radius=0) item = Entity(x, y, tiles.get('scroll_tile'), libtcod.white, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, tiles.get('scroll_tile'), libtcod.white, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)