Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Проникновение со взломом #97

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid?
{
userImpulse = true;

// Получение и модификация свойств снаряда на основе параметров оружия
foreach (var (ammoEntity, shootable) in ammo)
{
if (shootable is ProjectileComponent projectile && EntityManager.TryGetComponent<GunComponent>(gunUid, out var gunComp))
{
// Применение модификаторов проникающей способности
if (EntityManager.TryGetComponent<CanPenetrateComponent>(ammoEntity, out var penetration) &&
gunComp.PenetrationModifier != null)
{
penetration.PenetrationPower += gunComp.PenetrationModifier.Value;
}

// Применение модификатора урона
if (gunComp.DamageMultiplier != null)
{
projectile.Damage *= gunComp.DamageMultiplier.Value;
}

projectile.GunModifiersApplied = true;
}
}

// Rather than splitting client / server for every ammo provider it's easier
// to just delete the spawned entities. This is for programmer sanity despite the wasted perf.
// This also means any ammo specific stuff can be grabbed as necessary.
Expand Down
79 changes: 78 additions & 1 deletion Content.Shared/Projectiles/SharedProjectileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,69 @@
{
args.Cancel("pacified-cannot-throw-embed");
}
}

/// <summary>
/// Checks if the projectile is allowed to penetrate the target it hit.
/// </summary>
private void AfterProjectileHit(EntityUid uid, ProjectileComponent component, ref AfterProjectileHitEvent args)
{
if (!TryComp<CanPenetrateComponent>(uid, out var canPenetrate))

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 168 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'CanPenetrateComponent' could not be found (are you missing a using directive or an assembly reference?)
return;

//Delete the projectile if it has no penetration power left.
if (canPenetrate.PenetrationPower <= 0)
{
QueueDel(uid);
return;
}

//Delete the projectile if it hits an entity with a CollisionLayer that has a higher value than it's PenetrationLayer.
//This allows a projectile to only penetrate a specific set of entities.
if (canPenetrate.PenetrationLayer != null)
{
if (args.Fixture.CollisionLayer > (int) canPenetrate.PenetrationLayer)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 182 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)
{
QueueDel(uid);
return;
}
}

//Allow the projectile to deal damage again.
if(canPenetrate.DamageAfterCollide)
component.DamagedEntity = false;

//If the projectile has a limit on the amount of penetrations, reduce it.
if (canPenetrate.PenetrationPower != null)
{
//If it's CollisonLayer is higher than the MachineLayer it's a "hard" target and
//deducts more penetration power.
if (args.Fixture.CollisionLayer > (int) CollisionGroup.MachineLayer)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'CollisionGroup' does not exist in the current context

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'AfterProjectileHitEvent' does not contain a definition for 'Fixture' and no accessible extension method 'Fixture' accepting a first argument of type 'AfterProjectileHitEvent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in Content.Shared/Projectiles/SharedProjectileSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'CollisionGroup' does not exist in the current context
canPenetrate.PenetrationPower -= 1;

//If the target's CollisonLayer is equal to or lower than the MachineLayer,
//it's a "soft" target and deducts less penetration power.
else
canPenetrate.PenetrationPower -= 0.5f;

// Delete the projectile if it collides with an entity that it doesn't have enough penetration power for.
if (canPenetrate.PenetrationPower < 0)
{
QueueDel(uid);
return;
}
}

//Apply the penetration damage modifier if the projectile has one.
if (canPenetrate.DamageModifier != null)
component.Damage *= canPenetrate.DamageModifier.Value;

//Overrides the original DeleteOnCollide if the projectile passes all penetration checks.
//This is to prevent having to set DeleteOnCollide to false on every prototype
//you want to give the ability to penetrate entities.
if(component.DeleteOnCollide)
component.DeleteOnCollide = false;
}
}
[Serializable, NetSerializable]
public sealed class ImpactEffectEvent : EntityEventArgs
{
Expand All @@ -174,6 +235,22 @@
}
}

[Serializable, NetSerializable]
public class AfterProjectileHitEvent : EntityEventArgs
{
public EntityUid ProjectileId { get; set; }
public EntityUid TargetId { get; set; }
public bool ShouldPenetrate { get; set; }

public AfterProjectileHitEvent(EntityUid projectileId, EntityUid targetId, bool shouldPenetrate)
{
ProjectileId = projectileId;
TargetId = targetId;
ShouldPenetrate = shouldPenetrate;
}
}


/// <summary>
/// Raised when an entity is just about to be hit with a projectile but can reflect it
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/Weapons/Ranged/Components/GunComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ public sealed partial class GunComponent : Component
/// </summary>
[DataField]
public bool ClumsyProof = false;

/// <summary>
/// The amount of penetrations the gun adds to projectiles shot by the gun.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float? PenetrationModifier;

/// <summary>
/// The damage multiplier added to projectiles shot by the gun.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float? DamageMultiplier;
}

[Flags]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
types:
Piercing: 40
Structural: 30
- type: CanPenetrate
penetrationPower: 0
- type: StaminaDamageOnCollide
damage: 35
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- suitStorage
- type: AmmoCounter
- type: Gun
penetrationModifier: 1.5 #3 mobs or 1 wall and 1 mob.
fireRate: 0.75
selectedMode: SemiAuto
availableModes:
Expand Down
Loading