aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/cpp/Actor.cpp27
-rw-r--r--src/main/cpp/MeleeWeapon.cpp51
-rw-r--r--src/main/cpp/RangedWeapon.cpp24
3 files changed, 75 insertions, 27 deletions
diff --git a/src/main/cpp/Actor.cpp b/src/main/cpp/Actor.cpp
index a6dc597..08911c5 100644
--- a/src/main/cpp/Actor.cpp
+++ b/src/main/cpp/Actor.cpp
@@ -25,3 +25,30 @@ void Actor::heal(int amt)
_hp = maxHp;
}
}
+
+void Actor::store(Item &item)
+{
+ // TODO check if item is already in inventory
+ _inventory.push_front(&item);
+}
+
+Item* Actor::drop()
+{
+ // TODO
+ Item *item = _inventory.front();
+ _inventory.pop_front();
+
+ return item;
+}
+
+unsigned Actor::stat(Actor::Stat stat) const
+{
+ return _stats.at(stat);
+}
+
+unsigned Actor::skill(Actor::Skill skill) const
+{
+ // TODO
+ // return _skills.at(skill);
+ return 0;
+}
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;
}
diff --git a/src/main/cpp/RangedWeapon.cpp b/src/main/cpp/RangedWeapon.cpp
index 6f24666..13d4c70 100644
--- a/src/main/cpp/RangedWeapon.cpp
+++ b/src/main/cpp/RangedWeapon.cpp
@@ -2,8 +2,8 @@
#include "Actor.hpp"
#include "Bullet.hpp"
-RangedWeapon::RangedWeapon(const std::string &name)
-: Weapon(Item::Type::RANGEDWEAPON, name)
+RangedWeapon::RangedWeapon(Weapon::Class c, const std::string &name)
+: Weapon(Item::Type::RANGEDWEAPON, c, name)
{
}
@@ -11,7 +11,11 @@ bool RangedWeapon::use(Actor &user, Actor &actor)
{
//TODO implement attack probability
if (_charged) {
- actor.damage(user.attack() + _damage - actor.defence());
+ actor.damage(user.stat(Actor::Stat::ATTACK)
+ + _damage
+ - actor.stat(Actor::Stat::DEFENCE)
+ );
+
_charged = false;
}
@@ -20,26 +24,26 @@ bool RangedWeapon::use(Actor &user, Actor &actor)
bool RangedWeapon::reload(Actor &actor)
{
+ Bullet *bullet = nullptr;
+
//TODO add bullet type
std::list<Item*> inventory = actor.inventory();
for (Item *item : inventory) {
if (item->type == Item::Type::BULLET) {
//TODO get the bullet
- // Bullet *bullet = dynamic_cast <Bullet*> (item);
+ bullet = dynamic_cast<Bullet*>(item);
break;
}
}
- // TODO remove
- return true;
+ if (bullet == nullptr) {
+ return false;
+ }
- /*
if (bullet->decreaseAmount(1)) {
_charged = true;
return true;
- } else {
- return false;
}
- */
+ return false;
}