Skip to content

Commit

Permalink
Allow slashes to interact with remote worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Oct 15, 2023
1 parent d83211b commit 13213a8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions HKMP/Animation/Effects/CycloneSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
var hitRComponent = cycloneSlash.FindGameObjectInChildren("Hit R");
ChangeAttackTypeOfFsm(hitRComponent, 180f);

// Add rigid body and set it to be kinematic so it doesn't do physics, but still counts certain collisions
var rigidBody = cycloneSlash.AddComponent<Rigidbody2D>();
rigidBody.isKinematic = true;

cycloneSlash.SetActive(true);

// Set a name, so we can reference it later when we need to destroy it
Expand Down
26 changes: 23 additions & 3 deletions HKMP/Animation/Effects/DashSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,32 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
);

// Check which direction the knight is facing for the damages_enemy FSM
var facingRight = localScale.x > 0;
var facingRight = playerScaleX > 0;
ChangeAttackTypeOfFsm(dashSlash, facingRight ? 180f : 0f);

// Add rigid body and set it to be kinematic so it doesn't do physics, but still counts certain collisions
var rigidBody = dashSlash.AddComponent<Rigidbody2D>();
rigidBody.isKinematic = true;

var controlColliderFsm = dashSlash.LocateMyFSM("Control Collider");
// If the player is not facing right, the local position set by the FSM is not right given that we are spawning
// the dash slash on the player container instead of on the player object
if (!facingRight) {
var startPosVar = controlColliderFsm.FsmVariables.GetFsmVector3("Start Pos");
startPosVar.Value = new Vector3(
startPosVar.Value.x * -1,
startPosVar.Value.y,
startPosVar.Value.z
);
}

dashSlash.SetActive(true);

// Remove audio source component that exists on the dash slash object
Object.Destroy(dashSlash.GetComponent<AudioSource>());

// Set the newly instantiate collider to state Init, to reset it
// in case the local player was already performing it
var controlColliderFsm = dashSlash.LocateMyFSM("Control Collider");
if (controlColliderFsm.ActiveStateName != "Init") {
controlColliderFsm.SetState("Init");
}
Expand All @@ -70,7 +85,12 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
if (ServerSettings.IsPvpEnabled && ShouldDoDamage) {
// Since the dash slash should deal damage to other players, we create a separate object for that purpose
var pvpCollider = new GameObject("PvP Collider", typeof(PolygonCollider2D));
pvpCollider.transform.SetParent(dashSlash.transform);

var transform = pvpCollider.transform;
transform.SetParent(dashSlash.transform);
transform.localPosition = new Vector3(0, 0, 0);
transform.localScale = new Vector3(1, 1, 0);

pvpCollider.SetActive(true);
pvpCollider.layer = 22;

Expand Down
11 changes: 10 additions & 1 deletion HKMP/Animation/Effects/GreatSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
var facingRight = playerObject.transform.localScale.x > 0;
ChangeAttackTypeOfFsm(greatSlash, facingRight ? 180f : 0f);

// Add rigid body and set it to be kinematic so it doesn't do physics, but still counts certain collisions
var rigidBody = greatSlash.AddComponent<Rigidbody2D>();
rigidBody.isKinematic = true;

greatSlash.SetActive(true);

// Set the newly instantiate collider to state Init, to reset it
Expand All @@ -52,7 +56,12 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
if (ServerSettings.IsPvpEnabled && ShouldDoDamage) {
// Since the great slash should deal damage to other players, we create a separate object for that purpose
var pvpCollider = new GameObject("PvP Collider", typeof(PolygonCollider2D));
pvpCollider.transform.SetParent(greatSlash.transform);

var transform = pvpCollider.transform;
transform.SetParent(greatSlash.transform);
transform.localPosition = new Vector3(0, 0, 0);
transform.localScale = new Vector3(1, 1, 0);

pvpCollider.SetActive(true);
pvpCollider.layer = 22;

Expand Down
11 changes: 10 additions & 1 deletion HKMP/Animation/Effects/SlashBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa
var originalNailSlash = slash.GetComponent<NailSlash>();
Object.Destroy(originalNailSlash);

// Add rigid body and set it to be kinematic so it doesn't do physics, but still counts certain collisions
var rigidBody = slash.AddComponent<Rigidbody2D>();
rigidBody.isKinematic = true;

slash.SetActive(true);

// Get the slash audio source and its clip
Expand Down Expand Up @@ -166,7 +170,12 @@ protected void Play(GameObject playerObject, bool[] effectInfo, GameObject prefa
if (ServerSettings.IsPvpEnabled && ShouldDoDamage) {
// Since the slash should deal damage to other players, we create a separate object for that purpose
var pvpCollider = new GameObject("PvP Collider", typeof(PolygonCollider2D));
pvpCollider.transform.SetParent(slash.transform);

var transform = pvpCollider.transform;
transform.SetParent(slash.transform);
transform.localPosition = new Vector3(0, 0, 0);
transform.localScale = new Vector3(1, 1, 0);

pvpCollider.SetActive(true);
pvpCollider.layer = 22;

Expand Down

0 comments on commit 13213a8

Please sign in to comment.