예제 #1
0
        public StateSpaceComponents()
        {
            EntitiesToDelete                  = new List <Guid>();
            Entities                          = new List <Entity>();
            PositionComponents                = new Dictionary <Guid, PositionComponent>();
            VelocityComponents                = new Dictionary <Guid, VelocityComponent>();
            DisplayComponents                 = new Dictionary <Guid, DisplayComponent>();
            AnimationComponents               = new Dictionary <Guid, AnimationComponent>();
            LabelComponents                   = new Dictionary <Guid, LabelComponent>();
            SightRadiusComponents             = new Dictionary <Guid, SightRadiusComponent>();
            SkillLevelsComponents             = new Dictionary <Guid, SkillLevelsComponent>();
            TargetPositionComponents          = new Dictionary <Guid, TargetPositionComponent>();
            DirectionComponents               = new Dictionary <Guid, DirectionComponent>();
            TimeToLiveComponents              = new Dictionary <Guid, TimeToLiveComponent>();
            CollisionComponents               = new Dictionary <Guid, CollisionComponent>();
            NameComponents                    = new Dictionary <Guid, NameComponent>();
            AICombatComponents                = new Dictionary <Guid, AICombat>();
            AIAlignmentComponents             = new Dictionary <Guid, AIAlignment>();
            AIStateComponents                 = new Dictionary <Guid, AIState>();
            AIFieldOfViewComponents           = new Dictionary <Guid, AIFieldOfView>();
            AISleepComponents                 = new Dictionary <Guid, AISleep>();
            AIRoamComponents                  = new Dictionary <Guid, AIRoam>();
            AIFleeComponents                  = new Dictionary <Guid, AIFlee>();
            InputMovementComponents           = new Dictionary <Guid, InputMovementComponent>();
            EntityMessageComponents           = new Dictionary <Guid, EntityMessageComponent>();
            AlternateFOVColorChangeComponents = new Dictionary <Guid, AlternateFOVColorChangeComponent>();
            HealthRegenerationComponents      = new Dictionary <Guid, HealthRegenerationComponent>();
            OutlineComponents                 = new Dictionary <Guid, OutlineComponent>();
            SecondaryOutlineComponents        = new Dictionary <Guid, SecondaryOutlineComponent>();
            InventoryComponents               = new Dictionary <Guid, InventoryComponent>();
            PickupComponents                  = new Dictionary <Guid, PickupComponent>();
            StatModificationComponents        = new Dictionary <Guid, StatModificationComponent>();
            ValueComponents                   = new Dictionary <Guid, ValueComponent>();
            ItemFunctionsComponents           = new Dictionary <Guid, ItemFunctionsComponent>();
            PassivesComponents                = new Dictionary <Guid, PassivesComponent>();
            ArtifactStatsComponents           = new Dictionary <Guid, ArtifactStatsComponent>();
            BurningComponents                 = new Dictionary <Guid, BurningComponent>();

            GlobalCollisionComponent = new GlobalCollisionComponent()
            {
                EntitiesThatCollided = new List <Guid>()
            };
            PlayerComponent       = new PlayerComponent();
            GameMessageComponent  = new GameMessageComponent();
            GameplayInfoComponent = new GameplayInfoComponent();
            ObserverComponent     = new ObserverComponent()
            {
                Observed = new List <Guid>()
            };
            InventoryMenuComponent = new InventoryMenuComponent();
            DelayedActions         = new List <Action>();
            random = new Random();
        }
