681 lines
24 KiB
Lua
681 lines
24 KiB
Lua
EnergyBaseManager = {}
|
||
local this = EnergyBaseManager
|
||
local BaseFatigueConfig = ConfigManager.GetAllConfigsData(ConfigName.BaseFatigueConfig)
|
||
local SpecialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
|
||
local BaseResourceConfig = ConfigManager.GetConfig(ConfigName.BaseResourceConfig)
|
||
local BaseLevelConfig = ConfigManager.GetConfig(ConfigName.BaseLevelConfig)
|
||
this.baseMaxLv = #ConfigManager.GetAllConfigsData(ConfigName.BaseLevelConfig)
|
||
this.buildIcon = {
|
||
"X1_nengyuanjidi_bg_18",
|
||
"X1_nengyuanjidi_bg_16",
|
||
"X1_nengyuanjidi_bg_17",
|
||
"X1_nengyuanjidi_bg_19",
|
||
}
|
||
function EnergyBaseManager.Initialize()
|
||
this.BaseEnergyInfoData = {baseResourceDetails = {}, baseFacilityInfos = {}}
|
||
for i = 1, 6 do
|
||
this.BaseEnergyInfoData.baseResourceDetails[i] = {id = i}
|
||
end
|
||
this.curPlayerId = 0
|
||
end
|
||
|
||
-- 初始化数据
|
||
function EnergyBaseManager.SetBaseEnergyInfoData(func)
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) then
|
||
if func then
|
||
func()
|
||
end
|
||
return
|
||
end
|
||
--[[
|
||
baseLevel = 基地等级
|
||
coolieCount = 苦力总数
|
||
totalSnatchCount = 当日采集资源次数(关联疲劳度)
|
||
dailyRefreshTimes = 资源当日刷新次数
|
||
plunderRefreshTimes = 邻进资源刷新次数
|
||
baseFacilityInfos = {
|
||
[1] = {
|
||
type = 基地类型
|
||
level = 基地等级
|
||
}
|
||
}
|
||
baseResourceDetails = {
|
||
[1] = {
|
||
id = 资源位置编号(1-6)
|
||
resourceId = 资源ID 资源的配置ID
|
||
progress = 进度 往拥有者方向计算
|
||
startTime = 开始时间 拥有者收取开始时间
|
||
snatchId = 抢夺者用户ID
|
||
collieCount = 资源方苦力投入数量
|
||
snatchCollieCount = 资源方投入苦力数量
|
||
redSpeed = 资源方速度
|
||
blueSpeed = 抢夺方速度
|
||
snatchName = 抢夺者名称
|
||
}
|
||
}
|
||
freeCoolieCount = 空闲苦力数量
|
||
]]
|
||
this.curPlayerId = PlayerManager.uid
|
||
NetManager.BaseEnergyInfo(function (msg)
|
||
this.BaseEnergyInfoData = msg
|
||
|
||
-- local str, str2 = "", ""
|
||
-- for i = 1, #msg.baseFacilityInfos do
|
||
-- str = str
|
||
-- .."\n 类型:"..msg.baseFacilityInfos[i].type
|
||
-- .."\n 等级:"..msg.baseFacilityInfos[i].level
|
||
-- .."\n------------------------------------------"
|
||
-- end
|
||
-- for i = 1, #msg.baseResourceDetails do
|
||
-- str2 = str2
|
||
-- .."\n id:"..msg.baseResourceDetails[i].id
|
||
-- .."\n 资源ID:"..msg.baseResourceDetails[i].resourceId
|
||
-- .."\n 进度:"..msg.baseResourceDetails[i].progress
|
||
-- .."\n 开始时间:"..msg.baseResourceDetails[i].startTime
|
||
-- .."\n 抢夺者用户ID:"..msg.baseResourceDetails[i].snatchId
|
||
-- .."\n 资源方苦力投入数量:"..msg.baseResourceDetails[i].collieCount
|
||
-- .."\n 资源方投入苦力数量:"..msg.baseResourceDetails[i].snatchCollieCount
|
||
-- .."\n 资源方速度:"..msg.baseResourceDetails[i].redSpeed
|
||
-- .."\n 资源方速度:"..msg.baseResourceDetails[i].blueSpeed
|
||
-- .."\n------------------------------------------"
|
||
-- end
|
||
-- LogError("基地信息:"
|
||
-- .."\n 基地等级:"..msg.baseLevel
|
||
-- .."\n 苦力总数:"..msg.coolieCount
|
||
-- .."\n 当日采集资源次数:"..msg.totalSnatchCount
|
||
-- .."\n 资源当日刷新次数:"..msg.dailyRefreshTimes
|
||
-- .."\n 邻进资源刷新次数:"..msg.plunderRefreshTimes
|
||
-- .."\n 空闲苦力数量:"..msg.freeCoolieCount
|
||
-- .."\n 设施信息:"..str
|
||
-- .."\n 资源列表:"..str2
|
||
-- )
|
||
if func then
|
||
func()
|
||
end
|
||
end)
|
||
end
|
||
|
||
--获取基地等级、苦力总数、空闲苦力数量、当日采集资源次数
|
||
function this.GetBaseInfo()
|
||
return {
|
||
baseLevel = this.BaseEnergyInfoData.baseLevel,
|
||
coolieCount = this.BaseEnergyInfoData.coolieCount,
|
||
freeCoolieCount = this.BaseEnergyInfoData.freeCoolieCount,
|
||
totalSnatchCount = this.BaseEnergyInfoData.totalSnatchCount
|
||
}
|
||
end
|
||
|
||
--获取疲劳及当前疲劳的表信息
|
||
function this.GetFatigue()
|
||
local fatigue = this.BaseEnergyInfoData.totalSnatchCount
|
||
for i = 1, #BaseFatigueConfig do
|
||
if fatigue >= BaseFatigueConfig[i].LowerLimit and fatigue <= BaseFatigueConfig[i].UpperLimit then
|
||
return {fatigue, BaseFatigueConfig[i]}
|
||
end
|
||
end
|
||
return {fatigue, BaseFatigueConfig[#BaseFatigueConfig]}
|
||
end
|
||
|
||
--获取设施信息
|
||
function this.GetFacilityInfos()
|
||
return this.BaseEnergyInfoData.baseFacilityInfos
|
||
end
|
||
|
||
--获取资源信息
|
||
function this.ResourceDetails()
|
||
return this.BaseEnergyInfoData.baseResourceDetails
|
||
end
|
||
|
||
--获取设施表信息
|
||
function this.GetBuildInfo(type, lv)
|
||
local config = ConfigManager.GetConfigDataByDoubleKey(ConfigName.BaseAttachmentConfig, "Type", type, "Level", lv)
|
||
local next = ConfigManager.GetConfigDataByDoubleKey(ConfigName.BaseAttachmentConfig, "Type", type, "Level", lv+1)
|
||
return config, next
|
||
end
|
||
|
||
--获取设施等级
|
||
function this.GetBuildLv(type)
|
||
local facility = this.GetFacilityInfos()
|
||
for i = 1, #facility do
|
||
if facility[i].type == type then
|
||
return facility[i].level
|
||
end
|
||
end
|
||
end
|
||
|
||
--设施/基地type=0 升级
|
||
function this.BaseLevelUp(type, func)
|
||
local oldPower = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
||
NetManager.BaseLevelUpReq(type, function (msg)
|
||
if type == 0 then
|
||
this.BaseEnergyInfoData.baseLevel = this.BaseEnergyInfoData.baseLevel + 1
|
||
else
|
||
local facility = this.GetFacilityInfos()
|
||
for i = 1, #facility do
|
||
if facility[i].type == type then
|
||
facility[i].level = facility[i].level + 1
|
||
end
|
||
end
|
||
if type == 5 then
|
||
this.BaseEnergyInfoData.coolieCount = BagManager.GetItemCountById(19004)
|
||
this.BaseEnergyInfoData.freeCoolieCount = this.BaseEnergyInfoData.freeCoolieCount + 1
|
||
end
|
||
end
|
||
RefreshPower(oldPower)
|
||
FormationManager.UserPowerChanged()
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshBaseInfo)
|
||
if func then
|
||
func(msg)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--刷新资源
|
||
function this.RefreshResourceDetails(func)
|
||
NetManager.BaseResourceRefreshReq(function (msg)
|
||
this.BaseEnergyInfoData.dailyRefreshTimes = this.BaseEnergyInfoData.dailyRefreshTimes + 1
|
||
for i = 1, #msg.baseResourceDetails do
|
||
-- LogError(i)
|
||
this.SetResourceDetails(msg.baseResourceDetails[i])
|
||
end
|
||
-- this.Log()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResource)
|
||
if func then
|
||
func()
|
||
end
|
||
end)
|
||
end
|
||
|
||
--派遣
|
||
function this.BaseCoolieDispatch(id, uid, coolieCount, func, args)
|
||
NetManager.BaseCoolieDispatchReq(id, uid, coolieCount, function (msg)
|
||
this.GetBaseFreeCoolie(function ()
|
||
for i = 1, #msg.baseResourceDetails do
|
||
this.SetResourceDetails(msg.baseResourceDetails[i])
|
||
end
|
||
-- this.Log()
|
||
if this.curPlayerId == PlayerManager.uid then
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResource)
|
||
end
|
||
--数据上报
|
||
local state = true
|
||
local target = uid
|
||
local str = "base_recall_num"
|
||
if this.curPlayerId == PlayerManager.uid then
|
||
state = false
|
||
target = 0
|
||
end
|
||
if coolieCount > 0 then
|
||
str = "base_dispatch"
|
||
end
|
||
ThinkingAnalyticsManager.Track(str, {
|
||
base_dispatch_plunder = state,
|
||
base_dispatch_target_id = target,
|
||
base_dispatch_item_id = args.itemID,
|
||
base_dispatch_item_num = args.itemNum,
|
||
base_dispatch_time = args.itemTime,
|
||
base_dispatch_beggar_num = coolieCount,
|
||
base_dispatch_beggar_total = this.BaseEnergyInfoData.coolieCount,
|
||
base_dispatch_beggar_idle = this.BaseEnergyInfoData.freeCoolieCount,
|
||
base_dispatch_fatigue = this.BaseEnergyInfoData.totalSnatchCount
|
||
})
|
||
if func then
|
||
func(msg)
|
||
end
|
||
end)
|
||
end)
|
||
end
|
||
|
||
--设置资源信息
|
||
function this.SetResourceDetails(data)
|
||
local resource = this.ResourceDetails()
|
||
local state = false
|
||
for i = 1, #resource do
|
||
if resource[i].id == data.id then
|
||
state = true
|
||
resource[i].resourceId = data.resourceId
|
||
resource[i].startTime = data.startTime
|
||
resource[i].progress = data.progress
|
||
resource[i].snatchId = data.snatchId
|
||
resource[i].collieCount = data.collieCount
|
||
resource[i].snatchCollieCount = data.snatchCollieCount
|
||
resource[i].redSpeed = data.redSpeed
|
||
resource[i].blueSpeed = data.blueSpeed
|
||
end
|
||
end
|
||
if not state then
|
||
table.insert(this.BaseEnergyInfoData.baseResourceDetails, data)
|
||
end
|
||
end
|
||
|
||
--[[
|
||
计算公式
|
||
|
||
--当守方机器苦力数量≥抢夺方机器苦力数量:
|
||
a)收取时间基数 = 再生能源基础收取时间 * ( 1 – 收取进度 )
|
||
b)收取时间系数 = 1 / ( 守方机器苦力数量 – 抢夺方机器苦力数量 * 机器苦力数量参数 ) * ( 1 / 守方疲劳度收取速度 )
|
||
c)最终收取时间 = 收取时间基数 * 收取时间系数 ,向上取整
|
||
|
||
--当守方机器苦力数量<抢夺方机器苦力数量:
|
||
a)收取时间基数 = 再生能源基础收取时间 * ( 1 + 收取进度 )
|
||
b)收取时间系数 = 1 / ( 抢夺方机器苦力数量 – 守方机器苦力数量 * 机器苦力数量参数 ) * ( 1 / 抢夺方疲劳度收取速度 )
|
||
c)最终收取时间 = 收取时间基数 * 收取时间系数 ,向上取整
|
||
]]
|
||
|
||
local CC = SpecialConfig[554].Value/100--机器苦力数量参数
|
||
--计算时间
|
||
function this.ComputingTime(data)
|
||
local resourceData = BaseResourceConfig[data.resourceId]
|
||
if data.collieCount == 0 and data.snatchCollieCount == 0 then
|
||
return resourceData.CollectTime
|
||
end
|
||
|
||
local base, coefficient, finalTime
|
||
if data.collieCount >= data.snatchCollieCount then
|
||
base = resourceData.CollectTime*(1-data.progress)
|
||
coefficient = 1/(data.collieCount-data.snatchCollieCount*CC)*(1/data.redSpeed)
|
||
finalTime = base*coefficient
|
||
-- LogError("计算时间")
|
||
-- LogError(string.format("%s*(1-%s)=", resourceData.CollectTime, data.progress)..base)
|
||
-- LogError(string.format("1/(%s-%s*%s)*(1/%s)=",data.collieCount, data.snatchCollieCount, CC, data.redSpeed)..coefficient)
|
||
-- LogError(string.format("%s*%s=", base, coefficient)..TimeToHMS(finalTime))
|
||
else
|
||
base = resourceData.CollectTime*(1+data.progress)
|
||
coefficient = 1/(data.snatchCollieCount-data.collieCount*CC)*(1/data.blueSpeed)
|
||
finalTime = base*coefficient
|
||
-- LogError("计算时间")
|
||
-- LogError(string.format("%s*(1+%s)=", resourceData.CollectTime, data.progress)..base)
|
||
-- LogError(string.format("1/(%s-%s*%s)*(1/%s)=",data.snatchCollieCount, data.collieCount, CC, data.blueSpeed)..coefficient)
|
||
-- LogError(string.format("%s*%s=", base, coefficient)..TimeToHMS(finalTime))
|
||
end
|
||
return finalTime + data.startTime--this.curTime
|
||
end
|
||
|
||
--计算进度
|
||
function this.ComputingProgress(data)
|
||
local finalTime = this.ComputingTime(data) - GetTimeStamp()
|
||
local resourceData = BaseResourceConfig[data.resourceId]
|
||
local coefficient, progress
|
||
if data.collieCount >= data.snatchCollieCount then
|
||
coefficient = 1/(data.collieCount-data.snatchCollieCount*CC)*(1/data.redSpeed)
|
||
progress = 1-(finalTime/coefficient/resourceData.CollectTime)
|
||
-- LogError("计算进度")
|
||
-- LogError(string.format("1/(%s-%s*%s)*(1*%s)=", data.collieCount, data.snatchCollieCount, CC, config[2].CollectSpeed)..coefficient)
|
||
-- LogError(string.format("1-(%s/%s/%s)=", finalTime, coefficient, resourceData.CollectTime)..progress)
|
||
else
|
||
coefficient = 1/(data.snatchCollieCount-data.collieCount*CC)*(1/data.blueSpeed)
|
||
progress = finalTime/coefficient/resourceData.CollectTime-1
|
||
-- LogError("计算进度")
|
||
-- LogError(string.format("1/(%s-%s*%s)*(1*%s)=", data.snatchCollieCount, data.collieCount, CC, data.blueSpeed)..coefficient)
|
||
-- LogError(string.format("(%s/%s/%s)-1=", finalTime, coefficient, resourceData.CollectTime)..progress)
|
||
end
|
||
return progress
|
||
end
|
||
|
||
--刷新掠夺基地信息
|
||
function this.BaseSnatchRefresh(func)
|
||
--[[
|
||
baseOtherResourceInfo = {
|
||
[1] = {
|
||
baseUserInfo = {
|
||
uid
|
||
head
|
||
level
|
||
nickName
|
||
serverId
|
||
headFrame
|
||
}
|
||
baseResourceDetails = {
|
||
[1] = {
|
||
id = 资源位置编号(1-6)
|
||
resourceId = 资源ID 资源的配置ID
|
||
progress = 进度 往拥有者方向计算
|
||
startTime = 开始时间 拥有者收取开始时间
|
||
-- snatchStartTime = 抢夺开始时间
|
||
snatchId = 抢夺者用户ID
|
||
collieCount = 己方苦力投入数量
|
||
snatchCollieCount = 抢夺放投入苦力数量
|
||
snatchSpeed = 抢夺方速度
|
||
curProgress = 当前进度
|
||
snatchName = 抢夺者名称
|
||
}
|
||
}
|
||
}
|
||
}
|
||
]]
|
||
NetManager.BaseSnatchRefresh(function (msg)
|
||
this.isCanplunderRefresh = false
|
||
this.lastPlunderRefreshTime = GetTimeStamp()
|
||
this.PlunderRefreshTimer()
|
||
if func then
|
||
func(msg.baseOtherResourceInfo)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--基地苦力详情
|
||
function this.BaseCoolieDetailRequest(func)
|
||
--[[
|
||
baseCoolieInfos = {
|
||
[1] = {
|
||
snatcherInfo = {
|
||
uid
|
||
head
|
||
level
|
||
nickName
|
||
serverId
|
||
headFrame
|
||
}
|
||
resourceNo = 1-6位置
|
||
cfgId = 资源配置ID
|
||
useCoolieCount = 投入苦力数量
|
||
otherCoolieCount = 对手投入的苦力数量
|
||
targetUid = 资源原归属uid
|
||
blueCollectSpeed = 对手收取速度
|
||
redCollectSpeed = 资源方的速度
|
||
curProgress = 当前进度
|
||
startTime = 开始时间
|
||
}
|
||
}
|
||
]]
|
||
NetManager.BaseCoolieDetailRequest(function (msg)
|
||
if func then
|
||
func(msg.baseCoolieInfos)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--请求掠夺列表
|
||
function this.BasePlunderList(func)
|
||
NetManager.BasePlunderList(function (msg)
|
||
if func then
|
||
func(msg.baseOtherResourceInfo)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--访问别人基地
|
||
function this.AccessOtherBase(id, func)
|
||
this.curPlayerId = id
|
||
NetManager.BaseOtherInfo(id, function (msg)
|
||
if func then
|
||
func(msg.baseResourceDetails)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--根据ID获取资源信息
|
||
function this.ResourceDetailsForId(playerId, resource, id)
|
||
if playerId == PlayerManager.uid then
|
||
resource = this.ResourceDetails()
|
||
end
|
||
for i = 1, #resource do
|
||
if resource[i].id == id then
|
||
return resource[i]
|
||
end
|
||
end
|
||
end
|
||
|
||
--获取抢夺日志
|
||
function this.GetBaseSnatchLog(func)
|
||
--[[
|
||
targetUid
|
||
targetNickName
|
||
snatchTime = 抢夺时间
|
||
cfgId
|
||
winnerId
|
||
winnerNickName
|
||
]]
|
||
NetManager.BaseSnatchLogReq(function (msg)
|
||
if func then
|
||
func(msg.baseSnatchLog)
|
||
end
|
||
end)
|
||
end
|
||
|
||
--获取仇人列表
|
||
function this.GetBaseEnemyList(func)
|
||
NetManager.BaseEnemyList(function (msg)
|
||
if func then
|
||
func(msg.baseOtherResourceInfo)
|
||
end
|
||
end)
|
||
end
|
||
|
||
function this.EventBasePlunderPush(msg)
|
||
--[[
|
||
targetId
|
||
operator
|
||
baseResourceDetail
|
||
]]
|
||
-- LogError("EventBasePlunderPush:"..msg.targetId)
|
||
if msg.targetId == PlayerManager.uid then
|
||
this.SetResourceDetails(msg.baseResourceDetail)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResource)
|
||
elseif msg.targetId == this.curPlayerId then
|
||
this.AccessOtherBase(this.curPlayerId, function (data)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResourceForOtherBase, data)
|
||
end)
|
||
end
|
||
end
|
||
|
||
function this.EventBaseResourceRefresh(msg)
|
||
--[[
|
||
targetUid
|
||
resourceNo
|
||
drop
|
||
cfgId
|
||
]]
|
||
-- LogError("EventBaseResourceRefresh:"..msg.targetUid)
|
||
local func = function ()
|
||
if msg.targetUid == PlayerManager.uid then
|
||
for i = 1, #this.BaseEnergyInfoData.baseResourceDetails do
|
||
if this.BaseEnergyInfoData.baseResourceDetails[i].id == msg.resourceNo then
|
||
this.BaseEnergyInfoData.baseResourceDetails[i] = {
|
||
id = msg.resourceNo,
|
||
resourceId = 0,
|
||
progress = 0,
|
||
startTime = 0,
|
||
snatchId = 0,
|
||
collieCount = 0,
|
||
snatchCollieCount = 0,
|
||
redSpeed = 0,
|
||
blueSpeed = 0,
|
||
}
|
||
end
|
||
end
|
||
-- this.Log()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResource)
|
||
elseif msg.targetUid == this.curPlayerId then
|
||
this.AccessOtherBase(this.curPlayerId, function (data)
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshResourceForOtherBase, data)
|
||
end)
|
||
end
|
||
end
|
||
if msg.drop then
|
||
this.GetBaseFreeCoolie(function ()
|
||
if UIManager.IsOpen(UIName.EnergyBaseMainPanel) then
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function ()
|
||
this.BaseEnergyInfoData.totalSnatchCount = this.BaseEnergyInfoData.totalSnatchCount + 1
|
||
func()
|
||
end)
|
||
else
|
||
-- local d = BagManager.GetItemListFromTempBag(msg.drop)
|
||
-- TaskManager.EnergyBaseCollectOver(d[1].sId)
|
||
TaskManager.EnergyBaseCollectOver(BaseResourceConfig[msg.cfgId].Reward[1])
|
||
func()
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
|
||
function this.EventBasePushDataRefresh(msg)
|
||
--[[
|
||
totalSnatchCount = 当日采集资源次数
|
||
dailyRefreshTimes = 资源当日刷新次数
|
||
plunderRefreshTimes = 邻进资源刷新次数
|
||
]]
|
||
-- LogError("EventBasePushDataRefresh")
|
||
this.BaseEnergyInfoData.totalSnatchCount = msg.totalSnatchCount
|
||
this.BaseEnergyInfoData.dailyRefreshTimes = msg.dailyRefreshTimes
|
||
this.BaseEnergyInfoData.plunderRefreshTimes = msg.plunderRefreshTimes
|
||
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.RefreshBaseInfo)
|
||
end
|
||
|
||
-- function this.Log()
|
||
-- local str = "资源信息:"
|
||
-- for i = 1, #this.BaseEnergyInfoData.baseResourceDetails do
|
||
-- str = str
|
||
-- .."\n=====id:"..this.BaseEnergyInfoData.baseResourceDetails[i].id
|
||
-- .."\n=====资源ID:"..this.BaseEnergyInfoData.baseResourceDetails[i].resourceId
|
||
-- .."\n=====进度:"..this.BaseEnergyInfoData.baseResourceDetails[i].progress
|
||
-- .."\n=====开始时间:"..this.BaseEnergyInfoData.baseResourceDetails[i].startTime
|
||
-- .."\n=====抢夺者用户ID:"..this.BaseEnergyInfoData.baseResourceDetails[i].snatchId
|
||
-- .."\n=====资源方苦力投入数量:"..this.BaseEnergyInfoData.baseResourceDetails[i].collieCount
|
||
-- .."\n=====资源方投入苦力数量:"..this.BaseEnergyInfoData.baseResourceDetails[i].snatchCollieCount
|
||
-- .."\n=====资源方速度:"..this.BaseEnergyInfoData.baseResourceDetails[i].redSpeed
|
||
-- .."\n=====资源方速度:"..this.BaseEnergyInfoData.baseResourceDetails[i].blueSpeed
|
||
-- .."\n"
|
||
-- end
|
||
-- LogError(str)
|
||
-- end
|
||
|
||
--获取属性值加成
|
||
function this.GetAllPropertyAdd()
|
||
local infos = EnergyBaseManager.GetFacilityInfos()
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) or infos == nil or #infos == 0 then
|
||
return {}
|
||
end
|
||
local addAllProVal = {}
|
||
for i = 1, 4 do
|
||
local config = EnergyBaseManager.GetBuildInfo(infos[i].type, infos[i].level)
|
||
local propertyId = config.PropertyAdd[1][1]
|
||
local propertyValue = config.PropertyAdd[1][2]
|
||
if addAllProVal[propertyId] == nil then
|
||
addAllProVal[propertyId] = 0
|
||
end
|
||
addAllProVal[propertyId] = addAllProVal[propertyId] + propertyValue
|
||
end
|
||
|
||
return addAllProVal
|
||
end
|
||
|
||
function this.GetBaseFreeCoolie(func)
|
||
NetManager.BaseFreeCoolie(function (msg)
|
||
this.BaseEnergyInfoData.freeCoolieCount = msg.freeCoolieCount
|
||
if func then
|
||
func()
|
||
end
|
||
end)
|
||
end
|
||
|
||
this.plunderRefreshCD = tonumber(SpecialConfig[557].Value)--掠夺列表刷新时间CD
|
||
this.isCanplunderRefresh = true
|
||
this.lastPlunderRefreshTime = 0
|
||
function this.SetBaseFacilityInfo(func)
|
||
--[[
|
||
baseFacilityInfos
|
||
lastPlunderRefreshTime
|
||
baseLevel
|
||
]]
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) then
|
||
if func then
|
||
func()
|
||
end
|
||
return
|
||
end
|
||
NetManager.GetBaseFacilityInfo(function (msg)
|
||
this.BaseEnergyInfoData.baseLevel = msg.baseLevel
|
||
this.lastPlunderRefreshTime = msg.lastPlunderRefreshTime
|
||
this.isCanplunderRefresh = (GetTimeStamp()-this.lastPlunderRefreshTime >= this.plunderRefreshCD)
|
||
this.PlunderRefreshTimer()
|
||
for i = 1, #msg.baseFacilityInfos do
|
||
this.BaseEnergyInfoData.baseFacilityInfos[i] = {
|
||
type = msg.baseFacilityInfos[i].type,
|
||
level = msg.baseFacilityInfos[i].level
|
||
}
|
||
end
|
||
if func then
|
||
func()
|
||
end
|
||
end)
|
||
end
|
||
|
||
function this.PlunderRefreshTimer()
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
this.timer = Timer.New(function ()
|
||
local time = this.plunderRefreshCD+this.lastPlunderRefreshTime-GetTimeStamp()
|
||
if time <= 0 then
|
||
this.isCanplunderRefresh = true
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
end
|
||
end, 1, -1, true)
|
||
this.timer:Start()
|
||
end
|
||
|
||
function this.BaseUpLvRedpoint()
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) then
|
||
return false
|
||
end
|
||
if not this.BaseEnergyInfoData.baseLevel or this.BaseEnergyInfoData.baseLevel == 0 then
|
||
return false
|
||
end
|
||
if this.BaseEnergyInfoData.baseLevel >= this.baseMaxLv then
|
||
return false
|
||
end
|
||
local data = BaseLevelConfig[this.BaseEnergyInfoData.baseLevel].Cost
|
||
if BagManager.GetItemCountById(data[1]) < data[2] then
|
||
return false
|
||
end
|
||
return true
|
||
end
|
||
|
||
function this.BuildUpLvRedpoint()
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) then
|
||
return false
|
||
end
|
||
for i = 1, 4 do
|
||
if this.BuildUpLvRedpointForType(i) then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
function this.BuildUpLvRedpointForType(type)
|
||
local lv = this.GetBuildLv(type)
|
||
if not lv then
|
||
return false
|
||
end
|
||
local cur, next = this.GetBuildInfo(type, lv)
|
||
if this.BaseEnergyInfoData.baseLevel < cur.BaseLimit then
|
||
return false
|
||
end
|
||
if cur.Cost == nil then
|
||
return false
|
||
end
|
||
if BagManager.GetItemCountById(cur.Cost[1]) < cur.Cost[2] then
|
||
return false
|
||
end
|
||
return true
|
||
end
|
||
|
||
function this.RobotBuyRedpoint()
|
||
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.EnergyBase) then
|
||
return false
|
||
end
|
||
if this.BuildUpLvRedpointForType(5) then
|
||
return true
|
||
end
|
||
return false
|
||
end
|
||
|
||
return EnergyBaseManager |