private static void Attack(Player pl, Enemigo ene, int hab = -1) { if (pl.GetSpeed() > ene.GetSpeed()) { //Jugador Ataca NombreHabilidad(hab); if (hab == 0) { AtaqueDirigidoA(pl, ene, hab); } else if (hab == 2) { int rstH = 5 + pl.GetAttMa(); pl.RestoreHealth(rstH); if (pl.GetHealth() == pl.GetMHealth()) { buffer.InsertText("¡Te has recuperado al máximo!"); } } else if (hab == 4) { AtaqueDirigidoA(pl, ene, hab); AtaqueDirigidoA(pl, ene, hab); } if (hab != 2) { AtaqueDirigidoA(pl, ene, hab); } //Enemigo Ataca AtaqueDirigidoA(ene, pl); } else if (pl.GetSpeed() < ene.GetSpeed()) { //Enemigo Ataca AtaqueDirigidoA(ene, pl); //Jugador Ataca NombreHabilidad(hab); if (hab == 0) { AtaqueDirigidoA(pl, ene, hab); } else if (hab == 2) { int rstH = 5 + pl.GetAttMa(); pl.RestoreHealth(rstH); if (pl.GetHealth() == pl.GetMHealth()) { buffer.InsertText("¡Te has recuperado al máximo!"); } } else if (hab == 4) { AtaqueDirigidoA(pl, ene, hab); AtaqueDirigidoA(pl, ene, hab); } if (hab != 2) { AtaqueDirigidoA(pl, ene, hab); } } else { if (CustomMath.RandomUnit() < 0.5) { //Jugador Ataca NombreHabilidad(hab); if (hab == 0) { AtaqueDirigidoA(pl, ene, hab); } else if (hab == 2) { int rstH = 5 + pl.GetAttMa(); pl.RestoreHealth(rstH); if (pl.GetHealth() == pl.GetMHealth()) { buffer.InsertText("¡Te has recuperado al máximo!"); } } else if (hab == 4) { AtaqueDirigidoA(pl, ene, hab); AtaqueDirigidoA(pl, ene, hab); } if (hab != 2) { AtaqueDirigidoA(pl, ene, hab); } //Enemigo Ataca AtaqueDirigidoA(ene, pl); } else { //Enemigo Ataca AtaqueDirigidoA(ene, pl); //Jugador Ataca NombreHabilidad(hab); if (hab == 0) { AtaqueDirigidoA(pl, ene, hab); } else if (hab == 2) { int rstH = 5 + pl.GetAttMa(); pl.RestoreHealth(rstH); if (pl.GetHealth() == pl.GetMHealth()) { buffer.InsertText("¡Te has recuperado al máximo!"); } } else if (hab == 4) { AtaqueDirigidoA(pl, ene, hab); AtaqueDirigidoA(pl, ene, hab); } if (hab != 2) { AtaqueDirigidoA(pl, ene, hab); } } } }
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(); }