-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port] Энергетический Меч / Energy Sword (#6)
* add: Flip on hit system * WD EDIT * fix: animation * fix: sound * fix: sound * Revert "fix: sound" This reverts commit 64a1286. * fix: sound
- Loading branch information
Showing
12 changed files
with
298 additions
and
130 deletions.
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,75 @@ | ||
using Content.Shared._White.Animations; | ||
using Robust.Client.Animations; | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.Animations; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Client._White.Animations; | ||
|
||
public sealed class FlipOnHitSystem : SharedFlipOnHitSystem | ||
{ | ||
[Dependency] private readonly AnimationPlayerSystem _animationSystem = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<FlippingComponent, AnimationCompletedEvent>(OnAnimationComplete); | ||
SubscribeAllEvent<FlipOnHitEvent>(ev => PlayAnimation(GetEntity(ev.User))); | ||
} | ||
|
||
private void OnAnimationComplete(Entity<FlippingComponent> ent, ref AnimationCompletedEvent args) | ||
{ | ||
if (args.Key != FlippingComponent.AnimationKey) | ||
return; | ||
|
||
PlayAnimation(ent); | ||
} | ||
|
||
protected override void PlayAnimation(EntityUid user) | ||
{ | ||
if (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
if (TerminatingOrDeleted(user)) | ||
return; | ||
|
||
if (_animationSystem.HasRunningAnimation(user, FlippingComponent.AnimationKey)) | ||
{ | ||
EnsureComp<FlippingComponent>(user); | ||
return; | ||
} | ||
|
||
RemComp<FlippingComponent>(user); | ||
|
||
var baseAngle = Angle.Zero; | ||
if (EntityManager.TryGetComponent(user, out SpriteComponent? sprite)) | ||
baseAngle = sprite.Rotation; | ||
|
||
var degrees = baseAngle.Degrees; | ||
|
||
var animation = new Animation | ||
{ | ||
Length = TimeSpan.FromMilliseconds(400), | ||
AnimationTracks = | ||
{ | ||
new AnimationTrackComponentProperty | ||
{ | ||
ComponentType = typeof(SpriteComponent), | ||
Property = nameof(SpriteComponent.Rotation), | ||
InterpolationMode = AnimationInterpolationMode.Linear, | ||
KeyFrames = | ||
{ | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees - 10), 0f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 180), 0.2f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 360), 0.2f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees), 0f) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
_animationSystem.Play(user, animation, FlippingComponent.AnimationKey); | ||
} | ||
} |
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 @@ | ||
namespace Content.Client._White.Animations; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FlippingComponent : Component | ||
{ | ||
public const string AnimationKey = "flip"; | ||
} |
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
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,17 @@ | ||
using Content.Shared._White.Animations; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Server._White.Animations; | ||
|
||
public sealed class FlipOnHitSystem : SharedFlipOnHitSystem | ||
{ | ||
protected override void PlayAnimation(EntityUid user) | ||
{ | ||
var filter = Filter.Pvs(user, entityManager: EntityManager); | ||
|
||
if (TryComp<ActorComponent>(user, out var actor)) | ||
filter.RemovePlayer(actor.PlayerSession); | ||
|
||
RaiseNetworkEvent(new FlipOnHitEvent(GetNetEntity(user)), filter); | ||
} | ||
} |
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
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,6 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._White.Animations; | ||
|
||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class FlipOnHitComponent : Component; |
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,45 @@ | ||
using Content.Shared.Item.ItemToggle.Components; | ||
using Content.Shared.Standing; | ||
using Content.Shared.Weapons.Melee.Events; | ||
using Robust.Shared.Serialization; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Shared._White.Animations; | ||
|
||
public abstract class SharedFlipOnHitSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly StandingStateSystem _standingState = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<FlipOnHitComponent, MeleeHitEvent>(OnHit); | ||
} | ||
|
||
private void OnHit(Entity<FlipOnHitComponent> ent, ref MeleeHitEvent args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
if (args.HitEntities.Count == 0) | ||
return; | ||
|
||
if (TryComp(ent, out ItemToggleComponent? itemToggle) && !itemToggle.Activated) | ||
return; | ||
|
||
if (_standingState.IsDown(args.User)) | ||
return; | ||
|
||
PlayAnimation(args.User); | ||
} | ||
|
||
protected abstract void PlayAnimation(EntityUid user); | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class FlipOnHitEvent(NetEntity user) : EntityEventArgs | ||
{ | ||
public NetEntity User = user; | ||
} |
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,4 @@ | ||
namespace Content.Shared._White.Wield; | ||
|
||
[RegisterComponent] | ||
public sealed partial class ToggleableWieldedComponent : Component; |
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,20 @@ | ||
using Content.Shared.Item.ItemToggle.Components; | ||
using Content.Shared.Wieldable.Components; | ||
|
||
namespace Content.Shared._White.Wield; | ||
|
||
public sealed class ToggleableWieldedSystem : EntitySystem | ||
{ | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<ToggleableWieldedComponent, ItemToggleActivateAttemptEvent>(AttemptActivate); | ||
} | ||
|
||
private void AttemptActivate(Entity<ToggleableWieldedComponent> ent, ref ItemToggleActivateAttemptEvent args) | ||
{ | ||
if (TryComp(ent, out WieldableComponent? wieldable) && !wieldable.Wielded) | ||
args.Cancelled = true; | ||
} | ||
} |
Oops, something went wrong.