fish-station/Content.Server/_Sunrise/Radials/RadialSystem.cs
ThereDrD 8efeca7f48
Питомцы (#391)
* init

* port better radials

* change wizden radials to new radials

* minor radial ui refactor

* less redundant values

* cleanup

* minor cleanup + refactor

* rename action + base ghost logic

* ghost actions update

* attack action + better action granting

* add missing translation

* add debug entity for testing

* add radial actions sprites

* micro fixes

* translations for ghost panel

* fix attack action logic

* new pet action sprites

* better attack target action params

* add 2 new stock pets

* add translation string for new pets

* add additional checks for petting + cute effect for successful petting

* add transfer pets to new body logic for cloning and gibbing

* add summary for OnMasterGibbed

* add stock pets to loadout menu

* fix OnMasterGibbed logic and change it to OnMasterShutdown

* add localisation support

* add logic for shutdown pet component

* pets that spawned as loadout automatically linked now

* added new pets

* cleanup

* more pets

* ы

* фиксы

---------

Co-authored-by: SplikZerys <tronezero700@yandex.ru>
Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
Co-authored-by: Vigers Ray <vigersray@gmail.com>
2025-01-11 07:53:23 +03:00

123 lines
4.7 KiB
C#

using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Popups;
using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
using Content.Shared.Inventory.VirtualItem;
using Content.Shared._Sunrise.Radials;
using Content.Shared._Sunrise.Radials.Systems;
namespace Content.Server._Sunrise.Radials;
public sealed class RadialSystem : SharedRadialSystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IAdminManager _adminMgr = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RequestServerRadialsEvent>(HandleRadialRequest);
}
private void HandleRadialRequest(RequestServerRadialsEvent args, EntitySessionEventArgs eventArgs)
{
var player = eventArgs.SenderSession;
var playerEntity = GetEntity(args.EntityUid);
if (!Exists(playerEntity))
{
_sawmill.Warning($"{nameof(HandleRadialRequest)} called on a non-existent entity with id {args.EntityUid} by player {player}.");
return;
}
if (player.AttachedEntity is not {} attached)
{
_sawmill.Warning($"{nameof(HandleRadialRequest)} called by player {player} with no attached entity.");
return;
}
// We do not verify that the user has access to the requested entity. The individual verbs should check
// this, and some verbs (e.g. view variables) won't even care about whether an entity is accessible through
// the entity menu or not.
var force = args.AdminRequest && _adminMgr.HasAdminFlag(eventArgs.SenderSession, AdminFlags.Admin);
HashSet<Type> radialsTypes = new();
foreach (var key in args.RadialTypes)
{
var type = Radial.RadialTypes.FirstOrDefault(x => x.Name == key);
if (type != null)
radialsTypes.Add(type);
else
_sawmill.Error($"Unknown verb type received: {key}");
}
var response =
new RadialsResponseEvent(args.EntityUid, GetLocalRadials(playerEntity, attached, radialsTypes, force));
RaiseNetworkEvent(response, player);
}
/// <summary>
/// Execute the provided verb.
/// </summary>
/// <remarks>
/// This will try to call the action delegates and raise the local events for the given verb.
/// </remarks>
public override void ExecuteRadial(Radial radial, EntityUid user, EntityUid target, bool forced = false)
{
// is this verb actually valid?
if (radial.Disabled)
{
// Send an informative pop-up message
if (!string.IsNullOrWhiteSpace(radial.Message))
_popupSystem.PopupEntity(radial.Message, user, user);
return;
}
// first, lets log the verb. Just in case it ends up crashing the server or something.
LogRadial(radial, user, target, forced);
base.ExecuteRadial(radial, user, target, forced);
}
public void LogRadial(Radial radial, EntityUid user, EntityUid target, bool forced)
{
// first get the held item. again.
EntityUid? holding = null;
if (TryComp(user, out HandsComponent? hands) &&
hands.ActiveHandEntity is EntityUid heldEntity)
{
holding = heldEntity;
}
// if this is a virtual pull, get the held entity
if (holding != null && TryComp(holding, out VirtualItemComponent? pull))
holding = pull.BlockingEntity;
var verbText = $"{radial.Text}".Trim();
// lets not frame people, eh?
var executionText = forced ? "was forced to execute" : "executed";
if (holding == null)
{
_adminLogger.Add(LogType.Verb, radial.Impact,
$"{ToPrettyString(user):user} {executionText} the [{verbText:verb}] verb targeting {ToPrettyString(target):target}");
}
else
{
_adminLogger.Add(LogType.Verb, radial.Impact,
$"{ToPrettyString(user):user} {executionText} the [{verbText:verb}] verb targeting {ToPrettyString(target):target} while holding {ToPrettyString(holding.Value):held}");
}
}
}