-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpellEntry.cs
173 lines (149 loc) · 6.65 KB
/
SpellEntry.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using ThunderRoad;
using System.Reflection;
using System.Collections;
using UnityEngine.VFX;
//using FirearmAIFix;
using static ThunderRoad.Creature;
namespace WandSpellss
{
class SpellEntry : MonoBehaviour
{
Item wand;
ItemVoiceModule module;
private ItemModuleAI itemModuleAI;
Item current;
Transform parent;
GameObject parentLocal;
float spellSpeed;
bool magicEffect;
float expelliarmusPower;
AudioSource sourceCurrent;
Material evanescoMat;
Item currentItem;
VisualEffect highlighter;
Creature currentCreature;
Color initialItemColor;
Queue<SkinnedMeshRenderer> creatureRenders = new Queue<SkinnedMeshRenderer>();
Queue<Material> materialQueue = new Queue<Material>();
Queue<Renderer> renderersQueue = new Queue<Renderer>();
Material selectorMaterial;
Item currentLumos;
private double castDelayTime;
private bool isDelayingCast;
bool debug;
public void Setup(float importSpeed, bool importMagicEffect, float importExpelliarmusPower)
{
spellSpeed = importSpeed;
magicEffect = importMagicEffect;
expelliarmusPower = importExpelliarmusPower;
}
void Start() {
wand = GetComponent<Item>();
module = wand.data.GetModule<ItemVoiceModule>();
itemModuleAI = wand.data.GetModule<ItemModuleAI>();
AIFireable component = GetComponent<AIFireable>();
//Debug.Log(component.gameObject.GetComponent<FirearmAIFix.AimVisualiserFireable>());
if (component)
{
component.OnAIFire = OnAiFire;
}
//recogWand = wand.gameObject.AddComponent<KeyWordRecogWand>();
wand.OnGrabEvent += Wand_OnGrabEvent;
wand.OnUngrabEvent += Wand_OnUngrabEvent;
selectorMaterial = Loader.local.selectorMat;
debug = false;
}
public bool OnAiFire(AIFireable fireable, RagdollHand ragdollHand, bool finished)
{
var spelLType = "Stupefy";
var spellType = Type.GetType("WandSpellss." + spelLType + "");
TypeSelection(spellType, "Stupefy", GetComponentInParent<Item>());
return true;
}
private void Wand_OnUngrabEvent(Handle handle, RagdollHand ragdollHand, bool throwing)
{
//recogWand.isEnabled = false;
Loader.local.currentlyHeldWands.Remove(this.wand);
Loader.local.currentlyHeldWands.TrimExcess();
}
private void Wand_OnGrabEvent(Handle handle, RagdollHand ragdollHand)
{
Loader.local.currentWand = this.wand;
if (!Loader.local.currentlyHeldWands.Contains(this.wand))
{
Loader.local.currentlyHeldWands.Add(this.wand);
}
}
public void TypeSelection(Type spell, string name, Item wand) {
var spellHandler = Type.GetType(spell.Namespace + "." + name + "Handler");
var field = spellHandler.GetField("spellType", BindingFlags.Public | BindingFlags.Static);
var spellType = field.GetValue(null);
Debug.Log(spellHandler);
Debug.Log(spellType);
if ((SpellType)spellType == SpellType.Shoot)
{
SpellHandler.SpawnSpell(spellHandler, spell, name, wand, spellSpeed);
}
else if ((SpellType)spellType == SpellType.Raycast)
{
SpellHandler.UpdateSpell(spellHandler, spell, name, wand);
}
}
public void TypeSelection(Type spell, string name, Item wand, String itemType)
{
Debug.Log("In Type selection");
name = name.Remove(5).Trim();
Debug.Log(name);
var spellHandler = Type.GetType(spell.Namespace + "." + name + "Handler");
Debug.Log("After handler");
var field = spellHandler.GetField("spellType", BindingFlags.Public | BindingFlags.Static);
Debug.Log("After field");
var spellType = field.GetValue(null);
Debug.Log("After spell type value");
if ((SpellType)spellType == SpellType.Shoot)
{
SpellHandler.SpawnSpell(spellHandler, spell, name, wand, spellSpeed);
}
else if ((SpellType)spellType == SpellType.Raycast)
{
SpellHandler.UpdateSpell(spellHandler, spell, name, wand, itemType);
}
}
void Update() {
//debug for raycast objects being hit
if (debug)
{
if (Physics.Raycast(wand.flyDirRef.transform.position, wand.flyDirRef.transform.forward, out RaycastHit hit, float.MaxValue, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
{
if (hit.collider.GetComponentInParent<Item>() is Item item)
{
Renderer renderer = item.GetComponent<Renderer>();
if (!renderersQueue.Contains(renderer) && !materialQueue.Contains(renderer.material))
{
initialItemColor = renderer.material.GetColor("_BaseColor");
Texture initialAlbedo = renderer.material.GetTexture("_BaseMap");
Texture initialMetallic = renderer.material.GetTexture("_MetallicGlossMap");
Texture initialNormal = renderer.material.GetTexture("_BumpMap");
materialQueue.Enqueue(renderer.material);
renderersQueue.Enqueue(renderer);
selectorMaterial.SetTexture("_ShaderAlbedo", initialAlbedo);
selectorMaterial.SetTexture("_ShaderMetallic", initialMetallic);
selectorMaterial.SetTexture("_ShaderNormal", initialNormal);
renderer.material = selectorMaterial;
}
}
else
{
if (renderersQueue.Count > 0 && renderersQueue.Peek()) renderersQueue.Dequeue().material = materialQueue.Dequeue();
}
}
}
}
}
}