示例#1
0
 public void AddItemToBag(Item item)
 {
     if (!this.IsFull)
     {
         this.bag.Add(item);
         if (this.bag.Count == MaxBagSlots)
         {
             this.IsFull = true;
         }
     }
 }
示例#2
0
        private void EquipSlot(ItemSprite spr)
        {
            this.bagItemsVisualization.Clear();

            if (spr.mItem is IWeapon)
            {
                if (spr.mItem is IOffhand && !(this.hero.Inventory.MainHandWeapon is TwoHandedWeapon))
                {
                    if (!this.handsButtonPositionSet)
                    {
                        this.mainHandButton.SetPosition(new Vector2(this.mouse.X + 10, this.mouse.Y + 10));
                        this.offHandButton.SetPosition(new Vector2(this.mouse.X + 10, this.mouse.Y + 36));
                        this.handsButtonPositionSet = true;
                    }
                    this.selectedItem = (Item)spr.mItem;
                    this.itemSpritesCurrentlyUpdateable = false;
                    this.handSelectionVisible = true;
                }
                else if ((spr.mItem is TwoHandedWeapon && this.hero.Inventory.OffHand == null)
                    || (this.hero.Inventory.MainHandWeapon is TwoHandedWeapon))
                {
                    this.hero.ReplaceMainHand((Item)spr.mItem, this.MGame.Engine.HeroType);
                }

            }
            else if (spr.mItem is BodyArmor)
            {
                hero.ReplaceBodyArmor((Item)spr.mItem);
            }
            else if (spr.mItem is Helmet)
            {
                hero.ReplaceHelmet((Item)spr.mItem);
            }
            else if (spr.mItem is Shield
                && (this.hero.Inventory.MainHandWeapon is OneHandedWeapon || this.hero.Inventory.MainHandWeapon == null))
            {
                hero.ReplaceOffHand((Item)spr.mItem);
            }
            else if (spr.mItem is Boots)
            {
                hero.ReplaceBoots((Item)spr.mItem);
            }
            else if (spr.mItem is Gloves)
            {
                hero.ReplaceGloves((Gloves)spr.mItem);
            }
            else if (spr.mItem is HealingPotion)
            {
                var hp = (HealingPotion)spr.mItem;
                hero.ApplyHealthPoints(hp);
                hero.Inventory.RemoveItemFromBag((Item)spr.mItem);
            }
            else if (spr.mItem is ManaPotion)
            {
                var mp = (ManaPotion)spr.mItem;
                hero.ApplyManaPoints(mp);
                hero.Inventory.RemoveItemFromBag((Item)spr.mItem);
            }
            FillBag();
            FillEquippables();
        }
