Exemple #1
0
        public Situation HandleSituation(Situation currentSituation, GameController gameController)
        {
            Player             player     = gameController.player;
            SituationContainer situations = gameController.situations;

            Branch    branch          = situations.GetBranch(currentSituation.objectID);
            Situation resultSituation = currentSituation;

            MenuDrawer.Select(
                branch.title,
                Dictionaries.Merge(
                    branch.nextSituations.ToDictionary(
                        (NextSituation nextSituation) => Pair(nextSituation.title, Action(() => {
                resultSituation = situations.RandomSituationByIDs(nextSituation.IDs);
            }))
                        ),
                    MakeDictionary(
                        Pair("Инвентарь", Action(() => InventoryController.Start(player))),
                        Pair("Сохраниться", EmptyAction),
                        Pair("Выйти", ThrowAction(new GameOverException()))
                        )
                    )
                );

            return(resultSituation);
        }
Exemple #2
0
        public Situation HandleSituation(Situation currentSituation, GameController gameController)
        {
            Player             player     = gameController.player;
            SituationContainer situations = gameController.situations;
            ItemContainer      items      = gameController.items;

            Quest     quest           = situations.GetQuest(currentSituation.objectID);
            Situation resultSituation = currentSituation;

            Item questItem = items.ResolveReference(quest.questItem);

            MenuDrawer.Select(
                $"Вы встретили {quest.holderName}. Он/она/оно предлагает вам квест.",
                MakeDictionary(
                    Pair($"Дать {quest.questItem.count}x {questItem.name}", Action(() => {
                int requiredCount = quest.questItem.count;
                int realCount     = player.CountOfItemInInventory(questItem);

                if (realCount < requiredCount)
                {
                    MenuDrawer.ShowInfoDialog($"Вам нехватает {requiredCount - realCount}x {questItem.name}.");
                }
                else
                {
                    player.RemoveItemFromInventory(questItem, requiredCount);
                    player.coins += quest.coinsReward;

                    foreach (ItemReference rewardItemRef in quest.itemsReward)
                    {
                        Item rewardItem = items.ResolveReference(rewardItemRef);
                        player.AddItemToInventory(rewardItem, rewardItemRef.count);
                    }

                    string rewardItemsString = quest.itemsReward
                                               .Map(items.ResolveReferenceAndCount)
                                               .Map(TupleFunc((Item item, int count) => $"{count}x {item.name}"))
                                               .Join(", ");
                    if (rewardItemsString.IsEmpty())
                    {
                        MenuDrawer.ShowInfoDialog($"Квест выполнен! Вы получили за квест {quest.coinsReward} монет.");
                    }
                    else
                    {
                        MenuDrawer.ShowInfoDialog($"Квест выполнен! Вы получили за квест {rewardItemsString} и " +
                                                  $"{quest.coinsReward} монет.");
                    }
                }
            })),
                    Pair("Уйти", Action(() => {
                resultSituation = situations.RandomSituationByIDs(quest.situationsOnCancel);
            })),
                    Pair("Инвентарь", Action(() => InventoryController.Start(player))),
                    Pair("Сохраниться", EmptyAction),
                    Pair("Выйти", ThrowAction(new GameOverException()))
                    )
                );

            return(resultSituation);
        }
