示例#1
0
        private void BuyShopItem(RPGListMenu obj)
        {
            var purchasableItems = ItemRepository.Items.Where(i => i.CanBuy).ToList();

            if (obj.SelectedIndex >= purchasableItems.Count)
            {
                View.PopMenu();
                return;
            }

            var itemToBuy = purchasableItems[obj.SelectedIndex];

            if (PlayerData.Money >= itemToBuy.Cost)
            {
                PlayerData.Money -= itemToBuy.Cost;
                var item = ItemRepository.Get(itemToBuy.Name);
                PlayerData.AddItem(item);
                RPG.Notify(Notification.Alert("Purchased: " + itemToBuy.Name));
                UpdateShop(obj.SelectedIndex);
            }
            else
            {
                RPG.Notify(Notification.Alert("Not enough money."));
            }
        }
示例#2
0
        private void CraftItem(RPGListMenu obj)
        {
            var craftableItems = ItemRepository.Items.Where(i => i.CanCraft).ToList();

            if (obj.SelectedIndex >= craftableItems.Count)
            {
                View.PopMenu();
                return;
            }

            var itemToCraft = craftableItems[obj.SelectedIndex];

            //have items?
            var hasItems = true;

            foreach (var kvp in itemToCraft.CraftItems)
            {
                var inventoryItem = RPG.PlayerData.Inventory.FirstOrDefault(i => i.Name == kvp.Key);
                if (inventoryItem != null)
                {
                    if (inventoryItem.Quantity < kvp.Value)
                    {
                        hasItems = false;
                    }
                }
                else
                {
                    hasItems = false;
                }
            }

            if (hasItems)
            {
                foreach (var kvp in itemToCraft.CraftItems)
                {
                    var inventoryItem = RPG.PlayerData.Inventory.First(i => i.Name == kvp.Key);
                    inventoryItem.Quantity -= kvp.Value;
                    if (inventoryItem.Quantity <= 0)
                    {
                        PlayerData.Inventory.Remove(inventoryItem);
                    }
                }

                var item = ItemRepository.Get(itemToCraft.Name);
                PlayerData.AddItem(item);
                RPG.Notify(Notification.Alert("Crafted: " + itemToCraft.Name));
                UpdateCrafting(obj.SelectedIndex);
            }
            else
            {
                RPG.Notify(Notification.Alert("You do not have the items."));
            }
        }
示例#3
0
        public static void UseSkill(Skill skill)
        {
            if (!skill.Unlocked)
            {
                RPG.Notify(Notification.Alert("You have not unlocked this skill."));
                return;
            }

            skill.Use(skill);

            //Cooldowns, mana use etc
        }
示例#4
0
        private void UseInventoryItem(RPGListMenu obj)
        {
            var selected = obj.SelectedIndex;

            if (selected >= PlayerData.Inventory.Count)
            {
                View.PopMenu();
                return;
            }

            if (!PlayerData.Inventory.Any())
            {
                return;
            }


            var selectedItem = PlayerData.Inventory[selected];

            var used = RPGMethods.UseItem(selectedItem);

            if (selectedItem.Quantity <= 0)
            {
                selected--;
                if (selected < 0)
                {
                    selected = 0;
                }
            }

            UpdateInventory(selected);
            InventoryMenu.SelectedIndex = selected;
            if (used)
            {
                RPG.Notify(Notification.Alert("Used : " + selectedItem.Name));
            }
        }
示例#5
0
文件: RPG.cs 项目: tuita520/GTARPG
 public static void Notify(string notification)
 {
     Notifier.Notify(Notification.Alert(notification));
 }