Skip to content

Commit

Permalink
Fix charms/spells incorrectly causing parries
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Oct 3, 2023
1 parent d5e61ea commit 57a25b5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
3 changes: 1 addition & 2 deletions HKMP/Animation/Effects/CycloneSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayMakerFSM>();
fsm.SetFsmTemplate(NailClashTink.FsmTemplate);
AddParryFsm(cycloneSlash);
}

if (ShouldDoDamage && damage != 0) {
Expand Down
37 changes: 18 additions & 19 deletions HKMP/Animation/Effects/DashSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolygonCollider2D>().points =
dashSlash.GetComponent<PolygonCollider2D>().points;

if (ServerSettings.AllowParries) {
var fsm = dashSlash.AddComponent<PlayMakerFSM>();
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<PolygonCollider2D>().points =
dashSlash.GetComponent<PolygonCollider2D>().points;

dashSlashCollider.GetComponent<DamageHero>().damageDealt = damage;
}
}
Expand Down
3 changes: 1 addition & 2 deletions HKMP/Animation/Effects/GreatSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayMakerFSM>();
fsm.SetFsmTemplate(NailClashTink.FsmTemplate);
AddParryFsm(greatSlash);
}

if (ShouldDoDamage && damage != 0) {
Expand Down
23 changes: 22 additions & 1 deletion HKMP/Animation/Effects/ParryableEffect.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
using Hkmp.Util;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using UnityEngine;

namespace Hkmp.Animation.Effects;

/// <summary>
Expand All @@ -7,10 +12,26 @@ internal abstract class ParryableEffect : DamageAnimationEffect {
/// <summary>
/// The FSM for the nail parry effect.
/// </summary>
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<PlayMakerFSM>();
}

/// <summary>
/// Adds the FSM responsible for parrying to the given game object.
/// Does additional modification to the FSM to make it suitable for PvP.
/// </summary>
/// <param name="target">The GameObject that the FSM should be added to.</param>
protected void AddParryFsm(GameObject target) {
var fsm = target.AddComponent<PlayMakerFSM>();
fsm.SetFsmTemplate(NailClashTink.FsmTemplate);

var detectingState = fsm.GetState("Detecting");
detectingState.GetTransition(0).FsmEvent = new FsmEvent("TAKE DAMAGE 2");

var triggerAction = fsm.GetFirstAction<Trigger2dEventLayer>("Detecting");
triggerAction.sendEvent = new FsmEvent("TAKE DAMAGE 2");
}
}
3 changes: 1 addition & 2 deletions HKMP/Animation/Effects/SlashBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayMakerFSM>();
fsm.SetFsmTemplate(NailClashTink.FsmTemplate);
AddParryFsm(slash);
}

if (ShouldDoDamage && damage != 0) {
Expand Down

0 comments on commit 57a25b5

Please sign in to comment.