Esempio n. 1
0
 def get_tile_from_id(self, tile_id):
     for terrain in self.terraindata.getroot().findall('terrain'):
         if tile_id == terrain.find('id').text or tile_id == int(terrain.find('id').text):
             tile = TileObject(terrain.get('name'), terrain.find('minimap').text, None, \
                               SaveLoad.intify_comma_list(terrain.find('mcost').text), \
                               terrain.find('walk').text, terrain.find('fly').text, \
                               [terrain.find('DEF').text, terrain.find('AVO').text])
             return tile
     else:
         logger.error('Could not find tile matching id: %s', tile_id)
         return None # Couldn't find any that match id
Esempio n. 2
0
 def populate_tiles(self, colorKeyObj, offset=(0,0)):
     for x in range(offset[0], len(colorKeyObj)):
         for y in range(offset[1], len(colorKeyObj[x])):
             cur = colorKeyObj[x-offset[0]][y-offset[1]]
             for terrain in self.terraindata.getroot().findall('terrain'):
                 colorKey = terrain.find('color').text.split(',')
                 if (int(cur[0]) == int(colorKey[0]) and int(cur[1]) == int(colorKey[1]) and int(cur[2]) == int(colorKey[2])):
                     # Instantiate
                     self.tiles[(x,y)] = TileObject(terrain.get('name'), terrain.find('minimap').text, (x,y), \
                                                    SaveLoad.intify_comma_list(terrain.find('mcost').text), \
                                                    terrain.find('walk').text, terrain.find('fly').text, \
                                                    [terrain.find('DEF').text, terrain.find('AVO').text])
                     if 'HP' in self.tile_info_dict[(x,y)]: # Tile hp is needed so apply that here
                         self.tiles[(x,y)].give_hp_stat(self.tile_info_dict[(x,y)]['HP'])
                     break
             else: # Never found terrain...
                 logger.error('Terrain matching colorkey %s never found.', cur)
Esempio n. 3
0
def itemparser(itemstring, itemdata=None):
    if itemdata is None: # Just in case so we don't have to keep passing itemdat around
        itemdata = ET.parse('Data/items.xml')
    Items = []
    if itemstring: # itemstring needs to exist
        idlist = itemstring.split(',')
        for itemid in idlist:
            droppable = False
            if itemid.startswith('d'):
                itemid = itemid[1:] # Strip the first d off
                droppable = True
            for item in itemdata.getroot().findall('item'):
                if item.find('id').text == itemid:
                    spritetype = item.find('spritetype').text
                    spriteid = item.find('spriteid').text
                    components = item.find('components').text
                    if components:
                        components = components.split(',')
                    else:
                        components = []
                    name = item.get('name')
                    value = item.find('value').text
                    rng = item.find('RNG').text
                    desc = item.find('desc').text
                    aoe = AOEComponent('Normal', 0)
                    if 'weapon' in components or 'spell' in components:
                        weapontype = item.find('weapontype').text
                        if weapontype == 'None':
                            weapontype = []
                        else:
                            weapontype = weapontype.split(',')
                    else:
                        weapontype = []

                    if 'locked' in components:
                        locked = True
                    else:
                        locked = False
                    status = []
                    status_on_hold = []

                    my_components = {}
                    for component in components:
                        if component == 'uses':
                            uses = item.find('uses').text
                            my_components['uses'] = UsesComponent(int(uses))
                        elif component == 'c_uses':
                            c_uses = item.find('c_uses').text
                            my_components['c_uses'] = CUsesComponent(int(c_uses))
                        elif component == 'weapon':
                            stats = [item.find('stats')[0].text, item.find('stats')[1].text, item.find('stats')[2].text]
                            my_components['weapon'] = WeaponComponent(stats)
                        elif component == 'usable':
                            my_components['usable'] = UsableComponent()
                        elif component == 'spell':
                            lvl = item.find('LVL').text
                            targets = item.find('targets').text
                            my_components['spell'] = SpellComponent(lvl, targets)
                        elif component == 'status':
                            statusid = item.find('status').text.split(',')
                            for s_id in statusid:
                                status.append(StatusObject.statusparser(s_id)) # Item now has associated status object.
                        elif component == 'status_on_hold':
                            statusid = item.find('status_on_hold').text.split(',')
                            for s_id in statusid:
                                status_on_hold.append(StatusObject.statusparser(s_id)) # Item now has associated status on hold object
                        elif component == 'effective':
                            effective_against = item.find('effective').text.split(',')
                            my_components['effective'] = EffectiveComponent(effective_against)
                        elif component == 'permanent_stat_increase':
                            stat_increase = SaveLoad.intify_comma_list(item.find('stat_increase').text)
                            my_components['permanent_stat_increase'] = PermanentStatIncreaseComponent(stat_increase)
                        elif component == 'aoe':
                            info_line = item.find('aoe').text.split(',')
                            aoe = AOEComponent(info_line[0], int(info_line[1]))
                        elif component == 'heal':
                            my_components['heal'] = item.find('heal').text
                        elif component == 'damage':
                            my_components['damage'] = int(item.find('damage').text)
                        elif component == 'hit':
                            my_components['hit'] = int(item.find('hit').text)
                        elif component == 'weight':
                            my_components['WT'] = int(item.find('WT').text)
                        elif component == 'exp':
                            my_components['exp'] = int(item.find('exp').text)
                        elif component == 'wexp_increase':
                            my_components['wexp_increase'] = int(item.find('wexp_increase').text)
                        elif component in ['movement', 'self_movement']:
                            mode, magnitude = item.find(component).text.split(',')
                            my_components[component] = MovementComponent(mode, magnitude)
                        elif component == 'summon':
                            summon = item.find('summon')
                            klass = summon.find('klass').text
                            items = summon.find('items').text
                            name = summon.find('name').text
                            desc = summon.find('desc').text
                            ai = summon.find('ai').text
                            s_id = summon.find('s_id').text
                            my_components['summon'] = SummonComponent(klass, items, name, desc, ai, s_id)
                        else:
                            my_components[component] = True
                    currentItem = ItemObject(itemid, name, spritetype, spriteid, my_components, value, rng, desc, \
                                                         aoe, weapontype, status, status_on_hold, droppable=droppable, locked=locked)

                    Items.append(currentItem)   
                    
    return Items
