Beispiel #1
0
def create_summon(summon_info, summoner, position, metaDataObj, gameStateObj):
    # Important Info
    class_dict = metaDataObj['class_dict']
    u_i = {}

    GC.U_ID += 1
    u_i['u_id'] = GC.U_ID

    classes = summon_info.klass.split(',')
    u_i['level'] = summoner.level
    u_i['position'] = position
    u_i['team'] = summoner.team
    u_i['event_id'] = 0
    u_i['gender'] = 0
    classes = classes[:class_dict[summoner.klass]['tier'] + 1]
    u_i['klass'] = classes[-1]
    u_i['faction_icon'] = summoner.faction_icon
    u_i['name'] = summon_info.name
    u_i['desc'] = summon_info.desc
    u_i['ai'] = summon_info.ai
    u_i['tags'] = set(class_dict[u_i['klass']]['tags'].split(
        ',')) if class_dict[u_i['klass']]['tags'] else set()
    u_i['tags'].add('Summon_' + str(summon_info.s_id) + '_' +
                    str(summoner.id))  # Add unique identifier
    u_i['movement_group'] = class_dict[u_i['klass']]['movement_group']

    stats, u_i['growths'], u_i['growth_points'], u_i['items'], u_i['wexp'], u_i['level'] = \
        get_unit_info(class_dict, u_i['team'], u_i['klass'], u_i['level'], summon_info.item_line, gameStateObj.mode, gameStateObj.game_constants)
    u_i['stats'] = build_stat_dict(stats)
    unit = UnitObject.UnitObject(u_i)

    # Status Effects and Skills
    my_seed = sum(u_i['position']) if u_i['position'] else 0
    get_skills(class_dict,
               unit,
               classes,
               u_i['level'],
               gameStateObj,
               seed=my_seed)

    return unit
Beispiel #2
0
def create_unit(unitLine, allunits, factions, reinforceUnits, metaDataObj,
                gameStateObj):
    assert len(unitLine) in (
        9, 10
    ), "unitLine %s must have length 9 or 10 (if optional status)" % (unitLine)
    legend = {
        'team': unitLine[0],
        'unit_type': unitLine[1],
        'event_id': unitLine[2],
        'class': unitLine[3],
        'level': unitLine[4],
        'items': unitLine[5],
        'position': unitLine[6],
        'ai': unitLine[7],
        'faction': unitLine[8]
    }
    class_dict = metaDataObj['class_dict']

    u_i = {}

    GC.U_ID += 1
    u_i['u_id'] = GC.U_ID

    u_i['team'] = legend['team']
    u_i['event_id'] = legend['event_id']
    if legend['class'].endswith('F'):
        legend['class'] = legend['class'][:-1]  # strip off the F
        u_i['gender'] = 5  # Default female gender is 5
    else:
        u_i['gender'] = 0  # Default male gender is 0
    classes = legend['class'].split(',')
    u_i['klass'] = classes[-1]
    # Give default previous class
    default_previous_classes(u_i['klass'], classes, class_dict)

    force_fixed = False
    if (legend['level'].startswith('f')):  # Force fixed level up
        legend['level'] = legend['level'][1:]
        force_fixed = True
    u_i['level'] = int(legend['level'])
    u_i['position'] = tuple([
        int(num) for num in legend['position'].split(',')
    ]) if ',' in legend['position'] else None
    u_i['name'], u_i['faction_icon'], u_i['desc'] = factions[legend['faction']]

    stats, u_i['growths'], u_i['growth_points'], u_i['items'], u_i['wexp'], u_i['level'] = \
        get_unit_info(class_dict, u_i['team'], u_i['klass'], u_i['level'], legend['items'],
                      gameStateObj.mode, gameStateObj.game_constants, force_fixed=force_fixed)
    u_i['stats'] = build_stat_dict(stats)
    logger.debug("%s's stats: %s", u_i['name'], u_i['stats'])

    u_i['tags'] = class_dict[u_i['klass']]['tags']
    u_i['ai'] = legend['ai']
    u_i['movement_group'] = class_dict[u_i['klass']]['movement_group']

    cur_unit = UnitObject.UnitObject(u_i)

    # Reposition units
    if u_i['event_id'] != "0":  # Unit does not start on board
        cur_unit.position = None
        reinforceUnits[u_i['event_id']] = (cur_unit.id, u_i['position'])
    else:  # Unit does start on board
        cur_unit.position = u_i['position']

    # Status Effects and Skills
    get_skills(class_dict,
               cur_unit,
               classes,
               u_i['level'],
               gameStateObj,
               feat=False)

    # Extra Skills
    if len(unitLine) == 10:
        statuses = [
            StatusObject.statusparser(status)
            for status in unitLine[9].split(',')
        ]
        for status in statuses:
            StatusObject.HandleStatusAddition(status, cur_unit, gameStateObj)

    allunits.append(cur_unit)
    return cur_unit
