Example #1
0
    def finalize(self):
        super(MagicDamageConsequence, self).finalize()

        from typeclasses.scripts.combat import attacks, combat_settings

        victims = [participant.character for participant in self.participants]
        names = [obj.name for obj in victims]
        commafied_names = commafy(names)

        attack = attacks.Attack(targets=victims,
                                affect_real_dmg=True,
                                damage=self.damage,
                                use_mitigation=False,
                                can_kill=True,
                                private=False,
                                story="Magic has consequences!",
                                attack_tags=self.attack_tags)
        try:
            attack.execute()
        except combat_settings.CombatError as err:
            logger.log_err("Combat error when applying magical damage: " +
                           str(err))
            inform_staff(
                "|rCombat Error!|n Tried to apply %d damage to %s, but got error %s"
                % (self.damage, commafied_names, str(err)))
        else:
            part = "was"
            if len(victims) > 1:
                part = "were"
            inform_staff(
                "|y%s|n %s harmed for %d by a failed magical working." %
                (commafied_names, part, self.damage))
Example #2
0
    def advance_weekly_practice(self, practitioner):

        potential_factor = int(practitioner.potential ** (1 / 10.0))

        max_spend = min(
            practitioner.potential / ((potential_factor ** 2) * 10),
            practitioner.unspent_resonance,
        )
        nodes = practitioner.node_resonances.filter(practicing=True)
        if nodes.count() == 0:
            return None

        noderesults = []
        nodenames = []

        # Get a floating point value of how much resonance to add to each node
        spend_each = max_spend / (nodes.count() * 1.0)
        for node in nodes.all():
            nodenames.append(node.node.name)
            add_node = spend_each
            extra = ""
            teacher = ""
            if node.teaching_multiplier:
                add_node *= node.teaching_multiplier
                teacher = node.taught_by
                extra = "(taught by {} for bonus of {}x)".format(
                    str(node.taught_by), node.teaching_multiplier
                )

            if _MAGIC_LOG_ENABLED:
                logger.log_info(
                    "Magic: {} spent {} resonance on node {} for gain of {} {}".format(
                        str(practitioner), spend_each, node.node.name, add_node, extra
                    )
                )

            node.raw_resonance = node.raw_resonance + add_node

            noderesults.append(
                {
                    "node": node.node.name,
                    "gain": add_node,
                    "resonance": node.raw_resonance,
                    "teacher": teacher,
                }
            )

            node.teaching_multiplier = None
            node.taught_by = None
            node.taught_on = None
            node.save()

        self.inform_creator.add_player_inform(
            player=practitioner.character.dompc.player,
            msg="You practiced {} this week.".format(commafy(nodenames)),
            category="Magic",
        )

        return {"name": str(practitioner), "practices": noderesults}
Example #3
0
    def get_display(self):
        values = self.get()
        if not values or len(values) == 0:
            return "None"

        results = []
        for value in values:
            char_obj = self._get_character(value)
            results.append(char_obj.key)

        return commafy(results)
Example #4
0
    def results_string(self):
        victims = [
            participant.character.name for participant in self.participants
        ]
        commafied_names = commafy(victims)
        part = "was"
        if len(victims) > 1:
            part = "were"

        return "{} {} damaged for {} damage of types {}.".format(
            commafied_names, part, self.damage, self.attack_tags)
Example #5
0
    def see_through_contents(self):

        other_room = self.destination
        haven_square = None
        if hasattr(other_room, "shardhaven_square"):
            haven_square = other_room.shardhaven_square

        characters = []
        character_string = None

        for testobj in other_room.contents:
            if testobj.has_account or (hasattr(testobj, "is_character")
                                       and testobj.is_character):
                characters.append(testobj.name)

        if len(characters):
            character_string = commafy(characters)
        elif haven_square and haven_square.monster:
            if haven_square.monster.npc_type == Monster.MOOKS:
                character_string = haven_square.monster.plural_name
            else:
                character_string = haven_square.monster.name

        puzzle_string = None
        if haven_square and haven_square.puzzle and not haven_square.puzzle_solved:
            puzzle_string = haven_square.puzzle.display_name

        result = "You see nothing of note in the next room."
        if character_string:
            result = "In the next room, you see " + character_string + "."
            if puzzle_string:
                puzzle_part = a_or_an(puzzle_string)
                result += "  And {} {}.".format(puzzle_part, puzzle_string)
        elif puzzle_string:
            puzzle_part = a_or_an(puzzle_string)
            result = "In the next room, you see {} {}.".format(
                puzzle_part, puzzle_string)

        return result