341 lines
12 KiB
Lua
341 lines
12 KiB
Lua
ExploreManager = {}
|
||
local this = ExploreManager
|
||
local ExploreConfig = ConfigManager.GetConfig(ConfigName.Explore)
|
||
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local SpecialConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,141)
|
||
this.ExploreMapData = {}
|
||
this.FormationData = {}
|
||
this.curFormationIndex = 0
|
||
function this.Initialize()
|
||
for k,v in ConfigPairs(ExploreConfig) do
|
||
this.ExploreMapData[v.Id] = {}
|
||
this.ExploreMapData[v.Id].mapId = v.Id
|
||
this.ExploreMapData[v.Id].name = v.Name
|
||
this.ExploreMapData[v.Id].iconName = v.Icon
|
||
this.ExploreMapData[v.Id].exploreMapId = v.Map
|
||
this.ExploreMapData[v.Id].openLevel = v.Level
|
||
this.ExploreMapData[v.Id].mainRewardId = v.MainReward
|
||
this.ExploreMapData[v.Id].reward = v.RewardShow
|
||
this.ExploreMapData[v.Id].force = v.Force
|
||
this.ExploreMapData[v.Id].cost = v.Cost
|
||
this.ExploreMapData[v.Id].pos = Vector3.New(v.Position[1],v.Position[2],v.Position[3])
|
||
this.ExploreMapData[v.Id].formations = {}
|
||
this.ExploreMapData[v.Id].state = 0
|
||
end
|
||
local strs = string.split(SpecialConfig.Value,"|")
|
||
for i = 1,#strs do
|
||
local data = string.split(strs[i],"#")
|
||
local formationId = tonumber(data[1])
|
||
this.FormationData[formationId] = {}
|
||
this.FormationData[formationId].formationId = formationId
|
||
this.FormationData[formationId].index = i
|
||
this.FormationData[formationId].formationName = "队伍"..i
|
||
this.FormationData[formationId].openLv = tonumber(data[2])
|
||
this.FormationData[formationId].state = -1 -- -1 未开启 0 未探索 1 探索中 2 休眠中
|
||
this.FormationData[formationId].hp = 0
|
||
this.FormationData[formationId].exploreTime = 0
|
||
this.FormationData[formationId].mapId = 0
|
||
this.FormationData[formationId].dropReward = {}
|
||
end
|
||
Game.GlobalEvent:AddEvent(GameEvent.Player.OnLevelChange, this.OnLevelChange)
|
||
this.InitMissionData()
|
||
end
|
||
|
||
function this.OnLevelChange()
|
||
local isCheckRed = false
|
||
for k,v in pairs(this.FormationData) do
|
||
if v.state < 0 then
|
||
if PlayerManager.level >= v.openLv then
|
||
v.state = 0
|
||
if k == 3101 then
|
||
FormationManager.CopyStoryFormationToCurFormation(k)
|
||
end
|
||
isCheckRed = true
|
||
end
|
||
end
|
||
end
|
||
this.UpdateMapsState()
|
||
if isCheckRed then
|
||
CheckRedPointStatus(RedPointType.ExploreFunc)
|
||
end
|
||
end
|
||
|
||
function this.UpdateMapsState()
|
||
for k,v in pairs(this.ExploreMapData) do
|
||
if PlayerManager.level >= v.openLevel then
|
||
v.state = 1
|
||
end
|
||
end
|
||
end
|
||
|
||
--刷新编队信息
|
||
function this.UpdateFormationsData(_data)
|
||
for i = 1,#_data do
|
||
this.UpdateFormationData(_data[i])
|
||
end
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Explore.UpdateFormation)
|
||
end
|
||
|
||
--刷新编队
|
||
function this.UpdateFormationData(team)
|
||
if this.FormationData[team.teamId] then
|
||
this.FormationData[team.teamId].hp = team.hp
|
||
this.FormationData[team.teamId].exploreTime = team.exploreTime
|
||
this.FormationData[team.teamId].dropReward = team.dropReward
|
||
--这个编队是否开启
|
||
if PlayerManager.level < this.FormationData[team.teamId].openLv then
|
||
this.FormationData[team.teamId].state = -1
|
||
this.UpdateMapFormationData(this.FormationData[team.teamId].mapId,team.teamId,-1)
|
||
this.FormationData[team.teamId].mapId = 0
|
||
else
|
||
--探索剩余时间小于0
|
||
if team.exploreTime - GetTimeStamp() <= 0 then
|
||
this.FormationData[team.teamId].state = 0
|
||
this.UpdateMapFormationData(this.FormationData[team.teamId].mapId,team.teamId,-1)
|
||
this.FormationData[team.teamId].mapId = 0
|
||
else
|
||
this.FormationData[team.teamId].mapId = team.mapId
|
||
this.FormationData[team.teamId].state = 1
|
||
if this.FormationData[team.teamId].hp <= 0 then
|
||
this.FormationData[team.teamId].state = 2
|
||
end
|
||
this.UpdateMapFormationData(team.mapId,team.teamId,1)
|
||
end
|
||
end
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Explore.UpdateSingleFormation,team.teamId)
|
||
else
|
||
LogGreen(string.format("%s编队不属于探索玩法",team.teamId))
|
||
end
|
||
CheckRedPointStatus(RedPointType.ExploreFunc)
|
||
end
|
||
|
||
function this.ResetTeamByTeamId(teamId)
|
||
if this.FormationData[teamId] then
|
||
this.FormationData[teamId].hp = 0
|
||
this.FormationData[teamId].exploreTime = 0
|
||
this.FormationData[teamId].dropReward = {}
|
||
this.FormationData[teamId].state = 0
|
||
this.UpdateMapFormationData(this.FormationData[teamId].mapId,teamId,-1)
|
||
this.FormationData[teamId].mapId = 0
|
||
end
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Explore.UpdateFormation)
|
||
CheckRedPointStatus(RedPointType.ExploreFunc)
|
||
end
|
||
|
||
-- 刷新地图编队
|
||
function this.UpdateMapFormationData(mapId,teamId,updateType)
|
||
if not this.ExploreMapData[mapId] then
|
||
return
|
||
end
|
||
if updateType > 0 then
|
||
if not this.ExploreMapData[mapId].formations[teamId] then
|
||
this.ExploreMapData[mapId].formations[teamId] = teamId
|
||
end
|
||
else
|
||
if this.ExploreMapData[mapId].formations[teamId] then
|
||
this.ExploreMapData[mapId].formations[teamId] = nil
|
||
end
|
||
end
|
||
end
|
||
|
||
function this.GetMapInfoByMapId(mapId)
|
||
return this.ExploreMapData[mapId]
|
||
end
|
||
|
||
function this.GetExploreMapTipData(mapId)
|
||
local data = this.ExploreMapData[mapId]
|
||
local data1 = {}
|
||
data1.name = data.name
|
||
data1.showData = {}
|
||
|
||
local singleShowData = {}
|
||
singleShowData.tips = {}
|
||
table.insert(singleShowData.tips,string.format("推荐战力:%s",data.force))
|
||
table.insert(data1.showData,singleShowData)
|
||
|
||
local singleShowData = {}
|
||
singleShowData.tips = {}
|
||
table.insert(singleShowData.tips,string.format("消耗%s:%s/分",ItemConfig[data.cost[1]].Name,data.cost[2]))
|
||
table.insert(data1.showData,singleShowData)
|
||
|
||
local singleShowData = {}
|
||
singleShowData.tips = {}
|
||
table.insert(singleShowData.tips,"探索产出:")
|
||
singleShowData.reward = data.reward
|
||
table.insert(data1.showData,singleShowData)
|
||
return data1
|
||
end
|
||
|
||
function this.InitMapUserInfosData(data,mapId)
|
||
local datas = {}
|
||
local index = 15
|
||
local myData = {}
|
||
myData.userName = PlayerManager.nickName
|
||
myData.sex = NameManager.roleSex
|
||
myData.uid = PlayerManager.uid
|
||
myData.userSkin = PlayerManager.designation
|
||
myData.userTitle = PlayerManager.skin
|
||
myData.userMount = PlayerManager.ride
|
||
myData.practiceLevel = PracticeManager.PracticeLevel or 1
|
||
myData.lv = PlayerManager.level
|
||
myData.formationId = 0
|
||
myData.hp = 0
|
||
for k,v in pairs(this.ExploreMapData[mapId].formations) do
|
||
local singleUserData = {}
|
||
singleUserData.userName = myData.userName
|
||
singleUserData.sex = myData.sex
|
||
singleUserData.uid = myData.uid
|
||
singleUserData.userSkin = myData.userSkin
|
||
singleUserData.userTitle = myData.userTitle
|
||
singleUserData.userMount = myData.userMount
|
||
singleUserData.practiceLevel = myData.practiceLevel
|
||
singleUserData.lv = myData.lv
|
||
singleUserData.formationId = k
|
||
singleUserData.hp = this.FormationData[k].hp
|
||
table.insert(datas,singleUserData)
|
||
index = index - 1
|
||
if index == 0 then
|
||
break
|
||
end
|
||
end
|
||
|
||
for i = 1,#data do
|
||
if data[i].uid ~= PlayerManager.uid then
|
||
local singleUserData = {}
|
||
singleUserData.userName = data[i].name
|
||
singleUserData.sex = data[i].gender
|
||
singleUserData.uid = data[i].uid
|
||
singleUserData.userSkin = data[i].userSkin
|
||
singleUserData.userTitle = data[i].userTitle
|
||
singleUserData.userMount = data[i].userMount
|
||
singleUserData.practiceLevel = data[i].practiceLevel or 1
|
||
singleUserData.lv = data[i].level
|
||
singleUserData.formationId = i
|
||
singleUserData.hp = 0
|
||
table.insert(datas,singleUserData)
|
||
index = index - 1
|
||
if index == 0 then
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
return datas
|
||
end
|
||
|
||
--index 1 有未开启的返回一个未开启的 0返回 所有已开启的
|
||
function this.GetFormationData(index)
|
||
local datas = {}
|
||
local add = index
|
||
local strs = string.split(SpecialConfig.Value,"|")
|
||
for i = 1,#strs do
|
||
local data = string.split(strs[i],"#")
|
||
local formationId = tonumber(data[1])
|
||
if this.FormationData[formationId].state >= 0 then
|
||
table.insert(datas, this.FormationData[formationId])
|
||
else
|
||
if add > 0 then
|
||
table.insert(datas, this.FormationData[formationId])
|
||
add = add - 1
|
||
end
|
||
end
|
||
end
|
||
return datas
|
||
end
|
||
|
||
--获取已开启的地图
|
||
function this.GetMapsData()
|
||
local datas = {}
|
||
for k,v in pairs(this.ExploreMapData) do
|
||
if v.state == 1 then
|
||
table.insert(datas,v)
|
||
end
|
||
end
|
||
return datas
|
||
end
|
||
|
||
function this.GetFormationDataByMapId(mapId)
|
||
local datas = {}
|
||
for k,v in pairs(this.ExploreMapData[mapId].formations) do
|
||
table.insert(datas, this.FormationData[v])
|
||
end
|
||
return datas
|
||
end
|
||
|
||
function this.GetHpById(id)
|
||
return this.FormationData[id].hp
|
||
end
|
||
|
||
--红点检测
|
||
function this.CheckRedPoint()
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Explore) then
|
||
return false
|
||
end
|
||
for k,v in pairs(this.FormationData) do
|
||
if v.state == 0 then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
function this.InitMissionData()
|
||
this.mission = {}
|
||
for k,v in ConfigPairs(ConfigManager.GetConfig(ConfigName.exploreTask)) do
|
||
local data = {}
|
||
data.Id = v.Id
|
||
data.index = #this.mission + 1
|
||
data.Desc = v.ContentsShow
|
||
data.info = ""
|
||
data.progress = 0
|
||
data.value = v.Values[2][1]
|
||
data.jump = -1
|
||
data.BoxReward = {}
|
||
for i = 1,#v.Reward do
|
||
table.insert(data.BoxReward ,v.Reward[i])
|
||
end
|
||
data.state = 0
|
||
table.insert(this.mission,data)
|
||
end
|
||
end
|
||
function this.SetRewardData()
|
||
local missions = {}
|
||
local allMissionData = TaskManager.GetTypeTaskList(TaskTypeDef.ExploreTask)
|
||
for k,v in ipairs(this.mission) do
|
||
for j = 1,#allMissionData do
|
||
if v.Id == allMissionData[j].missionId then
|
||
v.progress = allMissionData[j].progress
|
||
if allMissionData[j].state == 2 then
|
||
-- goText.text="已领取"
|
||
v.progress = v.value
|
||
v.state = 0
|
||
elseif allMissionData[j].state == 1 then
|
||
-- goText.text="领取"
|
||
v.progress = v.value
|
||
v.state = allMissionData[j].state
|
||
elseif allMissionData[j].state == 0 then
|
||
-- goText.text="前往"
|
||
v.state = 2
|
||
end
|
||
v.info = v.Desc ..("(")..v.progress.."/"..v.value..(")")
|
||
table.insert(missions,v)
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
local typeIndex = {
|
||
[0] = 2,
|
||
[1] = 0,
|
||
[2] = 1,
|
||
}
|
||
table.sort(missions, function(a,b)
|
||
if typeIndex[a.state] == typeIndex[b.state] then
|
||
return a.Id < b.Id
|
||
else
|
||
return typeIndex[a.state] < typeIndex[b.state]
|
||
end
|
||
end)
|
||
return missions
|
||
end
|
||
|
||
return this |