Esempio n. 1
0
        /*_______________Consumicion______________*/
        public bool ConsumeItem(int num)
        {
            bool control = false;

            if (bag[num].GetType().BaseType == typeof(ItemConsumable))
            {
                if (bag[num].GetType() == typeof(ItemPocion))
                {
                    ItemPocion item = (ItemPocion)bag[num];
                    item.Consumir();
                    if (item.GetPocionType() == ItemPocion.PocionType.hp)
                    {
                        if (hp < GetMHealth())
                        {
                            Program.buffer.InsertText("Has tomado " + bag[num].GetName() + " y has recuperado " + item.GetRecoveryStat() + " de vida");
                        }
                        else
                        {
                            Program.buffer.InsertText("Has tomado " + bag[num].GetName() + " y te has recuperado el máximo de vida");
                        }
                    }
                    else
                    {
                        if (mana < manaM)
                        {
                            Program.buffer.InsertText("Has tomado " + bag[num].GetName() + " y has recuperado " + item.GetRecoveryStat() + " de maná");
                        }
                        else
                        {
                            Program.buffer.InsertText("Has tomado " + bag[num].GetName() + " y te has recuperado el máximo de maná");
                        }
                    }
                    bag[num] = null;
                    control  = true;
                }
                else if (bag[num].GetType() == typeof(ItemScroll))
                {
                    ItemScroll item = (ItemScroll)bag[num];
                    item.Consumir();
                    bag[num] = null;
                    control  = true;
                }
                if (!control)
                {
                    throw new NotImplementedException("Error con el objeto de tipo " + bag[num].GetType().Name);
                }
            }
            else
            {
                Program.buffer.InsertText(bag[num].GetName() + " no se puede consumir");
            }
            Item.Ordenar(bag);
            return(control);
        }
Esempio n. 2
0
        public static void Combate(Enemigo ene)
        {
            StartCombate();
            buffer.InsertText("¡Ha aparecido un " + ene.GetName() + "!");
            BackgroundCombat();
            string[] comandos = { "atacar", "defender", "huir", "consumir", "habilidad" };
            bool     huir     = false;
            int      itemHuir = -1;

            while (!(pl.IsDead() || ene.IsDead() || huir))
            {
                Console.SetCursorPosition(1, 18);
                string decide = Console.ReadLine().ToLower();
                buffer.InsertText("");
                buffer.InsertText(decide);
                if (decide.Equals(comandos[0]))
                {
                    Attack(pl, ene);
                }
                else if (decide.Equals(comandos[1]))
                {
                    buffer.InsertText("Te has puesto en guardia");
                    AtaqueDirigidoA(ene, pl, -2);
                }
                else if (decide.Equals(comandos[2]))
                {
                    float rand      = (float)CustomMath.RandomUnit();
                    float probHuida = (pl.GetMaldicion(3)) ? 0.25f + pl.GetSpeed() / (float)(2 * (pl.GetSpeed() + ene.GetSpeed())) : 0.25f + pl.GetSpeed() / (float)(pl.GetSpeed() + ene.GetSpeed());
                    if (rand < probHuida)
                    {
                        buffer.InsertText("¡Has huido!");
                        huir = true;
                    }
                    else
                    {
                        if (pl.GetMaldicion(3) && rand < (probHuida - 0.25f) * 2 + 0.25f)
                        {
                            buffer.InsertText("Notas como las piernas no te responden y eres incapaz de moverte");
                        }
                        else
                        {
                            buffer.InsertText("¡No has podido huir!");
                            AtaqueDirigidoA(ene, pl);
                        }
                    }
                }
                else if (decide.Equals(comandos[3]))
                {
                    int i = Comando.ConsumeItemCombat();
                    if (i > -1)
                    {
                        if (pl.GetBag()[i].GetType() == typeof(ItemScroll))
                        {
                            ItemScroll itemScroll = (ItemScroll)pl.GetBag()[i];
                            if (itemScroll.GetId() == 1)
                            {
                                itemHuir = i;
                                huir     = true;
                            }
                        }
                        if (itemHuir == -1)
                        {
                            pl.ConsumeItem(i);
                            AtaqueDirigidoA(ene, pl);
                        }
                    }
                }
                else if (decide.Equals(comandos[4]))
                {
                    buffer.InsertText("¿Que habilidad quieres usar?");
                    buffer.InsertText("[0]-> Ataque Veloz [1]-> Golpe Aplastador [2]-> Curación Menor [3]-> MegaGolpe [4]-> Dardos Mágicos");
                    buffer.Print(1, buffer.height - 2, ">");
                    BackgroundCombat();
                    Console.SetCursorPosition(2, Program.buffer.height - 2);
                    bool obj = int.TryParse(Console.ReadLine(), out int num);
                    if (!obj)
                    {
                        Program.buffer.InsertText("Solo acepta numeros");
                    }
                    else if (num >= 0 && num <= 4)
                    {
                        bool used = true;
                        if (num == 0 && pl.GetMana() - 10 >= 0)
                        {
                            pl.SetMana(pl.GetMana() - 10);
                        }
                        else if (num == 1 && pl.GetMana() - 5 >= 0)
                        {
                            pl.SetMana(pl.GetMana() - 5);
                        }
                        else if (num == 2 && pl.GetMana() - 5 >= 0)
                        {
                            pl.SetMana(pl.GetMana() - 5);
                        }
                        else if (num == 3 && pl.GetMana() - 10 >= 0)
                        {
                            pl.SetMana(pl.GetMana() - 10);
                        }
                        else if (num == 4 && pl.GetMana() - 10 >= 0)
                        {
                            pl.SetMana(pl.GetMana() - 10);
                        }
                        else
                        {
                            buffer.InsertText("No tienes suficiente maná");
                            used = false;
                        }
                        if (used)
                        {
                            Attack(pl, ene, num);
                        }
                    }
                    else
                    {
                        Program.buffer.InsertText("Ese número no es válido");
                    }
                }
                else
                {
                    buffer.InsertText("Comando no valido");
                }


                BackgroundCombat();
            }
            if (pl.IsDead())
            {
                buffer.InsertText("Has muerto...");
            }
            else if (ene.IsDead())
            {
                buffer.InsertText("");
                int exp = 5 + 3 * ene.GetLevel();
                buffer.InsertText("¡Has derrotado a " + ene.GetName() + "!");
                int money = CustomMath.RandomIntNumber(5 + 5 * Program.GetLevel(), 5 + 2 * Program.GetLevel());
                buffer.InsertText("Has conseguido " + money + " monedas");
                pl.GainMoney(money);
                pl.currentRoom.ene = null;
            }
            if (huir && itemHuir == -1)
            {
                ene.RestoreHealth();
                pl.currentRoom.SetVisible(1);
                switch (pl.lastRoom)
                {
                case 0:
                    Comando.MoveNorth();
                    break;

                case 1:
                    Comando.MoveWest();
                    break;

                case 2:
                    Comando.MoveSouth();
                    break;

                case 3:
                    Comando.MoveEast();
                    break;

                default:
                    throw new Exception("Error a la hora de huir");
                }
            }
            else if (huir)
            {
                ene.RestoreHealth();
                pl.ConsumeItem(itemHuir);
            }
            buffer.InsertText("pulsa cualquier boton para continuar");
            BackgroundCombat();
            Console.ReadKey();
        }