Beispiel #1
0
    def set_turn(self, gameMode, player1, player2, game_order):
        print("\n" * 100)
        print("\nThe token for '{}' is '{}'".format(player1.name,
                                                    player1.token))
        print("The token for '{}' is '{}'".format(player2.name, player2.token))

        # Spectate a game
        if (gameMode == 3):
            game_order.append(player1)
            game_order.append(player2)
            random.shuffle(game_order)

        else:
            print("\nTurn Selection:")
            print(
                "You can choose to go first or let the other player go first.\n"
            )
            # Play against a friend
            if (gameMode == 2):
                print("Roll dice to determine who gets to choose turn. \n")

                # Set initial value to None for both to ensure the while loop entry
                # which will handle the actual dice roll
                p1dice = util.rolldice()
                p2dice = util.rolldice()
                while p1dice == p2dice:
                    p1dice = util.rolldice()
                    p2dice = util.rolldice()

                player1.dice = p1dice
                player2.dice = p2dice

                print("{} rolled {}".format(player1.name, p1dice))
                print("{} rolled {}\n".format(player2.name, p2dice))

                if p1dice > p2dice:
                    util.set_turn_helper(game_order, player1, player2)
                else:
                    util.set_turn_helper(game_order, player2, player1)

            # Play against AI
            else:
                util.set_turn_helper(game_order, player1, player2)

        print("\n{} will go first.".format(game_order[0].name))
        print("{} will go last.".format(game_order[1].name))
Beispiel #2
0
 def spell_success(self):
     ability_scores = load_yaml('rules', 'ability_scores.yaml')
     wis = str(self.get('attributes/wis', 0))
     failrate = int(ability_scores["wis/%s/spell_failure" %(wis)].split('%')[0])
     out = "Spell failure rate: %s percent" % failrate
     roll = rolldice(numdice=1, numsides=100)
     out += '<br>%s' % roll[1]
     if roll[0] > failrate:
         out += '<br>Spell succeeds !'
         return (True, out)
     else:
         out += '<br>Spell fails !'
         return(False, out)
Beispiel #3
0
 def roll_hit_dice(self):
     """
     >>> objdata = load_yaml('characters', 'bardic_rogue.yaml')
     >>> char = Character(objdata)
     >>> hitdice = int(char()['combat/level-hitdice'])
     >>> max = int(hitdice * 8)
     >>> char.roll_hit_dice()
     >>> char.get('combat/hitpoints', 0) <= max
     True
     >>> char.get('combat/max_hp', 0) == max
     True
     """
     numdice = int(self.get('combat/level-hitdice', '1'))
     self.put('combat/hitpoints', rolldice(numdice=numdice, numsides=8)[0])
     self.put('combat/max_hp', numdice * 8)
Beispiel #4
0
def calc_damage(player, target, custom_dmg):
    dmg_mod = player.dmg_mod() + custom_dmg
    if custom_dmg:
        frontend.campaign.message('Applying custom damage modifier of %s' % custom_dmg)
    frontend.campaign.message('Total damage modifier %s' % dmg_mod)
    weapon = player.current_weapon()
    dmg = weapon.get('/conditional/dmg', 1)
    save = weapon.get('/conditional/save_against', 'none')
    if save != 'none':
        throw = target.saving_throw(save)
        if throw[0]:
            frontend.campaign.message(throw[1])
        return throw[0]
    damage = rolldice(numdice=1, numsides=dmg, modifier=dmg_mod)
    frontend.campaign.message('Rolling for damage: %s' % damage[1])
    taken = target.take_damage(damage[0])
    frontend.campaign.message(taken[1])
    return taken[0]
Beispiel #5
0
 def level_up(self):
     """
     >>> char = Character(load_yaml('characters', 'bardic_rogue.yaml'))
     >>> level = char.get('combat/level-hitdice', 1)
     >>> hp = char.get('combat/hitpoints', 1)
     >>> max = char.get('combat/max_hp', 1)
     >>> debug(char.level_up())
     >>> char.get('combat/hitpoints', 1) > hp
     True
     >>> char.get('combat/max_hp', 1) > max
     True
     >>> char.get('combat/level-hitdice', 1) == level + 1
     True
     """
     level = int(self.get('combat/level-hitdice', 1))
     level += 1
     out = '%s has reached level %s !' % (self.displayname(), level)
     self.put('combat/level-hitdice', level)
     ability_scores = load_yaml('rules', 'ability_scores.yaml')
     con = self.get('attributes/con', 1)
     out += '<br>Character constitution: %s' % con
     con_bonus = int(FlattenedDict(ability_scores).get('/con/%s/hit' % con,0))
     out += '<br>Constitution Bonus: %s' % con_bonus
     xp_levels = FlattenedDict(load_yaml('rules', 'xp_levels.yaml'))
     pclass = self.get('class/parent', '')
     xp_levels = xp_levels.readall(pclass)
     hitdice = str(xp_levels.get('%s/%s/hit_dice' % (pclass, level), 1))
     debug("Read hitdice as ", hitdice)
     if '+' not in hitdice:
         hitdice = hitdice + '+0'
     hitdice, bonus = hitdice.split('+')
     dice = int(xp_levels.get('%s/dice' % pclass, 1))
     more_hp, roll = rolldice(numdice=int(hitdice), numsides=dice, modifier=con_bonus)
     out += '<br>%s' % roll
     more_hp += int(bonus)
     current_max = int(self.get('combat/max_hp', 1))
     new_max = current_max + more_hp
     out += '<br>Maximum hitpoints increased by %s. Maximum hitpoints now: %s' % (more_hp, new_max)
     self.put('combat/max_hp', new_max)
     new_hp = new_max
     out += '<br>Character hitpoints now %s' % new_hp
     self.put('combat/hitpoints', new_hp)
     self.__init__(self())
     return out
