local RemoteProxy = requireProxy("remote/RemoteProxy") local proxyUtils = requireProxy("proxyUtils") local HeroEquipProxy = class("HeroEquipProxy", RemoteProxy) HeroEquipProxy.NAME = global.ProxyTable.HeroEquipProxy function HeroEquipProxy:ctor() HeroEquipProxy.super.ctor(self) self._equipDataByMakeIndex = {} --item self._equipPosData = {}--makeindex self.EquipPosData = requireConfig("EquipPosTypeConfig") self.EquipPosType = self.EquipPosData.EquipPosTypeConfig self.ModelViewEquipOff = {} self.ModelViewHairOff = {} self.ItemBelongType = global.MMO.ITEM_FROM_BELONG_HEROEQUIP self.posfight = {} self.suitnum = {} self.lastTakeOnPos = {} self.bestRingsOpen = false self.equipQuality = { DEFAULT_EQUIP = 1, --战装 GOD_MAGIC_EQUIP = 2, --魔神装 FASHION_EQUIP = 3 --神器(魔神武器衣服) } self._helmet_cap_part = nil --头盔斗笠内观是否是分开显示的 self:loadJson() end function HeroEquipProxy:loadJson() local cjson = require("cjson") -- 装备偏移 local function loadEquipOffset(filename, index) if global.FileUtilCtl:isFileExist(filename) then local jsonStr = global.FileUtilCtl:getDataFromFileEx(filename) local jsonData = {} xpcall(function() jsonData = cjson.decode(jsonStr) end, function() if global.isDebugMode or global.isGMMode then ShowSystemTips(string.format("json文件格式错误: %s", filename)) end end ) for key, value in pairs(jsonData) do local offValue = { x = value.x, y = value.y } if global.isWinPlayMode then if value.x1 then offValue.x = value.x1 end if value.y1 then offValue.y = value.y1 end end self.ModelViewEquipOff[tonumber(key) + index * 10000] = offValue end end end for i = 0, 10 do local filename = string.format("res/player_show/player_show_%s/equip_offest.txt", i) if global.FileUtilCtl:isFileExist(filename) then loadEquipOffset(filename, i) end end -- 头发偏移 local function loadHairOffset(filename) if global.FileUtilCtl:isFileExist(filename) then local jsonStr = global.FileUtilCtl:getDataFromFileEx(filename) local jsonData = {} xpcall(function() jsonData = cjson.decode(jsonStr) end, function() if global.isDebugMode or global.isGMMode then ShowSystemTips(string.format("json文件格式错误: %s", filename)) end end ) for key, value in pairs(jsonData) do local offValue = { x = value.x, y = value.y } if global.isWinPlayMode then if value.x1 then offValue.x = value.x1 end if value.y1 then offValue.y = value.y1 end end self.ModelViewHairOff[tonumber(key)] = offValue end end end loadHairOffset("data_config/hair_offest.txt") end function HeroEquipProxy:loginOut() return self._helmet_cap_part end function HeroEquipProxy:GetEquipModelOffSet() return self.ModelViewEquipOff end function HeroEquipProxy:GetModelHairOffSet() return self.ModelViewHairOff end function HeroEquipProxy:GetEquipPosByStdMode(StdMode) local posList = self.EquipPosData.EquipPosByStdMode[StdMode] if posList and next(posList) then for k, pos in pairs(posList) do local equip = self:GetEquipDataByPos(pos) if not equip then return pos end end return posList[1] end return nil end -- tips部位列表 function HeroEquipProxy:GetTipsEquipPosByStdModeList(StdMode) if self.EquipPosData.TipsEquipPosByStdMode[StdMode] then return self.EquipPosData.TipsEquipPosByStdMode[StdMode] end return self:GetEquipPosByStdModeList(StdMode) end function HeroEquipProxy:GetEquipPosByStdModeList(StdMode) return self.EquipPosData.EquipPosByStdMode[StdMode] end function HeroEquipProxy:GetEquipMappingConfig(pos) return self.EquipPosData.EquipPosMapping[pos] end -- 反向 function HeroEquipProxy:GetDeEquipMappingConfig(pos) if not pos then return nil end for belongPos, v in pairs(self.EquipPosData.EquipPosMapping) do for k, position in pairs(v) do if position == pos then return belongPos end end end return nil end function HeroEquipProxy:IsShowEquipItems(pos) local equipPos = pos or 0 local noShowItem = { [self.EquipPosType.Equip_Type_Dress] = true, [self.EquipPosType.Equip_Type_Weapon] = true, [self.EquipPosType.Equip_Type_Helmet] = true, [self.EquipPosType.Equip_Type_Cap] = true, [self.EquipPosType.Equip_Type_Shield] = true, [self.EquipPosType.Equip_Type_Veil] = true, [self.EquipPosType.Equip_Type_Super_Dress] = true, [self.EquipPosType.Equip_Type_Super_Weapon] = true, [self.EquipPosType.Equip_Type_Super_Helmet] = true, [self.EquipPosType.Equip_Type_Super_Cap] = true, [self.EquipPosType.Equip_Type_Super_Shield] = true, [self.EquipPosType.Equip_Type_Super_Veil] = true, [self.EquipPosType.Equip_Fashion_Dress] = true, [self.EquipPosType.Equip_Fashion_Weapon] = true, } return not noShowItem[pos] end function HeroEquipProxy:GetEquipTypeConfig() return self.EquipPosType end function HeroEquipProxy:ClearEquipData() self._equipDataByMakeIndex = {} self._equipPosData = {} end function HeroEquipProxy:GetEquipData() return self._equipDataByMakeIndex end function HeroEquipProxy:GetEquipPosData() return self._equipPosData end function HeroEquipProxy:GetEquipDataByMakeIndex(makeIndex) return self._equipDataByMakeIndex[makeIndex] end function HeroEquipProxy:FindEquipDataByPos(pos) if not self._equipPosData[pos] then return nil end return self:GetEquipDataByMakeIndex(self._equipPosData[pos]) end function HeroEquipProxy:GetEquipDataByPos(pos, beginOnMoving) local data = self:FindEquipDataByPos(pos) if beginOnMoving then local list = self:GetEquipMappingConfig(pos) -- 单显示位置 多个装备位置共享 if list then data = nil for _, v in ipairs(list) do data = self:FindEquipDataByPos(v) if data then break end end end end return data end function HeroEquipProxy:GetEquipDataByName(Name) local list = {} local data = self:GetEquipData() if not Name or Name == "" or not data or next(data) == nil then return list end local originName = nil for k, v in pairs(data) do originName = v.originName or v.Name if originName == Name then table.insert(list, v) end end return list end function HeroEquipProxy:GetEquipDataPosDataList(pos) local data = {} local list = self:GetEquipMappingConfig(pos) -- 单显示位置 多个装备位置共享 if list then for _, v in ipairs(list) do local equipData = self:FindEquipDataByPos(v) if equipData then table.insert(data, equipData) end end else local equipData = self:FindEquipDataByPos(pos) if equipData then table.insert(data, equipData) end end if next(data) == nil then data = nil end return data end -- 战力对比 checkPosData: 指定部位数据战力对比( {[1]={data, pos}}) function HeroEquipProxy:GetMinPowerPosByStdMode(StdMode, param, checkPosData) local StdMode = StdMode or 0 local onEquipMinPower = 0 local minPowerPos = -1 local hasEquip = true local pos = checkPosData or self:GetEquipPosByStdModeList(StdMode) if not pos or next(pos) == nil then print("this StdMode is not a equip") return minPowerPos, onEquipMinPower end if param.checkPos then local index = table.indexof(pos, param.checkPos) if index then local fristPos = pos[1] pos[1] = param.checkPos pos[index] = fristPos end end local isChekcPos = false if checkPosData then isChekcPos = true end for k, v in ipairs(pos) do local equipData = isChekcPos and v.data or self:GetEquipDataByPos(v) if not equipData then minPowerPos = isChekcPos and v.pos or v onEquipMinPower = 0 hasEquip = false break end local equipPower = GUIFunction:GetEquipPower(equipData, param, true) if onEquipMinPower == 0 or onEquipMinPower > equipPower then onEquipMinPower = equipPower minPowerPos = isChekcPos and v.pos or v if StdMode == 25 then break end end end return minPowerPos, onEquipMinPower, hasEquip end function HeroEquipProxy:GetEquipTakeOnPosByStdMode(StdMode, param) local StdMode = StdMode or 0 local onEquipMinPower = 0 local minPowerPos = -1 local hasEquip = true local pos = self:GetEquipPosByStdModeList(StdMode) if not pos or next(pos) == nil then print("this StdMode is not a equip") return minPowerPos, onEquipMinPower end local posCount = #pos if posCount > 1 then for k, v in pairs(pos) do local equipData = self:GetEquipDataByPos(v) if not equipData then minPowerPos = v onEquipMinPower = 0 hasEquip = false break end end if hasEquip then -- 如果没有空位 if not self.lastTakeOnPos[pos[1]] then self.lastTakeOnPos[pos[1]] = 1 else self.lastTakeOnPos[pos[1]] = self.lastTakeOnPos[pos[1]] + 1 if self.lastTakeOnPos[pos[1]] > posCount then self.lastTakeOnPos[pos[1]] = 1 end end local chooseIndex = self.lastTakeOnPos[pos[1]] or 1 local choosePos = pos[chooseIndex] or pos[1] local equipData = self:GetEquipDataByPos(choosePos) if equipData then local equipPower = GUIFunction:GetEquipPower(equipData, param, true) onEquipMinPower = equipPower minPowerPos = choosePos else minPowerPos = choosePos onEquipMinPower = 0 hasEquip = false end end else -- 单位置 直接为改位置 local onlyPos = pos[1] local equipData = self:GetEquipDataByPos(onlyPos) minPowerPos = onlyPos if not equipData then onEquipMinPower = 0 hasEquip = false else local equipPower = GUIFunction:GetEquipPower(equipData, param, true) onEquipMinPower = equipPower end end return minPowerPos, onEquipMinPower, hasEquip end function HeroEquipProxy:CheckEquipNeedSex(item, sex) if not item or not next(item) then return false end local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy) local stdMode = item.StdMode local sexOk = true local needSex = sex and sex or PlayerPropertyProxy:GetRoleSex() local equipNeedSexConfig = self.EquipPosData.EquipSexNeed or {} if equipNeedSexConfig[stdMode] and equipNeedSexConfig[stdMode] ~= needSex then sexOk = false end return sexOk end function HeroEquipProxy:CheckEquipWeight(onItem, pos) if not onItem or not next(onItem) or not pos or pos < 0 then return false end local offItem = self:GetEquipDataByPos(pos) local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy) local equipNeedSexConfig = self.EquipPosData.EquipHandWeightType or {} local AttType = GUIFunction:PShowAttType() local maxWeightType = AttType.Max_Wear_Weight local nowWeightType = AttType.Wear_Weight if equipNeedSexConfig[onItem.StdMode] then maxWeightType = AttType.Max_Hand_Weight nowWeightType = AttType.Hand_Weight end local onItemWeight = onItem.Weight local offItemWeight = offItem and offItem.Weight or 0 local playerMaxWeight = PlayerPropertyProxy:GetRoleAttByAttType(maxWeightType) or 0 local nowWearWeight = PlayerPropertyProxy:GetRoleAttByAttType(nowWeightType) or 0 local afterEquip = onItemWeight - offItemWeight + nowWearWeight return afterEquip <= playerMaxWeight end --检测附身符使用 (因为护身符可以穿戴在右手镯,当附身符有穿戴,双击以及自动使用时不能穿戴,只能拖拽穿戴) function HeroEquipProxy:CheckBujukUse(item, putPos) -- body if item and item.StdMode then if item.StdMode == 25 then return true, 9 end return true end return false end function HeroEquipProxy:CheckBestRingsSpace() for pos = self.EquipPosType.Equip_Type_BestRing1, self.EquipPosType.Equip_Type_BestRing12 do local data = self:GetEquipDataByPos(pos) if not data then return pos end end return false end function HeroEquipProxy:GetBestRingsOpenState() return self.bestRingsOpen end function HeroEquipProxy:SetBestRingsOpenState(state) self.bestRingsOpen = state end function HeroEquipProxy:AddEquipData(item, isInit) local MakeIndex = item.MakeIndex local Where = item.Where -- 当前位置已有装备,先删除 local lastItem = self:GetEquipDataByPos(item.Where) if lastItem then self:DelEquipData(lastItem) end -- 数据存储 self._equipDataByMakeIndex[MakeIndex] = item self._equipPosData[Where] = MakeIndex local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy) ItemManagerProxy:SetItemBelong(item.MakeIndex, self.ItemBelongType) if not isInit then local sData = {} sData.MakeIndex = item.MakeIndex sData.Where = item.Where sData.opera = global.MMO.Operator_Add sData.ItemData = item global.Facade:sendNotification(global.NoticeTable.PlayEquip_Oper_Data_Hero, sData) SLBridge:onLUAEvent(LUA_EVENT_HERO_EQUIP_CHANGE, sData) end end function HeroEquipProxy:DelEquipData(item) local MakeIndex = item.MakeIndex local item = self:GetEquipDataByMakeIndex(MakeIndex) if not item then return end local AutoUseItemProxy = global.Facade:retrieveProxy(global.ProxyTable.AutoUseItemProxy) AutoUseItemProxy:AddEquipOffMakeIndex(item.MakeIndex) -- 存储数据 local Where = item.Where self._equipPosData[Where] = nil self._equipDataByMakeIndex[MakeIndex] = nil local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy) ItemManagerProxy:SetItemBelong(MakeIndex, nil) local sData = {} sData.MakeIndex = MakeIndex sData.Where = Where sData.opera = global.MMO.Operator_Sub sData.ItemData = item global.Facade:sendNotification(global.NoticeTable.PlayEquip_Oper_Data_Hero, sData) SLBridge:onLUAEvent(LUA_EVENT_HERO_EQUIP_CHANGE, sData) end function HeroEquipProxy:ChangeEquipData(item, bagDelayUpdate, isChangeLook) local MakeIndex = item.MakeIndex local Where = item.Where local oldItem = self:GetEquipDataByMakeIndex(MakeIndex) if not oldItem then return end -- 数据存储 self._equipDataByMakeIndex[MakeIndex] = item local sData = {} sData.MakeIndex = MakeIndex sData.Where = Where sData.opera = global.MMO.Operator_Change sData.bagDelayUpdate = bagDelayUpdate sData.isChangeLook = isChangeLook global.Facade:sendNotification(global.NoticeTable.PlayEquip_Oper_Data_Hero, sData) SLBridge:onLUAEvent(LUA_EVENT_HERO_EQUIP_CHANGE, sData) end function HeroEquipProxy:SetEmbattle(data) self.embattle = {} if data and data ~= 0 then self.embattle[1] = H16Bit(data) self.embattle[2] = L16Bit(data) end end function HeroEquipProxy:GetEmbattle() return self.embattle end function HeroEquipProxy:handle_MSG_SC_EQUIP_Embattle_RESPONSE(msg) local header = msg:GetHeader() local recog = header.recog self:SetEmbattle(recog) global.Facade:sendNotification(global.NoticeTable.Layer_Embattle_Refresh_Hero) SLBridge:onLUAEvent(LUA_EVENT_HERO_EMBATTLE_CHANGE) end -- --更换iconID function HeroEquipProxy:ChangeEquipLook(MakeIndex) if not MakeIndex then return end local item = self:GetEquipDataByMakeIndex(MakeIndex) if not item then return end local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy) item.Looks, item.bEffect, item.sEffect = ItemConfigProxy:GetChangeItemLook(item.MakeIndex, item.Index) self:ChangeEquipData(item, nil, true) end -- 自定义装备使用 function HeroEquipProxy:SetCustUserItem(custUserItem) if not custUserItem or string.len(custUserItem) <= 0 then return end local ItemsConfig = requireConfig("ItemsConfig") ItemsConfig.EquipMapByStdMode = {} ItemsConfig.EquipMapByStdMode = ItemsConfig.EquipMapByStdModeTemp self.EquipPosData.EquipPosByStdMode = {} self.EquipPosData.EquipPosByStdMode = self.EquipPosData.EquipPosByStdModeTemp local itemArray = string.split(custUserItem, "#") for i, v in ipairs(itemArray) do local posArray = string.split(v, "=") local pos = posArray[1] and tonumber(posArray[1]) or nil local stdModeStr = posArray[2] if stdModeStr and string.len(stdModeStr) > 0 then local StdModeArray = string.split(stdModeStr, ",") for _i, _StdMode in ipairs(StdModeArray) do local StdMode = _StdMode and tonumber(_StdMode) or nil if StdMode and pos then if not self.EquipPosData.EquipPosByStdMode[StdMode] then self.EquipPosData.EquipPosByStdMode[StdMode] = {} end table.insert(self.EquipPosData.EquipPosByStdMode[StdMode], pos) ItemsConfig.EquipMapByStdMode[StdMode] = true end end end end end function HeroEquipProxy:handle_MSG_SC_PLAYER_EQUIP_ON_FAIL(msg) local header = msg:GetHeader() local data = {} data.isSuccess = false data.header = header global.Facade:sendNotification(global.NoticeTable.HeroTakeOnResponse, data) end function HeroEquipProxy:handle_MSG_SC_PLAYER_EQUIP_ON_SUCCESS(msg) local header = msg:GetHeader() local data = {} data.isSuccess = true data.header = header data.pos = header.recog global.Facade:sendNotification(global.NoticeTable.HeroTakeOnResponse, data) end function HeroEquipProxy:handle_MSG_SC_PLAYER_EQUIP_OFF_SUCCESS( msg ) local header = msg:GetHeader() global.Facade:sendNotification(global.NoticeTable.HeroTakeOffResponse, {isSuccess = true, pos = header.recog}) end function HeroEquipProxy:handle_MSG_SC_PLAYER_EQUIP_OFF_FAIL(msg) global.Facade:sendNotification(global.NoticeTable.HeroTakeOffResponse, {isSuccess = false, header = msg:GetHeader()}) end function HeroEquipProxy:handle_MSG_SC_PALYER_EQUIP_INFO_HERO(msg) local jsonData = ParseRawMsgToJson(msg) if not jsonData or next(jsonData) == nil then return end for k, equip in pairs(jsonData) do if equip and equip ~= "" then equip = ChangeItemServersSendDatas(equip) self:AddEquipData(equip, true) end end global.Facade:sendNotification(global.NoticeTable.PlayEquip_Oper_Init_Hero) SLBridge:onLUAEvent(LUA_EVENT_HERO_EQUIP_CHANGE, {opera = global.MMO.Operator_Init}) end function HeroEquipProxy:RequestBestRingsOpenState() LuaSendMsg(global.MsgType.MSG_CS_PLAYER_EQUIP_BEST_RINGS_STATE_HERO, 0, 0, 0, 0) end function HeroEquipProxy:handle_MSG_SC_PLAYER_EQUIP_BEST_RINGS_STATE(msg) local header = msg:GetHeader() local state = header.recog == 1 local isOpen = false if self.bestRingsOpen and state then isOpen = true end self:SetBestRingsOpenState(state) global.Facade:sendNotification(global.NoticeTable.Layer_PlayerBestRing_State_Hero, { isOpen = isOpen }) SLBridge:onLUAEvent(LUA_EVENT_HERO_BESTRINGBOX_STATE, {isOpen = isOpen}) end function HeroEquipProxy:onRegister() HeroEquipProxy.super.onRegister(self) end function HeroEquipProxy:RegisterMsgHandler() HeroEquipProxy.super.RegisterMsgHandler(self) local msgType = global.MsgType --初始化装备信息 LuaRegisterMsgHandler(msgType.MSG_SC_PALYER_EQUIP_INFO_HERO, handler(self, self.handle_MSG_SC_PALYER_EQUIP_INFO_HERO)) -- 装备穿上确认-成功 LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_EQUIP_ON_SUCCESS_HERO, handler(self, self.handle_MSG_SC_PLAYER_EQUIP_ON_SUCCESS)) -- -- 装备穿上确认-失败 LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_EQUIP_ON_FAIL_HERO, handler(self, self.handle_MSG_SC_PLAYER_EQUIP_ON_FAIL)) -- -- 装备脱下确认-成功 LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_EQUIP_OFF_SUCCESS_HERO, handler(self, self.handle_MSG_SC_PLAYER_EQUIP_OFF_SUCCESS)) -- -- 装备脱下确认-失败 LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_EQUIP_OFF_FAIL_HERO, handler(self, self.handle_MSG_SC_PLAYER_EQUIP_OFF_FAIL)) -- -- 首饰盒开启状态 LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_EQUIP_BEST_RINGS_STATE_HERO, handler(self, self.handle_MSG_SC_PLAYER_EQUIP_BEST_RINGS_STATE)) -- 法阵 LuaRegisterMsgHandler( msgType.MSG_SC_EQUIP_Embattle_RESPONSE_HERO,handler(self, self.handle_MSG_SC_EQUIP_Embattle_RESPONSE) ) end return HeroEquipProxy