A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.6KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using Gamecraft.CharacterVulnerability;
  4. using Svelto.ECS;
  5. using Unity.Mathematics;
  6. using GamecraftModdingAPI;
  7. using GamecraftModdingAPI.Utility;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. public class SpawnPoint : Block
  11. {
  12. /// <summary>
  13. /// Places a new spawn point.
  14. /// Any valid spawn block type is accepted.
  15. /// This re-implements Block.PlaceNew(...)
  16. /// </summary>
  17. public static new SpawnPoint PlaceNew(BlockIDs block, float3 position,
  18. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  19. int uscale = 1, float3 scale = default, Player player = null)
  20. {
  21. if (!(block == BlockIDs.LargeSpawn || block == BlockIDs.SmallSpawn || block == BlockIDs.MediumSpawn || block == BlockIDs.PlayerSpawn))
  22. {
  23. throw new BlockTypeException($"Block is not a {nameof(SpawnPoint)} block");
  24. }
  25. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  26. {
  27. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  28. position, uscale, scale, player, rotation);
  29. return new SpawnPoint(id);
  30. }
  31. return null;
  32. }
  33. public SpawnPoint(EGID id) : base(id)
  34. {
  35. if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
  36. {
  37. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  38. }
  39. }
  40. public SpawnPoint(uint id) : base(id)
  41. {
  42. if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
  43. {
  44. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  45. }
  46. }
  47. // custom spawn point properties
  48. /// <summary>
  49. /// The lives the player spawns in with.
  50. /// </summary>
  51. public uint Lives
  52. {
  53. get
  54. {
  55. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).lives;
  56. }
  57. set
  58. {
  59. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  60. spses.lives = value;
  61. }
  62. }
  63. /// <summary>
  64. /// Whether the spawned player can take damage.
  65. /// </summary>
  66. public bool Damageable
  67. {
  68. get
  69. {
  70. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).canTakeDamage;
  71. }
  72. set
  73. {
  74. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  75. spses.canTakeDamage = value;
  76. }
  77. }
  78. /// <summary>
  79. /// Whether the game over screen will be displayed
  80. /// </summary>
  81. public bool GameOverEnabled
  82. {
  83. get
  84. {
  85. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).gameOverScreen;
  86. }
  87. set
  88. {
  89. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  90. spses.gameOverScreen = value;
  91. }
  92. }
  93. /// <summary>
  94. /// The team id for players who spawn here.
  95. /// </summary>
  96. public byte Team
  97. {
  98. get
  99. {
  100. return BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id).teamId;
  101. }
  102. set
  103. {
  104. ref SpawnPointIdsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id);
  105. spses.teamId = value;
  106. }
  107. }
  108. }
  109. }