/// <summary> /// Close /// </summary> /// <param name="room">room object</param> /// <param name="player">player object</param> /// <param name="userInput">text entered by user</param> /// <param name="commandKey">command entered</param> public static void Close(Room room, Player player, string userInput, string commandKey) { var currentRoom = room; var findObject = Events.FindNth.Findnth(userInput); int nth = findObject.Key; Item foundItem = null; Exit foundExit = null; foundItem = FindItem.Item(room.items, nth, userInput); if (foundItem == null) { foundExit = FindItem.Exit(room.exits, nth, userInput); if (foundExit.canOpen == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't close that", player.Name + " tries to close the " + foundExit.name); return; } } if (foundItem != null) { if (foundItem.canOpen == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't close that", player.Name + " tries to close the " + foundItem.name); return; } if (foundItem.open == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "It's already closed", player.Name + " tries to close the " + foundItem.name + " which is already closed"); return; } if (foundItem.locked) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You need to unlock that before you can close it", player.Name + " tries to close the " + foundItem.name + "without a key"); return; } if (foundItem.open) { BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You close the chest", player.Name + " close the " + foundItem.name); foundItem.open = false; } else { BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "the " + foundItem.name + " is already close " + foundItem.name, player.Name + " tries to close the already close chest" + foundItem.name); return; } } else if (foundExit != null) { if (foundExit.open != true) { if (foundExit.locked) { BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You need to unlock that before you can close it", player.Name + " tries to close the " + foundExit.name + "without a key"); return; } BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You close " + foundExit.name, player.Name + " closes the " + foundExit.name); foundExit.open = false; } else { BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "the " + foundExit.name + " is already closed " + foundExit.name, player.Name + " tries to close the already closed chest" + foundExit.name); return; } } //save to cache Cache.updateRoom(room, currentRoom); }
/// <summary> /// lock Item /// </summary> /// <param name="room">room object</param> /// <param name="player">player object</param> /// <param name="userInput">text entered by user</param> /// <param name="commandKey">command entered</param> public static void LockItem(Room room, Player player, string userInput, string commandKey) { var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); // var lockedItem = (KeyValuePair<Item, Item>)FindObject(room, player, commandKey, userInput, FindInventory); // var container = lockedItem.Key; // var item = lockedItem.Value; var findObject = Events.FindNth.Findnth(userInput); int nth = findObject.Key; Item foundItem = null; Exit foundExit = null; foundItem = FindItem.Item(room.items, nth, userInput); if (foundItem == null) { foundExit = FindItem.Exit(room.exits, nth, userInput); if (foundExit.canLock == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't lock that", player.Name + " tries to lock the " + foundItem.name); return; } } if (foundItem != null) { if (foundItem.canLock == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't lock that", player.Name + " tries to lock the " + foundItem.name); return; } // find key matching chest lock id var hasKey = false; foreach (var key in player.Inventory) { if (key.keyValue != null) { if (key.keyValue == foundItem.keyId) { hasKey = true; } } } if (hasKey == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't have a key for that", player.Name + " tries to lock the " + foundItem.name + " without the key"); return; } if (foundItem.locked != true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You lock the chest", player.Name + " locks the " + foundItem.name); foundItem.locked = true; } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "the chest is already locked " + foundItem.name, player.Name + " tries to locked the already locked chest" + foundItem.name); return; } } else { // find key matching chest lock id var hasKey = false; foreach (var key in player.Inventory.Where(key => key.keyValue != null).Where(key => key.keyValue == foundExit.keyId)) { hasKey = true; } if (hasKey == false) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't have a key for that", player.Name + " tries to lock the " + foundExit.name + " without the key"); return; } if (foundExit.locked != true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You lock the chest", player.Name + " locks the " + foundExit.name); foundExit.locked = true; } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "the chest is already locked " + foundExit.name, player.Name + " tries to locked the already locked chest" + foundExit.name); return; } } //save to cache Cache.updateRoom(room, currentRoom); }