Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
GameObjectMethods.cpp
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 - 2013 Eluna Lua Engine <http://emudevs.com/>
3* This program is free software licensed under GPL version 3
4* Please see the included DOCS/LICENSE.TXT for more information
5*/
6
7#include "GameObjectMethods.h"
8#include "Includes.h"
9
11{
12 int GetRelativePoint(lua_State* L, GameObject* go)
13 {
14 float dist = luaL_checknumber(L, 1);
15 int deg = luaL_checkinteger(L, 2);
16
17 float o = Position::NormalizeOrientation(go->GetOrientation() + (deg * M_PI / 180));
18 sEluna->Push(L, go->GetPositionX() + (dist * cosf(o)));
19 sEluna->Push(L, go->GetPositionY() + (dist * sinf(o)));
20 sEluna->Push(L, o);
21 return 3;
22 }
23
24 int SummonCreature(lua_State* L, GameObject* go)
25 {
26 uint32 entry = luaL_checkunsigned(L, 1);
27 float x = luaL_checknumber(L, 2);
28 float y = luaL_checknumber(L, 3);
29 float z = luaL_checknumber(L, 4);
30 float o = luaL_checknumber(L, 5);
31 uint32 spawnType = luaL_optunsigned(L, 6, 0);
32 uint32 despawnTimer = luaL_optunsigned(L, 7, 0);
33
34 TempSummonType type;
35 switch (spawnType)
36 {
37 case 1:
39 break;
40 case 2:
42 break;
43 case 3:
45 break;
46 case 4:
48 break;
49 case 5:
51 break;
52 case 6:
54 break;
55 case 7:
57 break;
58 case 8:
60 break;
61 default:
62 return 0;
63 }
64 sEluna->Push(L, go->SummonCreature(entry, x, y, z, o, type, despawnTimer)->ToCreature());
65 return 1;
66 }
67
68 int SummonGameObject(lua_State* L, GameObject* go)
69 {
70 uint32 entry = luaL_checkunsigned(L, 1);
71 float x = luaL_checknumber(L, 2);
72 float y = luaL_checknumber(L, 3);
73 float z = luaL_checknumber(L, 4);
74 float o = luaL_checknumber(L, 5);
75 uint32 respawnDelay = luaL_optunsigned(L, 6, 30);
76 sEluna->Push(L, go->SummonGameObject(entry, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, respawnDelay));
77 return 1;
78 }
79
80 int GetDisplayId(lua_State* L, GameObject* go)
81 {
82 sEluna->Push(L, go->GetDisplayId());
83 return 1;
84 }
85
86 int HasQuest(lua_State* L, GameObject* go)
87 {
88 uint32 questId = luaL_checkunsigned(L, 1);
89
90 sEluna->Push(L, go->hasQuest(questId));
91 return 1;
92 }
93
94 int IsSpawned(lua_State* L, GameObject* go)
95 {
96 sEluna->Push(L, go->isSpawned());
97 return 1;
98 }
99
100 int IsTransport(lua_State* L, GameObject* go)
101 {
102 sEluna->Push(L, go->IsTransport());
103 return 1;
104 }
105
106 int IsDestructible(lua_State* L, GameObject* go)
107 {
108 sEluna->Push(L, go->IsDestructibleBuilding());
109 return 1;
110 }
111
112 int IsActive(lua_State* L, GameObject* go)
113 {
114 sEluna->Push(L, go->isActiveObject());
115 return 1;
116 }
117
118 int Move(lua_State* L, GameObject* go)
119 {
120 float x = luaL_checknumber(L, 1);
121 float y = luaL_checknumber(L, 2);
122 float z = luaL_checknumber(L, 3);
123 float o = luaL_checknumber(L, 4);
124 go->Relocate(x, y, z, o);
125 return 0;
126 }
127
128 int SaveToDB(lua_State* L, GameObject* go)
129 {
130 go->SaveToDB();
131 return 0;
132 }
133
134 int RemoveFromWorld(lua_State* L, GameObject* go)
135 {
136 bool del = luaL_optbool(L, 1, false);
137 if (del)
138 go->DeleteFromDB();
139 go->RemoveFromWorld();
140 return 0;
141 }
142
143 int RegisterEvent(lua_State* L, GameObject* go)
144 {
145 luaL_checktype(L, 1, LUA_TFUNCTION);
146 uint32 delay = luaL_checkunsigned(L, 2);
147 uint32 repeats = luaL_checkunsigned(L, 3);
148
149 lua_settop(L, 1);
150 int functionRef = lua_ref(L, true);
151 sEluna->Push(L, sEluna->m_EventMgr.AddEvent(go->GetGUID(), functionRef, delay, repeats, go));
152 return 1;
153 }
154
155 int RemoveEventById(lua_State* L, GameObject* go)
156 {
157 int eventId = luaL_checkinteger(L, 1);
158 sEluna->m_EventMgr.RemoveEvent(go->GetGUID(), eventId);
159 return 0;
160 }
161
162 int RemoveEvents(lua_State* L, GameObject* go)
163 {
164 sEluna->m_EventMgr.RemoveEvents(go->GetGUID());
165 return 0;
166 }
167
168 int UseDoorOrButton(lua_State* L, GameObject* go)
169 {
170 uint32 delay = luaL_optunsigned(L, 1, 0);
171
172 go->UseDoorOrButton(delay);
173 return 0;
174 }
175
176 int SetGoState(lua_State* L, GameObject* go)
177 {
178 uint32 state = luaL_optunsigned(L, 1, 0);
179
180 if (state == 0)
182 else if (state == 1)
184 else if (state == 2)
186
187 return 0;
188 }
189
190 int GetGoState(lua_State* L, GameObject* go)
191 {
192 if (!go || !go->IsInWorld())
193 return 0;
194
195 sEluna->Push(L, go->GetGoState());
196 return 1;
197 }
198
199 int SetLootState(lua_State* L, GameObject* go)
200 {
201 uint32 state = luaL_optunsigned(L, 1, 0);
202
203 if (state == 0)
205 else if (state == 1)
207 else if (state == 2)
209 else if (state == 3)
211
212 return 0;
213 }
214
215 int GetLootState(lua_State* L, GameObject* go)
216 {
217 sEluna->Push(L, go->getLootState());
218 return 1;
219 }
220
221 int Despawn(lua_State* L, GameObject* go)
222 {
223 uint32 delay = luaL_optunsigned(L, 1, 1);
224 if (!delay)
225 delay = 1;
226
227 go->SetSpawnedByDefault(false);
228 go->SetRespawnTime(delay);
229 return 0;
230 }
231
232 int Respawn(lua_State* L, GameObject* go)
233 {
234 uint32 delay = luaL_optunsigned(L, 1, 1);
235 if (!delay)
236 delay = 1;
237
238 go->SetSpawnedByDefault(true);
239 go->SetRespawnTime(delay);
240 return 0;
241 }
242};
#define M_PI
Definition Common.h:192
std::uint32_t uint32
Definition Define.h:77
static constexpr LootState GO_READY
static constexpr TempSummonType TEMPSUMMON_DEAD_DESPAWN
static constexpr TempSummonType TEMPSUMMON_MANUAL_DESPAWN
static constexpr GOState GO_STATE_ACTIVE_ALTERNATIVE
static constexpr TempSummonType TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN
static constexpr LootState GO_NOT_READY
static constexpr TempSummonType TEMPSUMMON_TIMED_DESPAWN
static constexpr LootState GO_JUST_DEACTIVATED
static constexpr TempSummonType TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
static constexpr TempSummonType TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
static constexpr GOState GO_STATE_ACTIVE
static constexpr GOState GO_STATE_READY
static constexpr TempSummonType TEMPSUMMON_CORPSE_TIMED_DESPAWN
static constexpr LootState GO_ACTIVATED
static constexpr TempSummonType TEMPSUMMON_CORPSE_DESPAWN
#define sEluna
Definition LuaEngine.h:710
TempSummonType
Definition Object.h:67
void SetGoState(GOState state)
GOState GetGoState() const
Definition GameObject.h:717
void DeleteFromDB()
void RemoveFromWorld() OVERRIDE
LootState getLootState() const
Definition GameObject.h:742
void UseDoorOrButton(uint32 time_to_restore=0, bool alternative=false, Unit *user=NULL)
bool isSpawned() const
Definition GameObject.h:705
void SetRespawnTime(int32 respawn)
Definition GameObject.h:699
void SetSpawnedByDefault(bool b)
Definition GameObject.h:712
uint32 GetDisplayId() const
Definition GameObject.h:828
void SetLootState(LootState s, Unit *unit=NULL)
bool IsDestructibleBuilding() const
void SaveToDB()
bool hasQuest(uint32 quest_id) const OVERRIDE
bool IsTransport() const
uint64 GetGUID() const
Definition Object.h:119
bool IsInWorld() const
Definition Object.h:114
Creature * ToCreature()
Definition Object.h:207
bool isActiveObject() const
Definition Object.h:776
GameObject * SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime)
Definition Object.cpp:2729
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TempSummonType::TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0) const
Definition Object.cpp:2703
int RemoveEvents(lua_State *L, GameObject *go)
int Move(lua_State *L, GameObject *go)
int GetRelativePoint(lua_State *L, GameObject *go)
int HasQuest(lua_State *L, GameObject *go)
int IsSpawned(lua_State *L, GameObject *go)
int GetDisplayId(lua_State *L, GameObject *go)
int Despawn(lua_State *L, GameObject *go)
int IsActive(lua_State *L, GameObject *go)
int RemoveEventById(lua_State *L, GameObject *go)
int SummonGameObject(lua_State *L, GameObject *go)
int IsTransport(lua_State *L, GameObject *go)
int SummonCreature(lua_State *L, GameObject *go)
int GetLootState(lua_State *L, GameObject *go)
int RemoveFromWorld(lua_State *L, GameObject *go)
int SetLootState(lua_State *L, GameObject *go)
int RegisterEvent(lua_State *L, GameObject *go)
int SetGoState(lua_State *L, GameObject *go)
int GetGoState(lua_State *L, GameObject *go)
int SaveToDB(lua_State *L, GameObject *go)
int UseDoorOrButton(lua_State *L, GameObject *go)
int Respawn(lua_State *L, GameObject *go)
int IsDestructible(lua_State *L, GameObject *go)
static float NormalizeOrientation(float o)
Definition Object.h:427
float GetOrientation() const
Definition Object.h:331
float GetPositionX() const
Definition Object.h:328
float GetPositionY() const
Definition Object.h:329
void Relocate(float x, float y)
Definition Object.h:302