源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

501 lines
16 KiB

EscortModel = EscortModel or BaseClass(BaseModel)
local EscortModel = EscortModel
function EscortModel:__init()
EscortModel.Instance = self
self.max_escort_num = Config.Convoykv["daily_convy_times"].value_content
self.double_escort_cost = stringtotable(Config.Convoykv["convoy_double_cost"].value_content)
-- self.max_rob_num = Config.Convoykv["daily_rob_times"].value_content
self.max_rob_num = 3
self.escort_pve_dun = 9999
-- self.escort_pve_dun = Config.Convoykv["convoy_dun_id"].value_content
self:Reset()
end
function EscortModel:Reset()
self.escort_base_info = {} --活动基础信息
self.escort_blood_info = {} --车的血量信息
self.escort_stage_info = {} --护送阶段信息
self.temp_pos = {} --车的上一个目的地
self.escort_rob_info = {} --打劫奖励信息
self.is_follow_car = false --是否跟随车
self.is_go_on = true --一阶段结算之后是否继续护送
self.not_show_escort_ask = false --是否不显示购买了
self.is_auto_buy = false --是否自动购买护送令牌
self.is_improve_to = false --是否提升至某个车
self.not_show_go_ask = false --是否不提示双倍时间了
self.escort_skill_num = false --是否提升至某个车
self.not_pause = true --是否暂停判断
self.last_use_defend_skill_time = 0 --上次使用庇护技能的时间戳
end
function EscortModel:GetInstance()
if EscortModel.Instance == nil then
EscortModel.Instance = EscortModel.New()
end
return EscortModel.Instance
end
function EscortModel:getInstance()
if EscortModel.Instance == nil then
EscortModel.New()
end
return EscortModel.Instance
end
--等级 护送对象id 是否协助
function EscortModel:GetEscortExpByLv( lv, escort_id, is_support )
local vip_ratio = 0
local vip = RoleManager.Instance.mainRoleInfo.vip_flag
if Config.Vipprivilege[vip.."@8"] then
vip_ratio = Config.Vipprivilege[vip.."@8"].value
end
local cfg = Config.Convoyexp
local convoy_exp = 0
for i,v in pairsByKeys(cfg) do
if v.lv_low <= lv and lv <= v.lv_high then
if is_support then
convoy_exp = v.supporting_exp
else
convoy_exp = v.convoy_exp
end
break
end
end
if escort_id and not is_support then
local double_ratio = self:CurTimeIsDouble() and 2 or 1
if Config.Convoyobject[escort_id] then
convoy_exp = (Config.Convoyobject[escort_id].stage_one_ratio)/100 * convoy_exp
end
end
-- 主界面只在双倍时间显示双倍奖励
if self:CurTimeIsDouble() then
convoy_exp = convoy_exp * 2
end
return convoy_exp
end
function EscortModel:GetEscortNameByIndex( index )
local count = 1
local cfg = Config.Convoyobject
for k,v in pairsByKeys(cfg) do
if count == index then
return Trim(v.name)
end
count = count + 1
end
return ""
end
function EscortModel:SetEscortBaseInfo( vo )
self.escort_base_info = vo
self:SetIsLastDouble(vo.is_double)
if self.escort_base_info.is_convoy == 0 then
Scene:getInstance():CleanEscortInfo()
end
self:ChangeVar("escort_base_info", self.escort_base_info, false, true)
end
function EscortModel:GetEscortBaseInfo( )
return self.escort_base_info
end
function EscortModel:SetIsLastDouble(is_double, force)
if force then
self.last_double_escort = is_double
else
self.last_double_escort = self.last_double_escort or is_double
end
self:Fire(EscortConst.CHANGE_LAST_DOUBLE)
end
function EscortModel:SetEscortObjectId( id,pray_val )
self.escort_base_info.object_id = id
self.escort_base_info.pray_val = pray_val
self:ChangeVar("escort_base_info", self.escort_base_info, false, true)
end
function EscortModel:SetEscortBloodInfo( vo )
self.escort_blood_info = vo
self:ChangeVar("escort_blood_info", self.escort_blood_info, false, true)
end
function EscortModel:GetEscortBloodInfo( )
return self.escort_blood_info
end
function EscortModel:SetEscortStageInfo( vo )
self.escort_stage_info = vo
-- self.escort_blood_info = {
-- object_id = vo.convoying,
-- hp = vo.hp,
-- hp_max = vo.hp_lim,
-- }
if TableSize(vo) == 0 then--退出护送了清空
Scene:getInstance():CleanEscortInfo()
end
self:ChangeVar("escort_stage_info", self.escort_stage_info, false, true)
end
function EscortModel:GetEscortStageInfo( )
return self.escort_stage_info
end
function EscortModel:GetEscortObjectIndexById( id )
local count = 1
local is_break = false
local cfg = Config.Convoyobject
for k,v in pairsByKeys(cfg) do
if k == id then
is_break = true
break
end
count = count + 1
end
if is_break then
return count
else
return 1
end
end
--飞到护送npc
function EscortModel:FlyToNpc( )
if SceneManager:getInstance():IsMainCityorYieldScene() then
if self:IsEscortState() then
Message.show("您当前正在护送中~")
return
end
-- if self:IsOverMaxCount() then
-- Message.show("今日护送次数已用完~")
-- return
-- end
if SceneManager:getInstance():GetSceneId() == EscortConst.ESCORT_START_SCENE
or SceneManager:getInstance():GetSceneId() == EscortConst.KF_ESCORT_START_SCENE then
self:GoEscortNpc()
else
GlobalEventSystem:Fire(EventName.FORCE_STOP_DO_TASK)
GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
if self.max_escort_num - self:GetEscortTimes() > 0 then
self.need_find_npc = true
end
self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50009)
end
else
Message.show("请先退出当前场景")
end
end
--[[
前往护送npc
stage: 0 领取阶段
1 护送阶段一
2 护送阶段二
3 缓冲状态(一阶段未结算 二阶段还没开始)
]]
function EscortModel:GoEscortNpc( stage, need_open_view )
local cur_stage = 0
stage = stage or cur_stage --不传就根据当前阶段去处理
local start_npc_id, start_scene_id = EscortConst.START_NPC, EscortConst.ESCORT_START_SCENE
local end_npc_id, end_scene_id = EscortConst.END_NPC, EscortConst.ESCORT_END_SCENE
-- local collect_id, collect_pos = EscortConst.ESCORT_COLLECT_ID, EscortConst.ESCORT_COLLECT_POS
if KfWorldModel:GetInstance():IsKFCityOpen() then
start_npc_id, start_scene_id = EscortConst.KF_START_NPC, EscortConst.KF_ESCORT_START_SCENE
end_npc_id, end_scene_id = EscortConst.KF_END_NPC, EscortConst.KF_ESCORT_END_SCENE
-- collect_id, collect_pos = EscortConst.KF_ESCORT_COLLECT_ID, EscortConst.KF_ESCORT_COLLECT_POS
end
--应对当前正在运送中 且在第一个场景就被拉进去跨服了 此时采集本服场景里面的采集物
if SceneManager.Instance:GetSceneId() == EscortConst.ESCORT_START_SCENE and start_scene_id == EscortConst.KF_ESCORT_START_SCENE then
start_scene_id = EscortConst.ESCORT_START_SCENE
end
local cur_id = SceneManager:getInstance():GetSceneId()
if cur_id == EscortConst.ESCORT_END_SCENE then--如果已经在第二个场景了 就修正一下数据
end_npc_id, end_scene_id = EscortConst.END_NPC, EscortConst.ESCORT_END_SCENE
elseif cur_id == EscortConst.KF_ESCORT_END_SCENE then--如果已经在第二个场景了 就修正一下数据
end_npc_id, end_scene_id = EscortConst.KF_END_NPC, EscortConst.KF_ESCORT_END_SCENE
end
if cur_id == start_scene_id and self:IsEscortState( ) then--如果是在开始场景 那就去找NPC
stage = 1
elseif cur_id == end_scene_id and self:IsEscortState( ) then
stage = 2
end
if stage == 0 then--去找接任务的NPC的
local function callback( ... )
if need_open_view then
GlobalEventSystem:Fire(EscortConst.OPEN_ESCORT_VIEW, true)
end
end
local findVo = FindVo.New()
findVo.type = FindVo.NPC
findVo.id = start_npc_id
findVo.sceneId = start_scene_id
findVo.call_back = callback
GlobalEventSystem:Fire(EventName.FIND,findVo)
elseif stage == 1 then
local pos_data = EscortConst.ESCORT_DOOR_POS
local function callback( ... )
self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50003,1)
end
local findVo = FindVo.New()
findVo.type = FindVo.POINT
findVo.sceneId = start_scene_id
findVo.x = pos_data[1]/ SceneObj.LogicRealRatio.x
findVo.y = pos_data[2]/ SceneObj.LogicRealRatio.y
findVo.call_back = callback
GlobalEventSystem:Fire(EventName.FIND,findVo)
elseif stage == 2 then
local function callback( ... )
self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50003,2)
end
local findVo = FindVo.New()
findVo.type = FindVo.NPC
findVo.id = end_npc_id
findVo.sceneId = end_scene_id
findVo.call_back = callback
GlobalEventSystem:Fire(EventName.FIND,findVo)
-- elseif stage == 3 then
-- local function call_back( )
-- self.try_collect_left_num = 6--采集物未创建的话,每隔一段时间尝试一下,6次就够了
-- local try_to_collect = nil--必须这么写
-- try_to_collect = function ( )
-- local monster = Scene.Instance:FindNearestMonster(collect_id, false, true)
-- if monster then
-- local main_role = Scene.Instance.main_role
-- if main_role then
-- if self.task_collect_start_real_pos == nil then
-- self.task_collect_start_real_pos = co.TableXY(main_role:GetRealPos())
-- else
-- self.task_collect_start_real_pos.x = main_role.real_pos.x
-- self.task_collect_start_real_pos.y = main_role.real_pos.y
-- end
-- if self.task_collect_end_real_pos == nil then
-- self.task_collect_end_real_pos = co.TableXY(monster:GetRealPos())
-- else
-- self.task_collect_end_real_pos.x = monster.real_pos.x
-- self.task_collect_end_real_pos.y = monster.real_pos.y
-- end
-- main_role:SetDirection(self.task_collect_start_real_pos, self.task_collect_end_real_pos, false, true)
-- end
-- EventSystem.Fire(GlobalEventSystem,EventName.OPEN_COLLECT_VIEW, monster.id, monster:GetVo().type_id, monster:GetVo().pick_time)
-- else
-- self.try_collect_left_num = self.try_collect_left_num - 1
-- --此时采集物可能还未创建,所以延迟一段时间再尝试
-- if not self.delay_collect_id and self.try_collect_left_num >= 0 then
-- self.delay_collect_id = GlobalTimerQuest:AddPeriodQuest(try_to_collect, 0.5, 1)
-- end
-- end
-- end
-- try_to_collect()
-- end
-- local findVo = FindVo.New()
-- findVo.sceneId = start_scene_id --pos_data[1][1]
-- findVo.type = FindVo.POINT --不能用findVo.MONSTER,不然会去找最近的怪物的
-- findVo.x = pos_data[1]/ SceneObj.LogicRealRatio.x
-- findVo.y = pos_data[2]/ SceneObj.LogicRealRatio.y
-- findVo.call_back = call_back
-- GlobalEventSystem:Fire(EventName.FIND,findVo)
end
end
--获取今日已护送次数
function EscortModel:GetEscortTimes( )
if self.escort_base_info and self.escort_base_info.convoy_counts then
return self.escort_base_info.convoy_counts
end
return 0
end
--获取今日护送最大次数
function EscortModel:GetMaxEscortTimes( )
return self.max_escort_num or 3
end
--获取今日已抢夺次数
function EscortModel:GetRobTimes( )
-- if self.escort_base_info and self.escort_base_info.rob_counts then
-- return self.escort_base_info.rob_counts
-- end
return 0
end
--获取今日抢夺最大次数
function EscortModel:GetMaxRobTimes( )
return self.max_rob_num
end
--护送是否已达最大次数
function EscortModel:IsOverMaxCount( )
if self.escort_base_info and self.escort_base_info.convoy_counts then
return self.escort_base_info.convoy_counts == self.max_escort_num
end
end
--现在是否双倍时间, 外部不能用此方法,因为数据不会实时刷新(现在已经用了,跪下来求了很久)
function EscortModel:CurTimeIsDouble( )
local bool = false
local daily_info = DailyModel.Instance:GetAcOpenStatus(500,1)
if daily_info then
bool = daily_info.status == 1
end
return bool
end
--是否在护送状态
function EscortModel:IsEscortState( )
if TableSize(self.escort_base_info) > 0 then
return self.escort_base_info.is_convoy == 1
else
return false
end
end
--根据类型来获取阶段奖励
function EscortModel:GetStageRewardByType( type )
local escort_data = self:GetEscortBaseInfo()
if TableSize(escort_data) == 0 then
return {}
end
local cfg_data = Config.Convoyobject[escort_data.object_id]
local double_ratio = self:CurTimeIsDouble() and 2 or 1
if type == "escort" then
local lv = RoleManager.Instance.mainRoleInfo.level
local cfg_exp = Config.Convoyexp
local convoy_exp = 0
for i,v in pairsByKeys(cfg_exp) do
if v.lv_low <= lv and lv <= v.lv_high then
convoy_exp = v.convoy_exp
break
end
end
local total_data = {}
local data2 = stringtotable(cfg_data.award)
local exp_num2 = convoy_exp * cfg_data.stage_one_ratio/100
if self:CurTimeIsDouble() or self.last_double_escort == 1 then
exp_num2 = exp_num2 * 2
end
local exp_data2 = {
[1] = 0,
[2] = EscortConst.EXP_TPYE_ID,
[3] = exp_num2
}
table.insert(data2, exp_data2)
table.insert(total_data, data2)
return total_data
elseif type == "escort_stage" then
local vip_ratio = 0
local vip = RoleManager.Instance.mainRoleInfo.vip_flag
if Config.Vipprivilege[vip.."@8"] then
vip_ratio = Config.Vipprivilege[vip.."@8"].value
end
local lv = RoleManager.Instance.mainRoleInfo.level
local cfg_exp = Config.Convoyexp
local convoy_exp = 0
for i,v in pairsByKeys(cfg_exp) do
if v.lv_low <= lv and lv <= v.lv_high then
convoy_exp = v.convoy_exp
break
end
end
--第一阶段
local total_data = {}
local data1 = {}
local exp_num1 = convoy_exp * cfg_data.stage_one_ratio/100
if self:CurTimeIsDouble() or self.last_double_escort == 1 then
exp_num1 = exp_num1 * 2
end
local exp_data1 = {
[1] = 0,
[2] = EscortConst.EXP_TPYE_ID,
[3] = exp_num1
}
table.insert(data1, exp_data1)
table.insert(total_data, data1)
return total_data
end
return {}
end
function EscortModel:SetTempPos( x,y )
local data = {
x = x,
y = y,
}
self.temp_pos[#self.temp_pos+1] = data
end
function EscortModel:CleanTempPos( )
self.temp_pos = {}
end
function EscortModel:GetTempPos( )
if #self.temp_pos >= 1 then
local temp_pos = table.remove(self.temp_pos,1)
local temp_x = temp_pos.x
local temp_y = temp_pos.y
return temp_x, temp_y
else
return nil,nil
end
end
--设置是否跟随护送车
function EscortModel:SetEscortCarFollow( bool )
self.temp_pos = {}
self.is_follow_car = bool
self:Fire(EscortConst.UPDATE_BUTTON_STATE)
end
--是否在跟车
function EscortModel:IsFollowEscortCar( bool )
return self.is_follow_car
end
--判断是否是自己的车
function EscortModel:IsMyEscortCar( monster_id )
local stage_info = self:GetEscortStageInfo()
return stage_info.monster_id == monster_id
end
--获取护送id
function EscortModel:GetMyEscortObjectId( )
local stage_info = self:GetEscortStageInfo()
return stage_info.convoying or 0
end
function EscortModel:SetEscortRobInfo( vo )
self.escort_rob_info = vo
self:ChangeVar("escort_rob_info", self.escort_rob_info, false, true)
end
function EscortModel:GetEscortRobInfo( )
return self.escort_rob_info
end
function EscortModel:GetEscortRobTime( )
return TableSize(self.escort_rob_info)
end
function EscortModel:GetMyEscortName( )
local id = self:GetMyEscortObjectId()
id = id == 0 and 1001 or id
local name = Trim(Config.Convoyobject[id].name)
local escort_quality = self:GetEscortObjectIndexById(id) --1绿2蓝3紫4橙
local color = WordManager.goods_color_list_dark[escort_quality]
return HtmlColorTxt(name, color)
end
--获取自己车的实例id
function EscortModel:GetMyEscortCarInstanceId()
local stage_info = self:GetEscortStageInfo()
return stage_info.monster_id
end
function EscortModel:SetEscortSceneLeftHideState( bool )
self.escort_left_hide = bool
self:Fire(EscortConst.UPDATE_ESCORT_LEFT_SHOW)
end
function EscortModel:GetEscortSceneLeftHideState( )
return self.escort_left_hide
end
function EscortModel:IsEscortSceneViewShow( )
return self.is_open_escort_scene
end
function EscortModel:SetEscortSceneViewOpen( bool )
self.is_open_escort_scene = bool
end