示例#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)
示例#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)
示例#3
0
文件: tests.py 项目: lilomar/ainneve
 def setUp(self):
     self.character_typeclass = Character
     super(CharTraitsTestCase, self).setUp()
     apply_archetype(self.char1, 'warrior')
     self.char1.traits.STR.base += 3
     self.char1.traits.PER.base += 1
     self.char1.traits.DEX.base += 1
     self.char1.traits.VIT.base += 3
     calculate_secondary_traits(self.char1.traits)
示例#4
0
 def setUp(self):
     self.character_typeclass = Character
     super(CharTraitsTestCase, self).setUp()
     apply_archetype(self.char1, 'warrior')
     self.char1.traits.STR.base += 3
     self.char1.traits.PER.base += 1
     self.char1.traits.DEX.base += 1
     self.char1.traits.VIT.base += 3
     calculate_secondary_traits(self.char1.traits)
示例#5
0
 def setUp(self):
     self.character_typeclass = Character
     super(CharSkillsTestCase, self).setUp()
     archetypes.apply_archetype(self.char1, 'warrior')
     tr = self.char1.traits
     tr.STR.base += 2
     tr.PER.base += 1
     tr.INT.base += 1
     tr.DEX.base += 1
     tr.CHA.base += 1
     tr.VIT.base += 2
示例#6
0
 def setUp(self):
     self.character_typeclass = Character
     super(CharSkillsTestCase, self).setUp()
     archetypes.apply_archetype(self.char1, 'warrior')
     tr = self.char1.traits
     tr.STR.base += 2
     tr.PER.base += 1
     tr.INT.base += 1
     tr.DEX.base += 1
     tr.CHA.base += 1
     tr.VIT.base += 2
示例#7
0
 def setUp(self):
     self.character_typeclass = Character
     super(ApplyRaceTestCase, self).setUp()
     # make sure char1 has traits to give bonuses to
     apply_archetype(self.char1, 'warrior')
     self.char1.traits.STR.base += 2
     self.char1.traits.PER.base += 1
     self.char1.traits.INT.base += 1
     self.char1.traits.DEX.base += 1
     self.char1.traits.CHA.base += 1
     self.char1.traits.VIT.base += 2
     calculate_secondary_traits(self.char1.traits)
 def setUp(self):
     self.character_typeclass = Character
     super(ApplyRaceTestCase, self).setUp()
     # make sure char1 has traits to give bonuses to
     apply_archetype(self.char1, 'warrior')
     self.char1.traits.STR.base += 2
     self.char1.traits.PER.base += 1
     self.char1.traits.INT.base += 1
     self.char1.traits.DEX.base += 1
     self.char1.traits.CHA.base += 1
     self.char1.traits.VIT.base += 2
     calculate_secondary_traits(self.char1.traits)
示例#9
0
文件: tests.py 项目: lilomar/ainneve
 def setUp(self):
     super(EquipTestCase, self).setUp()
     apply_archetype(self.char1, 'warrior')
     apply_race(self.char1, 'human', 'cunning')
     self.obj1.db.desc = 'Test Obj'
     self.obj1.db.damage = 1
     self.obj1.db.weight = 1.0
     self.obj2.db.desc = 'Test Obj2'
     self.obj2.swap_typeclass('typeclasses.armors.Armor',
                              clean_attributes=True,
                              run_start_hooks=True)
     self.obj2.db.toughness = 1
     self.obj2.db.weight = 2.0
