role_map.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. package model
  2. import (
  3. "math/rand"
  4. "rocommon/util"
  5. "roserver/baseserver/model"
  6. "roserver/serverproto"
  7. )
  8. type RoleMapOuter interface {
  9. //PlayerEnterMap(msg *serverproto.CSPlayerEnterMapReq)
  10. //PlayerLeave(pos *serverproto.Position)
  11. //PlayerMove(msg *serverproto.CSPlayerMoveReq)
  12. //
  13. ////map role info
  14. ////获取玩家地图展示信息
  15. //GetPlayerMapShowInfo(info *serverproto.PlayerShowInfo)
  16. //MapDoAction(actionId int32, pos *serverproto.Position) serverproto.ErrorCode
  17. MapPlayerChallengeWorldBoss(challengeBossUid uint64, summonIdx int32, aoiLineStr string)
  18. DoMapPlayerChallengeWorldBoss(challengeBossUid int32)
  19. MapWorldBossHp(damageHp int32)
  20. GetWorldBossList()
  21. GenWorldBossRandReward(pointInfo *serverproto.WorldBossRandPointInfo) serverproto.ErrorCode
  22. GetWorldBossListAckFilter(ackMsg *serverproto.SCPlayerWorldBossListAck)
  23. }
  24. ///MAP AOI相关
  25. //func (this *Role) PlayerEnterMap(msg *serverproto.CSPlayerEnterMapReq) {
  26. // if this.roleMap != nil && this.GetState() == ROLE_STATE_ONLINE {
  27. // //没有处理离开操作,重新进入的方式,先离开,再进入
  28. // if this.AoiNode() != "" {
  29. // this.roleMap.PlayerLeave(nil)
  30. // }
  31. // this.roleMap.PlayerEnterMap(msg)
  32. // }
  33. //}
  34. //func (this *Role) PlayerLeave(pos *serverproto.Position) {
  35. // if this.roleMap != nil {
  36. // this.roleMap.PlayerLeave(pos)
  37. // }
  38. //}
  39. //func (this *Role) PlayerMove(pos *serverproto.CSPlayerMoveReq) {
  40. // if this.roleMap != nil {
  41. // this.roleMap.PlayerMove(pos)
  42. // }
  43. //}
  44. //func (this *Role) GetPlayerMapShowInfo(info *serverproto.PlayerShowInfo) {
  45. // if this.roleMap != nil {
  46. // if this.AoiNode() != "" {
  47. // this.roleMap.GetPlayerMapShowInfo(info)
  48. // }
  49. // }
  50. //}
  51. //func (this *Role) MapDoAction(actionId int32, pos *serverproto.Position) serverproto.ErrorCode {
  52. // if this.roleMap != nil {
  53. // return this.roleMap.MapDoAction(actionId, pos)
  54. // }
  55. // return serverproto.ErrorCode_ERROR_FAIL
  56. //}
  57. func (this *Role) MapPlayerChallengeWorldBoss(challengeBossUid uint64, summonIdx int32, aoiLineStr string) {
  58. if this.roleMap != nil {
  59. this.roleMap.MapPlayerChallengeWorldBoss(challengeBossUid, summonIdx, aoiLineStr)
  60. }
  61. }
  62. func (this *Role) DoMapPlayerChallengeWorldBoss(challengeBossUid int32) {
  63. if this.roleMap != nil {
  64. this.roleMap.DoMapPlayerChallengeWorldBoss(challengeBossUid)
  65. }
  66. }
  67. func (this *Role) MapWorldBossHp(damageHp int32) {
  68. if this.roleMap != nil {
  69. this.roleMap.MapWorldBossHp(damageHp)
  70. }
  71. }
  72. func (this *Role) GetWorldBossList() {
  73. if this.roleMap != nil {
  74. this.roleMap.GetWorldBossList()
  75. }
  76. }
  77. func (this *Role) GenWorldBossRandReward(pointInfo *serverproto.WorldBossRandPointInfo) serverproto.ErrorCode {
  78. if this.roleMap != nil {
  79. return this.roleMap.GenWorldBossRandReward(pointInfo)
  80. }
  81. return serverproto.ErrorCode_ERROR_FAIL
  82. }
  83. func (this *Role) GetWorldBossListAckFilter(ackMsg *serverproto.SCPlayerWorldBossListAck) {
  84. if this.roleMap != nil {
  85. this.roleMap.GetWorldBossListAckFilter(ackMsg)
  86. }
  87. }
  88. ////////////////////////////////////////////////////
  89. type RoleMap struct {
  90. SaveObject
  91. roleMap *serverproto.RoleMap
  92. targetPos serverproto.Position
  93. ChallengeBossId uint64
  94. challengeBossList map[int32]int32 //[挑战过的bossid,次数]
  95. curLineNum int32 //当前选择并成功进入的地图线路
  96. }
  97. var zeroPosition *serverproto.Position
  98. func newRoleMap(r *Role) *RoleMap {
  99. roleMap := &RoleMap{
  100. SaveObject: SaveObject{
  101. role: r,
  102. },
  103. challengeBossList: map[int32]int32{},
  104. }
  105. zeroPosition = &serverproto.Position{}
  106. return roleMap
  107. }
  108. func (this *RoleMap) Load(msg interface{}) bool {
  109. proRole := msg.(*serverproto.Role)
  110. if proRole.RoleMap == nil {
  111. this.roleMap = &serverproto.RoleMap{
  112. Pos: &serverproto.Position{},
  113. }
  114. } else {
  115. this.roleMap = proRole.RoleMap
  116. if this.roleMap.Pos != nil {
  117. this.targetPos = *this.roleMap.Pos
  118. }
  119. for idx := 0; idx < len(this.roleMap.WorldBossChallengeList); idx++ {
  120. tmpId := this.roleMap.WorldBossChallengeList[idx]
  121. this.challengeBossList[tmpId] = tmpId
  122. }
  123. }
  124. return true
  125. }
  126. func (this *RoleMap) Save() {
  127. this.SetDirty(false)
  128. util.InfoF("uid=%v RoleMap save...", this.role.GetUUid())
  129. saveMsg := &serverproto.SSMapDataSaveReq{
  130. RoleMap: &serverproto.RoleMap{
  131. MapType: this.roleMap.MapType,
  132. Pos: &serverproto.Position{},
  133. WorldBossCount: this.roleMap.WorldBossCount,
  134. },
  135. }
  136. saveMsg.RoleMap.WorldBossChallengeList = append(this.roleMap.WorldBossChallengeList)
  137. if this.roleMap.Pos != nil {
  138. *saveMsg.RoleMap.Pos = *this.roleMap.Pos
  139. }
  140. this.role.SendDb(saveMsg)
  141. }
  142. func (this *RoleMap) GetRole() *Role {
  143. return this.role
  144. }
  145. func (this *RoleMap) GetPosition() *serverproto.Position {
  146. return this.roleMap.Pos
  147. }
  148. func (this *RoleMap) GetMapType() int32 {
  149. return this.roleMap.MapType
  150. }
  151. func (this *RoleMap) DailyReset(notify bool) {
  152. this.roleMap.WorldBossCount = 0
  153. this.roleMap.WorldBossChallengeList = this.roleMap.WorldBossChallengeList[:0]
  154. this.challengeBossList = map[int32]int32{}
  155. this.SetDirty(true)
  156. if notify {
  157. this.dataChangeNtf()
  158. }
  159. }
  160. func (this *RoleMap) CopyData() *serverproto.RoleMap {
  161. return this.roleMap
  162. }
  163. func (this *RoleMap) dataChangeNtf() {
  164. ntfMsg := &serverproto.SCRoleMapChangeNtf{
  165. WorldBossCount: this.roleMap.WorldBossCount,
  166. WorldBossChallengeList: append(this.roleMap.WorldBossChallengeList),
  167. }
  168. this.role.ReplayGate(ntfMsg, true)
  169. }
  170. func (this *RoleMap) GetPlayerMapShowInfo(info *serverproto.PlayerShowInfo) {
  171. //nickName
  172. //fashion data
  173. if this.role.GetRoleBase() != nil {
  174. info.Gender = this.role.GetRoleBase().GetRoleSex()
  175. info.JobId = this.role.GetRoleBase().RoleData().HeroData.ConfigId
  176. info.NickName = this.role.GetRoleBase().GetRoleName()
  177. info.FashionData = this.role.GetRoleBase().roleBase.FashionData
  178. info.HeadId = this.role.GetHeadId()
  179. }
  180. }
  181. //func (this *RoleMap) FashionShowChangeNtf() {
  182. // util.DebugF("uid=%v FashionShowChangeNtf fashionData=%v", this.role.GetUUid(), this.role.GetRoleBase().roleBase.FashionData)
  183. //
  184. // if this.role.AoiNode() != "" {
  185. // //ssMsg := &serverproto.SSPlayerShowChangeReq{
  186. // // ShowInfo: &serverproto.PlayerShowInfo{
  187. // // Uid: this.role.GetUUid(),
  188. // // FashionData: this.role.GetRoleBase().roleBase.FashionData,
  189. // // },
  190. // //}
  191. // //this.role.SendAoi(ssMsg)
  192. // } else {
  193. // util.DebugF("uid=%v not in map", this.role.GetUUid())
  194. // }
  195. //}
  196. //func (this *RoleMap) PlayerEnterMap(msg *serverproto.CSPlayerEnterMapReq) {
  197. // //获取进入地图位置
  198. // if this.roleMap.MapType != msg.MapType && msg.Pos != nil {
  199. // this.roleMap.Pos = &serverproto.Position{X: msg.Pos.X, Y: msg.Pos.Y, Z: msg.Pos.Z}
  200. // }
  201. // ssEnterMsg := &serverproto.SSGCrossMapEnterReq{
  202. // MapType: msg.MapType, //不同系统玩法
  203. // AoiLine: msg.LineNum, //选择的线路(1线 2线...)
  204. // Pos: msg.Pos,
  205. // Dir: msg.Dir,
  206. // ShowInfo: &serverproto.PlayerShowInfo{
  207. // Uid: this.role.GetUUid(),
  208. // Sex: this.role.GetRoleBase().GetRoleSex(),
  209. // JobId: this.role.GetRoleBase().RoleData().HeroData.ConfigId,
  210. // NickName: this.role.GetRoleBase().GetRoleName(),
  211. // FashionData: this.role.GetRoleBase().roleBase.FashionData,
  212. // HeadId: this.role.GetHeadId(),
  213. // },
  214. // }
  215. // util.DebugF("uid=%v PlayerEnterMap to aoiRouter", this.role.GetUUid())
  216. //
  217. // //master
  218. // this.role.SendSocial(ssEnterMsg)
  219. //}
  220. //func (this *RoleMap) OnPlayerEnterMapSuccess(msg *serverproto.SSGCrossMapEnterAck) {
  221. // this.curLineNum = msg.LineNum
  222. // this.roleMap.MapType = msg.MapType
  223. //}
  224. //func (this *RoleMap) PlayerLeave(position *serverproto.Position) {
  225. // //说明玩家已经离开aoi地图,不再做离开处理
  226. // if this.role.AoiNode() == "" {
  227. // return
  228. // }
  229. // if position != nil {
  230. // if this.roleMap.Pos == nil {
  231. // this.roleMap.Pos = &serverproto.Position{}
  232. // }
  233. // *this.roleMap.Pos = *position
  234. // this.SetDirty(true)
  235. // }
  236. //
  237. // //master
  238. // //reqMsg := &serverproto.SSPlayerLeaveMapNtf{}
  239. // //this.role.SendAoi(reqMsg)
  240. //
  241. // //this.role.aoiNode = ""
  242. //}
  243. //func (this *RoleMap) PlayerMove(msg *serverproto.CSPlayerMoveReq) {
  244. // if this.role.AoiNode() == "" {
  245. // return
  246. // }
  247. // if msg.Pos != nil {
  248. // this.roleMap.Pos = msg.Pos
  249. // }
  250. //
  251. // //master and ghost
  252. // //this.role.SendAoi(msg)
  253. //}
  254. //播放动画操作
  255. //func (this *RoleMap) MapDoAction(actionId int32, pos *serverproto.Position) serverproto.ErrorCode {
  256. //logutil.DebugF("[MapDoAction] action:%v", actionId)
  257. //if pos == nil {
  258. // pos = &serverproto.Position{}
  259. //}
  260. //
  261. //cfgData, ok := serverproto.MainCityShowAnimCfgLoader[actionId]
  262. //if !ok {
  263. // return serverproto.ErrorCode_ERROR_FAIL
  264. //}
  265. //
  266. //if this.aoiServiceNode == "" {
  267. // logutil.DebugF("[MapDoAction] role not in map :%v", this.role.GetUUid())
  268. // return serverproto.ErrorCode_ERROR_FAIL
  269. //}
  270. //
  271. ////消耗道具判定
  272. //if cfgData.CostItem > 0 && cfgData.CostItemnum > 0 &&
  273. // this.role.GetResNum(cfgData.CostItem) <= uint64(cfgData.CostItemnum) {
  274. // return serverproto.ErrorCode_ERROR_AOI_ACTION_RES_NOT_ENOUGH
  275. //}
  276. //
  277. //if cfgData.TypeId == 1 {
  278. // //判断是否能召唤世界boss
  279. // ssReqMsg := &serverproto.SSPlayerSummonReq{
  280. // AoiLineStr: this.aoiServiceNode,
  281. // Uid: this.role.GetUUid(),
  282. // ActionId: actionId,
  283. // DurationTime: cfgData.LifeTime,
  284. // ActionUid: model.GenerateUid(),
  285. // Pos: pos,
  286. // BriefInfo: &serverproto.CommonPlayerBriefInfo{},
  287. // }
  288. // //获取玩家基础信息
  289. // this.role.GetRoleBriefInfo(ssReqMsg.BriefInfo)
  290. //
  291. // if cfgData.WorldBossid != 0 {
  292. // if bossCfgData, ok := model.ConvertWorldBoss[cfgData.WorldBossid]; ok {
  293. // summonId := bossCfgData.SummonId
  294. // if npcCfgData, ok1 := serverproto.NpcCfgLoader[summonId]; ok1 {
  295. // ssReqMsg.SummonHp = int32(npcCfgData.Hp)
  296. // }
  297. // ssReqMsg.MainRewardList = append(bossCfgData.SummonRewardList)
  298. // ssReqMsg.OtherRewardList = append(bossCfgData.KillRewardList)
  299. // }
  300. // }
  301. // this.role.SendBattleBoss(ssReqMsg)
  302. //} else {
  303. // //消耗道具,直接消耗道具播放动画
  304. // var delItemList = map[int32]int32{}
  305. // delItemList[cfgData.CostItem] = cfgData.CostItemnum
  306. // this.role.DelItemList(delItemList)
  307. //
  308. // //通知其他玩家播放动画
  309. // if this.aoiServiceNode != "" {
  310. // csMsg := &serverproto.CSPlayerActionReq{
  311. // ActionId: actionId,
  312. // Uid: this.role.GetUUid(),
  313. // Pos: pos,
  314. // }
  315. // this.role.SendAoi(csMsg)
  316. // }
  317. //
  318. // ackMsg := &serverproto.SCPlayerActionAck{
  319. // Error: int32(serverproto.ErrorCode_ERROR_OK),
  320. // ActionId: actionId,
  321. // }
  322. // this.role.ReplayGate(ackMsg, true)
  323. //}
  324. //return serverproto.ErrorCode_ERROR_OK
  325. //}
  326. //挑战世界boss
  327. func (this *RoleMap) MapPlayerChallengeWorldBoss(challengeBossUid uint64, summonIdx int32, aoiLineStr string) {
  328. cfgBossDataInfo, ok := model.ConvertWorldBossChangePlayList[int32(challengeBossUid)]
  329. if !ok {
  330. // 表示当天可购买挑战的次数上限
  331. vipWorldBossCount := this.role.GetRoleBase().GetVipData(model.Vip_System_WorldBoss_Count)
  332. totalCount := vipWorldBossCount + model.GlobalWorldBossChallengeCount
  333. if this.roleMap.WorldBossCount >= totalCount {
  334. ackMsg := &serverproto.SCPlayerChallengeSummonAck{
  335. Error: int32(serverproto.ErrorCode_ERROR_AOI_BOSS_CHALLENGE_LIMIT),
  336. }
  337. this.role.ReplayGate(ackMsg, true)
  338. return
  339. }
  340. //普通世界boss
  341. tmpChallengeBossId := this.getTmpBossId(int32(challengeBossUid), summonIdx)
  342. if _, ok := this.challengeBossList[int32(tmpChallengeBossId)]; ok {
  343. ackMsg := &serverproto.SCPlayerChallengeSummonAck{
  344. Error: int32(serverproto.ErrorCode_ERROR_AOI_BOSS_HAS_CHALLENGED),
  345. }
  346. this.role.ReplayGate(ackMsg, true)
  347. return
  348. }
  349. //地图等级判定
  350. cfg, ok := serverproto.WorldBossCfgLoader[int32(challengeBossUid)]
  351. if !ok {
  352. ackMsg := &serverproto.SCPlayerChallengeSummonAck{
  353. Error: int32(serverproto.ErrorCode_ERROR_AOI_BOSS_NOT_FOUND),
  354. }
  355. this.role.ReplayGate(ackMsg, true)
  356. return
  357. }
  358. if cfg.Tiaozhantiaojian != 0 && this.role.GetRoleBattle().GetLevelId() < cfg.Tiaozhantiaojian {
  359. ackMsg := &serverproto.SCPlayerChallengeSummonAck{
  360. Error: int32(serverproto.ErrorCode_ERROR_AOI_BOSS_MAP_LEVEL_LOW),
  361. }
  362. this.role.ReplayGate(ackMsg, true)
  363. return
  364. }
  365. } else {
  366. //变身世界boss
  367. //消耗资源进行挑战
  368. if !this.role.GetRoleBag().CanDelItemList(cfgBossDataInfo.ConsumeList) {
  369. ackMsg := &serverproto.SCPlayerChallengeSummonAck{
  370. Error: int32(serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH),
  371. }
  372. this.role.ReplayGate(ackMsg, true)
  373. return
  374. }
  375. }
  376. reqMsg := &serverproto.CSPlayerChallengeSummonReq{
  377. Uid: this.role.GetUUid(),
  378. ChallengeBossUid: challengeBossUid,
  379. FightInfo: &serverproto.FightRoleInfo{},
  380. }
  381. //获取战斗信息
  382. this.role.GetRoleFightInfo(reqMsg.FightInfo, true)
  383. this.role.SendBattleBoss(reqMsg)
  384. }
  385. func (this *RoleMap) DoMapPlayerChallengeWorldBoss(challengeBossUid int32) {
  386. cfgBossDataInfo, ok := model.ConvertWorldBossChangePlayList[int32(challengeBossUid)]
  387. if ok {
  388. //变身世界boss
  389. //消耗资源进行挑战
  390. this.role.GetRoleBag().DelItemList(cfgBossDataInfo.ConsumeList, AddItemST{
  391. AddFrom: AddFrom_WorldBoss,
  392. Notify: true,
  393. })
  394. }
  395. }
  396. func (this *RoleMap) MapWorldBossHp(damageHp int32) {
  397. if this.ChallengeBossId > 0 && damageHp > 0 {
  398. reqMsg := &serverproto.CSPlayerChallengeHpReq{
  399. DamageHp: damageHp,
  400. ActionUid: this.ChallengeBossId,
  401. }
  402. this.role.SendBattleBoss(reqMsg)
  403. util.DebugF("uid=%v MapSummonHp send hp to battleboss bossid=%v,damaghp=%v", this.role.GetUUid(),
  404. this.ChallengeBossId, damageHp)
  405. }
  406. }
  407. func (this *RoleMap) GetWorldBossList() {
  408. csMsg := &serverproto.CSPlayerWorldBossListReq{}
  409. this.role.SendBattleBoss(csMsg)
  410. }
  411. func (this *RoleMap) GetWorldBossListAckFilter(ackMsg *serverproto.SCPlayerWorldBossListAck) {
  412. for idx := 0; idx < len(ackMsg.WorldBossList); idx++ {
  413. bossInfo := ackMsg.WorldBossList[idx]
  414. //普通世界boss
  415. if bossInfo.BossSummonType <= 0 {
  416. tmpBossId := this.getTmpBossId(bossInfo.BossId, bossInfo.BossSummonIdx)
  417. if _, ok := this.challengeBossList[tmpBossId]; ok {
  418. bossInfo.IsFight = true
  419. }
  420. }
  421. }
  422. }
  423. func (this *RoleMap) getTmpBossId(bossId, summonIdx int32) int32 {
  424. return bossId*10000 + summonIdx
  425. }
  426. func (this *RoleMap) getChallengeBossCost(idx int32) (ret serverproto.KeyValueType) {
  427. costLen := len(model.GlobalWorldBossChallengeCost)
  428. if idx <= 0 || costLen <= 0 {
  429. return
  430. }
  431. if idx > int32(costLen) {
  432. ret = model.GlobalWorldBossChallengeCost[costLen-1]
  433. } else {
  434. ret = model.GlobalWorldBossChallengeCost[idx-1]
  435. }
  436. return
  437. }
  438. //获取rand点奖励(drop)
  439. func (this *RoleMap) GenWorldBossRandReward(pointInfo *serverproto.WorldBossRandPointInfo) serverproto.ErrorCode {
  440. _, ok := model.ConvertWorldBossChangePlayList[int32(pointInfo.BossId)]
  441. if !ok {
  442. //记录挑战记录
  443. vipWorldBossCount := this.role.GetRoleBase().GetVipData(model.Vip_System_WorldBoss_Count)
  444. totalCount := vipWorldBossCount + model.GlobalWorldBossChallengeCount
  445. if this.roleMap.WorldBossCount >= totalCount {
  446. return serverproto.ErrorCode_ERROR_FAIL
  447. }
  448. //普通boss消耗次数
  449. this.roleMap.WorldBossCount++
  450. TaskMagCheck(this.role, serverproto.TaskType_World_Boss_Challenge_Count, 1)
  451. tmpBossId := this.getTmpBossId(pointInfo.BossId, pointInfo.BossSummonIdx)
  452. if _, ok := this.challengeBossList[tmpBossId]; !ok {
  453. this.roleMap.WorldBossChallengeList = append(this.roleMap.WorldBossChallengeList, tmpBossId)
  454. this.challengeBossList[tmpBossId] = tmpBossId
  455. }
  456. TaskMagCheck(this.role, serverproto.TaskType_World_Boss_Challenge_Count, 1)
  457. this.SetDirty(true)
  458. this.dataChangeNtf()
  459. }
  460. //reward
  461. vipCount := this.role.GetRoleBase().GetVipData(model.Vip_System_WorldBoss)
  462. var drawCount int32 = 1
  463. if vipCount > 0 {
  464. drawCount = vipCount
  465. if drawCount > 3 {
  466. drawCount = 3
  467. }
  468. }
  469. ret := serverproto.ErrorCode_ERROR_OK
  470. var addItemList = map[int32]int32{}
  471. rand.Seed(int64(util.GetTimeMilliseconds()))
  472. this.worldBossRankReward(pointInfo.BossId, drawCount, addItemList, pointInfo)
  473. if len(addItemList) > 0 {
  474. ret = this.role.CanAddItemList(addItemList)
  475. if ret == serverproto.ErrorCode_ERROR_OK {
  476. this.role.AddItemList(addItemList, AddFrom_WorldBoss, true)
  477. util.InfoF("uid=%v GenWorldBossRandReward rewardList itemList=%v", this.role.GetUUid(), addItemList)
  478. }
  479. }
  480. return ret
  481. }
  482. func (this *RoleMap) WorldBossRankReward() bool {
  483. var addItemList = map[int32]int32{}
  484. pointInfo := &serverproto.WorldBossRandPointInfo{}
  485. return this.worldBossRankReward(1, 3, addItemList, pointInfo)
  486. }
  487. func (this *RoleMap) worldBossRankReward(bossId int32, drawCount int32, addItemList map[int32]int32, pointInfo *serverproto.WorldBossRandPointInfo) bool {
  488. cfgData, ok := model.ConvertWorldBossList[bossId]
  489. if !ok {
  490. cfgData, ok = model.ConvertWorldBossChangePlayList[bossId]
  491. if !ok {
  492. util.ErrorF("uid=%v GenWorldBossRandReward cfgData not find bossid=%v", this.role.GetUUid(), bossId)
  493. }
  494. }
  495. var goldReward bool = false
  496. for k := 0; k < int(drawCount); k++ {
  497. randNum := rand.Int31n(cfgData.RollTotalWeight)
  498. util.DebugF("total=%v randNum=%v normal", cfgData.RollTotalWeight, randNum)
  499. if goldReward == true {
  500. randNum = rand.Int31n(cfgData.DeductionWeight)
  501. util.DebugF("total=%v randNum=%v gold", cfgData.DeductionWeight, randNum)
  502. }
  503. for idx := 0; idx < len(cfgData.RollList); idx++ {
  504. rewardWeight := cfgData.RollList[idx].RewardWeight
  505. if goldReward == true {
  506. rewardWeight = cfgData.RollList[idx].DeductionWeight
  507. }
  508. if rewardWeight > randNum {
  509. pointInfo.RewardList = append(pointInfo.RewardList, int32(idx+1))
  510. for i := 0; i < len(cfgData.RollList[idx].RewardList); i++ {
  511. val := cfgData.RollList[idx].RewardList[i]
  512. addItemList[val.Key] += val.Value
  513. }
  514. if idx == 0 { //一等奖,则下次概率衰减
  515. goldReward = true
  516. }
  517. break
  518. }
  519. }
  520. }
  521. util.InfoF("uid=%v worldBossRankReward randList=%v", this.role.GetUUid(), pointInfo.RewardList)
  522. return goldReward
  523. }
  524. func (this *RoleMap) GmReset() {
  525. this.roleMap.WorldBossCount = 0
  526. this.roleMap.WorldBossChallengeList = []int32{}
  527. this.challengeBossList = map[int32]int32{}
  528. this.SetDirty(true)
  529. this.dataChangeNtf()
  530. }