summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-07-09 15:21:50 +0200
committerPhilipp Sehmisch <mana@crushnet.org>2010-07-09 15:22:11 +0200
commit26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (patch)
tree6d7ea0ebe8be228a61315f72122eed3f2f995a0b /src/game-server
parent2627acefebc688d9d9733abe23ba5aae79f66ea0 (diff)
downloadmanaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.gz
manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.bz2
manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.xz
manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.zip
Added LUA script bindings for manipulating the specials available to a character.
Added script call for getting the cost of a special (recharge only for now) Deleting specials works server-sided but the client isn't informed about it properly. Specials without recharge cost don't appear for the player. Both of these features require an additional netcode message. Reviewed-by: Freeyorp
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/character.cpp38
-rw-r--r--src/game-server/character.hpp32
-rw-r--r--src/game-server/main-game.cpp3
-rw-r--r--src/game-server/statusmanager.cpp8
4 files changed, 59 insertions, 22 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 258a7025..46ffa05e 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -232,14 +232,7 @@ void Character::useSpecial(int id)
//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();
- }
-
+ Script::perform_special_action(id, this);
mSpecialUpdateNeeded = true;
return;
}
@@ -661,14 +654,29 @@ 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);
+ Special *s = new Special();
+ Script::addDataToSpecial(id, s);
mSpecials[id] = s;
mSpecialUpdateNeeded = true;
}
}
+
+void Character::takeSpecial(int id)
+{
+ std::map<int, Special*>::iterator i = mSpecials.find(id);
+ if (i != mSpecials.end())
+ {
+ delete i->second;
+ mSpecials.erase(i);
+ mSpecialUpdateNeeded = true;
+ }
+}
+
+void Character::clearSpecials()
+{
+ for(std::map<int, Special*>::iterator i = mSpecials.begin(); i != mSpecials.end(); i++)
+ {
+ delete i->second;
+ }
+ mSpecials.clear();
+}
diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp
index 7b74c08e..fdee3645 100644
--- a/src/game-server/character.hpp
+++ b/src/game-server/character.hpp
@@ -39,10 +39,9 @@ class Trade;
struct Special
{
- Special(int needed)
+ Special()
{
currentMana = 0;
- neededMana = needed;
}
int currentMana;
int neededMana;
@@ -95,6 +94,21 @@ class Character : public Being
void giveSpecial(int id);
/**
+ * Removes all specials from character
+ */
+ void clearSpecials();
+
+ /**
+ * Checks if a character knows a special action
+ */
+ bool hasSpecial(int id) { return mSpecials.find(id) != mSpecials.end(); }
+
+ /**
+ * Removes an available special action
+ */
+ void takeSpecial(int id);
+
+ /**
* Gets client computer.
*/
GameClient *getClient() const
@@ -296,7 +310,7 @@ class Character : public Being
{ return mStatusEffects.end(); }
/**
- * used to serialized kill count
+ * used to serialize kill count
*/
int getKillCountSize() const
{ return mKillCount.size(); }
@@ -311,6 +325,18 @@ class Character : public Being
{ mKillCount[monsterId] = kills; }
/**
+ * used to serialize specials
+ */
+ int getSpecialSize() const
+ { return mSpecials.size(); }
+
+ const std::map<int, Special*>::const_iterator getSpecialBegin() const
+ { return mSpecials.begin(); }
+
+ const std::map<int, Special*>::const_iterator getSpecialEnd() const
+ { return mSpecials.end(); }
+
+ /**
* Gets total accumulated exp for skill
*/
int getExperience(int skill) const
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index d551035b..0901ce16 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -69,6 +69,7 @@ using utils::Logger;
#define DEFAULT_STATUSDB_FILE "mana-status-effect.xml"
#define DEFAULT_PERMISSION_FILE "permissions.xml"
#define DEFAULT_GLOBAL_EVENT_SCRIPT_FILE "scripts/global_events.lua"
+#define DEFAULT_SPECIAL_ACTIONS_SCRIPT_FILE "scripts/special_actions.lua"
static int const WORLD_TICK_SKIP = 2; /** tolerance for lagging behind in world calculation) **/
@@ -186,6 +187,8 @@ void initialize()
PermissionManager::initialize(DEFAULT_PERMISSION_FILE);
// Initialize global event script
LuaScript::load_global_event_script(DEFAULT_GLOBAL_EVENT_SCRIPT_FILE);
+ // Initialize special action script
+ LuaScript::load_special_actions_script(DEFAULT_SPECIAL_ACTIONS_SCRIPT_FILE);
// --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 0e64df6b..702fd103 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -30,8 +30,8 @@
#include <set>
#include <sstream>
-typedef std::map< int, StatusEffect * > StatusEffects;
-static StatusEffects statusEffects;
+typedef std::map< int, StatusEffect * > StatusEffectsMap;
+static StatusEffectsMap statusEffects;
static std::string statusReferenceFile;
void StatusManager::initialize(const std::string &file)
@@ -108,7 +108,7 @@ void StatusManager::reload()
void StatusManager::deinitialize()
{
- for (StatusEffects::iterator i = statusEffects.begin(),
+ for (StatusEffectsMap::iterator i = statusEffects.begin(),
i_end = statusEffects.end(); i != i_end; ++i)
{
delete i->second;
@@ -118,7 +118,7 @@ void StatusManager::deinitialize()
StatusEffect *StatusManager::getStatus(int statusId)
{
- StatusEffects::const_iterator i = statusEffects.find(statusId);
+ StatusEffectsMap::const_iterator i = statusEffects.find(statusId);
return i != statusEffects.end() ? i->second : NULL;
}