private void GetAttacked() { Random rnd = new Random(); bool isCritical = rnd.Next(1, 1001) < EnemyCriticalChance * 10; int dmgDealt = 0; if (isCritical) { if (EnemyDMGMatter == DMGMatter.Strength) { dmgDealt = (int)Math.Round(EnemyStrength / SelfDMGTaken * EnemyDMGDealt * 1.5); SelfCurrentHealth -= dmgDealt; } else { dmgDealt = (int)Math.Round((double)EnemyMana / SelfDMGTaken * EnemyDMGDealt * 1.5); SelfCurrentHealth -= dmgDealt; } } else { if (EnemyDMGMatter == DMGMatter.Strength) { dmgDealt = (int)Math.Round(EnemyStrength / SelfDMGTaken * EnemyDMGDealt); SelfCurrentHealth -= dmgDealt; } else { dmgDealt = (int)Math.Round((double)EnemyMana / SelfDMGTaken * EnemyDMGDealt); SelfCurrentHealth -= dmgDealt; } } string enemyType = Convert.ToString(EnemyType); string selfType = Convert.ToString(SelfType); if (EnemyRevealed) { if (SelfRevealed) { string log = ActionMessage(EnemyName, SelfName, dmgDealt); BattleStrings.Add(new BattleString(log + "\n\n")); Console.WriteLine(log); } else { string log = ActionMessage(EnemyName, selfType, dmgDealt); BattleStrings.Add(new BattleString(log + "\n\n")); Console.WriteLine(log); } } else { if (EnemyRevealed) { string log = ActionMessage(enemyType, SelfName, dmgDealt); BattleStrings.Add(new BattleString(log + "\n\n")); Console.WriteLine(log); } else { string log = ActionMessage(enemyType, selfType, dmgDealt); BattleStrings.Add(new BattleString(log + "\n\n")); Console.WriteLine(log); } } }
public void Start() { while (SelfCurrentHealth > 0 && EnemyCurrentHealth > 0) { bool hintTaken = false; bool playerStarts = SelfAgility >= EnemyAgility; if (playerStarts) { bool choosingMove = true; while (choosingMove) { Console.WriteLine("\n\nClick anything to continue."); Console.ReadKey(true); Console.Clear(); if (hintTaken && !EnemyRevealed) { Console.WriteLine(EnemyHint + "\n"); } Console.WriteLine($"Player - {SelfCurrentHealth}/{SelfMaxHealth} || Enemy - {EnemyCurrentHealth}/{EnemyMaxHealth}"); Console.WriteLine("Choose number:\n\n1. Attack\n\n2. Noble Phantasm\n\n3. hint (wont take away turn)\n\n4. Guess name\n\n5. Quit\n\n"); string choice = Console.ReadLine(); if (choice == "1") { Attack(); choosingMove = false; } else if (choice == "2") { if (SelfNPPoint == 6) { Console.Clear(); SelfNP.SelfAwaken(this); choosingMove = false; SelfNPPoint = 0; BattleStrings.Add(new BattleString($"{Player.Name} have awakened noble phantasm\n\n")); } else { Console.Clear(); Console.WriteLine($"Servant have not enough NP point to awaken noble phantasm (current -> {SelfNPPoint} || needed -> 6)"); } } else if (choice == "3") { hintTaken = true; } else if (choice == "4") { if (!EnemyRevealed) { Console.Clear(); Console.Write("Whats enemy name? -> "); string answer = Console.ReadLine().Trim().ToLower(); bool isCorrect = NameCheck(answer); if (isCorrect && IsServant) { Console.WriteLine($"Correct, enemy name is {answer}, they have been weakened"); EnemyStrength = (int)Math.Round(EnemyStrength * 0.5); EnemyMana = (int)Math.Round(EnemyMana * 0.6); EnemyRevealed = true; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have revealed enemy name\n\n")); } else if (isCorrect) { Console.WriteLine($"Correct, enemy name is {answer}, they have been weakened"); EnemyStrength = (int)Math.Round(EnemyStrength * 0.5); EnemyRevealed = true; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have revealed enemy name\n\n")); } else { Console.WriteLine($"{answer} is not right name."); choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have tried to reveal enemy name, but failed...\n\n")); } } else { Console.WriteLine("You already know enemy name."); } } else if (choice == "5") { SelfCurrentHealth = 0; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} did give up... what a shame heh")); } else { Console.WriteLine("Invalid choice."); } } if (EnemyCurrentHealth > 0) { Console.WriteLine("\n\nClick anything to continue."); Console.ReadKey(true); Console.Clear(); if (IsServant) { if (EnemyNPPoint == 6) { EnemyNP.EnemyAwaken(this); EnemyNPPoint = 0; BattleStrings.Add(new BattleString("Enemy awakened noble phantasm.\n\n")); } else { GetAttacked(); } } else { GetAttacked(); } } } else { Console.WriteLine("\n\nClick anything to continue."); Console.ReadKey(true); Console.Clear(); if (IsServant) { if (EnemyNPPoint == 6) { EnemyNP.EnemyAwaken(this); EnemyNPPoint = 0; BattleStrings.Add(new BattleString("Enemy have awakened noble phantasm.\n\n")); } else { GetAttacked(); } } else { GetAttacked(); } bool choosingMove = true; if (SelfCurrentHealth > 0) { while (choosingMove) { Console.WriteLine("\n\nClick anything to continue."); Console.ReadKey(true); Console.Clear(); if (hintTaken && !EnemyRevealed) { Console.WriteLine(EnemyHint + "\n"); } Console.WriteLine($"Player - {SelfCurrentHealth}/{SelfMaxHealth} || Enemy - {EnemyCurrentHealth}/{EnemyMaxHealth}"); Console.WriteLine("Choose number:\n\n1. Attack\n\n2. Noble Phantasm\n\n3. hint (wont take away turn)\n\n4. Guess name\n\n5. Quit\n\n"); string choice = Console.ReadLine(); if (choice == "1") { Attack(); choosingMove = false; } else if (choice == "2") { if (SelfNPPoint == 6) { Console.Clear(); SelfNP.SelfAwaken(this); choosingMove = false; SelfNPPoint = 0; BattleStrings.Add(new BattleString($"{Player.Name} have awakened noble phantasm\n\n")); } else { Console.Clear(); Console.WriteLine($"Servant have not enough NP point to awaken noble phantasm (current -> {SelfNPPoint} || needed -> 6)"); } } else if (choice == "3") { hintTaken = true; } else if (choice == "4") { if (!EnemyRevealed) { Console.Clear(); Console.Write("Whats enemy name? -> "); string answer = Console.ReadLine().Trim().ToLower(); bool isCorrect = NameCheck(answer); if (IsServant) { if (isCorrect) { Console.WriteLine($"Correct, enemy name is {answer}, they have been weakened"); EnemyStrength = (int)Math.Round(EnemyStrength * 0.5); EnemyMana = (int)Math.Round((double)EnemyMana * 0.6); EnemyRevealed = true; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have revealed enemy name\n\n")); } else { Console.WriteLine($"{answer} is not right name."); choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have tried to reveal enemy name, but failed...\n\n")); } } else { if (isCorrect) { Console.WriteLine($"Correct, enemy name is {answer}, they have been weakened"); EnemyStrength = (int)Math.Round(EnemyStrength * 0.5); EnemyRevealed = true; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have revealed enemy name\n\n")); } else { Console.WriteLine($"{answer} is not right name."); choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} have tried to reveal enemy name, but failed...\n\n")); } } } else { Console.WriteLine("You already know enemy name."); } } else if (choice == "5") { SelfCurrentHealth = 0; choosingMove = false; BattleStrings.Add(new BattleString($"{Player.Name} did give up... what a shame heh")); } else { Console.WriteLine("Invalid choice."); } } } } if (SelfNPPoint != 6) { SelfNPPoint++; } EnemyNPPoint++; } if (SelfCurrentHealth <= 0) { BattleStrings.Add(new BattleString($"{Player.Name}'s servant is dead, you lost! Gaining {LoseExp} experience.")); Console.WriteLine($"You have lost, gaining {LoseExp} exp for master as reward"); Player.GetExp(LoseExp); Name = Name = $"{Player.Name}\n\nLevel {Player.UsingChar.Level} - {SelfName} VS Level {EnemyLevel} - {EnemyName} LOST"; Player.RemoveUsingChar(); } else { BattleStrings.Add(new BattleString($"{Player.Name} have won! Gaining {WinExp} experience.")); Name = Name = $"{Player.Name}\n\nLevel {Player.UsingChar.Level} - {SelfName} VS Level {EnemyLevel} - {EnemyName} Won"; Console.WriteLine($"You have won, gaining {WinExp} exp for master and servant as reward"); Player.UsingChar.GainExp(WinExp); Player.GetExp(WinExp); if (SelfCurrentHealth > Player.UsingChar.Health) { Player.UsingChar.CurrentHealth = Player.UsingChar.Health; } else { Player.UsingChar.CurrentHealth = SelfCurrentHealth; } if (Program.MustSave) { using (var context = new DataContext()) { Character character = context.Character.Where(e => e.Id == Player.UsingChar.Id).Single(); character.CurrentHealth = Player.UsingChar.CurrentHealth; context.SaveChanges(); }; } } Console.Clear(); BattleLog(); _battles.Add(this); Player.Battles.Add(this); if (Program.MustSave) { using (var context = new DataContext()) { context.Attach <Player>(Player); context.SaveChanges(); }; } }