league_base.go 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. package mapLeague
  2. import (
  3. actorRemote "f1-game/internal/actor_remote"
  4. "f1-game/internal/code"
  5. "f1-game/internal/component/redis"
  6. "f1-game/internal/constant"
  7. "f1-game/internal/data"
  8. "f1-game/internal/enum"
  9. "f1-game/internal/event"
  10. "f1-game/internal/extend/utils"
  11. nameEvent "f1-game/internal/name/event"
  12. nameLocal "f1-game/internal/name/local"
  13. nameRedis "f1-game/internal/name/redis"
  14. nameRemote "f1-game/internal/name/remote"
  15. nameRoute "f1-game/internal/name/route"
  16. "f1-game/internal/pb"
  17. "f1-game/internal/sessions"
  18. "f1-game/internal/types"
  19. ao "f1-game/nodes/game/player/asset/origin"
  20. mapCall "f1-game/nodes/map/internal/call"
  21. "f1-game/nodes/map/internal/db"
  22. dbLeague "f1-game/nodes/map/internal/db/data/league"
  23. leagueAttr "f1-game/nodes/map/league/attr"
  24. leagueBase "f1-game/nodes/map/league/base"
  25. leagueMember "f1-game/nodes/map/league/member"
  26. leagueStorage "f1-game/nodes/map/league/storage"
  27. "math/rand/v2"
  28. ctime "github.com/cherry-game/cherry/extend/time"
  29. cfacade "github.com/cherry-game/cherry/facade"
  30. cproto "github.com/cherry-game/cherry/net/proto"
  31. )
  32. func (p *actorLeague) initLeagueBase() {
  33. p.Local().Register(nameLocal.MapLeague_Upgrade, p.leagueUpgrade)
  34. p.Local().Register(nameLocal.MapLeague_ApplyList, p.leagueApplyList)
  35. p.Local().Register(nameLocal.MapLeague_ApplyOption, p.leagueApplyOption)
  36. p.Local().Register(nameLocal.MapLeague_ApplyAgreeAll, p.leagueApplyAgreeAll)
  37. p.Local().Register(nameLocal.MapLeague_ClearApplyList, p.leagueClearApplyList)
  38. p.Local().Register(nameLocal.MapLeague_Setting, p.leagueSetting)
  39. p.Local().Register(nameLocal.MapLeague_FlagSet, p.leagueFlagSet)
  40. p.Local().Register(nameLocal.MapLeague_LogList, p.leagueLogList)
  41. p.Local().Register(nameLocal.MapLeague_ResidenceBack, p.leagueResidenceBack)
  42. p.Local().Register(nameLocal.MapLeague_MapMark, p.leagueMapMark)
  43. p.Local().Register(nameLocal.MapLeague_MapMarkEdit, p.leagueMapMarkEdit)
  44. p.Local().Register(nameLocal.MapLeague_MapMarkDelete, p.leagueMapMarkDelete)
  45. p.Remote().Register(nameRemote.MapLeague_Info, p.leagueInfo)
  46. p.Remote().Register(nameRemote.MapLeague_ResidenceRemove, p.leagueResidenceRemove)
  47. p.Remote().Register(nameRemote.MapLeague_ForceResidenceBack, p.forceResidenceBack)
  48. p.Remote().Register(nameRemote.MapLeague_Join, p.leagueJoin)
  49. p.Event().Register(nameEvent.Map_PlayerPrestigeUpdate, p.leagueMemberPrestige)
  50. }
  51. func (p *actorLeague) leagueInfo(req *pb.I64) (*pb.League, int32) {
  52. leagueID := req.Value
  53. leagueTable, found := db.GetMapLeagueTable(leagueID)
  54. if !found {
  55. return nil, code.LeagueNotExist
  56. }
  57. league := leagueTable.ToLeagueInfoProto()
  58. // 设置联盟名称 // TODO 后续改成缓存的map直接读取map的
  59. if len(league.Diplomacy.Applys) > 0 {
  60. for _, apply := range league.Diplomacy.Applys {
  61. leagueTable, found := db.GetMapLeagueTable(apply.LeagueID)
  62. if found {
  63. apply.LeagueName = leagueTable.LeagueInfo.LeagueName
  64. }
  65. }
  66. }
  67. leagueMemberTable, found := db.GetMapLeagueMemberTable(leagueID)
  68. if found {
  69. totalPrestige := int32(0)
  70. list := redis.Game.GetPlayerDataList(leagueMemberTable.GetLeagueMemberIDs(), nameRedis.Player_Prestige)
  71. if len(list) > 0 {
  72. for _, playerData := range list {
  73. totalPrestige += playerData.Prestige
  74. }
  75. }
  76. league.LeaguePrestige = totalPrestige
  77. }
  78. return league, code.OK
  79. }
  80. // apply 加入联盟
  81. func (p *actorLeague) leagueJoin(req *pb.I64I32) int32 {
  82. var (
  83. playerID = req.Key
  84. mainCityLevel = req.Value
  85. )
  86. if playerID < 1 || p.leagueID < 1 {
  87. return code.IllegalArgument
  88. }
  89. //判断联盟是否存在 获取联盟信息
  90. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  91. if !found {
  92. return code.LeagueNotExist
  93. }
  94. // 判断是否提交过申请
  95. if leagueTable.LeagueInfo.CheckApplyExist(playerID) {
  96. return code.LeagueApplyRepeat
  97. }
  98. // 判断玩家等级是否满足
  99. if mainCityLevel < leagueTable.LeagueInfo.JoinNeedLevel {
  100. return code.LeagueNeedLevelNotEnough
  101. }
  102. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  103. if !found {
  104. return code.LeagueMembersEmpty
  105. }
  106. //判断当前联盟是否已满人 如果满人则拒绝入会申请
  107. if leagueMemberTable.GetLeagueMemberCount() >= leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit) {
  108. return code.LeagueMembersLimit
  109. }
  110. // 申请需要审批
  111. if leagueTable.LeagueInfo.IsJoinApproval() {
  112. // 添加申请记录
  113. leagueTable.LeagueInfo.AddApply(playerID)
  114. // 通知可处理申请的在线管理(有人员权限的管理员)
  115. p.leagueJoinApplyNotice(leagueTable.LeagueInfo.LeaderID, leagueMemberTable, playerID)
  116. } else {
  117. errCode := actorRemote.MapPlayer.LeagueJoin(playerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
  118. if code.IsFail(errCode) {
  119. p.Warn("[leagueJoin] player fail. leagueID:%d, playerID:%d", p.leagueID, playerID)
  120. return errCode
  121. }
  122. // 成功 加入联盟
  123. p.doLeagueMemberJoin(leagueTable, leagueMemberTable, playerID)
  124. }
  125. leagueTable.Save2Queue()
  126. return code.OK
  127. }
  128. // 联盟升级
  129. func (p *actorLeague) leagueUpgrade(session *cproto.Session, _ *pb.None) {
  130. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  131. if !found {
  132. p.ResponseCode(session, code.LeagueNotExist)
  133. return
  134. }
  135. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  136. if !found {
  137. p.ResponseCode(session, code.LeagueMembersEmpty)
  138. return
  139. }
  140. // 检测是否有权限
  141. opPlayerID := sessions.GetPlayerID(session)
  142. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Construction)
  143. if !ok {
  144. p.ResponseCode(session, code.LeaguePermissionDenied)
  145. return
  146. }
  147. var (
  148. curLevel = leagueTable.LeagueInfo.Level
  149. nextLevel = curLevel + 1
  150. )
  151. curLevelRow, found := data.LeagueLevel.GetByLevel(curLevel)
  152. if !found {
  153. p.ResponseCode(session, code.LeagueLevelConfigNotExist)
  154. return
  155. }
  156. // 已达最大等级
  157. if curLevelRow.Exp.Value <= 0 {
  158. p.ResponseCode(session, code.LeagueMaxLevel)
  159. return
  160. }
  161. // 获取下一等级配置
  162. _, found = data.LeagueLevel.GetByLevel(nextLevel)
  163. if !found {
  164. p.ResponseCode(session, code.LeagueLevelConfigNotExist)
  165. return
  166. }
  167. assets := types.Assets{
  168. {ID: curLevelRow.Exp.Key, Num: int64(curLevelRow.Exp.Value)},
  169. }
  170. errCode := p.subAssets(assets)
  171. if code.IsFail(errCode) {
  172. p.ResponseCode(session, errCode)
  173. return
  174. }
  175. leagueTable.LeagueInfo.Level = nextLevel
  176. // 更新属性
  177. leagueAttr.Service().UpdateAttrs(leagueTable)
  178. leagueTable.Save2Queue()
  179. objectID := int64(0)
  180. build, found := leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
  181. if found {
  182. objectID = build.ObjectID
  183. }
  184. p.PostEvent(event.NewLeagueUpgrade(p.leagueID, objectID, leagueTable.LeagueInfo.Level))
  185. // 检查更新仓库容量
  186. leagueStorage.Service().CheckAndInitCapacity(leagueTable)
  187. resp := &pb.I32I32{
  188. Key: leagueTable.LeagueInfo.Level,
  189. Value: leagueTable.LeagueInfo.Exp,
  190. }
  191. p.Response(session, resp)
  192. // 通知前端更新属性,看需不需要给所有成员推送
  193. p.Push(session, nameRoute.PushLeague_AttrChange, leagueTable.LeagueInfo.Attrs.ToProto())
  194. }
  195. // 获取入盟申请列表
  196. func (p *actorLeague) leagueApplyList(session *cproto.Session, _ *pb.None) {
  197. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  198. if !found {
  199. p.ResponseCode(session, code.LeagueNotExist)
  200. return
  201. }
  202. var (
  203. list = []*pb.LeagueApply{}
  204. playerIDs = []int64{}
  205. )
  206. for _, pair := range leagueTable.LeagueInfo.LeagueApplys {
  207. apply := &pb.LeagueApply{
  208. PlayerID: pair.Key,
  209. ApplyTime: pair.Value,
  210. }
  211. list = append(list, apply)
  212. playerIDs = append(playerIDs, pair.Key)
  213. }
  214. if len(playerIDs) > 0 {
  215. // 获取玩家基础信息
  216. playerDataMap := redis.Game.GetPlayerDataMap(playerIDs, nameRedis.PlayerBaseFields...)
  217. if len(playerDataMap) > 0 {
  218. for _, apply := range list {
  219. playerData, found := playerDataMap[apply.PlayerID]
  220. if found {
  221. apply.PlayerName = playerData.PlayerName
  222. apply.Level = playerData.LordLevel
  223. }
  224. }
  225. }
  226. }
  227. resp := &pb.LeagueApplyList{
  228. List: list,
  229. }
  230. p.Response(session, resp)
  231. }
  232. // 联盟申请处理 拒绝/通过
  233. func (p *actorLeague) leagueApplyOption(session *cproto.Session, req *pb.I64Bool) {
  234. var (
  235. opPlayerID = sessions.GetPlayerID(session)
  236. targetPlayerID = req.Key
  237. isArgee = req.Value
  238. )
  239. if targetPlayerID < 1 {
  240. p.ResponseCode(session, code.IllegalArgument)
  241. return
  242. }
  243. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  244. if !found {
  245. p.ResponseCode(session, code.LeagueNotExist)
  246. return
  247. }
  248. // 检测申请是否存在
  249. if !leagueTable.LeagueInfo.CheckApplyExist(targetPlayerID) {
  250. p.ResponseCode(session, code.LeagueApplyNotExist)
  251. return
  252. }
  253. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  254. if !found {
  255. p.ResponseCode(session, code.LeagueMembersEmpty)
  256. return
  257. }
  258. if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Member) {
  259. p.ResponseCode(session, code.LeaguePermissionDenied)
  260. return
  261. }
  262. errCode := code.OK
  263. //通过申请
  264. if isArgee {
  265. // 判断玩家是否已存在联盟中
  266. if leagueMemberTable.CheckMemberExist(targetPlayerID) {
  267. p.ResponseCode(session, code.LeagueAlreadyJoin)
  268. return
  269. }
  270. // 判断联盟人数是否已满
  271. if leagueMemberTable.GetLeagueMemberCount() >= leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit) {
  272. p.ResponseCode(session, code.LeagueMembersLimit)
  273. return
  274. }
  275. errCode := actorRemote.MapPlayer.LeagueJoin(targetPlayerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
  276. if code.IsOK(errCode) {
  277. // 成功 加入联盟
  278. p.doLeagueMemberJoin(leagueTable, leagueMemberTable, targetPlayerID)
  279. }
  280. }
  281. // 不管通过还是拒绝 都需要移除申请记录
  282. leagueTable.LeagueInfo.RemoveApply(targetPlayerID)
  283. leagueTable.Save2Queue()
  284. p.ResponseCode(session, errCode)
  285. }
  286. // 一键同意入盟申请
  287. func (p *actorLeague) leagueApplyAgreeAll(session *cproto.Session, _ *pb.None) {
  288. opPlayerID := sessions.GetPlayerID(session)
  289. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  290. if !found {
  291. p.ResponseCode(session, code.LeagueMembersEmpty)
  292. return
  293. }
  294. if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Member) {
  295. p.ResponseCode(session, code.LeaguePermissionDenied)
  296. return
  297. }
  298. if p.leagueTable.LeagueInfo.LeagueApplys.IsEmpty() {
  299. p.ResponseCode(session, code.LeagueApplyNotExist)
  300. return
  301. }
  302. var (
  303. curMemberCount = leagueMemberTable.GetLeagueMemberCount()
  304. memberCountLimit = p.leagueTable.LeagueInfo.Attrs.GetI32(enum.LeagueAttrMemberCountLimit)
  305. )
  306. // 判断联盟人数是否已满
  307. if curMemberCount >= memberCountLimit {
  308. p.ResponseCode(session, code.LeagueMembersLimit)
  309. return
  310. }
  311. var (
  312. removeApplys = []int64{}
  313. joinPlayerIDs = []int64{}
  314. )
  315. for _, pair := range p.leagueTable.LeagueInfo.LeagueApplys {
  316. targetPlayerID := pair.Key
  317. // 判断玩家是否已存在联盟中
  318. if exist := leagueMemberTable.CheckMemberExist(targetPlayerID); exist {
  319. removeApplys = append(removeApplys, targetPlayerID)
  320. continue
  321. }
  322. errCode := actorRemote.MapPlayer.LeagueJoin(targetPlayerID, p.leagueID, p.leagueTable.LeagueInfo.LeagueName)
  323. if code.IsOK(errCode) {
  324. joinPlayerIDs = append(joinPlayerIDs, targetPlayerID)
  325. curMemberCount++
  326. }
  327. removeApplys = append(removeApplys, targetPlayerID)
  328. // 检测联盟成员数是否超出上限
  329. if curMemberCount >= memberCountLimit {
  330. break
  331. }
  332. }
  333. // 添加加入联盟的玩家
  334. if len(joinPlayerIDs) > 0 {
  335. p.doLeagueMemberJoin(p.leagueTable, leagueMemberTable, joinPlayerIDs...)
  336. }
  337. if len(removeApplys) > 0 {
  338. // 删除入盟申请
  339. p.leagueTable.LeagueInfo.RemoveApply(removeApplys...)
  340. p.leagueTable.Save2Queue()
  341. }
  342. resp := &pb.I64List{
  343. List: removeApplys,
  344. }
  345. p.Response(session, resp)
  346. }
  347. // 清除联盟申请列表
  348. func (p *actorLeague) leagueClearApplyList(session *cproto.Session, _ *pb.None) {
  349. opPlayerID := sessions.GetPlayerID(session)
  350. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  351. if !found {
  352. p.ResponseCode(session, code.LeagueNotExist)
  353. return
  354. }
  355. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  356. if !found {
  357. p.ResponseCode(session, code.LeagueMembersEmpty)
  358. return
  359. }
  360. // 判断玩家是否有权处理
  361. if !leagueMemberTable.LeagueMember.CheckPermission(opPlayerID, enum.League_Permission_Member) {
  362. p.ResponseCode(session, code.LeaguePermissionDenied)
  363. return
  364. }
  365. // 清除申请列表
  366. if ok := leagueTable.LeagueInfo.ClearApplyList(); ok {
  367. leagueTable.Save2Queue()
  368. }
  369. p.ResponseCode(session, code.OK)
  370. }
  371. // 入盟等级&审批&公告设置
  372. func (p *actorLeague) leagueSetting(session *cproto.Session, req *pb.LeagueBaseSetting) {
  373. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  374. if !found {
  375. p.ResponseCode(session, code.LeagueNotExist)
  376. return
  377. }
  378. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  379. if !found {
  380. p.ResponseCode(session, code.LeagueMembersEmpty)
  381. return
  382. }
  383. // 判断玩家是否有权限 需要外交权限
  384. opPlayerID := sessions.GetPlayerID(session)
  385. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Diplomacy)
  386. if !ok {
  387. p.ResponseCode(session, code.LeaguePermissionDenied)
  388. return
  389. }
  390. var (
  391. update = false
  392. needApprove = req.NeedApprove
  393. levelLimit = req.LevelLimit
  394. leagueNotice = req.LeagueNotice
  395. )
  396. if leagueTable.LeagueInfo.JoinApproval != needApprove {
  397. leagueTable.LeagueInfo.JoinApproval = needApprove
  398. update = true
  399. }
  400. if leagueTable.LeagueInfo.JoinNeedLevel != levelLimit {
  401. // 判断等级是否存在
  402. maxLevel := data.FacilityLevel.GetMaxLevel(enum.Facility_MainID)
  403. if 0 <= levelLimit && levelLimit <= maxLevel {
  404. leagueTable.LeagueInfo.JoinNeedLevel = levelLimit
  405. update = true
  406. }
  407. }
  408. if leagueTable.LeagueInfo.LeagueNotice != leagueNotice {
  409. if ok := utils.CheckStrLen(leagueNotice, data.Const.LeagueNoticeLimit); ok {
  410. leagueTable.LeagueInfo.LeagueNotice = leagueNotice
  411. update = true
  412. }
  413. }
  414. if update {
  415. leagueTable.Save2Queue()
  416. }
  417. resp := &pb.LeagueBaseSetting{
  418. NeedApprove: leagueTable.LeagueInfo.JoinApproval,
  419. LevelLimit: leagueTable.LeagueInfo.JoinNeedLevel,
  420. LeagueNotice: leagueTable.LeagueInfo.LeagueNotice,
  421. }
  422. p.Response(session, resp)
  423. }
  424. // 联盟旗帜设置
  425. func (p *actorLeague) leagueFlagSet(session *cproto.Session, req *pb.I32I32) {
  426. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  427. if !found {
  428. p.ResponseCode(session, code.LeagueNotExist)
  429. return
  430. }
  431. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  432. if !found {
  433. p.ResponseCode(session, code.LeagueMembersEmpty)
  434. return
  435. }
  436. // 判断玩家是否有权限 需要外交权限
  437. opPlayerID := sessions.GetPlayerID(session)
  438. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Diplomacy)
  439. if !ok {
  440. p.ResponseCode(session, code.LeaguePermissionDenied)
  441. return
  442. }
  443. var (
  444. flagBg = req.Key
  445. flagIcon = req.Value
  446. )
  447. // 检测旗帜背景是否存在
  448. flagBgRow, found := data.LeagueFlag.GetByFlagID(flagBg)
  449. if !found {
  450. p.ResponseCode(session, code.LeagueFlagBgNotExist)
  451. return
  452. }
  453. if flagBgRow.FlagType != enum.League_FlagBg {
  454. p.ResponseCode(session, code.LeagueFlagBgError)
  455. return
  456. }
  457. // 检测旗帜图标是否存在
  458. flagIconRow, found := data.LeagueFlag.GetByFlagID(flagIcon)
  459. if !found {
  460. p.ResponseCode(session, code.LeagueFlagIconNotExist)
  461. return
  462. }
  463. if flagIconRow.FlagType != enum.League_FlagIcon {
  464. p.ResponseCode(session, code.LeagueFlagIconError)
  465. return
  466. }
  467. // TODO 设置旗帜是否需要扣除道具/设置冷却时间
  468. // 设置旗帜
  469. leagueTable.LeagueInfo.FlagBg = flagBg
  470. leagueTable.LeagueInfo.FlagIcon = flagIcon
  471. leagueTable.Save2Queue()
  472. resp := &pb.I32I32{
  473. Key: leagueTable.LeagueInfo.FlagBg,
  474. Value: leagueTable.LeagueInfo.FlagIcon,
  475. }
  476. p.Response(session, resp)
  477. }
  478. // 申请入盟通知
  479. func (p *actorLeague) leagueJoinApplyNotice(leaderID int64, leagueMemberTable *db.MapLeagueMemberTable, applyPlayerID int64) {
  480. playerList := leagueMemberTable.LeagueMember.GetPlayerListByPermission(leaderID, enum.League_Permission_Member)
  481. for _, playerID := range playerList {
  482. session, found := sessions.GetSession(playerID)
  483. if !found {
  484. continue
  485. }
  486. resp := &pb.I64{
  487. Value: applyPlayerID,
  488. }
  489. sessions.PushWithSession(session, nameRoute.PushLeague_AddApply, resp)
  490. }
  491. }
  492. // 联盟日志列表
  493. func (p *actorLeague) leagueLogList(session *cproto.Session, req *pb.I32) {
  494. _, found := db.GetMapLeagueTable(p.leagueID)
  495. if !found {
  496. p.ResponseCode(session, code.LeagueNotExist)
  497. return
  498. }
  499. leagueLogTable, found := db.GetMapLeagueLogTable(p.leagueID)
  500. if !found {
  501. p.ResponseCode(session, code.LeagueLogDataNotExist)
  502. return
  503. }
  504. var (
  505. logType = req.Value
  506. resp = &pb.LeagueLogList{}
  507. )
  508. leagueLogList := leagueLogTable.LeagueLogType.GetLeagueLogs(logType)
  509. if len(leagueLogList) > 0 {
  510. for _, leagueLog := range leagueLogList {
  511. resp.List = append(resp.List, leagueLog.ToProto())
  512. }
  513. }
  514. p.Response(session, resp)
  515. }
  516. // 联盟驻地迁入
  517. func (p *actorLeague) leagueResidenceBack(session *cproto.Session, req *pb.I32) {
  518. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  519. if !found {
  520. p.ResponseCode(session, code.LeagueNotExist)
  521. return
  522. }
  523. build, found := leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
  524. if !found {
  525. p.ResponseCode(session, code.LeagueResidenceNotExist)
  526. return
  527. }
  528. // 正在建造中
  529. if build.BuildEndTime > ctime.Now().ToMillisecond() {
  530. p.ResponseCode(session, code.LeagueResidenceBuilding)
  531. return
  532. }
  533. // 检测下标是否正确
  534. index := req.Value
  535. if index < 0 || !data.IsInnerSceneFoundation(index) {
  536. p.ResponseCode(session, code.IllegalArgument)
  537. return
  538. }
  539. _, found = leagueTable.Residences.Get(index)
  540. if found {
  541. p.ResponseCode(session, code.LeagueResidenceHadMember)
  542. return
  543. }
  544. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  545. if !found {
  546. p.ResponseCode(session, code.LeagueMembersEmpty)
  547. return
  548. }
  549. playerID := sessions.GetPlayerID(session)
  550. if found = leagueMemberTable.CheckMemberExist(playerID); !found {
  551. p.ResponseCode(session, code.LeagueMemberNotExist)
  552. return
  553. }
  554. var (
  555. gameNodeID = sessions.GetGameNodeID(session)
  556. costs = data.Const.GetLeagueResidenceBackCost()
  557. )
  558. // 执行迁入奖励扣除
  559. _, errCode := actorRemote.GamePlayer.AssetSub(gameNodeID, playerID, costs, ao.LeagueResidenceBackCost)
  560. if code.IsFail(errCode) {
  561. p.ResponseCode(session, errCode)
  562. return
  563. }
  564. // 执行入驻流程
  565. _, errCode = mapCall.Logic.RelocateBack(playerID, p.leagueID)
  566. if code.IsFail(errCode) {
  567. p.ResponseCode(session, errCode)
  568. return
  569. }
  570. residence := &dbLeague.Residence{
  571. PlayerID: playerID,
  572. }
  573. leagueTable.Residences[index] = residence
  574. // 通知所有成员
  575. p.LeagueResidenceNotice(leagueMemberTable.GetLeagueMemberIDs(), index, playerID)
  576. p.ResponseCode(session, code.OK)
  577. }
  578. // 联盟驻地迁出
  579. func (p *actorLeague) leagueResidenceRemove(req *pb.I64) int32 {
  580. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  581. if !found {
  582. return code.LeagueNotExist
  583. }
  584. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  585. if !found {
  586. return code.LeagueMembersEmpty
  587. }
  588. // 如果当前玩家是联盟成员 移除驻地信息
  589. if leagueMemberTable.LeagueMember.CheckMemberExist(req.Value) {
  590. targetPlayerID := req.Value
  591. if ok := leagueTable.RemoveResidence(targetPlayerID); ok {
  592. p.LeagueResidenceRemoveNotice(leagueMemberTable.GetLeagueMemberIDs(), targetPlayerID)
  593. }
  594. }
  595. return code.OK
  596. }
  597. // 被动迁入驻地
  598. func (p *actorLeague) forceResidenceBack(req *pb.I64) {
  599. playerID := req.Value
  600. p.Debug("[forceRelocateBack] PlayerID = %d", playerID)
  601. _, found := p.leagueTable.Builds.GetByType(constant.MapBuild_LeaguePoint)
  602. if !found {
  603. p.Debug("[forceRelocateBack] league point not exist: PlayerID = %d", playerID)
  604. return
  605. }
  606. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  607. if !found {
  608. return
  609. }
  610. if found = leagueMemberTable.CheckMemberExist(playerID); !found {
  611. p.Debug("[forceRelocateBack] Player %d not in league", playerID)
  612. return
  613. }
  614. foundIndex := int32(-1)
  615. // 给成员随机一个位置
  616. for _, index := range rand.Perm(len(data.InnerScene())) {
  617. if !data.IsInnerSceneFoundation(int32(index)) {
  618. continue
  619. }
  620. if _, found := p.leagueTable.Residences.Get(int32(index)); !found {
  621. foundIndex = int32(index)
  622. break
  623. }
  624. }
  625. if foundIndex == -1 {
  626. p.Debug("[forceRelocateBack] no empty index for Player: %d", playerID)
  627. return
  628. }
  629. residence := &dbLeague.Residence{
  630. PlayerID: playerID,
  631. }
  632. p.leagueTable.Residences.Put(foundIndex, residence)
  633. // 通知所有成员
  634. p.LeagueResidenceNotice(leagueMemberTable.GetLeagueMemberIDs(), foundIndex, playerID)
  635. }
  636. // 驻地迁入通知
  637. func (p *actorLeague) LeagueResidenceNotice(members []int64, index int32, playerID int64) {
  638. if len(members) <= 0 {
  639. return
  640. }
  641. proto := &pb.LeagueResidence{
  642. Index: index,
  643. PlayerID: playerID,
  644. PlayerName: leagueMember.Service().GetPlayerName(playerID),
  645. }
  646. // 通知在线联盟成员
  647. for _, memberPlayerID := range members {
  648. session, found := sessions.GetSession(memberPlayerID)
  649. if found {
  650. sessions.PushWithSession(session, nameRoute.PushMapLeague_ResidenceChange, proto)
  651. }
  652. }
  653. }
  654. // 驻地迁出通知
  655. func (p *actorLeague) LeagueResidenceRemoveNotice(members []int64, playerID int64) {
  656. if len(members) <= 0 {
  657. return
  658. }
  659. proto := &pb.I64{
  660. Value: playerID,
  661. }
  662. // 通知在线联盟成员
  663. for _, memberPlayerID := range members {
  664. session, found := sessions.GetSession(memberPlayerID)
  665. if found {
  666. sessions.PushWithSession(session, nameRoute.PushMapLeague_ResidenceRemove, proto)
  667. }
  668. }
  669. }
  670. // 联盟地图标记
  671. func (p *actorLeague) leagueMapMark(session *cproto.Session, req *pb.MapMarkRequest) {
  672. var (
  673. opPlayerID = sessions.GetPlayerID(session)
  674. title = req.Title
  675. desc = req.Desc
  676. point = req.Point
  677. command = req.Command
  678. markID, ok = data.PointToTileID(point.X, point.Y)
  679. )
  680. if !ok {
  681. p.ResponseCode(session, code.MapGetPointFail)
  682. return
  683. }
  684. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  685. if !found {
  686. p.ResponseCode(session, code.LeagueNotExist)
  687. return
  688. }
  689. _, found = leagueTable.MapMarks.Get(markID)
  690. if found {
  691. p.ResponseCode(session, code.MapMark_AlreadyExist)
  692. return
  693. }
  694. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  695. if !found {
  696. p.ResponseCode(session, code.LeagueMembersEmpty)
  697. return
  698. }
  699. // 检查权限
  700. if !leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command) {
  701. p.ResponseCode(session, code.LeaguePermissionDenied)
  702. return
  703. }
  704. // 判断是否达到上限
  705. if leagueTable.MapMarks.Size() >= data.Const.LeagueMapMarkNumLimit {
  706. p.ResponseCode(session, code.MapMark_NumLimit)
  707. return
  708. }
  709. // 判断标题和描述长度是否合法
  710. if !data.Const.CheckLeagueMapMarkTitle(title) {
  711. p.ResponseCode(session, code.MapMark_TitleLenLimit)
  712. return
  713. }
  714. if !data.Const.CheckLeagueMapMarkDesc(desc) {
  715. p.ResponseCode(session, code.MapMark_DescLenLimit)
  716. return
  717. }
  718. // 检测指令是否合法
  719. if constant.IsMapMarkCommandFail(command) {
  720. p.ResponseCode(session, code.MapMark_CommandNotExist)
  721. return
  722. }
  723. mapMark := &dbLeague.MapMark{
  724. Title: title,
  725. Desc: desc,
  726. Point: types.NewPoint(point.X, point.Y),
  727. Command: command,
  728. MarkTime: ctime.Now().ToSecond(),
  729. }
  730. leagueTable.MapMarks.Put(markID, mapMark)
  731. leagueTable.Save2Queue()
  732. // 广播给所有联盟成员
  733. p.mapMarkChangePush(leagueMemberTable.GetLeagueMemberIDs(), markID)
  734. // 发送指挥邮件
  735. p.SendLeagueMail(leagueMemberTable, opPlayerID, 0, enum.MailType_Command, title, desc, false)
  736. p.ResponseCode(session, code.OK)
  737. }
  738. // 删除联盟地图标记
  739. func (p *actorLeague) leagueMapMarkDelete(session *cproto.Session, req *pb.I32) {
  740. var (
  741. opPlayerID = sessions.GetPlayerID(session)
  742. markID = req.Value
  743. )
  744. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  745. if !found {
  746. p.ResponseCode(session, code.LeagueNotExist)
  747. return
  748. }
  749. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  750. if !found {
  751. p.ResponseCode(session, code.LeagueMembersEmpty)
  752. return
  753. }
  754. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command)
  755. if !ok {
  756. p.ResponseCode(session, code.LeaguePermissionDenied)
  757. return
  758. }
  759. if ok = leagueTable.DeleteMapMark(markID); !ok {
  760. p.ResponseCode(session, code.MapMark_NotExist)
  761. return
  762. }
  763. leagueTable.Save2Queue()
  764. // 广播给所有在线成员
  765. p.mapMarkDelPush(leagueMemberTable.GetLeagueMemberIDs(), markID)
  766. p.ResponseCode(session, code.OK)
  767. }
  768. // 联盟标记更新
  769. func (p *actorLeague) leagueMapMarkEdit(session *cproto.Session, req *pb.MapMarkEditRequest) {
  770. var (
  771. opPlayerID = sessions.GetPlayerID(session)
  772. markID = req.MarkID
  773. )
  774. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  775. if !found {
  776. p.ResponseCode(session, code.LeagueNotExist)
  777. return
  778. }
  779. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  780. if !found {
  781. p.ResponseCode(session, code.LeagueMembersEmpty)
  782. return
  783. }
  784. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Command)
  785. if !ok {
  786. p.ResponseCode(session, code.LeaguePermissionDenied)
  787. return
  788. }
  789. mapMark, found := leagueTable.MapMarks.Get(markID)
  790. if !found {
  791. p.ResponseCode(session, code.MapMark_NotExist)
  792. return
  793. }
  794. // 内容不变
  795. if mapMark.Title == req.Title && mapMark.Desc == req.Desc && mapMark.Command == req.Command {
  796. p.ResponseCode(session, code.MapMark_NotChange)
  797. return
  798. }
  799. mapMark.Title = req.Title
  800. mapMark.Desc = req.Desc
  801. mapMark.Command = req.Command
  802. mapMark.MarkTime = ctime.Now().ToSecond()
  803. leagueTable.Save2Queue()
  804. // 广播给所有在线成员
  805. p.mapMarkChangePush(leagueMemberTable.GetLeagueMemberIDs(), markID)
  806. // 发送指挥邮件
  807. p.SendLeagueMail(leagueMemberTable, opPlayerID, 0, enum.MailType_Command, mapMark.Title, mapMark.Desc, false)
  808. p.ResponseCode(session, code.OK)
  809. }
  810. // 联盟地图标记列表推送
  811. func (p *actorLeague) mapMarkChangePush(members []int64, markID int32) {
  812. if len(members) <= 0 {
  813. return
  814. }
  815. leagueTable, found := db.GetMapLeagueTable(p.leagueID)
  816. if !found {
  817. return
  818. }
  819. mapMark, found := leagueTable.MapMarks.Get(markID)
  820. if !found {
  821. return
  822. }
  823. proto := mapMark.ToProto(markID)
  824. // 通知所有在线成员
  825. for _, memberPlayerID := range members {
  826. session, found := sessions.GetSession(memberPlayerID)
  827. if found {
  828. sessions.PushWithSession(session, nameRoute.PushMapLeague_MapMarkChange, proto)
  829. }
  830. }
  831. }
  832. // 删除联盟地图标记通知
  833. func (p *actorLeague) mapMarkDelPush(members []int64, markID int32) {
  834. if len(members) <= 0 {
  835. return
  836. }
  837. proto := &pb.I32{
  838. Value: markID,
  839. }
  840. for _, memberPlayerID := range members {
  841. session, found := sessions.GetSession(memberPlayerID)
  842. if found {
  843. sessions.PushWithSession(session, nameRoute.PushMapLeague_MapMarkDel, proto)
  844. }
  845. }
  846. }
  847. // 联盟成员声望更新
  848. func (p *actorLeague) leagueMemberPrestige(e cfacade.IEventData) {
  849. evt, ok := e.(*event.PrestigeUpdate)
  850. if !ok {
  851. return
  852. }
  853. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  854. if !found {
  855. return
  856. }
  857. if exist := leagueMemberTable.CheckMemberExist(evt.PlayerID()); !exist {
  858. return
  859. }
  860. // 刷新联盟排行
  861. leagueBase.Service().SyncLeaguePrestigeRank(p.leagueTable, leagueMemberTable)
  862. }