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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ShiftOS
{
public partial class Hacking_Enemy : Form
{
public Hacking_Enemy(Hacking_YourHealth enemy, EnemyHacker thisHacker)
{
ThisHacker = thisHacker;
Enemy = enemy;
InitializeComponent();
}
private EnemyHacker ThisHacker { get; set; }
public Hacking_YourHealth Enemy { get; set; }
public List<Computer> AllComputers = null;
public Computer ThisPC { get; set; }
private void Hacking_Enemy_Load(object sender, EventArgs e)
{
AllComputers = new List<Computer>();
VisualizeNetwork();
tmrhealthdetect.Start();
ThisPC.Enemy = true;
}
private void VisualizeNetwork()
{
var rnd = new Random();
foreach (Module m in ThisHacker.Network)
{
var c = m.Deploy();
if (c.Type == SystemType.Core)
{
ThisPC = c;
ThisPC.EnemyComputer = Enemy.ThisPC;
Enemy.ThisPC.EnemyComputer = ThisPC;
}
c.Location = new Point(rnd.Next(100, 350), rnd.Next(100, 350));
AddModule(c);
}
}
public void System_Attacking(object s, EventArgs a)
{
int i = new Random().Next(Enemy.AllComputers.Count);
var pc = Enemy.AllComputers[i];
var se = (Computer)s;
pc.LaunchAttack(se.GetProperType());
}
public Computer SelectedComputer = null;
public void AddModule(Computer newModule)
{
var rnd = new Random();
panel1.Controls.Add(newModule);
foreach(var pc in AllComputers)
{
while (newModule.Bounds.IntersectsWith(pc.Bounds))
{
newModule.Location = new Point(rnd.Next(100, 350), rnd.Next(100, 350));
}
}
AllComputers.Add(newModule);
int hp = newModule.HP;
TotalHP += (decimal)newModule.HP;
newModule.Show();
newModule.OnDestruction += (object s, EventArgs a) =>
{
if(this.SelectedComputer == newModule)
{
SelectedComputer = null;
}
AllComputers.Remove(newModule);
newModule.Dispose();
};
newModule.Select += (object s, EventArgs a) =>
{
bool c = true;
foreach(var pc in Enemy.SelectedComputer.Enemies)
{
if(pc.Hostname == newModule.Hostname)
{
c = false;
}
}
if (c == true)
{
Enemy.SelectedComputer.Enemies.Add(newModule);
Enemy.ShowPCInfo(Enemy.SelectedComputer.Hostname);
if(Enemy.IsTutorial)
{
if(Enemy.TutorialProgress == 9)
{
Enemy.SetupTutorialUI(10);
}
}
}
};
newModule.HP_Decreased += new EventHandler(System_Damaged);
newModule.OnRepair += new EventHandler(System_Repaired);
if (newModule.Type == SystemType.Antivirus)
{
var b = newModule.GetAreaOfEffect();
newModule.AntivirusRepair += (object s, EventArgs a) =>
{
foreach (Computer pc in AllComputers)
{
if (pc != newModule && pc.Bounds.IntersectsWith(b))
{
if (newModule.Type == SystemType.RepairModule)
{
if (pc.HP < newModule.HP)
{
if (pc.HP < pc.GetTotal())
{
pc.Repair(1);
}
}
}
else {
if (pc.HP < 10)
{
pc.Repair(1);
}
}
}
}
};
}
if (newModule.Type == SystemType.Firewall)
{
panel1.Refresh();
Firewall_Deflect(newModule);
}
if (newModule.Type == SystemType.ServerStack)
{
newModule.MassDDoS += (object s, EventArgs a) =>
{
Enemy.Worm();
};
}
}
public void Firewall_Deflect(Computer fwall)
{
//Safegaurd...
if (fwall.Type == SystemType.Firewall)
{
var r = fwall.GetAreaOfEffect();
foreach (var pc in AllComputers)
{
if (pc != fwall)
{
if (pc.Bounds.IntersectsWith(r))
{
pc.DamageDefector = fwall.Grade;
}
}
}
}
}
public void Firewall_Destroy(Computer fwall)
{
//Safegaurd...
if (fwall.Type == SystemType.Firewall)
{
var r = fwall.GetAreaOfEffect();
foreach (var pc in AllComputers)
{
if (pc.Bounds.IntersectsWith(r))
{
pc.DamageDefector = 1;
UpdateFirewalls();
}
}
}
}
public void UpdateFirewalls()
{
foreach (var pc in AllComputers)
{
if (pc.Type == SystemType.Firewall)
{
Firewall_Deflect(pc);
}
}
}
private void System_Repaired(object s, EventArgs e)
{
var c = (Computer)s;
lbcompromised.Text = "System regenerating...";
int location = c.Left - (lbcompromised.Width / 4);
int y = c.Top - 25;
lbcompromised.Location = new Point(location, y);
lbcompromised.Show();
c.Flash(lbcompromised);
}
private void System_Damaged(object s, EventArgs e)
{
var c = (Computer)s;
lbcompromised.Text = "System damaged!";
int location = c.Left - (lbcompromised.Width / 4);
int y = c.Top - 25;
lbcompromised.Location = new Point(location, y);
lbcompromised.Show();
c.Flash(lbcompromised);
}
private decimal TotalHP = 0;
private void tmrhealthdetect_Tick(object sender, EventArgs e)
{
decimal health = 0;
var rnd = new Random();
int chance = 0;
foreach (var pc in AllComputers)
{
if (pc.Disabled == false)
{
foreach (var enemy in Enemy.AllComputers)
{
chance = rnd.Next(1, 20);
if (chance == 10)
{
if (Enemy.IsTutorial)
{
if (Enemy.TutorialProgress == 9)
{
Enemy.ThisPC.LaunchAttack(pc.GetProperType(), pc.GetDamageRate());
}
else if (Enemy.TutorialProgress == 32)
{
enemy.LaunchAttack(pc.GetProperType(), pc.GetDamageRate());
}
else
{
enemy.Enemies.Clear();
}
}
else {
enemy.LaunchAttack(pc.GetProperType(), pc.GetDamageRate());
}
}
}
}
}
foreach (var pc in AllComputers)
{
health += (decimal)pc.HP;
}
try {
decimal percent = (health / TotalHP) * 100;
lbstats.Text = $"Enemy Health: {percent}%";
if (ThisPC.HP <= 0)
{
if (Enemy.IsTutorial)
{
Enemy.SetupTutorialUI(33);
}
else {
API.CreateInfoboxSession("You won.", "You have successfully overthrown the enemy network.", infobox.InfoboxMode.Info);
UserRequestedClose = false;
Enemy.UserRequestedClose = false;
Enemy.Close();
this.Close();
}
}
}
catch(Exception ex)
{
}
}
public void Worm()
{
var rnd = new Random();
int r = rnd.Next(0, 10);
foreach (Computer c in AllComputers)
{
if(r == 5)
{
c.Disable();
}
}
}
public bool UserRequestedClose = true;
private void this_Closing(object sender, FormClosingEventArgs e)
{
if(UserRequestedClose == false)
{
tmrhealthdetect.Stop();
foreach(var pc in AllComputers)
{
pc.HP = 0;
}
}
}
}
}
|