Фикс логики системы отражения (#682)

* Fixed ReflectSystem + Added logic for reflective items positioning

* Total oppsie fix

* Born to shitcode
This commit is contained in:
BIGZi0348
2024-09-03 21:14:42 +03:00
committed by GitHub
parent 6853e5b44f
commit 79acb6f9ee
7 changed files with 95 additions and 12 deletions

View File

@@ -216,7 +216,7 @@ public abstract class SharedItemToggleSystem : EntitySystem
private void TurnOnonWielded(EntityUid uid, ItemToggleComponent itemToggle, ref ItemWieldedEvent args)
{
if (!itemToggle.Activated)
TryActivate(uid, itemToggle: itemToggle);
TryActivate(uid, args.User, itemToggle: itemToggle); // WD added "args.User" parameter
}
public bool IsActivated(EntityUid uid, ItemToggleComponent? comp = null)

View File

@@ -39,6 +39,22 @@ public sealed partial class ReflectComponent : Component
[DataField]
public bool Innate = false;
// WD START
/// <summary>
/// If the item for reflection needed in inventory slots only - select Body.
/// If the item for reflection needed in hands only - select Hands.
/// Otherwise it will reflect in any inventory position.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public Placement Placement = Placement.Hands | Placement.Body;
/// <summary>
/// Can only reflect when placed correctly.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool InRightPlace = true;
// WD END
/// <summary>
/// Maximum probability for a projectile to be reflected.
/// </summary>
@@ -71,3 +87,11 @@ public enum ReflectType : byte
NonEnergy = 1 << 0,
Energy = 1 << 1,
}
[Flags]
public enum Placement : byte
{
None = 0,
Hands = 1 << 0,
Body = 1 << 1,
}

View File

@@ -103,6 +103,7 @@ public sealed class ReflectSystem : EntitySystem
if (
!Resolve(reflector, ref reflect, false) ||
!reflect.Enabled ||
!reflect.InRightPlace || // WD
!TryComp<ReflectiveComponent>(projectile, out var reflective) ||
(reflect.Reflects & reflective.Reflective) == 0x0 ||
!TryComp<PhysicsComponent>(projectile, out var physics) ||
@@ -210,6 +211,7 @@ public sealed class ReflectSystem : EntitySystem
{
if (!TryComp<ReflectComponent>(reflector, out var reflect) ||
!reflect.Enabled ||
!reflect.InRightPlace || // WD
TryComp<StaminaComponent>(reflector, out var staminaComponent) && staminaComponent.Critical ||
_standing.IsDown(reflector))
{
@@ -246,7 +248,9 @@ public sealed class ReflectSystem : EntitySystem
EnsureComp<ReflectUserComponent>(args.Equipee);
if (component.Enabled)
component.InRightPlace = IsInRightPlace(component, Placement.Body); // WD
if (component.Enabled && component.InRightPlace) // WD added component.InRightPlace
EnableAlert(args.Equipee);
}
@@ -262,7 +266,9 @@ public sealed class ReflectSystem : EntitySystem
EnsureComp<ReflectUserComponent>(args.User);
if (component.Enabled)
component.InRightPlace = IsInRightPlace(component, Placement.Hands); // WD
if (component.Enabled && component.InRightPlace) // WD added component.InRightPlace
EnableAlert(args.User);
}
@@ -276,10 +282,18 @@ public sealed class ReflectSystem : EntitySystem
comp.Enabled = args.Activated;
Dirty(uid, comp);
if (comp.Enabled)
EnableAlert(uid);
else
DisableAlert(uid);
// WD edit start
// Reason for the edit: previously EnableAlert and DisableAlert were given an "EntityUid uid" which
// belongs to an item, not to the item user. Now its logic corrected and moved to "RefreshReflectUser()".
// if (comp.Enabled)
// EnableAlert(uid);
// else
// DisableAlert(uid);
if (args.User != null)
{
RefreshReflectUser((EntityUid) args.User);
}
// WD edit end
}
/// <summary>
@@ -293,7 +307,19 @@ public sealed class ReflectSystem : EntitySystem
continue;
EnsureComp<ReflectUserComponent>(user);
EnableAlert(user);
// WD edit start
// Reason for the edit: to ensure correct display of alert.
if (!TryComp<ReflectComponent>(ent, out var component))
continue;
if (component.Enabled && component.InRightPlace)
EnableAlert(user);
else
{
DisableAlert(user);
continue;
}
// WD edit end
return;
}
@@ -311,4 +337,15 @@ public sealed class ReflectSystem : EntitySystem
{
_alerts.ClearAlert(alertee, AlertType.Deflecting);
}
/// <summary>
/// Selfdescribing.
/// </summary>
private static bool IsInRightPlace(ReflectComponent component, Placement placement) // WD
{
if (component.Placement == (Placement.Hands | Placement.Body))
return true;
else
return (component.Placement & placement) != 0x0;
}
}

View File

@@ -3,5 +3,23 @@ namespace Content.Shared.Wieldable;
/// <summary>
/// Raised directed on an entity when it is wielded.
/// </summary>
[ByRefEvent]
public readonly record struct ItemWieldedEvent;
// WD edit start
// Reason for the edit: previously ItemWieldedEvent didn't contained "EntityUid user" parameter.
// Now it's done like ItemUnwieldedEvent with "EntityUid user" parameter for correct logic work.
// [ByRefEvent]
// public readonly record struct ItemWieldedEvent;
public sealed class ItemWieldedEvent : EntityEventArgs
{
public EntityUid? User;
/// <summary>
/// Whether the item is being forced to be wielded, or if the player chose to wield it themselves.
/// </summary>
public bool Force;
public ItemWieldedEvent(EntityUid? user = null, bool force = false)
{
User = user;
Force = force;
}
}
// WD edit end

View File

@@ -226,8 +226,8 @@ public sealed class WieldableSystem : EntitySystem
var othersMessage = Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used));
_popupSystem.PopupPredicted(selfMessage, othersMessage, user, user);
var targEv = new ItemWieldedEvent();
RaiseLocalEvent(used, ref targEv);
var targEv = new ItemWieldedEvent(user); // WD added user
RaiseLocalEvent(used, targEv); // WD removed ref from targEv
Dirty(used, component);
return true;

View File

@@ -108,6 +108,8 @@
- type: Reflect
reflectProb: 1
innate: true # armor grants a passive shield that does not require concentration to maintain
placement: # WD
- Body
reflects:
- Energy

View File

@@ -101,6 +101,8 @@
reflectProb: 0.3
velocityBeforeNotMaxProb: 6.0 # don't punish ninjas for being ninjas
velocityBeforeMinProb: 10.0
placement: # WD
- Hands
- type: MeleeBlock
delay: 6.1