Melee refactor (#10897)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Server.Clothing.Components;
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Damage.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Abilities.Boxer
|
||||
@@ -24,25 +17,22 @@ namespace Content.Server.Abilities.Boxer
|
||||
SubscribeLocalEvent<BoxingGlovesComponent, StaminaMeleeHitEvent>(OnStamHit);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, BoxerComponent boxer, ComponentInit args)
|
||||
private void OnInit(EntityUid uid, BoxerComponent component, ComponentInit args)
|
||||
{
|
||||
if (TryComp<MeleeWeaponComponent>(uid, out var meleeComp))
|
||||
meleeComp.Range *= boxer.RangeBonus;
|
||||
meleeComp.Range *= component.RangeBonus;
|
||||
}
|
||||
private void GetDamageModifiers(EntityUid uid, BoxerComponent component, ItemMeleeDamageEvent args)
|
||||
{
|
||||
if (component.UnarmedModifiers == default!)
|
||||
{
|
||||
Logger.Warning("BoxerComponent on " + uid + " couldn't get damage modifiers. Know that adding components with damage modifiers through VV or similar is unsupported.");
|
||||
return;
|
||||
}
|
||||
|
||||
args.ModifiersList.Add(component.UnarmedModifiers);
|
||||
}
|
||||
|
||||
private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, StaminaMeleeHitEvent args)
|
||||
{
|
||||
_containerSystem.TryGetContainingContainer(uid, out var equipee);
|
||||
if (TryComp<BoxerComponent>(equipee?.Owner, out var boxer))
|
||||
if (!_containerSystem.TryGetContainingContainer(uid, out var equipee))
|
||||
return;
|
||||
|
||||
if (TryComp<BoxerComponent>(equipee.Owner, out var boxer))
|
||||
args.Multiplier *= boxer.BoxingGlovesModifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Content.Server.Atmos.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Server.Temperature.Systems;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Atmos;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -12,6 +11,7 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Weapons.Melee;
|
||||
|
||||
namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
@@ -78,7 +78,8 @@ namespace Content.Server.Chemistry.Components
|
||||
target.Value.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message"));
|
||||
var meleeSys = EntitySystem.Get<MeleeWeaponSystem>();
|
||||
var angle = Angle.FromWorldVec(_entMan.GetComponent<TransformComponent>(target.Value).WorldPosition - _entMan.GetComponent<TransformComponent>(user).WorldPosition);
|
||||
meleeSys.SendLunge(angle, user);
|
||||
// TODO: This should just be using melee attacks...
|
||||
// meleeSys.SendLunge(angle, user);
|
||||
}
|
||||
|
||||
SoundSystem.Play(_injectSound.GetSound(), Filter.Pvs(user), user);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
@@ -10,7 +13,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
private void InitializeHypospray()
|
||||
{
|
||||
SubscribeLocalEvent<HyposprayComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<HyposprayComponent, ClickAttackEvent>(OnClickAttack);
|
||||
SubscribeLocalEvent<HyposprayComponent, MeleeHitEvent>(OnAttack);
|
||||
SubscribeLocalEvent<HyposprayComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
|
||||
}
|
||||
@@ -39,12 +42,12 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
comp.TryDoInject(target, user);
|
||||
}
|
||||
|
||||
public void OnClickAttack(EntityUid uid, HyposprayComponent comp, ClickAttackEvent args)
|
||||
public void OnAttack(EntityUid uid, HyposprayComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (args.Target == null)
|
||||
if (!args.HitEntities.Any())
|
||||
return;
|
||||
|
||||
comp.TryDoInject(args.Target.Value, args.User);
|
||||
comp.TryDoInject(args.HitEntities.First(), args.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +1,22 @@
|
||||
using Content.Server.Actions.Events;
|
||||
using Content.Server.Administration.Components;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Contests;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Stunnable;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Server.CombatMode
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class CombatModeSystem : SharedCombatModeSystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly MeleeWeaponSystem _meleeWeaponSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
[Dependency] private readonly ContestsSystem _contests = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, DisarmActionEvent>(OnEntityActionPerform);
|
||||
SubscribeLocalEvent<SharedCombatModeComponent, ComponentGetState>(OnGetState);
|
||||
}
|
||||
|
||||
private void OnEntityActionPerform(EntityUid uid, SharedCombatModeComponent component, DisarmActionEvent args)
|
||||
private void OnGetState(EntityUid uid, SharedCombatModeComponent component, ref ComponentGetState args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!_actionBlockerSystem.CanAttack(args.Performer))
|
||||
return;
|
||||
|
||||
if (TryComp<HandsComponent>(args.Performer, out var hands)
|
||||
&& hands.ActiveHand != null
|
||||
&& !hands.ActiveHand.IsEmpty)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("disarm-action-free-hand"), args.Performer, Filter.Entities(args.Performer));
|
||||
return;
|
||||
}
|
||||
|
||||
EntityUid? inTargetHand = null;
|
||||
|
||||
if (TryComp<HandsComponent>(args.Target, out HandsComponent? targetHandsComponent)
|
||||
&& targetHandsComponent.ActiveHand != null
|
||||
&& !targetHandsComponent.ActiveHand.IsEmpty)
|
||||
{
|
||||
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
|
||||
}
|
||||
|
||||
var attemptEvent = new DisarmAttemptEvent(args.Target, args.Performer,inTargetHand);
|
||||
|
||||
if (inTargetHand != null)
|
||||
{
|
||||
RaiseLocalEvent(inTargetHand.Value, attemptEvent, true);
|
||||
}
|
||||
RaiseLocalEvent(args.Target, attemptEvent, true);
|
||||
if (attemptEvent.Cancelled)
|
||||
return;
|
||||
|
||||
var diff = Transform(args.Target).MapPosition.Position - Transform(args.Performer).MapPosition.Position;
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
|
||||
var filterAll = Filter.Pvs(args.Performer);
|
||||
var filterOther = filterAll.RemoveWhereAttachedEntity(e => e == args.Performer);
|
||||
|
||||
args.Handled = true;
|
||||
var chance = CalculateDisarmChance(args.Performer, args.Target, inTargetHand, component);
|
||||
if (_random.Prob(chance))
|
||||
{
|
||||
SoundSystem.Play(component.DisarmFailSound.GetSound(), Filter.Pvs(args.Performer), args.Performer, AudioHelpers.WithVariation(0.025f));
|
||||
|
||||
var msgOther = Loc.GetString(
|
||||
"disarm-action-popup-message-other-clients",
|
||||
("performerName", Identity.Entity(args.Performer, EntityManager)),
|
||||
("targetName", Identity.Entity(args.Target, EntityManager)));
|
||||
|
||||
var msgUser = Loc.GetString("disarm-action-popup-message-cursor", ("targetName", Identity.Entity(args.Target, EntityManager)));
|
||||
|
||||
_popupSystem.PopupEntity(msgOther, args.Performer, filterOther);
|
||||
_popupSystem.PopupEntity(msgUser, args.Performer, Filter.Entities(args.Performer));
|
||||
|
||||
_meleeWeaponSystem.SendLunge(angle, args.Performer);
|
||||
return;
|
||||
}
|
||||
|
||||
_meleeWeaponSystem.SendAnimation("disarm", angle, args.Performer, args.Performer, new[] { args.Target });
|
||||
SoundSystem.Play(component.DisarmSuccessSound.GetSound(), filterAll, args.Performer, AudioHelpers.WithVariation(0.025f));
|
||||
_adminLogger.Add(LogType.DisarmedAction, $"{ToPrettyString(args.Performer):user} used disarm on {ToPrettyString(args.Target):target}");
|
||||
|
||||
var eventArgs = new DisarmedEvent() { Target = args.Target, Source = args.Performer, PushProbability = (1 - chance) };
|
||||
RaiseLocalEvent(args.Target, eventArgs, true);
|
||||
}
|
||||
|
||||
|
||||
private float CalculateDisarmChance(EntityUid disarmer, EntityUid disarmed, EntityUid? inTargetHand, SharedCombatModeComponent disarmerComp)
|
||||
{
|
||||
if (HasComp<DisarmProneComponent>(disarmer))
|
||||
return 1.0f;
|
||||
|
||||
if (HasComp<DisarmProneComponent>(disarmed))
|
||||
return 0.0f;
|
||||
|
||||
var contestResults = 1 - _contests.OverallStrengthContest(disarmer, disarmed);
|
||||
|
||||
float chance = (disarmerComp.BaseDisarmFailChance + contestResults);
|
||||
|
||||
if (inTargetHand != null && TryComp<DisarmMalusComponent>(inTargetHand, out var malus))
|
||||
{
|
||||
chance += malus.Malus;
|
||||
}
|
||||
|
||||
return Math.Clamp(chance, 0f, 1f);
|
||||
args.State = new CombatModeComponentState(component.IsInCombatMode, component.ActiveZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.Contests
|
||||
/// >1 = Advantage to roller
|
||||
/// <1 = Advantage to target
|
||||
/// Roller should be the entity with an advantage from being bigger/healthier/more skilled, etc.
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public sealed class ContestsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedMobStateSystem _mobStateSystem = default!;
|
||||
@@ -27,13 +27,10 @@ namespace Content.Server.Contests
|
||||
if (!Resolve(roller, ref rollerPhysics, false) || !Resolve(target, ref targetPhysics, false))
|
||||
return 1f;
|
||||
|
||||
if (rollerPhysics == null || targetPhysics == null)
|
||||
return 1f;
|
||||
|
||||
if (targetPhysics.FixturesMass == 0)
|
||||
return 1f;
|
||||
|
||||
return (rollerPhysics.FixturesMass / targetPhysics.FixturesMass);
|
||||
return rollerPhysics.FixturesMass / targetPhysics.FixturesMass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,18 +44,15 @@ namespace Content.Server.Contests
|
||||
if (!Resolve(roller, ref rollerDamage, false) || !Resolve(target, ref targetDamage, false))
|
||||
return 1f;
|
||||
|
||||
if (rollerDamage == null || targetDamage == null)
|
||||
return 1f;
|
||||
|
||||
// First, we'll see what health they go into crit at.
|
||||
float rollerThreshold = 100f;
|
||||
float targetThreshold = 100f;
|
||||
|
||||
if (TryComp<MobStateComponent>(roller, out var rollerState) && rollerState != null &&
|
||||
if (TryComp<MobStateComponent>(roller, out var rollerState) &&
|
||||
_mobStateSystem.TryGetEarliestIncapacitatedState(rollerState, 10000, out _, out var rollerCritThreshold))
|
||||
rollerThreshold = (float) rollerCritThreshold;
|
||||
|
||||
if (TryComp<MobStateComponent>(target, out var targetState) && targetState != null &&
|
||||
if (TryComp<MobStateComponent>(target, out var targetState) &&
|
||||
_mobStateSystem.TryGetEarliestIncapacitatedState(targetState, 10000, out _, out var targetCritThreshold))
|
||||
targetThreshold = (float) targetCritThreshold;
|
||||
|
||||
@@ -97,8 +91,9 @@ namespace Content.Server.Contests
|
||||
var massMultiplier = massWeight / weightTotal;
|
||||
var stamMultiplier = stamWeight / weightTotal;
|
||||
|
||||
return ((DamageContest(roller, target) * damageMultiplier) + (MassContest(roller, target) * massMultiplier)
|
||||
+ (StaminaContest(roller, target) * stamMultiplier));
|
||||
return DamageContest(roller, target) * damageMultiplier +
|
||||
MassContest(roller, target) * massMultiplier +
|
||||
StaminaContest(roller, target) * stamMultiplier;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -109,6 +104,7 @@ namespace Content.Server.Contests
|
||||
{
|
||||
return score switch
|
||||
{
|
||||
// TODO: Should just be a curve
|
||||
<= 0 => 1f,
|
||||
<= 0.25f => 0.9f,
|
||||
<= 0.5f => 0.75f,
|
||||
|
||||
@@ -7,10 +7,4 @@ public sealed class StaminaDamageOnHitComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("damage")]
|
||||
public float Damage = 30f;
|
||||
|
||||
/// <summary>
|
||||
/// Play a sound when this knocks down an entity.
|
||||
/// </summary>
|
||||
[DataField("knockdownSound")]
|
||||
public SoundSpecifier? KnockdownSound;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Damage.Events;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Stunnable;
|
||||
@@ -123,7 +123,7 @@ public sealed class StaminaSystem : EntitySystem
|
||||
foreach (var comp in toHit)
|
||||
{
|
||||
var oldDamage = comp.StaminaDamage;
|
||||
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp, component.KnockdownSound);
|
||||
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp);
|
||||
if (comp.StaminaDamage.Equals(oldDamage))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("stamina-resist"), comp.Owner, Filter.Entities(args.User));
|
||||
@@ -150,7 +150,7 @@ public sealed class StaminaSystem : EntitySystem
|
||||
_alerts.ShowAlert(uid, AlertType.Stamina, (short) severity);
|
||||
}
|
||||
|
||||
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null, SoundSpecifier? knockdownSound = null)
|
||||
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false) || component.Critical) return;
|
||||
|
||||
@@ -181,8 +181,6 @@ public sealed class StaminaSystem : EntitySystem
|
||||
{
|
||||
if (component.StaminaDamage >= component.CritThreshold)
|
||||
{
|
||||
if (knockdownSound != null)
|
||||
SoundSystem.Play(knockdownSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, knockdownSound.Params);
|
||||
EnterStamCrit(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Events;
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Content.Server.Entry
|
||||
"ConstructionGhost",
|
||||
"IconSmooth",
|
||||
"InteractionOutline",
|
||||
"MeleeWeaponArcAnimation",
|
||||
"AnimationsTest",
|
||||
"ItemStatus",
|
||||
"Marker",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Flash.Components;
|
||||
using Content.Server.Light.EntitySystems;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Flash;
|
||||
using Content.Shared.IdentityManagement;
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
|
||||
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Pulling;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -20,7 +16,6 @@ using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Random;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Server.Interaction
|
||||
{
|
||||
@@ -34,9 +29,8 @@ namespace Content.Server.Interaction
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -61,7 +55,7 @@ namespace Content.Server.Interaction
|
||||
if (Deleted(target))
|
||||
return false;
|
||||
|
||||
if (!target.TryGetContainer(out var container))
|
||||
if (!_container.TryGetContainingContainer(target, out var container))
|
||||
return false;
|
||||
|
||||
if (!TryComp(container.Owner, out ServerStorageComponent? storage))
|
||||
@@ -74,7 +68,7 @@ namespace Content.Server.Interaction
|
||||
return false;
|
||||
|
||||
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
||||
return _uiSystem.SessionHasOpenUi(container.Owner, StorageUiKey.Key, actor.PlayerSession);
|
||||
return _uiSystem.SessionHasOpenUi(container.Owner, SharedStorageComponent.StorageUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
#region Drag drop
|
||||
@@ -132,21 +126,6 @@ namespace Content.Server.Interaction
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Entity will try and use their active hand at the target location.
|
||||
/// Don't use for players
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="coords"></param>
|
||||
/// <param name="uid"></param>
|
||||
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (HasComp<ActorComponent>(entity))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
UserInteraction(entity, coords, uid);
|
||||
}
|
||||
|
||||
private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
||||
@@ -169,103 +148,5 @@ namespace Content.Server.Interaction
|
||||
|
||||
return _pullSystem.TogglePull(userEntity.Value, pull);
|
||||
}
|
||||
|
||||
public override void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid? target = null)
|
||||
{
|
||||
// TODO PREDICTION move server-side interaction logic into the shared system for interaction prediction.
|
||||
if (!ValidateInteractAndFace(user, coordinates))
|
||||
return;
|
||||
|
||||
// Check general interaction blocking.
|
||||
if (!_actionBlockerSystem.CanInteract(user, target))
|
||||
return;
|
||||
|
||||
// Check combat-specific action blocking.
|
||||
if (!_actionBlockerSystem.CanAttack(user, target))
|
||||
return;
|
||||
|
||||
if (!wideAttack)
|
||||
{
|
||||
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
||||
if (target != null && !Deleted(target.Value) && !ContainerSystem.IsInSameOrParentContainer(user, target.Value) && !CanAccessViaStorage(user, target.Value))
|
||||
{
|
||||
Logger.WarningS("system.interaction",
|
||||
$"User entity {ToPrettyString(user):user} clicked on object {ToPrettyString(target.Value):target} that isn't the parent, child, or in the same container");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Replace with body attack range when we get something like arm length or telekinesis or something.
|
||||
var unobstructed = (target == null)
|
||||
? InRangeUnobstructed(user, coordinates)
|
||||
: InRangeUnobstructed(user, target.Value);
|
||||
|
||||
if (!unobstructed)
|
||||
return;
|
||||
}
|
||||
else if (ContainerSystem.IsEntityInContainer(user))
|
||||
{
|
||||
// No wide attacking while in containers (holos, lockers, etc).
|
||||
// Can't think of a valid case where you would want this.
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify user has a hand, and find what object they are currently holding in their active hand
|
||||
if (TryComp(user, out HandsComponent? hands))
|
||||
{
|
||||
var item = hands.ActiveHandEntity;
|
||||
|
||||
if (!Deleted(item))
|
||||
{
|
||||
var meleeVee = new MeleeAttackAttemptEvent();
|
||||
RaiseLocalEvent(item.Value, ref meleeVee, true);
|
||||
|
||||
if (meleeVee.Cancelled) return;
|
||||
|
||||
if (wideAttack)
|
||||
{
|
||||
var ev = new WideAttackEvent(item.Value, user, coordinates);
|
||||
RaiseLocalEvent(item.Value, ev, false);
|
||||
|
||||
if (ev.Handled)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new ClickAttackEvent(item.Value, user, coordinates, target);
|
||||
RaiseLocalEvent(item.Value, ev, false);
|
||||
|
||||
if (ev.Handled)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!wideAttack && target != null && HasComp<ItemComponent>(target.Value))
|
||||
{
|
||||
// We pick up items if our hand is empty, even if we're in combat mode.
|
||||
InteractHand(user, target.Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this saner?
|
||||
// Attempt to do unarmed combat. We don't check for handled just because at this point it doesn't matter.
|
||||
|
||||
var used = user;
|
||||
|
||||
if (_inventory.TryGetSlotEntity(user, "gloves", out var gloves) && HasComp<MeleeWeaponComponent>(gloves))
|
||||
used = (EntityUid) gloves;
|
||||
|
||||
if (wideAttack)
|
||||
{
|
||||
var ev = new WideAttackEvent(used, user, coordinates);
|
||||
RaiseLocalEvent(used, ev, false);
|
||||
if (ev.Handled)
|
||||
_adminLogger.Add(LogType.AttackUnarmedWide, LogImpact.Low, $"{ToPrettyString(user):user} wide attacked at {coordinates}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new ClickAttackEvent(used, user, coordinates, target);
|
||||
RaiseLocalEvent(used, ev, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Content.Server.Doors.Components;
|
||||
using Content.Server.Magic.Events;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Spawners.Components;
|
||||
using Content.Server.Weapon.Ranged.Systems;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Body.Components;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.NPC.Components;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
|
||||
namespace Content.Server.NPC.Systems;
|
||||
|
||||
@@ -64,7 +64,7 @@ public sealed partial class NPCCombatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (weapon.CooldownEnd > _timing.CurTime)
|
||||
if (weapon.NextAttack > _timing.CurTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -84,6 +84,6 @@ public sealed partial class NPCCombatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
_interaction.DoAttack(component.Owner, targetXform.Coordinates, false, component.Target);
|
||||
_melee.AttemptLightAttack(component.Owner, weapon, component.Target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Weapon.Ranged.Systems;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -17,6 +18,7 @@ public sealed partial class NPCCombatSystem : EntitySystem
|
||||
[Dependency] private readonly GunSystem _gun = default!;
|
||||
[Dependency] private readonly InteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using GunSystem = Content.Server.Weapon.Ranged.Systems.GunSystem;
|
||||
|
||||
namespace Content.Server.Projectiles
|
||||
{
|
||||
@@ -52,7 +50,7 @@ namespace Content.Server.Projectiles
|
||||
{
|
||||
if (modifiedDamage.Total > FixedPoint2.Zero)
|
||||
{
|
||||
RaiseNetworkEvent(new DamageEffectEvent(otherEntity), Filter.Pvs(otherEntity, entityManager: EntityManager));
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {otherEntity}), Filter.Pvs(otherEntity, entityManager: EntityManager));
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.BulletHit,
|
||||
|
||||
@@ -28,6 +28,7 @@ using Content.Server.Popups;
|
||||
using Content.Shared.Destructible;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems
|
||||
@@ -48,6 +49,7 @@ namespace Content.Server.Storage.EntitySystems
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -263,6 +265,9 @@ namespace Content.Server.Storage.EntitySystems
|
||||
/// <returns></returns>
|
||||
private void OnActivate(EntityUid uid, ServerStorageComponent storageComp, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || _combatMode.IsInCombatMode(args.User))
|
||||
return;
|
||||
|
||||
if (TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
|
||||
return;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.Power.Events;
|
||||
using Content.Server.Speech.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction.Events;
|
||||
|
||||
@@ -3,7 +3,7 @@ using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Cargo.Systems;
|
||||
using Content.Server.EUI;
|
||||
@@ -5,6 +6,7 @@ using Content.Shared.Administration;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -16,7 +18,7 @@ public sealed class StatValuesCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "showvalues";
|
||||
public string Description => "Dumps all stats for a particular category into a table.";
|
||||
public string Help => $"{Command} <cargosell / lathsell>";
|
||||
public string Help => $"{Command} <cargosell / lathsell / melee>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (shell.Player is not IPlayerSession pSession)
|
||||
@@ -41,6 +43,9 @@ public sealed class StatValuesCommand : IConsoleCommand
|
||||
case "lathesell":
|
||||
message = GetLatheMessage();
|
||||
break;
|
||||
case "melee":
|
||||
message = GetMelee();
|
||||
break;
|
||||
default:
|
||||
shell.WriteError($"{args[0]} is not a valid stat!");
|
||||
return;
|
||||
@@ -100,6 +105,51 @@ public sealed class StatValuesCommand : IConsoleCommand
|
||||
return state;
|
||||
}
|
||||
|
||||
private StatValuesEuiMessage GetMelee()
|
||||
{
|
||||
var compFactory = IoCManager.Resolve<IComponentFactory>();
|
||||
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
var values = new List<string[]>();
|
||||
|
||||
foreach (var proto in protoManager.EnumeratePrototypes<EntityPrototype>())
|
||||
{
|
||||
if (proto.Abstract ||
|
||||
!proto.Components.TryGetValue(compFactory.GetComponentName(typeof(MeleeWeaponComponent)),
|
||||
out var meleeComp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var comp = (MeleeWeaponComponent) meleeComp.Component;
|
||||
|
||||
// TODO: Wielded damage
|
||||
// TODO: Esword damage
|
||||
|
||||
values.Add(new[]
|
||||
{
|
||||
proto.ID,
|
||||
(comp.Damage.Total * comp.AttackRate).ToString(),
|
||||
comp.AttackRate.ToString(CultureInfo.CurrentCulture),
|
||||
comp.Damage.Total.ToString(),
|
||||
comp.Range.ToString(CultureInfo.CurrentCulture),
|
||||
});
|
||||
}
|
||||
|
||||
var state = new StatValuesEuiMessage()
|
||||
{
|
||||
Title = "Cargo sell prices",
|
||||
Headers = new List<string>()
|
||||
{
|
||||
"ID",
|
||||
"Price",
|
||||
},
|
||||
Values = values,
|
||||
};
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private StatValuesEuiMessage GetLatheMessage()
|
||||
{
|
||||
var values = new List<string[]>();
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
namespace Content.Server.Weapon.Melee.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class MeleeWeaponComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("hitSound")]
|
||||
public SoundSpecifier? HitSound;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("noDamageSound")]
|
||||
public SoundSpecifier NoDamageSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/tap.ogg");
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("missSound")]
|
||||
public SoundSpecifier MissSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("arcCooldownTime")]
|
||||
public float ArcCooldownTime { get; } = 1f;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("cooldownTime")]
|
||||
public float CooldownTime { get; } = 1f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("clickArc")]
|
||||
public string ClickArc { get; set; } = "punch";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("arc")]
|
||||
public string? Arc { get; set; } = "default";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("arcwidth")]
|
||||
public float ArcWidth { get; set; } = 90;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("range")]
|
||||
public float Range { get; set; } = 1;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("clickAttackEffect")]
|
||||
public bool ClickAttackEffect { get; set; } = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("hidden")]
|
||||
public bool HideFromExamine { get; set; } = false;
|
||||
|
||||
public TimeSpan LastAttackTime;
|
||||
public TimeSpan CooldownEnd;
|
||||
|
||||
[DataField("damage", required:true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
[DataField("bluntStaminaDamageFactor")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public FixedPoint2 BluntStaminaDamageFactor { get; set; } = 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -1,520 +0,0 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Cooldown;
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Damage.Systems;
|
||||
using Content.Server.Examine;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Weapon.Melee
|
||||
{
|
||||
public sealed class MeleeWeaponSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly ExamineSystem _examine = default!;
|
||||
[Dependency] private readonly StaminaSystem _staminaSystem = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||
|
||||
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
||||
|
||||
public const float DamagePitchVariation = 0.15f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnHandSelected);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, ClickAttackEvent>(OnClickAttack);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, WideAttackEvent>(OnWideAttack);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, GetVerbsEvent<ExamineVerb>>(OnMeleeExaminableVerb);
|
||||
SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(OnChemicalInjectorHit);
|
||||
}
|
||||
|
||||
private void OnMeleeExaminableVerb(EntityUid uid, MeleeWeaponComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess || component.HideFromExamine)
|
||||
return;
|
||||
|
||||
var getDamage = new ItemMeleeDamageEvent(component.Damage);
|
||||
RaiseLocalEvent(uid, getDamage, false);
|
||||
|
||||
var damageSpec = GetDamage(component);
|
||||
|
||||
if (damageSpec == null)
|
||||
damageSpec = new DamageSpecifier();
|
||||
|
||||
damageSpec += getDamage.BonusDamage;
|
||||
|
||||
if (damageSpec.Total == FixedPoint2.Zero)
|
||||
return;
|
||||
|
||||
var verb = new ExamineVerb()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
var markup = _damageable.GetDamageExamine(damageSpec, Loc.GetString("damage-melee"));
|
||||
_examine.SendExamineTooltip(args.User, uid, markup, false, false);
|
||||
},
|
||||
Text = Loc.GetString("damage-examinable-verb-text"),
|
||||
Message = Loc.GetString("damage-examinable-verb-message"),
|
||||
Category = VerbCategory.Examine,
|
||||
IconTexture = "/Textures/Interface/VerbIcons/smite.svg.192dpi.png"
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private DamageSpecifier? GetDamage(MeleeWeaponComponent component)
|
||||
{
|
||||
return component.Damage.Total > FixedPoint2.Zero ? component.Damage : null;
|
||||
}
|
||||
|
||||
private void OnHandSelected(EntityUid uid, MeleeWeaponComponent comp, HandSelectedEvent args)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
var cool = TimeSpan.FromSeconds(comp.CooldownTime * 0.5f);
|
||||
|
||||
if (curTime < comp.CooldownEnd)
|
||||
{
|
||||
if (comp.CooldownEnd - curTime < cool)
|
||||
{
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd += cool;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd = curTime + cool;
|
||||
}
|
||||
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
private void OnClickAttack(EntityUid owner, MeleeWeaponComponent comp, ClickAttackEvent args)
|
||||
{
|
||||
args.Handled = true;
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if (curTime < comp.CooldownEnd ||
|
||||
args.Target == null ||
|
||||
args.Target == owner ||
|
||||
args.User == args.Target)
|
||||
return;
|
||||
|
||||
var location = Transform(args.User).Coordinates;
|
||||
var diff = args.ClickLocation.ToMapPos(EntityManager) - location.ToMapPos(EntityManager);
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
|
||||
if (args.Target is {Valid: true} target)
|
||||
{
|
||||
// Raising a melee hit event which may handle combat for us
|
||||
var hitEvent = new MeleeHitEvent(new List<EntityUid>() { target }, args.User, comp.Damage);
|
||||
RaiseLocalEvent(owner, hitEvent, false);
|
||||
|
||||
if (!hitEvent.Handled)
|
||||
{
|
||||
var targets = new[] { target };
|
||||
SendAnimation(comp.ClickArc, angle, args.User, owner, targets, comp.ClickAttackEffect, false);
|
||||
|
||||
// Raising a GetMeleeDamage event which gets our damage
|
||||
var getDamageEvent = new ItemMeleeDamageEvent(comp.Damage);
|
||||
RaiseLocalEvent(owner, getDamageEvent, false);
|
||||
|
||||
RaiseLocalEvent(target, new AttackedEvent(args.Used, args.User, args.ClickLocation), true);
|
||||
|
||||
var modifiersList = getDamageEvent.ModifiersList;
|
||||
modifiersList.AddRange(hitEvent.ModifiersList);
|
||||
var modifiedDamage = DamageSpecifier.ApplyModifierSets(comp.Damage + hitEvent.BonusDamage + getDamageEvent.BonusDamage, modifiersList);
|
||||
var damageResult = _damageable.TryChangeDamage(target, modifiedDamage);
|
||||
|
||||
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
|
||||
{
|
||||
FixedPoint2 bluntDamage;
|
||||
// If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor
|
||||
if (damageResult.DamageDict.TryGetValue("Blunt", out bluntDamage))
|
||||
{
|
||||
_staminaSystem.TakeStaminaDamage(target, (bluntDamage * comp.BluntStaminaDamageFactor).Float());
|
||||
}
|
||||
|
||||
if (args.Used == args.User)
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using their hands and dealt {damageResult.Total:damage} damage");
|
||||
else
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
|
||||
|
||||
PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, comp.HitSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundSystem.Play((hitEvent.HitSoundOverride != null)
|
||||
? hitEvent.HitSoundOverride.GetSound()
|
||||
: comp.NoDamageSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
|
||||
}
|
||||
|
||||
comp.LastAttackTime = curTime;
|
||||
SetAttackCooldown(owner, comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime), comp);
|
||||
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the melee weapon cooldown's end to the specified value. Will use the maximum of the existing cooldown or the new one.
|
||||
/// </summary>
|
||||
public void SetAttackCooldown(EntityUid uid, TimeSpan endTime, MeleeWeaponComponent? component = null)
|
||||
{
|
||||
// Some other system may want to artificially inflate melee weapon CD.
|
||||
if (!Resolve(uid, ref component) || component.CooldownEnd > endTime) return;
|
||||
|
||||
component.CooldownEnd = endTime;
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(component.LastAttackTime, component.CooldownEnd));
|
||||
}
|
||||
|
||||
private void OnWideAttack(EntityUid owner, MeleeWeaponComponent comp, WideAttackEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(comp.Arc)) return;
|
||||
|
||||
args.Handled = true;
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if (curTime < comp.CooldownEnd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var location = EntityManager.GetComponent<TransformComponent>(args.User).Coordinates;
|
||||
var diff = args.ClickLocation.ToMapPos(EntityManager) - location.ToMapPos(EntityManager);
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
|
||||
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
|
||||
var entities = ArcRayCast(EntityManager.GetComponent<TransformComponent>(args.User).WorldPosition, angle, comp.ArcWidth, comp.Range, EntityManager.GetComponent<TransformComponent>(owner).MapID, args.User);
|
||||
|
||||
var hitEntities = new List<EntityUid>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.IsInContainer() || entity == args.User)
|
||||
continue;
|
||||
|
||||
if (EntityManager.HasComponent<DamageableComponent>(entity))
|
||||
{
|
||||
hitEntities.Add(entity);
|
||||
}
|
||||
}
|
||||
// Raising a melee hit event which may handle combat for us
|
||||
var hitEvent = new MeleeHitEvent(hitEntities, args.User, comp.Damage);
|
||||
RaiseLocalEvent(owner, hitEvent, false);
|
||||
SendAnimation(comp.Arc, angle, args.User, owner, hitEntities);
|
||||
|
||||
if (!hitEvent.Handled)
|
||||
{
|
||||
var getDamageEvent = new ItemMeleeDamageEvent(comp.Damage);
|
||||
RaiseLocalEvent(owner, getDamageEvent, false);
|
||||
|
||||
var modifiersList = getDamageEvent.ModifiersList;
|
||||
modifiersList.AddRange(hitEvent.ModifiersList);
|
||||
var modifiedDamage = DamageSpecifier.ApplyModifierSets(comp.Damage + hitEvent.BonusDamage + getDamageEvent.BonusDamage, modifiersList);
|
||||
var appliedDamage = new DamageSpecifier();
|
||||
|
||||
foreach (var entity in hitEntities)
|
||||
{
|
||||
RaiseLocalEvent(entity, new AttackedEvent(args.Used, args.User, args.ClickLocation), true);
|
||||
|
||||
var damageResult = _damageable.TryChangeDamage(entity, modifiedDamage);
|
||||
|
||||
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
|
||||
{
|
||||
appliedDamage += damageResult;
|
||||
|
||||
if (args.Used == args.User)
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(entity):target} using their hands and dealt {damageResult.Total:damage} damage");
|
||||
else
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(entity):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
|
||||
}
|
||||
}
|
||||
|
||||
if (entities.Count != 0)
|
||||
{
|
||||
if (appliedDamage.Total > FixedPoint2.Zero)
|
||||
{
|
||||
var target = entities.First();
|
||||
PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, comp.HitSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundSystem.Play((hitEvent.HitSoundOverride != null)
|
||||
? hitEvent.HitSoundOverride.GetSound()
|
||||
: comp.NoDamageSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
|
||||
}
|
||||
}
|
||||
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.ArcCooldownTime);
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd));
|
||||
}
|
||||
|
||||
public static string? GetHighestDamageSound(DamageSpecifier modifiedDamage, IPrototypeManager protoManager)
|
||||
{
|
||||
var groups = modifiedDamage.GetDamagePerGroup(protoManager);
|
||||
|
||||
// Use group if it's exclusive, otherwise fall back to type.
|
||||
if (groups.Count == 1)
|
||||
{
|
||||
return groups.Keys.First();
|
||||
}
|
||||
|
||||
var highestDamage = FixedPoint2.Zero;
|
||||
string? highestDamageType = null;
|
||||
|
||||
foreach (var (type, damage) in modifiedDamage.DamageDict)
|
||||
{
|
||||
if (damage <= highestDamage) continue;
|
||||
highestDamageType = type;
|
||||
}
|
||||
|
||||
return highestDamageType;
|
||||
}
|
||||
|
||||
private void PlayHitSound(EntityUid target, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound)
|
||||
{
|
||||
var playedSound = false;
|
||||
|
||||
// Play sound based off of highest damage type.
|
||||
if (TryComp<MeleeSoundComponent>(target, out var damageSoundComp))
|
||||
{
|
||||
if (type == null && damageSoundComp.NoDamageSound != null)
|
||||
{
|
||||
SoundSystem.Play(damageSoundComp.NoDamageSound.GetSound(), Filter.Pvs(target, entityManager: EntityManager), target, AudioHelpers.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (type != null && damageSoundComp.SoundTypes?.TryGetValue(type, out var damageSoundType) == true)
|
||||
{
|
||||
SoundSystem.Play(damageSoundType.GetSound(), Filter.Pvs(target, entityManager: EntityManager), target, AudioHelpers.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (type != null && damageSoundComp.SoundGroups?.TryGetValue(type, out var damageSoundGroup) == true)
|
||||
{
|
||||
SoundSystem.Play(damageSoundGroup.GetSound(), Filter.Pvs(target, entityManager: EntityManager), target, AudioHelpers.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Use weapon sounds if the thing being hit doesn't specify its own sounds.
|
||||
if (!playedSound)
|
||||
{
|
||||
if (hitSoundOverride != null)
|
||||
{
|
||||
SoundSystem.Play(hitSoundOverride.GetSound(), Filter.Pvs(target, entityManager: EntityManager), target, AudioHelpers.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (hitSound != null)
|
||||
{
|
||||
SoundSystem.Play(hitSound.GetSound(), Filter.Pvs(target, entityManager: EntityManager), target);
|
||||
playedSound = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to generic sounds.
|
||||
if (!playedSound)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
// Unfortunately heat returns caustic group so can't just use the damagegroup in that instance.
|
||||
case "Burn":
|
||||
case "Heat":
|
||||
case "Cold":
|
||||
SoundSystem.Play("/Audio/Items/welder.ogg", Filter.Pvs(target, entityManager: EntityManager), target);
|
||||
break;
|
||||
// No damage, fallback to tappies
|
||||
case null:
|
||||
SoundSystem.Play("/Audio/Weapons/tap.ogg", Filter.Pvs(target, entityManager: EntityManager), target);
|
||||
break;
|
||||
case "Brute":
|
||||
SoundSystem.Play("/Audio/Weapons/smash.ogg", Filter.Pvs(target, entityManager: EntityManager), target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<EntityUid> ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, EntityUid ignore)
|
||||
{
|
||||
var widthRad = Angle.FromDegrees(arcWidth);
|
||||
var increments = 1 + 35 * (int) Math.Ceiling(widthRad / (2 * Math.PI));
|
||||
var increment = widthRad / increments;
|
||||
var baseAngle = angle - widthRad / 2;
|
||||
|
||||
var resSet = new HashSet<EntityUid>();
|
||||
|
||||
for (var i = 0; i < increments; i++)
|
||||
{
|
||||
var castAngle = new Angle(baseAngle + increment * i);
|
||||
var res = Get<SharedPhysicsSystem>().IntersectRay(mapId,
|
||||
new CollisionRay(position, castAngle.ToWorldVec(),
|
||||
(int) (CollisionGroup.MobMask | CollisionGroup.Opaque)), range, ignore).ToList();
|
||||
|
||||
if (res.Count != 0)
|
||||
{
|
||||
resSet.Add(res[0].HitEntity);
|
||||
}
|
||||
}
|
||||
|
||||
return resSet;
|
||||
}
|
||||
|
||||
private void OnChemicalInjectorHit(EntityUid owner, MeleeChemicalInjectorComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!_solutionsSystem.TryGetInjectableSolution(owner, out var solutionContainer))
|
||||
return;
|
||||
|
||||
var hitBloodstreams = new List<BloodstreamComponent>();
|
||||
foreach (var entity in args.HitEntities)
|
||||
{
|
||||
if (Deleted(entity))
|
||||
continue;
|
||||
|
||||
if (EntityManager.TryGetComponent<BloodstreamComponent?>(entity, out var bloodstream))
|
||||
hitBloodstreams.Add(bloodstream);
|
||||
}
|
||||
|
||||
if (hitBloodstreams.Count < 1)
|
||||
return;
|
||||
|
||||
var removedSolution = solutionContainer.SplitSolution(comp.TransferAmount * hitBloodstreams.Count);
|
||||
var removedVol = removedSolution.TotalVolume;
|
||||
var solutionToInject = removedSolution.SplitSolution(removedVol * comp.TransferEfficiency);
|
||||
var volPerBloodstream = solutionToInject.TotalVolume * (1 / hitBloodstreams.Count);
|
||||
|
||||
foreach (var bloodstream in hitBloodstreams)
|
||||
{
|
||||
var individualInjection = solutionToInject.SplitSolution(volPerBloodstream);
|
||||
_bloodstreamSystem.TryAddToChemicals((bloodstream).Owner, individualInjection, bloodstream);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendAnimation(string arc, Angle angle, EntityUid attacker, EntityUid source, IEnumerable<EntityUid> hits, bool textureEffect = false, bool arcFollowAttacker = true)
|
||||
{
|
||||
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponAnimationMessage(arc, angle, attacker, source,
|
||||
hits.Select(e => e).ToList(), textureEffect, arcFollowAttacker), Filter.Pvs(source, 1f));
|
||||
}
|
||||
|
||||
public void SendLunge(Angle angle, EntityUid source)
|
||||
{
|
||||
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayLungeAnimationMessage(angle, source), Filter.Pvs(source, 1f));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ItemMeleeDamageEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The base amount of damage dealt by the melee hit.
|
||||
/// </summary>
|
||||
public readonly DamageSpecifier BaseDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// Modifier sets to apply to the damage when it's all said and done.
|
||||
/// This should be modified by adding a new entry to the list.
|
||||
/// </summary>
|
||||
public List<DamageModifierSet> ModifiersList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Damage to add to the default melee weapon damage. Applied before modifiers.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This might be required as damage modifier sets cannot add a new damage type to a DamageSpecifier.
|
||||
/// </remarks>
|
||||
public DamageSpecifier BonusDamage = new();
|
||||
|
||||
public ItemMeleeDamageEvent(DamageSpecifier baseDamage)
|
||||
{
|
||||
BaseDamage = baseDamage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on the melee weapon entity used to attack something in combat mode,
|
||||
/// whether through a click attack or wide attack.
|
||||
/// </summary>
|
||||
public sealed class MeleeHitEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The base amount of damage dealt by the melee hit.
|
||||
/// </summary>
|
||||
public readonly DamageSpecifier BaseDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// Modifier sets to apply to the hit event when it's all said and done.
|
||||
/// This should be modified by adding a new entry to the list.
|
||||
/// </summary>
|
||||
public List<DamageModifierSet> ModifiersList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Damage to add to the default melee weapon damage. Applied before modifiers.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This might be required as damage modifier sets cannot add a new damage type to a DamageSpecifier.
|
||||
/// </remarks>
|
||||
public DamageSpecifier BonusDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// A list containing every hit entity. Can be zero.
|
||||
/// </summary>
|
||||
public IEnumerable<EntityUid> HitEntities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to define a new hit sound in case you want to override the default GenericHit.
|
||||
/// Also gets a pitch modifier added to it.
|
||||
/// </summary>
|
||||
public SoundSpecifier? HitSoundOverride {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// The user who attacked with the melee weapon.
|
||||
/// </summary>
|
||||
public EntityUid User { get; }
|
||||
|
||||
public MeleeHitEvent(List<EntityUid> hitEntities, EntityUid user, DamageSpecifier baseDamage)
|
||||
{
|
||||
HitEntities = hitEntities;
|
||||
User = user;
|
||||
BaseDamage = baseDamage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using Content.Shared.Damage.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
|
||||
namespace Content.Server.Weapon.Melee.Components;
|
||||
namespace Content.Server.Weapons.Melee.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Plays the specified sound upon receiving damage of the specified type.
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Weapon.Melee.EnergySword
|
||||
namespace Content.Server.Weapons.Melee.EnergySword.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
internal sealed class EnergySwordComponent : Component
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Server.Weapons.Melee.EnergySword.Components;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
@@ -9,11 +10,12 @@ using Content.Shared.Light.Component;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Weapon.Melee.EnergySword
|
||||
namespace Content.Server.Weapons.Melee.EnergySword
|
||||
{
|
||||
public sealed class EnergySwordSystem : EntitySystem
|
||||
{
|
||||
30
Content.Server/Weapons/Melee/Events/ItemMeleeDamageEvent.cs
Normal file
30
Content.Server/Weapons/Melee/Events/ItemMeleeDamageEvent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Damage;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.Events;
|
||||
|
||||
public sealed class ItemMeleeDamageEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The base amount of damage dealt by the melee hit.
|
||||
/// </summary>
|
||||
public readonly DamageSpecifier BaseDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// Modifier sets to apply to the damage when it's all said and done.
|
||||
/// This should be modified by adding a new entry to the list.
|
||||
/// </summary>
|
||||
public List<DamageModifierSet> ModifiersList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Damage to add to the default melee weapon damage. Applied before modifiers.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This might be required as damage modifier sets cannot add a new damage type to a DamageSpecifier.
|
||||
/// </remarks>
|
||||
public DamageSpecifier BonusDamage = new();
|
||||
|
||||
public ItemMeleeDamageEvent(DamageSpecifier baseDamage)
|
||||
{
|
||||
BaseDamage = baseDamage;
|
||||
}
|
||||
}
|
||||
53
Content.Server/Weapons/Melee/Events/MeleeHitEvent.cs
Normal file
53
Content.Server/Weapons/Melee/Events/MeleeHitEvent.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on the melee weapon entity used to attack something in combat mode,
|
||||
/// whether through a click attack or wide attack.
|
||||
/// </summary>
|
||||
public sealed class MeleeHitEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The base amount of damage dealt by the melee hit.
|
||||
/// </summary>
|
||||
public readonly DamageSpecifier BaseDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// Modifier sets to apply to the hit event when it's all said and done.
|
||||
/// This should be modified by adding a new entry to the list.
|
||||
/// </summary>
|
||||
public List<DamageModifierSet> ModifiersList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Damage to add to the default melee weapon damage. Applied before modifiers.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This might be required as damage modifier sets cannot add a new damage type to a DamageSpecifier.
|
||||
/// </remarks>
|
||||
public DamageSpecifier BonusDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// A list containing every hit entity. Can be zero.
|
||||
/// </summary>
|
||||
public IEnumerable<EntityUid> HitEntities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to define a new hit sound in case you want to override the default GenericHit.
|
||||
/// Also gets a pitch modifier added to it.
|
||||
/// </summary>
|
||||
public SoundSpecifier? HitSoundOverride {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// The user who attacked with the melee weapon.
|
||||
/// </summary>
|
||||
public EntityUid User { get; }
|
||||
|
||||
public MeleeHitEvent(List<EntityUid> hitEntities, EntityUid user, DamageSpecifier baseDamage)
|
||||
{
|
||||
HitEntities = hitEntities;
|
||||
User = user;
|
||||
BaseDamage = baseDamage;
|
||||
}
|
||||
}
|
||||
536
Content.Server/Weapons/Melee/MeleeWeaponSystem.cs
Normal file
536
Content.Server/Weapons/Melee/MeleeWeaponSystem.cs
Normal file
@@ -0,0 +1,536 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Actions.Events;
|
||||
using Content.Server.Administration.Components;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Contests;
|
||||
using Content.Server.Damage.Systems;
|
||||
using Content.Server.Examine;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Weapons.Melee.Components;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Weapons.Melee;
|
||||
|
||||
public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
|
||||
[Dependency] private readonly ContestsSystem _contests = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly ExamineSystem _examine = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutions = default!;
|
||||
[Dependency] private readonly StaminaSystem _stamina = default!;
|
||||
|
||||
public const float DamagePitchVariation = 0.05f;
|
||||
|
||||
private const int AttackMask = (int) (CollisionGroup.MobMask | CollisionGroup.Opaque);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(OnChemicalInjectorHit);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, GetVerbsEvent<ExamineVerb>>(OnMeleeExaminableVerb);
|
||||
}
|
||||
|
||||
private void OnMeleeExaminableVerb(EntityUid uid, MeleeWeaponComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess || component.HideFromExamine)
|
||||
return;
|
||||
|
||||
var getDamage = new ItemMeleeDamageEvent(component.Damage);
|
||||
RaiseLocalEvent(uid, getDamage);
|
||||
|
||||
var damageSpec = GetDamage(component);
|
||||
|
||||
if (damageSpec == null)
|
||||
damageSpec = new DamageSpecifier();
|
||||
|
||||
damageSpec += getDamage.BonusDamage;
|
||||
|
||||
if (damageSpec.Total == FixedPoint2.Zero)
|
||||
return;
|
||||
|
||||
var verb = new ExamineVerb()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
var markup = _damageable.GetDamageExamine(damageSpec, Loc.GetString("damage-melee"));
|
||||
_examine.SendExamineTooltip(args.User, uid, markup, false, false);
|
||||
},
|
||||
Text = Loc.GetString("damage-examinable-verb-text"),
|
||||
Message = Loc.GetString("damage-examinable-verb-message"),
|
||||
Category = VerbCategory.Examine,
|
||||
IconTexture = "/Textures/Interface/VerbIcons/smite.svg.192dpi.png"
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private DamageSpecifier? GetDamage(MeleeWeaponComponent component)
|
||||
{
|
||||
return component.Damage.Total > FixedPoint2.Zero ? component.Damage : null;
|
||||
}
|
||||
|
||||
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
|
||||
{
|
||||
if (uid == null)
|
||||
return;
|
||||
|
||||
PopupSystem.PopupEntity(message, uid.Value, Filter.Pvs(uid.Value, entityManager: EntityManager).RemoveWhereAttachedEntity(e => e == user));
|
||||
}
|
||||
|
||||
protected override void DoLightAttack(EntityUid user, LightAttackEvent ev, MeleeWeaponComponent component)
|
||||
{
|
||||
base.DoLightAttack(user, ev, component);
|
||||
|
||||
// Can't attack yourself
|
||||
// Not in LOS.
|
||||
if (user == ev.Target ||
|
||||
ev.Target == null ||
|
||||
Deleted(ev.Target) ||
|
||||
// For consistency with wide attacks stuff needs damageable.
|
||||
!HasComp<DamageableComponent>(ev.Target) ||
|
||||
!TryComp<TransformComponent>(ev.Target, out var targetXform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// InRangeUnobstructed is insufficient rn as it checks the centre of the body rather than the nearest edge.
|
||||
// TODO: Look at fixing it
|
||||
// This is mainly to keep consistency between the wide attack raycast and the click attack raycast.
|
||||
if (!_interaction.InRangeUnobstructed(user, ev.Target.Value, component.Range + 0.35f))
|
||||
return;
|
||||
|
||||
var damage = component.Damage * GetModifier(component, true);
|
||||
// Sawmill.Debug($"Melee damage is {damage.Total} out of {component.Damage.Total}");
|
||||
|
||||
// Raise event before doing damage so we can cancel damage if the event is handled
|
||||
var hitEvent = new MeleeHitEvent(new List<EntityUid> { ev.Target.Value }, user, damage);
|
||||
RaiseLocalEvent(component.Owner, hitEvent);
|
||||
|
||||
if (hitEvent.Handled)
|
||||
return;
|
||||
|
||||
var targets = new List<EntityUid>(1)
|
||||
{
|
||||
ev.Target.Value
|
||||
};
|
||||
|
||||
// For stuff that cares about it being attacked.
|
||||
RaiseLocalEvent(ev.Target.Value, new AttackedEvent(component.Owner, user, targetXform.Coordinates));
|
||||
|
||||
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage, hitEvent.ModifiersList);
|
||||
var damageResult = _damageable.TryChangeDamage(ev.Target, modifiedDamage);
|
||||
|
||||
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
|
||||
{
|
||||
// If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor
|
||||
if (damageResult.DamageDict.TryGetValue("Blunt", out var bluntDamage))
|
||||
{
|
||||
_stamina.TakeStaminaDamage(ev.Target.Value, (bluntDamage * component.BluntStaminaDamageFactor).Float());
|
||||
}
|
||||
|
||||
if (component.Owner == user)
|
||||
{
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(ev.Target.Value):target} using their hands and dealt {damageResult.Total:damage} damage");
|
||||
}
|
||||
else
|
||||
{
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(ev.Target.Value):target} using {ToPrettyString(component.Owner):used} and dealt {damageResult.Total:damage} damage");
|
||||
}
|
||||
|
||||
PlayHitSound(ev.Target.Value, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hitEvent.HitSoundOverride != null)
|
||||
{
|
||||
Audio.PlayPvs(hitEvent.HitSoundOverride, component.Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
Audio.PlayPvs(component.NoDamageSound, component.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
if (damageResult?.Total > FixedPoint2.Zero)
|
||||
{
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, targets), Filter.Pvs(targetXform.Coordinates, entityMan: EntityManager));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoHeavyAttack(EntityUid user, HeavyAttackEvent ev, MeleeWeaponComponent component)
|
||||
{
|
||||
base.DoHeavyAttack(user, ev, component);
|
||||
|
||||
// TODO: This is copy-paste as fuck with DoPreciseAttack
|
||||
if (!TryComp<TransformComponent>(user, out var userXform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetMap = ev.Coordinates.ToMap(EntityManager);
|
||||
|
||||
if (targetMap.MapId != userXform.MapID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var userPos = userXform.WorldPosition;
|
||||
var direction = targetMap.Position - userPos;
|
||||
var distance = Math.Min(component.Range, direction.Length);
|
||||
|
||||
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
|
||||
var entities = ArcRayCast(userPos, direction.ToWorldAngle(), component.Angle, distance, userXform.MapID, user);
|
||||
|
||||
if (entities.Count == 0)
|
||||
return;
|
||||
|
||||
var targets = new List<EntityUid>();
|
||||
var damageQuery = GetEntityQuery<DamageableComponent>();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity == user ||
|
||||
!damageQuery.HasComponent(entity))
|
||||
continue;
|
||||
|
||||
targets.Add(entity);
|
||||
}
|
||||
|
||||
var damage = component.Damage * GetModifier(component, false);
|
||||
// Sawmill.Debug($"Melee damage is {damage.Total} out of {component.Damage.Total}");
|
||||
|
||||
// Raise event before doing damage so we can cancel damage if the event is handled
|
||||
var hitEvent = new MeleeHitEvent(targets, user, damage);
|
||||
RaiseLocalEvent(component.Owner, hitEvent);
|
||||
|
||||
if (hitEvent.Handled)
|
||||
return;
|
||||
|
||||
// For stuff that cares about it being attacked.
|
||||
foreach (var target in targets)
|
||||
{
|
||||
RaiseLocalEvent(target, new AttackedEvent(component.Owner, user, Transform(target).Coordinates));
|
||||
}
|
||||
|
||||
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage, hitEvent.ModifiersList);
|
||||
var appliedDamage = new DamageSpecifier();
|
||||
|
||||
foreach (var entity in targets)
|
||||
{
|
||||
RaiseLocalEvent(entity, new AttackedEvent(component.Owner, user, ev.Coordinates));
|
||||
|
||||
var damageResult = _damageable.TryChangeDamage(entity, modifiedDamage);
|
||||
|
||||
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
|
||||
{
|
||||
appliedDamage += damageResult;
|
||||
|
||||
if (component.Owner == user)
|
||||
{
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(entity):target} using their hands and dealt {damageResult.Total:damage} damage");
|
||||
}
|
||||
else
|
||||
{
|
||||
_adminLogger.Add(LogType.MeleeHit,
|
||||
$"{ToPrettyString(user):user} melee attacked {ToPrettyString(entity):target} using {ToPrettyString(component.Owner):used} and dealt {damageResult.Total:damage} damage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entities.Count != 0)
|
||||
{
|
||||
if (appliedDamage.Total > FixedPoint2.Zero)
|
||||
{
|
||||
var target = entities.First();
|
||||
PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hitEvent.HitSoundOverride != null)
|
||||
{
|
||||
Audio.PlayPvs(hitEvent.HitSoundOverride, component.Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
Audio.PlayPvs(component.NoDamageSound, component.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (appliedDamage.Total > FixedPoint2.Zero)
|
||||
{
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, targets), Filter.Pvs(Transform(targets[0]).Coordinates, entityMan: EntityManager));
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, MeleeWeaponComponent component)
|
||||
{
|
||||
if (!base.DoDisarm(user, ev, component))
|
||||
return false;
|
||||
|
||||
if (!TryComp<CombatModeComponent>(user, out var combatMode))
|
||||
return false;
|
||||
|
||||
var target = ev.Target!.Value;
|
||||
|
||||
if (!TryComp<HandsComponent>(ev.Target.Value, out var targetHandsComponent))
|
||||
{
|
||||
// Client will have already predicted this.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_interaction.InRangeUnobstructed(user, ev.Target.Value, component.Range + 0.1f))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUid? inTargetHand = null;
|
||||
|
||||
if (targetHandsComponent.ActiveHand is { IsEmpty: false })
|
||||
{
|
||||
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
|
||||
}
|
||||
|
||||
var attemptEvent = new DisarmAttemptEvent(target, user, inTargetHand);
|
||||
|
||||
if (inTargetHand != null)
|
||||
{
|
||||
RaiseLocalEvent(inTargetHand.Value, attemptEvent);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(target, attemptEvent);
|
||||
|
||||
if (attemptEvent.Cancelled)
|
||||
return false;
|
||||
|
||||
var chance = CalculateDisarmChance(user, target, inTargetHand, combatMode);
|
||||
|
||||
if (_random.Prob(chance))
|
||||
{
|
||||
// Don't play a sound as the swing is already predicted.
|
||||
// Also don't play popups because most disarms will miss.
|
||||
return false;
|
||||
}
|
||||
|
||||
var filterOther = Filter.Pvs(user, entityManager: EntityManager).RemoveWhereAttachedEntity(e => e == user);
|
||||
|
||||
var msgOther = Loc.GetString(
|
||||
"disarm-action-popup-message-other-clients",
|
||||
("performerName", Identity.Entity(user, EntityManager)),
|
||||
("targetName", Identity.Entity(target, EntityManager)));
|
||||
|
||||
var msgUser = Loc.GetString("disarm-action-popup-message-cursor", ("targetName", Identity.Entity(target, EntityManager)));
|
||||
|
||||
PopupSystem.PopupEntity(msgOther, user, filterOther);
|
||||
PopupSystem.PopupEntity(msgUser, target, Filter.Entities(user));
|
||||
|
||||
Audio.PlayPvs(combatMode.DisarmSuccessSound, user, AudioParams.Default.WithVariation(0.025f).WithVolume(5f));
|
||||
_adminLogger.Add(LogType.DisarmedAction, $"{ToPrettyString(user):user} used disarm on {ToPrettyString(target):target}");
|
||||
|
||||
var eventArgs = new DisarmedEvent { Target = target, Source = user, PushProbability = 1 - chance };
|
||||
RaiseLocalEvent(target, eventArgs);
|
||||
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Aqua, new List<EntityUid>() {target}));
|
||||
return true;
|
||||
}
|
||||
|
||||
private float CalculateDisarmChance(EntityUid disarmer, EntityUid disarmed, EntityUid? inTargetHand, SharedCombatModeComponent disarmerComp)
|
||||
{
|
||||
if (HasComp<DisarmProneComponent>(disarmer))
|
||||
return 1.0f;
|
||||
|
||||
if (HasComp<DisarmProneComponent>(disarmed))
|
||||
return 0.0f;
|
||||
|
||||
var contestResults = 1 - _contests.OverallStrengthContest(disarmer, disarmed);
|
||||
|
||||
float chance = (disarmerComp.BaseDisarmFailChance + contestResults);
|
||||
|
||||
if (inTargetHand != null && TryComp<DisarmMalusComponent>(inTargetHand, out var malus))
|
||||
{
|
||||
chance += malus.Malus;
|
||||
}
|
||||
|
||||
return Math.Clamp(chance, 0f, 1f);
|
||||
}
|
||||
|
||||
private HashSet<EntityUid> ArcRayCast(Vector2 position, Angle angle, Angle arcWidth, float range, MapId mapId, EntityUid ignore)
|
||||
{
|
||||
// TODO: This is pretty sucky.
|
||||
var widthRad = arcWidth;
|
||||
var increments = 1 + 35 * (int) Math.Ceiling(widthRad / (2 * Math.PI));
|
||||
var increment = widthRad / increments;
|
||||
var baseAngle = angle - widthRad / 2;
|
||||
|
||||
var resSet = new HashSet<EntityUid>();
|
||||
|
||||
for (var i = 0; i < increments; i++)
|
||||
{
|
||||
var castAngle = new Angle(baseAngle + increment * i);
|
||||
var res = _physics.IntersectRay(mapId,
|
||||
new CollisionRay(position, castAngle.ToWorldVec(),
|
||||
AttackMask), range, ignore, false).ToList();
|
||||
|
||||
if (res.Count != 0)
|
||||
{
|
||||
resSet.Add(res[0].HitEntity);
|
||||
}
|
||||
}
|
||||
|
||||
return resSet;
|
||||
}
|
||||
|
||||
public override void DoLunge(EntityUid user, Angle angle, Vector2 localPos, string? animation)
|
||||
{
|
||||
RaiseNetworkEvent(new MeleeLungeEvent(user, angle, localPos, animation), Filter.Pvs(user, entityManager: EntityManager).RemoveWhereAttachedEntity(e => e == user));
|
||||
}
|
||||
|
||||
private void PlayHitSound(EntityUid target, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound)
|
||||
{
|
||||
var playedSound = false;
|
||||
|
||||
// Play sound based off of highest damage type.
|
||||
if (TryComp<MeleeSoundComponent>(target, out var damageSoundComp))
|
||||
{
|
||||
if (type == null && damageSoundComp.NoDamageSound != null)
|
||||
{
|
||||
Audio.PlayPvs(damageSoundComp.NoDamageSound, target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (type != null && damageSoundComp.SoundTypes?.TryGetValue(type, out var damageSoundType) == true)
|
||||
{
|
||||
Audio.PlayPvs(damageSoundType, target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (type != null && damageSoundComp.SoundGroups?.TryGetValue(type, out var damageSoundGroup) == true)
|
||||
{
|
||||
Audio.PlayPvs(damageSoundGroup, target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Use weapon sounds if the thing being hit doesn't specify its own sounds.
|
||||
if (!playedSound)
|
||||
{
|
||||
if (hitSoundOverride != null)
|
||||
{
|
||||
Audio.PlayPvs(hitSoundOverride, target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
else if (hitSound != null)
|
||||
{
|
||||
Audio.PlayPvs(hitSound, target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
playedSound = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to generic sounds.
|
||||
if (!playedSound)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
// Unfortunately heat returns caustic group so can't just use the damagegroup in that instance.
|
||||
case "Burn":
|
||||
case "Heat":
|
||||
case "Cold":
|
||||
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Items/welder.ogg"), target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
break;
|
||||
// No damage, fallback to tappies
|
||||
case null:
|
||||
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/tap.ogg"), target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
break;
|
||||
case "Brute":
|
||||
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/smash.ogg"), target, AudioParams.Default.WithVariation(DamagePitchVariation));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string? GetHighestDamageSound(DamageSpecifier modifiedDamage, IPrototypeManager protoManager)
|
||||
{
|
||||
var groups = modifiedDamage.GetDamagePerGroup(protoManager);
|
||||
|
||||
// Use group if it's exclusive, otherwise fall back to type.
|
||||
if (groups.Count == 1)
|
||||
{
|
||||
return groups.Keys.First();
|
||||
}
|
||||
|
||||
var highestDamage = FixedPoint2.Zero;
|
||||
string? highestDamageType = null;
|
||||
|
||||
foreach (var (type, damage) in modifiedDamage.DamageDict)
|
||||
{
|
||||
if (damage <= highestDamage)
|
||||
continue;
|
||||
|
||||
highestDamageType = type;
|
||||
}
|
||||
|
||||
return highestDamageType;
|
||||
}
|
||||
|
||||
private void OnChemicalInjectorHit(EntityUid owner, MeleeChemicalInjectorComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!_solutions.TryGetInjectableSolution(owner, out var solutionContainer))
|
||||
return;
|
||||
|
||||
var hitBloodstreams = new List<BloodstreamComponent>();
|
||||
var bloodQuery = GetEntityQuery<BloodstreamComponent>();
|
||||
|
||||
foreach (var entity in args.HitEntities)
|
||||
{
|
||||
if (Deleted(entity))
|
||||
continue;
|
||||
|
||||
if (bloodQuery.TryGetComponent(entity, out var bloodstream))
|
||||
hitBloodstreams.Add(bloodstream);
|
||||
}
|
||||
|
||||
if (!hitBloodstreams.Any())
|
||||
return;
|
||||
|
||||
var removedSolution = solutionContainer.SplitSolution(comp.TransferAmount * hitBloodstreams.Count);
|
||||
var removedVol = removedSolution.TotalVolume;
|
||||
var solutionToInject = removedSolution.SplitSolution(removedVol * comp.TransferEfficiency);
|
||||
var volPerBloodstream = solutionToInject.TotalVolume * (1 / hitBloodstreams.Count);
|
||||
|
||||
foreach (var bloodstream in hitBloodstreams)
|
||||
{
|
||||
var individualInjection = solutionToInject.SplitSolution(volPerBloodstream);
|
||||
_bloodstream.TryAddToChemicals((bloodstream).Owner, individualInjection, bloodstream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Components;
|
||||
namespace Content.Server.Weapons.Ranged.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class AmmoCounterComponent : SharedAmmoCounterComponent {}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Content.Server.Weapon.Ranged.Components
|
||||
namespace Content.Server.Weapons.Ranged.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class ChemicalAmmoComponent : Component
|
||||
@@ -2,7 +2,7 @@ using Content.Shared.Damage.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Components;
|
||||
namespace Content.Server.Weapons.Ranged.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Plays the specified sound upon receiving damage of that type.
|
||||
@@ -1,6 +1,6 @@
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Components;
|
||||
namespace Content.Server.Weapons.Ranged.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Responsible for handling recharging a basic entity ammo provider over time.
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Weapon.Ranged.Components;
|
||||
using Content.Server.Weapons.Ranged.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems
|
||||
namespace Content.Server.Weapons.Ranged.Systems
|
||||
{
|
||||
public sealed class ChemicalAmmoSystem : EntitySystem
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed class FlyBySoundSystem : SharedFlyBySoundSystem {}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem
|
||||
{
|
||||
@@ -7,7 +7,7 @@ using Content.Shared.Weapons.Ranged;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem
|
||||
{
|
||||
@@ -6,7 +6,7 @@ using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem
|
||||
{
|
||||
@@ -6,15 +6,12 @@ using Content.Server.Interaction;
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapon.Ranged.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Server.Weapons.Melee;
|
||||
using Content.Server.Weapons.Ranged.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Content.Shared.Weapons.Ranged;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
@@ -28,7 +25,7 @@ using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed partial class GunSystem : SharedGunSystem
|
||||
{
|
||||
@@ -196,7 +193,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
{
|
||||
if (dmg.Total > FixedPoint2.Zero)
|
||||
{
|
||||
RaiseNetworkEvent(new DamageEffectEvent(hitEntity), Filter.Pvs(hitEntity, entityManager: EntityManager));
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {result.HitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
|
||||
}
|
||||
|
||||
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
|
||||
@@ -1,13 +1,12 @@
|
||||
using Content.Server.Weapon.Ranged.Components;
|
||||
using Content.Server.Weapons.Ranged.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed class RechargeBasicEntityAmmoSystem : EntitySystem
|
||||
{
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
@@ -14,7 +13,7 @@ using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Systems;
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Weapon.Ranged.Systems;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Weapons.Ranged.Commands;
|
||||
namespace Content.Server.Weapons;
|
||||
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class TetherGunCommand : IConsoleCommand
|
||||
@@ -1,7 +1,6 @@
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Wieldable.Components;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
@@ -12,6 +11,7 @@ using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Server.Actions.Events;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
|
||||
|
||||
namespace Content.Server.Wieldable
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using Robust.Shared.Random;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Disease.Components;
|
||||
using Content.Server.Drone.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Server.Disease;
|
||||
@@ -13,6 +12,8 @@ using Content.Server.Inventory;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Server.Speech;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Weapons.Melee.Events;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Zombies;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ using Content.Server.Ghost.Roles.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -29,6 +28,7 @@ using Content.Server.Humanoid;
|
||||
using Content.Server.IdentityManagement;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Zombies
|
||||
@@ -119,8 +119,7 @@ namespace Content.Server.Zombies
|
||||
//This is the actual damage of the zombie. We assign the visual appearance
|
||||
//and range here because of stuff we'll find out later
|
||||
var melee = EnsureComp<MeleeWeaponComponent>(target);
|
||||
melee.Arc = zombiecomp.AttackArc;
|
||||
melee.ClickArc = zombiecomp.AttackArc;
|
||||
melee.Animation = zombiecomp.AttackAnimation;
|
||||
melee.Range = 0.75f;
|
||||
|
||||
//We have specific stuff for humanoid zombies because they matter more
|
||||
|
||||
Reference in New Issue
Block a user