Ejemplo n.º 1
0
        public static void Display(int cursorIndex = 0, string shopMessage = default)
        {
            // Get Player & Shop & Shop assortment
            Player        player    = Program.Player;
            VillageShop   shop      = player.VillagesManager.CurrentVillage.Shop;
            IList <IItem> shopItems = shop.GetAvailableItems();

            // Define menu items
            var menuItems = new Dictionary <string, Action <int> >();

            // Declare menu items
            foreach (IItem item in shopItems)
            {
                string label = $"\"{item.Name}\" for ${NumberConvertor.ShortenNumber(item.PriceForPlayer)} | { item.Amount } left";

                bool added = menuItems.TryAdd(label, (selectedIndex) =>
                {
                    // Check if player has enough money to afford this item
                    double moreMoney = player.MoneyManager.CanAfford(item.PriceForPlayer);

                    // Break if moreMoney > 0, because it means that player has not enough money
                    if (moreMoney > 0)
                    {
                        Display(selectedIndex, $"You need ${ NumberConvertor.ShortenNumber(moreMoney) } more to buy \"{ item.Name }\"");
                    }

                    // Remove item from the shop
                    IItem soldItem = shop.SellItem(item);

                    // Add item to the player's inventory (take money from player)
                    player.BuyItem(soldItem);

                    // Refresh the menu by redrawing -> nonlinear recursion
                    ShopMenu.Display(selectedIndex);
                });

                if (!added)
                {
                    throw new ApplicationException("Item duplication >> VillageShop");
                }
            }

            // Empty shop message
            if (shopItems.Count == 0)
            {
                menuItems.Add("The shop is empty right now", (selectedIndex) => Display(selectedIndex));
            }

            // Add go to menu menu itme
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Process shop message if valid
            if (shopMessage != default)
            {
                menuItems.Add(shopMessage, (selectedIndex) => Display());
            }

            // Display
            (new Menu(menuItems, "BUY IN THE SHOP:", cursorIndex)).Display();
        }
Ejemplo n.º 2
0
        public static void Display(int cursorPosition = 0)
        {
            // Ref player & village
            Player        player         = Program.Player;
            PlayerVillage villageManager = player.VillagesManager;

            // Define menu options dictionary
            var menuItems = new Dictionary <string, Action <int> >();

            // Get available tasks
            IList <VillageTask> availableTasks = villageManager.CurrentVillage.Tasks.GetAvailableTasks();

            // Get all village's tasks
            foreach (VillageTask task in availableTasks)
            {
                // Skip if player cannot do this task
                if (!villageManager.CanDoTask(task))
                {
                    continue;
                }

                // Define menu option title
                string optionLabel =
                    $"{task.Description} | +{task.ReputationBonus} Reputation | -{villageManager.GetTaskHealthRequirement(task) :0.0}hp";

                // Add option to the menu
                menuItems.Add(optionLabel, (selectedIndex) =>
                {
                    // Start doing task
                    PlayerDoTaskProgress.Display(task);
                });
            }

            // Add no tasks message
            if (availableTasks.Count == 0)
            {
                menuItems.Add("No tasks available right now. Maybe sleeping will help", Display);
            }

            // Add "back to menu" button
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Display
            (new Menu(menuItems, "SOCIALIZE:", cursorPosition)).Display();
        }
Ejemplo n.º 3
0
        public static void Display(int cursorPosition = 0)
        {
            // Ref player & currentVillage
            Player  player         = Program.Player;
            Village currentVillage = player.VillagesManager.CurrentVillage;

            // Show only nearest villages to the player
            var menuItems = new Dictionary <string, Action <int> >();

            // Get nearest villages
            IList <Village> nearestVillages = player.VillagesManager.GetNearestVillages(5);

            // Add nearest villages to the menu
            foreach (Village village in nearestVillages)
            {
                // Extract some values to construct the option label
                double distance          = village.GetDistanceTo(currentVillage);
                float  healthRequirement = player.VillagesManager.GetTripHealthRequirement(village);
                string reputationLabel   = player.VillagesManager.GetReputationAsString(village);

                // Generate option label
                string optionTitle =
                    $"\"{village.Name}\" ({distance:0.0}km) ({reputationLabel} Reputation) | -{healthRequirement:0.0}hp";

                // Add to the menu
                menuItems.Add(optionTitle, (selectedIndex) =>
                {
                    // Start traveling
                    PlayerTravelProgress.Display(village);
                });
            }

            // Not enough health to travel message
            if (nearestVillages.Count == 0)
            {
                menuItems.Add("You cannot travel anywhere. Sleep to open more villages", Display);
            }

            // Add "back to menu" button
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Display
            (new Menu(menuItems, "TRAVEL TO:", cursorPosition)).Display();
        }
