Revision: 465
Author: c0der78
Date: Tue Apr 19 15:57:05 2011
Log: arrange source code
http://code.google.com/p/arthea/source/detail?r=465
Modified:
/trunk/ArtheaEditor/AreaEditor.cs
/trunk/ArtheaEditor/ArtheaSplashScreen.cs
/trunk/ArtheaEditor/CollectionEditor.cs
/trunk/ArtheaEditor/EditorForm.cs
/trunk/ArtheaEditor/Import/FileReader.cs
/trunk/ArtheaEditor/Import/IFileReader.cs
/trunk/ArtheaEditor/Import/IImporter.cs
/trunk/ArtheaEditor/Import/ImportException.cs
/trunk/ArtheaEditor/Import/Rom/AreaSection.cs
/trunk/ArtheaEditor/Import/Rom/Converter.cs
/trunk/ArtheaEditor/Import/Rom/FileSection.cs
/trunk/ArtheaEditor/Import/Rom/HelpSection.cs
/trunk/ArtheaEditor/Import/Rom/MobileSection.cs
/trunk/ArtheaEditor/Import/Rom/ObjectSection.cs
/trunk/ArtheaEditor/Import/Rom/ResetSection.cs
/trunk/ArtheaEditor/Import/Rom/RomImporter.cs
/trunk/ArtheaEditor/Import/Rom/RoomSection.cs
/trunk/ArtheaEditor/Import/Rom/ShopSection.cs
/trunk/ArtheaEditor/Import/Rom/SocialSection.cs
/trunk/ArtheaEditor/Import/Rom/SpecialSection.cs
/trunk/ArtheaEditor/ImportDialog.cs
/trunk/ArtheaEditor/Program.cs
/trunk/ArtheaEditor/Properties/AssemblyInfo.cs
/trunk/ArtheaEngine/Argument.cs
/trunk/ArtheaEngine/ArtheaHelper.cs
/trunk/ArtheaEngine/Color.cs
/trunk/ArtheaEngine/Columns.cs
/trunk/ArtheaEngine/Extensions.cs
/trunk/ArtheaEngine/ICommand.cs
/trunk/ArtheaEngine/IConnection.cs
/trunk/ArtheaEngine/IEntity.cs
/trunk/ArtheaEngine/IPersistent.cs
/trunk/ArtheaEngine/IWritable.cs
/trunk/ArtheaEngine/Model/Ability.cs
/trunk/ArtheaEngine/Model/Account.cs
/trunk/ArtheaEngine/Model/Affect.cs
/trunk/ArtheaEngine/Model/Area.cs
/trunk/ArtheaEngine/Model/Board.cs
/trunk/ArtheaEngine/Model/Character.cs
/trunk/ArtheaEngine/Model/Class.cs
/trunk/ArtheaEngine/Model/Exit.cs
/trunk/ArtheaEngine/Model/Help.cs
/trunk/ArtheaEngine/Model/NonPlayer.cs
/trunk/ArtheaEngine/Model/Note.cs
/trunk/ArtheaEngine/Model/Object.cs
/trunk/ArtheaEngine/Model/Player.cs
/trunk/ArtheaEngine/Model/Race.cs
/trunk/ArtheaEngine/Model/Reset.cs
/trunk/ArtheaEngine/Model/Room.cs
/trunk/ArtheaEngine/Model/Shop.cs
/trunk/ArtheaEngine/Model/Skill.cs
/trunk/ArtheaEngine/Model/Social.cs
/trunk/ArtheaEngine/Model/Spell.cs
/trunk/ArtheaEngine/Model/World.cs
/trunk/ArtheaEngine/Money.cs
/trunk/ArtheaEngine/Properties/AssemblyInfo.cs
/trunk/ArtheaEngine/UpdateManager.cs
/trunk/ArtheaEngine.Tests/ArtheaHelperTest.cs
/trunk/ArtheaEngine.Tests/ColorTest.cs
/trunk/ArtheaEngine.Tests/ColumnsTest.cs
/trunk/ArtheaEngine.Tests/ExtensionsTest.cs
/trunk/ArtheaEngine.Tests/MoneyTest.cs
/trunk/ArtheaEngine.Tests/Properties/AssemblyInfo.cs
/trunk/ArtheaEngine.Tests/TestWriter.cs
/trunk/ArtheaServer/ArtheaSplashScreen.cs
/trunk/ArtheaServer/Commands/EditCommand.cs
/trunk/ArtheaServer/Commands/RebootCommand.cs
/trunk/ArtheaServer/Commands/ShutdownCommand.cs
/trunk/ArtheaServer/Creation/AffectEditor.cs
/trunk/ArtheaServer/Creation/AffectsEditor.cs
/trunk/ArtheaServer/Creation/Editor.cs
/trunk/ArtheaServer/Creation/ExitEditor.cs
/trunk/ArtheaServer/Creation/ExitsEditor.cs
/trunk/ArtheaServer/Creation/ObjectEditor.cs
/trunk/ArtheaServer/Creation/ResetEditor.cs
/trunk/ArtheaServer/MainForm.cs
/trunk/ArtheaServer/Program.cs
/trunk/ArtheaServer/TelnetConnection.cs
/trunk/ArtheaServer/TelnetServer.cs
/trunk/Thought.Net.Telnet/AsciiByte.cs
/trunk/Thought.Net.Telnet/ByteBuffer.cs
/trunk/Thought.Net.Telnet/Properties/AssemblyInfo.cs
/trunk/Thought.Net.Telnet/TelnetClient.cs
/trunk/Thought.Net.Telnet/TelnetCommand.cs
/trunk/Thought.Net.Telnet/TelnetCommandEventArgs.cs
/trunk/Thought.Net.Telnet/TelnetCommandEventHandler.cs
/trunk/Thought.Net.Telnet/TelnetListener.cs
/trunk/Thought.Net.Telnet/TelnetListenerEventHandler.cs
/trunk/Thought.Net.Telnet/TelnetOption.cs
/trunk/Thought.Net.Telnet/TelnetOptionEventArgs.cs
/trunk/Thought.Net.Telnet/TelnetOptionEventHandler.cs
/trunk/Thought.Net.Telnet/TelnetOptionLookup.cs
/trunk/Thought.Net.Telnet/TelnetPacket.cs
/trunk/Thought.Net.Telnet/TelnetPacketType.cs
/trunk/Thought.Net.Telnet/TelnetParser.cs
/trunk/Thought.Net.Telnet/TelnetParserState.cs
/trunk/Thought.Net.Telnet/TelnetStream.cs
/trunk/arthea.sql
=======================================
--- /trunk/ArtheaEditor/AreaEditor.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/AreaEditor.cs Tue Apr 19 15:57:05 2011
@@ -1,25 +1,36 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
-using ArtheaEngine.Model;
-using System.Collections;
-using System.Reflection;
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Data;
+ using System.Drawing;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
+ using System.Windows.Forms;
+
+ using ArtheaEngine.Model;
+
public partial class AreaEditor : UserControl
{
+ #region Fields
+
private Dictionary<PropertyInfo, Control> _fields = new
Dictionary<PropertyInfo, Control>();
+ #endregion Fields
+
+ #region Constructors
+
public AreaEditor()
{
InitializeComponent();
}
+
+ #endregion Constructors
+
+ #region Methods
protected override void OnLoad(EventArgs e)
{
@@ -41,5 +52,7 @@
tableLayoutPanel1.Controls.Add(valctl);
}
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/ArtheaSplashScreen.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/ArtheaSplashScreen.cs Tue Apr 19 15:57:05 2011
@@ -1,19 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Data;
+ using System.Drawing;
+ using System.Linq;
+ using System.Text;
+ using System.Windows.Forms;
+
public partial class ArtheaSplashScreen : Form
{
+ #region Constructors
+
public ArtheaSplashScreen()
{
InitializeComponent();
}
+
+ #endregion Constructors
}
}
=======================================
--- /trunk/ArtheaEditor/CollectionEditor.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/CollectionEditor.cs Tue Apr 19 15:57:05 2011
@@ -1,26 +1,34 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.Windows.Forms;
-
-#endregion
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Windows.Forms;
+
public partial class CollectionEditor : UserControl
{
+ #region Constructors
+
public CollectionEditor()
{
InitializeComponent();
Dock = DockStyle.Fill;
}
- private void lstCollection_SelectedIndexChanged(object sender,
EventArgs e)
- {
+ #endregion Constructors
+
+ #region Properties
+
+ public object SelectedItem
+ {
+ get { return lstCollection.SelectedItem; }
}
- public void SetCollection<T>(IList<T> items) where T : class
+ #endregion Properties
+
+ #region Methods
+
+ public void SetCollection<T>(IList<T> items)
+ where T : class
{
lstCollection.DataSource = items;
}
@@ -31,9 +39,10 @@
splitContainer1.Panel2.Controls.Add(ctl);
}
- public object SelectedItem
- {
- get { return lstCollection.SelectedItem; }
- }
+ private void lstCollection_SelectedIndexChanged(object sender,
EventArgs e)
+ {
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/EditorForm.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/EditorForm.cs Tue Apr 19 15:57:05 2011
@@ -1,23 +1,28 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows.Forms;
-using ArtheaEngine.Model;
-using ArtheaEditor.Import.Rom;
-using Object = ArtheaEngine.Model.Object;
-
-#endregion
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Windows.Forms;
+
+ using ArtheaEditor.Import.Rom;
+
+ using ArtheaEngine.Model;
+
+ using Object = ArtheaEngine.Model.Object;
+
public partial class EditorForm : Form
{
+ #region Constructors
+
public EditorForm()
{
InitializeComponent();
}
+
+ #endregion Constructors
+
+ #region Methods
private static Panel CreateFieldEditor<T>(object obj)
{
@@ -51,24 +56,26 @@
return layout;
}
- private void saveToolStripMenuItem_Click(object sender, EventArgs
e)
- {
- }
-
- private void riversOfMudToolStripMenuItem_Click(object sender,
EventArgs e)
- {
-
- new ImportDialog(new RomImporter()).ShowDialog();
+ private void areasToolStripMenuItem_Click(object sender, EventArgs
e)
+ {
+ var ed = new CollectionEditor();
+
+ ed.SetCollection(Area.List.ToList());
+
+ ed.SetEditor(new AreaEditor());
+
+ Controls.Clear();
+ Controls.Add(ed);
}
- private void smaugToolStripMenuItem_Click(object sender, EventArgs
e)
+ private void circleToolStripMenuItem_Click(object sender,
EventArgs e)
{
MessageBox.Show("Not Supported Yet.", "Unsupported",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
- private void circleToolStripMenuItem_Click(object sender,
EventArgs e)
- {
- MessageBox.Show("Not Supported Yet.", "Unsupported",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ private void riversOfMudToolStripMenuItem_Click(object sender,
EventArgs e)
+ {
+ new ImportDialog(new RomImporter()).ShowDialog();
}
private void rOTToolStripMenuItem_Click(object sender, EventArgs e)
@@ -76,16 +83,15 @@
MessageBox.Show("Not Supported Yet.", "Unsupported",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
- private void areasToolStripMenuItem_Click(object sender, EventArgs
e)
- {
- var ed = new CollectionEditor();
-
- ed.SetCollection(Area.List.ToList());
-
- ed.SetEditor(new AreaEditor());
-
- Controls.Clear();
- Controls.Add(ed);
- }
+ private void saveToolStripMenuItem_Click(object sender, EventArgs
e)
+ {
+ }
+
+ private void smaugToolStripMenuItem_Click(object sender, EventArgs
e)
+ {
+ MessageBox.Show("Not Supported Yet.", "Unsupported",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/FileReader.cs Tue Mar 29 00:43:30 2011
+++ /trunk/ArtheaEditor/Import/FileReader.cs Tue Apr 19 15:57:05 2011
@@ -1,28 +1,49 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.IO;
-using ArtheaEngine.Model;
-using NLog;
-
-namespace ArtheaEditor.Import
-{
+namespace ArtheaEditor.Import
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine.Model;
+
+ using NLog;
public class FileReader
{
+ #region Fields
+
private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
private readonly string _file;
+
private int _line;
private int _pos;
+ #endregion Fields
+
+ #region Constructors
+
public FileReader(string path)
{
_file = File.ReadAllText(path);
_pos = 0;
_line = 0;
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public bool EndOfFile
+ {
+ get { return _pos >= _file.Length - 1; }
+ }
+
+ #endregion Properties
+
+ #region Methods
public static long FlagConvert(char letter)
{
@@ -44,14 +65,6 @@
return bitsum;
}
-
- private char Read()
- {
- char c = _file[_pos++];
- if (c == '\n')
- _line++;
- return c;
- }
public long ReadFlag()
{
@@ -92,7 +105,6 @@
letter = Read();
} while (char.IsWhiteSpace(letter));
-
return letter;
}
@@ -258,10 +270,14 @@
}
}
- public bool EndOfFile
- {
- get { return _pos >= _file.Length - 1; }
- }
- }
-
-}
+ private char Read()
+ {
+ char c = _file[_pos++];
+ if (c == '\n')
+ _line++;
+ return c;
+ }
+
+ #endregion Methods
+ }
+}
=======================================
--- /trunk/ArtheaEditor/Import/IFileReader.cs Mon Mar 28 23:33:46 2011
+++ /trunk/ArtheaEditor/Import/IFileReader.cs Tue Apr 19 15:57:05 2011
@@ -1,10 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace ArtheaEditor.Import
-{
+namespace ArtheaEditor.Import
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
interface IFileReader
{
}
=======================================
--- /trunk/ArtheaEditor/Import/IImporter.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/Import/IImporter.cs Tue Apr 19 15:57:05 2011
@@ -1,14 +1,19 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.IO;
-
-namespace ArtheaEditor.Import
-{
+namespace ArtheaEditor.Import
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+
public interface IImporter
{
+ #region Methods
+
void Commit();
+
void Process(FileInfo fi);
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/ImportException.cs Mon Mar 28 23:33:46 2011
+++ /trunk/ArtheaEditor/Import/ImportException.cs Tue Apr 19 15:57:05 2011
@@ -1,27 +1,34 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Runtime.Serialization;
-
-namespace ArtheaEditor.Import
-{
+namespace ArtheaEditor.Import
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Runtime.Serialization;
+ using System.Text;
+
public class ImportException : Exception
{
- public ImportException(string msg) : base(msg)
+ #region Constructors
+
+ public ImportException(string msg)
+ : base(msg)
{
}
- public ImportException(string msg, Exception inner)
- : base(msg, inner)
- { }
-
- public ImportException(SerializationInfo info, StreamingContext
context)
- : base(info, context)
- { }
+ public ImportException(string msg, Exception inner)
+ : base(msg, inner)
+ {
+ }
+
+ public ImportException(SerializationInfo info, StreamingContext
context)
+ : base(info, context)
+ {
+ }
public ImportException()
{
}
+
+ #endregion Constructors
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/AreaSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/AreaSection.cs Tue Apr 19 15:57:05 2011
@@ -1,33 +1,45 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using NLog;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class AreaSection : FileSection
{
+ #region Constructors
+
public AreaSection()
{
Loaded = new List<Area>();
}
+
+ #endregion Constructors
+
+ #region Properties
+
public List<Area> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
- foreach (Area a in Loaded)
+ foreach (Area a in Loaded)
{
a.Save(conn);
}
-
}
public override void Load(FileReader reader)
@@ -41,23 +53,6 @@
LoadNewFormat(reader);
else
LoadOldFormat(reader);
-
-
- }
-
- private void LoadOldFormat(FileReader reader)
- {
- var area = new Area();
-
- reader.ReadString(); // filename
- area.Name = reader.ReadString();
- area.Credits = reader.ReadString();
- reader.ReadNumber(); // min vnum
- reader.ReadNumber(); // max vnum
-
- Loaded.Add(area);
-
- RomImporter.CurrentArea = area;
}
private void LoadNewFormat(FileReader reader)
@@ -104,5 +99,22 @@
}
}
}
+
+ private void LoadOldFormat(FileReader reader)
+ {
+ var area = new Area();
+
+ reader.ReadString(); // filename
+ area.Name = reader.ReadString();
+ area.Credits = reader.ReadString();
+ reader.ReadNumber(); // min vnum
+ reader.ReadNumber(); // max vnum
+
+ Loaded.Add(area);
+
+ RomImporter.CurrentArea = area;
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/Converter.cs Tue Mar 29 00:43:30 2011
+++ /trunk/ArtheaEditor/Import/Rom/Converter.cs Tue Apr 19 15:57:05 2011
@@ -1,15 +1,40 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using NLog;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public static class Converter
{
+ #region Methods
+
+ public static NpcFlag ConvertActFlags(long bits)
+ {
+ var convertTable = new Dictionary<char, NpcFlag>();
+ NpcFlag flags = 0;
+
+ convertTable.Add('B', NpcFlag.Sentinel);
+ convertTable.Add('F', NpcFlag.Aggressive);
+ convertTable.Add('G', NpcFlag.StayArea);
+ convertTable.Add('H', NpcFlag.Wimpy);
+
+ foreach (var entry in convertTable)
+ {
+ if (bits.HasFlag(FileReader.FlagConvert(entry.Key)))
+ {
+ flags |= entry.Value;
+ }
+ }
+
+ return flags;
+ }
+
public static string ConvertActTags(string format, int charIndex)
{
format = format.Replace("$n", "{" + charIndex + "}");
@@ -37,87 +62,6 @@
return format;
}
-
- public static Position ConvertPosition(string posName)
- {
-
- try
- {
- return (Position)Enum.Parse(typeof(Position), posName,
true);
- }
- catch (ArgumentException)
- {
- LogManager.GetCurrentClassLogger().Warn("unknown position
{0}", posName);
- return Position.Standing;
- }
- }
-
- public static Position ConvertPosition(int pos)
- {
- return (Position)pos;
- }
-
- public static Sex ConvertSex(string sex)
- {
- try
- {
- return (Sex)Enum.Parse(typeof(Sex), sex, true);
- }
- catch (ArgumentException)
- {
- LogManager.GetCurrentClassLogger().Warn("unknown sex {0}",
sex);
- return Sex.Neutral;
- }
- }
-
- public static Sex ConvertSex(int sex)
- {
- return (Sex)sex;
- }
-
- public static float ConvertSize(string size)
- {
- try
- {
- return (float)Enum.Parse(typeof(Size), size, true);
- }
- catch (ArgumentException)
- {
- LogManager.GetCurrentClassLogger().Warn("unknown size
{0}", size);
- return (float)Size.Medium;
- }
- }
-
- public static Race ConvertRace(string name)
- {
- Race r = Race.Lookup(name);
-
- if (r != null)
- return r;
-
- return Race.Lookup("unique");
- }
-
- public static NpcFlag ConvertActFlags(long bits)
- {
- var convertTable = new Dictionary<char, NpcFlag>();
- NpcFlag flags = 0;
-
- convertTable.Add('B', NpcFlag.Sentinel);
- convertTable.Add('F', NpcFlag.Aggressive);
- convertTable.Add('G', NpcFlag.StayArea);
- convertTable.Add('H', NpcFlag.Wimpy);
-
- foreach (var entry in convertTable)
- {
- if (bits.HasFlag(FileReader.FlagConvert(entry.Key)))
- {
- flags |= entry.Value;
- }
- }
-
- return flags;
- }
public static AffectLocation ConvertAffectLocation(int where)
{
@@ -159,6 +103,26 @@
return flags;
}
+ public static Direction ConvertDirection(int door)
+ {
+ switch (door)
+ {
+ case 0:
+ return Direction.North;
+ case 1:
+ return Direction.East;
+ case 2:
+ return Direction.South;
+ case 3:
+ return Direction.West;
+ case 4:
+ return Direction.Up;
+ case 5:
+ return Direction.Down;
+ default:
+ throw new ImportException("Invalid direction on room "
+ door);
+ }
+ }
public static ExitFlag ConvertExitFlags(long bits)
{
@@ -197,7 +161,6 @@
}
return itemFlags;
}
-
public static long ConvertFurnitureFlags(long bits)
{
@@ -244,6 +207,15 @@
return flags;
}
+ public static ObjectType ConvertObjectType(string p)
+ {
+ throw new NotImplementedException();
+ }
+
+ public static ObjectType ConvertObjectType(int t)
+ {
+ return (ObjectType)t;
+ }
public static long ConvertPortalFlags(long bits)
{
@@ -263,54 +235,33 @@
return flags;
}
- public static long ConvertWeaponFlags(long bits)
- {
- return bits;
- }
-
- public static WearFlag ConvertWearFlags(long bits)
- {
- var convertTable = new Dictionary<char, WearFlag>();
- WearFlag flags = 0;
-
- //convertTable.Add('P', Object.NoSacrifice);
-
- if (!bits.HasFlag(FileReader.FlagConvert('A')))
- {
- //flags |= Object.Static;
- }
-
- foreach (var entry in convertTable)
- {
- if (bits.HasFlag(FileReader.FlagConvert(entry.Key)))
- {
- flags |= entry.Value;
- }
- }
- return flags;
+ public static Position ConvertPosition(string posName)
+ {
+ try
+ {
+ return (Position)Enum.Parse(typeof(Position), posName,
true);
+ }
+ catch (ArgumentException)
+ {
+ LogManager.GetCurrentClassLogger().Warn("unknown position
{0}", posName);
+ return Position.Standing;
+ }
}
- public static Direction ConvertDirection(int door)
- {
- switch (door)
- {
- case 0:
- return Direction.North;
- case 1:
- return Direction.East;
- case 2:
- return Direction.South;
- case 3:
- return Direction.West;
- case 4:
- return Direction.Up;
- case 5:
- return Direction.Down;
- default:
- throw new ImportException("Invalid direction on room "
+ door);
- }
+ public static Position ConvertPosition(int pos)
+ {
+ return (Position)pos;
}
+ public static Race ConvertRace(string name)
+ {
+ Race r = Race.Lookup(name);
+
+ if (r != null)
+ return r;
+
+ return Race.Lookup("unique");
+ }
public static RoomFlag ConvertRoomFlags(long bits)
{
@@ -359,9 +310,40 @@
return Terrain.Inside;
}
}
- public static WeaponClass ConvertWeaponClass(string weaponType)
- {
-
+
+ public static Sex ConvertSex(string sex)
+ {
+ try
+ {
+ return (Sex)Enum.Parse(typeof(Sex), sex, true);
+ }
+ catch (ArgumentException)
+ {
+ LogManager.GetCurrentClassLogger().Warn("unknown sex {0}",
sex);
+ return Sex.Neutral;
+ }
+ }
+
+ public static Sex ConvertSex(int sex)
+ {
+ return (Sex)sex;
+ }
+
+ public static float ConvertSize(string size)
+ {
+ try
+ {
+ return (float)Enum.Parse(typeof(Size), size, true);
+ }
+ catch (ArgumentException)
+ {
+ LogManager.GetCurrentClassLogger().Warn("unknown size
{0}", size);
+ return (float)Size.Medium;
+ }
+ }
+
+ public static WeaponClass ConvertWeaponClass(string weaponType)
+ {
try
{
return (WeaponClass)Enum.Parse(typeof(WeaponClass),
weaponType, true);
@@ -370,17 +352,35 @@
{
return WeaponClass.Exotic;
}
-
}
- public static ObjectType ConvertObjectType(string p)
- {
- throw new NotImplementedException();
+ public static long ConvertWeaponFlags(long bits)
+ {
+ return bits;
}
- public static ObjectType ConvertObjectType(int t)
- {
- return (ObjectType)t;
- }
+ public static WearFlag ConvertWearFlags(long bits)
+ {
+ var convertTable = new Dictionary<char, WearFlag>();
+ WearFlag flags = 0;
+
+ //convertTable.Add('P', Object.NoSacrifice);
+
+ if (!bits.HasFlag(FileReader.FlagConvert('A')))
+ {
+ //flags |= Object.Static;
+ }
+
+ foreach (var entry in convertTable)
+ {
+ if (bits.HasFlag(FileReader.FlagConvert(entry.Key)))
+ {
+ flags |= entry.Value;
+ }
+ }
+ return flags;
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/FileSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/FileSection.cs Tue Apr 19 15:57:05 2011
@@ -1,14 +1,19 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Data;
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
public abstract class FileSection
{
+ #region Methods
+
public abstract void Commit(IDbConnection conn);
public abstract void Load(FileReader reader);
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/HelpSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/HelpSection.cs Tue Apr 19 15:57:05 2011
@@ -1,31 +1,43 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using NLog;
-using System.Data;
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class HelpSection : FileSection
{
+ #region Constructors
+
public HelpSection()
{
Loaded = new List<Help>();
}
+
+ #endregion Constructors
+
+ #region Properties
+
public List<Help> Loaded
{
get;
private set;
}
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
- foreach (Help help in Loaded)
+ foreach (Help help in Loaded)
help.Save(conn);
-
}
public override void Load(FileReader reader)
@@ -57,5 +69,7 @@
LogManager.GetCurrentClassLogger().Info("Loaded {0} helps.",
count);
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/MobileSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/MobileSection.cs Tue Apr 19 15:57:05 2011
@@ -1,35 +1,51 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using NLog;
-using System.Data;
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class MobileSection : FileSection
{
+ #region Fields
+
private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+ #endregion Fields
+
+ #region Constructors
+
public MobileSection()
{
Loaded = new Dictionary<int, NonPlayer>();
}
+
+ #endregion Constructors
+
+ #region Properties
public Dictionary<int, NonPlayer> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
- foreach (var npc in Loaded)
+ foreach (var npc in Loaded)
{
npc.Value.Save(conn);
}
-
}
public override void Load(FileReader reader)
@@ -54,7 +70,6 @@
public void LoadNewFormat(FileReader reader)
{
-
while (!reader.EndOfFile)
{
if (reader.ReadLetter() != '#')
@@ -101,7 +116,7 @@
reader.ReadNumber();
reader.ReadLetter();
reader.ReadNumber();
-
+
/* damage dice */
reader.ReadNumber();
reader.ReadLetter();
@@ -167,88 +182,90 @@
}
}
- private void LoadOldFormat(FileReader reader)
- {
- for (;;) {
- char letter = reader.ReadLetter();
- if (letter != '#') {
- throw new ImportException("# not found");
- }
- int vnum = reader.ReadNumber();
- if (vnum == 0)
- break;
-
- // TODO: check mob exists
-
- NonPlayer npc = new NonPlayer();
+ private void LoadOldFormat(FileReader reader)
+ {
+ for (;;) {
+ char letter = reader.ReadLetter();
+ if (letter != '#') {
+ throw new ImportException("# not found");
+ }
+ int vnum = reader.ReadNumber();
+ if (vnum == 0)
+ break;
+
+ // TODO: check mob exists
+
+ NonPlayer npc = new NonPlayer();
npc.Area = RomImporter.CurrentArea;
- npc.Name = reader.ReadString();
- npc.ShortDescr = reader.ReadString();
- npc.LongDescr = reader.ReadString();
- npc.Description = reader.ReadString();
+ npc.Name = reader.ReadString();
+ npc.ShortDescr = reader.ReadString();
+ npc.LongDescr = reader.ReadString();
+ npc.Description = reader.ReadString();
npc.Flags = Converter.ConvertActFlags(reader.ReadFlag());
- reader.ReadFlag(); // affected_by
- reader.ReadNumber(); // alignment
-
- letter = reader.ReadLetter();
-
- npc.Level = (short) reader.ReadNumber();
-
- reader.ReadNumber();
- reader.ReadNumber();
- reader.ReadNumber();
- reader.ReadLetter();
- reader.ReadNumber();
- reader.ReadLetter();
- reader.ReadNumber();
-
- reader.ReadNumber();
- reader.ReadLetter();
- reader.ReadNumber();
- reader.ReadLetter();
- reader.ReadNumber();
-
- reader.ReadNumber(); // wealth
- reader.ReadNumber(); // xp?
+ reader.ReadFlag(); // affected_by
+ reader.ReadNumber(); // alignment
+
+ letter = reader.ReadLetter();
+
+ npc.Level = (short) reader.ReadNumber();
+
+ reader.ReadNumber();
+ reader.ReadNumber();
+ reader.ReadNumber();
+ reader.ReadLetter();
+ reader.ReadNumber();
+ reader.ReadLetter();
+ reader.ReadNumber();
+
+ reader.ReadNumber();
+ reader.ReadLetter();
+ reader.ReadNumber();
+ reader.ReadLetter();
+ reader.ReadNumber();
+
+ reader.ReadNumber(); // wealth
+ reader.ReadNumber(); // xp?
npc.Position = Converter.ConvertPosition(reader.ReadNumber());
// start
- // position
-
+
//
position
+
Converter.ConvertPosition(reader.ReadNumber()); // default
- // position
-
- npc.Sex = Converter.ConvertSex(reader.ReadNumber());
-
- Argument arg = new Argument(npc.Name);
-
- npc.Race = Converter.ConvertRace(arg.Next());
-
- if (npc.Race == null) {
+
//
position
+
+ npc.Sex = Converter.ConvertSex(reader.ReadNumber());
+
+ Argument arg = new Argument(npc.Name);
+
+ npc.Race = Converter.ConvertRace(arg.Next());
+
+ if (npc.Race == null) {
npc.Race = Race.Lookup("unique");
- }
-
- if (letter != 'S') {
- throw new ImportException("vnum " + vnum + " bad subformat");
- }
-
- Loaded.Add(vnum, npc);
- }
- }
-
- private int[] ReadDice(FileReader reader) {
- int[] dice = new int[3];
-
- dice[0] = reader.ReadNumber();
- reader.ReadLetter();
- dice[1] = reader.ReadNumber();
- reader.ReadLetter();
- dice[2] = reader.ReadNumber();
-
- return dice;
-
- }
+ }
+
+ if (letter != 'S') {
+ throw new ImportException("vnum " + vnum + " bad
subformat");
+ }
+
+ Loaded.Add(vnum, npc);
+ }
+ }
+
+ private int[] ReadDice(FileReader reader)
+ {
+ int[] dice = new int[3];
+
+ dice[0] = reader.ReadNumber();
+ reader.ReadLetter();
+ dice[1] = reader.ReadNumber();
+ reader.ReadLetter();
+ dice[2] = reader.ReadNumber();
+
+ return dice;
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/ObjectSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/ObjectSection.cs Tue Apr 19 15:57:05 2011
@@ -1,40 +1,52 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Object = ArtheaEngine.Model.Object;
-using ArtheaEngine;
-using NLog;
-using ArtheaEngine.Model;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
+ using Object = ArtheaEngine.Model.Object;
+
public class ObjectSection : FileSection
{
+ #region Constructors
+
public ObjectSection()
{
Loaded = new Dictionary<int, Object>();
}
+
+ #endregion Constructors
+
+ #region Properties
public Dictionary<int, Object> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
- foreach (var obj in Loaded)
+ foreach (var obj in Loaded)
obj.Value.Save(conn);
-
}
public override void Load(FileReader reader)
{
Load(reader, true);
-
- }
+ }
+
public void Load(FileReader reader, bool newFormat)
{
if (RomImporter.CurrentArea == null)
@@ -184,8 +196,6 @@
reader.ReadFlag();
break;
}
-
-
item.Level = Convert.ToInt16(reader.ReadNumber());
item.Weight = Convert.ToInt16(reader.ReadNumber());
@@ -271,6 +281,7 @@
Loaded.Add(id, item);
}
}
+
public void LoadOldFormat(FileReader reader)
{
for (; ; )
@@ -346,5 +357,7 @@
Loaded.Add(vnum, obj);
}
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/ResetSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/ResetSection.cs Tue Apr 19 15:57:05 2011
@@ -1,41 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NLog;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using System.Data;
-namespace ArtheaEditor.Import.Rom
-{
- public class TempReset
- {
- public int arg1, arg2, arg3, arg4;
- public char command;
- public List<TempReset> subResets = new List<TempReset>();
- };
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
public class ResetSection : FileSection
{
+ #region Fields
+
static readonly Logger Log = LogManager.GetCurrentClassLogger();
+ #endregion Fields
+
+ #region Constructors
+
public ResetSection(RomImporter importer)
{
Loaded = new List<TempReset>();
Importer = importer;
}
- public RomImporter Importer { get; set; }
+ #endregion Constructors
+
+ #region Properties
+
+ public RomImporter Importer
+ {
+ get; set;
+ }
public IList<TempReset> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
- foreach (TempReset temp in Loaded)
+ foreach (TempReset temp in Loaded)
{
StringBuilder buf = new StringBuilder();
@@ -115,7 +128,6 @@
break;
}
}
-
Reset reset = new Reset(room);
@@ -227,14 +239,25 @@
default:
throw new ImportException("Unknown reset type " +
letter);
}
-
if (temp.command == 'M' || temp.command == 'O')
Loaded.Add(temp);
}
-
LogManager.GetCurrentClassLogger().Info("Loaded {0} resets.",
count);
}
+
+ #endregion Methods
+ }
+
+ public class TempReset
+ {
+ #region Fields
+
+ public int arg1, arg2, arg3, arg4;
+ public char command;
+ public List<TempReset> subResets = new List<TempReset>();
+
+ #endregion Fields
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/RomImporter.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/Import/Rom/RomImporter.cs Tue Apr 19 15:57:05 2011
@@ -1,30 +1,39 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Linq;
-using NLog;
-using Object=ArtheaEngine.Model.Object;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using ArtheaEditor.Import;
-using Conv = ArtheaEditor.Import.Rom.Converter;
-#endregion
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEditor.Import;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
+ using Conv = ArtheaEditor.Import.Rom.Converter;
+
+ using Object = ArtheaEngine.Model.Object;
+
public class RomImporter : IImporter
{
+ #region Fields
+
private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+
+ private readonly List<Area> _areas = new List<Area>();
private readonly Dictionary<int, NonPlayer> _characterIndexes =
new Dictionary<int, NonPlayer>();
private readonly Dictionary<int, Object> _objectIndexes = new
Dictionary<int, Object>();
private readonly Dictionary<int, Room> _roomIndexes = new
Dictionary<int, Room>();
- private readonly List<Area> _areas = new List<Area>();
+
private FileInfo _file;
private FileReader _reader;
+ #endregion Fields
+
+ #region Constructors
public RomImporter()
{
@@ -39,39 +48,48 @@
Specials = new SpecialSection();
}
- public HelpSection Helps
- {
- get;
- private set;
+ #endregion Constructors
+
+ #region Properties
+
+ public static Area CurrentArea
+ {
+ get; set;
}
- public RoomSection Rooms
+ public AreaSection Areas
{
get;
private set;
}
- public ResetSection Resets
+ public HelpSection Helps
{
get;
private set;
}
+
+ public MobileSection Mobiles
+ {
+ get; private set;
+ }
public ObjectSection Objects
- { get; private set; }
-
- public AreaSection Areas
+ {
+ get; private set;
+ }
+
+ public ResetSection Resets
{
get;
private set;
}
- public SocialSection Socials
+ public RoomSection Rooms
{
get;
private set;
}
-
public ShopSection Shops
{
@@ -79,13 +97,21 @@
private set;
}
- public MobileSection Mobiles { get; private set; }
+ public SocialSection Socials
+ {
+ get;
+ private set;
+ }
public SpecialSection Specials
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public void Commit()
{
@@ -117,7 +143,6 @@
}
}
}
- public static Area CurrentArea { get; set; }
public void Process(FileInfo fileInfo)
{
@@ -208,5 +233,6 @@
}
}
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/RoomSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/RoomSection.cs Tue Apr 19 15:57:05 2011
@@ -1,39 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using NLog;
-using ArtheaEngine;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class RoomSection : FileSection
{
+ #region Fields
+
static readonly Logger Log = LogManager.GetCurrentClassLogger();
+ #endregion Fields
+
+ #region Constructors
+
public RoomSection()
{
Loaded = new Dictionary<int, Room>();
Exits = new Dictionary<Exit, int>();
}
- public Dictionary<int, Room> Loaded
+ #endregion Constructors
+
+ #region Properties
+
+ public Dictionary<Exit, int> Exits
{
get;
private set;
}
- public Dictionary<Exit, int> Exits
+ public Dictionary<int, Room> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
-
foreach (var entry in Exits)
{
@@ -53,8 +68,8 @@
{
entry.Value.Save(conn);
}
-
- }
+ }
+
public override void Load(FileReader reader)
{
if (RomImporter.CurrentArea == null)
@@ -165,5 +180,7 @@
}
Log.Info("Loaded {0} rooms.", Loaded.Count);
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/ShopSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/ShopSection.cs Tue Apr 19 15:57:05 2011
@@ -1,16 +1,19 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NLog;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class ShopSection : FileSection
{
+ #region Constructors
public ShopSection(RomImporter importer)
{
@@ -18,17 +21,25 @@
Importer = importer;
}
- protected RomImporter Importer
+ #endregion Constructors
+
+ #region Properties
+
+ public Dictionary<int, Shop> Loaded
{
get;
private set;
}
- public Dictionary<int, Shop> Loaded
+ protected RomImporter Importer
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
@@ -50,7 +61,6 @@
shop.Save(conn);
npc.Save(conn);
}
-
}
public override void Load(FileReader reader)
@@ -77,6 +87,7 @@
LogManager.GetCurrentClassLogger().Info("loaded {0} shops",
Loaded.Count);
}
- }
-
-}
+
+ #endregion Methods
+ }
+}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/SocialSection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEditor/Import/Rom/SocialSection.cs Tue Apr 19 15:57:05 2011
@@ -1,32 +1,43 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArtheaEngine.Model;
-using ArtheaEngine;
-using NLog;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using ArtheaEngine;
+ using ArtheaEngine.Model;
+
+ using NLog;
+
public class SocialSection : FileSection
{
+ #region Constructors
+
public SocialSection()
{
Loaded = new List<Social>();
}
+
+ #endregion Constructors
+
+ #region Properties
public IList<Social> Loaded
{
get;
private set;
}
+
+ #endregion Properties
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
foreach (var s in Loaded)
s.Save(conn);
-
}
public override void Load(FileReader reader)
@@ -119,5 +130,7 @@
LogManager.GetCurrentClassLogger().Info("Loaded {0} socials.",
Loaded.Count);
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Import/Rom/SpecialSection.cs Sun Apr 3 15:23:52
2011
+++ /trunk/ArtheaEditor/Import/Rom/SpecialSection.cs Tue Apr 19 15:57:05
2011
@@ -1,17 +1,24 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NLog;
-using System.Data;
-
-namespace ArtheaEditor.Import.Rom
-{
+namespace ArtheaEditor.Import.Rom
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using NLog;
+
public class SpecialSection : FileSection
{
+ #region Constructors
+
public SpecialSection()
{
}
+
+ #endregion Constructors
+
+ #region Methods
public override void Commit(IDbConnection conn)
{
@@ -44,5 +51,7 @@
reader.ReadToEol();
}
}
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/ImportDialog.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/ImportDialog.cs Tue Apr 19 15:57:05 2011
@@ -1,29 +1,40 @@
-#region Includes
-
-using System;
-using System.IO;
-using System.Windows.Forms;
-using ArtheaEditor.Import;
-using ArtheaEditor.Import.Rom;
-using NLog.Config;
-using NLog.Targets;
-using NLog;
-
-#endregion
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.IO;
+ using System.Windows.Forms;
+
+ using ArtheaEditor.Import;
+ using ArtheaEditor.Import.Rom;
+
+ using NLog;
+ using NLog.Config;
+ using NLog.Targets;
+
public partial class ImportDialog : Form
{
+ #region Fields
+
private IImporter _importer;
+ #endregion Fields
+
+ #region Constructors
+
public ImportDialog(IImporter importer)
{
InitializeComponent();
_importer = importer;
-
-
+ }
+
+ #endregion Constructors
+
+ #region Methods
+
+ private void btnCommit_Click(object sender, EventArgs e)
+ {
+ _importer.Commit();
}
private void button1_Click(object sender, EventArgs e)
@@ -63,9 +74,6 @@
}
}
- private void btnCommit_Click(object sender, EventArgs e)
- {
- _importer.Commit();
- }
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEditor/Program.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEditor/Program.cs Tue Apr 19 15:57:05 2011
@@ -1,33 +1,34 @@
-#region Includes
-
-using System;
-using System.Windows.Forms;
-using Microsoft.VisualBasic.ApplicationServices;
-using ArtheaEngine.Model;
-
-#endregion
-
-namespace ArtheaEditor
-{
+namespace ArtheaEditor
+{
+ using System;
+ using System.Windows.Forms;
+
+ using ArtheaEngine.Model;
+
+ using Microsoft.VisualBasic.ApplicationServices;
+
internal static class Program
{
- [STAThread]
- static void Main(string[] args)
- {
- Application.EnableVisualStyles();
+ #region Methods
+
+ [STAThread]
+ static void Main(string[] args)
+ {
+ Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new MyApp().Run(args);
- }
-
+ }
+
+ #endregion Methods
+
+ #region Nested Types
+
public class MyApp : WindowsFormsApplicationBase
{
- protected override void OnCreateSplashScreen()
- {
- this.SplashScreen = new ArtheaSplashScreen();
- }
+ #region Methods
+
protected override void OnCreateMainForm()
{
-
// Do your initialization here
if (World.List.Count == 0)
@@ -38,6 +39,15 @@
// Then create the main form, the splash screen will
automatically close
this.MainForm = new EditorForm();
}
- }
+
+ protected override void OnCreateSplashScreen()
+ {
+ this.SplashScreen = new ArtheaSplashScreen();
+ }
+
+ #endregion Methods
+ }
+
+ #endregion Nested Types
}
}
=======================================
--- /trunk/ArtheaEditor/Properties/AssemblyInfo.cs Mon Mar 28 23:33:46 2011
+++ /trunk/ArtheaEditor/Properties/AssemblyInfo.cs Tue Apr 19 15:57:05 2011
@@ -1,14 +1,9 @@
-#region Includes
-
-using System.Reflection;
+using System.Reflection;
using System.Runtime.InteropServices;
-#endregion
-
-// General Information about an assembly is controlled through the
following
+// General Information about an assembly is controlled through the
following
// set of attributes. Change these attribute values to modify the
information
// associated with an assembly.
-
[assembly: AssemblyTitle("ArtheaEditor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@@ -18,26 +13,23 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
-
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is
exposed to COM
-
[assembly: Guid("c8933cb0-a44e-4d38-8c61-571c75c6d4c3")]
// Version information for an assembly consists of the following four
values:
//
// Major Version
-// Minor Version
+// Minor Version
// Build Number
// Revision
//
-// You can specify all the values or you can default the Build and
Revision Numbers
+// You can specify all the values or you can default the Build and
Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-
[assembly: AssemblyVersion("2010.8.1410.2108")]
[assembly: AssemblyFileVersion("2010.8.1410.2108")]
=======================================
--- /trunk/ArtheaEngine/Argument.cs Wed Apr 13 16:20:00 2011
+++ /trunk/ArtheaEngine/Argument.cs Tue Apr 19 15:57:05 2011
@@ -1,34 +1,119 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-
-#endregion
-
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections.Generic;
+
public class Argument
{
+ #region Fields
+
public static Argument Empty = new Argument();
+
private string _mString;
+
+ #endregion Fields
+
+ #region Constructors
+
+ public Argument(object arg)
+ {
+ _mString = arg.ToString();
+ }
private Argument()
{
}
- public Argument(object arg)
- {
- _mString = arg.ToString();
+ #endregion Constructors
+
+ #region Properties
+
+ public int Length
+ {
+ get { return _mString.Length; }
}
- public bool EndsWith(string part)
- {
- return _mString.EndsWith(part,
StringComparison.CurrentCultureIgnoreCase);
+ #endregion Properties
+
+ #region Indexers
+
+ public char this[int index]
+ {
+ get { return _mString[index]; }
}
- public bool IsNumber()
- {
- return _mString.IsNumber();
+ #endregion Indexers
+
+ #region Methods
+
+ /// <summary>
+ /// Performs an explicit conversion from <see
cref="Arthea.String"/> to <see cref="System.String"/>.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>The result of the conversion.</returns>
+ public static implicit operator string(Argument x)
+ {
+ return x._mString;
+ }
+
+ /// <summary>
+ /// Performs an implicit conversion from <see
cref="System.String"/> to <see cref="Arthea.String"/>.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>The result of the conversion.</returns>
+ public static implicit operator Argument(string x)
+ {
+ return new Argument(x);
+ }
+
+ /// <summary>
+ /// Checks if a string is empty
+ /// </summary>
+ /// <param name="str">the string to check</param>
+ /// <returns>true if string is empty</returns>
+ public static bool operator !(Argument str)
+ {
+ return str == null || str.IsEmpty();
+ }
+
+ /// <summary>
+ /// Check if two string are not equal (case insensitive)
+ /// </summary>
+ /// <param name="orig">first string</param>
+ /// <param name="str">second string</param>
+ /// <returns>true if strings are not equal</returns>
+ public static bool operator !=(Argument orig, string str)
+ {
+ return !orig._mString.Equals(str,
StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ /// <summary>
+ /// Checks if two strings are equal (case insensitive)
+ /// </summary>
+ /// <param name="orig">first string</param>
+ /// <param name="str">second string</param>
+ /// <returns>true if strings are equal</returns>
+ public static bool operator ==(Argument orig, string str)
+ {
+ return orig._mString.Equals(str,
StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ public string[] All()
+ {
+ var args = new List<string>();
+ var temp = new Argument(_mString);
+
+ while (!string.IsNullOrEmpty(temp))
+ {
+ args.Add(temp.Next());
+ }
+
+ return args.ToArray();
+ }
+
+ public bool EndsWith(string part)
+ {
+ return _mString.EndsWith(part,
StringComparison.CurrentCultureIgnoreCase);
}
public bool Equals(Argument obj)
@@ -46,7 +131,45 @@
return Equals((Argument) obj);
}
- public int Length { get { return _mString.Length; } }
+ public override int GetHashCode()
+ {
+ return (_mString != null ? _mString.GetHashCode() : 0);
+ }
+
+ public bool IsEmpty()
+ {
+ return string.IsNullOrEmpty(_mString);
+ }
+
+ public bool IsNumber()
+ {
+ return _mString.IsNumber();
+ }
+
+ /// <summary>
+ /// Gets the first arg of this string.
+ /// Will reassign this string.
+ /// </summary>
+ /// <returns>a string</returns>
+ public string Next()
+ {
+ return Next(true);
+ }
+
+ public string Peek()
+ {
+ return Next(false);
+ }
+
+ public Argument Replace(string orig, string value)
+ {
+ return _mString.Replace(orig, value);
+ }
+
+ public override string ToString()
+ {
+ return _mString;
+ }
/// <summary>
/// Gets the first argument in a string
@@ -66,7 +189,6 @@
var cEnd = ' ';
int pos, begin = 0;
-
if (_mString[0] == '\'' || _mString[0] == '"' || _mString[0]
== '(')
{
cEnd = _mString[0] == '(' ? ')' : _mString[0];
@@ -104,109 +226,6 @@
return arg;
}
- /// <summary>
- /// Gets the first arg of this string.
- /// Will reassign this string.
- /// </summary>
- /// <returns>a string</returns>
- public string Next()
- {
- return Next(true);
- }
-
- public string[] All()
- {
- var args = new List<string>();
- var temp = new Argument(_mString);
-
- while (!string.IsNullOrEmpty(temp))
- {
- args.Add(temp.Next());
- }
-
- return args.ToArray();
- }
-
- public override int GetHashCode()
- {
- return (_mString != null ? _mString.GetHashCode() : 0);
- }
-
- public bool IsEmpty()
- {
- return string.IsNullOrEmpty(_mString);
- }
-
- public string Peek()
- {
- return Next(false);
- }
-
- public Argument Replace(string orig, string value)
- {
- return _mString.Replace(orig, value);
- }
-
- public override string ToString()
- {
- return _mString;
- }
-
- /// <summary>
- /// Checks if two strings are equal (case insensitive)
- /// </summary>
- /// <param name="orig">first string</param>
- /// <param name="str">second string</param>
- /// <returns>true if strings are equal</returns>
- public static bool operator ==(Argument orig, string str)
- {
- return orig._mString.Equals(str,
StringComparison.CurrentCultureIgnoreCase);
- }
-
- /// <summary>
- /// Performs an explicit conversion from <see
cref="Arthea.String"/> to <see cref="System.String"/>.
- /// </summary>
- /// <param name="x">The x.</param>
- /// <returns>The result of the conversion.</returns>
- public static implicit operator string(Argument x)
- {
- return x._mString;
- }
-
- /// <summary>
- /// Performs an implicit conversion from <see
cref="System.String"/> to <see cref="Arthea.String"/>.
- /// </summary>
- /// <param name="x">The x.</param>
- /// <returns>The result of the conversion.</returns>
- public static implicit operator Argument(string x)
- {
- return new Argument(x);
- }
-
- /// <summary>
- /// Check if two string are not equal (case insensitive)
- /// </summary>
- /// <param name="orig">first string</param>
- /// <param name="str">second string</param>
- /// <returns>true if strings are not equal</returns>
- public static bool operator !=(Argument orig, string str)
- {
- return !orig._mString.Equals(str,
StringComparison.CurrentCultureIgnoreCase);
- }
-
- /// <summary>
- /// Checks if a string is empty
- /// </summary>
- /// <param name="str">the string to check</param>
- /// <returns>true if string is empty</returns>
- public static bool operator !(Argument str)
- {
- return str == null || str.IsEmpty();
- }
-
- public char this[int index]
- {
- get { return _mString[index]; }
- }
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/ArtheaHelper.cs Tue Apr 19 13:25:38 2011
+++ /trunk/ArtheaEngine/ArtheaHelper.cs Tue Apr 19 15:57:05 2011
@@ -1,62 +1,49 @@
-#region Includes
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Globalization;
-using System.Data.Linq;
-using System.Data.Odbc;
-using System.Configuration;
-using System.Data;
-using MySql.Data.MySqlClient;
-using System.Linq.Expressions;
-using System.Collections.Specialized;
-#endregion
-
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Collections.Specialized;
+ using System.Configuration;
+ using System.Data;
+ using System.Data.Linq;
+ using System.Data.Odbc;
+ using System.Globalization;
+ using System.Linq.Expressions;
+ using System.Reflection;
+ using System.Text;
+ using System.Text.RegularExpressions;
+
+ using MySql.Data.MySqlClient;
+
public static class ArtheaHelper
{
+ #region Fields
+
public const short Immortal = 201;
public const short MaxLevel = 201;
+ #endregion Fields
+
+ #region Constructors
+
static ArtheaHelper()
{
Randomizer = new Random();
}
- public static NotifyCollectionChangedEventHandler
CollectionChangedHandler<T>(Action<T, bool> action)
- {
- return new NotifyCollectionChangedEventHandler((o, e) =>
- {
- if (e.NewItems != null)
- {
- foreach (T r in e.NewItems)
- {
- action(r, true);
- }
- }
- if (e.OldItems != null)
- {
- foreach (T r in e.OldItems)
- {
- action(r, false);
- }
- }
- });
+ #endregion Constructors
+
+ #region Properties
+
+ public static Random Randomizer
+ {
+ get; private set;
}
- public static IDbConnection NewConnection()
- {
- var conn = new
MySqlConnection(ConfigurationManager.ConnectionStrings["ArtheaMYSQL"].ConnectionString);
-
- conn.Open();
-
- return conn;
- }
+ #endregion Properties
+
+ #region Methods
public static void CloneObj(object newObject, object thisObj)
{
@@ -83,18 +70,18 @@
}
else
{
- // If the field doesn't support the ICloneable
+ // If the field doesn't support the ICloneable
// interface then just set it.
fields[i].SetValue(newObject, fi.GetValue(thisObj));
}
- //Now we check if the object support the
+ //Now we check if the object support the
//IEnumerable interface, so if it does
- //we need to enumerate all its items and check if
+ //we need to enumerate all its items and check if
//they support the ICloneable interface.
@@ -106,7 +93,7 @@
var e = (IEnumerable) fi.GetValue(thisObj);
- //This version support the IList and the
+ //This version support the IList and the
//IDictionary interfaces to iterate on collections.
@@ -124,7 +111,7 @@
foreach (var obj in e)
{
- //Checking to see if the current item
+ //Checking to see if the current item
//support the ICloneable interface.
@@ -133,7 +120,7 @@
if (cloneType != null)
{
- //If it does support the ICloneable
interface,
+ //If it does support the ICloneable
interface,
//we use it to set the clone of
@@ -144,17 +131,16 @@
list[j] = clone.Clone();
}
- //NOTE: If the item in the list is not
-
- //support the ICloneable interface then in the
-
- //cloned list this item will be the same
+ //NOTE: If the item in the list is not
+
+ //support the ICloneable interface then in the
+
+ //cloned list this item will be the same
//item as in the original list
//(as long as this type is a reference type).
-
j++;
}
}
@@ -168,7 +154,7 @@
foreach (DictionaryEntry de in e)
{
- //Checking to see if the item
+ //Checking to see if the item
//support the ICloneable interface.
@@ -188,6 +174,27 @@
i++;
}
}
+
+ public static NotifyCollectionChangedEventHandler
CollectionChangedHandler<T>(Action<T, bool> action)
+ {
+ return new NotifyCollectionChangedEventHandler((o, e) =>
+ {
+ if (e.NewItems != null)
+ {
+ foreach (T r in e.NewItems)
+ {
+ action(r, true);
+ }
+ }
+ if (e.OldItems != null)
+ {
+ foreach (T r in e.OldItems)
+ {
+ action(r, false);
+ }
+ }
+ });
+ }
public static bool IsEmail(string inputEmail)
{
@@ -199,7 +206,16 @@
return re.IsMatch(inputEmail);
}
- public static Random Randomizer { get; private set; }
+ public static IDbConnection NewConnection()
+ {
+ var conn = new
MySqlConnection(ConfigurationManager.ConnectionStrings["ArtheaMYSQL"].ConnectionString);
+
+ conn.Open();
+
+ return conn;
+ }
+
+ #endregion Methods
}
public static class PropertyHelper<T>
=======================================
--- /trunk/ArtheaEngine/Color.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEngine/Color.cs Tue Apr 19 15:57:05 2011
@@ -1,177 +1,75 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-
-#endregion
-
-namespace ArtheaEngine
-{
- public class ColorWriter : StreamWriter
- {
- public ColorWriter(Stream stream, IConnection conn) : base(stream)
- {
- Connection = conn;
- }
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Text;
+
+ #region Enumerations
+
+ [Flags]
+ public enum ColorFlags
+ {
+ None = 0,
+ Bright = (1 << 0), // 1
+ Background = (1 << 1),
+ Blink = (1 << 2), // 5
+ Reverse = (1 << 3), // 7
+ Dim = (1 << 4), // 2
+ Underscore = (1 << 5) // 4
+ }
+
+ public enum ColorType
+ {
+ None = 0,
/// <summary>
- /// Converts the specified text.
+ /// A black foreground value
/// </summary>
- /// <param name="text">The text.</param>
- /// <returns></returns>
- public string Convert(string text)
- {
- if (text == null)
- return "";
-
- var index = text.IndexOf(Color.Code, 0);
-
- if (index == -1)
- return text;
-
- var lastIndex = 0;
-
- var buf = new StringBuilder();
-
- while (index != -1)
- {
- buf.Append(text.Substring(lastIndex, index - lastIndex));
-
- // increment, and check for trailing codes
- if (++index > text.Length)
- {
- buf.Append(Color.Code);
- break;
- }
-
- if (!Connection.Flags.HasFlag(ConnectionFlag.ColorOff))
- {
- switch (text[index])
- {
- case 'n':
- buf.Append("Arthea");
- break;
- case 'N':
- buf.Append("ARTHEA");
- break;
- case '*':
- buf.Append("\007");
- break;
- case Color.Code:
- buf.Append(Color.Code);
- break;
- case 'x':
- buf.Append(new Color());
- break;
- default:
- buf.Append(Color.Parse(text, ref index));
- break;
- }
- }
-
- lastIndex = ++index;
- index = text.IndexOf(Color.Code, index);
- }
-
- buf.Append(text.Substring(lastIndex));
-
- return buf.ToString();
- }
-
- public char[] Convert(char[] buffer)
- {
- var str = Convert(new string(buffer));
-
- return str.ToCharArray();
- }
-
- public override void Write(char[] buffer)
- {
- base.Write(Convert(buffer));
- }
-
- public override void Write(char[] buffer, int index, int count)
- {
- base.Write(Convert(buffer), index, count);
- }
-
- public override void Write(object value)
- {
- Write(value.ToString());
- }
-
- public override void Write(string format, object arg0)
- {
- Write(string.Format(format, arg0));
- }
-
- public override void Write(string format, object arg0, object
arg1, object arg2)
- {
- Write(string.Format(format, arg0, arg1, arg2));
- }
-
- public override void Write(string format, object arg0, object arg1)
- {
- Write(string.Format(format, arg0, arg1));
- }
-
- public override void Write(string format, params object[] arg)
- {
- Write(string.Format(format, arg));
- }
-
- public override void Write(string value)
- {
- base.Write(Convert(value));
- }
-
- public override void WriteLine(char[] buffer)
- {
- base.WriteLine(Convert(buffer));
- }
-
- public override void WriteLine(char[] buffer, int index, int count)
- {
- base.WriteLine(Convert(buffer), index, count);
- }
-
- public override void WriteLine(object value)
- {
- WriteLine(value.ToString());
- }
-
- public override void WriteLine(string format, object arg0)
- {
- WriteLine(string.Format(format, arg0));
- }
-
- public override void WriteLine(string format, object arg0, object
arg1)
- {
- WriteLine(string.Format(format, arg0, arg1));
- }
-
- public override void WriteLine(string format, object arg0, object
arg1, object arg2)
- {
- WriteLine(string.Format(format, arg0, arg1, arg2));
- }
-
- public override void WriteLine(string format, params object[] arg)
- {
- WriteLine(string.Format(format, arg));
- }
-
- public override void WriteLine(string value)
- {
- base.WriteLine(Convert(value));
- }
-
- public IConnection Connection { get; private set; }
- }
+ Black = 30,
+
+ /// <summary>
+ /// A blue foreground value
+ /// </summary>
+ Blue = 34,
+
+ /// <summary>
+ /// A Cyan foreground value
+ /// </summary>
+ Cyan = 36,
+
+ /// <summary>
+ /// A green foreground value
+ /// </summary>
+ Green = 32,
+
+ /// <summary>
+ /// A magenta foreground value
+ /// </summary>
+ Magenta = 35,
+
+ /// <summary>
+ /// A red foreground value
+ /// </summary>
+ Red = 31,
+
+ /// <summary>
+ /// A white foreground value
+ /// </summary>
+ White = 37,
+
+ /// <summary>
+ /// A yellow foreground value
+ /// </summary>
+ Yellow = 33,
+ }
+
+ #endregion Enumerations
public class Color
{
+ #region Fields
+
/// <summary>
/// The color escape code
/// </summary>
@@ -190,7 +88,6 @@
{'$',
ColorFlags.Dim},
{'%',
ColorFlags.Underscore}
};
-
private static readonly Dictionary<char, ColorType> ColorMap = new
Dictionary<char, ColorType>
{
{'g',
ColorType.Green},
@@ -202,9 +99,12 @@
{'d',
ColorType.Black},
{'w',
ColorType.White}
};
-
private static readonly Random Rand = new Random();
+ #endregion Fields
+
+ #region Constructors
+
public Color(ColorType type)
{
Value = type;
@@ -223,6 +123,28 @@
{
Value = ColorType.None;
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public ColorFlags Flags
+ {
+ get; set;
+ }
+
+ /// <summary>
+ /// Gets or sets the values.
+ /// </summary>
+ /// <value>The values.</value>
+ public ColorType Value
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
/// <summary>
/// Sets the color based on a code.
@@ -263,7 +185,6 @@
return col;
}
-
public void Clear()
{
@@ -363,69 +284,183 @@
return buf.ToString();
}
- public ColorFlags Flags { get; set; }
-
- /// <summary>
- /// Gets or sets the values.
- /// </summary>
- /// <value>The values.</value>
- public ColorType Value { get; set; }
+ #endregion Methods
}
- public enum ColorType
- {
- None = 0,
-
- /// <summary>
- /// A black foreground value
- /// </summary>
- Black = 30,
-
- /// <summary>
- /// A blue foreground value
- /// </summary>
- Blue = 34,
-
- /// <summary>
- /// A Cyan foreground value
- /// </summary>
- Cyan = 36,
-
- /// <summary>
- /// A green foreground value
- /// </summary>
- Green = 32,
-
- /// <summary>
- /// A magenta foreground value
- /// </summary>
- Magenta = 35,
-
- /// <summary>
- /// A red foreground value
- /// </summary>
- Red = 31,
+ public class ColorWriter : StreamWriter
+ {
+ #region Constructors
+
+ public ColorWriter(Stream stream, IConnection conn)
+ : base(stream)
+ {
+ Connection = conn;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public IConnection Connection
+ {
+ get; private set;
+ }
+
+ #endregion Properties
+
+ #region Methods
/// <summary>
- /// A white foreground value
+ /// Converts the specified text.
/// </summary>
- White = 37,
-
- /// <summary>
- /// A yellow foreground value
- /// </summary>
- Yellow = 33,
- }
-
- [Flags]
- public enum ColorFlags
- {
- None = 0,
- Bright = (1 << 0), // 1
- Background = (1 << 1),
- Blink = (1 << 2), // 5
- Reverse = (1 << 3), // 7
- Dim = (1 << 4), // 2
- Underscore = (1 << 5) // 4
+ /// <param name="text">The text.</param>
+ /// <returns></returns>
+ public string Convert(string text)
+ {
+ if (text == null)
+ return "";
+
+ var index = text.IndexOf(Color.Code, 0);
+
+ if (index == -1)
+ return text;
+
+ var lastIndex = 0;
+
+ var buf = new StringBuilder();
+
+ while (index != -1)
+ {
+ buf.Append(text.Substring(lastIndex, index - lastIndex));
+
+ // increment, and check for trailing codes
+ if (++index > text.Length)
+ {
+ buf.Append(Color.Code);
+ break;
+ }
+
+ if (!Connection.Flags.HasFlag(ConnectionFlag.ColorOff))
+ {
+ switch (text[index])
+ {
+ case 'n':
+ buf.Append("Arthea");
+ break;
+ case 'N':
+ buf.Append("ARTHEA");
+ break;
+ case '*':
+ buf.Append("\007");
+ break;
+ case Color.Code:
+ buf.Append(Color.Code);
+ break;
+ case 'x':
+ buf.Append(new Color());
+ break;
+ default:
+ buf.Append(Color.Parse(text, ref index));
+ break;
+ }
+ }
+
+ lastIndex = ++index;
+ index = text.IndexOf(Color.Code, index);
+ }
+
+ buf.Append(text.Substring(lastIndex));
+
+ return buf.ToString();
+ }
+
+ public char[] Convert(char[] buffer)
+ {
+ var str = Convert(new string(buffer));
+
+ return str.ToCharArray();
+ }
+
+ public override void Write(char[] buffer)
+ {
+ base.Write(Convert(buffer));
+ }
+
+ public override void Write(char[] buffer, int index, int count)
+ {
+ base.Write(Convert(buffer), index, count);
+ }
+
+ public override void Write(object value)
+ {
+ Write(value.ToString());
+ }
+
+ public override void Write(string format, object arg0)
+ {
+ Write(string.Format(format, arg0));
+ }
+
+ public override void Write(string format, object arg0, object
arg1, object arg2)
+ {
+ Write(string.Format(format, arg0, arg1, arg2));
+ }
+
+ public override void Write(string format, object arg0, object arg1)
+ {
+ Write(string.Format(format, arg0, arg1));
+ }
+
+ public override void Write(string format, params object[] arg)
+ {
+ Write(string.Format(format, arg));
+ }
+
+ public override void Write(string value)
+ {
+ base.Write(Convert(value));
+ }
+
+ public override void WriteLine(char[] buffer)
+ {
+ base.WriteLine(Convert(buffer));
+ }
+
+ public override void WriteLine(char[] buffer, int index, int count)
+ {
+ base.WriteLine(Convert(buffer), index, count);
+ }
+
+ public override void WriteLine(object value)
+ {
+ WriteLine(value.ToString());
+ }
+
+ public override void WriteLine(string format, object arg0)
+ {
+ WriteLine(string.Format(format, arg0));
+ }
+
+ public override void WriteLine(string format, object arg0, object
arg1)
+ {
+ WriteLine(string.Format(format, arg0, arg1));
+ }
+
+ public override void WriteLine(string format, object arg0, object
arg1, object arg2)
+ {
+ WriteLine(string.Format(format, arg0, arg1, arg2));
+ }
+
+ public override void WriteLine(string format, params object[] arg)
+ {
+ WriteLine(string.Format(format, arg));
+ }
+
+ public override void WriteLine(string value)
+ {
+ base.WriteLine(Convert(value));
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Columns.cs Mon Apr 18 17:51:17 2011
+++ /trunk/ArtheaEngine/Columns.cs Tue Apr 19 15:57:05 2011
@@ -1,68 +1,49 @@
-
-using ArtheaEngine.Model;
-using System.Text;
-using System.Collections.Generic;
-using System.Collections;
-using System;
-namespace ArtheaEngine
-{
- public class Column
- {
- public int Span { get; set; }
- public object Content { get; set; }
-
- public override string ToString()
- {
- return Content == null ? string.Empty : Content.ToString();
- }
- }
-
- public class Header : Column
- {
- }
-
- public class Row
- {
- public Row(int size)
- {
- Size = size;
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Text;
+
+ using ArtheaEngine.Model;
+
+ public class Column
+ {
+ #region Properties
+
+ public object Content
+ {
+ get; set;
}
- private List<Column> _columns = new List<Column>();
-
- public int Size { get; set; }
-
- public int Span()
- {
- int count = 0;
- foreach (var c in _columns)
- {
- count += c.Span;
- }
- return count;
+ public int Span
+ {
+ get; set;
}
- public bool Add(Column c)
- {
- if (Span() >= Size)
- return false;
-
- _columns.Add(c);
- return true;
- }
-
-
- public Column[] ToArray()
- {
- return _columns.ToArray();
+ #endregion Properties
+
+ #region Methods
+
+ public override string ToString()
+ {
+ return Content == null ? string.Empty : Content.ToString();
}
- }
+ #endregion Methods
+ }
+
public class ColumnList
{
- private LinkedList<Row> _rows = new LinkedList<Row>();
+ #region Fields
private Row _currRow;
+ private LinkedList<Row> _rows = new LinkedList<Row>();
+ private int _savedSize;
+
+ #endregion Fields
+
+ #region Constructors
public ColumnList(int rowLen)
{
@@ -71,15 +52,9 @@
_rows.AddLast(_currRow);
}
- private void AddColumn(Column c)
- {
- if (!_currRow.Add(c))
- {
- _currRow = new Row(_currRow.Size);
- _rows.AddLast(_currRow);
- _currRow.Add(c);
- }
- }
+ #endregion Constructors
+
+ #region Methods
public void Add(object content)
{
@@ -97,7 +72,7 @@
{
var tmp = string.Format(format, values);
- AddColumn(new Column { Span = 1, Content = tmp });
+ AddColumn(new Column { Span = 1, Content = tmp });
}
public void Add(int span, string format, params object[] values)
@@ -112,17 +87,15 @@
AddColumn(new Header { Span = _currRow.Size, Content = content
});
}
- private int _savedSize;
+ public void RestoreSize()
+ {
+ SetSize(_savedSize);
+ }
public void SaveSize()
{
_savedSize = _currRow.Size;
}
-
- public void RestoreSize()
- {
- SetSize(_savedSize);
- }
public void SetSize(int size)
{
@@ -139,7 +112,6 @@
public void Show(IWritable to)
{
-
int width;
if (to is Player)
@@ -161,6 +133,7 @@
Show(to, width);
}
+
public void Show(IWritable to, int width)
{
StringBuilder buf = new StringBuilder();
@@ -183,7 +156,7 @@
iCount = 0;
}
- if (c is Header)
+ if (c is Header)
format = string.Format("~!B~W{{0,-{0}}}",
(width/row.Size) + hiddenLength);
else
format = string.Format("{{0,-{0}}}",
(width/row.Size) + hiddenLength);
@@ -202,7 +175,7 @@
buf.AppendLine();
string format;
-
+
if(_columns[i] is Header)
format = string.Format("~!B~W{{0,-{0}}}", width +
(text.Length - text.DisplayLength()));
else
@@ -220,6 +193,18 @@
to.Page(buf.ToString());
}
+
+ private void AddColumn(Column c)
+ {
+ if (!_currRow.Add(c))
+ {
+ _currRow = new Row(_currRow.Size);
+ _rows.AddLast(_currRow);
+ _currRow.Add(c);
+ }
+ }
+
+ #endregion Methods
}
/// <summary>
@@ -227,22 +212,16 @@
/// </summary>
public static class Columns
{
+ #region Fields
+
/// <summary>
/// The default width for a column
/// </summary>
public static readonly ushort DefaultWidth = 80;
-
- /// <summary>
- /// Gets the width of the player default.
- /// </summary>
- /// <param name="player">The player.</param>
- /// <param name="columns">The columns.</param>
- /// <returns></returns>
- private static ushort GetPlayerDefaultWidth(Player player, ushort
columns)
- {
- return (ushort)(player.Account.Connection.ScreenWidth /
columns);
- }
+ #endregion Fields
+
+ #region Methods
/// <summary>
/// Shows the specified player.
@@ -284,5 +263,77 @@
player.Page(buf.ToString());
}
+
+ /// <summary>
+ /// Gets the width of the player default.
+ /// </summary>
+ /// <param name="player">The player.</param>
+ /// <param name="columns">The columns.</param>
+ /// <returns></returns>
+ private static ushort GetPlayerDefaultWidth(Player player, ushort
columns)
+ {
+ return (ushort)(player.Account.Connection.ScreenWidth /
columns);
+ }
+
+ #endregion Methods
+ }
+
+ public class Header : Column
+ {
+ }
+
+ public class Row
+ {
+ #region Fields
+
+ private List<Column> _columns = new List<Column>();
+
+ #endregion Fields
+
+ #region Constructors
+
+ public Row(int size)
+ {
+ Size = size;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public int Size
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public bool Add(Column c)
+ {
+ if (Span() >= Size)
+ return false;
+
+ _columns.Add(c);
+ return true;
+ }
+
+ public int Span()
+ {
+ int count = 0;
+ foreach (var c in _columns)
+ {
+ count += c.Span;
+ }
+ return count;
+ }
+
+ public Column[] ToArray()
+ {
+ return _columns.ToArray();
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Extensions.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Extensions.cs Tue Apr 19 15:57:05 2011
@@ -1,35 +1,22 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.ObjectModel;
-using System.Data.Odbc;
-using System.Data;
-using ArtheaEngine.Model;
-using System.Text.RegularExpressions;
-using System.Globalization;
-using System.Data.Linq.Mapping;
-using System.Data.Common;
-
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Data;
+ using System.Data.Common;
+ using System.Data.Linq.Mapping;
+ using System.Data.Odbc;
+ using System.Globalization;
+ using System.Linq;
+ using System.Text;
+ using System.Text.RegularExpressions;
+
+ using ArtheaEngine.Model;
+
public static class Extensions
{
- public static IDbCommand CreateCommand(this IDbConnection conn,
string procedure)
- {
- var cmd = conn.CreateCommand();
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.CommandText = procedure;
-
- return cmd;
- }
-
- public static string GetStringOrNull(this IDataRecord reader, int
index)
- {
- if (reader.IsDBNull(index)) return string.Empty;
-
- return reader.GetString(index);
- }
+ #region Methods
public static void AddParameter(this IDbCommand cmd, string name,
DbType type, object value)
{
@@ -40,95 +27,32 @@
cmd.Parameters.Add(p);
}
- public static object LastInsertId(this IDbConnection conn)
- {
- var cmd = conn.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "select last_insert_id()";
-
- var obj = cmd.ExecuteScalar();
-
- return obj;
- }
-
-
- public static T GetEnum<T>(this IDataRecord reader, int index)
where T: struct
- {
- T val;
-
- if (reader.IsDBNull(index) |
| !Enum.TryParse(reader.GetString(index), true, out val))
- return default(T);
-
- return val;
- }
-
- public static WearFlag ToFlag(this WearLocation loc)
- {
- /*switch (loc)
- {
- case WearLocation.Arms: return WearFlag.Arms;
- }*/
- return WearFlag.None;
- }
- public static string ToCSV(this ISet<string> Tags)
- {
- var buf = new StringBuilder();
-
- foreach (var tag in Tags)
- {
- buf.Append(tag).Append(", ");
- }
- if (buf.Length >= 2)
- buf.Remove(buf.Length-2, 2);
+ /// <summary>
+ /// Makes the readable.
+ /// </summary>
+ /// <param name="str">The STR.</param>
+ /// <returns></returns>
+ public static string CamelToHuman(this string str)
+ {
+ var buf = new StringBuilder();
+ var c = str.GetEnumerator();
+
+ if (!c.MoveNext())
+ return str;
+
+ buf.Append(char.ToUpper(c.Current));
+
+ while (c.MoveNext())
+ {
+ if (char.IsUpper(c.Current))
+ {
+ buf.Append(" ");
+ }
+ buf.Append(c.Current);
+ }
return buf.ToString();
}
-
- public static bool Save(this ISaveable obj)
- {
- using (var conn = ArtheaHelper.NewConnection())
- {
- var tx = conn.BeginTransaction();
-
- bool rval = obj.Save(conn);
-
- if (rval == false)
- tx.Rollback();
- else
- tx.Commit();
-
- return rval;
- }
- }
-
- public static bool Delete(this ISaveable obj)
- {
- using (var conn = ArtheaHelper.NewConnection())
- {
- return obj.Delete(conn);
- }
- }
-
- public static bool Load(this ILoadable obj)
- {
- using (var conn = ArtheaHelper.NewConnection())
- {
- return obj.Load(conn);
- }
- }
-
- public static bool Load(this ILoadable obj, IDbCommand cmd)
- {
- using (var reader = cmd.ExecuteReader())
- {
- if (!reader.Read()) return false;
-
- obj.MapRow(reader);
-
- return true;
- }
- }
-
/// <summary>
/// Puts the first letter in upper case and the rest in lower case
@@ -146,7 +70,6 @@
if (tolower)
return firstLetter + mString.Substring(1).ToLower();
-
return firstLetter + mString.Substring(1);
}
@@ -155,20 +78,58 @@
return mString.Capitalize(true);
}
- public static bool IsPrefixOf(this string mString, string value,
bool ignoreCase)
- {
- if (string.IsNullOrEmpty(mString) ||
string.IsNullOrEmpty(value)) return false;
-
- return value.StartsWith(mString, ignoreCase,
CultureInfo.CurrentCulture);
+ public static string Center(this string mString, int width)
+ {
+ var margin = (width/2.0f) - (mString.DisplayLength()/2.0f);
+ var buf = new StringBuilder();
+ buf.Append(' ', (int) Math.Floor(margin));
+ buf.Append(mString);
+ buf.Append(' ', (int) Math.Floor(margin));
+ return buf.ToString();
+ }
+
+ public static string Center(this string mString, Player ch)
+ {
+ return mString.Center(ch.Account.Connection.ScreenWidth);
}
- public static bool IsPrefixOf(this string mString, string value)
- {
- return IsPrefixOf(mString, value, true);
+ public static int CountLines(this string mString)
+ {
+ return mString.CountLines(0);
}
-
- public static bool DeepCompare<T>(this T[] orig, T[] passwd) where
T: IEquatable<T>
+ public static int CountLines(this string mString, int pos)
+ {
+ if (string.IsNullOrEmpty(mString)) return 0;
+
+ int point = mString.IndexOf(Environment.NewLine);
+
+ int count = 0;
+
+ while (point > 0)
+ {
+ if (point >= pos)
+ break;
+
+ count++;
+
+ point = mString.IndexOf(Environment.NewLine, point);
+ }
+
+ return count;
+ }
+
+ public static IDbCommand CreateCommand(this IDbConnection conn,
string procedure)
+ {
+ var cmd = conn.CreateCommand();
+ cmd.CommandType = CommandType.StoredProcedure;
+ cmd.CommandText = procedure;
+
+ return cmd;
+ }
+
+ public static bool DeepCompare<T>(this T[] orig, T[] passwd)
+ where T : IEquatable<T>
{
if (orig.Length != passwd.Length)
return false;
@@ -182,6 +143,14 @@
}
return true;
}
+
+ public static bool Delete(this ISaveable obj)
+ {
+ using (var conn = ArtheaHelper.NewConnection())
+ {
+ return obj.Delete(conn);
+ }
+ }
public static int DisplayLength(this string str)
{
@@ -198,6 +167,16 @@
return default(T);
}
+ public static T GetEnum<T>(this IDataRecord reader, int index)
+ where T : struct
+ {
+ T val;
+
+ if (reader.IsDBNull(index) |
| !Enum.TryParse(reader.GetString(index), true, out val))
+ return default(T);
+
+ return val;
+ }
public static int GetLineCountLength(this string str, int count)
{
@@ -237,28 +216,6 @@
}
return point - pos;
}
-
-
- public static bool Is(this string mString, string other)
- {
- return mString.Equals(other,
StringComparison.OrdinalIgnoreCase);
- }
-
- public static Direction Reverse(this Direction dir)
- {
- switch (dir)
- {
- case Direction.Down: return Direction.Up;
- case Direction.East: return Direction.West;
- case Direction.North: return Direction.South;
- case Direction.South: return Direction.North;
- case Direction.Up: return Direction.Down;
- case Direction.West: return Direction.East;
-
- default: throw new Exception("Unknown direction for
reverse");
-
- }
- }
/// <summary>
/// Gets the lines.
@@ -269,32 +226,6 @@
if (mString == null) return new string[0];
return mString.Split(new[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
}
-
- public static int CountLines(this string mString)
- {
- return mString.CountLines(0);
- }
-
- public static int CountLines(this string mString, int pos)
- {
- if (string.IsNullOrEmpty(mString)) return 0;
-
- int point = mString.IndexOf(Environment.NewLine);
-
- int count = 0;
-
- while (point > 0)
- {
- if (point >= pos)
- break;
-
- count++;
-
- point = mString.IndexOf(Environment.NewLine, point);
- }
-
- return count;
- }
/// <summary>
/// Finds an argument prefixed by a multiplier (7*argument)
@@ -318,23 +249,21 @@
return str.GetNumberedArg(out arg, '.');
}
- private static int GetNumberedArg(this string mString, out string
arg, char c)
- {
- var index = mString.IndexOf(c);
-
- if (index == -1)
- {
- arg = mString;
- return 1;
- }
-
- int number;
-
- int.TryParse(mString.Substring(0, index), out number);
-
- arg = mString.Substring(index + 1);
-
- return number;
+ public static string GetStringOrNull(this IDataRecord reader, int
index)
+ {
+ if (reader.IsDBNull(index)) return string.Empty;
+
+ return reader.GetString(index);
+ }
+
+ public static bool HasFlag(this long bits, long flag)
+ {
+ return (bits & flag) != 0;
+ }
+
+ public static bool HasFlag(this int bits, int flag)
+ {
+ return (bits & flag) != 0;
}
public static bool HasWord(this string value, string word)
@@ -352,7 +281,10 @@
return false;
}
-
+ public static bool Is(this string mString, string other)
+ {
+ return mString.Equals(other,
StringComparison.OrdinalIgnoreCase);
+ }
/// <summary>
/// Determines whether the specified STR has a line.
@@ -404,6 +336,18 @@
}
return true;
}
+
+ public static bool IsPrefixOf(this string mString, string value,
bool ignoreCase)
+ {
+ if (string.IsNullOrEmpty(mString) ||
string.IsNullOrEmpty(value)) return false;
+
+ return value.StartsWith(mString, ignoreCase,
CultureInfo.CurrentCulture);
+ }
+
+ public static bool IsPrefixOf(this string mString, string value)
+ {
+ return IsPrefixOf(mString, value, true);
+ }
/// <summary>
/// Joins the specified separator.
@@ -418,34 +362,69 @@
return String.Join(separator, newValue);
}
-
- /// <summary>
- /// Makes the readable.
- /// </summary>
- /// <param name="str">The STR.</param>
- /// <returns></returns>
- public static string CamelToHuman(this string str)
- {
- var buf = new StringBuilder();
- var c = str.GetEnumerator();
-
- if (!c.MoveNext())
- return str;
-
- buf.Append(char.ToUpper(c.Current));
-
- while (c.MoveNext())
- {
- if (char.IsUpper(c.Current))
- {
- buf.Append(" ");
- }
- buf.Append(c.Current);
- }
-
- return buf.ToString();
+ public static object LastInsertId(this IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand();
+ cmd.CommandType = CommandType.Text;
+ cmd.CommandText = "select last_insert_id()";
+
+ var obj = cmd.ExecuteScalar();
+
+ return obj;
+ }
+
+ public static bool Load(this ILoadable obj)
+ {
+ using (var conn = ArtheaHelper.NewConnection())
+ {
+ return obj.Load(conn);
+ }
+ }
+
+ public static bool Load(this ILoadable obj, IDbCommand cmd)
+ {
+ using (var reader = cmd.ExecuteReader())
+ {
+ if (!reader.Read()) return false;
+
+ obj.MapRow(reader);
+
+ return true;
+ }
}
+ public static Direction Reverse(this Direction dir)
+ {
+ switch (dir)
+ {
+ case Direction.Down: return Direction.Up;
+ case Direction.East: return Direction.West;
+ case Direction.North: return Direction.South;
+ case Direction.South: return Direction.North;
+ case Direction.Up: return Direction.Down;
+ case Direction.West: return Direction.East;
+
+ default: throw new Exception("Unknown direction for
reverse");
+
+ }
+ }
+
+ public static bool Save(this ISaveable obj)
+ {
+ using (var conn = ArtheaHelper.NewConnection())
+ {
+ var tx = conn.BeginTransaction();
+
+ bool rval = obj.Save(conn);
+
+ if (rval == false)
+ tx.Rollback();
+ else
+ tx.Commit();
+
+ return rval;
+ }
+ }
public static string StripColor(this string mString)
{
@@ -453,34 +432,48 @@
"[!@#$%]*[GRCBYMDWNgrcbymdwxn?*"
+ Color.Code + "]", string.Empty);
}
-
- public static string Center(this string mString, int width)
- {
- var margin = (width/2.0f) - (mString.DisplayLength()/2.0f);
+ public static string ToCSV(this ISet<string> Tags)
+ {
var buf = new StringBuilder();
- buf.Append(' ', (int) Math.Floor(margin));
- buf.Append(mString);
- buf.Append(' ', (int) Math.Floor(margin));
+
+ foreach (var tag in Tags)
+ {
+ buf.Append(tag).Append(", ");
+ }
+ if (buf.Length >= 2)
+ buf.Remove(buf.Length-2, 2);
+
return buf.ToString();
}
- public static string Center(this string mString, Player ch)
- {
- return mString.Center(ch.Account.Connection.ScreenWidth);
+ public static WearFlag ToFlag(this WearLocation loc)
+ {
+ /*switch (loc)
+ {
+ case WearLocation.Arms: return WearFlag.Arms;
+ }*/
+ return WearFlag.None;
}
- #region flag methods
-
- public static bool HasFlag(this long bits, long flag)
- {
- return (bits & flag) != 0;
- }
-
- public static bool HasFlag(this int bits, int flag)
- {
- return (bits & flag) != 0;
+ private static int GetNumberedArg(this string mString, out string
arg, char c)
+ {
+ var index = mString.IndexOf(c);
+
+ if (index == -1)
+ {
+ arg = mString;
+ return 1;
+ }
+
+ int number;
+
+ int.TryParse(mString.Substring(0, index), out number);
+
+ arg = mString.Substring(index + 1);
+
+ return number;
}
- #endregion
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/ICommand.cs Wed Apr 13 19:25:59 2011
+++ /trunk/ArtheaEngine/ICommand.cs Tue Apr 19 15:57:05 2011
@@ -1,50 +1,86 @@
-using ArtheaEngine.Model;
-using System;
-using System.Runtime.Serialization;
-
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System;
+ using System.Runtime.Serialization;
+
+ using ArtheaEngine.Model;
+
public interface ICommand
{
+ #region Properties
+
+ string Description
+ {
+ get;
+ }
+
+ string Name
+ {
+ get;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
bool CanUse(Character ch);
+
void Execute(Character ch, Argument argument);
- string Description { get; }
- string Name { get; }
+
+ #endregion Methods
}
- public class ShutdownException : Exception
- {
- public ShutdownException()
+ public class RebootException : Exception
+ {
+ #region Constructors
+
+ public RebootException()
: base()
- { }
-
- public ShutdownException(string msg) : base(msg) { }
-
- public ShutdownException(string msg, Exception innerEx)
+ {
+ }
+
+ public RebootException(string msg)
+ : base(msg)
+ {
+ }
+
+ public RebootException(string msg, Exception innerEx)
: base(msg, innerEx)
- { }
-
- public ShutdownException(SerializationInfo info, StreamingContext
context)
+ {
+ }
+
+ public RebootException(SerializationInfo info, StreamingContext
context)
: base(info, context)
- { }
-
+ {
+ }
+
+ #endregion Constructors
}
-
- public class RebootException : Exception
- {
- public RebootException()
+ public class ShutdownException : Exception
+ {
+ #region Constructors
+
+ public ShutdownException()
: base()
- { }
-
- public RebootException(string msg) : base(msg) { }
-
- public RebootException(string msg, Exception innerEx)
+ {
+ }
+
+ public ShutdownException(string msg)
+ : base(msg)
+ {
+ }
+
+ public ShutdownException(string msg, Exception innerEx)
: base(msg, innerEx)
- { }
-
- public RebootException(SerializationInfo info, StreamingContext
context)
+ {
+ }
+
+ public ShutdownException(SerializationInfo info, StreamingContext
context)
: base(info, context)
- { }
+ {
+ }
+
+ #endregion Constructors
}
}
=======================================
--- /trunk/ArtheaEngine/IConnection.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEngine/IConnection.cs Tue Apr 19 15:57:05 2011
@@ -1,20 +1,10 @@
-#region Includes
-
-using System;
-using ArtheaEngine.Model;
-
-#endregion
-
-namespace ArtheaEngine
-{
- public interface IConnection : IWritable, IDisposable
- {
- ConnectionFlag Flags { get; set; }
- Player Playing { get; set; }
- short ScreenHeight { get; }
- short ScreenWidth { get; }
- World World { get; }
- }
+namespace ArtheaEngine
+{
+ using System;
+
+ using ArtheaEngine.Model;
+
+ #region Enumerations
[Flags]
public enum ConnectionFlag
@@ -24,4 +14,38 @@
SuppressGoAhead,
ColorOff
}
-}
+
+ #endregion Enumerations
+
+ public interface IConnection : IWritable, IDisposable
+ {
+ #region Properties
+
+ ConnectionFlag Flags
+ {
+ get; set;
+ }
+
+ Player Playing
+ {
+ get; set;
+ }
+
+ short ScreenHeight
+ {
+ get;
+ }
+
+ short ScreenWidth
+ {
+ get;
+ }
+
+ World World
+ {
+ get;
+ }
+
+ #endregion Properties
+ }
+}
=======================================
--- /trunk/ArtheaEngine/IEntity.cs Mon Mar 28 23:33:46 2011
+++ /trunk/ArtheaEngine/IEntity.cs Tue Apr 19 15:57:05 2011
@@ -1,8 +1,16 @@
-using System;
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System;
+
public interface IEntity<T>
{
- T Id { get; }
+ #region Properties
+
+ T Id
+ {
+ get;
+ }
+
+ #endregion Properties
}
}
=======================================
--- /trunk/ArtheaEngine/IPersistent.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEngine/IPersistent.cs Tue Apr 19 15:57:05 2011
@@ -1,28 +1,37 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Data.Odbc;
-using System.Reflection;
-using System.Diagnostics;
-using System.Data;
-
-namespace ArtheaEngine
-{
- public interface ISaveable
- {
- bool Delete(IDbConnection conn);
- bool Save(IDbConnection conn);
- }
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Data.Odbc;
+ using System.Diagnostics;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
public interface ILoadable
{
+ #region Methods
+
bool Load(IDbConnection conn);
+
int MapRow(IDataRecord reader);
+
+ #endregion Methods
}
public interface IPersistent : ISaveable, ILoadable
{
-
+ }
+
+ public interface ISaveable
+ {
+ #region Methods
+
+ bool Delete(IDbConnection conn);
+
+ bool Save(IDbConnection conn);
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/IWritable.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEngine/IWritable.cs Tue Apr 19 15:57:05 2011
@@ -1,19 +1,25 @@
-#region Includes
-
-using System.Text;
-
-#endregion
-
-namespace ArtheaEngine
-{
+namespace ArtheaEngine
+{
+ using System.Text;
+
public interface IWritable
{
+ #region Methods
+
void Page(string buf);
+
void Write(string format, params object[] args);
+
void Write(byte[] value);
+
void Write(object obj);
+
void WriteLine();
+
void WriteLine(object value);
+
void WriteLine(string format, params object[] args);
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Ability.cs Sun Apr 3 22:15:32 2011
+++ /trunk/ArtheaEngine/Model/Ability.cs Tue Apr 19 15:57:05 2011
@@ -1,24 +1,36 @@
-#region Includes
-
-using System;
-using System.Reflection;
-using Object=ArtheaEngine.Model.Object;
-using System.Collections.Generic;
-using System.Configuration;
-using NLog;
-using System.Diagnostics;
-using System.Data;
-using System.Linq;
-using System.Data.Common;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Configuration;
+ using System.Data;
+ using System.Data.Common;
+ using System.Diagnostics;
+ using System.Linq;
+ using System.Reflection;
+
+ using NLog;
+
+ using Object = ArtheaEngine.Model.Object;
+
public abstract class Ability : ICloneable, IEntity<int>, ISaveable,
ILoadable
{
+ #region Fields
+
public static readonly HashSet<Ability> List = new
HashSet<Ability>();
+ private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+ static readonly object[] Parameters = new object[] {
+ "@id", DbType.Int32,
+ "@name", DbType.String,
+ "@level", DbType.Int16,
+ "@descr", DbType.String,
+ "@cost", DbType.Currency
+ };
+
+ #endregion Fields
+
+ #region Constructors
static Ability()
{
@@ -38,7 +50,68 @@
}
}
}
- private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+
+ #endregion Constructors
+
+ #region Properties
+
+ public Money Cost
+ {
+ get; set;
+ }
+
+ public string Description
+ {
+ get; set;
+ }
+
+ public abstract int Id
+ {
+ get;
+ }
+
+ public short Level
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static Ability Lookup(int id)
+ {
+ return List.SingleOrDefault(x => x.Id == id);
+ }
+
+ /// <summary>
+ /// Creates a new object that is a copy of the
current instance.
+ /// </summary>
+ /// <returns>
+ /// A new object that is a copy of this
instance.
+ /// </returns>
+ /// <filterpriority>2</filterpriority>
+ public object Clone()
+ {
+ var newObject = Activator.CreateInstance(GetType());
+
+ ArtheaHelper.CloneObj(newObject, this);
+
+ return newObject;
+ }
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_ability");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public void DisplayOffMsg(object from)
{
@@ -85,44 +158,6 @@
}
}
}
-
- protected virtual string GetAbilityMsg(string name)
- {
- var fi = GetType().GetField(name,
- BindingFlags.Static |
BindingFlags.NonPublic |
- BindingFlags.Public);
- return fi.GetValue(null) as string;
- }
-
- public static Ability Lookup(int id)
- {
- return List.SingleOrDefault(x => x.Id == id);
- }
- #region Implementation of ICloneable
-
- /// <summary>
- /// Creates a new object that is a copy of the
current instance.
- /// </summary>
- /// <returns>
- /// A new object that is a copy of this
instance.
- /// </returns>
- /// <filterpriority>2</filterpriority>
- public object Clone()
- {
- var newObject = Activator.CreateInstance(GetType());
-
- ArtheaHelper.CloneObj(newObject, this);
-
- return newObject;
- }
-
- #endregion
-
- public abstract int Id { get; }
- public short Level { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
- public Money Cost { get; set; }
public bool Load(IDbConnection conn)
{
@@ -133,6 +168,18 @@
return this.Load(cmd);
}
}
+
+ public int MapRow(IDataRecord row)
+ {
+ int i = 0;
+
+ Name = row.GetString(i++);
+ Level = row.GetInt16(i++);
+ Description = row.GetString(i++);
+ Cost = row.GetDecimal(i++);
+
+ return i;
+ }
public bool Save(IDbConnection conn)
{
@@ -144,36 +191,18 @@
cmd.AddParameter("@cost", DbType.Currency, Cost);
var res = cmd.ExecuteNonQuery() > 0;
-
+
return res;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_ability");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return cmd.ExecuteNonQuery() == 1;
+ protected virtual string GetAbilityMsg(string name)
+ {
+ var fi = GetType().GetField(name,
+ BindingFlags.Static |
BindingFlags.NonPublic |
+ BindingFlags.Public);
+ return fi.GetValue(null) as string;
}
- static readonly object[] Parameters = new object[] {
- "@id", DbType.Int32,
- "@name", DbType.String,
- "@level", DbType.Int16,
- "@descr", DbType.String,
- "@cost", DbType.Currency
- };
-
- public int MapRow(IDataRecord row)
- {
- int i = 0;
-
- Name = row.GetString(i++);
- Level = row.GetInt16(i++);
- Description = row.GetString(i++);
- Cost = row.GetDecimal(i++);
-
- return i;
- }
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Account.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Account.cs Tue Apr 19 15:57:05 2011
@@ -1,79 +1,85 @@
-#region Includes
-
-using System.Text;
-using System.Collections.Generic;
-using NLog;
-using System;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Data;
-using System.Data.Linq.Mapping;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Data;
+ using System.Data.Linq.Mapping;
+ using System.Diagnostics;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
[Flags]
public enum AccountFlag
{
None,
Admin
}
+
+ #endregion Enumerations
public class Account : ISaveable, IWritable, IEntity<long>, ILoadable
{
+ #region Constructors
+
public Account()
{
Players = new List<AccountPlayer>();
}
- public virtual IConnection Connection { get; set; }
-
- public long Id { get; set; }
- public string Login { get; set; }
- public byte[] Password { get; set; }
- public string Email { get; set; }
- public AccountFlag Flags { get; set; }
- public List<AccountPlayer> Players { get; set; }
-
- #region Implementation of IWritable
-
- public virtual void WriteLine()
- {
- Connection.WriteLine();
+ #endregion Constructors
+
+ #region Properties
+
+ public virtual IConnection Connection
+ {
+ get; set;
}
- public virtual void WriteLine(object value)
- {
- Connection.WriteLine(value);
+ public string Email
+ {
+ get; set;
}
- public virtual void WriteLine(string format, params object[] args)
- {
- Connection.WriteLine(format, args);
+ public AccountFlag Flags
+ {
+ get; set;
}
- public virtual void Write(string format, params object[] args)
- {
- Connection.WriteLine(format, args);
+ public long Id
+ {
+ get; set;
}
- public virtual void Write(byte[] value)
- {
- Connection.Write(value);
+ public string Login
+ {
+ get; set;
}
- public virtual void Write(object obj)
- {
- Connection.Write(obj);
+ public byte[] Password
+ {
+ get; set;
}
- public virtual void Page(string buf)
- {
- Connection.Page(buf);
+ public List<AccountPlayer> Players
+ {
+ get; set;
}
- #endregion
+ #endregion Properties
+
+ #region Methods
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_account");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public bool Load(string login)
{
@@ -92,31 +98,16 @@
LoadPlayerInfo(conn);
return true;
-
+
}
catch(Exception ex)
{
LogManager.GetCurrentClassLogger().Error(ex.Message);
}
-
+
return false;
}
}
-
- public int MapRow(IDataRecord reader)
- {
- int i = 0;
-
- Id = reader.GetInt64(i++);
- Login = reader.GetString(i++);
- var buf = new byte[255];
- var len = reader.GetBytes(i++, 0, buf, 0, 255);
- Password = new byte[len];
- Array.Copy(buf, Password, len);
- Email = reader.GetString(i++);
- Flags = reader.GetEnum<AccountFlag>(i++);
- return i;
- }
public bool Load(IDbConnection conn)
{
@@ -132,7 +123,6 @@
LoadPlayerInfo(conn);
return true;
-
}
public void LoadPlayerInfo(IDbConnection conn)
@@ -149,21 +139,30 @@
p.MapRow(reader);
p.Account = this;
-
Players.Add(p);
}
}
}
-
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_account");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1;
-
+ public int MapRow(IDataRecord reader)
+ {
+ int i = 0;
+
+ Id = reader.GetInt64(i++);
+ Login = reader.GetString(i++);
+ var buf = new byte[255];
+ var len = reader.GetBytes(i++, 0, buf, 0, 255);
+ Password = new byte[len];
+ Array.Copy(buf, Password, len);
+ Email = reader.GetString(i++);
+ Flags = reader.GetEnum<AccountFlag>(i++);
+ return i;
+ }
+
+ public virtual void Page(string buf)
+ {
+ Connection.Page(buf);
}
public bool Save(IDbConnection conn)
@@ -183,26 +182,72 @@
return res;
}
+
+ public virtual void Write(string format, params object[] args)
+ {
+ Connection.WriteLine(format, args);
+ }
+
+ public virtual void Write(byte[] value)
+ {
+ Connection.Write(value);
+ }
+
+ public virtual void Write(object obj)
+ {
+ Connection.Write(obj);
+ }
+
+ public virtual void WriteLine()
+ {
+ Connection.WriteLine();
+ }
+
+ public virtual void WriteLine(object value)
+ {
+ Connection.WriteLine(value);
+ }
+
+ public virtual void WriteLine(string format, params object[] args)
+ {
+ Connection.WriteLine(format, args);
+ }
+
+ #endregion Methods
}
public class AccountPlayer
{
- public long Id { get; set; }
- public string Name { get; set; }
- public short Level { get; set; }
- public DateTime LastLogin { get; set; }
- public Account Account { get; set; }
-
- public int MapRow(IDataRecord reader)
- {
- var i = 0;
-
- Id = reader.GetInt64(i++);
- Name = reader.GetString(i++);
- Level = reader.GetInt16(i++);
- //p.LastLogin = reader.GetDateTime(3);
- return i;
- }
+ #region Properties
+
+ public Account Account
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public DateTime LastLogin
+ {
+ get; set;
+ }
+
+ public short Level
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
public Player Load()
{
@@ -215,5 +260,18 @@
return p;
}
+
+ public int MapRow(IDataRecord reader)
+ {
+ var i = 0;
+
+ Id = reader.GetInt64(i++);
+ Name = reader.GetString(i++);
+ Level = reader.GetInt16(i++);
+ //p.LastLogin = reader.GetDateTime(3);
+ return i;
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Affect.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Affect.cs Tue Apr 19 15:57:05 2011
@@ -1,28 +1,77 @@
-
-using System;
-using NLog;
-using System.Linq;
-using System.Data.Odbc;
-using System.Data;
-using System.Reflection;
-using System.Text;
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Data;
+ using System.Data.Odbc;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
public enum AffectFlag : long
{
None
}
+
+ public enum AffectLocation
+ {
+ None,
+ AC,
+ Hit,
+ Mana,
+ Move
+ }
+
+ #endregion Enumerations
public class Affect : ISaveable, IEntity<long>, ILoadable, IFormattable
{
-
- public long Id { get; set; }
- public AffectLocation Location { get; set; }
- public AffectFlag Flag { get; set; }
- public int Modifier { get; set; }
- public int Duration { get; set; }
- public int Extra { get; set; }
+ #region Properties
+
+ public int Duration
+ {
+ get; set;
+ }
+
+ public int Extra
+ {
+ get; set;
+ }
+
+ public AffectFlag Flag
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public AffectLocation Location
+ {
+ get; set;
+ }
+
+ public int Modifier
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_affect");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public override bool Equals(object obj)
{
@@ -38,23 +87,6 @@
{
return ((int)Flag) + Modifier + Duration + (int)Location;
}
-
- public override string ToString()
- {
- string temp;
-
- if (Location != AffectLocation.None)
- temp = string.Format(" modifies {0} by {1}",
Location.ToString().ToLower(), Modifier);
- else if (Flag != AffectFlag.None)
- temp = string.Format(" adds {0} affect", Flag.ToString());
- else
- temp = string.Empty;
-
- var ability = Ability.Lookup(Extra);
-
- return string.Format("Spell {0}{1} for {2} hours.",
- (ability == null ? "unknown" :
ability.Name), temp, Duration);
- }
public bool Load(IDbConnection conn)
{
@@ -79,7 +111,6 @@
return i;
}
-
public bool Save(IDbConnection conn)
{
@@ -99,19 +130,27 @@
return res;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_affect");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1;
-
+ public override string ToString()
+ {
+ string temp;
+
+ if (Location != AffectLocation.None)
+ temp = string.Format(" modifies {0} by {1}",
Location.ToString().ToLower(), Modifier);
+ else if (Flag != AffectFlag.None)
+ temp = string.Format(" adds {0} affect", Flag.ToString());
+ else
+ temp = string.Empty;
+
+ var ability = Ability.Lookup(Extra);
+
+ return string.Format("Spell {0}{1} for {2} hours.",
+ (ability == null ? "unknown" :
ability.Name), temp, Duration);
}
public string ToString(string format, IFormatProvider
formatProvider)
{
if (string.IsNullOrEmpty(format) || format == "F")
- {
+ {
Ability what = null;
var buf = new StringBuilder();
@@ -145,14 +184,7 @@
throw new FormatException("unknown format");
}
- }
-
- public enum AffectLocation
- {
- None,
- AC,
- Hit,
- Mana,
- Move
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Area.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Area.cs Tue Apr 19 15:57:05 2011
@@ -1,26 +1,27 @@
-#region Includes
-
-using System.Collections.Generic;
-using Object = ArtheaEngine.Model.Object;
-using System.Collections.ObjectModel;
-using System;
-using NLog;
-using System.Data.Linq.Mapping;
-using System.Collections.Specialized;
-using System.Data;
-using System.Linq;
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Data.Linq.Mapping;
+ using System.Linq;
+
+ using NLog;
+
+ using Object = ArtheaEngine.Model.Object;
+
public class Area : IEntity<int>, ISaveable, ILoadable
{
+ #region Fields
+
public static readonly HashSet<Area> List = new HashSet<Area>();
- public static Area Lookup(int id)
- {
- return List.FirstOrDefault(x => x.Id == id);
- }
+ #endregion Fields
+
+ #region Constructors
+
public Area()
{
Rooms = new ObservableCollection<Room>();
@@ -41,55 +42,112 @@
});
}
- public int Id { get; set; }
-
- public string Name { get; set; }
-
- public string Credits { get; set; }
-
- public string Description { get; set; }
-
- public World World { get; set; }
-
- public ObservableCollection<Room> Rooms { get; set; }
-
- public ObservableCollection<Object> Objects { get; set; }
-
- public ObservableCollection<NonPlayer> NonPlayers { get; set; }
-
- public void Tick()
- {
- foreach (var room in Rooms)
- {
- room.Tick();
- }
+ #endregion Constructors
+
+ #region Properties
+
+ public string Credits
+ {
+ get; set;
+ }
+
+ public string Description
+ {
+ get; set;
+ }
+
+ public int Id
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ public ObservableCollection<NonPlayer> NonPlayers
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Object> Objects
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Room> Rooms
+ {
+ get; set;
}
- public void LoadRooms(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_area_rooms");
-
+ public World World
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static Area GetDefault()
+ {
+ var area = List.FirstOrDefault(a => a.Name == "Limbo");
+
+ if (area != null) return area;
+
+ area = new Area { Name = "Limbo", Credits = "Arthea", World =
World.GetDefault() };
+
+ return area;
+ }
+
+ public static Area Lookup(int id)
+ {
+ return List.FirstOrDefault(x => x.Id == id);
+ }
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_area");
cmd.AddParameter("@id", DbType.Int32, Id);
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
+ public bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_area");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ var reader = cmd.ExecuteReader();
+
+ if (!reader.Read()) return false;
+
+ MapRow(reader);
+
+ return true;
+ }
+
+ public void LoadNpcs(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_area_npcs");
+
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
- var room = new Room();
- room.MapRow(reader);
-
- Room.List.Add(room);
- Rooms.Add(room);
+ var npc = new NonPlayer();
+ npc.MapRow(reader);
+
+ NonPlayer.List.Add(npc);
+ NonPlayers.Add(npc);
}
}
-
- foreach (var room in Rooms)
- {
- room.LoadReset(conn);
- }
-
- }
+ }
+
public void LoadObjects(IDbConnection conn)
{
var cmd = conn.CreateCommand("select_area_objects");
@@ -110,9 +168,9 @@
}
}
- public void LoadNpcs(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_area_npcs");
+ public void LoadRooms(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_area_rooms");
cmd.AddParameter("@id", DbType.Int32, Id);
@@ -121,14 +179,20 @@
while (reader.Read())
{
- var npc = new NonPlayer();
- npc.MapRow(reader);
-
- NonPlayer.List.Add(npc);
- NonPlayers.Add(npc);
+ var room = new Room();
+ room.MapRow(reader);
+
+ Room.List.Add(room);
+ Rooms.Add(room);
}
}
- }
+
+ foreach (var room in Rooms)
+ {
+ room.LoadReset(conn);
+ }
+ }
+
public int MapRow(IDataRecord reader)
{
int i = 0;
@@ -143,51 +207,15 @@
return i;
}
- public bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_area");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- var reader = cmd.ExecuteReader();
-
- if (!reader.Read()) return false;
-
- MapRow(reader);
-
- return true;
-
- }
-
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_area");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return cmd.ExecuteNonQuery() == 1;
-
- }
-
- public static Area GetDefault()
- {
- var area = List.FirstOrDefault(a => a.Name == "Limbo");
-
- if (area != null) return area;
-
- area = new Area { Name = "Limbo", Credits = "Arthea", World =
World.GetDefault() };
-
- return area;
- }
-
-
public bool Save(IDbConnection conn)
{
var cmd = conn.CreateCommand("save_area");
-
+
cmd.AddParameter("@id", DbType.Int32, Id);
cmd.AddParameter("@name", DbType.String, Name);
cmd.AddParameter("@credits", DbType.String, Credits);
cmd.AddParameter("@world", DbType.Int32, World.Id);
-
+
var res = cmd.ExecuteNonQuery() > 0;
if (Id == 0 && res)
@@ -198,5 +226,15 @@
return res;
}
+
+ public void Tick()
+ {
+ foreach (var room in Rooms)
+ {
+ room.Tick();
+ }
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Board.cs Tue Apr 19 13:25:38 2011
+++ /trunk/ArtheaEngine/Model/Board.cs Tue Apr 19 15:57:05 2011
@@ -1,22 +1,82 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.Specialized;
-using System.Collections.ObjectModel;
-using NLog;
-using System.Data;
-using System.Reflection;
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
+ [Flags]
+ public enum BoardPermissions
+ {
+ /// <summary>
+ /// No permissions, all can read/write
+ /// </summary>
+ None,
+ /// <summary>
+ /// Only person in to or from fields
+ /// </summary>
+ Personal,
+ /// <summary>
+ /// admin can read/write
+ /// </summary>
+ Admin
+ }
+
+ #endregion Enumerations
+
+ public class AnnounceBoard : Board
+ {
+ #region Properties
+
+ public override string Description
+ {
+ get { return "Board for announcements from administrators."; }
+ }
+
+ public override int Id
+ {
+ get { return 1; }
+ }
+
+ public override string Name
+ {
+ get { return "Announce"; }
+ }
+
+ public override BoardPermissions ReadPermission
+ {
+ get { return BoardPermissions.None; }
+ }
+
+ public override BoardPermissions WritePermission
+ {
+ get { return BoardPermissions.Admin; }
+ }
+
+ #endregion Properties
+ }
+
/// <summary>
/// Implementation of board.
/// </summary>
public abstract class Board : IEntity<int>, IPersistent
{
+ #region Fields
+
public static readonly HashSet<Board> List = new HashSet<Board>();
+ #endregion Fields
+
+ #region Constructors
+
static Board()
{
var assm = Assembly.GetExecutingAssembly();
@@ -34,19 +94,6 @@
}
}
}
-
-
- public static Board Lookup(int id)
- {
- return List.FirstOrDefault(x => x.Id == id);
- }
-
- public abstract int Id { get; }
- public abstract string Name { get; }
- public abstract string Description { get; }
- public abstract BoardPermissions ReadPermission { get; }
- public abstract BoardPermissions WritePermission { get; }
- public ObservableCollection<Note> Notes { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Board"/> class.
@@ -59,6 +106,44 @@
n.Board = a ? this : null;
});
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public abstract string Description
+ {
+ get;
+ }
+
+ public abstract int Id
+ {
+ get;
+ }
+
+ public abstract string Name
+ {
+ get;
+ }
+
+ public ObservableCollection<Note> Notes
+ {
+ get; set;
+ }
+
+ public abstract BoardPermissions ReadPermission
+ {
+ get;
+ }
+
+ public abstract BoardPermissions WritePermission
+ {
+ get;
+ }
+
+ #endregion Properties
+
+ #region Methods
public static Note FindNote(long id)
{
@@ -71,30 +156,9 @@
return null;
}
- /// <summary>
- /// Returns a <see cref="T:System.String"></see> that represents
the current <see cref="T:System.Object"></see>.
- /// </summary>
- /// <returns>
- /// A <see cref="T:System.String"></see> that represents the
current <see cref="T:System.Object"></see>.
- /// </returns>
- public override string ToString()
- {
- return Name;
- }
-
- /// <summary>
- /// Determines whether a specific note can be read on this board.
- /// </summary>
- /// <param name="note">The note.</param>
- /// <param name="player">The player.</param>
- /// <returns>
- /// <c>true</c> if this the specified note can be read on this
board; otherwise, <c>false</c>.
- /// </returns>
- private bool NoteReadableBy(Note note, Character player)
- {
- return ((ReadPermission & BoardPermissions.Personal) == 0 ||
- note.From == player.Name ||
- note.To.Contains(player.Name));
+ public static Board Lookup(int id)
+ {
+ return List.FirstOrDefault(x => x.Id == id);
}
/// <summary>
@@ -122,6 +186,14 @@
return count;
}
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_board");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
/// <summary>
/// Gets the next unread.
@@ -147,43 +219,18 @@
return null;
}
- /// <summary>
- /// Shows the note list to.
- /// </summary>
- /// <param name="player">The player.</param>
- public void ShowNoteListTo(Player player)
- {
- StringCollection columns = new StringCollection();
-
- var count = 0;
-
- foreach(var note in Notes)
- {
- if (!NoteReadableBy(note, player))
- continue;
-
- columns.Add(string.Format("{0}{1,-2}> {2} ({3})",
-
player.HasReadNote(note) ? "~R*~x" : " ",
- (count + 1), note.Subject,
note.From));
- count++;
- }
-
- Columns.Show(player, 2, columns);
- }
-
+ public bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_board");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return this.Load(cmd);
+ }
public int MapRow(IDataRecord reader)
{
return 0;
}
-
- public bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_board");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return this.Load(cmd);
- }
public bool Save(IDbConnection conn)
{
@@ -198,60 +245,56 @@
return cmd.ExecuteNonQuery() > 0;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_board");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
-
- }
-
- public class AnnounceBoard : Board
- {
-
- public override int Id
- {
- get { return 1; }
- }
-
- public override string Name
- {
- get { return "Announce"; }
+ /// <summary>
+ /// Shows the note list to.
+ /// </summary>
+ /// <param name="player">The player.</param>
+ public void ShowNoteListTo(Player player)
+ {
+ StringCollection columns = new StringCollection();
+
+ var count = 0;
+
+ foreach(var note in Notes)
+ {
+ if (!NoteReadableBy(note, player))
+ continue;
+
+ columns.Add(string.Format("{0}{1,-2}> {2} ({3})",
+
player.HasReadNote(note) ? "~R*~x" : " ",
+ (count + 1), note.Subject,
note.From));
+ count++;
+ }
+
+ Columns.Show(player, 2, columns);
}
- public override string Description
- {
- get { return "Board for announcements from administrators."; }
+ /// <summary>
+ /// Returns a <see cref="T:System.String"></see> that represents
the current <see cref="T:System.Object"></see>.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="T:System.String"></see> that represents the
current <see cref="T:System.Object"></see>.
+ /// </returns>
+ public override string ToString()
+ {
+ return Name;
}
- public override BoardPermissions ReadPermission
- {
- get { return BoardPermissions.None; }
+ /// <summary>
+ /// Determines whether a specific note can be read on this board.
+ /// </summary>
+ /// <param name="note">The note.</param>
+ /// <param name="player">The player.</param>
+ /// <returns>
+ /// <c>true</c> if this the specified note can be read on this
board; otherwise, <c>false</c>.
+ /// </returns>
+ private bool NoteReadableBy(Note note, Character player)
+ {
+ return ((ReadPermission & BoardPermissions.Personal) == 0 ||
+ note.From == player.Name ||
+ note.To.Contains(player.Name));
}
- public override BoardPermissions WritePermission
- {
- get { return BoardPermissions.Admin; }
- }
- }
-
- [Flags]
- public enum BoardPermissions
- {
- /// <summary>
- /// No permissions, all can read/write
- /// </summary>
- None,
- /// <summary>
- /// Only person in to or from fields
- /// </summary>
- Personal,
- /// <summary>
- /// admin can read/write
- /// </summary>
- Admin
+ #endregion Methods
}
}
-
=======================================
--- /trunk/ArtheaEngine/Model/Character.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Character.cs Tue Apr 19 15:57:05 2011
@@ -1,29 +1,122 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection;
-using System.Text;
-using Object = ArtheaEngine.Model.Object;
-using NLog;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.Linq;
-using System.Data;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Globalization;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
+
+ using NLog;
+
+ using Object = ArtheaEngine.Model.Object;
+
+ #region Enumerations
+
+ [Flags]
+ public enum ActType
+ {
+ Char,
+ Room,
+ NotChar,
+ World
+ }
+
+ public enum Position
+ {
+ Dead,
+ Dying,
+ Stunned,
+ Sleeping,
+ Resting,
+ Fighting,
+ Standing
+ }
+
+ public enum Sex
+ {
+ Neutral,
+ Male,
+ Female,
+ Hermaphrodite
+ }
+
+ public enum Size
+ {
+ Minuscule,
+ Tiny,
+ Small,
+ Medium,
+ Large,
+ Huge,
+ Giant
+ }
+
+ #endregion Enumerations
+
+ public class ActionFormatter : IFormatProvider, ICustomFormatter
+ {
+ #region Constructors
+
+ public ActionFormatter(Character viewer)
+ {
+ Viewer = viewer;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public Character Viewer
+ {
+ get; private set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public string Format(string format, object arg, IFormatProvider
formatProvider)
+ {
+ var ch = arg as Character;
+ if (string.IsNullOrEmpty(format) || ch == null) return
arg.ToString();
+ return ch.ToString(format, formatProvider);
+ }
+
+ /// <summary>
+ /// Returns an object that provides formatting
services for the specified type.
+ /// </summary>
+ /// <returns>
+ /// An instance of the object specified by
<paramref name="formatType" />, if the <see cref="T:System.IFormatProvider"
/> implementation can supply that type of object; otherwise, null.
+ /// </returns>
+ /// <param name="formatType">
+ /// An object that specifies the type of
format object to return.
+ /// </param><filterpriority>1</filterpriority>
+ public object GetFormat(Type formatType)
+ {
+ return formatType == typeof(ICustomFormatter) ? this : null;
+ }
+
+ #endregion Methods
+ }
+
public abstract class Character : IEntity<long>, IWritable,
IFormattable, IDisposable, ICloneable, ISaveable, ILoadable
{
- private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+ #region Fields
+
public static readonly HashSet<Character> List = new
HashSet<Character>();
private static readonly string[] HeShe = { "it", "he", "she", "it"
};
private static readonly string[] HimHer =
{ "it", "him", "her", "it" };
private static readonly string[] HisHer =
{ "its", "his", "her", "it" };
+ private static readonly Logger Log =
LogManager.GetCurrentClassLogger();
+
+ #endregion Fields
+
+ #region Constructors
public Character()
{
@@ -46,58 +139,83 @@
});
}
- public static Character Lookup(string name)
- {
- return List.FirstOrDefault( x=> x.Name.HasWord(name) );
+ #endregion Constructors
+
+ #region Properties
+
+ public ObservableCollection<Affect> Affects
+ {
+ get; set;
}
- public static T Lookup<T>(string name) where T: Character
- {
- return List.OfType<T>().FirstOrDefault(x =>
x.Name.HasWord(name));
+ public ObservableCollection<CharObj> Carrying
+ {
+ get; set;
}
-
- public long Id { get; set; }
-
- public string Name { get; set; }
-
- public string Description { get; set; }
-
- public short Level { get; set; }
-
- public float Size { get; set; }
-
- public Position Position { get; set; }
-
- public Sex Sex { get; set; }
-
- public ObservableCollection<Affect> Affects { get; set; }
-
- public ObservableCollection<CharObj> Carrying { get; set; }
-
- public Room Room { get; set; }
-
- public Race Race { get; set; }
-
- object ICloneable.Clone()
- {
- return this.Clone();
+ public string Description
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public short Level
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ public Position Position
+ {
+ get; set;
+ }
+
+ public Race Race
+ {
+ get; set;
+ }
+
+ public Room Room
+ {
+ get; set;
+ }
+
+ public Sex Sex
+ {
+ get; set;
+ }
+
+ public float Size
+ {
+ get; set;
}
- public Character Clone()
- {
- return MemberwiseClone() as Character;
+ public abstract World World
+ {
+ get;
}
- public void Equip(Object obj, WearLocation location)
- {
- if (!obj.WearFlags.HasFlag(location.ToFlag()))
- {
- Log.Warn("Cannot equip object {0} on {1}", obj, location);
- return;
- }
-
- Carrying.Add(new CharObj { Object = obj, Character = this,
WearLocation = location });
+ #endregion Properties
+
+ #region Methods
+
+ public static Character Lookup(string name)
+ {
+ return List.FirstOrDefault( x=> x.Name.HasWord(name) );
+ }
+
+ public static T Lookup<T>(string name)
+ where T : Character
+ {
+ return List.OfType<T>().FirstOrDefault(x =>
x.Name.HasWord(name));
}
public virtual void Act(ActType type, string format, params
object[] args)
@@ -150,6 +268,33 @@
{
return true;
}
+
+ public Character Clone()
+ {
+ return MemberwiseClone() as Character;
+ }
+
+ public virtual bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_char");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery()== 1;
+ }
+
+ /// <summary>
+ /// Performs application-defined tasks
associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public virtual void Dispose()
+ {
+ if (Room != null)
+ {
+ Room.Characters.Remove(this);
+ Room = null;
+ }
+ List.Remove(this);
+ }
public virtual bool Equals(Character obj)
{
@@ -165,43 +310,84 @@
if (obj.GetType() != typeof(Character)) return false;
return Equals((Character)obj);
}
+
+ public void Equip(Object obj, WearLocation location)
+ {
+ if (!obj.WearFlags.HasFlag(location.ToFlag()))
+ {
+ Log.Warn("Cannot equip object {0} on {1}", obj, location);
+ return;
+ }
+
+ Carrying.Add(new CharObj { Object = obj, Character = this,
WearLocation = location });
+ }
public override int GetHashCode()
{
return Id.GetHashCode();
}
- public override string ToString()
- {
- return Name;
+ object ICloneable.Clone()
+ {
+ return this.Clone();
}
- public virtual string ToString(string format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- public abstract World World { get; }
-
- #region IDisposable Members
-
- /// <summary>
- /// Performs application-defined tasks
associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- /// <filterpriority>2</filterpriority>
- public virtual void Dispose()
- {
- if (Room != null)
- {
- Room.Characters.Remove(this);
- Room = null;
- }
- List.Remove(this);
+ public abstract bool Load(IDbConnection conn);
+
+ public virtual int MapRow(IDataRecord reader)
+ {
+ int i = 0;
+
+ Id = reader.GetInt64(i++);
+ Name = reader.GetString(i++);
+ Description = reader.GetStringOrNull(i++);
+ Level = reader.GetInt16(i++);
+
+ Race = Race.Lookup(reader.GetInt32(i++));
+ if (Race == null)
+ Race = new UniqueRace();
+ Size = reader.GetFloat(i++);
+ Position = reader.GetEnum<Position>(i++);
+ Sex = reader.GetEnum<Sex>(i++);
+
+ return i;
+ }
+
+ public abstract void Page(string buf);
+
+ public virtual bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_char");
+
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@name", DbType.String, Name);
+ cmd.AddParameter("@descr", DbType.String, Description);
+ cmd.AddParameter("@level", DbType.Int16, Level);
+ cmd.AddParameter("@race", DbType.Int32, Race.Id);
+ cmd.AddParameter("@size", DbType.Single, Size);
+ cmd.AddParameter("@position", DbType.String,
Position.ToString());
+ cmd.AddParameter("@sex", DbType.String, Sex);
+
+ var res = cmd.ExecuteNonQuery() > 0;
+
+ if (Id == 0 && res)
+ {
+ Id = Convert.ToInt64(conn.LastInsertId());
+ List.Add(this);
+ }
+
+ return res;
}
- #endregion
-
- #region IFormattable Members
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ public virtual string ToString(string format)
+ {
+ return ToString(format, CultureInfo.CurrentCulture);
+ }
public virtual string ToString(string format, IFormatProvider
formatProvider)
{
@@ -239,108 +425,62 @@
}
}
- #endregion
-
- #region IWritable Members
-
- public abstract void WriteLine();
- public abstract void WriteLine(object obj);
- public abstract void WriteLine(string format, params object[]
args);
public abstract void Write(string format, params object[] args);
+
public abstract void Write(byte[] value);
+
public abstract void Write(object obj);
- public abstract void Page(string buf);
-
- #endregion
-
-
- public virtual bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_char");
-
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@name", DbType.String, Name);
- cmd.AddParameter("@descr", DbType.String, Description);
- cmd.AddParameter("@level", DbType.Int16, Level);
- cmd.AddParameter("@race", DbType.Int32, Race.Id);
- cmd.AddParameter("@size", DbType.Single, Size);
- cmd.AddParameter("@position", DbType.String,
Position.ToString());
- cmd.AddParameter("@sex", DbType.String, Sex);
-
- var res = cmd.ExecuteNonQuery() > 0;
-
- if (Id == 0 && res)
- {
- Id = Convert.ToInt64(conn.LastInsertId());
- List.Add(this);
- }
-
- return res;
+
+ public abstract void WriteLine();
+
+ public abstract void WriteLine(object obj);
+
+ public abstract void WriteLine(string format, params object[]
args);
+
+ #endregion Methods
+ }
+
+ public class CharObj : IEntity<long>, ISaveable
+ {
+ #region Properties
+
+ public Character Character
+ {
+ get; set;
}
- public abstract bool Load(IDbConnection conn);
-
- public virtual int MapRow(IDataRecord reader)
- {
- int i = 0;
-
- Id = reader.GetInt64(i++);
- Name = reader.GetString(i++);
- Description = reader.GetStringOrNull(i++);
- Level = reader.GetInt16(i++);
-
- Race = Race.Lookup(reader.GetInt32(i++));
- if (Race == null)
- Race = new UniqueRace();
- Size = reader.GetFloat(i++);
- Position = reader.GetEnum<Position>(i++);
- Sex = reader.GetEnum<Sex>(i++);
-
- return i;
+ public long Id
+ {
+ get; set;
}
- public virtual bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_char");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery()== 1;
-
+ public Object Object
+ {
+ get; set;
+ }
+
+ public WearLocation WearLocation
+ {
+ get; set;
}
- }
-
- public class CharObj : IEntity<long>, ISaveable
- {
- public long Id { get; set; }
-
- public Character Character { get; set; }
-
- public Object Object { get; set; }
-
- public WearLocation WearLocation { get; set; }
+ #endregion Properties
+
+ #region Methods
public static explicit operator Object(CharObj chObj)
{
return chObj.Object;
}
- public bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_char_obj");
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_char_obj");
cmd.AddParameter("@id", DbType.Int64, Id);
cmd.AddParameter("@char_id", DbType.Int64, Character.Id);
cmd.AddParameter("@obj_id", DbType.Int64, Object.Id);
- cmd.AddParameter("@wearloc", DbType.String,
WearLocation.ToString());
-
- var res = cmd.ExecuteNonQuery() > 0;
-
- if (Id == 0 && res)
- {
- Id = Convert.ToInt64(conn.LastInsertId());
- }
-
- return res;
+
+ return cmd.ExecuteNonQuery() == 1;
}
public int MapRow(IDataRecord reader)
@@ -357,92 +497,24 @@
return i;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_char_obj");
+ public bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_char_obj");
cmd.AddParameter("@id", DbType.Int64, Id);
cmd.AddParameter("@char_id", DbType.Int64, Character.Id);
cmd.AddParameter("@obj_id", DbType.Int64, Object.Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
- }
-
- [Flags]
- public enum ActType
- {
- Char,
- Room,
- NotChar,
- World
- }
-
- public enum Position
- {
- Dead,
- Dying,
- Stunned,
- Sleeping,
- Resting,
- Fighting,
- Standing
- }
-
- public enum Sex
- {
- Neutral,
- Male,
- Female,
- Hermaphrodite
- }
-
- public enum Size
- {
- Minuscule,
- Tiny,
- Small,
- Medium,
- Large,
- Huge,
- Giant
- }
-
- public class ActionFormatter : IFormatProvider, ICustomFormatter
- {
- #region Implementation of IFormatProvider
-
- public ActionFormatter(Character viewer)
- {
- Viewer = viewer;
+ cmd.AddParameter("@wearloc", DbType.String,
WearLocation.ToString());
+
+ var res = cmd.ExecuteNonQuery() > 0;
+
+ if (Id == 0 && res)
+ {
+ Id = Convert.ToInt64(conn.LastInsertId());
+ }
+
+ return res;
}
- public Character Viewer { get; private set; }
-
- /// <summary>
- /// Returns an object that provides formatting
services for the specified type.
- /// </summary>
- /// <returns>
- /// An instance of the object specified by
<paramref name="formatType" />, if the <see cref="T:System.IFormatProvider"
/> implementation can supply that type of object; otherwise, null.
- /// </returns>
- /// <param name="formatType">
- /// An object that specifies the type of
format object to return.
- /// </param><filterpriority>1</filterpriority>
- public object GetFormat(Type formatType)
- {
- return formatType == typeof(ICustomFormatter) ? this : null;
- }
-
- #endregion
-
- #region Implementation of ICustomFormatter
-
- public string Format(string format, object arg, IFormatProvider
formatProvider)
- {
- var ch = arg as Character;
- if (string.IsNullOrEmpty(format) || ch == null) return
arg.ToString();
- return ch.ToString(format, formatProvider);
- }
-
- #endregion
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Class.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaEngine/Model/Class.cs Tue Apr 19 15:57:05 2011
@@ -1,22 +1,26 @@
-
-using System.Collections.Generic;
-using System;
-using System.Reflection;
-using System.Linq;
-using System.Data.Odbc;
-using System.Data;
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Data.Odbc;
+ using System.Linq;
+ using System.Reflection;
+
public abstract class Class : IEntity<int>, IPersistent
{
+ #region Fields
+
public static readonly HashSet<Class> List = new HashSet<Class>();
+ #endregion Fields
+
+ #region Constructors
+
static Class()
{
var assm = Assembly.GetExecutingAssembly();
-
foreach (var t in assm.GetTypes())
{
if (!t.IsSubclassOf(typeof(Class)) || t.IsAbstract)
@@ -29,8 +33,30 @@
List.Add(c);
}
-
- }
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public abstract string Description
+ {
+ get;
+ }
+
+ public abstract int Id
+ {
+ get;
+ }
+
+ public abstract string Name
+ {
+ get;
+ }
+
+ #endregion Properties
+
+ #region Methods
public static Class Lookup(int id)
{
@@ -42,9 +68,15 @@
return List.FirstOrDefault(x => x.Name.HasWord(name));
}
- public abstract int Id { get; }
- public abstract string Description { get; }
- public abstract string Name { get; }
+ public bool Delete(IDbConnection conn)
+ {
+ //return conn.ExecuteNonQuery("delete_class", DbType.Int32,
Id) == 1;
+ var cmd = conn.CreateCommand("read_class");
+
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public bool Load(IDbConnection conn)
{
@@ -66,16 +98,6 @@
{
return 0;
}
-
- public bool Delete(IDbConnection conn)
- {
- //return conn.ExecuteNonQuery("delete_class", DbType.Int32,
Id) == 1;
- var cmd = conn.CreateCommand("read_class");
-
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
public bool Save(IDbConnection conn)
{
@@ -88,32 +110,67 @@
return cmd.ExecuteNonQuery() > 0;
}
+
+ #endregion Methods
}
public class MageClass : Class
{
+ #region Constructors
+
public MageClass()
{
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public override string Description
+ {
+ get { return "Master of magic and the arcane."; }
+ }
+
public override int Id
{
get { return 1; }
}
- public override string Name { get { return "mage"; } }
- public override string Description { get { return "Master of magic
and the arcane."; } }
+
+ public override string Name
+ {
+ get { return "mage"; }
+ }
+
+ #endregion Properties
}
public class WarriorClass : Class
{
+ #region Constructors
+
public WarriorClass()
{
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public override string Description
+ {
+ get { return "Masters of hand to hand combat and weapons."; }
+ }
public override int Id
{
get { return 2; }
}
- public override string Name { get { return "warrior"; } }
- public override string Description { get { return "Masters of hand
to hand combat and weapons."; } }
+
+ public override string Name
+ {
+ get { return "warrior"; }
+ }
+
+ #endregion Properties
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Exit.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Exit.cs Tue Apr 19 15:57:05 2011
@@ -1,59 +1,90 @@
-
-using NLog;
-using System;
-using System.Data.Linq.Mapping;
-using System.Collections.Generic;
-using System.Data.Odbc;
-using System.Data;
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Data.Linq.Mapping;
+ using System.Data.Odbc;
+
+ using NLog;
+
+ #region Enumerations
+
+ public enum Direction
+ {
+ North,
+ South,
+ East,
+ West,
+ Up,
+ Down
+ }
+
[Flags]
public enum ExitFlag
{
None, Closed, Door, Locked, NoPass, PickProof
}
+
+ #endregion Enumerations
public class Exit : IEntity<long>, IPersistent
{
- public long Id { get; set; }
-
- public Room ToRoom { get; set; }
-
- public long? Key { get; set; }
-
- public ExitFlag Flags { get; set; }
-
- public string Name { get; set; }
-
- public string Description { get; set; }
-
- public Room Room { get; set; }
-
- public Direction Direction { get; set; }
-
- public bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_exit");
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@to_room", DbType.Int64, ToRoom.Id);
- if (Key.HasValue)
- cmd.AddParameter("@key", DbType.Int64, Key.Value);
- else
- cmd.AddParameter("@key", DbType.Int64, DBNull.Value);
-
- cmd.AddParameter("@flags", DbType.String, Flags.ToString());
- cmd.AddParameter("@name", DbType.String, Name);
- cmd.AddParameter("@descr", DbType.String, Description);
- cmd.AddParameter("@room", DbType.Int64, Room.Id);
- cmd.AddParameter("@dir", DbType.String, Direction.ToString());
-
- var res = cmd.ExecuteNonQuery() > 0;
-
- if (Id == 0 && res)
- Id = Convert.ToInt64(conn.LastInsertId());
-
- return res;
+ #region Properties
+
+ public string Description
+ {
+ get; set;
+ }
+
+ public Direction Direction
+ {
+ get; set;
+ }
+
+ public ExitFlag Flags
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public long? Key
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ public Room Room
+ {
+ get; set;
+ }
+
+ public Room ToRoom
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_exit");
+
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@room", DbType.Int64, Room.Id);
+ cmd.AddParameter("@dir", DbType.String, Direction.ToString());
+
+ return cmd.ExecuteNonQuery() == 1;
}
public bool Load(IDbConnection conn)
@@ -67,23 +98,11 @@
var reader = cmd.ExecuteReader();
-
if (!reader.Read()) return false;
MapRow(reader);
return true;
-
- }
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_exit");
-
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@room", DbType.Int64, Room.Id);
- cmd.AddParameter("@dir", DbType.String, Direction.ToString());
-
- return cmd.ExecuteNonQuery() == 1;
}
public int MapRow(IDataRecord reader)
@@ -102,15 +121,31 @@
return i;
}
- }
-
- public enum Direction
- {
- North,
- South,
- East,
- West,
- Up,
- Down
+
+ public bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_exit");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@to_room", DbType.Int64, ToRoom.Id);
+ if (Key.HasValue)
+ cmd.AddParameter("@key", DbType.Int64, Key.Value);
+ else
+ cmd.AddParameter("@key", DbType.Int64, DBNull.Value);
+
+ cmd.AddParameter("@flags", DbType.String, Flags.ToString());
+ cmd.AddParameter("@name", DbType.String, Name);
+ cmd.AddParameter("@descr", DbType.String, Description);
+ cmd.AddParameter("@room", DbType.Int64, Room.Id);
+ cmd.AddParameter("@dir", DbType.String, Direction.ToString());
+
+ var res = cmd.ExecuteNonQuery() > 0;
+
+ if (Id == 0 && res)
+ Id = Convert.ToInt64(conn.LastInsertId());
+
+ return res;
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Help.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Help.cs Tue Apr 19 15:57:05 2011
@@ -1,77 +1,81 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Collections.ObjectModel;
-using NLog;
-using System.Linq;
-using System.Collections.Specialized;
-using System.Data;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
[Flags]
public enum HelpCategory
{
None, Admin, Information
}
+
+ #endregion Enumerations
public class Help : IEquatable<Help>, IEntity<long>, IPersistent
{
+ #region Fields
+
public static readonly HashSet<Help> List = new HashSet<Help>();
+ #endregion Fields
+
+ #region Constructors
+
static Help()
{
ReadAll();
}
-
+
public Help()
{
}
- public long Id { get; set; }
-
- public string Text { get; set; }
-
- public HelpCategory Category { get; set; }
-
- public IList<Help> Related { get; set; }
-
- public ISet<string> Keywords { get; set; }
-
- #region Implementation of IEquatable<Help>
-
- public override bool Equals(object obj)
- {
- if (!(obj is Help)) return false;
-
- return Equals(obj as Help);
+ #endregion Constructors
+
+ #region Properties
+
+ public HelpCategory Category
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public ISet<string> Keywords
+ {
+ get; set;
}
- public override int GetHashCode()
- {
- return Id.GetHashCode();
+ public IList<Help> Related
+ {
+ get; set;
}
- /// <summary>
- /// Indicates whether the current object is
equal to another object of the same type.
- /// </summary>
- /// <returns>
- /// true if the current object is equal to the <paramref
name="other" /> parameter; otherwise, false.
- /// </returns>
- /// <param name="other">
- /// An object to compare with this object.
- /// </param>
- public bool Equals(Help other)
- {
- return Id == other.Id;
+ public string Text
+ {
+ get; set;
}
- #endregion
-
+ #endregion Properties
+
+ #region Methods
+
+ public static Help Lookup(long id)
+ {
+ return List.SingleOrDefault(x => x.Id == id);
+ }
public static void ReadAll()
{
@@ -104,62 +108,78 @@
}
}
- private static ISet<string> ReadKeywords(long id, IDbConnection
conn)
- {
- var cmd = conn.CreateCommand("select_help_keywords");
- cmd.AddParameter("@id", DbType.Int64, id);
-
- var reader = cmd.ExecuteReader();
-
- var list = new HashSet<string>();
-
- while (reader.Read())
- {
- list.Add(reader.GetString(1));
- }
-
- return list;
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_help");
+
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (!(obj is Help)) return false;
+
+ return Equals(obj as Help);
}
- private static IList<Help> ReadRelated(long id, IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_related_helps");
- cmd.AddParameter("@id", DbType.Int64, id);
+ /// <summary>
+ /// Indicates whether the current object is
equal to another object of the same type.
+ /// </summary>
+ /// <returns>
+ /// true if the current object is equal to the <paramref
name="other" /> parameter; otherwise, false.
+ /// </returns>
+ /// <param name="other">
+ /// An object to compare with this object.
+ /// </param>
+ public bool Equals(Help other)
+ {
+ return Id == other.Id;
+ }
+
+ public override int GetHashCode()
+ {
+ return Id.GetHashCode();
+ }
+
+ public bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_help");
+
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
var reader = cmd.ExecuteReader();
- var list = new List<Help>();
-
- while (reader.Read())
- {
- var relId = reader.GetInt64(1);
- var help = Lookup(relId);
- if (help != null)
- list.Add(help);
- else
- {
- var cmd2 = conn.CreateCommand("delete_related_help");
- cmd2.AddParameter("@id", DbType.Int64, id);
- cmd2.AddParameter("@related", DbType.Int64, relId);
- cmd2.ExecuteNonQuery();
- }
- }
-
- return list;
+ if (!reader.Read()) return false;
+
+ MapRow(reader);
+
+ Related = ReadRelated(Id, conn);
+
+ Keywords = ReadKeywords(Id, conn);
+ return true;
}
- public static Help Lookup(long id)
- {
- return List.SingleOrDefault(x => x.Id == id);
+ public int MapRow(IDataRecord reader)
+ {
+ int i = 0;
+
+ Id = reader.GetInt64(i++);
+ Text = reader.GetString(i++);
+ Category = reader.GetEnum<HelpCategory>(i++);
+
+ return i;
}
public bool Save(IDbConnection conn)
{
var cmd = conn.CreateCommand("save_help");
-
+
cmd.AddParameter("@id", DbType.Int64, Id);
cmd.AddParameter("@text", DbType.String, Text);
cmd.AddParameter("@category", DbType.String,
Category.ToString());
-
+
var res = cmd.ExecuteNonQuery() > 0;
if (Id == 0 && res)
@@ -189,44 +209,49 @@
return res;
}
- public int MapRow(IDataRecord reader)
- {
- int i = 0;
-
- Id = reader.GetInt64(i++);
- Text = reader.GetString(i++);
- Category = reader.GetEnum<HelpCategory>(i++);
-
- return i;
- }
-
- public bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_help");
-
- cmd.AddParameter("@id", DbType.Int64, Id);
-
+ private static ISet<string> ReadKeywords(long id, IDbConnection
conn)
+ {
+ var cmd = conn.CreateCommand("select_help_keywords");
+ cmd.AddParameter("@id", DbType.Int64, id);
+
+ var reader = cmd.ExecuteReader();
+
+ var list = new HashSet<string>();
+
+ while (reader.Read())
+ {
+ list.Add(reader.GetString(1));
+ }
+
+ return list;
+ }
+
+ private static IList<Help> ReadRelated(long id, IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_related_helps");
+ cmd.AddParameter("@id", DbType.Int64, id);
var reader = cmd.ExecuteReader();
- if (!reader.Read()) return false;
-
- MapRow(reader);
-
- Related = ReadRelated(Id, conn);
-
- Keywords = ReadKeywords(Id, conn);
- return true;
-
-
+ var list = new List<Help>();
+
+ while (reader.Read())
+ {
+ var relId = reader.GetInt64(1);
+ var help = Lookup(relId);
+ if (help != null)
+ list.Add(help);
+ else
+ {
+ var cmd2 = conn.CreateCommand("delete_related_help");
+ cmd2.AddParameter("@id", DbType.Int64, id);
+ cmd2.AddParameter("@related", DbType.Int64, relId);
+ cmd2.ExecuteNonQuery();
+ }
+ }
+
+ return list;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_help");
-
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/NonPlayer.cs Mon Apr 18 15:16:31 2011
+++ /trunk/ArtheaEngine/Model/NonPlayer.cs Tue Apr 19 15:57:05 2011
@@ -1,74 +1,81 @@
-#region Includes
-
-using System.Text;
-using NLog;
-using System;
-using System.Linq;
-using System.Data;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
[Flags]
public enum NpcFlag : long
{
None, Aggressive, Guildmaster, Sentinel, StayArea, Wimpy
}
+
+ #endregion Enumerations
public class NonPlayer : Character
{
- public string ShortDescr { get; set; }
-
- public string LongDescr { get; set; }
-
- public Area Area { get; set; }
-
- public NpcFlag Flags { get; set; }
-
- public override World World
- {
- get { return Area.World; }
+ #region Properties
+
+ public Area Area
+ {
+ get; set;
}
- public Shop Shop { get; set; }
-
- #region Overrides of Character
-
- public override void Page(string buf)
- {
+ public NpcFlag Flags
+ {
+ get; set;
}
- public override void Write(string format, params object[] args)
- {
+ public string LongDescr
+ {
+ get; set;
}
- public override void Write(byte[] value)
- {
+ public Shop Shop
+ {
+ get; set;
}
- public override void Write(object obj)
- {
+ public string ShortDescr
+ {
+ get; set;
}
- public override void WriteLine()
- {
+ public override World World
+ {
+ get { return Area.World; }
}
- public override void WriteLine(object obj)
- {
+ #endregion Properties
+
+ #region Methods
+
+ public static NonPlayer Load(long id)
+ {
+ var npc = new NonPlayer();
+ npc.Id = id;
+ npc.Load();
+
+ return npc;
}
- public override void WriteLine(string format, params object[] args)
- {
- }
-
- #endregion
+ public override bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_nonplayer");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1 && base.Delete(conn);
+ }
public override bool Load(IDbConnection conn)
{
var cmd = conn.CreateCommand("read_nonplayer");
-
+
cmd.AddParameter("@id", DbType.Int64, Id);
var reader = cmd.ExecuteReader();
@@ -78,7 +85,6 @@
MapRow(reader);
return true;
-
}
public override int MapRow(IDataRecord reader)
@@ -93,6 +99,11 @@
return i;
}
+
+ public override void Page(string buf)
+ {
+ }
+
public override bool Save(IDbConnection conn)
{
if (!base.Save(conn))
@@ -108,25 +119,32 @@
var res = cmd.ExecuteNonQuery() > 0;
return res;
-
+ }
+
+ public override void Write(string format, params object[] args)
+ {
}
- public override bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_nonplayer");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1 && base.Delete(conn);
-
+ public override void Write(byte[] value)
+ {
+ }
+
+ public override void Write(object obj)
+ {
}
- public static NonPlayer Load(long id)
- {
- var npc = new NonPlayer();
- npc.Id = id;
- npc.Load();
-
- return npc;
- }
+ public override void WriteLine()
+ {
+ }
+
+ public override void WriteLine(object obj)
+ {
+ }
+
+ public override void WriteLine(string format, params object[] args)
+ {
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Note.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Note.cs Tue Apr 19 15:57:05 2011
@@ -1,16 +1,19 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.ObjectModel;
-using NLog;
-using System.Collections.Specialized;
-using System.Data;
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Linq;
+ using System.Text;
+
+ using NLog;
+
public class Note : IEntity<long>, IPersistent
{
+ #region Constructors
+
/// <summary>
/// Initializes a new instance of the <see cref="Note"/> class.
/// </summary>
@@ -41,22 +44,58 @@
});
}
- public long Id { get; set; }
-
- public string Text { get; set; }
-
- public string To { get; set; }
- public string From { get; set; }
-
- public string Subject { get; set; }
-
- public Board Board { get; set; }
-
- public ObservableCollection<Note> Replies { get; set; }
-
- public Note Original { get; set; }
-
- public DateTime When { get; set; }
+ #endregion Constructors
+
+ #region Properties
+
+ public Board Board
+ {
+ get; set;
+ }
+
+ public string From
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public Note Original
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Note> Replies
+ {
+ get; set;
+ }
+
+ public string Subject
+ {
+ get; set;
+ }
+
+ public string Text
+ {
+ get; set;
+ }
+
+ public string To
+ {
+ get; set;
+ }
+
+ public DateTime When
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
public static void ReadAll(Board board)
{
@@ -90,34 +129,15 @@
}
}
- private void ReadReplies(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_note_replies");
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_note");
cmd.AddParameter("@id", DbType.Int64, Id);
cmd.AddParameter("@board", DbType.Int32, Board.Id);
- var reader = cmd.ExecuteReader();
-
- while (reader.Read())
- {
- var reply = new Note();
-
- reply.MapRow(reader);
-
- /*
- reply.Id = reader.GetInt64(0);
- reply.Text = reader.GetString(1);
- reply.To = reader.GetString(2);
- reply.From = reader.GetString(3);
- reply.Subject = reader.GetString(4);
- reply.When = reader.GetDateTime(5);*/
-
- Replies.Add(reply);
-
- reply.ReadReplies(conn);
- }
-
- }
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
public bool Load(IDbConnection conn)
{
var cmd = conn.CreateCommand("read_note");
@@ -129,7 +149,6 @@
if (!reader.Read()) return false;
-
var i = MapRow(reader);
if (!reader.IsDBNull(i))
@@ -143,7 +162,6 @@
if (!reader.IsDBNull(i))
Original = Board.FindNote(reader.GetInt64(i));
return true;
-
}
public int MapRow(IDataRecord reader)
@@ -186,14 +204,34 @@
return res;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_note");
+ private void ReadReplies(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_note_replies");
cmd.AddParameter("@id", DbType.Int64, Id);
cmd.AddParameter("@board", DbType.Int32, Board.Id);
-
- return cmd.ExecuteNonQuery() == 1;
+
+ var reader = cmd.ExecuteReader();
+
+ while (reader.Read())
+ {
+ var reply = new Note();
+
+ reply.MapRow(reader);
+
+ /*
+ reply.Id = reader.GetInt64(0);
+ reply.Text = reader.GetString(1);
+ reply.To = reader.GetString(2);
+ reply.From = reader.GetString(3);
+ reply.Subject = reader.GetString(4);
+ reply.When = reader.GetDateTime(5);*/
+
+ Replies.Add(reply);
+
+ reply.ReadReplies(conn);
+ }
}
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Object.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Object.cs Tue Apr 19 15:57:05 2011
@@ -1,30 +1,183 @@
-#region Includes
-
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using ArtheaEngine;
-using System.Linq;
-using NLog;
-using System.IO;
-using System.Runtime.Serialization.Formatters.Binary;
-using System.Collections.Specialized;
-using System.Data;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.IO;
+ using System.Linq;
+ using System.Runtime.Serialization.Formatters.Binary;
+
+ using ArtheaEngine;
+
+ using NLog;
+
+ /*
+ public class TrashObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Trash; }
+ }
+ }
+
+ public class ScrollObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Scroll; }
+ }
+ }
+
+ public class PillObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Pill; }
+ }
+ }
+
+ public class PotionObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Potion; }
+ }
+ }
+
+ public class WandObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Wand; }
+ }
+ }
+
+ public class StaffObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Staff; }
+ }
+ }
+
+ public class DrinkContainerObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.DrinkContainer; }
+ }
+ }
+
+ public class ContainerObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Container; }
+ }
+ }
+
+ public class FurnitureObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Furniture; }
+ }
+ }
+ public class ArmorObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Armor; }
+ }
+ }
+
+ public class WeaponObject : Object
+ {
+ public override ObjectType Type
+ {
+ get { return ObjectType.Weapon; }
+ }
+ }*/
+
+ #region Enumerations
+
[Flags]
public enum ObjectFlag : long
{
None
}
+
+ public enum ObjectType
+ {
+ Armor,
+ Weapon,
+ Furniture,
+ Container,
+ DrinkContainer,
+ Staff,
+ Wand,
+ Potion,
+ Pill,
+ Scroll,
+ Trash,
+ Food,
+ Key,
+ Portal,
+ Money
+ }
+
+ public enum WeaponClass
+ {
+ Exotic,
+ Sword,
+ Dagger,
+ Spear,
+ Mace,
+ Axe,
+ Flail,
+ Whip,
+ Polearm
+ }
+
+ [Flags]
+ public enum WearFlag
+ {
+ None
+ }
+
+ public enum WearLocation
+ {
+ None,
+ Head,
+ Neck,
+ Shoulders,
+ Arms,
+ Hands,
+ WristRight,
+ WristLeft,
+ Torso,
+ Waist,
+ Legs,
+ Feet,
+ Wielded,
+ Holding,
+ Back
+ }
+
+ #endregion Enumerations
public class Object : IEntity<long>, IDisposable, ICloneable,
IPersistent
{
+ #region Fields
+
public static readonly HashSet<Object> List = new
HashSet<Object>();
+ #endregion Fields
+
+ #region Constructors
+
public Object()
{
Values = new List<object>();
@@ -36,53 +189,99 @@
Affects = new ObservableCollection<Affect>();
}
- object ICloneable.Clone()
- {
- return this.Clone();
+ #endregion Constructors
+
+ #region Properties
+
+ public ObservableCollection<Affect> Affects
+ {
+ get; set;
}
- public Object Clone()
- {
- return MemberwiseClone() as Object;
+ public Area Area
+ {
+ get; set;
}
- public long Id { get; set; }
-
- public float Condition { get; set; }
-
- public string Description { get; set; }
-
- public short Level { get; set; }
-
- public string LongDescr { get; set; }
-
- public string ShortDescr { get; set; }
-
- public float Weight { get; set; }
-
- public string Name { get; set; }
-
- public decimal Cost { get; set; }
-
- public ObjectFlag Flags { get; set; }
-
- public WearFlag WearFlags { get; set; }
-
- public ObservableCollection<Affect> Affects { get; set; }
-
- public Room Room { get; set; }
-
- public Area Area { get; set; }
-
- public ObjectType Type { get; set; }
-
- public Character CarriedBy { get; set; }
-
- public Object Inside { get; set; }
-
- public ObservableCollection<Object> Contents { get; set; }
-
- public IList<object> Values { get; private set; }
+ public Character CarriedBy
+ {
+ get; set;
+ }
+
+ public float Condition
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Object> Contents
+ {
+ get; set;
+ }
+
+ public decimal Cost
+ {
+ get; set;
+ }
+
+ public string Description
+ {
+ get; set;
+ }
+
+ public ObjectFlag Flags
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public Object Inside
+ {
+ get; set;
+ }
+
+ public short Level
+ {
+ get; set;
+ }
+
+ public string LongDescr
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ public Room Room
+ {
+ get; set;
+ }
+
+ public string ShortDescr
+ {
+ get; set;
+ }
+
+ public ObjectType Type
+ {
+ get; set;
+ }
+
+ public IList<object> Values
+ {
+ get; private set;
+ }
+
+ public WearFlag WearFlags
+ {
+ get; set;
+ }
public WearLocation WearLocation
{
@@ -90,69 +289,54 @@
set;
}
- public virtual string ToString(string format, IFormatProvider
formatProvider)
- {
- if (string.IsNullOrEmpty(format)) format = "G";
-
- switch (format.ToUpper())
- {
- case "G":
- case "N":
- return ShortDescr.ToString(formatProvider);
- case "L":
- return Description.ToString(formatProvider);
- default:
- throw new FormatException("Invalid format for object");
- }
+ public float Weight
+ {
+ get; set;
}
- #region IDisposable Members
-
- public virtual void Dispose()
- {
-
+ #endregion Properties
+
+ #region Methods
+
+ public static Object Load(long id)
+ {
+ var obj = new Object();
+ obj.Id = id;
+ obj.Load();
+
+ return obj;
}
- #endregion
-
-
- public virtual bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_object");
+ public static Object Lookup(string argument)
+ {
+ return List.FirstOrDefault(x => x.Name.HasWord(argument));
+ }
+
+ public static Object Lookup(long id)
+ {
+ return List.FirstOrDefault(x => x.Id == id);
+ }
+
+ public Object Clone()
+ {
+ return MemberwiseClone() as Object;
+ }
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_object");
cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@condition", DbType.Single, Condition);
- cmd.AddParameter("@descr", DbType.String, Description);
- cmd.AddParameter("@level", DbType.Int16, Level);
- cmd.AddParameter("@long_descr", DbType.String, LongDescr);
- cmd.AddParameter("@short_descr", DbType.String, ShortDescr);
- cmd.AddParameter("@weight", DbType.Single, Weight);
- cmd.AddParameter("@name", DbType.String, Name);
- cmd.AddParameter("@cost", DbType.Currency, Cost);
- cmd.AddParameter("@flags", DbType.String, Flags.ToString());
- cmd.AddParameter("@wear_Flags", DbType.String,
WearFlags.ToString());
- cmd.AddParameter("@area", DbType.Int64, Area.Id);
- cmd.AddParameter("@type", DbType.String, Type.ToString());
-
- var ms = new MemoryStream();
- var bf = new BinaryFormatter();
-
- bf.Serialize(ms, Values);
- cmd.AddParameter("@values", DbType.Binary, ms.ToArray());
-
- if (Inside != null)
- cmd.AddParameter("@inside", DbType.Int64, Inside.Id);
- else
- cmd.AddParameter("@inside", DbType.Int64, DBNull.Value);
-
- var res = cmd.ExecuteNonQuery() > 0;
-
- if (Id == 0 && res)
- {
- Id = Convert.ToInt64(conn.LastInsertId());
- List.Add(this);
- }
-
- return res;
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
+ public virtual void Dispose()
+ {
+ }
+
+ object ICloneable.Clone()
+ {
+ return this.Clone();
}
public virtual bool Load(IDbConnection conn)
@@ -193,15 +377,6 @@
return i;
}
-
- public static Object Load(long id)
- {
- var obj = new Object();
- obj.Id = id;
- obj.Load();
-
- return obj;
- }
public void ReadContents(IDbConnection conn)
{
@@ -219,167 +394,61 @@
}
}
- public static Object Lookup(string argument)
- {
- return List.FirstOrDefault(x => x.Name.HasWord(argument));
- }
-
- public static Object Lookup(long id)
- {
- return List.FirstOrDefault(x => x.Id == id);
- }
-
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_object");
+ public virtual bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_object");
cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
- }
-
- public enum WearLocation
- {
- None,
- Head,
- Neck,
- Shoulders,
- Arms,
- Hands,
- WristRight,
- WristLeft,
- Torso,
- Waist,
- Legs,
- Feet,
- Wielded,
- Holding,
- Back
- }
-
- public enum WeaponClass
- {
- Exotic,
- Sword,
- Dagger,
- Spear,
- Mace,
- Axe,
- Flail,
- Whip,
- Polearm
- }
-
- public enum ObjectType
- {
- Armor,
- Weapon,
- Furniture,
- Container,
- DrinkContainer,
- Staff,
- Wand,
- Potion,
- Pill,
- Scroll,
- Trash,
- Food,
- Key,
- Portal,
- Money
- }
-
- [Flags]
- public enum WearFlag
- {
- None
- }
-
- /*
- public class TrashObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Trash; }
- }
- }
-
- public class ScrollObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Scroll; }
- }
- }
-
- public class PillObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Pill; }
- }
- }
-
- public class PotionObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Potion; }
- }
- }
-
- public class WandObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Wand; }
- }
- }
-
- public class StaffObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Staff; }
- }
- }
-
- public class DrinkContainerObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.DrinkContainer; }
- }
- }
-
- public class ContainerObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Container; }
- }
- }
-
- public class FurnitureObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Furniture; }
- }
- }
- public class ArmorObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Armor; }
- }
- }
-
- public class WeaponObject : Object
- {
- public override ObjectType Type
- {
- get { return ObjectType.Weapon; }
- }
- }*/
-}
+ cmd.AddParameter("@condition", DbType.Single, Condition);
+ cmd.AddParameter("@descr", DbType.String, Description);
+ cmd.AddParameter("@level", DbType.Int16, Level);
+ cmd.AddParameter("@long_descr", DbType.String, LongDescr);
+ cmd.AddParameter("@short_descr", DbType.String, ShortDescr);
+ cmd.AddParameter("@weight", DbType.Single, Weight);
+ cmd.AddParameter("@name", DbType.String, Name);
+ cmd.AddParameter("@cost", DbType.Currency, Cost);
+ cmd.AddParameter("@flags", DbType.String, Flags.ToString());
+ cmd.AddParameter("@wear_Flags", DbType.String,
WearFlags.ToString());
+ cmd.AddParameter("@area", DbType.Int64, Area.Id);
+ cmd.AddParameter("@type", DbType.String, Type.ToString());
+
+ var ms = new MemoryStream();
+ var bf = new BinaryFormatter();
+
+ bf.Serialize(ms, Values);
+ cmd.AddParameter("@values", DbType.Binary, ms.ToArray());
+
+ if (Inside != null)
+ cmd.AddParameter("@inside", DbType.Int64, Inside.Id);
+ else
+ cmd.AddParameter("@inside", DbType.Int64, DBNull.Value);
+
+ var res = cmd.ExecuteNonQuery() > 0;
+
+ if (Id == 0 && res)
+ {
+ Id = Convert.ToInt64(conn.LastInsertId());
+ List.Add(this);
+ }
+
+ return res;
+ }
+
+ public virtual string ToString(string format, IFormatProvider
formatProvider)
+ {
+ if (string.IsNullOrEmpty(format)) format = "G";
+
+ switch (format.ToUpper())
+ {
+ case "G":
+ case "N":
+ return ShortDescr.ToString(formatProvider);
+ case "L":
+ return Description.ToString(formatProvider);
+ default:
+ throw new FormatException("Invalid format for object");
+ }
+ }
+
+ #endregion Methods
+ }
+}
=======================================
--- /trunk/ArtheaEngine/Model/Player.cs Mon Apr 18 15:16:31 2011
+++ /trunk/ArtheaEngine/Model/Player.cs Tue Apr 19 15:57:05 2011
@@ -1,118 +1,149 @@
-#region Includes
-
-using System.Text;
-using System;
-using System.Linq;
-using System.Collections.Generic;
-using System.Data.SqlClient;
-using System.Configuration;
-using System.Collections.ObjectModel;
-using NLog;
-using System.Data;
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Configuration;
+ using System.Data;
+ using System.Data.SqlClient;
+ using System.Linq;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
[Flags]
- public enum PcFlag
+ public enum ChannelFlag
{
None
}
[Flags]
- public enum ChannelFlag
+ public enum PcFlag
{
None
}
+
+ #endregion Enumerations
public class Player : Character
{
+ #region Constructors
+
public Player()
{
LastNote = new Dictionary<int, DateTime>();
}
- public string Title { get; set; }
-
- public ChannelFlag ChannelFlags { get; set; }
-
- public Account Account { get; set; }
-
- public Dictionary<int, DateTime> LastNote { get; private set; }
-
- public Class Class { get; set; }
+ #endregion Constructors
+
+ #region Properties
+
+ public Account Account
+ {
+ get; set;
+ }
+
+ public ChannelFlag ChannelFlags
+ {
+ get; set;
+ }
+
+ public Class Class
+ {
+ get; set;
+ }
+
+ public Dictionary<int, DateTime> LastNote
+ {
+ get; private set;
+ }
+
+ public string Title
+ {
+ get; set;
+ }
public override World World
{
get { return Account.Connection.World; }
}
- public bool HasReadNote(Note note)
- {
- if (!LastNote.ContainsKey(
note.Board.Id))
- return false;
-
-
- return note.When < LastNote[
note.Board.Id];
- }
-
- #region Overrides of Character
+ #endregion Properties
+
+ #region Methods
+
+ public override bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_player");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1 && base.Delete(conn);
+ }
public override void Dispose()
{
base.Dispose();
}
- public override void Page(string buf)
- {
- if (Account != null)
- Account.Page(buf);
+ public bool HasReadNote(Note note)
+ {
+ if (!LastNote.ContainsKey(
note.Board.Id))
+ return false;
+
+ return note.When < LastNote[
note.Board.Id];
}
- public override void Write(string format, params object[] args)
- {
- if (Account != null)
- {
- Account.Write(format, args);
- }
- }
-
- public override void Write(byte[] value)
- {
- if (Account == null) return;
-
- Account.Write(value);
+ public override bool Load(IDbConnection conn)
+ {
+ using (var cmd = conn.CreateCommand("read_player"))
+ {
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ if (!this.Load(cmd))
+ return false;
+ }
+
+ LoadCarrying(conn);
+
+ if (Account.Login == null)
+ {
+ Account.Load();
+ }
+ return true;
}
- public override void Write(object obj)
- {
- if (Account == null) return;
-
- Account.Write(obj);
- }
-
- public override void WriteLine()
- {
- if (Account == null) return;
-
- Account.WriteLine();
+ public override int MapRow(IDataRecord reader)
+ {
+ var i = base.MapRow(reader);
+
+ Room = Room.Lookup(reader.GetInt64(i++));
+ Title = reader.GetStringOrNull(i++);
+ ChannelFlags = reader.GetEnum<ChannelFlag>(i++);
+
+ if (Account == null)
+ {
+ Account = new Account();
+ Account.Id = reader.GetInt64(i++);
+ }
+ else
+ {
+ if (Account.Id != reader.GetInt64(i++))
+ LogManager.GetCurrentClassLogger().Warn("Loading
player for different account!");
+ }
+ Class = Class.Lookup(reader.GetInt32(i++));
+ if (Class == null)
+ Class = new MageClass();
+
+ return i;
}
- public override void WriteLine(object obj)
- {
- if (Account == null) return;
-
- Account.WriteLine(obj);
- }
-
- public override void WriteLine(string format, params object[] args)
- {
- if (Account == null) return;
-
- Account.WriteLine(format, args);
- }
-
- #endregion
+ public override void Page(string buf)
+ {
+ if (Account != null)
+ Account.Page(buf);
+ }
public override bool Save(IDbConnection conn)
{
@@ -131,7 +162,6 @@
var res = cmd.ExecuteNonQuery() > 0;
-
foreach (var obj in Carrying)
{
cmd = conn.CreateCommand("save_char_obj");
@@ -147,77 +177,68 @@
return res;
}
- public override bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_player");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1 && base.Delete(conn);
+ public override void Write(string format, params object[] args)
+ {
+ if (Account != null)
+ {
+ Account.Write(format, args);
+ }
}
- private void LoadCarrying(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_char_objects");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- var reader = cmd.ExecuteReader();
-
- while (reader.Read())
- {
- var chObj = new CharObj();
-
- chObj.Character = this;
-
- chObj.MapRow(reader);
-
- Carrying.Add(chObj);
- }
+ public override void Write(byte[] value)
+ {
+ if (Account == null) return;
+
+ Account.Write(value);
+ }
+
+ public override void Write(object obj)
+ {
+ if (Account == null) return;
+
+ Account.Write(obj);
+ }
+
+ public override void WriteLine()
+ {
+ if (Account == null) return;
+
+ Account.WriteLine();
}
- public override bool Load(IDbConnection conn)
- {
- using (var cmd = conn.CreateCommand("read_player"))
- {
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- if (!this.Load(cmd))
- return false;
- }
-
- LoadCarrying(conn);
-
- if (Account.Login == null)
- {
- Account.Load();
- }
- return true;
-
+ public override void WriteLine(object obj)
+ {
+ if (Account == null) return;
+
+ Account.WriteLine(obj);
+ }
+
+ public override void WriteLine(string format, params object[] args)
+ {
+ if (Account == null) return;
+
+ Account.WriteLine(format, args);
}
- public override int MapRow(IDataRecord reader)
- {
- var i = base.MapRow(reader);
-
- Room = Room.Lookup(reader.GetInt64(i++));
- Title = reader.GetStringOrNull(i++);
- ChannelFlags = reader.GetEnum<ChannelFlag>(i++);
-
- if (Account == null)
- {
- Account = new Account();
- Account.Id = reader.GetInt64(i++);
- }
- else
- {
- if (Account.Id != reader.GetInt64(i++))
- LogManager.GetCurrentClassLogger().Warn("Loading
player for different account!");
- }
- Class = Class.Lookup(reader.GetInt32(i++));
- if (Class == null)
- Class = new MageClass();
-
- return i;
- }
- }
-
-}
+ private void LoadCarrying(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_char_objects");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ var reader = cmd.ExecuteReader();
+
+ while (reader.Read())
+ {
+ var chObj = new CharObj();
+
+ chObj.Character = this;
+
+ chObj.MapRow(reader);
+
+ Carrying.Add(chObj);
+ }
+ }
+
+ #endregion Methods
+ }
+}
=======================================
--- /trunk/ArtheaEngine/Model/Race.cs Mon Apr 18 15:16:31 2011
+++ /trunk/ArtheaEngine/Model/Race.cs Tue Apr 19 15:57:05 2011
@@ -1,30 +1,95 @@
-
-using System.Collections.Generic;
-using System.Linq;
-using System.Data;
-using System.Data.Odbc;
-using System.Reflection;
-using System;
-using NLog;
-using System.Data.Linq.Mapping;
-
-namespace ArtheaEngine.Model
-{
- public abstract class Race : IEntity<int>, IPersistent
- {
- public static readonly HashSet<Race> List = new HashSet<Race>();
-
- public static Race Lookup(string name)
- {
- return List.FirstOrDefault((r) => r.Name.IsPrefixOf(name));
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Data.Linq.Mapping;
+ using System.Data.Odbc;
+ using System.Linq;
+ using System.Reflection;
+
+ using NLog;
+
+ public class DwarfRace : PcRace
+ {
+ #region Constructors
+
+ public DwarfRace()
+ {
}
- public static Race Lookup(int id)
- {
- return List.FirstOrDefault(r => r.Id == id);
+ #endregion Constructors
+
+ #region Properties
+
+ public override string Description
+ {
+ get { return "A short, stocky race."; }
}
- public Race() { }
+ public override int Id
+ {
+ get { return 2; }
+ }
+
+ public override string Name
+ {
+ get { return "dwarf"; }
+ }
+
+ #endregion Properties
+ }
+
+ public class HumanRace : PcRace
+ {
+ #region Constructors
+
+ public HumanRace()
+ {
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public override string Description
+ {
+ get { return "The standard race."; }
+ }
+
+ public override int Id
+ {
+ get { return 1; }
+ }
+
+ public override string Name
+ {
+ get { return "human"; }
+ }
+
+ #endregion Properties
+ }
+
+ public abstract class PcRace : Race
+ {
+ #region Constructors
+
+ public PcRace()
+ {
+ }
+
+ #endregion Constructors
+ }
+
+ public abstract class Race : IEntity<int>, IPersistent
+ {
+ #region Fields
+
+ public static readonly HashSet<Race> List = new HashSet<Race>();
+
+ #endregion Fields
+
+ #region Constructors
static Race()
{
@@ -44,96 +109,99 @@
}
LogManager.GetCurrentClassLogger().Info("Loaded {0} races",
List.Count);
-
+ }
+
+ public Race()
+ {
}
- public abstract int Id { get; }
- public abstract string Name { get; }
- public abstract string Description { get; }
-
- public bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_race");
-
- cmd.AddParameter("@id", DbType.Int32, Id);
- cmd.AddParameter("@name", DbType.String, Name);
- cmd.AddParameter("@descr", DbType.String, Description);
-
- return cmd.ExecuteNonQuery() > 0;
+ #endregion Constructors
+
+ #region Properties
+
+ public abstract string Description
+ {
+ get;
+ }
+
+ public abstract int Id
+ {
+ get;
}
- public bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_race");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return this.Load(cmd);
+ public abstract string Name
+ {
+ get;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static Race Lookup(string name)
+ {
+ return List.FirstOrDefault((r) => r.Name.IsPrefixOf(name));
}
- public int MapRow(IDataRecord reader)
- {
- return 0;
+ public static Race Lookup(int id)
+ {
+ return List.FirstOrDefault(r => r.Id == id);
}
public bool Delete(IDbConnection conn)
{
var cmd = conn.CreateCommand("delete_race");
cmd.AddParameter("@id", DbType.Int32, Id);
-
+
return cmd.ExecuteNonQuery() == 1;
}
- }
-
- public abstract class PcRace : Race
- {
- public PcRace() { }
- }
-
- public class HumanRace : PcRace
- {
- public HumanRace()
- {
+ public bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_race");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return this.Load(cmd);
}
- public override int Id
- {
- get { return 1; }
- }
- public override string Name { get { return "human"; } }
-
- public override string Description
- {
- get { return "The standard race."; }
- }
-
+ public int MapRow(IDataRecord reader)
+ {
+ return 0;
+ }
+
+ public bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_race");
+
+ cmd.AddParameter("@id", DbType.Int32, Id);
+ cmd.AddParameter("@name", DbType.String, Name);
+ cmd.AddParameter("@descr", DbType.String, Description);
+
+ return cmd.ExecuteNonQuery() > 0;
+ }
+
+ #endregion Methods
}
- public class DwarfRace : PcRace
- {
- public DwarfRace()
- {
- }
-
- public override int Id
- {
- get { return 2; }
- }
- public override string Name { get { return "dwarf"; } }
+ public class UniqueRace : Race
+ {
+ #region Properties
+
public override string Description
{
- get { return "A short, stocky race."; }
- }
- }
-
- public class UniqueRace : Race
- {
+ get { return "A unique, unknown race."; }
+ }
+
public override int Id
{
get { return 0; }
}
- public override string Name { get { return "unique"; } }
-
- public override string Description { get { return "A unique,
unknown race."; } }
+
+ public override string Name
+ {
+ get { return "unique"; }
+ }
+
+ #endregion Properties
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Reset.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Reset.cs Tue Apr 19 15:57:05 2011
@@ -1,27 +1,80 @@
-using ArtheaEngine;
-using System.Linq;
-using System.Collections.ObjectModel;
-using System;
-using NLog;
-using LuaInterface;
-using System.Data.Odbc;
-using System.Data;
-
-namespace ArtheaEngine.Model
-{
- public class Reset : IEntity<long>, IPersistent
- {
- public long Id { get; set; }
- public string Code { get; set; }
- public Room Room { get; set; }
-
- private Lua Lua { get; set; }
-
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.ObjectModel;
+ using System.Data;
+ using System.Data.Odbc;
+ using System.Linq;
+
+ using ArtheaEngine;
+
+ using LuaInterface;
+
+ using NLog;
+
+ public class Reset : IEntity<long>, IPersistent
+ {
+ #region Constructors
public Reset(Room room)
{
Room = room;
}
+
+ #endregion Constructors
+
+ #region Properties
+
+ public string Code
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public Room Room
+ {
+ get; set;
+ }
+
+ private Lua Lua
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public virtual bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_reset");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@room", DbType.Int64, Room.Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
+ public void EquipReset(long id, WearLocation loc)
+ {
+ var npc = Lua["lastNPC"] as NonPlayer;
+
+ if (npc == null) return;
+
+ foreach (var co in npc.Carrying)
+ {
+ if (co.WearLocation == loc) return;
+ }
+
+ var obj = Object.Load(id);
+
+ npc.Carrying.Add(new CharObj { Object = obj, Character = npc,
WearLocation = loc });
+
+ obj.CarriedBy = npc;
+ }
public void Execute()
{
@@ -36,16 +89,7 @@
Lua = null;
}
- private void AddCommands()
- {
- Lua.RegisterFunction("npc", this,
GetType().GetMethod("NpcReset"));
- Lua.RegisterFunction("obj", this,
GetType().GetMethod("ObjReset"));
- Lua.RegisterFunction("give", this,
GetType().GetMethod("GiveReset"));
- Lua.RegisterFunction("equip", this,
GetType().GetMethod("EquipReset"));
- Lua.RegisterFunction("put", this,
GetType().GetMethod("PutReset"));
- }
-
- public void NpcReset(long id, params int[] args)
+ public void GiveReset(long id, params int[] args)
{
int max = 1;
int count = 0;
@@ -55,21 +99,43 @@
max = args[0];
}
- foreach (Character ch in Room.Characters)
- {
- if (ch.Id == id) count++;
+ var npc = Lua["lastNPC"] as NonPlayer;
+
+ if (npc == null) return;
+
+ foreach (CharObj o in npc.Carrying)
+ {
+ if (
o.Object.Id == id) count++;
}
if (count >= max) return;
- var npc = NonPlayer.Load(id);
-
- Room.Characters.Add(npc);
-
- Lua["lastNPC"] = npc;
+ var obj = Object.Load(id);
+
+ npc.Carrying.Add(new CharObj { Object = obj, Character = npc,
WearLocation = WearLocation.None });
+ obj.CarriedBy = npc;
+ }
+
+ public virtual bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_reset");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@room", DbType.Int64, Room.Id);
+
+ return this.Load(cmd);
}
- public void ObjReset(long id, params int[] args)
+ public int MapRow(IDataRecord reader)
+ {
+ int i = 0;
+
+ Id = reader.GetInt64(i++);
+ Code = reader.GetString(i++);
+
+ return i;
+ }
+
+ public void NpcReset(long id, params int[] args)
{
int max = 1;
int count = 0;
@@ -79,21 +145,21 @@
max = args[0];
}
- foreach (Object o in Room.Objects)
- {
- if (o.Id == id) count++;
+ foreach (Character ch in Room.Characters)
+ {
+ if (ch.Id == id) count++;
}
if (count >= max) return;
- var obj = Object.Load(id);
-
- Room.Objects.Add(obj);
-
- Lua["lastOBJ"] = obj;
+ var npc = NonPlayer.Load(id);
+
+ Room.Characters.Add(npc);
+
+ Lua["lastNPC"] = npc;
}
- public void GiveReset(long id, params int[] args)
+ public void ObjReset(long id, params int[] args)
{
int max = 1;
int count = 0;
@@ -103,39 +169,18 @@
max = args[0];
}
- var npc = Lua["lastNPC"] as NonPlayer;
-
- if (npc == null) return;
-
- foreach (CharObj o in npc.Carrying)
- {
- if (
o.Object.Id == id) count++;
+ foreach (Object o in Room.Objects)
+ {
+ if (o.Id == id) count++;
}
if (count >= max) return;
var obj = Object.Load(id);
- npc.Carrying.Add(new CharObj { Object = obj, Character = npc,
WearLocation = WearLocation.None });
- obj.CarriedBy = npc;
- }
-
- public void EquipReset(long id, WearLocation loc)
- {
- var npc = Lua["lastNPC"] as NonPlayer;
-
- if (npc == null) return;
-
- foreach (var co in npc.Carrying)
- {
- if (co.WearLocation == loc) return;
- }
-
- var obj = Object.Load(id);
-
- npc.Carrying.Add(new CharObj { Object = obj, Character = npc,
WearLocation = loc });
-
- obj.CarriedBy = npc;
+ Room.Objects.Add(obj);
+
+ Lua["lastOBJ"] = obj;
}
public void PutReset(long id, params int[] args)
@@ -165,26 +210,6 @@
newObj.Inside = obj;
}
- public virtual bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_reset");
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@room", DbType.Int64, Room.Id);
-
- return this.Load(cmd);
-
-
- }
-
- public int MapRow(IDataRecord reader)
- {
- int i = 0;
-
- Id = reader.GetInt64(i++);
- Code = reader.GetString(i++);
-
- return i;
- }
public virtual bool Save(IDbConnection conn)
{
var cmd = conn.CreateCommand("save_reset");
@@ -200,14 +225,15 @@
return res;
}
- public virtual bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_reset");
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@room", DbType.Int64, Room.Id);
-
- return cmd.ExecuteNonQuery() == 1;
+ private void AddCommands()
+ {
+ Lua.RegisterFunction("npc", this,
GetType().GetMethod("NpcReset"));
+ Lua.RegisterFunction("obj", this,
GetType().GetMethod("ObjReset"));
+ Lua.RegisterFunction("give", this,
GetType().GetMethod("GiveReset"));
+ Lua.RegisterFunction("equip", this,
GetType().GetMethod("EquipReset"));
+ Lua.RegisterFunction("put", this,
GetType().GetMethod("PutReset"));
}
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Room.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Room.cs Tue Apr 19 15:57:05 2011
@@ -1,28 +1,54 @@
-#region Includes
-
-using System;
-using Object=ArtheaEngine.Model.Object;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using NLog;
-using System.Linq;
-using System.Data;
-
-#endregion
-
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Linq;
+
+ using NLog;
+
+ using Object = ArtheaEngine.Model.Object;
+
+ #region Enumerations
+
[Flags]
public enum RoomFlag : long
{
None
}
+
+ public enum Terrain
+ {
+ Inside,
+ City,
+ Field,
+ Forest,
+ Hills,
+ Mountain,
+ Water,
+ Air,
+ Desert,
+ Jungle,
+ Road,
+ Path,
+ Cave,
+ Swamp
+ }
+
+ #endregion Enumerations
public class Room : IEntity<long>, IPersistent
{
+ #region Fields
+
public static HashSet<Room> List = new HashSet<Room>();
+ #endregion Fields
+
+ #region Constructors
+
public Room()
{
Characters = new ObservableCollection<Character>();
@@ -38,53 +64,89 @@
Exits = new Dictionary<Direction, Exit>();
}
- public static Room GetDefault()
- {
- var room = List.FirstOrDefault();
-
- if (room != null) return room;
-
- room = new Room { Name = "Limbo", Description = "You are in
darkness.", Terrain = Terrain.Air };
-
- room.Area = Area.GetDefault();
-
- return room;
+ #endregion Constructors
+
+ #region Properties
+
+ public Area Area
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Character> Characters
+ {
+ get; set;
+ }
+
+ public string Description
+ {
+ get; set;
}
- public void LoadReset(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("select_room_reset");
-
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- using (var reader = cmd.ExecuteReader())
- {
-
- if (!reader.Read()) return;
-
-
- Reset = new Reset(this);
- Reset.MapRow(reader);
- }
- }
- public long Id { get; set; }
-
- public Area Area { get; set; }
-
- public string Name { get; set; }
-
- public string Description { get; set; }
-
- public Terrain Terrain { get; set; }
- public RoomFlag Flags { get; set; }
-
- public Dictionary<Direction, Exit> Exits { get; set; }
-
- public ObservableCollection<Object> Objects { get; set; }
-
- public ObservableCollection<Character> Characters { get; set; }
-
- public Reset Reset { get; set; }
+ public Dictionary<Direction, Exit> Exits
+ {
+ get; set;
+ }
+
+ public RoomFlag Flags
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public string Name
+ {
+ get; set;
+ }
+
+ public ObservableCollection<Object> Objects
+ {
+ get; set;
+ }
+
+ public Reset Reset
+ {
+ get; set;
+ }
+
+ public Terrain Terrain
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static Room GetDefault()
+ {
+ var room = List.FirstOrDefault();
+
+ if (room != null) return room;
+
+ room = new Room { Name = "Limbo", Description = "You are in
darkness.", Terrain = Terrain.Air };
+
+ room.Area = Area.GetDefault();
+
+ return room;
+ }
+
+ public static Room Lookup(long id)
+ {
+ return List.FirstOrDefault(x => x.Id == id);
+ }
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_room");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public virtual bool Equals(Room obj)
{
@@ -105,29 +167,6 @@
{
return Id.GetHashCode();
}
-
- public virtual string ToString(string format, IFormatProvider
formatProvider)
- {
- if (string.IsNullOrEmpty(format)) format = "G";
-
- switch (format.ToUpper())
- {
- case "G":
- case "N":
- return Name.ToString(formatProvider);
- case "D":
- return Description.ToString(formatProvider);
- default:
- throw new FormatException("invalid room format");
- }
- }
-
- public void Tick()
- {
- if(Reset != null)
- Reset.Execute();
-
- }
public bool Load(IDbConnection conn)
{
@@ -140,7 +179,22 @@
MapRow(reader);
return true;
-
+ }
+
+ public void LoadReset(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("select_room_reset");
+
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ using (var reader = cmd.ExecuteReader())
+ {
+
+ if (!reader.Read()) return;
+
+ Reset = new Reset(this);
+ Reset.MapRow(reader);
+ }
}
public int MapRow(IDataRecord reader)
@@ -158,14 +212,6 @@
return i;
}
-
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_room");
- cmd.AddParameter("@id", DbType.Int64, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
public bool Save(IDbConnection conn)
{
@@ -192,27 +238,28 @@
return res;
}
- public static Room Lookup(long id)
- {
- return List.FirstOrDefault(x => x.Id == id);
- }
- }
-
- public enum Terrain
- {
- Inside,
- City,
- Field,
- Forest,
- Hills,
- Mountain,
- Water,
- Air,
- Desert,
- Jungle,
- Road,
- Path,
- Cave,
- Swamp
+ public void Tick()
+ {
+ if(Reset != null)
+ Reset.Execute();
+ }
+
+ public virtual string ToString(string format, IFormatProvider
formatProvider)
+ {
+ if (string.IsNullOrEmpty(format)) format = "G";
+
+ switch (format.ToUpper())
+ {
+ case "G":
+ case "N":
+ return Name.ToString(formatProvider);
+ case "D":
+ return Description.ToString(formatProvider);
+ default:
+ throw new FormatException("invalid room format");
+ }
+ }
+
+ #endregion Methods
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Shop.cs Tue Apr 19 15:23:35 2011
+++ /trunk/ArtheaEngine/Model/Shop.cs Tue Apr 19 15:57:05 2011
@@ -1,20 +1,59 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Data.Odbc;
-using System.Data;
-namespace ArtheaEngine.Model
-{
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Data;
+ using System.Data.Odbc;
+ using System.Linq;
+ using System.Text;
+
public class Shop : IEntity<long>, IPersistent
{
- public long Id { get; set; }
-
- public short ProfitBuy { get; set; }
- public short ProfitSell { get; set; }
- public short OpenHour { get; set; }
- public short CloseHour { get; set; }
- public Character Owner { get; set; }
+ #region Properties
+
+ public short CloseHour
+ {
+ get; set;
+ }
+
+ public long Id
+ {
+ get; set;
+ }
+
+ public short OpenHour
+ {
+ get; set;
+ }
+
+ public Character Owner
+ {
+ get; set;
+ }
+
+ public short ProfitBuy
+ {
+ get; set;
+ }
+
+ public short ProfitSell
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_shop");
+
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ cmd.AddParameter("@owner", DbType.Int64, Owner.Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
public bool Load(IDbConnection conn)
{
@@ -56,16 +95,6 @@
return res;
}
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_shop");
-
- cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@owner", DbType.Int64, Owner.Id);
-
- return cmd.ExecuteNonQuery() == 1;
-
- }
-
+ #endregion Methods
}
}
=======================================
***Additional files exist in this changeset.***