示例#3
0
        public override void Update(GameTime gameTime)
        {
            if (MGame.GameStateScreen == GameState.InventoryScreenState)
            {
                currentKeyboardState = Keyboard.GetState();
                mouse = Mouse.GetState();
                descriptionVisible = false;
                //equip if equippable
                for (int i = 0; i < bagItemsVisualization.Count; i++)
                {
                    var itSprite = bagItemsVisualization[i];
                    itSprite.UpdateCurrent(mouse);
                    if (itSprite.IsSelected)
                    {
                        currentItemDescription = itSprite.ItemDescription;
                        bigDescription = itSprite.BigDescription;
                        descriptionVisible = true;
                        descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);

                        if (itSprite.ShowContextMenu)
                        {
                            descriptionVisible = false;
                            if (mouse.RightButton == ButtonState.Pressed &&
                                lastMouseState.RightButton == ButtonState.Released)
                            {
                                if (!throwButtonPositionSet)
                                {
                                    throwButton.SetPosition(new Vector2(mouse.X + 10, mouse.Y + 10));
                                    cancelButton.SetPosition(new Vector2(mouse.X + 10, mouse.Y + 36));
                                    throwButtonPositionSet = true;
                                }
                                selectedItem = (Item)itSprite.mItem;
                                itemSpritesCurrentlyUpdateable = false;
                                throwButtonVisible = true;
                            }
                        }

                    }
                    if (itSprite.IsClicked && itemSpritesCurrentlyUpdateable)
                    {
                        if (mouse.LeftButton == ButtonState.Pressed &&
                            lastMouseState.LeftButton == ButtonState.Released)
                        //Will be true only if the user is currently clicking, but wasn't on the previous call.
                        {
                            EquipSlot(itSprite);
                            throwButtonPositionSet = false;
                            throwButtonVisible = false;
                            itSprite.ShowContextMenu = false;
                        }
                    }
                }
                //update equippables
                #region Update Equippables

                if (itemSpritesCurrentlyUpdateable)
                {
                    if (hero.Inventory.MainHandWeapon != null)
                    {
                        mainHandSprite.UpdateCurrent(mouse);
                        if (mainHandSprite.IsSelected)
                        {
                            currentItemDescription = mainHandSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (mainHandSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.MainHand);
                        }
                    }
                    if (hero.Inventory.BodyArmor != null)
                    {
                        bodyArmorSprite.UpdateCurrent(mouse);
                        if (bodyArmorSprite.IsSelected)
                        {
                            currentItemDescription = bodyArmorSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (bodyArmorSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.Armor);
                        }
                    }
                    if (hero.Inventory.OffHand != null)
                    {
                        offHandSprite.UpdateCurrent(mouse);
                        if (offHandSprite.IsSelected)
                        {
                            currentItemDescription = offHandSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (offHandSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.OffHand);
                        }
                    }
                    if (hero.Inventory.Helmet != null)
                    {
                        helmetSprite.UpdateCurrent(mouse);
                        if (helmetSprite.IsSelected)
                        {
                            currentItemDescription = helmetSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (helmetSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.Helmet);
                        }
                    }
                    if (hero.Inventory.Gloves != null)
                    {
                        glovesSprite.UpdateCurrent(mouse);
                        if (glovesSprite.IsSelected)
                        {
                            currentItemDescription = glovesSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (glovesSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.Gloves);
                        }
                    }
                    if (hero.Inventory.Boots != null)
                    {
                        bootsSprite.UpdateCurrent(mouse);
                        if (bootsSprite.IsSelected)
                        {
                            currentItemDescription = bootsSprite.ItemDescription;
                            descriptionVisible = true;
                            descriptionPosition = new Vector2(mouse.X + 10, mouse.Y + 10);
                        }
                        if (bootsSprite.IsClicked)
                        {
                            MoveToInventory(EquipmentType.Boots);
                        }
                    }
                }

                #endregion
                //END update equippables

                goBackButton.Update(currentKeyboardState, mouse, 0, 0);
                if (goBackButton.IsClicked || CheckKey(Keys.Escape))
                {
                    if (CalledWithFastButton)
                    {
                        MGame.GamePlayScreen.Paused = false;
                        MGame.GameStateScreen = GameState.GameScreenState;
                    }
                    else
                    {
                        MGame.GameStateScreen = GameState.PauseScreenState;
                    }
                }
                throwButton.Update(currentKeyboardState, mouse, 0, 0);
                cancelButton.Update(currentKeyboardState, mouse, 0, 0);
                mainHandButton.Update(currentKeyboardState, mouse, 0, 0);
                offHandButton.Update(currentKeyboardState, mouse, 0, 0);
                if (cancelButton.IsClicked && throwButtonVisible)
                {
                    if (mouse.LeftButton == ButtonState.Pressed &&
                        lastMouseState.LeftButton == ButtonState.Released)
                    {
                        throwButtonVisible = false;
                        throwButtonPositionSet = false;
                        itemSpritesCurrentlyUpdateable = true;
                    }
                }
                if (throwButton.IsClicked && throwButtonVisible)
                {
                    if (mouse.LeftButton == ButtonState.Pressed &&
                        lastMouseState.LeftButton == ButtonState.Released)
                    {
                        hero.Inventory.RemoveItemFromBag(selectedItem);
                        FillBag();
                        throwButtonVisible = false;
                        throwButtonPositionSet = false;
                        itemSpritesCurrentlyUpdateable = true;

                    }
                }
                if (mainHandButton.IsClicked && handSelectionVisible)
                {
                    if (mouse.LeftButton == ButtonState.Pressed &&
                        lastMouseState.LeftButton == ButtonState.Released)
                    {
                        handSelectionVisible = false;
                        handsButtonPositionSet = false;
                        itemSpritesCurrentlyUpdateable = true;
                        hero.ReplaceMainHand((Item)selectedItem, this.MGame.Engine.HeroType);
                        FillBag();
                        FillEquippables();
                    }
                }
                if (offHandButton.IsClicked && handSelectionVisible)
                {
                    if (mouse.LeftButton == ButtonState.Pressed &&
                        lastMouseState.LeftButton == ButtonState.Released)
                    {
                        handSelectionVisible = false;
                        handsButtonPositionSet = false;
                        itemSpritesCurrentlyUpdateable = true;
                        hero.ReplaceOffHand((Item)selectedItem);
                        FillBag();
                        FillEquippables();
                    }

                }

                lastMouseState = mouse;
                lastKeyboardState = currentKeyboardState;
            }
        }
示例#4
0
 public void RemoveItemFromBag(Item item)
 {
     var result = this.Bag.FirstOrDefault(x => x.Id == item.Id);
     if (result != null)
     {
         this.bag.Remove(result);
         this.IsFull = false;
     }
 }