Esempio n. 4
0
def statusparser(s_id):
    for status in GC.STATUSDATA.getroot().findall('status'):
        if status.find('id').text == s_id:
            components = status.find('components').text
            if components:
                components = components.split(',')
            else:
                components = []
            name = status.get('name')
            desc = status.find('desc').text
            image_index = status.find('image_index').text if status.find(
                'image_index') is not None else None
            if image_index:
                image_index = tuple(int(num) for num in image_index.split(','))
            else:
                image_index = (0, 0)

            my_components = {}
            for component in components:
                if component == 'time':
                    time = status.find('time').text
                    my_components['time'] = TimeComponent(time)
                elif component == 'stat_change':
                    my_components['stat_change'] = SaveLoad.intify_comma_list(
                        status.find('stat_change').text)
                    my_components['stat_change'].extend(
                        [0] * (cf.CONSTANTS['num_stats'] -
                               len(my_components['stat_change'])))
                elif component == 'upkeep_stat_change':
                    stat_change = SaveLoad.intify_comma_list(
                        status.find('upkeep_stat_change').text)
                    stat_change.extend(
                        [0] * (cf.CONSTANTS['num_stats'] - len(stat_change)))
                    my_components[
                        'upkeep_stat_change'] = UpkeepStatChangeComponent(
                            stat_change)
                elif component == 'endstep_stat_change':
                    stat_change = SaveLoad.intify_comma_list(
                        status.find('endstep_stat_change').text)
                    stat_change.extend(
                        [0] * (cf.CONSTANTS['num_stats'] - len(stat_change)))
                    my_components[
                        'endstep_stat_change'] = UpkeepStatChangeComponent(
                            stat_change)
                elif component == 'rhythm_stat_change':
                    change, reset, init_count, limit = status.find(
                        'rhythm_stat_change').text.split(';')
                    change = SaveLoad.intify_comma_list(change)
                    change.extend([0] *
                                  (cf.CONSTANTS['num_stats'] - len(change)))
                    reset = SaveLoad.intify_comma_list(reset)
                    init_count = int(init_count)
                    limit = int(limit)
                    my_components[
                        'rhythm_stat_change'] = RhythmStatChangeComponent(
                            change, reset, init_count, limit)
                elif component == 'endstep_rhythm_stat_change':
                    change, reset, init_count, limit = status.find(
                        'endstep_rhythm_stat_change').text.split(';')
                    change = SaveLoad.intify_comma_list(change)
                    change.extend([0] *
                                  (cf.CONSTANTS['num_stats'] - len(change)))
                    reset = SaveLoad.intify_comma_list(reset)
                    init_count = int(init_count)
                    limit = int(limit)
                    my_components[
                        'endstep_rhythm_stat_change'] = RhythmStatChangeComponent(
                            change, reset, init_count, limit)
                # Combat changes
                elif component == 'conditional_avoid':
                    avoid, conditional = status.find(
                        'conditional_avoid').text.split(';')
                    my_components['conditional_avoid'] = ConditionalComponent(
                        'conditional_avoid', avoid, conditional)
                elif component == 'conditional_hit':
                    hit, conditional = status.find(
                        'conditional_hit').text.split(';')
                    my_components['conditional_hit'] = ConditionalComponent(
                        'conditional_hit', hit, conditional)
                elif component == 'conditional_mt':
                    mt, conditional = status.find('conditional_mt').text.split(
                        ';')
                    my_components['conditional_mt'] = ConditionalComponent(
                        'conditional_mt', mt, conditional)
                elif component == 'conditional_resist':
                    mt, conditional = status.find(
                        'conditional_resist').text.split(';')
                    my_components['conditional_resist'] = ConditionalComponent(
                        'conditional_resist', mt, conditional)
                elif component == 'weakness':
                    damage_type, num = status.find('weakness').text.split(',')
                    my_components['weakness'] = WeaknessComponent(
                        damage_type, num)
                # Others...
                elif component == 'rescue':
                    my_components['rescue'] = RescueComponent()
                elif component == 'count':
                    my_components['count'] = CountComponent(
                        int(status.find('count').text))
                elif component == 'caretaker':
                    my_components['caretaker'] = int(
                        status.find('caretaker').text)
                elif component == 'remove_range':
                    my_components['remove_range'] = int(
                        status.find('remove_range').text)
                elif component == 'hp_percentage':
                    percentage = status.find('hp_percentage').text
                    my_components['hp_percentage'] = HPPercentageComponent(
                        percentage)
                elif component == 'upkeep_animation':
                    info_line = status.find('upkeep_animation').text
                    split_line = info_line.split(',')
                    my_components[
                        'upkeep_animation'] = UpkeepAnimationComponent(
                            split_line[0], split_line[1], split_line[2],
                            split_line[3])
                elif component == 'always_animation':
                    info_line = status.find('always_animation').text
                    split_line = info_line.split(',')
                    my_components[
                        'always_animation'] = AlwaysAnimationComponent(
                            split_line[0], split_line[1], split_line[2],
                            split_line[3])
                elif component == 'active':
                    charge = int(status.find('active').text)
                    my_components['active'] = getattr(ActiveSkill,
                                                      s_id)(name, charge)
                elif component == 'passive':
                    my_components['passive'] = getattr(ActiveSkill, s_id)(name)
                elif component == 'aura':
                    aura_range = int(status.find('range').text)
                    child = status.find('child').text
                    target = status.find('target').text
                    my_components['aura'] = ActiveSkill.Aura(
                        aura_range, target, child)
                elif status.find(component) is not None and status.find(
                        component).text:
                    my_components[component] = status.find(component).text
                else:
                    my_components[component] = True

            currentStatus = StatusObject(s_id, name, my_components, desc,
                                         image_index)

            return currentStatus
