From 1fdbc0af01b9e515a8610b20c4e0cb760a3635eb Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Fri, 19 Apr 2013 15:36:18 +0200 Subject: [Abilities] Made the rechargespeed depending on attributes This allows a lot more flexibility and makes stuff like magical items a lot easier to implement. We will also use this for the attack system in the future. So a attack (abilitiy) would simply depend on some value like Agility (or a derived attribute from it). Which sets the recharge speed. The recharge speed is the modified value of the attribute per game tick. --- src/account-server/character.h | 2 +- src/game-server/abilitymanager.cpp | 6 ++-- src/game-server/abilitymanager.h | 4 +-- src/game-server/character.cpp | 33 ++++++++++++---------- src/game-server/character.h | 10 +------ src/scripting/lua.cpp | 57 -------------------------------------- 6 files changed, 25 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/account-server/character.h b/src/account-server/character.h index f59fe234..53443c4b 100644 --- a/src/account-server/character.h +++ b/src/account-server/character.h @@ -65,7 +65,7 @@ struct AbilityValue : currentPoints(currentPoints) {} - unsigned currentPoints; + int currentPoints; }; struct Status diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp index eb89829f..b492f65a 100644 --- a/src/game-server/abilitymanager.cpp +++ b/src/game-server/abilitymanager.cpp @@ -98,8 +98,8 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode, bool rechargeable = XML::getBoolProperty(abilityNode, "rechargeable", true); int neededMana = XML::getProperty(abilityNode, "needed", 0); - int defaultRechargeSpeed = XML::getProperty(abilityNode, - "rechargespeed", 0); + int rechargeAttribute = XML::getProperty(abilityNode, + "rechargeattribute", 0); if (rechargeable && neededMana <= 0) { @@ -116,7 +116,7 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode, newInfo->id = id; newInfo->rechargeable = rechargeable; newInfo->neededPoints = neededMana; - newInfo->defaultRechargeSpeed = defaultRechargeSpeed; + newInfo->rechargeAttribute = rechargeAttribute; newInfo->target = getTargetByString(XML::getProperty(abilityNode, "target", std::string())); diff --git a/src/game-server/abilitymanager.h b/src/game-server/abilitymanager.h index 07bf4c3a..b363d1f8 100644 --- a/src/game-server/abilitymanager.h +++ b/src/game-server/abilitymanager.h @@ -43,7 +43,7 @@ public: AbilityInfo() : id(0), rechargeable(false), - defaultRechargeSpeed(0), + rechargeAttribute(0), neededPoints(0), target(TARGET_BEING) {} @@ -52,7 +52,7 @@ public: std::string name; std::string categoryName; bool rechargeable; - int defaultRechargeSpeed; + unsigned rechargeAttribute; unsigned neededPoints; TargetMode target; Script::Ref rechargedCallback; diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 9299f718..1e0a0b73 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -170,7 +170,10 @@ void CharacterComponent::update(Entity &entity) if (s.abilityInfo->rechargeable && s.currentPoints < s.abilityInfo->neededPoints) { - s.currentPoints += s.rechargeSpeed; + 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()) { @@ -184,7 +187,7 @@ void CharacterComponent::update(Entity &entity) } if (!mModifiedAbilities.empty()) - sendAbilityUpdate(); + sendAbilityUpdate(entity); } void CharacterComponent::characterDied(Entity *being) @@ -326,20 +329,10 @@ bool CharacterComponent::setAbilityMana(int id, int mana) return false; } -bool CharacterComponent::setAbilityRechargeSpeed(int id, int speed) +void CharacterComponent::sendAbilityUpdate(Entity &entity) { - AbilityMap::iterator it = mAbilities.find(id); - if (it != mAbilities.end()) - { - it->second.rechargeSpeed = speed; - mModifiedAbilities.insert(id); - return true; - } - return false; -} + auto *beingComponent = entity.getComponent(); -void CharacterComponent::sendAbilityUpdate() -{ MessageOut msg(GPMSG_ABILITY_STATUS); for (unsigned id : mModifiedAbilities) { @@ -347,10 +340,13 @@ void CharacterComponent::sendAbilityUpdate() if (it == mAbilities.end()) continue; // got deleted + const double rechargeSpeed = beingComponent->getModifiedAttribute( + it->second.abilityInfo->rechargeAttribute); + msg.writeInt8(id); msg.writeInt32(it->second.currentPoints); msg.writeInt32(it->second.abilityInfo->neededPoints); - msg.writeInt32(it->second.rechargeSpeed); + msg.writeInt32((int)rechargeSpeed); } mModifiedAbilities.clear(); @@ -483,6 +479,13 @@ 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) diff --git a/src/game-server/character.h b/src/game-server/character.h index 9b179693..6c2e31e8 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -51,12 +51,10 @@ struct AbilityValue AbilityValue(unsigned currentMana, const AbilityManager::AbilityInfo *abilityInfo) : currentPoints(currentMana) - , rechargeSpeed(abilityInfo->defaultRechargeSpeed) , abilityInfo(abilityInfo) {} unsigned currentPoints; - unsigned rechargeSpeed; const AbilityManager::AbilityInfo *abilityInfo; }; @@ -188,12 +186,6 @@ class CharacterComponent : public Component */ AbilityMap::iterator findAbility(int id) { return mAbilities.find(id); } - - /** - * Sets recharge speed of a ability - */ - bool setAbilityRechargeSpeed(int id, int speed); - /** * Removes all abilities from character */ @@ -511,7 +503,7 @@ class CharacterComponent : public Component /** * Informs the client about his characters abilities charge status */ - void sendAbilityUpdate(); + void sendAbilityUpdate(Entity &entity); enum TransactionType { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index bfafd3e2..895bcede 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1277,61 +1277,6 @@ static int chr_set_quest(lua_State *s) return 0; } -/** LUA entity:set_ability_recharge_speed (being) - * entity:set_ability_recharge_speed(int abilityid, int new_speed) - * entity:set_ability_recharge_speed(string abilityname, int new_speed) - ** - * Valid only for character entities. - * - * Sets the recharge speed of the ability to a new value for the character. - * - * **Note:** When passing the `abilityname` as parameter make sure that it is - * formatted in this way: <setname&get;_<abilityname> (for eg. "Magic_Healingspell"). - */ -static int entity_set_ability_recharge_speed(lua_State *s) -{ - Entity *c = checkCharacter(s, 1); - const int ability = checkAbility(s, 2); - const int speed = luaL_checkint(s, 3); - - if (!c->getComponent() - ->setAbilityRechargeSpeed(ability, speed)) - { - luaL_error(s, - "set_ability_recharge_speed called with ability " - "that is not owned by character."); - } - return 0; -} - -/** LUA entity:ability_recharge_speed (being) - * entity:ability_recharge_speed(int abilityid) - * entity:ability_recharge_speed(string abilityname) - ** - * Valid only for character entities. - * - * **Return value:** The current recharge speed of the ability that is owned by - * the character. - * - * **Note:** When passing the `abilityname` as parameter make sure that it is - * formatted in this way: <setname>_<abilityname> (for eg. "Magic_Healingspell"). - */ -static int entity_get_ability_recharge_speed(lua_State *s) -{ - Entity *c = checkCharacter(s, 1); - const int ability = checkAbility(s, 2); - - auto *characterComponent = c->getComponent(); - - AbilityMap::iterator it = characterComponent->findAbility(ability); - - luaL_argcheck(s, it != characterComponent->getAbilitiesEnd(), 2, - "character does not have ability"); - - lua_pushinteger(s, it->second.rechargeSpeed); - return 1; -} - /** LUA entity:set_ability_mana (being) * entity:set_ability_mana(int abilityid, int new_mana) * entity:set_ability_mana(string abilityname, int new_mana) @@ -3801,8 +3746,6 @@ LuaScript::LuaScript(): { "equip_item", entity_equip_item }, { "unequip_slot", entity_unequip_slot }, { "unequip_item", entity_unequip_item }, - { "set_ability_recharge_speed", entity_set_ability_recharge_speed }, - { "ability_recharge_speed", entity_get_ability_recharge_speed }, { "set_ability_mana", entity_set_ability_mana }, { "ability_mana", entity_get_ability_mana }, { "walk", entity_walk }, -- cgit v1.2.3-60-g2f50