mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
+24









Debug
deltanedas
metalgearsloth
Nemanja
PJBot
Psychpsyo
deltanedas
metalgearsloth
ravage
Pieter-Jan Briers
LEVELcat
Repo
nikthechampiongr
Doru991
DrSmugleaf
Skarletto
NULL882
lunarcomets
Miro Kavaliou
Kara
Kacper Urbańczyk
TsjipTsjip
daerSeebaer
Fluffiest Floofers
Flareguy
Leon Friedrich
Kevin Zheng
drteaspoon420
Ubaser
Nim
Kacper Urbańczyk
Tox Cruize
Ed
Michael Cu
fd2cc8570d
* Automatic changelog update * Make NPC names proper nouns & fix some genders (#20534) * Proper names & genders * Uppercase proper names * Make Smile female * fix bingus wrinkly head (#20531) * rouny meat and steak (#20526) * lost friendship flavor * add rouny steak * rouny special meat * rouny meat textures --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Automatic changelog update * Wearable Wet Floor Sign and 'Janitorial Suicide Vest' (#20311) * Explosive wet floor sign & janitorial suicide vest * fix attributions * Remove name & desc from explosive wet floor sign * Make wet floor sign chameleonable * Automatic changelog update * Minor slippery stuff (#20535) * Update submodule to 162.2.0 (#20570) * Predicted armor (#20560) * clean up some lines in smile the slime prototype (#20552) * Revert "Use full file path for temp replays (#19002)" (#20545) * Add EyesGlasses into ClothesMate (#20523) * Automatic changelog update * Fix Punpun crew monitor sensor (#20484) * Automatic changelog update * EasyPry airlocks for arrivals. Now also prying refactor I guess (#19394) Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Automatic changelog update * Make arcades hackable again (#20555) * Automatic changelog update * Health alert tweaks (#20557) * Automatic changelog update * Add active and ended game rule components, generic TryRoundStartAttempt and minPlayers field (#20564) * Improve active game rule querying, add generic try round start attempt method, move minPlayers to GameRuleComponent * Nukeops todo and cleanup * Remove Active field * Add EndedGameRuleComponent * bartender suit (#20521) * give me a drink bartender * guh * aARG * Necropolis and mine walls (#20578) * Automatic changelog update * archaic accent tweaks (#20567) * Automatic changelog update * Add confirmation to kick and respawn in the admin player actions panel (#20542) * Remove windows-latest CI runs, remove unused build-test-release.yml (#20540) * Change .editorconfig to keep existing attribute arrangement (#20538) * Automatic changelog update * Catch replay start and end errors on round restarts (#20565) * Update trivial components to use auto comp states (#20539) * Fix role unbans not applying in real time (#20547) * Disable AHelp buttons when no player is selected, update button styling (#20568) * Automatic changelog update * Added a toggle fullscreen button (default F11) (#20272) * Added a toggle fullscreen button (default F11) * Removed un-needed comments * Review Requested Changes * Fixed Acidental Spacing Change * bwoink, removed extraneous code * nothing, litterally * Automatic changelog update * Fix not networking markings (#20588) * Automatic changelog update * Update RobustToolbox to v162.2.1 (#20590) * Automatic changelog update * Glorfcode (force say on damage/stun/crit) (#20562) * Automatic changelog update * Fix AHelp progressively showing more AHelp panels (#20591) * Automatic changelog update * caninsert entitystorage tweaks (#20589) * Automatic changelog update * Fix mapping actions crashing on load (#20592) * Fix loading a map with a ThirstComponent crashing the game (#20594) * Fix electrocution displaying real name of disguised players (#20603) * Organ fixes (#20488) * Automatic changelog update * Kettle medical rework (#20435) * Initial try at medical rework for kettle * Re-add decal decorations to Kettle's medical * Add more lockers to kettle's med * Actually upload kettle's map, not its proto * Automatic changelog update * Added blocked visuals to volumetric pump (#20610) * Automatic changelog update * Move TimedDespawn to engine (#20515) * Update submodule to 163.0.0 (#20616) * Remove v0.1 version number from local main menu screen (#20617) * Remove cloneData parameter from AutoNetworkedField (#20596) * Update submodule to 164.0.0 (#20618) * fix cognizine ghost role (#20632) Co-authored-by: deltanedas <@deltanedas:kde.org> * Automatic changelog update * Move ID layer one pixel to correct alignment (#20630) * Update nukie hardsuit descriptions (#20529) * Make holofans destructable (#20445) * Automatic changelog update * bowl is open (#20453) Co-authored-by: deltanedas <@deltanedas:kde.org> * Add TestPair.WaitCommand() (#20615) * Rename ThreatPrototype and mark fields as required (#20611) * Adjust hard bomb shape (#20608) * dragon refactor, objectives and use GenericAntag (#20201) Co-authored-by: deltanedas <@deltanedas:kde.org> * Automatic changelog update * Added generic empty liquids tank (#20563) * Move view variables verb to the top of the list with no category and localize it (#20546) * saltern update (#20325) Co-authored-by: deltanedas <@deltanedas:kde.org> * Fix followers leaking (#20643) * Add Winter Boots (#20622) * add * fix prototype * Add QM mantle (#20621) * add * fix prototype * Automatic changelog update * Slime mobs breathe nitrogen and resprite their organs (#20577) * Slimes breathe nitrogen and resprite their organs * ups * mmm * Automatic changelog update * Fix the new lizard horn's consistency + issue (#20620) * fix * add * Revert "add" This reverts commit a054a3204a8f185a94ceb80b1bd3bc9f30423711. * Add RandomHumanoidAppearance component to for space ninjas (#20605) * Automatic changelog update * Space cat breathes space (#20550) * Space cat breathes space Made Space Cat lungs ROBUST * Made Space Cat's lungs ROBUST 2.0 * Automatic changelog update * Wide anomaly locator (#20581) * Add files via upload * Add files via upload * Add files via upload * Add files via upload * add textures * fix encoding * fix 2 * Automatic changelog update * Fixed Telescopic Shield Lighting (#20650) * Fixed Telescopic Shield Lighting Bug fix #20199 * no need for these at all --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> * Automatic changelog update * Add a special hardsuit for nukie medic (#20471) * Automatic changelog update * Carry over other mutations when doing species mutation (#20551) * Automatic changelog update * Add Spanish accent to poncho and sombrero (#20377) --------- Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com> Co-authored-by: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: ravage <142820619+ravage123321@users.noreply.github.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: LEVELcat <68501903+LEVELcat@users.noreply.github.com> Co-authored-by: Repo <47093363+Titian3@users.noreply.github.com> Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Doru991 <75124791+Doru991@users.noreply.github.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Skarletto <122584947+Skarletto@users.noreply.github.com> Co-authored-by: NULL882 <104377798+NULL882@users.noreply.github.com> Co-authored-by: lunarcomets <140772713+lunarcomets@users.noreply.github.com> Co-authored-by: Miro Kavaliou <miraslauk@gmail.com> Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: Kacper Urbańczyk <kacperjaroslawurbanczyk@gmail.com> Co-authored-by: TsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com> Co-authored-by: daerSeebaer <61566539+daerSeebaer@users.noreply.github.com> Co-authored-by: Fluffiest Floofers <thebluewulf@gmail.com> Co-authored-by: Flareguy <78941145+Flareguy@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: Kevin Zheng <kevinz5000@gmail.com> Co-authored-by: drteaspoon420 <87363733+drteaspoon420@users.noreply.github.com> Co-authored-by: Ubaser <134914314+UbaserB@users.noreply.github.com> Co-authored-by: Nim <128169402+Nimfar11@users.noreply.github.com> Co-authored-by: Kacper Urbańczyk <mikrel071204@gmail.com> Co-authored-by: Tox Cruize <141375638+TexCruize@users.noreply.github.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: Michael Cu <43478115+michaelcu@users.noreply.github.com>
849 lines
31 KiB
C#
849 lines
31 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.CombatMode;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Damage.Systems;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Hands;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Physics;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Weapons.Melee.Components;
|
|
using Content.Shared.Weapons.Melee.Events;
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
using Content.Shared.Weapons.Ranged.Events;
|
|
using Content.Shared.Weapons.Ranged.Systems;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Players;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Weapons.Melee;
|
|
|
|
public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|
{
|
|
[Dependency] protected readonly IGameTiming Timing = default!;
|
|
[Dependency] protected readonly IMapManager MapManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
|
|
[Dependency] protected readonly ActionBlockerSystem Blocker = default!;
|
|
[Dependency] protected readonly DamageableSystem Damageable = default!;
|
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
|
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
|
[Dependency] protected readonly SharedCombatModeSystem CombatMode = default!;
|
|
[Dependency] protected readonly SharedInteractionSystem Interaction = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] protected readonly SharedPopupSystem PopupSystem = default!;
|
|
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
|
|
[Dependency] private readonly StaminaSystem _stamina = default!;
|
|
|
|
public const float DamagePitchVariation = 0.05f;
|
|
private const int AttackMask = (int) (CollisionGroup.MobMask | CollisionGroup.Opaque);
|
|
|
|
/// <summary>
|
|
/// Maximum amount of targets allowed for a wide-attack.
|
|
/// </summary>
|
|
public const int MaxTargets = 5;
|
|
|
|
/// <summary>
|
|
/// If an attack is released within this buffer it's assumed to be full damage.
|
|
/// </summary>
|
|
public const float GracePeriod = 0.05f;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MeleeWeaponComponent, EntityUnpausedEvent>(OnMeleeUnpaused);
|
|
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnMeleeSelected);
|
|
SubscribeLocalEvent<MeleeWeaponComponent, ShotAttemptedEvent>(OnMeleeShotAttempted);
|
|
SubscribeLocalEvent<MeleeWeaponComponent, GunShotEvent>(OnMeleeShot);
|
|
SubscribeLocalEvent<BonusMeleeDamageComponent, GetMeleeDamageEvent>(OnGetBonusMeleeDamage);
|
|
SubscribeLocalEvent<BonusMeleeDamageComponent, GetHeavyDamageModifierEvent>(OnGetBonusHeavyDamageModifier);
|
|
SubscribeLocalEvent<BonusMeleeAttackRateComponent, GetMeleeAttackRateEvent>(OnGetBonusMeleeAttackRate);
|
|
|
|
SubscribeAllEvent<HeavyAttackEvent>(OnHeavyAttack);
|
|
SubscribeAllEvent<LightAttackEvent>(OnLightAttack);
|
|
SubscribeAllEvent<DisarmAttackEvent>(OnDisarmAttack);
|
|
SubscribeAllEvent<StopAttackEvent>(OnStopAttack);
|
|
|
|
#if DEBUG
|
|
SubscribeLocalEvent<MeleeWeaponComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, MeleeWeaponComponent component, MapInitEvent args)
|
|
{
|
|
if (component.NextAttack > Timing.CurTime)
|
|
Log.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}");
|
|
#endif
|
|
}
|
|
|
|
private void OnMeleeShotAttempted(EntityUid uid, MeleeWeaponComponent comp, ref ShotAttemptedEvent args)
|
|
{
|
|
if (comp.NextAttack > Timing.CurTime)
|
|
args.Cancel();
|
|
}
|
|
|
|
private void OnMeleeShot(EntityUid uid, MeleeWeaponComponent component, ref GunShotEvent args)
|
|
{
|
|
if (!TryComp<GunComponent>(uid, out var gun))
|
|
return;
|
|
|
|
if (gun.NextFire > component.NextAttack)
|
|
{
|
|
component.NextAttack = gun.NextFire;
|
|
Dirty(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnMeleeUnpaused(EntityUid uid, MeleeWeaponComponent component, ref EntityUnpausedEvent args)
|
|
{
|
|
component.NextAttack += args.PausedTime;
|
|
}
|
|
|
|
private void OnMeleeSelected(EntityUid uid, MeleeWeaponComponent component, HandSelectedEvent args)
|
|
{
|
|
var attackRate = GetAttackRate(uid, args.User, component);
|
|
if (attackRate.Equals(0f))
|
|
return;
|
|
|
|
if (!component.ResetOnHandSelected)
|
|
return;
|
|
|
|
if (Paused(uid))
|
|
return;
|
|
|
|
// If someone swaps to this weapon then reset its cd.
|
|
var curTime = Timing.CurTime;
|
|
var minimum = curTime + TimeSpan.FromSeconds(1 / attackRate);
|
|
|
|
if (minimum < component.NextAttack)
|
|
return;
|
|
|
|
component.NextAttack = minimum;
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
private void OnGetBonusMeleeDamage(EntityUid uid, BonusMeleeDamageComponent component, ref GetMeleeDamageEvent args)
|
|
{
|
|
if (component.BonusDamage != null)
|
|
args.Damage += component.BonusDamage;
|
|
if (component.DamageModifierSet != null)
|
|
args.Modifiers.Add(component.DamageModifierSet);
|
|
}
|
|
|
|
private void OnGetBonusHeavyDamageModifier(EntityUid uid, BonusMeleeDamageComponent component, ref GetHeavyDamageModifierEvent args)
|
|
{
|
|
args.DamageModifier += component.HeavyDamageFlatModifier;
|
|
args.Multipliers *= component.HeavyDamageMultiplier;
|
|
}
|
|
|
|
private void OnGetBonusMeleeAttackRate(EntityUid uid, BonusMeleeAttackRateComponent component, ref GetMeleeAttackRateEvent args)
|
|
{
|
|
args.Rate += component.FlatModifier;
|
|
args.Multipliers *= component.Multiplier;
|
|
}
|
|
|
|
private void OnStopAttack(StopAttackEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
var user = args.SenderSession.AttachedEntity;
|
|
|
|
if (user == null)
|
|
return;
|
|
|
|
if (!TryGetWeapon(user.Value, out var weaponUid, out var weapon) ||
|
|
weaponUid != GetEntity(msg.Weapon))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!weapon.Attacking)
|
|
return;
|
|
|
|
weapon.Attacking = false;
|
|
Dirty(weaponUid, weapon);
|
|
}
|
|
|
|
private void OnLightAttack(LightAttackEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
var user = args.SenderSession.AttachedEntity;
|
|
|
|
if (user == null)
|
|
return;
|
|
|
|
if (!TryGetWeapon(user.Value, out var weaponUid, out var weapon) ||
|
|
weaponUid != GetEntity(msg.Weapon))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AttemptAttack(args.SenderSession.AttachedEntity!.Value, weaponUid, weapon, msg, args.SenderSession);
|
|
}
|
|
|
|
private void OnHeavyAttack(HeavyAttackEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
if (args.SenderSession.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon) ||
|
|
weaponUid != GetEntity(msg.Weapon))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AttemptAttack(args.SenderSession.AttachedEntity.Value, weaponUid, weapon, msg, args.SenderSession);
|
|
}
|
|
|
|
private void OnDisarmAttack(DisarmAttackEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
if (args.SenderSession.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AttemptAttack(args.SenderSession.AttachedEntity.Value, weaponUid, weapon, msg, args.SenderSession);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the total damage a weapon does, including modifiers like wielding and enablind/disabling
|
|
/// </summary>
|
|
public DamageSpecifier GetDamage(EntityUid uid, EntityUid user, MeleeWeaponComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component, false))
|
|
return new DamageSpecifier();
|
|
|
|
var ev = new GetMeleeDamageEvent(uid, new (component.Damage), new(), user);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
return DamageSpecifier.ApplyModifierSets(ev.Damage, ev.Modifiers);
|
|
}
|
|
|
|
public float GetAttackRate(EntityUid uid, EntityUid user, MeleeWeaponComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return 0;
|
|
|
|
var ev = new GetMeleeAttackRateEvent(uid, component.AttackRate, 1, user);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
return ev.Rate * ev.Multipliers;
|
|
}
|
|
|
|
public FixedPoint2 GetHeavyDamageModifier(EntityUid uid, EntityUid user, MeleeWeaponComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return FixedPoint2.Zero;
|
|
|
|
var ev = new GetHeavyDamageModifierEvent(uid, component.ClickDamageModifier, 1, user);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
return ev.DamageModifier * ev.Multipliers;
|
|
}
|
|
|
|
public bool TryGetWeapon(EntityUid entity, out EntityUid weaponUid, [NotNullWhen(true)] out MeleeWeaponComponent? melee)
|
|
{
|
|
weaponUid = default;
|
|
melee = null;
|
|
|
|
var ev = new GetMeleeWeaponEvent();
|
|
RaiseLocalEvent(entity, ev);
|
|
if (ev.Handled)
|
|
{
|
|
if (TryComp(ev.Weapon, out melee))
|
|
{
|
|
weaponUid = ev.Weapon.Value;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Use inhands entity if we got one.
|
|
if (EntityManager.TryGetComponent(entity, out HandsComponent? hands) &&
|
|
hands.ActiveHandEntity is { } held)
|
|
{
|
|
if (EntityManager.TryGetComponent(held, out melee))
|
|
{
|
|
weaponUid = held;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Use hands clothing if applicable.
|
|
if (_inventory.TryGetSlotEntity(entity, "gloves", out var gloves) &&
|
|
TryComp<MeleeWeaponComponent>(gloves, out var glovesMelee))
|
|
{
|
|
weaponUid = gloves.Value;
|
|
melee = glovesMelee;
|
|
return true;
|
|
}
|
|
|
|
// Use our own melee
|
|
if (TryComp(entity, out melee))
|
|
{
|
|
weaponUid = entity;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void AttemptLightAttackMiss(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, EntityCoordinates coordinates)
|
|
{
|
|
AttemptAttack(user, weaponUid, weapon, new LightAttackEvent(null, GetNetEntity(weaponUid), GetNetCoordinates(coordinates)), null);
|
|
}
|
|
|
|
public bool AttemptLightAttack(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, EntityUid target)
|
|
{
|
|
if (!TryComp<TransformComponent>(target, out var targetXform))
|
|
return false;
|
|
|
|
return AttemptAttack(user, weaponUid, weapon, new LightAttackEvent(GetNetEntity(target), GetNetEntity(weaponUid), GetNetCoordinates(targetXform.Coordinates)), null);
|
|
}
|
|
|
|
public bool AttemptDisarmAttack(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, EntityUid target)
|
|
{
|
|
if (!TryComp<TransformComponent>(target, out var targetXform))
|
|
return false;
|
|
|
|
return AttemptAttack(user, weaponUid, weapon, new DisarmAttackEvent(GetNetEntity(target), GetNetCoordinates(targetXform.Coordinates)), null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when a windup is finished and an attack is tried.
|
|
/// </summary>
|
|
/// <returns>True if attack successful</returns>
|
|
private bool AttemptAttack(EntityUid user, EntityUid weaponUid, MeleeWeaponComponent weapon, AttackEvent attack, ICommonSession? session)
|
|
{
|
|
var curTime = Timing.CurTime;
|
|
|
|
if (weapon.NextAttack > curTime)
|
|
return false;
|
|
|
|
if (!CombatMode.IsInCombatMode(user))
|
|
return false;
|
|
|
|
switch (attack)
|
|
{
|
|
case LightAttackEvent light:
|
|
var lightTarget = GetEntity(light.Target);
|
|
|
|
if (!Blocker.CanAttack(user, lightTarget))
|
|
return false;
|
|
|
|
// Can't self-attack if you're the weapon
|
|
if (weaponUid == lightTarget)
|
|
return false;
|
|
|
|
break;
|
|
case DisarmAttackEvent disarm:
|
|
var disarmTarget = GetEntity(disarm.Target);
|
|
|
|
if (!Blocker.CanAttack(user, disarmTarget))
|
|
return false;
|
|
break;
|
|
default:
|
|
if (!Blocker.CanAttack(user))
|
|
return false;
|
|
break;
|
|
}
|
|
|
|
// Windup time checked elsewhere.
|
|
var fireRate = TimeSpan.FromSeconds(1f / GetAttackRate(weaponUid, user, weapon));
|
|
var swings = 0;
|
|
|
|
// TODO: If we get autoattacks then probably need a shotcounter like guns so we can do timing properly.
|
|
if (weapon.NextAttack < curTime)
|
|
weapon.NextAttack = curTime;
|
|
|
|
while (weapon.NextAttack <= curTime)
|
|
{
|
|
weapon.NextAttack += fireRate;
|
|
swings++;
|
|
}
|
|
|
|
Dirty(weaponUid, weapon);
|
|
|
|
// Do this AFTER attack so it doesn't spam every tick
|
|
var ev = new AttemptMeleeEvent();
|
|
RaiseLocalEvent(weaponUid, ref ev);
|
|
|
|
if (ev.Cancelled)
|
|
{
|
|
if (ev.Message != null)
|
|
{
|
|
PopupSystem.PopupClient(ev.Message, weaponUid, user);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Attack confirmed
|
|
for (var i = 0; i < swings; i++)
|
|
{
|
|
string animation;
|
|
|
|
switch (attack)
|
|
{
|
|
case LightAttackEvent light:
|
|
DoLightAttack(user, light, weaponUid, weapon, session);
|
|
animation = weapon.Animation;
|
|
break;
|
|
case DisarmAttackEvent disarm:
|
|
if (!DoDisarm(user, disarm, weaponUid, weapon, session))
|
|
return false;
|
|
|
|
animation = weapon.Animation;
|
|
break;
|
|
case HeavyAttackEvent heavy:
|
|
if (!DoHeavyAttack(user, heavy, weaponUid, weapon, session))
|
|
return false;
|
|
|
|
animation = weapon.WideAnimation;
|
|
break;
|
|
default:
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
DoLungeAnimation(user, weapon.Angle, GetCoordinates(attack.Coordinates).ToMap(EntityManager, TransformSystem), weapon.Range, animation);
|
|
}
|
|
|
|
weapon.Attacking = true;
|
|
return true;
|
|
}
|
|
|
|
protected abstract bool InRange(EntityUid user, EntityUid target, float range, ICommonSession? session);
|
|
|
|
protected virtual void DoLightAttack(EntityUid user, LightAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
|
{
|
|
// If I do not come back later to fix Light Attacks being Heavy Attacks you can throw me in the spider pit -Errant
|
|
var damage = GetDamage(meleeUid, user, component) * GetHeavyDamageModifier(meleeUid, user, component);
|
|
var target = GetEntity(ev.Target);
|
|
|
|
// For consistency with wide attacks stuff needs damageable.
|
|
if (Deleted(target) ||
|
|
!HasComp<DamageableComponent>(target) ||
|
|
!TryComp<TransformComponent>(target, out var targetXform) ||
|
|
// Not in LOS.
|
|
!InRange(user, target.Value, component.Range, session))
|
|
{
|
|
// Leave IsHit set to true, because the only time it's set to false
|
|
// is when a melee weapon is examined. Misses are inferred from an
|
|
// empty HitEntities.
|
|
// TODO: This needs fixing
|
|
if (meleeUid == user)
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Low,
|
|
$"{ToPrettyString(user):actor} melee attacked (light) using their hands and missed");
|
|
}
|
|
else
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Low,
|
|
$"{ToPrettyString(user):actor} melee attacked (light) using {ToPrettyString(meleeUid):tool} and missed");
|
|
}
|
|
var missEvent = new MeleeHitEvent(new List<EntityUid>(), user, meleeUid, damage);
|
|
RaiseLocalEvent(meleeUid, missEvent);
|
|
Audio.PlayPredicted(component.SwingSound, meleeUid, user);
|
|
return;
|
|
}
|
|
|
|
// 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> { target.Value }, user, meleeUid, damage);
|
|
RaiseLocalEvent(meleeUid, hitEvent);
|
|
|
|
if (hitEvent.Handled)
|
|
return;
|
|
|
|
var targets = new List<EntityUid>(1)
|
|
{
|
|
target.Value
|
|
};
|
|
|
|
var weapon = GetEntity(ev.Weapon);
|
|
|
|
Interaction.DoContactInteraction(weapon, target);
|
|
Interaction.DoContactInteraction(user, weapon);
|
|
|
|
// If the user is using a long-range weapon, this probably shouldn't be happening? But I'll interpret melee as a
|
|
// somewhat messy scuffle. See also, heavy attacks.
|
|
Interaction.DoContactInteraction(user, target);
|
|
|
|
// For stuff that cares about it being attacked.
|
|
var attackedEvent = new AttackedEvent(meleeUid, user, targetXform.Coordinates);
|
|
RaiseLocalEvent(target.Value, attackedEvent);
|
|
|
|
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage + attackedEvent.BonusDamage, hitEvent.ModifiersList);
|
|
var damageResult = Damageable.TryChangeDamage(target, modifiedDamage, origin:user);
|
|
|
|
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(target.Value, (bluntDamage * component.BluntStaminaDamageFactor).Float(), visual: false, source: user, with: meleeUid == user ? null : meleeUid);
|
|
}
|
|
|
|
if (meleeUid == user)
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Medium,
|
|
$"{ToPrettyString(user):actor} melee attacked (light) {ToPrettyString(target.Value):subject} using their hands and dealt {damageResult.Total:damage} damage");
|
|
}
|
|
else
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Medium,
|
|
$"{ToPrettyString(user):actor} melee attacked (light) {ToPrettyString(target.Value):subject} using {ToPrettyString(meleeUid):tool} and dealt {damageResult.Total:damage} damage");
|
|
}
|
|
|
|
PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
|
|
}
|
|
else
|
|
{
|
|
if (hitEvent.HitSoundOverride != null)
|
|
{
|
|
Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user);
|
|
}
|
|
else if (GetDamage(meleeUid, user, component).Total.Equals(FixedPoint2.Zero) && component.HitSound != null)
|
|
{
|
|
Audio.PlayPredicted(component.HitSound, meleeUid, user);
|
|
}
|
|
else
|
|
{
|
|
Audio.PlayPredicted(component.NoDamageSound, meleeUid, user);
|
|
}
|
|
}
|
|
|
|
if (damageResult?.Total > FixedPoint2.Zero)
|
|
{
|
|
DoDamageEffect(targets, user, targetXform);
|
|
}
|
|
}
|
|
|
|
protected abstract void DoDamageEffect(List<EntityUid> targets, EntityUid? user, TransformComponent targetXform);
|
|
|
|
private bool DoHeavyAttack(EntityUid user, HeavyAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
|
{
|
|
// TODO: This is copy-paste as fuck with DoPreciseAttack
|
|
if (!TryComp<TransformComponent>(user, out var userXform))
|
|
return false;
|
|
|
|
var targetMap = GetCoordinates(ev.Coordinates).ToMap(EntityManager, TransformSystem);
|
|
|
|
if (targetMap.MapId != userXform.MapID)
|
|
return false;
|
|
|
|
var userPos = TransformSystem.GetWorldPosition(userXform);
|
|
var direction = targetMap.Position - userPos;
|
|
var distance = Math.Min(component.Range, direction.Length());
|
|
|
|
var damage = GetDamage(meleeUid, user, component);
|
|
var entities = GetEntityList(ev.Entities);
|
|
|
|
if (entities.Count == 0)
|
|
{
|
|
if (meleeUid == user)
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Low,
|
|
$"{ToPrettyString(user):actor} melee attacked (heavy) using their hands and missed");
|
|
}
|
|
else
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Low,
|
|
$"{ToPrettyString(user):actor} melee attacked (heavy) using {ToPrettyString(meleeUid):tool} and missed");
|
|
}
|
|
var missEvent = new MeleeHitEvent(new List<EntityUid>(), user, meleeUid, damage);
|
|
RaiseLocalEvent(meleeUid, missEvent);
|
|
|
|
Audio.PlayPredicted(component.SwingSound, meleeUid, user);
|
|
return true;
|
|
}
|
|
|
|
// Naughty input
|
|
if (entities.Count > MaxTargets)
|
|
{
|
|
entities.RemoveRange(MaxTargets, entities.Count - MaxTargets);
|
|
}
|
|
|
|
// Validate client
|
|
for (var i = entities.Count - 1; i >= 0; i--)
|
|
{
|
|
if (ArcRaySuccessful(entities[i], userPos, direction.ToWorldAngle(), component.Angle, distance,
|
|
userXform.MapID, user, session))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Bad input
|
|
entities.RemoveAt(i);
|
|
}
|
|
|
|
var targets = new List<EntityUid>();
|
|
var damageQuery = GetEntityQuery<DamageableComponent>();
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity == user ||
|
|
!damageQuery.HasComponent(entity))
|
|
continue;
|
|
|
|
targets.Add(entity);
|
|
}
|
|
|
|
// 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, meleeUid, damage);
|
|
RaiseLocalEvent(meleeUid, hitEvent);
|
|
|
|
if (hitEvent.Handled)
|
|
return true;
|
|
|
|
var weapon = GetEntity(ev.Weapon);
|
|
|
|
Interaction.DoContactInteraction(user, weapon);
|
|
|
|
// For stuff that cares about it being attacked.
|
|
foreach (var target in targets)
|
|
{
|
|
Interaction.DoContactInteraction(weapon, target);
|
|
|
|
// If the user is using a long-range weapon, this probably shouldn't be happening? But I'll interpret melee as a
|
|
// somewhat messy scuffle. See also, light attacks.
|
|
Interaction.DoContactInteraction(user, target);
|
|
}
|
|
|
|
var appliedDamage = new DamageSpecifier();
|
|
|
|
foreach (var entity in targets)
|
|
{
|
|
var attackedEvent = new AttackedEvent(meleeUid, user, GetCoordinates(ev.Coordinates));
|
|
RaiseLocalEvent(entity, attackedEvent);
|
|
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage + attackedEvent.BonusDamage, hitEvent.ModifiersList);
|
|
|
|
var damageResult = Damageable.TryChangeDamage(entity, modifiedDamage, origin:user);
|
|
|
|
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
|
|
{
|
|
appliedDamage += damageResult;
|
|
|
|
if (meleeUid == user)
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Medium,
|
|
$"{ToPrettyString(user):actor} melee attacked (heavy) {ToPrettyString(entity):subject} using their hands and dealt {damageResult.Total:damage} damage");
|
|
}
|
|
else
|
|
{
|
|
AdminLogger.Add(LogType.MeleeHit, LogImpact.Medium,
|
|
$"{ToPrettyString(user):actor} melee attacked (heavy) {ToPrettyString(entity):subject} using {ToPrettyString(meleeUid):tool} and dealt {damageResult.Total:damage} damage");
|
|
}
|
|
}
|
|
}
|
|
|
|
if (entities.Count != 0)
|
|
{
|
|
if (appliedDamage.Total > FixedPoint2.Zero)
|
|
{
|
|
var target = entities.First();
|
|
PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound);
|
|
}
|
|
else
|
|
{
|
|
if (hitEvent.HitSoundOverride != null)
|
|
{
|
|
Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user);
|
|
}
|
|
else
|
|
{
|
|
Audio.PlayPredicted(component.NoDamageSound, meleeUid, user);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (appliedDamage.Total > FixedPoint2.Zero)
|
|
{
|
|
DoDamageEffect(targets, user, Transform(targets[0]));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected 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;
|
|
}
|
|
|
|
protected virtual bool ArcRaySuccessful(EntityUid targetUid, Vector2 position, Angle angle, Angle arcWidth, float range,
|
|
MapId mapId, EntityUid ignore, ICommonSession? session)
|
|
{
|
|
// Only matters for server.
|
|
return true;
|
|
}
|
|
|
|
private void PlayHitSound(EntityUid target, EntityUid? user, 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.PlayPredicted(damageSoundComp.NoDamageSound, target, user, AudioParams.Default.WithVariation(DamagePitchVariation));
|
|
playedSound = true;
|
|
}
|
|
else if (type != null && damageSoundComp.SoundTypes?.TryGetValue(type, out var damageSoundType) == true)
|
|
{
|
|
Audio.PlayPredicted(damageSoundType, target, user, AudioParams.Default.WithVariation(DamagePitchVariation));
|
|
playedSound = true;
|
|
}
|
|
else if (type != null && damageSoundComp.SoundGroups?.TryGetValue(type, out var damageSoundGroup) == true)
|
|
{
|
|
Audio.PlayPredicted(damageSoundGroup, target, user, 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.PlayPredicted(hitSoundOverride, target, user, AudioParams.Default.WithVariation(DamagePitchVariation));
|
|
playedSound = true;
|
|
}
|
|
else if (hitSound != null)
|
|
{
|
|
Audio.PlayPredicted(hitSound, target, user, 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 "Radiation":
|
|
case "Cold":
|
|
Audio.PlayPredicted(new SoundPathSpecifier("/Audio/Items/welder.ogg"), target, user, AudioParams.Default.WithVariation(DamagePitchVariation));
|
|
break;
|
|
// No damage, fallback to tappies
|
|
case null:
|
|
Audio.PlayPredicted(new SoundPathSpecifier("/Audio/Weapons/tap.ogg"), target, user, AudioParams.Default.WithVariation(DamagePitchVariation));
|
|
break;
|
|
case "Brute":
|
|
Audio.PlayPredicted(new SoundPathSpecifier("/Audio/Weapons/smash.ogg"), target, user, 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;
|
|
}
|
|
|
|
protected virtual bool DoDisarm(EntityUid user, DisarmAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
|
{
|
|
var target = GetEntity(ev.Target);
|
|
|
|
if (Deleted(target) ||
|
|
user == target)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Play a sound to give instant feedback; same with playing the animations
|
|
Audio.PlayPredicted(component.SwingSound, meleeUid, user);
|
|
return true;
|
|
}
|
|
|
|
private void DoLungeAnimation(EntityUid user, Angle angle, MapCoordinates coordinates, float length, string? animation)
|
|
{
|
|
// TODO: Assert that offset eyes are still okay.
|
|
if (!TryComp<TransformComponent>(user, out var userXform))
|
|
return;
|
|
|
|
var invMatrix = TransformSystem.GetInvWorldMatrix(userXform);
|
|
var localPos = invMatrix.Transform(coordinates.Position);
|
|
|
|
if (localPos.LengthSquared() <= 0f)
|
|
return;
|
|
|
|
localPos = userXform.LocalRotation.RotateVec(localPos);
|
|
|
|
// We'll play the effect just short visually so it doesn't look like we should be hitting but actually aren't.
|
|
const float bufferLength = 0.2f;
|
|
var visualLength = length - bufferLength;
|
|
|
|
if (localPos.Length() > visualLength)
|
|
localPos = localPos.Normalized() * visualLength;
|
|
|
|
DoLunge(user, angle, localPos, animation);
|
|
}
|
|
|
|
public abstract void DoLunge(EntityUid user, Angle angle, Vector2 localPos, string? animation, bool predicted = true);
|
|
}
|