Пример #1
0
def get_unit_info(class_dict, klass, level, item_line):
    # Handle stats
    movement = class_dict[klass]['movement']
    # hp, str, mag, skl, spd, lck, def, res, con
    growths = class_dict[klass]['growths'][:] # Using copies
    bases = class_dict[klass]['bases'][:] # Using copies
    stats, growth_points = auto_level(bases, growths, level)
    # Make sure we don't exceed max
    stats = [min(class_dict[klass]['max'][index], stat) for index, stat in enumerate(stats)]
    stats.append(movement)

    # Handle items
    items = ItemMethods.itemparser(item_line)

    # Handle required wexp
    wexp = class_dict[klass]['wexp_gain']
    for item in items:
        if item.weapon:
            weapon_types = item.TYPE
            item_level = item.weapon.LVL
        elif item.spell:
            weapon_types = item.TYPE
            item_level = item.spell.LVL
        else:
            continue
        for weapon_type in weapon_types:
            wexp_index = CustomObjects.WEAPON_TRIANGLE.type_to_index[weapon_type]
            item_requirement = CustomObjects.WEAPON_EXP.wexp_dict[item_level]
            if item_requirement > wexp[wexp_index] and wexp[wexp_index] > 0:
                wexp[wexp_index] = item_requirement

    return stats, growths, growth_points, items, wexp
Пример #2
0
 def apply_mod(self, item):
     self.reverse_mod(item)
     if Weapons.TRIANGLE.isMagic(item) and item.aoe.mode in ('Normal',
                                                             'Blast'):
         item.overcharged = True
         item.orig_aoe = item.aoe
         item.aoe = ItemMethods.AOEComponent('Blast',
                                             item.orig_aoe.number + 1)
 def apply_mod(self, unit, weapon, gameStateObj):
     if self.item:
         self.reverse_mod()
     self.item = weapon
     self.original_range = weapon.RNG
     self.original_aoe = weapon.aoe
     self.original_no_double = weapon.no_double
     weapon.aoe = ItemMethods.AOEComponent('Cleave', 1)
     weapon.RNG = [1]
     weapon.no_double = True
Пример #4
0
def get_unit_info(class_dict, klass, level, item_line, gameStateObj):
    # Handle stats
    # hp, str, mag, skl, spd, lck, def, res, con, mov
    bases = class_dict[klass]['bases'][:]  # Using copies
    growths = class_dict[klass]['growths'][:]  # Using copies

    bases = [
        sum(x) for x in zip(bases, gameStateObj.modify_stats['enemy_bases'])
    ]
    growths = [
        sum(x)
        for x in zip(growths, gameStateObj.modify_stats['enemy_growths'])
    ]

    stats, growth_points = auto_level(bases, growths, level,
                                      class_dict[klass]['max'], gameStateObj)
    # Make sure we don't exceed max
    stats = [
        Utility.clamp(stat, 0, class_dict[klass]['max'][index])
        for index, stat in enumerate(stats)
    ]

    # Handle items
    items = ItemMethods.itemparser(item_line)

    # Handle required wexp
    wexp = class_dict[klass]['wexp_gain'][:]
    # print(klass, wexp)
    for item in items:
        if item.weapon:
            weapon_types = item.TYPE
            item_level = item.weapon.LVL
        elif item.spell:
            weapon_types = item.TYPE
            item_level = item.spell.LVL
        else:
            continue
        for weapon_type in weapon_types:
            wexp_index = CustomObjects.WEAPON_TRIANGLE.type_to_index[
                weapon_type]
            item_requirement = CustomObjects.WEAPON_EXP.wexp_dict[item_level]
            # print(item, weapon_type, wexp_index, item_requirement, wexp[wexp_index])
            if item_requirement > wexp[wexp_index] and wexp[wexp_index] > 0:
                wexp[wexp_index] = item_requirement
    # print(wexp)

    return stats, growths, growth_points, items, wexp
