role_rush.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. package model
  2. import (
  3. "rocommon/util"
  4. "roserver/baseserver/model"
  5. "roserver/serverproto"
  6. )
  7. type RoleRush struct {
  8. SaveObject
  9. rushSkill *serverproto.RushSkill
  10. }
  11. func newRoleRush(r *Role) *RoleRush {
  12. roleCommon := &RoleRush{
  13. SaveObject: SaveObject{
  14. role: r,
  15. },
  16. }
  17. return roleCommon
  18. }
  19. func (this *RoleRush) Load(msg interface{}) bool {
  20. proRole := msg.(*serverproto.Role)
  21. if proRole != nil && proRole.RoleRush != nil {
  22. this.rushSkill = proRole.RoleRush.RushSkill
  23. }
  24. bChanged := false
  25. if this.rushSkill == nil {
  26. this.rushSkill = &serverproto.RushSkill{}
  27. bChanged = true
  28. }
  29. if bChanged == true {
  30. this.SetDirty(true)
  31. }
  32. return true
  33. }
  34. func (this *RoleRush) Save() {
  35. this.SetDirty(false)
  36. util.DebugF("uid=%v RoleDraw save...", this.role.GetUUid())
  37. saveMsg := &serverproto.SSRoleRushDataSaveReq{
  38. RoleRush: &serverproto.RoleRush{},
  39. }
  40. saveMsg.RoleRush.RushSkill = this.rushSkill
  41. this.role.SendDb(saveMsg)
  42. }
  43. func (this *RoleRush) CopyData(draw *serverproto.RoleDraw) {
  44. }
  45. func (this *RoleRush) OnlineGetRushReward(ackMsg *serverproto.SSGetRushRankRewardAck) {
  46. if ackMsg == nil {
  47. return
  48. }
  49. for _, reward := range ackMsg.RewardList {
  50. for _, data := range reward.RankReward {
  51. //没有奖励,返回
  52. if len(data.RewardList) <= 0 {
  53. continue
  54. }
  55. bRet := serverproto.ErrorCode_ERROR_OK
  56. if reward.RushType == model.Rush_Type_Tower {
  57. bRet = this.role.GetRoleTower().CheckRankReward(reward.FinishRound)
  58. } else if reward.RushType == model.Rush_Type_Arena {
  59. bRet = this.role.GetRoleArena().CheckRankReward(reward.FinishRound)
  60. } else if reward.RushType == model.Rush_Type_Map {
  61. bRet = this.role.GetRoleBattle().CheckRankReward(reward.FinishRound)
  62. } else if reward.RushType == model.Rush_Type_Pet {
  63. bRet = this.role.GetRolePet().CheckRankReward(reward.FinishRound)
  64. } else {
  65. bRet = this.CheckRushRankReward(reward.RushType, reward.FinishRound)
  66. }
  67. if bRet != serverproto.ErrorCode_ERROR_OK {
  68. continue
  69. }
  70. mailCfgId := model.GlobalMailIdRushTower
  71. mailType := int32(serverproto.MailType_MailType_RushTower)
  72. if reward.RushType == model.Rush_Type_Arena {
  73. mailCfgId = model.GlobalMailIdRushArena
  74. mailType = int32(serverproto.MailType_MailType_RushArena)
  75. } else if reward.RushType == model.Rush_Type_Map {
  76. mailCfgId = model.GlobalMailIdRushMap
  77. mailType = int32(serverproto.MailType_MailType_RushMap)
  78. } else if reward.RushType == model.Rush_Type_Pet {
  79. mailCfgId = model.GlobalMailRushPetRankReward
  80. mailType = int32(serverproto.MailType_MailType_RushPet)
  81. } else if reward.RushType == model.Rush_Type_Skill {
  82. mailCfgId = model.GlobalMailRushSkillRankReward
  83. mailType = int32(serverproto.MailType_MailType_RushSkill)
  84. }
  85. this.role.AddMail1(mailCfgId, mailType,
  86. data.RewardList, data.MailParamList, "", "")
  87. if reward.RushType == model.Rush_Type_Tower {
  88. this.role.GetRoleTower().SetRankReward(reward.FinishRound)
  89. } else if reward.RushType == model.Rush_Type_Arena {
  90. this.role.GetRoleArena().SetRankReward(reward.FinishRound)
  91. } else if reward.RushType == model.Rush_Type_Map {
  92. this.role.GetRoleBattle().SetRankReward(reward.FinishRound)
  93. } else if reward.RushType == model.Rush_Type_Pet {
  94. this.role.GetRolePet().SetRankReward(reward.FinishRound)
  95. } else {
  96. this.SetRushRankReward(reward.RushType, reward.FinishRound)
  97. }
  98. }
  99. }
  100. }
  101. //===================================================== 技能冲榜功能 =====================================================
  102. func (this *RoleRush) OnlineRush() {
  103. rewardReq := &serverproto.SSGetRushRankRewardReq{
  104. Uid: this.role.GetUUid(),
  105. }
  106. if this.rushSkill != nil {
  107. rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{
  108. Key: model.Rush_Type_Skill,
  109. Value: this.rushSkill.RankReward,
  110. })
  111. }
  112. if this.role.GetRolePet() != nil && this.role.GetRolePet().rushPet != nil {
  113. rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{
  114. Key: model.Rush_Type_Pet,
  115. Value: this.role.GetRolePet().rushPet.RankReward,
  116. })
  117. }
  118. if this.role.GetRoleTower() != nil {
  119. rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{
  120. Key: model.Rush_Type_Tower,
  121. Value: this.role.GetRoleTower().RankRewardRound,
  122. })
  123. }
  124. if this.role.GetRoleBattle() != nil && this.role.GetRoleBattle().rushMap != nil {
  125. rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{
  126. Key: model.Rush_Type_Map,
  127. Value: this.role.GetRoleBattle().rushMap.RankReward,
  128. })
  129. }
  130. if this.role.GetRoleArena() != nil && this.role.GetRoleArena().arenaInfo.RushArena != nil && this.role.GetRoleArena().arenaInfo != nil {
  131. rewardReq.RushData = append(rewardReq.RushData, &serverproto.KeyValueType{
  132. Key: model.Rush_Type_Arena,
  133. Value: this.role.GetRoleArena().arenaInfo.RushArena.RankReward,
  134. })
  135. }
  136. this.role.SendRank(rewardReq)
  137. }
  138. func (this *RoleRush) OnlineGetRushBaseReward(rushType int32, rewardRound int32) {
  139. if rushType == model.Rush_Type_Skill {
  140. this.OnlineGetRushSkillBaseReward(rewardRound)
  141. }
  142. }
  143. func (this *RoleRush) OnlineGetRushSkillBaseReward(rewardRound int32) {
  144. if this.rushSkill == nil || rewardRound <= 0 {
  145. return
  146. }
  147. if this.rushSkill.ScoreRewardFlag < rewardRound {
  148. var addItemList = map[int32]int32{}
  149. model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList)
  150. if len(addItemList) > 0 {
  151. this.role.AddMail(model.GlobalMailRushSkillBaseReward, serverproto.MailType_MailType_RushSkill,
  152. addItemList, []int32{int32(this.rushSkill.TotalScore)}, "", "")
  153. }
  154. this.rushSkill.ScoreRewardFlag = rewardRound
  155. this.rushSkill.TotalScore = 0
  156. this.SetDirty(true)
  157. } else {
  158. this.rushSkill.TotalScore = 0
  159. this.SetDirty(true)
  160. }
  161. }
  162. func (this *RoleRush) OnlineProcess() {
  163. if this.rushSkill == nil {
  164. return
  165. }
  166. //上线处理下,有可能这个人没有参加过。
  167. this.OnRushSkillScoreChange()
  168. // 上线请求下冲榜是否有历史奖励可以领取
  169. if this.rushSkill != nil {
  170. if this.rushSkill.RushRound != 0 && this.rushSkill.RushRound > this.rushSkill.ScoreRewardFlag {
  171. reqMsg := &serverproto.SSGetRushBaseRewardReq{}
  172. reqMsg.Uid = this.role.GetUUid()
  173. reqMsg.RushType = model.Rush_Type_Skill
  174. reqMsg.RushRound = this.rushSkill.RushRound
  175. this.role.SendRank(reqMsg)
  176. }
  177. }
  178. this.OnlineRush()
  179. }
  180. func (this *RoleRush) OnRushDataChange(rushType int32) {
  181. reqMsg := &serverproto.SSRushDataChangeReq{}
  182. reqMsg.Uid = this.role.GetUUid()
  183. reqMsg.RushType = rushType
  184. this.role.SendRank(reqMsg)
  185. }
  186. //发送到rank服务器验证
  187. func (this *RoleRush) OnRushSkillScoreChange() {
  188. reqMsg := &serverproto.SSRushDataChangeReq{}
  189. reqMsg.Uid = this.role.GetUUid()
  190. reqMsg.RushType = model.Rush_Type_Skill
  191. this.role.SendRank(reqMsg)
  192. }
  193. func (this *RoleRush) AddRushScore(rushType int32, curRound int32) {
  194. if rushType == model.Rush_Type_Skill {
  195. this.AddRushSkillScore(curRound)
  196. return
  197. }
  198. }
  199. func (this *RoleRush) AddRushSkillScore(curRound int32) {
  200. if this.rushSkill == nil {
  201. this.rushSkill = &serverproto.RushSkill{}
  202. this.SetDirty(true)
  203. }
  204. if curRound == 0 {
  205. return
  206. }
  207. if curRound != this.rushSkill.RushRound {
  208. this.rushSkill.RushRound = curRound
  209. this.rushSkill.TotalScore = 0
  210. }
  211. //发送到rank
  212. reqMsg := &serverproto.SSRushSkillInfoChangeNtf{}
  213. reqMsg.TotalScore = this.role.GetRoleBase().roleBase.RepressSkillPvpVal
  214. if reqMsg.TotalScore <= 0 {
  215. return
  216. }
  217. if uint32(reqMsg.TotalScore) >= this.rushSkill.TotalScore {
  218. this.rushSkill.TotalScore = uint32(reqMsg.TotalScore)
  219. reqMsg.Uid = this.role.GetUUid()
  220. this.role.SendRank(reqMsg)
  221. }
  222. this.SetDirty(true)
  223. }
  224. func (this *RoleRush) GetBaseReward(ackMsg *serverproto.SCRushActivityRewardAck, rushType int32, rushRound int32) serverproto.ErrorCode {
  225. if rushType == model.Rush_Type_Skill {
  226. return this.GetBaseScoreReward(ackMsg, rushRound)
  227. }
  228. return serverproto.ErrorCode_ERROR_FAIL
  229. }
  230. func (this *RoleRush) GetBaseScoreReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode {
  231. if ackMsg == nil {
  232. return serverproto.ErrorCode_ERROR_FAIL
  233. }
  234. if this.rushSkill == nil {
  235. this.rushSkill = &serverproto.RushSkill{}
  236. this.SetDirty(true)
  237. }
  238. if this.rushSkill.ScoreRewardFlag >= rushRound {
  239. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  240. }
  241. var addItemList = map[int32]int32{}
  242. model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList)
  243. if len(addItemList) <= 0 {
  244. return serverproto.ErrorCode_ERROR_FAIL
  245. }
  246. for key, value := range addItemList {
  247. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  248. Key: key,
  249. Value: value,
  250. })
  251. }
  252. this.role.AddItemList(addItemList, AddFrom_RushSkill, true)
  253. this.rushSkill.ScoreRewardFlag = rushRound
  254. this.SetDirty(true)
  255. return serverproto.ErrorCode_ERROR_OK
  256. }
  257. func (this *RoleRush) GetRushRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
  258. if ssAck.RushType == model.Rush_Type_Skill {
  259. return this.GetRushSkillRankReward(ssAck)
  260. }
  261. return serverproto.ErrorCode_ERROR_FAIL
  262. }
  263. func (this *RoleRush) GetRushSkillRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
  264. if ssAck == nil {
  265. return serverproto.ErrorCode_ERROR_FAIL
  266. }
  267. if this.rushSkill == nil {
  268. this.rushSkill = &serverproto.RushSkill{}
  269. this.SetDirty(true)
  270. }
  271. if this.rushSkill.RankReward >= ssAck.RushRound {
  272. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  273. }
  274. var addItemList = map[int32]int32{}
  275. for _, data := range ssAck.ItemList {
  276. addItemList[data.Key] += data.Value
  277. }
  278. this.role.AddItemList(addItemList, AddFrom_RushSkill, true)
  279. this.rushSkill.RankReward = ssAck.RushRound
  280. this.SetDirty(true)
  281. return serverproto.ErrorCode_ERROR_OK
  282. }
  283. func (this *RoleRush) GetRushInfo(ackMsg *serverproto.SCRushActivityAck, curRound int32) {
  284. if ackMsg.RushType == model.Rush_Type_Skill {
  285. this.GetRushSkillInfo(ackMsg, curRound)
  286. return
  287. }
  288. }
  289. func (this *RoleRush) GetRushSkillInfo(ackMsg *serverproto.SCRushActivityAck, curRound int32) {
  290. if ackMsg == nil {
  291. return
  292. }
  293. if this.rushSkill == nil {
  294. this.rushSkill = &serverproto.RushSkill{}
  295. this.SetDirty(true)
  296. }
  297. // ackMsg.SelfScore = this.rushSkill.TotalScore
  298. ackMsg.RankReward = false
  299. if this.rushSkill.RankReward == curRound {
  300. ackMsg.RankReward = true
  301. }
  302. ackMsg.ChallengReward = false
  303. if this.rushSkill.ScoreRewardFlag >= curRound {
  304. ackMsg.ChallengReward = true
  305. }
  306. }
  307. func (this *RoleRush) CheckRushRankReward(rushType int32, finishRound int32) serverproto.ErrorCode {
  308. if model.Rush_Type_Skill == rushType {
  309. return this.CheckSkillRankReward(finishRound)
  310. }
  311. return serverproto.ErrorCode_ERROR_FAIL
  312. }
  313. func (this *RoleRush) CheckSkillRankReward(finishRound int32) serverproto.ErrorCode {
  314. if this.rushSkill == nil {
  315. this.rushSkill = &serverproto.RushSkill{}
  316. this.SetDirty(true)
  317. }
  318. if this.rushSkill.RankReward >= finishRound {
  319. return serverproto.ErrorCode_ERROR_FAIL
  320. }
  321. return serverproto.ErrorCode_ERROR_OK
  322. }
  323. func (this *RoleRush) SetRushRankReward(rushType int32, finishRound int32) {
  324. if model.Rush_Type_Skill == rushType {
  325. this.SetRankReward(finishRound)
  326. }
  327. }
  328. func (this *RoleRush) SetRankReward(finishRound int32) {
  329. if this.rushSkill == nil {
  330. this.rushSkill = &serverproto.RushSkill{}
  331. this.SetDirty(true)
  332. }
  333. this.rushSkill.RankReward = finishRound
  334. this.SetDirty(true)
  335. }
  336. func (this *RoleRush) GetFightCountMailReward(rushRound int32) {
  337. if this.rushSkill == nil {
  338. this.rushSkill = &serverproto.RushSkill{}
  339. this.SetDirty(true)
  340. }
  341. if this.rushSkill.ScoreRewardFlag < rushRound {
  342. var addItemList = map[int32]int32{}
  343. model.GetRushActivityBaseReward(this.rushSkill.RushRound, model.Rush_Type_Skill, int32(this.rushSkill.TotalScore), addItemList)
  344. if len(addItemList) > 0 {
  345. this.role.AddMail(model.GlobalMailRushSkillBaseReward, serverproto.MailType_MailType_RushSkill,
  346. addItemList, []int32{int32(this.rushSkill.TotalScore)}, "", "")
  347. }
  348. this.rushSkill.ScoreRewardFlag = rushRound
  349. this.rushSkill.TotalScore = 0
  350. this.SetDirty(true)
  351. }
  352. }