-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDotSpawner.cs
executable file
·194 lines (174 loc) · 6.18 KB
/
DotSpawner.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
// DotSpawner.cs
// Nick S.
// Game Logic - AI
using System.Collections.Generic;
using UnityEngine;
using Geo.Command;
using Spawner.Command;
using DotBehaviour.Command;
using Pickup.Command;
using AI.Command;
/*
* Dot Spawner
*
* Spawns Dots as enemies. The serialized fields are passed to the AI's constructors.
*
Public
// Randomly kills an AI. This mimics Darwainism.
void Lottery()
// Spawns a new Dot.
void Spawn()
// Kills a dot- removes it from the list and updates the killer's info.
void Kill(GameObject dead, GameObject killer = null)
*/
public class DotSpawner : MonoBehaviour, ISpawner
{
[SerializeField] public GameObject Player;
/** Spawner Stats **/
[SerializeField] public int NumDots = 15;
[SerializeField] public int ArchetypeCount = 3;
[SerializeField] public float SpawnOffset = 400f;
[SerializeField] public Vector3 SpawnLocation = new Vector3(0, 25, 0);
[SerializeField] public Vector3 InitScale = new Vector3(25, 25, 25);
[SerializeField] public bool EnableTrail = true;
[SerializeField] public bool DrawDebugLine = true;
/** Dot AI Stats **/
[SerializeField] public float Speed = 50;
[SerializeField] public float MaxHealth = 3;
[SerializeField] public float FireRate = 0.05f;
[SerializeField] public float FireChance = 25;
[SerializeField] public float ShieldChance = 25;
[SerializeField] public float Damage = 1;
// Container of alive objects.
private List<GameObject> Alive;
// Global counter to keep track of unique dots.
private int counter = -1;
public void Start()
{
Alive = new List<GameObject>();
transform.position = SpawnLocation;
/*
if (Player != null)
{
var boop = GameObject.Instantiate(Player, transform);
boop.tag = "Player";
}
*/
}
void Update()
{
Lottery(1000f);
if(Alive.Count < NumDots)
{
Spawn();
}
}
// .1% to kill a random dot
public void Lottery(float cap)
{
if (UnityEngine.Random.Range(0, cap) <= 1 && Alive.Count > 0)
{
int index = UnityEngine.Random.Range(0, Alive.Count - 1);
Kill(Alive[index]);
}
}
public void Spawn()
{
counter++;
Vector3 Location = SpawnLocation;
Location.x = UnityEngine.Random.Range(-SpawnOffset, SpawnOffset);
Location.z = UnityEngine.Random.Range(-SpawnOffset, SpawnOffset);
// Add a random Ai controller to the List
int res = UnityEngine.Random.Range(1, 100);
if (res < 33)
{
Debug.Log("Spawned simple dot ai");
GameObject Dot = new GameObject("Geo Simple Dot" + counter);
Dot.transform.position = Location;
Dot.transform.localScale = InitScale;
IAI ai = Dot.AddComponent<DotController>();
ai.init(null, Speed, MaxHealth, FireRate, FireChance, ShieldChance, EnableTrail, DrawDebugLine);
Alive.Add(Dot);
}
else if(res < 66)
{
Debug.Log("Spawned shooter dot ai");
GameObject Dot = new GameObject("Geo Shooter Dot" + counter);
Dot.transform.position = Location;
Dot.transform.localScale = InitScale;
IAI ai = Dot.AddComponent<DotController>();
ShooterDotBehaviour b = Dot.AddComponent<ShooterDotBehaviour>();
b.init(ai);
ai.init(b, Speed, MaxHealth, FireRate, FireChance, ShieldChance, EnableTrail, DrawDebugLine);
Alive.Add(Dot);
}
else
{
Debug.Log("Spawned shield dot ai");
GameObject Dot = new GameObject("Geo Shield Dot" + counter);
Dot.transform.position = Location;
Dot.transform.localScale = InitScale;
IAI ai = Dot.AddComponent<DotController>();
ShieldDotBehaviour b = Dot.AddComponent<ShieldDotBehaviour>();
b.init(ai);
ai.init(b, Speed, MaxHealth, FireRate, FireChance, ShieldChance, EnableTrail, DrawDebugLine);
Alive.Add(Dot);
}
}
public void Kill(GameObject dead, GameObject killer = null)
{
/** Update the killer's score **/
IGeo geo;
if (killer != null && (
dead.ToString().Contains("Dot") ||
dead.ToString().Contains("Player")))
{
if (killer.gameObject.ToString().Contains("Simple Dot"))
{
geo = killer.gameObject.GetComponent<DotController>();
geo.AddKill("Dot");
}
else if (killer.gameObject.ToString().Contains("Shield Dot"))
{
geo = killer.gameObject.GetComponent<DotController>();
geo.AddKill("Dot");
}
else if (killer.gameObject.ToString().Contains("Shooter Dot"))
{
geo = killer.gameObject.GetComponent<DotController>();
geo.AddKill("Dot");
}
else if (killer.gameObject.ToString().Contains("Player"))
{
geo = killer.gameObject.GetComponent<PlayerController>();
geo.AddKill("Dot");
}
}
if (dead.ToString().Contains("Player"))
{
IGeo p = dead.GetComponent<PlayerController>();
p.Respawn();
Debug.Log("You died! Fool- score: " + p.GetScore());
return;
}
/** Kill the dead object **/
Alive.Remove(dead);
IAI[] res = dead.GetComponents<IAI>();
if(res.Length > 0)
{
IAI ai = res[0];
ai.Kill();
}
if(killer != null)
{
Debug.Log(killer.gameObject.ToString() + " killed " + dead.ToString());
}
// Spawn the stat drop.
IPickup pickup = dead.GetComponent<PickupObject>();
if(pickup != null)
{
pickup.Spawn(dead.transform.position + dead.transform.forward*10);
}
Destroy(dead);
}
}