diff options
Diffstat (limited to 'src/main/cpp/MeleeWeapon.cpp')
-rw-r--r-- | src/main/cpp/MeleeWeapon.cpp | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/src/main/cpp/MeleeWeapon.cpp b/src/main/cpp/MeleeWeapon.cpp index 92c7632..8c7ffce 100644 --- a/src/main/cpp/MeleeWeapon.cpp +++ b/src/main/cpp/MeleeWeapon.cpp @@ -1,15 +1,71 @@ +#include "Weapon.hpp" #include "MeleeWeapon.hpp" #include "Actor.hpp" #include <string> -MeleeWeapon::MeleeWeapon(Type t, const std::string &name) -: Weapon(name), type(t) +MeleeWeapon::MeleeWeapon(Type t, const std::string &name, bool throwable) +: Weapon(Item::Type::MELEEWEAPON, name), type(t), _throwable(throwable) { } bool MeleeWeapon::use(Actor &user, Actor &actor) { - //TODO implement attack probability - //actor.damage(_damage); + //TODO implements attack probability + //TODO balance advantages + MeleeWeapon* weapon = dynamic_cast <MeleeWeapon*> (user.weapon()); + int bonus; + + if (MeleeWeapon* enemyWeapon = dynamic_cast <MeleeWeapon*> (actor.weapon())) { + switch (weapon->type) { + case MeleeWeapon::Type::AXE: + switch (enemyWeapon->type) { + case MeleeWeapon::Type::AXE: + bonus = 0; + break; + case MeleeWeapon::Type::LANCE: + bonus = 10; + break; + case MeleeWeapon::Type::SWORD: + bonus = -10; + break; + } + break; + case MeleeWeapon::Type::LANCE: + switch (enemyWeapon->type) { + case MeleeWeapon::Type::AXE: + bonus = -10; + break; + case MeleeWeapon::Type::LANCE: + bonus = 0; + break; + case MeleeWeapon::Type::SWORD: + bonus = 10; + break; + } + break; + case MeleeWeapon::Type::SWORD: + switch (enemyWeapon->type) { + case MeleeWeapon::Type::AXE: + bonus = 10; + break; + case MeleeWeapon::Type::LANCE: + bonus = -10; + break; + case MeleeWeapon::Type::SWORD: + bonus = 0; + break; + } + break; + } + } else { + bonus = 0; + } + + if (actor.levelAxe() <= _requiredLevel) { + actor.damage(_damage + user.attack() - actor.defence() + bonus); + return true; + } else { + return false; + } } |