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)
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)
def at_object_creation(self): super(NPC, self).at_object_creation() # initialize traits npc = Archetype() for key, kwargs in npc.traits.iteritems(): self.traits.add(key, **kwargs) apply_skills(self)
def menunode_allocate_mana(caller, raw_string): """Mana point allocation menu node.""" char = caller.new_char tr = char.traits manas = ('WM', 'BM') raw_string = raw_string.strip() if raw_string.isdigit() and int(raw_string) <= len(manas): tr[manas[int(raw_string) - 1]].base += 1 remaining = tr.MAG.actual - sum(tr[m].base for m in manas) if remaining: text = "Your |CMagic|n trait is |w{}|n.\n\n".format(tr.MAG.actual) text += "This allows you to allocate that many points to your\n" text += "|wWhite Mana|n and |xBlack Mana|n counters.\n" text += "You have |w{}|n points remaining. ".format(remaining) text += "Select a mana counter to increase:" help = "Magic users spend Mana points when casting spells. Different\n" help += "colors of magic require different colors of mana. The effects of\n" help += "different magics vary by color.\n\n" help += " White - white magic spells are generally support/healing based\n" help += " Black - black magic spells are generally attack-oriented\n\n" help += "The number of points allocated here determines the number of\n" help += "each color mana that will be spawned each turn of the game." options = [{ "desc": _format_trait_opts(tr[m], '|w' if m == 'WM' else '|x'), "goto": "menunode_allocate_mana" } for m in manas] def reset_mana(s): for m in manas: char.traits[m].base = 0 options.append({ "desc": "Start Over", "exec": reset_mana, "goto": "menunode_allocate_mana" }) return (text, help), options else: if tr.MAG.actual > 0: output = "Final Mana Values:\n" output += " |wWhite Mana|n: |w{}|n\n".format(tr.WM.actual) output += " |xBlack Mana|n: |w{}|n\n".format(tr.BM.actual) else: output = "" # TODO: implement spells; add level 0 spell cmdsets here archetypes.calculate_secondary_traits(char.traits) archetypes.finalize_traits(char.traits) tickerhandler.add(interval=6, callback=char.at_turn_start) skills.apply_skills(char) return menunode_allocate_skills(caller, output)
def at_object_creation(self): super(NPC, self).at_object_creation() self.db.emote_aggressive = "stares about angrily" self.db.slots = {'wield': None, 'armor': None} # initialize traits npc = Archetype() for key, kwargs in npc.traits.iteritems(): self.traits.add(key, **kwargs) apply_skills(self)
def menunode_allocate_mana(caller, raw_string): """Mana point allocation menu node.""" char = caller.new_char tr = char.traits manas = ('WM', 'BM') raw_string = raw_string.strip() if raw_string.isdigit() and int(raw_string) <= len(manas): tr[manas[int(raw_string) - 1]].base += 1 remaining = tr.MAG.actual - sum(tr[m].base for m in manas) if remaining: text = "Your |CMagic|n trait is |w{}|n.\n\n".format(tr.MAG.actual) text += "This allows you to allocate that many points to your\n" text += "|wWhite Mana|n and |xBlack Mana|n counters.\n" text += "You have |w{}|n points remaining. ".format(remaining) text += "Select a mana counter to increase:" help = "Magic users spend Mana points when casting spells. Different\n" help += "colors of magic require different colors of mana. The effects of\n" help += "different magics vary by color.\n\n" help += " White - white magic spells are generally support/healing based\n" help += " Black - black magic spells are generally attack-oriented\n\n" help += "The number of points allocated here determines the number of\n" help += "each color mana that will be spawned each turn of the game." options = [{"desc": _format_trait_opts(tr[m], '|w' if m == 'WM' else '|x'), "goto": "menunode_allocate_mana"} for m in manas] def reset_mana(s): for m in manas: char.traits[m].base = 0 options.append({"desc": "Start Over", "exec": reset_mana, "goto": "menunode_allocate_mana"}) return (text, help), options else: if tr.MAG.actual > 0: output = "Final Mana Values:\n" output += " |wWhite Mana|n: |w{}|n\n".format(tr.WM.actual) output += " |xBlack Mana|n: |w{}|n\n".format(tr.BM.actual) else: output = "" # TODO: implement spells; add level 0 spell cmdsets here archetypes.calculate_secondary_traits(char.traits) archetypes.finalize_traits(char.traits) tickerhandler.add(interval=6, callback=char.at_turn_start) skills.apply_skills(char) return menunode_allocate_skills(caller, output)
def test_validate_skills(self): """test module function `apply_skills`""" skills.apply_skills(self.char1) # not self.assertFalse(skills.validate_skills(self.char1)[0]) self.assertIn('Not enough -1', skills.validate_skills(self.char1)[1]) sk = self.char1.skills sk.escape.minus += 1 sk.climb.minus += 1 sk.jump.minus += 1 sk.medicine.plus += 1 self.assertTrue(skills.validate_skills(self.char1)[0]) sk.appraise.plus += 1 self.assertFalse(skills.validate_skills(self.char1)[0]) self.assertIn('Not enough +1', skills.validate_skills(self.char1)[1])
def test_apply_skills(self): """test module function `apply_skills`""" skills.apply_skills(self.char1) sk = self.char1.skills self.assertEqual(sk.escape.actual, 8) self.assertEqual(sk.climb.actual, 8) self.assertEqual(sk.jump.actual, 8) self.assertEqual(sk.lockpick.actual, 2) self.assertEqual(sk.listen.actual, 2) self.assertEqual(sk.sense.actual, 2) self.assertEqual(sk.appraise.actual, 2) self.assertEqual(sk.medicine.actual, 2) self.assertEqual(sk.survival.actual, 2) self.assertEqual(sk.balance.actual, 5) self.assertEqual(sk.sneak.actual, 5) self.assertEqual(sk.throwing.actual, 5) self.assertEqual(sk.animal.actual, 5) self.assertEqual(sk.barter.actual, 5) self.assertEqual(sk.leadership.actual, 5)
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