aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/MeleeWeapon.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/cpp/MeleeWeapon.cpp51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/main/cpp/MeleeWeapon.cpp b/src/main/cpp/MeleeWeapon.cpp
index 5dd0c0d..c2bb446 100644
--- a/src/main/cpp/MeleeWeapon.cpp
+++ b/src/main/cpp/MeleeWeapon.cpp
@@ -3,23 +3,41 @@
#include "Actor.hpp"
#include <string>
+#include <stdexcept>
-MeleeWeapon::MeleeWeapon(Type t, const std::string &name, bool throwable)
- : Weapon(Item::Type::MELEEWEAPON, name), type(t), _throwable(throwable)
+MeleeWeapon::MeleeWeapon(Weapon::Class weaponClass, const std::string &name, bool throwable)
+ : Weapon(Item::Type::MELEEWEAPON, weaponClass, name), _throwable(throwable)
{
+ if (!(weaponClass == Weapon::Class::SWORD
+ || weaponClass == Weapon::Class::AXE
+ || weaponClass == Weapon::Class::LANCE)) {
+
+ throw std::invalid_argument("Invalid class type for MeleeWeapon");
+ }
}
bool MeleeWeapon::use(Actor &user, Actor &actor)
{
//TODO implements attack probability
//TODO balance advantages
- MeleeWeapon* weapon = dynamic_cast <MeleeWeapon*> (user.weapon());
- int bonus;
+
+ int bonus = 0;
+ MeleeWeapon *userWeapon = dynamic_cast<MeleeWeapon*>(user.weapon());
+ // MeleeWeapon *actorWeapon = dynamic_cast<MeleeWeapon*>(actor.weapon());
+
+ if (userWeapon == nullptr) {
+ return false;
+ }
- if (MeleeWeapon* enemyWeapon = dynamic_cast <MeleeWeapon*> (actor.weapon())) {
- switch (weapon->type) {
+ // if (user.skill(userWeapon->weaponClass) <= _requiredLevel) {
+ // return false;
+ // }
+
+ /*
+ if (actorWeapon != nullptr) {
+ switch (userWeapon->weaponType) {
case MeleeWeapon::Type::AXE:
- switch (enemyWeapon->type) {
+ switch (actorWeapon->weaponType) {
case MeleeWeapon::Type::AXE:
bonus = 0;
break;
@@ -32,7 +50,7 @@ bool MeleeWeapon::use(Actor &user, Actor &actor)
}
break;
case MeleeWeapon::Type::LANCE:
- switch (enemyWeapon->type) {
+ switch (actorWeapon->weaponType) {
case MeleeWeapon::Type::AXE:
bonus = -10;
break;
@@ -45,7 +63,7 @@ bool MeleeWeapon::use(Actor &user, Actor &actor)
}
break;
case MeleeWeapon::Type::SWORD:
- switch (enemyWeapon->type) {
+ switch (actorWeapon->weaponType) {
case MeleeWeapon::Type::AXE:
bonus = 10;
break;
@@ -58,14 +76,13 @@ bool MeleeWeapon::use(Actor &user, Actor &actor)
}
break;
}
- } else {
- bonus = 0;
}
+ */
- if (actor.levelAxe() <= _requiredLevel) {
- actor.damage(_damage + user.attack() - actor.defence() + bonus);
- return true;
- } else {
- return false;
- }
+ actor.damage(_damage
+ + user.stat(Actor::Stat::ATTACK)
+ - actor.stat(Actor::Stat::DEFENCE) + bonus
+ );
+
+ return true;
}