diff options
author | Nao Pross <naopross@thearcway.org> | 2018-02-25 21:11:43 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-02-25 21:11:43 +0100 |
commit | 20b958c69451dd8251a8899cf7264d5c92ed7c60 (patch) | |
tree | 440ec68a189efdf42a21a9d621b6de2c04305fb5 /src | |
parent | Update CMakeLists and Makefile (diff) | |
download | Subconscious-old-20b958c69451dd8251a8899cf7264d5c92ed7c60.tar.gz Subconscious-old-20b958c69451dd8251a8899cf7264d5c92ed7c60.zip |
Better management of stats and skill of actors and items
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/Actor.cpp | 27 | ||||
-rw-r--r-- | src/main/cpp/MeleeWeapon.cpp | 51 | ||||
-rw-r--r-- | src/main/cpp/RangedWeapon.cpp | 24 | ||||
-rw-r--r-- | src/main/headers/Actor.hpp | 71 | ||||
-rw-r--r-- | src/main/headers/Bullet.hpp | 5 | ||||
-rw-r--r-- | src/main/headers/Item.hpp | 6 | ||||
-rw-r--r-- | src/main/headers/MeleeWeapon.hpp | 7 | ||||
-rw-r--r-- | src/main/headers/RangedWeapon.hpp | 2 | ||||
-rw-r--r-- | src/main/headers/Tile.hpp | 2 | ||||
-rw-r--r-- | src/main/headers/Weapon.hpp | 13 | ||||
-rw-r--r-- | src/main/headers/config.h | 2 | ||||
-rw-r--r-- | src/main/headers/config.h.in | 2 | ||||
-rw-r--r-- | src/main/resources/definitions.xml | 4 | ||||
-rw-r--r-- | src/main/resources/effects/effects_template.xml | 12 | ||||
-rw-r--r-- | src/main/resources/items/items_template.xml | 76 |
15 files changed, 173 insertions, 131 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; } diff --git a/src/main/headers/Actor.hpp b/src/main/headers/Actor.hpp index 1e160f6..6366f2e 100644 --- a/src/main/headers/Actor.hpp +++ b/src/main/headers/Actor.hpp @@ -1,14 +1,34 @@ #ifndef ACTOR_HPP #define ACTOR_HPP +#include "Weapon.hpp" + #include <list> #include <string> +#include <map> + -#include "Item.hpp" +class Item; class Actor { public: + enum class Stat + { + ATTACK, + DEFENCE, + MAGICATTACK, // magia + MAGICDEFENSE, // resistenza + PRECISION, + DODGE, + REACTION + }; + + enum class Skill + { + + }; + const std::string name; const unsigned maxHp; @@ -19,35 +39,19 @@ public: void heal(int amt); void store(Item &item); - Item& drop(); + Item* drop(); + + unsigned stat(Stat stat) const; + unsigned skill(Skill skill) const; /* accessors */ bool alive() const { return _alive; } unsigned hp() const { return _hp; } - unsigned attack() const { return _attack; } - unsigned defence() const { return _defence; } - - unsigned magicAttack() const { return _magicAttack; } - unsigned magicDefence() const { return _magicDefence; } - - unsigned precisionProbabiliy() const { return _precisionProbability; } - unsigned dodgeProbabiliy() const { return _dodgeProbability; } - - unsigned reactionSpeed() const { return _reactionSpeed; } - const std::list<Item*>& inventory() const { return _inventory; } - //TODO add weaponslot Item* weapon() const { return _weapon; } - unsigned levelAxe() const { return _levelAxe; } - unsigned levelLance() const { return _levelLance; } - unsigned levelSword() const { return _levelSword; } - unsigned levelRanged() const { return _levelRanged; } - unsigned levelStick() const { return _levelStick; } - unsigned levelMedicine() const { return _levelMedicine; } - int x() { return _x; } int y() { return _y; } @@ -59,31 +63,14 @@ protected: unsigned _movements; int _x, _y; - /* combat related */ - unsigned _attack; - unsigned _defence; - - unsigned _magicAttack; // nota come magia - unsigned _magicDefence; // nota come resistenza - - unsigned _precisionProbability; - unsigned _dodgeProbability; - unsigned _reactionSpeed; - - // unsigned _abilityProbability; - /* others */ + Item* _weapon; + unsigned _inventorySize; std::list<Item*> _inventory; - Item* _weapon; - - unsigned _levelAxe; - unsigned _levelLance; - unsigned _levelSword; - unsigned _levelRanged; - unsigned _levelStick; - unsigned _levelMedicine; + std::map<Stat, unsigned> _stats; + std::map<Weapon::Class, unsigned> _skills; Actor(std::string _name, unsigned _maxHp); }; diff --git a/src/main/headers/Bullet.hpp b/src/main/headers/Bullet.hpp index b12c614..db5cdff 100644 --- a/src/main/headers/Bullet.hpp +++ b/src/main/headers/Bullet.hpp @@ -2,12 +2,11 @@ #define BULLET_HPP #include "Item.hpp" -#include "RangedWeapon.hpp" -class Bullet : protected Item +class Bullet : public Item { public: - virtual bool use(RangedWeapon &weapon); + virtual bool use() { return false; } virtual bool decreaseAmount(unsigned qnt); }; diff --git a/src/main/headers/Item.hpp b/src/main/headers/Item.hpp index ce0c921..e338dbc 100644 --- a/src/main/headers/Item.hpp +++ b/src/main/headers/Item.hpp @@ -5,13 +5,11 @@ class Actor; -/* - * TODO description - */ class Item { public: - enum Type { + enum class Type + { BULLET, MELEEWEAPON, RANGEDWEAPON, STICK, HEAL, FOOD }; diff --git a/src/main/headers/MeleeWeapon.hpp b/src/main/headers/MeleeWeapon.hpp index 97a0930..e7917b8 100644 --- a/src/main/headers/MeleeWeapon.hpp +++ b/src/main/headers/MeleeWeapon.hpp @@ -10,13 +10,8 @@ class MeleeWeapon : public Weapon { public: - enum Type { - SWORD, AXE, LANCE - }; - const Type type; - - MeleeWeapon(Type t, const std::string &name, bool throwable); + MeleeWeapon(Weapon::Class weaponClass, const std::string &name, bool throwable); bool use(Actor &user, Actor &actor); protected: diff --git a/src/main/headers/RangedWeapon.hpp b/src/main/headers/RangedWeapon.hpp index e5b0b66..38e1750 100644 --- a/src/main/headers/RangedWeapon.hpp +++ b/src/main/headers/RangedWeapon.hpp @@ -9,7 +9,7 @@ class RangedWeapon : public Weapon { public: - RangedWeapon(const std::string &name); + RangedWeapon(Weapon::Class c, const std::string &name); bool use(Actor &user, Actor &actor); bool reload(Actor &actor); diff --git a/src/main/headers/Tile.hpp b/src/main/headers/Tile.hpp index 88e7216..0fc3105 100644 --- a/src/main/headers/Tile.hpp +++ b/src/main/headers/Tile.hpp @@ -5,7 +5,7 @@ struct Tile { - enum Type + enum class Type { GRASS, WATER }; diff --git a/src/main/headers/Weapon.hpp b/src/main/headers/Weapon.hpp index 40eb7a3..f59fe4d 100644 --- a/src/main/headers/Weapon.hpp +++ b/src/main/headers/Weapon.hpp @@ -2,17 +2,26 @@ #define WEAPON_HPP #include "Item.hpp" -#include "Actor.hpp" #include <string> +class Actor; + class Weapon : public Item { +public: + enum class Class + { + SWORD, AXE, LANCE, RANGED + }; + + const Class weaponClass; + protected: unsigned _damage; unsigned _requiredLevel; - Weapon(Item::Type t, const std::string &name) : Item(t, name) {} + Weapon(Item::Type t, Class _weaponClass, const std::string &name) : Item(t, name), weaponClass(_weaponClass) {} }; #endif diff --git a/src/main/headers/config.h b/src/main/headers/config.h index e69de29..091b36d 100644 --- a/src/main/headers/config.h +++ b/src/main/headers/config.h @@ -0,0 +1,2 @@ +#define subconscious_VERSION_MAJOR 0 +#define subconscious_VERSION_MINOR 1 diff --git a/src/main/headers/config.h.in b/src/main/headers/config.h.in index e69de29..03848b5 100644 --- a/src/main/headers/config.h.in +++ b/src/main/headers/config.h.in @@ -0,0 +1,2 @@ +#define subconscious_VERSION_MAJOR @subconscious_VERSION_MAJOR@ +#define subconscious_VERSION_MINOR @subconscious_VERSION_MINOR@ diff --git a/src/main/resources/definitions.xml b/src/main/resources/definitions.xml new file mode 100644 index 0000000..5157d99 --- /dev/null +++ b/src/main/resources/definitions.xml @@ -0,0 +1,4 @@ +<item> + <name></name> + <maxAmount></maxAmount> +</item> diff --git a/src/main/resources/effects/effects_template.xml b/src/main/resources/effects/effects_template.xml index fe577b0..3b74e3a 100644 --- a/src/main/resources/effects/effects_template.xml +++ b/src/main/resources/effects/effects_template.xml @@ -3,9 +3,9 @@ Available modifications: - speed - attackDamage --!> - -<effect modifies=""> - <name></name> - <value></value> -</effect> - +<effects> + <effect modifies=""> + <name></name> + <value></value> + </effect> +</effects> diff --git a/src/main/resources/items/items_template.xml b/src/main/resources/items/items_template.xml index 19c9264..afd3c72 100644 --- a/src/main/resources/items/items_template.xml +++ b/src/main/resources/items/items_template.xml @@ -5,55 +5,53 @@ Available item types: - medicine - food --> +<items> + <item type=""> + <name></name> + <maxAmount></maxAmount> + </item> -<item type=""> - <name></name> - <maxAmount></maxAmount> -</item> + <item type="stick"> + <!-- item --> + <name></name> + <maxAmount></maxAmount> + <!-- stick --> + <requiredLevel></reqiredLevel> + <requiredClass>Wizard</requiredClass> + </item> -<item type="stick"> - <!-- item --> - <name></name> - <maxAmount></maxAmount> - <!-- stick --> - <requiredLevel></reqiredLevel> - <requiredClass>Wizard</requiredClass> -</item> + <item type="medicine"> + <!-- item --> + <name></name> + <maxAmount></maxAmount> + <!-- medicine --> + <heal></heal> + <requiredLevel></reqiredLevel> + </item> -<item type="medicine"> - <!-- item --> - <name></name> - <maxAmount></maxAmount> + <item type="food"> + <!-- item --!> + <name></name> + <maxAmount></maxAmount> - <!-- medicine --> - <heal></heal> - <requiredLevel></reqiredLevel> -</item> + <!-- food --!> + <heal></heal> + <\item> -<item type="food"> - <!-- item --!> - <name></name> - <maxAmount></maxAmount> + <item type="weapon"> + <!-- item --!> + <name></name> + <maxAmount></maxAmount> - <!-- food --!> - <heal></heal> -<\item> - - - -<item type="weapon"> - <!-- item --!> - <name></name> - <maxAmount></maxAmount> - - <!-- weapon --!> - <damage></damage> - <requiredLevel></reqiredLevel> -</item> + <!-- weapon --!> + <damage></damage> + <requiredLevel></reqiredLevel> + </item> +</items> |