示例#10
0
 def test_apply_arcanist(self):
     """confirm the Arcanist archetype is initialized correctly"""
     archetypes.apply_archetype(self.char1, 'arcanist')
     self.assertEqual(self.char1.db.archetype, 'Arcanist')
     self.assertEqual(set(archetypes.ALL_TRAITS),
                      set(self.char1.db.traits.keys()))
     self.assertEqual(self.char1.traits.STR.actual, 1)
     self.assertEqual(self.char1.traits.PER.actual, 4)
     self.assertEqual(self.char1.traits.INT.actual, 6)
     self.assertEqual(self.char1.traits.DEX.actual, 1)
     self.assertEqual(self.char1.traits.CHA.actual, 4)
     self.assertEqual(self.char1.traits.VIT.actual, 1)
     self.assertEqual(self.char1.traits.MAG.actual, 6)
 def test_toomany_points(self):
     """confirm validation of over-allocated traits"""
     # perfect char not allowed
     for t in archetypes.PRIMARY_TRAITS:
         self.char1.traits[t].base = 10
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertFalse(is_valid)
     self.assertEqual(errmsg, 'Too many trait points allocated.')
     # no more than 30 allowed
     archetypes.apply_archetype(self.char1, 'warrior', reset=True)
     self.char1.traits.INT.base += 9
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertFalse(is_valid)
     self.assertEqual(errmsg, 'Too many trait points allocated.')
示例#12
0
 def test_toomany_points(self):
     """confirm validation of over-allocated traits"""
     # perfect char not allowed
     for t in archetypes.PRIMARY_TRAITS:
         self.char1.traits[t].base = 10
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertFalse(is_valid)
     self.assertEqual(errmsg, 'Too many trait points allocated.')
     # no more than 30 allowed
     archetypes.apply_archetype(self.char1, 'warrior', reset=True)
     self.char1.traits.INT.base += 9
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertFalse(is_valid)
     self.assertEqual(errmsg, 'Too many trait points allocated.')
示例#13
0
文件: tests.py 项目: lilomar/ainneve
 def setUp(self):
     super(ItemEncumbranceTestCase, self).setUp()
     apply_archetype(self.char1, 'warrior')
     apply_race(self.char1, 'human', 'cunning')
     self.char1.traits.STR.base += 3
     self.char1.traits.VIT.base += 3
     self.char1.traits.DEX.base += 2
     calculate_secondary_traits(self.char1.traits)
     self.obj1.db.desc = 'Test Obj'
     self.obj1.db.damage = 1
     self.obj1.db.weight = 1.0
     self.obj2.swap_typeclass('typeclasses.armors.Armor',
                              clean_attributes=True,
                              run_start_hooks=True)
     self.obj2.db.toughness = 1
     self.obj2.db.weight = 18.0
 def test_apply_archetype(self):
     data = self.at_data.copy()
     for k, v in data.iteritems():
         if self.char1.db.archetype is not None:
             archetypes.apply_archetype(self.char1, k, reset=True)
         else:
             archetypes.apply_archetype(self.char1, k)
         self.assertEqual(self.char1.traits.AGL, data[k]['AGL'])
         self.assertEqual(self.char1.traits.STR, data[k]['STR'])
         self.assertEqual(self.char1.traits.KNW, data[k]['KNW'])
         self.assertEqual(self.char1.traits.MCH, data[k]['MCH'])
         self.assertEqual(self.char1.traits.PER, data[k]['PER'])
         self.assertEqual(self.char1.traits.TCH, data[k]['TCH'])
         self.assertEqual(self.char1.traits.WOUNDS, 0)
         self.assertEqual(self.char1.traits.FATE, 0)
         self.assertEqual(self.char1.traits.CP, 0)
         self.assertEqual(self.char1.traits.ENC, 0)
示例#15
0
 def test_valid_allocations(self):
     """confirm valid trait allocations"""
     # warriors have 8 points to allocate
     self.char1.traits.STR.base += 2
     self.char1.traits.PER.base += 1
     self.char1.traits.INT.base += 1
     self.char1.traits.DEX.base += 1
     self.char1.traits.CHA.base += 1
     self.char1.traits.VIT.base += 2
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertEqual(sum(self.char1.traits[t].actual
                          for t in archetypes.PRIMARY_TRAITS), 30)
     self.assertTrue(is_valid)
     # smartest warrior ever
     archetypes.apply_archetype(self.char1, 'warrior', reset=True)
     self.char1.traits.INT.base += 8
     is_valid, errmsg = archetypes.validate_primary_traits(self.char1.traits)
     self.assertTrue(is_valid)
