Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / room / World.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Godot;
  4.  
  5. /// <summary>
  6. /// 游戏世界
  7. /// </summary>
  8. public partial class World : CanvasModulate, ICoroutine
  9. {
  10. /// <summary>
  11. /// 当前的游戏世界对象
  12. /// </summary>
  13. public static World Current => GameApplication.Instance.World;
  14. /// <summary>
  15. /// //对象根节点
  16. /// </summary>
  17. [Export] public Node2D NormalLayer;
  18. /// <summary>
  19. /// 对象根节点, 带y轴排序功能
  20. /// </summary>
  21. [Export] public Node2D YSortLayer;
  22. /// <summary>
  23. /// 地图根节点
  24. /// </summary>
  25. [Export] public TileMap TileRoot;
  26.  
  27. [Export] public Node2D StaticSpriteRoot;
  28. [Export] public Node2D AffiliationAreaRoot;
  29. [Export] public Node2D FogMaskRoot;
  30. [Export] public Node2D NavigationRoot;
  31. /// <summary>
  32. /// 是否暂停
  33. /// </summary>
  34. public bool Pause
  35. {
  36. get => _pause;
  37. set
  38. {
  39. if (_pause != value)
  40. {
  41. _pause = value;
  42. if (value)
  43. {
  44. ProcessMode = ProcessModeEnum.WhenPaused;
  45. }
  46. else
  47. {
  48. ProcessMode = ProcessModeEnum.Inherit;
  49. }
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 所有被扔在地上的武器
  55. /// </summary>
  56. public HashSet<Weapon> Weapon_UnclaimedWeapons { get; } = new HashSet<Weapon>();
  57. /// <summary>
  58. /// 记录所有存活的敌人
  59. /// </summary>
  60. public List<Enemy> Enemy_InstanceList { get; } = new List<Enemy>();
  61. private bool _pause = false;
  62. private List<CoroutineData> _coroutineList;
  63.  
  64. public override void _Ready()
  65. {
  66. //Color = Colors.Black;
  67. //临时处理, 加载TileSet
  68. var tileSet = ResourceManager.Load<TileSet>(ResourcePath.resource_tileSet_map2_TileSet2_tres);
  69. //var tileSet = ResourceManager.Load<TileSet>(ResourcePath.resource_tileSet_map1_TileSet1_tres);
  70. //var tileSetAtlasSource = (TileSetAtlasSource)tileSet.GetSource(0);
  71. //tileSetAtlasSource.Texture = ImageTexture.CreateFromImage(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
  72. TileRoot.TileSet = tileSet;
  73. //TileRoot.YSortEnabled = false;
  74. }
  75.  
  76. public override void _Process(double delta)
  77. {
  78. //协程更新
  79. ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, (float)delta);
  80. }
  81.  
  82. /// <summary>
  83. /// 获取指定层级根节点
  84. /// </summary>
  85. public Node2D GetRoomLayer(RoomLayerEnum layerEnum)
  86. {
  87. switch (layerEnum)
  88. {
  89. case RoomLayerEnum.NormalLayer:
  90. return NormalLayer;
  91. case RoomLayerEnum.YSortLayer:
  92. return YSortLayer;
  93. }
  94.  
  95. return null;
  96. }
  97.  
  98. /// <summary>
  99. /// 通知其他敌人发现目标了
  100. /// </summary>
  101. /// <param name="self">发送通知的角色</param>
  102. /// <param name="target">目标</param>
  103. public void NotifyEnemyTarget(Role self, ActivityObject target)
  104. {
  105. foreach (var role in Enemy_InstanceList)
  106. {
  107. if (role != self && !role.IsDestroyed && role.AffiliationArea == self.AffiliationArea)
  108. {
  109. //将未发现目标的敌人状态置为惊讶状态
  110. var controller = role.StateController;
  111. //延时通知效果
  112. role.CallDelay(Utils.Random.RandomRangeFloat(0.2f, 1f), () =>
  113. {
  114. if (controller.CurrState == AIStateEnum.AiNormal)
  115. {
  116. controller.ChangeState(AIStateEnum.AiLeaveFor, target);
  117. }
  118. });
  119. }
  120. }
  121. }
  122. public long StartCoroutine(IEnumerator able)
  123. {
  124. return ProxyCoroutineHandler.ProxyStartCoroutine(ref _coroutineList, able);
  125. }
  126. public void StopCoroutine(long coroutineId)
  127. {
  128. ProxyCoroutineHandler.ProxyStopCoroutine(ref _coroutineList, coroutineId);
  129. }
  130.  
  131. public bool IsCoroutineOver(long coroutineId)
  132. {
  133. return ProxyCoroutineHandler.ProxyIsCoroutineOver(ref _coroutineList, coroutineId);
  134. }
  135.  
  136. public void StopAllCoroutine()
  137. {
  138. ProxyCoroutineHandler.ProxyStopAllCoroutine(ref _coroutineList);
  139. }
  140. }