Esempio n. 5
0
def itemparser(itemstring):
    Items = []
    if itemstring:  # itemstring needs to exist
        idlist = itemstring.split(',')
        for itemid in idlist:
            droppable = False
            event_combat = False
            if itemid.startswith('d'):
                itemid = itemid[1:]  # Strip the first d off
                droppable = True
            elif itemid.startswith('e'):
                itemid = itemid[1:]
                event_combat = True
            try:
                item = GC.ITEMDATA[itemid]
            except KeyError as e:
                print("Key Error %s. %s cannot be found in items.xml" %
                      (e, itemid))
                continue

            components = item['components']
            if components:
                components = components.split(',')
            else:
                components = []

            aoe = AOEComponent('Normal', 0)
            if 'weapon' in components or 'spell' in components:
                weapontype = item['weapontype']
                if weapontype == 'None':
                    weapontype = None
            else:
                weapontype = None

            if 'locked' in components:
                locked = True
            else:
                locked = False
            status = []
            status_on_hold = []
            status_on_equip = []

            my_components = {}
            for component in components:
                if component == 'uses':
                    my_components['uses'] = UsesComponent(int(item['uses']))
                elif component == 'c_uses':
                    my_components['c_uses'] = CUsesComponent(
                        int(item['c_uses']))
                elif component == 'weapon':
                    stats = [item['MT'], item['HIT'], item['LVL']]
                    my_components['weapon'] = WeaponComponent(stats)
                elif component == 'usable':
                    my_components['usable'] = UsableComponent()
                elif component == 'spell':
                    my_components['spell'] = SpellComponent(
                        item['LVL'], item['targets'])
                elif component == 'extra_select':
                    my_components['extra_select'] = [
                        ExtraSelectComponent(*c.split(','))
                        for c in item['extra_select'].split(';')
                    ]
                    my_components['extra_select_index'] = 0
                    my_components['extra_select_targets'] = []
                elif component == 'status':
                    statusid = item['status'].split(',')
                    for s_id in statusid:
                        status.append(s_id)
                elif component == 'status_on_hold':
                    statusid = item['status_on_hold'].split(',')
                    for s_id in statusid:
                        status_on_hold.append(s_id)
                elif component == 'status_on_equip':
                    statusid = item['status_on_equip'].split(',')
                    for s_id in statusid:
                        status_on_equip.append(s_id)
                elif component == 'effective':
                    try:
                        effective_against, bonus = item['effective'].split(';')
                        effective_against = effective_against.split(',')
                        my_components['effective'] = EffectiveComponent(
                            effective_against, int(bonus))
                    except:
                        continue
                elif component == 'permanent_stat_increase':
                    stat_increase = SaveLoad.intify_comma_list(
                        item['stat_increase'])
                    my_components[
                        'permanent_stat_increase'] = PermanentStatIncreaseComponent(
                            stat_increase)
                elif component == 'promotion':
                    legal_classes = item['promotion'].split(',')
                    my_components['promotion'] = legal_classes
                elif component == 'aoe':
                    info_line = item['aoe'].split(',')
                    aoe = AOEComponent(info_line[0], int(info_line[1]))
                # Affects map animation
                elif component == 'map_hit_color':
                    my_components['map_hit_color'] = tuple(
                        int(c) for c in item['map_hit_color'].split(','))
                    assert len(my_components['map_hit_color']
                               ) == 3  # No translucency allowed right now
                elif component in ('damage', 'hit', 'weight', 'exp', 'crit',
                                   'wexp_increase', 'wexp'):
                    if component in item:
                        my_components[component] = int(item[component])
                elif component in ('movement', 'self_movement'):
                    mode, magnitude = item[component].split(',')
                    my_components[component] = MovementComponent(
                        mode, magnitude)
                elif component == 'summon':
                    klass = item['summon_klass']
                    items = item['summon_items']
                    name = item['summon_name']
                    desc = item['summon_desc']
                    ai = item['summon_ai']
                    s_id = item['summon_s_id']
                    my_components['summon'] = SummonComponent(
                        klass, items, name, desc, ai, s_id)
                elif component in item:
                    my_components[component] = item[component]
                else:
                    my_components[component] = True
            currentItem = ItemObject(itemid,
                                     item['name'],
                                     item['spritetype'],
                                     item['spriteid'],
                                     my_components,
                                     item['value'],
                                     item['RNG'],
                                     item['desc'],
                                     aoe,
                                     weapontype,
                                     status,
                                     status_on_hold,
                                     status_on_equip,
                                     droppable=droppable,
                                     locked=locked,
                                     event_combat=event_combat)

            Items.append(currentItem)
    return Items
