| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package mapLeague
- import (
- cherryApp "f1-game/internal/cherry_app"
- nameRemote "f1-game/internal/name/remote"
- "f1-game/internal/pb"
- "f1-game/internal/sessions"
- "f1-game/nodes/map/internal/db"
- mapFacade "f1-game/nodes/map/internal/facade"
- cherryActor "github.com/cherry-game/cherry/net/actor"
- )
- type actorLeague struct {
- cherryApp.ActorLogger
- leagueID int64 // 联盟ID
- leagueTable *db.MapLeagueTable
- }
- func newActorLeague(leagueID int64) actorLeague {
- return actorLeague{
- ActorLogger: cherryApp.NewLoggerPrefix("league", leagueID),
- leagueID: leagueID,
- }
- }
- func (p *actorLeague) OnInit() {
- p.initMapLeagueTable()
- p.startTimer()
- p.initTech()
- p.initAssemble()
- p.initReport()
- p.initCastle()
- p.initStorage()
- p.initDiplomacy()
- p.initQuest()
- p.initMap()
- p.initWar()
- p.initLeagueBase() // 联盟基础
- p.initLeagueMember() // 联盟成员
- p.initLeagueMail() // 联盟邮件
- p.Remote().Register(nameRemote.MapLeague_OnLogin, p.onLogin)
- }
- // 初始化地图联盟表
- func (p *actorLeague) initMapLeagueTable() {
- if leagueTable, found := db.GetMapLeagueTable(p.leagueID); found {
- p.leagueTable = leagueTable
- return
- }
- p.leagueTable = db.NewMapLeagueTable(p.leagueID)
- }
- // 登录操作
- func (p *actorLeague) onLogin(req *pb.I64) {
- playerID := req.Value
- if playerID < 1 {
- return
- }
- session, found := sessions.GetSession(playerID)
- if !found {
- p.Warn("league push fail, session not found. playerID:%d", playerID)
- return
- }
- // 推送整合到service中
- mapFacade.LeagueServicePush(p.leagueTable, session)
- }
- // 推送消息给联盟成员
- func (p *actorLeague) pushToMembers(route string, arg any) {
- leagueMemberTable, ok := db.GetMapLeagueMemberTable(p.leagueID)
- if !ok {
- return
- }
- sessions.PushPlayers(leagueMemberTable.GetLeagueMemberIDs(), route, arg)
- }
- func (p *actorLeague) EventRegister(name string, fn cherryActor.IEventFunc) {
- p.Event().Register(name, fn, p.leagueID)
- }
|