* MVP * Uncomment animated prototypes * Disable wagging on death * Move component to server * Looped tail animation * Apply front tail template * Disable animated markings globally * Add emote sending * Update documentation * Move locale * Use static instantAction & remove action on comp del * Use fluent POSS-ADJ * Update docs * Add copyright * Update copyright * Update license & copyright * Move to main directory & format meta.json * Fix path * Change namespace * Remove empty meta.json * Update * REMOVE unnecessary IsNullOrWhiteSpace check Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Move animated markings to main file * Use emotes * new * fix * fix * Tests, pls * fix dixel * Remove networked from wagging comp * Remove unused import * Remove unused imports * Move wagging comp to shared * Revert the emotes If we're getting it the action is better. --------- Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
111 lines
3.8 KiB
C#
111 lines
3.8 KiB
C#
using Content.Server.Actions;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Humanoid;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Humanoid.Markings;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Toggleable;
|
|
using Content.Shared.Wagging;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Wagging;
|
|
|
|
/// <summary>
|
|
/// Adds an action to toggle wagging animation for tails markings that supporting this
|
|
/// </summary>
|
|
public sealed class WaggingSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ActionsSystem _actions = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<WaggingComponent, MapInitEvent>(OnWaggingMapInit);
|
|
SubscribeLocalEvent<WaggingComponent, ComponentShutdown>(OnWaggingShutdown);
|
|
SubscribeLocalEvent<WaggingComponent, ToggleActionEvent>(OnWaggingToggle);
|
|
SubscribeLocalEvent<WaggingComponent, MobStateChangedEvent>(OnMobStateChanged);
|
|
}
|
|
|
|
private void OnWaggingMapInit(EntityUid uid, WaggingComponent component, MapInitEvent args)
|
|
{
|
|
_actions.AddAction(uid, ref component.ActionEntity, component.Action, uid);
|
|
}
|
|
|
|
private void OnWaggingShutdown(EntityUid uid, WaggingComponent component, ComponentShutdown args)
|
|
{
|
|
_actions.RemoveAction(uid, component.ActionEntity);
|
|
}
|
|
|
|
private void OnWaggingToggle(EntityUid uid, WaggingComponent component, ref ToggleActionEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
TryToggleWagging(uid, wagging: component);
|
|
}
|
|
|
|
private void OnMobStateChanged(EntityUid uid, WaggingComponent component, MobStateChangedEvent args)
|
|
{
|
|
if (args.NewMobState != MobState.Dead)
|
|
return;
|
|
|
|
if (component.Wagging)
|
|
TryToggleWagging(uid, wagging: component);
|
|
}
|
|
|
|
public bool TryToggleWagging(EntityUid uid, WaggingComponent? wagging = null, HumanoidAppearanceComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref wagging, ref humanoid))
|
|
return false;
|
|
|
|
if (!humanoid.MarkingSet.Markings.TryGetValue(MarkingCategories.Tail, out var markings))
|
|
return false;
|
|
|
|
if (markings.Count == 0)
|
|
return false;
|
|
|
|
wagging.Wagging = !wagging.Wagging;
|
|
|
|
for (var idx = 0; idx < markings.Count; idx++) // Animate all possible tails
|
|
{
|
|
var currentMarkingId = markings[idx].MarkingId;
|
|
string newMarkingId;
|
|
|
|
if (wagging.Wagging)
|
|
{
|
|
newMarkingId = $"{currentMarkingId}{wagging.Suffix}";
|
|
}
|
|
else
|
|
{
|
|
if (currentMarkingId.EndsWith(wagging.Suffix))
|
|
{
|
|
newMarkingId = currentMarkingId[..^wagging.Suffix.Length];
|
|
}
|
|
else
|
|
{
|
|
newMarkingId = currentMarkingId;
|
|
Log.Warning($"Unable to revert wagging for {currentMarkingId}");
|
|
}
|
|
}
|
|
|
|
if (!_prototype.HasIndex<MarkingPrototype>(newMarkingId))
|
|
{
|
|
Log.Warning($"{ToPrettyString(uid)} tried toggling wagging but {newMarkingId} marking doesn't exist");
|
|
continue;
|
|
}
|
|
|
|
_humanoidAppearance.SetMarkingId(uid, MarkingCategories.Tail, idx, newMarkingId,
|
|
humanoid: humanoid);
|
|
}
|
|
|
|
var emoteText = Loc.GetString(wagging.Wagging ? "wagging-emote-start" : "wagging-emote-stop", ("ent", uid));
|
|
_chat.TrySendInGameICMessage(uid, emoteText, InGameICChatType.Emote, ChatTransmitRange.Normal); // Ok while emotes dont have radial menu
|
|
|
|
return true;
|
|
}
|
|
}
|