-
Notifications
You must be signed in to change notification settings - Fork 3
/
FennelDeath.cs
104 lines (97 loc) · 4 KB
/
FennelDeath.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections;
using UnityEngine;
using Logger = Modding.Logger;
namespace Fennel
{
internal class FennelDeath : MonoBehaviour
{
private SpriteRenderer _sr;
private Animator _anim;
private Rigidbody2D _rb;
private HeroController _target;
private AudioSource _aud;
public static bool isDying;
private void Awake()
{
_sr = gameObject.GetComponent<SpriteRenderer>();
_anim = gameObject.GetComponent<Animator>();
_rb = gameObject.GetComponent<Rigidbody2D>();
_aud = gameObject.GetComponent<AudioSource>();
_target = HeroController.instance;
}
private void Start()
{
if (ArenaFinder.BossLevel == 0)
{
Fennel._settings.CompletionFennel.completedTier1 = true;
}
else if (ArenaFinder.BossLevel == 1)
{
Fennel._settings.CompletionFennel.completedTier2 = true;
}
else
{
Fennel._settings.CompletionFennel.completedTier3 = true;
}
isDying = true;
_sr.material.SetFloat("_FlashAmount", 0f);
_rb.velocity = new Vector2(0f, 0f);
foreach (PolygonCollider2D i in gameObject.GetComponentsInChildren<PolygonCollider2D>(true))
{
i.enabled = false;
}
StartCoroutine(DeathSentence());
}
IEnumerator DeathSentence()
{
PlayerData.instance.isInvincible = true;
_rb.gravityScale = 1f;
_anim.Play("hurt");
yield return new WaitWhile(() => gameObject.transform.GetPositionY() >= 6.75f);
_rb.gravityScale = 0f;
_rb.velocity = new Vector2(0f, 0f);
FaceHero();
_anim.Play("death");
_aud.clip = ArenaFinder.audioClips["sndDeath"];
_aud.Play();
yield return new WaitForSeconds(0.05f);
yield return new WaitWhile(() => _anim.IsPlaying());
FaceHero();
GameObject text = Instantiate(GameObject.Find("DialogueManager"));
text.SetActive(true);
yield return null;
var txtfsm = text.LocateMyFSM("Box Open");
txtfsm.SendEvent("BOX UP");
GameManager.instance.playerData.SetBool("disablePause", true);
_target.RelinquishControl();
_target.StopAnimationControl();
_target.gameObject.GetComponent<tk2dSpriteAnimator>().Play("Idle");
GameObject sec = text.transform.Find("Text").gameObject;
sec.GetComponent<DialogueBox>().StartConversation("FENNEL_END", "testudo");
yield return new WaitWhile(() => sec.GetComponent<DialogueBox>().currentPage <= 1);
txtfsm.SendEvent("BOX DOWN");
text.SetActive(false);
_target.RegainControl();
GameManager.instance.playerData.SetBool("disablePause", false);
_target.StartAnimationControl();
yield return new WaitForSeconds(0.5f);
//Do particle death here--------------------------------------------------------------------------------------------------------------------------------------------------------
yield return new WaitForSeconds(1f);
var endCtrl = GameObject.Find("Boss Scene Controller").LocateMyFSM("Dream Return");
endCtrl.SendEvent("DREAM RETURN");
}
private float FaceHero()
{
var heroSignX = Mathf.Sign(gameObject.transform.GetPositionX() - _target.transform.GetPositionX());
var pScale = gameObject.transform.localScale;
gameObject.transform.localScale = new Vector2(Mathf.Abs(pScale.x) * heroSignX, pScale.y);
if (heroSignX < 0) _target.FaceLeft();
else _target.FaceRight();
return heroSignX;
}
private static void Log(object obj)
{
Logger.Log("[Death] " + obj);
}
}
}