muddesigner/MudEngine/GameObjects/Characters/BaseCharacter.cs
Scionwest_cp 793c3cf1e9 MudEngine:
- FileManager.GetDataPath now returns the actual Root directory when Root is requested rather than Root/Projects. That was considered Root for the older Designer.
 - CommandEngine.GetCommands is now a method rather than a property.
 - CommandEngine.LoadAllCommands replaced with CommandEngine.LoadBaseCommands for loading Engine specific Game commands. This is called from within Game.Start. A possible property for disabling default commands could be looked at in the future.
 - CommandEngine.LoadCommandLibrary method added for loading custom user commands. This is fully implemented.
 - CommandEngine.ClearCommands method added for clearing all currently loaded commands.
 - Game.IsDebug static property added.
 - Added additional logging for testing purposes throughout the project. Changing Game.IsDebug to false will remove the majority of the logged messages.
 - Game.IsMultiplayer property added for enabling or disabling the server for Online/Offline support. Fully implemented.
 - Game no longer loads user script libraries as this was being handled already by ScriptEngine.Initialize()
 - Log now caches messages so consoles can print only content that was logged since the last loop. Using Log.FlushMessages() will clear the cached messages allowing each loop to show only the new logged messages.
 - BaseCharacter IsAdmin argument in the constructor has been removed. No longer needed for testing.
 - ScriptEngine can now compile more than 1 script without error.
 - ScriptEngine.Assembly property added for accessing the currently loaded script library. This should be a List<Assembly> in the future for multiple libraries.
 - Removed the last of my BlitScript engine code from ScriptEngine.cs as it was XNA specific. Need to look at StartupObject.cs as I believe that is XNA specific as well and not needed.

MudGame:
 - Renamed MudGame to MudOfflineExample as it will be used for testing the game with Game.IsMultiplayer disabled. Makes testing easier then needing to stop/restart the server and connect via telnet constantly.

MudServer:
 - Added MudServer project. This is a dedicated server that runs with Game.IsMultiplayer enabled. Developers can connect to it via telnet clients. All engine game commands are implemented.
 - MudServer includes bin/Debug/Scripts.dll, which is a compiled library of scripts generated via MudCompiler. MudEngine.Game handles loading the library and there is no additional code required by the developers to implement their libraries into their games provided the name is 'Scripts.dll'
2010-07-27 16:31:50 -07:00

146 lines
4.6 KiB
C#

//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.Commands;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items;
using System.Net;
using System.Net.Sockets;
namespace MudEngine.GameObjects.Characters
{
public class BaseCharacter : BaseObject
{
/// <summary>
/// The current Room this Character is located at.
/// </summary>
public Room CurrentRoom { get; set; }
/// <summary>
/// Gets or Sets if this Character is controlled by the user. If not user controlled then it will be AI controlled.
/// </summary>
public Boolean IsControlled { get; set; }
/// <summary>
/// Gets or Sets if this user has Admin privileges or not.
/// </summary>
public Boolean IsAdmin { get; private set; }
/// <summary>
/// Gets or Sets if this player is active.
/// </summary>
public Boolean IsActive { get; private set; }
/// <summary>
/// Gets a reference to the currently running game.
/// </summary>
public Game Game { get; private set; }
public BaseCharacter(Game game)
{
Game = game;
IsActive = false;
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
}
/// <summary>
/// Moves the player from one Room to another if the supplied direction contains a doorway.
/// Returns false if no doorway is available.
/// </summary>
/// <param name="travelDirection"></param>
/// <returns></returns>
public bool Move(AvailableTravelDirections travelDirection)
{
//Check if the current room has a doorway in the supplied direction of travel.
if (!CurrentRoom.DoorwayExist(travelDirection))
{
return false;
}
//We have a doorway, lets move to the next room.
CurrentRoom = CurrentRoom.GetDoor(travelDirection).ArrivalRoom;
OnTravel(travelDirection);
return true;
}
public virtual void OnTravel(AvailableTravelDirections travelDirection)
{
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
}
public String ExecuteCommand(string command)
{
//TODO: Character class can handle a lot of the command management here, checking various things prior to sending
//the command off to the command engine for execution.
CommandResults result = CommandEngine.ExecuteCommand(command, this);
if (result.Result != null)
{
StringBuilder sb = new StringBuilder();
foreach (object item in result.Result)
{
if (item is string)
sb.AppendLine(item.ToString());
}
return sb.ToString();
}
return "";
}
internal void Initialize()
{
CurrentRoom = Game.InitialRealm.InitialZone.InitialRoom;
IsActive = true;
}
internal void Receive(byte[] data)
{
// convert that data to string
String str;
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
str = enc.GetString(data);
if (Game.IsDebug)
Log.Write("Client entered command: " + str);
// execute, and get result
str = ExecuteCommand(str);
// convert the result back to bytes and send it back
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Send(encoding.GetBytes(str));
if (!Game.IsRunning)
Clear();
}
internal void Send(byte[] data)
{
try
{
client.Send(data);
}
catch (Exception) // error, connection failed: close client
{
Clear();
}
}
internal void Clear()
{
// TODO: Save();
IsActive = false;
client.Close();
// TODO: Reset game so it can be used again
}
internal Socket client;
}
}