From 20b958c69451dd8251a8899cf7264d5c92ed7c60 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 25 Feb 2018 21:11:43 +0100 Subject: Better management of stats and skill of actors and items --- src/main/cpp/MeleeWeapon.cpp | 51 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'src/main/cpp/MeleeWeapon.cpp') 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 +#include -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 (user.weapon()); - int bonus; + + int bonus = 0; + MeleeWeapon *userWeapon = dynamic_cast(user.weapon()); + // MeleeWeapon *actorWeapon = dynamic_cast(actor.weapon()); + + if (userWeapon == nullptr) { + return false; + } - if (MeleeWeapon* enemyWeapon = dynamic_cast (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; } -- cgit v1.2.1