Esempio n. 1
0
def dispatch_stats(line, env={}):
    """Stat printing code!

    Because `ls card <card>` doesn't make any damn sense we have stats! Stats
    exists to print the stat line and weapons stats for some card, and operates
    by looking up the stats from the env object and then writing them to
    standard out.

    Valid commands:
        'stats <card>'

    """
    if(line[0] == "stats"):
        if(len(line) >= 2 and line[1] in env['models']):
            model = env['models'][helpers.resolve_name(line[1],
                                                       env['model aliases'])]
            print(str(model))
        return (env, True)

    else:
        return (env, False)
Esempio n. 2
0
def dispatch_stats(line, env={}):
    """Stat printing code!

    Because `ls card <card>` doesn't make any damn sense we have stats! Stats
    exists to print the stat line and weapons stats for some card, and operates
    by looking up the stats from the env object and then writing them to
    standard out.

    Valid commands:
        'stats <card>'

    """
    if (line[0] == "stats"):
        if (len(line) >= 2 and line[1] in env['models']):
            model = env['models'][helpers.resolve_name(line[1],
                                                       env['model aliases'])]
            print(str(model))
        return (env, True)

    else:
        return (env, False)
Esempio n. 3
0
def dispatch_attack(line,env={}):
    """Attack code!

    This is what this entire tool was built for... It parses an attack
    description, being one model vs another, then computes and dumps a
    stats table projecting the success likelyhoods and average
    outcomes of such an attack. The <name> fields are resolved for
    aliases, so feel free to create shortcuts.

    Valid commands are:
        'attack <name> [with ([def|arm|pow|mat|rat|strength] [-|+|=]<number>)+ end]
                <name> [with ([def|arm|pow|mat|rat|strength] [-|+|=]<number>)+ end]'

    Examples:
        'attack Defender with mat +2 strength +5 end Lancer'
        'attack Defender Lancer'
        'attack estryker Defender'

    """
    if(line[0] == "attack"):
        if(len(line) < 3):
            help(dispatch_attack)
            return (env, False)

        else:
            a_model = line[1]
            a_with,i = helpers.parse_with(line, 2)
            d_model = line[i]
            i += 1
            d_with,i = helpers.parse_with(line, i)

            a_model = helpers.resolve_name(a_model,env['model aliases'])
            if a_model in env['models']:
                a_model = env['models'][a_model]
            else:
                print("ERROR: model %s was not found! aborting..." % a_model)
                return (env, False)

            d_model = helpers.resolve_name(d_model,env['model aliases'])
            if d_model in env['models']:
                d_model = env['models'][d_model]
            else:
                print("ERROR: model %s was not found! aborting..." % d_model)
                return (env, False)

            def update_fn(stat_map):
                def closured_fn(state):
                    """A semantic closure hack to implement a real lambda with an
                    environment. Friggin python man.

                    """
                    attr_aliases = {'str':'strength','def':'defense','arm':'armor'}
                    for key in stat_map:
                        tgt_key = key
                        # a little hack to get the str alias..
                        if key in attr_aliases:
                            tgt_key = attr_aliases[key]
                        # throw a warning and continue for weird keys..
                        if tgt_key not in state:
                            print("WARNING: modifier for %s ignored!" % key)
                            continue

                        # parse and apply the val!
                        val = stat_map[key]
                        if(val[0] == '-'):
                            state[tgt_key] -= int(val[1:])
                        elif(val[0] == '='):
                            state[tgt_key] = int(val[1:])
                        elif(val[0] == '+'):
                            state[tgt_key] += int(val[1:])
                        else:
                            state[tgt_key] += int(val)
                    return state
                return closured_fn

            a_id = a_model.addEffect(update_fn(a_with))
            d_id = d_model.addEffect(update_fn(d_with))

            # just for grins print the current stats..
            print("\nattacking:")
            print(str(a_model))
            print("\ndefending:")
            print(str(d_model))
            print("\n")

            # now go ahead and do the attack evaluation #
            wm.evaluate_attack(a_model, d_model)

            # remove those effects from the models..
            a_model.removeEffect(a_id)
            d_model.removeEffect(d_id)

            # and return!
            return (env, True)
    else:
        return (env, False)
Esempio n. 4
0
def dispatch_attack(line, env={}):
    """Attack code!

    This is what this entire tool was built for... It parses an attack
    description, being one model vs another, then computes and dumps a
    stats table projecting the success likelyhoods and average
    outcomes of such an attack. The <name> fields are resolved for
    aliases, so feel free to create shortcuts.

    Valid commands are:
        'attack <name> [with ([def|arm|pow|mat|rat|strength] [-|+|=]<number>)+ end]
                <name> [with ([def|arm|pow|mat|rat|strength] [-|+|=]<number>)+ end]'

    Examples:
        'attack Defender with mat +2 strength +5 end Lancer'
        'attack Defender Lancer'
        'attack estryker Defender'

    """
    if (line[0] == "attack"):
        if (len(line) < 3):
            help(dispatch_attack)
            return (env, False)

        else:
            a_model = line[1]
            a_with, i = helpers.parse_with(line, 2)
            d_model = line[i]
            i += 1
            d_with, i = helpers.parse_with(line, i)

            a_model = helpers.resolve_name(a_model, env['model aliases'])
            if a_model in env['models']:
                a_model = env['models'][a_model]
            else:
                print("ERROR: model %s was not found! aborting..." % a_model)
                return (env, False)

            d_model = helpers.resolve_name(d_model, env['model aliases'])
            if d_model in env['models']:
                d_model = env['models'][d_model]
            else:
                print("ERROR: model %s was not found! aborting..." % d_model)
                return (env, False)

            def update_fn(stat_map):
                def closured_fn(state):
                    """A semantic closure hack to implement a real lambda with an
                    environment. Friggin python man.

                    """
                    attr_aliases = {
                        'str': 'strength',
                        'def': 'defense',
                        'arm': 'armor'
                    }
                    for key in stat_map:
                        tgt_key = key
                        # a little hack to get the str alias..
                        if key in attr_aliases:
                            tgt_key = attr_aliases[key]
                        # throw a warning and continue for weird keys..
                        if tgt_key not in state:
                            print("WARNING: modifier for %s ignored!" % key)
                            continue

                        # parse and apply the val!
                        val = stat_map[key]
                        if (val[0] == '-'):
                            state[tgt_key] -= int(val[1:])
                        elif (val[0] == '='):
                            state[tgt_key] = int(val[1:])
                        elif (val[0] == '+'):
                            state[tgt_key] += int(val[1:])
                        else:
                            state[tgt_key] += int(val)
                    return state

                return closured_fn

            a_id = a_model.addEffect(update_fn(a_with))
            d_id = d_model.addEffect(update_fn(d_with))

            # just for grins print the current stats..
            print("\nattacking:")
            print(str(a_model))
            print("\ndefending:")
            print(str(d_model))
            print("\n")

            # now go ahead and do the attack evaluation #
            wm.evaluate_attack(a_model, d_model)

            # remove those effects from the models..
            a_model.removeEffect(a_id)
            d_model.removeEffect(d_id)

            # and return!
            return (env, True)
    else:
        return (env, False)