コード例 #1
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
 internal static void UpdateDisoveredStatus(MagicalScroll newScroll)
 {
     if (!newScroll.discoveredEffect)
     {
         MagicalScroll archiveScroll = FindInArchives(newScroll);
         newScroll.discoveredEffect = archiveScroll.discoveredEffect;
         newScroll.titleOfOneScroll = archiveScroll.titleOfOneScroll;
     }
 }
コード例 #2
0
        /// <summary>
        /// Adds picked up items to the inventory and stacks any stackable
        /// items if one already exists of the same item class.
        /// </summary>
        /// <param name="item">InventoryItem being picked up or added through any other means.</param>
        internal static void Add(InventoryItem item)
        {
            if (inputInstructions == null)
            {
                throw new InvalidOperationException("Inventory not Initialized.");
            }
            weight += item.InventoryWeight;

            // First detect if the item has been discovered before and update it's name from archives
            if (item is MagicalScroll)
            {
                MagicalScroll.UpdateDisoveredStatus(item as MagicalScroll);
            }

            bool itemExistsInInventory = false;

            if (item is IStackable && inventoryContents.Count > 0)
            {
                // If identical item already in inventory, then add the new item qty to the inventory
                foreach (var kvPair in inventoryContents)
                {
                    var existingStack = kvPair.Value;
                    if (item.IsSimilar(existingStack))
                    {
                        // Preserve objects from Dictionaries before replacing them
                        var listKey          = existingStack.SortingValue;
                        var existingGameText = inventoryList[listKey];


                        // Update quantity
                        (existingStack as IStackable).Add((item as IStackable).Qty);

                        // Update GameText to show new quantity
                        existingGameText.Text = existingStack.InventoryTitle;

                        // Remove old item from dictionary and replace with new item (because key changed).
                        inventoryList.Remove(listKey);
                        inventoryList.Add(existingStack.SortingValue, existingGameText);
                        itemExistsInInventory = true;
                        break;
                    }
                }
            }

            if (!itemExistsInInventory)
            {   // Otherwise, add the new item to the inventory instead
                inventoryContents.Add(item.UniqueID, item);
                inventoryList.Add(item.SortingValue, new GameText(item.InventoryTitle, graphicsDevice));
            }

            if (inventoryList.Count == 1)
            {
                UpdateCurrentItem();
            }
        }
