Wieldable/two-handed weapons (#4554)

* wielding kinda works

* rough out all the edges, wielding works nicely

* popups + loc

* increase damage & extra damage against whitelist

* small fixes

* forgot to actually do that

* reviews

* reviews + thing

* use resistances and not extradamageagainstwhitelist

* slashy

* make increasedamageonwield and melee hit events work with modifiersets

* Silly individual
This commit is contained in:
mirrorcult
2021-09-17 07:16:11 -07:00
committed by GitHub
parent 078a62762f
commit 62f6c8dd8e
36 changed files with 719 additions and 161 deletions

View File

@@ -183,6 +183,24 @@ namespace Content.Shared.Damage
return newDamage;
}
/// <summary>
/// Reduce (or increase) damages by applying multiple modifier sets.
/// </summary>
/// <param name="damageSpec"></param>
/// <param name="modifierSets"></param>
/// <returns></returns>
public static DamageSpecifier ApplyModifierSets(DamageSpecifier damageSpec, IEnumerable<DamageModifierSet> modifierSets)
{
DamageSpecifier newDamage = new(damageSpec);
foreach (var set in modifierSets)
{
// this is probably really inefficient. just don't call this in a hot path I guess.
newDamage = ApplyModifierSet(newDamage, set);
}
return newDamage;
}
/// <summary>
/// Remove any damage entries with zero damage.
/// </summary>

View File

@@ -0,0 +1,53 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
namespace Content.Shared.Hands.Components
{
[RegisterComponent]
[NetworkedComponent]
public sealed class HandVirtualItemComponent : Component
{
private EntityUid _blockingEntity;
public override string Name => "HandVirtualItem";
/// <summary>
/// The entity blocking this hand.
/// </summary>
public EntityUid BlockingEntity
{
get => _blockingEntity;
set
{
_blockingEntity = value;
Dirty();
}
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new VirtualItemComponentState(BlockingEntity);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not VirtualItemComponentState pullState)
return;
_blockingEntity = pullState.BlockingEntity;
}
[Serializable, NetSerializable]
public sealed class VirtualItemComponentState : ComponentState
{
public readonly EntityUid BlockingEntity;
public VirtualItemComponentState(EntityUid blockingEntity)
{
BlockingEntity = blockingEntity;
}
}
}
}

View File

@@ -1,50 +0,0 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
namespace Content.Shared.Hands.Components
{
[RegisterComponent]
[NetworkedComponent]
public sealed class HandVirtualPullComponent : Component
{
private EntityUid _pulledEntity;
public override string Name => "HandVirtualPull";
public EntityUid PulledEntity
{
get => _pulledEntity;
set
{
_pulledEntity = value;
Dirty();
}
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new VirtualPullComponentState(_pulledEntity);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not VirtualPullComponentState pullState)
return;
_pulledEntity = pullState.PulledEntity;
}
[Serializable, NetSerializable]
public sealed class VirtualPullComponentState : ComponentState
{
public readonly EntityUid PulledEntity;
public VirtualPullComponentState(EntityUid pulledEntity)
{
PulledEntity = pulledEntity;
}
}
}
}

View File

@@ -228,7 +228,23 @@ namespace Content.Shared.Hands.Components
}
}
private bool TryGetHandHoldingEntity(IEntity entity, [NotNullWhen(true)] out Hand? handFound)
/// <summary>
/// Returns the number of hands that have no items in them.
/// </summary>
/// <returns></returns>
public int GetFreeHands()
{
int acc = 0;
foreach (var hand in Hands)
{
if (hand.HeldEntity == null)
acc += 1;
}
return acc;
}
public bool TryGetHandHoldingEntity(IEntity entity, [NotNullWhen(true)] out Hand? handFound)
{
handFound = null;
@@ -418,6 +434,7 @@ namespace Content.Shared.Hands.Components
Logger.Error($"{nameof(SharedHandsComponent)} on {Owner} could not remove {heldEntity} from {handContainer}.");
return;
}
OnHeldEntityRemovedFromHand(heldEntity, hand.ToHandState());
HandsModified();

View File

@@ -96,4 +96,20 @@ namespace Content.Shared.Hands
HandName = handName;
}
}
/// <summary>
/// Raised directed on both the blocking entity and user when
/// a virtual hand item is deleted.
/// </summary>
public class VirtualItemDeletedEvent : EntityEventArgs
{
public EntityUid BlockingEntity;
public EntityUid User;
public VirtualItemDeletedEvent(EntityUid blockingEntity, EntityUid user)
{
BlockingEntity = blockingEntity;
User = user;
}
}
}

View File

@@ -122,6 +122,8 @@ namespace Content.Shared.Pulling.Components
}
}
valuePuller.Pulling = Owner;
// Continue with pulling process.
var pullAttempt = new PullAttemptMessage(pullerPhysics, _physics);
@@ -241,7 +243,7 @@ namespace Content.Shared.Pulling.Components
Puller = puller;
if (Puller != puller)
if(Puller != puller)
{
return false;
}
@@ -266,6 +268,11 @@ namespace Content.Shared.Pulling.Components
_physics.RemoveJoint(_pullJoint);
}
if (user != null && user.TryGetComponent<SharedPullerComponent>(out var puller))
{
puller.Pulling = null;
}
_pullJoint = null;
Puller = null;
return true;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Movement.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
using Component = Robust.Shared.GameObjects.Component;
namespace Content.Shared.Pulling.Components
@@ -11,14 +12,15 @@ namespace Content.Shared.Pulling.Components
private IEntity? _pulling;
public float WalkSpeedModifier => Pulling == null ? 1.0f : 0.75f;
public float WalkSpeedModifier => _pulling == null ? 1.0f : 0.75f;
public float SprintSpeedModifier => Pulling == null ? 1.0f : 0.75f;
public float SprintSpeedModifier => _pulling == null ? 1.0f : 0.75f;
[ViewVariables]
public IEntity? Pulling
{
get => _pulling;
private set
set
{
if (_pulling == value)
{

View File

@@ -1,10 +1,11 @@
using Content.Shared.Alert;
using Content.Shared.Hands;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Shared.Pulling
namespace Content.Shared.Pulling.Systems
{
[UsedImplicitly]
public sealed class SharedPullerSystem : EntitySystem
@@ -15,6 +16,21 @@ namespace Content.Shared.Pulling
SubscribeLocalEvent<SharedPullerComponent, PullStartedMessage>(PullerHandlePullStarted);
SubscribeLocalEvent<SharedPullerComponent, PullStoppedMessage>(PullerHandlePullStopped);
SubscribeLocalEvent<SharedPullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
}
private void OnVirtualItemDeleted(EntityUid uid, SharedPullerComponent component, VirtualItemDeletedEvent args)
{
if (component.Pulling == null)
return;
if (component.Pulling == EntityManager.GetEntity(args.BlockingEntity));
{
if (ComponentManager.TryGetComponent<SharedPullableComponent>(args.BlockingEntity, out var comp))
{
comp.TryStopPull(EntityManager.GetEntity(uid));
}
}
}
private static void PullerHandlePullStarted(