From 57a25b55e64c33858347266650c7f6b17dc4f662 Mon Sep 17 00:00:00 2001 From: Extremelyd1 Date: Tue, 3 Oct 2023 22:19:36 +0200 Subject: [PATCH] Fix charms/spells incorrectly causing parries --- HKMP/Animation/Effects/CycloneSlash.cs | 3 +- HKMP/Animation/Effects/DashSlash.cs | 37 +++++++++++------------ HKMP/Animation/Effects/GreatSlash.cs | 3 +- HKMP/Animation/Effects/ParryableEffect.cs | 23 +++++++++++++- HKMP/Animation/Effects/SlashBase.cs | 3 +- 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/HKMP/Animation/Effects/CycloneSlash.cs b/HKMP/Animation/Effects/CycloneSlash.cs index 6e9e5e9..26fa979 100644 --- a/HKMP/Animation/Effects/CycloneSlash.cs +++ b/HKMP/Animation/Effects/CycloneSlash.cs @@ -56,8 +56,7 @@ public override void Play(GameObject playerObject, bool[] effectInfo) { var damage = ServerSettings.CycloneSlashDamage; if (ServerSettings.IsPvpEnabled) { if (ServerSettings.AllowParries) { - var fsm = cycloneSlash.AddComponent(); - fsm.SetFsmTemplate(NailClashTink.FsmTemplate); + AddParryFsm(cycloneSlash); } if (ShouldDoDamage && damage != 0) { diff --git a/HKMP/Animation/Effects/DashSlash.cs b/HKMP/Animation/Effects/DashSlash.cs index a23cae6..a42bdce 100644 --- a/HKMP/Animation/Effects/DashSlash.cs +++ b/HKMP/Animation/Effects/DashSlash.cs @@ -62,29 +62,28 @@ public override void Play(GameObject playerObject, bool[] effectInfo) { var damage = ServerSettings.DashSlashDamage; if (ServerSettings.IsPvpEnabled) { + // Somehow adding a DamageHero component or the parry FSM simply to the dash slash object doesn't work, + // so we create a separate object for it + var dashSlashCollider = Object.Instantiate( + new GameObject( + "DashSlashCollider", + typeof(PolygonCollider2D), + typeof(DamageHero) + ), + dashSlash.transform + ); + dashSlashCollider.SetActive(true); + dashSlashCollider.layer = 22; + + // Copy over the polygon collider points + dashSlashCollider.GetComponent().points = + dashSlash.GetComponent().points; + if (ServerSettings.AllowParries) { - var fsm = dashSlash.AddComponent(); - fsm.SetFsmTemplate(NailClashTink.FsmTemplate); + AddParryFsm(dashSlashCollider); } if (ShouldDoDamage && damage != 0) { - // Somehow adding a DamageHero component simply to the dash slash object doesn't work, - // so we create a separate object for it - var dashSlashCollider = Object.Instantiate( - new GameObject( - "DashSlashCollider", - typeof(PolygonCollider2D), - typeof(DamageHero) - ), - dashSlash.transform - ); - dashSlashCollider.SetActive(true); - dashSlashCollider.layer = 22; - - // Copy over the polygon collider points - dashSlashCollider.GetComponent().points = - dashSlash.GetComponent().points; - dashSlashCollider.GetComponent().damageDealt = damage; } } diff --git a/HKMP/Animation/Effects/GreatSlash.cs b/HKMP/Animation/Effects/GreatSlash.cs index cd81358..0f98145 100644 --- a/HKMP/Animation/Effects/GreatSlash.cs +++ b/HKMP/Animation/Effects/GreatSlash.cs @@ -49,8 +49,7 @@ public override void Play(GameObject playerObject, bool[] effectInfo) { var damage = ServerSettings.GreatSlashDamage; if (ServerSettings.IsPvpEnabled) { if (ServerSettings.AllowParries) { - var fsm = greatSlash.AddComponent(); - fsm.SetFsmTemplate(NailClashTink.FsmTemplate); + AddParryFsm(greatSlash); } if (ShouldDoDamage && damage != 0) { diff --git a/HKMP/Animation/Effects/ParryableEffect.cs b/HKMP/Animation/Effects/ParryableEffect.cs index c5e4846..818d3a8 100644 --- a/HKMP/Animation/Effects/ParryableEffect.cs +++ b/HKMP/Animation/Effects/ParryableEffect.cs @@ -1,3 +1,8 @@ +using Hkmp.Util; +using HutongGames.PlayMaker; +using HutongGames.PlayMaker.Actions; +using UnityEngine; + namespace Hkmp.Animation.Effects; /// @@ -7,10 +12,26 @@ internal abstract class ParryableEffect : DamageAnimationEffect { /// /// The FSM for the nail parry effect. /// - protected readonly PlayMakerFSM NailClashTink; + private readonly PlayMakerFSM NailClashTink; protected ParryableEffect() { var hiveKnightSlash = HkmpMod.PreloadedObjects["Hive_05"]["Battle Scene/Hive Knight/Slash 1"]; NailClashTink = hiveKnightSlash.GetComponent(); } + + /// + /// Adds the FSM responsible for parrying to the given game object. + /// Does additional modification to the FSM to make it suitable for PvP. + /// + /// The GameObject that the FSM should be added to. + protected void AddParryFsm(GameObject target) { + var fsm = target.AddComponent(); + fsm.SetFsmTemplate(NailClashTink.FsmTemplate); + + var detectingState = fsm.GetState("Detecting"); + detectingState.GetTransition(0).FsmEvent = new FsmEvent("TAKE DAMAGE 2"); + + var triggerAction = fsm.GetFirstAction("Detecting"); + triggerAction.sendEvent = new FsmEvent("TAKE DAMAGE 2"); + } } diff --git a/HKMP/Animation/Effects/SlashBase.cs b/HKMP/Animation/Effects/SlashBase.cs index 168ea43..c6035e8 100644 --- a/HKMP/Animation/Effects/SlashBase.cs +++ b/HKMP/Animation/Effects/SlashBase.cs @@ -155,8 +155,7 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa // TODO: make it possible to pogo on players if (ServerSettings.AllowParries) { - var fsm = slash.AddComponent(); - fsm.SetFsmTemplate(NailClashTink.FsmTemplate); + AddParryFsm(slash); } if (ShouldDoDamage && damage != 0) {