From 2e977bb3182332fce247c7bdee5db2c43c9de5ee Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 21 Apr 2013 11:53:57 +0200 Subject: [Abilities] Moved the ability code into a own component This later allows monsters and characters to use this component. --- src/CMakeLists.txt | 2 + src/game-server/abilitycomponent.cpp | 203 +++++++++++++++++++++++++++++++++++ src/game-server/abilitycomponent.h | 108 +++++++++++++++++++ src/game-server/character.cpp | 164 +++------------------------- src/game-server/character.h | 87 ++------------- src/game-server/commandhandler.cpp | 15 ++- src/game-server/component.h | 1 + src/game-server/gamehandler.cpp | 12 +-- src/scripting/lua.cpp | 18 ++-- 9 files changed, 355 insertions(+), 255 deletions(-) create mode 100644 src/game-server/abilitycomponent.cpp create mode 100644 src/game-server/abilitycomponent.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f18ebd..e62a89b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,6 +197,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 0000000..c8610b5 --- /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 . + */ + +#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()->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(); + 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( + 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 0000000..ae48e91 --- /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 . + */ + +#ifndef ABILITYCOMPONENT_H_ +#define ABILITYCOMPONENT_H_ + +#include "game-server/abilitymanager.h" +#include "game-server/component.h" + +#include + +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 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 signal_ability_changed; + sigc::signal 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 1e0a0b7..0fa1e10 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()->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(); - 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( - 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(); + auto &abilities = entity.getComponent()->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 6c2e31e..a67436c 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 AbilityMap; - class CharacterData { @@ -159,48 +143,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. */ @@ -347,18 +289,6 @@ class CharacterComponent : public Component void setKillCount(int monsterId, int kills) { 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. */ @@ -462,8 +392,6 @@ class CharacterComponent : public Component sigc::signal 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 mExperience; /**< experience collected for each skill.*/ - AbilityMap mAbilities; std::set 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()->clearAbilities(); } inline void CharacterData::giveAbility(int id, int mana) { - mCharacterComponent->giveAbility(id, mana); + mEntity->getComponent()->giveAbility(id, mana); } inline int CharacterData::getAbilitySize() const { - return mCharacterComponent->getAbilitiesSize(); + return mEntity->getComponent()->getAbilities().size(); } inline AbilityMap::const_iterator CharacterData::getAbilityBegin() const { - return mCharacterComponent->getAbilitiesBegin(); + return mEntity->getComponent()->getAbilities().begin(); } inline AbilityMap::const_iterator CharacterData::getAbilityEnd() const { - return mCharacterComponent->getAbilitiesEnd(); + return mEntity->getComponent()->getAbilities().end(); } inline Possessions &CharacterData::getPossessions() const diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 5abd722..3e74835 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()->giveAbility(abilityId)) + !other->getComponent()->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()->takeAbility(abilityId)) + if (!other->getComponent()->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() - ->setAbilityMana(abilityId, mana)) + if (!other->getComponent()->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(); + auto *abilityComponent = other->getComponent(); say("Abilityies of character " + other->getComponent()->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 824de2c..0a23965 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 2740284..b1a87a2 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()->getPublicID(); LOG_DEBUG("Character " << publicId << " tries to use his ability " << abilityID); - auto *characterComponent = client.character - ->getComponent(); - characterComponent->useAbilityOnBeing(*client.character, abilityID, being); + auto *abilityComponent = client.character + ->getComponent(); + 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()->getPublicID(); LOG_DEBUG("Character " << publicId << " tries to use his ability attack " << abilityID); - auto *characterComponent = client.character - ->getComponent(); - characterComponent->useAbilityOnPoint(*client.character, abilityID, x, y); + auto *abilityComponent = client.character + ->getComponent(); + 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 1f9c1cf..fd48f9b 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1295,7 +1295,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()->setAbilityMana(ability, mana)) + if (!c->getComponent()->setAbilityMana(ability, mana)) { luaL_error(s, "set_ability_mana called with ability " @@ -1317,10 +1317,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(); + auto *abilityComponent = c->getComponent(); 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; @@ -2301,7 +2301,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()->giveAbility(ability, currentMana); + c->getComponent()->giveAbility(ability, currentMana); return 0; } @@ -2317,7 +2317,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()->hasAbility(ability)); + lua_pushboolean(s, c->getComponent()->hasAbility(ability)); return 1; } @@ -2336,9 +2336,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(); - lua_pushboolean(s, cc->hasAbility(ability)); - cc->takeAbility(ability); + auto *abilityComponent = c->getComponent(); + lua_pushboolean(s, abilityComponent->hasAbility(ability)); + abilityComponent->takeAbility(ability); return 1; } -- cgit