-
Notifications
You must be signed in to change notification settings - Fork 0
/
Confringo.cs
212 lines (175 loc) · 7.83 KB
/
Confringo.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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using ThunderRoad;
using UnityEngine.VFX;
using Random = UnityEngine.Random;
namespace WandSpellss
{
public class Confringo : MonoBehaviour
{
private VisualEffect vfx;
private Item item;
public Item wand;
private bool hit = false;
private float time = 1.5f;
private float elapsedTime = 0f;
float currentTime = 0f;
private Vector3 hitLocation;
private float distance;
private float radius = 3f;
Vector3 originalLocation;
private void Start()
{
item = GetComponentInParent<Item>();
//CastRay();
}
public void SpellEffect(Collision c)
{
Collider[] colliders = Physics.OverlapSphere(c.contacts[0].point, 3f);
List<Creature> creaturesInColliders = new List<Creature>();
List<Item> itemsInColliders = new List<Item>();
foreach (Collider collider in colliders)
{
if(collider.GetComponentInParent<Creature>() is Creature creature && !creature.isPlayer && !creaturesInColliders.Contains(creature))
{
creaturesInColliders.Add(creature);
}
if (collider.GetComponentInParent<Item>() is Item item && !itemsInColliders.Contains(item))
{
itemsInColliders.Add(item);
}
}
foreach (Creature creature in creaturesInColliders)
{
creature.ragdoll.SetState(Ragdoll.State.Destabilized);
foreach (Rigidbody body in creature.ragdoll.parts.Select(part =>part.physicBody.rigidBody))
{
float mass = body.mass;
body.AddExplosionForce(mass * 2000f, c.contacts[0].point, 3f, 30f);
}
}
foreach (Item item in itemsInColliders)
{
float mass = item.physicBody.rigidBody.mass;
item.physicBody.rigidBody.AddExplosionForce(mass * 2000f, c.contacts[0].point, 3f, 30f);
}
Loader.local.explosion.transform.position = c.contacts[0].point;
GameObject effect = Instantiate(Loader.local.explosion);
Loader.local.couroutineManager.StartCustomCoroutine(Loader.local.couroutineManager.DestroyVFX(effect));
}
public void OnCollisionEnter(Collision c)
{
SpellEffect(c);
}
internal void CastRay() {
RaycastHit hit;
Transform parent;
Debug.Log("Hit Cast Ray method");
if (Physics.Raycast(wand.flyDirRef.transform.position, wand.flyDirRef.transform.forward, out hit, float.MaxValue, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
{
Debug.Log("Hit raycasted");
Catalog.GetData<ItemData>("StupefyObject")?.SpawnAsync(projectile =>
{
Debug.Log("Hit spawner");
this.item = projectile;
item.transform.position = wand.transform.position;
hitLocation = hit.collider.gameObject.transform.position;
distance = Vector3.Distance(wand.flyDirRef.transform.position, hitLocation);
this.hit = true;
if (projectile.gameObject.GetComponent<Expelliarmus>() is Expelliarmus armus)
{
Destroy(armus);
}
});
originalLocation = wand.flyDirRef.transform.position;
}
}
Vector3 GetBezier(Vector3 p0, Vector3 p1, Vector3 p2, float time)
{
float tt = time * time;
float u = 1f - time;
float uu = u * u;
Vector3 result = uu * p0;
result += 2f * u * time * p1;
result += tt * p2;
return result;
}
Vector3 random;
private bool randomFound = false;
/*private void Update()
{
if (hit)
{
if (!randomFound)
{
random = new Vector3(
Random.Range(originalLocation.x, hitLocation.x),
Random.Range((originalLocation + new Vector3(0, 1, 0)).y,
(originalLocation + new Vector3(0, -1, 0)).y),
Random.Range(originalLocation.z, hitLocation.z));
randomFound = true;
}
elapsedTime += Time.deltaTime;
float percentageComplete = elapsedTime / (distance / time);
Vector3 bezierCurrentPosition = GetBezier(originalLocation, random, hitLocation, time);
Vector3 bezierNextPosition =
GetBezier(originalLocation, random, hitLocation, time + 0.01f);
item.transform.position = Vector3.Lerp(bezierCurrentPosition, bezierNextPosition, Mathf.SmoothStep(0, 1, percentageComplete));
if (percentageComplete >= 1f)
{
Collider[] colliders = Physics.OverlapSphere(hitLocation, 3f);
foreach (Collider collider in colliders)
{
if (collider.GetComponentInParent<Rigidbody>() is Rigidbody body)
{
body.AddExplosionForce(5f, hitLocation, 3f, 1.5f);
}
}
}
}
}*/
}
public class ConfringoHandler : Spell
{
public static SpellType spellType = SpellType.Shoot;
public override Spell AddGameObject(GameObject gameObject)
{
throw new NotImplementedException();
}
public override void SpawnSpell(Type type, string name, Item wand, float spellSpeed)
{
Debug.Log("Got to spawn spell method");
try
{
Catalog.GetData<ItemData>(name + "Object")?.SpawnAsync(projectile =>
{
projectile.transform.position = wand.flyDirRef.transform.position;
projectile.transform.rotation = wand.flyDirRef.transform.rotation;
projectile.IgnoreObjectCollision(wand);
projectile.IgnoreRagdollCollision(Player.currentCreature.ragdoll);
projectile.gameObject.AddComponent(type);
projectile.Throw();
projectile.physicBody.rigidBody.useGravity = false;
projectile.physicBody.rigidBody.drag = 0.0f;
foreach (AudioSource c in wand.GetComponentsInChildren<AudioSource>())
{
if (c.name == name) c.Play();
}
projectile.GetComponent<Rigidbody>().AddForce(wand.flyDirRef.forward * spellSpeed, ForceMode.Impulse);
projectile.gameObject.AddComponent<SpellDespawn>();
});
}
catch (NullReferenceException e) { Debug.Log(e.Message); }
}
public override void UpdateSpell(Type type, string name, Item wand)
{
throw new NotImplementedException();
}
public override void UpdateSpell(Type type, string name, Item wand, String itemType)
{
throw new NotImplementedException();
}
}
}