2021-10-05 14:29:03 +11:00
|
|
|
using System.Collections.Generic;
|
2021-03-08 04:09:59 +11:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Climbing.Components;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.ActionBlocker;
|
2021-08-10 10:34:01 +10:00
|
|
|
using Content.Shared.Climbing;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Content.Shared.GameTicking;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2020-08-19 18:13:22 -04:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Climbing
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2021-08-10 10:34:01 +10:00
|
|
|
internal sealed class ClimbSystem : SharedClimbSystem
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
private readonly HashSet<ClimbingComponent> _activeClimbers = new();
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
2021-10-05 14:29:03 +11:00
|
|
|
SubscribeLocalEvent<ClimbableComponent, GetAlternativeVerbsEvent>(AddClimbVerb);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 01:03:09 +00:00
|
|
|
public void ForciblySetClimbing(EntityUid uid, ClimbingComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref component, false))
|
|
|
|
|
return;
|
|
|
|
|
component.IsClimbing = true;
|
|
|
|
|
UnsetTransitionBoolAfterBufferTime(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
private void AddClimbVerb(EntityUid uid, ClimbableComponent component, GetAlternativeVerbsEvent args)
|
|
|
|
|
{
|
2021-11-09 13:15:55 +01:00
|
|
|
if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User.Uid))
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Check that the user climb.
|
|
|
|
|
if (!args.User.TryGetComponent(out ClimbingComponent? climbingComponent) ||
|
|
|
|
|
climbingComponent.IsClimbing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Add a climb verb
|
|
|
|
|
Verb verb = new();
|
|
|
|
|
verb.Act = () => component.TryClimb(args.User);
|
|
|
|
|
verb.Text = Loc.GetString("comp-climbable-verb-climb");
|
|
|
|
|
// TODO VERBS ICON add a climbing icon?
|
|
|
|
|
args.Verbs.Add(verb);
|
2021-06-29 15:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
public void AddActiveClimber(ClimbingComponent climbingComponent)
|
|
|
|
|
{
|
|
|
|
|
_activeClimbers.Add(climbingComponent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveActiveClimber(ClimbingComponent climbingComponent)
|
|
|
|
|
{
|
|
|
|
|
_activeClimbers.Remove(climbingComponent);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 01:03:09 +00:00
|
|
|
public void UnsetTransitionBoolAfterBufferTime(EntityUid uid, ClimbingComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref component, false))
|
|
|
|
|
return;
|
|
|
|
|
component.Owner.SpawnTimer((int) (SharedClimbingComponent.BufferTime * 1000), () =>
|
|
|
|
|
{
|
|
|
|
|
if (component.Deleted) return;
|
|
|
|
|
component.OwnerIsTransitioning = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 18:13:22 -04:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
foreach (var climber in _activeClimbers.ToArray())
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
climber.Update();
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
public void Reset(RoundRestartCleanupEvent ev)
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
_activeClimbers.Clear();
|
|
|
|
|
}
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
}
|