public static async Task CraftItem(PlayerSetup.Player player, Room.Room room, Craft craftItem) { //add skill check here var getSkill = player.Skills.FirstOrDefault(x => x.Alias.Equals(craftItem.CraftCommand.ToString())); if (getSkill == null) { HubContext.Instance.SendToClient("You don't know how to do that", player.HubGuid); return; } if (player.MovePoints < craftItem.MoveCost) { if (craftItem.CraftCommand == CraftType.Chop || craftItem.CraftCommand == CraftType.Brew) { HubContext.Instance.SendToClient("You are too tired to make " + Helpers.ReturnName(null, null, craftItem.CreatesItem.name).ToLower() + ".", player.HubGuid); return; } HubContext.Instance.SendToClient("You are too tired to make " + Helpers.ReturnName(null, null, craftItem.Name).ToLower() + ".", player.HubGuid); return; } player.MovePoints -= craftItem.MoveCost; var successChance = ShowSkills.CraftSuccess(getSkill.Points); if (getSkill.Points >= successChance) { //success if (player.ActiveSkill != null) { HubContext.Instance.SendToClient("wait till you have finished " + player.ActiveSkill.Name, player.HubGuid); return; } player.ActiveSkill = getSkill; var oldRoom = room; HubContext.Instance.SendToClient(craftItem.StartMessage, player.HubGuid); await Task.Delay(1500); foreach (var emote in craftItem.CraftingEmotes) { HubContext.Instance.SendToClient(emote, player.HubGuid); await Task.Delay(2000); } HubContext.Instance.SendToClient(craftItem.SuccessMessage, player.HubGuid); if (craftItem.Materials != null) { foreach (var materials in craftItem.Materials) { for (var i = 0; i < materials.Count; i++) { var item = player.Inventory.FirstOrDefault(x => x.name.ToLower() .Contains(materials.Name.ToLower())); player.Inventory.Remove(item); } } } if (craftItem.CraftAppearsInRoom) { room.items.Add(craftItem.CreatesItem); } if (!craftItem.CraftAppearsInRoom) { PlayerSetup.Player.AddItem(player, craftItem.CreatesItem); } Score.UpdateUiInventory(player); Cache.updateRoom(room, oldRoom); player.ActiveSkill = null; } else { var failMessage = craftItem.FailureMessages[Helpers.Rand(1, craftItem.FailureMessages.Count)]; HubContext.Instance.SendToClient(failMessage.Message, player.HubGuid); if (failMessage.BreakMaterial) { var item = player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains(craftItem .Materials[Helpers.Rand(1, craftItem.Materials.Count)].Name.ToLower())); player.Inventory.Remove(item); } var xp = new Experience(); if (getSkill != null) { if (player.ChosenCraft == craftItem.CraftCommand.ToString()) { getSkill.Points += Helpers.Rand(1, 10); HubContext.Instance.SendToClient("<p class='roomExit'>You learn from your mistakes and gain 100 experience points.</p>", player.HubGuid); player.Experience += 100; } else { if (string.IsNullOrEmpty(player.ChosenCraft) && getSkill.Points <= 99) { HubContext.Instance.SendToClient("<p class='roomExit'>You learn from your mistakes and gain 100 experience points.</p>", player.HubGuid); player.Experience += 100; getSkill.Points += Helpers.Rand(1, 10); if (getSkill.Points > 99) { var rankWarning = ShowSkills.checkRank(getSkill.Points, player); HubContext.Instance.SendToClient(rankWarning, player.HubGuid); getSkill.Points = 99; } } else if (getSkill.Points <= 99) { HubContext.Instance.SendToClient("<p class='roomExit'>You learn from your mistakes and gain 100 experience points.</p>", player.HubGuid); player.Experience += 100; getSkill.Points += Helpers.Rand(1, 10); if (getSkill.Points > 99) { getSkill.Points = 99; } } } } Score.ReturnScoreUI(player); xp.GainLevel(player); } }
/// <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); }
public static void IsDead(Player attacker, Player defender, Room room) { if (defender.HitPoints <= 0) { HubContext.SendToAllExcept(defender.Name + " dies ", room.fighting, room.players); HubContext.SendToClient("You die", defender.HubGuid); HubContext.SendToClient(defender.Name + " dies", attacker.HubGuid); defender.Target = null; //Turn corpse into room item var defenderCorpse = new Item { name = "The corpse of " + defender.Name, container = true, containerItems = new List <Item>(), description = new Description { look = "The slain corpse of " + defender.Name + " is here.", room = "The slain corpse of " + defender.Name } }; foreach (var invItem in defender.Inventory) { invItem.location = Item.ItemLocation.Room; defenderCorpse.containerItems.Add(invItem); } var oldRoom = room; room.items.Add(defenderCorpse); room.corpses.Add(defender); if (defender.Type == Player.PlayerTypes.Mob || string.IsNullOrEmpty(defender.HubGuid)) { room.mobs.Remove(defender); } else { //room.players.Remove(defender); //Add slain player to recall } defender.Target = null; attacker.Target = null; attacker.Status = PlayerSetup.Player.PlayerStatus.Standing; defender.Status = defender.Type == Player.PlayerTypes.Player ? PlayerSetup.Player.PlayerStatus.Ghost : PlayerSetup.Player.PlayerStatus.Dead; Cache.updateRoom(room, oldRoom); var xp = new Experience(); int xpGain = xp.GainXp(attacker, defender); attacker.Experience += xpGain; attacker.TotalExperience += xpGain; HubContext.SendToClient(xpGain + "XP", attacker.HubGuid); xp.GainLevel(attacker); //calc xp //create corpse foreach (var player in room.players) { var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); } } }
/// <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); }
/// <summary> /// Drops item from player inventory /// </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 DropItem(Room room, Player player, string userInput, string commandKey) { var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); var returnedItem = (KeyValuePair <Item, Item>)FindObject(room, player, commandKey, userInput, FindInventory); var container = returnedItem.Key; var item = returnedItem.Value; if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase)) { var playerInv = player.Inventory; var playerInvCount = player.Inventory.Count; for (int i = playerInvCount - 1; i >= 0; i--) { playerInv[i].location = Item.ItemLocation.Room; if (container == null) { playerInv[i].location = Item.ItemLocation.Room; room.items.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + playerInv[i].name, player.Name + " drops a " + playerInv[i].name); } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } if (container.open == false) { HubContext.SendToClient("You have to open the " + container.name + " before you can put somthing inside", player.HubGuid); return; } container.containerItems.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + playerInv[i].name + " into a " + container.name, player.Name + " drops a " + playerInv[i].name + " into a " + container.name); } player.Inventory.Remove(playerInv[i]); } } else { if (item == null) { return; } player.Inventory.Remove(item); item.location = Item.ItemLocation.Room; if (container == null) { room.items.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + item.name, player.Name + " drops a " + item.name); } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } if (container.open == false) { HubContext.SendToClient("You have to open the " + container.name + " before you can put somthing inside", player.HubGuid); return; } container.containerItems.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You put a " + item.name + " inside the " + container.name, player.Name + " puts a " + item.name + " inside the " + container.name); } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); } }
/// <summary> /// Adds item from room to player inventory /// </summary> /// <param name="room">Room Object</param> /// <param name="player">Player Object</param> /// <param name="userInput">Text user entered</param> public static void GetItem(Room room, Player player, string userInput, string commandKey, string type) { //TODO handle container var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); if (all[0] == "all") { type = "all"; } var returnedItem = (KeyValuePair <Item, Item>)FindObject(room, player, commandKey, userInput, type); var container = returnedItem.Key; var item = returnedItem.Value; if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase) && all.Length == 1) { var roomItems = room.items; var roomItemsCount = roomItems.Count; for (int i = roomItemsCount - 1; i >= 0; i--) { //Get all Items from the room roomItems[i].location = Item.ItemLocation.Inventory; player.Inventory.Add(roomItems[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You pick up a " + roomItems[i].name, player.Name + " picks up a " + roomItems[i].name); room.items.Remove(roomItems[i]); } } else if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase) && container != null) { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } //get all from container var containerItems = container.containerItems; var containerCount = containerItems.Count; for (int i = containerCount - 1; i >= 0; i--) { containerItems[i].location = Item.ItemLocation.Inventory; player.Inventory.Add(containerItems[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You get a " + containerItems[i].name + " from a " + container.name, player.Name + " get a " + containerItems[i].name + " from a " + container.name); containerItems.Remove(containerItems[i]); } } else if (item != null) { //get single Item if (container == null) { room.items.Remove(item); item.location = Item.ItemLocation.Inventory; player.Inventory.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You pick up a " + item.name, player.Name + " picks up a " + item.name); } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } //Get item from container container.containerItems.Remove(item); container.location = Item.ItemLocation.Inventory; player.Inventory.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You get a " + item.name + " from a " + container.name, player.Name + " gets a " + item.name + " from a " + container.name); } } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "There is nothing here to pick up", player.Name + " searches for something to pick up"); return; } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); }
public static void IsDead(Player attacker, Player defender, Room room) { if (defender.HitPoints <= 0) { CheckEvent.FindEvent(CheckEvent.EventType.Death, attacker, "death"); foreach (var player in room.players) { if (player != defender) { HubContext.SendToClient(defender.Name + " dies ", player.HubGuid); } else { HubContext.SendToClient("You die", defender.HubGuid); } } defender.Target = null; defender.ActiveFighting = false; defender.Status = Player.PlayerStatus.Ghost; //Turn corpse into room item var defenderCorpse = new Item { name = "The corpse of " + defender.Name, container = true, containerItems = new List <Item>(), description = new Description { look = "The slain corpse of " + defender.Name + " is here.", room = "The slain corpse of " + defender.Name } }; foreach (var invItem in defender.Inventory) { invItem.location = Item.ItemLocation.Room; defenderCorpse.containerItems.Add(invItem); } var oldRoom = room; room.items.Add(defenderCorpse); room.corpses.Add(defender); if (defender.Type == Player.PlayerTypes.Mob || string.IsNullOrEmpty(defender.HubGuid)) { room.mobs.Remove(defender); } else { //room.players.Remove(defender); //Add slain player to recall } defender.Target = null; if (attacker.Target.Name == defender.Name) { attacker.Target = null; attacker.Status = PlayerSetup.Player.PlayerStatus.Standing; attacker.ActiveFighting = false; } defender.Status = defender.Type == Player.PlayerTypes.Player ? PlayerSetup.Player.PlayerStatus.Ghost : PlayerSetup.Player.PlayerStatus.Dead; Cache.updateRoom(room, oldRoom); var xp = new Experience(); int xpGain = xp.GainXp(attacker, defender); attacker.Experience += xpGain; attacker.TotalExperience += xpGain; HubContext.SendToClient(xpGain + "XP", attacker.HubGuid); xp.GainLevel(attacker); //calc xp //create corpse foreach (var player in room.players) { var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); } if (attacker.HubGuid != null) { room.fighting.Remove(attacker.HubGuid); } if (defender.HubGuid != null) { room.fighting.Remove(defender.HubGuid); } //remove followers if (defender.Following != null) { if (defender.Followers.Count > 0) { foreach (var follower in defender.Followers) { if (follower.HubGuid != null) { HubContext.SendToClient("You stop following " + defender.Name, follower.HubGuid); } } } defender.Followers = null; defender.Following = null; } // check if defender is following? if (attacker.Followers?.FirstOrDefault(x => x.Equals(defender)) != null) { attacker.Followers.Remove(defender); if (attacker.HubGuid != null) { HubContext.SendToClient(defender.Name + " stops following you", attacker.HubGuid); } } } }
/// <summary> /// Drops item from player inventory /// </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 GiveItem(Room room, Player player, string userInput, string commandKey, string type) { var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); var itemToGive = all[0]; var thing = all.Last(); var item = itemToGive; var foundItem = player.Inventory.FirstOrDefault(x => item != null && x.name.StartsWith(item, StringComparison.CurrentCultureIgnoreCase)); var foundThing = room.players.FirstOrDefault(x => thing != null && x.Name.StartsWith(thing, StringComparison.CurrentCultureIgnoreCase)) ?? room.mobs.FirstOrDefault(x => thing != null && x.Name.StartsWith(thing, StringComparison.CurrentCultureIgnoreCase)); if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase)) { var playerInv = player.Inventory; var playerInvCount = player.Inventory.Count; for (int i = playerInvCount - 1; i >= 0; i--) { if (foundThing != null) { foundThing.Inventory.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You give a " + playerInv[i].name + " to " + foundThing.Name, player.Name + " gives a " + playerInv[i].name + " to " + foundThing.Name); player.Inventory.Remove(playerInv[i]); } } } else { if (foundThing == null) { HubContext.SendToClient("You don't see " + thing + " here.", player.HubGuid); return; } if (foundItem == null) { HubContext.SendToClient("You are not carrying a " + item, player.HubGuid); return; } player.Inventory.Remove(foundItem); foundThing.Inventory.Add(foundItem); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You give a " + foundItem.name + " to " + foundThing.Name, player.Name + " gives a " + foundItem.name + " to " + foundThing.Name); //check quest foreach (var quest in player.QuestLog) { if (!quest.Completed && quest.Type == Quest.QuestType.FindMob) { //Find quest requires player to give item to the mob. if (quest.QuestGiver == foundThing.Name && quest.QuestItem.name == foundItem.name) { // player completed quest var mobQuest = foundThing.Quest.FirstOrDefault(x => x.Id.Equals(quest.Id)); if (mobQuest != null) { HubContext.SendToClient( foundThing.Name + " says to you " + mobQuest.RewardDialog.Message.Replace("$playerName", player.Name), player.HubGuid, null, true); } //award player } } } } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); Score.UpdateUiInventory(player); var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); }