示例#16
0
 def test_invalid_apply_sequence(self):
     """test invalid archetype assignment sequences"""
     # cannot assign the same archetype twice
     archetypes.apply_archetype(self.char1, 'scout')
     with self.assertRaises(archetypes.ArchetypeException):
         archetypes.apply_archetype(self.char1, 'scout')
     # cannot assign triple archetype
     archetypes.apply_archetype(self.char1, 'warrior')
     self.assertEqual(self.char1.db.archetype, 'Warrior-Scout')
     with self.assertRaises(archetypes.ArchetypeException):
         archetypes.apply_archetype(self.char1, 'arcanist')
示例#17
0
def menunode_allocate_traits(caller, raw_string):
    """Discretionary trait point allocation menu node."""
    char = caller.new_char
    text = ""
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(
            archetypes.PRIMARY_TRAITS):
        chartrait = char.traits[archetypes.PRIMARY_TRAITS[int(raw_string) - 1]]
        if chartrait.actual < 10:
            chartrait.mod += 1
        else:
            text += "|rCannot allocate more than 10 points to one trait!|n\n"

    remaining = archetypes.get_remaining_allocation(char.traits)

    text += "Your character's traits influence combat abilities and skills.\n"
    text += "Type 'help' to see individual trait definitions.\n\n"
    text += "Allocate additional trait points as you choose.\n"
    text += "\n  |w{}|n Points Remaining\n".format(remaining)
    text += "Please select a trait to increase:"

    help = "Traits:\n"
    help += "  Strength - affects melee attacks, fortitude saves, and physical tasks\n"
    help += "  Perception - affects ranged attacks, reflex saves, and perception tasks\n"
    help += "  Intelligence - affects skill bonuses, will saves, and magic\n"
    help += "  Dexterity - affects unarmed attacks, defense, and dexterity-based skills\n"
    help += "  Charisma - affects skills related to interaction with others\n"
    help += "  Vitality - affects health and stamina points"

    options = [{
        "desc": _format_trait_opts(char.traits[t]),
        "goto": "menunode_allocate_traits"
    } for t in archetypes.PRIMARY_TRAITS]
    options.append({
        "desc":
        "Start Over",
        "exec":
        lambda s: archetypes.apply_archetype(
            char, char.db.archetype, reset=True),
        "goto":
        "menunode_allocate_traits"
    })

    if remaining > 0:
        return (text, help), options
    else:
        data = []
        for i in xrange(3):
            data.append([
                _format_trait_opts(char.traits[t])
                for t in archetypes.PRIMARY_TRAITS[i::3]
            ])
        table = EvTable(header=False, table=data)
        return menunode_races(caller, "Final Skills:\n{}".format(table))
示例#18
0
def menunode_allocate_traits(caller, raw_string):
    """Discretionary trait point allocation menu node."""
    char = caller.new_char
    text = ""
    raw_string = raw_string.strip()
    if raw_string.isdigit() and int(raw_string) <= len(archetypes.PRIMARY_TRAITS):
        chartrait = char.traits[archetypes.PRIMARY_TRAITS[int(raw_string) - 1]]
        if chartrait.actual < 10:
            chartrait.mod += 1
        else:
            text += "|rCannot allocate more than 10 points to one trait!|n\n"

    remaining = archetypes.get_remaining_allocation(char.traits)

    text += "Your character's traits influence combat abilities and skills.\n"
    text += "Type 'help' to see individual trait definitions.\n\n"
    text += "Allocate additional trait points as you choose.\n"
    text += "\n  |w{}|n Points Remaining\n".format(remaining)
    text += "Please select a trait to increase:"

    help = "Traits:\n"
    help += "  Strength - affects melee attacks, fortitude saves, and physical tasks\n"
    help += "  Perception - affects ranged attacks, reflex saves, and perception tasks\n"
    help += "  Intelligence - affects skill bonuses, will saves, and magic\n"
    help += "  Dexterity - affects unarmed attacks, defense, and dexterity-based skills\n"
    help += "  Charisma - affects skills related to interaction with others\n"
    help += "  Vitality - affects health and stamina points"

    options = [{"desc": _format_trait_opts(char.traits[t]),
                "goto": "menunode_allocate_traits"}
               for t in archetypes.PRIMARY_TRAITS]
    options.append({"desc": "Start Over",
                    "exec": lambda s: archetypes.apply_archetype(
                                          char,
                                          char.db.archetype,
                                          reset=True),
                    "goto": "menunode_allocate_traits"})

    if remaining > 0:
        return (text, help), options
    else:
        data = []
        for i in xrange(3):
            data.append([_format_trait_opts(char.traits[t])
                         for t in archetypes.PRIMARY_TRAITS[i::3]])
        table = EvTable(header=False, table=data)
        return menunode_races(caller, "Final Skills:\n{}".format(table))
