-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagicEleBoss.cs
411 lines (343 loc) · 14.1 KB
/
MagicEleBoss.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class MagicEleBoss : MonoBehaviour, IdamageableStatus<string, int>
{
private Rigidbody rb;
private float distance;
public float attack_range;
public float move_speed;
public float current_health;
public float max_health;
private float timescale_multi;
private float fill_amount;
public GameObject HP_Fill_bar;
public GameObject HP_background_bar;
public GameObject floating_damage;
private GameObject float_damage_inst;
public GameObject red_ele_ragdoll;
public GameObject attack_spawner;
private GameObject chargeup_instance;
public GameObject chargeup_prefab;
public GameObject Lob1_Prefab;
public GameObject Barrage_prefab;
public GameObject GiantLob_Prefab;
private float attack_timer;
private float attack_delay = 5f;
private Animator animator;
//public bool isAttacking;
private bool Has_Attacked;
private bool stop_moving;
private bool side_move;
private int random_direction;
private bool spawning;
private int walk_threshold = 6;
private int run_threshold = 15;
RaycastHit ground_ray;
float ground_distance;
private bool ground_check = true;
Vector3 Targetposition;
private SkinnedMeshRenderer mesh;
private Material[] base_material;
GameObject exp_holder;
public GameObject exp_prefab;
public GameObject spawn_smoke_prefab;
private bool dying;
void Start()
{
spawning = true;
dying = false;
StartCoroutine(Spawn());
//exp_holder = GameObject.Find("Exp Holder");
timescale_multi = 1.0f;
rb = transform.GetComponent<Rigidbody>();
animator = GetComponent<Animator>();
current_health = max_health;
mesh = transform.GetChild(1).transform.GetComponent<SkinnedMeshRenderer>();
base_material = new Material[1] { mesh.material };
//base_material[0] = mesh.materials[0];
}
void FixedUpdate()
{
Targetposition = new Vector3(Basics.instance.Player.transform.position.x, transform.position.y, Basics.instance.Player.transform.position.z);
distance = Vector3.Distance(Targetposition, transform.position);
if (Physics.Raycast(transform.position, Vector3.down, out ground_ray, 200, 3))
{
if (ground_ray.transform.tag == "Terrain")
{
ground_distance = Vector3.Distance(transform.position, ground_ray.point);
}
}
if (ground_distance > 2)
{
transform.Translate(Vector3.down * 5 * Time.deltaTime);
}
//Get in range
if (distance >= attack_range)
{
if (!stop_moving && !spawning && !dying)
{
transform.LookAt(Targetposition);
transform.Translate(Vector3.forward * move_speed * Time.deltaTime * timescale_multi);
}
}
if (Has_Attacked && !stop_moving && timescale_multi != 0 && !dying)
{
switch (random_direction)
{
case 1:
transform.Translate(Vector3.left * (move_speed / 2 * Time.deltaTime));
break;
case 2:
transform.Translate(Vector3.right * (move_speed / 2 * Time.deltaTime));
break;
case 3:
transform.Translate(Vector3.back * (move_speed / 2 * Time.deltaTime));
break;
case 4:
transform.Translate(Vector3.forward * (move_speed / 2 * Time.deltaTime));
break;
}
}
if (distance < attack_range && !dying)
{
animator.SetBool("Movement", false);
}
else
{
animator.SetBool("Movement", true);
}
//else if (distance > (attack_range + walk_threshold) && distance < (attack_range + run_threshold))
//{
// animator.SetFloat("Movement", Mathf.SmoothStep(0, .5f, 1));
//}
//else animator.SetFloat("Movement", Mathf.SmoothStep(0, 1, 1));
//animator.SetFloat("Movement", Mathf.Abs(rb.velocity.magnitude));
//Set animator based on speed, rb velocity?
//animator.SetFloat("Speed", golem_speed);
//Attack
attack_timer += Time.deltaTime;
if ((attack_range > distance) && (attack_timer > attack_delay) && !spawning && !dying)
{
if (!Has_Attacked)
{
StartCoroutine(Attack());
// Destroy(chargeup_instance.gameObject, 2);
//attack_timer = 0;
random_direction = Random.Range(1, 5);
Has_Attacked = true;
}
//isAttacking = true;
}
//TRANSLATE THIS TO c# its to check line of sight
//var hit : RaycastHit;
//var rayDirection = player.position - transform.position;
//if (Physics.Raycast(transform.position, rayDirection, hit))
//{
// if (hit.transform == player)
// {
// // enemy can see the player!
// }
// else
// {
// // there is something obstructing the view
// }
//}
//Death
if (current_health <= 0.0f)
{
//StartCoroutine(Death());
//PlayerStats.instance.Experience_Count++;
//Vector3 exp_spawn = transform.position;
//exp_spawn.y += 5;
//GameObject exp_inst = Instantiate(exp_prefab, exp_spawn, Quaternion.identity);
//exp_inst.transform.parent = exp_holder.transform;
//GameObject ragdoll_inst = Instantiate(red_ele_ragdoll, transform.position, transform.rotation);
animator.SetBool("Death", true);
Basics.instance.GuardianBoss_Dead = true;
dying = true;
Destroy(gameObject, 8);
//Destroy(ragdoll_inst, 5);
}
else
{
//Vector3 Targetposition = new Vector3(Basics.instance.Player.transform.position.x, transform.position.y, Basics.instance.Player.transform.position.z);
//transform.LookAt(Targetposition);]
if (!spawning)
{
transform.LookAt(Targetposition);
}
}
//if (float_damage_inst != null)
//{
// //float_damage_inst.transform.LookAt(Basics.instance.Main_Camera.transform);
// float_damage_inst.transform.rotation = Quaternion.LookRotation(float_damage_inst.transform.position - Basics.instance.Main_Camera.transform.position);
//}
//if (chargeup_instance != null)
//{
// Destroy(chargeup_instance.gameObject, 5);
//}
}
public void Damage(float Spell_Damage)
{
//StartCoroutine(Allow_Physics());
float damage_total;
damage_total = Spell_Damage;
current_health -= Spell_Damage;
float_damage_inst = Instantiate(Basics.instance.Floating_Damage_Holder, transform);
float_damage_inst.transform.position = new Vector3(float_damage_inst.transform.position.x, float_damage_inst.transform.position.y - 4, float_damage_inst.transform.position.z);
//float_damage_inst.transform.localScale = new Vector3(2, 2, 2);
float_damage_inst.transform.GetChild(0).GetComponent<TMP_Text>().text = damage_total.ToString();
Destroy(float_damage_inst, 1);
//Enemy health bar
if (!this.HP_background_bar.activeSelf)
{
this.HP_background_bar.SetActive(true);
this.HP_Fill_bar.SetActive(true);
}
fill_amount = (current_health / max_health);
HP_Fill_bar.GetComponent<Image>().fillAmount = fill_amount;
}
IEnumerator Pause_Movement()
{
stop_moving = true;
yield return new WaitForSeconds(2);
stop_moving = false;
}
//IEnumerator Death()
//{
// GameObject ragdoll_inst = Instantiate(red_ele_ragdoll, transform);
// Destroy(gameObject);
// //animator.SetBool("Death", true);
// yield return new WaitForSeconds(4);
// //Debug.Log("Shit golem down");
// Destroy(gameObject);
// //Destroy(hp_bar_inst);
//}
IEnumerator Attack()
{
int attack_select = Random.Range(0, 9);
switch (attack_select)
{
case int n when n < 8:
{
if (timescale_multi != 0)
{
//Standard Bullet attack
//animator.Play("SpellReady");
stop_moving = true;
animator.SetBool("Lob", true);
chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform);
yield return new WaitForSeconds(1.6f);
//animator.Play("Attack01");
GameObject bullet_instance = Instantiate(Lob1_Prefab, attack_spawner.transform.position, Quaternion.identity);
Destroy(bullet_instance, 6);
yield return new WaitForSeconds(1);
animator.SetBool("Lob", false);
stop_moving = false;
Destroy(chargeup_instance, 1);
attack_timer = 0;
}
else yield return null;
}
break;
case 8:
//Channel attack, add enum cooldown w bool like spell
if (timescale_multi != 0)
{
stop_moving = true;
animator.SetBool("Channel", true);
chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform);
yield return new WaitForSeconds(2);
GameObject missile_instance = Instantiate(Barrage_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
Destroy(missile_instance, 12);
yield return new WaitForSeconds(2);
GameObject missile_instance2 = Instantiate(Barrage_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
Destroy(missile_instance2, 12);
yield return new WaitForSeconds(2);
GameObject missile_instance3 = Instantiate(Barrage_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
Destroy(missile_instance3, 12);
animator.SetBool("Channel", false);
Destroy(chargeup_instance, 1);
stop_moving = false;
attack_timer = 0;
}
else yield return null;
break;
//CAN have some random numbers to a movement instead of attack like a roar
//case 4: //ADD giant overhead lob w custom animation
// //Field aoe attack
// stop_moving = true;
// animator.SetBool("Attacking", true);
// chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// chargeup_instance.transform.SetParent(transform);
// //chargeup_instace.transform.SetParent()
// yield return new WaitForSeconds(1.5f);
// GameObject storm_instance = Instantiate(storm_prefab, Basics.instance.Player.transform.position, attack_spawner.transform.rotation);
// Destroy(storm_instance, 8);
// animator.SetBool("Attacking", false);
// stop_moving = false;
// attack_timer = 0;
// break;
}
Has_Attacked = false;
}
IEnumerator Spawn()
{
GameObject spawnsmoke_inst = Instantiate(spawn_smoke_prefab, transform);
transform.GetComponent<BoxCollider>().enabled = false;
yield return new WaitForSeconds(8);
transform.GetComponent<BoxCollider>().enabled = true;
Destroy(spawnsmoke_inst);
spawning = false;
rb.isKinematic = false;
}
//IEnumerator Allow_Physics()
//{
// rb.drag = 1;
// ground_check = false;
// yield return new WaitForSeconds(4);
// rb.drag = 10;
// ground_check = true;
//}
public IEnumerator Set_Status(string type, float duration)
{
switch (type)
{
case "frost":
mesh.material = Basics.instance.Frost_Status_Mat;
break;
case "air":
Material[] air_material = new Material[2] { base_material[0], Basics.instance.Air_Status_Mat };
mesh.materials = air_material;
break;
case "earth":
mesh.material = Basics.instance.Earth_Status_Mat;
break;
}
timescale_multi = 0;
animator.speed = 0;
duration = duration / 4;
yield return new WaitForSeconds(duration);
mesh.materials = base_material;
timescale_multi = 1;
animator.speed = 1;
}
public void Status(string Status_Effect, int duration)
{
StartCoroutine(Set_Status(Status_Effect, duration));
}
//private void OnCollisionStay(Collision collision)
//{
// if (collision.transform.tag == "Player")
// {
// IDamageable<float> damageable = collision.transform.GetComponent<IDamageable<float>>();
// if (damageable != null)
// {
// damageable.Damage(1);
// }
// }
//}
}