Exemple #3
0
        public Situation HandleSituation(Situation currentSituation, GameController gameController)
        {
            Player             player     = gameController.player;
            SituationContainer situations = gameController.situations;
            ItemContainer      items      = gameController.items;

            Merchant  merchant        = situations.GetMerchant(currentSituation.objectID);
            Situation resultSituation = currentSituation;

            Dictionary <string, Action> actions = merchant.items.ToDictionary(
                (MerchantItem itemRef) => {
                int itemPrice = itemRef.price;
                Item item     = items.GetByTypeAndID(itemRef.type, itemRef.id);
                string title  = $"Купить '{item.name}' ({item.description}) - {itemPrice} монет";

                return(Pair(title, Action(() => {
                    if (player.coins >= itemPrice)
                    {
                        if (player.inventory.Count < Player.MAX_INVENTORY_SIZE)
                        {
                            player.AddItemToInventory(item);
                            player.coins -= itemPrice;
                            MenuDrawer.ShowInfoDialog($"Вы купили '{item.name}'!");
                        }
                        else
                        {
                            MenuDrawer.ShowInfoDialog("Вам нехватает места в инвентаре!");
                        }
                    }
                    else
                    {
                        MenuDrawer.ShowInfoDialog($"Вам нехватает {itemPrice - player.coins} монет!");
                    }
                })));
            }
                );

            MenuDrawer.Select(
                $"Вы провстречали '{merchant.name}' ({merchant.type}). Ваши монеты: {player.coins}.",
                Dictionaries.Merge(
                    actions,
                    MakeDictionary(
                        Pair("Продолжить", Action(() => {
                resultSituation = situations.RandomSituationByIDs(merchant.nextSituations);
            })),
                        Pair("Инвентарь", Action(() => InventoryController.Start(player))),
                        Pair("Сохраниться", EmptyAction),
                        Pair("Выйти", ThrowAction(new GameOverException()))
                        )
                    )
                );

            return(resultSituation);
        }
Exemple #4
0
        public Situation HandleSituation(Situation currentSituation, GameController gameController)
        {
            Player             player     = gameController.player;
            SituationContainer situations = gameController.situations;
            ItemContainer      items      = gameController.items;

            Enemy     enemy           = situations.GetEnemy(currentSituation.objectID);
            Situation resultSituation = currentSituation;

            MenuDrawer.Select(
                $"{enemy.name} встаёт на вашем пути. У него {enemy.health}/{enemy.maxHealth} здоровья, " +
                $"{enemy.defense} защиты и {enemy.attack} атаки.",
                MakeDictionary(
                    Pair("Сразиться", Action(() => {
                int enemyHealth = enemy.health;

                string resultSituationID = "";

                while (resultSituationID.IsEmpty())
                {
                    MenuDrawer.Select(
                        $"Игрок ({player.health}/{player.maxHealth} HP, {player.attack} ATK, {player.defense} DEF) " +
                        $"VS {enemy.name} ({enemyHealth}/{enemy.maxHealth} HP, {enemy.attack} ATK, {enemy.defense} DEF)",

                        MakeDictionary <string, Action>(
                            Pair <string, Action>("Атаковать", () => {
                        enemyHealth -= ComputeRealDamage(player.attack, enemy.defense);
                        if (enemyHealth <= 0)
                        {
                            resultSituationID = enemy.situationsOnDefeat.RandomElement();
                            player.coins     += enemy.coinsReward;

                            foreach (ItemReference dropRef in enemy.drop)
                            {
                                Item item = items.ResolveReference(dropRef);
                                for (int i = 0; i < dropRef.count; i++)
                                {
                                    player.AddItemToInventory(item);
                                }
                            }

                            if (enemy.drop.IsEmpty())
                            {
                                MenuDrawer.ShowInfoDialog($"{enemy.name} повержен! Вы получили за это " +
                                                          $"{enemy.coinsReward} монет.");
                            }
                            else
                            {
                                IEnumerable <string> dropNames = enemy.drop
                                                                 .Select((ItemReference itemRef) => {
                                    Item item = items.GetByTypeAndID(itemRef.type, itemRef.id);
                                    return($"{itemRef.count}x {item.name}");
                                });
                                string dropString = string.Join(", ", dropNames);
                                MenuDrawer.ShowInfoDialog($"{enemy.name} повержен! Вы получили за это " +
                                                          $"{dropString} и {enemy.coinsReward} монет.");
                            }
                        }
                        else
                        {
                            int damageToPlayer = ComputeRealDamage(enemy.attack, player.defense);
                            player.health     -= damageToPlayer;
                            if (player.health <= 0)
                            {
                                MenuDrawer.ShowInfoDialog($"Вас убил {enemy.name}!");
                                throw new GameOverException();
                            }

                            MenuDrawer.ShowInfoDialog($"{enemy.name} нанёс вам {damageToPlayer} урона.");
                        }
                    }),
                            Pair <string, Action>("Инвентарь", () => InventoryController.Start(player)),
                            Pair <string, Action>("Убежать", () => {
                        resultSituationID = enemy.situationsOnRunAway.RandomElement();
                    })
                            )
                        );
                }

                resultSituation = situations.GetSituation(resultSituationID);
            })),
                    Pair("Убежать", Action(() => {
                resultSituation = situations.RandomSituationByIDs(enemy.situationsOnRunAway);
            })),
                    Pair("Инвентарь", Action(() => InventoryController.Start(player))),
                    Pair("Сохраниться", EmptyAction),
                    Pair("Выйти", ThrowAction(new GameOverException()))
                    )
                );

            return(resultSituation);
        }
