Spawn point system.

Hey we can place spawn points on the map now instead of hardcoding them!
Spawn points are simply invisible bare bones entities.
This commit is contained in:
Pieter-Jan Briers
2019-03-17 15:52:27 +01:00
parent 8aefe6c615
commit e1f6a2bbd5
14 changed files with 147 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
using Content.Shared.GameObjects.Components.Markers;
using SS14.Client.Interfaces.Console;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
namespace Content.Client.Commands
{
internal sealed class ShowMarkersCommand : IConsoleCommand
{
// ReSharper disable once StringLiteralTypo
public string Command => "togglemarkers";
public string Description => "Toggles visibility of markers such as spawn points.";
public string Help => "";
public bool Execute(IDebugConsole console, params string[] args)
{
bool? whichToSet = null;
foreach (var entity in IoCManager.Resolve<IEntityManager>()
.GetEntities(new TypeEntityQuery(typeof(SharedSpawnPointComponent))))
{
if (!entity.TryGetComponent(out ISpriteComponent sprite))
{
continue;
}
if (!whichToSet.HasValue)
{
whichToSet = !sprite.Visible;
}
sprite.Visible = whichToSet.Value;
}
return false;
}
}
}

View File

@@ -71,6 +71,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Commands\DebugCommands.cs" />
<Compile Include="EntryPoint.cs" /> <Compile Include="EntryPoint.cs" />
<Compile Include="GameObjects\Components\Actor\CharacterInterface.cs" /> <Compile Include="GameObjects\Components\Actor\CharacterInterface.cs" />
<Compile Include="GameObjects\Components\DamageableComponent.cs" /> <Compile Include="GameObjects\Components\DamageableComponent.cs" />

View File

@@ -26,6 +26,7 @@ using SS14.Shared.IoC;
using SS14.Shared.Prototypes; using SS14.Shared.Prototypes;
using System; using System;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Markers;
using SS14.Client.Interfaces.UserInterface; using SS14.Client.Interfaces.UserInterface;
using SS14.Shared.Log; using SS14.Shared.Log;
@@ -97,6 +98,8 @@ namespace Content.Client
factory.RegisterIgnore("PowerCell"); factory.RegisterIgnore("PowerCell");
factory.Register<SharedSpawnPointComponent>();
IoCManager.Register<IClientNotifyManager, ClientNotifyManager>(); IoCManager.Register<IClientNotifyManager, ClientNotifyManager>();
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>(); IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();
IoCManager.Register<IClientGameTicker, ClientGameTicker>(); IoCManager.Register<IClientGameTicker, ClientGameTicker>();

View File

@@ -80,6 +80,7 @@
<Compile Include="GameObjects\Components\Items\Storage\StoreableComponent.cs" /> <Compile Include="GameObjects\Components\Items\Storage\StoreableComponent.cs" />
<Compile Include="GameObjects\Components\Items\Storage\ServerStorageComponent.cs" /> <Compile Include="GameObjects\Components\Items\Storage\ServerStorageComponent.cs" />
<Compile Include="GameObjects\Components\Items\Storage\ItemComponent.cs" /> <Compile Include="GameObjects\Components\Items\Storage\ItemComponent.cs" />
<Compile Include="GameObjects\Components\Markers\SpawnPointComponent.cs" />
<Compile Include="GameObjects\Components\Mobs\DamageStates.cs" /> <Compile Include="GameObjects\Components\Mobs\DamageStates.cs" />
<Compile Include="GameObjects\Components\Mobs\DamageThresholdTemplates\DamageThresholdTemplates.cs" /> <Compile Include="GameObjects\Components\Mobs\DamageThresholdTemplates\DamageThresholdTemplates.cs" />
<Compile Include="GameObjects\Components\Mobs\DamageThresholdTemplates\HumanTemplate.cs" /> <Compile Include="GameObjects\Components\Mobs\DamageThresholdTemplates\HumanTemplate.cs" />

View File

@@ -34,11 +34,13 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Server.Mobs; using Content.Server.Mobs;
using Content.Server.Players; using Content.Server.Players;
using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Markers;
using Content.Server.GameObjects.Components.Weapon.Ranged; using Content.Server.GameObjects.Components.Weapon.Ranged;
using Content.Server.GameTicking; using Content.Server.GameTicking;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Server.Interfaces.GameTicking; using Content.Server.Interfaces.GameTicking;
using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Markers;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using SS14.Server.Interfaces.ServerStatus; using SS14.Server.Interfaces.ServerStatus;
using SS14.Shared.Timing; using SS14.Shared.Timing;
@@ -119,6 +121,9 @@ namespace Content.Server
factory.Register<MindComponent>(); factory.Register<MindComponent>();
factory.Register<SpeciesComponent>(); factory.Register<SpeciesComponent>();
factory.Register<SpawnPointComponent>();
factory.RegisterReference<SpawnPointComponent, SharedSpawnPointComponent>();
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>(); IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>(); IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
IoCManager.Register<IGameTicker, GameTicker>(); IoCManager.Register<IGameTicker, GameTicker>();

View File

