local Formation_Model = {} local private = {} local line_up_pb = require 'Proto/line_up_pb' local EventSystem = require('Event/EventSystem') function Formation_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageSlotHeroSwitch, private.SlotHeroSwitchResp) private.slotHeroIds = {} end function Formation_Model.GetSlotsCount() local count = 0 for i, v in ipairs(private.slotHeroIds) do if v and v >= 0 then count = count + 1 end end return count end function Formation_Model.GetSlotHeroIds() return private.slotHeroIds end function Formation_Model.GetSlotHeroIdByIndex(index) return private.slotHeroIds[index] end function Formation_Model.UpdateSlotHeroIds(slotMsg) for i, v in ipairs(slotMsg) do private.slotHeroIds[i] = v end end function Formation_Model.GetSlotIndexByHeroId(heroId) for i, v in ipairs(private.slotHeroIds) do if v == heroId then return i end end return nil end function Formation_Model.SlotHeroSwitchReq(oldHeroId, newHeroId) local msg = line_up_pb.SlotHeroSwitchReq() msg.oldHeroId = oldHeroId msg.curHeroId = newHeroId private.heroSwitchMsg = {OldHeroId = oldHeroId, CurHeroId = newHeroId} NetManager.SendMessage(MessageEnums.MessageSlotHeroSwitch, msg) end function private.SlotHeroSwitchResp(msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_HeroFormation_ChangeHero, msgResp.curHeroId) -- 判断切换后是否能激活战骑和宝物羁绊 CTL.Tips.ShowChangeHeroRelationPanel(private.heroSwitchMsg.OldHeroId, private.heroSwitchMsg.CurHeroId) private.heroSwitchMsg = {} end end function Formation_Model.OnShutdown() end return Formation_Model