warrior.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "units/warrior.h"
  2. #include "units/unit.h"
  3. #include <cassert>
  4. Warrior::Warrior(QString parameters) : Unit(parameters)
  5. {
  6. }
  7. int Warrior::reduceIncomingDamage(std::string damageType, int damage) { //returns damage after reducing by defence
  8. assert("Incorrect damage type in call reduceIncomingDamage(), expected" &&
  9. (damageType[0] == 'p' || damageType[0] == 'P' || damageType[0] == 'm' || damageType[0] == 'M'));
  10. assert("Magic defence of unit is incorrectly high (>40), but must be" && magic_defence_ <= 40);
  11. assert("Physic defence of unit is incorrectly high (>40), but must be" && physic_defence_ <= 40);
  12. int near_same = this->theSameNear();
  13. int active_defence;
  14. if (damageType[0] == 'p' || damageType[0] == 'P') {
  15. active_defence = physic_defence_;
  16. }
  17. else if (damageType[0] == 'm' || damageType[0] == 'M') {
  18. active_defence = magic_defence_;
  19. }
  20. //return (damage - 2.5 * damage * active_defence / 100);
  21. int reduced_damage;
  22. switch (near_same) {
  23. case 0:
  24. reduced_damage = damage - 2.5 * double(damage) * double(active_defence) / 100.0;
  25. break;
  26. case 1:
  27. reduced_damage = damage - 2.9 * double(damage) * double(active_defence) / 100.0;
  28. break;
  29. case 2:
  30. reduced_damage = damage - 3.3 * double(damage) * double(active_defence) / 100.0;
  31. break;
  32. case 3:
  33. reduced_damage = damage - 3.7 * double(damage) * double(active_defence) / 100.0;
  34. break;
  35. default:
  36. reduced_damage = damage - 4.1 * double(damage) * double(active_defence) / 100.0;
  37. break;
  38. }
  39. return reduced_damage;
  40. }