Exemplo n.º 1
0
    def from_input(cls):
        name = easyinput.input_str("name")
        hp = easyinput.input_int('hp')
        init_mod = easyinput.input_int('init mod', 0)
        ap = easyinput.input_int('action points', 0)
        surges = easyinput.input_int('healing surges', 0)

        recharges = []
        while True:
            data = []
            data = easyinput.input_str("recharge", default='').split(',')
            if len(data) == 2:
                recharge = {}
                recharge['name'] = data[0]
                recharge['value'] = int(data[1])
                recharge['used'] = False
                recharges.append(recharge)
            else:
                break

        count = easyinput.input_int('count', 1)

        # Now make the combatants...
        members = {}
        for i in range(count):
            c = Combatant(name, hp, pc=False, surges=surges, ap=ap, sw=0, recharges=recharges)
            members[c.index] = c

        if count > 1:
            name = name + 's'

        return CombatGroup(name, members, init_mod)
Exemplo n.º 2
0
 def choose_combatant(self):
     print self.format_combatants()
     index = easyinput.input_int('choose combatant')
     if index not in self.combatant_hash:
         print 'Error: {} is not a valid index'.format(index)
         return self.choose_combatant()
     return self.combatant_hash[index]
Exemplo n.º 3
0
    def end_turn(self):
        for c in self.conditions.values():
            if c['cond_type'] == 's':
                r = None
                if self.pc:
                    print '{}: save against {}.'.format(self, c['name'])
                    r = easyinput.input_int('saving throw')
                else:
                    save_die = Dice.from_str('1d20')
                    r = save_die.roll()['total']

                if r >= 10:
                    self.remove_condition(c['index'])
                    print '{} successfully saved against {}.'.format(self, c['name'])
                else:
                    print '{} failed a save against {}.'.format(self, c['name'])

            elif c['cond_type'] == 't' and c['end_type'] == 'e':
                if c['duration'] <= 0:
                    self.remove_condition(c['index'])
                else:
                    print '{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration'], 's'[c['duration']==1:])

        for r in self.recharges.values():
            if r['used']:
                if r['just_used']:
                    r['just_used'] = False
                    continue

                # Roll to recharge
                d = Dice.from_str('1d6')
                n = d.roll()['total']
                if n >= r['value']:
                    r['used'] = False
                    print '{} can use {} again!'.format(self, r['name'])
Exemplo n.º 4
0
    def choose_recharge_power(self):
        if not len(self.recharges):
            print '{} has no rechargable powers.'.format(self)
            return None

        print self.format_recharge_summary()
        index = easyinput.input_int('choice')

        if index not in self.recharges:
            print 'Error: {} is not a valid index'.format(index)
            return self.choose_recharge_power()

        return self.recharges[index]
Exemplo n.º 5
0
    def choose_condition(self):
        if not len(self.conditions):
            print '{} has no conditions.'.format(self)
            return None

        print self.format_condition_summary()
        index = easyinput.input_int('choice')

        if index not in self.conditions:
            print 'Error: {} is not a valid index'.format(index)
            return self.choose_condition()

        return self.conditions[index]
Exemplo n.º 6
0
    def do_add(self, line):
        """add [N]
        Add the specified number of groups"""

        data = parse_data(line)

        if len(data) >= 1:
            num_groups = int(data[0])
        else:
            num_groups = easyinput.input_int('number of groups')

        for i in range(1, num_groups+1):
            print "Adding group {}".format(i)
            self.btl.add_group(CombatGroup.from_input())
Exemplo n.º 7
0
    def do_temp(self, line):
        """temp [index] [amount]
        Add temporary hit points to the specified combatant"""

        data = parse_data(line)

        c = battle.do_combatant_select(self.btl, data)
        if not c:
            return
        
        if len(data) >= 2:
            amount = int(data[1])
        else:
            amount = easyinput.input_int('amount')

        c.add_temp_hp(amount)
Exemplo n.º 8
0
    def do_heal(self, line):
        """heal [index] [amount]
        Heal hit points for the specified combatant"""
        
        data = parse_data(line)

        c = battle.do_combatant_select(self.btl, data)
        if not c:
            return

        if len(data) >= 2:
            amount = int(data[1])
        else:
            amount = easyinput.input_int('amount')
            
        c.heal(amount)
Exemplo n.º 9
0
    def do_damage(self, line):
        """damage [index] [amount]
        Deals damage to the specified combatant"""

        data = parse_data(line)

        c = battle.do_combatant_select(self.btl, data)
        if not c:
            return

        if len(data) >= 2:
            amount = int(data[1])
        else:
            amount = easyinput.input_int('damage')
            
        c.damage(amount)
Exemplo n.º 10
0
    def begin(self):
        if self.is_started():
            print "Error: battle is already running"

        for g in self.groups:
            if g.is_solo_group() and g.get_member_by_pos(0).pc:
                g.set_init(easyinput.input_int('Initiative for {}'.format(g.name)))
            else:
                g.roll_init()

        self.groups.sort(reverse=True, key=lambda group: group.init)
        self.current = 0

        print '\nInitiative Roster:\n'
        for g in self.groups:
            print '{} ({})'.format(g.name, g.init)
        print ''

        self.next_round()
        self.get_current_group().begin_turn()
Exemplo n.º 11
0
    def add_group(self, group):
        # If battle is already going, need to know
        # where in the init order the new mooks go
        if self.is_started():
            if group.is_solo_group() and group.members[0].pc:
                group.set_init(easyinput.input_int('Initiative for {}'.format(group.name)))
            else:
                group.roll_init()

            added = False
            for i in range(len(self.groups)):
                if group.init > self.groups[i].init:
                    self.groups.insert(i, group)
                    added = True
                    break
            
            if not added:
                self.groups.append(group)
        else:
            self.groups.append(group)

        for i, c in group.members.items():
            self.combatant_hash[i] = c