def _onStateChanged(self, state): if state == self.Running: running_animations.append(self) if self.dic.get('__reparent'): self.dic['__old_parent'] = self.widget.parentItem() self.widget.setParentItem(self.dic['__reparent']) elif state == self.Stopped: try: attr = getattr(self.dic['widget'], 'set' + str(self.propertyName()).capitalize()) except RuntimeError: logger.ddebug('runtime error for {}'.format(self)) #FUCKIT return attr(self.__new) self.__new = None if self.dic.get('__reparent'): self.widget.setParentItem(self.dic['__old_parent']) self.dic.pop('__reparent') self.dic.pop('__old_parent') running_animations.remove(self)
def on_spell_teleportation(self, spell, tile, being, attacker): logger.ddebug('{} teleported to {}'.format(spell.target.being, spell.target)) if self.player_can_see(tile): self.events['being_became_invisible'].emit(spell.target.being.guid) if self.player_can_see(spell.target): self.events['being_became_visible'].emit(spell.target.idx, spell.target.being.view())
def _take_damage(self, attackee, attacker, damage): if attacker: logger.ddebug('{ar.You} {ar.inflict} {hp} hit points of damage on {ae.your_self}.'.format( ar=attacker.words, ae=attackee.words, hp=damage)) else: logger.ddebug('{hp} hit points of damage is inflected on {ae.your_self}.'.format(ae=attackee.words, hp=damage)) attackee.hit_points -= damage if attackee.is_dead: self.controller.die(attackee, attacker)
def zap(self, being, wand, direction): if wand.charges < 1: logger.msg_info('{You} cannot zap a wand without charges.'.format(**being.words_dict)) return False wand.item.charges -= 1 tile = self.game.level.tile_for(being) spell = wand.spell first = True # if its ray we now know it. if not wand.item.known and wand.kind.bounce: wand.item.known = True # if we have a ray or a beam if wand.kind.ray_dice: length = wand.kind.ray_dice.roll() while length > 0: tiles = self.game.level.get_ray(tile, direction, length+1, all_types=wand.item.can_tunnel) if first: tiles = tiles[1:] length -= len(tiles) self.events['wand_zapped'].emit(spell.view(), [t.idx for t in tiles], direction) for t in tiles: logger.ddebug('A {} passes through {}.'.format(wand.item.zap, t)) other = tile.being if spell.damage and t.being: if self.player_can_see(t): logger.msg_warn("The {zap} hits {you}.".format(zap=wand.item.zap, **t.being.words_dict)) else: logger.ddebug("The (unseen) {zap} hits {you}.".format(zap=wand.item.zap, **t.being.words_dict)) if self.combat_arena.spell_attack(tile, t, spell): wand.item.known = True if spell.method and spell.handle(self.game, t): wand.item.known = True logger.msg_warn('The wand {} {}.'.format(spell.verb.she, t.being)) self.handle_spell(spell, t, other, tile.being) # if the wand does not bounce or the tiletype does not bouce then stop if not (tiles[-1].tiletype.bounce and wand.kind.bounce): break direction = direction.bounce(tiles[-1].tiletype.bounce) tile = self.game.level.adjacent_tile(tiles[-1], direction) first = False elif spell.method and spell.handle(self.game, tile): wand.item.known = True self.handle_spell(spell, tile, being) if not being.is_dead: self.turn_done(being) return True
def spell_attack(self, subject, target, spell): attackee = target.being attacker = subject.being if attacker: logger.ddebug('{} casting {} on {}.'.format(attacker.words.You_are, spell, attackee.words.your_self)) else: logger.ddebug('{} is cast upon {}.'.format(str(spell).capitalize(), attackee.words.your_self)) if [c for c in attackee.conditions if c.spell_resistance == spell.name]: logger.msg_info('{} resits the {} spell.'.format(attackee.words.You, spell.name)) self.controller.events['being_spell_resistance'].emit(target.idx, attackee.guid, spell.view()) else: damage = spell.damage.roll() logger.msg_debug("The {} spell does {} damage on {}".format(spell.name, damage, attackee)) self.controller.events['being_spell_damage'].emit(target.idx, attackee.guid, spell.view()) self._take_damage(attackee, attacker, damage) return True
def die(self, being, attacker=None): t = self.game.level.tile_for(being) if attacker: attacker.experience += int(being.value) if self.player_can_see(t): if attacker: target = being.words.your_self if being is attacker else being.words.you logger.msg_fatal('{ar.You} {ar.kill} {target}!'.format(ar=attacker.words, target=target)) else: logger.msg_fatal('{You_are} killed!'.format(**being.words_dict)) else: logger.ddebug('An unseen {} dies!'.format(being)) self.game.level.kill_being(being) if being.has_been_seen: self.events['being_died'].emit(t.idx, being.guid) if self.game.player is being: self.game.die() return True
def turn_done(self, being): if being.is_dead: return False player = self.game.player vision = player.vision if being is player: self.game.turn_done() changed = [t for t in self.game.level.values() if vision.has_changed(t)] if changed: self.events['tiles_changed_state'].emit([t.view(player) for t in changed]) for tile in [t for t in changed if t.being]: if self.player_can_see(tile): logger.ddebug('!!! {} became visible on {}.'.format(tile.being.words.You, tile)) self.events['being_became_visible'].emit(tile.idx, tile.being.view()) tile.being.has_been_seen = True else: logger.ddebug('!!! {} became invisible on {}.'.format(tile.being.words.You, tile)) self.events['being_became_invisible'].emit(tile.being.guid) return True
def move(self, subject, target): if not target: logger.msg_impossible("There is no tile for {you} to move there.".format(**subject.being.words_dict)) return False elif target.being: logger.msg_impossible("{You} cannot move into a square with a monster!".format(**subject.being.words_dict)) return False elif not target.tiletype.is_open: logger.msg_impossible("{You} cannot move through {tiletype}.".format(tiletype=target.tiletype, **subject.being.words_dict)) return False being = subject.being self.game.level.move_being(subject, target) target_seen = self.player_can_see(target) subject_seen = self.player_can_see(subject) # if we are the player we always know about it if being.is_player: if not target.inventory: logger.debug('{You} {move} to {}.'.format(target, **being.words_dict)) else: logger.msg_info('{You_are} standing on {}.'.format(target.inventory, **being.words_dict)) self.events['being_moved'].emit(subject.idx, target.idx, being.guid, being.direction) # else if a monster just walked out of the dark elif target_seen and not subject_seen: logger.ddebug('{} came out of the dark onto {}.'.format(being.words.You, target)) self.events['being_became_visible'].emit(subject.idx, being.view()) self.events['being_moved'].emit(subject.idx, target.idx, being.guid, being.direction) being.has_been_seen = True # else if a monster just walked into the dark elif subject_seen and not target_seen: logger.ddebug('{} went into the dark onto {}.'.format(being.words.You, target)) self.events['being_moved'].emit(subject.idx, target.idx, being.guid, being.direction) self.events['being_became_invisible'].emit(being.guid) # else if we watched the monster move elif subject_seen and target_seen: logger.ddebug('The player watched {} move onto {}.'.format(target.being, target)) self.events['being_moved'].emit(subject.idx, target.idx, being.guid, being.direction) else: logger.ddebug('{} moved to {}, but the player did not see it.'.format(target.being.words.You, target)) self.turn_done(target.being) return True
def _onBeingAdded(self, widget): self._beings[widget['guid']] = widget logger.ddebug('Adding {} to being dic.'.format(widget))