Grog-Knight

some game in C++
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/Grog-Knight

commit 66c3c808727864cd916a56c7557f9761712a4bf7
parent cb99c6da30efbd91452e629689d35b7c390919b5
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Fri, 22 May 2015 17:57:43 +0200

Merge pull request #14 from Ne02ptzero/build

Gotta catch it !
Diffstat:
MSources/inc/Equipment.hpp | 3++-
MSources/inc/Loot.hpp | 3+++
MSources/src/Armor.cpp | 2+-
MSources/src/Characters.cpp | 2+-
MSources/src/Equipment.cpp | 6++++++
MSources/src/Loot.cpp | 11++++++++++-
MSources/src/Ring.cpp | 2+-
MSources/src/Weapon.cpp | 2+-
8 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/Sources/inc/Equipment.hpp b/Sources/inc/Equipment.hpp @@ -46,11 +46,12 @@ public: void BeginContact(Elements *elem, b2Contact *contact); void EndContact(Elements *elem, b2Contact *contact); void ReceiveMessage(Message* m); - + virtual std::string getName(); private: Weapon* _weapon; Armor* _armor; Ring* _ring; + std::string _name; }; #endif diff --git a/Sources/inc/Loot.hpp b/Sources/inc/Loot.hpp @@ -29,9 +29,12 @@ # include "Characters.hpp" # include "Object.hpp" +class Equipment; + class Loot { public: Loot(Characters *c); + Loot(Characters *c, Equipment* toDrop); ~Loot(void); private: Loot(void); diff --git a/Sources/src/Armor.cpp b/Sources/src/Armor.cpp @@ -89,7 +89,7 @@ void Armor::_parseJson(std::string file) { if (!read.parse(file, json)) Log::error("Error in json syntax :\n" + read.getFormattedErrorMessages()); if (this->_name != json["infos"].get("name", "").asString()) - Log::warning("The Armor name is different with the name in the config file."); + Log::warning("The class name is different with the name in the config file: " + this->_name + "/" + json["infos"].get("name", "").asString()); this->_name = json["infos"].get("name", "").asString(); this->_flavor = json["infos"].get("flavor", "").asString(); this->_lootLevel = json["infos"].get("lootLevel", "").asInt(); diff --git a/Sources/src/Characters.cpp b/Sources/src/Characters.cpp @@ -615,7 +615,7 @@ void Characters::_pickupItem(int status) { if (this->_item->getAttribute("type3") == "Weapon"){ unequipWeapon(); this->equipWeapon(static_cast<Equipment*>(this->_item)->getWeapon()); - } + } else if (this->_item->getAttribute("type3") == "Ring") { unequipRing(); this->equipRing(static_cast<Equipment*>(this->_item)->getRing()); diff --git a/Sources/src/Equipment.cpp b/Sources/src/Equipment.cpp @@ -35,6 +35,7 @@ Equipment::Equipment(void): Object() { this->addAttribute("type2", "Equipment"); this->SetPosition(5, -12); + this->_name = "TBD"; this->_weapon = new Weapon(Game::wList->getWeapon("Bow")); this->SetSprite(this->_weapon->getSprite()); theSwitchboard.SubscribeTo(this, "DeleteEquipment"); @@ -63,6 +64,7 @@ Equipment::Equipment(Weapon *w, Characters* c): Object() { this->addAttribute("type3", "Weapon"); this->SetPosition(c->GetBody()->GetWorldCenter().x, c->GetBody()->GetWorldCenter().y); this->_weapon = new Weapon(w); + this->_name = w->getName(); this->SetSprite(this->_weapon->getSprite()); this->SetName("loot"); theSwitchboard.SubscribeTo(this, "DeleteEquipment" + this->GetName()); @@ -76,6 +78,7 @@ Equipment::Equipment(Armor *w, Characters* c): Object() { this->addAttribute("type3", "Armor"); this->SetPosition(c->GetBody()->GetWorldCenter().x, c->GetBody()->GetWorldCenter().y); this->_armor = new Armor(w); + this->_name = w->getName(); this->SetSprite(this->_armor->getSprite()); this->SetName("loot"); theSwitchboard.SubscribeTo(this, "DeleteEquipment" + this->GetName()); @@ -88,6 +91,7 @@ Equipment::Equipment(Ring *w, Characters* c): Object() { this->addAttribute("type3", "Ring"); this->SetPosition(c->GetBody()->GetWorldCenter().x, c->GetBody()->GetWorldCenter().y); this->_ring = new Ring(w); + this->_name = w->getName(); this->SetSprite(this->_ring->getSprite()); this->SetName("loot"); theSwitchboard.SubscribeTo(this, "DeleteEquipment" + this->GetName()); @@ -137,6 +141,8 @@ Armor* Equipment::getArmor(void) { return this->_armor; } Ring* Equipment::getRing(void) { return this->_ring; } +std::string Equipment::getName(void) { return this->_name; } + //! Intern broadcasts function. /** * The Receive Message function. diff --git a/Sources/src/Loot.cpp b/Sources/src/Loot.cpp @@ -42,9 +42,18 @@ Loot::Loot(Characters* c) { } else if (rand() % 100 <= c->_getAttr("loot", "equipmentRate").asInt()) { if (rand() % 2 == 1) new Equipment(Game::wList->getWeaponRandom(c->_getAttr("loot", "EqReward").asInt()), c); - if (rand() % 2 == 1) + else if (rand() % 2 == 1) new Equipment(Game::aList->getArmorRandom(c->_getAttr("loot", "EqReward").asInt()), c); else new Equipment(Game::rList->getRingRandom(c->_getAttr("loot", "EqReward").asInt()), c); } } + +Loot::Loot(Characters* c, Equipment *toDrop) { + if (toDrop->getAttribute("type3") == "Weapon") + new Equipment(Game::wList->getWeapon(toDrop->getName()), c); + else if (toDrop->getAttribute("type3") == "Armor") + new Equipment(Game::aList->getArmor(toDrop->getName()), c); + else if (toDrop->getAttribute("type3") == "Ring") + new Equipment(Game::rList->getRing(toDrop->getName()), c); +} diff --git a/Sources/src/Ring.cpp b/Sources/src/Ring.cpp @@ -89,7 +89,7 @@ void Ring::_parseJson(std::string file) { if (!read.parse(file, json)) Log::error("Error in json syntax :\n" + read.getFormattedErrorMessages()); if (this->_name != json["infos"].get("name", "").asString()) - Log::warning("The Ring name is different with the name in the config file."); + Log::warning("The class name is different with the name in the config file: " + this->_name + "/" + json["infos"].get("name", "").asString()); this->_name = json["infos"].get("name", "").asString(); this->_flavor = json["infos"].get("flavor", "").asString(); this->_lootLevel = json["infos"].get("lootLevel", "").asInt(); diff --git a/Sources/src/Weapon.cpp b/Sources/src/Weapon.cpp @@ -183,7 +183,7 @@ void Weapon::_parseJson(std::string file) { if (!read.parse(file, json)) Log::error("Error in json syntax :\n" + read.getFormattedErrorMessages()); if (this->_name != json["infos"].get("name", "").asString()) - Log::warning("The weapon name is different with the name in the config file."); + Log::warning("The class name is different with the name in the config file: " + this->_name + "/" + json["infos"].get("name", "").asString()); this->_name = json["infos"].get("name", "").asString(); this->_flavor = json["infos"].get("flavor", "").asString(); this->_active = json["infos"].get("active", "").asFloat();