Exemplo n.º 1
0
        public string Equip(List <InventoryItem> replacesItems) // IWearable
        {
            // Catch null parameters
            if (replacesItems == null)
            {
                throw new ArgumentNullException("No list was passed in parameters");
            }

            bool        leftHandFull  = false;
            bool        rightHandFull = false;
            MagicalRing oldRing       = null;


            // Catch items of wrong class, and determine if items of MagicalRing class are
            // equiped on left or right hand
            foreach (var item in replacesItems)
            {
                if (item.Class != Class)
                {
                    throw new ArgumentException("List contained one or more items from the wrong class");
                }
                oldRing = item as MagicalRing;
                if (oldRing.Equipped && oldRing.WornOn == "(Left hand)")
                {
                    leftHandFull = true;
                }
                if (oldRing.Equipped && oldRing.WornOn == "(Right hand)")
                {
                    rightHandFull = true;
                }
            }

            // If hands are full, require removal of one first
            if (leftHandFull && rightHandFull)
            {
                return("Magical rings cannot share the same hand. Remove one first.");
            }

            equipped = true;
            if (!leftHandFull)
            {
                isLeftHand = true;
            }
            else
            {
                isLeftHand = false;
            }


            var it = IdentifyText; // Causes item to be renamed if just discovered

            return("You put " + InventoryTitle + " on your " + (isLeftHand ? "left hand." : "right hand."));
        }
Exemplo n.º 2
0
        internal override bool IsSimilar(InventoryItem other)
        {
            if (other == null || other.Class != Class)
            {
                return(false);
            }
            MagicalRing otherRing = other as MagicalRing;

            if (otherRing.magicalEffect != magicalEffect && otherRing.effectPower != effectPower)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates loot that a monster may cary limitted to their cary limit and chance of having loot
        /// </summary>
        /// <param name="lootProbability"></param>
        /// <param name="lootMaxWeight"></param>
        /// <returns></returns>
        protected static List <InventoryItem> StartingLoot(float lootProbability, float lootMaxWeight)
        {
            List <InventoryItem> newLoot = new List <InventoryItem>();

            if (rand.NextDouble() < lootProbability)
            {
                InventoryItem newLootItem = null;
                do
                {
                    int lootOption = rand.Next(3);

                    switch (lootOption)
                    {
                    case 0: newLootItem = new Food(); break;

                    case 1: newLootItem = new MagicalRing(); break;

                    case 2: newLootItem = MagicalScroll.GenerateNewScroll(); break;
                    }
                } while (newLootItem.InventoryWeight > lootMaxWeight);
                newLoot.Add(newLootItem);
            }
            return(newLoot);
        }