2020-10-14 16:57:35 +08:00
|
|
|
XiaoYaoManager = {}
|
|
|
|
|
local this = XiaoYaoManager
|
|
|
|
|
this.curMapId=0;
|
2020-10-11 09:40:22 +08:00
|
|
|
|
|
|
|
|
this.MonsterData={}
|
2020-10-15 14:16:57 +08:00
|
|
|
this.fightBossIndex = 0
|
2020-10-11 09:40:22 +08:00
|
|
|
|
2020-10-15 16:50:56 +08:00
|
|
|
this.HeroData={}
|
|
|
|
|
this.GetHeroIndex = 0
|
|
|
|
|
|
2020-10-11 09:40:22 +08:00
|
|
|
this.luckyTurnTableRewards={}
|
|
|
|
|
this.luckyluckyTurnTableTimes = 0
|
|
|
|
|
this.luckyluckyTurnTableRemainTime = 0
|
2020-10-11 11:10:07 +08:00
|
|
|
|
2020-10-14 16:57:35 +08:00
|
|
|
--打开逍遥游地图列表界面
|
|
|
|
|
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
|
2020-10-11 09:40:22 +08:00
|
|
|
end
|
2020-10-14 16:57:35 +08:00
|
|
|
Log("打开逍遥游地图列表界面")
|
|
|
|
|
UIManager.OpenPanel(UIName.XiaoYaoYouPanel,_data)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--打开逍遥游地图界面
|
|
|
|
|
function this.OpenXiaoYaoMap(mapId)
|
|
|
|
|
NetManager.JourneyGetOneInfoResponse(mapId,function (msg)
|
|
|
|
|
this.curMapId=mapId
|
2020-10-15 19:26:17 +08:00
|
|
|
local curMapData=msg
|
|
|
|
|
if curMapData.cell~=nil then
|
|
|
|
|
table.sort(curMapData.cell,function(a,b)
|
2020-10-14 16:57:35 +08:00
|
|
|
return a.cellIndex < b.cellIndex
|
|
|
|
|
end)
|
2020-10-15 14:16:57 +08:00
|
|
|
end
|
|
|
|
|
this.fightBossIndex = 0
|
|
|
|
|
this.InitLuckyTurnTables(msg)
|
|
|
|
|
this.InitMonsterData(msg.monsterInfo,1)
|
2020-10-15 16:50:56 +08:00
|
|
|
this.InitHeroData(msg.goodsInfo,1)
|
2020-10-15 19:26:17 +08:00
|
|
|
Log("打开逍遥游地图界面")
|
|
|
|
|
UIManager.OpenPanel(UIName.XiaoYaoMapPanel,curMapData)
|
2020-10-15 19:31:46 +08:00
|
|
|
|
2020-10-14 16:57:35 +08:00
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--掷骰子请求
|
2020-10-15 12:04:23 +08:00
|
|
|
function this.StartXiaoYao()
|
2020-10-15 11:53:03 +08:00
|
|
|
NetManager.JourneyDoResponse(this.curMapId,function (msg)
|
2020-10-11 09:40:22 +08:00
|
|
|
--0、普通节点 1、奖励节点 2、双倍节点 3、额外骰子节点 4、招募英雄节点 5、怪物节点 6,转盘
|
|
|
|
|
if msg.pathType == 5 then
|
2020-10-15 20:30:11 +08:00
|
|
|
this.InitMonsterData(msg.monster,2)
|
2020-10-11 09:40:22 +08:00
|
|
|
elseif msg.pathType == 6 then
|
|
|
|
|
this.InitLuckyTurnTables(msg)
|
2020-10-15 16:50:56 +08:00
|
|
|
elseif msg.pathType == 4 then
|
|
|
|
|
this.InitHeroData(msg.goodsInfo,2)
|
2020-10-11 09:40:22 +08:00
|
|
|
end
|
2020-10-15 10:53:00 +08:00
|
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.XiaoYao.StartXiaoYao, msg)
|
2020-10-14 16:57:35 +08:00
|
|
|
end)
|
|
|
|
|
end
|
2020-10-15 16:50:56 +08:00
|
|
|
|
2020-10-15 14:16:57 +08:00
|
|
|
--初始化幸运转盘
|
2020-10-11 09:40:22 +08:00
|
|
|
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
|
2020-10-15 17:48:14 +08:00
|
|
|
this.luckyluckyTurnTableTimes = msg.randomTime
|
2020-10-11 09:40:22 +08:00
|
|
|
elseif msg.overTime and msg.overTime > 0 then
|
|
|
|
|
this.luckyluckyTurnTableRemainTime = msg.overTime
|
|
|
|
|
end
|
2020-10-15 17:48:14 +08:00
|
|
|
LogGreen("幸运转盘剩余次数:"..this.luckyluckyTurnTableTimes)
|
2020-10-15 20:30:11 +08:00
|
|
|
LogGreen("幸运转盘剩余时间:"..this.luckyluckyTurnTableRemainTime)
|
2020-10-11 09:40:22 +08:00
|
|
|
end
|
|
|
|
|
|
2020-10-15 16:50:56 +08:00
|
|
|
-- type 1初始化 2添加 hero
|
|
|
|
|
function this.InitHeroData(goodsInfo,type)
|
|
|
|
|
if type == 1 then
|
|
|
|
|
this.HeroData = {}
|
|
|
|
|
for i = 1, #goodsInfo do
|
|
|
|
|
local hero = {}
|
|
|
|
|
hero.goodsId = goodsInfo[i].goodsId
|
|
|
|
|
hero.goodsIndex = goodsInfo[i].goodsIndex
|
|
|
|
|
hero.remainTime = goodsInfo[i].remainTime
|
|
|
|
|
table.insert(this.HeroData,hero)
|
|
|
|
|
end
|
|
|
|
|
elseif type == 2 then
|
|
|
|
|
local hero = {}
|
|
|
|
|
hero.goodsId = goodsInfo.goodsId
|
|
|
|
|
hero.goodsIndex = goodsInfo.goodsIndex
|
|
|
|
|
hero.remainTime = goodsInfo.remainTime
|
|
|
|
|
table.insert(this.HeroData,hero)
|
|
|
|
|
end
|
|
|
|
|
table.sort(this.HeroData,function(a,b)
|
|
|
|
|
return a.goodsIndex > b.goodsIndex
|
|
|
|
|
end)
|
2020-10-15 17:48:14 +08:00
|
|
|
LogGreen("招募英雄个数"..#this.HeroData)
|
2020-10-15 16:50:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function this.GetHeroDatas()
|
|
|
|
|
if not this.HeroData or #this.HeroData < 1 then
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for i = 1 , #this.HeroData do
|
2020-10-15 19:41:47 +08:00
|
|
|
if this.HeroData[i].remainTime - PlayerManager.serverTime < 1 then
|
2020-10-15 16:50:56 +08:00
|
|
|
if this.HeroData[i].goodsIndex == this.GetHeroIndex then
|
|
|
|
|
this.GetHeroIndex = 0
|
|
|
|
|
end
|
|
|
|
|
table.remove(this.HeroData,i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
table.sort(this.HeroData,function(a,b)
|
|
|
|
|
return a.goodsIndex > b.goodsIndex
|
|
|
|
|
end)
|
|
|
|
|
return this.HeroData
|
|
|
|
|
end
|
|
|
|
|
|
2020-10-15 14:16:57 +08:00
|
|
|
-- type 1初始化 2添加 boss
|
2020-10-11 09:40:22 +08:00
|
|
|
function this.InitMonsterData(BackMonsterDatas,type)
|
|
|
|
|
if type == 1 then
|
|
|
|
|
this.MonsterData = {}
|
2020-10-15 14:16:57 +08:00
|
|
|
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].rewardShow
|
2020-10-15 19:41:47 +08:00
|
|
|
LogGreen("monster.monsterId"..monster.monsterId)
|
|
|
|
|
LogGreen("monster.monsterIndex"..monster.monsterIndex)
|
|
|
|
|
LogGreen("monster.monsterHp"..monster.monsterHp)
|
|
|
|
|
LogGreen("monster.remainTime"..monster.remainTime)
|
|
|
|
|
LogGreen("monster.attackNum"..monster.attackNum)
|
|
|
|
|
LogGreen("monster.reward"..monster.reward)
|
2020-10-15 14:16:57 +08:00
|
|
|
table.insert(this.MonsterData,monster)
|
|
|
|
|
end
|
|
|
|
|
elseif type == 2 then
|
2020-10-11 09:40:22 +08:00
|
|
|
local monster = {}
|
2020-10-15 14:16:57 +08:00
|
|
|
monster.monsterId = BackMonsterDatas.monsterId
|
|
|
|
|
monster.monsterIndex = BackMonsterDatas.monsterIndex
|
|
|
|
|
monster.monsterHp = BackMonsterDatas.monsterHp
|
|
|
|
|
monster.remainTime = BackMonsterDatas.remainTime
|
|
|
|
|
monster.attackNum = BackMonsterDatas.attackNum
|
|
|
|
|
monster.reward = BackMonsterDatas.rewardShow
|
2020-10-15 19:41:47 +08:00
|
|
|
LogGreen("monster.monsterId"..monster.monsterId)
|
|
|
|
|
LogGreen("monster.monsterIndex"..monster.monsterIndex)
|
|
|
|
|
LogGreen("monster.monsterHp"..monster.monsterHp)
|
|
|
|
|
LogGreen("monster.remainTime"..monster.remainTime)
|
|
|
|
|
LogGreen("monster.attackNum"..monster.attackNum)
|
|
|
|
|
|
|
|
|
|
--LogGreen("monster.reward"..monster.reward)
|
|
|
|
|
LogGreen("monster.reward"..monster.reward)
|
2020-10-15 14:16:57 +08:00
|
|
|
table.insert(this.MonsterData,monster)
|
2020-10-11 09:40:22 +08:00
|
|
|
end
|
2020-10-15 17:48:14 +08:00
|
|
|
LogGreen("boss个数"..#this.MonsterData)
|
2020-10-11 09:40:22 +08:00
|
|
|
end
|
2020-10-15 16:50:56 +08:00
|
|
|
|
2020-10-15 14:16:57 +08:00
|
|
|
--刷新
|
|
|
|
|
function this.UpdateMonsterData(BackMonsterData,id)
|
|
|
|
|
for i= 1, #this.MonsterData do
|
|
|
|
|
if not BackMonsterData and this.MonsterData[i].monsterIndex == id then
|
|
|
|
|
table.remove(this.MonsterData,i)
|
|
|
|
|
elseif BackMonsterData and BackMonsterData.monsterIndex == this.MonsterData[i].monsterIndex then
|
|
|
|
|
this.MonsterData[i].monsterHp = BackMonsterData.monsterHp
|
|
|
|
|
this.MonsterData[i].attackNum = BackMonsterData.attackNum
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-10-11 09:40:22 +08:00
|
|
|
|
|
|
|
|
function this.GetMonsterDatas()
|
|
|
|
|
if not this.MonsterData or #this.MonsterData < 1 then
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
for i = 1 , #this.MonsterData do
|
2020-10-15 19:41:47 +08:00
|
|
|
if this.MonsterData[i].remainTime - PlayerManager.serverTime < 1 then
|
2020-10-15 14:16:57 +08:00
|
|
|
if this.MonsterData[i].monsterIndex == this.fightBossIndex then
|
|
|
|
|
this.fightBossIndex = 0
|
|
|
|
|
end
|
2020-10-11 09:40:22 +08:00
|
|
|
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
|
2020-10-15 19:41:47 +08:00
|
|
|
if this.MonsterData[i].remainTime - PlayerManager.serverTime < 1 then
|
2020-10-11 09:40:22 +08:00
|
|
|
table.remove(this.MonsterData,i)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-10-15 16:50:56 +08:00
|
|
|
this.SortMonster(this.MonsterData)
|
2020-10-11 09:40:22 +08:00
|
|
|
return #this.MonsterData,this.MonsterData[#this.MonsterData].remainTime
|
|
|
|
|
end
|
2020-10-14 16:57:35 +08:00
|
|
|
|
2020-10-11 11:10:07 +08:00
|
|
|
--开始战斗
|
2020-10-15 19:41:47 +08:00
|
|
|
function this.ExecuteFightBattle(id,func)
|
2020-10-11 11:10:07 +08:00
|
|
|
NetManager.StartXiaoyaoBossFightRequest(id,function(msg)
|
|
|
|
|
local fightData = BattleManager.GetBattleServerData(msg,0)
|
2020-10-15 19:41:47 +08:00
|
|
|
if func then
|
|
|
|
|
func()
|
|
|
|
|
end
|
2020-10-15 14:16:57 +08:00
|
|
|
UIManager.OpenPanel(UIName.BattlePanel, fightData, BATTLE_TYPE.STORY_FIGHT,function(result)
|
|
|
|
|
this.UpdateMonsterData(msg.monster,id)
|
|
|
|
|
this.OpenMapList()
|
|
|
|
|
UIManager.OpenPanel(UIName.XiaoYaoLuckyBossPopup)
|
|
|
|
|
if result.result == 1 then
|
|
|
|
|
this.fightBossIndex = 0
|
|
|
|
|
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function() end)
|
|
|
|
|
end
|
2020-10-11 11:10:07 +08:00
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
2020-10-15 16:50:56 +08:00
|
|
|
-- 转盘请求
|
|
|
|
|
function this.GameOperate(func)
|
|
|
|
|
-- 初始化数据
|
|
|
|
|
NetManager.XiaoyaoyouTurnTableRequest(function(msg)
|
|
|
|
|
this.luckyluckyTurnTableTimes = msg.count
|
|
|
|
|
this.luckyTurnTableRewards = this.InitLuckyTurnTables(msg.nextRandom)
|
|
|
|
|
if func then
|
|
|
|
|
func(msg)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
2020-10-14 16:57:35 +08:00
|
|
|
return XiaoYaoManager
|