var curRot = _transform.GetWorldRotation(xform);
+ // 4-dir handling is separate --
+ // only raise event if the cardinal direction has changed
+ if (rotator.Simple4DirMode)
+ {
+ var angleDir = angle.GetCardinalDir();
+ if (angleDir == curRot.GetCardinalDir())
+ return;
+
+ RaisePredictiveEvent(new RequestMouseRotatorRotationSimpleEvent()
+ {
+ Direction = angleDir,
+ });
+
+ return;
+ }
+
// Don't raise event if mouse ~hasn't moved (or if too close to goal rotation already)
var diff = Angle.ShortestDistance(angle, curRot);
if (Math.Abs(diff.Theta) < rotator.AngleTolerance.Theta)
+using Content.Shared.MouseRotator;
+using Content.Shared.Movement.Components;
using Content.Shared.Targeting;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
[ViewVariables(VVAccess.ReadWrite), DataField("isInCombatMode"), AutoNetworkedField]
public bool IsInCombatMode;
+ /// <summary>
+ /// Will add <see cref="MouseRotatorComponent"/> and <see cref="NoRotateOnMoveComponent"/>
+ /// to entities with this flag enabled that enter combat mode, and vice versa for removal.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public bool ToggleMouseRotator = true;
+
[ViewVariables(VVAccess.ReadWrite), DataField("activeZone"), AutoNetworkedField]
public TargetingZone ActiveZone;
}
using Content.Shared.Actions;
+using Content.Shared.MouseRotator;
+using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Content.Shared.Targeting;
using Robust.Shared.Network;
private void OnShutdown(EntityUid uid, CombatModeComponent component, ComponentShutdown args)
{
_actionsSystem.RemoveAction(uid, component.CombatToggleActionEntity);
+
+ SetMouseRotatorComponents(uid, false);
}
private void OnActionPerform(EntityUid uid, CombatModeComponent component, ToggleCombatActionEvent args)
if (component.CombatToggleActionEntity != null)
_actionsSystem.SetToggled(component.CombatToggleActionEntity, component.IsInCombatMode);
+
+ // Change mouse rotator comps if flag is set
+ if (!component.ToggleMouseRotator)
+ return;
+
+ SetMouseRotatorComponents(entity, value);
}
public virtual void SetActiveZone(EntityUid entity, TargetingZone zone,
component.ActiveZone = zone;
}
+
+ private void SetMouseRotatorComponents(EntityUid uid, bool value)
+ {
+ if (value)
+ {
+ EnsureComp<MouseRotatorComponent>(uid);
+ EnsureComp<NoRotateOnMoveComponent>(uid);
+ }
+ else
+ {
+ RemComp<MouseRotatorComponent>(uid);
+ RemComp<NoRotateOnMoveComponent>(uid);
+ }
+ }
}
public sealed partial class ToggleCombatActionEvent : InstantActionEvent { }
/// <summary>
/// How much the desired angle needs to change before a predictive event is sent
/// </summary>
- [DataField]
- [ViewVariables(VVAccess.ReadWrite)]
- public Angle AngleTolerance = Angle.FromDegrees(5.0);
+ [DataField, AutoNetworkedField]
+ public Angle AngleTolerance = Angle.FromDegrees(20.0);
/// <summary>
/// The angle that will be lerped to
/// </summary>
- [AutoNetworkedField, DataField]
+ [DataField, AutoNetworkedField]
public Angle? GoalRotation;
/// <summary>
/// Max degrees the entity can rotate per second
/// </summary>
- [DataField]
- [ViewVariables(VVAccess.ReadWrite)]
+ [DataField, AutoNetworkedField]
public double RotationSpeed = float.MaxValue;
+
+ /// <summary>
+ /// This one is important. If this is true, <see cref="AngleTolerance"/> does not apply, and the system will
+ /// use <see cref="RequestMouseRotatorRotationSimpleEvent"/> instead. In this mode, the client will only send
+ /// events when an entity should snap to a different cardinal direction, rather than for every angle change.
+ ///
+ /// This is useful for cases like humans, where what really matters is the visual sprite direction, as opposed to something
+ /// like turrets or ship guns, which have finer range of movement.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public bool Simple4DirMode = true;
}
/// <summary>
{
public Angle Rotation;
}
+
+/// <summary>
+/// Simpler version of <see cref="RequestMouseRotatorRotationEvent"/> for implementations
+/// that only require snapping to 4-dir and not full angle rotation.
+/// </summary>
+[Serializable, NetSerializable]
+public sealed class RequestMouseRotatorRotationSimpleEvent : EntityEventArgs
+{
+ public Direction Direction;
+}
base.Initialize();
SubscribeAllEvent<RequestMouseRotatorRotationEvent>(OnRequestRotation);
+ SubscribeAllEvent<RequestMouseRotatorRotationSimpleEvent>(OnRequestSimpleRotation);
}
public override void Update(float frameTime)
private void OnRequestRotation(RequestMouseRotatorRotationEvent msg, EntitySessionEventArgs args)
{
- if (args.SenderSession.AttachedEntity is not { } ent || !TryComp<MouseRotatorComponent>(ent, out var rotator))
+ if (args.SenderSession.AttachedEntity is not { } ent
+ || !TryComp<MouseRotatorComponent>(ent, out var rotator) || rotator.Simple4DirMode)
{
- Log.Error($"User {args.SenderSession.Name} ({args.SenderSession.UserId}) tried setting local rotation without a mouse rotator component attached!");
+ Log.Error($"User {args.SenderSession.Name} ({args.SenderSession.UserId}) tried setting local rotation directly without a valid mouse rotator component attached!");
return;
}
rotator.GoalRotation = msg.Rotation;
Dirty(ent, rotator);
}
+
+ private void OnRequestSimpleRotation(RequestMouseRotatorRotationSimpleEvent ev, EntitySessionEventArgs args)
+ {
+ if (args.SenderSession.AttachedEntity is not { } ent
+ || !TryComp<MouseRotatorComponent>(ent, out var rotator) || !rotator.Simple4DirMode)
+ {
+ Log.Error($"User {args.SenderSession.Name} ({args.SenderSession.UserId}) tried setting 4-dir rotation directly without a valid mouse rotator component attached!");
+ return;
+ }
+
+ rotator.GoalRotation = ev.Direction.ToAngle();
+ Dirty(ent, rotator);
+ }
}
interactSuccessSound:
path: /Audio/Effects/double_beep.ogg
- type: CombatMode
+ toggleMouseRotator: false
- type: Damageable
damageContainer: Inorganic
- type: Destructible
SoundTargetInLOS: !type:SoundPathSpecifier
path: /Audio/Effects/double_beep.ogg
- type: MouseRotator
+ angleTolerance: 5
rotationSpeed: 180
+ simple4DirMode: false
- type: NoRotateOnInteract
- type: NoRotateOnMove
- type: Input