Files
OldThink/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs

83 lines
3.7 KiB
C#
Raw Permalink Normal View History

2021-11-29 02:34:44 +13:00
using Content.Server.Administration.Logs;
using Content.Server.Damage.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Camera;
using Content.Server._White.Crossbow;
using Content.Shared._White.Cult.Systems;
ECS damageable (#4529) * ECS and damage Data * Comments and newlines * Added Comments * Make TryChangeDamageEvent immutable * Remove SetAllDamage event Use public SetAllDamage function instead * Undo destructible mistakes That was some shit code. * Rename DamageData to DamageSpecifier And misc small edits misc * Cache trigger prototypes. * Renaming destructible classes & functions * Revert "Cache trigger prototypes." This reverts commit 86bae15ba6616884dba75f552dfdfbe2d1fb6586. * Replace prototypes with prototype IDs. * Split damage.yml into individual files * move get/handle component state to system * Update HealthChange doc * Make godmode call Dirty() on damageable component * Add Initialize() to fix damage test * Make non-static * uncache resistance set prototype and trim DamageableComponentState * Remove unnecessary Dirty() calls during initialization * RemoveTryChangeDamageEvent * revert Dirty() * Fix MobState relying on DamageableComponent.Dirty() * Fix DisposalUnit Tests. These were previously failing, but because the async was not await-ed, this never raised the exception. After I fixed MobState component, this exception stopped happening and instead the assertions started being tested & failing * Disposal test 2: electric boogaloo * Fix typos/mistakes also add comments and fix spacing. * Use Uids instead of IEntity * fix merge * Comments, a merge issue, and making some damage ignore resistances * Extend DamageSpecifier and use it for DamageableComponent * fix master merge * Fix Disposal unit test. Again. Snapgrids were removed in master * Execute Exectute
2021-09-15 03:07:37 +10:00
using Content.Shared.Damage;
2023-08-07 12:09:35 +03:00
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Systems;
2021-11-28 14:56:53 +01:00
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Mobs.Components;
2024-01-21 08:56:32 +03:00
using Content.Shared.Projectiles;
using Content.Shared.Throwing;
2024-06-13 23:56:59 +00:00
using Content.Shared.Weapons.Melee;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
namespace Content.Server.Damage.Systems
{
public sealed class DamageOtherOnHitSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly GunSystem _guns = default!;
2023-08-07 12:09:35 +03:00
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
2023-08-11 03:44:52 +10:00
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly ThrownItemSystem _thrownItem = default!;
2021-11-29 02:34:44 +13:00
public override void Initialize()
{
2024-06-13 23:56:59 +00:00
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit,
before: new[] {typeof(MeleeThrowOnHitSystem)},
after: new[] {typeof(BloodSpearSystem)}); // WD EDIT
2023-08-07 12:09:35 +03:00
SubscribeLocalEvent<DamageOtherOnHitComponent, DamageExamineEvent>(OnDamageExamine);
}
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
{
// WD EDIT START
if (args.Handled)
return;
var damage = component.Damage;
if (TryComp(uid, out ThrowDamageModifierComponent? modifier))
damage += modifier.Damage;
var dmg = _damageable.TryChangeDamage(args.Target, damage, component.IgnoreResistances, origin: args.Component.Thrower);
// WD EDIT END
2022-02-07 14:52:58 +13:00
// Log damage only for mobs. Useful for when people throw spears at each other, but also avoids log-spam when explosions send glass shards flying.
if (dmg != null && HasComp<MobStateComponent>(args.Target))
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.GetTotal():damage} damage from collision");
if (dmg is { Empty: false })
{
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Target }, Filter.Pvs(args.Target, entityManager: EntityManager));
}
2024-06-13 23:56:59 +00:00
_guns.PlayImpactSound(args.Target, dmg, component.Sound, component.Sound != null); // WD EDIT
/* if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
{
var direction = body.LinearVelocity.Normalized();
_sharedCameraRecoil.KickCamera(args.Target, direction);
}*/
// WD EDIT
// TODO: If more stuff touches this then handle it after.
2024-01-21 08:56:32 +03:00
if (!HasComp<EmbeddableProjectileComponent>(uid) && TryComp<PhysicsComponent>(uid, out var physics)) // WD EDIT
{
_thrownItem.LandComponent(args.Thrown, args.Component, physics, false);
}
}
2023-08-07 12:09:35 +03:00
private void OnDamageExamine(EntityUid uid, DamageOtherOnHitComponent component, ref DamageExamineEvent args)
{
_damageExamine.AddDamageExamine(args.Message, component.Damage, Loc.GetString("damage-throw"));
}
}
}