@@ -0,0 +1,28 @@
using System;
using Content.Shared.GameObjects.Components.Markers;
using SS14.Shared.GameObjects;
using SS14.Shared.Serialization;
using SS14.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Markers
{
public sealed class SpawnPointComponent : SharedSpawnPointComponent
{
private SpawnPointType _spawnType;
[ViewVariables]
public SpawnPointType SpawnType => _spawnType;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _spawnType, "spawn_type", SpawnPointType.Unset);
}
}
public enum SpawnPointType
{
Unset = 0,
LateJoin,
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.GameObjects; using Content.Server.GameObjects;
using Content.Server.GameObjects.Components.Markers;
using Content.Server.GameTicking.GamePresets; using Content.Server.GameTicking.GamePresets;
using Content.Server.Interfaces.GameTicking; using Content.Server.Interfaces.GameTicking;
using Content.Server.Mobs; using Content.Server.Mobs;
@@ -16,6 +17,7 @@ using SS14.Server.Player;
using SS14.Shared.Configuration; using SS14.Shared.Configuration;
using SS14.Shared.Console; using SS14.Shared.Console;
using SS14.Shared.Enums; using SS14.Shared.Enums;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.Configuration; using SS14.Shared.Interfaces.Configuration;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Map; using SS14.Shared.Interfaces.Map;
@@ -75,6 +77,8 @@ namespace Content.Server.GameTicking
[ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers; [ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers;
private DateTime _roundStartTimeUtc; private DateTime _roundStartTimeUtc;
private readonly Random _spawnRandom = new Random();
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private IEntityManager _entityManager; [Dependency] private IEntityManager _entityManager;
[Dependency] private IMapManager _mapManager; [Dependency] private IMapManager _mapManager;
@@ -217,7 +221,7 @@ namespace Content.Server.GameTicking
private IEntity _spawnPlayerMob() private IEntity _spawnPlayerMob()
{ {
var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, _spawnPoint); var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, _getLateJoinSpawnPoint());
var shoes = _entityManager.SpawnEntity("ShoesItem"); var shoes = _entityManager.SpawnEntity("ShoesItem");
var uniform = _entityManager.SpawnEntity("UniformAssistant"); var uniform = _entityManager.SpawnEntity("UniformAssistant");
if (entity.TryGetComponent(out InventoryComponent inventory)) if (entity.TryGetComponent(out InventoryComponent inventory))
@@ -231,7 +235,29 @@ namespace Content.Server.GameTicking
private IEntity _spawnObserverMob() private IEntity _spawnObserverMob()
{ {
return _entityManager.ForceSpawnEntityAt(ObserverPrototypeName, _spawnPoint); return _entityManager.ForceSpawnEntityAt(ObserverPrototypeName, _getLateJoinSpawnPoint());
}
private GridCoordinates _getLateJoinSpawnPoint()
{
var location = _spawnPoint;
var possiblePoints = new List<GridCoordinates>();
foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent))))
{
var point = entity.GetComponent<SpawnPointComponent>();
if (point.SpawnType == SpawnPointType.LateJoin)
{
possiblePoints.Add(entity.Transform.GridPosition);
}
}
if (possiblePoints.Count != 0)
{
location = _spawnRandom.Pick(possiblePoints);
}
return location;
} }
/// <summary> /// <summary>

View File

@@ -68,6 +68,7 @@
<Compile Include="GameObjects\Components\Inventory\EquipmentSlotDefinitions.cs" /> <Compile Include="GameObjects\Components\Inventory\EquipmentSlotDefinitions.cs" />
<Compile Include="GameObjects\Components\Inventory\InventoryTemplates.cs" /> <Compile Include="GameObjects\Components\Inventory\InventoryTemplates.cs" />
<Compile Include="GameObjects\Components\Inventory\SharedInventoryComponent.cs" /> <Compile Include="GameObjects\Components\Inventory\SharedInventoryComponent.cs" />
<Compile Include="GameObjects\Components\Markers\SharedSpawnPointComponent.cs" />
<Compile Include="GameObjects\Components\Power\PowerShared.cs" /> <Compile Include="GameObjects\Components\Power\PowerShared.cs" />
<Compile Include="GameObjects\Components\Power\SharedPowerCellComponent.cs" /> <Compile Include="GameObjects\Components\Power\SharedPowerCellComponent.cs" />
<Compile Include="GameObjects\Components\Storage\SharedStorageComponent.cs" /> <Compile Include="GameObjects\Components\Storage\SharedStorageComponent.cs" />

View File

@@ -0,0 +1,9 @@
using SS14.Shared.GameObjects;
namespace Content.Shared.GameObjects.Components.Markers
{
public class SharedSpawnPointComponent : Component
{
public sealed override string Name => "SpawnPoint";
}
}

View File

@@ -0,0 +1,31 @@
- type: entity
name: Spawn Point
id: spawn_point
abstract: true
components:
- type: Sprite
netsync: false
visible: false
sprite: Objects/markers.rsi
- type: Icon
sprite: Objects/markers.rsi
- type: SpawnPoint
placement:
mode: SnapgridCenter
- type: entity
name: LateJoin Spawn Point
id: spawn_point_latejoin
parent: spawn_point
components:
- type: Sprite
state: cross_red
- type: SpawnPoint
spawn_type: LateJoin
- type: Icon
state: cross_red

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

View File

@@ -0,0 +1 @@
{"version": 1, "size": {"x": 32, "y": 32}, "license": "CC-BY-SA-3.0", "copyright": "Taken from https://github.com/vgstation-coders/vgstation13/blob/e71d6c4fba5a51f99b81c295dcaec4fc2f58fb19/icons/mob/screen1.dmi", "states": [{"name": "cross_blue", "directions": 1, "delays": [[1.0]]}, {"name": "cross_green", "directions": 1, "delays": [[1.0]]}, {"name": "cross_red", "directions": 1, "delays": [[1.0]]}]}