miduo_client/Assets/ManagedResources/~Lua/Modules/XiaoYao/XiaoYaoManager.lua

165 lines
5.8 KiB
Lua

XiaoYaoManager = {}
local this = XiaoYaoManager
this.curMapId=0;
this.curMapData={}
this.MonsterData={}
this.luckyTurnTableRewards={}
this.luckyluckyTurnTableTimes = 0
this.luckyluckyTurnTableRemainTime = 0
--打开逍遥游地图列表界面
function this.OpenMapList()
Log("点击打开逍遥游地图列表界面")
NetManager.JourneyGetInfoResponse(function (msg)
local _data={}
Log(#msg.infos)
for i = 1, #msg.infos do
Log("mapId:"..msg.infos[i].mapId..",process:"..msg.infos[i].process)
_data[msg.infos[i].mapId]=msg.infos[i].process
end
Log("打开逍遥游地图列表界面")
UIManager.OpenPanel(UIName.XiaoYaoYouPanel,_data)
end)
end
--打开逍遥游地图界面
function this.OpenXiaoYaoMap(mapId)
NetManager.JourneyGetOneInfoResponse(mapId,function (msg)
this.curMapId=mapId
this.curMapData=msg
Log("格子数量:"..#this.curMapData.cell)
for i = 1, #this.curMapData.cell do
Log("index:"..this.curMapData.cell[i].cellIndex)
-- body
end
local grids=this.curMapData.cell
if grids~=nil then
table.sort(this.curMapData.cell,function(a,b)
return a.cellIndex < b.cellIndex
end)
end
-- this.InitLuckyTurnTables(msg)
-- this.InitMonsterData(msg.monsterInfo,1)
Log("打开逍遥游地图列表界面")
UIManager.OpenPanel(UIName.XiaoYaoMapPanel)
end)
end
--掷骰子请求
function this.StartXiaoYao()
NetManager.JourneyDoResponse(function (msg)
for i = 1, #msg.pointes do
this.curMapData.location=this.curMapData.location+msg.pointes[i]
end
--0、普通节点 1、奖励节点 2、双倍节点 3、额外骰子节点 4、招募英雄节点 5、怪物节点 6,转盘
if msg.pathType == 5 then
this.InitMonsterData(msg.monsterInfo,2)
elseif msg.pathType == 6 then
this.InitLuckyTurnTables(msg)
end
end)
end
function this.InitLuckyTurnTables(msg)
this.luckyTurnTableRewards = {}
for i = 1, #msg.randomItem do
table.insert(this.luckyTurnTableRewards,msg.randomItem[i])
end
this.luckyluckyTurnTableTimes = msg.randomNum
if msg.randomTime and msg.randomTime > 0 then
this.luckyluckyTurnTableRemainTime = msg.randomTime
elseif msg.overTime and msg.overTime > 0 then
this.luckyluckyTurnTableRemainTime = msg.overTime
end
end
-- type 1初始化 2添加
function this.InitMonsterData(BackMonsterDatas,type)
if type == 1 then
this.MonsterData = {}
end
for i= 1, #BackMonsterDatas do
local monster = {}
monster.monsterId = BackMonsterDatas[i].monsterId
monster.monsterIndex = BackMonsterDatas[i].monsterIndex
monster.monsterHp = BackMonsterDatas[i].monsterHp
monster.remainTime = BackMonsterDatas[i].remainTime
monster.attackNum = BackMonsterDatas[i].attackNum
monster.reward = BackMonsterDatas[i].reward
table.insert(this.MonsterData,monster)
end
this.SortMonster(this.MonsterData)
end
function this.GetMonsterDatas()
if not this.MonsterData or #this.MonsterData < 1 then
return nil
end
for i = 1 , #this.MonsterData do
if this.MonsterData[i].remainTime - PlayerManager.serverTime() < 1 then
table.remove(this.MonsterData,i)
end
end
table.sort(this.MonsterData,function(a,b)
return a.monsterIndex > b.monsterIndex
end)
return this.MonsterData
end
function this.SortMonster(MonsterData)
table.sort(MonsterData,function(a,b)
if a.remainTime <= b.remainTime then
return a.monsterIndex > b.monsterIndex
else
return a.remainTime > b.remainTime
end
end)
end
function this.GetMonsterDataReMainTimesAndTime()
if not this.MonsterData or #this.MonsterData < 1 then
return nil
end
local removeData = {}
for i = 1 , #this.MonsterData do
if this.MonsterData[i].remainTime - PlayerManager.serverTime() < 1 then
table.remove(this.MonsterData,i)
end
end
return #this.MonsterData,this.MonsterData[#this.MonsterData].remainTime
end
--开始战斗
function this.ExecuteFightBattle(id,func)
NetManager.StartXiaoyaoBossFightRequest(id,function(msg)
local fightData = BattleManager.GetBattleServerData(msg,0)
UIManager.OpenPanel(UIName.BattlePanel, fightData, BATTLE_TYPE.DAILY_CHALLENGE,function(result)
if func then
func()
end
if result.result == 0 then
if this.levelData[this.curType].state == 1 then
UIManager.OpenPanel(UIName.XuanYuanMirrorPanelList,this.curType)
else
UIManager.OpenPanel(UIName.XuanYuanMirrorPanel)
end
elseif result.result == 1 then
this.levelData[this.curType].passId = id
this.UpdateLevelState(this.curType)
PrivilegeManager.RefreshPrivilegeUsedTimes(XuanYuanMirrorManager.freeTimeId, 1)
CheckRedPointStatus(RedPointType.People_Mirror)
if this.levelData[this.curType].state == 1 then
UIManager.OpenPanel(UIName.XuanYuanMirrorPanelList,this.curType)
else
UIManager.OpenPanel(UIName.XuanYuanMirrorPanel)
end
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
end)
end
end)
end)
end
return XiaoYaoManager