| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package lineup
- import (
- "f1-game/internal/constant"
- "f1-game/internal/data"
- facade "f1-game/internal/facade"
- nameRoute "f1-game/internal/name/route"
- "f1-game/internal/pb"
- "f1-game/internal/sessions"
- "f1-game/internal/types"
- "f1-game/nodes/game/internal/db"
- clog "github.com/cherry-game/cherry/logger"
- cproto "github.com/cherry-game/cherry/net/proto"
- )
- var srv = &service{}
- func Service() *service {
- return srv
- }
- type service struct {
- facade.PlayerServiceBase[*db.PlayerTable]
- }
- func (p *service) OnLogin(playerTable *db.PlayerTable, session *cproto.Session) {
- lineupTable := db.GetLineupTable(playerTable.PlayerID)
- // 检测阵容队伍变化 // TODO 暂时默认一个队伍
- if success := lineupTable.LineupMap.AddLineups(constant.Adventure_Type, 1); success {
- lineupTable.Save2Queue()
- }
- }
- // func (p *service) OnLogined(playerTable *db.PlayerTable, session *cproto.Session) {
- // }
- // func (p *service) OnLogout(playerTable *db.PlayerTable) {
- // }
- // func (p *service) OnReset(playerTable *db.PlayerTable, _ *ctime.CherryTime, byLogin bool) {
- // }
- // Push 推送队伍信息
- func (p *service) Push(playerTable *db.PlayerTable, session *cproto.Session) {
- lineupTable := db.GetLineupTable(playerTable.PlayerID)
- // 推送阵容数据
- lineupResp := pb.LineupsList{
- Lineups: lineupTable.LineupMap.ToProto(),
- }
- sessions.PushWithSession(session, nameRoute.PushGamePlayer_Lineup, &lineupResp)
- }
- // LineupChangePush 推送变化的阵容信息
- func (p *service) LineupChangePush(playerID int64, lineupType int32, lineupIDList ...int32) {
- var (
- teamTable = db.GetLineupTable(playerID)
- list = []*pb.Lineup{}
- )
- lineups, found := teamTable.LineupMap.GetLineups(lineupType)
- if !found {
- clog.Warnf("Lineup ChangePush lineupType not found. playerID:%d, lineupType:%d", playerID, lineupType)
- return
- }
- for _, lineupID := range lineupIDList {
- if lineup, ok := lineups.GetLineup(lineupID); ok {
- proto := lineup.ToProto()
- list = append(list, &proto)
- }
- }
- if len(list) == 0 {
- return
- }
- resp := &pb.Lineups{
- LineupType: lineupType,
- List: list,
- }
- sessions.PushPlayer(playerID, nameRoute.PushGamePlayer_LineupChange, resp)
- }
- // 通过英雄列表获取羁绊列表
- func (p *service) GetFetterListByHeroList(playerID int64, heroIDList types.Set[int32]) types.Set[int32] {
- if len(heroIDList) < 1 {
- return nil
- }
- activeFetterIDs := types.Set[int32]{}
- for heroID := range heroIDList {
- fetterIDs := data.HeroFetter.GetFetterIDs(heroID)
- // 当前英雄没有羁绊,则跳过
- if len(fetterIDs) < 1 {
- continue
- }
- for fetterID := range fetterIDs {
- if activeFetterIDs.Contains(fetterID) {
- continue
- }
- fetterRow, found := data.HeroFetter.GetByID(fetterID)
- if !found {
- clog.Warnf("[GetFetterListByHeroList] fetter not found, playerID:%d, fetterID: %d", playerID, fetterID)
- continue
- }
- curNum := int32(0)
- for _, needHeroID := range fetterRow.HeroIDs {
- if heroIDList.Contains(needHeroID) {
- curNum++
- // 如果当前所需英雄数量已经满足,则直接添加羁绊ID,并跳过
- if curNum >= fetterRow.ActiveHeroNum {
- activeFetterIDs.Add(fetterID)
- break
- }
- }
- }
- }
- }
- return activeFetterIDs
- }
|