Пример #5
0
    def load(self, load_info):
        logger.info("Load")
        # Rebuild gameStateObj
        self.allunits = [
            UnitObject.UnitObject(info) for info in load_info['allunits']
        ]
        self.factions = load_info['factions'] if 'factions' in load_info else (
            load_info['groups'] if 'groups' in load_info else {})
        self.allreinforcements = load_info['allreinforcements']
        self.prefabs = load_info['prefabs']
        self.triggers = load_info.get('triggers', dict())
        map_info = load_info['map']
        self.playtime = load_info['playtime']
        self.convoy = [
            ItemMethods.deserialize(item_dict)
            for item_dict in load_info['convoy']
        ]
        self.convoy = [item for item in self.convoy if item]
        self.turncount = load_info['turncount']
        self.game_constants = load_info['game_constants']
        self.level_constants = load_info['level_constants']
        self.objective = CustomObjects.Objective.deserialize(
            load_info['objective']) if load_info['objective'] else None
        self.phase_music = CustomObjects.PhaseMusic.deserialize(
            load_info['phase_music']) if load_info['phase_music'] else None
        support_dict = load_info['support']
        self.talk_options = load_info['talk_options']
        self.base_conversations = load_info['base_conversations']
        self.stateMachine = StateMachine.StateMachine(
            load_info['state_list'][0], load_info['state_list'][1])
        self.statistics = load_info['statistics']
        # self.message = [Dialogue.Dialogue_Scene(scene) for scene in load_info['message']]
        self.message = []
        self.unlocked_lore = load_info['unlocked_lore']
        self.market_items = load_info.get('market_items', set())
        self.mode = load_info.get('mode', self.default_mode())

        # Map
        self.map = SaveLoad.create_map('Data/Level' +
                                       str(self.game_constants['level']))
        if map_info:
            self.map.replay_commands(map_info['command_list'],
                                     self.game_constants['level'])
            self.map.command_list = map_info['command_list']
            for position, current_hp in map_info['HP']:
                self.map.tiles[position].set_hp(current_hp)

        # Statuses
        for index, info in enumerate(load_info['allunits']):
            for s_dict in info['status_effects']:
                if isinstance(s_dict, dict):
                    StatusObject.deserialize(s_dict, self.allunits[index],
                                             self)
                else:
                    self.allunits[index].status_effects.append(s_dict)

        # Support
        if cf.CONSTANTS['support']:
            self.support = Support.Support_Graph('Data/support_nodes.txt',
                                                 'Data/support_edges.txt')
            self.support.deserialize(support_dict)
        else:
            self.support = None

        # Set up blitting surface
        if self.map:
            mapSurfWidth = self.map.width * GC.TILEWIDTH
            mapSurfHeight = self.map.height * GC.TILEHEIGHT
            self.mapSurf = Engine.create_surface((mapSurfWidth, mapSurfHeight))

            self.grid_manager = AStar.Grid_Manager(self.map)
            self.boundary_manager = CustomObjects.BoundaryManager(self.map)

            for unit in self.allunits:
                if unit.position:
                    self.grid_manager.set_unit_node(unit.position, unit)

        self.generic()
        if 'phase_info' in load_info:
            self.phase.current, self.phase.previous = load_info['phase_info']
