mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-05-02 13:07:00 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Ports the lone abductor and possibly(?) the duo abductors. --- # TODO <!-- A list of everything you have to do before this PR is "complete" You probably won't have to complete everything before merging but it's good to leave future references --> - [X] Figure out why abductors aren't spawning as the abductor race. - [X] Make sure it's not a buggy mess. --- <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p>  </p> </details> --- # Credits Thank to [Starlight ](https://discord.com/invite/wAyQKB78fH)for the original version! Darkrell, Rinary, and Landosaur made the funny little guys.  # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 Darkrell, Rinary, Landosaur - add: The Abductors are here to replace your organs. Gleep Glorp! --------- Co-authored-by: gluesniffler <159397573+gluesniffler@users.noreply.github.com> Co-authored-by: Solstice <solsticeofthewinter@gmail.com> Co-authored-by: SX_7 <sn1.test.preria.2002@gmail.com> Co-authored-by: Theodore Lukin <66275205+pheenty@users.noreply.github.com> Co-authored-by: Piras314 <p1r4s@proton.me> Co-authored-by: Ilya246 <57039557+ilya246@users.noreply.github.com> (cherry picked from commit ea9f1526868289d20832989cb02f79c76c240918)
244 lines
8.0 KiB
C#
244 lines
8.0 KiB
C#
using Content.Shared.Gravity;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Physics;
|
|
using Robust.Shared.Utility;
|
|
|
|
// Shitmed Change
|
|
using Content.Shared._Shitmed.Antags.Abductor;
|
|
using Content.Shared.Silicons.StationAi;
|
|
|
|
namespace Content.Shared.DoAfter;
|
|
|
|
public abstract partial class SharedDoAfterSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IDynamicTypeFactory _factory = default!;
|
|
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
|
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
|
|
|
private DoAfter[] _doAfters = Array.Empty<DoAfter>();
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var time = GameTiming.CurTime;
|
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
|
var handsQuery = GetEntityQuery<HandsComponent>();
|
|
|
|
var enumerator = EntityQueryEnumerator<ActiveDoAfterComponent, DoAfterComponent>();
|
|
while (enumerator.MoveNext(out var uid, out var active, out var comp))
|
|
{
|
|
Update(uid, active, comp, time, xformQuery, handsQuery);
|
|
}
|
|
}
|
|
|
|
protected void Update(
|
|
EntityUid uid,
|
|
ActiveDoAfterComponent active,
|
|
DoAfterComponent comp,
|
|
TimeSpan time,
|
|
EntityQuery<TransformComponent> xformQuery,
|
|
EntityQuery<HandsComponent> handsQuery)
|
|
{
|
|
var dirty = false;
|
|
|
|
var values = comp.DoAfters.Values;
|
|
var count = values.Count;
|
|
if (_doAfters.Length < count)
|
|
_doAfters = new DoAfter[count];
|
|
|
|
values.CopyTo(_doAfters, 0);
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
var doAfter = _doAfters[i];
|
|
if (doAfter.CancelledTime != null)
|
|
{
|
|
if (time - doAfter.CancelledTime.Value > ExcessTime)
|
|
{
|
|
comp.DoAfters.Remove(doAfter.Index);
|
|
dirty = true;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (doAfter.Completed)
|
|
{
|
|
if (time - doAfter.StartTime > doAfter.Args.Delay + ExcessTime)
|
|
{
|
|
comp.DoAfters.Remove(doAfter.Index);
|
|
dirty = true;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (ShouldCancel(doAfter, xformQuery, handsQuery))
|
|
{
|
|
InternalCancel(doAfter, comp);
|
|
dirty = true;
|
|
continue;
|
|
}
|
|
|
|
if (time - doAfter.StartTime >= doAfter.Args.Delay)
|
|
{
|
|
TryComplete(doAfter, comp);
|
|
dirty = true;
|
|
}
|
|
}
|
|
|
|
if (dirty)
|
|
Dirty(uid, comp);
|
|
|
|
if (comp.DoAfters.Count == 0)
|
|
RemCompDeferred(uid, active);
|
|
}
|
|
|
|
private bool TryAttemptEvent(DoAfter doAfter)
|
|
{
|
|
var args = doAfter.Args;
|
|
|
|
if (args.ExtraCheck?.Invoke() == false)
|
|
return false;
|
|
|
|
if (doAfter.AttemptEvent == null)
|
|
{
|
|
// I feel like this is somewhat cursed, but its the only way I can think of without having to just send
|
|
// redundant data over the network and increasing DoAfter boilerplate.
|
|
var evType = typeof(DoAfterAttemptEvent<>).MakeGenericType(args.Event.GetType());
|
|
doAfter.AttemptEvent = _factory.CreateInstance(evType, new object[] { doAfter, args.Event });
|
|
}
|
|
|
|
args.Event.DoAfter = doAfter;
|
|
if (args.EventTarget != null)
|
|
RaiseLocalEvent(args.EventTarget.Value, doAfter.AttemptEvent, args.Broadcast);
|
|
else
|
|
RaiseLocalEvent(doAfter.AttemptEvent);
|
|
|
|
var ev = (CancellableEntityEventArgs) doAfter.AttemptEvent;
|
|
if (!ev.Cancelled)
|
|
return true;
|
|
|
|
ev.Uncancel();
|
|
return false;
|
|
}
|
|
|
|
private void TryComplete(DoAfter doAfter, DoAfterComponent component)
|
|
{
|
|
if (doAfter.Cancelled || doAfter.Completed)
|
|
return;
|
|
|
|
// Perform final check (if required)
|
|
if (doAfter.Args.AttemptFrequency == AttemptFrequency.StartAndEnd
|
|
&& !TryAttemptEvent(doAfter))
|
|
{
|
|
InternalCancel(doAfter, component);
|
|
return;
|
|
}
|
|
|
|
doAfter.Completed = true;
|
|
|
|
RaiseDoAfterEvents(doAfter, component);
|
|
|
|
if (doAfter.Args.Event.Repeat)
|
|
{
|
|
doAfter.StartTime = GameTiming.CurTime;
|
|
doAfter.Completed = false;
|
|
}
|
|
}
|
|
|
|
private bool ShouldCancel(DoAfter doAfter,
|
|
EntityQuery<TransformComponent> xformQuery,
|
|
EntityQuery<HandsComponent> handsQuery)
|
|
{
|
|
var args = doAfter.Args;
|
|
|
|
//re-using xformQuery for Exists() checks.
|
|
if (args.Used is { } used && !xformQuery.HasComponent(used))
|
|
return true;
|
|
|
|
if (args.EventTarget is {Valid: true} eventTarget && !xformQuery.HasComponent(eventTarget))
|
|
return true;
|
|
|
|
if (!xformQuery.TryGetComponent(args.User, out var userXform))
|
|
return true;
|
|
|
|
TransformComponent? targetXform = null;
|
|
if (args.Target is { } target && !xformQuery.TryGetComponent(target, out targetXform))
|
|
return true;
|
|
|
|
TransformComponent? usedXform = null;
|
|
if (args.Used is { } @using && !xformQuery.TryGetComponent(@using, out usedXform))
|
|
return true;
|
|
|
|
// TODO: Re-use existing xform query for these calculations.
|
|
if (args.BreakOnMove && !(!args.BreakOnWeightlessMove && _gravity.IsWeightless(args.User, xform: userXform)))
|
|
{
|
|
// Whether the user has moved too much from their original position.
|
|
if (!userXform.Coordinates.InRange(EntityManager, _transform, doAfter.UserPosition, args.MovementThreshold))
|
|
return true;
|
|
|
|
// Whether the distance between the user and target(if any) has changed too much.
|
|
if (targetXform != null &&
|
|
targetXform.Coordinates.TryDistance(EntityManager, userXform.Coordinates, out var distance))
|
|
{
|
|
if (Math.Abs(distance - doAfter.TargetDistance) > args.MovementThreshold)
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// Whether the user and the target are too far apart.
|
|
if (args.Target != null)
|
|
{
|
|
if (args.DistanceThreshold != null)
|
|
{
|
|
if (!_interaction.InRangeUnobstructed(args.User, args.Target.Value, args.DistanceThreshold.Value))
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (!_interaction.InRangeUnobstructed(args.User, args.Target.Value))
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// Whether the distance between the tool and the user has grown too much.
|
|
if (args.Used != null)
|
|
{
|
|
if (args.DistanceThreshold != null)
|
|
{
|
|
if (!_interaction.InRangeUnobstructed(args.User,
|
|
args.Used.Value,
|
|
args.DistanceThreshold.Value))
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (!_interaction.InRangeUnobstructed(args.User,args.Used.Value))
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (args.AttemptFrequency == AttemptFrequency.EveryTick && !TryAttemptEvent(doAfter))
|
|
return true;
|
|
|
|
if (args.NeedHand)
|
|
{
|
|
if (!handsQuery.TryGetComponent(args.User, out var hands) || hands.Count == 0)
|
|
return true;
|
|
|
|
if (args.BreakOnHandChange && (hands.ActiveHand?.Name != doAfter.InitialHand
|
|
|| hands.ActiveHandEntity != doAfter.InitialItem))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
var hasNoSpecificComponents = !HasComp<StationAiOverlayComponent>(args.User) && !HasComp<AbductorScientistComponent>(args.User); // Shitmed Change
|
|
if (args.RequireCanInteract && !_actionBlocker.CanInteract(args.User, args.Target) && hasNoSpecificComponents) // Shitmed Change
|
|
return true;
|
|
|
|
|
|
return false;
|
|
}
|
|
}
|