Convert familiars to GhostRoleMobSpawner (#9525)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,8 @@ using Content.Server.Cooldown;
|
||||
using Content.Server.Bible.Components;
|
||||
using Content.Server.MobState;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Ghost.Roles.Components;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Random;
|
||||
@@ -39,6 +41,7 @@ namespace Content.Server.Bible
|
||||
SubscribeLocalEvent<SummonableComponent, GetItemActionsEvent>(GetSummonAction);
|
||||
SubscribeLocalEvent<SummonableComponent, SummonActionEvent>(OnSummon);
|
||||
SubscribeLocalEvent<FamiliarComponent, MobStateChangedEvent>(OnFamiliarDeath);
|
||||
SubscribeLocalEvent<FamiliarComponent, GhostRoleSpawnerUsedEvent>(OnSpawned);
|
||||
}
|
||||
|
||||
private readonly Queue<EntityUid> _addQueue = new();
|
||||
@@ -194,6 +197,17 @@ namespace Content.Server.Bible
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the familiar spawns, set its source to the bible.
|
||||
/// </summary>
|
||||
private void OnSpawned(EntityUid uid, FamiliarComponent component, GhostRoleSpawnerUsedEvent args)
|
||||
{
|
||||
if (!TryComp<SummonableComponent>(Transform(args.Spawner).ParentUid, out var summonable))
|
||||
return;
|
||||
|
||||
component.Source = summonable.Owner;
|
||||
summonable.Summon = uid;
|
||||
}
|
||||
|
||||
private void AttemptSummon(SummonableComponent component, EntityUid user, TransformComponent? position)
|
||||
{
|
||||
@@ -212,12 +226,11 @@ namespace Content.Server.Bible
|
||||
var familiar = EntityManager.SpawnEntity(component.SpecialItemPrototype, position.Coordinates);
|
||||
component.Summon = familiar;
|
||||
|
||||
// We only want to add the familiar component to mobs
|
||||
if (HasComp<MobStateComponent>(familiar))
|
||||
// If this is going to use a ghost role mob spawner, attach it to the bible.
|
||||
if (HasComp<GhostRoleMobSpawnerComponent>(familiar))
|
||||
{
|
||||
// Make this Summon the familiar's source
|
||||
var familiarComp = EnsureComp<FamiliarComponent>(familiar);
|
||||
familiarComp.Source = component.Owner;
|
||||
_popupSystem.PopupEntity(Loc.GetString("bible-summon-requested"), user, Filter.Pvs(user), PopupType.Medium);
|
||||
Transform(familiar).AttachParent(component.Owner);
|
||||
}
|
||||
component.AlreadySummoned = true;
|
||||
_actionsSystem.RemoveAction(user, component.SummonAction);
|
||||
|
||||
@@ -4,6 +4,7 @@ using JetBrains.Annotations;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components
|
||||
{
|
||||
@@ -38,6 +39,11 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
throw new NullReferenceException("Prototype string cannot be null or empty!");
|
||||
|
||||
var mob = _entMan.SpawnEntity(Prototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var xform = _entMan.GetComponent<TransformComponent>(mob);
|
||||
xform.AttachToGridOrMap();
|
||||
|
||||
var spawnedEvent = new GhostRoleSpawnerUsedEvent(Owner, mob);
|
||||
_entMan.EventBus.RaiseLocalEvent(mob, spawnedEvent, false);
|
||||
|
||||
if (MakeSentient)
|
||||
MakeSentientCommand.MakeSentient(mob, _entMan);
|
||||
@@ -53,7 +59,7 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
Taken = true;
|
||||
|
||||
if (_deleteOnSpawn)
|
||||
_entMan.DeleteEntity(Owner);
|
||||
_entMan.QueueDeleteEntity(Owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace Content.Server.Ghost.Roles.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised on a spawned entity after they use a ghost role mob spawner.
|
||||
/// </summary>
|
||||
public sealed class GhostRoleSpawnerUsedEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity that spawned this.
|
||||
/// </summary>
|
||||
public EntityUid Spawner;
|
||||
|
||||
/// <summary>
|
||||
/// The entity spawned.
|
||||
/// </summary>
|
||||
public EntityUid Spawned;
|
||||
|
||||
public GhostRoleSpawnerUsedEvent(EntityUid spawner, EntityUid spawned)
|
||||
{
|
||||
Spawner = spawner;
|
||||
|
||||
Spawned = spawned;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user