Revision: 468
Author: c0der78
Date: Wed Apr 20 15:25:46 2011
Log: add some combat stuff
http://code.google.com/p/arthea/source/detail?r=468
Added:
/trunk/ArtheaEditor/Libraries
/trunk/ArtheaEditor/Libraries/Transitions.dll
/trunk/ArtheaEngine/Combat.cs
/trunk/ArtheaEngine/Dice.cs
/trunk/ArtheaServer/Commands/KillCommand.cs
/trunk/ArtheaServer/Commands/LookCommand.cs
/trunk/ArtheaServer/Libraries
/trunk/ArtheaServer/Libraries/Microsoft.Win32.TaskScheduler.dll
Deleted:
/trunk/External
Modified:
/trunk/ArtheaEditor/ArtheaEditor.csproj
/trunk/ArtheaEngine/ArtheaEngine.csproj
/trunk/ArtheaEngine/Model/Ability.cs
/trunk/ArtheaEngine/Model/Area.cs
/trunk/ArtheaEngine/Model/Character.cs
/trunk/ArtheaEngine/Model/Reset.cs
/trunk/ArtheaEngine/Model/Room.cs
/trunk/ArtheaEngine/Model/Social.cs
/trunk/ArtheaEngine/Model/World.cs
/trunk/ArtheaEngine/UpdateManager.cs
/trunk/ArtheaEngine.Tests/ArtheaEngine.Tests.csproj
/trunk/ArtheaServer/ArtheaServer.csproj
/trunk/ArtheaServer/Commands/ChannelCommand.cs
/trunk/ArtheaServer/MainForm.cs
/trunk/ArtheaServer/TelnetServer.cs
=======================================
--- /dev/null
+++ /trunk/ArtheaEditor/Libraries/Transitions.dll Wed Apr 20 15:25:46 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/ArtheaEngine/Combat.cs Wed Apr 20 15:25:46 2011
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ArtheaEngine.Model;
+
+namespace ArtheaEngine
+{
+ public class Combat : ITickable
+ {
+ public Combat(Character ch, Character victim)
+ {
+ Attacker = ch;
+ Victim = victim;
+ }
+ public int TickInterval { get { return 1000; } }
+
+ public void Tick()
+ {
+ int[] attacks = Attacker.Attack.RollAgainst(Victim.Defense);
+
+ foreach (var attack in attacks)
+ {
+ var damages = Attacker.Attack.RollAgainst(Victim.Defense);
+
+ var damage = 0;
+
+ Array.ForEach(attacks, x => damage += x);
+
+ Attacker.Act("You hit {0} for {1} damage!", Victim,
damage);
+ Victim.Act("{0} hits you for {1} damage!", Attacker,
damage);
+ Victim.Room.Act("{0} hits {1} for {2} damage!", Attacker,
Victim, damage);
+ }
+ }
+
+ public Character Attacker { get; private set; }
+ public Character Victim { get; private set; }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/ArtheaEngine/Dice.cs Wed Apr 20 15:25:46 2011
@@ -0,0 +1,117 @@
+namespace ArtheaEngine
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Linq;
+ using System.Text;
+
+ public class Dice : Collection<Die>
+ {
+ #region Constructors
+
+ public Dice(int count, int faces)
+ {
+ while (count-- > 0)
+ Add(new Die(faces));
+ }
+
+ public Dice(params Die[] dice)
+ {
+ foreach (var d in dice)
+ Add(d);
+ }
+
+ public Dice()
+ {
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public int Bonus
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public int[] Roll()
+ {
+ int[] values = new int[Count];
+
+ for (int index = 0; index < values.Length; index++)
+ {
+ values[index] = Items[index].Roll();
+ }
+ return values;
+ }
+
+ public int[] RollAgainst(Dice dice)
+ {
+ Collection<int> values = new Collection<int>();
+
+ foreach (var a in Roll())
+ {
+ foreach (var b in dice.Roll())
+ {
+ if (a >= b)
+ values.Add(a);
+ }
+ }
+ return values.ToArray();
+ }
+
+ #endregion Methods
+ }
+
+ public class Die
+ {
+ #region Fields
+
+ private static Random rand = new Random();
+
+ #endregion Fields
+
+ #region Constructors
+
+ public Die(int faceCount)
+ {
+ if (faceCount <= 0)
+ {
+ throw new ArgumentOutOfRangeException("faceCount", "Dice
must have one or more faces.");
+ }
+
+ FaceCount = faceCount;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public int FaceCount
+ {
+ get; set;
+ }
+
+ public int Value
+ {
+ get; set;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public int Roll()
+ {
+ Value = rand.Next(1, FaceCount + 1);
+ return Value;
+ }
+
+ #endregion Methods
+ }
+}
=======================================
--- /dev/null
+++ /trunk/ArtheaServer/Commands/KillCommand.cs Wed Apr 20 15:25:46 2011
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ArtheaEngine.Model;
+using ArtheaEngine;
+
+namespace ArtheaServer.Commands
+{
+ public class KillCommand : Command
+ {
+ public KillCommand()
+ : base("kill", "Attacks another character in the game.", 1)
+ { }
+
+ public override void Execute(Character ch, Argument argument)
+ {
+ var victim = ch.Room.Characters.FirstOrDefault(x =>
x.Name.HasWord(argument));
+
+ if (victim == null)
+ {
+ ch.WriteLine("They aren't here.");
+ return;
+ }
+
+ var combat = new Combat(ch, victim);
+
+ UpdateManager.Add(combat);
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/ArtheaServer/Commands/LookCommand.cs Wed Apr 20 15:25:46 2011
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ArtheaEngine.Model;
+using ArtheaEngine;
+
+namespace ArtheaServer.Commands
+{
+ public class LookCommand : Command
+ {
+ public LookCommand()
+ : base("look", "Examines a room, person or object.", 1)
+ { }
+
+ public override void Execute(Character ch, Argument argument)
+ {
+ if (!argument)
+ {
+ if (ch.Room == null)
+ return;
+
+ ch.WriteLine("~G{0}~x",
ch.Room.Name);
+ ch.WriteLine(ch.Room.Description);
+
+ ch.WriteLine();
+ ch.Write("~g[Exits: ");
+ if (ch.Room.Exits.Count == 0)
+ {
+ ch.WriteLine("None]~x");
+ }
+ else
+ {
+ foreach (var e in ch.Room.Exits)
+ {
+ ch.Write(e.Key);
+ }
+ ch.WriteLine("]~x");
+ }
+ if (ch.Room.Characters.Count > 0)
+ {
+ ch.WriteLine();
+
+
+ foreach (var rch in ch.Room.Characters)
+ {
+ if (rch == ch) continue;
+
+ ch.Act("{0} is here.", rch);
+ }
+ }
+
+ if (ch.Room.Objects.Count > 0)
+ {
+ ch.WriteLine();
+
+ foreach (var obj in ch.Room.Objects)
+ {
+ ch.Act("{0:L}", obj);
+ }
+ }
+ }
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/ArtheaServer/Libraries/Microsoft.Win32.TaskScheduler.dll Wed Apr
20 15:25:46 2011
Binary file, no diff available.
=======================================
--- /trunk/ArtheaEditor/ArtheaEditor.csproj Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEditor/ArtheaEditor.csproj Wed Apr 20 15:25:46 2011
@@ -58,7 +58,7 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Transitions">
- <HintPath>..\External\Transitions.dll</HintPath>
+ <HintPath>Libraries\Transitions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -174,7 +174,7 @@
-->
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_UpdateAssemblyVersion="True"
BuildVersion_UpdateFileVersion="True"
BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs"
BuildVersion_BuildVersioningStyle="YearStamp.MonthStamp.TimeStamp.None" />
+ <UserProperties
BuildVersion_BuildVersioningStyle="YearStamp.MonthStamp.TimeStamp.None"
BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs"
BuildVersion_UpdateFileVersion="True"
BuildVersion_UpdateAssemblyVersion="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
=======================================
--- /trunk/ArtheaEngine/ArtheaEngine.csproj Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEngine/ArtheaEngine.csproj Wed Apr 20 15:25:46 2011
@@ -51,7 +51,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="lua51">
+ <Reference Include="lua51, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=1e1fb15b02227b8a, processorArchitecture=x86">
+ <SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\lua51.dll</HintPath>
</Reference>
<Reference Include="LuaInterface">
@@ -86,6 +87,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Columns.cs" />
+ <Compile Include="Combat.cs" />
+ <Compile Include="Dice.cs" />
<Compile Include="IPersistent.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Model\Board.cs" />
=======================================
--- /trunk/ArtheaEngine/Model/Ability.cs Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEngine/Model/Ability.cs Wed Apr 20 15:25:46 2011
@@ -124,7 +124,7 @@
msg = GetAbilityMsg("MsgOffSelf");
ch.WriteLine(msg);
msg = GetAbilityMsg("MsgOffChar");
- ch.Act(ActType.Room, null, null, msg);
+ ch.Room.Act(msg);
}
else if (from is Object)
{
@@ -134,14 +134,11 @@
msg = GetAbilityMsg("MsgOffObj");
if (item.CarriedBy != null)
{
- item.CarriedBy.Act(ActType.Char, null, null, msg);
+ item.CarriedBy.Act(msg);
}
else if (item.Room != null)
{
- foreach (var ch in item.Room.Characters)
- {
- ch.Act(ActType.Char, null, null, msg);
- }
+ item.Room.Act(msg);
}
}
}
@@ -150,10 +147,7 @@
var room = from as Room;
msg = GetAbilityMsg("MsgOffRoom");
- foreach (var ch in room.Characters)
- {
- ch.WriteLine(msg);
- }
+ room.Act(msg);
}
}
=======================================
--- /trunk/ArtheaEngine/Model/Area.cs Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEngine/Model/Area.cs Wed Apr 20 15:25:46 2011
@@ -11,7 +11,7 @@
using NLog;
- public class Area : IEntity<int>, ISaveable, ILoadable, IFormattable
+ public class Area : IEntity<int>, ISaveable, ILoadable, IFormattable,
ITickable
{
#region Fields
@@ -39,6 +39,8 @@
{
n.Area = a ? this : null;
});
+
+ TickInterval = ArtheaHelper.Randomizer.Next(6000, 12000);
}
#endregion Constructors
@@ -71,6 +73,11 @@
get; set;
}
+ public int TickInterval
+ {
+ get;
+ set;
+ }
public ObservableCollection<Object> Objects
{
get; set;
@@ -229,6 +236,7 @@
public void Tick()
{
+ LogManager.GetCurrentClassLogger().Info("{0} tick!", Name);
foreach (var room in Rooms)
{
room.Tick();
=======================================
--- /trunk/ArtheaEngine/Model/Character.cs Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEngine/Model/Character.cs Wed Apr 20 15:25:46 2011
@@ -14,6 +14,7 @@
#region Enumerations
+ /*
[Flags]
public enum ActType
{
@@ -21,7 +22,7 @@
Room,
NotChar,
World
- }
+ }*/
public enum Position
{
@@ -135,6 +136,9 @@
o.Character = null;
}
});
+
+ Attack = new Dice(1, 2);
+ Defense = new Dice(1, 2);
}
#endregion Constructors
@@ -145,11 +149,21 @@
{
get; set;
}
+
+ public Dice Attack
+ {
+ get; set;
+ }
public ObservableCollection<CharObj> Carrying
{
get; set;
}
+
+ public Dice Defense
+ {
+ get; set;
+ }
public string Description
{
@@ -215,7 +229,7 @@
{
return List.OfType<T>().FirstOrDefault(x =>
x.Name.HasWord(name));
}
-
+ /*
public virtual void Act(ActType type, string format, params
object[] args)
{
var temp = new List<object> { this };
@@ -261,6 +275,11 @@
}
}
}
+ */
+ public void Act(string format, params object[] args)
+ {
+ WriteLine(string.Format(new ActionFormatter(this), format,
args));
+ }
public virtual bool CanSee(Character who)
{
@@ -341,7 +360,9 @@
Description = reader.GetStringOrNull(i++);
Level = reader.GetInt16(i++);
- Race = Race.Lookup(reader.GetInt32(i++));
+ if (!reader.IsDBNull(i))
+ Race = Race.Lookup(reader.GetInt32(i++));
+ else i++;
if (Race == null)
Race = new UniqueRace();
Size = reader.GetFloat(i++);
=======================================
--- /trunk/ArtheaEngine/Model/Reset.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaEngine/Model/Reset.cs Wed Apr 20 15:25:46 2011
@@ -11,9 +11,14 @@
using LuaInterface;
using NLog;
+ using System.IO;
+ using System.Text.RegularExpressions;
public class Reset : IEntity<long>, IPersistent
{
+ NonPlayer lastNPC;
+ Object lastOBJ;
+
#region Constructors
public Reset(Room room)
@@ -39,11 +44,6 @@
{
get; set;
}
-
- private Lua Lua
- {
- get; set;
- }
#endregion Properties
@@ -58,62 +58,78 @@
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)
+ public void EquipReset(string[] args)//long id, WearLocation loc)
+ {
+ if (lastNPC == null) return;
+
+ long id = long.Parse(args[1]);
+
+ WearLocation loc = (WearLocation)
Enum.Parse(typeof(WearLocation), args[2], true);
+
+ foreach (var co in lastNPC.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;
+ lastOBJ = Object.Load(id);
+
+ lastNPC.Carrying.Add(new CharObj { Object = lastOBJ, Character
= lastNPC, WearLocation = loc });
+
+ lastOBJ.CarriedBy = lastNPC;
}
public void Execute()
{
- Lua = new Lua();
-
- AddCommands();
-
- Lua.DoString(Code);
-
- Lua.Close();
-
- Lua = null;
+ var reader = new StringReader(Code);
+
+ for(var line = reader.ReadLine(); line != null; line =
reader.ReadLine())
+ {
+ var args = line.Split(new []{'(', ',', ')'},
StringSplitOptions.RemoveEmptyEntries);
+
+ switch (args[0].ToLower())
+ {
+ case "npc":
+ NpcReset(args);
+ break;
+ case "equip":
+ EquipReset(args);
+ break;
+ case "give":
+ GiveReset(args);
+ break;
+ case "put":
+ PutReset(args);
+ break;
+ }
+ }
+
}
- public void GiveReset(long id, params int[] args)
- {
+ public void GiveReset(string[] args)
+ {
+ long id = long.Parse(args[1]);
+
int max = 1;
int count = 0;
- if (args.Length > 0)
- {
- max = args[0];
+ if (args.Length > 2)
+ {
+ max = int.Parse(args[2]);
}
- var npc = Lua["lastNPC"] as NonPlayer;
-
- if (npc == null) return;
-
- foreach (CharObj o in npc.Carrying)
+ if (lastNPC == null) return;
+
+ foreach (CharObj o in lastNPC.Carrying)
{
if (
o.Object.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;
+ lastOBJ= Object.Load(id);
+
+ lastNPC.Carrying.Add(new CharObj { Object = lastOBJ, Character
= lastNPC, WearLocation = WearLocation.None });
+ lastOBJ.CarriedBy = lastNPC;
}
public virtual bool Load(IDbConnection conn)
@@ -135,14 +151,16 @@
return i;
}
- public void NpcReset(long id, params int[] args)
+ public void NpcReset(string[] args)
{
int max = 1;
int count = 0;
- if (args.Length > 0)
- {
- max = args[0];
+ long id = long.Parse(args[1]);
+
+ if (args.Length > 2)
+ {
+ max = int.Parse(args[2]);
}
foreach (Character ch in Room.Characters)
@@ -152,21 +170,22 @@
if (count >= max) return;
- var npc = NonPlayer.Load(id);
-
- Room.Characters.Add(npc);
-
- Lua["lastNPC"] = npc;
+ lastNPC = NonPlayer.Load(id);
+
+ Room.Characters.Add(lastNPC);
+
}
- public void ObjReset(long id, params int[] args)
- {
+ public void ObjReset(string[] args)
+ {
+ long id = long.Parse(args[1]);
+
int max = 1;
int count = 0;
- if (args.Length > 0)
- {
- max = args[0];
+ if (args.Length > 2)
+ {
+ max = int.Parse(args[2]);
}
foreach (Object o in Room.Objects)
@@ -176,28 +195,25 @@
if (count >= max) return;
- var obj = Object.Load(id);
-
- Room.Objects.Add(obj);
-
- Lua["lastOBJ"] = obj;
+ lastOBJ = Object.Load(id);
+
+ Room.Objects.Add(lastOBJ);
}
- public void PutReset(long id, params int[] args)
- {
+ public void PutReset(string[] args)
+ {
+ long id = long.Parse(args[1]);
int max = 1;
int count = 0;
- var obj = Lua["lastOBJ"] as Object;
-
- if (obj == null) return;
-
- if (args.Length > 0)
- {
- max = args[0];
+ if (lastOBJ == null) return;
+
+ if (args.Length > 2)
+ {
+ max = int.Parse(args[2]);
}
- foreach (Object o in obj.Contents)
+ foreach (Object o in lastOBJ.Contents)
{
if (o.Id == id) count++;
}
@@ -206,8 +222,8 @@
var newObj = Object.Load(id);
- obj.Contents.Add(newObj);
- newObj.Inside = obj;
+ lastOBJ.Contents.Add(newObj);
+ newObj.Inside = lastOBJ;
}
public virtual bool Save(IDbConnection conn)
@@ -225,14 +241,6 @@
return res;
}
- 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 Wed Apr 20 00:25:42 2011
+++ /trunk/ArtheaEngine/Model/Room.cs Wed Apr 20 15:25:46 2011
@@ -137,6 +137,36 @@
{
return List.FirstOrDefault(x => x.Id == id);
}
+
+ public void Act(string format, params object[] args)
+ {
+ foreach (var ch in Characters)
+ {
+ ch.WriteLine(string.Format(new ActionFormatter(ch),
format, args));
+ }
+ }
+
+ public void Act(Character skip, string format, params object[]
args)
+ {
+ foreach (var ch in Characters)
+ {
+ if (ch == skip)
+ continue;
+
+ ch.WriteLine(string.Format(new ActionFormatter(ch),
format, args));
+ }
+ }
+
+ public void Act(ICollection<Character> skip, string format, params
object[] args)
+ {
+ foreach (var ch in Characters)
+ {
+ if (skip.Contains(ch))
+ continue;
+
+ ch.WriteLine(string.Format(new ActionFormatter(ch),
format, args));
+ }
+ }
public bool Delete(IDbConnection conn)
{
@@ -170,23 +200,30 @@
{
var cmd = conn.CreateCommand("read_room");
cmd.AddParameter("@id", DbType.Int64, Id);
- var reader = cmd.ExecuteReader();
-
- if (!reader.Read()) return false;
-
- MapRow(reader);
-
+ using (var reader = cmd.ExecuteReader())
+ {
+
+ if (!reader.Read()) return false;
+
+ MapRow(reader);
+ }
+
return true;
}
public void LoadReset(IDbConnection conn)
{
- var reset = new Reset(this);
-
- if (!reset.Load(conn))
- return;
-
- Reset = reset;
+ var cmd = conn.CreateCommand("select_room_reset");
+ cmd.AddParameter("@id", DbType.Int64, Id);
+ using (var reader = cmd.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+
+ Reset = new Reset(this);
+ Reset.MapRow(reader);
+ }
+ }
}
public int MapRow(IDataRecord reader)
=======================================
--- /trunk/ArtheaEngine/Model/Social.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaEngine/Model/Social.cs Wed Apr 20 15:25:46 2011
@@ -165,8 +165,8 @@
{
if (argument.IsEmpty())
{
- ch.Act(ActType.Room, OthersNoArg);
- ch.Act(ActType.Char, CharNoArg);
+ ch.Room.Act(OthersNoArg, ch);
+ ch.Act(CharNoArg);
return;
}
@@ -182,21 +182,21 @@
return;
}
- ch.Act(ActType.Char, CharObjFound, obj);
- ch.Act(ActType.Room, OthersObjFound, obj);
+ ch.Act(CharObjFound, obj);
+ ch.Room.Act(OthersObjFound, ch, obj);
return;
}
if (victim == ch)
{
- ch.Act(ActType.Char, CharSelf);
- ch.Act(ActType.Room, OthersSelf);
+ ch.Act(CharSelf);
+ ch.Act(OthersSelf, ch);
return;
}
- ch.Act(ActType.Char, CharFound, victim);
- victim.Act(ActType.Char, VictFound, ch);
- victim.Act(ActType.NotChar, OthersFound, ch);
+ ch.Act(CharFound, victim);
+ victim.Act(VictFound, ch);
+ victim.Room.Act(new []{ ch, victim}, OthersFound, ch, victim);
return;
}
=======================================
--- /trunk/ArtheaEngine/Model/World.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaEngine/Model/World.cs Wed Apr 20 15:25:46 2011
@@ -194,6 +194,9 @@
area.MapRow(reader);
Area.List.Add(area);
+
+ UpdateManager.Add(area);
+
Areas.Add(area);
}
}
=======================================
--- /trunk/ArtheaEngine/UpdateManager.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaEngine/UpdateManager.cs Wed Apr 20 15:25:46 2011
@@ -7,50 +7,45 @@
using System.Timers;
using ArtheaEngine.Model;
+ using System.Collections.ObjectModel;
+
+ public interface ITickable
+ {
+ void Tick();
+
+ int TickInterval { get; }
+ }
public static class UpdateManager
{
#region Fields
- const int AreaTick = 34*1000;
-
- static readonly HashSet<World> _worlds = new HashSet<World>();
-
- static Timer areaUpdate = new Timer { Interval = AreaTick };
+ static readonly Dictionary<ITickable, Timer> _timers = new
Dictionary<ITickable, Timer>();
#endregion Fields
- #region Constructors
-
- static UpdateManager()
- {
- areaUpdate.Elapsed += UpdateAreas;
- areaUpdate.Enabled = true;
- }
-
- #endregion Constructors
-
- #region Methods
-
- public static void AddWorld(World world)
- {
- _worlds.Add(world);
- }
-
- public static void RemoveWorld(World world)
- {
- _worlds.Remove(world);
- }
-
- public static void UpdateAreas(object o, ElapsedEventArgs args)
- {
- foreach (var world in _worlds)
- {
- foreach (Area area in world.Areas)
- {
- area.Tick();
- }
- }
+ #region Methods
+
+ public static void Remove(ITickable ticker)
+ {
+ if (!_timers.ContainsKey(ticker)) return;
+
+ _timers[ticker].Stop();
+
+ _timers.Remove(ticker);
+ }
+ public static void Add(ITickable ticker)
+ {
+ var timer = new Timer { Interval = ticker.TickInterval,
Enabled = true };
+
+ timer.Elapsed += delegate(object t, ElapsedEventArgs e)
+ {
+ ticker.Tick();
+ };
+
+ _timers.Add(ticker, timer);
+
+ timer.Start();
}
#endregion Methods
=======================================
--- /trunk/ArtheaEngine.Tests/ArtheaEngine.Tests.csproj Wed Apr 20 00:25:42
2011
+++ /trunk/ArtheaEngine.Tests/ArtheaEngine.Tests.csproj Wed Apr 20 15:25:46
2011
@@ -35,7 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit-console-runner">
- <HintPath>..\..\..\..\..\Program Files\NUnit
2.5.10\bin\net-2.0\lib\nunit-console-runner.dll</HintPath>
+ <HintPath>..\..\..\..\..\Program Files (x86)\NUnit
2.5.10\bin\net-2.0\lib\nunit-console-runner.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.10.11092,
Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\Program Files\NUnit
2.5.10\bin\net-2.0\framework\nunit.framework.dll</HintPath>
=======================================
--- /trunk/ArtheaServer/ArtheaServer.csproj Tue Apr 19 13:25:38 2011
+++ /trunk/ArtheaServer/ArtheaServer.csproj Wed Apr 20 15:25:46 2011
@@ -39,7 +39,7 @@
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Win32.TaskScheduler">
- <HintPath>..\External\Microsoft.Win32.TaskScheduler.dll</HintPath>
+ <HintPath>Libraries\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.3.6.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -74,6 +74,8 @@
<Compile Include="Commands\Command.cs" />
<Compile Include="Commands\CommandsCommand.cs" />
<Compile Include="Commands\EditCommand.cs" />
+ <Compile Include="Commands\KillCommand.cs" />
+ <Compile Include="Commands\LookCommand.cs" />
<Compile Include="Commands\QuitCommand.cs" />
<Compile Include="Commands\RebootCommand.cs" />
<Compile Include="Commands\SaveCommand.cs" />
=======================================
--- /trunk/ArtheaServer/Commands/ChannelCommand.cs Sun Apr 3 15:23:52 2011
+++ /trunk/ArtheaServer/Commands/ChannelCommand.cs Wed Apr 20 15:25:46 2011
@@ -218,7 +218,7 @@
{
if (ch == wch || CanUseChannel(wch))
{
- wch.Act(ActType.Char, string.Format("{0} {1}{2}~x",
+ wch.Act(string.Format("{0} {1}{2}~x",
DisplayName,
Color, argument), args);
}
}
=======================================
--- /trunk/ArtheaServer/MainForm.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaServer/MainForm.cs Wed Apr 20 15:25:46 2011
@@ -27,23 +27,6 @@
using NLog.Targets;
using Thought.Net.Telnet;
-
- public class ConnectionConfig
- {
- #region Properties
-
- public string PlayerName
- {
- get; set;
- }
-
- public SocketInformation SockInfo
- {
- get; set;
- }
-
- #endregion Properties
- }
public partial class MainForm : Form
{
@@ -215,6 +198,25 @@
#endregion Methods
}
+
+ public class ConnectionConfig
+ {
+ #region Properties
+
+ public string PlayerName
+ {
+ get;
+ set;
+ }
+
+ public SocketInformation SockInfo
+ {
+ get;
+ set;
+ }
+
+ #endregion Properties
+ }
public sealed class RTLogTarget : TargetWithLayout
{
=======================================
--- /trunk/ArtheaServer/TelnetServer.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaServer/TelnetServer.cs Wed Apr 20 15:25:46 2011
@@ -219,8 +219,6 @@
Log.Info(World.Name + " accepting connections on port " +
World.Port);
- UpdateManager.AddWorld(World);
-
State = ServerState.Running;
while (State == ServerState.Running)