def create_boss(self): def en_collision(state, e1, e2): if e2.contains_component(Player): combat = e1.get_component(InitiateCombat) state.combat_launch_entity = e1 combat.on_interact(state) self.combat_mechanic.enemies[1] = copy.copy( e1.get_component(InitiateCombat).combat_entities[0]) self.combat_mechanic.enemies[1].get_component( Stats).reinit_HP() return Entity('Boss').add_component( Combat(copy.deepcopy(self.load_combat_images.obtain('Boss'))), Stats(10, (4, 8, 3, 1)), Position(None, None, None), AlignedBox(-4.5, -4.5, 4.5, 4.5), Collider(en_collision), GridMovement(C.PLAYER_WALK_RELOAD), Orientable(C.DIRECTION_E, C.PLAYER_WALK_RELOAD), Sprite({ tuple(self.load_images.obtain_entity('Boss', 1)): lambda e: e.get_component(Orientable).orientation == C. DIRECTION_N, tuple(self.load_images.obtain_entity('Boss', 1)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_O, tuple(self.load_images.obtain_entity('Boss', 1)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_S, tuple(self.load_images.obtain_entity('Boss', 1)): lambda e: True }))
def create_devil(self): sprite_img = self.load_combat_images.obtain('Devil') sprite_img.width = 48 sprite_img.height = 48 return Entity('Devil').add_component( Combat(copy.deepcopy(self.load_combat_images.obtain('Devil'))), Stats(20, (0.2, 0, 2, 1)), Position(None, None, None), AlignedBox(-0.5, -0.5, 0.5, 0.5), GridMovement(C.PLAYER_WALK_RELOAD), Orientable(C.DIRECTION_E, C.PLAYER_WALK_RELOAD), Sprite({sprite_img: lambda e: True}))
def setUp(self): self.game_manager = GameManager() level = Level() level.name = "DEFAULT" level.min_room_size = 1 level.max_room_size = 10 level.max_rooms = 10 level.width = 80 level.height = 45 self.game_manager.game_context.player = self.game_manager.game_context.character_factory.create( "test", "warrior", "human", Stats(), "humanoid") self.game_manager.init_dungeon(level) self.level = level
def build_leather_hood(): _item = Item( uid="hood", name="hood", description="A leather hood.", display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"), ) _item.register_component(data.python_templates.material.Leather.copy()) _item.register_component(Stats(health=10, size=Size.Medium, weight=2)) _item.register_component( Armor(base_armor_class=2, armor_category=item_enums.ArmorCategory.Medium, wearable_body_parts_uid=["humanoid_head"], worn_layer=item_enums.WornLayer.Outer)) return _item
def build_long_sword(): _long_sword = Item( uid="long_sword", name="Longsword", description="A longsword.", display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"), ) _long_sword.register_component(data.python_templates.material.Iron.copy()) _long_sword.register_component(Stats(health=1, size=Size.Medium)) _long_sword.register_component( Weapon(weapon_category=item_enums.WeaponCategory.Martial, weapon_type=item_enums.WeaponType.Melee, size=Size.Medium, melee_damage_type=DamageType.Slash, damage_dice=DiceStack(1, Dice(8)))) return _long_sword
def build_boot(): _boot = Item( uid="boot", name="Boot", description="An iron boot", display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"), ) _boot.register_component(data.python_templates.material.Iron.copy()) _boot.register_component(Stats(health=10, size=Size.Medium, weight=0.5)) _boot.register_component( Armor(base_armor_class=0.5, armor_category=item_enums.ArmorCategory.Medium, wearable_body_parts_uid=["humanoid_foot"], worn_layer=item_enums.WornLayer.Outer, maximum_dexterity_bonus=2)) return _boot
def build_leather_pants(): # TODO Some items need to take two slots rather than one. item = Item( uid="pants", name="pants", description="Leather pants", display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"), ) item.register_component(data.python_templates.material.Leather.copy()) item.register_component(Stats(health=10, size=Size.Medium, weight=0.5)) item.register_component( Armor(base_armor_class=1, armor_category=item_enums.ArmorCategory.Medium, wearable_body_parts_uid=["humanoid_leg"], worn_layer=item_enums.WornLayer.Outer, maximum_dexterity_bonus=2)) return item
def create_player(self): return Entity().add_component( Stats(5), Inventory(), Controllable(), GridMovement(C.PLAYER_WALK_RELOAD), Orientable(C.DIRECTION_O, C.PLAYER_WALK_RELOAD), Position(None, None, None), AlignedBox(-0.5, -0.5, 0.5, 0.5), Sprite({ tuple(self.load_images.obtain_entity('Player', 3)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_N, tuple(self.load_images.obtain_entity('Player', 1)): lambda e: e.get_component(Orientable).orientation == C. DIRECTION_O, tuple(self.load_images.obtain_entity('Player', 0)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_S, tuple(self.load_images.obtain_entity('Player', 2)): lambda e: True }), Player())
def create_wolf(self): return Entity('Wolf').add_component( Combat(copy.deepcopy(self.load_combat_images.obtain('Wolf'))), Stats(30, (0.2, 0, 3, 1)), Position(None, None, None), AlignedBox(-0.5, -0.5, 0.5, 0.5), GridMovement(C.PLAYER_WALK_RELOAD), Orientable(C.DIRECTION_E, C.PLAYER_WALK_RELOAD), Sprite({ tuple(self.load_images.obtain_entity('Wolf', 3)): lambda e: e.get_component(Orientable).orientation == C. DIRECTION_N, tuple(self.load_images.obtain_entity('Wolf', 1)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_O, tuple(self.load_images.obtain_entity('Wolf', 0)): lambda e: e.get_component(Orientable ).orientation == C.DIRECTION_S, tuple(self.load_images.obtain_entity('Wolf', 2)): lambda e: True }))
def create_bat(self): return Entity('Bat').add_component( Combat(copy.deepcopy(self.load_combat_images.obtain('Bat'))), Stats(15, (0.1, 0, 1, 1)), )
from __future__ import annotations from json import load as json_load from entity import Actor from components.ai import HostileEnemy from components.level import Level from components.inventory import Inventory from components.stats import Stats RACES: None try: with open('res/races.json') as f: RACES = json_load(f) except FileNotFoundError: raise FileNotFoundError() HUMAN = RACES['human'] human = Actor( char=RACES['human']['char'], color=RACES['human']['color'], name=str(RACES['human']['name']['singular'].capitalize()), ai_cls=HostileEnemy, stats=Stats(stats=RACES['human']['stats']), level=Level(), # TODO inventory=Inventory())