101 lines
3.2 KiB
Lua
101 lines
3.2 KiB
Lua
local EquipManager = class("EquipManager", BaseModule)
|
||
|
||
function EquipManager:showEquipListUI(heroEntity, part)
|
||
UIManager:showUI("app/ui/equip/equip_list_ui", {heroEntity = heroEntity, part = part})
|
||
end
|
||
|
||
-- 展示材料获取弹窗(英雄id,部位,材料id,材料数量)
|
||
function EquipManager:showItemGetPop(heroId, part, id, num)
|
||
self:reqEquipUpgradeGift(heroId, part)
|
||
|
||
UIManager:showUI("app/ui/dungeon/item_get_ui", {heroId = heroId, part = part, id = id, value = num})
|
||
end
|
||
|
||
-- 请求触发装备升级礼包
|
||
function EquipManager:reqEquipUpgradeGift(heroId, part)
|
||
if DataManager.EquipData:getCanShowGiftId(heroId, part) ~= nil then
|
||
return
|
||
end
|
||
|
||
self:sendMessage(ProtoMsgType.FromMsgEnum.TriggerWeaponArmorGiftReq, {hero_id = heroId, equip_position = part}, {}, self.rspEquipUpgradeGift, nil)
|
||
end
|
||
|
||
function EquipManager:rspEquipUpgradeGift(result)
|
||
DataManager.EquipData:initGifts(result.info)
|
||
end
|
||
|
||
-- 升级装备
|
||
function EquipManager:reqUpgrade(id, part)
|
||
local entity = DataManager.EquipData:getEquip(id, part)
|
||
if not entity then
|
||
return
|
||
end
|
||
|
||
local heroEntity = DataManager.HeroData:getHeroById(id)
|
||
if heroEntity == nil or not heroEntity:isUnlock() then
|
||
return
|
||
end
|
||
|
||
for index, cost in ipairs(entity:getUpgradeMaterials()) do
|
||
if cost.num > DataManager.BagData.ItemData:getItemNumById(cost.id) then
|
||
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_8))
|
||
self:showItemGetPop(id, part, cost.id, cost.num)
|
||
return
|
||
end
|
||
end
|
||
|
||
if not entity:isEnoughGold() then
|
||
if not ModuleManager.ShopManager:tryTriggerCoinGift() then
|
||
GFunc.showItemNotEnough(GConst.ItemConst.ITEM_ID_GOLD)
|
||
end
|
||
return
|
||
end
|
||
|
||
if entity:isMaxLevel() then
|
||
if entity:getPart() == GConst.EquipConst.PART_TYPE.WEAPON then
|
||
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_7, DataManager.PlayerData:getLv() + 1))
|
||
else
|
||
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_9, entity:getLevel() + 1))
|
||
end
|
||
return
|
||
end
|
||
|
||
local itemGetType = BIReport.ITEM_GET_TYPE.EQUIP_UPGRADE
|
||
if part ~= GConst.EquipConst.PART_TYPE.WEAPON then
|
||
itemGetType = BIReport.ITEM_GET_TYPE.ARMOR_UPGRADE
|
||
end
|
||
self:sendMessage(ProtoMsgType.FromMsgEnum.EquipUpgradeReq, {hero_id = id, position = part}, {}, self.rspUpgrade, itemGetType)
|
||
end
|
||
|
||
function EquipManager:rspUpgrade(result)
|
||
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||
DataManager.EquipData:onUpgradeEquip(result.reqData.hero_id, result.reqData.position)
|
||
|
||
if result.reqData.position == GConst.EquipConst.PART_TYPE.WEAPON then
|
||
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_UPGRADE_WEAPON)
|
||
else
|
||
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_UPGRADE_ARMOR)
|
||
end
|
||
end
|
||
end
|
||
|
||
--@region
|
||
function EquipManager:onEquipWearReq(slotId, ids)
|
||
local params = {}
|
||
params.slot = slotId
|
||
params.ids = ids
|
||
self:sendMessage(ProtoMsgType.FromMsgEnum.EquipWearReq, params, {}, self.onEquipWearRsp, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
|
||
end
|
||
|
||
function EquipManager:onEquipWearRsp(result)
|
||
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||
DataManager.EquipData:onWearSuccess(result.reqData.slot, result.reqData.ids)
|
||
DataManager.HeroData:setDirty()
|
||
DataManager.HeroData:calcPower()
|
||
|
||
AudioManager:playEffect(AudioManager.EFFECT_ID.HERO_UP)
|
||
end
|
||
end
|
||
|
||
--@endregion
|
||
return EquipManager |