Фикс логики системы отражения (#682)
* Fixed ReflectSystem + Added logic for reflective items positioning * Total oppsie fix * Born to shitcode
This commit is contained in:
@@ -216,7 +216,7 @@ public abstract class SharedItemToggleSystem : EntitySystem
|
|||||||
private void TurnOnonWielded(EntityUid uid, ItemToggleComponent itemToggle, ref ItemWieldedEvent args)
|
private void TurnOnonWielded(EntityUid uid, ItemToggleComponent itemToggle, ref ItemWieldedEvent args)
|
||||||
{
|
{
|
||||||
if (!itemToggle.Activated)
|
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)
|
public bool IsActivated(EntityUid uid, ItemToggleComponent? comp = null)
|
||||||
|
|||||||
@@ -39,6 +39,22 @@ public sealed partial class ReflectComponent : Component
|
|||||||
[DataField]
|
[DataField]
|
||||||
public bool Innate = false;
|
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>
|
/// <summary>
|
||||||
/// Maximum probability for a projectile to be reflected.
|
/// Maximum probability for a projectile to be reflected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -71,3 +87,11 @@ public enum ReflectType : byte
|
|||||||
NonEnergy = 1 << 0,
|
NonEnergy = 1 << 0,
|
||||||
Energy = 1 << 1,
|
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 (
|
if (
|
||||||
!Resolve(reflector, ref reflect, false) ||
|
!Resolve(reflector, ref reflect, false) ||
|
||||||
!reflect.Enabled ||
|
!reflect.Enabled ||
|
||||||
|
!reflect.InRightPlace || // WD
|
||||||
!TryComp<ReflectiveComponent>(projectile, out var reflective) ||
|
!TryComp<ReflectiveComponent>(projectile, out var reflective) ||
|
||||||
(reflect.Reflects & reflective.Reflective) == 0x0 ||
|
(reflect.Reflects & reflective.Reflective) == 0x0 ||
|
||||||
!TryComp<PhysicsComponent>(projectile, out var physics) ||
|
!TryComp<PhysicsComponent>(projectile, out var physics) ||
|
||||||
@@ -210,6 +211,7 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (!TryComp<ReflectComponent>(reflector, out var reflect) ||
|
if (!TryComp<ReflectComponent>(reflector, out var reflect) ||
|
||||||
!reflect.Enabled ||
|
!reflect.Enabled ||
|
||||||
|
!reflect.InRightPlace || // WD
|
||||||
TryComp<StaminaComponent>(reflector, out var staminaComponent) && staminaComponent.Critical ||
|
TryComp<StaminaComponent>(reflector, out var staminaComponent) && staminaComponent.Critical ||
|
||||||
_standing.IsDown(reflector))
|
_standing.IsDown(reflector))
|
||||||
{
|
{
|
||||||
@@ -246,7 +248,9 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(args.Equipee);
|
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);
|
EnableAlert(args.Equipee);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +266,9 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(args.User);
|
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);
|
EnableAlert(args.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,10 +282,18 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
comp.Enabled = args.Activated;
|
comp.Enabled = args.Activated;
|
||||||
Dirty(uid, comp);
|
Dirty(uid, comp);
|
||||||
|
|
||||||
if (comp.Enabled)
|
// WD edit start
|
||||||
EnableAlert(uid);
|
// Reason for the edit: previously EnableAlert and DisableAlert were given an "EntityUid uid" which
|
||||||
else
|
// belongs to an item, not to the item user. Now its logic corrected and moved to "RefreshReflectUser()".
|
||||||
DisableAlert(uid);
|
// if (comp.Enabled)
|
||||||
|
// EnableAlert(uid);
|
||||||
|
// else
|
||||||
|
// DisableAlert(uid);
|
||||||
|
if (args.User != null)
|
||||||
|
{
|
||||||
|
RefreshReflectUser((EntityUid) args.User);
|
||||||
|
}
|
||||||
|
// WD edit end
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -293,7 +307,19 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(user);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@@ -311,4 +337,15 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
_alerts.ClearAlert(alertee, AlertType.Deflecting);
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,23 @@ namespace Content.Shared.Wieldable;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed on an entity when it is wielded.
|
/// Raised directed on an entity when it is wielded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
// WD edit start
|
||||||
public readonly record struct ItemWieldedEvent;
|
// 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
|
||||||
|
|||||||
@@ -226,8 +226,8 @@ public sealed class WieldableSystem : EntitySystem
|
|||||||
var othersMessage = Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used));
|
var othersMessage = Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used));
|
||||||
_popupSystem.PopupPredicted(selfMessage, othersMessage, user, user);
|
_popupSystem.PopupPredicted(selfMessage, othersMessage, user, user);
|
||||||
|
|
||||||
var targEv = new ItemWieldedEvent();
|
var targEv = new ItemWieldedEvent(user); // WD added user
|
||||||
RaiseLocalEvent(used, ref targEv);
|
RaiseLocalEvent(used, targEv); // WD removed ref from targEv
|
||||||
|
|
||||||
Dirty(used, component);
|
Dirty(used, component);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -108,6 +108,8 @@
|
|||||||
- type: Reflect
|
- type: Reflect
|
||||||
reflectProb: 1
|
reflectProb: 1
|
||||||
innate: true # armor grants a passive shield that does not require concentration to maintain
|
innate: true # armor grants a passive shield that does not require concentration to maintain
|
||||||
|
placement: # WD
|
||||||
|
- Body
|
||||||
reflects:
|
reflects:
|
||||||
- Energy
|
- Energy
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@
|
|||||||
reflectProb: 0.3
|
reflectProb: 0.3
|
||||||
velocityBeforeNotMaxProb: 6.0 # don't punish ninjas for being ninjas
|
velocityBeforeNotMaxProb: 6.0 # don't punish ninjas for being ninjas
|
||||||
velocityBeforeMinProb: 10.0
|
velocityBeforeMinProb: 10.0
|
||||||
|
placement: # WD
|
||||||
|
- Hands
|
||||||
- type: MeleeBlock
|
- type: MeleeBlock
|
||||||
delay: 6.1
|
delay: 6.1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user