-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHShip.cs
317 lines (281 loc) · 12.5 KB
/
HShip.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HazeronAdviser
{
class HShip : HObj
{
protected string _homesicknessColumn = "-";
public string HomesicknessColumn
{
get { return _homesicknessColumn; }
}
protected int _homesickness = 100;
public int Homesickness
{
get { return _homesickness; }
}
protected string _damageOverview = "";
public string DamageOverview
{
get { return _damageOverview; }
}
protected string _damageColumn = "-";
public string DamageColumn
{
get { return _damageColumn; }
}
protected string _accountOverview = "";
public string AccountOverview
{
get { return _accountOverview; }
}
protected string _accountColumn = "-";
public string AccountColumn
{
get { return _accountColumn; }
}
protected long _accountBalance = 0;
public long AccountBalance
{
get { return _accountBalance; }
}
protected string _fuelColumn = "-";
public string FuelColumn
{
get { return _fuelColumn; }
}
protected int _fuel = 0, _fuelCapacity = 0, _fuelQuality;
public int Fuel
{
get { return _fuel; }
}
public int FuelCapacity
{
get { return _fuelCapacity; }
}
public int FuelQuality
{
get { return _fuelQuality; }
}
protected string _cargoOverview = "";
public string CargoOverview
{
get { return _cargoOverview; }
}
protected string _cargoColumn = "-";
public string CargoColumn
{
get { return _cargoColumn; }
}
protected int _cargo = 0, _cargoCapacity = 0;
public int Cargo
{
get { return _cargo; }
}
public int CargoCapacity
{
get { return _cargoCapacity; }
}
protected string _missionOverview = "";
public string MissionOverview
{
get { return _missionOverview; }
}
protected string _missionColumn = "-";
public string MissionColumn
{
get { return _missionColumn; }
}
protected string _rosterOverview = "";
public string RosterOverview
{
get { return _rosterOverview; }
}
protected string _rosterColumn = "-";
public string RosterColumn
{
get { return _rosterColumn; }
}
protected string _officerName = "-";
public string OfficerName
{
get { return _officerName; }
}
protected string _officerHomeSystem = "-";
public string OfficerHomeSystem
{
get { return _officerHomeSystem; }
}
protected string _officerHomePlanet = "-";
public string OfficerHomePlanet
{
get { return _officerHomePlanet; }
}
protected string _eventOverview = "";
public string EventOverview
{
get { return _eventOverview; }
}
protected string _officerOverview = "";
public string OfficerOverview
{
get { return _officerOverview; }
}
protected List<AttentionMessage> _attentions = new List<AttentionMessage>();
public List<AttentionMessage> Attentions
{
get { return _attentions; }
}
public HShip(HMail mail)
: base(mail)
{
}
public override void Initialize()
{
// String working vars.
int subStart, subEnd;
string[] tempArray;
Dictionary<string, int> sectionsInReport = new Dictionary<string, int>();
string reportSection;
// This is the order of the sections in the mail body, keep them in same order!
const string headlineEVENT = "<b>EVENT LOG</b>";
const string headlineDAMAGE = "<b>DAMAGE REPORT</b>";
const string headlineACCOUNT = "<b>ACCOUNT</b>";
const string headlineFUEL = "<b>FUEL</b>";
const string headlineCARGO = "<b>CARGO</b>";
const string headlineMISSION = "<b>MISSION</b>";
const string headlineROSTER = "<b>ROSTER</b>";
string[] sections = new string[] { headlineEVENT
, headlineDAMAGE
, headlineACCOUNT
, headlineFUEL
, headlineCARGO
, headlineMISSION
, headlineROSTER
};
// Check for sections.
int freakingHell = 0;
foreach (string section in sections)
{
int sigh = _mail.Body.IndexOf(section, freakingHell);
if (sigh >= 0)
{
freakingHell = sigh;
sectionsInReport.Add(section, freakingHell);
}
}
// Time for Ship spicific things.
// Homesickness
if (_mail.Body.Contains("I miss my home; "))
{
subStart = _mail.Body.IndexOf("I miss my home; it's been ") + 26; // "I miss my home; it's been ".Length == 26
subEnd = _mail.Body.Substring(subStart).IndexOf(" days since I last heard from my family.");
_homesickness = 7 - Convert.ToInt32(_mail.Body.Substring(subStart, subEnd));
_homesicknessColumn = " " + _homesickness + " /7 days";
}
// EVENT LOG
if (TryGetSectionText(sectionsInReport, headlineEVENT, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_eventOverview = HShip.EventLogStyle(reportSection);
}
// DAMAGE REPORT
if (TryGetSectionText(sectionsInReport, headlineDAMAGE, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
_damageOverview = reportSection;
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_damageColumn = tempArray[tempArray.Length - 1];
}
else
_damageColumn = "All Systems Ok";
// ACCOUNT
if (TryGetSectionText(sectionsInReport, headlineACCOUNT, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
_accountOverview = reportSection;
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_accountColumn = tempArray[1].Remove(tempArray[1].IndexOf('¢') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_accountBalance = Convert.ToInt64(_accountColumn.Remove(_accountColumn.IndexOf('¢')).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
_accountColumn = _accountBalance.ToString("C", Hazeron.NumberFormat);
}
// FUEL
if (TryGetSectionText(sectionsInReport, headlineFUEL, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
reportSection = reportSection.Substring(16);
_fuelColumn = reportSection.Remove(reportSection.IndexOf(Environment.NewLine) - 11);
tempArray = _fuelColumn.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
_fuel = Convert.ToInt32(tempArray[0].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
_fuelCapacity = Convert.ToInt32(tempArray[tempArray.Length - 1].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
_fuelQuality = Convert.ToInt32(tempArray[1].Substring(1));
_fuelColumn = $"{(float)_fuel / _fuelCapacity * 100}% Q{_fuelQuality}";
}
// CARGO
if (TryGetSectionText(sectionsInReport, headlineCARGO, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
_cargoOverview = reportSection;
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//_cargoColumn = tempArray[tempArray.Length - 1];
}
// MISSION
if (TryGetSectionText(sectionsInReport, headlineMISSION, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
_missionOverview = reportSection;
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//_missionColumn = tempArray[tempArray.Length - 1];
}
// ROSTER
if (TryGetSectionText(sectionsInReport, headlineROSTER, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
_rosterOverview = reportSection;
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//_rosterColumn = tempArray[tempArray.Length - 1];
}
// Officer Info
//// Name
subStart = _mail.Body.IndexOf("<p>") + 3; // "<p>".Length == 3
subEnd = _mail.Body.Substring(subStart).IndexOf("<div style");
_officerName = HHelper.CleanText(_mail.Body.Substring(subStart, subEnd));
//// Home
_officerHomeSystem = "<system name>";
subStart = _mail.Body.IndexOf("I was deployed from ") + 20; // "I was deployed from ".Length == 20
subEnd = _mail.Body.Substring(subStart).IndexOf(" in ");
_officerHomePlanet = HHelper.CleanText(_mail.Body.Substring(subStart, subEnd));
// Officer Overview
_officerOverview = "Location:" + Environment.NewLine;
_officerOverview += " " + _systemName + Environment.NewLine;
_officerOverview += " " + _planetName + Environment.NewLine;
_officerOverview += Environment.NewLine;
_officerOverview += "Officer:" + Environment.NewLine;
_officerOverview += " " + _officerName + Environment.NewLine;
_officerOverview += Environment.NewLine;
_officerOverview += "Officer Home:" + Environment.NewLine;
_officerOverview += " " + _officerHomeSystem + Environment.NewLine;
_officerOverview += " " + _officerHomePlanet + Environment.NewLine;
_officerOverview += Environment.NewLine;
_officerOverview += "Stationed ship:" + Environment.NewLine;
_officerOverview += " " + _name;
// Overview
_overview = "Location:" + Environment.NewLine;
_overview += " " + _systemName + Environment.NewLine;
_overview += " " + _planetName + Environment.NewLine;
if (_eventOverview != "")
_overview += Environment.NewLine + _eventOverview;
// Attentions
if (_homesickness < 7) // Less than 1 week until decay.
_attentions.Add(new AttentionMessage(3, "ColumnHomesickness", "- Homesick." + Environment.NewLine + " Suicide happen in " + _homesickness.ToString() + " days."));
if ((_fuel / (double)_fuelCapacity) <= 0.05 || _fuel <= 50) // No fuel.
_attentions.Add(new AttentionMessage(2, "ColumnFuel", "- No fuel." + Environment.NewLine + " " + Math.Round(_fuel / (double)_fuelCapacity * 100, 2).ToString() + "% fuel remaining."));
else if ((_fuel / (double)_fuelCapacity) <= 0.25) // Low fuel.
_attentions.Add(new AttentionMessage(1, "ColumnFuel", "- Low fuel." + Environment.NewLine + " " + Math.Round(_fuel / (double)_fuelCapacity * 100, 2).ToString() + "% fuel remaining."));
base.Initialize();
}
}
}