mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
* AutoEquip+redEdit * guns+projectile+equip for red * rsi fix * +blue * review suggestion * startingGear + deleteSpawnOnGamerule * DeleteSpawnOnGamerule + map * +magboots for marine * 1 * 2 * 3 * +grenades * final + fix * fix * fix2 * fix3 * Update Content.Server/_White/PVS/PVSIgnoreSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Mining/MeteorSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Mining/MeteorSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Mining/MeteorSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/_White/PVS/PVSIgnoreSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Projectiles/ProjectileSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Shared/_White/PVS/PVSIgnoreComponent.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Projectiles/ProjectileSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Projectiles/ProjectileSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Update Content.Server/Projectiles/ProjectileSystem.cs Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> * Fix govna ya ebal * fixWalls * Apply suggestions from code review Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * fix hz * fix hz2 --------- Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com>
177 lines
7.7 KiB
C#
177 lines
7.7 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Damage.Systems;
|
|
using Content.Server.Destructible;
|
|
using Content.Server.Effects;
|
|
using Content.Server.Weapons.Ranged.Systems;
|
|
using Content.Shared.Camera;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Damage.Events;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Projectiles;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Projectiles;
|
|
|
|
public sealed class ProjectileSystem : SharedProjectileSystem
|
|
{
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly ColorFlashEffectSystem _color = default!;
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
|
[Dependency] private readonly DestructibleSystem _destructibleSystem = default!;
|
|
[Dependency] private readonly GunSystem _guns = default!;
|
|
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!; // WWDP edit
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(OnStartCollide);
|
|
SubscribeLocalEvent<EmbeddableProjectileComponent, DamageExamineEvent>(OnDamageExamine, after: [typeof(DamageOtherOnHitSystem)]);
|
|
// WD EDIT START
|
|
SubscribeLocalEvent<EmbeddableProjectileComponent, EmbedEvent>(OnEmbed);
|
|
// WD EDIT END
|
|
}
|
|
|
|
private void OnStartCollide(EntityUid uid, ProjectileComponent component, ref StartCollideEvent args)
|
|
{
|
|
// This is so entities that shouldn't get a collision are ignored.
|
|
if (args.OurFixtureId != ProjectileFixture || !args.OtherFixture.Hard
|
|
|| component.ProjectileSpent || component is { Weapon: null, OnlyCollideWhenShot: true, })
|
|
return;
|
|
|
|
var target = args.OtherEntity;
|
|
// it's here so this check is only done once before possible hit
|
|
var attemptEv = new ProjectileReflectAttemptEvent(uid, component, false);
|
|
RaiseLocalEvent(target, ref attemptEv);
|
|
if (attemptEv.Cancelled)
|
|
{
|
|
SetShooter(uid, component, target);
|
|
return;
|
|
}
|
|
|
|
var ev = new ProjectileHitEvent(component.Damage, target, component.Shooter);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
var otherName = ToPrettyString(target);
|
|
var damageRequired = _destructibleSystem.DestroyedAt(target);
|
|
if (TryComp<DamageableComponent>(target, out var damageableComponent))
|
|
{
|
|
damageRequired -= damageableComponent.TotalDamage;
|
|
damageRequired = FixedPoint2.Max(damageRequired, FixedPoint2.Zero);
|
|
}
|
|
var modifiedDamage = _damageableSystem.TryChangeDamage(target, ev.Damage, component.IgnoreResistances, damageable: damageableComponent, origin: component.Shooter);
|
|
var deleted = Deleted(target);
|
|
|
|
if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter))
|
|
{
|
|
if (modifiedDamage.AnyPositive() && !deleted)
|
|
_color.RaiseEffect(Color.Red, [ target, ], Filter.Pvs(target, entityManager: EntityManager));
|
|
|
|
_adminLogger.Add(
|
|
LogType.BulletHit,
|
|
HasComp<ActorComponent>(target) ? LogImpact.Extreme : LogImpact.High,
|
|
$"Projectile {ToPrettyString(uid):projectile} shot by {ToPrettyString(component.Shooter!.Value):user} hit {otherName:target} and dealt {modifiedDamage.GetTotal():damage} damage");
|
|
}
|
|
|
|
// If penetration is to be considered, we need to do some checks to see if the projectile should stop.
|
|
if (modifiedDamage is not null && component.PenetrationThreshold != 0)
|
|
{
|
|
// If a damage type is required, stop the bullet if the hit entity doesn't have that type.
|
|
if (component.PenetrationDamageTypeRequirement != null)
|
|
{
|
|
var stopPenetration = false;
|
|
foreach (var requiredDamageType in component.PenetrationDamageTypeRequirement)
|
|
{
|
|
if (!modifiedDamage.DamageDict.Keys.Contains(requiredDamageType))
|
|
{
|
|
stopPenetration = true;
|
|
break;
|
|
}
|
|
}
|
|
if (stopPenetration)
|
|
component.ProjectileSpent = true;
|
|
}
|
|
|
|
// If the object won't be destroyed, it "tanks" the penetration hit.
|
|
if (modifiedDamage.GetTotal() < damageRequired)
|
|
{
|
|
component.ProjectileSpent = true;
|
|
}
|
|
|
|
if (!component.ProjectileSpent)
|
|
{
|
|
component.PenetrationAmount += damageRequired;
|
|
// The projectile has dealt enough damage to be spent.
|
|
if (component.PenetrationAmount >= component.PenetrationThreshold)
|
|
{
|
|
component.ProjectileSpent = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Goobstation start - Enhanced penetration with limits
|
|
if (component.Penetrate
|
|
&& component.IgnoredEntities.Count < component.MaxPenetrations
|
|
&& (component.PenetrationChance >= 1.0f
|
|
|| _random.Prob(component.PenetrationChance)))
|
|
component.IgnoredEntities.Add(target);
|
|
else
|
|
component.ProjectileSpent = true;
|
|
// Goobstation end
|
|
}
|
|
|
|
if (!deleted)
|
|
{
|
|
_guns.PlayImpactSound(target, modifiedDamage, component.SoundHit, component.ForceSound);
|
|
|
|
if (!args.OurBody.LinearVelocity.IsLengthZero())
|
|
_sharedCameraRecoil.KickCamera(target, args.OurBody.LinearVelocity.Normalized());
|
|
}
|
|
|
|
if (component.DeleteOnCollide && component.ProjectileSpent || (component.NoPenetrateMask & args.OtherFixture.CollisionLayer) != 0) // Goobstation - Make x-ray arrows not penetrate blob
|
|
QueueDel(uid);
|
|
|
|
// WD EDIT START
|
|
if (component.StopFlyingOnImpact && TryComp<PhysicsComponent>(uid, out var physics))
|
|
_physics.SetBodyStatus(uid, physics, BodyStatus.OnGround);
|
|
// WD EDIT END
|
|
|
|
if (component.ImpactEffect != null && TryComp(uid, out TransformComponent? xform))
|
|
RaiseNetworkEvent(new ImpactEffectEvent(component.ImpactEffect, GetNetCoordinates(xform.Coordinates)), Filter.Pvs(xform.Coordinates, entityMan: EntityManager));
|
|
}
|
|
|
|
private void OnDamageExamine(EntityUid uid, EmbeddableProjectileComponent component, ref DamageExamineEvent args)
|
|
{
|
|
if (!component.EmbedOnThrow)
|
|
return;
|
|
|
|
if (!args.Message.IsEmpty)
|
|
args.Message.PushNewline();
|
|
|
|
var isHarmful = TryComp<EmbedPassiveDamageComponent>(uid, out var passiveDamage) && passiveDamage.Damage.AnyPositive();
|
|
var loc = isHarmful
|
|
? "damage-examine-embeddable-harmful"
|
|
: "damage-examine-embeddable";
|
|
|
|
var staminaCostMarkup = FormattedMessage.FromMarkupOrThrow(Loc.GetString(loc));
|
|
args.Message.AddMessage(staminaCostMarkup);
|
|
}
|
|
|
|
// WD EDIT START
|
|
private void OnEmbed(EntityUid uid, EmbeddableProjectileComponent component, ref EmbedEvent args)
|
|
{
|
|
var dmg = _damageableSystem.TryChangeDamage(args.Embedded, component.Damage, origin: args.Shooter);
|
|
if (dmg is { Empty: false })
|
|
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Embedded }, Filter.Pvs(args.Embedded, entityManager: EntityManager));
|
|
}
|
|
// WD EDIT END
|
|
}
|