Warrior.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. } else {
  20. // THIS PART SHOULD BE UNREACHABLE
  21. active_defence = physic_defence_;
  22. }
  23. //return (damage - 2.5 * damage * active_defence / 100);
  24. int reduced_damage;
  25. switch (near_same) {
  26. case 0:
  27. reduced_damage = damage - 2.5 * double(damage) * double(active_defence) / 100.0;
  28. break;
  29. case 1:
  30. reduced_damage = damage - 2.9 * double(damage) * double(active_defence) / 100.0;
  31. break;
  32. case 2:
  33. reduced_damage = damage - 3.3 * double(damage) * double(active_defence) / 100.0;
  34. break;
  35. case 3:
  36. reduced_damage = damage - 3.7 * double(damage) * double(active_defence) / 100.0;
  37. break;
  38. default:
  39. reduced_damage = damage - 4.1 * double(damage) * double(active_defence) / 100.0;
  40. break;
  41. }
  42. return reduced_damage;
  43. }