-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamWorldSettings.cs
More file actions
247 lines (208 loc) · 8.07 KB
/
SteamWorldSettings.cs
File metadata and controls
247 lines (208 loc) · 8.07 KB
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
using System;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace LiveSplit.SteamWorldDig {
public partial class SteamWorldSettings : UserControl {
private SteamWorldMemory mem;
private bool hasLog = true;
private static string LOGFILE = "_SteamWorld.log";
public SteamWorldSettings() {
InitializeComponent();
mem = new SteamWorldMemory();
listDifficulty.SelectedItem = "Speedrunner";
}
private void BtnRandomize_Click(object sender, EventArgs e)
{
btnRandomize.Text = "Randomizing...";
btnRandomize.Enabled = false;
this.UseWaitCursor = true;
// Store all information about items and areas from the game
if (mem.HookProcess())
{
textBoxInfo.Text = "";
/* Generate a new seed if blank */
if (string.IsNullOrWhiteSpace(textSeed.Text))
{
SetSeedBasedOnDifficulty();
}
StringBuilder sb = new StringBuilder();
string difficulty = GetRandomizerDifficulty();
sb.Append("Selecting difficulty is ").AppendLine(difficulty);
textBoxInfo.Text = sb.ToString();
string seed = GetSeed();
if (string.IsNullOrWhiteSpace(seed))
{
btnRandomize.Text = "Randomize";
btnRandomize.Enabled = false;
this.UseWaitCursor = false;
return;
}
int parsedSeed;
if (!int.TryParse(seed, out parsedSeed))
{
MessageBox.Show("Seed must be numeric or blank.", "Seed Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
sb.AppendLine("Seed must be numeric or blank.");
textBoxInfo.Text = sb.ToString();
btnRandomize.Text = "Randomize";
btnRandomize.Enabled = false;
this.UseWaitCursor = false;
return;
}
sb.Append("Seed is ").AppendLine(seed);
textBoxInfo.Text = sb.ToString();
sb.AppendLine("Collecting upgrades...");
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
mem.SaveAllUpgrades();
sb.Append("Found: ").AppendLine(mem.PrintAllUpgrades());
sb.AppendLine("Collecting cave entries...");
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
mem.SaveAllAreaEntries();
sb.Append("Found: ").AppendLine(mem.PrintAllAreaEntries());
sb.AppendLine("Collecting cave exits...");
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
mem.SaveAllAreaExits();
sb.Append("Found: ").AppendLine(mem.PrintAllAreaExits());
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
List<Location> locations;
if (difficulty == "Speedrunner")
{
locations = new LocationsSpeedrunner().Locations;
}
else
{
locations = new LocationsCasual().Locations;
}
SteamWorldRandomizer randomizer = new SteamWorldRandomizer(mem, parsedSeed, locations);
sb.Append("Starting building a randomizer");
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
int ret = 0;
for (int i=0; i<1000; i++)
{
ret = randomizer.Randomize();
if (ret == -1)
{
sb.AppendLine("").AppendLine("Error occured: mismatch number of upgrades");
textBoxInfo.Text = sb.ToString();
break;
}
if (ret == -2)
{
sb.AppendLine("").AppendLine("Error occured: mismatch number of areas");
textBoxInfo.Text = sb.ToString();
break;
}
if (ret == 1)
{
sb.AppendLine("").AppendLine("Successfully found a correct case!");
textBoxInfo.Text = sb.ToString();
break;
}
sb.Append(".");
textBoxInfo.Text = sb.ToString();
textBoxInfo.Update();
}
if (ret == 0)
{
sb.AppendLine("").AppendLine("Could not find any correct case...");
textBoxInfo.Text = sb.ToString();
}
}
btnRandomize.Text = "Randomize";
btnRandomize.Enabled = false;
this.UseWaitCursor = false;
}
private void SetSeedBasedOnDifficulty()
{
switch (listDifficulty.SelectedItem.ToString())
{
case "Casual":
textSeed.Text = string.Format("C{0:0000000}", (new SeedRandom()).Next(10000000));
break;
default:
textSeed.Text = string.Format("S{0:0000000}", (new SeedRandom()).Next(10000000));
break;
}
}
private string GetRandomizerDifficulty()
{
string difficulty = "Speedrunner";
if (textSeed.Text.ToUpper().Contains("C"))
{
difficulty = "Casual";
}
else if (textSeed.Text.ToUpper().Contains("S"))
{
difficulty = "Speedrunner";
}
listDifficulty.SelectedItem = difficulty;
return difficulty;
}
private string GetSeed()
{
if (textSeed.Text.ToUpper().Contains("C"))
{
return textSeed.Text.ToUpper().Replace("C", "");
}
else if (textSeed.Text.ToUpper().Contains("S"))
{
return textSeed.Text.ToUpper().Replace("S", "");
}
MessageBox.Show("The seed string is unrecognized.", "Seed Difficulty", MessageBoxButtons.OK, MessageBoxIcon.Error);
return "";
}
private void WriteLog(string data)
{
if (hasLog || !Console.IsOutputRedirected)
{
if (Console.IsOutputRedirected)
{
using (StreamWriter wr = new StreamWriter(LOGFILE, true))
{
wr.WriteLine(data);
}
}
else
{
Console.WriteLine(data);
}
}
}
public XmlNode UpdateSettings(XmlDocument document)
{
XmlElement xmlSettings = document.CreateElement("Settings");
return xmlSettings;
}
//private void SetSetting(XmlDocument document, XmlElement settings, bool val, string name)
//{
// XmlElement xmlOption = document.CreateElement(name);
// xmlOption.InnerText = val.ToString();
// settings.AppendChild(xmlOption);
//}
public void SetSettings(XmlNode settings)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
//private bool GetSetting(XmlNode settings, string name, bool defaultVal = false)
//{
// XmlNode option = settings.SelectSingleNode(name);
// if (option != null && option.InnerText != "")
// {
// return bool.Parse(option.InnerText);
// }
// return defaultVal;
//}
}
}