Ejemplo n.º 4
0
        public static void Display()
        {
            // Define menu items dictionary
            var menuItems = new Dictionary <string, Action <int> >();

            // Get all monsters in the assembly to access names
            Type        monsterInterfaceType = typeof(AMonster);
            List <Type> monsterTypes         = AppDomain.CurrentDomain.GetAssemblies()
                                               .SelectMany(ma => ma.GetTypes())
                                               .Where(ma => monsterInterfaceType.IsAssignableFrom(ma) && !ma.IsInterface).ToList();

            // Fill the options list
            foreach (Type monsterType in monsterTypes)
            {
                // Get name property from the type
                var monsterName = (string)monsterType.GetProperty("Name")?.GetValue(null);

                // Get monster strength level
                var monsterLevel = (string)monsterType.GetField("FightDifficulty")?.GetValue(null);

                // Skip if there's a problem with the project structure
                if (monsterName == null)
                {
                    continue;
                }

                // Add monster to the menu
                string itemLabel = $"Dungeon \"{monsterName}\" (Difficulty: {monsterLevel})";

                menuItems.Add(itemLabel, (selectedIndex) =>
                {
                    (new DungeonEngine(monsterType)).ProcessTicks();
                });
            }

            // Add go to menu menu itme
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Display menu
            (new Menu(menuItems, "GO TO DUNGEON:")).Display();
        }
Ejemplo n.º 5
0
        public static void Display(int cursorIndex = 0)
        {
            // Access player & playerInventory
            Player          player          = Program.Player;
            PlayerInventory playerInventory = player.Inventory;
            Village         playerVillage   = player.VillagesManager.CurrentVillage;

            // Define menu items dictionary
            var menuItems = new Dictionary <string, Action <int> >();

            // Get inventory items
            IList <IItem> inventoryItems = playerInventory.Items;

            // Add items
            foreach (IItem item in inventoryItems)
            {
                // Add equip option
                if (item is IEquipable equipableItem)
                {
                    // Check if item is already equiped. Prepare for unequip action if yes
                    bool doEquip = !equipableItem.IsEquipedOn(playerInventory);

                    // Action label
                    string equipText = (doEquip) ? "Equip" : "Unequip";

                    // Add option to the menu
                    menuItems.Add($"{ equipText } \"{ item.Name }\"", (selectedIndex) =>
                    {
                        // Equip/Unequip
                        if (doEquip)
                        {
                            equipableItem.EquipOn(playerInventory);
                        }
                        else
                        {
                            equipableItem.UnequipOn(playerInventory);
                        }

                        // Refresh menu
                        Display(selectedIndex);
                    });
                }
                else if (item is IUseable useableItem)
                { // Add apply {buff} option
                    menuItems.Add($"Use \"{ item.Name }\" | You have { item.Amount }", (selectedIndex) =>
                    {
                        // Remove item from the player's inventory
                        player.Inventory.RemoveItem(item);

                        // Apply item's effects on player
                        useableItem.UseOn(player);

                        // Refresh menu
                        Display(selectedIndex);
                    });
                }

                // Add sell option
                menuItems.Add($"Sell \"{ item.Name }\" for ${ NumberConvertor.ShortenNumber(item.SellPriceForPlayer) } | You have { item.Amount }", (selectedIndex) =>
                {
                    player.SellItem(item);

                    // Refresh menu
                    Display(selectedIndex);
                });
            }

            // Add empty inventory status
            if (inventoryItems.Count == 0)
            {
                menuItems.Add("Your inventory is empty", Display);
            }

            // Add "back to menu" button
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Display
            (new Menu(menuItems, "INVENTORY ACTIONS:", cursorIndex)).Display();
        }