task_manager.go 24 KB

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