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.

126 lines
3.7KB

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