예제 #2
0
        public static void ShowInventoryMenu(StateSpaceComponents spaceComponents, SpriteBatch spriteBatch, Camera camera, SpriteFont messageFont, SpriteFont optionFont, Texture2D UI)
        {
            Entity player = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();

            if (player != null)
            {
                int messageSpacing                  = (int)messageFont.MeasureString("g").Y + 1;
                int messageNumberLeft               = 0;
                int messageNumberMiddle             = 0;
                int messageNumberRight              = 0;
                int panelWidth                      = (int)(camera.FullViewport.Width / 3);
                InventoryMenuComponent menu         = spaceComponents.InventoryMenuComponent;
                InventoryComponent     playerInvo   = spaceComponents.InventoryComponents[player.Id];
                SkillLevelsComponent   playerSkills = spaceComponents.SkillLevelsComponents[player.Id];

                //Draw background
                spriteBatch.Draw(UI, camera.FullViewport.Bounds, Color.Black * .7f);

                //Draw Header
                Vector2 headerSize      = optionFont.MeasureString(Messages.InventoryHeader);
                int     beginningHeight = (int)headerSize.Y + messageSpacing * 2;
                spriteBatch.Draw(UI, new Rectangle(0, 0, camera.FullViewport.Width, beginningHeight), Color.DarkViolet * .3f);
                spriteBatch.DrawString(optionFont, Messages.InventoryHeader, new Vector2((int)(camera.FullViewport.Width / 2) - (int)(headerSize.X / 2), messageSpacing), Color.CornflowerBlue);
                beginningHeight += messageSpacing;

                //Draw columns
                //Left
                spriteBatch.Draw(UI, new Rectangle(0, beginningHeight, panelWidth - messageSpacing, camera.FullViewport.Height), Color.DarkBlue * .25f);
                //Middle
                spriteBatch.Draw(UI, new Rectangle(messageSpacing + panelWidth, beginningHeight, panelWidth - messageSpacing, camera.FullViewport.Height), Color.DarkBlue * .25f);
                //Right
                spriteBatch.Draw(UI, new Rectangle(messageSpacing * 2 + panelWidth * 2, beginningHeight, panelWidth - messageSpacing, camera.FullViewport.Height), Color.DarkBlue * .25f);

                //Draw item selection panel
                spriteBatch.DrawString(messageFont, string.Format("Wealth: {0}", playerSkills.Wealth), new Vector2(messageSpacing, beginningHeight), Colors.Messages.Special);
                messageNumberLeft += 2;
                spriteBatch.DrawString(messageFont, string.Format(Messages.InventoryArtifacts + " ({0}/{1})", playerInvo.Artifacts.Count, playerInvo.MaxArtifacts), new Vector2(messageSpacing, beginningHeight + (messageSpacing * messageNumberLeft)), Color.CornflowerBlue);
                messageNumberLeft += 1;
                foreach (Guid item in playerInvo.Artifacts)
                {
                    Color  color   = (menu.SelectedItem == item) ? Colors.Messages.LootPickup : Color.NavajoWhite;
                    string prepend = (menu.SelectedItem == item) ? "> " : string.Empty;
                    spriteBatch.DrawString(messageFont, prepend + spaceComponents.NameComponents[item].Name, new Vector2(messageSpacing, (messageSpacing * messageNumberLeft) + beginningHeight), color);
                    messageNumberLeft += 1;
                }
                spriteBatch.DrawString(messageFont, string.Format(Messages.InventoryConsumables + " ({0}/{1})", playerInvo.Consumables.Count, playerInvo.MaxConsumables), new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft) + beginningHeight), Color.CornflowerBlue);
                messageNumberLeft += 1;
                foreach (Guid item in playerInvo.Consumables)
                {
                    Color  color   = (menu.SelectedItem == item) ? Colors.Messages.LootPickup : Color.NavajoWhite;
                    string prepend = (menu.SelectedItem == item) ? "> " : string.Empty;
                    spriteBatch.DrawString(messageFont, prepend + spaceComponents.NameComponents[item].Name, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft) + beginningHeight), color);
                    messageNumberLeft += 1;
                }
                messageNumberLeft += 2;

                //Gather item information panels
                if (menu.SelectedItem != Guid.Empty)
                {
                    PickupComponent itemInfo  = spaceComponents.PickupComponents[menu.SelectedItem];
                    NameComponent   itemName  = spaceComponents.NameComponents[menu.SelectedItem];
                    ValueComponent  itemValue = spaceComponents.ValueComponents[menu.SelectedItem];
                    List <Tuple <Color, string> > centerMessages = new List <Tuple <Color, string> >();
                    List <Tuple <Color, string> > rightMessages  = new List <Tuple <Color, string> >();

                    //Get name, description, and value
                    rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, itemName.Name));
                    rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, itemName.Description));
                    centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Special, string.Format("This item can be scrapped for {0} gold.", itemValue.Gold)));

                    switch (itemInfo.PickupType)
                    {
                    case ItemType.ARTIFACT:
                        //Collect item use stats for right panel
                        //Artifact Stats
                        ArtifactStatsComponent artifactStats = spaceComponents.ArtifactStatsComponents[menu.SelectedItem];
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Special, string.Format("Upgrade Level: {0}", artifactStats.UpgradeLevel)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Special, string.Format("Depth found: {0}", artifactStats.FloorFound)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Good, "STATISTICS WHILE EQUIPPED:"));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Kills: {0}", artifactStats.KillsWith)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Maximum hit combo: {0}", artifactStats.MaximumComboWith)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Damage given: {0}", artifactStats.DamageGivenWith)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Damage taken: {0}", artifactStats.DamageTakenWith)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Times dodged: {0}", artifactStats.DodgesWith)));
                        rightMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("Times missed: {0}", artifactStats.MissesWith)));

                        //Draw commands for artifact on the left panel
                        spriteBatch.DrawString(messageFont, "Commands: ", new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);
                        spriteBatch.DrawString(messageFont, Messages.Upgrade, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);
                        spriteBatch.DrawString(messageFont, Messages.Scrap, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);
                        spriteBatch.DrawString(messageFont, Messages.Drop, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);

                        //Collect info for middle panel
                        StatModificationComponent stats = spaceComponents.StatModificationComponents[menu.SelectedItem];
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, "This artifact affects the following stats: "));
                        if (stats.AccuracyChange != 0)
                        {
                            string sign  = stats.AccuracyChange > 0 ? "+" : string.Empty;
                            Color  color = stats.AccuracyChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Accuracy {0}{1}", sign, stats.AccuracyChange)));
                        }
                        if (stats.DefenseChange != 0)
                        {
                            string sign  = stats.DefenseChange > 0 ? "+" : string.Empty;
                            Color  color = stats.DefenseChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Defense {0}{1}", sign, stats.DefenseChange)));
                        }
                        if (stats.HealthChange != 0)
                        {
                            string sign  = stats.HealthChange > 0 ? "+" : string.Empty;
                            Color  color = stats.HealthChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Maximum Health {0}{1}", sign, stats.HealthChange)));
                        }
                        if (stats.DieNumberChange != 0)
                        {
                            string sign  = stats.DieNumberChange > 0 ? "+" : string.Empty;
                            Color  color = stats.DieNumberChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Dice Number on Attack {0}{1}", sign, stats.DieNumberChange)));
                        }
                        if (stats.MinimumDamageChange != 0)
                        {
                            string sign  = stats.MinimumDamageChange > 0 ? "+" : string.Empty;
                            Color  color = stats.MinimumDamageChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Minimum Damage {0}{1}", sign, stats.MinimumDamageChange)));
                        }
                        if (stats.MaximumDamageChange != 0)
                        {
                            string sign  = stats.MaximumDamageChange > 0 ? "+" : string.Empty;
                            Color  color = stats.MaximumDamageChange > 0 ? Colors.Messages.Good : Colors.Messages.Bad;
                            centerMessages.Add(new Tuple <Color, string>(color, string.Format("Maximum Damage {0}{1}", sign, stats.MaximumDamageChange)));
                        }

                        //PLACEHOLDER
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, "This artifact has the following effects: "));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Good, "Passive 1: Kills with this item equipped generate 100 gold."));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Bad, "Passive 2: Enemies will not flee (LOCKED)"));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Bad, "Passive 3: Tiles stepped on turn to lava for 5 turns (LOCKED)"));
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Bad, "Bonus: ??? (Kill 40 more enemies with this item to unlock)"));
                        break;

                    case ItemType.CONSUMABLE:
                        //Draw command info on left panel
                        spriteBatch.DrawString(messageFont, "Commands: ", new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);
                        spriteBatch.DrawString(messageFont, Messages.Scrap, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);
                        spriteBatch.DrawString(messageFont, Messages.Drop, new Vector2(messageSpacing, (messageSpacing * 3) + (messageSpacing * messageNumberLeft++) + beginningHeight), Colors.Messages.Normal);

                        //Collect info for middle panel
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, System.Environment.NewLine));
                        ItemFunctionsComponent consumableInfo = spaceComponents.ItemFunctionsComponents[menu.SelectedItem];
                        centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Good, string.Format("This item has {0} uses left.", consumableInfo.Uses)));
                        if (consumableInfo.Uses > 1)
                        {
                            centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Bad, string.Format("This item loses {0} value each use.", consumableInfo.CostToUse)));
                        }
                        if (consumableInfo.Ranged)
                        {
                            centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("This item is cast at a range.")));
                        }
                        else
                        {
                            centerMessages.Add(new Tuple <Color, string>(Colors.Messages.Normal, string.Format("This item is used where you stand.")));
                        }
                        break;
                    }

                    //Print out all the info
                    foreach (Tuple <Color, string> message in centerMessages)
                    {
                        if (string.IsNullOrEmpty(message.Item2))
                        {
                            continue;
                        }
                        string text = MessageDisplaySystem.WordWrap(messageFont, message.Item2, panelWidth - 30 - DevConstants.Grid.TileSpriteSize);

                        float textHeight = messageFont.MeasureString(message.Item2).Y;
                        spriteBatch.DrawString(messageFont, text, new Vector2(messageSpacing * 2 + panelWidth, (int)beginningHeight + (int)textHeight + 10 + (messageNumberMiddle * messageSpacing)), message.Item1);
                        messageNumberMiddle += Regex.Matches(text, System.Environment.NewLine).Count;
                        messageNumberMiddle += 1;
                    }
                    foreach (Tuple <Color, string> message in rightMessages)
                    {
                        if (string.IsNullOrEmpty(message.Item2))
                        {
                            continue;
                        }
                        string text = MessageDisplaySystem.WordWrap(messageFont, message.Item2, panelWidth - 30 - DevConstants.Grid.TileSpriteSize);

                        float textHeight = messageFont.MeasureString(message.Item2).Y;
                        spriteBatch.DrawString(messageFont, text, new Vector2(messageSpacing * 3 + panelWidth * 2, (int)beginningHeight + (int)textHeight + 10 + (messageNumberRight * messageSpacing)), message.Item1);
                        if (text != System.Environment.NewLine)
                        {
                            messageNumberRight += Regex.Matches(text, System.Environment.NewLine).Count;
                        }
                        messageNumberRight += 1;
                    }
                }
            }
        }
