From af3e76c5ee367ceffb78fa4a8ffc0eadf90e5de3 Mon Sep 17 00:00:00 2001 From: mafaldo Date: Sat, 17 Feb 2018 00:29:32 +0100 Subject: add Item type, use for MeleeWeapon --- src/main/cpp/Bullet.cpp | 11 ++++++++ src/main/cpp/MeleeWeapon.cpp | 64 ++++++++++++++++++++++++++++++++++++++++--- src/main/cpp/RangedWeapon.cpp | 29 +++++++++++++++----- src/main/cpp/Stick.cpp | 11 ++++++++ 4 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 src/main/cpp/Bullet.cpp create mode 100644 src/main/cpp/Stick.cpp (limited to 'src/main/cpp') diff --git a/src/main/cpp/Bullet.cpp b/src/main/cpp/Bullet.cpp new file mode 100644 index 0000000..c856213 --- /dev/null +++ b/src/main/cpp/Bullet.cpp @@ -0,0 +1,11 @@ +#include "Bullet.hpp" + +bool Bullet::decreaseAmount(int qnt) +{ + if (_amount >= qnt) { + _amount = _amount - qnt; + return true; + } else { + return false; + } +} 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 -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 (user.weapon()); + int bonus; + + if (MeleeWeapon* enemyWeapon = dynamic_cast (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; + } } diff --git a/src/main/cpp/RangedWeapon.cpp b/src/main/cpp/RangedWeapon.cpp index eb33780..21feae4 100644 --- a/src/main/cpp/RangedWeapon.cpp +++ b/src/main/cpp/RangedWeapon.cpp @@ -1,12 +1,9 @@ #include "RangedWeapon.hpp" #include "Actor.hpp" - -#include -#include -#include +#include "Bullet.hpp" RangedWeapon::RangedWeapon(const std::string &name) -: Weapon(name) +: Weapon(Item::Type::RANGEDWEAPON, name) { } @@ -19,7 +16,25 @@ bool RangedWeapon::use(Actor &user, Actor &actor) } } -void RangedWeapon::reload(Actor &actor) +bool RangedWeapon::reload(Actor &actor) { - //std::vector bullet = actor.bullet(); + //TODO add bullet type + std::list inventory = actor.inventory(); + for (Item* item : inventory) { + if (item->type == Item::Type::BULLET) { + //TODO get the bullet + //Bullet* bullet = dynamic_cast (item); + break; + } + } + + /* + if (bullet->decreaseAmount(1)) { + _charged = true; + return true; + } else { + return false; + } + */ + } diff --git a/src/main/cpp/Stick.cpp b/src/main/cpp/Stick.cpp new file mode 100644 index 0000000..bc67ccb --- /dev/null +++ b/src/main/cpp/Stick.cpp @@ -0,0 +1,11 @@ +#include "Stick.hpp" + +Stick::Stick(const std::string &name, int maxUses) : Item(Item::Type::STICK, name), _maxUses(maxUses) +{ + _remainingUses = _maxUses; +} + +bool Stick::use(Actor &user, Actor &actor) +{ + +} -- cgit v1.2.1