summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--src/game-server/item.cpp10
-rw-r--r--src/game-server/item.hpp14
-rw-r--r--src/game-server/itemmanager.cpp17
4 files changed, 44 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 0ad9568c..daecf9df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,14 @@
+2008-10-22 Chuck Miller <shadowmil@gmail.com>
+
+ * src/game-server/item.cpp, src/game-server/item.hpp
+ src/game-server/itemmanager.cpp: Added on item use scripts.
+
2008-10-22 David Athay <ko2fan@gmail.com>
- * src/scripting/lua.cpp, src/game-server/mapcomposite.cpp,
+ * src/scripting/lua.cpp, src/game-server/mapcomposite.cpp,
src/game-server/main-game.cpp: Fixed NPC id's starting from 0. Changed
time between reconnection attempts.
- * src/scripting/lua.cpp, src/game-server/npc.hpp,
+ * src/scripting/lua.cpp, src/game-server/npc.hpp,
src/game-server/npc.cpp: Added enabling and disabling NPCs.
2008-10-21 Roderic Morris <roderic@ccs.neu.edu>
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp
index 4d0530f8..5a5c3da0 100644
--- a/src/game-server/item.cpp
+++ b/src/game-server/item.cpp
@@ -29,6 +29,7 @@
#include "game-server/attackzone.hpp"
#include "game-server/being.hpp"
+#include "scripting/script.hpp"
WeaponType weaponTypeFromString (const std::string &name)
{
@@ -140,12 +141,19 @@ void ItemModifiers::cancelAttributes(Being *b) const
ItemClass::~ItemClass()
{
if (mAttackZone) delete mAttackZone;
+ if (mScript) delete mScript;
}
bool ItemClass::use(Being *itemUser)
{
if (mType != ITEM_USABLE) return false;
-
+ if (mScript)
+ {
+ mScript->prepare("item_use");
+ mScript->push(mDatabaseID);
+ mScript->push(itemUser);
+ mScript->execute();
+ }
mModifiers.applyAttributes(itemUser);
return true;
}
diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp
index e0d8943f..3878755e 100644
--- a/src/game-server/item.hpp
+++ b/src/game-server/item.hpp
@@ -27,6 +27,8 @@
#include <vector>
#include "game-server/object.hpp"
+#include "scripting/script.hpp"
+
class AttackZone;
class Being;
@@ -175,8 +177,8 @@ class ItemModifiers
class ItemClass
{
public:
- ItemClass(int id, ItemType type)
- : mDatabaseID(id), mType(type), mAttackZone(NULL)
+ ItemClass(int id, ItemType type, Script *s = NULL)
+ : mDatabaseID(id), mType(type), mAttackZone(NULL), mScript(NULL)
{}
~ItemClass();
@@ -260,6 +262,12 @@ class ItemClass
{ return mSpriteID; }
/**
+ * Sets the script that is to be used
+ */
+ void setScript(Script *s)
+ { mScript = s; }
+
+ /**
* Set attack zone (only needed when the item is a weapon)
*/
void setAttackZone(AttackZone* attackZone) { mAttackZone = attackZone; }
@@ -272,6 +280,8 @@ class ItemClass
private:
+ //Script for using items
+ Script *mScript;
// Item reference information
unsigned short mDatabaseID;
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 159b8356..65419011 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -33,6 +33,8 @@
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include <sstream>
+
typedef std::map< int, ItemClass * > ItemClasses;
static ItemClasses itemClasses; /**< Item reference */
static std::string itemReferenceFile;
@@ -179,10 +181,23 @@ void ItemManager::reload()
weight = 1;
}
+ Script *s;
+ //TODO: Clean this up some
+ std::stringstream filename;
+ filename << "scripts/items/" << id << ".lua";
+
+ if(ResourceManager::exists(filename.str())) //file exists!
+ {
+ LOG_INFO("Loading item script: " + filename.str());
+ s = Script::create("lua");
+ s->loadFile(filename.str());
+ }
+
+
item->setWeight(weight);
item->setCost(value);
item->setMaxPerSlot(maxPerSlot);
- //item->setScriptName(scriptName);
+ item->setScript(s);
item->setModifiers(modifiers);
item->setSpriteID(sprite ? sprite : id);
++nbItems;