summaryrefslogtreecommitdiffstats
path: root/src
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
parent5ea5371434b76fc7511db4fa5b72e34046497943 (diff)
downloadmanaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.tar.gz
manaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.tar.xz
manaserv-8abc32b07bd86a45be9863ec9ae8ca1fdb4d3e75.zip
Implemented basic special recharge on the server.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/character.cpp78
-rw-r--r--src/game-server/character.hpp18
2 files changed, 87 insertions, 9 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index a17e3d8..d35124e 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;
+ }
+}
diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp
index 5ca899a..8e2cc95 100644
--- a/src/game-server/character.hpp
+++ b/src/game-server/character.hpp
@@ -35,6 +35,17 @@ class MessageOut;
class Point;
class Trade;
+struct Special
+{
+ Special(int needed)
+ {
+ currentMana = 0;
+ neededMana = needed;
+ }
+ int currentMana;
+ int neededMana;
+};
+
/**
* The representation of a player's character in the game world.
*/
@@ -72,6 +83,11 @@ class Character : public Being
void useSpecial(int id);
/**
+ * Allows a character to perform a special action
+ */
+ void giveSpecial(int id);
+
+ /**
* Gets client computer.
*/
GameClient *getClient() const
@@ -345,6 +361,8 @@ class Character : public Being
std::vector<unsigned int> mExperience; /**< experience collected for each skill.*/
+ std::map<int, Special*> mSpecials;
+
int mDatabaseID; /**< Character's database ID. */
unsigned char mGender; /**< Gender of the character. */
unsigned char mHairStyle; /**< Hair Style of the character. */