Beispiel #3
0
def add_unit_from_legend(legend, allunits, reinforceUnits, metaDataObj,
                         gameStateObj):
    class_dict = metaDataObj['class_dict']
    for unit in GC.UNITDATA.getroot().findall('unit'):
        if unit.find('id').text == legend['unit_id']:
            u_i = {}
            u_i['u_id'] = unit.find('id').text
            u_i['event_id'] = legend['event_id']
            u_i['position'] = tuple([
                int(num) for num in legend['position'].split(',')
            ]) if ',' in legend['position'] else None
            u_i['name'] = unit.get('name')
            u_i['team'] = legend['team']

            classes = unit.find('class').text.split(',')
            u_i['klass'] = classes[-1]
            # Give default previous class
            default_previous_classes(u_i['klass'], classes, class_dict)
            u_i['gender'] = int(unit.find('gender').text)
            u_i['level'] = int(unit.find('level').text)

            stats = intify_comma_list(unit.find('bases').text)
            for n in range(len(stats), cf.CONSTANTS['num_stats']):
                stats.append(class_dict[u_i['klass']]['bases'][n])
            if u_i['team'] == 'player' or u_i[
                    'team'] == 'other':  # Modify stats
                mode_bases = gameStateObj.mode['player_bases']
                mode_growths = gameStateObj.mode['player_growths']
            else:
                mode_bases = gameStateObj.mode['enemy_bases']
                mode_growths = gameStateObj.mode['enemy_growths']
            stats = [sum(x) for x in zip(stats, mode_bases)]
            assert len(stats) == cf.CONSTANTS[
                'num_stats'], "bases %s must be exactly %s integers long" % (
                    stats, cf.CONSTANTS['num_stats'])

            u_i['growths'] = intify_comma_list(unit.find('growths').text)
            u_i['growths'].extend(
                [0] * (cf.CONSTANTS['num_stats'] - len(u_i['growths'])))
            u_i['growths'] = [
                sum(x) for x in zip(u_i['growths'], mode_growths)
            ]
            assert len(u_i['growths']) == cf.CONSTANTS[
                'num_stats'], "growths %s must be exactly %s integers long" % (
                    stats, cf.CONSTANTS['num_stats'])

            num_levelups = u_i['level'] - 1 + (
                cf.CONSTANTS['promoted_level']
                if class_dict[u_i['klass']]['tier'] > 1 else 0)
            stats, u_i['growth_points'] = auto_level(
                stats, mode_growths, num_levelups,
                class_dict[u_i['klass']]['max'], gameStateObj.mode)

            u_i['stats'] = build_stat_dict(stats)
            logger.debug("%s's stats: %s", u_i['name'], u_i['stats'])

            if 'items' in legend:
                u_i['items'] = legend['items']
            else:
                u_i['items'] = ItemMethods.itemparser(
                    unit.find('inventory').text)
            # Parse wexp
            u_i['wexp'] = unit.find('wexp').text.split(',')
            for index, wexp in enumerate(u_i['wexp'][:]):
                if wexp in Weapons.EXP.wexp_dict:
                    u_i['wexp'][index] = Weapons.EXP.wexp_dict[wexp]
            u_i['wexp'] = [int(num) for num in u_i['wexp']]

            assert len(u_i['wexp']) == len(
                Weapons.TRIANGLE.types
            ), "%s's wexp must have as many slots as there are weapon types." % (
                u_i['name'])

            u_i['desc'] = unit.find('desc').text
            # Tags
            class_tags = class_dict[u_i['klass']]['tags']
            personal_tags = set(unit.find('tags').text.split(
                ',')) if unit.find('tags') is not None and unit.find(
                    'tags').text is not None else set()
            u_i['tags'] = class_tags | personal_tags

            u_i['ai'] = legend['ai']
            u_i['movement_group'] = class_dict[u_i['klass']]['movement_group']

            cur_unit = UnitObject.UnitObject(u_i)

            if u_i['event_id'] != "0":  # unit does not start on board
                cur_unit.position = None
                reinforceUnits[u_i['event_id']] = (u_i['u_id'],
                                                   u_i['position'])
            else:  # Unit does start on board
                cur_unit.position = u_i['position']

            # Status Effects and Skills
            get_skills(class_dict,
                       cur_unit,
                       classes,
                       u_i['level'],
                       gameStateObj,
                       feat=False)
            # Personal Skills
            personal_skills = unit.find('skills').text.split(
                ',') if unit.find('skills') is not None and unit.find(
                    'skills').text is not None else []
            c_s = [
                StatusObject.statusparser(status) for status in personal_skills
            ]
            for status in c_s:
                if status:
                    StatusObject.HandleStatusAddition(status, cur_unit,
                                                      gameStateObj)
            # handle having a status that gives stats['HP']
            cur_unit.set_hp(int(cur_unit.stats['HP']))

            allunits.append(cur_unit)
            return cur_unit