Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readd character ghost role spawners #60

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Content.Server.Ghost.Roles.Components
{
/// <summary>
/// Allows a ghost to take this role, spawning their selected character.
/// </summary>
[RegisterComponent]
[Access(typeof(GhostRoleSystem))]
public sealed partial class GhostRoleCharacterSpawnerComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] [DataField("deleteOnSpawn")]
public bool DeleteOnSpawn = true;

[ViewVariables(VVAccess.ReadWrite)] [DataField("availableTakeovers")]
public int AvailableTakeovers = 1;

[ViewVariables]
public int CurrentTakeovers = 0;

[ViewVariables(VVAccess.ReadWrite)] [DataField("outfitPrototype")]
public string OutfitPrototype = "PassengerGear";
}
}
63 changes: 63 additions & 0 deletions Content.Server/DeltaV/Ghost/Roles/GhostRoleSystem.Character.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Content.Server.Administration.Commands;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.Events;
using Content.Server.Preferences.Managers;
using Content.Server.Station.Systems;
using Content.Shared.Mind.Components;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;

namespace Content.Server.Ghost.Roles
{
public sealed partial class GhostRoleSystem
{
[Dependency] private readonly IServerPreferencesManager _prefs = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private void OnSpawnerTakeCharacter( EntityUid uid, GhostRoleCharacterSpawnerComponent component,
ref TakeGhostRoleEvent args)
{
if (!TryComp(uid, out GhostRoleComponent? ghostRole) ||
ghostRole.Taken)
{
args.TookRole = false;
return;
}

var character = (HumanoidCharacterProfile) _prefs.GetPreferences(args.Player.UserId).SelectedCharacter;

var mob = _entityManager.System<StationSpawningSystem>()
.SpawnPlayerMob(Transform(uid).Coordinates, null, character, null);
_transform.AttachToGridOrMap(mob);

string? outfit = null;
if (_prototypeManager.TryIndex<StartingGearPrototype>(component.OutfitPrototype, out var outfitProto))
outfit = outfitProto.ID;

var spawnedEvent = new GhostRoleSpawnerUsedEvent(uid, mob);
RaiseLocalEvent(mob, spawnedEvent);

EnsureComp<MindContainerComponent>(mob);

GhostRoleInternalCreateMindAndTransfer(args.Player, uid, mob, ghostRole);

if (outfit != null)
SetOutfitCommand.SetOutfit(mob, outfit, _entityManager);

if (++component.CurrentTakeovers < component.AvailableTakeovers)
{
args.TookRole = true;
return;
}

ghostRole.Taken = true;

if (component.DeleteOnSpawn)
QueueDel(uid);

args.TookRole = true;
}
}
}
3 changes: 2 additions & 1 deletion Content.Server/Ghost/Roles/GhostRoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace Content.Server.Ghost.Roles
{
[UsedImplicitly]
public sealed class GhostRoleSystem : EntitySystem
public sealed partial class GhostRoleSystem : EntitySystem // Converted to partial to allow for DeltaV character ghost roles
{
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand Down Expand Up @@ -62,6 +62,7 @@ public override void Initialize()
SubscribeLocalEvent<GhostRoleComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<GhostRoleMobSpawnerComponent, TakeGhostRoleEvent>(OnSpawnerTakeRole);
SubscribeLocalEvent<GhostTakeoverAvailableComponent, TakeGhostRoleEvent>(OnTakeoverTakeRole);
SubscribeLocalEvent<GhostRoleCharacterSpawnerComponent, TakeGhostRoleEvent>(OnSpawnerTakeCharacter); // DeltaV - Character ghost roles, see Content.Server/DeltaV/Ghost/Roles/GhostRoleSystem.Character.cs
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- type: entity
id: SpawnPointPlayerCharacter
name: ghost role spawn point
suffix: player character, DO NOT MAP
parent: MarkerBase
components:
- type: GhostRole
name: Roleplay Ghost Role
description: Placeholder
rules: Placeholder
- type: GhostRoleCharacterSpawner
- type: Sprite
sprite: Markers/jobs.rsi
layers:
- state: green
- sprite: Mobs/Species/Human/parts.rsi
state: full
Loading