Пример #1
0
        public void SetMerchant(Player p, Character c)
        {
            _merchant = c;

            _conversationManager.ClearConversations();

            Conversations list = GameRef.Content.Load <Conversations>(@"SilverProphet\MerchantConversations\" + _merchant.Name);

            _conversation = list.ConversationList[_merchant.Name];

            if (!_merchantManager.ContainsMerchant(_merchant.Name))
            {
                _inventory = GameRef.Content.Load <MerchantInventory>(@"SilverProphet\MerchantInventories\" + _merchant.Name);
            }
            else
            {
                _inventory = _merchantManager.GetMerchant(_merchant.Name);
            }

            player    = p;
            _portrait = c.Portrait;

            _mode = MerchantMode.Talk;

            _selectedIndex = 0;
            _selectedItem  = "";

            _conversation.StartConversation();
        }
Пример #2
0
        public override void Update(GameTime gameTime)
        {
            PlayerIndex index = PlayerIndex.One;
            int         i     = 0;

            switch (_mode)
            {
            case MerchantMode.Talk:
                _conversation.Update(gameTime);

                if (Xin.WasReleased(PlayerIndexInControl, Buttons.A, Keys.Space, out index) || Xin.WasReleased(PlayerIndexInControl, Buttons.A, Keys.Space, out index))
                {
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.Buy)
                    {
                        _mode = MerchantMode.Buy;
                    }
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.Sell)
                    {
                        _mode = MerchantMode.Sell;
                    }
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.End)
                    {
                        _manager.PopState();
                    }
                }
                else if (Xin.CheckMouseReleased(MouseButton.Left) && _conversation.CurrentScene.IsMouseOver)
                {
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.Buy)
                    {
                        _mode = MerchantMode.Buy;
                    }
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.Sell)
                    {
                        _mode = MerchantMode.Sell;
                    }
                    if (_conversation.CurrentScene.OptionAction.Action == ActionType.End)
                    {
                        _manager.PopState();
                    }
                }
                break;

            case MerchantMode.Buy:
                if (Xin.WasReleased(PlayerIndexInControl, Buttons.A, Keys.Space, out index) || (Xin.CheckMouseReleased(MouseButton.Left) && mouseOver))
                {
                    if (_inventoryManager.ItemList[_selectedItem].Cost <= player.Gold)
                    {
                        player.AddItem(_selectedItem);
                        player.UpdateGold(_inventoryManager.ItemList[_selectedItem].Cost * -1);
                        player.Character.AddItem(_inventoryManager.ItemList[_selectedItem]);
                        _inventory.RemoveItem(_selectedItem);

                        foreach (string s in player.ActiveQuests.Keys)
                        {
                            if (player.ActiveQuests[s].CurrentStep.QuestStepType == QuestStepType.Buy &&
                                player.ActiveQuests[s].CurrentStep.Target == Enum.GetName(typeof(ItemCategory), _inventoryManager.ItemList[_selectedItem].ItemType))
                            {
                                player.ActiveQuests[s].CurrentStep.Finish();
                                player.ActiveQuests[s].UpdateQuestStep();
                            }
                        }
                    }
                    else
                    {
                        // show that the offer was refused
                    }
                }
                else if (Xin.WasReleased(PlayerIndexInControl, Buttons.Back, Keys.Escape, out index) || Xin.CheckMouseReleased(MouseButton.Right))
                {
                    _mode = MerchantMode.Talk;
                }
                else if (!mouseOver)
                {
                    if (Xin.WasReleased(PlayerIndexInControl, Buttons.LeftThumbstickUp, Keys.Up, out index))
                    {
                        _selectedIndex--;

                        if (_selectedIndex < 0)
                        {
                            _selectedIndex = _inventory.Inventory.Count - 1;
                        }
                    }
                    else if (Xin.WasReleased(PlayerIndexInControl, Buttons.LeftThumbstickDown, Keys.Down, out index))
                    {
                        _selectedIndex++;

                        if (_selectedIndex >= _inventory.Inventory.Count)
                        {
                            _selectedIndex = 0;
                        }
                    }
                }

                foreach (string s in _inventory.Inventory.Keys)
                {
                    if (_selectedIndex == i)
                    {
                        _selectedItem = s;
                        break;
                    }
                    i++;
                }
                break;

            case MerchantMode.Sell:
                if (Xin.WasReleased(PlayerIndexInControl, Buttons.A, Keys.Space, out index) || (Xin.CheckMouseReleased(MouseButton.Left) && mouseOver))
                {
                    player.RemoveItem(_selectedItem);
                    player.UpdateGold(_inventoryManager.ItemList[_selectedItem].Cost / 2);
                    _inventory.AddItem(_selectedItem);

                    foreach (string s in player.ActiveQuests.Keys)
                    {
                        if (player.ActiveQuests[s].CurrentStep.QuestStepType == QuestStepType.Sell &&
                            player.ActiveQuests[s].CurrentStep.Target == Enum.GetName(typeof(ItemCategory), _inventoryManager.ItemList[_selectedItem].ItemType))
                        {
                            player.ActiveQuests[s].CurrentStep.Finish();
                            player.ActiveQuests[s].UpdateQuestStep();
                        }
                    }
                }
                else if (Xin.WasReleased(PlayerIndexInControl, Buttons.Back, Keys.Escape, out index) || Xin.CheckMouseReleased(MouseButton.Right))
                {
                    _mode = MerchantMode.Talk;
                }
                else if (!mouseOver)
                {
                    if (Xin.WasReleased(PlayerIndexInControl, Buttons.LeftThumbstickUp, Keys.Up, out index))
                    {
                        _selectedIndex--;

                        if (_selectedIndex < 0)
                        {
                            _selectedIndex = _inventory.Inventory.Count - 1;
                        }
                    }
                    else if (Xin.WasReleased(PlayerIndexInControl, Buttons.LeftThumbstickDown, Keys.Down, out index))
                    {
                        _selectedIndex++;

                        if (_selectedIndex >= _inventory.Inventory.Count)
                        {
                            _selectedIndex = 0;
                        }
                    }
                }

                foreach (string s in player.Backpack.Keys)
                {
                    if (_selectedIndex == i)
                    {
                        _selectedItem = s;
                        break;
                    }
                    i++;
                }
                break;
            }

            base.Update(gameTime);
        }