actor_build.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package mapLogic
  2. import (
  3. "f1-game/internal/constant"
  4. "f1-game/internal/data"
  5. "f1-game/internal/enum"
  6. "f1-game/internal/event"
  7. "f1-game/internal/extend/times"
  8. "f1-game/internal/pb"
  9. "f1-game/internal/types"
  10. mapCall "f1-game/nodes/map/internal/call"
  11. "f1-game/nodes/map/internal/db"
  12. mapTypes "f1-game/nodes/map/internal/types"
  13. clog "github.com/cherry-game/cherry/logger"
  14. )
  15. func (p *actor) addBuildAOI(buildTable *db.LogicBuildTable) {
  16. marker := buildTable.ToAOIMarker()
  17. mapCall.AOI.Enter(marker)
  18. }
  19. func (p *actor) buildTimer() {
  20. p.updateTime()
  21. for _, buildTable := range p.BuildTables {
  22. // 不处理隐藏建筑
  23. if !buildTable.IsHide {
  24. p.buildTicker(buildTable)
  25. }
  26. if buildTable.IsDataChanged {
  27. buildTable.IsDataChanged = false
  28. buildTable.Save2Queue()
  29. }
  30. if buildTable.IsDelete {
  31. p.BuildTables.Remove(buildTable.ObjectID)
  32. }
  33. }
  34. }
  35. func (p *actor) buildTicker(buildTable *db.LogicBuildTable) {
  36. // 正在建造中
  37. if buildTable.IsBuilding {
  38. if buildTable.CheckFinish(p.nowMillis) {
  39. p.buildFinish(buildTable)
  40. }
  41. } else if buildTable.IsUpgrading {
  42. // 正在升级中
  43. if buildTable.CheckUpgradeFinish(p.nowMillis) {
  44. p.buildUpgradeFinish(buildTable)
  45. }
  46. }
  47. // 放弃中
  48. if buildTable.IsDiscard() {
  49. p.doBuildDiscard(buildTable)
  50. }
  51. // 攻城判断
  52. if buildTable.IsBeingSiege() {
  53. p.buildSiegeCheck(buildTable)
  54. }
  55. // 加固开启
  56. if buildTable.IsReinforceOpen() {
  57. p.buildReinforce(buildTable)
  58. }
  59. }
  60. // 加固处理
  61. func (p *actor) buildReinforce(buildTable *db.LogicBuildTable) {
  62. if p.nowMillis >= buildTable.Reinforce.EndTime {
  63. if buildTable.IsReinforcePreparing() {
  64. buildTable.Reinforce.ChangeStage(enum.ReinforceStage_Effect, p.nowMillis+data.Const.GetMapReinforceEffectTime())
  65. clog.Debugf("change reinforce: playerID = %v, stage = %s, endTime = %s",
  66. buildTable.PlayerID,
  67. enum.GetReinforceStageName(buildTable.Reinforce.Stage),
  68. times.MillisToDatetimeFormat(buildTable.Reinforce.EndTime))
  69. // 在 watcher 上记录冷却时间
  70. watcherTable := p.WatcherTables.GetValue(buildTable.PlayerID)
  71. watcherTable.ReinforceCooldown = p.nowMillis + data.Const.GetMapReinforceCooldown()
  72. watcherTable.Save2Queue()
  73. // AOI 通知
  74. mapCall.AOI.UpdateAll(buildTable.ObjectID, buildTable.Type)
  75. } else if buildTable.IsReinforceEffecting() {
  76. buildTable.Reinforce.ChangeStage(enum.ReinforceStage_None, 0)
  77. clog.Debugf("change reinforce: playerID = %v, stage = %ss",
  78. buildTable.PlayerID,
  79. enum.GetReinforceStageName(buildTable.Reinforce.Stage))
  80. }
  81. buildTable.IsDataChanged = true
  82. }
  83. }
  84. // 检查建筑的攻城状态
  85. func (p *actor) buildSiegeCheck(buildTable *db.LogicBuildTable) {
  86. for tileID := range buildTable.SiegeTiles {
  87. tileTable := p.TileTables.GetValue(tileID)
  88. // 判断是否有攻城的和掠夺的
  89. if !tileTable.HasSiege() && !tileTable.HasSnatch() {
  90. buildTable.RemoveSiegeTile(tileID)
  91. }
  92. }
  93. // 如果没有再被攻城了,通知自动防守部队解散
  94. if !buildTable.IsBeingSiege() {
  95. playerTeams := map[int64][]int32{}
  96. buildTable.AutoDefendList.Range(func(marchObjectID int64, _ *mapTypes.TileMarchInfo) bool {
  97. marchTable := p.MarchTables.GetValue(marchObjectID)
  98. playerTeams[marchTable.PlayerID] = append(playerTeams[marchTable.PlayerID], marchTable.TeamID)
  99. return true
  100. })
  101. buildTable.AutoDefendList.Clear()
  102. buildTable.IsDataChanged = true
  103. if len(playerTeams) > 0 {
  104. for playerID, teamIDs := range playerTeams {
  105. mapCall.Player.AutoDefendQuit(playerID, teamIDs...)
  106. }
  107. }
  108. }
  109. }
  110. func (p *actor) doBuildDiscard(buildTable *db.LogicBuildTable) {
  111. if buildTable.DiscardEndTime > p.nowMillis {
  112. return
  113. }
  114. // 驻守部队修改状态为停留中
  115. tileTable := p.TileTables.GetValue(buildTable.GetTileID())
  116. if tileTable != nil {
  117. tileTable.GarrisonList.Range(func(marchObjectID int64, tileMarchInfo *mapTypes.TileMarchInfo) bool {
  118. marchTable := p.MarchTables.GetValue(marchObjectID)
  119. if marchTable != nil {
  120. // 修改状态为 停留中
  121. p.updateMarchState(marchTable, enum.MarchState_Stay, 0)
  122. // 加入停留队列
  123. tileTable := p.TileTables.GetValue(marchTable.GetTileID())
  124. tileTable.AddStay(marchTable.ObjectID, mapTypes.NewTileMarchInfo(
  125. tileTable.TileID,
  126. marchTable.ObjectID,
  127. p.nowMillis,
  128. ))
  129. p.addTileProcess(tileTable)
  130. }
  131. return true
  132. })
  133. tileTable.GarrisonList.Clear()
  134. tileTable.IsDataChanged = true
  135. }
  136. // 删除建筑
  137. p.buildRemove(buildTable)
  138. }
  139. func (p *actor) buildFinish(buildTable *db.LogicBuildTable) {
  140. clog.Debugf("[buildFinish] ObjectID = %d, ConfigID = %d", buildTable.ObjectID, buildTable.ConfigID)
  141. buildTable.IsBuilding = false
  142. buildTable.IsDataChanged = true
  143. // 重置攻城属性
  144. siegeTable := p.SiegeTables.GetValue(buildTable.ObjectID)
  145. siegeTable.SiegeReset(false)
  146. // 通知客户端
  147. p.UpdateObjectFull(buildTable.ObjectID, buildTable.Type)
  148. // 通知联盟建筑等级更新
  149. if buildTable.BuildType == enum.BuildType_League {
  150. // 发送建筑完成事件
  151. p.PostEvent(event.NewLeagueBuildFinish(buildTable.LeagueID, buildTable.ObjectID, buildTable.Level, false))
  152. }
  153. // 联盟旗帜和联盟驻地要检查领土内的资源点,通知更新
  154. // TODO 一个一个发,是否可以一组发
  155. if buildTable.ConfigID == constant.MapBuild_LeaguePoint || buildTable.ConfigID == constant.MapBuild_LeagueFlag {
  156. buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  157. if ok {
  158. for _, point := range buildRow.GetAffectOffsetPoints(buildTable.X(), buildTable.Y(), false) {
  159. tileID, ok := data.PointToTileID(point.X, point.Y)
  160. if !ok {
  161. continue
  162. }
  163. tileTable, ok := p.TileTables.Get(tileID)
  164. if !ok || tileTable.ResObjectID == 0 {
  165. continue
  166. }
  167. resTable, ok := p.ResTables.Get(tileTable.ResObjectID)
  168. if !ok || !resTable.HasPlayer() || !p.isSameLeague(resTable.LeagueID, tileTable.LeagueID) {
  169. continue
  170. }
  171. // 抛事件
  172. p.PostEvent(event.NewResUpdate(resTable.PlayerID, &event.MapResUpdateData{
  173. ObjectID: resTable.ObjectID,
  174. UpdateType: enum.ResUpdate_InLeagueArea,
  175. InLeagueArea: true,
  176. }))
  177. }
  178. }
  179. }
  180. }
  181. func (p *actor) buildUpgradeFinish(buildTable *db.LogicBuildTable) {
  182. clog.Debugf("[buildUpgradeFinish] ObjectID = %d, ConfigID = %d", buildTable.ObjectID, buildTable.ConfigID)
  183. buildTable.IsUpgrading = false
  184. buildTable.Level = buildTable.Level + 1
  185. buildTable.IsDataChanged = true
  186. // 通知客户端
  187. p.UpdateObjectFull(buildTable.ObjectID, buildTable.Type)
  188. // 通知联盟建筑等级更新
  189. if buildTable.BuildType == enum.BuildType_League {
  190. // 发送联盟建筑升级事件
  191. p.PostEvent(event.NewLeagueBuildFinish(buildTable.LeagueID, buildTable.ObjectID, buildTable.Level, true))
  192. }
  193. }
  194. // buildAdd 增加建筑
  195. func (p *actor) buildAdd(buildTable *db.LogicBuildTable) {
  196. clog.Debugf("[buildAdd] ObjectID = %v, ConfigID = %v", buildTable.ObjectID, buildTable.ConfigID)
  197. buildTable.IsDataChanged = true
  198. // 放入缓存
  199. p.BuildTables.Put(buildTable.ObjectID, buildTable)
  200. // 移除建筑覆盖范围内的资源点,怪物等
  201. for _, point := range buildTable.GetPoints() {
  202. tileID, ok := data.PointToTileID(point.X, point.Y)
  203. if !ok {
  204. continue
  205. }
  206. tileTable := p.TileTables.GetValue(tileID)
  207. if resTable, ok := p.getResTableInTile(tileTable); ok {
  208. p.resDead(resTable)
  209. }
  210. if monsterTable, ok := p.getMonsterTableInTile(tileTable); ok {
  211. p.monsterDead(monsterTable)
  212. tileTable.SetMonsterObjectID(0)
  213. }
  214. }
  215. for _, point := range buildTable.GetPoints() {
  216. tileID, ok := data.PointToTileID(point.X, point.Y)
  217. if !ok {
  218. continue
  219. }
  220. tileTable := p.TileTables.GetValue(tileID)
  221. tileTable.SetBuildObjectID(buildTable.ObjectID)
  222. p.addTileProcess(tileTable)
  223. }
  224. // 剔除被阻挡的出生点
  225. p.bornPos.Remove(buildTable.GetTiles()...)
  226. switch buildTable.ConfigID {
  227. // case constant.MapBuild_SiegeBase:
  228. // // 如果是攻城大营,初始化
  229. // buildTable.SiegeBase = &dbLogic.SiegeBase{}
  230. // buildTable.IsDataChanged = true
  231. case constant.MapBuild_LeagueFlag:
  232. // 如果是联盟旗帜,设置领地
  233. buildRow, _ := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  234. affectPoints := buildRow.GetAffectOffsetPoints(buildTable.X(), buildTable.Y(), true)
  235. for _, point := range affectPoints {
  236. // 跳过阻挡点
  237. if data.MapData().IsPointBlock(point.X, point.Y) {
  238. continue
  239. }
  240. tileID, ok := data.PointToTileID(point.X, point.Y)
  241. if !ok {
  242. continue
  243. }
  244. tileTable := p.TileTables.GetValue(tileID)
  245. tileTable.AddAreaFlagObjectID(buildTable.ObjectID, buildTable.LeagueID)
  246. p.addTileProcess(tileTable)
  247. }
  248. clog.Debugf("cover tile areas: BuildObjectID = %d, BuildConfigID = %d Points = %+v", buildTable.ObjectID, buildTable.ConfigID, affectPoints)
  249. case constant.MapBuild_LeaguePoint:
  250. // 如果是联盟驻地,设置领地
  251. buildRow, _ := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  252. affectPoints := buildRow.GetAffectOffsetPoints(buildTable.X(), buildTable.Y(), true)
  253. for _, point := range affectPoints {
  254. // 跳过阻挡点
  255. if data.MapData().IsPointBlock(point.X, point.Y) {
  256. continue
  257. }
  258. tileID, ok := data.PointToTileID(point.X, point.Y)
  259. if !ok {
  260. continue
  261. }
  262. tileTable := p.TileTables.GetValue(tileID)
  263. tileTable.SetAreaStrongholdObjectID(buildTable.ObjectID, buildTable.LeagueID)
  264. p.addTileProcess(tileTable)
  265. }
  266. clog.Debugf("cover tile areas: BuildObjectID = %d, BuildConfigID = %d Points = %+v", buildTable.ObjectID, buildTable.ConfigID, affectPoints)
  267. }
  268. if buildTable.BuildType == enum.BuildType_League {
  269. mapCall.League.BuildUpdate(buildTable.LeagueID, &pb.BuildUpdate{
  270. ConfigID: buildTable.ConfigID,
  271. ObjectID: buildTable.ObjectID,
  272. X: buildTable.X(),
  273. Y: buildTable.Y(),
  274. IsAdd: true,
  275. })
  276. }
  277. p.addBuildAOI(buildTable)
  278. // 设置动态障碍点
  279. mapCall.PathFind.SetBarriers(buildTable.ToBarrierRequest())
  280. if buildTable.PlayerID != 0 {
  281. p.PushOwnerMapObjectAdd(buildTable.PlayerID, buildTable.ToOwnerMapObjectPb())
  282. }
  283. }
  284. // 移除建筑,isDelete 为true表示真的删除建筑
  285. func (p *actor) buildRemove(buildTable *db.LogicBuildTable) {
  286. // 移除地块建筑并更新关联坐标
  287. for _, point := range buildTable.GetPoints() {
  288. tileID, ok := data.PointToTileID(point.X, point.Y)
  289. if !ok {
  290. continue
  291. }
  292. tileTable := p.TileTables.GetValue(tileID)
  293. tileTable.SetBuildObjectID(0)
  294. p.addTileProcess(tileTable)
  295. }
  296. switch buildTable.ConfigID {
  297. // 联盟旗帜
  298. case constant.MapBuild_LeagueFlag, constant.MapBuild_LeaguePoint:
  299. {
  300. buildRow, _ := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  301. affectPoints := buildRow.GetAffectOffsetPoints(buildTable.X(), buildTable.Y(), true)
  302. for _, point := range affectPoints {
  303. // 跳过阻挡点
  304. if data.MapData().IsPointBlock(point.X, point.Y) {
  305. continue
  306. }
  307. tileID, ok := data.PointToTileID(point.X, point.Y)
  308. if !ok {
  309. continue
  310. }
  311. tileTable := p.TileTables.GetValue(tileID)
  312. if buildTable.ConfigID == constant.MapBuild_LeagueFlag {
  313. // 旗帜移除地块标记
  314. tileTable.RemoveAreaFlagObjectID(buildTable.ObjectID)
  315. } else {
  316. // 领地移除地块标记
  317. tileTable.ClearAreaStrongholdObjectID()
  318. }
  319. // 抛出资源点更新事件
  320. if tileTable.ResObjectID > 0 {
  321. resTable, ok := p.ResTables.Get(tileTable.ResObjectID)
  322. if ok && resTable.HasPlayer() && p.isSameLeague(resTable.LeagueID, buildTable.LeagueID) {
  323. p.PostEvent(event.NewResUpdate(resTable.PlayerID, &event.MapResUpdateData{
  324. ObjectID: resTable.ObjectID,
  325. UpdateType: enum.ResUpdate_InLeagueArea,
  326. InLeagueArea: false,
  327. }))
  328. }
  329. }
  330. p.addTileProcess(tileTable)
  331. }
  332. clog.Debugf("remove cover tile areas: BuildObjectID = %d, BuildConfigID = %d Points = %+v", buildTable.ObjectID, buildTable.ConfigID, affectPoints)
  333. if buildTable.ConfigID == constant.MapBuild_LeaguePoint {
  334. // 抛出联盟驻地被摧毁事件
  335. p.PostEvent(event.NewLeaguePointDestroy(buildTable.LeagueID, buildTable.ObjectID))
  336. // 设置 WatcherTable 的联盟驻地为 0
  337. // TODO: 如何不遍历所有的 WatcherTable 就知道公会有哪些玩家
  338. for _, watcherTable := range p.WatcherTables {
  339. if watcherTable.LeagueID == buildTable.LeagueID {
  340. watcherTable.SetLeaguePoint(0)
  341. clog.Debugf("[buildRemove] SetLeaguePoint. PlayerID = %v, buildID = %v", watcherTable.PlayerID, 0)
  342. }
  343. }
  344. }
  345. }
  346. }
  347. // 只有不是玩家主城的建筑才会删除
  348. if buildTable.ConfigID != constant.MapBuild_MainCity {
  349. buildTable.IsDelete = true
  350. buildTable.IsDataChanged = true
  351. // 移除对象的攻城表
  352. siegeTable := p.SiegeTables.GetValue(buildTable.ObjectID)
  353. siegeTable.IsDelete = true
  354. siegeTable.Save2Queue()
  355. p.SiegeTables.Remove(siegeTable.ObjectID)
  356. } else {
  357. buildTable.IsHide = true
  358. buildTable.IsDataChanged = true
  359. }
  360. if buildTable.PlayerID > 0 {
  361. // 玩家的建筑
  362. watcherTable := p.WatcherTables.GetValue(buildTable.PlayerID)
  363. watcherTable.RemoveBuild(buildTable.ObjectID)
  364. } else if buildTable.LeagueID > 0 {
  365. // 联盟的建筑
  366. mapCall.League.BuildUpdate(buildTable.LeagueID, &pb.BuildUpdate{
  367. ConfigID: buildTable.ConfigID,
  368. ObjectID: buildTable.ObjectID,
  369. X: buildTable.X(),
  370. Y: buildTable.Y(),
  371. IsAdd: false,
  372. })
  373. }
  374. if buildTable.PlayerID != 0 {
  375. p.PushOwnerMapObjectDel(buildTable.PlayerID, buildTable.ObjectID)
  376. }
  377. // 移出 AOI
  378. mapCall.AOI.Leave(buildTable.ObjectID, buildTable.Type)
  379. // 移除动态障碍点
  380. mapCall.PathFind.RemoveBarriers(buildTable.OffsetPoints)
  381. // 移除建筑补充被覆盖的资源点
  382. p.resReplenish(buildTable.GetPoints())
  383. // 回收出生点
  384. p.bornPos.Recycle(buildTable.GetTiles()...)
  385. }
  386. func (p *actor) getBuild(playerID int64, configID int32) (*db.LogicBuildTable, bool) {
  387. for _, build := range p.BuildTables {
  388. if build.PlayerID == playerID && build.ConfigID == configID {
  389. return build, true
  390. }
  391. }
  392. return nil, false
  393. }
  394. // 获取联盟驻地
  395. // TODO: 优化掉这个方法,看看哪些地方调用了这个方法,看看能否通过其它方式传递 leaguePoint 的 ObjectID 进来直接查
  396. func (p *actor) getLeaguePoint(leagueID int64) (*db.LogicBuildTable, bool) {
  397. for _, build := range p.BuildTables {
  398. if build.ConfigID == constant.MapBuild_LeaguePoint && build.LeagueID == leagueID {
  399. return build, true
  400. }
  401. }
  402. return nil, false
  403. }
  404. // isBuildSiege 建筑是否被攻城
  405. func (p *actor) isBuildSiege(buildTable *db.LogicBuildTable) bool {
  406. tileTable := p.TileTables.GetValue(buildTable.GetTileID())
  407. if tileTable.HasSiege() {
  408. return true
  409. }
  410. if tileTable.HasChildren() {
  411. for _, point := range tileTable.ChildPoints() {
  412. tileID, ok := data.PointToTileID(point.X, point.Y)
  413. if !ok {
  414. continue
  415. }
  416. childTile := p.TileTables.GetValue(tileID)
  417. if childTile.HasSiege() {
  418. return true
  419. }
  420. }
  421. }
  422. return false
  423. }
  424. // isPointInBuildingRange 判断一个点是否在建筑范围内
  425. // TODO: 优化掉这个方法
  426. func (p *actor) isPointInBuildingRange(buildTable *db.LogicBuildTable, point types.Point) bool {
  427. if buildTable.Point.X == point.X && buildTable.Point.Y == point.Y {
  428. return true
  429. }
  430. buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  431. if ok {
  432. affectOffsetPoints := buildRow.GetAffectOffsetPoints(buildTable.Point.X, buildTable.Point.Y, true)
  433. for _, effectPoint := range affectOffsetPoints {
  434. if effectPoint.X == point.X && effectPoint.Y == point.Y {
  435. return true
  436. }
  437. }
  438. }
  439. return false
  440. }
  441. // isCoordInLeagueTerritory 判断一个坐标是否是处于某个联盟的领土
  442. // TODO: 优化掉这个方法
  443. func (p *actor) isCoordInLeagueTerritory(coord types.Point, league int64) bool {
  444. for _, build := range p.BuildTables {
  445. if build.LeagueID != league ||
  446. build.IsBuilding {
  447. continue
  448. }
  449. switch build.ConfigID {
  450. case constant.MapBuild_LeaguePoint,
  451. constant.MapBuild_LeagueFlag:
  452. if p.isPointInBuildingRange(build, coord) {
  453. return true
  454. }
  455. }
  456. }
  457. return false
  458. }
  459. // isTileInLeagueTerritoryAndBorderingOtherLeague 判断一个坐标是否是处于某个联盟的领土并且与另一个联盟接壤
  460. func (p *actor) isTileInLeagueTerritoryAndBorderingOtherLeague(targetTileID int32, targetLeague int64, srcLeague int64) bool {
  461. if srcLeague == 0 {
  462. return false
  463. }
  464. tileTable, ok := p.TileTables.Get(targetTileID)
  465. if !ok || !p.isSameLeague(tileTable.LeagueID, targetLeague) {
  466. return false
  467. }
  468. // 依次判断是否有旗帜、驻地、系统城的领土覆盖
  469. for flagObjectID := range tileTable.AreaFlagObjectIDs {
  470. buildTable, ok := p.BuildTables.Get(flagObjectID)
  471. if !ok || buildTable.IsBuilding {
  472. continue
  473. }
  474. buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  475. if !ok {
  476. continue
  477. }
  478. for _, point := range buildRow.GetAffectEdgePoints(buildTable.Point.X, buildTable.Point.Y) {
  479. tileID, ok := data.PointToTileID(point.X, point.Y)
  480. if !ok {
  481. continue
  482. }
  483. tileTable := p.TileTables.GetValue(tileID)
  484. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  485. return true
  486. }
  487. }
  488. }
  489. // 驻地
  490. if tileTable.AreaStrongholdObjectID > 0 {
  491. buildTable, ok := p.BuildTables.Get(tileTable.AreaStrongholdObjectID)
  492. if ok && !buildTable.IsBuilding {
  493. if buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID); ok {
  494. for _, point := range buildRow.GetAffectEdgePoints(buildTable.Point.X, buildTable.Point.Y) {
  495. tileID, ok := data.PointToTileID(point.X, point.Y)
  496. if !ok {
  497. continue
  498. }
  499. tileTable := p.TileTables.GetValue(tileID)
  500. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  501. return true
  502. }
  503. }
  504. }
  505. }
  506. }
  507. // 系统城
  508. if tileTable.AreaCastleObjectID > 0 {
  509. castleTable, ok := p.CastleTables.Get(tileTable.AreaCastleObjectID)
  510. if ok && !p.isSameLeague(castleTable.LeagueID, srcLeague) {
  511. if castleRow, ok := data.MapCastle.GetByConfigID(castleTable.ConfigID); ok {
  512. for _, point := range castleRow.GetAffectEdgePoints(castleTable.Point.X, castleTable.Point.Y) {
  513. tileID, ok := data.PointToTileID(point.X, point.Y)
  514. if !ok {
  515. continue
  516. }
  517. tileTable := p.TileTables.GetValue(tileID)
  518. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  519. return true
  520. }
  521. }
  522. }
  523. }
  524. }
  525. return false
  526. }
  527. // isPointsConnectedToLeagueTerritory 点是否与目标联盟连接
  528. func (p *actor) isPointsConnectedToLeagueTerritory(points types.Points, leagueID int64) bool {
  529. for _, point := range points {
  530. tileID, ok := data.PointToTileID(point.X, point.Y)
  531. if !ok {
  532. continue
  533. }
  534. tileTable := p.TileTables.GetValue(tileID)
  535. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, leagueID) {
  536. return true
  537. }
  538. }
  539. return false
  540. }
  541. // isLeagueTerritoryBuildingBuiltOnTile 地块上是否有已经建成的联盟领地建筑
  542. func (p *actor) isLeagueTerritoryBuildingBuiltOnTile(tileTable *db.LogicTileTable, leagueID int64) bool {
  543. if tileTable != nil && tileTable.LeagueID == leagueID {
  544. // 旗帜
  545. for objectId := range tileTable.AreaFlagObjectIDs {
  546. tileBuildObj := p.BuildTables.GetValue(objectId)
  547. if tileBuildObj != nil && !tileBuildObj.IsBuilding {
  548. return true
  549. }
  550. }
  551. // 驻地
  552. tileBuildObj := p.BuildTables.GetValue(tileTable.AreaStrongholdObjectID)
  553. if tileBuildObj != nil && !tileBuildObj.IsBuilding {
  554. return true
  555. }
  556. // 系统城
  557. castleTable, ok := p.CastleTables.Get(tileTable.AreaCastleObjectID)
  558. if ok && !p.isSameLeague(castleTable.LeagueID, leagueID) {
  559. return true
  560. }
  561. }
  562. return false
  563. }