82
Content.Shared/Devour/Components/DevourerComponent.cs
Normal file
82
Content.Shared/Devour/Components/DevourerComponent.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Devour;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Devour.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedDevourSystem))]
|
||||
public sealed class DevourerComponent : Component
|
||||
{
|
||||
[DataField("devourActionId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityTargetActionPrototype>))]
|
||||
public string DevourActionId = "Devour";
|
||||
|
||||
[DataField("devourAction")]
|
||||
public EntityTargetAction? DevourAction;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("soundDevour")]
|
||||
public SoundSpecifier? SoundDevour = new SoundPathSpecifier("/Audio/Effects/demon_consume.ogg")
|
||||
{
|
||||
Params = AudioParams.Default.WithVolume(-3f),
|
||||
};
|
||||
|
||||
[DataField("devourTime")]
|
||||
public float DevourTime = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time it takes to devour something
|
||||
/// <remarks>
|
||||
/// NOTE: original intended design was to increase this proportionally with damage thresholds, but those proved quite difficult to get consistently. right now it devours the structure at a fixed timer.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
[DataField("structureDevourTime")]
|
||||
public float StructureDevourTime = 10f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("soundStructureDevour")]
|
||||
public SoundSpecifier? SoundStructureDevour = new SoundPathSpecifier("/Audio/Machines/airlock_creaking.ogg")
|
||||
{
|
||||
Params = AudioParams.Default.WithVolume(-3f),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Where the entities go when it devours them, empties when it is butchered.
|
||||
/// </summary>
|
||||
public Container Stomach = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("shouldStoreDevoured")]
|
||||
public bool ShouldStoreDevoured = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("whitelist")]
|
||||
public EntityWhitelist? Whitelist = new()
|
||||
{
|
||||
Components = new[]
|
||||
{
|
||||
"MobState",
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The chemical ID injected upon devouring
|
||||
/// </summary>
|
||||
[DataField("chemical", customTypeSerializer: typeof(PrototypeIdSerializer<ReagentPrototype>))]
|
||||
public string Chemical = "Ichor";
|
||||
|
||||
/// <summary>
|
||||
/// The amount of ichor injected per devour
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("healRate")]
|
||||
public float HealRate = 15f;
|
||||
|
||||
/// <summary>
|
||||
/// The favorite food not only feeds you, but also heals
|
||||
/// </summary>
|
||||
[DataField("foodPreference")]
|
||||
public FoodPreference FoodPreference = FoodPreference.All;
|
||||
}
|
||||
|
||||
94
Content.Shared/Devour/SharedDevourSystem.cs
Normal file
94
Content.Shared/Devour/SharedDevourSystem.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Mobs;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Server.Devour.Components;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Devour;
|
||||
|
||||
public abstract class SharedDevourSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DevourerComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<DevourerComponent, DevourActionEvent>(OnDevourAction);
|
||||
}
|
||||
|
||||
protected void OnStartup(EntityUid uid, DevourerComponent component, ComponentStartup args)
|
||||
{
|
||||
//Devourer doesn't actually chew, since he sends targets right into his stomach.
|
||||
//I did it mom, I added ERP content into upstream. Legally!
|
||||
component.Stomach = _containerSystem.EnsureContainer<Container>(uid, "stomach");
|
||||
|
||||
if (component.DevourAction != null)
|
||||
_actionsSystem.AddAction(uid, component.DevourAction, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The devour action
|
||||
/// </summary>
|
||||
protected void OnDevourAction(EntityUid uid, DevourerComponent component, DevourActionEvent args)
|
||||
{
|
||||
if (args.Handled || component.Whitelist?.IsValid(args.Target, EntityManager) != true)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
var target = args.Target;
|
||||
|
||||
// Structure and mob devours handled differently.
|
||||
if (TryComp(target, out MobStateComponent? targetState))
|
||||
{
|
||||
switch (targetState.CurrentState)
|
||||
{
|
||||
case MobState.Critical:
|
||||
case MobState.Dead:
|
||||
|
||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(uid, component.DevourTime, new DevourDoAfterEvent(), uid, target: target, used: uid)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-fail-target-alive"), uid, uid);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-structure"), uid, uid);
|
||||
|
||||
if (component.SoundStructureDevour != null)
|
||||
_audioSystem.PlayPvs(component.SoundStructureDevour, uid, component.SoundStructureDevour.Params);
|
||||
|
||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(uid, component.StructureDevourTime, new DevourDoAfterEvent(), uid, target: target, used: uid)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DevourActionEvent : EntityTargetActionEvent { }
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DevourDoAfterEvent : SimpleDoAfterEvent { }
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FoodPreference : byte
|
||||
{
|
||||
Humanoid = 0,
|
||||
All = 1
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Dragon;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DragonDevourDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user