summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-04-19 15:36:18 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-05-08 14:02:51 +0200
commitec473d0d76e89e606122187ceab61df8a0ab17cf (patch)
treeb873b90f233025aaacbb327614779df05e139e6b
parent7b289c333a6c5735dffa504c8482aee3b648b6cd (diff)
downloadmanaserv-ec473d0d76e89e606122187ceab61df8a0ab17cf.tar.gz
manaserv-ec473d0d76e89e606122187ceab61df8a0ab17cf.tar.xz
manaserv-ec473d0d76e89e606122187ceab61df8a0ab17cf.zip
[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.
-rw-r--r--example/abilities.xml6
-rw-r--r--src/account-server/character.h2
-rw-r--r--src/game-server/abilitymanager.cpp6
-rw-r--r--src/game-server/abilitymanager.h4
-rw-r--r--src/game-server/character.cpp33
-rw-r--r--src/game-server/character.h10
-rw-r--r--src/scripting/lua.cpp57
7 files changed, 28 insertions, 90 deletions
diff --git a/example/abilities.xml b/example/abilities.xml
index 4289d6c..93a67c0 100644
--- a/example/abilities.xml
+++ b/example/abilities.xml
@@ -6,7 +6,7 @@
name="Test Spell 1"
rechargeable="true"
needed="100"
- rechargespeed="10"
+ rechargeattribute="6"
target="point"
/>
<ability
@@ -14,7 +14,7 @@
name="Test Spell 2"
rechargeable="true"
needed="1000"
- rechargespeed="10"
+ rechargeattribute="6"
target="being"
/>
<ability
@@ -22,7 +22,7 @@
name="Test Spell 3"
rechargeable="true"
needed="10000"
- rechargespeed="10"
+ rechargeattribute="6"
target="point"
/>
</ability-category>
diff --git a/src/account-server/character.h b/src/account-server/character.h
index f59fe23..53443c4 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 eb89829..b492f65 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 07bf4c3..b363d1f 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 9299f71..1e0a0b7 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<BeingComponent>();
+ 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<BeingComponent>();
-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 9b17969..6c2e31e 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 d5831d6..1f9c1cf 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1278,61 +1278,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>_<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<CharacterComponent>()
- ->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<CharacterComponent>();
-
- 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)
@@ -3738,8 +3683,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 },