Esempio n. 1
0
def sample_char(char, archetype, race, focus=None):
    """Loads sample traits onto a character.

    Args:
        char (Character): character to load traits
        archetype (str): name of base archetype
        race (str): name of race to become
        focus Optional(str): focus to apply. if None, default is race's
            first item in foci collection
        """
    archetypes.apply_archetype(char, archetype, reset=True)
    char.traits.STR.base += 1
    char.traits.PER.base += 1
    char.traits.INT.base += 1
    char.traits.DEX.base += 1
    char.traits.CHA.base += 1
    char.traits.VIT.base += 2
    char.traits.MAG.base += 2
    focus = focus or races.load_race(race).foci[0]
    races.apply_race(char, race, focus)
    archetypes.calculate_secondary_traits(char.traits)
    archetypes.finalize_traits(char.traits)
    tickerhandler.add(char, 6, hook_key='at_turn_start')
    skills.apply_skills(char)
    skills.finalize_skills(char.skills)
Esempio n. 2
0
def sample_char(char, archetype, race, focus=None):
    """Loads sample traits onto a character.

    Args:
        char (Character): character to load traits
        archetype (str): name of base archetype
        race (str): name of race to become
        focus Optional(str): focus to apply. if None, default is race's
            first item in foci collection
        """
    archetypes.apply_archetype(char, archetype, reset=True)
    char.traits.STR.base += 1
    char.traits.PER.base += 1
    char.traits.INT.base += 1
    char.traits.DEX.base += 1
    char.traits.CHA.base += 1
    char.traits.VIT.base += 2
    char.traits.MAG.base += 2
    focus = focus or races.load_race(race).foci[0]
    races.apply_race(char, race, focus)
    archetypes.calculate_secondary_traits(char.traits)
    archetypes.finalize_traits(char.traits)
    tickerhandler.add(interval=6, callback=char.at_turn_start)
    skills.apply_skills(char)
    skills.finalize_skills(char.skills)
Esempio n. 3
0
 def test_finalize_skills(self):
     """test module function `finalize_skills`"""
     skills.apply_skills(self.char1)
     # allocate skills for char1
     sk = self.char1.skills
     sk.escape.minus += 1
     sk.climb.minus += 1
     sk.jump.minus += 1
     sk.medicine.plus += 1
     skills.finalize_skills(sk)
     # confirm the plusses and minuses are applied
     self.assertEqual(sk.escape.actual, 7)
     self.assertEqual(sk.climb.actual, 7)
     self.assertEqual(sk.jump.actual, 7)
     self.assertEqual(sk.medicine.actual, 3)
     # confirm plus/minus counters are deleted
     with self.assertRaises(AttributeError):
         x = sk.escape.plus
     with self.assertRaises(AttributeError):
         x = sk.escape.minus
Esempio n. 4
0
 def test_finalize_skills(self):
     """test module function `finalize_skills`"""
     skills.apply_skills(self.char1)
     # allocate skills for char1
     sk = self.char1.skills
     sk.escape.minus += 1
     sk.climb.minus += 1
     sk.jump.minus += 1
     sk.medicine.plus += 1
     skills.finalize_skills(sk)
     # confirm the plusses and minuses are applied
     self.assertEqual(sk.escape.actual, 7)
     self.assertEqual(sk.climb.actual, 7)
     self.assertEqual(sk.jump.actual, 7)
     self.assertEqual(sk.medicine.actual, 3)
     # confirm plus/minus counters are deleted
     with self.assertRaises(AttributeError):
         x = sk.escape.plus
     with self.assertRaises(AttributeError):
         x = sk.escape.minus
