using System; using RobocraftX.Blocks; using Gamecraft.CharacterVulnerability; using Svelto.ECS; using Unity.Mathematics; using GamecraftModdingAPI; using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { public class SpawnPoint : Block { /// /// Places a new spawn point. /// Any valid spawn block type is accepted. /// This re-implements Block.PlaceNew(...) /// public static new SpawnPoint PlaceNew(BlockIDs block, float3 position, float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0, int uscale = 1, float3 scale = default, Player player = null) { if (!(block == BlockIDs.LargeSpawn || block == BlockIDs.SmallSpawn || block == BlockIDs.MediumSpawn || block == BlockIDs.PlayerSpawn)) { throw new BlockTypeException($"Block is not a {nameof(SpawnPoint)} block"); } if (PlacementEngine.IsInGame && GameState.IsBuildMode()) { EGID id = PlacementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, player, rotation); return new SpawnPoint(id); } return null; } public SpawnPoint(EGID id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } public SpawnPoint(uint id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } // custom spawn point properties /// /// The lives the player spawns in with. /// public uint Lives { get { return BlockEngine.GetBlockInfo(Id).lives; } set { ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo(Id); spses.lives = value; } } /// /// Whether the spawned player can take damage. /// public bool Damageable { get { return BlockEngine.GetBlockInfo(Id).canTakeDamage; } set { ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo(Id); spses.canTakeDamage = value; } } /// /// Whether the game over screen will be displayed /// public bool GameOverEnabled { get { return BlockEngine.GetBlockInfo(Id).gameOverScreen; } set { ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo(Id); spses.gameOverScreen = value; } } /// /// The team id for players who spawn here. /// public byte Team { get { return BlockEngine.GetBlockInfo(Id).teamId; } set { ref SpawnPointIdsEntityStruct spses = ref BlockEngine.GetBlockInfo(Id); spses.teamId = value; } } } }