Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / serialize / DungeonRoomInfo.cs
@小李xl 小李xl on 2 Sep 2023 2 KB 删除房间功能
  1.  
  2. using System.Collections.Generic;
  3. using System.Text.Json.Serialization;
  4.  
  5. /// <summary>
  6. /// 房间配置数据
  7. /// </summary>
  8. public class DungeonRoomInfo
  9. {
  10. /// <summary>
  11. /// 房间位置, 在tile坐标系中的位置, 单位: 格
  12. /// </summary>
  13. [JsonInclude]
  14. public SerializeVector2 Position;
  15. /// <summary>
  16. /// 房间大小, 在tile坐标系中占用的格子, 单位: 格
  17. /// </summary>
  18. [JsonInclude]
  19. public SerializeVector2 Size;
  20. /// <summary>
  21. /// 房间连通门
  22. /// </summary>
  23. [JsonInclude]
  24. public List<DoorAreaInfo> DoorAreaInfos;
  25.  
  26. /// <summary>
  27. /// 当前房间所属分组的名称
  28. /// </summary>
  29. [JsonInclude]
  30. public string GroupName;
  31. /// <summary>
  32. /// 房间类型
  33. /// </summary>
  34. [JsonInclude]
  35. public DungeonRoomType RoomType = DungeonRoomType.Battle;
  36.  
  37. /// <summary>
  38. /// 房间名称
  39. /// </summary>
  40. [JsonInclude]
  41. public string RoomName;
  42. /// <summary>
  43. /// 房间权重, 值越大, 生成地牢是越容易出现该房间
  44. /// </summary>
  45. [JsonInclude]
  46. public int Weight = ResourceManager.DefaultWeight;
  47.  
  48. /// <summary>
  49. /// 房间备注
  50. /// </summary>
  51. [JsonInclude]
  52. public string Remark;
  53.  
  54. private List<DoorAreaInfo> _completionDoorArea;
  55.  
  56. /// <summary>
  57. /// 获取门区域配置数据, 如果该函数会自动填充未配置的数据
  58. /// </summary>
  59. public List<DoorAreaInfo> GetCompletionDoorArea()
  60. {
  61. if (_completionDoorArea == null)
  62. {
  63. //需要处理 DoorAreaInfos 长度为 0 的房间, 并为其配置默认值
  64. _completionDoorArea = new List<DoorAreaInfo>(DoorAreaInfos);
  65. if (_completionDoorArea.Count == 0)
  66. {
  67. _completionDoorArea.Add(new DoorAreaInfo(DoorDirection.N, GameConfig.TileCellSize, ((int)Size.X - 1) * GameConfig.TileCellSize));
  68. _completionDoorArea.Add(new DoorAreaInfo(DoorDirection.S, GameConfig.TileCellSize, ((int)Size.X - 1) * GameConfig.TileCellSize));
  69. _completionDoorArea.Add(new DoorAreaInfo(DoorDirection.W, GameConfig.TileCellSize, ((int)Size.Y - 1) * GameConfig.TileCellSize));
  70. _completionDoorArea.Add(new DoorAreaInfo(DoorDirection.E, GameConfig.TileCellSize, ((int)Size.Y - 1) * GameConfig.TileCellSize));
  71. }
  72. }
  73. return _completionDoorArea;
  74. }
  75.  
  76. /// <summary>
  77. /// 清除门区域配置数据, 再次调用 GetCompletionDoorArea() 会重新计算 DoorAreaInfo 数据
  78. /// </summary>
  79. public void ClearCompletionDoorArea()
  80. {
  81. if (_completionDoorArea != null)
  82. {
  83. _completionDoorArea.Clear();
  84. _completionDoorArea = null;
  85. }
  86. }
  87. }