aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/IVirus.cs29
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs2
-rw-r--r--ShiftOS_TheReturn/ShiftOS.Engine.csproj2
-rw-r--r--ShiftOS_TheReturn/VirusManager.cs100
4 files changed, 132 insertions, 1 deletions
diff --git a/ShiftOS_TheReturn/IVirus.cs b/ShiftOS_TheReturn/IVirus.cs
new file mode 100644
index 0000000..0c06aea
--- /dev/null
+++ b/ShiftOS_TheReturn/IVirus.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Engine
+{
+ public interface IVirus
+ {
+ void Infect(int threatlevel);
+ void Disinfect();
+ }
+
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
+ public class VirusAttribute : Attribute
+ {
+ public VirusAttribute(string id, string name, string desc)
+ {
+ Name = name;
+ ID = id;
+ Description = desc;
+ }
+
+ public string Name { get; set; }
+ public string Description { get; set; }
+ public string ID { get; set; }
+ }
+}
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs
index b767605..e20bc08 100644
--- a/ShiftOS_TheReturn/SaveSystem.cs
+++ b/ShiftOS_TheReturn/SaveSystem.cs
@@ -191,7 +191,7 @@ namespace ShiftOS.Engine
{
// "No errors, this never gets called."
Console.WriteLine("[inetd] SEVERE: " + ex.Message);
- string dest = "Startup Exception " + DateTime.Now.ToString() + ".txt";
+ string dest = "Startup Exception " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";
System.IO.File.WriteAllText(dest, ex.ToString());
Console.WriteLine("[inetd] Full exception details have been saved to: " + dest);
Thread.Sleep(3000);
diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
index 9bfa5f9..f1946ad 100644
--- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj
+++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
@@ -136,6 +136,7 @@
<Compile Include="Infobox.cs" />
<Compile Include="IShiftOSWindow.cs" />
<Compile Include="IStatusIcon.cs" />
+ <Compile Include="IVirus.cs" />
<Compile Include="KernelWatchdog.cs" />
<Compile Include="Localization.cs" />
<Compile Include="LoginManager.cs" />
@@ -165,6 +166,7 @@
<Compile Include="TerminalTextWriter.cs" />
<Compile Include="TutorialManager.cs" />
<Compile Include="UserManagementCommands.cs" />
+ <Compile Include="VirusManager.cs" />
<Compile Include="WinOpenAttribute.cs" />
<EmbeddedResource Include="Infobox.resx">
<DependentUpon>Infobox.cs</DependentUpon>
diff --git a/ShiftOS_TheReturn/VirusManager.cs b/ShiftOS_TheReturn/VirusManager.cs
new file mode 100644
index 0000000..74d0e80
--- /dev/null
+++ b/ShiftOS_TheReturn/VirusManager.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ShiftOS.Objects;
+
+namespace ShiftOS.Engine
+{
+ public static class VirusManager
+ {
+ public static List<IVirus> ActiveInfections = new List<IVirus>();
+
+ public static void Init()
+ {
+ ActiveInfections = new List<IVirus>();
+ if (SaveSystem.CurrentSave.ViralInfections == null)
+ SaveSystem.CurrentSave.ViralInfections = new List<ViralInfection>();
+ foreach(var virusdata in SaveSystem.CurrentSave.ViralInfections)
+ {
+ var virus = CreateVirus(virusdata.ID, virusdata.ThreatLevel);
+ var existing = ActiveInfections.FirstOrDefault(x => x.GetType() == virus.GetType());
+ if(existing != null)
+ {
+ var eIndex = ActiveInfections.IndexOf(existing);
+ ActiveInfections[eIndex] = virus;
+ existing.Disinfect();
+ }
+ else
+ {
+ ActiveInfections.Add(virus);
+ }
+ }
+ }
+
+ public static void Infect(string id, int threatlevel)
+ {
+ if (threatlevel < 1)
+ throw new Exception("Threat level can't be below 1.");
+ if (threatlevel > 4)
+ throw new Exception("Threat level can't be above 4.");
+
+ var infection = SaveSystem.CurrentSave.ViralInfections.FirstOrDefault(x => x.ID == id);
+ if (infection != null)
+ {
+ if(infection.ThreatLevel < threatlevel)
+ {
+ infection.ThreatLevel = threatlevel;
+ }
+ }
+ else
+ {
+ SaveSystem.CurrentSave.ViralInfections.Add(new ViralInfection
+ {
+ ID = id,
+ ThreatLevel = threatlevel
+ });
+ }
+ var virus = CreateVirus(id, threatlevel);
+ var existing = ActiveInfections.FirstOrDefault(x => x.GetType() == virus.GetType());
+ if(existing != null)
+ {
+ var eIndex = ActiveInfections.IndexOf(existing);
+ ActiveInfections[eIndex] = virus;
+ existing.Disinfect();
+ }
+ else
+ {
+ ActiveInfections.Add(virus);
+ }
+ }
+
+ internal static IVirus CreateVirus(string id, int threatlevel)
+ {
+ if (threatlevel < 1)
+ throw new Exception("Threat level can't be below 1.");
+ if (threatlevel > 4)
+ throw new Exception("Threat level can't be above 4.");
+
+ foreach(var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IVirus)) && Shiftorium.UpgradeAttributesUnlocked(x)))
+ {
+ var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is VirusAttribute) as VirusAttribute;
+ if(attrib != null)
+ {
+ if(attrib.ID == id)
+ {
+ IVirus virus = (IVirus)Activator.CreateInstance(type);
+ virus.Infect(threatlevel);
+ return virus;
+ }
+ }
+ }
+ {
+
+ }
+
+ throw new Exception("Cannot create virus.");
+ }
+ }
+}