Files
mod-ale/GameObjectMethods.h
Rochet2 b1f85bfc21 Eluna
Improved pushing so that a single userdata is used per object pushed.
Made everything use the singleton less, allowing more free code and easier to implement multithreading later.
Made macros for hookmgr and fixed the issue with hooks called inside hooks.
2014-06-29 21:28:49 +02:00

173 lines
4.1 KiB
C++

/*
* Copyright (C) 2010 - 2014 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef GAMEOBJECTMETHODS_H
#define GAMEOBJECTMETHODS_H
namespace LuaGameObject
{
/* BOOLEAN */
int HasQuest(lua_State* L, GameObject* go)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
#ifdef MANGOS
Eluna::Push(L, go->HasQuest(questId));
#else
Eluna::Push(L, go->hasQuest(questId));
#endif
return 1;
}
int IsSpawned(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->isSpawned());
return 1;
}
int IsTransport(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->IsTransport());
return 1;
}
int IsActive(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->isActiveObject());
return 1;
}
/*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side
{
Eluna::Push(L, go->IsDestructibleBuilding());
return 1;
}*/
/* GETTERS */
int GetDisplayId(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->GetDisplayId());
return 1;
}
int GetGoState(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->GetGoState());
return 1;
}
int GetLootState(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->getLootState());
return 1;
}
/* SETTERS */
int SetGoState(lua_State* L, GameObject* go)
{
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0);
if (state == 0)
go->SetGoState(GO_STATE_ACTIVE);
else if (state == 1)
go->SetGoState(GO_STATE_READY);
else if (state == 2)
go->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
return 0;
}
int SetLootState(lua_State* L, GameObject* go)
{
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0);
if (state == 0)
go->SetLootState(GO_NOT_READY);
else if (state == 1)
go->SetLootState(GO_READY);
else if (state == 2)
go->SetLootState(GO_ACTIVATED);
else if (state == 3)
go->SetLootState(GO_JUST_DEACTIVATED);
return 0;
}
/* OTHER */
int SaveToDB(lua_State* L, GameObject* go)
{
go->SaveToDB();
return 0;
}
int RemoveFromWorld(lua_State* L, GameObject* go)
{
bool deldb = Eluna::CHECKVAL<bool>(L, 2, false);
if (deldb)
go->DeleteFromDB();
go->RemoveFromWorld();
return 0;
}
int RegisterEvent(lua_State* L, GameObject* go)
{
luaL_checktype(L, 2, LUA_TFUNCTION);
uint32 delay = Eluna::CHECKVAL<uint32>(L, 3);
uint32 repeats = Eluna::CHECKVAL<uint32>(L, 4);
lua_pushvalue(L, 2);
int functionRef = lua_ref(L, true);
functionRef = sEluna->m_EventMgr->AddEvent(&go->m_Events, functionRef, delay, repeats, go);
if (functionRef)
Eluna::Push(L, functionRef);
return 1;
}
int RemoveEventById(lua_State* L, GameObject* go)
{
int eventId = Eluna::CHECKVAL<int>(L, 2);
sEluna->m_EventMgr->RemoveEvent(&go->m_Events, eventId);
return 0;
}
int RemoveEvents(lua_State* L, GameObject* go)
{
sEluna->m_EventMgr->RemoveEvents(&go->m_Events);
return 0;
}
int UseDoorOrButton(lua_State* L, GameObject* go)
{
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 0);
go->UseDoorOrButton(delay);
return 0;
}
int Despawn(lua_State* L, GameObject* go)
{
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 1);
if (!delay)
delay = 1;
go->SetSpawnedByDefault(false);
go->SetRespawnTime(delay);
return 0;
}
int Respawn(lua_State* L, GameObject* go)
{
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 1);
if (!delay)
delay = 1;
go->SetSpawnedByDefault(true);
go->SetRespawnTime(delay);
return 0;
}
};
#endif