actor_build.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. mapCall.AOI.UpdateAll(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. mapCall.AOI.UpdateAll(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. }
  281. // 移除建筑,isDelete 为true表示真的删除建筑
  282. func (p *actor) buildRemove(buildTable *db.LogicBuildTable) {
  283. // 移除地块建筑并更新关联坐标
  284. for _, point := range buildTable.GetPoints() {
  285. tileID, ok := data.PointToTileID(point.X, point.Y)
  286. if !ok {
  287. continue
  288. }
  289. tileTable := p.TileTables.GetValue(tileID)
  290. tileTable.SetBuildObjectID(0)
  291. p.addTileProcess(tileTable)
  292. }
  293. switch buildTable.ConfigID {
  294. // 联盟旗帜
  295. case constant.MapBuild_LeagueFlag, constant.MapBuild_LeaguePoint:
  296. {
  297. buildRow, _ := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  298. affectPoints := buildRow.GetAffectOffsetPoints(buildTable.X(), buildTable.Y(), true)
  299. for _, point := range affectPoints {
  300. // 跳过阻挡点
  301. if data.MapData().IsPointBlock(point.X, point.Y) {
  302. continue
  303. }
  304. tileID, ok := data.PointToTileID(point.X, point.Y)
  305. if !ok {
  306. continue
  307. }
  308. tileTable := p.TileTables.GetValue(tileID)
  309. if buildTable.ConfigID == constant.MapBuild_LeagueFlag {
  310. // 旗帜移除地块标记
  311. tileTable.RemoveAreaFlagObjectID(buildTable.ObjectID)
  312. } else {
  313. // 领地移除地块标记
  314. tileTable.ClearAreaStrongholdObjectID()
  315. }
  316. // 抛出资源点更新事件
  317. if tileTable.ResObjectID > 0 {
  318. resTable, ok := p.ResTables.Get(tileTable.ResObjectID)
  319. if ok && resTable.HasPlayer() && p.isSameLeague(resTable.LeagueID, buildTable.LeagueID) {
  320. p.PostEvent(event.NewResUpdate(resTable.PlayerID, &event.MapResUpdateData{
  321. ObjectID: resTable.ObjectID,
  322. UpdateType: enum.ResUpdate_InLeagueArea,
  323. InLeagueArea: false,
  324. }))
  325. }
  326. }
  327. p.addTileProcess(tileTable)
  328. }
  329. clog.Debugf("remove cover tile areas: BuildObjectID = %d, BuildConfigID = %d Points = %+v", buildTable.ObjectID, buildTable.ConfigID, affectPoints)
  330. if buildTable.ConfigID == constant.MapBuild_LeaguePoint {
  331. // 抛出联盟驻地被摧毁事件
  332. p.PostEvent(event.NewLeaguePointDestroy(buildTable.LeagueID, buildTable.ObjectID))
  333. // 设置 WatcherTable 的联盟驻地为 0
  334. // TODO: 如何不遍历所有的 WatcherTable 就知道公会有哪些玩家
  335. for _, watcherTable := range p.WatcherTables {
  336. if watcherTable.LeagueID == buildTable.LeagueID {
  337. watcherTable.SetLeaguePoint(0)
  338. clog.Debugf("[buildRemove] SetLeaguePoint. PlayerID = %v, buildID = %v", watcherTable.PlayerID, 0)
  339. }
  340. }
  341. }
  342. }
  343. }
  344. // 只有不是玩家主城的建筑才会删除
  345. if buildTable.ConfigID != constant.MapBuild_MainCity {
  346. buildTable.IsDelete = true
  347. buildTable.IsDataChanged = true
  348. // 移除对象的攻城表
  349. siegeTable := p.SiegeTables.GetValue(buildTable.ObjectID)
  350. siegeTable.IsDelete = true
  351. siegeTable.Save2Queue()
  352. p.SiegeTables.Remove(siegeTable.ObjectID)
  353. } else {
  354. buildTable.IsHide = true
  355. buildTable.IsDataChanged = true
  356. }
  357. if buildTable.PlayerID > 0 {
  358. // 玩家的建筑
  359. watcherTable := p.WatcherTables.GetValue(buildTable.PlayerID)
  360. watcherTable.RemoveBuild(buildTable.ObjectID)
  361. } else if buildTable.LeagueID > 0 {
  362. // 联盟的建筑
  363. mapCall.League.BuildUpdate(buildTable.LeagueID, &pb.BuildUpdate{
  364. ConfigID: buildTable.ConfigID,
  365. ObjectID: buildTable.ObjectID,
  366. X: buildTable.X(),
  367. Y: buildTable.Y(),
  368. IsAdd: false,
  369. })
  370. }
  371. // 移出 AOI
  372. mapCall.AOI.Leave(buildTable.ObjectID, buildTable.Type)
  373. // 移除动态障碍点
  374. mapCall.PathFind.RemoveBarriers(buildTable.OffsetPoints)
  375. // 移除建筑补充被覆盖的资源点
  376. p.resReplenish(buildTable.GetPoints())
  377. // 回收出生点
  378. p.bornPos.Recycle(buildTable.GetTiles()...)
  379. }
  380. func (p *actor) getBuild(playerID int64, configID int32) (*db.LogicBuildTable, bool) {
  381. for _, build := range p.BuildTables {
  382. if build.PlayerID == playerID && build.ConfigID == configID {
  383. return build, true
  384. }
  385. }
  386. return nil, false
  387. }
  388. // 获取联盟驻地
  389. // TODO: 优化掉这个方法,看看哪些地方调用了这个方法,看看能否通过其它方式传递 leaguePoint 的 ObjectID 进来直接查
  390. func (p *actor) getLeaguePoint(leagueID int64) (*db.LogicBuildTable, bool) {
  391. for _, build := range p.BuildTables {
  392. if build.ConfigID == constant.MapBuild_LeaguePoint && build.LeagueID == leagueID {
  393. return build, true
  394. }
  395. }
  396. return nil, false
  397. }
  398. // isBuildSiege 建筑是否被攻城
  399. func (p *actor) isBuildSiege(buildTable *db.LogicBuildTable) bool {
  400. tileTable := p.TileTables.GetValue(buildTable.GetTileID())
  401. if tileTable.HasSiege() {
  402. return true
  403. }
  404. if tileTable.HasChildren() {
  405. for _, point := range tileTable.ChildPoints() {
  406. tileID, ok := data.PointToTileID(point.X, point.Y)
  407. if !ok {
  408. continue
  409. }
  410. childTile := p.TileTables.GetValue(tileID)
  411. if childTile.HasSiege() {
  412. return true
  413. }
  414. }
  415. }
  416. return false
  417. }
  418. // isPointInBuildingRange 判断一个点是否在建筑范围内
  419. // TODO: 优化掉这个方法
  420. func (p *actor) isPointInBuildingRange(buildTable *db.LogicBuildTable, point types.Point) bool {
  421. if buildTable.Point.X == point.X && buildTable.Point.Y == point.Y {
  422. return true
  423. }
  424. buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  425. if ok {
  426. affectOffsetPoints := buildRow.GetAffectOffsetPoints(buildTable.Point.X, buildTable.Point.Y, true)
  427. for _, effectPoint := range affectOffsetPoints {
  428. if effectPoint.X == point.X && effectPoint.Y == point.Y {
  429. return true
  430. }
  431. }
  432. }
  433. return false
  434. }
  435. // isCoordInLeagueTerritory 判断一个坐标是否是处于某个联盟的领土
  436. // TODO: 优化掉这个方法
  437. func (p *actor) isCoordInLeagueTerritory(coord types.Point, league int64) bool {
  438. for _, build := range p.BuildTables {
  439. if build.LeagueID != league ||
  440. build.IsBuilding {
  441. continue
  442. }
  443. switch build.ConfigID {
  444. case constant.MapBuild_LeaguePoint,
  445. constant.MapBuild_LeagueFlag:
  446. if p.isPointInBuildingRange(build, coord) {
  447. return true
  448. }
  449. }
  450. }
  451. return false
  452. }
  453. // isTileInLeagueTerritoryAndBorderingOtherLeague 判断一个坐标是否是处于某个联盟的领土并且与另一个联盟接壤
  454. func (p *actor) isTileInLeagueTerritoryAndBorderingOtherLeague(targetTileID int32, targetLeague int64, srcLeague int64) bool {
  455. if srcLeague == 0 {
  456. return false
  457. }
  458. tileTable, ok := p.TileTables.Get(targetTileID)
  459. if !ok || !p.isSameLeague(tileTable.LeagueID, targetLeague) {
  460. return false
  461. }
  462. // 依次判断是否有旗帜、驻地、系统城的领土覆盖
  463. for flagObjectID := range tileTable.AreaFlagObjectIDs {
  464. buildTable, ok := p.BuildTables.Get(flagObjectID)
  465. if !ok || buildTable.IsBuilding {
  466. continue
  467. }
  468. buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID)
  469. if !ok {
  470. continue
  471. }
  472. for _, point := range buildRow.GetAffectEdgePoints(buildTable.Point.X, buildTable.Point.Y) {
  473. tileID, ok := data.PointToTileID(point.X, point.Y)
  474. if !ok {
  475. continue
  476. }
  477. tileTable := p.TileTables.GetValue(tileID)
  478. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  479. return true
  480. }
  481. }
  482. }
  483. // 驻地
  484. if tileTable.AreaStrongholdObjectID > 0 {
  485. buildTable, ok := p.BuildTables.Get(tileTable.AreaStrongholdObjectID)
  486. if ok && !buildTable.IsBuilding {
  487. if buildRow, ok := data.MapBuild.GetByConfigID(buildTable.ConfigID); ok {
  488. for _, point := range buildRow.GetAffectEdgePoints(buildTable.Point.X, buildTable.Point.Y) {
  489. tileID, ok := data.PointToTileID(point.X, point.Y)
  490. if !ok {
  491. continue
  492. }
  493. tileTable := p.TileTables.GetValue(tileID)
  494. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  495. return true
  496. }
  497. }
  498. }
  499. }
  500. }
  501. // 系统城
  502. if tileTable.AreaCastleObjectID > 0 {
  503. castleTable, ok := p.CastleTables.Get(tileTable.AreaCastleObjectID)
  504. if ok && !p.isSameLeague(castleTable.LeagueID, srcLeague) {
  505. if castleRow, ok := data.MapCastle.GetByConfigID(castleTable.ConfigID); ok {
  506. for _, point := range castleRow.GetAffectEdgePoints(castleTable.Point.X, castleTable.Point.Y) {
  507. tileID, ok := data.PointToTileID(point.X, point.Y)
  508. if !ok {
  509. continue
  510. }
  511. tileTable := p.TileTables.GetValue(tileID)
  512. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, srcLeague) {
  513. return true
  514. }
  515. }
  516. }
  517. }
  518. }
  519. return false
  520. }
  521. // isPointsConnectedToLeagueTerritory 点是否与目标联盟连接
  522. func (p *actor) isPointsConnectedToLeagueTerritory(points types.Points, leagueID int64) bool {
  523. for _, point := range points {
  524. tileID, ok := data.PointToTileID(point.X, point.Y)
  525. if !ok {
  526. continue
  527. }
  528. tileTable := p.TileTables.GetValue(tileID)
  529. if tileTable != nil && p.isLeagueTerritoryBuildingBuiltOnTile(tileTable, leagueID) {
  530. return true
  531. }
  532. }
  533. return false
  534. }
  535. // isLeagueTerritoryBuildingBuiltOnTile 地块上是否有已经建成的联盟领地建筑
  536. func (p *actor) isLeagueTerritoryBuildingBuiltOnTile(tileTable *db.LogicTileTable, leagueID int64) bool {
  537. if tileTable != nil && tileTable.LeagueID == leagueID {
  538. // 旗帜
  539. for objectId := range tileTable.AreaFlagObjectIDs {
  540. tileBuildObj := p.BuildTables.GetValue(objectId)
  541. if tileBuildObj != nil && !tileBuildObj.IsBuilding {
  542. return true
  543. }
  544. }
  545. // 驻地
  546. tileBuildObj := p.BuildTables.GetValue(tileTable.AreaStrongholdObjectID)
  547. if tileBuildObj != nil && !tileBuildObj.IsBuilding {
  548. return true
  549. }
  550. // 系统城
  551. castleTable, ok := p.CastleTables.Get(tileTable.AreaCastleObjectID)
  552. if ok && !p.isSameLeague(castleTable.LeagueID, leagueID) {
  553. return true
  554. }
  555. }
  556. return false
  557. }