Example #1
0
        /// <summary>
        /// Simpler version of equip item, doesn't care about slots
        /// </summary>
        /// <param name="equipItem"></param>
        internal bool EquipItemNoSlots(IEquippableItem equipItem)
        {
            Item item = equipItem as Item;

            if (item == null)
            {
                //Should never happen
                LogFile.Log.LogEntry("Problem with item equip");
                Game.MessageQueue.AddMessage("You can't equip this item (bug)");
                return false;
            }

            //Play help movie
            if (Game.Dungeon.Player.PlayItemMovies && ItemHelpMovieSeen == false)
            {
                //Screen.Instance.PlayMovie("helpitems", true);
                ItemHelpMovieSeen = true;
            }

            //Set the item as found
            item.IsFound = true;

            //If we have room in our equipped slots, equip and add the item to the inventory
            if (CurrentEquippedItems < MaximumEquippedItems)
            {
                //Add the item to our inventory
                item.IsEquipped = true;
                Inventory.AddItem(item);

                CurrentEquippedItems++;

                //Let the item do its equip action
                //This can happen multiple times in PrincessRL since items can be dropped
                //Probably just play a video
                equipItem.Equip(this);

                //Update the player's combat stats which may have been affected

                CalculateCombatStats();

                //Update the inventory listing since equipping an item changes its stackability
                //No longer necessary since no equippable items get displayed in inventory
                //Inventory.RefreshInventoryListing();

                //Message the user
                LogFile.Log.LogEntryDebug("Item equipped: " + item.SingleItemDescription, LogDebugLevel.Medium);
                //Game.MessageQueue.AddMessage(item.SingleItemDescription + " found.");

                return true;
            }
            else if (LocationLevel == 0)
            {
                //If not, and we're in town, don't pick it up
                Game.MessageQueue.AddMessage("You can't carry any more items. Press 'd' to drop your current items.");
                LogFile.Log.LogEntryDebug("Max number of items reached", LogDebugLevel.Medium);

                return false;
            }
            else
            {
                //If not, and we're not in town, set it as inInventory so it won't be drawn. It'll get returned to town on when go back
                item.InInventory = true;

                //Play the video
                equipItem.Equip(this);

                Game.MessageQueue.AddMessage("You place the " + item.SingleItemDescription + " in your backpack.");
                LogFile.Log.LogEntryDebug("Max number of items reached. Item returns to town.", LogDebugLevel.Medium);

                return true;
            }
        }
Example #2
0
        /// <summary>
        /// Equip an item. Item is removed from the main inventory.
        /// Returns true if item was used successfully.
        /// </summary>
        /// <param name="selectedGroup"></param>
        /// <returns></returns>
        public bool EquipItem(InventoryListing selectedGroup)
        {
            //Select the first item in the stack
            int  itemIndex = selectedGroup.ItemIndex[0];
            Item itemToUse = Inventory.Items[itemIndex];

            //Check if this item is equippable
            IEquippableItem equippableItem = itemToUse as IEquippableItem;

            if (equippableItem == null)
            {
                LogFile.Log.LogEntryDebug("Can't equip item, not equippable: " + itemToUse.SingleItemDescription, LogDebugLevel.Medium);
                Game.MessageQueue.AddMessage("Can't equip " + itemToUse.SingleItemDescription);
                return(false);
            }

            //Find all matching slots available on the player

            List <EquipmentSlot>     itemPossibleSlots  = equippableItem.EquipmentSlots;
            List <EquipmentSlotInfo> matchingEquipSlots = new List <EquipmentSlotInfo>();

            foreach (EquipmentSlot slotType in itemPossibleSlots)
            {
                matchingEquipSlots.AddRange(this.EquipmentSlots.FindAll(x => x.slotType == slotType));
            }

            //No suitable slots
            if (matchingEquipSlots.Count == 0)
            {
                LogFile.Log.LogEntryDebug("Can't equip item, no valid slots: " + itemToUse.SingleItemDescription, LogDebugLevel.Medium);
                Game.MessageQueue.AddMessage("Can't equip " + itemToUse.SingleItemDescription);

                return(false);
            }

            //Look for first empty slot

            EquipmentSlotInfo freeSlot = matchingEquipSlots.Find(x => x.equippedItem == null);

            if (freeSlot == null)
            {
                //Not slots free, unequip first slot
                Item            oldItem           = matchingEquipSlots[0].equippedItem;
                IEquippableItem oldItemEquippable = oldItem as IEquippableItem;

                //Sanity check
                if (oldItemEquippable == null)
                {
                    LogFile.Log.LogEntry("Currently equipped item is not equippable!: " + oldItem.SingleItemDescription);
                    return(false);
                }

                //Run unequip routine
                oldItemEquippable.UnEquip(this);
                oldItem.IsEquipped = false;

                //Can't do this right now, since not in inventory items appear on the floor

                //This slot is now free
                freeSlot = matchingEquipSlots[0];
            }

            //We now have a free slot to equip in

            //Put new item in first relevant slot and run equipping routine
            matchingEquipSlots[0].equippedItem = itemToUse;
            equippableItem.Equip(this);
            itemToUse.IsEquipped = true;

            //Update the inventory listing since equipping an item changes its stackability
            Inventory.RefreshInventoryListing();

            //Message the user
            LogFile.Log.LogEntryDebug("Item equipped: " + itemToUse.SingleItemDescription, LogDebugLevel.Low);
            Game.MessageQueue.AddMessage(itemToUse.SingleItemDescription + " equipped in " + StringEquivalent.EquipmentSlots[matchingEquipSlots[0].slotType]);

            return(true);
        }