Beispiel #6
0
    def attack_roll(self, target, mod):
        self.next_weapon()
        messages.message('%s has THAC0 of: %s' % (self.displayname(), self.thac0))
        target_stats = '%s has a defense modifier of %s and armor class %s' % (target.displayname(), target.def_mod(), target.armor_class())

        messages.message(target_stats)
        target_roll = self.thac0 - target.armor_class() - target.def_mod()

        messages.message('%s needs to roll %s to hit %s' % (self.displayname(), target_roll, target.displayname()))
        roll = rolldice(numdice=1, numsides=20, modifier=mod)
        if roll[0] == 1:
                return (roll[0], "Critical Miss !", roll[1])
        elif roll[0] == 20:
            return (roll[0], "Critical Hit !", roll[1])
        else:
            if roll[0] >= target_roll:
                return (roll[0], "Hit !", roll[1])
            else:
                return (roll[0], "Miss !", roll[1])
Beispiel #7
0
 def saving_throw(self, against):
     saving = load_yaml('rules', 'saving_throws.yaml') or {}
     prettyname = saving['names'][against]
     race = self.get('personal/race', '')
     con = int(self.get('attributes/con', 0))
     mod = 0
     if race in list(saving.keys()):
         for key in list(saving[race].keys()):
             if inrange(con, key):
                 mod = int(saving[race][key])
                 continue
     target = int(FlattenedDict(self.saving_throws).get(against, 0))
     out = "%s Tries to roll a saving throw against %s" % (self.displayname(), prettyname)
     out += "<br>%s needs to roll %s" % (self.displayname(), target)
     roll = rolldice(numdice=1, numsides=20, modifier=mod)
     out += '<br>%s' % roll[1]
     if roll[0] >= int(target):
         out += '<br>Saved !'
         return (True, out)
     else:
         out += "<br>Did not save !"
         return (False, out)
Beispiel #8
0
 def learn_spell(self, spellitem):
     spells = self.get('inventory/spells', [])
     if isinstance(spells, str):
         try:
             spells = simpleobjdata.loads(spells)
         except:
             spells = []
     if not isinstance(spells, list):
         self.put('inventory/spells', [])
     spelltype = spellitem.get('spell_type', 'wizard spells')
     parentclass = self.get('class/parent', '')
     childclass = self.get('class/class', '')
     canlearn = load_yaml('rules', 'various.yaml')["spell progression"]
     found = False
     for key in canlearn:
         if key == parentclass or key == childclass:
             debug(key)
             found = True
             break
     if not found:
         return "%s cannot learn spells" % self.displayname()
     oneline = list(canlearn[key].keys())[0]
     if spelltype not in canlearn[key][oneline]:
         return "%s cannot learn %s, failed to learn spell %s" % (self.displayname(), spelltype, spellitem.displayname())
     intelect = str(self.get('attributes/int', 1))
     chance = FlattenedDict(load_yaml('rules', 'ability_scores.yaml'))
     chance = chance['/int/%s/spell_learn' % intelect]
     out = "<strong>%s has a %s chance to learn a new spell</strong>" % (self.displayname(), chance)
     chance = int(chance.replace('%', ''))
     roll = rolldice(numdice=1, numsides=100, modifier=0)
     out += '<br>%s' % roll[1]
     if roll[0] > chance:
         return '%s<br><strong>%s has failed to learn %s!</strong>' % (out, self.displayname(), spellitem.displayname())
     spellitem.identify()
     self()['core']['inventory']['spells'].append(spellitem())
     self.autosave()
     return "%s<br><strong>%s has learned %s</strong>" % (out, self.displayname(), spellitem.displayname())