task_manager.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. package model
  2. import (
  3. "rocommon/util"
  4. "roserver/serverproto"
  5. )
  6. //参数说明,在common.proto协议文件中
  7. //[枚举类型:枚举参数...] 枚举参数根据枚举类型不同会有不同个数
  8. func TaskMagCheck(role *Role, taskType serverproto.TaskType, count int32) {
  9. //todo...
  10. // 对当前已经接受的任务做枚举判断
  11. // 主界面任务单独做处理
  12. if !role.isLoad {
  13. util.ErrorF("uid=%v TaskMagCheck taskType=%v", role.GetUUid(), taskType)
  14. return
  15. }
  16. role.roleTask.TaskCheck(taskType, count)
  17. //头像设置处理
  18. role.roleTask.headConditionCheck(taskType, count)
  19. //转职条件处理
  20. role.roleTask.jobConditionCheck(taskType, count)
  21. //精彩活动任务处理
  22. role.roleActivity.TaskCheck(taskType, count)
  23. // 称号任务系统
  24. role.roleHead.TaskCheck(taskType, count)
  25. }
  26. func TaskConditionCheck(role *Role, taskData *serverproto.TaskData, taskType serverproto.TaskType,
  27. conditionList map[int32][]int32, count int32, bForce bool) bool {
  28. if taskData.State == TASK_REWARD_STATE_COMPLETED ||
  29. taskData.State == TASK_REWARD_STATE_REWARD {
  30. return false
  31. }
  32. bChange := false
  33. //完成单条任务条件
  34. if count > 0 {
  35. for key := range conditionList {
  36. //判断当前任务中的子条件是否已经完成
  37. if checkSubConditionState(key, taskData) {
  38. break
  39. }
  40. if key == int32(taskType) {
  41. ret := conditionCheck(role, taskData, taskType, conditionList[key], count, bForce)
  42. if ret == TASK_CONDITION_OK {
  43. bChange = true
  44. } else if ret == TASK_CONDITION_CHANGE {
  45. bChange = true
  46. }
  47. break
  48. }
  49. }
  50. } else {
  51. //直接检查任务所有条件,适用于接取新任务时的操作
  52. for key, _ := range conditionList {
  53. if checkSubConditionState(key, taskData) {
  54. continue
  55. }
  56. //默认为0,如果是特定的任务枚举。则做初始化
  57. initCount := GetNextTaskInitCount(role, key)
  58. ret := conditionCheck(role, taskData, serverproto.TaskType(key), conditionList[key], initCount, bForce)
  59. if ret == TASK_CONDITION_OK {
  60. bChange = true
  61. } else if ret == TASK_CONDITION_CHANGE {
  62. bChange = true
  63. }
  64. }
  65. }
  66. //统计子条件完成数量
  67. finishNum := 0
  68. for _, data := range taskData.Progress {
  69. if data.State == 1 {
  70. finishNum++
  71. }
  72. }
  73. if finishNum >= len(conditionList) {
  74. taskData.State = TASK_REWARD_STATE_COMPLETED
  75. }
  76. if finishNum > 0 || bChange {
  77. return true
  78. }
  79. return false
  80. }
  81. //true->finish bool->not finish
  82. func checkSubConditionState(key int32, taskData *serverproto.TaskData) bool {
  83. for idx := 0; idx < len(taskData.Progress); idx++ {
  84. item := taskData.Progress[idx]
  85. if item.Key == key {
  86. if item.State == 1 {
  87. return true
  88. }
  89. break
  90. }
  91. }
  92. return false
  93. }
  94. func conditionCheck(role *Role, taskData *serverproto.TaskData, taskType serverproto.TaskType,
  95. conditionList []int32, count int32, bForce bool) int32 {
  96. switch taskType {
  97. //主角Base等级
  98. case serverproto.TaskType_Base_Level:
  99. targetNum := conditionList[1]
  100. baseLevel := role.GetRoleBase().GetRoleLevel()
  101. return changeTaskProgressSet(&taskData.Progress, baseLevel, int32(taskType), targetNum)
  102. //job等级
  103. case serverproto.TaskType_Job_Level:
  104. targetNum := conditionList[1]
  105. jobLevel := role.GetRoleBase().GetRoleJobLevel()
  106. return changeTaskProgressSet(&taskData.Progress, jobLevel, int32(taskType), targetNum)
  107. //todo...
  108. // 完成转职,对应转职阶段
  109. case serverproto.TaskType_Job_Stage:
  110. //任意N个伙伴等级达到X级
  111. case serverproto.TaskType_Hero_Level_Num:
  112. if len(conditionList) >= 3 {
  113. heroLevel := conditionList[1]
  114. targetNum := conditionList[2]
  115. heroNum := role.GetRoleHero().GetHeroLevelNum(heroLevel)
  116. return changeTaskProgressSet(&taskData.Progress, heroNum, int32(taskType), targetNum)
  117. }
  118. //N个伙伴战力达到指定数值
  119. case serverproto.TaskType_Hero_Power_Num:
  120. if len(conditionList) >= 3 {
  121. heroPower := conditionList[1]
  122. targetNum := conditionList[2]
  123. heroNum := role.GetRoleHero().GetHeroPowerNum(heroPower)
  124. return changeTaskProgressSet(&taskData.Progress, heroNum, int32(taskType), targetNum)
  125. }
  126. //任意N件装备精炼等级达到X级
  127. case serverproto.TaskType_Equip_Level_Num:
  128. if len(conditionList) >= 3 {
  129. equipLevel := conditionList[1]
  130. targetNum := conditionList[2]
  131. equipNum := role.GetRoleBase().GetEquipSlotLevelNum(equipLevel)
  132. return changeTaskProgressSet(&taskData.Progress, equipNum, int32(taskType), targetNum)
  133. }
  134. case serverproto.TaskType_Eve_Equip_Level_Role:
  135. if len(conditionList) >= 3 {
  136. equipLevel := conditionList[1]
  137. targetNum := conditionList[2]
  138. equipNum := role.GetRoleBase().GetEquipSlotLevelRoleCnt(equipLevel)
  139. return changeTaskProgressSet(&taskData.Progress, equipNum, int32(taskType), targetNum)
  140. }
  141. //通关指定关卡
  142. case serverproto.TaskType_Level_Battle_Count:
  143. passBattleId := conditionList[1]
  144. var targetNum int32 = 1
  145. if len(conditionList) >= 3 {
  146. targetNum = conditionList[2]
  147. }
  148. //todo...关卡通关次数会在battle结构中做记录
  149. passNum := role.GetRoleBattle().GetPassBattleIdNum(passBattleId)
  150. return changeTaskProgressSet(&taskData.Progress, passNum, int32(taskType), targetNum)
  151. // 总战力达到指定数值
  152. case serverproto.TaskType_Total_Power:
  153. targetNum := conditionList[1]
  154. //var totalPower = int32(role.GetRoleFightPower().TotalFightPower)
  155. var totalPower = int32(role.roleBattleAttr.curTotalFightPower)
  156. return changeTaskProgressSet(&taskData.Progress, totalPower, int32(taskType), targetNum)
  157. //主角全身装备精炼等级达到N
  158. case serverproto.TaskType_Role_Equip_Forge_Count:
  159. if len(conditionList) >= 3 {
  160. refineLevel := conditionList[1]
  161. targetNum := conditionList[2]
  162. levelNum := role.GetRoleBase().GetMainEquipSlotLevelNum(refineLevel)
  163. return changeTaskProgressSet(&taskData.Progress, levelNum, int32(taskType), targetNum)
  164. }
  165. //N个伙伴装备精炼等级达到X
  166. case serverproto.TaskType_Part_Equip_Forge_Count:
  167. if len(conditionList) >= 3 {
  168. refineLevel := conditionList[1]
  169. targetNum := conditionList[2]
  170. levelNum := role.GetRoleBase().GetPartnerEquipSlotLevelNum(refineLevel)
  171. return changeTaskProgressSet(&taskData.Progress, levelNum, int32(taskType), targetNum)
  172. }
  173. //获得N个数量的任意伙伴
  174. case serverproto.TaskType_Hero_Total_Num:
  175. targetNum := conditionList[1]
  176. totalHeroNum := role.GetRoleHero().GetHeroNum()
  177. return changeTaskProgressSet(&taskData.Progress, totalHeroNum, int32(taskType), targetNum)
  178. //指定伙伴达到指定等级 [23:伙伴ID:伙伴等级]
  179. case serverproto.TaskType_Hero_Id_Level:
  180. if len(conditionList) >= 3 {
  181. targetNum := conditionList[2]
  182. heroLevel := role.GetRoleHero().GetHeroByConfigId(conditionList[1]).BaseLevel
  183. return changeTaskProgressSet(&taskData.Progress, heroLevel, int32(taskType), targetNum)
  184. }
  185. case serverproto.TaskType_Climbing_Tower_Level:
  186. if len(conditionList) >= 2 {
  187. targetNum := conditionList[1]
  188. towerLevel := role.GetRoleTower().GetCurTower()
  189. return changeTaskProgressSet(&taskData.Progress, towerLevel, int32(taskType), targetNum)
  190. }
  191. //累计获得银币数量(累计)
  192. case serverproto.TaskType_Get_Silver_Count:
  193. if len(conditionList) >= 2 {
  194. targetNum := conditionList[1]
  195. curNum := role.GetRoleTask().totalAddZeny
  196. return changeTaskProgressSet(&taskData.Progress, int32(curNum), int32(taskType), targetNum)
  197. }
  198. //英灵殿胜利次数(累计,主线任务)
  199. case serverproto.TaskType_Arena_Battle_Win_Count_Accu:
  200. if len(conditionList) >= 2 {
  201. targetNum := conditionList[1]
  202. curNum := role.GetRoleArena().arenaInfo.RecordWinCount
  203. return changeTaskProgressSet(&taskData.Progress, int32(curNum), int32(taskType), targetNum)
  204. }
  205. //当前拥有的该品质的装备数量
  206. case serverproto.TaskType_Equip_Quality_Num:
  207. if len(conditionList) >= 3 {
  208. equipQuality := conditionList[1]
  209. targetNum := conditionList[2]
  210. curNum := role.GetRoleEquip().GetQualityEquipNum(equipQuality)
  211. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  212. }
  213. //当前拥有该品质的卡片数量
  214. case serverproto.TaskType_Card_Quality_Num:
  215. if len(conditionList) >= 3 {
  216. cardQuality := conditionList[1] //normal mini mvp
  217. targetNum := conditionList[2]
  218. curNum := role.GetRoleCard().GetQualityCardNum(cardQuality)
  219. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  220. }
  221. //当前拥有对应品质的宠物
  222. case serverproto.TaskType_Pet_Quality_Num:
  223. if len(conditionList) >= 3 {
  224. petQuality := conditionList[1] //normal mini mvp
  225. targetNum := conditionList[2]
  226. curNum := role.GetRolePet().GetQualityPetNum(petQuality)
  227. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  228. }
  229. //任务开启时能达到的最大排名,pvp排名
  230. case serverproto.TaskType_Arena_Rank_Level:
  231. if len(conditionList) >= 2 {
  232. targetNum := conditionList[1]
  233. //count表示排名
  234. curNum := count
  235. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  236. }
  237. //互相关注的好友数量
  238. case serverproto.TaskType_Friend_SubFan_Num:
  239. if len(conditionList) >= 2 {
  240. targetNum := conditionList[1]
  241. curNum := int32(len(role.GetRoleSocial().GetFriendList()))
  242. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  243. }
  244. //对应恶魔品质完成挑战次数
  245. case serverproto.TaskType_Evil_Battle_Count_Accu:
  246. if len(conditionList) >= 3 {
  247. evilQuality := conditionList[1] //normal mini mvp
  248. targetNum := conditionList[2]
  249. curNum := role.GetRoleBattle().GetQualityBossChallengeCount(evilQuality)
  250. //count表示品质
  251. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  252. }
  253. //英灵殿战斗次数累计
  254. case serverproto.TaskType_Arena_Battle_Start_Count_Accu:
  255. if len(conditionList) >= 2 {
  256. targetNum := conditionList[1]
  257. curNum := role.GetRoleArena().GetTotalChallengeCount()
  258. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  259. }
  260. //历史抽卡次数
  261. case serverproto.TaskType_Draw_Card_Num:
  262. if len(conditionList) >= 2 {
  263. targetNum := conditionList[1]
  264. curNum := role.GetRoleDraw().GetDrawCardNum()
  265. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  266. }
  267. //历史抽宠物次数
  268. case serverproto.TaskType_Draw_Pet_Num:
  269. if len(conditionList) >= 2 {
  270. targetNum := conditionList[1]
  271. curNum := role.GetRoleDraw().GetDrawPetNum()
  272. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  273. }
  274. //历史商店购买次数
  275. case serverproto.TaskType_Shop_Buy_Count:
  276. if len(conditionList) >= 2 {
  277. targetNum := conditionList[1]
  278. curNum := role.GetRoleShop().GetShopTotalBuyNum()
  279. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  280. }
  281. //历史拥有时装数量
  282. case serverproto.TaskType_Get_Suit_Count:
  283. if len(conditionList) >= 2 {
  284. targetNum := conditionList[1]
  285. curNum := role.GetRoleFashion().GetFashionCount()
  286. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  287. }
  288. //历史上在远征之门中通关任意副本
  289. case serverproto.TaskType_Expedition_Battle_Count:
  290. if len(conditionList) >= 2 {
  291. targetNum := conditionList[1]
  292. curNum := role.GetRoleBattle().GetExpeditionTotalFinishNum()
  293. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  294. }
  295. case serverproto.TaskType_Eve_Expedition_Battle_Type:
  296. if len(conditionList) >= 2 {
  297. targetNum := conditionList[1]
  298. curNum := role.GetRoleBattle().GetExpeditionCur()
  299. return changeTaskProgressSet(&taskData.Progress, curNum, int32(taskType), targetNum)
  300. }
  301. case serverproto.TaskType_Eve_Pet_Id_Cnt:
  302. if len(conditionList) >= 3 {
  303. cfgId := conditionList[1]
  304. cnt := role.GetRolePet().GetPetNumByCfgId(cfgId)
  305. cnt += role.GetRolePet().GetBondPetCntByCfgId(cfgId)
  306. return changeTaskProgressSet(&taskData.Progress, cnt, int32(taskType), conditionList[2])
  307. }
  308. case serverproto.TaskType_Eve_Arean_Dan:
  309. if len(conditionList) >= 2 {
  310. lvl := conditionList[1]
  311. curLvl := role.roleArena.scoreLevel
  312. //// 客户端要求 服务器来处理
  313. if curLvl >= 10000 {
  314. curLvl -= 10000
  315. }
  316. lvl -= 10000
  317. return changeTaskProgressSet(&taskData.Progress, curLvl, int32(taskType), lvl)
  318. }
  319. case serverproto.TaskType_Eve_Pet_Battle_Quality_cnt:
  320. if len(conditionList) >= 3 {
  321. petCnt := conditionList[1]
  322. quality := conditionList[2]
  323. curPetCnt := role.GetRolePet().GetPetBattleCntByQuality(quality)
  324. return changeTaskProgressSet(&taskData.Progress, curPetCnt, int32(taskType), petCnt)
  325. }
  326. case serverproto.TaskType_Eve_Fight_value:
  327. roleBase := role.GetRoleBase()
  328. if count > 0 && roleBase != nil && roleBase.RoleData() != nil {
  329. startFight := uint64(0)
  330. for _, progress := range taskData.Progress {
  331. if progress.Key != int32(serverproto.TaskType_Eve_Fight_value) {
  332. continue
  333. }
  334. startFight = uint64(progress.Total)
  335. }
  336. var totalPower = roleBase.RoleData().FightPower - startFight
  337. if totalPower < 0 {
  338. totalPower = 0
  339. }
  340. return changeTaskProgressSet(&taskData.Progress, int32(totalPower), int32(taskType), conditionList[1])
  341. }
  342. case serverproto.TaskType_Eve_Item_Count:
  343. if len(conditionList) >= 3 {
  344. id := conditionList[1]
  345. cnt := conditionList[2]
  346. if count <= 0 || count == id {
  347. num := role.GetRoleBag().getItemNum(id)
  348. return changeTaskProgressSet(&taskData.Progress, int32(num), int32(taskType), cnt)
  349. }
  350. }
  351. case serverproto.TaskType_Eve_Head_Icon_Cont:
  352. if len(conditionList) >= 2 {
  353. count := conditionList[1]
  354. curCont := role.GetRoleBase().GetHeadFrameCount()
  355. return changeTaskProgressSet(&taskData.Progress, curCont, int32(taskType), count)
  356. }
  357. case serverproto.TaskType_Eve_Skill_Advance_Num:
  358. if len(conditionList) >= 2 {
  359. Lvl := conditionList[1]
  360. curLvl := role.GetRoleSkill().GetAllHeroSkillAdvanceNum()
  361. return changeTaskProgressSet(&taskData.Progress, curLvl, int32(taskType), Lvl)
  362. }
  363. case serverproto.TaskType_Eve_Five_Artifact_Activate:
  364. if len(conditionList) >= 3 {
  365. star := conditionList[1]
  366. cnt := conditionList[2]
  367. curCnt := role.roleSkillEquip.GetSkillEquipCntByStar(star)
  368. return changeTaskProgressSet(&taskData.Progress, curCnt, int32(taskType), cnt)
  369. }
  370. case serverproto.TaskType_Eve_Evil_Fight_Lvl:
  371. if len(conditionList) >= 2 {
  372. Lvl := conditionList[1]
  373. curLvl := role.GetRoleBattle().GetEvilLvl()
  374. return changeTaskProgressSet(&taskData.Progress, curLvl, int32(taskType), Lvl)
  375. }
  376. case serverproto.TaskType_Eve_Login_Day:
  377. fallthrough
  378. case serverproto.TaskType_Eve_Use_Quick_Battle:
  379. fallthrough
  380. case serverproto.TaskType_Eve_DaoChange_Win:
  381. fallthrough
  382. case serverproto.TaskType_Eve_Month_Card_High:
  383. fallthrough
  384. case serverproto.TaskType_Eve_Month_Card:
  385. fallthrough
  386. case serverproto.TaskType_Eve_Arean_First: // 赛季冠军
  387. if len(conditionList) >= 2 {
  388. cnt := role.roleTask.GetTypeCnt(int32(taskType))
  389. return changeTaskProgressEqual(&taskData.Progress, cnt, int32(taskType), conditionList[1])
  390. }
  391. case serverproto.TaskType_Eve_Battle_Role_Quality:
  392. if len(conditionList) >= 3 {
  393. equipQuality := conditionList[1]
  394. cnt := conditionList[2]
  395. curcnt := role.GetRoleHero().GetQualityEquipNumByBattle(equipQuality)
  396. return changeTaskProgressSet(&taskData.Progress, curcnt, int32(taskType), cnt)
  397. }
  398. case serverproto.TaskType_Eve_Keepsake_lvl_All:
  399. lvl := conditionList[1]
  400. meet := role.roleKeepSake.IsAllMeetLvl(lvl)
  401. ty := int32(taskType)
  402. if len(taskData.Progress) <= 0 {
  403. addProgress := &serverproto.TaskProgressType{
  404. Key: ty,
  405. }
  406. if meet {
  407. addProgress.State = TASK_REWARD_STATE_COMPLETED
  408. }
  409. taskData.Progress = append(taskData.Progress, addProgress)
  410. }
  411. for _, data := range taskData.Progress {
  412. if data.Key != ty {
  413. continue
  414. }
  415. //已经完成
  416. if data.State == TASK_REWARD_STATE_COMPLETED {
  417. return TASK_CONDITION_OK
  418. }
  419. if !meet {
  420. continue
  421. }
  422. data.State = TASK_REWARD_STATE_COMPLETED
  423. return TASK_CONDITION_OK
  424. }
  425. case serverproto.TaskType_Eve_Merge_Card: // 合成指定卡片
  426. fallthrough
  427. case serverproto.TaskType_Eve_Merge_Equip: // 合成指定装备ID
  428. targetNum := conditionList[1]
  429. ty := int32(taskType)
  430. if len(taskData.Progress) <= 0 {
  431. addProgress := &serverproto.TaskProgressType{
  432. Key: ty,
  433. }
  434. taskData.Progress = append(taskData.Progress, addProgress)
  435. }
  436. for _, data := range taskData.Progress {
  437. if data.Key != ty {
  438. continue
  439. }
  440. //已经完成
  441. if data.State == TASK_REWARD_STATE_COMPLETED {
  442. return TASK_CONDITION_OK
  443. }
  444. if count != targetNum {
  445. continue
  446. }
  447. data.Value++
  448. data.State = TASK_REWARD_STATE_COMPLETED
  449. return TASK_CONDITION_OK
  450. }
  451. return TASK_CONDITION_NONE
  452. /////////////////////////记录次数操作
  453. case serverproto.TaskType_Get_Card_Count: //获得卡片数量
  454. fallthrough
  455. case serverproto.TaskType_Silver_Consumption_Count: //银币消耗
  456. fallthrough
  457. case serverproto.TaskType_Climbing_Tower_Count: //爬塔次数
  458. fallthrough
  459. case serverproto.TaskType_Gold_Consumption_Count: //金币消耗
  460. fallthrough
  461. case serverproto.TaskType_Arena_Battle_Win_Count: //英灵殿胜利次数
  462. fallthrough
  463. case serverproto.TaskType_Arena_Battle_Start_Count: //英灵殿战斗次数
  464. fallthrough
  465. case serverproto.TaskType_Card_Composed_Count: //卡片合成
  466. fallthrough
  467. case serverproto.TaskType_Card_Reset_Count: //卡片重置
  468. fallthrough
  469. case serverproto.TaskType_Evil_Fight_Count: //恶魔协会战斗次数
  470. fallthrough
  471. case serverproto.TaskType_Get_Online_Box_Count: //开宝箱次数
  472. fallthrough
  473. case serverproto.TaskType_Hero_LevelUp_Count: //升级任意伙伴N次
  474. fallthrough
  475. case serverproto.TaskType_Equip_Level_Count: //精炼任意装备N次
  476. fallthrough
  477. case serverproto.TaskType_Equip_Forge_Count: //合成任意装备N次
  478. fallthrough
  479. case serverproto.TaskType_Battle_Boss_Count: //boss战次数
  480. fallthrough
  481. case serverproto.TaskType_Role_Quick_Battle_Count: //快速战斗次数
  482. fallthrough
  483. case serverproto.TaskType_Battle_Boss_Reward_Count: //挑战boss成功次数
  484. fallthrough
  485. case serverproto.TaskType_Skill_Slot_Level_Up_Count: //升级任意技能槽N次
  486. fallthrough
  487. case serverproto.TaskType_Expedition_CallHelp_Count: //远征之门发起救助操作次数
  488. fallthrough
  489. case serverproto.TaskType_Friend_Invite_Count: //完成发起好友邀请次数
  490. fallthrough
  491. case serverproto.TaskType_Guild_Join_Count: //加入公会次数
  492. fallthrough
  493. case serverproto.TaskType_Chat_Message_Count: //主线任务中新增在聊天频道中发一句话的任务需求
  494. fallthrough
  495. case serverproto.TaskType_Expedition_Challenge_Count: //远征之门使用消耗挑战次数(任务开启时记录)
  496. fallthrough
  497. case serverproto.TaskType_Guild_Boss_Normal_Count: //公会普通boss挑战次数(任务开启)
  498. fallthrough
  499. case serverproto.TaskType_Eve_Card_Num:
  500. fallthrough
  501. case serverproto.TaskType_Eve_Pet_Num:
  502. fallthrough
  503. case serverproto.TaskType_Recharge_Num:
  504. fallthrough
  505. case serverproto.TaskType_Eve_Arean_Buy:
  506. fallthrough
  507. case serverproto.TaskType_Eve_Arean_First_Cnt:
  508. fallthrough
  509. case serverproto.TaskType_Eve_Recharge_Value:
  510. fallthrough
  511. case serverproto.TaskType_Eve_DaoChange_Win_Add:
  512. fallthrough
  513. case serverproto.TaskType_World_Boss_Challenge_Count: //公会普通boss挑战次数(任务开启)
  514. fallthrough
  515. case serverproto.TaskType_BT_ZhenJiaRecharge: // 真/假每日累计充值活动
  516. fallthrough
  517. case serverproto.TaskType_BT_ROCoinRecharge: // bt RO币累计活动
  518. targetNum := conditionList[1]
  519. if count <= 0 && !bForce {
  520. return TASK_CONDITION_NONE
  521. }
  522. return changeTaskProgressAdd(&taskData.Progress, count, int32(taskType), targetNum)
  523. case serverproto.TaskType_Eve_Accu_count:
  524. evilQuality := conditionList[1] //normal mini mvp
  525. targetNum := conditionList[2]
  526. if evilQuality == count {
  527. return changeTaskProgressAdd(&taskData.Progress, 1, int32(taskType), targetNum)
  528. }
  529. }
  530. return TASK_CONDITION_NONE
  531. }
  532. //累计方式
  533. func changeTaskProgressAdd(progress *[]*serverproto.TaskProgressType, addCount, taskType, targetNum int32) int32 {
  534. bEdit := false
  535. for index, data := range *progress {
  536. if data.Key == taskType {
  537. //已经完成
  538. if data.State == TASK_REWARD_STATE_COMPLETED {
  539. return TASK_CONDITION_OK
  540. }
  541. (*progress)[index].Value += addCount
  542. if (*progress)[index].Value >= targetNum {
  543. (*progress)[index].Value = targetNum
  544. (*progress)[index].State = TASK_REWARD_STATE_COMPLETED
  545. return TASK_CONDITION_OK
  546. }
  547. bEdit = true
  548. break
  549. }
  550. }
  551. if !bEdit {
  552. addProgress := &serverproto.TaskProgressType{
  553. Key: taskType,
  554. Value: addCount,
  555. }
  556. *progress = append(*progress, addProgress)
  557. if addCount >= targetNum {
  558. addProgress.Value = targetNum
  559. addProgress.State = TASK_REWARD_STATE_COMPLETED
  560. return TASK_CONDITION_OK
  561. }
  562. }
  563. return TASK_CONDITION_CHANGE
  564. }
  565. //数值方式(目标个数)
  566. func changeTaskProgressSet(progress *[]*serverproto.TaskProgressType, setCount, taskType, targetNum int32) int32 {
  567. bEdit := false
  568. for index, data := range *progress {
  569. if data.Key == taskType {
  570. //已经完成
  571. if data.State == TASK_REWARD_STATE_COMPLETED {
  572. return TASK_CONDITION_OK
  573. }
  574. if setCount >= (*progress)[index].Value {
  575. (*progress)[index].Value = setCount
  576. if (*progress)[index].Value >= targetNum {
  577. (*progress)[index].Value = targetNum
  578. (*progress)[index].State = TASK_REWARD_STATE_COMPLETED
  579. return TASK_CONDITION_OK
  580. }
  581. bEdit = true
  582. } else {
  583. return TASK_CONDITION_NONE
  584. }
  585. //if (*progress)[index].Value >= setCount {
  586. // (*progress)[index].State = TASK_REWARD_STATE_COMPLETED
  587. // return TASK_CONDITION_OK
  588. //} else {
  589. // if setCount > (*progress)[index].Value {
  590. // (*progress)[index].Value = setCount
  591. // if (*progress)[index].Value >= targetNum {
  592. // (*progress)[index].Value = targetNum
  593. // (*progress)[index].State = TASK_REWARD_STATE_COMPLETED
  594. // return TASK_CONDITION_OK
  595. // }
  596. // bEdit = true
  597. // } else {
  598. // return TASK_CONDITION_NONE
  599. // }
  600. //}
  601. break
  602. }
  603. }
  604. if !bEdit {
  605. addProgress := &serverproto.TaskProgressType{
  606. Key: taskType,
  607. Value: setCount,
  608. }
  609. *progress = append(*progress, addProgress)
  610. if setCount >= targetNum {
  611. addProgress.Value = targetNum
  612. addProgress.State = TASK_REWARD_STATE_COMPLETED
  613. return TASK_CONDITION_OK
  614. }
  615. }
  616. return TASK_CONDITION_CHANGE
  617. }
  618. //直接赋值 注意该函数的区别
  619. func changeTaskProgressEqual(progress *[]*serverproto.TaskProgressType, addCount, taskType, targetNum int32) int32 {
  620. bEdit := false
  621. for index, data := range *progress {
  622. if data.Key == taskType {
  623. //已经完成
  624. if data.State == TASK_REWARD_STATE_COMPLETED {
  625. return TASK_CONDITION_OK
  626. }
  627. (*progress)[index].Value = addCount
  628. if (*progress)[index].Value >= targetNum {
  629. (*progress)[index].Value = targetNum
  630. (*progress)[index].State = TASK_REWARD_STATE_COMPLETED
  631. return TASK_CONDITION_OK
  632. }
  633. bEdit = true
  634. break
  635. }
  636. }
  637. if !bEdit {
  638. addProgress := &serverproto.TaskProgressType{
  639. Key: taskType,
  640. Value: addCount,
  641. }
  642. *progress = append(*progress, addProgress)
  643. if addCount >= targetNum {
  644. addProgress.Value = targetNum
  645. addProgress.State = TASK_REWARD_STATE_COMPLETED
  646. return TASK_CONDITION_OK
  647. }
  648. }
  649. return TASK_CONDITION_CHANGE
  650. }
  651. func GetNextTaskInitCount(role *Role, taskEnum int32) int32 {
  652. if role == nil {
  653. return 0
  654. }
  655. switch serverproto.TaskType(taskEnum) {
  656. case serverproto.TaskType_Get_Card_Count:
  657. return role.GetRoleCard().GetCardCount()
  658. case serverproto.TaskType_Guild_Join_Count:
  659. if role.GetRoleGuildId() > 0 {
  660. return 1
  661. }
  662. }
  663. return 0
  664. }