league_tech.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package mapLeague
  2. import (
  3. "f1-game/internal/code"
  4. "f1-game/internal/data"
  5. "f1-game/internal/enum"
  6. "f1-game/internal/event"
  7. nameLocal "f1-game/internal/name/local"
  8. nameRoute "f1-game/internal/name/route"
  9. "f1-game/internal/pb"
  10. "f1-game/internal/sessions"
  11. "f1-game/nodes/map/internal/db"
  12. dbLeague "f1-game/nodes/map/internal/db/data/league"
  13. leagueAttr "f1-game/nodes/map/league/attr"
  14. leagueBase "f1-game/nodes/map/league/base"
  15. leagueStorage "f1-game/nodes/map/league/storage"
  16. cstring "github.com/cherry-game/cherry/extend/string"
  17. clog "github.com/cherry-game/cherry/logger"
  18. cproto "github.com/cherry-game/cherry/net/proto"
  19. )
  20. func (p *actorLeague) initTech() {
  21. p.Local().Register(nameLocal.MapLeague_TechList, p.techList)
  22. p.Local().Register(nameLocal.MapLeague_TechUpgrade, p.techUpgrade)
  23. }
  24. // 科技列表
  25. func (p *actorLeague) techList(session *cproto.Session, _ *pb.None) {
  26. p.Response(session, p.leagueTable.Techs.ToProto())
  27. }
  28. // 科技升级
  29. func (p *actorLeague) techUpgrade(session *cproto.Session, req *pb.I32) {
  30. techID := req.GetValue()
  31. if techID < 1 {
  32. p.ResponseCode(session, code.IllegalArgument)
  33. return
  34. }
  35. // 检查当前操作者是否有权限
  36. leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID)
  37. if !found {
  38. p.ResponseCode(session, code.LeagueMembersEmpty)
  39. return
  40. }
  41. opPlayerID := sessions.GetPlayerID(session)
  42. // 权限检查 需要同盟建设权限
  43. ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Construction)
  44. if !ok {
  45. p.ResponseCode(session, code.LeaguePermissionDenied)
  46. return
  47. }
  48. // 检查科技是否解锁
  49. if !p.leagueTable.Techs.CheckUnlock(techID) {
  50. p.ResponseCode(session, code.MapLeague_TechNotUnlock)
  51. return
  52. }
  53. tech, found := p.leagueTable.Techs.Techs.Get(techID)
  54. if !found {
  55. tech = dbLeague.NewTech(techID)
  56. }
  57. // 检查前置条件
  58. if !p.leagueTable.Techs.CheckPreTech(techID, tech.Level) {
  59. p.ResponseCode(session, code.MapLeague_TechUpPreConditionNotMet)
  60. return
  61. }
  62. // 检查科技等级上限
  63. if !data.LeagueTechLevel.ContainTechIDLevel(techID, tech.Level+1) {
  64. p.ResponseCode(session, code.MapLeague_TechUpLevelLimit)
  65. return
  66. }
  67. techRow, ok := data.LeagueTechLevel.GetByTechIDLevel(techID, tech.Level)
  68. if !ok {
  69. p.ResponseCode(session, code.MapLeague_TechUpLevelLimit)
  70. return
  71. }
  72. // 扣除联盟资源
  73. p.subAssets(techRow.UpgradeCost)
  74. tech.Level++
  75. p.leagueTable.Techs.Techs.Put(techID, tech)
  76. // 更新属性
  77. leagueAttr.Service().UpdateAttrs(p.leagueTable)
  78. p.leagueTable.Save2Queue()
  79. // 检查更新仓库容量
  80. leagueStorage.Service().CheckAndInitCapacity(p.leagueTable)
  81. p.Response(session, tech.ToProto())
  82. // 记录日志
  83. leagueLogTable, _ := db.GetMapLeagueLogTable(p.leagueID)
  84. // TODO 只消耗一种资源,如果策划改了就需要增加日志ID,不能修改原有的ID
  85. costAsset := techRow.UpgradeCost[0]
  86. leagueLogTable.AddLeagueLog(enum.Log_LeagueTechUpgradeCost, leagueBase.Service().GetPlayerName(opPlayerID), cstring.ToString(costAsset.ID), cstring.ToString(costAsset.Num), cstring.ToString(tech.TechID))
  87. p.PostEvent(event.NewLeagueTechUpgrade(p.leagueID, tech.TechID, tech.Level))
  88. // 通知前端更新属性
  89. p.Push(session, nameRoute.PushLeague_AttrChange, p.leagueTable.LeagueInfo.Attrs.ToProto())
  90. clog.Debugf("techUp success: %+v", tech)
  91. }