Пример #6
0
def add_unit(unitLine, allunits, reinforceUnits, metaDataObj, gameStateObj):
    assert len(unitLine) == 6, "unitLine %s must have length 6" % (unitLine)
    legend = {
        'team': unitLine[0],
        'unit_type': unitLine[1],
        'event_id': unitLine[2],
        'unit_id': unitLine[3],
        'position': unitLine[4],
        'ai': unitLine[5]
    }
    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)
            u_i['faction'] = unit.find('faction').text

            stats = intify_comma_list(unit.find('bases').text)
            for n in xrange(len(stats), cf.CONSTANTS['num_stats']):
                stats.append(class_dict[u_i['klass']]['bases'][n])
            if u_i['team'] == 'player':  # Modify stats
                bases = gameStateObj.modify_stats['player_bases']
                growths = gameStateObj.modify_stats['player_growths']
            else:
                bases = gameStateObj.modify_stats['enemy_bases']
                growths = gameStateObj.modify_stats['enemy_growths']
            stats = [sum(x) for x in zip(stats, bases)]
            assert len(stats) == cf.CONSTANTS[
                'num_stats'], "bases %s must be exactly %s integers long" % (
                    stats, cf.CONSTANTS['num_stats'])
            u_i['stats'] = build_stat_dict(stats)
            logger.debug("%s's stats: %s", u_i['name'], u_i['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'], growths)]
            assert len(u_i['growths']) == cf.CONSTANTS[
                'num_stats'], "growths %s must be exactly %s integers long" % (
                    stats, cf.CONSTANTS['num_stats'])
            u_i['growth_points'] = [50] * cf.CONSTANTS['num_stats']

            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 CustomObjects.WEAPON_EXP.wexp_dict:
                    u_i['wexp'][index] = CustomObjects.WEAPON_EXP.wexp_dict[
                        wexp]
            u_i['wexp'] = [int(num) for num in u_i['wexp']]

            assert len(u_i['wexp']) == len(
                CustomObjects.WEAPON_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)
            break
    return allunits, reinforceUnits
Пример #7
0
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Solo'
     self.item = ItemMethods.itemparser('so_Fade')[0]
Пример #8
0
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Tile'
     self.item = ItemMethods.itemparser('so_Summon_2')[0]
Пример #9
0
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Interact'
     self.item = ItemMethods.itemparser('so_Revelation')[0]
Пример #10
0
def get_unit_info(class_dict,
                  team,
                  klass,
                  level,
                  item_line,
                  mode,
                  game_constants,
                  force_fixed=False):
    # Handle stats
    # hp, str, mag, skl, spd, lck, def, res, con, mov
    bases = class_dict[klass]['bases'][:]  # Using copies
    growths = class_dict[klass]['growths'][:]  # Using copies

    if team == 'player' or team == 'other':  # Modify stats
        mode_bases = mode['player_bases']
        mode_growths = mode['player_growths']
        hidden_levels = int(eval(mode['autolevel_players']))
        explicit_levels = 0
    else:
        mode_bases = mode['enemy_bases']
        mode_growths = mode['enemy_growths']
        if 'extra_enemy_growths' in game_constants:
            mode_growths = [
                g + int(game_constants['extra_enemy_growths'])
                for g in mode_growths
            ]
        hidden_levels = int(eval(mode['autolevel_enemies']))
        explicit_levels = int(eval(mode['truelevel_enemies']))

    level += explicit_levels

    bases = [sum(x) for x in zip(bases, mode_bases)]
    growths = [sum(x) for x in zip(growths, mode_growths)]

    num_levelups = level - 1
    stats, growth_points = auto_level(bases,
                                      growths,
                                      num_levelups + hidden_levels,
                                      class_dict[klass]['max'],
                                      mode,
                                      force_fixed=force_fixed)

    # Handle items
    items = ItemMethods.itemparser(item_line)

    # Handle required wexp
    wexp = class_dict[klass]['wexp_gain'][:]
    # print(klass, wexp)
    for item in items:
        if item.weapon:
            weapon_type = item.TYPE
            item_level = item.weapon.LVL
        elif item.spell:
            weapon_type = item.TYPE
            item_level = item.spell.LVL
        else:
            continue
        if weapon_type:
            wexp_index = Weapons.TRIANGLE.name_to_index[weapon_type]
            item_requirement = Weapons.EXP.wexp_dict[item_level]
            # print(item, weapon_type, wexp_index, item_requirement, wexp[wexp_index])
            if item_requirement > wexp[wexp_index] and wexp[wexp_index] > 0:
                wexp[wexp_index] = item_requirement
    # print(wexp)

    return stats, growths, growth_points, items, wexp, level
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Solo'
     self.item = ItemMethods.itemparser('so_Fade')[0]
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Tile'
     self.item = ItemMethods.itemparser('so_Summon_2')[0]
 def __init__(self, name, required_charge):
     Active_Skill.__init__(self, name, required_charge)
     self.mode = 'Interact'
     self.item = ItemMethods.itemparser('so_Rally')[0]
