Files
OldThink/Content.Shared/Weapons/Melee/MeleeWeaponComponent.cs
Aviu00 d4525a91e6 Fixes & more (#548)
* - fix: Narsie not spawning, items not dropping on paralyze, cult tweaks.

* - fix: Diagonal grilles layer.

* - add: Cockroaches don't drop organs.

* - add: Magic hands now work on interact & disable context menu interaction.

* - fix: Shackles speech after doafter.

* - tweak: Reduce flashbang knockdown, check for CanLieDown.

* - tweak: Hspear limit.

* - tweak: Remove knockdown tile friction.

* - tweak: Engi belt in sus box.

* - fix: Constructs can hear cult chat.

* - fix: Desword audio.

* - fix: Context menu.

* - fix: Actually drop items on paralyze.

* - tweak: Revert range reduction.

* - add: Update thermal visibility.

* - add: NPCs can miss.

* - tweak: Update desc.

* - fix: Actually fix desword audio.

* - tweak: Secret weights & game presets.

* - fix: Cult stun.
2024-08-03 18:23:46 +03:00

201 lines
7.0 KiB
C#

using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Weapons.Melee;
/// <summary>
/// When given to a mob lets them do unarmed attacks, or when given to an item lets someone wield it to do attacks.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
public sealed partial class MeleeWeaponComponent : Component
{
// TODO: This is becoming bloated as shit.
// This should just be its own component for alt attacks.
/// <summary>
/// Does this entity do a disarm on alt attack.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool AltDisarm = true;
/// <summary>
/// Should the melee weapon's damage stats be examinable.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool Hidden;
/// <summary>
/// Next time this component is allowed to light attack. Heavy attacks are wound up and never have a cooldown.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoPausedField]
public TimeSpan NextAttack;
/// <summary>
/// Starts attack cooldown when equipped if true.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool ResetOnHandSelected = true;
/*
* Melee combat works based around 2 types of attacks:
* 1. Click attacks with left-click. This attacks whatever is under your mnouse
* 2. Wide attacks with right-click + left-click. This attacks whatever is in the direction of your mouse.
*/
/// <summary>
/// How many times we can attack per second.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float AttackRate = 1f;
/// <summary>
/// Are we currently holding down the mouse for an attack.
/// Used so we can't just hold the mouse button and attack constantly.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool Attacking = false;
// WD START
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool CanHeavyAttack = true;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool CanAttackSelf = true;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool CanBeBlocked = true;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool CanMiss;
[DataField]
public EntityWhitelist? AttackWhitelist;
[DataField]
public EntityWhitelist? AttackBlacklist;
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
[AutoPausedField]
public TimeSpan NextMobAttack;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float? EquipCooldown;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool IgnoreResistances;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float HeavyAttackStaminaCost = 8;
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId MissAnimation = "WeaponArcPunch";
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId DisarmAnimation = "WeaponArcDisarm";
// WD END
/// <summary>
/// If true, attacks will be repeated automatically without requiring the mouse button to be lifted.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool AutoAttack;
/// <summary>
/// Base damage for this weapon. Can be modified via heavy damage or other means.
/// </summary>
[DataField(required: true)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public DamageSpecifier Damage = default!;
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 BluntStaminaDamageFactor = FixedPoint2.New(0.5f);
/// <summary>
/// Multiplies damage by this amount for single-target attacks.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public FixedPoint2 ClickDamageModifier = FixedPoint2.New(1);
/// <summary>
/// Nearest edge range to hit an entity.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float Range = 1.5f;
/// <summary>
/// Total width of the angle for wide attacks.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public Angle Angle = Angle.FromDegrees(60);
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId Animation = "WeaponArcThrust"; // WD EDIT
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId WideAnimation = "WeaponArcSlash";
/// <summary>
/// Rotation of the animation.
/// 0 degrees means the top faces the attacker.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public Angle WideAnimationRotation = Angle.Zero;
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool SwingLeft;
// Sounds
/// <summary>
/// This gets played whenever a melee attack is done. This is predicted by the client.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("soundSwing"), AutoNetworkedField]
public SoundSpecifier SwingSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg")
{
Params = AudioParams.Default.WithVolume(-3f).WithVariation(0.025f),
};
// We do not predict the below sounds in case the client thinks but the server disagrees. If this were the case
// then a player may doubt if the target actually took damage or not.
// If overwatch and apex do this then we probably should too.
[ViewVariables(VVAccess.ReadWrite)]
[DataField("soundHit"), AutoNetworkedField]
public SoundSpecifier? HitSound;
/// <summary>
/// Plays if no damage is done to the target entity.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("soundNoDamage"), AutoNetworkedField]
public SoundSpecifier NoDamageSound { get; set; } = new SoundCollectionSpecifier("WeakHit");
/// <summary>
/// If true, the weapon must be equipped for it to be used.
/// E.g boxing gloves must be equipped to your gloves,
/// not just held in your hand to be used.
/// </summary>
[DataField, AutoNetworkedField]
public bool MustBeEquippedToUse = false;
}
/// <summary>
/// Event raised on entity in GetWeapon function to allow systems to manually
/// specify what the weapon should be.
/// </summary>
public sealed class GetMeleeWeaponEvent : HandledEntityEventArgs
{
public EntityUid? Weapon;
}