예제 #1
0
        //method that casts spell and returns true, when spell is learned, otherwise doesn't cast and return false
        private bool TryCastSpell(Spell spell, Wizard origin, Wizard target)
        {
            var usedItemIndex = origin._learnedSpells.FindIndex(targetSpell => targetSpell.ToString() == spell.ToString());

            if (usedItemIndex != -1)
            {
                if (spell == new SpellHeal())
                {
                    origin.CastSpell(origin._learnedSpells[usedItemIndex], target, origin.CurrentMana / 4);
                }
                else
                {
                    origin.CastSpell(origin._learnedSpells[usedItemIndex], target);
                }
                return(true);
            }

            return(false);
        }
예제 #2
0
        //method to make enemy move logic
        private void EnemyMove(Wizard enemy)
        {
            //dead enemy can't make a move
            if (enemy.CharacterState == State.Dead)
            {
                return;
            }

            //enemy that need revival, heal or unparalyze
            Wizard inDangerTarget = enemy;
            //enemy that need mana regeneration
            Wizard lowerManaTarget = enemy;

            //if enemy quantity more than 1 we want to choose the most weakened character in list of enemies
            if (_enemy.Count > 1)
            {
                foreach (var wizard in _enemy)
                {
                    if (wizard.CurrentHealthPoints < inDangerTarget.CurrentHealthPoints ||
                        wizard.CharacterState is State.Dead or State.Paralyzed)
                    {
                        if (wizard.CharacterState == State.Paralyzed &&
                            inDangerTarget.CharacterState == State.Paralyzed)
                        {
                            //if both characters are paralyzed it chooses one with least hp
                            switch (wizard.CurrentHealthPoints < inDangerTarget.CurrentHealthPoints)
                            {
                            case true:
                            {
                                inDangerTarget = wizard;
                                break;
                            }

                            case false:
                            {
                                break;
                            }
                            }
                        }
                        else
                        {
                            inDangerTarget = wizard;
                        }
                    }
                    //find character with the least mana
                    if (wizard.CurrentMana < lowerManaTarget.CurrentMana)
                    {
                        lowerManaTarget = wizard;
                    }
                }
            }
            //switch to revive or unparalyze character or his teammate
            switch (inDangerTarget.CharacterState)
            {
            case State.Dead:
            {
                if (TryCastSpell(new SpellRevival(), enemy, inDangerTarget))
                {
                    return;
                }

                break;
            }

            case State.Paralyzed:
            {
                if (TryCastSpell(new SpellUnparalyze(), enemy, inDangerTarget))
                {
                    return;
                }

                break;
            }
            }

            //cast heal spell when character is lowHP and mana is not low
            if (inDangerTarget.CurrentHealthPoints < inDangerTarget.MaxHealthPoints / 2 && enemy.CurrentMana >= enemy.MaxMana / 2)
            {
                if (TryCastSpell(new SpellHeal(), enemy, inDangerTarget))
                {
                    return;
                }
            }

            Artefact outFromFunc;

            //use living water when it is in inventory and inDangerTarget needs hp regeneration
            if (inDangerTarget.CurrentHealthPoints < inDangerTarget.MaxHealthPoints / 2 &&
                enemy.HasWaterBottle(true, out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, inDangerTarget);
                return;
            }

            //use dead water when it is in inventory and lowerManaTarget needs mana regeneration
            if (lowerManaTarget.CurrentMana < lowerManaTarget.MaxMana / 4 &&
                enemy.HasWaterBottle(false, out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, lowerManaTarget);
                return;
            }

            //use armor spell when mana is almost full(it is quite expensive)
            if (enemy.CurrentMana > enemy.MaxMana * 8 / 10)
            {
                if (TryCastSpell(new SpellArmor(), enemy, enemy))
                {
                    return;
                }
            }

            //switch to undo the negative state
            switch (enemy.CharacterState)
            {
            case State.Poisoned:
            {
                if (TryUseArtefact(new FrogLegsDecoct(), enemy, enemy))
                {
                    return;
                }

                break;
            }

            case State.Sick:
            {
                if (TryCastSpell(new SpellAntidote(), enemy, enemy))
                {
                    return;
                }

                break;
            }
            }

            //use artefact with negative status on main player
            if (_mainPlayer.CharacterState != State.Dead &&
                (_mainPlayer.CharacterState is State.Healthy or State.Weakened) &&
                enemy.HasStatusArtefact(out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, _mainPlayer);
                return;
            }

            //use spell FireBall on main player when there is enough mana and spell is learned
            if (enemy._learnedSpells.FindIndex(spell => spell.ToString() == new SpellFireball().ToString()) != -1 &&
                enemy.CurrentMana > enemy.MaxMana / 4)
            {
                enemy.CastSpell(new SpellFireball(), _mainPlayer, enemy.CurrentMana / 4);
            }

            enemy.UseArtefact(enemy._inventory[0], _mainPlayer);
        }
