def make_random_potion(self, x, y): random_potion_type = get_random_key(self.potions) if random_potion_type == 'healing potion': item_component = Item(use_function=heal) item = Entity(x, y, '!', Colors.DARK_RED, 'healing potion', render_order=RenderOrder.ITEM, item=item_component, description='recover a small amount of health') else: item_component = Item(use_function=gain_level) item = Entity(x, y, '!', Colors.GREEN, 'knowledge potion', render_order=RenderOrder.ITEM, item=item_component, description='drink to gain one experience level') return item
def create_item(x, y, item_choice): if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcod.violet, 'Healing Salve', 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_amber, '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, '#', libtcod.yellow, 'Fireball 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, 'Scroll of Lightning', render_order=RenderOrder.ITEM, item=item_component) return item
def place_entities(self, room, entities, max_monsters_per_room, max_items_per_room): number_of_monsters = randint(0, max_monsters_per_room) # generates a random no. monsters between these bounds number_of_items = randint(0, max_items_per_room) for i in range(number_of_monsters): # chooses a random location in the room to spawn each monster below x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) """ Creating the monsters""" if not any([entity for entity in entities if entity.x == x and entity.y == y]): # checking no overlap for placement of entities if randint(0, 100) < 80: # used to determine the frequency of diff enemies appearing, 80% chance here it's an 'o' fighter_component = Fighter(hp=10, defense=0, power=3) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_chartreuse, 'Orc', blocks = True, render_order=RenderOrder.ACTOR, fighter = fighter_component, ai = ai_component) # calls the Entity class else: fighter_component = Fighter(hp=16, defense=1, power=4) 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) """Creating the 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_chance = randint(0, 100) if item_chance < 70: item_component = Item(use_function=heal, amount=4) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 80: 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=12, radius=3) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 90: 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=20, maximum_range=5) item = Entity(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def create_item(name, item_type, colors, color, char, x, y, kwargs): if item_type == 'potion': use_function = kwargs.get('use_function') amount = kwargs.get('amount') item_component = Item(use_function=use_function, amount=amount) item = Entity(x, y, char, colors.get(color), name, render_order=RenderOrder.ITEM, item=item_component) elif item_type == 'equipment': slot = kwargs.get('slot') bonuses = kwargs.get('bonuses') power_bonus = bonuses.get('power', 0) defense_bonus = bonuses.get('defense', 0) max_hp_bonus = bonuses.get('hp', 0) max_mana_bonus = bonuses.get('mana', 0) max_focus_bonus = bonuses.get('focus', 0) equippable_component = Equippable(slot, power_bonus=power_bonus, defense_bonus=defense_bonus, max_hp_bonus=max_hp_bonus, max_mana_bonus=max_mana_bonus, max_focus_bonus=max_focus_bonus) item = Entity(x, y, char, colors.get(color), name, equippable=equippable_component) elif item_type == 'scroll': words = kwargs.get('words') lexicon = kwargs.get('lexicon') addendum = kwargs.get('addendum') text = [ 'The magic word for {} is {}.'.format(lexicon[word], word) for word in words ] if addendum: text.extend(addendum) item_component = Item(text=text) item = Entity(x, y, char, colors.get(color), name, render_order=RenderOrder.ITEM, item=item_component) return item
def place_item(room, entities): item_chance = NumberGenerator.random_integer(0, 100) x = NumberGenerator.random_integer(room.x1 + 1, room.x2 - 1) y = NumberGenerator.random_integer(room.y1 + 1, room.y2 - 1) if not any( [entity for entity in entities if entity.x == x and entity.y == y]): if item_chance < 50: item_component = Item(use_function=heal, amount="2d4+2") item = Entity(x, y, '+', tcod.pink, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 60: item_component = Item( attack_name="fireball", use_function=range_attack, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', tcod.light_cyan), damage=DiceRoll("2d12"), radius=3, range=10, attack_type='sphere') item = Entity(x, y, '#', tcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item( attack_name="dart", use_function=range_attack, targeting=True, targeting_message=Message( 'Left-click a target tile for the dart, or right-click to cancel.', tcod.light_cyan), damage=DiceRoll("2d12"), radius=0, range=3, attack_type='sphere') item = Entity(x, y, '>', tcod.red, 'Dart', render_order=RenderOrder.ITEM, item=item_component) return item
def make_random_wand(self, x, y): random_wand_type = get_random_key(self.wands) if random_wand_type == 'wand of digging': item_component = Item(use_function=cast_dig, directional_targeting=True, targeting_msg=Message( 'In which direction? (ESC to cancel)', Colors.WHITE), range=7, charges=5) item = Entity(x, y, '/', Colors.BROWN, 'wand of digging', render_order=RenderOrder.ITEM, item=item_component, description='blasts paths through the earth') elif random_wand_type == 'wand of blood': item_component = Item(use_function=cast_leech, directional_targeting=True, targeting_msg=Message( 'In which direction? (ESC to cancel)', Colors.WHITE), range=4, charges=3) item = Entity(x, y, '/', Colors.DARK_RED, 'wand of blood', render_order=RenderOrder.ITEM, item=item_component, description='steals the life force of your foes') else: item_component = Item(use_function=cast_gust_of_wind, directional_targeting=True, targeting_msg=Message( 'In which direction? (ESC to cancel)', Colors.WHITE), range=6, charges=5) item = Entity(x, y, '/', Colors.WHITE, 'wand of wind', render_order=RenderOrder.ITEM, item=item_component, description='unleashes a targeted blast of wind') return item
def place_entities(self, room, entities, max_monsters_per_room, max_items_per_room): # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) 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]): if randint(0, 100) < 80: fighter_component = Fighter(hp=10, defense=0, power=3) 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=16, defense=1, power=4) 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_chance = randint(0, 100) if item_chance < 70: item_component = Item(use_function=heal, amount=4) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 80: 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=12, radius=3) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 90: 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=20, 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, max_items_per_room): number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) ############################################################################################# enbbemy spawning 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 ]): # what the F**K is with this syntax (it's looking to see if there are any entities in that spot) if randint(0, 100) < 80: fighter_component = Fighter(hp = 10, defense = 0, power = 3) ai_component = BasicMonster() monster = Entity(x, y, 'o', libtcod.desaturated_green, 'orc', blocks=True,render_order = RenderOrder.ACTOR, fighter=fighter_component, ai = ai_component) # makes mostly orcs else: fighter_component = Fighter(hp = 16, defense = 1, power = 4) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'troll', blocks=True,render_order = RenderOrder.ACTOR, fighter=fighter_component, ai = ai_component) #sometimes trolls entities.append(monster) #adds monster to the list of entities ##################### ITEM GENERATION ############################################################################### 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_chance = randint(0, 100) ### this is where the type of item is determined. sub-type is per item # 00-70 if item_chance >= 0 and item_chance <= 30: ################################################################################################################################# # potions type_chance = randint(0,100) ## kind of potion that spanws ## 00-100 lesser healing pot if type_chance >= 0 and type_chance <= 100: item_component = Item(use_function=heal, amount=4) item = Entity(x,y,'!', libtcod.violet, 'Lesser Healing Potion', render_order =RenderOrder.ITEM, item=item_component) # 71-100 else: # scrolls type_chance = randint(0,100) ## 00-60 Minor lightning if type_chance >= 0 and type_chance <= 60: item_component = Item(use_function=cast_lightning, damage=20, maximum_range=5) item = Entity(x,y,'#', libtcod.light_yellow, 'Scroll of Minor Lightning', render_order =RenderOrder.ITEM, item=item_component) ## 61-80 Minor Fireball if type_chance >= 61 and type_chance <= 80: item_component = Item(use_function=cast_fireball,targeting=True,targeting_message=Message('Left click to target a tile, right click to canel', libtcod.light_cyan), damage=12, radius =3) item = Entity(x,y,'#', libtcod.light_red, 'Scroll of Minor Fireball', render_order =RenderOrder.ITEM, item=item_component) ## 81-100 Minor Fireball if type_chance >= 81 and type_chance <= 100: item_component = Item(use_function=cast_confuse,targeting=True,targeting_message=Message('Left click to target a tile, right click to canel', libtcod.light_cyan), duration = 10) item = Entity(x,y,'#', libtcod.light_blue, 'Scroll of Momentary Confusion', render_order =RenderOrder.ITEM, item=item_component) entities.append(item)
def placeEntities(self, room, entities, maxMonstersPerRoom, maxItemsPerRoom): nMonsters = randint(0, maxMonstersPerRoom) nItems = randint(0, maxItemsPerRoom) for i in range(nMonsters): 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 randint(0,100) < 80: fighterComponent = Fighter(hp = 10, defense = 0, power = 3) aiComponent = basicMonster() monster = Entity(x, y, 'O', tcod.Color(75,115,85), 'Orc', blocks = True, rOrder = renderOrder.actor, fighter = fighterComponent, ai = aiComponent) else: fighterComponent = Fighter(hp = 16, defense = 1, power = 4) aiComponent = basicMonster() monster = Entity(x, y, 'T', tcod.Color(10,70,30), 'Troll', blocks = True, rOrder = renderOrder.actor, fighter = fighterComponent, ai = aiComponent) entities.append(monster) for _ in range(nItems): 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]): itemComponent = Item(useFunction = heal, amount = 4) item = Entity(x, y, '!', tcod.violet, ' Healing Potion', rOrder = renderOrder.item, item = itemComponent) entities.append(item)
def from_json(json_data): x = json_data.get('x') y = json_data.get('y') char = json_data.get('char') colour = lc.Color( json_data.get('colour')[0], json_data.get('colour')[1], json_data.get('colour')[2]) name = json_data.get('name') blocks = json_data.get('blocks') render_order = RenderOrder(json_data.get('render_order')) fighter = Fighter.from_json( json_data.get('fighter')) if json_data.get('fighter') else None ai = ai_from_json(json_data.get('ai')) if json_data.get('ai') else None item = Item.from_json( json_data.get('item')) if json_data.get('item') else None inventory = Inventory.from_json( json_data.get('inventory')) if json_data.get('inventory') else None stairs = Stairs.from_json( json_data.get('stairs')) if json_data.get('stairs') else None equipment = Equipment.from_json( json_data.get('equipment')) if json_data.get('equipment') else None level = Level.from_json( json_data.get('level')) if json_data.get('level') else None equip = Equip.from_json( json_data.get('equip')) if json_data.get('equip') else None return Entity(x, y, char, colour, name, blocks, render_order, fighter, ai, item, inventory, stairs, level, equipment, equip)
def place_entities(self, room, entities, max_monsters_per_room, max_items_per_room): # Get a random numer of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) 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 ]): if randint(0, 100) < 80: fighter_component = Fighter(hp=10, defense=0, power=3) 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=16, defense=1, power=4) 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.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_component = Item() item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def __init__(self, x, y, char, colour, name, blocks=False, render_order=RenderOrder.CORPSE, fighter=None, ai=None, item=None, inventory=None, stairs=None, level=None, equipment=None, equippable=None): self.x = x self.y = y self.char = char self.colour = colour self.name = name self.blocks = blocks self.render_order = render_order self.fighter = fighter self.ai = ai self.item = item self.inventory = inventory self.stairs = stairs self.level = level self.equipment = equipment self.equippable = equippable if self.fighter: self.fighter.owner = self if self.ai: self.ai.owner = self if self.item: self.item.owner = self if self.inventory: self.inventory.owner = self if self.stairs: self.stairs.owner = self if self.level: self.level.owner = self if self.equipment: self.equipment.owner = self if self.equippable: self.equippable.owner = self if not self.item: item = Item() self.item = item self.item.owner = self
def __init__(self, char, color, name, blocks: bool = False, position=None, render_order=RenderOrder.CORPSE, fighter=None, ai=None, item=None, inventory=None, stairs=None, level=None, equipment=None, equippable=None): self.pos = position self.render = RenderData(char, color, render_order) self.name = name self.blocks = blocks self.fighter = fighter self.ai = ai self.item = item self.inventory = inventory self.stairs = stairs self.level = level self.equippable = equippable self.equipment = equipment if self.fighter: self.fighter.owner = self if self.ai: self.ai.owner = self if self.item: self.item.owner = self if self.inventory: self.inventory.owner = self if self.stairs: self.stairs.owner = self if self.level: self.level.owner = self if self.equipment: self.equipment.owner = self if self.equippable: self.equippable.owner = self if not self.item: self.item = Item() self.item.owner = self
def generate_item(item_name, x, y, game_map=None): item = get_items_list(item_name) use_function = item.get('use_function') power = item.get('power') aspect = item.get('aspect') color = item.get('color') name = item.get('name') targeting_message = item.get('targeting_message') text_color = item.get('text_color') radius = item.get('radius') targeting = item.get('targeting') maximum_range = item.get('maximum_range') damage_type = item.get('damage_type') stackable = item.get('stackable') item_component = Item(use_function=use_function, power=power, game_map=game_map, targeting_message=Message(targeting_message, text_color), radius=radius, targeting=targeting, maximum_range=maximum_range, damage_type=damage_type, stackable=stackable) item_to_return = Entity(x, y, aspect, color, name, render_order=RenderOrder.ITEM, item=item_component) return item_to_return
def place_entities(self,room,entities,max_monsters_per_room,max_items_per_room): #get rand no. of monsters number_of_monsters=randint(0,max_monsters_per_room) number_of_items=randint(0,max_items_per_room) for i in range(number_of_monsters): #choose rand location 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 randint(0,100)<80: fighter_component=Fighter(hp=10,defence=0,power=3) 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=16,defence=1,power=4) 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.x1+1,room.x2-1) y=randint(room.y1+1,room.y2-1) if not any([entity for entity in entities if entity.x==entity.y==y]): item_component=Item(use_function=heal,amount=4) item=Entity(x,y,"!",libtcod.violet,"Healing Potion",render_order=RenderOrder.ITEM,item=item_component) entities.append(item)
def get_items_from_file(self,file_path): items = list() with open(file_path) as items_file: data = json.load(items_file) for d in data: items.append(Item(d,self)) return items
def generate_starting_pistol(log): # sort of a weird one, this function puts together the Ascetic's Pistol that every run begins with components = { 'Item': Item(use_function=starting_pistol['functions'], uses=starting_pistol['uses'], item_type=starting_pistol['type'], equip_effects=starting_pistol['equip_abilities'], strength=starting_pistol['strength'], defense=0, price=starting_pistol['price'], **starting_pistol['kwargs']) } gun = Entity(0, 0, starting_pistol['icon'], starting_pistol['color'], starting_pistol['name'], blocks=False, render_order=RenderOrder.ITEM, message_log=log, state=AIStates.INANIMATE, components=components) return gun
def get_game_variables(constants): # Entities fighter_component = Fighter(hp=10000, defense=1, strength=200, dexterity=0, intelligence=0, charisma=0) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcodpy.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] for itm in range(0, 25): item_component = Item(use_function=heal, amount=40) item = Entity(0, 0, '!', libtcodpy.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) player.inventory.add_item(item) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, strength_bonus=2) dagger = Entity(0, 0, '-', libtcodpy.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) # Game Map 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 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 __init__(self, x, y, char, color, name, impassable=False, render_order=RenderOrder.CORPSE, fighter=None, ai=None, item=None, inventory=None, stairs=None, level=None, equipment=None, equippable=None, regeneration=None, vendor=None, description=None): #BASE TRAITS WHICH ALL ENTITIES POSSESS self.x = x self.y = y self.char = char self.color = color self.name = name self.description = description self.impassable = impassable self.render_order = render_order #OPTIONAL COMPONENTS self.fighter = fighter self.ai = ai self.item = item self.inventory = inventory self.stairs = stairs self.level = level self.equipment = equipment self.equippable = equippable self.regeneration = regeneration self.vendor = vendor if self.fighter: self.fighter.owner = self if self.ai: self.ai.owner = self if self.item: self.item.owner = self if self.inventory: self.inventory.owner = self if self.stairs: self.stairs.owner = self if self.vendor: self.vendor.owner = self if self.level: self.level.owner = self if self.equipment: self.equipment.owner = self if self.equippable: self.equippable.owner = self #all equippables must possess item components to be carried in inventory if not self.item: self.item = Item() self.item.owner = self if self.regeneration: self.regeneration.owner = self
def place_entities(self, room, entities, max_monsters_per_room, max_items_per_room): number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) # Monsters for i in range(number_of_monsters): rand_x = randint(room.x1 + 1, room.x2 - 1) rand_y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == rand_x and entity.y == rand_y]): if randint(0, 100) < 80: o_f_comp = Fighter(10, 0, 3) o_ai_comp = BasicMonster() monster = Entity(rand_x, rand_y, 'o', libtcod.desaturated_green, 'Orc', True, RenderOrder.ACTOR, o_f_comp, o_ai_comp) else: t_f_comp = Fighter(16, 1, 4) t_ai_comp = BasicMonster() monster = Entity(rand_x, rand_y, 'T', libtcod.darker_green, 'Troll', True, RenderOrder.ACTOR, t_f_comp, t_ai_comp) entities.append(monster) # Items for i in range(number_of_items): rand_x = randint(room.x1 + 1, room.x2 - 1) rand_y = randint(room.y1 + 1, room.y2 - 1) if not any([entity for entity in entities if entity.x == rand_x and entity.y == rand_y]): item_chance = randint(0, 100) if item_chance < 60: item_heal_comp = Item(use_function=itm_heal, amount=4) item = Entity(rand_x, rand_y, '!', libtcod.violet, 'Healing Potion', render_order = RenderOrder.ITEM, item=item_heal_comp) elif item_chance < 75: 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=12, radius=3) item = Entity(rand_x, rand_y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_chance < 90: 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(rand_x, rand_y, '#', libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_scroll_lightning_comp = Item(use_function=cast_lightning, damage=20, maximum_range=5) item = Entity(rand_x, rand_y, '#', libtcod.yellow, 'Lightning Scroll', render_order = RenderOrder.ITEM, item=item_scroll_lightning_comp) entities.append(item)
def __init__(self, x, y): super().__init__(x, y, 'y', libtcod.violet, 'Magic Chalice', render_order=RenderOrder.ITEM) Item(use_function=item_functions.rub_chalice).add_to_entity(self)
def __init__(self, x, y): super().__init__(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM) Item(use_function=item_functions.heal, amount=40).add_to_entity(self)
def init_player_and_entities(player_name): """ 플레이어 """ fighter_component = Fighter(hp=30, sanity=100, defense=2, power=5) luminary_component = Luminary(luminosity=10) inventory_component = Inventory(26) equipment_comp = Equipment() player = Entity(int(MAP_WIDTH / 2), int(MAP_HEIGHT / 2), '@', tcod.white, player_name, blocks=True, render_order=RenderOrder.ACTOR, _Luminary=luminary_component, _Fighter=fighter_component, _Inventory=inventory_component, _Equipment=equipment_comp) entities = [player] i_comp = Item(use_function=read, about='당신과 당신의 절친, 메리가 같이 한 일들이 적혀 있다' ) #about activities of you and your best friend, Mary Journal = Entity(player.x, player.y, ':', tcod.darkest_red, '수첩', render_order=RenderOrder.ITEM, _Item=i_comp) i_comp = Item(use_function=talisman) Talisman = Entity(player.x, player.y, '*', tcod.lighter_purple, '시계꽃 부적', render_order=RenderOrder.ITEM, _Item=i_comp) player._Inventory.items.append(Journal) player._Inventory.items.append(Talisman) return player, entities
def __init__(self, x, y, name, char, color, fighter: Fighter = None, ai: BasicMonster = None, item: Item = None, inventory: Inventory = None, stairs: Stairs = None, level: Level = None, equipement: Equipement = None, equippable: Equippable = None, render_order: RenderOrder = RenderOrder.CORPSE): self.x = x self.y = y self.name = name self.char = char self.color = color self.fighter = fighter self.ai = ai self.item = item self.inventory = inventory self.stairs = stairs self.level = level self.equipement = equipement self.equippable = equippable self.render_order = render_order if self.fighter: self.fighter.owner = self if self.ai: self.ai.owner = self if self.item: self.item.owner = self if self.inventory: self.inventory.owner = self if self.stairs: self.stairs.owner = self if self.level: self.level.owner = self if self.equipement: self.equipement.owner = self if self.equippable: self.equippable.owner = self if not self.item: item = Item() self.item = item self.item.owner = self
def make(self): target_msg = Message('Left-click to cast, right-click to cancel', tcod.light_cyan) item_component = Item(use_function=cast_paralysis, targeting=True, targeting_message=target_msg) item = Entity(0, 0, '#', tcod.pink, 'Paralysis Tome', True, render_order=RenderOrder.ITEM, item=item_component) return item
def __init__(self, x, y, char, colour, name, blocks=False, render_order=RenderOrder.CORPSE, combat_entity=None, ai=None, item=None, inventory=None, bonfire=None, level=None, page=None, book=None, spells=[], effects=[], score=0): self.x = x self.y = y self.char = char self.colour = colour self.name = name self.blocks = blocks self.render_order = render_order self.combat_entity = combat_entity self.ai = ai self.item = item self.inventory = inventory self.bonfire = bonfire self.level = level self.page = page self.book = book self.spells = spells self.effects = effects self.haste_bonus = 0 self.score = 0 # Using composition instead of inheritance to build entities that can do different things. if self.combat_entity: self.combat_entity.owner = self if self.ai: self.ai.owner = self if self.item: self.item.owner = self if self.inventory: self.inventory.owner = self if self.bonfire: self.bonfire.owner = self if self.level: self.level.owner = self if self.book: self.book.owner = self if self.page: self.page.owner = self if not self.item: item = Item() self.item = item self.item.owner = self if self.spells: self.spells.owner = self if self.effects: self.effects.owner = self
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', 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] equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) dagger = Entity(0, 0, '-', libtcod.darker_orange, "Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) item_component = Item(use_function=cast_magic, damage=2, maximum_range=3) magic_wand = Entity(0, 0, '|', libtcod.darker_sepia, "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) 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 __init__(self, x, y): super().__init__(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM) Item(use_function=item_functions.cast_lightning, damage=40, maximum_range=5).add_to_entity(self)
def create_potion(point, usable): item = Entity(point, chr(173), usable.name, COLORS.get('equipment_uncommon'), render_order=RenderOrder.ITEM, item=Item(), usable=usable) return potion_description(item)
def place_entities(self, room, entities, max_monsters, max_items): # Get random number for monsters num_monsters = randint(0, max_monsters) num_items = randint(0, max_items) for i in range(num_monsters): # Pick 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]): if randint(0, 100) < 80: fighter_comp = Fighter(hp=10, defense=0, power=3) ai_comp = BasicMonster() monster = Entity(x, y, 'O', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_comp, ai=ai_comp) else: fighter_comp = Fighter(hp=16, defense=1, power=4) ai_comp = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_comp, ai=ai_comp) entities.append(monster) for i in range(num_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_chance = randint(0, 100) if item_chance < 70: item_comp = Item(use_function=heal, amount=4) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_comp) else: item_comp = Item(use_function=lightning_attack, damage=20, max_range=5) item = Entity(x, y, '#', libtcod.Color(255, 255, 0), 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_comp) entities.append(item)