コード例 #1
0
ファイル: tables.py プロジェクト: borntyping-sandbox/misc
def rollTable(tbl, mod=0):
    """Roll against a dice/result table.
    """
    logger.info("Dice spec: %s", tbl['dice'],)
    try:
        rolls = [int(n) for n in tbl['rolls']]
        logger.info("Rolls: %s", rolls,)
        results = tbl['results']
        logger.info("Results: %s", results,)
    except KeyError:
        rolls = []
    
    r = dcalc.calculate(tbl['dice'])
    logger.info("Roll: %s", r,)
    result = r
    if r in rolls:
        i = rolls.index(r)
        try:
            result = results[i]
        except IndexError, e:
            raise IndexError, \
                """Roll: %s
Index: %s in rolls:
%s (length %s)
no corresponding index for roll in
%s (length %s)""" % (r, i, rolls, len(rolls), results, len(results))
コード例 #2
0
ファイル: tables.py プロジェクト: eykd/Dyce
def rollTable(tbl, mod=0):
    """Roll against a dice/result table.
    """
    logger.info("Dice spec: %s", tbl['dice'],)
    try:
        rolls = [int(n) for n in tbl['rolls']]
        logger.info("Rolls: %s", rolls,)
        results = tbl['results']
        logger.info("Results: %s", results,)
    except KeyError:
        rolls = []
    
    r = dcalc.calculate(tbl['dice'])
    logger.info("Roll: %s", r,)
    result = r
    if r in rolls:
        i = rolls.index(r)
        try:
            result = results[i]
        except IndexError:
            raise IndexError(
                """Roll: %s
Index: %s in rolls:
%s (length %s)
no corresponding index for roll in
%s (length %s)""" % (r, i, rolls, len(rolls), results, len(results)))
    else:
        result = r
        
    if str(result).startswith('reroll'):
        if ':' in result:
            new_tbl = tbl[result.split(':', 1)[1]]
            result = rollTable(new_tbl)
        else:
            result = rollTable(tbl)
    elif result == 'None':
        result = None

    return result