Example #1
0
def installed_devices(vehicle):
    try:
        global equip_settings
        equip_settings[vehicle.name] = []
        for slotIdx, installed_device in enumerate(vehicle.optDevices):
            if installed_device and installed_device.isRemovable:
                equip_settings[vehicle.name].append(installed_device.intCD)
            else:
                equip_settings[vehicle.name].append(None)
    except Exception, ex:
        err(traceback.format_exc())
Example #2
0
def xvm_equip_init(*args, **kwargs):
    try:
        global player_name, last_vehicles_id_arr, equip_settings
        last_vehicles_id_arr = []
        equip_settings = {}
        if not (config.get('hangar/enableEquipAutoReturn') and BigWorld.player()):
            debug('xvm_equip: disabled')
            player_name = None
            return
        player_name = '%s_%s' % (BigWorld.player().name, GAME_REGION)
        debug('xvm_equip: enabled, using name %s' % player_name)
    except Exception, ex:
        err(traceback.format_exc())
        player_name = None
Example #3
0
def TmenXpPanel_onVehicleChange(*args, **kwargs):
    try:
        if not player_name:
            return
        global last_vehicles_id_arr, equip_settings
        if last_vehicles_id_arr and last_vehicles_id_arr[-1] == g_currentVehicle.item.intCD:
            return
        if not (last_vehicles_id_arr and equip_settings) and not get_settings():
            return
        vehicle = g_currentVehicle.item
        # get one of each type of removable devices from vehicles by FIFO order of usage
        if vehicle.intCD in last_vehicles_id_arr:
            last_vehicles_id_arr.remove(vehicle.intCD)
        last_vehicles_id_arr.append(vehicle.intCD)
        updated_inventoryCount = {}
        for device in g_itemsCache.items.getItems(GUI_ITEM_TYPE.OPTIONALDEVICE, REQ_CRITERIA.REMOVABLE).values():
            updated_inventoryCount[device.name] = device.inventoryCount
        devices_arr = []
        for vehicle_id in last_vehicles_id_arr[:-1]:
            prev_vehicle = g_itemsCache.items.getItemByCD(vehicle_id)
            if not prev_vehicle or not prev_vehicle.isInInventory: # sold?
                last_vehicles_id_arr.remove(vehicle_id)
                continue
            if prev_vehicle.isAlive:
                for slotIdx, installed_device in enumerate(prev_vehicle.optDevices):
                    if installed_device and installed_device.isRemovable and installed_device.name not in devices_arr and not updated_inventoryCount[installed_device.name]:
                        #debug('xvm_equip: get %s from %s' % (installed_device.name, prev_vehicle.name))
                        wg_compat.g_instance.processReturnEquip(prev_vehicle, installed_device, slotIdx, False)
                        devices_arr.append(installed_device.name)

        if vehicle.name in equip_settings and len(equip_settings[vehicle.name]) == 3: # equip all modules from user prefs
            if vehicle.isAlive:
                debug_str = 'xvm_equip: equip to %s devices:' % vehicle.name
                for slotIdx, installed_device in enumerate(vehicle.optDevices):
                    needed_device_id = equip_settings[vehicle.name][slotIdx]
                    if needed_device_id and (not installed_device or (installed_device.isRemovable and installed_device.intCD != needed_device_id)):
                        needed_device = g_itemsCache.items.getItemByCD(needed_device_id)
                        debug_str += ' %s' % needed_device.name
                        wg_compat.g_instance.processReturnEquip(vehicle, needed_device, slotIdx, True)
                debug(debug_str)
            else:
                debug("xvm_equip: can't put equipment, vehicle %s not ready" % vehicle.name)
        else: # no prefs, save currently installed modules to user prefs
            installed_devices(vehicle)
            debug('xvm_equip: no prefs for %s, save installed modules: %s' % (vehicle.name, equip_settings[vehicle.name]))
            save_settings()
    except Exception, ex:
        err(traceback.format_exc())
Example #4
0
def AmmunitionPanel_setVehicleModule(self, newId, slotIdx, oldId, isRemove):
    try:
        if not player_name:
            return
        global equip_settings
        veh_name = g_currentVehicle.item.name
        settings_changed = False
        if isRemove and veh_name in equip_settings:
            equip_settings[veh_name][slotIdx] = None
            settings_changed = True
        else:
            newId = int(newId)
            new_device = g_itemsCache.items.getItemByCD(newId)
            if new_device and new_device.isRemovable and new_device.itemTypeName == 'optionalDevice':
                equip_settings[veh_name][slotIdx] = new_device.intCD
                settings_changed = True
        if settings_changed:
            debug('xvm_equip: devices changed on %s, new set: %s' % (veh_name, equip_settings[veh_name]))
            save_settings()
    except Exception, ex:
        err(traceback.format_exc())
Example #5
0
def get_settings():
    try:
        global last_vehicles_id_arr, equip_settings
        inventory_vehicles_dict = dict(g_itemsCache.items.getVehicles(REQ_CRITERIA.INVENTORY))
        last_vehicles_id_arr = inventory_vehicles_dict.keys()
        equip_settings = userprefs.get('auto_equip/%s' % player_name)
        if equip_settings is None or 'version' not in equip_settings or equip_settings['version'] != PREF_VERSION: # no prefs, or old version: get currently installed devices
            if equip_settings is None:
                debug('xvm_equip: no prefs for %s, get currently installed devices' % player_name)
            else:
                debug('xvm_equip: old prefs for %s, get currently installed devices' % player_name)
            equip_settings = {'version': PREF_VERSION}
            for vehicle in inventory_vehicles_dict.values():
                installed_devices(vehicle)
            save_settings()
        debug('xvm_equip: got settings: %s' % equip_settings)
        return True
    except Exception, ex:
        equip_settings = None
        err(traceback.format_exc())
        return False