-
Notifications
You must be signed in to change notification settings - Fork 0
/
Levioso.cs
131 lines (111 loc) · 4.49 KB
/
Levioso.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
using System;
using System.Collections;
using UnityEngine;
using ThunderRoad;
using UnityEngine.VFX;
namespace WandSpellss
{
public class Levioso : MonoBehaviour
{
private GameObject leviosoUpdate;
private Rigidbody currentCreature;
private bool startLevitate;
private GameObject go;
private Vector3 position;
public void Start()
{
go = new GameObject();
startLevitate = false;
leviosoUpdate = new GameObject();
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.GetComponentInParent<Creature>() is Creature creature)
{
creature.ragdoll.SetState(Ragdoll.State.Destabilized);
currentCreature = creature.ragdoll.targetPart.physicBody.rigidBody;
startLevitate = true;
position = creature.ragdoll.targetPart.transform.position;
}
else if(collision.gameObject.GetComponentInParent<Item>() is Item item)
{
currentCreature = item.physicBody.rigidBody;
startLevitate = true;
position = item.transform.position;
}
go.AddComponent<LeviosoUpdate>().Setup(startLevitate, currentCreature,position);
Loader.local.couroutineManager.StartCustomCoroutine(SpawnSparkEffect(Loader.local.leviosoSparks, collision.contacts[0].point));
}
public IEnumerator SpawnSparkEffect(GameObject effect, Vector3 position)
{
effect.transform.position = position;
effect = Instantiate(effect);
effect.GetComponentInChildren<VisualEffect>().Play();
yield return new WaitForSeconds(3f);
Destroy(effect);
}
}
public class LeviosoUpdate : MonoBehaviour
{
private Rigidbody rigidbody;
private bool startLevitate;
private Vector3 position;
private void Start()
{
Loader.local.couroutineManager.StartCustomCoroutine(Loader.local.couroutineManager.StopLeviate(this.gameObject));
}
public void Setup(bool startLevitate, Rigidbody rigid, Vector3 pos)
{
this.rigidbody = rigid;
this.startLevitate = startLevitate;
this.position = pos;
}
private void Update()
{
if (rigidbody)
{
rigidbody.velocity = ((position + (Vector3.up * 4f)) - rigidbody.transform.position) * 5f;
}
}
}
public class LeviosoHandler : 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)
{
try
{
Catalog.GetData<ItemData>(name + "Object")?.SpawnAsync(projectile =>
{
projectile.gameObject.AddComponent(type);
projectile.transform.position = wand.flyDirRef.transform.position;
projectile.transform.rotation = wand.flyDirRef.transform.rotation;
projectile.IgnoreObjectCollision(wand);
projectile.IgnoreRagdollCollision(Player.currentCreature.ragdoll);
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();
}
}
}