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.

SpawnPoint.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 {typeof(SpawnPoint).Name} block");
  24. }
  25. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  26. {
  27. try
  28. {
  29. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  30. position, uscale, scale, player, rotation);
  31. Sync();
  32. return new SpawnPoint(id);
  33. }
  34. catch (Exception e)
  35. {
  36. Logging.MetaDebugLog(e);
  37. }
  38. }
  39. return null;
  40. }
  41. public SpawnPoint(EGID id) : base(id)
  42. {
  43. if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
  44. {
  45. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  46. }
  47. }
  48. public SpawnPoint(uint id) : base(id)
  49. {
  50. if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
  51. {
  52. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  53. }
  54. }
  55. // custom spawn point properties
  56. /// <summary>
  57. /// The lives the player spawns in with.
  58. /// </summary>
  59. public uint Lives
  60. {
  61. get
  62. {
  63. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).lives;
  64. }
  65. set
  66. {
  67. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  68. spses.lives = value;
  69. }
  70. }
  71. /// <summary>
  72. /// Whether the spawned player can take damage.
  73. /// </summary>
  74. public bool Damageable
  75. {
  76. get
  77. {
  78. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).canTakeDamage;
  79. }
  80. set
  81. {
  82. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  83. spses.canTakeDamage = value;
  84. }
  85. }
  86. /// <summary>
  87. /// Whether the game over screen will be displayed
  88. /// </summary>
  89. public bool GameOverEnabled
  90. {
  91. get
  92. {
  93. return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).gameOverScreen;
  94. }
  95. set
  96. {
  97. ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
  98. spses.gameOverScreen = value;
  99. }
  100. }
  101. /// <summary>
  102. /// The team id for players who spawn here.
  103. /// </summary>
  104. public byte Team
  105. {
  106. get
  107. {
  108. return BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id).teamId;
  109. }
  110. set
  111. {
  112. ref SpawnPointIdsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id);
  113. spses.teamId = value;
  114. }
  115. }
  116. }
  117. }