Eluna Closes:

#70, #69, #83, http://emudevs.com/showthread.php/3438-Custom-Items-and-On-Item-Use-Events
Fixes Object::~Object crash log from #71
This commit is contained in:
Rochet2
2014-07-01 00:35:06 +03:00
parent 8fe509c838
commit d09b5b04ba
6 changed files with 70 additions and 17 deletions

View File

@@ -401,14 +401,16 @@ bool Eluna::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets)
ObjectGuid guid = pItem->GET_GUID();
bool castSpell = true;
if (!OnItemGossip(pPlayer, pItem, targets))
if (!OnItemUse(pPlayer, pItem, targets))
castSpell = false;
pItem = pPlayer->GetItemByGuid(guid);
if (pItem && OnItemUse(pPlayer, pItem, targets))
if (pItem)
{
if (!OnItemGossip(pPlayer, pItem, targets))
castSpell = false;
pItem = pPlayer->GetItemByGuid(guid);
else
castSpell = false;
}
if (pItem && castSpell)
return true;

View File

@@ -50,6 +50,18 @@ void Eluna::ReloadEluna()
Uninitialize();
Initialize();
#ifdef TRINITY
// Re initialize creature AI restoring C++ AI or applying lua AI
{
TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
{
iter->second->AIM_Initialize();
}
}
#endif
reload = false;
}

View File

@@ -859,28 +859,35 @@ public:
luaL_newmetatable(L, tname);
int metatable = lua_gettop(L);
// tostring
lua_pushcfunction(L, tostringT);
lua_setfield(L, metatable, "__tostring");
// garbage collecting
if (manageMemory)
{
lua_pushcfunction(L, gcT);
lua_setfield(L, metatable, "__gc");
}
// hide metatable
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__metatable");
// required to access methods
// make methods accessible through metatable
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__index");
// metamethods
lua_pushcfunction(L, tostringT);
lua_setfield(L, metatable, "__tostring");
lua_pushcfunction(L, gcT);
lua_setfield(L, metatable, "__gc");
// make new indexes saved to methods
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__newindex");
// special method to get the object type
lua_pushcfunction(L, typeT);
lua_setfield(L, methods, "GetObjectType");
lua_setfield(L, metatable, "GetObjectType");
lua_setmetatable(L, methods);
lua_remove(L, methods);
// pop methods and metatable
lua_pop(L, 2);
}
template<typename C>
@@ -897,7 +904,7 @@ public:
return;
}
lua_getfield(L, -1, "__metatable");
lua_getfield(L, -1, "__index");
lua_remove(L, -2);
if (!lua_istable(L, -1))
{

View File

@@ -333,6 +333,7 @@ ElunaRegister<Unit> UnitMethods[] =
{ "SendUnitSay", &LuaUnit::SendUnitSay }, // :SendUnitSay(msg, language) - Sends a "Say" message with the specified language (all languages: 0)
{ "SendUnitYell", &LuaUnit::SendUnitYell }, // :SendUnitYell(msg, language) - Sends a "Yell" message with the specified language (all languages: 0)
{ "CastSpell", &LuaUnit::CastSpell }, // :CastSpell(target, spellID[, triggered]) - Casts spell on target (player/npc/creature), if triggered is true then instant cast
{ "CastCustomSpell", &LuaUnit::CastCustomSpell }, // :CastCustomSpell(&Unit target, uint32 spell, bool triggered = false, int32 bp0 = nil, int32 bp1 = nil, int32 bp2 = nil, &Item castItem = nil, uint64 originalCaster = 0) - Casts spell on target (player/npc/creature), if triggered is true then instant cast. pb0, 1 and 2 are modifiers for the base points of the spell.
{ "CastSpellAoF", &LuaUnit::CastSpellAoF }, // :CastSpellAoF(x, y, z, spellID[, triggered]) - Casts the spell on coordinates, if triggered is false has mana cost and cast time
{ "PlayDirectSound", &LuaUnit::PlayDirectSound }, // :PlayDirectSound(soundId, player) - Unit plays soundID to player, or everyone around if no player
{ "PlayDistanceSound", &LuaUnit::PlayDistanceSound }, // :PlayDistanceSound(soundId, player) - Unit plays soundID to player, or everyone around if no player. The sound fades the further you are

View File

@@ -1962,7 +1962,7 @@ namespace LuaPlayer
if (!item)
{
uint32 itemId = Eluna::CHECKVAL<uint32>(L, 2);
player->DestroyItemCount(itemId, itemCount, false);
player->DestroyItemCount(itemId, itemCount, true);
}
else
player->DestroyItemCount(item, itemCount, true);

View File

@@ -1420,6 +1420,37 @@ namespace LuaUnit
return 0;
}
/**
Casts the spell at target.
pb0, 1 and 2 are modifiers for the base points of the spell.
@param &Unit target
@param uint32 spell
@param bool triggered = false
@param int32 bp0 = nil
@param int32 bp1 = nil
@param int32 bp2 = nil
@param &Item castItem = nil
@param uint64 originalCaster = 0
*/
int CastCustomSpell(lua_State* L, Unit* unit)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
uint32 spell = Eluna::CHECKVAL<uint32>(L, 3);
bool triggered = Eluna::CHECKVAL<bool>(L, 4, false);
bool has_bp0 = lua_isnoneornil(L, 5);
int32 bp0 = Eluna::CHECKVAL<int32>(L, 5, 0);
bool has_bp1 = lua_isnoneornil(L, 6);
int32 bp1 = Eluna::CHECKVAL<int32>(L, 6, 0);
bool has_bp2 = lua_isnoneornil(L, 7);
int32 bp2 = Eluna::CHECKVAL<int32>(L, 7, 0);
Item* castItem = Eluna::CHECKOBJ<Item>(L, 8, false);
uint64 originalCaster = Eluna::CHECKVAL<uint64>(L, 9, 0);
unit->CastCustomSpell(target, spell, has_bp0 ? &bp0 : NULL, has_bp1 ? &bp1 : NULL, has_bp2 ? &bp2 : NULL, triggered, castItem, NULL, ObjectGuid(originalCaster));
return 0;
}
int CastSpellAoF(lua_State* L, Unit* unit)
{
float _x = Eluna::CHECKVAL<float>(L, 2);