Skip to content

Commit

Permalink
Allow remote players to hit enemies with nail slash
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Oct 5, 2023
1 parent 8074cd4 commit b15279c
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions HKMP/Animation/Effects/SlashBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hkmp.Util;
using HutongGames.PlayMaker.Actions;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Hkmp.Animation.Effects;

Expand Down Expand Up @@ -74,8 +75,6 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa
var originalNailSlash = slash.GetComponent<NailSlash>();
Object.Destroy(originalNailSlash);

ChangeAttackTypeOfFsm(slash);

slash.SetActive(true);

// Get the slash audio source and its clip
Expand Down Expand Up @@ -151,10 +150,38 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa

polygonCollider.enabled = true;

// Instantiate additional game object that can interact with enemies so remote enemies can be hit
GameObject enemySlash;
{
enemySlash = Object.Instantiate(prefab, playerAttacks.transform);
enemySlash.layer = 17;
enemySlash.name = "Enemy Slash";
enemySlash.transform.localScale = slash.transform.localScale;

var typesToRemove = new[] {
typeof(MeshFilter), typeof(MeshRenderer), typeof(tk2dSprite), typeof(tk2dSpriteAnimator),
typeof(NailSlash),
typeof(AudioSource)
};
foreach (var typeToRemove in typesToRemove) {
Object.Destroy(enemySlash.GetComponent(typeToRemove));
}

for (var i = 0; i < enemySlash.transform.childCount; i++) {
Object.Destroy(enemySlash.transform.GetChild(i));
}

polygonCollider = enemySlash.GetComponent<PolygonCollider2D>();
polygonCollider.enabled = true;

var damagesEnemyFsm = slash.LocateMyFSM("damages_enemy");
Object.Destroy(damagesEnemyFsm);

ChangeAttackTypeOfFsm(enemySlash);
}

var damage = ServerSettings.NailDamage;
if (ServerSettings.IsPvpEnabled) {
// TODO: make it possible to pogo on players

if (ServerSettings.AllowParries) {
AddParryFsm(slash);
}
Expand All @@ -167,6 +194,7 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa
// After the animation is finished, we can destroy the slash object
var animationDuration = slashAnimator.CurrentClip.Duration;
Object.Destroy(slash, animationDuration);
Object.Destroy(enemySlash, animationDuration);

if (!hasGrubberflyElegyCharm
|| isOnOneHealth && !hasFuryCharm
Expand Down

0 comments on commit b15279c

Please sign in to comment.