/// <summary> /// Gets a container item from the room matching a given identifier. /// </summary> /// <param name="identifier">The container identifier.</param> /// <returns>The container if found otherwise null.</returns> public SMItem GetRoomContainer(string identifier) { SMItem item = SMItemHelper.GetItemFromList(this.RoomItems, identifier); if (item == null || !item.CanHoldOtherItems()) { return(null); } return(item); }
/// <summary> /// Gets the item weight, including any items it contains. /// </summary> /// <returns>The item weight.</returns> /// <param name="item">Item to get the weight for.</param> public static int GetItemWeight(SMItem item) { int weight = item.ItemWeight; if (item.CanHoldOtherItems() && item.HeldItems != null) { foreach (SMItem smi in item.HeldItems) { weight += GetItemWeight(smi); } } return(weight); }
/// <summary> /// Calculates the used capacity of a container. /// </summary> /// <param name="item">The container to look at.</param> /// <returns>The containers used capacity.</returns> public static int GetItemUsedCapacity(SMItem item) { if (!item.CanHoldOtherItems()) { return(0); } int used = 0; if (item.HeldItems.Any()) { foreach (SMItem smi in item.HeldItems) { used += GetItemWeight(smi); } } return(used); }
/// <summary> /// Gets the items listing of a given container in a string ready for outputting. /// </summary> /// <param name="container">Container SMItem to get the listings for.</param> /// <returns>Containers item listings.</returns> public static string GetContainerContents(SMItem container) { // Return null it not a container if (!container.CanHoldOtherItems()) { return(null); } // If the container is empty if (container.HeldItems == null || !container.HeldItems.Any()) { return(OutputFormatterFactory.Get().Italic("Empty")); } // Get list of item counts // TODO bring this functionality into this class List <ItemCountObject> lines = SMItemUtils.GetItemCountList(container.HeldItems); string output = ""; foreach (ItemCountObject line in lines) { string itemDetails = $"{line.Count} x "; if (line.Count > 1) { itemDetails += line.PluralName; } else { itemDetails += line.SingularName; } output += OutputFormatterFactory.Get().General(itemDetails); } return(output); }
/// <summary> /// Calculates the available capacity of a container. /// </summary> /// <param name="item">The container to look at.</param> /// <returns>The containers available capacity.</returns> public static int GetItemAvailbleCapacity(SMItem item) { if (!item.CanHoldOtherItems()) { return(0); } if (item.HeldItems == null || !item.HeldItems.Any()) { return(item.ItemCapacity); } int used = 0; if (item.HeldItems.Any()) { foreach (SMItem smi in item.HeldItems) { used += GetItemWeight(smi); } } return(item.ItemCapacity - used); }
/// <summary> /// Inspect a person, object, etc. /// </summary> /// <param name="smc">The character doing the inspecting</param> /// <param name="thingToInspect">The thing that the person wants to inspect</param> public void InspectThing(SMCharacter smc, string thingToInspect) { // Check if it's a character first SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.FirstName.ToLower() == thingToInspect.ToLower()) || (checkChar.LastName.ToLower() == thingToInspect.ToLower())); if (targetCharacter != null) { string levelText = ""; if (int.Parse(targetCharacter.CalculateLevel()) > 0) { levelText = " (Level " + targetCharacter.CalculateLevel() + ")"; } smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetCharacter.GetFullName() + levelText + ":")); if ((targetCharacter.Description != null) && (targetCharacter.Description != "")) { smc.sendMessageToPlayer(this.Formatter.Italic(targetCharacter.Description)); } else { smc.sendMessageToPlayer(this.Formatter.Italic("No description set...")); } List <string> inventory = targetCharacter.GetInventoryList(); string inventoryOutput = String.Empty; if (inventory.Any()) { foreach (string item in inventory) { inventoryOutput += this.Formatter.ListItem(item); } inventoryOutput += this.Formatter.GetNewLines(1); } smc.sendMessageToPlayer(inventoryOutput); targetCharacter.sendMessageToPlayer(this.Formatter.Italic(smc.GetFullName() + " looks at you")); return; } // If not a character, check if it is an NPC... SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.NPCType.ToLower() == thingToInspect.ToLower())); if (targetNPC != null) { string levelText = ""; if (int.Parse(targetNPC.CalculateLevel()) > 0) { levelText = " (Level " + targetNPC.CalculateLevel() + ")"; } smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetNPC.GetFullName() + levelText + ":")); if ((targetNPC.Description != null) && (targetNPC.Description != "")) { smc.sendMessageToPlayer(this.Formatter.Italic(targetNPC.Description)); } else { smc.sendMessageToPlayer(this.Formatter.Italic("No description set...")); } List <string> inventory = targetNPC.GetInventoryList(); string inventoryOutput = String.Empty; if (inventory.Any()) { foreach (string item in inventory) { inventoryOutput += this.Formatter.ListItem(item); } inventoryOutput += this.Formatter.GetNewLines(1); } smc.sendMessageToPlayer(inventoryOutput); targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID); targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc); return; } // If not an NPC, check the players equipped items and the items in the room... SMItem smi = smc.GetEquippedItem(thingToInspect); if (smi == null) { smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect); } if (smi != null) { string itemDeatils = this.Formatter.Bold("Description of \"" + smi.ItemName + "\":", 1); itemDeatils += this.Formatter.General(smi.ItemDescription, 1); if (smi.CanHoldOtherItems()) { itemDeatils += this.Formatter.Italic($"This \"{smi.ItemName}\" contains the following items:", 1); itemDeatils += SMItemHelper.GetContainerContents(smi); } if (smi.Effects != null) { smi.InitiateEffects(smc); } smc.sendMessageToPlayer(itemDeatils); return; } // Otherwise nothing found smc.sendMessageToPlayer(this.Formatter.Italic("Can not inspect that item.")); }
/// <summary> /// Inspect a person, object, etc. /// </summary> /// <param name="smc">The character doing the inspecting</param> /// <param name="thingToInspect">The thing that the person wants to inspect</param> public void InspectThing(SMCharacter smc, string thingToInspect) { // Check if it's a character first SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower()); if (targetCharacter != null) { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetCharacter.GetFullName() + " (Level " + targetCharacter.CalculateLevel() + "):")); if ((targetCharacter.Description != null) || (targetCharacter.Description != "")) { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetCharacter.Description)); } else { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set...")); } smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetCharacter.GetInventoryList())); targetCharacter.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(smc.GetFullName() + " looks at you")); return; } // If not a character, check if it is an NPC... SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower()); if (targetNPC != null) { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetNPC.GetFullName() + " (Level " + targetNPC.CalculateLevel() + "):")); if ((targetNPC.Description != null) || (targetNPC.Description != "")) { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetNPC.Description)); } else { smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set...")); } smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetNPC.GetInventoryList())); targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID); targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc); return; } // If not an NPC, check the players equipped items and the items in the room... SMItem smi = smc.GetEquippedItem(thingToInspect); if (smi == null) { smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect); } if (smi != null) { string itemDeatils = OutputFormatterFactory.Get().Bold("Description of \"" + smi.ItemName + "\":"); itemDeatils += OutputFormatterFactory.Get().ListItem(smi.ItemDescription); if (smi.CanHoldOtherItems()) { itemDeatils += OutputFormatterFactory.Get().Italic($"This \"{smi.ItemName}\" contains the following items:"); itemDeatils += SMItemHelper.GetContainerContents(smi); } smc.sendMessageToPlayer(itemDeatils); return; } // Otherwise nothing found smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("Can not inspect that item.")); }