private void MoveDown() { if (SelectedCombatant.TieBreaker != Combatants.Count - 1) { var nextCombatant = Combatants.FirstOrDefault(c => c.TieBreaker == SelectedCombatant.TieBreaker + 1); nextCombatant.TieBreaker--; SelectedCombatant.TieBreaker++; } Combatants.Sort(); }
private void MoveUp() { if (SelectedCombatant.TieBreaker != 0) { var previousCombatant = Combatants.FirstOrDefault(c => c.TieBreaker == SelectedCombatant.TieBreaker - 1); previousCombatant.TieBreaker++; SelectedCombatant.TieBreaker--; } Combatants.Sort(); }
} // EndTurn() public static void VerifyStatus(int targetId, ApplicationDbContext ctx) { Creature target = Combatants.FirstOrDefault(x => x.Id == targetId); if (target.HitPoints < 1) { target.Alive = false; if (target.HitPoints < 0) { target.HitPoints = 0; } AddToLog(new string($"W skutek odniesionych ran {target.Name} pada martwy.")); } if (Hero.Alive == false) { AddToLog(new string($"To koniec podróży. Oczy {Hero.Name} już na zawsze pozostaną zamknięte. Inni zostaną wysłani, ale czy ktokolwiek odniesie sukces?")); GameplayManager.Phase = Enumerators.GamePhase.CharacterCreation; GameplayManager.Step = 0; Status = false; } else { deadCount = 0; foreach (var creature in Enemies) { if (creature.Alive == false) { deadCount++; } } if (Enemies.Count == deadCount) { int experience = 0; foreach (var creature in Enemies) { experience += creature.Experience; } Hero.Experience += experience; AddToLog(new string($"{Hero.Name} rozgromił wszystkich przeciwników, których resztki leżą rozrzucone na ziemii. Walka skończona.")); AddToLog(new string($"{Hero.Name} Zyskuje {experience} punktów doświadczenia.")); CheckLevel(ctx); } } } // VerifyStatus()
private void Previous() { Combatant activeCombatant = Combatants.FirstOrDefault(c => c.IsActive); activeCombatant.IsActive = false; int index = Combatants.IndexOf(activeCombatant); if (index == 0) { index = Combatants.Count - 1; } else { index--; } Combatants[index].IsActive = true; }
private void Next() { Combatant activeCombatant = Combatants.FirstOrDefault(c => c.IsActive); activeCombatant.IsActive = false; int index = Combatants.IndexOf(activeCombatant); if (index == Combatants.Count - 1) { index = 0; } else { index++; } Combatants[index].IsActive = true; }
} // AddToLog() public static void Attack(int attackerId, int attackType, int targetId, ApplicationDbContext ctx) { //attackType 0 - fast, 1 - normal, 2 - strong int chanceLevel = 0; bool HitSucces = false; Creature attacker = Combatants.FirstOrDefault(x => x.Id == attackerId); if (random.Next(1, 100) == 50) { targetId = attackerId; AddToLog(new string($"{attacker.Name} chybia cel raniąc siebie.")); } // fail - 1% chance, the attacker hitting itself Creature target = Combatants.FirstOrDefault(x => x.Id == targetId); if (attackType == 0) { attacker.ActionPoints -= (attacker.Weapon.ActionCost - 1); } else if (attackType == 1) { attacker.ActionPoints -= attacker.Weapon.ActionCost; } else { attacker.ActionPoints -= (attacker.Weapon.ActionCost + 1); } #region Hit chance if (targetId != attackerId) { if (attackType == 0) { chanceLevel = attacker.Weapon.HitChance + 10 + attacker.Agility - target.Agility; // +10 as fast attack is more likely to hit } else if (attackType == 1) { chanceLevel = attacker.Weapon.HitChance + attacker.Agility - target.Agility; } else { chanceLevel = attacker.Weapon.HitChance - 10 + attacker.Agility - target.Agility; // -10 as strong attack is less likely to hit } int calculateHit = random.Next(0, 100); if (calculateHit <= chanceLevel) { HitSucces = true; } else { HitSucces = false; AddToLog($"{attacker.Name} chybia."); } } else { HitSucces = true; } #endregion #region HitSucces true if (HitSucces == true) { double attackPower = (double)attacker.Weapon.BaseDamage; double attackMagicPower = (double)attacker.Weapon.MagicDamage; double criticalSuccess = 1; if (random.Next(1, 100) == 50) { criticalSuccess = 2; } // 1% chance to deal double damage if (attackType == 0) { if (attacker.Strength >= 4) { attackPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (0.8 - 0.65) + 0.65); attackMagicPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (0.8 - 0.65) + 0.65); } else { attackPower *= 2 * random.NextDouble() * (0.8 - 0.65) + 0.65; attackMagicPower *= 2 * random.NextDouble() * (0.8 - 0.65) + 0.65; } } else if (attackType == 1) { if (attacker.Strength >= 4) { attackPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (1.1 - 0.9) + 0.9); attackMagicPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (1.1 - 0.9) + 0.9); } else { attackPower *= 2 * random.NextDouble() * (1.1 - 0.9) + 0.9; attackMagicPower *= 2 * random.NextDouble() * (1.1 - 0.9) + 0.9; } } else { if (attacker.Strength >= 4) { attackPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (1.35 - 1.2) + 1.2); attackMagicPower *= (double)attacker.Strength / 4 * (random.NextDouble() * (1.35 - 1.2) + 1.2); } else { attackPower *= 2 * random.NextDouble() * (1.35 - 1.2) + 1.2; attackMagicPower *= 2 * random.NextDouble() * (1.35 - 1.2) + 1.2; } } double damage = (attackPower * (100 / (100 + (double)target.DamageResistance)) - attackPower / 2) * criticalSuccess; double MDamage = (attackMagicPower * (100 / (100 + (double)target.MagicResistance)) - attackPower / 2) * criticalSuccess; int realDMG = (int)Math.Round(damage); int realMDMG = (int)Math.Round(MDamage); if (criticalSuccess == 2) { AddToLog(new string($"Cios jaki wyprowadza {attacker.Name} uderza ze zdwojoną siłą.")); } if (realDMG > 0 && realMDMG > 0) { target.HitPoints -= realDMG; target.HitPoints -= realMDMG; AddToLog(new string($"{attacker.Name} trafia {target.Name} zadając {realDMG} fizycznych i {realMDMG} magicznych puntków obrażeń.")); } else if (realDMG > 0) { target.HitPoints -= realDMG; AddToLog(new string($"{attacker.Name} trafia {target.Name} zadając {realDMG} puntków obrażeń.")); } else if (realMDMG > 0) { target.HitPoints -= realMDMG; AddToLog(new string($"{attacker.Name} trafia {target.Name} zadając {realMDMG} magicznych puntków obrażeń.")); } VerifyStatus(targetId, ctx); } // HitSucces true #endregion } // Attack()