aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/MeleeWeapon.cpp
diff options
context:
space:
mode:
authormafaldo <mafaldo@heavyhammer.home>2018-02-17 00:29:32 +0100
committermafaldo <mafaldo@heavyhammer.home>2018-02-17 00:29:32 +0100
commitaf3e76c5ee367ceffb78fa4a8ffc0eadf90e5de3 (patch)
tree24dcdaa94c20211974fca97e41647ff0dec31923 /src/main/cpp/MeleeWeapon.cpp
parentAdd cpack directive and update README (diff)
downloadSubconscious-old-af3e76c5ee367ceffb78fa4a8ffc0eadf90e5de3.tar.gz
Subconscious-old-af3e76c5ee367ceffb78fa4a8ffc0eadf90e5de3.zip
add Item type, use for MeleeWeapon
Diffstat (limited to 'src/main/cpp/MeleeWeapon.cpp')
-rw-r--r--src/main/cpp/MeleeWeapon.cpp64
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;
+ }
}