Фикс логики системы отражения (#682)
* Fixed ReflectSystem + Added logic for reflective items positioning * Total oppsie fix * Born to shitcode
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user