Better click attack effect

This commit is contained in:
Víctor Aguilera Puerto
2020-08-31 19:32:06 +02:00
parent 69bd44c94c
commit b927fddf4c
4 changed files with 17 additions and 55 deletions

View File

@@ -21,8 +21,7 @@ namespace Content.Client.GameObjects.EntitySystems
public override void Initialize()
{
SubscribeNetworkEvent<PlayMeleeWeaponArcAnimationMessage>(PlayWeaponArc);
SubscribeNetworkEvent<PlayMeleeWeaponAnimationMessage>(PlayWeapon);
SubscribeNetworkEvent<PlayMeleeWeaponAnimationMessage>(PlayWeaponArc);
}
public override void FrameUpdate(float frameTime)
@@ -35,7 +34,7 @@ namespace Content.Client.GameObjects.EntitySystems
}
}
private void PlayWeaponArc(PlayMeleeWeaponArcAnimationMessage msg)
private void PlayWeaponArc(PlayMeleeWeaponAnimationMessage msg)
{
if (!_prototypeManager.TryIndex(msg.ArcPrototype, out MeleeWeaponAnimationPrototype weaponArc))
{
@@ -81,32 +80,5 @@ namespace Content.Client.GameObjects.EntitySystems
});
}
}
private void PlayWeapon(PlayMeleeWeaponAnimationMessage msg)
{
var attacker = EntityManager.GetEntity(msg.Attacker);
var lunge = attacker.EnsureComponent<MeleeLungeComponent>();
lunge.SetData(msg.Angle);
if (!EntityManager.TryGetEntity(msg.Hit, out var hitEntity)
|| !hitEntity.TryGetComponent(out ISpriteComponent sprite))
{
return;
}
var originalColor = sprite.Color;
var newColor = Color.Red * originalColor;
sprite.Color = newColor;
Timer.Spawn(100, () =>
{
// Only reset back to the original color if something else didn't change the color in the mean time.
if (sprite.Color == newColor)
{
sprite.Color = originalColor;
}
});
}
}
}

View File

@@ -36,6 +36,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
public float ArcCooldownTime { get; private set; } = 1f;
public float CooldownTime { get; private set; } = 0.5f;
[ViewVariables(VVAccess.ReadWrite)]
public string ClickArc { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public string Arc { get; set; }
@@ -59,6 +62,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
serializer.DataField(this, x => x.Range, "range", 1);
serializer.DataField(this, x => x.ArcWidth, "arcwidth", 90);
serializer.DataField(this, x => x.Arc, "arc", "default");
serializer.DataField(this, x => x.ClickArc, "clickArc", "punch");
serializer.DataField(this, x => x._hitSound, "hitSound", "/Audio/Weapons/genhit1.ogg");
serializer.DataField(this, x => x._missSound, "hitSound", "/Audio/Weapons/punchmiss.ogg");
serializer.DataField(this, x => x.ArcCooldownTime, "arcCooldownTime", 1f);
@@ -159,11 +163,16 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
damageComponent.ChangeDamage(DamageType, Damage, false, Owner);
}
if (!OnHitEntities(new[] {target}, eventArgs))
var targets = new[] {target};
if (!OnHitEntities(targets, eventArgs))
return true;
var sys = _entitySystemManager.GetEntitySystem<MeleeWeaponSystem>();
sys.SendAnimation(angle, eventArgs.User, target);
if (ClickArc != null)
{
var sys = _entitySystemManager.GetEntitySystem<MeleeWeaponSystem>();
sys.SendAnimation(ClickArc, angle, eventArgs.User, targets);
}
_lastAttackTime = curTime;
_cooldownEnd = _lastAttackTime + TimeSpan.FromSeconds(CooldownTime);

View File

@@ -11,13 +11,8 @@ namespace Content.Server.GameObjects.EntitySystems
{
public void SendAnimation(string arc, Angle angle, IEntity attacker, IEnumerable<IEntity> hits)
{
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponArcAnimationMessage(arc, angle, attacker.Uid,
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponAnimationMessage(arc, angle, attacker.Uid,
hits.Select(e => e.Uid).ToList()));
}
public void SendAnimation(Angle angle, IEntity attacker, IEntity hit)
{
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponAnimationMessage(angle, attacker.Uid, hit.Uid));
}
}
}

View File

@@ -9,9 +9,9 @@ namespace Content.Shared.GameObjects.EntitySystemMessages
public static class MeleeWeaponSystemMessages
{
[Serializable, NetSerializable]
public sealed class PlayMeleeWeaponArcAnimationMessage : EntitySystemMessage
public sealed class PlayMeleeWeaponAnimationMessage : EntitySystemMessage
{
public PlayMeleeWeaponArcAnimationMessage(string arcPrototype, Angle angle, EntityUid attacker, List<EntityUid> hits)
public PlayMeleeWeaponAnimationMessage(string arcPrototype, Angle angle, EntityUid attacker, List<EntityUid> hits)
{
ArcPrototype = arcPrototype;
Angle = angle;
@@ -24,19 +24,5 @@ namespace Content.Shared.GameObjects.EntitySystemMessages
public EntityUid Attacker { get; }
public List<EntityUid> Hits { get; }
}
[Serializable, NetSerializable]
public sealed class PlayMeleeWeaponAnimationMessage : EntitySystemMessage
{
public PlayMeleeWeaponAnimationMessage(Angle angle, EntityUid attacker, EntityUid hit)
{
Attacker = attacker;
Hit = hit;
}
public Angle Angle { get; }
public EntityUid Attacker { get; }
public EntityUid Hit { get; }
}
}
}