Adds Vault Verb (#1889)
* -Vault Verb -Made CanVault a method so it can be called from several places * Notifymanager bad * Unnecessary Import
This commit is contained in:
@@ -1,23 +1,22 @@
|
|||||||
|
using Content.Server.GameObjects.Components.Body;
|
||||||
|
using Content.Server.GameObjects.EntitySystems.DoAfter;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
|
using Content.Shared.GameObjects.Verbs;
|
||||||
|
using Content.Shared.Interfaces;
|
||||||
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using Robust.Server.Interfaces.Player;
|
|
||||||
using Content.Server.Interfaces;
|
|
||||||
using Content.Shared.GameObjects.EntitySystems;
|
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
|
||||||
using Content.Shared.GameObjects.Components.Movement;
|
|
||||||
using Content.Shared.Interfaces;
|
|
||||||
using Content.Server.GameObjects.Components.Body;
|
|
||||||
using Content.Server.GameObjects.EntitySystems.DoAfter;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using System;
|
using System;
|
||||||
using Robust.Shared.Log;
|
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Movement
|
namespace Content.Server.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
@@ -25,7 +24,6 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
[ComponentReference(typeof(IClimbable))]
|
[ComponentReference(typeof(IClimbable))]
|
||||||
public class ClimbableComponent : SharedClimbableComponent, IDragDropOn
|
public class ClimbableComponent : SharedClimbableComponent, IDragDropOn
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
|
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,68 +62,101 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
|
|
||||||
bool IDragDropOn.CanDragDropOn(DragDropEventArgs eventArgs)
|
bool IDragDropOn.CanDragDropOn(DragDropEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (!ActionBlockerSystem.CanInteract(eventArgs.User))
|
string reason;
|
||||||
{
|
bool canVault;
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't do that!"));
|
|
||||||
|
|
||||||
|
if (eventArgs.User == eventArgs.Dropped)
|
||||||
|
canVault = CanVault(eventArgs.User, eventArgs.Target, out reason);
|
||||||
|
else
|
||||||
|
canVault = CanVault(eventArgs.User, eventArgs.Dropped, eventArgs.Target, out reason);
|
||||||
|
|
||||||
|
if (!canVault)
|
||||||
|
eventArgs.User.PopupMessage(eventArgs.User, reason);
|
||||||
|
|
||||||
|
return canVault;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the user can vault the target
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The entity that wants to vault</param>
|
||||||
|
/// <param name="target">The object that is being vaulted</param>
|
||||||
|
/// <param name="reason">The reason why it cant be dropped</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool CanVault(IEntity user, IEntity target, out string reason)
|
||||||
|
{
|
||||||
|
if (!ActionBlockerSystem.CanInteract(user))
|
||||||
|
{
|
||||||
|
reason = Loc.GetString("You can't do that!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventArgs.User == eventArgs.Dropped) // user is dragging themselves onto a climbable
|
if (!user.HasComponent<ClimbingComponent>())
|
||||||
{
|
{
|
||||||
if (!eventArgs.User.HasComponent<ClimbingComponent>())
|
reason = Loc.GetString("You are incapable of climbing!");
|
||||||
{
|
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You are incapable of climbing!"));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodyManager = eventArgs.User.GetComponent<BodyManagerComponent>();
|
var bodyManager = user.GetComponent<BodyManagerComponent>();
|
||||||
|
|
||||||
if (bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Leg).Count == 0 ||
|
if (bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Leg).Count == 0 ||
|
||||||
bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Foot).Count == 0)
|
bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Foot).Count == 0)
|
||||||
{
|
{
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You are unable to climb!"));
|
reason = Loc.GetString("You are unable to climb!");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var userPosition = eventArgs.User.Transform.MapPosition;
|
var userPosition = user.Transform.MapPosition;
|
||||||
var climbablePosition = eventArgs.Target.Transform.MapPosition;
|
var climbablePosition = target.Transform.MapPosition;
|
||||||
var interaction = EntitySystem.Get<SharedInteractionSystem>();
|
var interaction = EntitySystem.Get<SharedInteractionSystem>();
|
||||||
bool Ignored(IEntity entity) => (entity == eventArgs.Target || entity == eventArgs.User);
|
bool Ignored(IEntity entity) => (entity == target || entity == user);
|
||||||
|
|
||||||
if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored))
|
if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored))
|
||||||
{
|
{
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't reach there!"));
|
reason = Loc.GetString("You can't reach there!");
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // user is dragging some other entity onto a climbable
|
|
||||||
{
|
|
||||||
if (eventArgs.Target == null || !eventArgs.Dropped.HasComponent<ClimbingComponent>())
|
|
||||||
{
|
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't do that!"));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var userPosition = eventArgs.User.Transform.MapPosition;
|
reason = string.Empty;
|
||||||
var otherUserPosition = eventArgs.Dropped.Transform.MapPosition;
|
return true;
|
||||||
var climbablePosition = eventArgs.Target.Transform.MapPosition;
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the user can vault the dragged entity onto the the target
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user that wants to vault the entity</param>
|
||||||
|
/// <param name="dragged">The entity that is being vaulted</param>
|
||||||
|
/// <param name="target">The object that is being vaulted onto</param>
|
||||||
|
/// <param name="reason">The reason why it cant be dropped</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool CanVault(IEntity user, IEntity dragged, IEntity target, out string reason)
|
||||||
|
{
|
||||||
|
if (!ActionBlockerSystem.CanInteract(user))
|
||||||
|
{
|
||||||
|
reason = Loc.GetString("You can't do that!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == null || !dragged.HasComponent<ClimbingComponent>())
|
||||||
|
{
|
||||||
|
reason = Loc.GetString("You can't do that!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var userPosition = user.Transform.MapPosition;
|
||||||
|
var otherUserPosition = dragged.Transform.MapPosition;
|
||||||
|
var climbablePosition = target.Transform.MapPosition;
|
||||||
var interaction = EntitySystem.Get<SharedInteractionSystem>();
|
var interaction = EntitySystem.Get<SharedInteractionSystem>();
|
||||||
bool Ignored(IEntity entity) => (entity == eventArgs.Target || entity == eventArgs.User || entity == eventArgs.Dropped);
|
bool Ignored(IEntity entity) => (entity == target || entity == user || entity == dragged);
|
||||||
|
|
||||||
if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored) ||
|
if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored) ||
|
||||||
!interaction.InRangeUnobstructed(userPosition, otherUserPosition, _range, predicate: Ignored))
|
!interaction.InRangeUnobstructed(userPosition, otherUserPosition, _range, predicate: Ignored))
|
||||||
{
|
{
|
||||||
_notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't reach there!"));
|
reason = Loc.GetString("You can't reach there!");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
reason = string.Empty;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +208,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
// there's also the cases where the user might collide with the person they are forcing onto the climbable that i haven't accounted for
|
// there's also the cases where the user might collide with the person they are forcing onto the climbable that i haven't accounted for
|
||||||
|
|
||||||
PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} forces {1:theName} onto {2:theName}!", user, entityToMove, Owner), 15);
|
PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} forces {1:theName} onto {2:theName}!", user, entityToMove, Owner), 15);
|
||||||
_notifyManager.PopupMessage(user, user, Loc.GetString("You force {0:theName} onto {1:theName}!", entityToMove, Owner));
|
user.PopupMessage(user, Loc.GetString("You force {0:theName} onto {1:theName}!", entityToMove, Owner));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +244,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
climbMode.TryMoveTo(user.Transform.WorldPosition, endPoint);
|
climbMode.TryMoveTo(user.Transform.WorldPosition, endPoint);
|
||||||
|
|
||||||
PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner), 15);
|
PopupMessageOtherClientsInRange(user, Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner), 15);
|
||||||
_notifyManager.PopupMessage(user, user, Loc.GetString("You jump onto {0:theName}!", Owner));
|
user.PopupMessage(user, Loc.GetString("You jump onto {0:theName}!", Owner));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,5 +264,27 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
source.PopupMessage(viewer.AttachedEntity, message);
|
source.PopupMessage(viewer.AttachedEntity, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows you to vault an object with the ClimbableComponent through right click
|
||||||
|
/// </summary>
|
||||||
|
[Verb]
|
||||||
|
private sealed class ClimbVerb : Verb<ClimbableComponent>
|
||||||
|
{
|
||||||
|
protected override void GetData(IEntity user, ClimbableComponent component, VerbData data)
|
||||||
|
{
|
||||||
|
if (!component.CanVault(user, component.Owner, out var _))
|
||||||
|
{
|
||||||
|
data.Visibility = VerbVisibility.Invisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Text = Loc.GetString("Vault");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Activate(IEntity user, ClimbableComponent component)
|
||||||
|
{
|
||||||
|
component.TryClimb(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user