| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- package mapLeague
- import (
- actorRemote "f1-game/internal/actor_remote"
- "f1-game/internal/code"
- "f1-game/internal/component/redis"
- "f1-game/internal/constant"
- "f1-game/internal/data"
- "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"
- nameRedis "f1-game/internal/name/redis"
- nameRemote "f1-game/internal/name/remote"
- nameRoute "f1-game/internal/name/route"
- "f1-game/internal/pb"
- "f1-game/internal/sessions"
- "f1-game/internal/types"
- ao "f1-game/nodes/game/player/asset/origin"
- mapCall "f1-game/nodes/map/internal/call"
- "f1-game/nodes/map/internal/db"
- dbLeague "f1-game/nodes/map/internal/db/data/league"
- leagueAttr "f1-game/nodes/map/league/attr"
- leagueBase "f1-game/nodes/map/league/base"
- leagueMember "f1-game/nodes/map/league/member"
- leagueStorage "f1-game/nodes/map/league/storage"
- "math/rand/v2"
- ctime "github.com/cherry-game/cherry/extend/time"
- cfacade "github.com/cherry-game/cherry/facade"
- cproto "github.com/cherry-game/cherry/net/proto"
- )
- func (p *actorLeague) initLeagueBase() {
- p.Local().Register(nameLocal.MapLeague_Upgrade, p.leagueUpgrade)
- p.Local().Register(nameLocal.MapLeague_ApplyList, p.leagueApplyList)
- p.Local().Register(nameLocal.MapLeague_ApplyOption, p.leagueApplyOption)
- p.Local().Register(nameLocal.MapLeague_ApplyAgreeAll, p.leagueApplyAgreeAll)
- p.Local().Register(nameLocal.MapLeague_ClearApplyList, p.leagueClearApplyList)
- p.Local().Register(nameLocal.MapLeague_Setting, p.leagueSetting)
- p.Local().Register(nameLocal.MapLeague_FlagSet, p.leagueFlagSet)
- p.Local().Register(nameLocal.MapLeague_LogList, p.leagueLogList)
- p.Local().Register(nameLocal.MapLeague_ResidenceBack, p.leagueResidenceBack)
- p.Local().Register(nameLocal.MapLeague_MapMark, p.leagueMapMark)
- p.Local().Register(nameLocal.MapLeague_MapMarkEdit, p.leagueMapMarkEdit)
- p.Local().Register(nameLocal.MapLeague_MapMarkDelete, p.leagueMapMarkDelete)
- p.Remote().Register(nameRemote.MapLeague_Info, p.leagueInfo)
- p.Remote().Register(nameRemote.MapLeague_ResidenceRemove, p.leagueResidenceRemove)
- p.Remote().Register(nameRemote.MapLeague_ForceResidenceBack, p.forceResidenceBack)
- p.Remote().Register(nameRemote.MapLeague_Join, p.leagueJoin)
- p.Event().Register(nameEvent.Map_PlayerPrestigeUpdate, p.leagueMemberPrestige)
- }
- func (p *actorLeague) leagueInfo(req *pb.I64) (*pb.League, int32) {
- leagueID := req.Value
- leagueTable, found := db.GetMapLeagueTable(leagueID)
- if !found {
- return nil, code.LeagueNotExist
- }
- league := leagueTable.ToLeagueInfoProto()
- // 设置联盟名称 // TODO 后续改成缓存的map直接读取map的
- if len(league.Diplomacy.Applys) > 0 {
- for _, apply := range league.Diplomacy.Applys {
- leagueTable, found := db.GetMapLeagueTable(apply.LeagueID)
- if found {
- apply.LeagueName = leagueTable.LeagueInfo.LeagueName
- }
- }
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(leagueID)
- if found {
- totalPrestige := int32(0)
- list := redis.Game.GetPlayerDataList(leagueMemberTable.GetLeagueMemberIDs(), nameRedis.Player_Prestige)
- if len(list) > 0 {
- for _, playerData := range list {
- totalPrestige += playerData.Prestige
- }
- }
- league.LeaguePrestige = totalPrestige
- }
- return league, code.OK
- }
- // apply 加入联盟
- func (p *actorLeague) leagueJoin(req *pb.I64I32) int32 {
- var (
- playerID = req.Key
- mainCityLevel = req.Value
- )
- if playerID < 1 || p.leagueID < 1 {
- return code.IllegalArgument
- }
- //判断联盟是否存在 获取联盟信息
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- return code.LeagueNotExist
- }
- // 判断是否提交过申请
- if leagueTable.LeagueInfo.CheckApplyExist(playerID) {
- return code.LeagueApplyRepeat
- }
- // 判断玩家等级是否满足
- if mainCityLevel < leagueTable.LeagueInfo.JoinNeedLevel {
- return code.LeagueNeedLevelNotEnough
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- return code.LeagueMembersEmpty
- }
- //判断当前联盟是否已满人 如果满人则拒绝入会申请
- if leagueMemberTable.GetLeagueMemberCount() >= leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit) {
- return code.LeagueMembersLimit
- }
- // 申请需要审批
- if leagueTable.LeagueInfo.IsJoinApproval() {
- // 添加申请记录
- leagueTable.LeagueInfo.AddApply(playerID)
- // 通知可处理申请的在线管理(有人员权限的管理员)
- p.leagueJoinApplyNotice(leagueTable.LeagueInfo.LeaderID, leagueMemberTable, playerID)
- } else {
- errCode := actorRemote.MapPlayer.LeagueJoin(playerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
- if code.IsFail(errCode) {
- p.Warn("[leagueJoin] player fail. leagueID:%d, playerID:%d", p.leagueID, playerID)
- return errCode
- }
- // 成功 加入联盟
- p.doLeagueMemberJoin(leagueTable, leagueMemberTable, playerID)
- }
- leagueTable.Save2Queue()
- return code.OK
- }
- // 联盟升级
- func (p *actorLeague) leagueUpgrade(session *cproto.Session, _ *pb.None) {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- // 检测是否有权限
- opPlayerID := sessions.GetPlayerID(session)
- ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Construction)
- if !ok {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- var (
- curLevel = leagueTable.LeagueInfo.Level
- nextLevel = curLevel + 1
- )
- curLevelRow, found := data.LeagueLevel.GetByLevel(curLevel)
- if !found {
- p.ResponseCode(session, code.LeagueLevelConfigNotExist)
- return
- }
- // 已达最大等级
- if curLevelRow.Exp.Value <= 0 {
- p.ResponseCode(session, code.LeagueMaxLevel)
- return
- }
- // 获取下一等级配置
- _, found = data.LeagueLevel.GetByLevel(nextLevel)
- if !found {
- p.ResponseCode(session, code.LeagueLevelConfigNotExist)
- return
- }
- assets := types.Assets{
- {ID: curLevelRow.Exp.Key, Num: int64(curLevelRow.Exp.Value)},
- }
- errCode := p.subAssets(assets)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- leagueTable.LeagueInfo.Level = nextLevel
- // 更新属性
- leagueAttr.Service().UpdateAttrs(leagueTable)
- leagueTable.Save2Queue()
- objectID := int64(0)
- build, found := leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
- if found {
- objectID = build.ObjectID
- }
- p.PostEvent(event.NewLeagueUpgrade(p.leagueID, objectID, leagueTable.LeagueInfo.Level))
- // 检查更新仓库容量
- leagueStorage.Service().CheckAndInitCapacity(leagueTable)
- resp := &pb.I32I32{
- Key: leagueTable.LeagueInfo.Level,
- Value: leagueTable.LeagueInfo.Exp,
- }
- p.Response(session, resp)
- // 通知前端更新属性,看需不需要给所有成员推送
- p.Push(session, nameRoute.PushLeague_AttrChange, leagueTable.LeagueInfo.Attrs.ToProto())
- }
- // 获取入盟申请列表
- func (p *actorLeague) leagueApplyList(session *cproto.Session, _ *pb.None) {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- var (
- list = []*pb.LeagueApply{}
- playerIDs = []int64{}
- )
- for _, pair := range leagueTable.LeagueInfo.LeagueApplys {
- apply := &pb.LeagueApply{
- PlayerID: pair.Key,
- ApplyTime: pair.Value,
- }
- list = append(list, apply)
- playerIDs = append(playerIDs, pair.Key)
- }
- if len(playerIDs) > 0 {
- // 获取玩家基础信息
- playerDataMap := redis.Game.GetPlayerDataMap(playerIDs, nameRedis.PlayerBaseFields...)
- if len(playerDataMap) > 0 {
- for _, apply := range list {
- playerData, found := playerDataMap[apply.PlayerID]
- if found {
- apply.PlayerName = playerData.PlayerName
- apply.Level = playerData.LordLevel
- }
- }
- }
- }
- resp := &pb.LeagueApplyList{
- List: list,
- }
- p.Response(session, resp)
- }
- // 联盟申请处理 拒绝/通过
- func (p *actorLeague) leagueApplyOption(session *cproto.Session, req *pb.I64Bool) {
- var (
- opPlayerID = sessions.GetPlayerID(session)
- targetPlayerID = req.Key
- isArgee = req.Value
- )
- if targetPlayerID < 1 {
- p.ResponseCode(session, code.IllegalArgument)
- return
- }
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- // 检测申请是否存在
- if !leagueTable.LeagueInfo.CheckApplyExist(targetPlayerID) {
- p.ResponseCode(session, code.LeagueApplyNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Member) {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- errCode := code.OK
- //通过申请
- if isArgee {
- // 判断玩家是否已存在联盟中
- if leagueMemberTable.CheckMemberExist(targetPlayerID) {
- p.ResponseCode(session, code.LeagueAlreadyJoin)
- return
- }
- // 判断联盟人数是否已满
- if leagueMemberTable.GetLeagueMemberCount() >= leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit) {
- p.ResponseCode(session, code.LeagueMembersLimit)
- return
- }
- errCode := actorRemote.MapPlayer.LeagueJoin(targetPlayerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
- if code.IsOK(errCode) {
- // 成功 加入联盟
- p.doLeagueMemberJoin(leagueTable, leagueMemberTable, targetPlayerID)
- }
- }
- // 不管通过还是拒绝 都需要移除申请记录
- leagueTable.LeagueInfo.RemoveApply(targetPlayerID)
- leagueTable.Save2Queue()
- p.ResponseCode(session, errCode)
- }
- // 一键同意入盟申请
- func (p *actorLeague) leagueApplyAgreeAll(session *cproto.Session, _ *pb.None) {
- opPlayerID := sessions.GetPlayerID(session)
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Member) {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- if p.leagueTable.LeagueInfo.LeagueApplys.IsEmpty() {
- p.ResponseCode(session, code.LeagueApplyNotExist)
- return
- }
- var (
- curMemberCount = leagueMemberTable.GetLeagueMemberCount()
- memberCountLimit = p.leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit)
- )
- // 判断联盟人数是否已满
- if curMemberCount >= memberCountLimit {
- p.ResponseCode(session, code.LeagueMembersLimit)
- return
- }
- var (
- removeApplys = []int64{}
- joinPlayerIDs = []int64{}
- )
- for _, pair := range p.leagueTable.LeagueInfo.LeagueApplys {
- targetPlayerID := pair.Key
- // 判断玩家是否已存在联盟中
- if exist := leagueMemberTable.CheckMemberExist(targetPlayerID); exist {
- removeApplys = append(removeApplys, targetPlayerID)
- continue
- }
- errCode := actorRemote.MapPlayer.LeagueJoin(targetPlayerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
- if code.IsOK(errCode) {
- joinPlayerIDs = append(joinPlayerIDs, targetPlayerID)
- curMemberCount++
- }
- removeApplys = append(removeApplys, targetPlayerID)
- // 检测联盟成员数是否超出上限
- if curMemberCount >= memberCountLimit {
- break
- }
- }
- // 添加加入联盟的玩家
- if len(joinPlayerIDs) > 0 {
- p.doLeagueMemberJoin(p.leagueTable, leagueMemberTable, joinPlayerIDs...)
- }
- if len(removeApplys) > 0 {
- // 删除入盟申请
- p.leagueTable.LeagueInfo.RemoveApply(removeApplys...)
- p.leagueTable.Save2Queue()
- }
- resp := &pb.I64List{
- List: removeApplys,
- }
- p.Response(session, resp)
- }
- // 清除联盟申请列表
- func (p *actorLeague) leagueClearApplyList(session *cproto.Session, _ *pb.None) {
- opPlayerID := sessions.GetPlayerID(session)
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- // 判断玩家是否有权处理
- if !leagueMemberTable.LeagueMember.CheckPermission(opPlayerID, enum.League_Permission_Member) {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- // 清除申请列表
- if ok := leagueTable.LeagueInfo.ClearApplyList(); ok {
- leagueTable.Save2Queue()
- }
- p.ResponseCode(session, code.OK)
- }
- // 入盟等级&审批&公告设置
- func (p *actorLeague) leagueSetting(session *cproto.Session, req *pb.LeagueBaseSetting) {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- // 判断玩家是否有权限 需要外交权限
- opPlayerID := sessions.GetPlayerID(session)
- ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Diplomacy)
- if !ok {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- var (
- update = false
- needApprove = req.NeedApprove
- levelLimit = req.LevelLimit
- leagueNotice = req.LeagueNotice
- )
- if leagueTable.LeagueInfo.JoinApproval != needApprove {
- leagueTable.LeagueInfo.JoinApproval = needApprove
- update = true
- }
- if leagueTable.LeagueInfo.JoinNeedLevel != levelLimit {
- // 判断等级是否存在
- maxLevel := data.FacilityLevel.GetMaxLevel(enum.Facility_MainID)
- if 0 <= levelLimit && levelLimit <= maxLevel {
- leagueTable.LeagueInfo.JoinNeedLevel = levelLimit
- update = true
- }
- }
- if leagueTable.LeagueInfo.LeagueNotice != leagueNotice {
- if ok := utils.CheckStrLen(leagueNotice, data.Const.LeagueNoticeLimit); ok {
- leagueTable.LeagueInfo.LeagueNotice = leagueNotice
- update = true
- }
- }
- if update {
- leagueTable.Save2Queue()
- }
- resp := &pb.LeagueBaseSetting{
- NeedApprove: leagueTable.LeagueInfo.JoinApproval,
- LevelLimit: leagueTable.LeagueInfo.JoinNeedLevel,
- LeagueNotice: leagueTable.LeagueInfo.LeagueNotice,
- }
- p.Response(session, resp)
- }
- // 联盟旗帜设置
- func (p *actorLeague) leagueFlagSet(session *cproto.Session, req *pb.I32I32) {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- // 判断玩家是否有权限 需要外交权限
- opPlayerID := sessions.GetPlayerID(session)
- ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Diplomacy)
- if !ok {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- var (
- flagBg = req.Key
- flagIcon = req.Value
- )
- // 检测旗帜背景是否存在
- flagBgRow, found := data.LeagueFlag.GetByFlagID(flagBg)
- if !found {
- p.ResponseCode(session, code.LeagueFlagBgNotExist)
- return
- }
- if flagBgRow.FlagType != enum.League_FlagBg {
- p.ResponseCode(session, code.LeagueFlagBgError)
- return
- }
- // 检测旗帜图标是否存在
- flagIconRow, found := data.LeagueFlag.GetByFlagID(flagIcon)
- if !found {
- p.ResponseCode(session, code.LeagueFlagIconNotExist)
- return
- }
- if flagIconRow.FlagType != enum.League_FlagIcon {
- p.ResponseCode(session, code.LeagueFlagIconError)
- return
- }
- // TODO 设置旗帜是否需要扣除道具/设置冷却时间
- // 设置旗帜
- leagueTable.LeagueInfo.FlagBg = flagBg
- leagueTable.LeagueInfo.FlagIcon = flagIcon
- leagueTable.Save2Queue()
- resp := &pb.I32I32{
- Key: leagueTable.LeagueInfo.FlagBg,
- Value: leagueTable.LeagueInfo.FlagIcon,
- }
- p.Response(session, resp)
- }
- // 申请入盟通知
- func (p *actorLeague) leagueJoinApplyNotice(leaderID int64, leagueMemberTable *db.MapLeagueMemberTable, applyPlayerID int64) {
- playerList := leagueMemberTable.LeagueMember.GetPlayerListByPermission(leaderID, enum.League_Permission_Member)
- for _, playerID := range playerList {
- session, found := sessions.GetSession(playerID)
- if !found {
- continue
- }
- resp := &pb.I64{
- Value: applyPlayerID,
- }
- sessions.PushWithSession(session, nameRoute.PushLeague_AddApply, resp)
- }
- }
- // 联盟日志列表
- func (p *actorLeague) leagueLogList(session *cproto.Session, req *pb.I32) {
- _, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueLogTable, found := db.GetMapLeagueLogTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueLogDataNotExist)
- return
- }
- var (
- logType = req.Value
- resp = &pb.LeagueLogList{}
- )
- leagueLogList := leagueLogTable.LeagueLogType.GetLeagueLogs(logType)
- if len(leagueLogList) > 0 {
- for _, leagueLog := range leagueLogList {
- resp.List = append(resp.List, leagueLog.ToProto())
- }
- }
- p.Response(session, resp)
- }
- // 联盟驻地迁入
- func (p *actorLeague) leagueResidenceBack(session *cproto.Session, req *pb.I32) {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- build, found := leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
- if !found {
- p.ResponseCode(session, code.LeagueResidenceNotExist)
- return
- }
- // 正在建造中
- if build.BuildEndTime > ctime.Now().ToMillisecond() {
- p.ResponseCode(session, code.LeagueResidenceBuilding)
- return
- }
- // 检测下标是否正确
- index := req.Value
- if index < 0 || !data.IsInnerSceneFoundation(index) {
- p.ResponseCode(session, code.IllegalArgument)
- return
- }
- _, found = leagueTable.Residences.Get(index)
- if found {
- p.ResponseCode(session, code.LeagueResidenceHadMember)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- playerID := sessions.GetPlayerID(session)
- if found = leagueMemberTable.CheckMemberExist(playerID); !found {
- p.ResponseCode(session, code.LeagueMemberNotExist)
- return
- }
- var (
- gameNodeID = sessions.GetGameNodeID(session)
- costs = data.Const.GetLeagueResidenceBackCost()
- )
- // 执行迁入奖励扣除
- _, errCode := actorRemote.GamePlayer.AssetSub(gameNodeID, playerID, costs, ao.LeagueResidenceBackCost)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- // 执行入驻流程
- _, errCode = mapCall.Logic.RelocateBack(playerID, p.leagueID)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- residence := &dbLeague.Residence{
- PlayerID: playerID,
- }
- leagueTable.Residences[index] = residence
- // 通知所有成员
- p.LeagueResidenceNotice(leagueMemberTable.GetLeagueMemberIDs(), index, playerID)
- p.ResponseCode(session, code.OK)
- }
- // 联盟驻地迁出
- func (p *actorLeague) leagueResidenceRemove(req *pb.I64) int32 {
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- return code.LeagueNotExist
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- return code.LeagueMembersEmpty
- }
- // 如果当前玩家是联盟成员 移除驻地信息
- if leagueMemberTable.LeagueMember.CheckMemberExist(req.Value) {
- targetPlayerID := req.Value
- if ok := leagueTable.RemoveResidence(targetPlayerID); ok {
- p.LeagueResidenceRemoveNotice(leagueMemberTable.GetLeagueMemberIDs(), targetPlayerID)
- }
- }
- return code.OK
- }
- // 被动迁入驻地
- func (p *actorLeague) forceResidenceBack(req *pb.I64) {
- playerID := req.Value
- p.Debug("[forceRelocateBack] PlayerID = %d", playerID)
- _, found := p.leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
- if !found {
- p.Debug("[forceRelocateBack] league point not exist: PlayerID = %d", playerID)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- return
- }
- if found = leagueMemberTable.CheckMemberExist(playerID); !found {
- p.Debug("[forceRelocateBack] Player %d not in league", playerID)
- return
- }
- foundIndex := int32(-1)
- // 给成员随机一个位置
- for _, index := range rand.Perm(len(data.InnerScene())) {
- if !data.IsInnerSceneFoundation(int32(index)) {
- continue
- }
- if _, found := p.leagueTable.Residences.Get(int32(index)); !found {
- foundIndex = int32(index)
- break
- }
- }
- if foundIndex == -1 {
- p.Debug("[forceRelocateBack] no empty index for Player: %d", playerID)
- return
- }
- residence := &dbLeague.Residence{
- PlayerID: playerID,
- }
- p.leagueTable.Residences.Put(foundIndex, residence)
- // 通知所有成员
- p.LeagueResidenceNotice(leagueMemberTable.GetLeagueMemberIDs(), foundIndex, playerID)
- }
- // 驻地迁入通知
- func (p *actorLeague) LeagueResidenceNotice(members []int64, index int32, playerID int64) {
- if len(members) <= 0 {
- return
- }
- proto := &pb.LeagueResidence{
- Index: index,
- PlayerID: playerID,
- PlayerName: leagueMember.Service().GetPlayerName(playerID),
- }
- // 通知在线联盟成员
- for _, memberPlayerID := range members {
- session, found := sessions.GetSession(memberPlayerID)
- if found {
- sessions.PushWithSession(session, nameRoute.PushMapLeague_ResidenceChange, proto)
- }
- }
- }
- // 驻地迁出通知
- func (p *actorLeague) LeagueResidenceRemoveNotice(members []int64, playerID int64) {
- if len(members) <= 0 {
- return
- }
- proto := &pb.I64{
- Value: playerID,
- }
- // 通知在线联盟成员
- for _, memberPlayerID := range members {
- session, found := sessions.GetSession(memberPlayerID)
- if found {
- sessions.PushWithSession(session, nameRoute.PushMapLeague_ResidenceRemove, proto)
- }
- }
- }
- // 联盟地图标记
- func (p *actorLeague) leagueMapMark(session *cproto.Session, req *pb.MapMarkRequest) {
- var (
- opPlayerID = sessions.GetPlayerID(session)
- title = req.Title
- desc = req.Desc
- point = req.Point
- command = req.Command
- markID, ok = data.PointToTileID(point.X, point.Y)
- )
- if !ok {
- p.ResponseCode(session, code.MapGetPointFail)
- return
- }
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- _, found = leagueTable.MapMarks.Get(markID)
- if found {
- p.ResponseCode(session, code.MapMark_AlreadyExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- // 检查权限
- if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command) {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- // 判断是否达到上限
- if leagueTable.MapMarks.Size() >= data.Const.LeagueMapMarkNumLimit {
- p.ResponseCode(session, code.MapMark_NumLimit)
- return
- }
- // 判断标题和描述长度是否合法
- if !data.Const.CheckLeagueMapMarkTitle(title) {
- p.ResponseCode(session, code.MapMark_TitleLenLimit)
- return
- }
- if !data.Const.CheckLeagueMapMarkDesc(desc) {
- p.ResponseCode(session, code.MapMark_DescLenLimit)
- return
- }
- // 检测指令是否合法
- if constant.IsMapMarkCommandFail(command) {
- p.ResponseCode(session, code.MapMark_CommandNotExist)
- return
- }
- mapMark := &dbLeague.MapMark{
- Title: title,
- Desc: desc,
- Point: types.NewPoint(point.X, point.Y),
- Command: command,
- MarkTime: ctime.Now().ToSecond(),
- }
- leagueTable.MapMarks.Put(markID, mapMark)
- leagueTable.Save2Queue()
- // 广播给所有联盟成员
- p.mapMarkChangePush(leagueMemberTable.GetLeagueMemberIDs(), markID)
- // 发送指挥邮件
- p.SendLeagueMail(leagueMemberTable, opPlayerID, 0, enum.MailType_Command, title, desc, false)
- p.ResponseCode(session, code.OK)
- }
- // 删除联盟地图标记
- func (p *actorLeague) leagueMapMarkDelete(session *cproto.Session, req *pb.I32) {
- var (
- opPlayerID = sessions.GetPlayerID(session)
- markID = req.Value
- )
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command)
- if !ok {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- if ok = leagueTable.DeleteMapMark(markID); !ok {
- p.ResponseCode(session, code.MapMark_NotExist)
- return
- }
- leagueTable.Save2Queue()
- // 广播给所有在线成员
- p.mapMarkDelPush(leagueMemberTable.GetLeagueMemberIDs(), markID)
- p.ResponseCode(session, code.OK)
- }
- // 联盟标记更新
- func (p *actorLeague) leagueMapMarkEdit(session *cproto.Session, req *pb.MapMarkEditRequest) {
- var (
- opPlayerID = sessions.GetPlayerID(session)
- markID = req.MarkID
- )
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueNotExist)
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- p.ResponseCode(session, code.LeagueMembersEmpty)
- return
- }
- ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command)
- if !ok {
- p.ResponseCode(session, code.LeaguePermissionDenied)
- return
- }
- mapMark, found := leagueTable.MapMarks.Get(markID)
- if !found {
- p.ResponseCode(session, code.MapMark_NotExist)
- return
- }
- // 内容不变
- if mapMark.Title == req.Title && mapMark.Desc == req.Desc && mapMark.Command == req.Command {
- p.ResponseCode(session, code.MapMark_NotChange)
- return
- }
- mapMark.Title = req.Title
- mapMark.Desc = req.Desc
- mapMark.Command = req.Command
- mapMark.MarkTime = ctime.Now().ToSecond()
- leagueTable.Save2Queue()
- // 广播给所有在线成员
- p.mapMarkChangePush(leagueMemberTable.GetLeagueMemberIDs(), markID)
- // 发送指挥邮件
- p.SendLeagueMail(leagueMemberTable, opPlayerID, 0, enum.MailType_Command, mapMark.Title, mapMark.Desc, false)
- p.ResponseCode(session, code.OK)
- }
- // 联盟地图标记列表推送
- func (p *actorLeague) mapMarkChangePush(members []int64, markID int32) {
- if len(members) <= 0 {
- return
- }
- leagueTable, found := db.GetMapLeagueTable(p.leagueID)
- if !found {
- return
- }
- mapMark, found := leagueTable.MapMarks.Get(markID)
- if !found {
- return
- }
- proto := mapMark.ToProto(markID)
- // 通知所有在线成员
- for _, memberPlayerID := range members {
- session, found := sessions.GetSession(memberPlayerID)
- if found {
- sessions.PushWithSession(session, nameRoute.PushMapLeague_MapMarkChange, proto)
- }
- }
- }
- // 删除联盟地图标记通知
- func (p *actorLeague) mapMarkDelPush(members []int64, markID int32) {
- if len(members) <= 0 {
- return
- }
- proto := &pb.I32{
- Value: markID,
- }
- for _, memberPlayerID := range members {
- session, found := sessions.GetSession(memberPlayerID)
- if found {
- sessions.PushWithSession(session, nameRoute.PushMapLeague_MapMarkDel, proto)
- }
- }
- }
- // 联盟成员声望更新
- func (p *actorLeague) leagueMemberPrestige(e cfacade.IEventData) {
- evt, ok := e.(*event.PrestigeUpdate)
- if !ok {
- return
- }
- leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
- if !found {
- return
- }
- if exist := leagueMemberTable.CheckMemberExist(evt.PlayerID()); !exist {
- return
- }
- // 刷新联盟排行
- leagueBase.Service().SyncLeaguePrestigeRank(p.leagueTable, leagueMemberTable)
- }
|