654 lines
28 KiB
Lua
654 lines
28 KiB
Lua
----- 装备合成 -----
|
|
local this = {}
|
|
local sortingOrder = 0
|
|
local equipStarsConfig = ConfigManager.GetConfig(ConfigName.EquipStarsConfig)
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local TabBox = require("Modules/Common/TabBox")
|
|
local _TabData = {
|
|
[1] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10456] },
|
|
[2] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10457] },
|
|
[3] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10458] },
|
|
[4] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10459] },
|
|
[5] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = Language[10460] },
|
|
--[5] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "戒指" },
|
|
--[6] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "腰带" }
|
|
}
|
|
local _TabFontColor = {
|
|
default = Color.New(130 / 255, 128 / 255, 120 / 255, 1),
|
|
select = Color.New(154 / 255, 78 / 255, 36 / 255, 1)
|
|
}
|
|
local _TabImagePos = {
|
|
default = -3,
|
|
select = -10
|
|
}
|
|
local curIndex = 0
|
|
local compoundNum = 0
|
|
local compoundMaxNum = 0
|
|
--this.tabs = {}
|
|
local curNeedEquip = {}
|
|
local curSelectEquip = {}
|
|
local curSelectGO
|
|
local materidaIsCan = false
|
|
local otherMateialIsCan = false
|
|
local bagPosEquips = {}
|
|
local needGoldNum = 0
|
|
local needOtherNum = 0
|
|
local otherId = 1258
|
|
local allGo = {}
|
|
local allUp = {}
|
|
function this:InitComponent(gameObject)
|
|
this.spLoader = SpriteLoader.New()
|
|
this.tabBox = Util.GetGameObject(gameObject, "CompoundPanel_Equip/TabBox")
|
|
this.needGoldText = Util.GetGameObject(gameObject,
|
|
"CompoundPanel_Equip/GameObject/compoundBtn/costTab/GameObject1/needGoldText"):GetComponent("Text")
|
|
this.compoundBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/GameObject/compoundBtn")
|
|
this.autoCompoundBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/GameObject/autoCompoundBtn")
|
|
this.addBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/addBtn")
|
|
this.subtractBtn = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/subtractBtn")
|
|
this.numText = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/numText"):GetComponent("InputField")
|
|
this.progressText = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/progressText"):GetComponent("Text")
|
|
this.needEquip = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/needEquip")
|
|
this.compoundEquip = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/compoundEquip")
|
|
this.progressImage = Util.GetGameObject(gameObject, "CompoundPanel_Equip/titleGo/progress/Image"):GetComponent(
|
|
"Image")
|
|
this.needOtherObg = Util.GetGameObject(gameObject, "CompoundPanel_Equip/GameObject/compoundBtn/costTab/GameObject")
|
|
this.needOtherImg = Util.GetGameObject(gameObject,
|
|
"CompoundPanel_Equip/GameObject/compoundBtn/costTab/GameObject/icon"):GetComponent("Image")
|
|
this.needOtherTxt = Util.GetGameObject(gameObject,
|
|
"CompoundPanel_Equip/GameObject/compoundBtn/costTab/GameObject/needGoldText"):GetComponent("Text")
|
|
this.needOtherImg.sprite = this.spLoader:LoadSprite(GetResourcePath(itemConfig[otherId].ResourceID))
|
|
this.equipPre = Util.GetGameObject(gameObject, "CompoundPanel_Equip/equipPre")
|
|
this.ScrollBar = Util.GetGameObject(gameObject, "CompoundPanel_Equip/Scrollbar"):GetComponent("Scrollbar")
|
|
local v2 = Util.GetGameObject(gameObject, "CompoundPanel_Equip/scroll"):GetComponent("RectTransform").rect
|
|
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,
|
|
Util.GetGameObject(gameObject, "CompoundPanel_Equip/scroll").transform,
|
|
this.equipPre, this.ScrollBar, Vector2.New(-v2.x * 2, -v2.y * 2), 1, 5, Vector2.New(15, 15))
|
|
this.ScrollView.moveTween.MomentumAmount = 1
|
|
this.ScrollView.moveTween.Strength = 1
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddClick(this.compoundBtn, function()
|
|
this.Compound(curIndex)
|
|
end)
|
|
--
|
|
Util.AddClick(this.autoCompoundBtn, function()
|
|
if curIndex == 5 then
|
|
this.AutoAllCompound()
|
|
else
|
|
this.AutoCompound(curIndex)
|
|
end
|
|
end)
|
|
Util.AddClick(this.addBtn, function()
|
|
this.CompoundNumChange(1)
|
|
end)
|
|
Util.AddClick(this.subtractBtn, function()
|
|
this.CompoundNumChange(2)
|
|
end)
|
|
-- 长按加
|
|
require("Common.LongPressManager")
|
|
local lp = LongPressManager.New(this.addBtn)
|
|
lp:SetPressTime(1)
|
|
lp:SetPressBeatFunc(function()
|
|
this.CompoundNumChange(1)
|
|
end)
|
|
lp:SetPressBeatTime(0.1)
|
|
-- 长按减
|
|
local lp = LongPressManager.New(this.subtractBtn)
|
|
lp:SetPressTime(1)
|
|
lp:SetPressBeatFunc(function()
|
|
this.CompoundNumChange(2)
|
|
end)
|
|
lp:SetPressBeatTime(0.1)
|
|
|
|
-- 编辑完成回调
|
|
Util.AddInputField_OnEndEdit(this.numText.gameObject, function(str)
|
|
local num = tonumber(str)
|
|
if num then
|
|
if num <= 0 then
|
|
compoundNum = 1
|
|
elseif num >= compoundMaxNum then
|
|
compoundNum = compoundMaxNum
|
|
else
|
|
compoundNum = num
|
|
end
|
|
end
|
|
this.ShowGoldNum(equipStarsConfig[curSelectEquip.Star - 1], compoundNum)
|
|
end)
|
|
end
|
|
|
|
function this:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.ShowGoldNum0)
|
|
end
|
|
|
|
function this:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.ShowGoldNum0)
|
|
end
|
|
|
|
function this.ShowGoldNum0()
|
|
if needGoldNum > BagManager.GetItemCountById(14) then
|
|
materidaIsCan = false
|
|
this.needGoldText.text = string.format("<color=#FF0011>%s</color>", PrintWanNum(needGoldNum))
|
|
else
|
|
materidaIsCan = true
|
|
this.needGoldText.text = string.format("<color=#FCF5D3FF>%s</color>", PrintWanNum(needGoldNum))
|
|
end
|
|
if needOtherNum > BagManager.GetItemCountById(otherId) then
|
|
otherMateialIsCan = false
|
|
this.needOtherTxt.text = string.format("<color=#FF0011>%s</color>", needOtherNum)
|
|
else
|
|
otherMateialIsCan = true
|
|
this.needOtherTxt.text = string.format("<color=#FCF5D3FF>%s</color>", needOtherNum)
|
|
end
|
|
end
|
|
|
|
function this:OnShow(...)
|
|
curIndex = 5
|
|
sortingOrder = 0
|
|
needGoldNum = 0
|
|
this.TabCtrl = TabBox.New()
|
|
this.TabCtrl:SetTabAdapter(this.TabAdapter)
|
|
this.TabCtrl:SetChangeTabCallBack(this.SwitchView)
|
|
this.TabCtrl:Init(this.tabBox, _TabData, curIndex)
|
|
this.tabBox.gameObject:SetActive(false)
|
|
end
|
|
|
|
local sortingOrder = 0
|
|
function this:OnSortingOrderChange(_sortingOrder)
|
|
sortingOrder = _sortingOrder
|
|
for i, v in pairs(allUp) do
|
|
--LogError("2222222222222222222")
|
|
-- Util.AddParticleSortLayer(v, _sortingOrder - sortingOrder )
|
|
SetParticleSortLayer(v, sortingOrder + 2)
|
|
end
|
|
for i, v in pairs(allGo) do
|
|
--Util.AddParticleSortLayer(v, _sortingOrder - sortingOrder )
|
|
SetParticleSortLayer(v, sortingOrder + 2)
|
|
end
|
|
end
|
|
|
|
function this.OnClickTabBtn(_curIndex, isNotTop, isNotAni)
|
|
curIndex = _curIndex
|
|
local equipDatas = nil
|
|
if curIndex == 5 then
|
|
equipDatas = EquipManager.GetAllGodEquips()
|
|
this.autoCompoundBtn:SetActive(false)
|
|
else
|
|
equipDatas = EquipManager.GetAllSEquipsByPosition(curIndex)
|
|
this.autoCompoundBtn:SetActive(true)
|
|
end
|
|
bagPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(curIndex)
|
|
if equipDatas and #equipDatas > 0 then
|
|
curSelectEquip = equipDatas[1]
|
|
end
|
|
this.ShowTitleData(equipStarsConfig[curSelectEquip.Star])
|
|
this.ScrollView:SetData(equipDatas, function(index, go)
|
|
this.SingleItemDataShow(go, equipDatas[index], equipStarsConfig[equipDatas[index].Star])
|
|
end, isNotTop, isNotAni)
|
|
end
|
|
|
|
function this.ShowTitleData(curEquipStarsConfig)
|
|
this.ShowTitleEquipData(this.compoundEquip, curSelectEquip, curEquipStarsConfig)
|
|
|
|
--得到静态表中合成当前装备需要的装备
|
|
local config = equipStarsConfig[curSelectEquip.Star - 1]
|
|
curNeedEquip = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipConfig, "Position", curSelectEquip.Position,
|
|
"Star", curSelectEquip.Star - 1)
|
|
this.ShowTitleEquipData(this.needEquip, curNeedEquip, config) --需要的材料
|
|
|
|
--得到背包中中合成当前装备需要的装备
|
|
local allCanCompoundEquips = EquipManager.GetBagCompoundEquipDatasByequipSData(curSelectEquip)
|
|
local num = 0
|
|
for i = 1, #allCanCompoundEquips do
|
|
num = num + allCanCompoundEquips[i].num
|
|
end
|
|
this.progressText.text = num .. "/" .. config.RankupCount
|
|
this.progressImage.fillAmount = num / config.RankupCount
|
|
--compoundNum = math.floor(num /config.RankupCount)
|
|
compoundNum = 1
|
|
compoundMaxNum = math.floor(num / config.RankupCount)
|
|
for i = 1, compoundMaxNum do
|
|
local items = config.RankupResources
|
|
local isEnough = true
|
|
for j = 1, #items do
|
|
if BagManager.GetItemCountById(items[j][1]) < items[j][2] * i then
|
|
isEnough = false
|
|
end
|
|
end
|
|
if isEnough then
|
|
compoundNum = i
|
|
end
|
|
end
|
|
this.ShowGoldNum(config, compoundNum)
|
|
end
|
|
|
|
function this.ShowGoldNum(upEquipStarsConfig, compoundNum)
|
|
needGoldNum = compoundNum * upEquipStarsConfig.RankupResources[1][2]
|
|
if needGoldNum > BagManager.GetItemCountById(upEquipStarsConfig.RankupResources[1][1]) then
|
|
materidaIsCan = false
|
|
this.needGoldText.text = string.format("<color=#FF0011>%s</color>", PrintWanNum(needGoldNum))
|
|
else
|
|
materidaIsCan = true
|
|
this.needGoldText.text = string.format("<color=#FCF5D3FF>%s</color>", PrintWanNum(needGoldNum))
|
|
end
|
|
--如果有额外消耗物品
|
|
if upEquipStarsConfig.RankupResources[2] then
|
|
needOtherNum = compoundNum * upEquipStarsConfig.RankupResources[2][2]
|
|
otherId = upEquipStarsConfig.RankupResources[2][1]
|
|
if needOtherNum > BagManager.GetItemCountById(otherId) then
|
|
otherMateialIsCan = false
|
|
this.needOtherTxt.text = string.format("<color=#FF0011>%s</color>", needOtherNum)
|
|
else
|
|
otherMateialIsCan = true
|
|
this.needOtherTxt.text = string.format("<color=#FCF5D3FF>%s</color>", needOtherNum)
|
|
end
|
|
this.needOtherObg:SetActive(true)
|
|
else
|
|
this.needOtherObg:SetActive(false)
|
|
otherMateialIsCan = true
|
|
end
|
|
this.numText.text = compoundNum
|
|
Util.SetGray(this.addBtn, false)
|
|
Util.SetGray(this.subtractBtn, false)
|
|
this.addBtn:GetComponent("Button").enabled = true
|
|
this.subtractBtn:GetComponent("Button").enabled = true
|
|
if compoundNum >= compoundMaxNum then
|
|
Util.SetGray(this.addBtn, true)
|
|
this.addBtn:GetComponent("Button").enabled = false
|
|
end
|
|
if compoundNum <= 1 then
|
|
Util.SetGray(this.subtractBtn, true)
|
|
this.subtractBtn:GetComponent("Button").enabled = false
|
|
end
|
|
if compoundNum == 0 then
|
|
Util.SetGray(this.addBtn, true)
|
|
Util.SetGray(this.subtractBtn, true)
|
|
this.addBtn:GetComponent("Button").enabled = false
|
|
this.subtractBtn:GetComponent("Button").enabled = false
|
|
end
|
|
end
|
|
|
|
function this.ShowTitleEquipData(_go, _itemData, curEquipStarsConfig)
|
|
Util.GetGameObject(_go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
|
|
GetQuantityImageByquality(curEquipStarsConfig.Quality))
|
|
Util.GetGameObject(_go.transform, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(
|
|
itemConfig[_itemData.Id].ResourceID))
|
|
Util.GetGameObject(_go.transform, "name"):GetComponent("Text").text = GetLanguageStrById(itemConfig[_itemData.Id]
|
|
.Name)
|
|
local effect = Util.GetGameObject(_go.transform, "UI_effect_WuCai_Kuang")
|
|
local effect2 = Util.GetGameObject(_go.transform, "c_ui_qinyan_duan")
|
|
effect:SetActive(curEquipStarsConfig.Quality == 7)
|
|
effect2:SetActive(curEquipStarsConfig.Quality == 8)
|
|
SetParticleSortLayer(effect, sortingOrder + 2)
|
|
SetParticleSortLayer(effect2, sortingOrder + 2)
|
|
table.insert(allUp, effect)
|
|
table.insert(allUp, effect2)
|
|
--Util.GetGameObject(_go.transform,"name"):GetComponent("Text").text=_itemData.Name
|
|
SetHeroStars(this.spLoader, Util.GetGameObject(_go.transform, "star"), curEquipStarsConfig.Stars, 1, nil, -15)
|
|
Util.AddClick(Util.GetGameObject(_go.transform, "icon"), function()
|
|
-- UIManager.OpenPanel(UIName.HandBookEquipInfoPanel, _itemData.Id)
|
|
-- LogPink("_itemData.Id:"..tostring(_itemData.Id))
|
|
local itemData = {}
|
|
itemData.id = _itemData.Id
|
|
-- UIManager.OpenPanel(UIName.RoleEquipChangePopup, nil, 4, nil, itemData, nil, nil)
|
|
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2, self, itemData, 0)
|
|
end)
|
|
end
|
|
|
|
function this.SingleItemDataShow(_go, _itemData, curEquipStarsConfig)
|
|
if not allGo[_go] then
|
|
allGo[_go] = _go
|
|
Util.AddParticleSortLayer(_go, sortingOrder)
|
|
end
|
|
Util.GetGameObject(_go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
|
|
GetQuantityImageByquality(curEquipStarsConfig.Quality))
|
|
Util.GetGameObject(_go.transform, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(
|
|
itemConfig[_itemData.Id].ResourceID))
|
|
Util.GetGameObject(_go.transform, "name"):GetComponent("Text").text = SubString2(GetLanguageStrById(_itemData.Name),
|
|
8)
|
|
Util.GetGameObject(_go.transform, "UI_effect_WuCai_Kuang"):SetActive(curEquipStarsConfig.Quality == 7)
|
|
Util.GetGameObject(_go.transform, "c_ui_qinyan_duan"):SetActive(curEquipStarsConfig.Quality == 8)
|
|
SetHeroStars(this.spLoader, Util.GetGameObject(_go.transform, "star"), curEquipStarsConfig.Stars, 1, nil, -15)
|
|
local choosed = Util.GetGameObject(_go.transform, "choosed")
|
|
choosed:SetActive(curSelectEquip.Id == _itemData.Id)
|
|
local redPoint = Util.GetGameObject(_go.transform, "redPoint")
|
|
local isShow = false
|
|
local config = equipStarsConfig[curEquipStarsConfig.Id - 1]
|
|
if curIndex == 5 then
|
|
local aaa = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.EquipConfig, "Quality", config.Quality,
|
|
"Position", _itemData.Position, "Star", curEquipStarsConfig.Id - 1)
|
|
if aaa then
|
|
isShow = true
|
|
local itemNum = BagManager.GetItemCountById(aaa.Id)
|
|
if itemNum < config.RankupCount then
|
|
isShow = false
|
|
end
|
|
if isShow then
|
|
local items = config.RankupResources
|
|
for i = 1, #items do
|
|
if items[i][2] > BagManager.GetItemCountById(items[i][1]) then
|
|
isShow = false
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
else
|
|
if bagPosEquips[curEquipStarsConfig.Id - 1] then
|
|
isShow = true
|
|
if bagPosEquips[curEquipStarsConfig.Id - 1] < config.RankupCount then
|
|
isShow = false
|
|
end
|
|
if isShow then
|
|
local items = config.RankupResources
|
|
for i = 1, #items do
|
|
if items[i][2] > BagManager.GetItemCountById(items[i][1]) then
|
|
isShow = false
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
redPoint:SetActive(isShow)
|
|
if curSelectEquip.Id == _itemData.Id then
|
|
curSelectGO = _go
|
|
end
|
|
Util.AddOnceClick(Util.GetGameObject(_go.transform, "icon"), function()
|
|
if curSelectEquip.Id == _itemData.Id then
|
|
return
|
|
else
|
|
curSelectEquip = _itemData
|
|
choosed:SetActive(true)
|
|
if curSelectGO then
|
|
Util.GetGameObject(curSelectGO.transform, "choosed"):SetActive(false)
|
|
curSelectGO = _go
|
|
end
|
|
end
|
|
this.ShowTitleData(curEquipStarsConfig)
|
|
end)
|
|
Util.AddLongPressClick(Util.GetGameObject(_go.transform, "icon"), function()
|
|
-- UIManager.OpenPanel(UIName.HandBookEquipInfoPanel, _itemData.Id)
|
|
local itemData = {}
|
|
itemData.id = _itemData.Id
|
|
-- UIManager.OpenPanel(UIName.RoleEquipChangePopup, nil, 4, nil, itemData, nil, nil)
|
|
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2, self, itemData, 0)
|
|
end, 0.5)
|
|
end
|
|
|
|
--加减方法
|
|
function this.CompoundNumChange(type)
|
|
if type == 1 then --加
|
|
if compoundNum >= compoundMaxNum then
|
|
return
|
|
end
|
|
compoundNum = compoundNum + 1
|
|
else --减
|
|
if compoundNum <= 1 then
|
|
return
|
|
end
|
|
compoundNum = compoundNum - 1
|
|
end
|
|
--LogError("compoundNum "..compoundNum)
|
|
this.ShowGoldNum(equipStarsConfig[curSelectEquip.Star - 1], compoundNum)
|
|
end
|
|
|
|
function this.Compound()
|
|
--LogError(" `````````````````` "..curIndex.." "..curSelectEquip.Star.." "..compoundNum)
|
|
if compoundNum <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10461])
|
|
return
|
|
end
|
|
if not materidaIsCan then
|
|
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.Gold })
|
|
return
|
|
end
|
|
|
|
if not otherMateialIsCan then
|
|
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[otherId].Name) .. Language[10462])
|
|
return
|
|
end
|
|
local aaa = curIndex
|
|
if curIndex == 5 then
|
|
aaa = curSelectEquip.Position
|
|
end
|
|
--LogError("curSelectEquip.Name=="..curSelectEquip.Name.." id=="..curSelectEquip.Id.." aaa=="..aaa)
|
|
NetManager.ComplexEquipRequest(aaa, curSelectEquip.Star, compoundNum, function(msg)
|
|
SoundManager.PlaySound(SoundConfig.UI_Duanzao)
|
|
-- SoundManager.PlaySound(SoundConfig.UI_Baoqi)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
|
|
this.OnClickTabBtn(curIndex, true, true)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function this.AutoCompound(_position)
|
|
--进度剩余的的装备材料的数量
|
|
local curPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(_position)
|
|
local bagPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(_position)
|
|
--进度需要的消耗金币的数量
|
|
local shengGoldNum = 0
|
|
--进度需要消耗其他物品的数量
|
|
local shengOtherNum = 0
|
|
--进度剩余的的消耗材料的数量
|
|
local bagNums = {}
|
|
|
|
--已有的消耗材料数量
|
|
for i = 1, #curPosEquips do
|
|
if equipStarsConfig[i].RankupResources then
|
|
for j = 1, #equipStarsConfig[i].RankupResources do
|
|
bagNums[equipStarsConfig[i].RankupResources[j][1]] = BagManager.GetItemCountById(equipStarsConfig[i]
|
|
.RankupResources[j][1])
|
|
end
|
|
end
|
|
end
|
|
--一种装备一种装备的循环检测 金币能合成的数量 与 背包装备能合成的数量 取最小值 然后扣除临时消耗道具
|
|
--最后所有装备存在curPosEquips 与 之前背包 bagPosEquips 作比较 看合成了什么装备 删除了什么装备 和计算消耗材料
|
|
local isNoGold = false --是否缺金币
|
|
for i = 1, #curPosEquips do
|
|
local materialEndNum = -1
|
|
--合成的1个 下一个装备的需要的消耗材料的数量
|
|
local materialNums = {}
|
|
--当前已有的消耗材料能合成的下一个装备的数量最大数量
|
|
if equipStarsConfig[i].RankupResources then
|
|
for j = 1, #equipStarsConfig[i].RankupResources do
|
|
local itemId = equipStarsConfig[i].RankupResources[j][1]
|
|
materialNums[itemId] = equipStarsConfig[i].RankupResources[j][2]
|
|
local curItmeCompoundNums = math.floor(bagNums[itemId] / equipStarsConfig[i].RankupResources[j][2])
|
|
if materialEndNum == -1 then
|
|
materialEndNum = curItmeCompoundNums
|
|
elseif materialEndNum > curItmeCompoundNums then
|
|
materialEndNum = curItmeCompoundNums
|
|
end
|
|
end
|
|
end
|
|
if i < #curPosEquips or i == 1 then
|
|
--当前拥有的装备材料能合成的下一个装备的数量
|
|
local curQuEquipCompoundNum = math.floor(curPosEquips[i] / equipStarsConfig[i].RankupCount)
|
|
local endCompoundNum = materialEndNum > curQuEquipCompoundNum and curQuEquipCompoundNum or materialEndNum
|
|
if not isNoGold and materialEndNum < 1 and curQuEquipCompoundNum > 0 then
|
|
isNoGold = true
|
|
end
|
|
for itemId, num in pairs(materialNums) do
|
|
bagNums[itemId] = bagNums[itemId] - endCompoundNum * num
|
|
if itemId == 14 then
|
|
shengGoldNum = shengGoldNum + endCompoundNum * num
|
|
else
|
|
shengOtherNum = shengOtherNum + endCompoundNum * num
|
|
end
|
|
end
|
|
curPosEquips[i] = curPosEquips[i] - endCompoundNum * equipStarsConfig[i].RankupCount
|
|
if curPosEquips[i + 1] then
|
|
curPosEquips[i + 1] = curPosEquips[i + 1] + endCompoundNum
|
|
end
|
|
end
|
|
end
|
|
local curRewards = {}
|
|
for i = 1, #curPosEquips do
|
|
local str = ""
|
|
if curPosEquips[i] - bagPosEquips[i] > 0 then
|
|
str = Language[10463] .. i .. " " .. curPosEquips[i] - bagPosEquips[i]
|
|
local singleEquipData = {}
|
|
singleEquipData.id = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipConfig, "Position", curIndex,
|
|
"Star", i).Id
|
|
singleEquipData.num = curPosEquips[i] - bagPosEquips[i]
|
|
table.insert(curRewards, { singleEquipData.id, singleEquipData.num })
|
|
else
|
|
str = str .. Language[10464] .. bagPosEquips[i] - curPosEquips[i]
|
|
end
|
|
end
|
|
if isNoGold and #curRewards <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10461])
|
|
return
|
|
end
|
|
if shengGoldNum <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10465])
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.EquipCompound,
|
|
shengGoldNum, shengOtherNum, curRewards, function()
|
|
NetManager.ComplexEquipRequest(curIndex, 0, 0, function(msg)
|
|
SoundManager.PlaySound(SoundConfig.UI_Duanzao)
|
|
SoundManager.PlaySound(SoundConfig.UI_Baoqi)
|
|
this.OnClickTabBtn(curIndex, true, true)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
|
|
end)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function this.AutoAllCompound()
|
|
--进度剩余的的装备材料的数量
|
|
|
|
--进度需要的消耗金币的数量
|
|
local shengGoldNum = 0
|
|
--进度需要消耗其他物品的数量
|
|
local shengOtherNum = 0
|
|
--进度剩余的的消耗材料的数量
|
|
local bagNums = {}
|
|
local curRewards = {}
|
|
local isNoGold = false --是否缺金币
|
|
for aaa = 1, 4 do
|
|
if isNoGold then
|
|
break
|
|
end
|
|
local curPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(aaa)
|
|
local bagPosEquips = EquipManager.GetEquipCompoundDataByEquipPosition1(aaa)
|
|
|
|
--已有的消耗材料数量
|
|
for i = 1, #curPosEquips do
|
|
if equipStarsConfig[i].RankupResources then
|
|
for j = 1, #equipStarsConfig[i].RankupResources do
|
|
bagNums[equipStarsConfig[i].RankupResources[j][1]] = BagManager.GetItemCountById(equipStarsConfig[i]
|
|
.RankupResources[j][1])
|
|
end
|
|
end
|
|
end
|
|
--一种装备一种装备的循环检测 金币能合成的数量 与 背包装备能合成的数量 取最小值 然后扣除临时消耗道具
|
|
--最后所有装备存在curPosEquips 与 之前背包 bagPosEquips 作比较 看合成了什么装备 删除了什么装备 和计算消耗材料
|
|
|
|
for i = 1, #curPosEquips do
|
|
local materialEndNum = -1
|
|
--合成的1个 下一个装备的需要的消耗材料的数量
|
|
local materialNums = {}
|
|
--当前已有的消耗材料能合成的下一个装备的数量最大数量
|
|
if equipStarsConfig[i].RankupResources then
|
|
for j = 1, #equipStarsConfig[i].RankupResources do
|
|
local itemId = equipStarsConfig[i].RankupResources[j][1]
|
|
materialNums[itemId] = equipStarsConfig[i].RankupResources[j][2]
|
|
local curItmeCompoundNums = math.floor(bagNums[itemId] / equipStarsConfig[i].RankupResources[j][2])
|
|
if materialEndNum == -1 then
|
|
materialEndNum = curItmeCompoundNums
|
|
elseif materialEndNum > curItmeCompoundNums then
|
|
materialEndNum = curItmeCompoundNums
|
|
end
|
|
end
|
|
end
|
|
if i < #curPosEquips or i == 1 then
|
|
--当前拥有的装备材料能合成的下一个装备的数量
|
|
local curQuEquipCompoundNum = math.floor(curPosEquips[i] / equipStarsConfig[i].RankupCount)
|
|
local endCompoundNum = materialEndNum > curQuEquipCompoundNum and curQuEquipCompoundNum or materialEndNum
|
|
if not isNoGold and materialEndNum < 1 and curQuEquipCompoundNum > 0 then
|
|
isNoGold = true
|
|
end
|
|
for itemId, num in pairs(materialNums) do
|
|
bagNums[itemId] = bagNums[itemId] - endCompoundNum * num
|
|
if itemId == 14 then
|
|
shengGoldNum = shengGoldNum + endCompoundNum * num
|
|
else
|
|
shengOtherNum = shengOtherNum + endCompoundNum * num
|
|
end
|
|
end
|
|
curPosEquips[i] = curPosEquips[i] - endCompoundNum * equipStarsConfig[i].RankupCount
|
|
if curPosEquips[i + 1] then
|
|
curPosEquips[i + 1] = curPosEquips[i + 1] + endCompoundNum
|
|
end
|
|
end
|
|
end
|
|
|
|
for i = 1, #curPosEquips do
|
|
local str = ""
|
|
if curPosEquips[i] - bagPosEquips[i] > 0 then
|
|
str = Language[10463] .. i .. " " .. curPosEquips[i] - bagPosEquips[i]
|
|
local singleEquipData = {}
|
|
singleEquipData.id = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipConfig, "Position", aaa,
|
|
"Star", i).Id
|
|
singleEquipData.num = curPosEquips[i] - bagPosEquips[i]
|
|
table.insert(curRewards, { singleEquipData.id, singleEquipData.num })
|
|
else
|
|
str = str .. Language[10464] .. bagPosEquips[i] - curPosEquips[i]
|
|
end
|
|
end
|
|
end
|
|
|
|
if isNoGold and #curRewards <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10461])
|
|
return
|
|
end
|
|
if shengGoldNum <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10465])
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.EquipCompound,
|
|
shengGoldNum, shengOtherNum, curRewards, function()
|
|
NetManager.ComplexEquipRequest(curIndex, 0, 0, function(msg)
|
|
SoundManager.PlaySound(SoundConfig.UI_Duanzao)
|
|
SoundManager.PlaySound(SoundConfig.UI_Baoqi)
|
|
this.OnClickTabBtn(curIndex, true, true)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
|
|
end)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
-- tab节点显示自定义
|
|
function this.TabAdapter(tab, index, status)
|
|
local tabLab = Util.GetGameObject(tab, "Text")
|
|
local tabImage = Util.GetGameObject(tab, "Image")
|
|
tabImage:GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status])
|
|
tabImage:GetComponent("Image"):SetNativeSize()
|
|
tabLab:GetComponent("Text").text = _TabData[index].name
|
|
tabLab:GetComponent("Text").color = _TabFontColor[status]
|
|
tabImage.transform.localPosition = Vector3.New(tabImage.transform.localPosition.x, _TabImagePos[status], 0);
|
|
end
|
|
|
|
--切换视图
|
|
function this.SwitchView(index)
|
|
this.OnClickTabBtn(index)
|
|
end
|
|
|
|
function this:OnClose()
|
|
needGoldNum = 0
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
needGoldNum = 0
|
|
allGo = {}
|
|
allUp = {}
|
|
end
|
|
|
|
return this
|