예제 #3
0
        //a little menu for usage of spells and artefacts
        private void UseMenu()
        {
            Console.WriteLine("Write what do you want do use: \"spell\" or \"artefact\"");
            string temp;

            while (true)
            {
                temp = Console.ReadLine()?.ToUpper();
                //artefact usage section
                if (temp is "A" or "ARTEFACT")
                {
                    _mainPlayer.ShowInventory();
                    Thread.Sleep(2000);
                    Console.WriteLine("Pick a number of an artefact that you want to use");
                    int pickArtefact;
                    while (true)
                    {
                        //checks for correct input of picked artefact
                        if (int.TryParse(Console.ReadLine(), out pickArtefact) &&
                            pickArtefact <= _mainPlayer._inventory.Count && pickArtefact > 0)
                        {
                            break;
                        }

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Gods hate ridicule, you played with fire and lose");
                        Console.ResetColor();
                    }

                    Thread.Sleep(2000);
                    //call for target selection
                    int select = SelectTarget();
                    //use previously picked artefact on selected enemy
                    _mainPlayer.UseArtefact(_mainPlayer._inventory[pickArtefact - 1],
                                            select == 0 ? _mainPlayer : _enemy[select - 1]);
                    Thread.Sleep(2000);
                    break;
                }

                //spell cast section
                if (temp is "SPELL" or "S")
                {
                    //check for empty list of learned spells
                    bool isEmpty = !_mainPlayer._learnedSpells.Any();
                    if (isEmpty)
                    {
                        Console.WriteLine("Oopsie... You don't know any spell yet ;(");
                        UseMenu();
                    }
                    else
                    {
                        _mainPlayer.ShowLearnedSpells();
                        Thread.Sleep(2000);
                        Console.WriteLine("Pick a number of a spell that you want to use");
                        int pickSpell;
                        while (true)
                        {
                            //check for correct input
                            if (int.TryParse(Console.ReadLine(), out pickSpell) &&
                                pickSpell <= _mainPlayer._learnedSpells.Count && pickSpell > 0)
                            {
                                break;
                            }

                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Gods hate ridicule, you played with fire and lose");
                            Console.ResetColor();
                        }

                        //select target for spell cast
                        int select = SelectTarget();

                        if (_mainPlayer._learnedSpells[pickSpell - 1].ToString() == new SpellHeal().ToString() ||
                            _mainPlayer._learnedSpells[pickSpell - 1].ToString() == new SpellFireball().ToString())
                        {
                            //cast spells with magic power parameter
                            Console.WriteLine("Enter magic power");
                            int magic;
                            while (true)
                            {
                                //check for correct input of spell choice
                                if (int.TryParse(Console.ReadLine(), out magic) && magic > 0 &&
                                    magic * _mainPlayer._learnedSpells[pickSpell - 1].ManaCost <=
                                    _mainPlayer.CurrentMana)
                                {
                                    break;
                                }

                                if (magic * _mainPlayer._learnedSpells[pickSpell - 1].ManaCost <=
                                    _mainPlayer.CurrentMana)
                                {
                                    Console.WriteLine("You don't have enough mana");
                                    UseMenu();
                                }
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Gods hate ridicule, you played with fire and lose");
                                Console.ResetColor();
                            }
                            //cast picked spell with magic power parameter on selected enemy
                            _mainPlayer.CastSpell(_mainPlayer._learnedSpells[pickSpell - 1],
                                                  select == 0 ? _mainPlayer : _enemy[select - 1], magic);
                            break;
                        }
                        //cast all the spells that do not need magic power parameter
                        if (_mainPlayer._learnedSpells[pickSpell - 1].ToString() != new SpellHeal().ToString() ||
                            _mainPlayer._learnedSpells[pickSpell - 1].ToString() != new SpellFireball().ToString())
                        {
                            _mainPlayer.CastSpell(_mainPlayer._learnedSpells[pickSpell - 1],
                                                  select == 0 ? _mainPlayer : _enemy[select - 1]);
                        }
                    }

                    break;
                }

                //common message for wrong input
                Console.WriteLine(
                    "Something went wrong, try again and follow the right command's format.");
            }
        }