Beispiel #1
0
def testroll(dicestr=None, target=None):
    results = []
    for idx in range(6):
        if dicestr is None:
            results.append(str(Traveller.roll(target)))
        else:
            results.append(str(Traveller.roll(dicestr, target)))
    if dicestr is None:
        dicestr = 'Traveller.default'
    print('%s target=%s: %s' % (str(dicestr), target, " ".join(results)))
Beispiel #2
0
    def changeStr(self, command, debug=False):
        self.history.append('Adding %s' % command)
        if type(command) == list:
            raise ValueError(
                'For changeCharacter, command can not be a list (yet).')
        parts = command.split(' ')
        logging.debug('In changeStr: %s' % "|".join(parts))
        if len(parts) == 1 and not Traveller.iscr(parts[0]):
            self.change(('skill', parts[0], 'add', '1'))
        elif len(parts) == 2:
            # ''+1 Dex' -> 'attr, dex, add 1'
            if parts[1].lower() in Character.attrShort:
                self.change(('attr', parts[1], 'add', str(parts[0])))

            # '10' , '$10', 'cr10' -> money onhand add 10
            if parts[1].startswith('$') == '$' or re.match(
                    '[Cc][Rr]', parts[1]):
                self.change(('money', parts[1], 'add', str(parts[0])))
Beispiel #3
0
        parsed = command.split(' ')
        result = self.roll(attr=parsed[0], target=parsed[1], debug=debug)
        if debug:
            print('in checkStr(%s): attr=%s target=%s  result was %s' %
                  (command, parsed[0], parsed[1], result))
        return result

    def doBasicTraining(self, character):
        self.history.append('In basic training')
        for skill in self.config['ServiceDevelopment'].results():
            character.changeStr(skill)


if __name__ == '__main__':
    print('Test Traveller Code:')
    print("Roll 1 dice: %d" % Traveller.roll(1))
    print("Roll 2 dice: %d" % Traveller.roll(2))

    print("Roll 8+ on 2 dice %s" % Traveller.roll(2, '8+'))
    print("Roll 10+ on 2 dice %s" % Traveller.roll(2, '10+'))
    print("Roll 8+ on 2 dice %s" % Traveller.roll('8+'))
    print("Roll 10+ on 2 dice %s" % Traveller.roll('10+'))

    print("Roll 13+ on 2 dice %s" % Traveller.roll(2, '13+'))
    print("Roll 13+ on 2 dice %s" % Traveller.roll(2, '13+'))
    print("Roll 13+ on 2 dice %s" % Traveller.roll('13+'))
    print("Roll 13+ on 2 dice %s" % Traveller.roll('13+'))

    print("Roll 1+ on 2 dice %s" % Traveller.roll(2, '1+'))
    print("Roll 1+ on 2 dice %s" % Traveller.roll(2, '1+'))
    print("Roll 1+ on 2 dice %s" % Traveller.roll('1+'))
Beispiel #4
0
 def test_15(self):
    result = Traveller.roll(target='7+', dm='-1')
    self.assertFalse(result)
Beispiel #5
0
# Traveller.  CephenusEngine inherits from Traveller when the rules are the
# same.  If you want to use ClassTraveler rules (from the LBBs), then you
# should use the Traveller file instead of CepheusEngine, below:

import sys

sys.path.append('..')
from CepheusEngine import Career, Character
from Traveller import Traveller

# TODO: do we need that Traveller line above?

# Let's start out with the basic Traveller functionality.

# In traveller, the default roll is two dice, so if you just say roll, it is 2d6:
print("Defaut Traveller roll, which is 2d6: %d" % Traveller.roll())

#print("Roll 2 dice: %d" % Traveller.roll(2))

# Traveller has target numbers, like you must roll 8 or higher:
print("Roll 8+ on 2 dice %s" % Traveller.roll('8+'))
# Notice that this returns true or false, not the actual number.

# Traveller also has dice modifiers, for adding +2 to your roll:
print("Roll 8+ with a dice modifier of +2 %s" % Traveller.roll('8+', +2))

# Using Python's named arguments, you can change the order of the arguments,
# if you want to:
print("Roll 8+ with a dice modifier of +2 %s" %
      Traveller.roll(dm=+2, target='8+'))
Beispiel #6
0
 def test_13(self):
    result = Traveller.roll(dm='+0')
    self.assertEqual(result, 4)
Beispiel #7
0
 def test_14(self):
    result = Traveller.roll(target='5-', dm='+1')
    self.assertTrue(result)
Beispiel #8
0
 def test_12(self):
    result = Traveller.roll(dm='-1')
    self.assertEqual(result, 3)
Beispiel #9
0
 def test_11(self):
    result = Traveller.roll(dm='+1')
    self.assertEqual(result, 5)
Beispiel #10
0
 def test_3(self):
    result = Traveller.roll(3)
    self.assertEqual(result, 6)
Beispiel #11
0
 def test_2(self):
    result = Traveller.roll(1)
    self.assertEqual(result, 2)
Beispiel #12
0
 def test_1(self):
    result = Traveller.roll()
    self.assertEqual(result, 4)