源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

500 行
16 KiB

  1. EscortModel = EscortModel or BaseClass(BaseModel)
  2. local EscortModel = EscortModel
  3. function EscortModel:__init()
  4. EscortModel.Instance = self
  5. self.max_escort_num = Config.Convoykv["daily_convy_times"].value_content
  6. self.double_escort_cost = stringtotable(Config.Convoykv["convoy_double_cost"].value_content)
  7. -- self.max_rob_num = Config.Convoykv["daily_rob_times"].value_content
  8. self.max_rob_num = 3
  9. self.escort_pve_dun = 9999
  10. -- self.escort_pve_dun = Config.Convoykv["convoy_dun_id"].value_content
  11. self:Reset()
  12. end
  13. function EscortModel:Reset()
  14. self.escort_base_info = {} --活动基础信息
  15. self.escort_blood_info = {} --车的血量信息
  16. self.escort_stage_info = {} --护送阶段信息
  17. self.temp_pos = {} --车的上一个目的地
  18. self.escort_rob_info = {} --打劫奖励信息
  19. self.is_follow_car = false --是否跟随车
  20. self.is_go_on = true --一阶段结算之后是否继续护送
  21. self.not_show_escort_ask = false --是否不显示购买了
  22. self.is_auto_buy = false --是否自动购买护送令牌
  23. self.is_improve_to = false --是否提升至某个车
  24. self.not_show_go_ask = false --是否不提示双倍时间了
  25. self.escort_skill_num = false --是否提升至某个车
  26. self.not_pause = true --是否暂停判断
  27. self.last_use_defend_skill_time = 0 --上次使用庇护技能的时间戳
  28. end
  29. function EscortModel:GetInstance()
  30. if EscortModel.Instance == nil then
  31. EscortModel.Instance = EscortModel.New()
  32. end
  33. return EscortModel.Instance
  34. end
  35. function EscortModel:getInstance()
  36. if EscortModel.Instance == nil then
  37. EscortModel.New()
  38. end
  39. return EscortModel.Instance
  40. end
  41. --等级 护送对象id 是否协助
  42. function EscortModel:GetEscortExpByLv( lv, escort_id, is_support )
  43. local vip_ratio = 0
  44. local vip = RoleManager.Instance.mainRoleInfo.vip_flag
  45. if Config.Vipprivilege[vip.."@8"] then
  46. vip_ratio = Config.Vipprivilege[vip.."@8"].value
  47. end
  48. local cfg = Config.Convoyexp
  49. local convoy_exp = 0
  50. for i,v in pairsByKeys(cfg) do
  51. if v.lv_low <= lv and lv <= v.lv_high then
  52. if is_support then
  53. convoy_exp = v.supporting_exp
  54. else
  55. convoy_exp = v.convoy_exp
  56. end
  57. break
  58. end
  59. end
  60. if escort_id and not is_support then
  61. local double_ratio = self:CurTimeIsDouble() and 2 or 1
  62. if Config.Convoyobject[escort_id] then
  63. convoy_exp = (Config.Convoyobject[escort_id].stage_one_ratio)/100 * convoy_exp
  64. end
  65. end
  66. -- 主界面只在双倍时间显示双倍奖励
  67. if self:CurTimeIsDouble() then
  68. convoy_exp = convoy_exp * 2
  69. end
  70. return convoy_exp
  71. end
  72. function EscortModel:GetEscortNameByIndex( index )
  73. local count = 1
  74. local cfg = Config.Convoyobject
  75. for k,v in pairsByKeys(cfg) do
  76. if count == index then
  77. return Trim(v.name)
  78. end
  79. count = count + 1
  80. end
  81. return ""
  82. end
  83. function EscortModel:SetEscortBaseInfo( vo )
  84. self.escort_base_info = vo
  85. self:SetIsLastDouble(vo.is_double)
  86. if self.escort_base_info.is_convoy == 0 then
  87. Scene:getInstance():CleanEscortInfo()
  88. end
  89. self:ChangeVar("escort_base_info", self.escort_base_info, false, true)
  90. end
  91. function EscortModel:GetEscortBaseInfo( )
  92. return self.escort_base_info
  93. end
  94. function EscortModel:SetIsLastDouble(is_double, force)
  95. if force then
  96. self.last_double_escort = is_double
  97. else
  98. self.last_double_escort = self.last_double_escort or is_double
  99. end
  100. self:Fire(EscortConst.CHANGE_LAST_DOUBLE)
  101. end
  102. function EscortModel:SetEscortObjectId( id,pray_val )
  103. self.escort_base_info.object_id = id
  104. self.escort_base_info.pray_val = pray_val
  105. self:ChangeVar("escort_base_info", self.escort_base_info, false, true)
  106. end
  107. function EscortModel:SetEscortBloodInfo( vo )
  108. self.escort_blood_info = vo
  109. self:ChangeVar("escort_blood_info", self.escort_blood_info, false, true)
  110. end
  111. function EscortModel:GetEscortBloodInfo( )
  112. return self.escort_blood_info
  113. end
  114. function EscortModel:SetEscortStageInfo( vo )
  115. self.escort_stage_info = vo
  116. -- self.escort_blood_info = {
  117. -- object_id = vo.convoying,
  118. -- hp = vo.hp,
  119. -- hp_max = vo.hp_lim,
  120. -- }
  121. if TableSize(vo) == 0 then--退出护送了清空
  122. Scene:getInstance():CleanEscortInfo()
  123. end
  124. self:ChangeVar("escort_stage_info", self.escort_stage_info, false, true)
  125. end
  126. function EscortModel:GetEscortStageInfo( )
  127. return self.escort_stage_info
  128. end
  129. function EscortModel:GetEscortObjectIndexById( id )
  130. local count = 1
  131. local is_break = false
  132. local cfg = Config.Convoyobject
  133. for k,v in pairsByKeys(cfg) do
  134. if k == id then
  135. is_break = true
  136. break
  137. end
  138. count = count + 1
  139. end
  140. if is_break then
  141. return count
  142. else
  143. return 1
  144. end
  145. end
  146. --飞到护送npc
  147. function EscortModel:FlyToNpc( )
  148. if SceneManager:getInstance():IsMainCityorYieldScene() then
  149. if self:IsEscortState() then
  150. Message.show("您当前正在护送中~")
  151. return
  152. end
  153. -- if self:IsOverMaxCount() then
  154. -- Message.show("今日护送次数已用完~")
  155. -- return
  156. -- end
  157. if SceneManager:getInstance():GetSceneId() == EscortConst.ESCORT_START_SCENE
  158. or SceneManager:getInstance():GetSceneId() == EscortConst.KF_ESCORT_START_SCENE then
  159. self:GoEscortNpc()
  160. else
  161. GlobalEventSystem:Fire(EventName.FORCE_STOP_DO_TASK)
  162. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  163. if self.max_escort_num - self:GetEscortTimes() > 0 then
  164. self.need_find_npc = true
  165. end
  166. self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50009)
  167. end
  168. else
  169. Message.show("请先退出当前场景")
  170. end
  171. end
  172. --[[
  173. npc
  174. stage: 0
  175. 1
  176. 2
  177. 3
  178. ]]
  179. function EscortModel:GoEscortNpc( stage, need_open_view )
  180. local cur_stage = 0
  181. stage = stage or cur_stage --不传就根据当前阶段去处理
  182. local start_npc_id, start_scene_id = EscortConst.START_NPC, EscortConst.ESCORT_START_SCENE
  183. local end_npc_id, end_scene_id = EscortConst.END_NPC, EscortConst.ESCORT_END_SCENE
  184. -- local collect_id, collect_pos = EscortConst.ESCORT_COLLECT_ID, EscortConst.ESCORT_COLLECT_POS
  185. if KfWorldModel:GetInstance():IsKFCityOpen() then
  186. start_npc_id, start_scene_id = EscortConst.KF_START_NPC, EscortConst.KF_ESCORT_START_SCENE
  187. end_npc_id, end_scene_id = EscortConst.KF_END_NPC, EscortConst.KF_ESCORT_END_SCENE
  188. -- collect_id, collect_pos = EscortConst.KF_ESCORT_COLLECT_ID, EscortConst.KF_ESCORT_COLLECT_POS
  189. end
  190. --应对当前正在运送中 且在第一个场景就被拉进去跨服了 此时采集本服场景里面的采集物
  191. if SceneManager.Instance:GetSceneId() == EscortConst.ESCORT_START_SCENE and start_scene_id == EscortConst.KF_ESCORT_START_SCENE then
  192. start_scene_id = EscortConst.ESCORT_START_SCENE
  193. end
  194. local cur_id = SceneManager:getInstance():GetSceneId()
  195. if cur_id == EscortConst.ESCORT_END_SCENE then--如果已经在第二个场景了 就修正一下数据
  196. end_npc_id, end_scene_id = EscortConst.END_NPC, EscortConst.ESCORT_END_SCENE
  197. elseif cur_id == EscortConst.KF_ESCORT_END_SCENE then--如果已经在第二个场景了 就修正一下数据
  198. end_npc_id, end_scene_id = EscortConst.KF_END_NPC, EscortConst.KF_ESCORT_END_SCENE
  199. end
  200. if cur_id == start_scene_id and self:IsEscortState( ) then--如果是在开始场景 那就去找NPC
  201. stage = 1
  202. elseif cur_id == end_scene_id and self:IsEscortState( ) then
  203. stage = 2
  204. end
  205. if stage == 0 then--去找接任务的NPC的
  206. local function callback( ... )
  207. if need_open_view then
  208. GlobalEventSystem:Fire(EscortConst.OPEN_ESCORT_VIEW, true)
  209. end
  210. end
  211. local findVo = FindVo.New()
  212. findVo.type = FindVo.NPC
  213. findVo.id = start_npc_id
  214. findVo.sceneId = start_scene_id
  215. findVo.call_back = callback
  216. GlobalEventSystem:Fire(EventName.FIND,findVo)
  217. elseif stage == 1 then
  218. local pos_data = EscortConst.ESCORT_DOOR_POS
  219. local function callback( ... )
  220. self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50003,1)
  221. end
  222. local findVo = FindVo.New()
  223. findVo.type = FindVo.POINT
  224. findVo.sceneId = start_scene_id
  225. findVo.x = pos_data[1]/ SceneObj.LogicRealRatio.x
  226. findVo.y = pos_data[2]/ SceneObj.LogicRealRatio.y
  227. findVo.call_back = callback
  228. GlobalEventSystem:Fire(EventName.FIND,findVo)
  229. elseif stage == 2 then
  230. local function callback( ... )
  231. self:Fire(EscortConst.REQUEST_SCMD_EVENT, 50003,2)
  232. end
  233. local findVo = FindVo.New()
  234. findVo.type = FindVo.NPC
  235. findVo.id = end_npc_id
  236. findVo.sceneId = end_scene_id
  237. findVo.call_back = callback
  238. GlobalEventSystem:Fire(EventName.FIND,findVo)
  239. -- elseif stage == 3 then
  240. -- local function call_back( )
  241. -- self.try_collect_left_num = 6--采集物未创建的话,每隔一段时间尝试一下,6次就够了
  242. -- local try_to_collect = nil--必须这么写
  243. -- try_to_collect = function ( )
  244. -- local monster = Scene.Instance:FindNearestMonster(collect_id, false, true)
  245. -- if monster then
  246. -- local main_role = Scene.Instance.main_role
  247. -- if main_role then
  248. -- if self.task_collect_start_real_pos == nil then
  249. -- self.task_collect_start_real_pos = co.TableXY(main_role:GetRealPos())
  250. -- else
  251. -- self.task_collect_start_real_pos.x = main_role.real_pos.x
  252. -- self.task_collect_start_real_pos.y = main_role.real_pos.y
  253. -- end
  254. -- if self.task_collect_end_real_pos == nil then
  255. -- self.task_collect_end_real_pos = co.TableXY(monster:GetRealPos())
  256. -- else
  257. -- self.task_collect_end_real_pos.x = monster.real_pos.x
  258. -- self.task_collect_end_real_pos.y = monster.real_pos.y
  259. -- end
  260. -- main_role:SetDirection(self.task_collect_start_real_pos, self.task_collect_end_real_pos, false, true)
  261. -- end
  262. -- EventSystem.Fire(GlobalEventSystem,EventName.OPEN_COLLECT_VIEW, monster.id, monster:GetVo().type_id, monster:GetVo().pick_time)
  263. -- else
  264. -- self.try_collect_left_num = self.try_collect_left_num - 1
  265. -- --此时采集物可能还未创建,所以延迟一段时间再尝试
  266. -- if not self.delay_collect_id and self.try_collect_left_num >= 0 then
  267. -- self.delay_collect_id = GlobalTimerQuest:AddPeriodQuest(try_to_collect, 0.5, 1)
  268. -- end
  269. -- end
  270. -- end
  271. -- try_to_collect()
  272. -- end
  273. -- local findVo = FindVo.New()
  274. -- findVo.sceneId = start_scene_id --pos_data[1][1]
  275. -- findVo.type = FindVo.POINT --不能用findVo.MONSTER,不然会去找最近的怪物的
  276. -- findVo.x = pos_data[1]/ SceneObj.LogicRealRatio.x
  277. -- findVo.y = pos_data[2]/ SceneObj.LogicRealRatio.y
  278. -- findVo.call_back = call_back
  279. -- GlobalEventSystem:Fire(EventName.FIND,findVo)
  280. end
  281. end
  282. --获取今日已护送次数
  283. function EscortModel:GetEscortTimes( )
  284. if self.escort_base_info and self.escort_base_info.convoy_counts then
  285. return self.escort_base_info.convoy_counts
  286. end
  287. return 0
  288. end
  289. --获取今日护送最大次数
  290. function EscortModel:GetMaxEscortTimes( )
  291. return self.max_escort_num or 3
  292. end
  293. --获取今日已抢夺次数
  294. function EscortModel:GetRobTimes( )
  295. -- if self.escort_base_info and self.escort_base_info.rob_counts then
  296. -- return self.escort_base_info.rob_counts
  297. -- end
  298. return 0
  299. end
  300. --获取今日抢夺最大次数
  301. function EscortModel:GetMaxRobTimes( )
  302. return self.max_rob_num
  303. end
  304. --护送是否已达最大次数
  305. function EscortModel:IsOverMaxCount( )
  306. if self.escort_base_info and self.escort_base_info.convoy_counts then
  307. return self.escort_base_info.convoy_counts == self.max_escort_num
  308. end
  309. end
  310. --现在是否双倍时间, 外部不能用此方法,因为数据不会实时刷新(现在已经用了,跪下来求了很久)
  311. function EscortModel:CurTimeIsDouble( )
  312. local bool = false
  313. local daily_info = DailyModel.Instance:GetAcOpenStatus(500,1)
  314. if daily_info then
  315. bool = daily_info.status == 1
  316. end
  317. return bool
  318. end
  319. --是否在护送状态
  320. function EscortModel:IsEscortState( )
  321. if TableSize(self.escort_base_info) > 0 then
  322. return self.escort_base_info.is_convoy == 1
  323. else
  324. return false
  325. end
  326. end
  327. --根据类型来获取阶段奖励
  328. function EscortModel:GetStageRewardByType( type )
  329. local escort_data = self:GetEscortBaseInfo()
  330. if TableSize(escort_data) == 0 then
  331. return {}
  332. end
  333. local cfg_data = Config.Convoyobject[escort_data.object_id]
  334. local double_ratio = self:CurTimeIsDouble() and 2 or 1
  335. if type == "escort" then
  336. local lv = RoleManager.Instance.mainRoleInfo.level
  337. local cfg_exp = Config.Convoyexp
  338. local convoy_exp = 0
  339. for i,v in pairsByKeys(cfg_exp) do
  340. if v.lv_low <= lv and lv <= v.lv_high then
  341. convoy_exp = v.convoy_exp
  342. break
  343. end
  344. end
  345. local total_data = {}
  346. local data2 = stringtotable(cfg_data.award)
  347. local exp_num2 = convoy_exp * cfg_data.stage_one_ratio/100
  348. if self:CurTimeIsDouble() or self.last_double_escort == 1 then
  349. exp_num2 = exp_num2 * 2
  350. end
  351. local exp_data2 = {
  352. [1] = 0,
  353. [2] = EscortConst.EXP_TPYE_ID,
  354. [3] = exp_num2
  355. }
  356. table.insert(data2, exp_data2)
  357. table.insert(total_data, data2)
  358. return total_data
  359. elseif type == "escort_stage" then
  360. local vip_ratio = 0
  361. local vip = RoleManager.Instance.mainRoleInfo.vip_flag
  362. if Config.Vipprivilege[vip.."@8"] then
  363. vip_ratio = Config.Vipprivilege[vip.."@8"].value
  364. end
  365. local lv = RoleManager.Instance.mainRoleInfo.level
  366. local cfg_exp = Config.Convoyexp
  367. local convoy_exp = 0
  368. for i,v in pairsByKeys(cfg_exp) do
  369. if v.lv_low <= lv and lv <= v.lv_high then
  370. convoy_exp = v.convoy_exp
  371. break
  372. end
  373. end
  374. --第一阶段
  375. local total_data = {}
  376. local data1 = {}
  377. local exp_num1 = convoy_exp * cfg_data.stage_one_ratio/100
  378. if self:CurTimeIsDouble() or self.last_double_escort == 1 then
  379. exp_num1 = exp_num1 * 2
  380. end
  381. local exp_data1 = {
  382. [1] = 0,
  383. [2] = EscortConst.EXP_TPYE_ID,
  384. [3] = exp_num1
  385. }
  386. table.insert(data1, exp_data1)
  387. table.insert(total_data, data1)
  388. return total_data
  389. end
  390. return {}
  391. end
  392. function EscortModel:SetTempPos( x,y )
  393. local data = {
  394. x = x,
  395. y = y,
  396. }
  397. self.temp_pos[#self.temp_pos+1] = data
  398. end
  399. function EscortModel:CleanTempPos( )
  400. self.temp_pos = {}
  401. end
  402. function EscortModel:GetTempPos( )
  403. if #self.temp_pos >= 1 then
  404. local temp_pos = table.remove(self.temp_pos,1)
  405. local temp_x = temp_pos.x
  406. local temp_y = temp_pos.y
  407. return temp_x, temp_y
  408. else
  409. return nil,nil
  410. end
  411. end
  412. --设置是否跟随护送车
  413. function EscortModel:SetEscortCarFollow( bool )
  414. self.temp_pos = {}
  415. self.is_follow_car = bool
  416. self:Fire(EscortConst.UPDATE_BUTTON_STATE)
  417. end
  418. --是否在跟车
  419. function EscortModel:IsFollowEscortCar( bool )
  420. return self.is_follow_car
  421. end
  422. --判断是否是自己的车
  423. function EscortModel:IsMyEscortCar( monster_id )
  424. local stage_info = self:GetEscortStageInfo()
  425. return stage_info.monster_id == monster_id
  426. end
  427. --获取护送id
  428. function EscortModel:GetMyEscortObjectId( )
  429. local stage_info = self:GetEscortStageInfo()
  430. return stage_info.convoying or 0
  431. end
  432. function EscortModel:SetEscortRobInfo( vo )
  433. self.escort_rob_info = vo
  434. self:ChangeVar("escort_rob_info", self.escort_rob_info, false, true)
  435. end
  436. function EscortModel:GetEscortRobInfo( )
  437. return self.escort_rob_info
  438. end
  439. function EscortModel:GetEscortRobTime( )
  440. return TableSize(self.escort_rob_info)
  441. end
  442. function EscortModel:GetMyEscortName( )
  443. local id = self:GetMyEscortObjectId()
  444. id = id == 0 and 1001 or id
  445. local name = Trim(Config.Convoyobject[id].name)
  446. local escort_quality = self:GetEscortObjectIndexById(id) --1绿2蓝3紫4橙
  447. local color = WordManager.goods_color_list_dark[escort_quality]
  448. return HtmlColorTxt(name, color)
  449. end
  450. --获取自己车的实例id
  451. function EscortModel:GetMyEscortCarInstanceId()
  452. local stage_info = self:GetEscortStageInfo()
  453. return stage_info.monster_id
  454. end
  455. function EscortModel:SetEscortSceneLeftHideState( bool )
  456. self.escort_left_hide = bool
  457. self:Fire(EscortConst.UPDATE_ESCORT_LEFT_SHOW)
  458. end
  459. function EscortModel:GetEscortSceneLeftHideState( )
  460. return self.escort_left_hide
  461. end
  462. function EscortModel:IsEscortSceneViewShow( )
  463. return self.is_open_escort_scene
  464. end
  465. function EscortModel:SetEscortSceneViewOpen( bool )
  466. self.is_open_escort_scene = bool
  467. end