mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Lua work - loading works, I think checking for sub works. Calling subs is in the beginning stages and binding is starting
This commit is contained in:
parent
43d0350870
commit
dc045591e4
@ -120,10 +120,6 @@ IF(NOT MSVC)
|
||||
ADD_DEFINITIONS(-std=c++0x)
|
||||
ENDIF(NOT MSVC)
|
||||
|
||||
IF(EQEMU_ENABLE_RVALUE_MOVE)
|
||||
ADD_DEFINITIONS(-DEQEMU_RVALUE_MOVE)
|
||||
ENDIF(EQEMU_ENABLE_RVALUE_MOVE)
|
||||
|
||||
#Various definitions
|
||||
IF(EQEMU_BUILD_PERL)
|
||||
ADD_DEFINITIONS(-DEMBPERL)
|
||||
@ -148,7 +144,7 @@ ENDIF(EQEMU_BUILD_PERL)
|
||||
|
||||
IF(EQEMU_BUILD_LUA)
|
||||
FIND_PACKAGE(Lua51 REQUIRED)
|
||||
INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}")
|
||||
INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}" "common/luabridge")
|
||||
ENDIF(EQEMU_BUILD_LUA)
|
||||
|
||||
INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${MySQL_INCLUDE_DIR}")
|
||||
|
||||
4759
common/luabridge/LuaBridge.h
Normal file
4759
common/luabridge/LuaBridge.h
Normal file
File diff suppressed because it is too large
Load Diff
348
common/luabridge/RefCountedObject.h
Normal file
348
common/luabridge/RefCountedObject.h
Normal file
@ -0,0 +1,348 @@
|
||||
//==============================================================================
|
||||
/*
|
||||
https://github.com/vinniefalco/LuaBridge
|
||||
https://github.com/vinniefalco/LuaBridgeDemo
|
||||
|
||||
Copyright (C) 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
This is a derivative work used by permission from part of
|
||||
JUCE, available at http://www.rawaterialsoftware.com
|
||||
|
||||
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
This file incorporates work covered by the following copyright and
|
||||
permission notice:
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef LUABRIDGE_REFCOUNTEDOBJECT_HEADER
|
||||
#define LUABRIDGE_REFCOUNTEDOBJECT_HEADER
|
||||
|
||||
#if !defined (LUABRIDGE_LUABRIDGE_HEADER)
|
||||
#error LuaBridge.h must be included before including this file
|
||||
#endif
|
||||
|
||||
//#define LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Adds reference-counting to an object.
|
||||
|
||||
To add reference-counting to a class, derive it from this class, and
|
||||
use the RefCountedObjectPtr class to point to it.
|
||||
|
||||
e.g. @code
|
||||
class MyClass : public RefCountedObjectType
|
||||
{
|
||||
void foo();
|
||||
|
||||
// This is a neat way of declaring a typedef for a pointer class,
|
||||
// rather than typing out the full templated name each time..
|
||||
typedef RefCountedObjectPtr<MyClass> Ptr;
|
||||
};
|
||||
|
||||
MyClass::Ptr p = new MyClass();
|
||||
MyClass::Ptr p2 = p;
|
||||
p = 0;
|
||||
p2->foo();
|
||||
@endcode
|
||||
|
||||
Once a new RefCountedObjectType has been assigned to a pointer, be
|
||||
careful not to delete the object manually.
|
||||
*/
|
||||
template <class CounterType>
|
||||
class RefCountedObjectType
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Increments the object's reference count.
|
||||
|
||||
This is done automatically by the smart pointer, but is public just
|
||||
in case it's needed for nefarious purposes.
|
||||
*/
|
||||
inline void incReferenceCount() const
|
||||
{
|
||||
++refCount;
|
||||
}
|
||||
|
||||
/** Decreases the object's reference count.
|
||||
|
||||
If the count gets to zero, the object will be deleted.
|
||||
*/
|
||||
inline void decReferenceCount() const
|
||||
{
|
||||
assert (getReferenceCount() > 0);
|
||||
|
||||
if (--refCount == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
/** Returns the object's current reference count. */
|
||||
inline int getReferenceCount() const
|
||||
{
|
||||
return static_cast <int> (refCount);
|
||||
}
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
/** Creates the reference-counted object (with an initial ref count of zero). */
|
||||
RefCountedObjectType() : refCount ()
|
||||
{
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~RefCountedObjectType()
|
||||
{
|
||||
// it's dangerous to delete an object that's still referenced by something else!
|
||||
assert (getReferenceCount() == 0);
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
CounterType mutable refCount;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A smart-pointer class which points to a reference-counted object.
|
||||
|
||||
The template parameter specifies the class of the object you want to point to - the easiest
|
||||
way to make a class reference-countable is to simply make it inherit from RefCountedObjectType,
|
||||
but if you need to, you could roll your own reference-countable class by implementing a pair of
|
||||
mathods called incReferenceCount() and decReferenceCount().
|
||||
|
||||
When using this class, you'll probably want to create a typedef to abbreviate the full
|
||||
templated name - e.g.
|
||||
|
||||
@code typedef RefCountedObjectPtr <MyClass> MyClassPtr;@endcode
|
||||
*/
|
||||
template <class ReferenceCountedObjectClass>
|
||||
class RefCountedObjectPtr
|
||||
{
|
||||
public:
|
||||
/** The class being referenced by this pointer. */
|
||||
typedef ReferenceCountedObjectClass ReferencedType;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a pointer to a null object. */
|
||||
inline RefCountedObjectPtr() : referencedObject (0)
|
||||
{
|
||||
}
|
||||
|
||||
/** Creates a pointer to an object.
|
||||
|
||||
This will increment the object's reference-count if it is non-null.
|
||||
*/
|
||||
inline RefCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject)
|
||||
: referencedObject (refCountedObject)
|
||||
{
|
||||
if (refCountedObject != 0)
|
||||
refCountedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
/** Copies another pointer.
|
||||
This will increment the object's reference-count (if it is non-null).
|
||||
*/
|
||||
inline RefCountedObjectPtr (const RefCountedObjectPtr& other)
|
||||
: referencedObject (other.referencedObject)
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
#if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
/** Takes-over the object from another pointer. */
|
||||
inline RefCountedObjectPtr (RefCountedObjectPtr&& other)
|
||||
: referencedObject (other.referencedObject)
|
||||
{
|
||||
other.referencedObject = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Copies another pointer.
|
||||
This will increment the object's reference-count (if it is non-null).
|
||||
*/
|
||||
template <class DerivedClass>
|
||||
inline RefCountedObjectPtr (const RefCountedObjectPtr<DerivedClass>& other)
|
||||
: referencedObject (static_cast <ReferenceCountedObjectClass*> (other.getObject()))
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
RefCountedObjectPtr& operator= (const RefCountedObjectPtr& other)
|
||||
{
|
||||
return operator= (other.referencedObject);
|
||||
}
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
template <class DerivedClass>
|
||||
RefCountedObjectPtr& operator= (const RefCountedObjectPtr<DerivedClass>& other)
|
||||
{
|
||||
return operator= (static_cast <ReferenceCountedObjectClass*> (other.getObject()));
|
||||
}
|
||||
|
||||
#if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
/** Takes-over the object from another pointer. */
|
||||
RefCountedObjectPtr& operator= (RefCountedObjectPtr&& other)
|
||||
{
|
||||
std::swap (referencedObject, other.referencedObject);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
RefCountedObjectPtr& operator= (ReferenceCountedObjectClass* const newObject)
|
||||
{
|
||||
if (referencedObject != newObject)
|
||||
{
|
||||
if (newObject != 0)
|
||||
newObject->incReferenceCount();
|
||||
|
||||
ReferenceCountedObjectClass* const oldObject = referencedObject;
|
||||
referencedObject = newObject;
|
||||
|
||||
if (oldObject != 0)
|
||||
oldObject->decReferenceCount();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Destructor.
|
||||
|
||||
This will decrement the object's reference-count, and may delete it if it
|
||||
gets to zero.
|
||||
*/
|
||||
inline ~RefCountedObjectPtr()
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->decReferenceCount();
|
||||
}
|
||||
|
||||
/** Returns the object that this pointer references.
|
||||
The pointer returned may be zero, of course.
|
||||
*/
|
||||
inline operator ReferenceCountedObjectClass*() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
// the -> operator is called on the referenced object
|
||||
inline ReferenceCountedObjectClass* operator->() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
/** Returns the object that this pointer references.
|
||||
The pointer returned may be zero, of course.
|
||||
*/
|
||||
inline ReferenceCountedObjectClass* getObject() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
ReferenceCountedObjectClass* referencedObject;
|
||||
};
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, ReferenceCountedObjectClass* const object2)
|
||||
{
|
||||
return object1.getObject() == object2;
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, const RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1.getObject() == object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (ReferenceCountedObjectClass* object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1 == object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, const ReferenceCountedObjectClass* object2)
|
||||
{
|
||||
return object1.getObject() != object2;
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1.getObject() != object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (ReferenceCountedObjectClass* object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1 != object2.getObject();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
namespace luabridge
|
||||
{
|
||||
|
||||
template <class T>
|
||||
struct ContainerTraits <RefCountedObjectPtr <T> >
|
||||
{
|
||||
typedef T Type;
|
||||
|
||||
static T* get (RefCountedObjectPtr <T> const& c)
|
||||
{
|
||||
return c.getObject ();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
#endif
|
||||
|
||||
248
common/luabridge/RefCountedPtr.h
Normal file
248
common/luabridge/RefCountedPtr.h
Normal file
@ -0,0 +1,248 @@
|
||||
//==============================================================================
|
||||
/*
|
||||
https://github.com/vinniefalco/LuaBridge
|
||||
https://github.com/vinniefalco/LuaBridgeDemo
|
||||
|
||||
Copyright (C) 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Copyright (C) 2007, Nathan Reed
|
||||
|
||||
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef LUABRIDGE_REFCOUNTEDPTR_HEADER
|
||||
#define LUABRIDGE_REFCOUNTEDPTR_HEADER
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <hash_map>
|
||||
#else
|
||||
# include <stdint.h>
|
||||
# include <ext/hash_map>
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Support for our RefCountedPtr.
|
||||
*/
|
||||
struct RefCountedPtrBase
|
||||
{
|
||||
// Declaration of container for the refcounts
|
||||
#ifdef _MSC_VER
|
||||
typedef stdext::hash_map <const void *, int> RefCountsType;
|
||||
#else
|
||||
struct ptr_hash
|
||||
{
|
||||
size_t operator () (const void * const v) const
|
||||
{
|
||||
static __gnu_cxx::hash<unsigned int> H;
|
||||
return H(uintptr_t(v));
|
||||
}
|
||||
};
|
||||
typedef __gnu_cxx::hash_map<const void *, int, ptr_hash> RefCountsType;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
inline RefCountsType& getRefCounts ()
|
||||
{
|
||||
static RefCountsType refcounts;
|
||||
return refcounts ;
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A reference counted smart pointer.
|
||||
|
||||
The api is compatible with boost::RefCountedPtr and std::RefCountedPtr, in the
|
||||
sense that it implements a strict subset of the functionality.
|
||||
|
||||
This implementation uses a hash table to look up the reference count
|
||||
associated with a particular pointer.
|
||||
|
||||
@tparam T The class type.
|
||||
|
||||
@todo Decompose RefCountedPtr using a policy. At a minimum, the underlying
|
||||
reference count should be policy based (to support atomic operations)
|
||||
and the delete behavior should be policy based (to support custom
|
||||
disposal methods).
|
||||
|
||||
@todo Provide an intrusive version of RefCountedPtr.
|
||||
*/
|
||||
template <class T>
|
||||
class RefCountedPtr : private RefCountedPtrBase
|
||||
{
|
||||
public:
|
||||
template <typename Other>
|
||||
struct rebind
|
||||
{
|
||||
typedef RefCountedPtr <Other> other;
|
||||
};
|
||||
|
||||
/** Construct as nullptr or from existing pointer to T.
|
||||
|
||||
@param p The optional, existing pointer to assign from.
|
||||
*/
|
||||
RefCountedPtr (T* p = 0) : m_p (p)
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Construct from another RefCountedPtr.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
*/
|
||||
RefCountedPtr (RefCountedPtr <T> const& rhs) : m_p (rhs.get())
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Construct from a RefCountedPtr of a different type.
|
||||
|
||||
@invariant A pointer to U must be convertible to a pointer to T.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
@tparam U The other object type.
|
||||
*/
|
||||
template <typename U>
|
||||
RefCountedPtr (RefCountedPtr <U> const& rhs) : m_p (static_cast <T*> (rhs.get()))
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Release the object.
|
||||
|
||||
If there are no more references then the object is deleted.
|
||||
*/
|
||||
~RefCountedPtr ()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
/** Assign from another RefCountedPtr.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
@return A reference to the RefCountedPtr.
|
||||
*/
|
||||
RefCountedPtr <T>& operator= (RefCountedPtr <T> const& rhs)
|
||||
{
|
||||
if (m_p != rhs.m_p)
|
||||
{
|
||||
reset ();
|
||||
m_p = rhs.m_p;
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Assign from another RefCountedPtr of a different type.
|
||||
|
||||
@note A pointer to U must be convertible to a pointer to T.
|
||||
|
||||
@tparam U The other object type.
|
||||
@param rhs The other RefCountedPtr to assign from.
|
||||
@return A reference to the RefCountedPtr.
|
||||
*/
|
||||
template <typename U>
|
||||
RefCountedPtr <T>& operator= (RefCountedPtr <U> const& rhs)
|
||||
{
|
||||
reset ();
|
||||
m_p = static_cast <T*> (rhs.get());
|
||||
++getRefCounts () [m_p];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* get () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* operator* () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* operator-> () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Determine the number of references.
|
||||
|
||||
@note This is not thread-safe.
|
||||
|
||||
@return The number of active references.
|
||||
*/
|
||||
long use_count () const
|
||||
{
|
||||
return getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Release the pointer.
|
||||
|
||||
The reference count is decremented. If the reference count reaches
|
||||
zero, the object is deleted.
|
||||
*/
|
||||
void reset ()
|
||||
{
|
||||
if (m_p != 0)
|
||||
{
|
||||
if (--getRefCounts () [m_p] <= 0)
|
||||
delete m_p;
|
||||
|
||||
m_p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
||||
namespace luabridge
|
||||
{
|
||||
|
||||
template <class T>
|
||||
struct ContainerTraits <RefCountedPtr <T> >
|
||||
{
|
||||
typedef T Type;
|
||||
|
||||
static T* get (RefCountedPtr <T> const& c)
|
||||
{
|
||||
return c.get ();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -31,6 +31,8 @@ SET(zone_sources
|
||||
horse.cpp
|
||||
inventory.cpp
|
||||
loottables.cpp
|
||||
lua_entity.cpp
|
||||
lua_mob.cpp
|
||||
lua_parser.cpp
|
||||
Map.cpp
|
||||
merc.cpp
|
||||
@ -110,6 +112,8 @@ SET(zone_headers
|
||||
guild_mgr.h
|
||||
hate_list.h
|
||||
horse.h
|
||||
lua_entity.h
|
||||
lua_mob.h
|
||||
lua_parser.h
|
||||
map.h
|
||||
masterentity.h
|
||||
|
||||
@ -215,18 +215,19 @@ bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname)
|
||||
return false;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventNPC(QuestEventID evt, NPC *npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
EventNPCLocal(evt, npc, init, data, extra_data);
|
||||
double QuestParserCollection::EventNPC(QuestEventID evt, NPC *npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
double ret = EventNPCLocal(evt, npc, init, data, extra_data);
|
||||
EventNPCGlobal(evt, npc, init, data, extra_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
double QuestParserCollection::EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
std::map<uint32, uint32>::iterator iter = _npc_quest_status.find(npc->GetNPCTypeID());
|
||||
if(iter != _npc_quest_status.end()) {
|
||||
//loaded or failed to load
|
||||
if(iter->second != QuestFailedToLoad) {
|
||||
std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(iter->second);
|
||||
qiter->second->EventNPC(evt, npc, init, data, extra_data);
|
||||
return qiter->second->EventNPC(evt, npc, init, data, extra_data);
|
||||
}
|
||||
} else {
|
||||
std::string filename;
|
||||
@ -234,11 +235,12 @@ void QuestParserCollection::EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init,
|
||||
if(qi) {
|
||||
_npc_quest_status[npc->GetNPCTypeID()] = qi->GetIdentifier();
|
||||
qi->LoadNPCScript(filename, npc->GetNPCTypeID());
|
||||
qi->EventNPC(evt, npc, init, data, extra_data);
|
||||
return qi->EventNPC(evt, npc, init, data, extra_data);
|
||||
} else {
|
||||
_npc_quest_status[npc->GetNPCTypeID()] = QuestFailedToLoad;
|
||||
}
|
||||
}
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
@ -258,26 +260,28 @@ void QuestParserCollection::EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init
|
||||
}
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
EventPlayerLocal(evt, client, data, extra_data);
|
||||
double QuestParserCollection::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
double ret = EventPlayerLocal(evt, client, data, extra_data);
|
||||
EventPlayerGlobal(evt, client, data, extra_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
double QuestParserCollection::EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
if(_player_quest_status == QuestUnloaded) {
|
||||
std::string filename;
|
||||
QuestInterface *qi = GetQIByPlayerQuest(filename);
|
||||
if(qi) {
|
||||
_player_quest_status = qi->GetIdentifier();
|
||||
qi->LoadPlayerScript(filename);
|
||||
qi->EventPlayer(evt, client, data, extra_data);
|
||||
return qi->EventPlayer(evt, client, data, extra_data);
|
||||
}
|
||||
} else {
|
||||
if(_player_quest_status != QuestFailedToLoad) {
|
||||
std::map<uint32, QuestInterface*>::iterator iter = _interfaces.find(_player_quest_status);
|
||||
iter->second->EventPlayer(evt, client, data, extra_data);
|
||||
return iter->second->EventPlayer(evt, client, data, extra_data);
|
||||
}
|
||||
}
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventPlayerGlobal(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
@ -297,7 +301,7 @@ void QuestParserCollection::EventPlayerGlobal(QuestEventID evt, Client *client,
|
||||
}
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) {
|
||||
double QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) {
|
||||
std::string item_script;
|
||||
if(evt == EVENT_SCALE_CALC || evt == EVENT_ITEM_ENTERZONE) {
|
||||
item_script = item->GetItem()->CharmFile;
|
||||
@ -313,7 +317,7 @@ void QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst
|
||||
//loaded or failed to load
|
||||
if(iter->second != QuestFailedToLoad) {
|
||||
std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(iter->second);
|
||||
qiter->second->EventItem(evt, client, item, objid, extra_data);
|
||||
return qiter->second->EventItem(evt, client, item, objid, extra_data);
|
||||
}
|
||||
} else {
|
||||
std::string filename;
|
||||
@ -321,20 +325,21 @@ void QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst
|
||||
if(qi) {
|
||||
_item_quest_status[item_script] = qi->GetIdentifier();
|
||||
qi->LoadItemScript(filename, item_script);
|
||||
qi->EventItem(evt, client, item, objid, extra_data);
|
||||
return qi->EventItem(evt, client, item, objid, extra_data);
|
||||
} else {
|
||||
_item_quest_status[item_script] = QuestFailedToLoad;
|
||||
}
|
||||
}
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
void QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) {
|
||||
double QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) {
|
||||
std::map<uint32, uint32>::iterator iter = _spell_quest_status.find(spell_id);
|
||||
if(iter != _spell_quest_status.end()) {
|
||||
//loaded or failed to load
|
||||
if(iter->second != QuestFailedToLoad) {
|
||||
std::map<uint32, QuestInterface*>::iterator qiter = _interfaces.find(iter->second);
|
||||
qiter->second->EventSpell(evt, npc, client, spell_id, extra_data);
|
||||
return qiter->second->EventSpell(evt, npc, client, spell_id, extra_data);
|
||||
}
|
||||
} else {
|
||||
std::string filename;
|
||||
@ -342,11 +347,12 @@ void QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *clien
|
||||
if(qi) {
|
||||
_spell_quest_status[spell_id] = qi->GetIdentifier();
|
||||
qi->LoadSpellScript(filename, spell_id);
|
||||
qi->EventSpell(evt, npc, client, spell_id, extra_data);
|
||||
return qi->EventSpell(evt, npc, client, spell_id, extra_data);
|
||||
} else {
|
||||
_spell_quest_status[spell_id] = QuestFailedToLoad;
|
||||
}
|
||||
}
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
QuestInterface *QuestParserCollection::GetQIByNPCQuest(uint32 npcid, std::string &filename) {
|
||||
|
||||
@ -48,10 +48,10 @@ public:
|
||||
bool SpellHasQuestSub(uint32 spell_id, const char *subname);
|
||||
bool ItemHasQuestSub(ItemInst *itm, const char *subname);
|
||||
|
||||
void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
|
||||
void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
|
||||
double EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
|
||||
double EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
|
||||
|
||||
private:
|
||||
bool HasQuestSubLocal(uint32 npcid, const char *subname);
|
||||
@ -59,9 +59,9 @@ private:
|
||||
bool PlayerHasQuestSubLocal(const char *subname);
|
||||
bool PlayerHasQuestSubGlobal(const char *subname);
|
||||
|
||||
void EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
double EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
void EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
void EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
double EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
void EventPlayerGlobal(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
|
||||
QuestInterface *GetQIByNPCQuest(uint32 npcid, std::string &filename);
|
||||
|
||||
@ -1425,6 +1425,10 @@ void Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_
|
||||
if(dead)
|
||||
return; //cant die more than once...
|
||||
|
||||
if(parse->EventPlayer(EVENT_DEATH, this, "", 0) <= 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int exploss;
|
||||
|
||||
mlog(COMBAT__HITS, "Fatal blow dealt by %s with %d damage, spell %d, skill %d", killerMob ? killerMob->GetName() : "Unknown", damage, spell, attack_skill);
|
||||
@ -1472,8 +1476,6 @@ void Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_
|
||||
GetMerc()->Suspend();
|
||||
}
|
||||
|
||||
parse->EventPlayer(EVENT_DEATH, this, "", 0);
|
||||
|
||||
if (killerMob != nullptr)
|
||||
{
|
||||
if (killerMob->IsNPC()) {
|
||||
|
||||
@ -10665,11 +10665,11 @@ void Client::Handle_OP_PopupResponse(const EQApplicationPacket *app) {
|
||||
char *buf = 0;
|
||||
MakeAnyLenString(&buf, "%d", prs->popupid);
|
||||
|
||||
parse->EventPlayer(EVENT_POPUPRESPONSE, this, buf, 0);
|
||||
parse->EventPlayer(EVENT_POPUP_RESPONSE, this, buf, 0);
|
||||
|
||||
Mob* Target = GetTarget();
|
||||
if(Target && Target->IsNPC()) {
|
||||
parse->EventNPC(EVENT_POPUPRESPONSE, Target->CastToNPC(), this, buf, 0);
|
||||
parse->EventNPC(EVENT_POPUP_RESPONSE, Target->CastToNPC(), this, buf, 0);
|
||||
}
|
||||
|
||||
safe_delete_array(buf);
|
||||
|
||||
@ -63,7 +63,7 @@ const char *QuestEventSubroutines[_LargestEventID] = {
|
||||
"EVENT_TASK_FAIL",
|
||||
"EVENT_AGGRO_SAY",
|
||||
"EVENT_PLAYER_PICKUP",
|
||||
"EVENT_POPUPRESPONSE",
|
||||
"EVENT_POPUP_RESPONSE",
|
||||
"EVENT_PROXIMITY_SAY",
|
||||
"EVENT_CAST",
|
||||
"EVENT_SCALE_CALC",
|
||||
@ -1207,7 +1207,7 @@ void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_POPUPRESPONSE:{
|
||||
case EVENT_POPUP_RESPONSE:{
|
||||
ExportVar(package_name.c_str(), "popupid", data);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -106,7 +106,8 @@ public:
|
||||
const Trap* CastToTrap() const;
|
||||
const Beacon* CastToBeacon() const;
|
||||
|
||||
inline const uint16& GetID() const{ return id; }
|
||||
inline const uint16& GetID() const { return id; }
|
||||
|
||||
virtual const char* GetName() { return ""; }
|
||||
virtual void DBAWComplete(uint8 workpt_b1, DBAsyncWork* dbaw) { pDBAsyncWorkID = 0; }
|
||||
bool CheckCoordLosNoZLeaps(float cur_x, float cur_y, float cur_z, float trg_x, float trg_y, float trg_z, float perwalk=1);
|
||||
|
||||
@ -32,7 +32,7 @@ typedef enum {
|
||||
EVENT_TASK_FAIL,
|
||||
EVENT_AGGRO_SAY,
|
||||
EVENT_PLAYER_PICKUP,
|
||||
EVENT_POPUPRESPONSE,
|
||||
EVENT_POPUP_RESPONSE,
|
||||
EVENT_PROXIMITY_SAY,
|
||||
EVENT_CAST,
|
||||
EVENT_SCALE_CALC,
|
||||
|
||||
83
zone/lua_entity.cpp
Normal file
83
zone/lua_entity.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
#include "masterentity.h"
|
||||
#include "lua_entity.h"
|
||||
#include "lua_mob.h"
|
||||
|
||||
bool Lua_Entity::IsClient() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsClient();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsNPC() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsNPC();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsMob() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsMob();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsMerc() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsMerc();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsCorpse() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsCorpse();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsPlayerCorpse() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsPlayerCorpse();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsNPCCorpse() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsNPCCorpse();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsObject() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsObject();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsDoor() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsDoor();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsTrap() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsTrap();
|
||||
}
|
||||
|
||||
bool Lua_Entity::IsBeacon() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->IsBeacon();
|
||||
}
|
||||
|
||||
int Lua_Entity::GetID() {
|
||||
Entity *ent = reinterpret_cast<Entity*>(d_);
|
||||
return ent->GetID();
|
||||
}
|
||||
|
||||
Lua_Mob Lua_Entity::CastToMob() {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
return Lua_Mob(m);
|
||||
}
|
||||
|
||||
|
||||
//Lua_Client* CastToClient();
|
||||
//Lua_NPC* CastToNPC();
|
||||
//Lua_Mob* CastToMob();
|
||||
//Lua_Merc* CastToMerc();
|
||||
//Lua_Corpse* CastToCorpse();
|
||||
//Lua_Object* CastToObject();
|
||||
//Lua_Doors* CastToDoors();
|
||||
//Lua_Trap* CastToTrap();
|
||||
//Lua_Beacon* CastToBeacon();
|
||||
|
||||
#endif
|
||||
50
zone/lua_entity.h
Normal file
50
zone/lua_entity.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef EQEMU_LUA_ENTITY_H
|
||||
#define EQEMU_LUA_ENTITY_H
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
class Entity;
|
||||
//class Lua_Client;
|
||||
//class Lua_NPC;
|
||||
class Lua_Mob;
|
||||
//class Lua_Merc;
|
||||
//class Lua_Corpse;
|
||||
//class Lua_Object;
|
||||
//class Lua_Doors;
|
||||
//class Lua_Trap;
|
||||
//class Lua_Beacon;
|
||||
|
||||
class Lua_Entity
|
||||
{
|
||||
public:
|
||||
Lua_Entity() { }
|
||||
Lua_Entity(Entity *d) : d_(d) { }
|
||||
virtual ~Lua_Entity() { }
|
||||
|
||||
bool IsClient();
|
||||
bool IsNPC();
|
||||
bool IsMob();
|
||||
bool IsMerc();
|
||||
bool IsCorpse();
|
||||
bool IsPlayerCorpse();
|
||||
bool IsNPCCorpse();
|
||||
bool IsObject();
|
||||
bool IsDoor();
|
||||
bool IsTrap();
|
||||
bool IsBeacon();
|
||||
int GetID();
|
||||
|
||||
//Lua_Client CastToClient();
|
||||
//Lua_NPC CastToNPC();
|
||||
Lua_Mob CastToMob();
|
||||
//Lua_Merc CastToMerc();
|
||||
//Lua_Corpse CastToCorpse();
|
||||
//Lua_Object CastToObject();
|
||||
//Lua_Doors CastToDoors();
|
||||
//Lua_Trap CastToTrap();
|
||||
//Lua_Beacon CastToBeacon();
|
||||
|
||||
void *d_;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
11
zone/lua_mob.cpp
Normal file
11
zone/lua_mob.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
#include "masterentity.h"
|
||||
#include "lua_mob.h"
|
||||
|
||||
const char *Lua_Mob::GetName() {
|
||||
Mob *m = reinterpret_cast<Mob*>(d_);
|
||||
return m->GetName();
|
||||
}
|
||||
|
||||
#endif
|
||||
20
zone/lua_mob.h
Normal file
20
zone/lua_mob.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef EQEMU_LUA_MOB_H
|
||||
#define EQEMU_LUA_MOB_H
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
#include "lua_entity.h"
|
||||
|
||||
class Mob;
|
||||
|
||||
class Lua_Mob : public Lua_Entity
|
||||
{
|
||||
public:
|
||||
Lua_Mob() { }
|
||||
Lua_Mob(Mob *d) { this->d_ = d; }
|
||||
virtual ~Lua_Mob() { }
|
||||
|
||||
const char *GetName();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,4 +1,320 @@
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
#include "lua_parser.h"
|
||||
#include <ctype.h>
|
||||
#include <sstream>
|
||||
|
||||
#include <lua.hpp>
|
||||
#include <LuaBridge.h>
|
||||
|
||||
#include "masterentity.h"
|
||||
#include "lua_entity.h"
|
||||
#include "lua_mob.h"
|
||||
|
||||
const char *LuaEvents[_LargestEventID] = {
|
||||
"event_say",
|
||||
"event_item",
|
||||
"event_death",
|
||||
"event_spawn",
|
||||
"event_attack",
|
||||
"event_combat",
|
||||
"event_aggro",
|
||||
"event_slay",
|
||||
"event_npc_slay",
|
||||
"event_waypoint_arrive",
|
||||
"event_waypoint_depart",
|
||||
"event_timer",
|
||||
"event_signal",
|
||||
"event_hp",
|
||||
"event_enter",
|
||||
"event_exit",
|
||||
"event_enterzone",
|
||||
"event_clickdoor",
|
||||
"event_loot",
|
||||
"event_zone",
|
||||
"event_level_up",
|
||||
"event_killed_merit",
|
||||
"event_cast_on",
|
||||
"event_taskaccepted",
|
||||
"event_task_stage_complete",
|
||||
"event_task_update",
|
||||
"event_task_complete",
|
||||
"event_task_fail",
|
||||
"event_aggro_say",
|
||||
"event_player_pickup",
|
||||
"event_popup_response",
|
||||
"event_proximity_say",
|
||||
"event_cast",
|
||||
"event_scale_calc",
|
||||
"event_item_enterzone",
|
||||
"event_target_change",
|
||||
"event_hate_list",
|
||||
"event_spell_effect_client",
|
||||
"event_spell_effect_npc",
|
||||
"event_spell_effect_buff_tic_client",
|
||||
"event_spell_effect_buff_tic_npc",
|
||||
"event_spell_effect_translocate_complete",
|
||||
"event_combine_success",
|
||||
"event_combine_failure",
|
||||
"event_item_click",
|
||||
"event_item_click_cast",
|
||||
"event_group_change",
|
||||
"event_forage_success",
|
||||
"event_forage_failure",
|
||||
"event_fish_start",
|
||||
"event_fish_success",
|
||||
"event_fish_failure",
|
||||
"event_click_object",
|
||||
"event_discover_item",
|
||||
"event_disconnect",
|
||||
"event_connect",
|
||||
"event_item_tick",
|
||||
"event_duel_win",
|
||||
"event_duel_lose"
|
||||
};
|
||||
|
||||
LuaParser::LuaParser() {
|
||||
}
|
||||
|
||||
LuaParser::~LuaParser() {
|
||||
ClearStates();
|
||||
}
|
||||
|
||||
double LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
if(evt >= _LargestEventID) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
if(!npc) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
std::stringstream package_name;
|
||||
package_name << "npc_" << npc->GetNPCTypeID();
|
||||
|
||||
lua_State *L = nullptr;
|
||||
auto iter = states_.find(package_name.str());
|
||||
if(iter == states_.end()) {
|
||||
return 100.0;
|
||||
}
|
||||
L = iter->second;
|
||||
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, LuaEvents[evt]);
|
||||
int arg_count = 1;
|
||||
int ret_count = 0;
|
||||
|
||||
Lua_Entity ent(npc);
|
||||
|
||||
luabridge::Stack<Lua_Entity>::push(L, ent);
|
||||
if(lua_pcall(L, arg_count, ret_count, 0)) {
|
||||
printf("Error: %s\n", lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
double LuaParser::EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
double LuaParser::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
double LuaParser::EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
double LuaParser::EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
double LuaParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
bool LuaParser::HasQuestSub(uint32 npc_id, const char *subname) {
|
||||
std::stringstream package_name;
|
||||
package_name << "npc_" << npc_id;
|
||||
|
||||
return HasFunction(subname, package_name.str());
|
||||
}
|
||||
|
||||
bool LuaParser::HasGlobalQuestSub(const char *subname) {
|
||||
return HasFunction(subname, "global_npc");
|
||||
}
|
||||
|
||||
bool LuaParser::PlayerHasQuestSub(const char *subname) {
|
||||
return HasFunction(subname, "player");
|
||||
}
|
||||
|
||||
bool LuaParser::GlobalPlayerHasQuestSub(const char *subname) {
|
||||
return HasFunction(subname, "global_player");
|
||||
}
|
||||
|
||||
bool LuaParser::SpellHasQuestSub(uint32 spell_id, const char *subname) {
|
||||
std::stringstream package_name;
|
||||
package_name << "spell_" << spell_id;
|
||||
|
||||
return HasFunction(subname, package_name.str());
|
||||
}
|
||||
|
||||
bool LuaParser::ItemHasQuestSub(ItemInst *itm, const char *subname) {
|
||||
std::stringstream package_name;
|
||||
package_name << "item_";
|
||||
|
||||
std::stringstream item_name;
|
||||
const Item_Struct* item = itm->GetItem();
|
||||
if(strcmp("EVENT_SCALE_CALC", subname) == 0 || strcmp("EVENT_ITEM_ENTERZONE", subname) == 0)
|
||||
{
|
||||
item_name << item->CharmFile;
|
||||
}
|
||||
else if(strcmp("EVENT_ITEM_CLICK", subname) == 0 || strcmp("EVENT_ITEM_CLICK_CAST", subname) == 0 )
|
||||
{
|
||||
item_name << "script_";
|
||||
item_name << item->ScriptFileID;
|
||||
}
|
||||
else
|
||||
{
|
||||
item_name << "item_";
|
||||
item_name << item->ID;
|
||||
}
|
||||
|
||||
package_name << item_name;
|
||||
return HasFunction(subname, package_name.str());
|
||||
}
|
||||
|
||||
void LuaParser::LoadNPCScript(std::string filename, int npc_id) {
|
||||
std::stringstream package_name;
|
||||
package_name << "npc_" << npc_id;
|
||||
|
||||
LoadScript(filename, package_name.str());
|
||||
}
|
||||
|
||||
void LuaParser::LoadGlobalNPCScript(std::string filename) {
|
||||
LoadScript(filename, "global_npc");
|
||||
}
|
||||
|
||||
void LuaParser::LoadPlayerScript(std::string filename) {
|
||||
LoadScript(filename, "player");
|
||||
}
|
||||
|
||||
void LuaParser::LoadGlobalPlayerScript(std::string filename) {
|
||||
LoadScript(filename, "global_player");
|
||||
}
|
||||
|
||||
void LuaParser::LoadItemScript(std::string filename, std::string item_script) {
|
||||
std::stringstream package_name;
|
||||
package_name << "item_" << item_script;
|
||||
|
||||
LoadScript(filename, package_name.str());
|
||||
}
|
||||
|
||||
void LuaParser::LoadSpellScript(std::string filename, uint32 spell_id) {
|
||||
std::stringstream package_name;
|
||||
package_name << "spell_" << spell_id;
|
||||
|
||||
LoadScript(filename, package_name.str());
|
||||
}
|
||||
|
||||
void LuaParser::AddVar(std::string name, std::string val) {
|
||||
vars_[name] = val;
|
||||
}
|
||||
|
||||
std::string LuaParser::GetVar(std::string name) {
|
||||
auto iter = vars_.find(name);
|
||||
if(iter != vars_.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void LuaParser::ReloadQuests() {
|
||||
ClearStates();
|
||||
}
|
||||
|
||||
void LuaParser::LoadScript(std::string filename, std::string package_name) {
|
||||
auto iter = states_.find(package_name);
|
||||
if(iter != states_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
lua_State *L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
//lua_pushnil(L);
|
||||
//lua_setglobal(L, "os");
|
||||
//
|
||||
//lua_pushnil(L);
|
||||
//lua_setglobal(L, "io");
|
||||
|
||||
MapFunctions(L);
|
||||
|
||||
if(luaL_dofile(L, filename.c_str())) {
|
||||
printf("Lua Error: %s\n", lua_tostring(L, -1));
|
||||
lua_close(L);
|
||||
return;
|
||||
}
|
||||
|
||||
states_[package_name] = L;
|
||||
}
|
||||
|
||||
bool LuaParser::HasFunction(std::string subname, std::string package_name) {
|
||||
size_t sz = subname.length();
|
||||
for(size_t i = 0; i < sz; ++i) {
|
||||
char c = subname[i];
|
||||
if(65 <= c && c <= 90) {
|
||||
c += 32;
|
||||
}
|
||||
subname[i] = c;
|
||||
}
|
||||
|
||||
auto iter = states_.find(package_name);
|
||||
if(iter == states_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lua_getfield(iter->second, LUA_GLOBALSINDEX, subname.c_str());
|
||||
if(lua_isfunction(iter->second, -1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LuaParser::ClearStates() {
|
||||
auto iter = states_.begin();
|
||||
while(iter != states_.end()) {
|
||||
if(iter->second) {
|
||||
lua_close(iter->second);
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
states_.clear();
|
||||
}
|
||||
|
||||
void LuaParser::MapFunctions(lua_State *L) {
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.beginClass<Lua_Entity>("Entity")
|
||||
.addFunction("IsClient", &Lua_Entity::IsClient)
|
||||
.addFunction("IsNPC", &Lua_Entity::IsNPC)
|
||||
.addFunction("IsMob", &Lua_Entity::IsMob)
|
||||
.addFunction("IsMerc", &Lua_Entity::IsMerc)
|
||||
.addFunction("IsCorpse", &Lua_Entity::IsCorpse)
|
||||
.addFunction("IsPlayerCorpse", &Lua_Entity::IsPlayerCorpse)
|
||||
.addFunction("IsNPCCorpse", &Lua_Entity::IsNPCCorpse)
|
||||
.addFunction("IsObject", &Lua_Entity::IsObject)
|
||||
.addFunction("IsDoor", &Lua_Entity::IsDoor)
|
||||
.addFunction("IsTrap", &Lua_Entity::IsTrap)
|
||||
.addFunction("IsBeacon", &Lua_Entity::IsBeacon)
|
||||
.addFunction("GetID", &Lua_Entity::GetID)
|
||||
.addFunction("CastToMob", &Lua_Entity::CastToMob)
|
||||
.endClass()
|
||||
.deriveClass<Lua_Mob, Lua_Entity>("Mob")
|
||||
.addFunction("GetName", &Lua_Mob::GetName)
|
||||
.endClass();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,46 +2,56 @@
|
||||
#define _EQE_LUA_PARSER_H
|
||||
#ifdef LUA_EQEMU
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
#include "QuestParserCollection.h"
|
||||
#include "QuestInterface.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
struct lua_State;
|
||||
class ItemInst;
|
||||
class Client;
|
||||
class NPC;
|
||||
|
||||
class LuaParser : public QuestInterface {
|
||||
public:
|
||||
//virtual void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
//virtual void EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
//virtual void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
//virtual void EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
//virtual void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
|
||||
//virtual void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
|
||||
//
|
||||
//virtual bool HasQuestSub(uint32 npcid, const char *subname);
|
||||
//virtual bool HasGlobalQuestSub(const char *subname);
|
||||
//virtual bool PlayerHasQuestSub(const char *subname);
|
||||
//virtual bool GlobalPlayerHasQuestSub(const char *subname);
|
||||
//virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname);
|
||||
//virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
|
||||
//
|
||||
//virtual void LoadNPCScript(std::string filename, int npc_id) { }
|
||||
////virtual void LoadGlobalNPCScript(std::string filename) { }
|
||||
//virtual void LoadPlayerScript(std::string filename) { }
|
||||
////virtual void LoadGlobalPlayerScript(std::string filename) { }
|
||||
//virtual void LoadItemScript(std::string filename, std::string item_script) { }
|
||||
//virtual void LoadSpellScript(std::string filename, uint32 spell_id) { }
|
||||
//
|
||||
//virtual void AddVar(std::string name, std::string val);
|
||||
//virtual void ReloadQuests(bool reset_timers = true);
|
||||
LuaParser();
|
||||
~LuaParser();
|
||||
|
||||
virtual double EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
virtual double EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
|
||||
virtual double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
virtual double EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
|
||||
virtual double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
|
||||
virtual double EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
|
||||
|
||||
virtual bool HasQuestSub(uint32 npc_id, const char *subname);
|
||||
virtual bool HasGlobalQuestSub(const char *subname);
|
||||
virtual bool PlayerHasQuestSub(const char *subname);
|
||||
virtual bool GlobalPlayerHasQuestSub(const char *subname);
|
||||
virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname);
|
||||
virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
|
||||
|
||||
virtual void LoadNPCScript(std::string filename, int npc_id);
|
||||
virtual void LoadGlobalNPCScript(std::string filename);
|
||||
virtual void LoadPlayerScript(std::string filename);
|
||||
virtual void LoadGlobalPlayerScript(std::string filename);
|
||||
virtual void LoadItemScript(std::string filename, std::string item_script);
|
||||
virtual void LoadSpellScript(std::string filename, uint32 spell_id);
|
||||
|
||||
virtual void AddVar(std::string name, std::string val);
|
||||
virtual std::string GetVar(std::string name);
|
||||
virtual void ReloadQuests();
|
||||
virtual uint32 GetIdentifier() { return 0xb0712acc; }
|
||||
|
||||
private:
|
||||
lua_State* L;
|
||||
void LoadScript(std::string filename, std::string package_name);
|
||||
bool HasFunction(std::string function, std::string package_name);
|
||||
void ClearStates();
|
||||
void MapFunctions(lua_State *L);
|
||||
|
||||
std::map<std::string, std::string> vars_;
|
||||
std::map<std::string, lua_State*> states_;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user