-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterBolt.cs
111 lines (96 loc) · 2.51 KB
/
MasterBolt.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
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
public class MasterBolt : ProjectileHitEffect
{
public UnityEvent hitEvent;
public UnityEvent disableEvent;
public LayerMask mask;
private MoveTransform move;
private ProjectileHit projectileHit;
private RaycastTrail trail;
public ParticleSystem part;
public bool spawnMore = true;
public bool disableIfNoTarget;
public bool onlyTargetAlive;
private List<DataHandler> hitUnits = new List<DataHandler>();
public float chanceOfSuccess = 1f;
private void Start()
{
projectileHit = GetComponent<ProjectileHit>();
move = GetComponent<MoveTransform>();
trail = GetComponent<RaycastTrail>();
}
public override bool DoEffect(HitData hit)
{
if (!base.gameObject)
{
return false;
}
if (hitEvent != null)
{
hitEvent.Invoke();
}
if (!hit.rigidbody)
{
part.Play();
trail.enabled = false;
move.enabled = false;
projectileHit.done = true;
return true;
}
Collider[] array = Physics.OverlapSphere(base.transform.position, 20f, mask);
Transform transform = null;
float num = 999f;
for (int i = 0; i < array.Length; i++)
{
if (!(base.transform.InverseTransformPoint(array[i].transform.position).z > 0.6f) || !(Vector3.Angle(base.transform.forward, array[i].transform.position - base.transform.position) < 90f))
{
continue;
}
DataHandler componentInParent = array[i].transform.GetComponentInParent<DataHandler>();
if ((bool)componentInParent)
{
if (!componentInParent.Dead && !hitUnits.Contains(componentInParent))
{
hitUnits.Add(componentInParent);
}
if (componentInParent.Dead)
{
continue;
}
}
float num2 = Vector3.Distance(base.transform.position, array[i].transform.position);
if (num2 < num)
{
transform = array[i].transform;
num = num2;
}
}
if (transform != null)
{
if (Random.value < chanceOfSuccess && spawnMore)
{
Object.Instantiate(base.gameObject, base.transform.position, base.transform.rotation);
}
move.velocity = (transform.position - base.transform.position).normalized * move.selfImpulse.magnitude;
}
else if (disableIfNoTarget)
{
projectileHit.DisableProjectile();
disableEvent.Invoke();
}
CheckAchievements();
return true;
}
private void CheckAchievements()
{
var service = ServiceLocator.GetService<AchievementService>();
var num = hitUnits.Count(hitUnit => hitUnit.Dead);
if (num >= 20)
{
service.UnlockAchievement("ZEUS_KILL_UNITS");
}
}
}