2023-04-07 11:21:12 -07:00
using System.Diagnostics.CodeAnalysis ;
2023-07-08 14:08:32 +10:00
using System.Numerics ;
2023-06-01 00:57:31 -05:00
using Content.Shared.Administration.Logs ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
using Content.Shared.Alert ;
2023-04-02 16:48:32 +03:00
using Content.Shared.Audio ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
using Content.Shared.Damage.Components ;
2023-06-01 00:57:31 -05:00
using Content.Shared.Database ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
using Content.Shared.Gravity ;
2023-08-25 12:48:27 +10:00
using Content.Shared.Hands ;
2023-07-30 18:07:45 -07:00
using Content.Shared.Inventory ;
using Content.Shared.Inventory.Events ;
2024-01-03 17:24:02 +11:00
using Content.Shared.Item.ItemToggle.Components ;
2023-04-07 11:21:12 -07:00
using Content.Shared.Popups ;
2023-05-15 15:21:05 +10:00
using Content.Shared.Projectiles ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
using Content.Shared.Standing ;
2023-05-15 15:21:05 +10:00
using Content.Shared.Weapons.Ranged.Components ;
2023-09-11 02:04:02 -07:00
using Content.Shared.Weapons.Ranged.Events ;
2023-11-27 22:12:34 +11:00
using Robust.Shared.Audio.Systems ;
2023-05-15 15:21:05 +10:00
using Robust.Shared.Network ;
2023-09-11 02:04:02 -07:00
using Robust.Shared.Physics.Components ;
2023-04-07 11:21:12 -07:00
using Robust.Shared.Physics.Systems ;
using Robust.Shared.Random ;
2023-09-11 02:04:02 -07:00
using Robust.Shared.Timing ;
2023-04-02 16:48:32 +03:00
namespace Content.Shared.Weapons.Reflect ;
/// <summary>
/// This handles reflecting projectiles and hitscan shots.
/// </summary>
2024-01-03 17:24:02 +11:00
public sealed class ReflectSystem : EntitySystem
2023-04-02 16:48:32 +03:00
{
2023-05-15 15:21:05 +10:00
[Dependency] private readonly INetManager _netManager = default ! ;
2023-04-02 16:48:32 +03:00
[Dependency] private readonly IRobustRandom _random = default ! ;
2023-06-01 00:57:31 -05:00
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default ! ;
2023-09-11 02:04:02 -07:00
[Dependency] private readonly IGameTiming _gameTiming = default ! ;
2023-04-02 16:48:32 +03:00
[Dependency] private readonly SharedPopupSystem _popup = default ! ;
[Dependency] private readonly SharedPhysicsSystem _physics = default ! ;
[Dependency] private readonly SharedAudioSystem _audio = default ! ;
[Dependency] private readonly SharedTransformSystem _transform = default ! ;
2023-07-30 18:07:45 -07:00
[Dependency] private readonly InventorySystem _inventorySystem = default ! ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
[Dependency] private readonly SharedGravitySystem _gravity = default ! ;
[Dependency] private readonly StandingStateSystem _standing = default ! ;
[Dependency] private readonly AlertsSystem _alerts = default ! ;
2023-04-02 16:48:32 +03:00
2024-05-23 22:43:04 -04:00
[ValidatePrototypeId<AlertPrototype>]
private const string DeflectingAlert = "Deflecting" ;
2023-04-02 16:48:32 +03:00
public override void Initialize ( )
{
base . Initialize ( ) ;
2023-07-30 18:07:45 -07:00
2024-06-04 14:26:19 +01:00
SubscribeLocalEvent < ReflectComponent , ProjectileReflectAttemptEvent > ( OnObjectReflectProjectileAttempt ) ;
SubscribeLocalEvent < ReflectComponent , HitScanReflectAttemptEvent > ( OnObjectReflectHitscanAttempt ) ;
2023-07-30 18:07:45 -07:00
SubscribeLocalEvent < ReflectComponent , GotEquippedEvent > ( OnReflectEquipped ) ;
SubscribeLocalEvent < ReflectComponent , GotUnequippedEvent > ( OnReflectUnequipped ) ;
2023-08-25 12:48:27 +10:00
SubscribeLocalEvent < ReflectComponent , GotEquippedHandEvent > ( OnReflectHandEquipped ) ;
SubscribeLocalEvent < ReflectComponent , GotUnequippedHandEvent > ( OnReflectHandUnequipped ) ;
2024-01-03 17:24:02 +11:00
SubscribeLocalEvent < ReflectComponent , ItemToggledEvent > ( OnToggleReflect ) ;
2024-06-04 14:26:19 +01:00
SubscribeLocalEvent < ReflectUserComponent , ProjectileReflectAttemptEvent > ( OnUserProjectileReflectAttempt ) ;
SubscribeLocalEvent < ReflectUserComponent , HitScanReflectAttemptEvent > ( OnUserHitscanReflectAttempt ) ;
2023-04-02 16:48:32 +03:00
}
2024-06-04 14:26:19 +01:00
private void OnUserHitscanReflectAttempt ( Entity < ReflectUserComponent > user , ref HitScanReflectAttemptEvent args )
2023-04-02 16:48:32 +03:00
{
2023-08-25 12:48:27 +10:00
if ( args . Reflected )
2023-04-19 20:02:30 +10:00
return ;
2023-08-25 12:48:27 +10:00
2024-06-04 14:26:19 +01:00
if ( ! UserCanReflect ( user , out var bestReflectorUid ) )
return ;
2023-08-25 12:48:27 +10:00
2024-06-04 14:26:19 +01:00
if ( ! TryReflectHitscan ( user . Owner , bestReflectorUid . Value , args . Shooter , args . SourceItem , args . Direction , out var dir ) )
return ;
args . Direction = dir . Value ;
args . Reflected = true ;
2023-08-25 12:48:27 +10:00
}
2024-06-04 14:26:19 +01:00
private void OnUserProjectileReflectAttempt ( Entity < ReflectUserComponent > user , ref ProjectileReflectAttemptEvent args )
2023-08-25 12:48:27 +10:00
{
2024-06-04 14:26:19 +01:00
if ( args . Cancelled )
return ;
2023-04-19 20:02:30 +10:00
2024-06-04 14:26:19 +01:00
if ( ! TryComp < ReflectiveComponent > ( args . ProjUid , out var reflectiveComponent ) )
return ;
if ( ! UserCanReflect ( user , out var bestReflectorUid , ( args . ProjUid , reflectiveComponent ) ) )
return ;
if ( ! TryReflectProjectile ( user , bestReflectorUid . Value , ( args . ProjUid , args . Component ) ) )
return ;
args . Cancelled = true ;
}
private void OnObjectReflectHitscanAttempt ( Entity < ReflectComponent > obj , ref HitScanReflectAttemptEvent args )
{
if ( args . Reflected | | ( obj . Comp . Reflects & args . Reflective ) = = 0x0 )
return ;
if ( ! TryReflectHitscan ( obj , obj , args . Shooter , args . SourceItem , args . Direction , out var dir ) )
return ;
args . Direction = dir . Value ;
args . Reflected = true ;
2023-04-02 16:48:32 +03:00
}
2024-06-04 14:26:19 +01:00
private void OnObjectReflectProjectileAttempt ( Entity < ReflectComponent > obj , ref ProjectileReflectAttemptEvent args )
2023-04-02 16:48:32 +03:00
{
if ( args . Cancelled )
return ;
2023-04-19 20:02:30 +10:00
2024-06-04 14:26:19 +01:00
if ( ! TryReflectProjectile ( obj , obj , ( args . ProjUid , args . Component ) ) )
return ;
args . Cancelled = true ;
}
/// <summary>
/// Can a user reflect something that's hit them? Returns true if so, and the best reflector available in the user's equipment.
/// </summary>
private bool UserCanReflect ( Entity < ReflectUserComponent > user , [ NotNullWhen ( true ) ] out Entity < ReflectComponent > ? bestReflector , Entity < ReflectiveComponent > ? projectile = null )
{
bestReflector = null ;
foreach ( var entityUid in _inventorySystem . GetHandOrInventoryEntities ( user . Owner , SlotFlags . WITHOUT_POCKET ) )
{
if ( ! TryComp < ReflectComponent > ( entityUid , out var comp ) )
continue ;
if ( ! comp . Enabled )
continue ;
if ( bestReflector ! = null & & bestReflector . Value . Comp . ReflectProb > = comp . ReflectProb )
continue ;
if ( projectile ! = null & & ( comp . Reflects & projectile . Value . Comp . Reflective ) = = 0x0 )
continue ;
bestReflector = ( entityUid , comp ) ;
}
return bestReflector ! = null ;
2023-04-02 16:48:32 +03:00
}
2023-04-19 20:02:30 +10:00
2024-06-04 14:26:19 +01:00
private bool TryReflectProjectile ( EntityUid user , Entity < ReflectComponent > reflector , Entity < ProjectileComponent > projectile )
2023-04-02 16:48:32 +03:00
{
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
if (
2024-06-04 14:26:19 +01:00
// Is it on?
! reflector . Comp . Enabled | |
// Is the projectile deflectable?
2023-05-15 15:21:05 +10:00
! TryComp < ReflectiveComponent > ( projectile , out var reflective ) | |
2024-06-04 14:26:19 +01:00
// Does the deflector deflect the type of projecitle?
( reflector . Comp . Reflects & reflective . Reflective ) = = 0x0 | |
// Is the projectile correctly set up with physics?
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
! TryComp < PhysicsComponent > ( projectile , out var physics ) | |
2024-06-04 14:26:19 +01:00
// If the user of the reflector is a mob with stamina, is it capable of deflecting?
TryComp < StaminaComponent > ( user , out var staminaComponent ) & & staminaComponent . Critical | |
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
_standing . IsDown ( reflector )
)
return false ;
2024-06-04 14:26:19 +01:00
// If this dice roll fails, the shot isn't deflected
if ( ! _random . Prob ( GetReflectChance ( reflector ) ) )
2023-04-19 20:02:30 +10:00
return false ;
2023-04-02 16:48:32 +03:00
2024-06-04 14:26:19 +01:00
// Below handles what happens after being deflected.
var rotation = _random . NextAngle ( - reflector . Comp . Spread / 2 , reflector . Comp . Spread / 2 ) . Opposite ( ) ;
2023-04-19 20:02:30 +10:00
var existingVelocity = _physics . GetMapLinearVelocity ( projectile , component : physics ) ;
2023-08-25 12:48:27 +10:00
var relativeVelocity = existingVelocity - _physics . GetMapLinearVelocity ( user ) ;
2023-04-19 20:02:30 +10:00
var newVelocity = rotation . RotateVec ( relativeVelocity ) ;
2023-04-02 16:48:32 +03:00
2023-04-19 20:02:30 +10:00
// Have the velocity in world terms above so need to convert it back to local.
var difference = newVelocity - existingVelocity ;
2023-04-02 16:48:32 +03:00
2023-04-19 20:02:30 +10:00
_physics . SetLinearVelocity ( projectile , physics . LinearVelocity + difference , body : physics ) ;
var locRot = Transform ( projectile ) . LocalRotation ;
var newRot = rotation . RotateVec ( locRot . ToVec ( ) ) ;
_transform . SetLocalRotation ( projectile , newRot . ToAngle ( ) ) ;
2023-05-15 15:21:05 +10:00
if ( _netManager . IsServer )
{
2023-08-25 12:48:27 +10:00
_popup . PopupEntity ( Loc . GetString ( "reflect-shot" ) , user ) ;
2024-06-04 14:26:19 +01:00
_audio . PlayPvs ( reflector . Comp . SoundOnReflect , user , AudioHelpers . WithVariation ( 0.05f , _random ) ) ;
2023-05-15 15:21:05 +10:00
}
2024-06-04 14:26:19 +01:00
_adminLogger . Add ( LogType . BulletHit , LogImpact . Medium , $"{ToPrettyString(user)} reflected {ToPrettyString(projectile)} from {ToPrettyString(projectile.Comp.Weapon)} shot by {projectile.Comp.Shooter}" ) ;
2023-06-01 00:57:31 -05:00
2024-06-04 14:26:19 +01:00
projectile . Comp . Shooter = user ;
projectile . Comp . Weapon = user ;
Dirty ( projectile ) ;
2023-05-15 15:21:05 +10:00
2023-04-19 20:02:30 +10:00
return true ;
2023-04-02 16:48:32 +03:00
}
2023-08-25 12:48:27 +10:00
private bool TryReflectHitscan (
EntityUid user ,
2024-06-04 14:26:19 +01:00
Entity < ReflectComponent > reflector ,
2023-08-25 12:48:27 +10:00
EntityUid ? shooter ,
EntityUid shotSource ,
Vector2 direction ,
2023-05-15 15:21:05 +10:00
[NotNullWhen(true)] out Vector2 ? newDirection )
2023-04-02 16:48:32 +03:00
{
2024-06-04 14:26:19 +01:00
if (
// Is the reflector enabled?
! reflector . Comp . Enabled | |
// If the user is a mob with stamina, is it capable of deflecting?
TryComp < StaminaComponent > ( user , out var staminaComponent ) & & staminaComponent . Critical | |
_standing . IsDown ( user ) )
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
{
newDirection = null ;
return false ;
}
2024-06-04 14:26:19 +01:00
// If this dice roll fails, the shot is not deflected.
if ( ! _random . Prob ( GetReflectChance ( reflector ) ) )
2023-05-15 15:21:05 +10:00
{
newDirection = null ;
return false ;
}
2024-06-04 14:26:19 +01:00
// Below handles what happens after being deflected.
2023-05-15 15:21:05 +10:00
if ( _netManager . IsServer )
2023-04-02 16:48:32 +03:00
{
2023-08-25 12:48:27 +10:00
_popup . PopupEntity ( Loc . GetString ( "reflect-shot" ) , user ) ;
2024-06-04 14:26:19 +01:00
_audio . PlayPvs ( reflector . Comp . SoundOnReflect , user , AudioHelpers . WithVariation ( 0.05f , _random ) ) ;
2023-04-02 16:48:32 +03:00
}
2023-04-19 20:02:30 +10:00
2024-06-04 14:26:19 +01:00
var spread = _random . NextAngle ( - reflector . Comp . Spread / 2 , reflector . Comp . Spread / 2 ) ;
2023-05-15 15:21:05 +10:00
newDirection = - spread . RotateVec ( direction ) ;
2023-06-01 00:57:31 -05:00
if ( shooter ! = null )
2023-08-25 12:48:27 +10:00
_adminLogger . Add ( LogType . HitScanHit , LogImpact . Medium , $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)} shot by {ToPrettyString(shooter.Value)}" ) ;
2023-06-01 00:57:31 -05:00
else
2023-08-25 12:48:27 +10:00
_adminLogger . Add ( LogType . HitScanHit , LogImpact . Medium , $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)}" ) ;
2023-06-01 00:57:31 -05:00
2023-05-15 15:21:05 +10:00
return true ;
2023-04-02 16:48:32 +03:00
}
2023-07-30 18:07:45 -07:00
2024-06-04 14:26:19 +01:00
private float GetReflectChance ( Entity < ReflectComponent > reflector )
{
/ *
* The rules of deflection are as follows :
* If you innately reflect things via magic , biology etc . , you always have a full chance .
* If you are standing up and standing still , you ' re prepared to deflect and have full chance .
* If you have velocity , your deflection chance depends on your velocity , clamped .
* If you are floating , your chance is the minimum value possible .
* /
if ( reflector . Comp . Innate )
return reflector . Comp . ReflectProb ;
if ( _gravity . IsWeightless ( reflector ) )
return reflector . Comp . MinReflectProb ;
if ( ! TryComp < PhysicsComponent > ( reflector , out var reflectorPhysics ) )
return reflector . Comp . ReflectProb ;
return MathHelper . Lerp (
reflector . Comp . MinReflectProb ,
reflector . Comp . ReflectProb ,
// Inverse progression between velocities fed in as progression between probabilities. We go high -> low so the output here needs to be _inverted_.
1 - Math . Clamp ( ( reflectorPhysics . LinearVelocity . Length ( ) - reflector . Comp . VelocityBeforeNotMaxProb ) / ( reflector . Comp . VelocityBeforeMinProb - reflector . Comp . VelocityBeforeNotMaxProb ) , 0 , 1 )
) ;
}
private void OnReflectEquipped ( Entity < ReflectComponent > reflector , ref GotEquippedEvent args )
2023-07-30 18:07:45 -07:00
{
2023-09-11 02:04:02 -07:00
if ( _gameTiming . ApplyingState )
return ;
2023-08-25 12:48:27 +10:00
EnsureComp < ReflectUserComponent > ( args . Equipee ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
2024-06-04 14:26:19 +01:00
if ( reflector . Comp . Enabled )
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
EnableAlert ( args . Equipee ) ;
2023-07-30 18:07:45 -07:00
}
2024-06-04 14:26:19 +01:00
private void OnReflectUnequipped ( Entity < ReflectComponent > reflector , ref GotUnequippedEvent args )
2023-07-30 18:07:45 -07:00
{
2023-08-25 12:48:27 +10:00
RefreshReflectUser ( args . Equipee ) ;
}
2023-07-30 18:07:45 -07:00
2024-06-04 14:26:19 +01:00
private void OnReflectHandEquipped ( Entity < ReflectComponent > reflector , ref GotEquippedHandEvent args )
2023-08-25 12:48:27 +10:00
{
2023-09-11 02:04:02 -07:00
if ( _gameTiming . ApplyingState )
return ;
2023-08-25 12:48:27 +10:00
EnsureComp < ReflectUserComponent > ( args . User ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
2024-06-04 14:26:19 +01:00
if ( reflector . Comp . Enabled )
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
EnableAlert ( args . User ) ;
2023-08-25 12:48:27 +10:00
}
2023-07-30 18:07:45 -07:00
2024-06-04 14:26:19 +01:00
private void OnReflectHandUnequipped ( Entity < ReflectComponent > reflector , ref GotUnequippedHandEvent args )
2023-08-25 12:48:27 +10:00
{
RefreshReflectUser ( args . User ) ;
}
2023-07-30 18:07:45 -07:00
2024-06-04 14:26:19 +01:00
private void OnToggleReflect ( Entity < ReflectComponent > reflector , ref ItemToggledEvent args )
2024-01-03 17:24:02 +11:00
{
2024-06-04 14:26:19 +01:00
reflector . Comp . Enabled = args . Activated ;
Dirty ( reflector ) ;
if ( args . User = = null )
return ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
2024-06-04 14:26:19 +01:00
if ( reflector . Comp . Enabled )
EnableAlert ( args . User . Value ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
else
2024-06-04 14:26:19 +01:00
DisableAlert ( args . User . Value ) ;
2024-01-03 17:24:02 +11:00
}
2023-08-25 12:48:27 +10:00
/// <summary>
2024-06-04 14:26:19 +01:00
/// Refreshes whether someone has reflection potential, so we can raise directed events on them.
2023-08-25 12:48:27 +10:00
/// </summary>
private void RefreshReflectUser ( EntityUid user )
{
2024-04-28 00:11:46 -07:00
foreach ( var ent in _inventorySystem . GetHandOrInventoryEntities ( user , SlotFlags . WITHOUT_POCKET ) )
2023-07-30 18:07:45 -07:00
{
2023-08-25 12:48:27 +10:00
if ( ! HasComp < ReflectComponent > ( ent ) )
2023-07-30 18:07:45 -07:00
continue ;
2023-08-25 12:48:27 +10:00
EnsureComp < ReflectUserComponent > ( user ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
EnableAlert ( user ) ;
2023-08-25 12:48:27 +10:00
return ;
2023-07-30 18:07:45 -07:00
}
2023-08-25 12:48:27 +10:00
RemCompDeferred < ReflectUserComponent > ( user ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
DisableAlert ( user ) ;
}
private void EnableAlert ( EntityUid alertee )
{
2024-05-23 22:43:04 -04:00
_alerts . ShowAlert ( alertee , DeflectingAlert ) ;
Weapon Reflection Movement Mechanic (#27219)
* Weapon Reflection Movement Mechanic
Adds a movement mechanic to deflection.
Standing still gives you your best chance of deflecting a shot.
Moving lowers this to 2/3rds. Sprinting to 1/3rd.
This allows for robust players to express better and provides
counterplay to someone finding a goober-strong deflection
weapon, giving more design space.
As part of this PR I've also touched the numbers of a few swords,
shields, etc. and modified some descriptions to make them read
better. The balance numbers are not remotely final, but as intent:
1. All the sidearm swords (katana, cutlass, captain's sabre) have the same damage. There's no good reason the "ceremonial" blade the captain has doing more damage than a katana.
2. The Captain's Sabre has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting. This one is controversial due to the recent nerf, I suspect: This could easily be 15->10->5?
3. The Energy Katana has a flat 30% reflect chance.
4. The meme Throngler has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
5. The E-Sword has a 30% reflect chance, dropping to 20% when moving and 10% when sprinting.
6. The Double E-Sword has a mighty 75% reflect chance, dropping to 50% and then 25%.
7. Both reflective shields - Mirror and Energy - have a 95% deflect chance, dropping to 63% then 31%.
* Resolve PR comments.
* Weh?
* Reign in double esword a tad
* Shield nerfs no longer real
* Improve Mirror Cult desc
* Simple alert for deflection! No art yet.
* Added a new icon for deflecting
2024-05-07 19:14:58 +01:00
}
private void DisableAlert ( EntityUid alertee )
{
2024-05-23 22:43:04 -04:00
_alerts . ClearAlert ( alertee , DeflectingAlert ) ;
2023-07-30 18:07:45 -07:00
}
2023-04-02 16:48:32 +03:00
}