Пример #14
0
def add_unit(unitLine, allunits, reinforceUnits, metaDataObj):
    assert len(unitLine) == 6 or len(unitLine) == 7, "unitLine %s must have length 6 or 7"%(unitLine)
    unitdata = metaDataObj['unitdata']
    class_dict = metaDataObj['class_dict']
    itemdata = metaDataObj['itemdata']
    statusdata = metaDataObj['statusdata']
    for unit in unitdata.getroot().findall('unit'):
        if unit.find('id').text == unitLine[3]:
            u_i = {}
            u_i['u_id'] = unit.find('id').text
            u_i['event_id'] = unitLine[2]
            u_i['position'] = tuple([int(num) for num in unitLine[4].split(',')])
            u_i['name'] = unit.get('name')
            u_i['team'] = unitLine[0]

            classes = unit.find('class').text.split(',')
            u_i['klass'] = classes[-1]
            u_i['gender'] = unit.find('gender').text
            u_i['level'] = int(unit.find('level').text)
            u_i['faction'] = unit.find('faction').text

            stats = intify_comma_list(unit.find('bases').text)
            if len(stats) == 8: # Add con if not present
                stats.append(int(class_dict[u_i['klass']]['bases'][8]))
            assert len(stats) == 9, "bases %s must be exactly 9 integers long"%(stats)
            stats.append(int(class_dict[u_i['klass']]['movement']))
            u_i['stats'] = build_stat_dict(stats)
            logger.debug("%s's stats: %s", u_i['name'], u_i['stats'])
            u_i['growths'] = intify_comma_list(unit.find('growths').text)
            u_i['growth_points'] = [0, 0, 0, 0, 0, 0, 0, 0]

            u_i['new_items'] = ItemMethods.itemparser(unit.find('inventory').text, itemdata)
            u_i['wexp'] = intify_comma_list(unit.find('wexp').text)
            
            u_i['desc'] = unit.find('desc').text
            # Tags
            class_tags = class_dict[u_i['klass']]['tags'].split(',') if class_dict[u_i['klass']]['tags'] else []
            personal_tags = unit.find('tags').text.split(',') if unit.find('tags') is not None and unit.find('tags').text is not None else []
            u_i['tags'] = class_tags + personal_tags

            # For mounts... Not yet available in Lex Talionis
            mount_status = []
            for status in class_dict[u_i['klass']]['mount_status']:
                mount_status.append(StatusObject.statusparser(status, statusdata))

            u_i['ai'] = unitLine[5]
            u_i['movement_group'] = class_dict[u_i['klass']]['movement_group']

            Unit = UnitObject.UnitObject(u_i)

            # Status Effects and Skills
            get_skills(class_dict, statusdata, Unit, classes, u_i['level'], 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 []    ### Actually add statuses
            c_s = [StatusObject.statusparser(status, statusdata) for status in personal_skills]
            for status in c_s:  
                if status:
                    StatusObject.HandleStatusAddition(status, Unit)
            # handle having a status that gives stats['HP']
            Unit.currenthp = int(Unit.stats['HP'])

            # Mount
            if len(unitLine) == 7:
                mount_id = unitLine[6]
                place_mount(mount_id, Unit, reinforceUnits)
            Unit.position = u_i['position'] # Reposition units

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

            allunits.append(Unit)
    return allunits, reinforceUnits