-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathActiveMission.cs
211 lines (198 loc) · 8.28 KB
/
ActiveMission.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
using System;
using System.Collections.Generic;
using System.Xml;
using Hacknet.Mission;
namespace Hacknet
{
internal class ActiveMission
{
public bool activeCheck;
public string client;
private string[] delims = new string[1]
{
"#%#"
};
public int difficulty;
public MailServer.EMailData email;
private string endFunctionName;
private int endFunctionValue;
public Dictionary<string, string> generationKeys;
public string genFile;
public string genOther;
public string genPath;
public string genTarget;
public string genTargetName;
public List<MisisonGoal> goals;
private bool hasFinished;
public string nextMission;
public string[] postingAcceptFlagRequirements;
public string postingBody;
public string postingTitle;
public string reloadGoalsSourceFile;
public int requiredRank;
public bool ShouldIgnoreSenderVerification;
private string startFunctionName;
private int startFunctionValue;
public string target;
public bool wasAutoGenerated;
public bool willSendEmail = true;
public ActiveMission(List<MisisonGoal> _goals, string next, MailServer.EMailData _email)
{
goals = _goals;
nextMission = next;
email = _email;
endFunctionValue = -1;
endFunctionName = "";
postingTitle = postingBody = "";
reloadGoalsSourceFile = "Missions/BitMissionIntro.xml";
}
public void Update(float t)
{
if (!activeCheck || hasFinished || !isComplete(null))
return;
finish();
hasFinished = true;
}
public string getSaveString()
{
var str = "<mission next=\"" + nextMission + "\" goals=\"" + reloadGoalsSourceFile + "\"";
if (wasAutoGenerated)
str = str + " genTarget=\"" + genTarget + "\" genFile=\"" + genFile + "\" genPath=\"" + genPath +
"\" genTargetName=\"" + genTargetName + "\" genOther=\"" + genOther + "\"";
return string.Concat(str, " activeCheck=\"", activeCheck, "\">\n") + "<email sender=\"" + email.sender +
"\" subject=\"" + email.subject + "\">" + Folder.Filter(email.body) + "</email>" +
"<endFunc val=\"" + endFunctionValue + "\" name=\"" + endFunctionName + "\" />" +
"<posting title=\"" + postingTitle + "\">" + Folder.Filter(postingBody) + "</posting>" + "</mission>";
}
public static object load(XmlReader reader)
{
while (reader.Name != "mission")
reader.Read();
reader.MoveToAttribute("next");
var next = reader.ReadContentAsString();
reader.MoveToAttribute("goals");
var filename = reader.ReadContentAsString();
if (reader.MoveToAttribute("genTarget"))
{
var str1 = reader.ReadContentAsString();
reader.MoveToAttribute("genFile");
var str2 = reader.ReadContentAsString();
reader.MoveToAttribute("genPath");
var str3 = reader.ReadContentAsString();
reader.MoveToAttribute("genTargetName");
var str4 = reader.ReadContentAsString();
reader.MoveToAttribute("genOther");
var str5 = reader.ReadContentAsString();
MissionGenerationParser.Comp = str1;
MissionGenerationParser.File = str2;
MissionGenerationParser.Path = str3;
MissionGenerationParser.Target = str4;
MissionGenerationParser.Other = str5;
}
reader.MoveToAttribute("activeChack");
reader.ReadContentAsString().ToLower().Equals("true");
if (next == "NULL_MISSION")
return null;
if (!filename.StartsWith("Content"))
filename = "Content/" + filename;
var _goals = new List<MisisonGoal>();
var activeMission1 = new ActiveMission(new List<MisisonGoal>(), "NONE",
new MailServer.EMailData("Unknown", "Unknown", "Unknown", new List<string>()));
try
{
activeMission1 = (ActiveMission) ComputerLoader.readMission(filename);
_goals = activeMission1.goals;
}
catch (Exception ex)
{
Utils.SendRealWorldEmail("Mission Load Error", "[email protected]",
"Hacknet " + MainMenu.OSVersion + "\r\n" + Utils.GenerateReportFromException(ex));
}
var sendr = "ERRORBOT";
var subj = "ERROR";
var bod = "ERROR :: MAIL LOAD FAILED";
while (reader.Name != "email" && reader.Name != "endFunc")
reader.Read();
if (reader.Name.Equals("email"))
{
if (reader.MoveToAttribute("sender"))
sendr = reader.ReadContentAsString();
if (reader.MoveToAttribute("subject"))
subj = reader.ReadContentAsString();
var num = (int) reader.MoveToContent();
bod = reader.ReadElementContentAsString();
}
var _email = new MailServer.EMailData(sendr, bod, subj, activeMission1.email.attachments);
var activeMission2 = new ActiveMission(_goals, next, _email);
activeMission2.activeCheck = activeMission1.activeCheck;
activeMission2.reloadGoalsSourceFile = filename;
while (reader.Name != "endFunc")
reader.Read();
reader.MoveToAttribute("val");
var num1 = reader.ReadContentAsInt();
reader.MoveToAttribute("name");
var str6 = reader.ReadContentAsString();
activeMission2.endFunctionName = str6;
activeMission2.endFunctionValue = num1;
while (reader.Name != "posting")
reader.Read();
reader.MoveToAttribute("title");
var str7 = reader.ReadContentAsString();
var num2 = (int) reader.MoveToContent();
var str8 = Folder.deFilter(reader.ReadElementContentAsString());
activeMission2.postingTitle = str7;
activeMission2.postingBody = str8;
return activeMission2;
}
public void addEndFunction(int val, string name)
{
endFunctionValue = val;
endFunctionName = name;
}
public void addStartFunction(int val, string name)
{
startFunctionValue = val;
startFunctionName = name;
}
public void ActivateSuppressedStartFunctionIfPresent()
{
if (startFunctionName == null)
return;
MissionFunctions.runCommand(startFunctionValue, startFunctionName);
}
public bool isComplete(List<string> additionalDetails = null)
{
for (var index = 0; index < goals.Count; ++index)
{
if (!goals[index].isComplete(additionalDetails))
return false;
}
return true;
}
public void finish()
{
OS.currentInstance.branchMissions.Clear();
if (!nextMission.Equals("NONE"))
{
ComputerLoader.loadMission("Content/Missions/" + nextMission);
OS.currentInstance.currentMission.ActivateSuppressedStartFunctionIfPresent();
}
else
OS.currentInstance.currentMission = null;
if (endFunctionName != null)
MissionFunctions.runCommand(endFunctionValue, endFunctionName);
OS.currentInstance.saveGame();
if (!OS.currentInstance.multiplayer)
return;
OS.currentInstance.endMultiplayerMatch(true);
}
public void sendEmail(OS os)
{
if (!willSendEmail)
return;
((MailServer) os.netMap.mailServer.getDaemon(typeof (MailServer))).addMail(
MailServer.generateEmail(email.subject, email.body, email.sender, email.attachments),
os.defaultUser.name);
}
}
}