Exemplo n.º 1
0
 public Item ReferencedItemIn(ItemContainer itemContainer)
 {
     if (_refrencedItem == null)
     {
         _refrencedItem = itemContainer.GetByTypeAndID(type, id);
     }
     return(_refrencedItem);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }