OpenHacknet/ActiveMission.cs
afffsdd 7ce3487c21 Clean up
- Fix compile error
 - Fix double casts
2015-10-27 23:26:44 -04:00

211 lines
No EOL
8.3 KiB
C#

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", "hacknetbugs+Hacknet@gmail.com",
"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);
}
}
}