-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Точность и спад урона #188
Open
wCATw
wants to merge
8
commits into
master
Choose a base branch
from
kotovskiy/accuracy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,024
−77
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b4573ed
accuracy system + evasion system [Need test and prototypes]
01df590
xeno > mutant
1b3125b
mutant and stalker have evasion and size
fcce9da
fix
5251e83
projectiles and base weapon have accuracy and falloff
746e77c
fix
2ef7a22
wtf?? fix
c7b3ce1
file naming fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
accuracy system + evasion system [Need test and prototypes]
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._Stalker.Evasion; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(EvasionSystem))] | ||
public sealed partial class EvasionComponent : Component | ||
{ | ||
/// <summary> | ||
/// Base evasion value. | ||
/// Conversion from 13: evasion | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 Evasion = 0; | ||
|
||
/// <summary> | ||
/// Evasion value after applicable modifiers. This is subtracted from the hit chance of most incoming projectiles. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 ModifiedEvasion = 0; | ||
|
||
/// <summary> | ||
/// Base evasion value for friendly fire. | ||
/// Conversion from 13: FF_hit_evade | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 EvasionFriendly = 15; | ||
|
||
/// <summary> | ||
/// Evasion value after applicable modifiers. This is subtracted from the hit chance of most incoming friendly projectiles. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 ModifiedEvasionFriendly = 0; | ||
} | ||
|
||
public enum EvasionModifiers : int | ||
{ | ||
Rest = -15, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чисто RMC хуйня у нас такого нет |
||
Invisibility = 1000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кровососы выебут тебя в очко |
||
SizeSmall = 10, | ||
SizeBig = -10 | ||
} |
10 changes: 10 additions & 0 deletions
10
Content.Shared/_Stalker/Evasion/EvasionRefreshModifiersEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Content.Shared.FixedPoint; | ||
|
||
namespace Content.Shared._Stalker.Evasion; | ||
|
||
[ByRefEvent] | ||
public record struct EvasionRefreshModifiersEvent( | ||
Entity<EvasionComponent> Entity, | ||
FixedPoint2 Evasion, | ||
FixedPoint2 EvasionFriendly | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Content.Shared._Stalker.Stun; | ||
using Content.Shared.Standing; | ||
|
||
namespace Content.Shared._Stalker.Evasion; | ||
|
||
public sealed class EvasionSystem : EntitySystem | ||
{ | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<EvasionComponent, MapInitEvent>(CallRefresh); | ||
SubscribeLocalEvent<EvasionComponent, DownedEvent>(CallRefresh); | ||
SubscribeLocalEvent<EvasionComponent, StoodEvent>(CallRefresh); | ||
|
||
SubscribeLocalEvent<STSizeComponent, EvasionRefreshModifiersEvent>(OnSizeRefreshEvasion); | ||
} | ||
|
||
public void RefreshEvasionModifiers(EntityUid entity) | ||
{ | ||
if (!TryComp(entity, out EvasionComponent? evasionComponent)) | ||
return; | ||
|
||
RefreshEvasionModifiers((entity, evasionComponent)); | ||
} | ||
|
||
public void RefreshEvasionModifiers(Entity<EvasionComponent> entity) | ||
{ | ||
var ev = new EvasionRefreshModifiersEvent( | ||
entity, | ||
entity.Comp.Evasion, | ||
entity.Comp.EvasionFriendly); | ||
|
||
RaiseLocalEvent(entity.Owner, ref ev); | ||
|
||
entity.Comp.ModifiedEvasion = ev.Evasion; | ||
entity.Comp.ModifiedEvasionFriendly = ev.EvasionFriendly; | ||
|
||
Dirty(entity); | ||
} | ||
|
||
private void CallRefresh<T>(Entity<EvasionComponent> entity, ref T args) where T : notnull | ||
{ | ||
RefreshEvasionModifiers(entity); | ||
} | ||
|
||
private void OnSizeRefreshEvasion(Entity<STSizeComponent> size, ref EvasionRefreshModifiersEvent args) | ||
{ | ||
if (size.Owner != args.Entity.Owner) | ||
return; | ||
|
||
if (size.Comp.Size <= STSizes.Small) | ||
args.Evasion += (int) EvasionModifiers.SizeSmall; | ||
|
||
if (size.Comp.Size >= STSizes.Big) | ||
args.Evasion += (int) EvasionModifiers.SizeBig; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Content.Shared/_Stalker/Projectiles/DeleteOnCollideComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class DeleteOnCollideComponent : Component; |
16 changes: 16 additions & 0 deletions
16
Content.Shared/_Stalker/Projectiles/ModifyTargetOnHitComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class ModifyTargetOnHitComponent : Component | ||
{ | ||
[DataField] | ||
public ComponentRegistry? Add; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityWhitelist? Whitelist; | ||
} |
7 changes: 7 additions & 0 deletions
7
Content.Shared/_Stalker/Projectiles/PreventCollideWithDeadComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class PreventCollideWithDeadComponent : Component; |
18 changes: 18 additions & 0 deletions
18
Content.Shared/_Stalker/Projectiles/ProjectileMaxRangeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Map; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class ProjectileMaxRangeComponent : Component | ||
{ | ||
[DataField, AutoNetworkedField] | ||
public EntityCoordinates? Origin; | ||
|
||
[DataField(required: true), AutoNetworkedField] | ||
public float Max; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool Delete = true; | ||
} |
88 changes: 88 additions & 0 deletions
88
Content.Shared/_Stalker/Projectiles/STProjectileAccuracyComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Content.Shared._Stalker.Random; | ||
using Content.Shared._Stalker.Weapons.Ranged; | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STProjectileSystem), typeof(STGunSystem))] | ||
public sealed partial class STProjectileAccuracyComponent : Component | ||
{ | ||
/// <summary> | ||
/// This lists all the thresholds and their falloff values. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public List<AccuracyFalloffThreshold> Thresholds = new() | ||
{ | ||
new AccuracyFalloffThreshold(5f, 10, false) | ||
}; | ||
|
||
/// <summary> | ||
/// Minimum hit chance. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 MinAccuracy = 5; | ||
|
||
/// <summary> | ||
/// The accuracy of the projectile before taking into account any modifiers reliant on the target. | ||
/// This value is multiplied by the firing weapon's accuracy multiplier upon the projectile being shot. | ||
/// Conversion from 13: accuracy + accuracy (one from the ammo, the other from the projectile itself) | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 Accuracy = 90; | ||
|
||
/// <summary> | ||
/// Setting this to true will make the projectile not apply the usual penalty accuracy penalty when attacking friendlies. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public bool IgnoreFriendlyEvasion = false; | ||
|
||
/// <summary> | ||
/// If set to true, this makes the projectile automatically hit regardless of accuracy or any other modifiers. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public bool ForceHit = false; | ||
|
||
/// <summary> | ||
/// These are the coordinates from which the projectile was shot. Used to determine the distance travelled. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public EntityCoordinates? ShotFrom; | ||
|
||
[DataField, AutoNetworkedField] | ||
public long GunSeed; | ||
|
||
[DataField, AutoNetworkedField] | ||
public uint Tick; | ||
} | ||
|
||
[DataRecord, Serializable, NetSerializable] | ||
public record struct AccuracyFalloffThreshold( | ||
/// <summary> | ||
/// The range at which accuracy falloff starts to take effect. | ||
/// Conversion from 13: accurate_range | ||
/// Conversion from 13 for buildup: accurate_range_min | ||
/// </summary> | ||
float Range, | ||
|
||
/// <summary> | ||
/// This is the number by which the projectile's accuracy is decreased for each tile travelled beyond its effective range. | ||
/// Conversion from 13: 10 | ||
/// Conversion from 13 for buildup: accuracy_range_falloff | ||
/// </summary> | ||
FixedPoint2 Falloff, | ||
|
||
/// <summary> | ||
/// Setting this to true makes it so AccurateRange is treated as the minimum accurate range. | ||
/// Falloff is applied by how much the shot falls short of that distance, instead of by how much it exceeds it. | ||
/// </summary> | ||
bool Buildup | ||
); | ||
|
||
public enum AccuracyModifiers : int | ||
{ | ||
TargetOccluded = -15 | ||
} |
59 changes: 59 additions & 0 deletions
59
Content.Shared/_Stalker/Projectiles/STProjectileDamageFalloffComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class STProjectileDamageFalloffComponent : Component | ||
{ | ||
/// <summary> | ||
/// This lists all the thresholds and their falloff values. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public List<DamageFalloffThreshold> Thresholds = new() | ||
{ | ||
new DamageFalloffThreshold(0f, 1, false), | ||
new DamageFalloffThreshold(22f, 9999, true) | ||
}; | ||
|
||
/// <summary> | ||
/// This determines the minimum fraction of the projectile's original damage that must remain after falloff is applied. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 MinRemainingDamageMult = 0.05f; | ||
|
||
/// <summary> | ||
/// This is the additional falloff multiplier applied by the firing weapon. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 WeaponMult = 1; | ||
|
||
/// <summary> | ||
/// These are the coordinates from which the projectile was shot. Used to determine the distance travelled. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public EntityCoordinates? ShotFrom; | ||
} | ||
|
||
[DataRecord, Serializable, NetSerializable] | ||
public record struct DamageFalloffThreshold( | ||
/// <summary> | ||
/// The range at which falloff starts to take effect. | ||
/// Conversion from 13: effective_range_max | ||
/// </summary> | ||
float Range, | ||
|
||
/// <summary> | ||
/// This is the number by which the projectile's damage is decreased for each tile travelled beyond its effective range. | ||
/// Conversion from 13: damage_falloff | ||
/// </summary> | ||
FixedPoint2 Falloff, | ||
|
||
/// <summary> | ||
/// This makes this falloff value ignore the firing weapon's falloff multiplier. Used primarily to simulate having a capped maximum range. Should generally be false. | ||
/// </summary> | ||
bool IgnoreModifiers | ||
); |
263 changes: 263 additions & 0 deletions
263
Content.Shared/_Stalker/Projectiles/STProjectileSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
using System.Numerics; | ||
using Content.Shared._Stalker.Evasion; | ||
using Content.Shared._Stalker.Random; | ||
using Content.Shared.Examine; | ||
using Content.Shared.FixedPoint; | ||
using Content.Shared.Mobs.Systems; | ||
using Content.Shared.NPC.Systems; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Projectiles; | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.Network; | ||
using Robust.Shared.Physics.Events; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
public sealed class STProjectileSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ExamineSystemShared _examine = default!; | ||
[Dependency] private readonly MobStateSystem _mobState = default!; | ||
[Dependency] private readonly NpcFactionSystem _npcFaction = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly INetManager _net = default!; | ||
[Dependency] private readonly SharedPhysicsSystem _physics = default!; | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<DeleteOnCollideComponent, StartCollideEvent>(OnDeleteOnCollideStartCollide); | ||
SubscribeLocalEvent<ModifyTargetOnHitComponent, ProjectileHitEvent>(OnModifyTargetOnHit); | ||
SubscribeLocalEvent<ProjectileMaxRangeComponent, MapInitEvent>(OnProjectileMaxRangeMapInit); | ||
|
||
SubscribeLocalEvent<STProjectileDamageFalloffComponent, MapInitEvent>(OnFalloffProjectileMapInit); | ||
SubscribeLocalEvent<STProjectileDamageFalloffComponent, ProjectileHitEvent>(OnFalloffProjectileHit); | ||
|
||
SubscribeLocalEvent<STProjectileAccuracyComponent, MapInitEvent>(OnProjectileAccuracyMapInit); | ||
SubscribeLocalEvent<STProjectileAccuracyComponent, PreventCollideEvent>(OnProjectileAccuracyPreventCollide); | ||
|
||
SubscribeLocalEvent<SpawnOnTerminateComponent, MapInitEvent>(OnSpawnOnTerminatingMapInit); | ||
SubscribeLocalEvent<SpawnOnTerminateComponent, EntityTerminatingEvent>(OnSpawnOnTerminatingTerminate); | ||
|
||
SubscribeLocalEvent<PreventCollideWithDeadComponent, PreventCollideEvent>(OnPreventCollideWithDead); | ||
} | ||
|
||
private void OnDeleteOnCollideStartCollide(Entity<DeleteOnCollideComponent> ent, ref StartCollideEvent args) | ||
{ | ||
if (_net.IsServer) | ||
QueueDel(ent); | ||
} | ||
|
||
private void OnModifyTargetOnHit(Entity<ModifyTargetOnHitComponent> ent, ref ProjectileHitEvent args) | ||
{ | ||
if (!_whitelist.IsWhitelistPassOrNull(ent.Comp.Whitelist, args.Target)) | ||
return; | ||
|
||
if (ent.Comp.Add is { } add) | ||
EntityManager.AddComponents(args.Target, add); | ||
} | ||
|
||
private void OnProjectileMaxRangeMapInit(Entity<ProjectileMaxRangeComponent> ent, ref MapInitEvent args) | ||
{ | ||
ent.Comp.Origin = _transform.GetMoverCoordinates(ent); | ||
Dirty(ent); | ||
} | ||
|
||
private void OnFalloffProjectileMapInit(Entity<STProjectileDamageFalloffComponent> projectile, ref MapInitEvent args) | ||
{ | ||
projectile.Comp.ShotFrom = _transform.GetMoverCoordinates(projectile.Owner); | ||
Dirty(projectile); | ||
} | ||
|
||
private void OnFalloffProjectileHit(Entity<STProjectileDamageFalloffComponent> projectile, ref ProjectileHitEvent args) | ||
{ | ||
if (projectile.Comp.ShotFrom == null || projectile.Comp.MinRemainingDamageMult < 0) | ||
return; | ||
|
||
var distance = (_transform.GetMoverCoordinates(args.Target).Position - projectile.Comp.ShotFrom.Value.Position).Length(); | ||
var minDamage = args.Damage.GetTotal() * projectile.Comp.MinRemainingDamageMult; | ||
|
||
foreach (var threshold in projectile.Comp.Thresholds) | ||
{ | ||
var pastEffectiveRange = distance - threshold.Range; | ||
|
||
if (pastEffectiveRange <= 0) | ||
continue; | ||
|
||
var totalDamage = args.Damage.GetTotal(); | ||
|
||
if (totalDamage <= minDamage) | ||
break; | ||
|
||
var extraMult = threshold.IgnoreModifiers ? 1 : projectile.Comp.WeaponMult; | ||
var minMult = FixedPoint2.Min(minDamage / totalDamage, 1); | ||
|
||
args.Damage *= FixedPoint2.Clamp((totalDamage - pastEffectiveRange * threshold.Falloff * extraMult) / totalDamage, minMult, 1); | ||
|
||
} | ||
} | ||
|
||
public void SetProjectileFalloffWeaponMult(Entity<STProjectileDamageFalloffComponent> projectile, FixedPoint2 mult) | ||
{ | ||
projectile.Comp.WeaponMult = mult; | ||
Dirty(projectile); | ||
} | ||
|
||
private void OnProjectileAccuracyMapInit(Entity<STProjectileAccuracyComponent> projectile, ref MapInitEvent args) | ||
{ | ||
projectile.Comp.ShotFrom = _transform.GetMoverCoordinates(projectile.Owner); | ||
projectile.Comp.Tick = _timing.CurTick.Value; | ||
|
||
Dirty(projectile); | ||
} | ||
|
||
private void OnProjectileAccuracyPreventCollide(Entity<STProjectileAccuracyComponent> projectile, ref PreventCollideEvent args) | ||
{ | ||
if (args.Cancelled) | ||
return; | ||
|
||
if (projectile.Comp.ForceHit || projectile.Comp.ShotFrom == null) | ||
return; | ||
|
||
if (!TryComp(projectile.Owner, out ProjectileComponent? projectileComponent)) | ||
return; | ||
|
||
if (!TryComp(args.OtherEntity, out EvasionComponent? evasionComponent)) | ||
return; | ||
|
||
var accuracy = projectile.Comp.Accuracy; | ||
var targetCoords = _transform.GetMoverCoordinates(args.OtherEntity); | ||
var distance = (targetCoords.Position - projectile.Comp.ShotFrom.Value.Position).Length(); | ||
|
||
foreach (var threshold in projectile.Comp.Thresholds) | ||
{ | ||
var pastRange = distance - threshold.Range; | ||
|
||
if (threshold.Buildup) | ||
{ | ||
if (pastRange >= 0) | ||
continue; | ||
|
||
accuracy += threshold.Falloff * pastRange; | ||
continue; | ||
} | ||
|
||
if (pastRange <= 0) | ||
continue; | ||
|
||
accuracy -= threshold.Falloff * pastRange; | ||
} | ||
|
||
if (!_examine.InRangeUnOccluded(_transform.ToMapCoordinates(projectile.Comp.ShotFrom.Value), _transform.ToMapCoordinates(targetCoords), distance, null)) | ||
accuracy += (int) AccuracyModifiers.TargetOccluded; | ||
|
||
if (!projectile.Comp.IgnoreFriendlyEvasion && IsProjectileTargetFriendly(projectile.Owner, args.OtherEntity)) | ||
accuracy -= evasionComponent.ModifiedEvasionFriendly; | ||
|
||
accuracy -= evasionComponent.ModifiedEvasion; | ||
|
||
accuracy = accuracy > projectile.Comp.MinAccuracy ? accuracy : projectile.Comp.MinAccuracy; | ||
|
||
var random = new Xoshiro128P(projectile.Comp.GunSeed, (long) projectile.Comp.Tick << 32 | GetNetEntity(args.OtherEntity).Id).NextFloat(0f, 100f); | ||
|
||
if (accuracy >= random) | ||
return; | ||
|
||
args.Cancelled = true; | ||
} | ||
|
||
private bool IsProjectileTargetFriendly(EntityUid projectile, EntityUid target) | ||
{ | ||
if (!TryComp(projectile, out ProjectileComponent? projectileComp) || projectileComp.Shooter == null) | ||
return false; | ||
|
||
return _npcFaction.IsEntityFriendly(projectileComp.Shooter.Value, target); | ||
} | ||
|
||
private void OnSpawnOnTerminatingMapInit(Entity<SpawnOnTerminateComponent> ent, ref MapInitEvent args) | ||
{ | ||
ent.Comp.Origin = _transform.GetMoverCoordinates(ent); | ||
Dirty(ent); | ||
} | ||
|
||
private void OnSpawnOnTerminatingTerminate(Entity<SpawnOnTerminateComponent> ent, ref EntityTerminatingEvent args) | ||
{ | ||
if (_net.IsClient) | ||
return; | ||
|
||
if (!TryComp(ent, out TransformComponent? transform)) | ||
return; | ||
|
||
if (TerminatingOrDeleted(transform.ParentUid)) | ||
return; | ||
|
||
var coordinates = transform.Coordinates; | ||
if (ent.Comp.ProjectileAdjust && | ||
ent.Comp.Origin is { } origin && | ||
coordinates.TryDelta(EntityManager, _transform, origin, out var delta) && | ||
delta.Length() > 0) | ||
{ | ||
coordinates = coordinates.Offset(delta.Normalized() / -2); | ||
} | ||
|
||
SpawnAtPosition(ent.Comp.Spawn, coordinates); | ||
|
||
if (ent.Comp.Popup is { } popup) | ||
_popup.PopupCoordinates(Loc.GetString(popup), coordinates, ent.Comp.PopupType ?? PopupType.Small); | ||
} | ||
|
||
private void OnPreventCollideWithDead(Entity<PreventCollideWithDeadComponent> ent, ref PreventCollideEvent args) | ||
{ | ||
if (args.Cancelled) | ||
return; | ||
|
||
if (_mobState.IsDead(args.OtherEntity)) | ||
args.Cancelled = true; | ||
} | ||
|
||
public void SetMaxRange(Entity<ProjectileMaxRangeComponent> ent, float max) | ||
{ | ||
ent.Comp.Max = max; | ||
Dirty(ent); | ||
} | ||
|
||
private void StopProjectile(Entity<ProjectileMaxRangeComponent> ent) | ||
{ | ||
if (ent.Comp.Delete) | ||
{ | ||
if (_net.IsServer) | ||
QueueDel(ent); | ||
} | ||
else | ||
{ | ||
_physics.SetLinearVelocity(ent, Vector2.Zero); | ||
RemCompDeferred<ProjectileMaxRangeComponent>(ent); | ||
} | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
if (_net.IsClient) | ||
return; | ||
|
||
var maxQuery = EntityQueryEnumerator<ProjectileMaxRangeComponent>(); | ||
while (maxQuery.MoveNext(out var uid, out var comp)) | ||
{ | ||
var coordinates = _transform.GetMoverCoordinates(uid); | ||
if (comp.Origin is not { } origin || | ||
!coordinates.TryDistance(EntityManager, _transform, origin, out var distance)) | ||
{ | ||
StopProjectile((uid, comp)); | ||
continue; | ||
} | ||
|
||
if (distance < comp.Max && Math.Abs(distance - comp.Max) > 0.1f) | ||
continue; | ||
|
||
StopProjectile((uid, comp)); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Shared/_Stalker/Projectiles/SpawnOnTerminateComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Content.Shared.Popups; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared._Stalker.Projectiles; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STProjectileSystem))] | ||
public sealed partial class SpawnOnTerminateComponent : Component | ||
{ | ||
[DataField, AutoNetworkedField] | ||
public EntityCoordinates? Origin; | ||
|
||
[DataField(required: true), AutoNetworkedField] | ||
public EntProtoId Spawn; | ||
|
||
[DataField, AutoNetworkedField] | ||
public LocId? Popup; | ||
|
||
[DataField, AutoNetworkedField] | ||
public PopupType? PopupType; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool ProjectileAdjust = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Content.Shared._Stalker.Random; | ||
|
||
/// <summary> | ||
/// Seed initializer PRNG (splitmix64). | ||
/// </summary> | ||
/// <remarks>http://prng.di.unimi.it/splitmix64.c</remarks> | ||
public record struct SplitMix64 | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public SplitMix64() | ||
: this(DateTime.UtcNow.Ticks) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
/// <param name="seed">Seed value.</param> | ||
public SplitMix64(long seed) | ||
{ | ||
x = (UInt64) seed; | ||
} | ||
|
||
|
||
private UInt64 x; | ||
|
||
/// <summary> | ||
/// Returns the next 64-bit pseudo-random number. | ||
/// </summary> | ||
public long Next() | ||
{ | ||
UInt64 z = unchecked(x += 0x9e3779b97f4a7c15); | ||
z = unchecked((z ^ (z >> 30)) * 0xbf58476d1ce4e5b9); | ||
z = unchecked((z ^ (z >> 27)) * 0x94d049bb133111eb); | ||
return unchecked((Int64) (z ^ (z >> 31))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Content.Shared._Stalker.Random; | ||
|
||
// https://github.com/medo64/Medo.ScrambledLinear/blob/main/src/Xoshiro/Xoshiro128P.cs | ||
/// <summary> | ||
/// 32-bit generator intended for floating point numbers with 128-bit state (xoshiro128+). | ||
/// </summary> | ||
/// <remarks>http://prng.di.unimi.it/xoshiro128plus.c</remarks> | ||
public record struct Xoshiro128P | ||
{ | ||
private UInt32 _s0; | ||
private UInt32 _s1; | ||
private UInt32 _s2; | ||
private UInt32 _s3; | ||
|
||
|
||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public Xoshiro128P() : this(DateTime.UtcNow.Ticks) { } | ||
|
||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
/// <param name="seed">Seed value.</param> | ||
public Xoshiro128P(long seed) | ||
{ | ||
var sm64 = new SplitMix64(seed); | ||
|
||
_s0 = unchecked((UInt32)sm64.Next()); | ||
_s1 = unchecked((UInt32)sm64.Next()); | ||
_s2 = unchecked((UInt32)sm64.Next()); | ||
_s3 = unchecked((UInt32)sm64.Next()); | ||
} | ||
|
||
public Xoshiro128P(long s0, long s1) | ||
{ | ||
var sm64 = new SplitMix64(s0); | ||
_s0 = unchecked((UInt32)sm64.Next()); | ||
_s1 = unchecked((UInt32)sm64.Next()); | ||
|
||
sm64 = new SplitMix64(s1); | ||
_s2 = unchecked((UInt32)sm64.Next()); | ||
_s3 = unchecked((UInt32)sm64.Next()); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the next 32-bit pseudo-random number. | ||
/// </summary> | ||
public int Next() | ||
{ | ||
UInt32 result = unchecked(_s0 + _s3); | ||
|
||
UInt32 t = _s1 << 9; | ||
|
||
_s2 ^= _s0; | ||
_s3 ^= _s1; | ||
_s1 ^= _s2; | ||
_s0 ^= _s3; | ||
|
||
_s2 ^= t; | ||
|
||
_s3 = RotateLeft(_s3, 11); | ||
|
||
return Math.Abs((int)result); | ||
} | ||
|
||
public float NextFloat() | ||
{ | ||
return Next() * 4.6566128752458E-10f; | ||
} | ||
|
||
public float NextFloat(float min, float max) | ||
{ | ||
return NextFloat() * (max - min) + min; | ||
} | ||
|
||
private static UInt32 RotateLeft(UInt32 x, int k) | ||
{ | ||
return (x << k) | (x >> (32 - k)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Content.Shared._Stalker.Stun; | ||
|
||
public sealed class STSizeStunSystem : EntitySystem | ||
{ | ||
public bool IsHumanoidSized(Entity<STSizeComponent> ent) | ||
{ | ||
return ent.Comp.Size <= STSizes.Humanoid; | ||
} | ||
|
||
public bool IsXenoSized(Entity<STSizeComponent> ent) | ||
{ | ||
return ent.Comp.Size >= STSizes.VerySmallXeno; | ||
} | ||
|
||
public bool TryGetSize(EntityUid ent, out STSizes size) | ||
{ | ||
size = default; | ||
if (!TryComp(ent, out STSizeComponent? sizeComp)) | ||
return false; | ||
|
||
size = sizeComp.Size; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._Stalker.Stun; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class STSizeComponent : Component | ||
{ | ||
[DataField(required: true), AutoNetworkedField] | ||
public STSizes Size = STSizes.Humanoid; | ||
} | ||
|
||
|
||
[Serializable, NetSerializable] | ||
public enum STSizes : byte | ||
{ | ||
Small, | ||
Humanoid, | ||
VerySmallXeno, | ||
SmallXeno, | ||
Xeno, | ||
Big, | ||
Immobile | ||
} |
8 changes: 8 additions & 0 deletions
8
Content.Shared/_Stalker/Weapons/Ranged/GetDamageFalloffEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Content.Shared.FixedPoint; | ||
|
||
namespace Content.Shared._Stalker.Weapons.Ranged; | ||
|
||
[ByRefEvent] | ||
public record struct GetDamageFalloffEvent( | ||
FixedPoint2 FalloffMultiplier | ||
); |
8 changes: 8 additions & 0 deletions
8
Content.Shared/_Stalker/Weapons/Ranged/GetWeaponAccuracyEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Content.Shared.FixedPoint; | ||
|
||
namespace Content.Shared._Stalker.Weapons.Ranged; | ||
|
||
[ByRefEvent] | ||
public record struct GetWeaponAccuracyEvent( | ||
FixedPoint2 AccuracyMultiplier | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Content.Shared._Stalker.Projectiles; | ||
using Content.Shared.Examine; | ||
using Content.Shared.FixedPoint; | ||
using Content.Shared.Weapons.Ranged.Components; | ||
using Content.Shared.Weapons.Ranged.Events; | ||
using Content.Shared.Wieldable.Components; | ||
|
||
namespace Content.Shared._Stalker.Weapons.Ranged; | ||
|
||
public sealed class STGunSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly STProjectileSystem _stProjectileSystem = default!; | ||
|
||
private const string AccuracyExamineColour = "yellow"; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<STWeaponDamageFalloffComponent, AmmoShotEvent>(OnWeaponDamageFalloffShot); | ||
SubscribeLocalEvent<STWeaponDamageFalloffComponent, GunRefreshModifiersEvent>(OnWeaponDamageFalloffRefreshModifiers); | ||
|
||
SubscribeLocalEvent<STWeaponAccuracyComponent, ExaminedEvent>(OnWeaponAccuracyExamined); | ||
SubscribeLocalEvent<STWeaponAccuracyComponent, GunRefreshModifiersEvent>(OnWeaponAccuracyRefreshModifiers); | ||
SubscribeLocalEvent<STWeaponAccuracyComponent, AmmoShotEvent>(OnWeaponAccuracyShot); | ||
} | ||
|
||
private void OnWeaponDamageFalloffRefreshModifiers(Entity<STWeaponDamageFalloffComponent> weapon, ref GunRefreshModifiersEvent args) | ||
{ | ||
var ev = new GetDamageFalloffEvent(weapon.Comp.FalloffMultiplier); | ||
RaiseLocalEvent(weapon.Owner, ref ev); | ||
|
||
weapon.Comp.ModifiedFalloffMultiplier = FixedPoint2.Max(ev.FalloffMultiplier, 0); | ||
|
||
Dirty(weapon); | ||
} | ||
|
||
private void OnWeaponDamageFalloffShot(Entity<STWeaponDamageFalloffComponent> weapon, ref AmmoShotEvent args) | ||
{ | ||
foreach (var projectile in args.FiredProjectiles) | ||
{ | ||
if (!TryComp(projectile, out STProjectileDamageFalloffComponent? falloffComponent)) | ||
continue; | ||
|
||
_stProjectileSystem.SetProjectileFalloffWeaponMult((projectile, falloffComponent), weapon.Comp.ModifiedFalloffMultiplier); | ||
} | ||
} | ||
|
||
private void OnWeaponAccuracyExamined(Entity<STWeaponAccuracyComponent> weapon, ref ExaminedEvent args) | ||
{ | ||
if (!HasComp<GunComponent>(weapon.Owner)) | ||
return; | ||
|
||
using (args.PushGroup(nameof(STWeaponAccuracyComponent))) | ||
{ | ||
args.PushMarkup(Loc.GetString("st-examine-text-weapon-accuracy", ("colour", AccuracyExamineColour), ("accuracy", weapon.Comp.ModifiedAccuracyMultiplier))); | ||
} | ||
} | ||
|
||
private void OnWeaponAccuracyRefreshModifiers(Entity<STWeaponAccuracyComponent> weapon, ref GunRefreshModifiersEvent args) | ||
{ | ||
var baseMult = weapon.Comp.AccuracyMultiplierUnwielded; | ||
|
||
if (TryComp(weapon.Owner, out WieldableComponent? wieldableComponent) && wieldableComponent.Wielded) | ||
baseMult = weapon.Comp.AccuracyMultiplier; | ||
|
||
var ev = new GetWeaponAccuracyEvent(baseMult); | ||
RaiseLocalEvent(weapon.Owner, ref ev); | ||
|
||
weapon.Comp.ModifiedAccuracyMultiplier = Math.Max(0.1, (double) ev.AccuracyMultiplier); | ||
|
||
Dirty(weapon); | ||
} | ||
|
||
private void OnWeaponAccuracyShot(Entity<STWeaponAccuracyComponent> weapon, ref AmmoShotEvent args) | ||
{ | ||
var netId = GetNetEntity(weapon.Owner).Id; | ||
FixedPoint2 orderAccuracy = 0; | ||
FixedPoint2 orderAccuracyPerTile = 0; | ||
|
||
for (int t = 0; t < args.FiredProjectiles.Count; ++t) | ||
{ | ||
if (!TryComp(args.FiredProjectiles[t], out STProjectileAccuracyComponent? accuracyComponent)) | ||
continue; | ||
|
||
accuracyComponent.Accuracy *= weapon.Comp.ModifiedAccuracyMultiplier; | ||
accuracyComponent.Accuracy += orderAccuracy; | ||
|
||
if (orderAccuracyPerTile != 0) | ||
accuracyComponent.Thresholds.Add(new AccuracyFalloffThreshold(0f, -orderAccuracyPerTile, false)); | ||
|
||
accuracyComponent.GunSeed = (long) t << 32 | netId; | ||
Dirty<STProjectileAccuracyComponent>((args.FiredProjectiles[t], accuracyComponent)); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Shared/_Stalker/Weapons/Ranged/STWeaponAccuracyComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._Stalker.Weapons.Ranged; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STGunSystem))] | ||
public sealed partial class STWeaponAccuracyComponent : Component | ||
{ | ||
/// <summary> | ||
/// This is the base multiplier applied to all fired projectiles' accuracy scores when the weapon is wielded. | ||
/// Conversion from 13: accuracy_mult | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 AccuracyMultiplier = 1; | ||
|
||
/// <summary> | ||
/// This is the base multiplier applied to all fired projectiles' accuracy scores when the weapon is not wielded. | ||
/// Conversion from 13: accuracy_mult_unwielded | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 AccuracyMultiplierUnwielded = 1; | ||
|
||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 ModifiedAccuracyMultiplier = 1; | ||
} |
19 changes: 19 additions & 0 deletions
19
Content.Shared/_Stalker/Weapons/Ranged/STWeaponDamageFalloffComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._Stalker.Weapons.Ranged; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(STGunSystem))] | ||
public sealed partial class STWeaponDamageFalloffComponent : Component | ||
{ | ||
/// <summary> | ||
/// This is the baase multiplier applied the all fired projectiles' falloff. | ||
/// Conversion from 13: damage_falloff_mult | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 FalloffMultiplier = 1; | ||
|
||
[DataField, AutoNetworkedField] | ||
public FixedPoint2 ModifiedFalloffMultiplier = 1; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разъеби лопатой эту хуйню, тут нормально бы смотрелись флоаты