Esempio n. 1
0
        /// <summary>
        /// Attempts to put on a wearable InventoryItem if there is space. Does not remove items to do so.
        /// </summary>
        /// <param name="item">Item to put on</param>
        private static void Equip(InventoryItem item)
        {
            if (item == null || !(item is IWearable))
            {
                return;
            }
            var wornItem = item as IWearable;

            if (wornItem.Equipped)
            {
                return;
            }

            // Identify all items of the same class that are equiped. Most classes will have only
            // one item equiped at a time, but rings may have more than one. This list is used to
            // handle removing and replacing one worn item with another.
            List <InventoryItem> replaces = new List <InventoryItem>();

            foreach (var kvPair in inventoryContents) // UniqueID, InventoryItem
            {
                if (kvPair.Value.Class != item.Class)
                {
                    continue;
                }
                // If they are the same class, then assume IWearable
                if ((kvPair.Value as IWearable).Equipped)
                {
                    replaces.Add(kvPair.Value);
                }
            }


            string attemptResponse = wornItem.Equip(replaces);

            if (attemptResponse != string.Empty)
            {
                InventoryEffectManager.AddMessageToQueue(attemptResponse);
                closingWindow = true;
            }
            GameText inventoryText = inventoryList[searchString];

            inventoryText.Text = item.InventoryTitle + wornItem.WornOn;
            inventoryList.Remove(searchString);
            inventoryList.Add(item.SortingValue, inventoryText);
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to unequip an item if it is not cursed. Cursed items are blocked from removal.
        /// </summary>
        /// <param name="item">Item to remove from body</param>
        private static void Unequip(InventoryItem item)
        {
            if (item == null || !(item is IWearable))
            {
                return;
            }
            var wornItem = item as IWearable;

            if (!wornItem.Equipped)
            {
                return;
            }

            string attemptResponse = wornItem.Unequip();

            if (attemptResponse != string.Empty)
            {
                InventoryEffectManager.AddMessageToQueue(attemptResponse);
                closingWindow = true;
            }
            inventoryList[searchString].Text = item.InventoryTitle + wornItem.WornOn; // Because removal may fail
        }
Esempio n. 3
0
 internal static void RemoveCurseItem(bool selected = false)
 {
     InventoryEffectManager.AddMessageToQueue("Remove Curse effect not implemented yet.");
 }
Esempio n. 4
0
        /// <summary>
        /// Separates a consumable from the stack (if stackable) and consumes it triggering its effect.
        /// The weight is adjusted with the loss of the item and the item is removed from the list if it
        /// is the last of its kind in the stack or otherwise not stackable. Consumed items do not get dropped
        /// to the floor.
        /// </summary>
        /// <param name="item">Item to be consumed.</param>
        private static void Consume(InventoryItem item)
        {
            if (item == null || !(item is IConsumable))
            {
                return;
            }


            IConsumable consumedItem;
            bool        lastOfStack = false;



            if (item is IStackable && (item as IStackable).Qty > 1)
            {
                // Preserve old inventoryList Dictionary values on item
                var oldItemSortingValue      = item.SortingValue;
                var oldItemInventoryGameText = inventoryList[oldItemSortingValue];

                // Remove old item from inventoryList (not contents though)
                inventoryList.Remove(oldItemSortingValue);

                // Get the consumed item by removing it from the stack
                consumedItem = (IConsumable)((item as IStackable).Remove());

                // Update the GameText object using the new InventoryTitle (incorperates qty change)
                oldItemInventoryGameText.Text = item.InventoryTitle;

                // Insert the updated data back into the Dictionary (because the key is different, we couldn't just change it)
                inventoryList.Add(item.SortingValue, oldItemInventoryGameText);
            }

            else
            {
                consumedItem = item as IConsumable;
                lastOfStack  = true;
            }


            string listKey = item.SortingValue; // Preserve old key in case using an item renames it.

            // Consume the item and get the string response from it for the message log
            // Note, that in order for remaining items in the stack to get the new name, Consume must be
            // called on the stack, not the item being tossed away.
            string attemptResponse = (item as IConsumable).Consume();

            if (attemptResponse != string.Empty)
            {
                InventoryEffectManager.AddMessageToQueue(attemptResponse);
            }
            if (InventoryEffectManager.HasMessages && currentSelectionAction == SelectionActions.None)
            {
                closingWindow = true;
            }

            // If last in the stack, remove the stack and update inventory weight
            if (lastOfStack && inventoryContents.Remove(item.UniqueID))
            {
                inventoryList.Remove(listKey);
                weight -= item.InventoryWeight;
            }
            else   // otherwise just update the inventory weight and text
            if (!lastOfStack)
            {
                weight -= (consumedItem as InventoryItem).InventoryWeight;
                if (item.SortingValue != listKey)
                {
                    GameText textItem = inventoryList[listKey];
                    textItem.Text = item.InventoryTitle;
                    inventoryList.Remove(listKey);
                    inventoryList.Add(item.SortingValue, textItem);
                }
            }

            else
            {
                throw new IndexOutOfRangeException("Item to be removed not found in the Inventory's Contents List");
            }
            UpdateCurrentItem();
        }
Esempio n. 5
0
        public void Attack(ICombatant target)
        {
            // Construct attack message
            CombatManager.AttackDelivery attackMessage = new CombatManager.AttackDelivery();

            var currentWeapon = Inventory.CurrentWeapon;

            if (currentWeapon != null)
            {
                attackMessage.CombatType = currentWeapon.CombatType;
                attackMessage.DamageDice = currentWeapon.DamageDice;
            }
            else
            {
                // http://www.dandwiki.com/wiki/SRD:Unarmed_Strike
                attackMessage.CombatType = CombatManager.CombatType.Melee;
                attackMessage.DamageDice = new KeyValuePair <CombatManager.DamageType, CombatManager.DieType>[]
                {
                    new KeyValuePair <CombatManager.DamageType, CombatManager.DieType>
                        (CombatManager.DamageType.Bludgeoning, CombatManager.DieType.D3)
                };
            }
            attackMessage.CombatType      = CombatManager.CombatType.Melee;
            attackMessage.Attacker        = this;
            attackMessage.Target          = target;
            attackMessage.ToHitModifier   = 0;
            attackMessage.DamageModifiers = new Dictionary <CombatManager.DamageType, int>(0); // Set Capacity to 1


            // Send the attack
            CombatManager.AttackResult attackResult = CombatManager.DeliverAttack(attackMessage);


            // Process the attack results
            if (attackResult.Critical)
            {
                DungeonGameEngine.ProcessMessageQueue(false,
                                                      "You struck a Critical blow to the " + target.EntityName + ".");
            }
            else if (attackResult.Fumble)
            {
                // Not all fumbles have to cause trouble
                if (Utility.Rand.Next(4) == 0)
                {
                    // But this one did, so what happened
                    var fumbleAction = Utility.Rand.Next(100);
                    if (fumbleAction < 70)
                    {
                        // Either you hit yourself
                        DungeonGameEngine.ProcessMessageQueue(false,
                                                              "You swing wildly and miss, hitting yourself in the head in the process.");
                        if (Utility.Rand.Next(2) == 0)
                        {
                            InventoryEffectManager.HeroConfused = true;
                        }
                        else
                        {
                            InventoryEffectManager.KnockHeroUnconcious();
                        }
                    }
                    else
                    {
                        // Or you broke your weapon
                        if (currentWeapon != null)
                        {
                            DungeonGameEngine.ProcessMessageQueue(false, currentWeapon.Break());
                        }
                    }
                }
            }
            else if (attackResult.Hit)
            {
                DungeonGameEngine.ProcessMessageQueue(false,
                                                      "You hit the " + target.EntityName + ".");
            }
            else
            {
                DungeonGameEngine.ProcessMessageQueue(false,
                                                      "You missed the " + target.EntityName + ".");
            }
        }                           // ICombatant