summaryrefslogtreecommitdiff
path: root/src/game-server/character.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-03-05 19:33:04 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-03-05 19:33:04 +0100
commit8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75 (patch)
tree7e11c55c1ee70cbcee9788e70713bda3ef541716 /src/game-server/character.cpp
parent5ea5371434b76fc7511db4fa5b72e34046497943 (diff)
downloadmanaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.tar.gz
manaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.tar.bz2
manaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.tar.xz
manaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.zip
Implemented basic special recharge on the server.
Diffstat (limited to 'src/game-server/character.cpp')
-rw-r--r--src/game-server/character.cpp78
1 files changed, 69 insertions, 9 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index a17e3d89..d35124e5 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -72,15 +72,45 @@ Character::Character(MessageIn &msg):
}
setSize(16);
Inventory(this).initialize();
+
+ //give the character some specials for testing.
+ //TODO: get from quest vars and equipment
+ giveSpecial(1);
+ giveSpecial(2);
+ giveSpecial(3);
+
}
void Character::update()
{
+ //update character level
if (mRecalculateLevel)
{
mRecalculateLevel = false;
recalculateLevel();
}
+
+ //update special recharge
+ std::list<Special *> rechargeNeeded;
+ int numRechargeNeeded = 0;
+ for (std::map<int, Special*>::iterator i = mSpecials.begin(); i != mSpecials.end(); i++)
+ {
+ Special * s = i->second;
+ if (s->currentMana < s->neededMana)
+ {
+ rechargeNeeded.push_back(s);
+ numRechargeNeeded++;
+ }
+ }
+ if (numRechargeNeeded > 0)
+ {
+ int rechargePerSpecial = getModifiedAttribute(CHAR_ATTR_INTELLIGENCE) / numRechargeNeeded;
+ for (std::list<Special*>::iterator i = rechargeNeeded.begin(); i != rechargeNeeded.end(); i++)
+ {
+ (*i)->currentMana += rechargePerSpecial;
+ }
+ }
+
Being::update();
}
@@ -144,15 +174,31 @@ void Character::respawn()
void Character::useSpecial(int id)
{
- //TODO: look up which of its special attacks the character wants to use
- //TODO: check if the character is allowed to use it right now
-
- Script *s = getMap()->getScript();
- if (s) {
- s->prepare("cast");
- s->push(this);
- s->push(id);
- s->execute();
+ //check if the character may use this special in general
+ std::map<int, Special*>::iterator i = mSpecials.find(id);
+ if (i == mSpecials.end())
+ {
+ LOG_INFO("Character uses special "<<id<<" without autorisation.");
+ return;
+ }
+
+ //check if the special is currently recharged
+ Special *special = i->second;
+ if (special->currentMana < special->neededMana)
+ {
+ LOG_INFO("Character uses special "<<id<<" which is not recharged. ("
+ <<special->currentMana<<"/"<<special->neededMana<<")");
+ return;
+ }
+
+ //tell script engine to cast the spell
+ special->currentMana = 0;
+ Script *script = getMap()->getScript();
+ if (script) {
+ script->prepare("cast");
+ script->push(this);
+ script->push(id);
+ script->execute();
}
return;
@@ -471,3 +517,17 @@ Character::~Character()
}
}
+void Character::giveSpecial(int id)
+{
+ if (mSpecials.find(id) == mSpecials.end())
+ {
+ // TODO: get the needed mana from a SpecialDB
+ int neededMana;
+ if (id == 1) neededMana = 10;
+ if (id == 2) neededMana = 100;
+ if (id == 3) neededMana = 1000;
+
+ Special *s = new Special(neededMana);
+ mSpecials[id] = s;
+ }
+}