Esempio n. 6
0
def statusparser(status_string, statusdata=None):
    if statusdata is None: # Just in case so we don't have to keep passing statusdata around
        statusdata = ET.parse('Data/status.xml')
    Status = []
    if status_string: # itemstring needs to exist
        for status in statusdata.getroot().findall('status'):
            if status.find('id').text == status_string:
                components = status.find('components').text
                if components:
                    components = components.split(',')
                else:
                    components = []
                name = status.get('name')
                desc = status.find('desc').text
                icon_index = status.find('icon_index').text if status.find('icon_index') is not None else None
                if icon_index:
                    icon_index = tuple(int(num) for num in icon_index.split(','))
                else:
                    icon_index = (0,0)

                my_components = {}
                for component in components:
                    if component == 'time':
                        time = status.find('time').text
                        my_components['time'] = TimeComponent(time)
                    elif component == 'stat_change':
                        my_components['stat_change'] = SaveLoad.intify_comma_list(status.find('stat_change').text)
                    elif component == 'upkeep_stat_change':
                        stat_change = SaveLoad.intify_comma_list(status.find('upkeep_stat_change').text)
                        my_components['upkeep_stat_change'] = UpkeepStatChangeComponent(stat_change)
                    elif component == 'endstep_stat_change':
                        stat_change = SaveLoad.intify_comma_list(status.find('endstep_stat_change').text)
                        my_components['endstep_stat_change'] = UpkeepStatChangeComponent(stat_change)
                    elif component == 'rhythm_stat_change':
                        change, reset, init_count, limit = status.find('rhythm_stat_change').text.split(';')
                        change = SaveLoad.intify_comma_list(change)
                        reset = SaveLoad.intify_comma_list(reset)
                        init_count = int(init_count)
                        limit = int(limit)
                        my_components['rhythm_stat_change'] = RhythmStatChangeComponent(change, reset, init_count, limit)
                    elif component == 'endstep_rhythm_stat_change':
                        change, reset, init_count, limit = status.find('endstep_rhythm_stat_change').text.split(';')
                        change = SaveLoad.intify_comma_list(change)
                        reset = SaveLoad.intify_comma_list(reset)
                        init_count = int(init_count)
                        limit = int(limit)
                        my_components['endstep_rhythm_stat_change'] = RhythmStatChangeComponent(change, reset, init_count, limit)
                    # Combat changes
                    elif component == 'avoid':
                        avoid = status.find('avoid').text
                        my_components['avoid'] = avoid
                    elif component == 'hit':
                        hit = status.find('hit').text
                        my_components['hit'] = hit
                    elif component == 'mt':
                        mt = status.find('mt').text
                        my_components['mt'] = mt
                    elif component == 'conditional_avoid':
                        avoid, conditional = status.find('conditional_avoid').text.split(';')
                        my_components['conditional_avoid'] = ConditionalComponent('conditional_avoid', avoid, conditional)
                    elif component == 'conditional_hit':
                        hit, conditional = status.find('conditional_hit').text.split(';')
                        my_components['conditional_hit'] = ConditionalComponent('conditional_hit', hit, conditional)
                    elif component == 'conditional_mt':
                        mt, conditional = status.find('conditional_mt').text.split(';')
                        my_components['conditional_mt'] = ConditionalComponent('conditional_mt', mt, conditional)
                    elif component == 'conditional_resist':
                        mt, conditional = status.find('conditional_resist').text.split(';')
                        my_components['conditional_resist'] = ConditionalComponent('conditional_resist', mt, conditional)
                    elif component == 'weakness':
                        damage_type, num = status.find('weakness').text.split(',')
                        my_components['weakness'] = WeaknessComponent(damage_type, num)
                    # Others...
                    elif component == 'rescue':
                        my_components['rescue'] = RescueComponent()
                    elif component == 'count':
                        my_components['count'] = CountComponent(int(status.find('count').text))
                    elif component == 'vampire':
                        my_components['vampire'] = status.find('vampire').text
                    elif component == 'caretaker':
                        my_components['caretaker'] = int(status.find('caretaker').text)
                    elif component == 'hp_percentage':
                        percentage = status.find('hp_percentage').text
                        my_components['hp_percentage'] = HPPercentageComponent(percentage)
                    elif component == 'upkeep_animation':
                        info_line = status.find('upkeep_animation').text
                        split_line = info_line.split(',')
                        my_components['upkeep_animation'] = UpkeepAnimationComponent(split_line[0], split_line[1], split_line[2], split_line[3])
                    elif component == 'always_animation':
                        info_line = status.find('always_animation').text
                        split_line = info_line.split(',')
                        my_components['always_animation'] = AlwaysAnimationComponent(split_line[0], split_line[1], split_line[2], split_line[3])
                    elif component == 'active':
                        charge = int(status.find('active').text)
                        my_components['active'] = ActiveSkill.active_skill_dict[name](name, charge)
                    elif component == 'passive':
                        my_components['passive'] = ActiveSkill.passive_skill_dict[name](name)
                    elif component == 'aura':
                        aura_range = int(status.find('range').text)
                        child = status.find('child').text
                        target = status.find('target').text
                        my_components['aura'] = ActiveSkill.Aura(aura_range, target, child)
                    elif component == 'status_after_battle':
                        child = status.find('status_after_battle').text
                        my_components['status_after_battle'] = child
                    elif component == 'status_on_complete':
                        child = status.find('status_on_complete').text
                        my_components['status_on_complete'] = child
                    elif component == 'ai':
                        ai = status.find('ai').text
                        my_components['ai'] = ai
                    else:
                        my_components[component] = True

                currentStatus = StatusObject(status_string, name, my_components, desc, icon_index)

                return currentStatus