muddesigner/MudEngine/WinPC_Engine/GameScripts/BaseScript.cs
Scionwest_cp c40d32e7ae Basic Realm->Zone->Room combination is now created during World.Initialize(). This will be replaced with loading XML instead of hard-coding.
Newly created characters are assigned to the new World.StartLocation.
Rooms can now be connected.
Realms and Zones can create Zones and Rooms accordingly
Force moving of a character is now supported.  Walking has yet to be implemented.
2012-03-04 16:56:04 -08:00

95 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;
using MudEngine.Game;
using MudEngine.DAL;
using MudEngine.Core;
namespace MudEngine.GameScripts
{
public class BaseScript
{
[DefaultValue("Scripted Object")]
public String Name { get; set; }
public String ID { get; set; }
public String Description { get; set; }
public XMLData SaveData { get; protected set; }
public StandardGame Game { get; private set; }
public BaseScript(StandardGame game, String name, String description)
{
this.Name = name;
this.Description = description;
this.Game = game;
this.ID = Guid.NewGuid().ToString();
this.SaveData = new XMLData(this.GetType().Name);
}
public virtual Boolean Save(String filename)
{
return this.Save(filename, false);
}
public virtual Boolean Save(String filename, Boolean ignoreFileWrite)
{
if (File.Exists(filename))
File.Delete(filename);
try
{
this.SaveData = new XMLData(this.GetType().Name);
this.SaveData.AddSaveData("Name", Name);
this.SaveData.AddSaveData("ID", ID);
this.SaveData.AddSaveData("Description", Description);
if (!ignoreFileWrite)
this.SaveData.Save(filename);
}
catch
{
return false;
}
return true;
}
public virtual void Load(String filename)
{
try
{
if (!File.Exists(filename))
return;
this.SaveData.Load(filename);
this.Name = this.SaveData.GetData("Name");
this.ID = this.SaveData.GetData("ID");
this.Description = this.SaveData.GetData("Description");
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
return;
}
return;
}
public override string ToString()
{
if (String.IsNullOrEmpty(this.Name))
return "{" + this.GetType().Name + "}:" + "Without Name";
else
return "{" + this.GetType().Name + "}:" + this.Name;
}
}
}