public int ReceiveDamage(int att, int def) { int damage = (int)(Math.Sin(Math.Atan2(att, def)) * att * (1 - CustomMath.RandomUnit() * 0.1)); damage = (damage == 0) ? 1 : damage; hp -= damage; return(damage); }
private static void AtaqueDirigidoA(CombatClass atacante, CombatClass defensor, int hab = -1) { if (!atacante.IsDead()) { float rand = (float)CustomMath.RandomUnit(); float acc = atacante.GetHitPerc() + rand; if (hab == 3) { acc /= 2; } if (acc >= defensor.GetAvoidPerc()) { int ataque = atacante.GetAtt(); int defensa = defensor.GetDef(); if (hab == -2) { defensa = (int)(defensa * 1.5); } else if (hab == 1) { ataque = (int)(ataque * 1.5); } else if (hab == 3) { ataque = ataque * 3; } int danorecibido = defensor.ReceiveDamage(ataque, defensa); try { if (atacante.GetType() == typeof(Player)) { buffer.InsertText("Has hecho " + danorecibido + " de daño a " + ((Enemigo)defensor).GetName()); } else { buffer.InsertText(((Enemigo)atacante).GetName() + " te ha hecho " + danorecibido + " de daño"); } }catch (InvalidCastException e) { buffer.InsertText("Error: " + e.Message); buffer.InsertText("atacante: " + atacante.GetType().ToString()); buffer.InsertText("defensor: " + defensor.GetType().ToString()); } } else { if (atacante.GetType() == typeof(Player)) { buffer.InsertText("¡Has fallado!"); } else { buffer.InsertText("¡" + ((Enemigo)atacante).GetName() + " ha fallado!"); } } } }
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); } 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); } AtaqueDirigidoA(pl, ene, hab); } else { if (CustomMath.RandomUnit() < 0.5) { //Jugador Ataca NombreHabilidad(hab); if (hab == 0) { AtaqueDirigidoA(pl, ene, hab); } 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); } AtaqueDirigidoA(pl, ene, hab); } } }
public Enemigo(DatoEnemigo datoEnemigo, int level) { this.level = level; nombre = datoEnemigo.nombre; hpM = (int)((datoEnemigo.hpM * level / 100 + 10)); hp = hpM; att = (int)((5 + datoEnemigo.att * level / 100) * (1 - CustomMath.RandomUnit() * 0.1f)); def = (int)((5 + datoEnemigo.def * level / 100) * (1 - CustomMath.RandomUnit() * 0.1f)); speed = (int)((5 + datoEnemigo.speed * level / 100) * (1 - CustomMath.RandomUnit() * 0.1f)); manaM = (int)((5 + datoEnemigo.manaM * level / 100) * (1 - CustomMath.RandomUnit() * 0.1f)); mana = manaM; attMa = (int)((5 + datoEnemigo.attMa * level / 100) * (1 - CustomMath.RandomUnit() * 0.1f)); avoidPerc = datoEnemigo.avoidPerc; hitPerc = datoEnemigo.hitPerc; }
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; 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])) { if (Comando.ConsumeItem()) { 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"); buffer.Print(1, buffer.height - 2, ">"); BackgroundCombat(); Console.SetCursorPosition(2, buffer.height - 2); bool obj = int.TryParse(Console.ReadLine(), out int num); if (!obj) { buffer.InsertText("Solo acepta numeros"); } if (num >= 0 && num <= 3) { if (num == 0) { if (pl.GetMana() - 10 >= 0) { pl.SetMana(pl.GetMana() - 10); Attack(pl, ene, num); } else { buffer.InsertText("No tienes suficiente maná"); } } else if (num == 1) { if (pl.GetMana() - 5 >= 0) { Attack(pl, ene, num); } else { buffer.InsertText("No tienes suficiente maná"); } } else if (num == 2) { if (pl.GetMana() - 5 >= 0) { pl.SetMana(pl.GetMana() - 5); NombreHabilidad(num); pl.RestoreHealth(5); if (pl.GetHealth() == pl.GetMHealth()) { buffer.InsertText("¡Te has recuperado al máximo!"); } else { buffer.InsertText("Has recuperado 5 de vida"); } AtaqueDirigidoA(ene, pl, num); } else { buffer.InsertText("No tienes suficiente maná"); } } else if (num == 3) { if (pl.GetMana() - 10 >= 0) { pl.SetMana(pl.GetMana() - 10); Attack(pl, ene, num); } else { buffer.InsertText("No tienes suficiente maná"); } } } else { 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() + ", has conseguido " + exp + " xp!"); pl.Experiencia += exp; if (pl.levelUp) { pl.levelUp = false; buffer.InsertText("¡HAS SUBIDO DE NIVEL!"); buffer.InsertText("Nivel: " + (pl.GetLevel() - 1) + " >> " + pl.GetLevel()); } pl.currentRoom.ene = null; } buffer.InsertText("pulsa cualquier boton para continuar"); BackgroundCombat(); if (huir) { 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"); } } Console.ReadKey(); }
//pantalla principal, donde pasa toda la magia public void MainScreen() { CommandMethod method; string textInput; //Dibuja el fondo de primeras ConsoleBuffer.ObteBuffer().Print(1, 0, "PRINCIPAL"); ConsoleBuffer.ObteBuffer().PrintBackground(); ConsoleBuffer.ObteBuffer().InsertText(pl.currentRoom.GetDescriptionTotal()); ConsoleBuffer.ObteBuffer().PrintText(height - 3); ConsoleBuffer.ObteBuffer().SmallMap(); ConsoleBuffer.ObteBuffer().PrintScreen(); do { //Pon el cursos en la posicion de escribir //Console.SetCursorPosition(1, 18); Monitor.Enter(this); Monitor.Wait(this); //Espera input textInput = comando; //Espacio para facilitar lectura ConsoleBuffer.ObteBuffer().InsertText(""); //Lo inserta en el lineTexto ConsoleBuffer.ObteBuffer().InsertText(textInput); //Si el comando es valido if (Comando.CheckCommand(textInput)) { // obten el metodo method = Comando.ReturnCommand(textInput); //si ha obtenido metodo if (method != null) { bool temp = method(); if ((method.Method.Name.Equals("MoveNorth") || method.Method.Name.Equals("MoveSouth") || method.Method.Name.Equals("MoveWest") || method.Method.Name.Equals("MoveEast")) && temp) { pl.currentRoom.SetVisible(2); if (pl.GetMaldicion(1)) { if (pl.GetHealth() > 1 && CustomMath.RandomUnit() < 0.1f) { ConsoleBuffer.ObteBuffer().InsertText("Te has tropezado y has perdido 1 punto de vida"); pl.ReceiveDamage(1, 0); } } /*if (pl.currentRoom.ene != null) * { * ConsoleBuffer.ObteBuffer().InsertText("Un enemigo ha aparecido"); * ConsoleBuffer.ObteBuffer().Print(1, 0, "PRINCIPAL"); * ConsoleBuffer.ObteBuffer().PrintBackground(); * ConsoleBuffer.ObteBuffer().PrintText(17); * SmallMap(this); * ConsoleBuffer.ObteBuffer().PrintScreen(); * Console.ReadKey(); * ConsoleBuffer cbMain = ConsoleBuffer.ObteBuffer(); * ConsoleBuffer.ObteBuffer() = new ConsoleBuffer(width, height, height - 5,this); * EscenaCombate.Combate(pl.currentRoom.ene); * ConsoleBuffer.ObteBuffer() = cbMain; * if (pl.IsDead()) * { * textInput = "exit"; * } * }*/ ConsoleBuffer.ObteBuffer().InsertText(pl.currentRoom.GetDescriptionTotal()); } } else { //En caso contrario avisa ConsoleBuffer.ObteBuffer().InsertText("Not implemented"); } } else { ConsoleBuffer.ObteBuffer().InsertText("Comando no valido"); } if (goNextLevel) { level++; goNextLevel = false; // hola int cRooms = 10 + 5 * level; Level.StartLevel(cRooms); lvlLayout = Level.actualRooms; pl.currentRoom = lvlLayout[0]; ConsoleBuffer.ObteBuffer().ClearBox(); if (pl.GetMaldicion(3)) { if (CustomMath.RandomUnit() < 0.5) { ConsoleBuffer.ObteBuffer().InsertText("Tu invalidez ha hecho que ruedes escaleras abajo de manera muy sonora y cómica. Milagrosamente no has recibido ningún daño. La escalera por la que has rebotado se ha destruido"); } else { ConsoleBuffer.ObteBuffer().InsertText("Tu invalidez ha hecho que tus piernas dejen de responder y tengas que bajar usando las manos. Después de media hora has conseguido bajar. Al tocar el suelo del siguiente piso tus piernas vuelven a responder. La escalera por la que te has arrastrado se ha destruido"); } } else { ConsoleBuffer.ObteBuffer().InsertText("Cuando bajas escuchas un fuerte estruendo. Al mirar arriba las escaleras acaban en el techo de la sala"); } ConsoleBuffer.ObteBuffer().InsertText(pl.currentRoom.GetDescriptionTotal()); if (pl.GetMaldicion(4)) { ConsoleBuffer.ObteBuffer().InsertText("Sientes como un peso se levanta de ti"); for (int i = 0; i < pl.GetArrMal().Length; i++) { if (pl.GetArrMal()[i].GetId() == 4) { pl.GetArrMal()[i] = null; i = pl.GetArrMal().Length; } } } } ConsoleBuffer.ObteBuffer().Print(1, 0, "PRINCIPAL"); ConsoleBuffer.ObteBuffer().PrintBackground(); ConsoleBuffer.ObteBuffer().PrintText(17); ConsoleBuffer.ObteBuffer().SmallMap(); ConsoleBuffer.ObteBuffer().PrintScreen(); } while (!textInput.Equals("exit") && !pl.IsDead()); }
public static void StartLevel(int cantidad) { actualRooms = new List <Room>(); List <Vector2> actualVectors; if (Program.ObteJuego().level > 5) { double prob = CustomMath.RandomUnit(); if (prob < 95d / 300d) { actualVectors = GenerateLevelVersion2(cantidad); } else if (prob < 190d / 300d) { actualVectors = GenerateLevel(cantidad); } else if (prob < 285d / 300d) { actualVectors = GenerateLevelVersion3(cantidad); } else { actualVectors = GenerateLevelVersion4(cantidad); } } else { actualVectors = GenerateLevel(cantidad); } for (int i = 0; i < actualVectors.Count; i++) { actualRooms.Add(new Room(actualVectors[i].x, actualVectors[i].y)); } //First Room is visible actualRooms[0].SetVisible(2); //SET DOORS for (int i = 0; i < actualRooms.Count; i++) { if (!(actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null)) { for (int j = i + 1; j < actualRooms.Count; j++) { if (actualRooms[i].GetNorthRoom() == null) { if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() + 1 == actualRooms[j].GetPosY()) { actualRooms[i].SetNorth(actualRooms[j]); actualRooms[j].SetSouth(actualRooms[i]); } } if (actualRooms[i].GetWestRoom() == null) { if (actualRooms[i].GetPosX() - 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY()) { actualRooms[i].SetWest(actualRooms[j]); actualRooms[j].SetEast(actualRooms[i]); } } if (actualRooms[i].GetSouthRoom() == null) { if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() - 1 == actualRooms[j].GetPosY()) { actualRooms[i].SetSouth(actualRooms[j]); actualRooms[j].SetNorth(actualRooms[i]); } } if (actualRooms[i].GetEastRoom() == null) { if (actualRooms[i].GetPosX() + 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY()) { actualRooms[i].SetEast(actualRooms[j]); actualRooms[j].SetWest(actualRooms[i]); } } if (actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null) { j = actualRooms.Count; } } } } /*--------------------------------------Crear salas especiales------------------------------------------*/ List <Room> exitRooms = new List <Room>(); /*se usa para la cantidad de puertas que debe tener una sala*/ int temp = 3; do { for (int i = 1; i < actualRooms.Count; i++) { int noDoors = 0; if (actualRooms[i].GetEastRoom() == null) { noDoors++; } if (actualRooms[i].GetWestRoom() == null) { noDoors++; } if (actualRooms[i].GetNorthRoom() == null) { noDoors++; } if (actualRooms[i].GetSouthRoom() == null) { noDoors++; } if (noDoors == temp) { /*solo habitaciones con 3 salidas*/ exitRooms.Add(actualRooms[i]); } } if (exitRooms.Count == 0) { temp--; } } while (exitRooms.Count == 0); /*Salida_____________*/ int num = CustomMath.RandomIntNumber(exitRooms.Count - 1); Room exit = exitRooms[num]; exitRooms.RemoveAt(num);//Elimina la sala de las posibilidades de salida RoomExit texit = new RoomExit(exit.GetPosX(), exit.GetPosY()); texit.SetEast(exit.GetEastRoom()); texit.SetWest(exit.GetWestRoom()); texit.SetNorth(exit.GetNorthRoom()); texit.SetSouth(exit.GetSouthRoom()); if (texit.GetNorthRoom() != null) { texit.GetNorthRoom().SetSouth(texit); } if (texit.GetSouthRoom() != null) { texit.GetSouthRoom().SetNorth(texit); } if (texit.GetWestRoom() != null) { texit.GetWestRoom().SetEast(texit); } if (texit.GetEastRoom() != null) { texit.GetEastRoom().SetWest(texit); } actualRooms.Remove(exit); actualRooms.Add(texit); /*Habitacion cerrada__________*/ bool existsClosedRoom = false; if (temp == 3 && CustomMath.RandomUnit() < (Program.ObteJuego().level - 1) / 3f && exitRooms.Count > 0) { existsClosedRoom = true; num = CustomMath.RandomIntNumber(exitRooms.Count - 1); //num se esta reutilizando de salida Room tempRoom = exitRooms[num]; exitRooms.RemoveAt(num); //Elimina la sala cerrada de las posibilidades Room newRoom; newRoom = new RoomClosed(tempRoom.GetPosX(), tempRoom.GetPosY()); newRoom.SetEast(tempRoom.GetEastRoom()); newRoom.SetWest(tempRoom.GetWestRoom()); newRoom.SetNorth(tempRoom.GetNorthRoom()); newRoom.SetSouth(tempRoom.GetSouthRoom()); if (newRoom.GetNorthRoom() != null) { newRoom.GetNorthRoom().SetSouth(newRoom); } if (newRoom.GetSouthRoom() != null) { newRoom.GetSouthRoom().SetNorth(newRoom); } if (newRoom.GetWestRoom() != null) { newRoom.GetWestRoom().SetEast(newRoom); } if (newRoom.GetEastRoom() != null) { newRoom.GetEastRoom().SetWest(newRoom); } actualRooms.Remove(tempRoom); actualRooms.Add(newRoom); } /*Tesoro____________*/ int limit = (Program.ObteJuego().level > 5)? 3 : (Program.ObteJuego().level + 1) / 2; RoomTreasure treasure = null; while (limit > 0) { num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);//num se esta reutilizando de salida if (actualRooms[num].GetType() == typeof(Room)) { Room r = actualRooms[num]; treasure = new RoomTreasure(r.GetPosX(), r.GetPosY()); treasure.SetEast(r.GetEastRoom()); treasure.SetWest(r.GetWestRoom()); treasure.SetNorth(r.GetNorthRoom()); treasure.SetSouth(r.GetSouthRoom()); if (treasure.GetNorthRoom() != null) { treasure.GetNorthRoom().SetSouth(treasure); } if (treasure.GetSouthRoom() != null) { treasure.GetSouthRoom().SetNorth(treasure); } if (treasure.GetWestRoom() != null) { treasure.GetWestRoom().SetEast(treasure); } if (treasure.GetEastRoom() != null) { treasure.GetEastRoom().SetWest(treasure); } actualRooms.Remove(r); actualRooms.Add(treasure); limit--; } } if (CustomMath.RandomUnit() < 0.5) { RoomBless bless; Room r; do { r = actualRooms[CustomMath.RandomIntNumber(actualRooms.Count - 1, 1)]; } while (r.GetType() != typeof(Room)); bless = new RoomBless(r.GetPosX(), r.GetPosY()); bless.SetEast(r.GetEastRoom()); bless.SetWest(r.GetWestRoom()); bless.SetNorth(r.GetNorthRoom()); bless.SetSouth(r.GetSouthRoom()); if (bless.GetNorthRoom() != null) { bless.GetNorthRoom().SetSouth(bless); } if (bless.GetSouthRoom() != null) { bless.GetSouthRoom().SetNorth(bless); } if (bless.GetWestRoom() != null) { bless.GetWestRoom().SetEast(bless); } if (bless.GetEastRoom() != null) { bless.GetEastRoom().SetWest(bless); } actualRooms.Remove(r); actualRooms.Add(bless); } /*Miscelaneous*/ if (existsClosedRoom) { bool control = true; do { num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1); if (actualRooms[num].GetType() == typeof(Room)) { actualRooms[num].GetItem(new Item("Llave vieja")); control = false; } } while (control); } }