Exemple #5
0
        public Situation HandleSituation(Situation currentSituation, GameController gameController)
        {
            Player             player     = gameController.player;
            SituationContainer situations = gameController.situations;
            ItemContainer      items      = gameController.items;

            CraftingPlace craftingPlace   = situations.GetCraftingPlace(currentSituation.objectID);
            Situation     resultSituation = currentSituation;

            var actions = craftingPlace.crafts.ToDictionary((Craft craft) => {
                List <Tuple <Item, int> > ingredientsAndCounts =
                    craft.ingredients.Map(items.ResolveReferenceAndCount);

                List <string> ingredientsNames = ingredientsAndCounts
                                                 .Map(TupleFunc((Item ingredient, int count) => $"{count}x {ingredient.name}"));

                Item craftResult = items.ResolveReference(craft.result);
                var craftTitle   = $"{ingredientsNames.Join(" + ")} => {craft.result.count}x {craftResult.name}";

                return(Pair(craftTitle, Action(() => {
                    List <Tuple <Item, int> > missingIngredients = ingredientsAndCounts
                                                                   .Map(TupleFunc((Item ingredient, int requiredCount) => {
                        int realCount = player.CountOfItemInInventory(ingredient);
                        return Tuple.Create(ingredient, requiredCount - realCount);
                    }))
                                                                   .Filter(TupleFunc((Item ingredient, int missingCount) => missingCount > 0));

                    if (missingIngredients.IsEmpty())
                    {
                        int ingredientsCount = ingredientsAndCounts
                                               .Map(TupleFunc((Item ingredient, int count) => count))
                                               .Sum();
                        int inventorySizeAfterCraft = player.inventory.Count - ingredientsCount + craft.result.count;

                        if (inventorySizeAfterCraft < Player.MAX_INVENTORY_SIZE)
                        {
                            ingredientsAndCounts.ForEach(TupleAction <Item, int>(player.RemoveItemFromInventory));
                            player.AddItemToInventory(craftResult, craft.result.count);
                            MenuDrawer.ShowInfoDialog($"Вы скрафтили {craft.result.count}x {craftResult.name}!");
                        }
                        else
                        {
                            MenuDrawer.ShowInfoDialog("Вам нехватает места в инвентаре!");
                        }
                    }
                    else
                    {
                        string missingIngredientsString = missingIngredients
                                                          .Map(TupleFunc((Item ingredient, int count) => $"{count}x {ingredient.name}"))
                                                          .Join(", ");
                        MenuDrawer.ShowInfoDialog($"Вам нехватает {missingIngredientsString}!");
                    }
                })));
            });

            MenuDrawer.Select(
                craftingPlace.name,
                Dictionaries.Merge(
                    actions,
                    MakeDictionary(
                        Pair("Продолжить", Action(() => {
                resultSituation = situations.RandomSituationByIDs(craftingPlace.nextSituations);
            })),
                        Pair("Инвентарь", Action(() => InventoryController.Start(player))),
                        Pair("Сохраниться", EmptyAction),
                        Pair("Выйти", ThrowAction(new GameOverException()))
                        )
                    )
                );

            return(resultSituation);
        }