コード例 #3
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
 private static MagicalScroll FindInArchives(MagicalScroll newScroll)
 {
     foreach (var kvPair in scrollProbability)
     {
         if (kvPair.Key.IsSimilar(newScroll))
         {
             return(kvPair.Key);
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
        /// <summary>
        /// Removes a single item from the stack and returns it as a separate stack of 1
        /// </summary>
        /// <returns>Separate item removed</returns>
        public IStackable Remove()                      // IStackable
        {
            if (qty > 1)
            {
                qty--;

                MagicalScroll removedScroll = (MagicalScroll)MemberwiseClone();
                removedScroll.qty = 1;
                InventoryWeight   = qty * UNIT_WEIGHT;
                return(removedScroll);
            }
            else
            {
                throw new ArithmeticException("A pile of food cannot exist with qty = 0");
            }
        }
コード例 #5
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
        /// <summary>
        /// Resets the MagicalScroll static data to the state needed for a new game. All scrolls
        /// created in a previous game are deleted and the dictionary is repopulated with new scrolls
        /// each having a new unique magical name.
        /// </summary>
        internal static void InitNewGame()
        {
            scrollProbability = new Dictionary <MagicalScroll, float>();

            GameConstants.TemporaryEffects[] tempEffectList =
            {
                GameConstants.TemporaryEffects.Blind,
                GameConstants.TemporaryEffects.Confused,
                GameConstants.TemporaryEffects.Hastened,
                GameConstants.TemporaryEffects.ImprovedNightSight,
                GameConstants.TemporaryEffects.Observant,
                GameConstants.TemporaryEffects.SensesMonster,
                GameConstants.TemporaryEffects.SensesMonster,
                GameConstants.TemporaryEffects.Slowed
            };

            GameConstants.InstantEffects[] instantEffectList =
            {
                GameConstants.InstantEffects.VaporizeMonsters,
                GameConstants.InstantEffects.AscendStairs,
                GameConstants.InstantEffects.Identify,
                GameConstants.InstantEffects.RevealMap,
                GameConstants.InstantEffects.RestoreStrength,
                GameConstants.InstantEffects.RemoveCurse,
                GameConstants.InstantEffects.LightRoom
            };

            float[] instEffectProbability = { 0.02f, 0.03f, 0.10f, 0.15f, 0.10f, 0.10f, 0.10f };

            foreach (var selectedEffect in tempEffectList)
            {
                MagicalScroll newScroll = new MagicalScroll(typeof(GameConstants.TemporaryEffects),
                                                            selectedEffect, GameConstants.InstantEffects.Undefined);
                scrollProbability.Add(newScroll, 0.05f); // Each temp effect has even chance of selection
            }

            for (int i = 0; i < instantEffectList.Count(); i++)
            {
                MagicalScroll newScroll = new MagicalScroll(typeof(GameConstants.InstantEffects),
                                                            GameConstants.TemporaryEffects.Undefined, instantEffectList[i]);
                scrollProbability.Add(newScroll, instEffectProbability[i]);
            }
        }
コード例 #6
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
        /// <summary>
        /// Selects a scroll from the archives to copy, preserving any discovered effects for the
        /// new scroll.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        internal static MagicalScroll GenerateNewScroll(Point location = new Point())
        {
            MagicalScroll newScroll = null;
            KeyValuePair <MagicalScroll, float> kvPair;

            while (newScroll == null)
            {
                // Randomly pick a scroll, then roll against probability of selecting that scroll
                int i = rand.Next(scrollProbability.Count);
                kvPair = scrollProbability.ElementAt(i);
                if (kvPair.Value > rand.NextDouble())
                {
                    newScroll          = (MagicalScroll)kvPair.Key.MemberwiseClone();
                    newScroll.qty      = 1;
                    newScroll.Location = location;
                    newScroll.AssignNewID();
                }
            }
            return(newScroll);
        }
コード例 #7
0
ファイル: Monster.cs プロジェクト: jclovis3/DungeonGeek
        /// <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);
        }
コード例 #8
0
ファイル: MagicalScroll.cs プロジェクト: jclovis3/DungeonGeek
        private void NameScroll()
        {
            if (effectType == typeof(GameConstants.TemporaryEffects))
            {
                switch (tempEffect)
                {
                case GameConstants.TemporaryEffects.Hastened:
                    titleOfOneScroll = "a scroll of speed"; break;

                case GameConstants.TemporaryEffects.Slowed:
                    titleOfOneScroll = "a scroll of slowness"; break;

                case GameConstants.TemporaryEffects.Blind:
                    titleOfOneScroll = "a scroll of utter darkness"; break;

                case GameConstants.TemporaryEffects.Confused:
                    titleOfOneScroll = "a scroll of confusion"; break;

                case GameConstants.TemporaryEffects.ImprovedNightSight:
                    titleOfOneScroll = "a scroll of increased night vision"; break;

                case GameConstants.TemporaryEffects.SensesMonster:
                    titleOfOneScroll = "a scroll monster awareness"; break;

                case GameConstants.TemporaryEffects.Stuck:
                    titleOfOneScroll = "a scroll of paralysis"; break;

                case GameConstants.TemporaryEffects.Observant:
                    titleOfOneScroll = "a scroll of perception"; break;
                }
            }
            else
            {
                switch (instantEffect)
                {
                case GameConstants.InstantEffects.RestoreStrength:
                    titleOfOneScroll = "a scroll of restore strength"; break;

                case GameConstants.InstantEffects.RemoveCurse:
                    titleOfOneScroll = "a scroll of remove curse"; break;

                case GameConstants.InstantEffects.Identify:
                    titleOfOneScroll = "a scroll of identify"; break;

                case GameConstants.InstantEffects.RevealMap:
                    titleOfOneScroll = "a scroll with a map on it"; break;

                case GameConstants.InstantEffects.AscendStairs:
                    titleOfOneScroll = "a scroll of magical assending stairs"; break;

                case GameConstants.InstantEffects.LightRoom:
                    titleOfOneScroll = "a scroll so bright it could light a room"; break;

                case GameConstants.InstantEffects.VaporizeMonsters:
                    titleOfOneScroll = "a scroll of vaporize known monsters"; break;
                }
            } // end if(effectType == typeof(GameConstants.TemporaryEffects))



            // Update the name for the scrollArchives
            MagicalScroll archiveScroll = FindInArchives(this);

            archiveScroll.titleOfOneScroll = titleOfOneScroll;
            archiveScroll.discoveredEffect = true;
        }