Init
Base System Files. Missing 2 Module Scripts.
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
|
||||
namespace KCS
|
||||
{
|
||||
|
||||
public partial class KCS
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.WorldSave += new WorldSaveEventHandler(Save);
|
||||
Load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static Dictionary<string, bool> mRegSyst = new Dictionary<string, bool>();
|
||||
public static Dictionary<string, bool> RegisteredSystem { get { return mRegSyst; } }
|
||||
|
||||
public static void RegisterSystem(string system)
|
||||
{
|
||||
if (mRegSyst.ContainsKey(system))
|
||||
return;
|
||||
|
||||
Type type = Type.GetType(system);
|
||||
if (type == null)
|
||||
{
|
||||
Console.WriteLine("Unauthorized Addon Detected: " + system);
|
||||
return;
|
||||
}
|
||||
|
||||
KCSSystem mSyst = (KCSSystem)Activator.CreateInstance(type);
|
||||
if (mSyst != null)
|
||||
{
|
||||
mRegSyst.Add(system, true);
|
||||
Console.WriteLine("Kitsunic System Registered:" + system);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SystEnabled(string system)
|
||||
{
|
||||
return mRegSyst.ContainsKey(system) && (bool)mRegSyst[system];
|
||||
}
|
||||
|
||||
public static void SystDisabled(string system)
|
||||
{
|
||||
if (mRegSyst.ContainsKey(system))
|
||||
{
|
||||
Type type = ScriptCompiler.FindTypeByFullName(system);
|
||||
if (type != null)
|
||||
{
|
||||
if (!Directory.Exists("Kitsunic"))
|
||||
Directory.CreateDirectory("Kitsunic");
|
||||
|
||||
KCSSystem Syst = (KCSSystem)Activator.CreateInstance(type);
|
||||
if (Syst != null)
|
||||
{
|
||||
Syst.StartSave("Kitsunic/");
|
||||
Syst.Disable();
|
||||
}
|
||||
mRegSyst[system] = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Unauthorized System - {0} - Disabling is Impossible" + system);
|
||||
}
|
||||
|
||||
public static void EnableSystem(string system)
|
||||
{
|
||||
if (mRegSyst.ContainsKey(system))
|
||||
{
|
||||
Type type = ScriptCompiler.FindTypeByFullName(system);
|
||||
if (type != null)
|
||||
{
|
||||
if (!Directory.Exists("Kitsunic"))
|
||||
Directory.CreateDirectory("Kitsunic");
|
||||
|
||||
KCSSystem Syst = (KCSSystem)Activator.CreateInstance(type);
|
||||
if (Syst != null)
|
||||
{
|
||||
Syst.StartLoad("Kitsunic/");
|
||||
Syst.Enable();
|
||||
}
|
||||
mRegSyst[system] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Unauthorized System - {0} - Enabling is Impossible" + system);
|
||||
}
|
||||
|
||||
public static void Save(WorldSaveEventArgs mArgs)
|
||||
{
|
||||
if (!Directory.Exists("Saves/Kitsunic"))
|
||||
Directory.CreateDirectory("Saves/Kitsunic");
|
||||
|
||||
string filename = "Kitsunic.sav";
|
||||
string path = @"Saves/Kitsunic/";
|
||||
string pfilename = path + filename;
|
||||
DateTime start = DateTime.Now;
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(". . . . . . . . .");
|
||||
Console.WriteLine("Brewing Kitsunic Potions. . .");
|
||||
|
||||
try
|
||||
{
|
||||
using (FileStream mFileStream = new FileStream(pfilename, FileMode.OpenOrCreate, FileAccess.Write))
|
||||
{
|
||||
BinaryFileWriter writer = new BinaryFileWriter(mFileStream, true);
|
||||
|
||||
writer.Write((int)mRegSyst.Count);
|
||||
foreach ( KeyValuePair<string,bool> keyValuePair in mRegSyst )
|
||||
{
|
||||
Type type = ScriptCompiler.FindTypeByFullName(keyValuePair.Key);
|
||||
if(type != null)
|
||||
{
|
||||
writer.Write(keyValuePair.Key);
|
||||
writer.Write(keyValuePair.Value);
|
||||
|
||||
if(keyValuePair.Value)
|
||||
{
|
||||
KCSSystem system = (KCSSystem)Activator.CreateInstance(type);
|
||||
if (system != null)
|
||||
system.StartSave(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer.Close();
|
||||
mFileStream.Close();
|
||||
}
|
||||
|
||||
Console.WriteLine("Completing in {0:F1} Seconds.", (DateTime.Now - start).TotalSeconds);
|
||||
Console.WriteLine(". . . . . . .");
|
||||
Console.WriteLine();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Console.WriteLine("Saving Failed. Reason:" + err);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
if (!Directory.Exists("Saves/Kitsunic"))
|
||||
return;
|
||||
|
||||
string filename = "Kitsunic.sav";
|
||||
string path = @"Saves/Kitsunic/";
|
||||
string pfilename = path + filename;
|
||||
DateTime start = DateTime.Now;
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(". . . . . . . . .");
|
||||
Console.WriteLine("Brewing Kitsunic Toxins. . .");
|
||||
|
||||
try
|
||||
{
|
||||
using (FileStream mFileStream = new FileStream(pfilename, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
BinaryReader mBinaryReader = new BinaryReader(mFileStream);
|
||||
BinaryFileReader reader = new BinaryFileReader(mBinaryReader);
|
||||
|
||||
if (mRegSyst == null)
|
||||
mRegSyst = new Dictionary<string, bool>();
|
||||
|
||||
int Count = reader.ReadInt();
|
||||
for(int i = 0; i < Count; i++)
|
||||
{
|
||||
string system = reader.ReadString();
|
||||
Type type = ScriptCompiler.FindTypeByFullName(system);
|
||||
bool enabled = reader.ReadBool();
|
||||
|
||||
if( type != null )
|
||||
{
|
||||
mRegSyst[system] = enabled;
|
||||
|
||||
if (mRegSyst[system])
|
||||
{
|
||||
KCSSystem mSyst = (KCSSystem)Activator.CreateInstance(type);
|
||||
if (mSyst != null)
|
||||
mSyst.StartLoad(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
mFileStream.Close();
|
||||
}
|
||||
|
||||
Console.WriteLine("Completed in {0:F1} seconds.", (DateTime.Now - start).TotalSeconds);
|
||||
Console.WriteLine(". . . . . . . . .");
|
||||
Console.WriteLine();
|
||||
}
|
||||
catch(Exception err )
|
||||
{
|
||||
Console.WriteLine("Loading Failed. Reason:" + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user