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
|
using Newtonsoft.Json;
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 NetGen : Form
{
public NetGen()
{
InitializeComponent();
}
private EnemyHacker network = null;
private int stage = 0;
private List<Computer> potentialModules = null;
private Module fmod = null;
private void NetGen_Load(object sender, EventArgs e)
{
SetupUI();
potentialModules = new List<Computer>();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
public void SetupUI()
{
btnback.Hide();
switch(stage)
{
case 0:
lbtitle.Text = "Network Information";
lbdescription.Text = "Information about the network.";
pnlnetinf.BringToFront();
break;
case 1:
//create net
network = new EnemyHacker(txtnetname.Text, txtnetdesc.Text, txtnetdesc.Text, 0, 0, "unknown");
var c = network.Network[0].Deploy();
c.Left = (pnlnetdesign.Width - 64) / 2;
c.Top = (pnlnetdesign.Height - 64) / 2;
pnlnetdesign.Controls.Add(c);
c.Select += (s, a) =>
{
ShowSysInf(c);
};
c.Show();
lbtitle.Text = "Playfield Designer";
lbdescription.Text = "Design the playfield of the network. Strategically place defensive and offensive modules to protect the Core from attacks. You can have a maximum of 20 objects (minus core) on-screen.";
pnlnetdesign.BringToFront();
btnnext.Text = "Finish";
break;
case 2:
var tp = new TextPad();
var core = network.Network[0];
core.X = 0;
core.Y = 0;
foreach (var pc in potentialModules)
{
var m = new Module(pc.Type, pc.Grade, pc.Hostname);
m.X = pc.Left;
m.Y = pc.Top;
network.AddModule(m);
}
var json = JsonConvert.SerializeObject(network);
API.CreateForm(tp, "Network JSON", API.GetIcon("TextPad"));
tp.txtuserinput.Text = json;
this.Close();
break;
}
}
private void btnnext_Click(object sender, EventArgs e)
{
stage += 1;
SetupUI();
}
private void btnback_Click(object sender, EventArgs e)
{
stage -= 1;
}
private void btnaddmodule_Click(object sender, EventArgs e)
{
SetupBuyable();
pnlbuy.Visible = !pnlbuy.Visible;
}
List<FutureModule> BuyableModules = null;
public void SetupBuyable()
{
BuyableModules = Hacking.GetFutureModules();
cmbbuyable.Items.Clear();
foreach (var m in BuyableModules)
{
cmbbuyable.Items.Add(m.Name);
}
lbmoduleinfo.Text = "";
txtgrade.Text = "1";
}
private void SetupModuleInfo()
{
bool cont = false;
FutureModule m = null;
foreach (var mod in BuyableModules)
{
if (mod.Name == cmbbuyable.Text)
{
m = mod;
cont = true;
}
}
if (cont == true)
{
lbmoduleinfo.Text = m.Name;
lbmoduleinfo.Text += Environment.NewLine + $"Cost: {m.Cost * Convert.ToInt32(txtgrade.Text)} CP";
lbmoduleinfo.Text += Environment.NewLine + $"Description: {Environment.NewLine}{m.Description}";
}
}
private void cmbbuyable_SelectedIndexChanged(object sender, EventArgs e)
{
SetupModuleInfo();
}
private void txtgrade_TextChanged(object sender, EventArgs e)
{
int grade = 0;
int.TryParse(txtgrade.Text, out grade);
if(grade < 1)
{
txtgrade.Text = "1";
}
else if(grade > 4)
{
txtgrade.Text = "4";
}
}
bool PlacingNewModule = false;
private void btndonebuying_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(cmbbuyable.Text))
{
if(!string.IsNullOrEmpty(cmbbuyable.Text))
{
int grade = Convert.ToInt32(txtgrade.Text);
string hostname = txthostname.Text;
FutureModule m = null;
foreach(var mod in BuyableModules)
{
if(mod.Name == cmbbuyable.Text)
{
m = mod;
}
}
if(m != null)
{
bool cont = true;
if (potentialModules.Count <= 20)
{
foreach (var pc in potentialModules)
{
if (pc.Hostname == hostname)
{
cont = false;
}
}
}
else
{
cont = false;
}
if(cont)
{
var newModule = new Module(m.Type, grade, hostname);
fmod = newModule;
PlacingNewModule = true;
pnlbuy.Hide();
}
else
{
API.CreateInfoboxSession("Can't place new module", "Either an existing module with the same hostname already exists in the field, or you have hit the maximum.", infobox.InfoboxMode.Info);
}
}
}
}
}
private void place_module(object sender, MouseEventArgs e)
{
if (PlacingNewModule == true)
{
if (e.Button == MouseButtons.Left)
{
var coordinates = pnlnetdesign.PointToClient(Cursor.Position);
int x = coordinates.X;
int y = coordinates.Y;
var computerToPlace = fmod.Deploy();
computerToPlace.Location = new Point(x, y);
pnlnetdesign.Controls.Add(computerToPlace);
potentialModules.Add(computerToPlace);
computerToPlace.Select += (s, a) =>
{
ShowSysInf(computerToPlace);
};
computerToPlace.Show();
}
else
{
PlacingNewModule = false;
}
}
}
private Computer SelectedSystem = null;
public void ShowSysInf(Computer pc)
{
pnlpcinfo.Left = pnlbuy.Left;
var nl = Environment.NewLine;
SelectedSystem = pc;
pnlpcinfo.Show();
lbpcinfo.Text = $"Hostname: {SelectedSystem.Hostname}";
lbpcinfo.Text += $"{nl}Max HP: {SelectedSystem.HP}";
lbpcinfo.Text += $"{nl}Grade: {SelectedSystem.Grade}";
lbpcinfo.Text += $"{nl}Type: {SelectedSystem.Type}";
}
private void btndelete_Click(object sender, EventArgs e)
{
if(SelectedSystem != null)
{
potentialModules.Remove(SelectedSystem);
pnlnetdesign.Controls.Remove(SelectedSystem);
SelectedSystem.Dispose();
}
SelectedSystem = null;
pnlpcinfo.Hide();
}
private void btncloseinfo_Click(object sender, EventArgs e)
{
SelectedSystem = null;
pnlpcinfo.Hide();
}
}
}
|