/// <summary> /// Wears an item /// </summary> /// <param name="player">The Player</param> /// <param name="itemToWear">Item to wear</param> public static void WearItem(Player player, string itemToWear, bool wield = false) { var room = Cache.getRoom(player); if (string.IsNullOrEmpty(itemToWear)) { HubContext.SendToClient("Wear what?", player.HubGuid); return; } var oldPlayer = player; if (!itemToWear.Equals("all", StringComparison.CurrentCultureIgnoreCase)) { var findObject = Events.FindNth.Findnth(itemToWear); int nth = findObject.Key; string itemToFind = findObject.Value; var foundItem = FindItem.Item(player.Inventory, nth, itemToFind, Item.ItemLocation.Inventory); // player.Inventory.Find(i => i.name.ToLower().Contains(itemToWear.ToLower())); if (foundItem == null) { if (wield) { HubContext.SendToClient("You do not have that item to wield.", player.HubGuid); return; } HubContext.SendToClient("You do not have that item to wear.", player.HubGuid); return; } foundItem.location = Item.ItemLocation.Worn; var slot = Enum.GetName(typeof(Item.EqSlot), foundItem.slot); //TODO: WTF is this? var eqLocation = player.Equipment.GetType().GetProperty(slot); if (slot == null) { return; } // Log error? What the hell is eqLocation? var hasValue = eqLocation.GetValue(player.Equipment); if (hasValue.ToString() != "Nothing") { RemoveItem(player, hasValue.ToString(), true); } eqLocation.SetValue(player.Equipment, foundItem.name); if (foundItem.ArmorRating != null) { player.ArmorRating += foundItem.ArmorRating.Armour; } if (!wield || !slot.Equals(Item.EqSlot.Wielded.ToString())) { HubContext.SendToClient("You wear " + foundItem.name, player.HubGuid); var result = AvsAnLib.AvsAn.Query(foundItem.name); string article = result.Article; foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} wears {article} {foundItem.name}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } //Wear event CheckEvent.FindEvent(CheckEvent.EventType.Wear, player, foundItem.name); } else { HubContext.SendToClient("You wield " + foundItem.name, player.HubGuid); var result = AvsAnLib.AvsAn.Query(foundItem.name); string article = result.Article; foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} wields {article} {foundItem.name}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } } Score.UpdateUiInventory(player); Score.ReturnScoreUI(player); } else { var listOfItemsWorn = string.Empty; foreach (var item in player.Inventory.Where(x => x.location.Equals(Item.ItemLocation.Inventory))) { if (item.location == Item.ItemLocation.Inventory && item.equipable == true) { var slot = Enum.GetName(typeof(Item.EqSlot), item.slot); //TODO: WTF is this? if (slot != null) { var eqLocation = player.Equipment.GetType().GetProperty(slot); if (eqLocation != null) { var hasValue = eqLocation.GetValue(player.Equipment); if (hasValue.ToString() != "Nothing") { RemoveItem(player, hasValue.ToString(), true); } } item.location = Item.ItemLocation.Worn; eqLocation.SetValue(player.Equipment, item.name); if (item.ArmorRating != null) { player.ArmorRating += item.ArmorRating.Armour; } listOfItemsWorn += $" {item.name}"; if (!wield || !slot.Equals("wield", StringComparison.CurrentCultureIgnoreCase)) { var result = AvsAnLib.AvsAn.Query(item.name); string article = result.Article; HubContext.SendToClient("You wear " + article + item.name, player.HubGuid); foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} wears {article} {item.name}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } } else { var result = AvsAnLib.AvsAn.Query(item.name); string article = result.Article; HubContext.SendToClient("You wield " + article + item.name, player.HubGuid); foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} wields {article} {item.name}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } } } } } CheckEvent.FindEvent(CheckEvent.EventType.Wear, player, listOfItemsWorn); } Score.UpdateUiInventory(player); Score.ReturnScoreUI(player); Cache.updatePlayer(player, oldPlayer); }
public static void DoLockPick(IHubContext context, PlayerSetup.Player player, Room room, string item) { //Check if player has spell var hasSkill = Skill.CheckPlayerHasSkill(player, LockPickAb().Name); if (hasSkill == false) { context.SendToClient("You don't know that skill.", player.HubGuid); return; } var canDoSkill = Skill.CanDoSkill(player); if (!canDoSkill) { return; } if (string.IsNullOrEmpty(item)) { context.SendToClient("You need to specify an item.", player.HubGuid); return; } var hasItem = FindItem.Item(room.items, -1, item, Item.Item.ItemLocation.Room); if (hasItem == null) { context.SendToClient("Nothing here by that name.", player.HubGuid); return; } if (!hasItem.locked) { context.SendToClient($"{Helpers.ReturnName(null, null, hasItem.name).ToLower()} is already unlocked.", player.HubGuid); return; } var chanceOfSuccess = Helpers.Rand(LockPickDifficulty(hasItem.LockPick), 100); var skill = player.Skills.FirstOrDefault(x => x.Name.Equals("Lock Pick")); var skillProf = skill.Proficiency; if (skillProf >= chanceOfSuccess) { HubContext.Instance.SendToClient("*CLICK!*", player.HubGuid); //Itme stats HubContext.Instance.SendToClient($"You unlock {Helpers.ReturnName(null, null, hasItem.name).ToLower()}", player.HubGuid); hasItem.locked = false; Score.ReturnScoreUI(player); } else { //something random HubContext.Instance.SendToClient($"You fail to unlock {Helpers.ReturnName(null, null, hasItem.name).ToLower().ToLower()}.", player.HubGuid); Score.ReturnScoreUI(player); } }
public static void StarContinualLight(Player player, Room room, string commandOptions = "") { //Check if player has spell var hasSpell = Skill.CheckPlayerHasSkill(player, ContinualLightAb().Name); if (hasSpell == false) { HubContext.Instance.SendToClient("You don't know that spell.", player.HubGuid); return; } var canDoSkill = Skill.CanDoSkill(player); if (!canDoSkill) { return; } #region refactor string[] options = commandOptions.Split(' '); int nth = -1; string getNth = string.Empty; string objectToFind = String.Empty; if (options.Length == 3) { objectToFind = options[2]; if (objectToFind.IndexOf('.') != -1) { getNth = objectToFind.Substring(0, objectToFind.IndexOf('.')); int.TryParse(getNth, out nth); } } else if (options.Length > 3) { objectToFind = options[2]; if (objectToFind.IndexOf('.') != -1) { getNth = objectToFind.Substring(0, objectToFind.IndexOf('.')); int.TryParse(getNth, out nth); } _color = options[3]; } #endregion if (nth == 0) { nth = -1; } _target = FindItem.Item(player.Inventory, nth, objectToFind, Item.Item.ItemLocation.Inventory); if (_target == null && options.Length == 3) { _color = options[2]; } if (ReturnColor(_color) == null) { HubContext.Instance.SendToClient($"{_color} is not valid, you can choose from: Blue, Red, Green, Yellow, Purple, Orange and White", player.HubGuid); return; } if (!_taskRunnning && _target != null) { if (player.ManaPoints < ContinualLightAb().ManaCost) { HubContext.Instance.SendToClient("You clasp your hands together attempting to draw energy between your hands but fail", player.HubGuid); return; } //TODO REfactor player.ManaPoints -= ContinualLightAb().ManaCost; Score.UpdateUiPrompt(player); if (_target.itemFlags == null) { _target.itemFlags = new List <Item.Item.ItemFlags>(); } if (_target.itemFlags.Contains(Item.Item.ItemFlags.glow)) { HubContext.Instance.SendToClient("This item is already illuminated", player.HubGuid); return; } var result = AvsAnLib.AvsAn.Query(_target.name); string article = result.Article; HubContext.Instance.SendToClient($"You grasp {article} {_target.name} between your hands which starts to shimmer a slight {_color} colour", player.HubGuid); foreach (var character in room.players) { if (character != player) { var hisOrHer = Helpers.ReturnHisOrHers(player, character); var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} grasps {article} {_target.name} between {hisOrHer} hands which starts to shimmer a slight {_color} colour"; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } Task.Run(() => DoContinualLight(player, room)); } else { if (_target == null) { if (player.ManaPoints < ContinualLightAb().ManaCost) { HubContext.Instance.SendToClient("You attempt to draw energy but fail", player.HubGuid); return; } //TODO REfactor player.ManaPoints -= ContinualLightAb().ManaCost; Score.UpdateUiPrompt(player); HubContext.Instance.SendToClient($"You clasp your hands together forming a bright {_color} ball between them", player.HubGuid); foreach (var character in room.players) { if (character != player) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} 's hands start to glow as they begin chanting the Continual light spell"; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } Task.Run(() => DoContinualLight(player, room)); } } }
public static void StartInvis(Player player, Room room, string commandOptions = "") { //Check if player has spell var hasSpell = Skill.CheckPlayerHasSkill(player, InvisAb().Name); if (hasSpell == false) { HubContext.Instance.SendToClient("You don't know that spell.", player.HubGuid); return; } var canDoSkill = Skill.CanDoSkill(player); if (!canDoSkill) { return; } #region refactor string[] options = commandOptions.Split(' '); int nth = -1; string getNth = string.Empty; string objectToFind = String.Empty; if (options.Length == 3) { objectToFind = options[2]; if (objectToFind.IndexOf('.') != -1) { getNth = objectToFind.Substring(0, objectToFind.IndexOf('.')); int.TryParse(getNth, out nth); } } #endregion if (nth == 0) { nth = -1; } if (!string.IsNullOrEmpty(objectToFind)) { _target = FindItem.Item(player.Inventory, nth, objectToFind, Item.Item.ItemLocation.Inventory); if (_target == null) { var findPlayer = FindItem.Player(room.players, nth, objectToFind); var findMob = FindItem.Player(room.mobs, nth, objectToFind); if (findPlayer != null || findMob != null) { HubContext.Instance.SendToClient("You can only cast invis on yourself or items in your inventory.", player.HubGuid); return; } else { HubContext.Instance.SendToClient("You don't have that to turn invisible.", player.HubGuid); return; } } } else { _target = null; } if (!_taskRunnning && _target != null) { if (player.ManaPoints < InvisAb().ManaCost) { HubContext.Instance.SendToClient("You attempt to draw energy but fail", player.HubGuid); return; } //TODO REfactor player.ManaPoints -= InvisAb().ManaCost; Score.UpdateUiPrompt(player); if (_target.itemFlags == null) { _target.itemFlags = new List <Item.Item.ItemFlags>(); } if (_target.itemFlags.Contains(Item.Item.ItemFlags.invis)) { HubContext.Instance.SendToClient("This item is already invisible", player.HubGuid); return; } var result = AvsAnLib.AvsAn.Query(_target.name); string article = result.Article; HubContext.Instance.SendToClient($"You take hold of the {_target.name} between your hands which starts to fade in and out of existence", player.HubGuid); var playersInRoom = new List <Player>(room.players); foreach (var character in room.players) { if (character != player) { var hisOrHer = Helpers.ReturnHisOrHers(player, character); var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} takes hold of the {_target.name} between {hisOrHer} hands which starts to fade in and out of existence."; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } Task.Run(() => DoInvis(player, room)); } else { if (_target == null) { if (player.ManaPoints < InvisAb().ManaCost) { HubContext.Instance.SendToClient("You attempt to draw energy but fail", player.HubGuid); return; } //TODO REfactor player.ManaPoints -= InvisAb().ManaCost; Score.UpdateUiPrompt(player); var hasFaerieFire = player.Effects?.FirstOrDefault( x => x.Name.Equals("Faerie Fire", StringComparison.CurrentCultureIgnoreCase)) != null; if (!hasFaerieFire) { HubContext.Instance.SendToClient($"You start to fade in and out of existence.", player.HubGuid); foreach (var character in room.players) { if (character != player) { var hisOrHer = Helpers.ReturnHisOrHers(player, character); var roomMessage = $"{Helpers.ReturnName(player, character, string.Empty)} starts to fade in and out of existence"; HubContext.Instance.SendToClient(roomMessage, character.HubGuid); } } Task.Run(() => DoInvis(player, room)); } else { HubContext.Instance.SendToClient($"You fail to turn invisible due to the glow of Faerie fire surrounding you.", player.HubGuid); } } } }