| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- 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"
- 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"
- leagueStorage "f1-game/nodes/map/league/storage"
- "math/rand/v2"
- ctime "github.com/cherry-game/cherry/extend/time"
- 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)
- }
- 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 {
- league.LeaguePrestige = leagueMemberTable.GetMemberPrestige()
- }
- 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, &pb.LeagueJoinNotice{
- LeagueID: p.leagueID,
- LeagueName: p.leagueTable.LeagueInfo.LeagueName,
- CastleConfigIDs: p.leagueTable.Castles.GetConfigIDs(),
- })
- 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)
- p.ResponseCode(session, code.OK)
- // 联盟升级推送
- leagueBase.Service().LeagueUpgradPush(leagueTable, leagueMemberTable)
- }
- // 获取入盟申请列表
- 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, &pb.LeagueJoinNotice{
- LeagueID: p.leagueID,
- LeagueName: p.leagueTable.LeagueInfo.LeagueName,
- CastleConfigIDs: p.leagueTable.Castles.GetConfigIDs(),
- })
- 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, &pb.LeagueJoinNotice{
- LeagueID: p.leagueID,
- LeagueName: p.leagueTable.LeagueInfo.LeagueName,
- CastleConfigIDs: p.leagueTable.Castles.GetConfigIDs(),
- })
- 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 leagueTable.LeagueInfo.ClearApplyList() {
- 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 utils.CheckStrLen(leagueNotice, data.Const.LeagueNoticeLimit) {
- 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 leagueTable.RemoveResidence(targetPlayerID) {
- 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: leagueBase.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)
- }
- }
- }
|