def decrease_hp(self, delta): operation_log = OperationLog() if self.armour and self.armour.item.defense > 0: self.armour.item.defense -= delta if self.armour.item.defense <= 0: delta = (-1) * self.armour.item.defense self.owner.color = self.owner.main_color self.max_defense -= self.armour.item.max_defense operation_log.add_item({ 'message': Message('Armour destroyed.', self.armour.item.color) }) self.armour = None else: delta = 0 if self.defense > 0: self.defense -= delta if self.defense < 0: delta = (-1) * self.defense self.defense = 0 else: delta = 0 self.hp -= delta if self.hp <= 0: operation_log.add_item({'dead': self.owner}) return operation_log
def drop_item(self, entities, item_entity): operation_log = OperationLog() item_entity.x = self.owner.x item_entity.y = self.owner.y entities.append(item_entity) self.del_item(item_entity) operation_log.add_item( {'message': Message(f'You dropped {item_entity.name}', tc.yellow)}) return operation_log
def pick_item(self, item): operation_log = OperationLog() if item.item.type == ItemType.HP_PTN: operation_log.add_item({ 'message': Message(f'+{item.item.hp_up} HP potion!', tc.green) }) self.stats.increase_hp(5) self.inventory.del_item(item) elif item.item.type == ItemType.INTOX_PTN: operation_log.add_item( {'message': Message('You\'re intoxicated!', tc.fuchsia)}) if self.mv_handler.intox_start_time: self.mv_handler.intox_start_time += item.item.intox_time else: self.mv_handler.set_intox_start_time(time.time()) self.inventory.del_item(item) return operation_log
def kill_mob(mob): name = mob.name mob.char = ord('#') mob.color = tc.dark_grey mob.is_blocking = False mob.stats = None mob.act = lambda *args, **kwargs: OperationLog() mob.name = 'died ' + mob.name mob.render_order = RenderOrder.DEAD_ENTITY if mob.item is not None: if mob.item.type == ItemType.HP_PTN: mob.char = ord(' ') return Message('', tc.fuchsia), State.HEALTH_UP if mob.item.type == ItemType.INTOX_PTN: mob.char = ord(' ') return Message('', tc.fuchsia), State.INTOXICATE if name == 'Aggr': return Message(f'{name} is dead!', tc.yellow) return Message(f'{name} is dead!', tc.yellow)
def get_item(self, entities): operation_log = OperationLog() for entity in entities: if entity.x == self.x and entity.y == self.y: if isinstance(entity, Mob) and entity.item is not None: operation_log = OperationLog() if not self.inventory.add_item(entity): operation_log.add_item({ 'new_item': None, 'message': Message('Inventory is full.', tc.yellow) }) else: operation_log.add_item({ 'new_item': entity, 'message': Message(f'New item {entity.name}!', tc.light_azure) }) break return operation_log
def attack_target(self, target): operation_log = OperationLog() if not target.stats: return operation_log damage = self.force if damage > 0: if isinstance(target, Player) or target.item is None: operation_log.add_item({ 'message': Message( f'{self.owner.name} damaged {target.name} in {damage} hps.', tc.white) }) operation_log.log.extend(target.stats.decrease_hp(damage).log) return operation_log
def activate_item(self, item_entity): operation_log = OperationLog() if item_entity.item is not None: if item_entity.item.type == ItemType.ARMOUR_I: if self.owner.stats.armour: self.items.append(self.owner.stats.armour) self.owner.stats.max_defense -= self.owner.stats.armour.item.max_defense self.owner.color = self.owner.main_color self.owner.stats.armour = None self.owner.stats.armour = item_entity self.owner.main_color = self.owner.color self.owner.color = item_entity.item.color self.owner.stats.max_defense += item_entity.item.max_defense operation_log.add_item( {'message': Message('Armour activated.', tc.yellow)}) self.items.remove(item_entity) return operation_log
def kill_player(player): player.char = ord('X') player.color = tc.darker_fuchsia return Message("You're DEAD. GAME OVER", tc.dark_red)