service.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package lineup
  2. import (
  3. "f1-game/internal/constant"
  4. "f1-game/internal/data"
  5. facade "f1-game/internal/facade"
  6. nameRoute "f1-game/internal/name/route"
  7. "f1-game/internal/pb"
  8. "f1-game/internal/sessions"
  9. "f1-game/internal/types"
  10. "f1-game/nodes/game/internal/db"
  11. clog "github.com/cherry-game/cherry/logger"
  12. cproto "github.com/cherry-game/cherry/net/proto"
  13. )
  14. var srv = &service{}
  15. func Service() *service {
  16. return srv
  17. }
  18. type service struct {
  19. facade.PlayerServiceBase[*db.PlayerTable]
  20. }
  21. func (p *service) OnLogin(playerTable *db.PlayerTable, session *cproto.Session) {
  22. lineupTable := db.GetLineupTable(playerTable.PlayerID)
  23. // 检测阵容队伍变化 // TODO 暂时默认一个队伍
  24. if success := lineupTable.LineupMap.AddLineups(constant.Adventure_Type, 1); success {
  25. lineupTable.Save2Queue()
  26. }
  27. }
  28. // func (p *service) OnLogined(playerTable *db.PlayerTable, session *cproto.Session) {
  29. // }
  30. // func (p *service) OnLogout(playerTable *db.PlayerTable) {
  31. // }
  32. // func (p *service) OnReset(playerTable *db.PlayerTable, _ *ctime.CherryTime, byLogin bool) {
  33. // }
  34. // Push 推送队伍信息
  35. func (p *service) Push(playerTable *db.PlayerTable, session *cproto.Session) {
  36. lineupTable := db.GetLineupTable(playerTable.PlayerID)
  37. // 推送阵容数据
  38. lineupResp := pb.LineupsList{
  39. Lineups: lineupTable.LineupMap.ToProto(),
  40. }
  41. sessions.PushWithSession(session, nameRoute.PushGamePlayer_Lineup, &lineupResp)
  42. }
  43. // LineupChangePush 推送变化的阵容信息
  44. func (p *service) LineupChangePush(playerID int64, lineupType int32, lineupIDList ...int32) {
  45. var (
  46. teamTable = db.GetLineupTable(playerID)
  47. list = []*pb.Lineup{}
  48. )
  49. lineups, found := teamTable.LineupMap.GetLineups(lineupType)
  50. if !found {
  51. clog.Warnf("Lineup ChangePush lineupType not found. playerID:%d, lineupType:%d", playerID, lineupType)
  52. return
  53. }
  54. for _, lineupID := range lineupIDList {
  55. if lineup, ok := lineups.GetLineup(lineupID); ok {
  56. proto := lineup.ToProto()
  57. list = append(list, &proto)
  58. }
  59. }
  60. if len(list) == 0 {
  61. return
  62. }
  63. resp := &pb.Lineups{
  64. LineupType: lineupType,
  65. List: list,
  66. }
  67. sessions.PushPlayer(playerID, nameRoute.PushGamePlayer_LineupChange, resp)
  68. }
  69. // 通过英雄列表获取羁绊列表
  70. func (p *service) GetFetterListByHeroList(playerID int64, heroIDList types.Set[int32]) types.Set[int32] {
  71. if len(heroIDList) < 1 {
  72. return nil
  73. }
  74. activeFetterIDs := types.Set[int32]{}
  75. for heroID := range heroIDList {
  76. fetterIDs := data.HeroFetter.GetFetterIDs(heroID)
  77. // 当前英雄没有羁绊,则跳过
  78. if len(fetterIDs) < 1 {
  79. continue
  80. }
  81. for fetterID := range fetterIDs {
  82. if activeFetterIDs.Contains(fetterID) {
  83. continue
  84. }
  85. fetterRow, found := data.HeroFetter.GetByID(fetterID)
  86. if !found {
  87. clog.Warnf("[GetFetterListByHeroList] fetter not found, playerID:%d, fetterID: %d", playerID, fetterID)
  88. continue
  89. }
  90. curNum := int32(0)
  91. for _, needHeroID := range fetterRow.HeroIDs {
  92. if heroIDList.Contains(needHeroID) {
  93. curNum++
  94. // 如果当前所需英雄数量已经满足,则直接添加羁绊ID,并跳过
  95. if curNum >= fetterRow.ActiveHeroNum {
  96. activeFetterIDs.Add(fetterID)
  97. break
  98. }
  99. }
  100. }
  101. }
  102. }
  103. return activeFetterIDs
  104. }