package mapLeague import ( "f1-game/internal/code" "f1-game/internal/enum" "f1-game/internal/event" "f1-game/internal/extend/utils" nameEvent "f1-game/internal/name/event" nameLocal "f1-game/internal/name/local" nameRemote "f1-game/internal/name/remote" "f1-game/internal/pb" "f1-game/internal/sessions" mapCall "f1-game/nodes/map/internal/call" "f1-game/nodes/map/internal/db" dbLeague "f1-game/nodes/map/internal/db/data/league" cstring "github.com/cherry-game/cherry/extend/string" ctime "github.com/cherry-game/cherry/extend/time" cfacade "github.com/cherry-game/cherry/facade" clog "github.com/cherry-game/cherry/logger" cproto "github.com/cherry-game/cherry/net/proto" ) func (p *actorLeague) initCastle() { p.Local().Register(nameLocal.MapLeague_CastleList, p.castleList) p.Local().Register(nameLocal.MapLeague_CastleAppoint, p.castleAppoint) p.EventRegister(nameEvent.League_CastleUpdate, p.castleUpdate) } // 获取城池列表 func (p *actorLeague) castleList(session *cproto.Session, _ *pb.None) { p.Response(session, p.leagueTable.Castles.ToProto()) } // 城池任命或取消任命 func (p *actorLeague) castleAppoint(session *cproto.Session, req *pb.I64I64) { var ( objectID = req.GetKey() // 城池对象ID targetPlayerID = req.GetValue() // 目标玩家ID 0 取消任命 ) if objectID < 1 { p.ResponseCode(session, code.IllegalArgument) return } // 判断城池是否存在 castle, found := p.leagueTable.Castles.Castles.Get(objectID) if !found { p.ResponseCode(session, code.MapLeague_CastleNotExist) return } // 判断操作者权限 只有盟主有权任命 leagueTable, found := db.GetMapLeagueTable(p.leagueID) if !found { p.ResponseCode(session, code.LeagueNotExist) return } // 当前操作者ID opPlayerID := sessions.GetPlayerID(session) if leagueTable.LeagueInfo.LeaderID != opPlayerID { p.ResponseCode(session, code.LeaguePermissionDenied) return } // 任命 if targetPlayerID > 0 { // 判断是不是本联盟成员 leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID) if !found { p.ResponseCode(session, code.LeagueMembersEmpty) return } found = leagueMemberTable.CheckMemberExist(targetPlayerID) if !found { p.ResponseCode(session, code.LeagueMemberNotExist) return } // 判断目标玩家是否已经是其他城池的城主 if p.leagueTable.Castles.IsAppointed(targetPlayerID) { p.ResponseCode(session, code.MapLeague_CastleAlreadyHasOther) return } // 已经有城主 if castle.OwnerID > 0 { p.ResponseCode(session, code.MapLeague_CastleAlreadyHasLord) return } castle.SetCastleLord(targetPlayerID) } else { // 取消任命 castle.SetCastleLord(0) } p.leagueTable.Save2Queue() p.ResponseCode(session, code.OK) clog.Debugf("castleAppoint success: %+v", castle) } // 联盟城池更新 func (p *actorLeague) castleUpdate(eventData cfacade.IEventData) { evt, ok := eventData.(*event.LeagueCastleUpdate) if !ok { p.Warn("[castleUpdate] eventData error. leagueID:%d", p.leagueID) return } var ( objectID = evt.GetObjectID() configID = evt.GetConfigID() point = evt.GetPoint() isDel = evt.IsDel() ) if isDel { p.leagueTable.Castles.DelCastle(objectID) // 通知所有联盟成员减少产量 p.callToMembers(nameRemote.MapPlayer_UpdateCastleResYield, &pb.I32Bool{ Key: configID, Value: true, }) // 添加被攻占日志 leagueLogTable, _ := db.GetMapLeagueLogTable(p.leagueID) leagueLogTable.AddLeagueLog(enum.Log_LeagueCaptureCity_Enemy, utils.ToStringSlice(evt.GetNewLeagueName(), configID)...) } else { newCastle := dbLeague.NewCastle(objectID, configID, point, ctime.Now().ToMillisecond()) p.leagueTable.Castles.AddCastle(newCastle) // 通知所有联盟成员增加产量 p.callToMembers(nameRemote.MapPlayer_UpdateCastleResYield, &pb.I32Bool{ Key: configID, Value: false, }) // 添加攻占日志 leagueLogTable, _ := db.GetMapLeagueLogTable(p.leagueID) leagueLogTable.AddLeagueLog(enum.Log_LeagueCaptureCity, cstring.ToString(configID)) } p.leagueTable.Save2Queue() // 刷新霸业排行榜 seasonScore := p.leagueTable.Castles.GetSeasonScore() rank := p.leagueTable.ToRankLeague(seasonScore) mapCall.Rank.UpdateLeagueRank(enum.Rank_202, rank) p.Debug("[castleUpdate] objectID = %d, configID = %d, point = %v, isDel = %v", objectID, configID, point, isDel) }