Esempio n. 5
0
def menunode_allocate_skills(caller, raw_string):
    """Skill -1 counter allocation menu node."""
    char = caller.new_char
    sk = char.skills
    total = 3
    counts = {1: 'one', 2: 'two', 3: 'three'}

    plusses = (ceil(char.traits.INT.actual / 3.0) -
               sum(sk[s].plus for s in skills.ALL_SKILLS))
    minuses = total - sum(sk[s].minus for s in skills.ALL_SKILLS)

    text = ""
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(skills.ALL_SKILLS):
        skill = sk[skills.ALL_SKILLS[int(raw_string) - 1]]
        if minuses:
            if skill.actual - skill.minus - 1 > 0:
                skill.minus += 1
                minuses -= 1
            else:
                text += "|rSkills cannot be reduced below one.|n\n"
        elif plusses:
            if skill.actual + skill.plus + 1 <= 10:
                skill.plus += 1
                plusses -= 1
            else:
                text += "|rSkills cannot be increased above ten.|n\n"

    if plusses or minuses:
        text += "{}\n\n".format(raw_string) if raw_string and raw_string[0] == 'F' else ""
        text += "Your ability to perform actions in Ainneve is\n"
        text += "tied to your character's skills.\n"

        if minuses:
            text += "Please allocate |w{}|n |m'-1'|n counter{}.".format(
                        counts[minuses],
                        's' if minuses != 1 else '')
        elif plusses:
            text += "Please allocate |w{}|n |m'+1'|n counter{}.".format(
                        counts[plusses],
                        's' if plusses != 1 else '')

        help = "Skill allocation is a two step process. First, you\n"
        help += "distribute three '-1' counters across your skills,\n"
        help += "then a number of '+1' counters equal to your Intelligence\n"
        help += "divided by 3."

        options = [{"desc": _format_skill_opts(sk[s]),
                    "goto": "menunode_allocate_skills"}
                   for s in skills.ALL_SKILLS]

        def clear_skills(s):
            """Reset plus and minus counters on all skills."""
            for skill in skills.ALL_SKILLS:
                sk[skill].plus = 0
                sk[skill].minus = 0

        options.append({"desc": "Start Over",
                        "exec": clear_skills,
                        "goto": "menunode_allocate_skills"})
        return (text, help), options
    else:
        skills.finalize_skills(char.skills)
        data = []
        for i in xrange(3):
            data.append([_format_trait_opts(sk[s], color='|M')
                         for s in skills.ALL_SKILLS[i::3]])
        table = EvTable(header=False, table=data)
        output = "Final Skills:\n"
        output += "{skills}\n"

        char.db.wallet['SC'] = d_roll('2d6+3')
        output += "You begin with |w{sc} SC|n (Silver Coins)."

        return menunode_equipment_cats(
            caller,
            output.format(skills=table, sc=char.db.wallet['SC'])
        )
Esempio n. 6
0
def menunode_allocate_skills(caller, raw_string):
    """Skill -1 counter allocation menu node."""
    char = caller.new_char
    sk = char.skills
    total = 3
    counts = {1: 'one', 2: 'two', 3: 'three'}

    plusses = (ceil(char.traits.INT.actual / 3.0) -
               sum(sk[s].plus for s in skills.ALL_SKILLS))
    minuses = total - sum(sk[s].minus for s in skills.ALL_SKILLS)

    text = ""
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(skills.ALL_SKILLS):
        skill = sk[skills.ALL_SKILLS[int(raw_string) - 1]]
        if minuses:
            if skill.actual - skill.minus - 1 > 0:
                skill.minus += 1
                minuses -= 1
            else:
                text += "|rSkills cannot be reduced below one.|n\n"
        elif plusses:
            if skill.actual + skill.plus + 1 <= 10:
                skill.plus += 1
                plusses -= 1
            else:
                text += "|rSkills cannot be increased above ten.|n\n"

    if plusses or minuses:
        text += "{}\n\n".format(
            raw_string) if raw_string and raw_string[0] == 'F' else ""
        text += "Your ability to perform actions in Ainneve is\n"
        text += "tied to your character's skills.\n"

        if minuses:
            text += "Please allocate |w{}|n |m'-1'|n counter{}.".format(
                counts[minuses], 's' if minuses != 1 else '')
        elif plusses:
            text += "Please allocate |w{}|n |m'+1'|n counter{}.".format(
                counts[plusses], 's' if plusses != 1 else '')

        help = "Skill allocation is a two step process. First, you\n"
        help += "distribute three '-1' counters across your skills,\n"
        help += "then a number of '+1' counters equal to your Intelligence\n"
        help += "divided by 3."

        options = [{
            "desc": _format_skill_opts(sk[s]),
            "goto": "menunode_allocate_skills"
        } for s in skills.ALL_SKILLS]

        def clear_skills(s):
            """Reset plus and minus counters on all skills."""
            for skill in skills.ALL_SKILLS:
                sk[skill].plus = 0
                sk[skill].minus = 0

        options.append({
            "desc": "Start Over",
            "exec": clear_skills,
            "goto": "menunode_allocate_skills"
        })
        return (text, help), options
    else:
        skills.finalize_skills(char.skills)
        data = []
        for i in xrange(3):
            data.append([
                _format_trait_opts(sk[s], color='|M')
                for s in skills.ALL_SKILLS[i::3]
            ])
        table = EvTable(header=False, table=data)
        output = "Final Skills:\n"
        output += "{skills}\n"

        char.db.wallet['SC'] = d_roll('2d6+3')
        output += "You begin with |w{sc} SC|n (Silver Coins)."

        return menunode_equipment_cats(
            caller, output.format(skills=table, sc=char.db.wallet['SC']))