-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckController.cs
189 lines (166 loc) · 4.87 KB
/
CheckController.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
using UnityEngine;
using System.Collections;
public class CheckController : MonoBehaviour {
private bool _alive = true;
private GameController gameController;
private TrapController trapController;
private CreatureController creatureController;
private EnemyController enemyController;
private DisplayToolBar displayToolBar;
private enum State
{
Starting,
Checks
}
private State _state;
void Start ()
{
gameController = GetComponent<GameController>();
trapController = GetComponent<TrapController>();
creatureController = GetComponent<CreatureController>();
enemyController = GetComponent<EnemyController>();
displayToolBar = GetComponent<DisplayToolBar>();
StartCoroutine("FSM");
_state = CheckController.State.Starting;
}
void OnDisable()
{
StopAllCoroutines();
}
void OnDestroy()
{
StopAllCoroutines();
}
private IEnumerator FSM()
{
while (_alive)
{
switch (_state)
{
case State.Starting:
Starting();
yield return new WaitForSeconds(0.9f);
break;
case State.Checks:
yield return new WaitForSeconds(1);
// Debug.Log("Checks");
CheckTraps();
CheckCreatures();
CheckEnemies();
displayToolBar.CoolDownControl();
break;
}
yield return null;
}
}
void Starting()
{
if (gameController.players.Count > 0)
{
_state = CheckController.State.Checks;
AdjustDifficulty();
}
}
void CheckTraps ()
{
if (trapController.traps.Count == 0 && trapController.secrets.Count == 0)
{
return;
}
else
{
foreach (GameObject player in gameController.players)
{
trapController.CheckPerPlayer(player);
}
}
}
void CheckCreatures ()
{
// Debug.Log(creatureController.creatures.Count);
if (creatureController.creatures.Count == 0)
{
return;
}
else
{
foreach (GameObject go in creatureController.creatures )
{
creatureController.CheckCreature(gameController, go);
}
}
}
void CheckEnemies ()
{
// Debug.Log(enemyController.enemies.Count);
if (enemyController)
{
if (enemyController.enemies.Count == 0)
{
return;
}
else
{
foreach (GameObject player in gameController.players)
{
enemyController.CheckDistance(player);
}
}
}
}
void AdjustDifficulty ()
{
string difficulty = "";
string realism = "";
if (difficulty == "" || difficulty == "nil")
{
difficulty = "Normal";
}
GetComponent<DisplayOptionsScript>().difficulty = difficulty;
if (realism == "" || realism == "nil")
{
realism = "Epic Fantasy";
}
GetComponent<DisplayOptionsScript>().realism = realism;
}
void AddjustEnemies ()
{
if (GetComponent<DisplayOptionsScript>().difficulty == "Easy")
{
AdjustEasy();
}
else if (GetComponent<DisplayOptionsScript>().difficulty == "Hard")
{
AdjustHard();
}
}
void AdjustEasy ()
{
foreach (GameObject go in GetComponent<EnemyController>().enemies)
{
EnemyStats es = go.GetComponent<EnemyStats>();
es.health = (int)(es.health * 0.7f);
es.curHealth = (int)(es.curHealth * 0.7f);
if (es.defence > 10)
{
es.defence = es.defence - 10;
}
go.GetComponent<EnemyAttack>().attack = (int)(go.GetComponent<EnemyAttack>().attack * 0.7f);
}
}
void AdjustHard ()
{
foreach (GameObject go in GetComponent<EnemyController>().enemies)
{
EnemyStats es = go.GetComponent<EnemyStats>();
es.health = (int)(es.health * 1.3f);
es.curHealth = (int)(es.curHealth * 1.3f);
if (es.defence > 10)
{
es.defence = es.defence + 10;
}
es.armour = (int) (es.armour * 1.1f);
go.GetComponent<EnemyAttack>().attack = (int)(go.GetComponent<EnemyAttack>().attack * 1.30f);
}
}
}