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

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