-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEffect_Petrification.cs
146 lines (112 loc) · 4.68 KB
/
Effect_Petrification.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Landfall.TABS;
using TGCore.Library;
using UnityEngine;
using UnityEngine.Events;
namespace HiddenUnits
{
public class Effect_Petrification : UnitEffectBase
{
public override void DoEffect()
{
OwnUnit = transform.root.GetComponent<Unit>();
ColorHandler = OwnUnit.data.GetComponent<UnitColorHandler>();
DragHandler = OwnUnit.data.GetComponent<DragHandler>();
AllRigs = OwnUnit.data.allRigs;
OriginalDrags = OwnUnit.data.allRigs.defaultDrags.ToList();
var multi = OwnUnit.data.GetComponent<HoldingHandlerMulti>();
if (OwnUnit.data.weaponHandler)
{
if (OwnUnit.data.weaponHandler.rightWeapon) Weapons.Add(OwnUnit.data.weaponHandler.rightWeapon.rigidbody);
if (OwnUnit.data.weaponHandler.leftWeapon) Weapons.Add(OwnUnit.data.weaponHandler.leftWeapon.rigidbody);
}
else if (multi)
{
Weapons.AddRange(multi.spawnedWeapons.Select(x => x.GetComponent<Rigidbody>()));
}
TrueDelay = Mathf.Clamp(unPetrifyDelay - OwnUnit.data.maxHealth / 250 + 0.4f, 1f, unPetrifyDelay);
StartCoroutine(DoPetrifying());
}
public override void Ping()
{
pingEvent.Invoke();
}
private IEnumerator DoPetrifying()
{
if (OwnUnit.data.Dead || OwnUnit.data.healthHandler.willBeRewived) yield break;
petrifyEvent.Invoke();
var t = 0f;
while (t < 1f && !OwnUnit.data.Dead)
{
t += Time.deltaTime * petrifySpeed;
for (var i = 0; i < AllRigs.AllDrags.Length; i++)
{
AllRigs.AllDrags[i].x = OriginalDrags[i].x + t;
AllRigs.AllDrags[i].y = OriginalDrags[i].y + t;
}
DragHandler.UpdateDrag();
ColorHandler.SetColor(petrifyColor, t);
yield return null;
}
if (OwnUnit.data.Dead)
{
ResetUnit();
yield break;
}
OriginalDrags = AllRigs.AllDrags.ToList();
OwnUnit.WeaponHandler.StopAttacksFor(TrueDelay);
foreach (var rig in AllRigs.AllRigs) rig.isKinematic = true;
foreach (var weapon in Weapons) weapon.isKinematic = true;
StartCoroutine(DoUnPetrifying());
}
private IEnumerator DoUnPetrifying()
{
yield return new WaitForSeconds(TrueDelay);
if (OwnUnit.data.Dead) yield break;
unPetrifyEvent.Invoke();
foreach (var rig in AllRigs.AllRigs) rig.isKinematic = false;
foreach (var weapon in Weapons) weapon.isKinematic = false;
var t = 0f;
while (t < 1f && !OwnUnit.data.Dead)
{
t += Time.deltaTime * unPetrifySpeed;
for (var i = 0; i < AllRigs.AllDrags.Length; i++)
{
AllRigs.AllDrags[i].x = OriginalDrags[i].x - t;
AllRigs.AllDrags[i].y = OriginalDrags[i].y - t;
}
DragHandler.UpdateDrag();
ColorHandler.SetColor(petrifyColor, 1 - t);
yield return null;
}
}
private void ResetUnit()
{
ColorHandler.SetColor(petrifyColor, 0f);
for (var i = 0; i < AllRigs.AllDrags.Length; i++)
{
AllRigs.AllDrags[i].x = OwnUnit.data.allRigs.defaultDrags[i].x;
AllRigs.AllDrags[i].y = OwnUnit.data.allRigs.defaultDrags[i].y;
}
}
private Unit OwnUnit;
private UnitColorHandler ColorHandler;
private DragHandler DragHandler;
private RigidbodyHolder AllRigs;
private List<Vector2> OriginalDrags;
private List<Rigidbody> Weapons = new List<Rigidbody>();
private float TrueDelay;
[Header("Petrification")]
public UnityEvent petrifyEvent = new UnityEvent();
public UnitColorInstance petrifyColor;
public float petrifySpeed = 2f;
[Header("De-Petrification")]
public UnityEvent unPetrifyEvent = new UnityEvent();
public float unPetrifyDelay = 4f;
public float unPetrifySpeed = 4f;
[Header("Ping")]
public UnityEvent pingEvent = new UnityEvent();
}
}