task_manager.go 25 KB

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