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); } }
public static void RepairItem(PlayerSetup.Player player, Room.Room room, string commandOptions) { var hasSkill = player.Skills.FirstOrDefault(x => x.Name.Equals("Repair")); if (hasSkill == null) { HubContext.Instance.SendToClient("You don't know how to do that.", player.HubGuid); return; } if (string.IsNullOrEmpty(commandOptions)) { return; } var item = FindNth.Findnth(commandOptions); var foundItem = FindItem.Item(player.Inventory, item.Key, item.Value, Item.Item.ItemLocation.Inventory); var repairHammer = player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains(player.Equipment.Held.ToLower())); if (foundItem == null) { HubContext.Instance.SendToClient("You don't have " + Helpers.ReturnName(null, null, item.Value), player.HubGuid); return; } if (foundItem.Condition >= 75) { HubContext.Instance.SendToClient("You can't improve " + Helpers.ReturnName(null, null, foundItem.name) + " any further.", player.HubGuid); return; } if (repairHammer != null && repairHammer.type == Item.Item.ItemType.Repair) { var chance = Helpers.Rand(1, 100); if (hasSkill.Proficiency >= chance) { foundItem.Condition += Helpers.Rand(10, 25); HubContext.Instance.SendToClient(Helpers.ReturnName(null, null, item.Value) + " looks to be in a better condition.", player.HubGuid); if (foundItem.Condition > 0) { var iname = Helpers.FirstLetterToUpper(foundItem.name.ToLower().Replace("broken", String.Empty) .Trim()); foundItem.name = iname; } if (foundItem.Condition >= 75) { var removeBrokenFromName = foundItem.name.ToLower().Replace("broken ", String.Empty).Trim(); foundItem.name = Helpers.FirstLetterToUpper(removeBrokenFromName); foundItem.Condition = 75; HubContext.Instance.SendToClient(Helpers.ReturnName(null, null, item.Value) + " has been fully repaired.", player.HubGuid); Score.UpdateUiInventory(player); return; } repairHammer.Uses -= 1; } else { HubContext.Instance.SendToClient("You fail to improve the condition of " + Helpers.ReturnName(null, null, item.Value), player.HubGuid); PlayerSetup.Player.LearnFromMistake(player, hasSkill, 100); } if (repairHammer.Uses <= 0) { HubContext.Instance.SendToClient("The repair hammer falls to pieces in your hand.", player.HubGuid); player.Inventory.Remove(repairHammer); player.Equipment.Held = "Nothing"; } Score.UpdateUiInventory(player); Score.ReturnScoreUI(player); } else { HubContext.Instance.SendToClient("You need to equip a repair hammer", player.HubGuid); return; } }