diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-21 11:53:57 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:46 +0200 |
commit | d1fe3b52bda94126ba96b20146f5e9dfd3a9c311 (patch) | |
tree | 8596913ef185a3bbc13b108ba67132f53019f281 | |
parent | 4f46549b29234d7e7bc545cc6234880ee117a950 (diff) | |
download | manaserv-d1fe3b52bda94126ba96b20146f5e9dfd3a9c311.tar.gz manaserv-d1fe3b52bda94126ba96b20146f5e9dfd3a9c311.tar.bz2 manaserv-d1fe3b52bda94126ba96b20146f5e9dfd3a9c311.tar.xz manaserv-d1fe3b52bda94126ba96b20146f5e9dfd3a9c311.zip |
[Abilities] Moved the ability code into a own component
This later allows monsters and characters to use this component.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/game-server/abilitycomponent.cpp | 203 | ||||
-rw-r--r-- | src/game-server/abilitycomponent.h | 108 | ||||
-rw-r--r-- | src/game-server/character.cpp | 164 | ||||
-rw-r--r-- | src/game-server/character.h | 87 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 15 | ||||
-rw-r--r-- | src/game-server/component.h | 1 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 12 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 18 |
9 files changed, 355 insertions, 255 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b9c20be..2a665774 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -203,6 +203,8 @@ SET(SRCS_MANASERVGAME game-server/main-game.cpp common/permissionmanager.h common/permissionmanager.cpp + game-server/abilitycomponent.cpp + game-server/abilitycomponent.h game-server/abilitymanager.cpp game-server/abilitymanager.h game-server/accountconnection.h diff --git a/src/game-server/abilitycomponent.cpp b/src/game-server/abilitycomponent.cpp new file mode 100644 index 00000000..c8610b5a --- /dev/null +++ b/src/game-server/abilitycomponent.cpp @@ -0,0 +1,203 @@ +/* + * The Mana Server + * Copyright (C) 2013 The Mana Developers + * + * This file is part of The Mana Server. + * + * The Mana Server is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "abilitycomponent.h" + +#include "game-server/being.h" +#include "game-server/entity.h" + +#include "scripting/scriptmanager.h" + +#include "utils/logger.h" + +AbilityComponent::AbilityComponent(Entity &entity) +{ + entity.getComponent<BeingComponent>()->signal_attribute_changed.connect( + sigc::mem_fun(this, &AbilityComponent::attributeChanged)); +} + +void AbilityComponent::update(Entity &entity) +{ + // Update ability recharge + for (auto &it : mAbilities) + { + AbilityValue &s = it.second; + if (s.abilityInfo->rechargeable && + s.currentPoints < s.abilityInfo->neededPoints) + { + auto *beingComponent = entity.getComponent<BeingComponent>(); + const double rechargeSpeed = beingComponent->getModifiedAttribute( + s.abilityInfo->rechargeAttribute); + s.currentPoints += (int)rechargeSpeed; + if (s.currentPoints >= s.abilityInfo->neededPoints && + s.abilityInfo->rechargedCallback.isValid()) + { + Script *script = ScriptManager::currentState(); + script->prepare(s.abilityInfo->rechargedCallback); + script->push(&entity); + script->push(s.abilityInfo->id); + script->execute(entity.getMap()); + } + } + } + +} + +/** + * Removes an available ability action + */ +bool AbilityComponent::takeAbility(int id) +{ + AbilityMap::iterator i = mAbilities.find(id); + if (i != mAbilities.end()) + { + mAbilities.erase(i); + signal_ability_took.emit(id); + return true; + } + return false; +} + +bool AbilityComponent::abilityUseCheck(AbilityMap::iterator it) +{ + if (it == mAbilities.end()) + { + LOG_INFO("Character uses ability " << it->first + << " without authorization."); + return false; + } + + //check if the ability is currently recharged + AbilityValue &ability = it->second; + if (ability.abilityInfo->rechargeable && + ability.currentPoints < ability.abilityInfo->neededPoints) + { + LOG_INFO("Character uses ability " << it->first + << " which is not recharged. (" + << ability.currentPoints << "/" + << ability.abilityInfo->neededPoints << ")"); + return false; + } + + if (!ability.abilityInfo->useCallback.isValid()) + { + LOG_WARN("No callback for use of ability " + << ability.abilityInfo->categoryName << "/" + << ability.abilityInfo->name << ". Ignoring ability."); + return false; + } + return true; +} + +/** + * makes the character perform a ability on a being + * when it is allowed to do so + */ +void AbilityComponent::useAbilityOnBeing(Entity &user, int id, Entity *b) +{ + AbilityMap::iterator it = mAbilities.find(id); + if (!abilityUseCheck(it)) + return; + AbilityValue &ability = it->second; + + if (ability.abilityInfo->target != AbilityManager::TARGET_BEING) + return; + + //tell script engine to cast the spell + Script *script = ScriptManager::currentState(); + script->prepare(ability.abilityInfo->useCallback); + script->push(&user); + script->push(b); + script->push(ability.abilityInfo->id); + script->execute(user.getMap()); +} + +/** + * makes the character perform a ability on a map point + * when it is allowed to do so + */ +void AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y) +{ + AbilityMap::iterator it = mAbilities.find(id); + if (!abilityUseCheck(it)) + return; + AbilityValue &ability = it->second; + + if (ability.abilityInfo->target != AbilityManager::TARGET_POINT) + return; + + //tell script engine to cast the spell + Script *script = ScriptManager::currentState(); + script->prepare(ability.abilityInfo->useCallback); + script->push(&user); + script->push(x); + script->push(y); + script->push(ability.abilityInfo->id); + script->execute(user.getMap()); +} + +/** + * Allows a character to perform a ability + */ +bool AbilityComponent::giveAbility(int id, int currentPoints) +{ + if (mAbilities.find(id) == mAbilities.end()) + { + const AbilityManager::AbilityInfo *abilityInfo = + abilityManager->getAbilityInfo(id); + if (!abilityInfo) + { + LOG_ERROR("Tried to give not existing ability id " << id << "."); + return false; + } + mAbilities.insert(std::pair<int, AbilityValue>( + id, AbilityValue(currentPoints, abilityInfo))); + + signal_ability_changed.emit(id); + return true; + } + return false; +} + +/** + * Sets new current mana + makes sure that the client will get informed. + */ +bool AbilityComponent::setAbilityMana(int id, int mana) +{ + AbilityMap::iterator it = mAbilities.find(id); + if (it != mAbilities.end()) + { + it->second.currentPoints = mana; + signal_ability_changed.emit(id); + return true; + } + return false; +} + +void AbilityComponent::attributeChanged(Entity *entity, unsigned attr) +{ + for (auto &abilityIt : mAbilities) + { + // Inform the client about rechargespeed changes + if (abilityIt.second.abilityInfo->rechargeAttribute == attr) + signal_ability_changed.emit(abilityIt.first); + } +} + diff --git a/src/game-server/abilitycomponent.h b/src/game-server/abilitycomponent.h new file mode 100644 index 00000000..ae48e917 --- /dev/null +++ b/src/game-server/abilitycomponent.h @@ -0,0 +1,108 @@ +/* + * The Mana Server + * Copyright (C) 2013 The Mana Developers + * + * This file is part of The Mana Server. + * + * The Mana Server is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ABILITYCOMPONENT_H_ +#define ABILITYCOMPONENT_H_ + +#include "game-server/abilitymanager.h" +#include "game-server/component.h" + +#include <sigc++/signal.h> + +struct AbilityValue +{ + AbilityValue(unsigned currentMana, + const AbilityManager::AbilityInfo *abilityInfo) + : currentPoints(currentMana) + , abilityInfo(abilityInfo) + {} + + unsigned currentPoints; + const AbilityManager::AbilityInfo *abilityInfo; +}; + +/** + * Stores abilities by their id. + */ +typedef std::map<unsigned, AbilityValue> AbilityMap; + + +class AbilityComponent: public Component +{ +public: + static const ComponentType type = CT_Ability; + + AbilityComponent(Entity &entity); + + void update(Entity &entity); + + void useAbilityOnBeing(Entity &user, int id, Entity *b); + void useAbilityOnPoint(Entity &user, int id, int x, int y); + + bool giveAbility(int id, int currentMana = 0); + bool hasAbility(int id) const; + bool takeAbility(int id); + AbilityMap::iterator findAbility(int id); + const AbilityMap &getAbilities() const; + void clearAbilities(); + + bool setAbilityMana(int id, int mana); + + sigc::signal<void, int> signal_ability_changed; + sigc::signal<void, int> signal_ability_took; + +private: + bool abilityUseCheck(AbilityMap::iterator it); + void attributeChanged(Entity *entity, unsigned attr); + + AbilityMap mAbilities; +}; + + +/** + * Gets the ability value by id + */ +inline AbilityMap::iterator AbilityComponent::findAbility(int id) +{ + return mAbilities.find(id); +} + +/** + * Removes all abilities from character + */ +inline void AbilityComponent::clearAbilities() +{ + mAbilities.clear(); +} + +/** + * Checks if a character knows a ability action + */ +inline bool AbilityComponent::hasAbility(int id) const +{ + return mAbilities.find(id) != mAbilities.end(); +} + +inline const AbilityMap &AbilityComponent::getAbilities() const +{ + return mAbilities; +} + +#endif /* ABILITYCOMPONENT_H_ */ diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 1e0a0b73..0fa1e10b 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -127,6 +127,11 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mKnuckleAttackInfo = new AttackInfo(0, knuckleDamage, 7, 3, 0); combatcomponent->addAttack(mKnuckleAttackInfo); + auto *abilityComponent = new AbilityComponent(entity); + entity.addComponent(abilityComponent); + abilityComponent->signal_ability_changed.connect( + sigc::mem_fun(this, &CharacterComponent::abilityStatusChanged)); + // Get character data. mDatabaseID = msg.readInt32(); beingComponent->setName(msg.readString()); @@ -140,7 +145,7 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): beingComponent->signal_attribute_changed.connect(sigc::mem_fun( this, &CharacterComponent::attributeChanged)); - for (auto &abilityIt : mAbilities) + for (auto &abilityIt : abilityComponent->getAbilities()) mModifiedAbilities.insert(abilityIt.first); } @@ -163,29 +168,6 @@ void CharacterComponent::update(Entity &entity) if (entity.getComponent<BeingComponent>()->getAction() == DEAD) return; - // Update ability recharge - for (auto &it : mAbilities) - { - AbilityValue &s = it.second; - if (s.abilityInfo->rechargeable && - s.currentPoints < s.abilityInfo->neededPoints) - { - auto *beingComponent = entity.getComponent<BeingComponent>(); - const double rechargeSpeed = beingComponent->getModifiedAttribute( - s.abilityInfo->rechargeAttribute); - s.currentPoints += (int)rechargeSpeed; - if (s.currentPoints >= s.abilityInfo->neededPoints && - s.abilityInfo->rechargedCallback.isValid()) - { - Script *script = ScriptManager::currentState(); - script->prepare(s.abilityInfo->rechargedCallback); - script->push(&entity); - script->push(s.abilityInfo->id); - script->execute(entity.getMap()); - } - } - } - if (!mModifiedAbilities.empty()) sendAbilityUpdate(entity); } @@ -227,117 +209,22 @@ void CharacterComponent::respawn(Entity &entity) Point(spawnX, spawnY)); } -bool CharacterComponent::abilityUseCheck(AbilityMap::iterator it) -{ - if (it == mAbilities.end()) - { - LOG_INFO("Character uses ability " << it->first - << " without authorization."); - return false; - } - - //check if the ability is currently recharged - AbilityValue &ability = it->second; - if (ability.abilityInfo->rechargeable && - ability.currentPoints < ability.abilityInfo->neededPoints) - { - LOG_INFO("Character uses ability " << it->first - << " which is not recharged. (" - << ability.currentPoints << "/" - << ability.abilityInfo->neededPoints << ")"); - return false; - } - - if (!ability.abilityInfo->useCallback.isValid()) - { - LOG_WARN("No callback for use of ability " - << ability.abilityInfo->categoryName << "/" - << ability.abilityInfo->name << ". Ignoring ability."); - return false; - } - return true; -} - -void CharacterComponent::useAbilityOnBeing(Entity &user, int id, Entity *b) -{ - AbilityMap::iterator it = mAbilities.find(id); - if (!abilityUseCheck(it)) - return; - AbilityValue &ability = it->second; - - if (ability.abilityInfo->target != AbilityManager::TARGET_BEING) - return; - - //tell script engine to cast the spell - Script *script = ScriptManager::currentState(); - script->prepare(ability.abilityInfo->useCallback); - script->push(&user); - script->push(b); - script->push(ability.abilityInfo->id); - script->execute(user.getMap()); -} - -void CharacterComponent::useAbilityOnPoint(Entity &user, int id, int x, int y) -{ - AbilityMap::iterator it = mAbilities.find(id); - if (!abilityUseCheck(it)) - return; - AbilityValue &ability = it->second; - - if (ability.abilityInfo->target != AbilityManager::TARGET_POINT) - return; - - //tell script engine to cast the spell - Script *script = ScriptManager::currentState(); - script->prepare(ability.abilityInfo->useCallback); - script->push(&user); - script->push(x); - script->push(y); - script->push(ability.abilityInfo->id); - script->execute(user.getMap()); -} - -bool CharacterComponent::giveAbility(int id, int currentPoints) -{ - if (mAbilities.find(id) == mAbilities.end()) - { - const AbilityManager::AbilityInfo *abilityInfo = - abilityManager->getAbilityInfo(id); - if (!abilityInfo) - { - LOG_ERROR("Tried to give not existing ability id " << id << "."); - return false; - } - mAbilities.insert(std::pair<int, AbilityValue>( - id, AbilityValue(currentPoints, abilityInfo))); - - mModifiedAbilities.insert(id); - return true; - } - return false; -} - -bool CharacterComponent::setAbilityMana(int id, int mana) +void CharacterComponent::abilityStatusChanged(int id) { - AbilityMap::iterator it = mAbilities.find(id); - if (it != mAbilities.end()) - { - it->second.currentPoints = mana; - mModifiedAbilities.insert(id); - return true; - } - return false; + mModifiedAbilities.insert(id); } void CharacterComponent::sendAbilityUpdate(Entity &entity) { auto *beingComponent = entity.getComponent<BeingComponent>(); + auto &abilities = entity.getComponent<AbilityComponent>()->getAbilities(); + MessageOut msg(GPMSG_ABILITY_STATUS); for (unsigned id : mModifiedAbilities) { - auto it = mAbilities.find(id); - if (it == mAbilities.end()) + auto it = abilities.find(id); + if (it == abilities.end()) continue; // got deleted const double rechargeSpeed = beingComponent->getModifiedAttribute( @@ -479,13 +366,6 @@ void CharacterComponent::attributeChanged(Entity *entity, unsigned attr) knuckleDamage.base = beingComponent->getModifiedAttribute(ATTR_STR); knuckleDamage.delta = knuckleDamage.base / 2; } - - for (auto &abilityIt : mAbilities) - { - // Inform the client about rechargespeed changes - if (abilityIt.second.abilityInfo->rechargeAttribute == attr) - mModifiedAbilities.insert(abilityIt.first); - } } int CharacterComponent::expForLevel(int level) @@ -729,26 +609,6 @@ void CharacterComponent::disconnected(Entity &entity) signal_disconnected.emit(entity); } - -bool CharacterComponent::takeAbility(int id) -{ - AbilityMap::iterator i = mAbilities.find(id); - if (i != mAbilities.end()) - { - mAbilities.erase(i); - MessageOut msg(GPMSG_ABILITY_REMOVED); - msg.writeInt8(id); - gameHandler->sendTo(mClient, msg); - return true; - } - return false; -} - -void CharacterComponent::clearAbilities() -{ - mAbilities.clear(); -} - void CharacterComponent::triggerLoginCallback(Entity &entity) { executeCallback(mLoginCallback, entity); diff --git a/src/game-server/character.h b/src/game-server/character.h index 6c2e31e8..a67436cc 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -25,6 +25,7 @@ #include "common/inventorydata.h" #include "common/manaserv_protocol.h" +#include "game-server/abilitycomponent.h" #include "game-server/being.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" @@ -46,23 +47,6 @@ class MessageOut; class Point; class Trade; -struct AbilityValue -{ - AbilityValue(unsigned currentMana, - const AbilityManager::AbilityInfo *abilityInfo) - : currentPoints(currentMana) - , abilityInfo(abilityInfo) - {} - - unsigned currentPoints; - const AbilityManager::AbilityInfo *abilityInfo; -}; - -/** - * Stores abilities by their id. - */ -typedef std::map<unsigned, AbilityValue> AbilityMap; - class CharacterData { @@ -160,48 +144,6 @@ class CharacterComponent : public Component void respawn(Entity &entity); /** - * makes the character perform a ability on a being - * when it is allowed to do so - */ - void useAbilityOnBeing(Entity &user, int id, Entity *b); - - /** - * makes the character perform a ability on a map point - * when it is allowed to do so - */ - void useAbilityOnPoint(Entity &user, int id, int x, int y); - - /** - * Allows a character to perform a ability - */ - bool giveAbility(int id, int currentMana = 0); - - /** - * Sets new current mana + makes sure that the client will get informed. - */ - bool setAbilityMana(int id, int mana); - - /** - * Gets the ability value by id - */ - AbilityMap::iterator findAbility(int id) - { return mAbilities.find(id); } - /** - * Removes all abilities from character - */ - void clearAbilities(); - - /** - * Checks if a character knows a ability action - */ - bool hasAbility(int id) { return mAbilities.find(id) != mAbilities.end(); } - - /** - * Removes an available ability action - */ - bool takeAbility(int id); - - /** * Gets client computer. */ GameClient *getClient() const @@ -348,18 +290,6 @@ class CharacterComponent : public Component { mKillCount[monsterId] = kills; } /** - * Used to serialize abilities. - */ - int getAbilitiesSize() const - { return mAbilities.size(); } - - const AbilityMap::const_iterator getAbilitiesBegin() const - { return mAbilities.begin(); } - - const AbilityMap::const_iterator getAbilitiesEnd() const - { return mAbilities.end(); } - - /** * Gets total accumulated exp for skill. */ int getExperience(int skill) const @@ -462,8 +392,6 @@ class CharacterComponent : public Component sigc::signal<void, Entity &> signal_disconnected; private: - bool abilityUseCheck(AbilityMap::iterator it); - double getAttrBase(AttributeMap::const_iterator it) const { return it->second.getBase(); } double getAttrMod(AttributeMap::const_iterator it) const @@ -500,6 +428,8 @@ class CharacterComponent : public Component */ void recalculateLevel(Entity &entity); + void abilityStatusChanged(int id); + /** * Informs the client about his characters abilities charge status */ @@ -527,7 +457,6 @@ class CharacterComponent : public Component std::map<int, int> mExperience; /**< experience collected for each skill.*/ - AbilityMap mAbilities; std::set<unsigned> mModifiedAbilities; int mDatabaseID; /**< Character's database ID. */ @@ -738,27 +667,27 @@ inline void CharacterData::setKillCount(int monsterId, int kills) inline void CharacterData::clearAbilities() { - mCharacterComponent->clearAbilities(); + mEntity->getComponent<AbilityComponent>()->clearAbilities(); } inline void CharacterData::giveAbility(int id, int mana) { - mCharacterComponent->giveAbility(id, mana); + mEntity->getComponent<AbilityComponent>()->giveAbility(id, mana); } inline int CharacterData::getAbilitySize() const { - return mCharacterComponent->getAbilitiesSize(); + return mEntity->getComponent<AbilityComponent>()->getAbilities().size(); } inline AbilityMap::const_iterator CharacterData::getAbilityBegin() const { - return mCharacterComponent->getAbilitiesBegin(); + return mEntity->getComponent<AbilityComponent>()->getAbilities().begin(); } inline AbilityMap::const_iterator CharacterData::getAbilityEnd() const { - return mCharacterComponent->getAbilitiesEnd(); + return mEntity->getComponent<AbilityComponent>()->getAbilities().end(); } inline Possessions &CharacterData::getPossessions() const diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 5abd7220..3e748352 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -1632,7 +1632,7 @@ static void handleGiveAbility(Entity *player, std::string &args) abilityId = abilityManager->getId(ability); if (abilityId <= 0 || - !other->getComponent<CharacterComponent>()->giveAbility(abilityId)) + !other->getComponent<AbilityComponent>()->giveAbility(abilityId)) { say("Invalid ability.", player); return; @@ -1673,7 +1673,7 @@ static void handleTakeAbility(Entity *player, std::string &args) say("Invalid ability.", player); return; } - if (!other->getComponent<CharacterComponent>()->takeAbility(abilityId)) + if (!other->getComponent<AbilityComponent>()->takeAbility(abilityId)) { say("Character does not have ability.", player); return; @@ -1732,8 +1732,7 @@ static void handleRechargeAbility(Entity *player, std::string &args) } mana = utils::stringToInt(newMana); } - if (!other->getComponent<CharacterComponent>() - ->setAbilityMana(abilityId, mana)) + if (!other->getComponent<AbilityComponent>()->setAbilityMana(abilityId, mana)) { say("Character does not have ability.", player); return; @@ -1762,15 +1761,13 @@ static void handleListAbility(Entity *player, std::string &args) return; } - auto *characterComponent = - other->getComponent<CharacterComponent>(); + auto *abilityComponent = other->getComponent<AbilityComponent>(); say("Abilityies of character " + other->getComponent<BeingComponent>()->getName() + ":", player); - for (AbilityMap::const_iterator it = characterComponent->getAbilitiesBegin(), - it_end = characterComponent->getAbilitiesEnd(); it != it_end; ++it) + for (auto &abilityIt : abilityComponent->getAbilities()) { - const AbilityValue &info = it->second; + const AbilityValue &info = abilityIt.second; std::stringstream str; str << info.abilityInfo->id << ": " << info.abilityInfo->categoryName << "/" << info.abilityInfo->name << " charge: " << info.currentPoints; diff --git a/src/game-server/component.h b/src/game-server/component.h index 824de2c8..0a239652 100644 --- a/src/game-server/component.h +++ b/src/game-server/component.h @@ -27,6 +27,7 @@ class Entity; enum ComponentType { + CT_Ability, CT_Actor, CT_Character, CT_Being, diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 2740284e..b1a87a24 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -702,9 +702,9 @@ void GameHandler::handleUseAbilityOnBeing(GameClient &client, MessageIn &message client.character->getComponent<ActorComponent>()->getPublicID(); LOG_DEBUG("Character " << publicId << " tries to use his ability " << abilityID); - auto *characterComponent = client.character - ->getComponent<CharacterComponent>(); - characterComponent->useAbilityOnBeing(*client.character, abilityID, being); + auto *abilityComponent = client.character + ->getComponent<AbilityComponent>(); + abilityComponent->useAbilityOnBeing(*client.character, abilityID, being); } void GameHandler::handleUseAbilityOnPoint(GameClient &client, MessageIn &message) @@ -720,9 +720,9 @@ void GameHandler::handleUseAbilityOnPoint(GameClient &client, MessageIn &message client.character->getComponent<ActorComponent>()->getPublicID(); LOG_DEBUG("Character " << publicId << " tries to use his ability attack " << abilityID); - auto *characterComponent = client.character - ->getComponent<CharacterComponent>(); - characterComponent->useAbilityOnPoint(*client.character, abilityID, x, y); + auto *abilityComponent = client.character + ->getComponent<AbilityComponent>(); + abilityComponent->useAbilityOnPoint(*client.character, abilityID, x, y); } void GameHandler::handleActionChange(GameClient &client, MessageIn &message) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 895bcede..63c48abd 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1294,7 +1294,7 @@ static int entity_set_ability_mana(lua_State *s) Entity *c = checkCharacter(s, 1); const int ability = checkAbility(s, 2); const int mana = luaL_checkint(s, 3); - if (!c->getComponent<CharacterComponent>()->setAbilityMana(ability, mana)) + if (!c->getComponent<AbilityComponent>()->setAbilityMana(ability, mana)) { luaL_error(s, "set_ability_mana called with ability " @@ -1316,10 +1316,10 @@ static int entity_set_ability_mana(lua_State *s) static int entity_get_ability_mana(lua_State *s) { Entity *c = checkCharacter(s, 1); - auto *characterComponent = c->getComponent<CharacterComponent>(); + auto *abilityComponent = c->getComponent<AbilityComponent>(); const int ability = checkAbility(s, 2); - AbilityMap::iterator it = characterComponent->findAbility(ability); - luaL_argcheck(s, it != characterComponent->getAbilitiesEnd(), 2, + AbilityMap::iterator it = abilityComponent->findAbility(ability); + luaL_argcheck(s, it != abilityComponent->getAbilities().end(), 2, "character does not have ability"); lua_pushinteger(s, it->second.currentPoints); return 1; @@ -2356,7 +2356,7 @@ static int entity_give_ability(lua_State *s) const int ability = checkAbility(s, 2); const int currentMana = luaL_optint(s, 3, 0); - c->getComponent<CharacterComponent>()->giveAbility(ability, currentMana); + c->getComponent<AbilityComponent>()->giveAbility(ability, currentMana); return 0; } @@ -2372,7 +2372,7 @@ static int entity_has_ability(lua_State *s) Entity *c = checkCharacter(s, 1); const int ability = luaL_checkint(s, 2); - lua_pushboolean(s, c->getComponent<CharacterComponent>()->hasAbility(ability)); + lua_pushboolean(s, c->getComponent<AbilityComponent>()->hasAbility(ability)); return 1; } @@ -2391,9 +2391,9 @@ static int entity_take_ability(lua_State *s) Entity *c = checkCharacter(s, 1); const int ability = luaL_checkint(s, 2); - CharacterComponent *cc = c->getComponent<CharacterComponent>(); - lua_pushboolean(s, cc->hasAbility(ability)); - cc->takeAbility(ability); + auto *abilityComponent = c->getComponent<AbilityComponent>(); + lua_pushboolean(s, abilityComponent->hasAbility(ability)); + abilityComponent->takeAbility(ability); return 1; } |