init.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package mapLogic
  2. import (
  3. "f1-game/internal/types"
  4. "f1-game/nodes/map/internal/db"
  5. mapTypes "f1-game/nodes/map/internal/types"
  6. capp "github.com/cherry-game/cherry/facade"
  7. )
  8. func Init(app capp.IApplication, mapTables *db.LogicTables, playerTables map[int64]*db.MapPlayerTable, leagueTables map[int64]*db.MapLeagueTable) {
  9. // 初始化联盟pb数据
  10. initLeagues(leagueTables)
  11. mapBornPos := initMapBornPos(mapTables)
  12. bornLimit := initStateBornLimit(playerTables)
  13. // 初始化 logic 数据
  14. actorLogic := NewActor(mapTables, mapBornPos, bornLimit)
  15. app.ActorSystem().CreateActor(actorLogic.AliasID(), actorLogic)
  16. }
  17. func initLeagues(leagueTables map[int64]*db.MapLeagueTable) {
  18. for _, league := range leagueTables {
  19. pbMapLeagues[league.LeagueID] = league.ToMapLeague()
  20. }
  21. }
  22. func initMapBornPos(mapTables *db.LogicTables) mapTypes.MapBornPos {
  23. mapBornPos := mapTypes.NewBornPos()
  24. // 过滤出生点
  25. // 系统建筑不会占领出生点
  26. // 玩家建筑占领的出生点
  27. for _, buildTable := range mapTables.BuildTables {
  28. mapBornPos.Remove(buildTable.GetTiles()...)
  29. }
  30. // TODO 集结中的怪物占领的出生点
  31. return mapBornPos
  32. }
  33. func initStateBornLimit(playerTables map[int64]*db.MapPlayerTable) types.Map[int32, int32] {
  34. bornLimit := types.NewMap[int32, int32]()
  35. for _, playerTable := range playerTables {
  36. if !playerTable.IsSelectBornState() {
  37. continue
  38. }
  39. bornLimit[playerTable.BornStateID]++
  40. }
  41. return bornLimit
  42. }