示例#19
0
 def test_apply_arcanist_scout(self):
     """confirm the Arcanist-Scout archetype is initialized correctly"""
     archetypes.apply_archetype(self.char1, 'arcanist')
     archetypes.apply_archetype(self.char1, 'scout')
     self.assertEqual(self.char1.db.archetype, 'Arcanist-Scout')
     self.assertEqual(set(archetypes.ALL_TRAITS),
                      set(self.char1.db.traits.keys()))
     self.assertEqual(self.char1.traits.STR.actual, 2)
     self.assertEqual(self.char1.traits.PER.actual, 5)
     self.assertEqual(self.char1.traits.INT.actual, 6)
     self.assertEqual(self.char1.traits.DEX.actual, 2)
     self.assertEqual(self.char1.traits.CHA.actual, 2)
     self.assertEqual(self.char1.traits.VIT.actual, 1)
     self.assertEqual(self.char1.traits.MAG.actual, 3)
     # reset and test opposite order
     archetypes.apply_archetype(self.char1, 'scout', reset=True)
     archetypes.apply_archetype(self.char1, 'arcanist')
     self.assertEqual(self.char1.db.archetype, 'Arcanist-Scout')
示例#20
0
def menunode_select_archetype(caller, raw_string):
    """Archetype detail and selection menu node."""
    arch = archetypes.VALID_ARCHETYPES[int(raw_string.strip()) - 1]
    arch = archetypes.load_archetype(arch)
    text = arch.ldesc + "Would you like to become this archetype?"
    help = "Examine the properties of this archetype and decide whether\n"
    help += "to use its starting attributes for your character."
    options = ({"key": ("Yes", "ye", "y"),
                "desc": "Become {} {}".format("an" if arch.name[0] == 'A'
                                              else "a",
                                              arch.name),
                "exec": lambda s: archetypes.apply_archetype(s.new_char, arch.name,
                                                             reset=True),
                "goto": "menunode_allocate_traits"},
               {"key": ("No", "n", "_default"),
                "desc": "Return to Archetype selection",
                "goto": "menunode_welcome_archetypes"})
    return (text, help), options
示例#21
0
def menunode_select_archetype(caller, raw_string):
    """Archetype detail and selection menu node."""
    arch = archetypes.VALID_ARCHETYPES[int(raw_string.strip()) - 1]
    arch = archetypes.load_archetype(arch)
    text = arch.ldesc + "Would you like to become this archetype?"
    help = "Examine the properties of this archetype and decide whether\n"
    help += "to use its starting attributes for your character."
    options = ({"key": ("Yes", "ye", "y"),
                "desc": "Become {} {}".format("an" if arch.name[0] == 'A'
                                              else "a",
                                              arch.name),
                "exec": lambda s: archetypes.apply_archetype(s.new_char, arch.name,
                                                             reset=True),
                "goto": "menunode_allocate_traits"},
               {"key": ("No", "n", "_default"),
                "desc": "Return to Archetype selection",
                "goto": "menunode_welcome_archetypes"})
    return (text, help), options
 def test_valid_allocations(self):
     archetypes.apply_archetype(self.char1, 'soldier', reset=True)
     self.assertTrue(archetypes.validate_primary_traits(self.char1.traits))
示例#23
0
 def setUp(self):
     super(PublicFunctionsTestCase, self).setUp()
     archetypes.apply_archetype(self.char1, 'warrior')