예제 #3
0
        public static bool HandleInventoryInput(StateSpaceComponents spaceComponents, GameTime gameTime, KeyboardState prevKey, KeyboardState key)
        {
            bool   keepInventory = true;
            Entity player        = spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).FirstOrDefault();

            if (player != null)
            {
                InventoryMenuComponent menu            = spaceComponents.InventoryMenuComponent;
                InventoryComponent     playerInventory = spaceComponents.InventoryComponents[player.Id];

                //Construct array of all inventory items
                List <Guid> items = new List <Guid>();
                items.AddRange(playerInventory.Artifacts);
                items.AddRange(playerInventory.Consumables);
                int itemSelection = items.IndexOf(menu.SelectedItem);
                if (itemSelection < 0)
                {
                    itemSelection = 0;
                }

                //Item selection
                //If nothing is selected, select the first item
                if ((menu.SelectedItem == Guid.Empty && items.Count > 0) || (items.Count > 0 && !items.Contains(menu.SelectedItem)))
                {
                    menu.SelectedItem = items[itemSelection];
                }

                if (key.IsKeyDown(Keys.Down) && prevKey.IsKeyUp(Keys.Down))
                {
                    itemSelection += 1;
                    if (itemSelection >= items.Count)
                    {
                        itemSelection = 0;
                    }
                }
                else if (key.IsKeyDown(Keys.Up) && prevKey.IsKeyUp(Keys.Up))
                {
                    itemSelection -= 1;
                    if (itemSelection < 0)
                    {
                        itemSelection = items.Count - 1;
                    }
                }
                else if (key.IsKeyDown(Keys.D) && prevKey.IsKeyUp(Keys.D))
                {
                    //Drop the selected item.
                    PositionComponent playerPos = spaceComponents.PositionComponents[player.Id];
                    Entity            item      = spaceComponents.Entities.Where(x => x.Id == items[itemSelection]).FirstOrDefault();
                    if (item != null)
                    {
                        item.ComponentFlags |= Component.COMPONENT_POSITION;
                        spaceComponents.PositionComponents[item.Id] = playerPos;
                        playerInventory.Artifacts.Remove(item.Id);
                        playerInventory.Consumables.Remove(item.Id);
                        itemSelection = 0;
                        items.Remove(item.Id);
                    }
                }
                else if (key.IsKeyDown(Keys.S) && prevKey.IsKeyUp(Keys.S))
                {
                    //Scrap the selected item
                    Entity item = spaceComponents.Entities.Where(x => x.Id == items[itemSelection]).FirstOrDefault();
                    if (item != null)
                    {
                        SkillLevelsComponent playerSkills = spaceComponents.SkillLevelsComponents[player.Id];
                        ValueComponent       itemValue    = spaceComponents.ValueComponents[item.Id];
                        playerSkills.Wealth += itemValue.Gold;
                        playerInventory.Artifacts.Remove(item.Id);
                        playerInventory.Consumables.Remove(item.Id);
                        spaceComponents.EntitiesToDelete.Add(item.Id);
                        spaceComponents.SkillLevelsComponents[player.Id] = playerSkills;
                        itemSelection = 0;
                        items.Remove(item.Id);
                    }
                }

                //Set new selections
                if (items.Count > 0)
                {
                    menu.SelectedItem = items[itemSelection];
                    spaceComponents.InventoryMenuComponent = menu;
                }
                else
                {
                    menu.SelectedItem = Guid.Empty;
                    spaceComponents.InventoryMenuComponent = menu;
                }
            }
            return(keepInventory);
        }