本文整理汇总了C#中IUser.MessageHandler方法的典型用法代码示例。如果您正苦于以下问题:C# IUser.MessageHandler方法的具体用法?C# IUser.MessageHandler怎么用?C# IUser.MessageHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUser
的用法示例。
在下文中一共展示了IUser.MessageHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Drop
public static void Drop(IUser player, List<string> commands) {
//1.get the item name from the command, may have to join all the words after dropping the command
StringBuilder itemName = new StringBuilder();
IRoom room = Room.GetRoom(player.Player.Location);
string full = commands[0];
commands.RemoveAt(0);
commands.RemoveAt(0);
foreach (string word in commands) {
itemName.Append(word + " ");
}
int itemPosition = 1;
string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
int.TryParse(position[position.Count() - 1], out itemPosition);
itemName = itemName.Remove(itemName.Length - 2, 2);
}
//2.get the item from the DB
List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
IItem item = items[itemPosition - 1];
//3.have player drop item
IMessage message = new Message();
message.InstigatorID = player.UserID.ToString();
message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
if (item != null) {
player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
item.Location = player.Player.Location;
item.Owner = player.UserID;
item.Save();
//4.Inform room and player of action
message.Room = string.Format("{0} drops {1}", player.Player.FirstName, item.Name);
room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
message.Self = string.Format("You drop {0}", item.Name);
}
else {
message.Self = "You are not carrying anything of the sorts.";
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
}
示例2: DisplayStats
//TODO: this needs more work done and also need to figure out a nice way to display it to the user
private static void DisplayStats(IUser player, List<string> commands) {
Character.Character character = player.Player as Character.Character;
if (character != null) {
StringBuilder sb = new StringBuilder();
sb.AppendLine("You are currently " + character.ActionState.ToString().ToUpper() + " and " + character.StanceState.ToString().ToUpper());
sb.AppendLine("\nName: " + character.FirstName.CamelCaseWord() + " " + character.LastName.CamelCaseWord());
sb.AppendLine("Level : " + character.Level);
sb.AppendLine("Class: " + character.Class);
sb.AppendLine("Race: " + character.Race);
sb.AppendLine("XP: " + (long)character.Experience);
sb.AppendLine("Next Level XP required: " + (long)character.NextLevelExperience + " (Needed: " + (long)(character.NextLevelExperience - character.Experience) + ")");
sb.AppendLine("\n[Attributes]");
foreach (var attrib in player.Player.GetAttributes()) {
sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3} Rank: {3}",attrib.Name.CamelCaseWord(), attrib.Value, attrib.Max, attrib.Rank));
}
sb.AppendLine("\n[Sub Attributes]");
foreach (var attrib in player.Player.GetSubAttributes()) {
sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value);
}
sb.AppendLine("Description/Bio: " + player.Player.Description);
player.MessageHandler(sb.ToString());
}
}
示例3: Examine
private static void Examine(IUser player, List<string> commands) {
string message = "";
bool foundIt = false;
if (commands.Count > 2) {
//order is room, door, items, player, NPCs
//rooms should have a list of items that belong to the room (non removable) but which can be interacted with by the player. For example a loose brick, oven, fridge, closet, etc.
//in turn these objects can have items that can be removed from the room I.E. food, clothing, weapons, etc.
IRoom room = Room.GetRoom(player.Player.Location);
IDoor door = FindDoor(player.Player.Location, commands);
if (door != null) {
message = door.Examine;
foundIt = true;
}
//TODO: For items and players we need to be able to use the dot operator to discern between multiple of the same name.
//look for items in room, then inventory, finally equipment. What about another players equipment?
//maybe the command could be "examine [itemname] [playername]" or "examine [itemname] equipment/inventory"
if (!foundIt) {
message = FindAnItem(commands, player, room, out foundIt);
}
if (!foundIt) {
message = FindAPlayer(commands, room, out foundIt);
}
if (!foundIt) {
message = FindAnNpc(commands, room, out foundIt);
}
}
if (!foundIt) {
message = "Examine what?";
}
player.MessageHandler(message);
}
示例4: Inventory
private static void Inventory(IUser player, List<string> commands){
List<IItem> inventoryList = player.Player.Inventory.GetInventoryAsItemList();
StringBuilder sb = new StringBuilder();
Dictionary<string, int> grouping = new Dictionary<string, int>();
//let's group repeat items for easier display this may be a candidate for a helper method
foreach (IItem item in inventoryList) {
IContainer container = item as IContainer;
if (!grouping.ContainsKey(item.Name)) {
if (!item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
grouping.Add(item.Name, 1);
}
else{
grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1);
container = null;
}
}
else {
if (!item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
grouping[item.Name] += 1;
}
else {
grouping[item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]"] += 1;
container = null;
}
}
}
if (grouping.Count > 0) {
sb.AppendLine("You are carrying:");
foreach (KeyValuePair<string, int> pair in grouping) {
sb.AppendLine(pair.Key.CamelCaseString() + (pair.Value > 1 ? "[" + pair.Value + "]" : ""));
}
sb.AppendLine("\n\r");
}
else{
sb.AppendLine("\n\r[ EMPTY ]\n\r");
}
player.MessageHandler(sb.ToString());
}
示例5: Unequip
public static void Unequip(IUser player, List<string> commands) {
StringBuilder itemName = new StringBuilder();
int itemPosition = 1;
IMessage message = new Message();
message.InstigatorID = player.UserID.ToString();
message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
//they said 'all' so we are going to remove everything
if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase)) {
foreach (KeyValuePair<Wearable, IItem> item in player.Player.Equipment.GetEquipment()) {
if (player.Player.Equipment.UnequipItem(item.Value, player.Player)) {
}
}
message.Room = string.Format("{0} removes all his equipment.", player.Player.FirstName);
}
else {
string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
int.TryParse(position[position.Count() - 1], out itemPosition);
itemName = itemName.Remove(itemName.Length - 2, 2);
}
string full = commands[0];
commands.RemoveAt(0);
commands.RemoveAt(0);
foreach (string word in commands) {
itemName.Append(word + " ");
}
List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
IItem item = items[itemPosition - 1];
if (item != null) {
player.Player.Equipment.UnequipItem(item, player.Player);
message.Room = string.Format("{0} unequips {1}", player.Player.FirstName, item.Name);
message.Self = string.Format("You unequip {0}", item.Name);
}
else {
if (commands.Count == 2) {
message.Self = "Unequip what?";
}
else {
message.Self = "You don't seem to be equipping that at the moment.";
}
}
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
}
示例6: Loot
public bool Loot(IUser looter, List<string> commands, bool bypassCheck = false) {
bool looted = false;
if (IsDead()) {
List<IItem> result = new List<IItem>();
StringBuilder sb = new StringBuilder();
if (!bypassCheck) {
if (CanLoot(looter.UserID)) {
looter.MessageHandler("You did not deal the killing blow and can not loot this corpse at this time.");
return false;
}
}
if (commands.Contains("all")) {
sb.AppendLine("You loot the following items from " + FirstName + ":");
Inventory.GetInventoryAsItemList().ForEach(i => {
sb.AppendLine(i.Name);
looter.Player.Inventory.AddItemToInventory(i);
});
looted = true;
}
else if (commands.Count > 2) { //the big one, should allow to loot individual item from the inventory
string itemName = Items.Items.ParseItemName(commands);
int index = 1;
int position = 1;
string[] positionString = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (positionString.Count() > 1) {
int.TryParse(positionString[positionString.Count() - 1], out position);
}
Inventory.GetInventoryAsItemList().ForEach(i => {
if (string.Equals(i.Name, itemName, StringComparison.InvariantCultureIgnoreCase) && index == position) {
looter.Player.Inventory.AddItemToInventory(i);
sb.AppendLine("You loot " + i.Name + " from " + FirstName);
index = -1; //we found it and don't need this to match anymore
looted = true;
//no need to break since we are checking on index and I doubt a player will have so many items in their inventory that it will
//take a long time to go through each of them
}
else {
index++;
}
});
}
else {
sb.AppendLine(FirstName + " is carrying: ");
Inventory.GetInventoryAsItemList().ForEach(i => sb.AppendLine(i.Name));
}
}
return looted;
}
示例7: Loot
private static void Loot(IUser player, List<string> commands) {
IActor npc = null;
string[] position = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
//ok so the player specified a specific NPC in the room list to loot and not just the first to match
int pos;
int.TryParse(position[position.Count() - 1], out pos);
if (pos != 0) {
npc = Character.NPCUtils.GetAnNPCByID(GetObjectInPosition(pos, commands[2], player.Player.Location));
}
}
if (npc == null) {
var npcList = Character.NPCUtils.GetAnNPCByName(commands[2], player.Player.Location);
if (npcList.Count > 1) {
npc = npcList.SingleOrDefault(n => n.Location == player.Player.Location);
}
else {
npc = npcList[0];
}
}
if (npc == null) {
npc = Character.NPCUtils.GetAnNPCByID(player.Player.CurrentTarget);
}
if (npc != null && npc.IsDead()) {
npc.Loot(player, commands);
}
else if (npc != null && !npc.IsDead()) {
player.MessageHandler("You can't loot what is not dead! Maybe you should try killing it first.");
}
//wasn't an npc we specified so it's probably a player
if (npc == null) {
IUser lootee = FindTargetByName(commands[commands.Count - 1], player.Player.Location);
if (lootee != null && lootee.Player.IsDead()) {
lootee.Player.Loot(player, commands);
}
else if (lootee != null && !lootee.Player.IsDead()) {
player.MessageHandler("You can't loot what is not dead! Maybe you should try pickpocketing or killing it first.");
}
else {
player.MessageHandler("You can't loot what doesn't exist...unless you see dead people, but you don't.");
}
}
return;
}
示例8: Sit
private static void Sit(IUser player, List<string> commands) {
IMessage message = new Message();
message.InstigatorID = player.UserID.ToString();
message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
if (player.Player.StanceState != CharacterStanceState.Sitting && (player.Player.ActionState == CharacterActionState.None
|| player.Player.ActionState == CharacterActionState.Fighting)) {
player.Player.SetStanceState(CharacterStanceState.Sitting);
message.Self = "You sit down.";
message.Room = String.Format("{0} sits down.", player.Player.FirstName);
}
else if (player.Player.ActionState != CharacterActionState.None) {
message.Self = String.Format("You can't sit down. You are {0}!", player.Player.ActionState.ToString().ToLower());
}
else {
message.Self = String.Format("You can't sit down. You are {0}!", player.Player.StanceState.ToString().ToLower());
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
}
示例9: MasterLooterLoots
private void MasterLooterLoots(IUser looter, List<string> commands, IActor npc) {
if (string.Equals(looter.UserID, MasterLooter)) {
npc.Loot(looter, commands, true);
}
else {
looter.MessageHandler("Only the master looter can loot corpses killed by the group.");
}
}
示例10: Give
private static void Give(IUser player, List<string> commands) {
//get the item name from the command, may have to join all the words after dropping the command
StringBuilder itemName = new StringBuilder();
IRoom room = Room.GetRoom(player.Player.Location);
string[] full = commands[0].Replace("give","").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in full) {
if (word.ToLower() != "to") {
itemName.Append(word + " ");
}
else {
break; //we got to the end of the item name
}
}
int itemPosition = 1;
string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
int.TryParse(position[position.Count() - 1], out itemPosition);
itemName = itemName.Remove(itemName.Length - 2, 2);
}
//get the item from the DB
List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
if (items.Count == 0) {
player.MessageHandler("You can't seem to find an item by that name.");
return;
}
IItem item = items[itemPosition - 1];
string toPlayerName = commands[0].ToLower().Replace("give", "").Replace(itemName.ToString(), "").Replace("to", "").Trim();
bool HasDotOperator = false;
int playerPosition = 0;
position = toPlayerName.Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
int.TryParse(position[position.Count() - 1], out playerPosition);
HasDotOperator = true;
}
IUser toPlayer = null;
List<IUser> toPlayerList = new List<IUser>();
//we need some special logic here, first we'll try by first name only and see if we get a hit. If there's more than one person named the same
//then we'll see if the last name was included in the commands. And try again. If not we'll check for the dot operator and all if else fails tell them
//to be a bit more specific about who they are trying to directly speak to.
string[] nameBreakDown = toPlayerName.ToLower().Split(' ');
foreach (var id in room.GetObjectsInRoom(RoomObjects.Players, 100)) {
toPlayerList.Add(Server.GetAUser(id));
}
if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[0]).Count() > 1) { //let's narrow it down by including a last name (if provided)
toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).Where(p => String.Compare(p.Player.LastName.ToLower(), nameBreakDown[1] ?? "", true) == 0).SingleOrDefault();
if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
toPlayer = toPlayerList[playerPosition];
}
else {
toPlayer = toPlayerList[0];
}
}
}
else { //we found an exact match
toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).SingleOrDefault();
if (toPlayer != null && toPlayer.UserID == player.UserID) {
toPlayer = null; //It's the player saying something!
}
}
if (toPlayer == null) { //we are looking for an npc at this point
toPlayerList.Clear();
foreach (var id in room.GetObjectsInRoom(RoomObjects.Npcs, 100)) {
toPlayerList.Add(Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId>() { id }));
}
if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[0]).Count() > 1) { //let's narrow it down by including a last name (if provided)
toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).Where(p => String.Compare(p.Player.LastName, nameBreakDown[1] ?? "", true) == 0).SingleOrDefault();
if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
toPlayer = toPlayerList[playerPosition];
}
else {
toPlayer = toPlayerList[0];
}
}
}
else { //we found an exact match
toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).SingleOrDefault();
if (commands.Count == 2 || toPlayer != null && toPlayer.UserID == player.UserID) {
toPlayer = null;
player.MessageHandler("Really? Giving to yourself?.");
}
else if (toPlayer == null) {
player.MessageHandler("You can't give things to someone who is not here.");
}
}
//.........这里部分代码省略.........
示例11: DeActivate
private static void DeActivate(IUser player, List<string> commands) {
//used for turning off a lightSource that can be lit.
IIluminate lightItem = null;
//just making the command be display friendly for the messages
string command = null;
switch (commands[1]) {
case "TURNOFF": command = "turn off";
break;
case "SWITCHOFF": command = "switch off";
break;
default: command = commands[1];
break;
}
commands.RemoveRange(0, 2);
IMessage message = new Message();
IRoom room = Room.GetRoom(player.Player.Location);
lightItem = FindLightInEquipment(commands, player, room);
if (lightItem != null) {
if (lightItem.isLit) {
message = lightItem.Extinguish();
message.Room = string.Format(message.Room, player.Player.FirstName);
}
else {
message.Self = "It's already off!";
}
}
else {
message.Self = "You don't see anything to " + command + ".";
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
}
示例12: Drink
public static void Drink(IUser player, List<string> commands) {
IItem item = GetItem(commands, player.Player.Location);
if (item == null) {
player.MessageHandler("You don't seem to be carrying that to drink it.");
return;
}
if (item.ItemType.ContainsKey(ItemsType.DRINKABLE)) {
Consume(player, commands, "drink", item);
}
else {
player.MessageHandler("You can't drink that!");
}
}
示例13: Put
//container commands
public async static void Put(IUser player, List<string> commands) {
//this command is used only for putting an Item in the root inventory of a player into a bag.
//If an item needs to go from a bag to the root inventory level player should use the GET command instead.
int itemPosition = 1;
int containerPosition = 1;
string itemName = "";
string containerName = "";
//this allows players to use either IN or INTO
int commandIndex = 0;
foreach (string word in commands) {
if (string.Equals(word, "in", StringComparison.InvariantCultureIgnoreCase)) {
commands[commandIndex] = "into";
break;
}
commandIndex++;
}
var location = "";
if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase)) {
commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
}
else {
location = player.Player.Location;
}
List<string> commandAltered = ParseItemPositions(commands, "into", out itemPosition, out itemName);
ParseContainerPosition(commandAltered, "", out containerPosition, out containerName);
IItem retrievedItem = null;
IItem containerItem = null;
//using a recursive method we will dig down into each sub container looking for the appropriate container
if (location.Equals(ObjectId.Empty)) {
TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);
//player is an idiot and probably wanted to put it in his inventory but didn't specify it so let's check there as well
if (containerItem == null) {
foreach (IItem tempContainer in player.Player.Inventory.GetInventoryAsItemList()) {
containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase)) {
break;
}
}
}
}
else{ //player specified it is in his inventory
foreach (var id in player.Player.Inventory.GetInventoryList()) {
IItem tempContainer = await Items.Items.GetByID(ObjectId.Parse(id));
containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase)) {
break;
}
}
}
bool stored = false;
retrievedItem = player.Player.Inventory.GetInventoryAsItemList().Where(i => i.Name == itemName).SingleOrDefault();
if (containerItem != null && retrievedItem != null) {
retrievedItem.Location = containerItem.Location;
retrievedItem.Owner = containerItem.Id;
retrievedItem.Save();
IContainer container = containerItem as IContainer;
stored = container.StoreItem(retrievedItem.Id);
}
string msg = null;
if (!stored) {
msg = "Could not put " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
}
else {
msg = "You place " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
}
player.MessageHandler(msg);
}
示例14: Tell
//a tell is a private message basically, location is not a factor
private static void Tell(IUser player, List<string> commands) {
IMessage message = new Message();
message.InstigatorID = player.Player.Id.ToString();
message.InstigatorType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;
List<IUser> toPlayerList = Server.GetAUserByFirstName(commands[2]).ToList();
IUser toPlayer = null;
if (commands[2].ToUpper() == "SELF") {
message.Self = "You go to tell yourself something when you realize you already know it.";
return;
}
if (toPlayerList.Count < 1) {
message.Self = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
}
else if (toPlayerList.Count > 1) { //let's narrow it down by including a last name (if provided)
toPlayer = toPlayerList.Where(p => String.Compare(p.Player.LastName, commands[3], true) == 0).SingleOrDefault();
}
else {
toPlayer = toPlayerList[0];
if (toPlayer.UserID == player.UserID) {
player.MessageHandler("You tell yourself something important.");
return;
}
}
bool fullName = true;
if (toPlayer == null) {
message.Self = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
}
else {
message.TargetID = toPlayer.Player.Id.ToString();
message.InstigatorType = toPlayer.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;
int startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower() + " " + toPlayer.Player.LastName.ToLower());
if (startAt == -1 || startAt > 11) {
startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower());
fullName = false;
}
if (startAt > 11) startAt = 11 + toPlayer.Player.FirstName.Length + 1;
else startAt += toPlayer.Player.FirstName.Length + 1;
if (fullName) startAt += toPlayer.Player.LastName.Length + 1;
if (commands[0].Length > startAt) {
string temp = commands[0].Substring(startAt);
message.Self = "You tell " + toPlayer.Player.FirstName + " \"" + temp + "\"";
message.Target = player.Player.FirstName + " tells you \"" + temp + "\"";
}
else {
message.Self = "You have nothing to tell them.";
}
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
if (toPlayer.Player.IsNPC) {
toPlayer.MessageHandler(message);
}
else {
toPlayer.MessageHandler(message.Target);
}
}
示例15: Equip
public static void Equip(IUser player, List<string> commands) {
StringBuilder itemName = new StringBuilder();
int itemPosition = 1;
IMessage message = new Message();
message.InstigatorID = player.UserID.ToString();
message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
//we need to make a list of items to wear from the players inventory and sort them based on stats
if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase)) {
foreach (IItem item in player.Player.Inventory.GetAllItemsToWear()) {
if (player.Player.Equipment.EquipItem(item, player.Player.Inventory)) {
message.Self += string.Format("You equip {0}.\n", item.Name);
message.Room += string.Format("{0} equips {1}.\n", player.Player.FirstName, item.Name);
}
}
}
else {
string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
if (position.Count() > 1) {
int.TryParse(position[position.Count() - 1], out itemPosition);
itemName = itemName.Remove(itemName.Length - 2, 2);
}
string full = commands[0];
commands.RemoveRange(0, 2);
foreach (string word in commands) {
itemName.Append(word + " ");
}
List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
//players need to specify an indexer or we will just give them the first one we found that matched
IItem item = items[itemPosition - 1];
IWeapon weapon = item as IWeapon;
if (item != null && item.IsWearable) {
player.Player.Equipment.EquipItem(item, player.Player.Inventory);
if (item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
IContainer container = item as IContainer;
container.Wear();
}
if (item.ItemType.ContainsKey(ItemsType.CLOTHING)) {
IClothing clothing = item as IClothing;
clothing.Wear();
}
message.Room = string.Format("{0} equips {1}.", player.Player.FirstName, item.Name);
message.Self = string.Format("You equip {0}.", item.Name);
}
else if (weapon.IsWieldable) {
message.Self = "This item can only be wielded not worn.";
}
else if (!item.IsWearable || !weapon.IsWieldable) {
message.Self = "That doesn't seem like something you can wear.";
}
else {
message.Self = "You don't seem to have that in your inventory to be able to wear.";
}
}
if (player.Player.IsNPC) {
player.MessageHandler(message);
}
else {
player.MessageHandler(message.Self);
}
Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
}