From 9e6b86c5ad756c404198c9a4516092bd363485f7 Mon Sep 17 00:00:00 2001 From: Aviu00 <93730715+Aviu00@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:23:51 +0000 Subject: [PATCH] Magic fix (#404) * - tweak: Hfrequency blade. * - fix: Magic fixes. --- .../Systems/Actions/ChargeActionSystem.cs | 31 ++++++++- Content.Server/Magic/MagicSystem.cs | 7 +- .../_White/Wizard/Charging/ChargingSystem.cs | 64 ++++++++++-------- .../_White/Wizard/Magic/WizardSpellsSystem.cs | 65 +++++++++---------- .../Wizard/Teleport/WizardTeleportSpellEui.cs | 8 ++- .../Prototypes/_White/Wizard/magic_items.yml | 7 +- 6 files changed, 108 insertions(+), 74 deletions(-) diff --git a/Content.Client/UserInterface/Systems/Actions/ChargeActionSystem.cs b/Content.Client/UserInterface/Systems/Actions/ChargeActionSystem.cs index 69660882a6..29a00acff3 100644 --- a/Content.Client/UserInterface/Systems/Actions/ChargeActionSystem.cs +++ b/Content.Client/UserInterface/Systems/Actions/ChargeActionSystem.cs @@ -56,23 +56,39 @@ public sealed class ChargeActionSystem : SharedChargingSystem { base.Update(frameTime); - if (_playerManager.LocalEntity is not { } user) + if (!_timing.IsFirstTimePredicted) return; + if (_playerManager.LocalEntity is not { } user) + { + Reset(); + return; + } + if (!_mobState.IsAlive(user) || _statusEffects.HasStatusEffect(user, "Incorporeal")) + { + Reset(); return; + } - if (!_timing.IsFirstTimePredicted || _controller == null || _controller.SelectingTargetFor is not { } actionId) + if (_controller == null || _controller.SelectingTargetFor is not { } actionId) + { + Reset(); return; + } if (!_actionsSystem.TryGetActionData(actionId, out var baseAction) || baseAction is not BaseTargetActionComponent action || !action.IsChargeEnabled) + { + Reset(); return; + } if (!action.Enabled || action is { Charges: 0, RenewCharges: false } || action.Cooldown.HasValue && action.Cooldown.Value.End > _timing.CurTime) { + Reset(); return; } @@ -139,6 +155,17 @@ public sealed class ChargeActionSystem : SharedChargingSystem } } + private void Reset() + { + _charging = false; + _prevCharging = false; + _chargeTime = 0f; + _chargeLevel = 0; + _prevChargeLevel = 0; + _isChargingPlaying = false; + _isChargedPlaying = false; + } + private void HandleAction(EntityUid actionId, BaseTargetActionComponent action, EntityUid user, int chargeLevel) { var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition); diff --git a/Content.Server/Magic/MagicSystem.cs b/Content.Server/Magic/MagicSystem.cs index a512446826..8b4ce53231 100644 --- a/Content.Server/Magic/MagicSystem.cs +++ b/Content.Server/Magic/MagicSystem.cs @@ -164,8 +164,7 @@ public sealed class MagicSystem : EntitySystem if (!_wizardSpells.CanCast(args)) // WD EDIT return; - args.Handled = true; - Speak(args); + _wizardSpells.Cast(args); // WD EDIT var transform = Transform(args.Performer); var coords = transform.Coordinates; @@ -190,9 +189,7 @@ public sealed class MagicSystem : EntitySystem if (!_wizardSpells.CanCast(ev)) // WD EDIT return; - ev.Handled = true; - - Speak(ev); + _wizardSpells.Cast(ev); // WD EDIT var direction = _transformSystem.GetMapCoordinates(ev.Target).Position - _transformSystem.GetMapCoordinates(ev.Performer).Position; var impulseVector = direction * 10000; diff --git a/Content.Server/_White/Wizard/Charging/ChargingSystem.cs b/Content.Server/_White/Wizard/Charging/ChargingSystem.cs index f5e8f840fe..63b36002bc 100644 --- a/Content.Server/_White/Wizard/Charging/ChargingSystem.cs +++ b/Content.Server/_White/Wizard/Charging/ChargingSystem.cs @@ -1,6 +1,7 @@ using Content.Shared._White.Wizard; using Content.Shared._White.Wizard.Charging; using Content.Shared.Follower; +using Content.Shared.Mobs; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Player; @@ -25,10 +26,13 @@ public sealed class ChargingSystem : SharedChargingSystem SubscribeNetworkEvent(OnCharging); SubscribeNetworkEvent(OnCharged); SubscribeNetworkEvent(OnStop); + SubscribeLocalEvent(OnDetach); + SubscribeLocalEvent(OnStateChanged); SubscribeNetworkEvent(Add); SubscribeNetworkEvent(Remove); + } #region Audio @@ -103,40 +107,29 @@ public sealed class ChargingSystem : SharedChargingSystem if (user == null) return; - if (_chargingLoops.TryGetValue(user.Value, out var currentStream)) - { - _audio.Stop(currentStream); - _chargingLoops.Remove(user.Value); - } - - if (_chargedLoop.TryGetValue(user.Value, out var chargedLoop)) - { - _audio.Stop(chargedLoop); - _chargedLoop.Remove(user.Value); - } - } - - private void OnDetach(PlayerDetachedEvent msg, EntitySessionEventArgs args) - { - var user = msg.Entity; - - if (_chargingLoops.TryGetValue(user, out var currentStream)) - { - _audio.Stop(currentStream); - _chargingLoops.Remove(user); - } - - if (_chargedLoop.TryGetValue(user, out var chargedLoop)) - { - _audio.Stop(chargedLoop); - _chargedLoop.Remove(user); - } + StopAllSounds(user.Value); } #endregion #region Charges + private void OnDetach(PlayerDetachedEvent msg) + { + var user = msg.Entity; + + RemoveAllCharges(user); + StopAllSounds(user); + } + + private void OnStateChanged(MobStateChangedEvent ev) + { + var user = ev.Target; + + RemoveAllCharges(user); + StopAllSounds(user); + } + private void Add(AddWizardChargeEvent msg, EntitySessionEventArgs args) { if (args.SenderSession.AttachedEntity != null) @@ -153,6 +146,21 @@ public sealed class ChargingSystem : SharedChargingSystem #region Helpers + public void StopAllSounds(EntityUid uid) + { + if (_chargingLoops.TryGetValue(uid, out var currentStream)) + { + _audio.Stop(currentStream); + _chargingLoops.Remove(uid); + } + + if (_chargedLoop.TryGetValue(uid, out var chargedLoop)) + { + _audio.Stop(chargedLoop); + _chargedLoop.Remove(uid); + } + } + public void AddCharge(EntityUid uid, string msgChargeProto) { var itemEnt = Spawn(msgChargeProto, Transform(uid).Coordinates); diff --git a/Content.Server/_White/Wizard/Magic/WizardSpellsSystem.cs b/Content.Server/_White/Wizard/Magic/WizardSpellsSystem.cs index 3a43e05cf9..1599db00fd 100644 --- a/Content.Server/_White/Wizard/Magic/WizardSpellsSystem.cs +++ b/Content.Server/_White/Wizard/Magic/WizardSpellsSystem.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Numerics; using Content.Server._White.Cult; using Content.Server._White.IncorporealSystem; +using Content.Server._White.Wizard.Charging; using Content.Server._White.Wizard.Magic.Amaterasu; using Content.Server._White.Wizard.Magic.Other; using Content.Server._White.Wizard.Magic.TeslaProjectile; @@ -80,6 +81,7 @@ public sealed class WizardSpellsSystem : EntitySystem [Dependency] private readonly EuiManager _euiManager = default!; [Dependency] private readonly MindSystem _mindSystem = default!; [Dependency] private readonly ActionContainerSystem _actionContainer = default!; + [Dependency] private readonly ChargingSystem _charging = default!; #endregion @@ -125,7 +127,7 @@ public sealed class WizardSpellsSystem : EntitySystem return; } - msg.Handled = true; + Cast(msg); } #endregion @@ -143,8 +145,7 @@ public sealed class WizardSpellsSystem : EntitySystem var comp = EnsureComp(ent); comp.Uid = msg.Performer; - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -187,8 +188,7 @@ public sealed class WizardSpellsSystem : EntitySystem _standing.TryLieDown(uid); _standing.TryLieDown(target); - msg.Handled = true; - Speak(msg); + Cast(msg); SwapComponent(uid, target); SwapComponent(uid, target); @@ -213,8 +213,7 @@ public sealed class WizardSpellsSystem : EntitySystem _euiManager.OpenEui(eui, actor.PlayerSession); eui.StateDirty(); - msg.Handled = true; - Speak(msg); + Cast(msg, false); } #endregion @@ -264,8 +263,7 @@ public sealed class WizardSpellsSystem : EntitySystem _handsSystem.TryForcePickupAnyHand(msg.Performer, recallComponent.Item.Value); _audio.PlayPvs(recallComponent.RecallSound, msg.Performer); - msg.Handled = true; - Speak(msg); + Cast(msg); return; } @@ -293,8 +291,7 @@ public sealed class WizardSpellsSystem : EntitySystem Spawn("AdminInstantEffectSmoke3", Transform(msg.Target).Coordinates); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -317,8 +314,7 @@ public sealed class WizardSpellsSystem : EntitySystem Spawn("AdminInstantEffectSmoke3", Transform(msg.Target).Coordinates); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -340,8 +336,7 @@ public sealed class WizardSpellsSystem : EntitySystem Spawn("AdminInstantEffectSmoke3", Transform(msg.Target).Coordinates); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -357,8 +352,7 @@ public sealed class WizardSpellsSystem : EntitySystem _empSystem.EmpPulse(coords, 15, 1000000, 60f); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -381,8 +375,7 @@ public sealed class WizardSpellsSystem : EntitySystem _statusEffectsSystem.TryAddStatusEffect(msg.Performer, "Incorporeal", TimeSpan.FromSeconds(10), false); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -434,8 +427,7 @@ public sealed class WizardSpellsSystem : EntitySystem Spawn("AdminInstantEffectSmoke3", oldCoords); Spawn("AdminInstantEffectSmoke3", coords); - msg.Handled = true; - Speak(msg); + Cast(msg); } #endregion @@ -460,9 +452,7 @@ public sealed class WizardSpellsSystem : EntitySystem break; } - SetCooldown(msg.Action, msg.ActionUseType); - msg.Handled = true; - Speak(msg); + Cast(msg); } private void ForcewallSpellDefault(ForceWallSpellEvent msg) @@ -533,9 +523,7 @@ public sealed class WizardSpellsSystem : EntitySystem if (!result) return; - SetCooldown(msg.Action, msg.ActionUseType); - msg.Handled = true; - Speak(msg); + Cast(msg); } private void CardsSpellDefault(CardsSpellEvent msg) @@ -638,9 +626,7 @@ public sealed class WizardSpellsSystem : EntitySystem if (!result) return; - SetCooldown(msg.Action, msg.ActionUseType); - msg.Handled = true; - Speak(msg); + Cast(msg); } private void FireballSpellDefault(FireballSpellEvent msg) @@ -725,9 +711,7 @@ public sealed class WizardSpellsSystem : EntitySystem if (!result) return; - SetCooldown(msg.Action, msg.ActionUseType); - msg.Handled = true; - Speak(msg); + Cast(msg); } private bool ForceSpellAlt(ForceSpellEvent msg) @@ -782,9 +766,7 @@ public sealed class WizardSpellsSystem : EntitySystem if (!result) return; - SetCooldown(msg.Action, msg.ActionUseType); - msg.Handled = true; - Speak(msg); + Cast(msg); } private bool ArcSpellDefault(ArcSpellEvent msg) @@ -844,6 +826,17 @@ public sealed class WizardSpellsSystem : EntitySystem RaiseLocalEvent(uid, new EnergyDomeClothesTurnOffEvent()); } + public void Cast(BaseActionEvent msg, bool removeAllCharges = true) + { + SetCooldown(msg.Action, msg.ActionUseType); + msg.Handled = true; + Speak(msg); + if (!removeAllCharges) + return; + _charging.RemoveAllCharges(msg.Performer); + _charging.StopAllSounds(msg.Performer); + } + public bool CanCast(BaseActionEvent msg) { return !msg.Handled && CheckRequirements(msg.Action, msg.Performer) && diff --git a/Content.Server/_White/Wizard/Teleport/WizardTeleportSpellEui.cs b/Content.Server/_White/Wizard/Teleport/WizardTeleportSpellEui.cs index c9848c24bd..19e74ce393 100644 --- a/Content.Server/_White/Wizard/Teleport/WizardTeleportSpellEui.cs +++ b/Content.Server/_White/Wizard/Teleport/WizardTeleportSpellEui.cs @@ -1,4 +1,5 @@ -using Content.Server.EUI; +using Content.Server._White.Wizard.Charging; +using Content.Server.EUI; using Content.Server.Popups; using Content.Shared._White.Wizard.Teleport; using Content.Shared.Eui; @@ -15,6 +16,7 @@ public sealed class WizardTeleportSpellEui : BaseEui private readonly TeleportLocationSystem _teleportLocation; private readonly PullingSystem _pulling; private readonly PopupSystem _popupSystem; + private readonly ChargingSystem _charging; private readonly EntityUid _performer; @@ -28,6 +30,7 @@ public sealed class WizardTeleportSpellEui : BaseEui _pulling = _entityManager.System(); _teleportLocation = _entityManager.System(); _popupSystem = _entityManager.System(); + _charging = _entityManager.System(); _performer = performer; @@ -107,6 +110,9 @@ public sealed class WizardTeleportSpellEui : BaseEui _entityManager.SpawnEntity("AdminInstantEffectSmoke10", oldCoords); _entityManager.SpawnEntity("AdminInstantEffectSmoke10", coords); + _charging.RemoveAllCharges(_performer); + _charging.StopAllSounds(_performer); + Close(); } } diff --git a/Resources/Prototypes/_White/Wizard/magic_items.yml b/Resources/Prototypes/_White/Wizard/magic_items.yml index 60836bd1d5..4adfd2e9c8 100644 --- a/Resources/Prototypes/_White/Wizard/magic_items.yml +++ b/Resources/Prototypes/_White/Wizard/magic_items.yml @@ -15,12 +15,15 @@ - type: Clothing sprite: White/Objects/Weapons/Chaplain/hfrequency.rsi slots: - - back - - suitStorage + - none - type: Reflect reflectProb: 0.4 - type: Item sprite: White/Objects/Weapons/Chaplain/hfrequency.rsi + size: Large + storedRotation: 44 + shape: + - 0, 0, 3, 0 - type: entity name: клинок заклинаний