diff --git a/AuraMethods.h b/AuraMethods.h index f72c422..f9000ec 100644 --- a/AuraMethods.h +++ b/AuraMethods.h @@ -11,77 +11,77 @@ namespace LuaAura { int GetCaster(lua_State* L, Aura* aura) { - sEluna->Push(L, aura->GetCaster()); + Eluna::Push(L, aura->GetCaster()); return 1; } int GetCasterGUID(lua_State* L, Aura* aura) { #ifdef MANGOS - sEluna->Push(L, aura->GetCasterGuid()); + Eluna::Push(L, aura->GetCasterGuid()); #else - sEluna->Push(L, aura->GetCasterGUID()); + Eluna::Push(L, aura->GetCasterGUID()); #endif return 1; } int GetCasterLevel(lua_State* L, Aura* aura) { - sEluna->Push(L, aura->GetCaster()->getLevel()); + Eluna::Push(L, aura->GetCaster()->getLevel()); return 1; } int GetDuration(lua_State* L, Aura* aura) { #ifdef MANGOS - sEluna->Push(L, aura->GetAuraDuration()); + Eluna::Push(L, aura->GetAuraDuration()); #else - sEluna->Push(L, aura->GetDuration()); + Eluna::Push(L, aura->GetDuration()); #endif return 1; } int GetCharges(lua_State* L, Aura* aura) { - sEluna->Push(L, aura->GetStackAmount()); + Eluna::Push(L, aura->GetStackAmount()); return 1; } int GetAuraId(lua_State* L, Aura* aura) { - sEluna->Push(L, aura->GetId()); + Eluna::Push(L, aura->GetId()); return 1; } int GetMaxDuration(lua_State* L, Aura* aura) { #ifdef MANGOS - sEluna->Push(L, aura->GetAuraMaxDuration()); + Eluna::Push(L, aura->GetAuraMaxDuration()); #else - sEluna->Push(L, aura->GetMaxDuration()); + Eluna::Push(L, aura->GetMaxDuration()); #endif return 1; } int GetStackAmount(lua_State* L, Aura* aura) { - sEluna->Push(L, aura->GetStackAmount()); + Eluna::Push(L, aura->GetStackAmount()); return 1; } int GetOwner(lua_State* L, Aura* aura) { #ifdef MANGOS - sEluna->Push(L, aura->GetTarget()); + Eluna::Push(L, aura->GetTarget()); #else - sEluna->Push(L, aura->GetOwner()); + Eluna::Push(L, aura->GetOwner()); #endif return 1; } int SetDuration(lua_State* L, Aura* aura) { - int duration = sEluna->CHECKVAL(L, 2); + int duration = Eluna::CHECKVAL(L, 2); #ifdef MANGOS aura->GetHolder()->SetAuraDuration(duration); #else @@ -92,7 +92,7 @@ namespace LuaAura int SetMaxDuration(lua_State* L, Aura* aura) { - int duration = sEluna->CHECKVAL(L, 2); + int duration = Eluna::CHECKVAL(L, 2); #ifdef MANGOS aura->GetHolder()->SetAuraMaxDuration(duration); #else @@ -103,8 +103,8 @@ namespace LuaAura int SetStackAmount(lua_State* L, Aura* aura) { - int amount = sEluna->CHECKVAL(L, 2); - int duration = sEluna->CHECKVAL(L, 2); + int amount = Eluna::CHECKVAL(L, 2); + int duration = Eluna::CHECKVAL(L, 2); #ifdef MANGOS aura->GetHolder()->SetStackAmount(amount); #else @@ -115,7 +115,7 @@ namespace LuaAura int Remove(lua_State* L, Aura* aura) { - int duration = sEluna->CHECKVAL(L, 2); + int duration = Eluna::CHECKVAL(L, 2); #ifdef MANGOS aura->GetHolder()->RemoveAura(aura->GetEffIndex()); #else diff --git a/CorpseMethods.h b/CorpseMethods.h index 1de01bc..b55203c 100644 --- a/CorpseMethods.h +++ b/CorpseMethods.h @@ -13,9 +13,9 @@ namespace LuaCorpse int GetOwnerGUID(lua_State* L, Corpse* corpse) { #ifdef MANGOS - sEluna->Push(L, corpse->GetOwnerGuid()); + Eluna::Push(L, corpse->GetOwnerGuid()); #else - sEluna->Push(L, corpse->GetOwnerGUID()); + Eluna::Push(L, corpse->GetOwnerGUID()); #endif return 1; } @@ -23,14 +23,14 @@ namespace LuaCorpse // GetGhostTime() int GetGhostTime(lua_State* L, Corpse* corpse) { - sEluna->Push(L, uint32(corpse->GetGhostTime())); + Eluna::Push(L, uint32(corpse->GetGhostTime())); return 1; } // GetType() int GetType(lua_State* L, Corpse* corpse) { - sEluna->Push(L, corpse->GetType()); + Eluna::Push(L, corpse->GetType()); return 1; } diff --git a/CreatureMethods.h b/CreatureMethods.h index ec498a6..d252171 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -12,70 +12,70 @@ namespace LuaCreature /* BOOLEAN */ int IsReputationGainDisabled(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsReputationGainDisabled()); + Eluna::Push(L, creature->IsReputationGainDisabled()); return 1; } int IsRegeneratingHealth(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->IsRegeneratingHealth()); + Eluna::Push(L, creature->IsRegeneratingHealth()); #else - sEluna->Push(L, creature->isRegeneratingHealth()); + Eluna::Push(L, creature->isRegeneratingHealth()); #endif return 1; } int HasInvolvedQuest(lua_State* L, Creature* creature) { - uint32 quest_id = sEluna->CHECKVAL(L, 2); + uint32 quest_id = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, creature->HasInvolvedQuest(quest_id)); + Eluna::Push(L, creature->HasInvolvedQuest(quest_id)); #else - sEluna->Push(L, creature->hasInvolvedQuest(quest_id)); + Eluna::Push(L, creature->hasInvolvedQuest(quest_id)); #endif return 1; } int IsTargetAcceptable(lua_State* L, Creature* creature) { - Unit* target = sEluna->CHECKOBJ(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, creature->isTargetableForAttack(target)); + Eluna::Push(L, creature->isTargetableForAttack(target)); return 1; } int CanAssistTo(lua_State* L, Creature* creature) { - Unit* u = sEluna->CHECKOBJ(L, 2); - Unit* enemy = sEluna->CHECKOBJ(L, 3); - bool checkfaction = sEluna->CHECKVAL(L, 4, true); + Unit* u = Eluna::CHECKOBJ(L, 2); + Unit* enemy = Eluna::CHECKOBJ(L, 3); + bool checkfaction = Eluna::CHECKVAL(L, 4, true); - sEluna->Push(L, creature->CanAssistTo(u, enemy, checkfaction)); + Eluna::Push(L, creature->CanAssistTo(u, enemy, checkfaction)); return 1; } int HasSearchedAssistance(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->HasSearchedAssistance()); + Eluna::Push(L, creature->HasSearchedAssistance()); return 1; } int IsTappedBy(lua_State* L, Creature* creature) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, creature->isTappedBy(player)); + Eluna::Push(L, creature->isTappedBy(player)); return 1; } int HasLootRecipient(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->HasLootRecipient()); + Eluna::Push(L, creature->HasLootRecipient()); #else - sEluna->Push(L, creature->hasLootRecipient()); + Eluna::Push(L, creature->hasLootRecipient()); #endif return 1; } @@ -84,222 +84,222 @@ namespace LuaCreature { #ifdef MANGOS if (CreatureAI* ai = creature->AI()) - sEluna->Push(L, ai->IsCombatMovement()); + Eluna::Push(L, ai->IsCombatMovement()); else - sEluna->Push(L, false); + Eluna::Push(L, false); #else - sEluna->Push(L, !creature->HasReactState(REACT_PASSIVE)); + Eluna::Push(L, !creature->HasReactState(REACT_PASSIVE)); #endif return 1; } int CanSwim(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->CanSwim()); + Eluna::Push(L, creature->CanSwim()); return 1; } int CanWalk(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->CanWalk()); + Eluna::Push(L, creature->CanWalk()); return 1; } int IsInEvadeMode(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsInEvadeMode()); + Eluna::Push(L, creature->IsInEvadeMode()); return 1; } int IsElite(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->IsElite()); + Eluna::Push(L, creature->IsElite()); #else - sEluna->Push(L, creature->isElite()); + Eluna::Push(L, creature->isElite()); #endif return 1; } int IsGuard(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsGuard()); + Eluna::Push(L, creature->IsGuard()); return 1; } int IsCivilian(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsCivilian()); + Eluna::Push(L, creature->IsCivilian()); return 1; } int IsRacialLeader(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsRacialLeader()); + Eluna::Push(L, creature->IsRacialLeader()); return 1; } int IsWorldBoss(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->IsWorldBoss()); + Eluna::Push(L, creature->IsWorldBoss()); #else - sEluna->Push(L, creature->isWorldBoss()); + Eluna::Push(L, creature->isWorldBoss()); #endif return 1; } int HasCategoryCooldown(lua_State* L, Creature* creature) { - uint32 spell = sEluna->CHECKVAL(L, 2); + uint32 spell = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, creature->HasCategoryCooldown(spell)); + Eluna::Push(L, creature->HasCategoryCooldown(spell)); return 1; } int HasSpell(lua_State* L, Creature* creature) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, creature->HasSpell(id)); + Eluna::Push(L, creature->HasSpell(id)); return 1; } int HasQuest(lua_State* L, Creature* creature) { - uint32 questId = sEluna->CHECKVAL(L, 2); + uint32 questId = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, creature->HasQuest(questId)); + Eluna::Push(L, creature->HasQuest(questId)); #else - sEluna->Push(L, creature->hasQuest(questId)); + Eluna::Push(L, creature->hasQuest(questId)); #endif return 1; } int HasSpellCooldown(lua_State* L, Creature* creature) { - uint32 spellId = sEluna->CHECKVAL(L, 2); + uint32 spellId = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, creature->HasSpellCooldown(spellId)); + Eluna::Push(L, creature->HasSpellCooldown(spellId)); return 1; } int CanFly(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->CanFly()); + Eluna::Push(L, creature->CanFly()); return 1; } /*int IsTrigger(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsTrigger()); + Eluna::Push(L, creature->IsTrigger()); return 1; }*/ /*int IsDamageEnoughForLootingAndReward(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->IsDamageEnoughForLootingAndReward()); + Eluna::Push(L, creature->IsDamageEnoughForLootingAndReward()); return 1; }*/ /*int CanStartAttack(lua_State* L, Creature* creature) // TODO: Implement core side { - Unit* target = sEluna->CHECKOBJ(L, 2); - bool force = sEluna->CHECKVAL(L, 3, true); + Unit* target = Eluna::CHECKOBJ(L, 2); + bool force = Eluna::CHECKVAL(L, 3, true); - sEluna->Push(L, creature->CanStartAttack(target, force)); + Eluna::Push(L, creature->CanStartAttack(target, force)); return 1; }*/ /*int HasLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { - uint16 lootMode = sEluna->CHECKVAL(L, 2); + uint16 lootMode = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, creature->HasLootMode(lootMode)); + Eluna::Push(L, creature->HasLootMode(lootMode)); return 1; }*/ /* GETTERS */ int GetRespawnDelay(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetRespawnDelay()); + Eluna::Push(L, creature->GetRespawnDelay()); return 1; } int GetRespawnRadius(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetRespawnRadius()); + Eluna::Push(L, creature->GetRespawnRadius()); return 1; } int GetDefaultMovementType(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetDefaultMovementType()); + Eluna::Push(L, creature->GetDefaultMovementType()); return 1; } int GetAggroRange(lua_State* L, Creature* creature) { - Unit* target = sEluna->CHECKOBJ(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, creature->GetAttackDistance(target)); + Eluna::Push(L, creature->GetAttackDistance(target)); return 1; } int GetAttackDistance(lua_State* L, Creature* creature) { - Unit* target = sEluna->CHECKOBJ(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, creature->GetAttackDistance(target)); + Eluna::Push(L, creature->GetAttackDistance(target)); return 1; } int GetLootRecipientGroup(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->GetGroupLootRecipient()); + Eluna::Push(L, creature->GetGroupLootRecipient()); #else - sEluna->Push(L, creature->GetLootRecipientGroup()); + Eluna::Push(L, creature->GetLootRecipientGroup()); #endif return 1; } int GetLootRecipient(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetLootRecipient()); + Eluna::Push(L, creature->GetLootRecipient()); return 1; } int GetScriptName(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetScriptName()); + Eluna::Push(L, creature->GetScriptName()); return 1; } int GetAIName(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetAIName()); + Eluna::Push(L, creature->GetAIName()); return 1; } int GetScriptId(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetScriptId()); + Eluna::Push(L, creature->GetScriptId()); return 1; } int GetCreatureSpellCooldownDelay(lua_State* L, Creature* creature) { - uint32 spell = sEluna->CHECKVAL(L, 2); + uint32 spell = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, creature->GetCreatureSpellCooldownDelay(spell)); + Eluna::Push(L, creature->GetCreatureSpellCooldownDelay(spell)); return 1; } int GetCorpseDelay(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetCorpseDelay()); + Eluna::Push(L, creature->GetCorpseDelay()); return 1; } @@ -312,20 +312,20 @@ namespace LuaCreature creature->GetHomePosition(x, y, z, o); #endif - sEluna->Push(L, x); - sEluna->Push(L, y); - sEluna->Push(L, z); - sEluna->Push(L, o); + Eluna::Push(L, x); + Eluna::Push(L, y); + Eluna::Push(L, z); + Eluna::Push(L, o); return 4; } int GetAITarget(lua_State* L, Creature* creature) { - uint32 targetType = sEluna->CHECKVAL(L, 2); - bool playerOnly = sEluna->CHECKVAL(L, 3, false); - uint32 position = sEluna->CHECKVAL(L, 4, 0); - float dist = sEluna->CHECKVAL(L, 5, -1.0f); - int32 aura = sEluna->CHECKVAL(L, 6, 0); + uint32 targetType = Eluna::CHECKVAL(L, 2); + bool playerOnly = Eluna::CHECKVAL(L, 3, false); + uint32 position = Eluna::CHECKVAL(L, 4, 0); + float dist = Eluna::CHECKVAL(L, 5, -1.0f); + int32 aura = Eluna::CHECKVAL(L, 6, 0); ThreatList const& threatlist = creature->getThreatManager().getThreatList(); if (position >= threatlist.size()) @@ -361,20 +361,20 @@ namespace LuaCreature { std::list::const_iterator itr = targetList.begin(); std::advance(itr, position); - sEluna->Push(L, *itr); + Eluna::Push(L, *itr); } case SELECT_TARGET_FARTHEST: case SELECT_TARGET_BOTTOMAGGRO: { std::list::reverse_iterator ritr = targetList.rbegin(); std::advance(ritr, position); - sEluna->Push(L, *ritr); + Eluna::Push(L, *ritr); } case SELECT_TARGET_RANDOM: { std::list::const_iterator itr = targetList.begin(); std::advance(itr, urand(position, targetList.size() - 1)); - sEluna->Push(L, *itr); + Eluna::Push(L, *itr); } default: luaL_argerror(L, 2, "SelectAggroTarget expected"); @@ -397,8 +397,8 @@ namespace LuaCreature if (!target) continue; ++i; - sEluna->Push(L, i); - sEluna->Push(L, target); + Eluna::Push(L, i); + Eluna::Push(L, target); lua_settable(L, tbl); } @@ -408,34 +408,34 @@ namespace LuaCreature int GetAITargetsCount(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->getThreatManager().getThreatList().size()); + Eluna::Push(L, creature->getThreatManager().getThreatList().size()); return 1; } int GetNPCFlags(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetUInt32Value(UNIT_NPC_FLAGS)); + Eluna::Push(L, creature->GetUInt32Value(UNIT_NPC_FLAGS)); return 1; } #ifndef CATA int GetShieldBlockValue(lua_State* L, Creature* creature) { - sEluna->Push(L, creature->GetShieldBlockValue()); + Eluna::Push(L, creature->GetShieldBlockValue()); return 1; } #endif /*int GetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { - sEluna->Push(L, creature->GetLootMode()); + Eluna::Push(L, creature->GetLootMode()); return 1; }*/ /* SETTERS */ int SetNPCFlags(lua_State* L, Creature* creature) { - uint32 flags = sEluna->CHECKVAL(L, 2); + uint32 flags = Eluna::CHECKVAL(L, 2); creature->SetUInt32Value(UNIT_NPC_FLAGS, flags); return 0; @@ -443,7 +443,7 @@ namespace LuaCreature int SetDeathState(lua_State* L, Creature* creature) { - int32 state = sEluna->CHECKVAL(L, 2); + int32 state = Eluna::CHECKVAL(L, 2); #ifdef MANGOS creature->SetDeathState((DeathState)state); @@ -455,7 +455,7 @@ namespace LuaCreature int SetWalk(lua_State* L, Creature* creature) // TODO: Move same to Player ? { - bool enable = sEluna->CHECKVAL(L, 2, true); + bool enable = Eluna::CHECKVAL(L, 2, true); creature->SetWalk(enable); return 0; @@ -463,7 +463,7 @@ namespace LuaCreature int SetAllowedCombat(lua_State* L, Creature* creature) { - bool allow = sEluna->CHECKVAL(L, 2); + bool allow = Eluna::CHECKVAL(L, 2); #ifdef MANGOS if (CreatureAI* ai = creature->AI()) @@ -476,7 +476,7 @@ namespace LuaCreature int SetDisableReputationGain(lua_State* L, Creature* creature) { - bool disable = sEluna->CHECKVAL(L, 2, true); + bool disable = Eluna::CHECKVAL(L, 2, true); creature->SetDisableReputationGain(disable); return 0; @@ -490,7 +490,7 @@ namespace LuaCreature int SetRespawnRadius(lua_State* L, Creature* creature) { - float dist = sEluna->CHECKVAL(L, 2); + float dist = Eluna::CHECKVAL(L, 2); creature->SetRespawnRadius(dist); return 0; @@ -498,7 +498,7 @@ namespace LuaCreature int SetRespawnDelay(lua_State* L, Creature* creature) { - uint32 delay = sEluna->CHECKVAL(L, 2); + uint32 delay = Eluna::CHECKVAL(L, 2); creature->SetRespawnDelay(delay); return 0; @@ -506,7 +506,7 @@ namespace LuaCreature int SetDefaultMovementType(lua_State* L, Creature* creature) { - int32 type = sEluna->CHECKVAL(L, 2); + int32 type = Eluna::CHECKVAL(L, 2); creature->SetDefaultMovementType((MovementGeneratorType)type); return 0; @@ -514,7 +514,7 @@ namespace LuaCreature int SetNoSearchAssistance(lua_State* L, Creature* creature) { - bool val = sEluna->CHECKVAL(L, 2, true); + bool val = Eluna::CHECKVAL(L, 2, true); creature->SetNoSearchAssistance(val); return 0; @@ -522,7 +522,7 @@ namespace LuaCreature int SetNoCallAssistance(lua_State* L, Creature* creature) { - bool val = sEluna->CHECKVAL(L, 2, true); + bool val = Eluna::CHECKVAL(L, 2, true); creature->SetNoCallAssistance(val); return 0; @@ -530,7 +530,7 @@ namespace LuaCreature int SetHover(lua_State* L, Creature* creature) { - bool enable = sEluna->CHECKVAL(L, 2, true); + bool enable = Eluna::CHECKVAL(L, 2, true); #ifdef MANGOS creature->SetLevitate(enable); @@ -542,7 +542,7 @@ namespace LuaCreature /*int SetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { - uint16 lootMode = sEluna->CHECKVAL(L, 2); + uint16 lootMode = Eluna::CHECKVAL(L, 2); creature->SetLootMode(lootMode); return 0; @@ -550,17 +550,17 @@ namespace LuaCreature /*int SetDisableGravity(lua_State* L, Creature* creature) { - bool disable = sEluna->CHECKVAL(L, 2, true); - bool packetOnly = sEluna->CHECKVAL(L, 3, false); + bool disable = Eluna::CHECKVAL(L, 2, true); + bool packetOnly = Eluna::CHECKVAL(L, 3, false); - sEluna->Push(L, creature->SetDisableGravity(disable, packetOnly)); + Eluna::Push(L, creature->SetDisableGravity(disable, packetOnly)); return 1; }*/ /* OTHER */ int DespawnOrUnsummon(lua_State* L, Creature* creature) { - uint32 msTimeToDespawn = sEluna->CHECKVAL(L, 2, 0); + uint32 msTimeToDespawn = Eluna::CHECKVAL(L, 2, 0); #ifdef MANGOS creature->ForcedDespawn(msTimeToDespawn); @@ -600,7 +600,7 @@ namespace LuaCreature int CallForHelp(lua_State* L, Creature* creature) { - float radius = sEluna->CHECKVAL(L, 2); + float radius = Eluna::CHECKVAL(L, 2); creature->CallForHelp(radius); return 0; @@ -614,7 +614,7 @@ namespace LuaCreature int AttackStart(lua_State* L, Creature* creature) { - Unit* target = sEluna->CHECKOBJ(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 2); creature->AI()->AttackStart(target); return 0; @@ -629,9 +629,9 @@ namespace LuaCreature int SelectVictim(lua_State* L, Creature* creature) { #ifdef MANGOS - sEluna->Push(L, creature->SelectHostileTarget()); + Eluna::Push(L, creature->SelectHostileTarget()); #else - sEluna->Push(L, creature->SelectVictim()); + Eluna::Push(L, creature->SelectVictim()); #endif return 1; } @@ -644,7 +644,7 @@ namespace LuaCreature /*int RemoveLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { - uint16 lootMode = sEluna->CHECKVAL(L, 2); + uint16 lootMode = Eluna::CHECKVAL(L, 2); creature->RemoveLootMode(lootMode); return 0; @@ -652,7 +652,7 @@ namespace LuaCreature /*int AddLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { - uint16 lootMode = sEluna->CHECKVAL(L, 2); + uint16 lootMode = Eluna::CHECKVAL(L, 2); creature->AddLootMode(lootMode); return 0; diff --git a/GameObjectMethods.h b/GameObjectMethods.h index d517cd1..42e93f3 100644 --- a/GameObjectMethods.h +++ b/GameObjectMethods.h @@ -12,63 +12,63 @@ namespace LuaGameObject /* BOOLEAN */ int HasQuest(lua_State* L, GameObject* go) { - uint32 questId = sEluna->CHECKVAL(L, 2); + uint32 questId = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, go->HasQuest(questId)); + Eluna::Push(L, go->HasQuest(questId)); #else - sEluna->Push(L, go->hasQuest(questId)); + Eluna::Push(L, go->hasQuest(questId)); #endif return 1; } int IsSpawned(lua_State* L, GameObject* go) { - sEluna->Push(L, go->isSpawned()); + Eluna::Push(L, go->isSpawned()); return 1; } int IsTransport(lua_State* L, GameObject* go) { - sEluna->Push(L, go->IsTransport()); + Eluna::Push(L, go->IsTransport()); return 1; } int IsActive(lua_State* L, GameObject* go) { - sEluna->Push(L, go->isActiveObject()); + Eluna::Push(L, go->isActiveObject()); return 1; } /*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side { - sEluna->Push(L, go->IsDestructibleBuilding()); + Eluna::Push(L, go->IsDestructibleBuilding()); return 1; }*/ /* GETTERS */ int GetDisplayId(lua_State* L, GameObject* go) { - sEluna->Push(L, go->GetDisplayId()); + Eluna::Push(L, go->GetDisplayId()); return 1; } int GetGoState(lua_State* L, GameObject* go) { - sEluna->Push(L, go->GetGoState()); + Eluna::Push(L, go->GetGoState()); return 1; } int GetLootState(lua_State* L, GameObject* go) { - sEluna->Push(L, go->getLootState()); + Eluna::Push(L, go->getLootState()); return 1; } /* SETTERS */ int SetGoState(lua_State* L, GameObject* go) { - uint32 state = sEluna->CHECKVAL(L, 2, 0); + uint32 state = Eluna::CHECKVAL(L, 2, 0); if (state == 0) go->SetGoState(GO_STATE_ACTIVE); @@ -82,7 +82,7 @@ namespace LuaGameObject int SetLootState(lua_State* L, GameObject* go) { - uint32 state = sEluna->CHECKVAL(L, 2, 0); + uint32 state = Eluna::CHECKVAL(L, 2, 0); if (state == 0) go->SetLootState(GO_NOT_READY); @@ -105,7 +105,7 @@ namespace LuaGameObject int RemoveFromWorld(lua_State* L, GameObject* go) { - bool deldb = sEluna->CHECKVAL(L, 2, false); + bool deldb = Eluna::CHECKVAL(L, 2, false); if (deldb) go->DeleteFromDB(); go->RemoveFromWorld(); @@ -115,33 +115,33 @@ namespace LuaGameObject int RegisterEvent(lua_State* L, GameObject* go) { luaL_checktype(L, 2, LUA_TFUNCTION); - uint32 delay = sEluna->CHECKVAL(L, 3); - uint32 repeats = sEluna->CHECKVAL(L, 4); + uint32 delay = Eluna::CHECKVAL(L, 3); + uint32 repeats = Eluna::CHECKVAL(L, 4); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); - functionRef = sEluna->m_EventMgr.AddEvent(&go->m_Events, functionRef, delay, repeats, go); + functionRef = sEluna->m_EventMgr->AddEvent(&go->m_Events, functionRef, delay, repeats, go); if (functionRef) - sEluna->Push(L, functionRef); + Eluna::Push(L, functionRef); return 1; } int RemoveEventById(lua_State* L, GameObject* go) { - int eventId = sEluna->CHECKVAL(L, 2); - sEluna->m_EventMgr.RemoveEvent(&go->m_Events, eventId); + int eventId = Eluna::CHECKVAL(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); + sEluna->m_EventMgr->RemoveEvents(&go->m_Events); return 0; } int UseDoorOrButton(lua_State* L, GameObject* go) { - uint32 delay = sEluna->CHECKVAL(L, 2, 0); + uint32 delay = Eluna::CHECKVAL(L, 2, 0); go->UseDoorOrButton(delay); return 0; @@ -149,7 +149,7 @@ namespace LuaGameObject int Despawn(lua_State* L, GameObject* go) { - uint32 delay = sEluna->CHECKVAL(L, 2, 1); + uint32 delay = Eluna::CHECKVAL(L, 2, 1); if (!delay) delay = 1; @@ -160,7 +160,7 @@ namespace LuaGameObject int Respawn(lua_State* L, GameObject* go) { - uint32 delay = sEluna->CHECKVAL(L, 2, 1); + uint32 delay = Eluna::CHECKVAL(L, 2, 1); if (!delay) delay = 1; diff --git a/GlobalMethods.h b/GlobalMethods.h index 965b2c5..70d1d1c 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -7,62 +7,60 @@ #ifndef GLOBALMETHODS_H #define GLOBALMETHODS_H -extern bool StartEluna(); - namespace LuaGlobalFunctions { /* GETTERS */ int GetLuaEngine(lua_State* L) { - sEluna->Push(L, "ElunaEngine"); + Eluna::Push(L, "ElunaEngine"); return 1; } int GetCoreName(lua_State* L) { - sEluna->Push(L, CORE_NAME); + Eluna::Push(L, CORE_NAME); return 1; } int GetCoreVersion(lua_State* L) { - sEluna->Push(L, CORE_VERSION); + Eluna::Push(L, CORE_VERSION); return 1; } int GetCoreExpansion(lua_State* L) { #ifdef CLASSIC - sEluna->Push(L, 0); + Eluna::Push(L, 0); #elif defined(TBC) - sEluna->Push(L, 1); + Eluna::Push(L, 1); #elif defined(WOTLK) - sEluna->Push(L, 2); + Eluna::Push(L, 2); #elif defined(CATA) - sEluna->Push(L, 3); + Eluna::Push(L, 3); #endif return 1; } int GetQuest(lua_State* L) { - uint32 questId = sEluna->CHECKVAL(L, 1); + uint32 questId = Eluna::CHECKVAL(L, 1); - sEluna->Push(L, sObjectMgr->GetQuestTemplate(questId)); + Eluna::Push(L, sObjectMgr->GetQuestTemplate(questId)); return 1; } int GetPlayerByGUID(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, sObjectAccessor->FindPlayer(ObjectGuid(guid))); + uint64 guid = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, sObjectAccessor->FindPlayer(ObjectGuid(guid))); return 1; } int GetPlayerByName(lua_State* L) { - const char* message = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, sObjectAccessor->FindPlayerByName(message)); + const char* message = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, sObjectAccessor->FindPlayerByName(message)); return 1; } @@ -70,16 +68,16 @@ namespace LuaGlobalFunctions { time_t time = sWorld->GetGameTime(); if (time < 0) - sEluna->Push(L, int32(time)); + Eluna::Push(L, int32(time)); else - sEluna->Push(L, uint32(time)); + Eluna::Push(L, uint32(time)); return 1; } int GetPlayersInWorld(lua_State* L) { - uint32 team = sEluna->CHECKVAL(L, 1, TEAM_NEUTRAL); - bool onlyGM = sEluna->CHECKVAL(L, 2, false); + uint32 team = Eluna::CHECKVAL(L, 1, TEAM_NEUTRAL); + bool onlyGM = Eluna::CHECKVAL(L, 2, false); lua_newtable(L); int tbl = lua_gettop(L); @@ -97,8 +95,8 @@ namespace LuaGlobalFunctions #endif { ++i; - sEluna->Push(L, i); - sEluna->Push(L, player); + Eluna::Push(L, i); + Eluna::Push(L, player); lua_settable(L, tbl); } } @@ -110,9 +108,9 @@ namespace LuaGlobalFunctions int GetPlayersInMap(lua_State* L) { - uint32 mapID = sEluna->CHECKVAL(L, 1); - uint32 instanceID = sEluna->CHECKVAL(L, 2, 0); - uint32 team = sEluna->CHECKVAL(L, 3, TEAM_NEUTRAL); + uint32 mapID = Eluna::CHECKVAL(L, 1); + uint32 instanceID = Eluna::CHECKVAL(L, 2, 0); + uint32 team = Eluna::CHECKVAL(L, 3, TEAM_NEUTRAL); Map* map = sMapMgr->FindMap(mapID, instanceID); if (!map) @@ -135,8 +133,8 @@ namespace LuaGlobalFunctions if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team)) { ++i; - sEluna->Push(L, i); - sEluna->Push(L, player); + Eluna::Push(L, i); + Eluna::Push(L, player); lua_settable(L, tbl); } } @@ -147,69 +145,69 @@ namespace LuaGlobalFunctions int GetGuildByName(lua_State* L) { - const char* name = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, sGuildMgr->GetGuildByName(name)); + const char* name = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, sGuildMgr->GetGuildByName(name)); return 1; } int GetMapById(lua_State* L) { - uint32 mapid = sEluna->CHECKVAL(L, 1); - uint32 instance = sEluna->CHECKVAL(L, 2); + uint32 mapid = Eluna::CHECKVAL(L, 1); + uint32 instance = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, sMapMgr->FindMap(mapid, instance)); + Eluna::Push(L, sMapMgr->FindMap(mapid, instance)); return 1; } int GetGuildByLeaderGUID(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); + uint64 guid = Eluna::CHECKVAL(L, 1); - sEluna->Push(L, sGuildMgr->GetGuildByLeader(ObjectGuid(guid))); + Eluna::Push(L, sGuildMgr->GetGuildByLeader(ObjectGuid(guid))); return 1; } int GetPlayerCount(lua_State* L) { - sEluna->Push(L, sWorld->GetActiveSessionCount()); + Eluna::Push(L, sWorld->GetActiveSessionCount()); return 1; } int GetPlayerGUID(lua_State* L) { - uint32 lowguid = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); + uint32 lowguid = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); return 1; } int GetItemGUID(lua_State* L) { - uint32 lowguid = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM)); + uint32 lowguid = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM)); return 1; } int GetObjectGUID(lua_State* L) { - uint32 lowguid = sEluna->CHECKVAL(L, 1); - uint32 entry = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); + uint32 lowguid = Eluna::CHECKVAL(L, 1); + uint32 entry = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); return 1; } int GetUnitGUID(lua_State* L) { - uint32 lowguid = sEluna->CHECKVAL(L, 1); - uint32 entry = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT)); + uint32 lowguid = Eluna::CHECKVAL(L, 1); + uint32 entry = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT)); return 1; } int GetGUIDLow(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); + uint64 guid = Eluna::CHECKVAL(L, 1); - sEluna->Push(L, GUID_LOPART(guid)); + Eluna::Push(L, GUID_LOPART(guid)); return 1; } @@ -226,8 +224,8 @@ namespace LuaGlobalFunctions LOCALE_esMX = 7, LOCALE_ruRU = 8 */ - uint32 entry = sEluna->CHECKVAL(L, 1); - int loc_idx = sEluna->CHECKVAL(L, 2, DEFAULT_LOCALE); + uint32 entry = Eluna::CHECKVAL(L, 1); + int loc_idx = Eluna::CHECKVAL(L, 2, DEFAULT_LOCALE); if (loc_idx < 0 || loc_idx >= MAX_LOCALES) return luaL_argerror(L, 2, "valid LocaleConstant expected"); @@ -247,28 +245,28 @@ namespace LuaGlobalFunctions #endif "0:0:0:0|h[" << name << "]|h|r"; - sEluna->Push(L, oss.str()); + Eluna::Push(L, oss.str()); return 1; } int GetGUIDType(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, GUID_HIPART(guid)); + uint64 guid = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, GUID_HIPART(guid)); return 1; } int GetGUIDEntry(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, GUID_ENPART(guid)); + uint64 guid = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, GUID_ENPART(guid)); return 1; } int GetAreaName(lua_State* L) { - uint32 areaOrZoneId = sEluna->CHECKVAL(L, 1); - int locale = sEluna->CHECKVAL(L, 2, DEFAULT_LOCALE); + uint32 areaOrZoneId = Eluna::CHECKVAL(L, 1); + int locale = Eluna::CHECKVAL(L, 2, DEFAULT_LOCALE); if (locale < 0 || locale >= MAX_LOCALES) return luaL_argerror(L, 2, "Invalid locale specified"); @@ -276,25 +274,26 @@ namespace LuaGlobalFunctions if (!areaEntry) return luaL_argerror(L, 1, "Invalid Area or Zone ID"); - sEluna->Push(L, areaEntry->area_name[locale]); + Eluna::Push(L, areaEntry->area_name[locale]); return 1; } /* OTHER */ int RegisterPacketEvent(lua_State* L) { - uint32 ev = sEluna->CHECKVAL(L, 1); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); if (functionRef > 0) - sEluna->Register(REGTYPE_PACKET, 0, ev, functionRef); + sEluna->Register(REGTYPE_PACKET, entry, ev, functionRef); return 0; } int RegisterServerEvent(lua_State* L) { - uint32 ev = sEluna->CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); @@ -305,7 +304,7 @@ namespace LuaGlobalFunctions int RegisterPlayerEvent(lua_State* L) { - uint32 ev = sEluna->CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); @@ -316,7 +315,7 @@ namespace LuaGlobalFunctions int RegisterGuildEvent(lua_State* L) { - uint32 ev = sEluna->CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); @@ -327,7 +326,7 @@ namespace LuaGlobalFunctions int RegisterGroupEvent(lua_State* L) { - uint32 ev = sEluna->CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); @@ -338,8 +337,8 @@ namespace LuaGlobalFunctions int RegisterCreatureGossipEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -350,8 +349,8 @@ namespace LuaGlobalFunctions int RegisterGameObjectGossipEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -362,8 +361,8 @@ namespace LuaGlobalFunctions int RegisterItemEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -374,8 +373,8 @@ namespace LuaGlobalFunctions int RegisterItemGossipEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -386,8 +385,8 @@ namespace LuaGlobalFunctions int RegisterPlayerGossipEvent(lua_State* L) { - uint32 menu_id = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 menu_id = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -398,8 +397,8 @@ namespace LuaGlobalFunctions int RegisterCreatureEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -410,8 +409,8 @@ namespace LuaGlobalFunctions int RegisterGameObjectEvent(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 ev = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 ev = Eluna::CHECKVAL(L, 2); luaL_checktype(L, 3, LUA_TFUNCTION); lua_pushvalue(L, 3); int functionRef = lua_ref(L, true); @@ -422,20 +421,20 @@ namespace LuaGlobalFunctions int ReloadEluna(lua_State* L) { - sEluna->Push(L, StartEluna()); - return 1; + Eluna::ReloadEluna(); + return 0; } int SendWorldMessage(lua_State* L) { - const char* message = sEluna->CHECKVAL(L, 1); + const char* message = Eluna::CHECKVAL(L, 1); sWorld->SendServerMessage(SERVER_MSG_STRING, message); return 0; } int WorldDBQuery(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); if (!query) return 1; @@ -450,13 +449,13 @@ namespace LuaGlobalFunctions if (!result) return 1; - sEluna->Push(L, result); + Eluna::Push(L, result); return 1; } int WorldDBExecute(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); if (query) WorldDatabase.Execute(query); return 0; @@ -464,7 +463,7 @@ namespace LuaGlobalFunctions int CharDBQuery(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); if (!query) return 1; @@ -479,13 +478,13 @@ namespace LuaGlobalFunctions if (!result) return 1; - sEluna->Push(L, result); + Eluna::Push(L, result); return 1; } int CharDBExecute(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); if (query) CharacterDatabase.Execute(query); return 0; @@ -493,7 +492,7 @@ namespace LuaGlobalFunctions int AuthDBQuery(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); QueryResult* result = NULL; #ifdef MANGOS @@ -506,13 +505,13 @@ namespace LuaGlobalFunctions if (!result) return 0; - sEluna->Push(L, result); + Eluna::Push(L, result); return 1; } int AuthDBExecute(lua_State* L) { - const char* query = sEluna->CHECKVAL(L, 1); + const char* query = Eluna::CHECKVAL(L, 1); if (query) LoginDatabase.Execute(query); return 0; @@ -521,54 +520,54 @@ namespace LuaGlobalFunctions int CreateLuaEvent(lua_State* L) { luaL_checktype(L, 1, LUA_TFUNCTION); - uint32 delay = sEluna->CHECKVAL(L, 2); - uint32 repeats = sEluna->CHECKVAL(L, 3); + uint32 delay = Eluna::CHECKVAL(L, 2); + uint32 repeats = Eluna::CHECKVAL(L, 3); lua_pushvalue(L, 1); int functionRef = lua_ref(L, true); - functionRef = sEluna->m_EventMgr.AddEvent(&sEluna->m_EventMgr.GlobalEvents, functionRef, delay, repeats); + functionRef = sEluna->m_EventMgr->AddEvent(&sEluna->m_EventMgr->GlobalEvents, functionRef, delay, repeats); if (functionRef) - sEluna->Push(L, functionRef); + Eluna::Push(L, functionRef); return 1; } int RemoveEventById(lua_State* L) { - int eventId = sEluna->CHECKVAL(L, 1); - bool all_Events = sEluna->CHECKVAL(L, 1, false); + int eventId = Eluna::CHECKVAL(L, 1); + bool all_Events = Eluna::CHECKVAL(L, 1, false); if (all_Events) - sEluna->m_EventMgr.RemoveEvent(eventId); + sEluna->m_EventMgr->RemoveEvent(eventId); else - sEluna->m_EventMgr.RemoveEvent(&sEluna->m_EventMgr.GlobalEvents, eventId); + sEluna->m_EventMgr->RemoveEvent(&sEluna->m_EventMgr->GlobalEvents, eventId); return 0; } int RemoveEvents(lua_State* L) { - bool all_Events = sEluna->CHECKVAL(L, 1, false); + bool all_Events = Eluna::CHECKVAL(L, 1, false); if (all_Events) - sEluna->m_EventMgr.RemoveEvents(); + sEluna->m_EventMgr->RemoveEvents(); else - sEluna->m_EventMgr.GlobalEvents.KillAllEvents(true); + sEluna->m_EventMgr->GlobalEvents.KillAllEvents(true); return 0; } int PerformIngameSpawn(lua_State* L) { - int spawntype = sEluna->CHECKVAL(L, 1); - uint32 entry = sEluna->CHECKVAL(L, 2); - uint32 mapID = sEluna->CHECKVAL(L, 3); - uint32 instanceID = sEluna->CHECKVAL(L, 4); - float x = sEluna->CHECKVAL(L, 5); - float y = sEluna->CHECKVAL(L, 6); - float z = sEluna->CHECKVAL(L, 7); - float o = sEluna->CHECKVAL(L, 8); - bool save = sEluna->CHECKVAL(L, 9, false); - uint32 durorresptime = sEluna->CHECKVAL(L, 10, 0); + int spawntype = Eluna::CHECKVAL(L, 1); + uint32 entry = Eluna::CHECKVAL(L, 2); + uint32 mapID = Eluna::CHECKVAL(L, 3); + uint32 instanceID = Eluna::CHECKVAL(L, 4); + float x = Eluna::CHECKVAL(L, 5); + float y = Eluna::CHECKVAL(L, 6); + float z = Eluna::CHECKVAL(L, 7); + float o = Eluna::CHECKVAL(L, 8); + bool save = Eluna::CHECKVAL(L, 9, false); + uint32 durorresptime = Eluna::CHECKVAL(L, 10, 0); #if (!defined(TBC) && !defined(CLASSIC)) - uint32 phase = sEluna->CHECKVAL(L, 11, PHASEMASK_NORMAL); + uint32 phase = Eluna::CHECKVAL(L, 11, PHASEMASK_NORMAL); if (!phase) return 1; #endif @@ -621,7 +620,7 @@ namespace LuaGlobalFunctions if (durorresptime) pCreature->ForcedDespawn(durorresptime); - sEluna->Push(L, pCreature); + Eluna::Push(L, pCreature); } else { @@ -654,7 +653,7 @@ namespace LuaGlobalFunctions if (pCreature->IsLinkingEventTrigger()) map->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_RESPAWN, pCreature); - sEluna->Push(L, pCreature); + Eluna::Push(L, pCreature); } return 1; @@ -709,7 +708,7 @@ namespace LuaGlobalFunctions sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID)); - sEluna->Push(L, pGameObj); + Eluna::Push(L, pGameObj); } else { @@ -729,7 +728,7 @@ namespace LuaGlobalFunctions map->Add(pGameObj); - sEluna->Push(L, pGameObj); + Eluna::Push(L, pGameObj); } return 1; } @@ -761,7 +760,7 @@ namespace LuaGlobalFunctions } sObjectMgr->AddCreatureToGrid(db_lowguid, sObjectMgr->GetCreatureData(db_lowguid)); - sEluna->Push(L, creature); + Eluna::Push(L, creature); } else { @@ -774,7 +773,7 @@ namespace LuaGlobalFunctions else creature->SetTempSummonType(TEMPSUMMON_MANUAL_DESPAWN); - sEluna->Push(L, creature); + Eluna::Push(L, creature); } return 1; @@ -817,7 +816,7 @@ namespace LuaGlobalFunctions } else map->AddToMap(object); - sEluna->Push(L, object); + Eluna::Push(L, object); return 1; } #endif @@ -827,22 +826,22 @@ namespace LuaGlobalFunctions // CreatePacket(opcode, size) int CreatePacket(lua_State* L) { - uint32 opcode = sEluna->CHECKVAL(L, 1); - uint32 size = sEluna->CHECKVAL(L, 2); + uint32 opcode = Eluna::CHECKVAL(L, 1); + uint32 size = Eluna::CHECKVAL(L, 2); if (opcode >= NUM_MSG_TYPES) return luaL_argerror(L, 1, "valid opcode expected"); - sEluna->Push(L, new WorldPacket((Opcodes)opcode, size)); + Eluna::Push(L, new WorldPacket((Opcodes)opcode, size)); return 1; } int AddVendorItem(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 item = sEluna->CHECKVAL(L, 2); - int maxcount = sEluna->CHECKVAL(L, 3); - uint32 incrtime = sEluna->CHECKVAL(L, 4); - uint32 extendedcost = sEluna->CHECKVAL(L, 5); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 item = Eluna::CHECKVAL(L, 2); + int maxcount = Eluna::CHECKVAL(L, 3); + uint32 incrtime = Eluna::CHECKVAL(L, 4); + uint32 extendedcost = Eluna::CHECKVAL(L, 5); #ifdef MANGOS if (!sObjectMgr->IsVendorItemValid(false, "npc_vendor", entry, item, maxcount, incrtime, extendedcost, 0)) @@ -868,8 +867,8 @@ namespace LuaGlobalFunctions int VendorRemoveItem(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); - uint32 item = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 1); + uint32 item = Eluna::CHECKVAL(L, 2); if (!sObjectMgr->GetCreatureTemplate(entry)) return luaL_argerror(L, 1, "valid CreatureEntry expected"); @@ -883,7 +882,7 @@ namespace LuaGlobalFunctions int VendorRemoveAllItems(lua_State* L) { - uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 entry = Eluna::CHECKVAL(L, 1); VendorItemData const* items = sObjectMgr->GetNpcVendorItemList(entry); if (!items || items->Empty()) @@ -901,18 +900,18 @@ namespace LuaGlobalFunctions int Kick(lua_State* L) { - Player* player = sEluna->CHECKOBJ(L, 1); + Player* player = Eluna::CHECKOBJ(L, 1); player->GetSession()->KickPlayer(); return 0; } int Ban(lua_State* L) { - int banMode = sEluna->CHECKVAL(L, 1); - const char* nameOrIP_cstr = sEluna->CHECKVAL(L, 2); - uint32 duration = sEluna->CHECKVAL(L, 3); - const char* reason = sEluna->CHECKVAL(L, 4); - Player* whoBanned = sEluna->CHECKOBJ(L, 5); + int banMode = Eluna::CHECKVAL(L, 1); + const char* nameOrIP_cstr = Eluna::CHECKVAL(L, 2); + uint32 duration = Eluna::CHECKVAL(L, 3); + const char* reason = Eluna::CHECKVAL(L, 4); + Player* whoBanned = Eluna::CHECKOBJ(L, 5); std::string nameOrIP(nameOrIP_cstr); switch (banMode) @@ -958,12 +957,12 @@ namespace LuaGlobalFunctions int SendMail(lua_State* L) { int i = 0; - std::string subject = sEluna->CHECKVAL(L, ++i); - std::string text = sEluna->CHECKVAL(L, ++i); - uint32 receiverGUIDLow = sEluna->CHECKVAL(L, ++i); - uint32 senderGUIDLow = sEluna->CHECKVAL(L, ++i, 0); - uint32 stationary = sEluna->CHECKVAL(L, ++i, MAIL_STATIONERY_DEFAULT); - uint32 delay = sEluna->CHECKVAL(L, ++i, 0); + std::string subject = Eluna::CHECKVAL(L, ++i); + std::string text = Eluna::CHECKVAL(L, ++i); + uint32 receiverGUIDLow = Eluna::CHECKVAL(L, ++i); + uint32 senderGUIDLow = Eluna::CHECKVAL(L, ++i, 0); + uint32 stationary = Eluna::CHECKVAL(L, ++i, MAIL_STATIONERY_DEFAULT); + uint32 delay = Eluna::CHECKVAL(L, ++i, 0); int argAmount = lua_gettop(L); MailSender sender(MAIL_NORMAL, senderGUIDLow, (MailStationery)stationary); @@ -1018,53 +1017,53 @@ namespace LuaGlobalFunctions // bit_and(a, b) int bit_and(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - uint32 b = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, a & b); + uint32 a = Eluna::CHECKVAL(L, 1); + uint32 b = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, a & b); return 1; } // bit_or(a, b) int bit_or(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - uint32 b = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, a | b); + uint32 a = Eluna::CHECKVAL(L, 1); + uint32 b = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, a | b); return 1; } // bit_lshift(a, b) int bit_lshift(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - uint32 b = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, a << b); + uint32 a = Eluna::CHECKVAL(L, 1); + uint32 b = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, a << b); return 1; } // bit_rshift(a, b) int bit_rshift(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - uint32 b = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, a >> b); + uint32 a = Eluna::CHECKVAL(L, 1); + uint32 b = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, a >> b); return 1; } // bit_xor(a, b) int bit_xor(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - uint32 b = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, a ^ b); + uint32 a = Eluna::CHECKVAL(L, 1); + uint32 b = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, a ^ b); return 1; } // bit_not(a) int bit_not(lua_State* L) { - uint32 a = sEluna->CHECKVAL(L, 1); - sEluna->Push(L, ~a); + uint32 a = Eluna::CHECKVAL(L, 1); + Eluna::Push(L, ~a); return 1; } @@ -1072,10 +1071,10 @@ namespace LuaGlobalFunctions int AddTaxiPath(lua_State* L) { luaL_checktype(L, 1, LUA_TTABLE); - uint32 mountA = sEluna->CHECKVAL(L, 2); - uint32 mountH = sEluna->CHECKVAL(L, 3); - uint32 price = sEluna->CHECKVAL(L, 4, 0); - uint32 pathId = sEluna->CHECKVAL(L, 5, 0); + uint32 mountA = Eluna::CHECKVAL(L, 2); + uint32 mountH = Eluna::CHECKVAL(L, 3); + uint32 price = Eluna::CHECKVAL(L, 4, 0); + uint32 pathId = Eluna::CHECKVAL(L, 5, 0); lua_pushvalue(L, 1); std::list nodes; @@ -1083,11 +1082,11 @@ namespace LuaGlobalFunctions int start = lua_gettop(L); int end = start; - sEluna->Push(L); + Eluna::Push(L); while (lua_next(L, -2) != 0) { luaL_checktype(L, -1, LUA_TTABLE); - sEluna->Push(L); + Eluna::Push(L); while (lua_next(L, -2) != 0) { lua_insert(L, end++); @@ -1104,18 +1103,18 @@ namespace LuaGlobalFunctions while (end - start < 8) // fill optional args with 0 { - sEluna->Push(L, 0); + Eluna::Push(L, 0); lua_insert(L, end++); } TaxiPathNodeEntry* entry = new TaxiPathNodeEntry(); // mandatory - entry->mapid = sEluna->CHECKVAL(L, start); - entry->x = sEluna->CHECKVAL(L, start + 1); - entry->y = sEluna->CHECKVAL(L, start + 2); - entry->z = sEluna->CHECKVAL(L, start + 3); + entry->mapid = Eluna::CHECKVAL(L, start); + entry->x = Eluna::CHECKVAL(L, start + 1); + entry->y = Eluna::CHECKVAL(L, start + 2); + entry->z = Eluna::CHECKVAL(L, start + 3); // optional - entry->actionFlag = sEluna->CHECKVAL(L, start + 4); - entry->delay = sEluna->CHECKVAL(L, start + 5); + entry->actionFlag = Eluna::CHECKVAL(L, start + 4); + entry->delay = Eluna::CHECKVAL(L, start + 5); nodes.push_back(*entry); @@ -1126,13 +1125,43 @@ namespace LuaGlobalFunctions lua_pop(L, 1); } - sEluna->Push(L, LuaTaxiMgr::AddPath(nodes, mountA, mountH, price, pathId)); + if (nodes.size() < 2) + return 1; + if (!pathId) + pathId = sTaxiPathNodesByPath.size(); + if (sTaxiPathNodesByPath.size() <= pathId) + sTaxiPathNodesByPath.resize(pathId + 1); + sTaxiPathNodesByPath[pathId].clear(); + sTaxiPathNodesByPath[pathId].resize(nodes.size()); + static uint32 nodeId = 500; + uint32 startNode = nodeId; + uint32 index = 0; + for (std::list::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + { + TaxiPathNodeEntry entry = *it; + entry.path = pathId; + TaxiNodesEntry* nodeEntry = new TaxiNodesEntry(); + nodeEntry->ID = index; + nodeEntry->map_id = entry.mapid; + nodeEntry->MountCreatureID[0] = mountH; + nodeEntry->MountCreatureID[1] = mountA; + nodeEntry->x = entry.x; + nodeEntry->y = entry.y; + nodeEntry->z = entry.z; + sTaxiNodesStore.SetEntry(nodeId, nodeEntry); + entry.index = nodeId++; + sTaxiPathNodesByPath[pathId].set(index++, TaxiPathNodePtr(new TaxiPathNodeEntry(entry))); + } + if (startNode >= nodeId) + return 1; + sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); + Eluna::Push(L, pathId); return 1; } int AddCorpse(lua_State* L) { - Corpse* corpse = sEluna->CHECKOBJ(L, 1); + Corpse* corpse = Eluna::CHECKOBJ(L, 1); sObjectAccessor->AddCorpse(corpse); return 0; @@ -1140,17 +1169,17 @@ namespace LuaGlobalFunctions int RemoveCorpse(lua_State* L) { - Corpse* corpse = sEluna->CHECKOBJ(L, 1); + Corpse* corpse = Eluna::CHECKOBJ(L, 1); sObjectAccessor->RemoveCorpse(corpse); return 1; } int ConvertCorpseForPlayer(lua_State* L) { - uint64 guid = sEluna->CHECKVAL(L, 1); - bool insignia = sEluna->CHECKVAL(L, 2, false); + uint64 guid = Eluna::CHECKVAL(L, 1); + bool insignia = Eluna::CHECKVAL(L, 2, false); - sEluna->Push(L, sObjectAccessor->ConvertCorpseForPlayer(ObjectGuid(guid), insignia)); + Eluna::Push(L, sObjectAccessor->ConvertCorpseForPlayer(ObjectGuid(guid), insignia)); return 0; } @@ -1162,31 +1191,31 @@ namespace LuaGlobalFunctions int FindWeather(lua_State* L) { - uint32 zoneId = sEluna->CHECKVAL(L, 1); + uint32 zoneId = Eluna::CHECKVAL(L, 1); #ifdef MANGOS Weather* weather = sWorld->FindWeather(zoneId); #else Weather* weather = WeatherMgr::FindWeather(zoneId); #endif - sEluna->Push(L, weather); + Eluna::Push(L, weather); return 1; } int AddWeather(lua_State* L) { - uint32 zoneId = sEluna->CHECKVAL(L, 1); + uint32 zoneId = Eluna::CHECKVAL(L, 1); #ifdef MANGOS Weather* weather = sWorld->AddWeather(zoneId); #else Weather* weather = WeatherMgr::AddWeather(zoneId); #endif - sEluna->Push(L, weather); + Eluna::Push(L, weather); return 1; } int RemoveWeather(lua_State* L) { - uint32 zoneId = sEluna->CHECKVAL(L, 1); + uint32 zoneId = Eluna::CHECKVAL(L, 1); #ifdef MANGOS sWorld->RemoveWeather(zoneId); #else @@ -1197,7 +1226,7 @@ namespace LuaGlobalFunctions int SendFineWeatherToPlayer(lua_State* L) { - Player* player = sEluna->CHECKOBJ(L, 1); + Player* player = Eluna::CHECKOBJ(L, 1); #ifdef MANGOS Weather::SendFineWeatherUpdateToPlayer(player); #else diff --git a/GroupMethods.h b/GroupMethods.h index f99f0f1..bee861a 100644 --- a/GroupMethods.h +++ b/GroupMethods.h @@ -12,76 +12,76 @@ namespace LuaGroup /* BOOLEAN */ int IsLeader(lua_State* L, Group* group) { - uint64 guid = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, group->IsLeader(ObjectGuid(guid))); + uint64 guid = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, group->IsLeader(ObjectGuid(guid))); return 1; } int IsFull(lua_State* L, Group* group) { - sEluna->Push(L, group->IsFull()); + Eluna::Push(L, group->IsFull()); return 1; } int isRaidGroup(lua_State* L, Group* group) { - sEluna->Push(L, group->isRaidGroup()); + Eluna::Push(L, group->isRaidGroup()); return 1; } int isBGGroup(lua_State* L, Group* group) { - sEluna->Push(L, group->isBGGroup()); + Eluna::Push(L, group->isBGGroup()); return 1; } int IsMember(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); - sEluna->Push(L, group->IsMember(player->GET_GUID())); + Player* player = Eluna::CHECKOBJ(L, 2); + Eluna::Push(L, group->IsMember(player->GET_GUID())); return 1; } int IsAssistant(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, group->IsAssistant(player->GET_GUID())); + Eluna::Push(L, group->IsAssistant(player->GET_GUID())); return 1; } int SameSubGroup(lua_State* L, Group* group) { - Player* player1 = sEluna->CHECKOBJ(L, 2); - Player* player2 = sEluna->CHECKOBJ(L, 3); - sEluna->Push(L, group->SameSubGroup(player1, player2)); + Player* player1 = Eluna::CHECKOBJ(L, 2); + Player* player2 = Eluna::CHECKOBJ(L, 3); + Eluna::Push(L, group->SameSubGroup(player1, player2)); return 1; } int HasFreeSlotSubGroup(lua_State* L, Group* group) { - uint8 subGroup = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, group->HasFreeSlotSubGroup(subGroup)); + uint8 subGroup = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, group->HasFreeSlotSubGroup(subGroup)); return 1; } int AddInvite(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, group->AddInvite(player)); + Eluna::Push(L, group->AddInvite(player)); return 1; } /*int isLFGGroup(lua_State* L, Group* group) // TODO: Implementation { - sEluna->Push(L, group->isLFGGroup()); + Eluna::Push(L, group->isLFGGroup()); return 1; }*/ /*int isBFGroup(lua_State* L, Group* group) // TODO: Implementation { - sEluna->Push(L, group->isBFGroup()); + Eluna::Push(L, group->isBFGroup()); return 1; }*/ @@ -104,8 +104,8 @@ namespace LuaGroup continue; ++i; - sEluna->Push(L, i); - sEluna->Push(L, member); + Eluna::Push(L, i); + Eluna::Push(L, member); lua_settable(L, tbl); } @@ -116,9 +116,9 @@ namespace LuaGroup int GetLeaderGUID(lua_State* L, Group* group) { #ifdef MANGOS - sEluna->Push(L, group->GetLeaderGuid()); + Eluna::Push(L, group->GetLeaderGuid()); #else - sEluna->Push(L, group->GetLeaderGUID()); + Eluna::Push(L, group->GetLeaderGUID()); #endif return 1; } @@ -126,9 +126,9 @@ namespace LuaGroup int GetLeader(lua_State* L, Group* group) { #ifdef MANGOS - sEluna->Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGuid())); + Eluna::Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGuid())); #else - sEluna->Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGUID())); + Eluna::Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGUID())); #endif return 1; } @@ -136,42 +136,42 @@ namespace LuaGroup int GetGUID(lua_State* L, Group* group) { #ifdef CLASSIC - sEluna->Push(L, group->GetId()); + Eluna::Push(L, group->GetId()); #else - sEluna->Push(L, group->GET_GUID()); + Eluna::Push(L, group->GET_GUID()); #endif return 1; } int GetMemberGUID(lua_State* L, Group* group) { - const char* name = sEluna->CHECKVAL(L, 2); + const char* name = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, group->GetMemberGuid(name)); + Eluna::Push(L, group->GetMemberGuid(name)); #else - sEluna->Push(L, group->GetMemberGUID(name)); + Eluna::Push(L, group->GetMemberGUID(name)); #endif return 1; } int GetMembersCount(lua_State* L, Group* group) { - sEluna->Push(L, group->GetMembersCount()); + Eluna::Push(L, group->GetMembersCount()); return 1; } int GetMemberGroup(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, group->GetMemberGroup(player->GET_GUID())); + Eluna::Push(L, group->GetMemberGroup(player->GET_GUID())); return 1; } /* OTHER */ int ChangeLeader(lua_State* L, Group* group) { - Player* leader = sEluna->CHECKOBJ(L, 2); + Player* leader = Eluna::CHECKOBJ(L, 2); group->ChangeLeader(leader->GET_GUID()); return 0; @@ -180,9 +180,9 @@ namespace LuaGroup // SendPacket(packet, sendToPlayersInBattleground[, ignoreguid]) int SendPacket(lua_State* L, Group* group) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); - bool ignorePlayersInBg = sEluna->CHECKVAL(L, 3); - uint64 ignore = sEluna->CHECKVAL(L, 4); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); + bool ignorePlayersInBg = Eluna::CHECKVAL(L, 3); + uint64 ignore = Eluna::CHECKVAL(L, 4); group->BroadcastPacket(data, ignorePlayersInBg, -1, ObjectGuid(ignore)); return 0; @@ -190,13 +190,13 @@ namespace LuaGroup int RemoveMember(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint32 method = sEluna->CHECKVAL(L, 3, 0); + Player* player = Eluna::CHECKOBJ(L, 2); + uint32 method = Eluna::CHECKVAL(L, 3, 0); #ifdef MANGOS - sEluna->Push(L, group->RemoveMember(player->GET_GUID(), method)); + Eluna::Push(L, group->RemoveMember(player->GET_GUID(), method)); #else - sEluna->Push(L, group->RemoveMember(player->GET_GUID(), (RemoveMethod)method)); + Eluna::Push(L, group->RemoveMember(player->GET_GUID(), (RemoveMethod)method)); #endif return 1; } @@ -215,8 +215,8 @@ namespace LuaGroup int ChangeMembersGroup(lua_State* L, Group* group) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint8 groupID = sEluna->CHECKVAL(L, 3); + Player* player = Eluna::CHECKOBJ(L, 2); + uint8 groupID = Eluna::CHECKVAL(L, 3); group->ChangeMembersGroup(player->GET_GUID(), groupID); return 0; @@ -224,9 +224,9 @@ namespace LuaGroup int SetTargetIcon(lua_State* L, Group* group) { - uint8 icon = sEluna->CHECKVAL(L, 2); - uint64 target = sEluna->CHECKVAL(L, 3); - uint64 setter = sEluna->CHECKVAL(L, 4, 0); + uint8 icon = Eluna::CHECKVAL(L, 2); + uint64 target = Eluna::CHECKVAL(L, 3); + uint64 setter = Eluna::CHECKVAL(L, 4, 0); if (icon >= TARGETICONCOUNT) return luaL_argerror(L, 2, "valid target icon expected"); diff --git a/GuildMethods.h b/GuildMethods.h index 7cc10d4..d0500bd 100644 --- a/GuildMethods.h +++ b/GuildMethods.h @@ -24,8 +24,8 @@ namespace LuaGuild if (player->GetSession() && (player->GetGuildId() == guild->GetId())) { ++i; - sEluna->Push(L, i); - sEluna->Push(L, player); + Eluna::Push(L, i); + Eluna::Push(L, player); lua_settable(L, tbl); } } @@ -37,16 +37,16 @@ namespace LuaGuild int GetMemberCount(lua_State* L, Guild* guild) { - sEluna->Push(L, guild->GetMemberSize()); + Eluna::Push(L, guild->GetMemberSize()); return 1; } int GetLeader(lua_State* L, Guild* guild) { #ifdef MANGOS - sEluna->Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGuid())); + Eluna::Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGuid())); #else - sEluna->Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGUID())); + Eluna::Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGUID())); #endif return 1; } @@ -54,37 +54,37 @@ namespace LuaGuild int GetLeaderGUID(lua_State* L, Guild* guild) { #ifdef MANGOS - sEluna->Push(L, guild->GetLeaderGuid()); + Eluna::Push(L, guild->GetLeaderGuid()); #else - sEluna->Push(L, guild->GetLeaderGUID()); + Eluna::Push(L, guild->GetLeaderGUID()); #endif return 1; } int GetId(lua_State* L, Guild* guild) { - sEluna->Push(L, guild->GetId()); + Eluna::Push(L, guild->GetId()); return 1; } int GetName(lua_State* L, Guild* guild) { - sEluna->Push(L, guild->GetName()); + Eluna::Push(L, guild->GetName()); return 1; } int GetMOTD(lua_State* L, Guild* guild) { - sEluna->Push(L, guild->GetMOTD()); + Eluna::Push(L, guild->GetMOTD()); return 1; } int GetInfo(lua_State* L, Guild* guild) { #ifdef MANGOS - sEluna->Push(L, guild->GetGINFO()); + Eluna::Push(L, guild->GetGINFO()); #else - sEluna->Push(L, guild->GetInfo()); + Eluna::Push(L, guild->GetInfo()); #endif return 1; } @@ -93,7 +93,7 @@ namespace LuaGuild #ifndef CATA int SetLeader(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS guild->SetLeader(player->GET_GUID()); @@ -107,8 +107,8 @@ namespace LuaGuild #ifndef CLASSIC int SetBankTabText(lua_State* L, Guild* guild) { - uint8 tabId = sEluna->CHECKVAL(L, 2); - const char* text = sEluna->CHECKVAL(L, 3); + uint8 tabId = Eluna::CHECKVAL(L, 2); + const char* text = Eluna::CHECKVAL(L, 3); #ifdef MANGOS guild->SetGuildBankTabText(tabId, text); #else @@ -122,7 +122,7 @@ namespace LuaGuild // SendPacketToGuild(packet) int SendPacket(lua_State* L, Guild* guild) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); guild->BroadcastPacket(data); return 0; @@ -131,8 +131,8 @@ namespace LuaGuild // SendPacketToRankedInGuild(packet, rankId) int SendPacketToRanked(lua_State* L, Guild* guild) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); - uint8 ranked = sEluna->CHECKVAL(L, 3); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); + uint8 ranked = Eluna::CHECKVAL(L, 3); guild->BroadcastPacketToRank(data, ranked); return 0; @@ -146,8 +146,8 @@ namespace LuaGuild int AddMember(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint8 rankId = sEluna->CHECKVAL(L, 3, GUILD_RANK_NONE); + Player* player = Eluna::CHECKOBJ(L, 2); + uint8 rankId = Eluna::CHECKVAL(L, 3, GUILD_RANK_NONE); guild->AddMember(player->GET_GUID(), rankId); return 0; @@ -155,8 +155,8 @@ namespace LuaGuild int DeleteMember(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); - bool isDisbanding = sEluna->CHECKVAL(L, 3, false); + Player* player = Eluna::CHECKOBJ(L, 2); + bool isDisbanding = Eluna::CHECKVAL(L, 3, false); #ifdef MANGOS guild->DelMember(player->GET_GUID(), isDisbanding); @@ -168,8 +168,8 @@ namespace LuaGuild int ChangeMemberRank(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint8 newRank = sEluna->CHECKVAL(L, 3); + Player* player = Eluna::CHECKOBJ(L, 2); + uint8 newRank = Eluna::CHECKVAL(L, 3); guild->ChangeMemberRank(player->GET_GUID(), newRank); return 0; @@ -179,8 +179,8 @@ namespace LuaGuild // Move to Player methods int WithdrawBankMoney(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint32 money = sEluna->CHECKVAL(L, 3); + Player* player = Eluna::CHECKOBJ(L, 2); + uint32 money = Eluna::CHECKVAL(L, 3); #ifdef MANGOS if (guild->GetGuildBankMoney() < money) return 0; @@ -194,8 +194,8 @@ namespace LuaGuild // Move to Player methods int DepositBankMoney(lua_State* L, Guild* guild) { - Player* player = sEluna->CHECKOBJ(L, 2); - uint32 money = sEluna->CHECKVAL(L, 3); + Player* player = Eluna::CHECKOBJ(L, 2); + uint32 money = Eluna::CHECKVAL(L, 3); #ifdef MANGOS guild->SetBankMoney(guild->GetGuildBankMoney() + money); diff --git a/HookMgr.cpp b/HookMgr.cpp index 56e7c42..6198483 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -4,488 +4,455 @@ * Please see the included DOCS/LICENSE.md for more information */ -#include "LuaEngine.h" #include "HookMgr.h" +#include "LuaEngine.h" +#include "Includes.h" -void HookMgr::RemoveRef(const void* obj) const +/* +Call model for EventBind: + +// Begin the call if should +EVENT_BEGIN(bindmap, eventid, return returnvalue); +// push arguments +Push(L, pPlayer); +EVENT_EXECUTE(returnedargs); +FOR_RET(iter) { - lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, sHookMgr->userdata_table); - lua_pushfstring(sEluna->L, "%p", obj); - lua_gettable(sEluna->L, -2); - if (!lua_isnoneornil(sEluna->L, -1)) - { - lua_pushfstring(sEluna->L, "%p", obj); - lua_pushnil(sEluna->L); - lua_settable(sEluna->L, -4); - } - lua_pop(sEluna->L, 2); +// process returned arguments } +ENDCALL(); +*/ -void HookMgr::OnEngineRestart() -{ - if (!sEluna->ServerEventBindings.HasEvents(ELUNA_EVENT_ON_RESTART)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(ELUNA_EVENT_ON_RESTART); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} +// RET is a return statement +#define EVENT_BEGIN(BINDMAP, EVENT, RET) \ + if (!BINDMAP->HasEvents(EVENT)) \ + RET; \ + lua_State* L = sEluna->L; \ + uint32 _LuaEvent = EVENT; \ + int _LuaStackTop = lua_gettop(L); \ + EventBind* _LuaBindMap = sEluna->BINDMAP; \ + Eluna::Push(L, _LuaEvent); -void HookMgr::OnWorldUpdate(uint32 diff) +// use LUA_MULTRET for multiple return values +// return values will be at top of stack if any +#define EVENT_EXECUTE(RETVALS) \ + int _LuaReturnValues = RETVALS; \ + int _LuaParams = lua_gettop(L) - _LuaStackTop; \ + if (_LuaParams < 1) \ + { \ + ELUNA_LOG_ERROR("[Eluna]: Executing event %u, params was %i. Report to devs", _LuaEvent, _LuaParams); \ + } \ + for (EventBind::ElunaBindingMap::const_iterator it = _LuaBindMap->Bindings[_LuaEvent].begin(); it != _LuaBindMap->Bindings[_LuaEvent].end(); ++it) \ + { \ + lua_rawgeti(L, LUA_REGISTRYINDEX, (*it)); \ + int stacktop = lua_gettop(L); \ + for (int i = stacktop - _LuaParams; i < stacktop; ++i) \ + lua_pushvalue(L, i); \ + Eluna::ExecuteCall(L, _LuaParams, _LuaReturnValues); \ + } \ + for (int i = _LuaParams; i > 0; --i) \ + if (!lua_isnone(L, i)) \ + lua_remove(L, i); + +// RET is a return statement +#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \ + int _Luabind = sEluna->BINDMAP->GetBind(ENTRY, EVENT); \ + if (!_Luabind) \ + RET; \ + lua_State* L = sEluna->L; \ + uint32 _LuaEvent = EVENT; \ + int _LuaStackTop = lua_gettop(L); \ + EntryBind* _LuaBindMap = sEluna->BINDMAP; \ + lua_rawgeti(L, LUA_REGISTRYINDEX, _Luabind); \ + Eluna::Push(L, _LuaEvent); + +#define ENTRY_EXECUTE(RETVALS) \ + int _LuaReturnValues = RETVALS; \ + int _LuaParams = lua_gettop(L) - _LuaStackTop - 1; \ + Eluna::ExecuteCall(L, _LuaParams, _LuaReturnValues); + +#define FOR_RETS(IT) \ + for (int IT = _LuaStackTop + 1; IT <= lua_gettop(L); ++IT) + +#define ENDCALL() \ + if (_LuaReturnValues != LUA_MULTRET && lua_gettop(L) != _LuaStackTop + _LuaReturnValues) \ + { \ + ELUNA_LOG_ERROR("[Eluna]: Ending event %u, stack top was %i and was supposed to be %i. Report to devs", _LuaEvent, lua_gettop(L), _LuaStackTop); \ + } \ + lua_settop(L, _LuaStackTop); + +void Eluna::OnLuaStateClose() { - sEluna->m_EventMgr.Update(diff); - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_UPDATE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE); - sEluna->Push(sEluna->L, diff); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, ELUNA_EVENT_ON_LUA_STATE_CLOSE, return); + EVENT_EXECUTE(0); + ENDCALL(); } // areatrigger -bool HookMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) +bool Eluna::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) { - if (!sEluna->ServerEventBindings.HasEvents(TRIGGER_EVENT_ON_TRIGGER)) - return false; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(TRIGGER_EVENT_ON_TRIGGER); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pTrigger->id); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, TRIGGER_EVENT_ON_TRIGGER, return false); + Push(L, pPlayer); + Push(L, pTrigger->id); + EVENT_EXECUTE(0); + ENDCALL(); return false; } // weather -void HookMgr::OnChange(Weather* weather, WeatherState state, float grade) +void Eluna::OnChange(Weather* weather, WeatherState state, float grade) { - if (!sEluna->ServerEventBindings.HasEvents(WEATHER_EVENT_ON_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WEATHER_EVENT_ON_CHANGE); - sEluna->Push(sEluna->L, (weather->GetZone())); - sEluna->Push(sEluna->L, state); - sEluna->Push(sEluna->L, grade); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, WEATHER_EVENT_ON_CHANGE, return); + Push(L, weather->GetZone()); + Push(L, state); + Push(L, grade); + EVENT_EXECUTE(0); + ENDCALL(); } // Auction House -void HookMgr::OnAdd(AuctionHouseObject* ah) +void Eluna::OnAdd(AuctionHouseObject* ah) { - if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_ADD)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_ADD); - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, AUCTION_EVENT_ON_ADD, return); + Push(L, (ah)); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnRemove(AuctionHouseObject* ah) +void Eluna::OnRemove(AuctionHouseObject* ah) { - if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_REMOVE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_REMOVE); - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, AUCTION_EVENT_ON_REMOVE, return); + Push(L, (ah)); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnSuccessful(AuctionHouseObject* ah) +void Eluna::OnSuccessful(AuctionHouseObject* ah) { - if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_SUCCESSFUL)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_SUCCESSFUL); - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, AUCTION_EVENT_ON_SUCCESSFUL, return); + Push(L, (ah)); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnExpire(AuctionHouseObject* ah) +void Eluna::OnExpire(AuctionHouseObject* ah) { - if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_EXPIRE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_EXPIRE); - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, AUCTION_EVENT_ON_EXPIRE, return); + Push(L, (ah)); + EVENT_EXECUTE(0); + ENDCALL(); } // Packet -bool HookMgr::OnPacketSend(WorldSession* session, WorldPacket& packet) +bool Eluna::OnPacketSend(WorldSession* session, WorldPacket& packet) { bool result = true; Player* player = NULL; if (session) player = session->GetPlayer(); - if (sEluna->ServerEventBindings.HasEvents(SERVER_EVENT_ON_PACKET_SEND)) - { - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_SEND); - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->ServerEventBindings.EndCall(); - } - if (sEluna->PacketEventBindings.HasEvents(Opcodes(packet.GetOpcode()))) - { - ELUNA_GUARD(); - sEluna->PacketEventBindings.BeginCall(Opcodes(packet.GetOpcode())); - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->PacketEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->PacketEventBindings.EndCall(); - } + OnPacketSendOne(player, packet, result); + OnPacketSendOne(player, packet, result); return result; } -bool HookMgr::OnPacketReceive(WorldSession* session, WorldPacket& packet) +void Eluna::OnPacketSendAny(Player* player, WorldPacket& packet, bool& result) +{ + EVENT_BEGIN(ServerEventBindings, SERVER_EVENT_ON_PACKET_SEND, return); + Push(L, new WorldPacket(packet)); + Push(L, player); + EVENT_EXECUTE(2); + FOR_RETS(i) + { + if (lua_isnoneornil(L, i)) + continue; + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (!CHECKVAL(L, i, true)) + { + result = false; + break; + } + } + ENDCALL(); +} +void Eluna::OnPacketSendOne(Player* player, WorldPacket& packet, bool& result) +{ + ENTRY_BEGIN(PacketEventBindings, Opcodes(packet.GetOpcode()), SERVER_EVENT_ON_PACKET_SEND, return); + Push(L, new WorldPacket(packet)); + Push(L, player); + ENTRY_EXECUTE(2); + FOR_RETS(i) + { + if (lua_isnoneornil(L, i)) + continue; + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (!CHECKVAL(L, i, true)) + { + result = false; + break; + } + } + ENDCALL(); +} + +bool Eluna::OnPacketReceive(WorldSession* session, WorldPacket& packet) { bool result = true; Player* player = NULL; if (session) player = session->GetPlayer(); - if (sEluna->ServerEventBindings.HasEvents(SERVER_EVENT_ON_PACKET_RECEIVE)) - { - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_RECEIVE); - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->ServerEventBindings.EndCall(); - } - if (sEluna->PacketEventBindings.HasEvents(Opcodes(packet.GetOpcode()))) - { - ELUNA_GUARD(); - sEluna->PacketEventBindings.BeginCall(Opcodes(packet.GetOpcode())); - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->PacketEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->PacketEventBindings.EndCall(); - } + OnPacketReceiveAny(player, packet, result); + OnPacketReceiveOne(player, packet, result); return result; } +void Eluna::OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result) +{ + EVENT_BEGIN(ServerEventBindings, SERVER_EVENT_ON_PACKET_RECEIVE, return); + Push(L, new WorldPacket(packet)); + Push(L, player); + EVENT_EXECUTE(2); + FOR_RETS(i) + { + if (lua_isnoneornil(L, i)) + continue; + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (!CHECKVAL(L, i, true)) + { + result = false; + break; + } + } + ENDCALL(); +} +void Eluna::OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result) +{ + ENTRY_BEGIN(PacketEventBindings, Opcodes(packet.GetOpcode()), SERVER_EVENT_ON_PACKET_RECEIVE, return); + Push(L, new WorldPacket(packet)); + Push(L, player); + ENTRY_EXECUTE(2); + FOR_RETS(i) + { + if (lua_isnoneornil(L, i)) + continue; + if (WorldPacket* data = CHECKOBJ(L, i, false)) + packet = *data; + if (!CHECKVAL(L, i, true)) + { + result = false; + break; + } + } + ENDCALL(); +} + // AddOns -bool HookMgr::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel) +bool Eluna::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel) { - if (!sEluna->ServerEventBindings.HasEvents(ADDON_EVENT_ON_MESSAGE)) - return false; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(ADDON_EVENT_ON_MESSAGE); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, type); + EVENT_BEGIN(ServerEventBindings, ADDON_EVENT_ON_MESSAGE, return false); + Push(L, sender); + Push(L, type); const char* c_msg = msg.c_str(); - sEluna->Push(sEluna->L, strtok((char*)c_msg, "\t")); // prefix - sEluna->Push(sEluna->L, strtok(NULL, "")); // msg + Push(L, strtok((char*)c_msg, "\t")); // prefix + Push(L, strtok(NULL, "")); // msg if (receiver) - sEluna->Push(sEluna->L, receiver); + Push(L, receiver); else if (guild) - sEluna->Push(sEluna->L, guild); + Push(L, guild); else if (group) - sEluna->Push(sEluna->L, group); + Push(L, group); else if (channel) - sEluna->Push(sEluna->L, channel->GetChannelId()); + Push(L, channel->GetChannelId()); else - sEluna->Push(sEluna->L); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + Push(L); + EVENT_EXECUTE(0); + ENDCALL(); return true; } -#ifndef MANGOS -class ElunaWorldAI : public WorldScript +void Eluna::OnOpenStateChange(bool open) { -public: - ElunaWorldAI(): WorldScript("ElunaWorldAI") {} - ~ElunaWorldAI() {} - - void OnOpenStateChange(bool open) override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_OPEN_STATE_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_OPEN_STATE_CHANGE); - sEluna->Push(sEluna->L, open); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnConfigLoad(bool reload) override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_CONFIG_LOAD)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_CONFIG_LOAD); - sEluna->Push(sEluna->L, reload); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN_INIT)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_INIT); - sEluna->Push(sEluna->L, code); - sEluna->Push(sEluna->L, mask); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdownCancel() override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN_CANCEL)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_CANCEL); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnUpdate(uint32 diff) override - { - sEluna->m_EventMgr.Update(diff); - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_UPDATE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE); - sEluna->Push(sEluna->L, diff); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnStartup() override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_STARTUP)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_STARTUP); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdown() override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } -}; -#endif - -void HookMgr::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code) -{ - int bind = sEluna->ItemGossipBindings.GetBind(item->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (bind) - { - ELUNA_GUARD(); - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, item); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - if (code.empty()) - sEluna->Push(sEluna->L); - else - sEluna->Push(sEluna->L, code); - sEluna->ExecuteCall(6, 0); - } + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_OPEN_STATE_CHANGE, return); + Push(L, open); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code) +void Eluna::OnConfigLoad(bool reload) { - int bind = sEluna->playerGossipBindings.GetBind(menuId, GOSSIP_EVENT_ON_SELECT); - if (bind) - { - ELUNA_GUARD(); - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); // receiver - sEluna->Push(sEluna->L, pPlayer); // sender, just not to mess up the amount of args. - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - if (code.empty()) - sEluna->Push(sEluna->L); - else - sEluna->Push(sEluna->L, code); - sEluna->Push(sEluna->L, menuId); - sEluna->ExecuteCall(7, 0); - } + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_CONFIG_LOAD, return); + Push(L, reload); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) +{ + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_SHUTDOWN_INIT, return); + Push(L, code); + Push(L, mask); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::OnShutdownCancel() +{ + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_SHUTDOWN_CANCEL, return); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::OnWorldUpdate(uint32 diff) +{ + m_EventMgr->Update(diff); + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_UPDATE, return); + Push(L, diff); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::OnStartup() +{ + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_STARTUP, return); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::OnShutdown() +{ + EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_SHUTDOWN, return); + EVENT_EXECUTE(0); + ENDCALL(); +} + +void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code) +{ + ENTRY_BEGIN(ItemGossipBindings, item->GetEntry(), GOSSIP_EVENT_ON_SELECT, return); + pPlayer->PlayerTalkClass->ClearMenus(); + Push(L, pPlayer); + Push(L, item); + Push(L, sender); + Push(L, action); + if (code.empty()) + Push(L); + else + Push(L, code); + ENTRY_EXECUTE(0); + ENDCALL(); +} + +void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code) +{ + ENTRY_BEGIN(playerGossipBindings, menuId, GOSSIP_EVENT_ON_SELECT, return); + pPlayer->PlayerTalkClass->ClearMenus(); + Push(L, pPlayer); // receiver + Push(L, pPlayer); // sender, just not to mess up the amount of args. + Push(L, sender); + Push(L, action); + if (code.empty()) + Push(L); + else + Push(L, code); + ENTRY_EXECUTE(0); + ENDCALL(); } // item -bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget) +bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget) { - int bind = sEluna->ItemEventBindings.GetBind(pTarget->GetEntry(), ITEM_EVENT_ON_DUMMY_EFFECT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, ITEM_EVENT_ON_DUMMY_EFFECT); - sEluna->Push(sEluna->L, pCaster); - sEluna->Push(sEluna->L, spellId); - sEluna->Push(sEluna->L, effIndex); - sEluna->Push(sEluna->L, pTarget); - sEluna->ExecuteCall(5, 0); + ENTRY_BEGIN(ItemEventBindings, pTarget->GetEntry(), ITEM_EVENT_ON_DUMMY_EFFECT, return false); + Push(L, pCaster); + Push(L, spellId); + Push(L, effIndex); + Push(L, pTarget); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) +bool Eluna::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) { - int bind = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_QUEST_ACCEPT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, ITEM_EVENT_ON_QUEST_ACCEPT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(ItemEventBindings, pItem->GetEntry(), ITEM_EVENT_ON_QUEST_ACCEPT, return false); + Push(L, pPlayer); + Push(L, pItem); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) +bool Eluna::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) { - int bind1 = sEluna->ItemGossipBindings.GetBind(pItem->GetEntry(), GOSSIP_EVENT_ON_HELLO); - int bind2 = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_USE); - if (!bind1 && !bind2) - return false; - ELUNA_GUARD(); - if (bind1) - { - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind1); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->ExecuteCall(3, 0); - } - if (bind2) - { - sEluna->BeginCall(bind2); - sEluna->Push(sEluna->L, ITEM_EVENT_ON_USE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); -#ifdef MANGOS - if (GameObject* target = targets.getGOTarget()) - sEluna->Push(sEluna->L, target); - else if (Item* target = targets.getItemTarget()) - sEluna->Push(sEluna->L, target); - else if (Corpse* target = pPlayer->GetMap()->GetCorpse(targets.getCorpseTargetGuid())) - sEluna->Push(sEluna->L, target); - else if (Unit* target = targets.getUnitTarget()) - sEluna->Push(sEluna->L, target); - else - sEluna->Push(sEluna->L); -#else - if (GameObject* target = targets.GetGOTarget()) - sEluna->Push(sEluna->L, target); - else if (Item* target = targets.GetItemTarget()) - sEluna->Push(sEluna->L, target); - else if (Corpse* target = targets.GetCorpseTarget()) - sEluna->Push(sEluna->L, target); - else if (Unit* target = targets.GetUnitTarget()) - sEluna->Push(sEluna->L, target); - else if (WorldObject* target = targets.GetObjectTarget()) - sEluna->Push(sEluna->L, target); - else - sEluna->Push(sEluna->L); -#endif - sEluna->ExecuteCall(4, 0); - } + OnItemUse(pPlayer, pItem, targets); + OnItemGossip(pPlayer, pItem, targets); // pPlayer->SendEquipError((InventoryResult)83, pItem, NULL); + // return true; + return false; +} +bool Eluna::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) +{ + ENTRY_BEGIN(ItemEventBindings, pItem->GetEntry(), GOSSIP_EVENT_ON_HELLO, return false); + Push(L, pPlayer); + Push(L, pItem); +#ifdef MANGOS + if (GameObject* target = targets.getGOTarget()) + Push(L, target); + else if (Item* target = targets.getItemTarget()) + Push(L, target); + else if (Corpse* target = pPlayer->GetMap()->GetCorpse(targets.getCorpseTargetGuid())) + Push(L, target); + else if (Unit* target = targets.getUnitTarget()) + Push(L, target); + else + Push(L); +#else + if (GameObject* target = targets.GetGOTarget()) + Push(L, target); + else if (Item* target = targets.GetItemTarget()) + Push(L, target); + else if (Corpse* target = targets.GetCorpseTarget()) + Push(L, target); + else if (Unit* target = targets.GetUnitTarget()) + Push(L, target); + else if (WorldObject* target = targets.GetObjectTarget()) + Push(L, target); + else + Push(L); +#endif + ENTRY_EXECUTE(0); + ENDCALL(); + return true; +} +bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) +{ + ENTRY_BEGIN(ItemEventBindings, pItem->GetEntry(), ITEM_EVENT_ON_USE, return false); + Push(L, pPlayer); + Push(L, pItem); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnExpire(Player* pPlayer, ItemTemplate const* pProto) +bool Eluna::OnExpire(Player* pPlayer, ItemTemplate const* pProto) { - int bind = sEluna->ItemEventBindings.GetBind(pProto->ItemId, ITEM_EVENT_ON_EXPIRE); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, ITEM_EVENT_ON_EXPIRE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pProto->ItemId); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(ItemEventBindings, pProto->ItemId, ITEM_EVENT_ON_EXPIRE, return false); + Push(L, pPlayer); + Push(L, pProto->ItemId); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnRemove(Player* pPlayer, Item* item) +bool Eluna::OnRemove(Player* pPlayer, Item* item) { - int bind = sEluna->ItemEventBindings.GetBind(item->GetEntry(), ITEM_EVENT_ON_REMOVE); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, ITEM_EVENT_ON_REMOVE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, item); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(ItemEventBindings, item->GetEntry(), ITEM_EVENT_ON_REMOVE, return false); + Push(L, pPlayer); + Push(L, item); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } // Player -extern bool StartEluna(); -bool HookMgr::OnCommand(Player* player, const char* text) +bool Eluna::OnCommand(Player* player, const char* text) { std::string fullcmd(text); char* creload = strtok((char*)text, " "); @@ -501,1093 +468,852 @@ bool HookMgr::OnCommand(Player* player, const char* text) if (std::string("eluna").find(eluna) == 0) { sWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna..."); - StartEluna(); + ReloadEluna(); return false; } } } bool result = true; - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_COMMAND)) - return result; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_COMMAND); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, fullcmd); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + EVENT_BEGIN(ServerEventBindings, PLAYER_EVENT_ON_COMMAND, return result); + Push(L, player); + Push(L, fullcmd); + EVENT_EXECUTE(1); + FOR_RETS(i) { - if (lua_isnoneornil(sEluna->L, i)) + if (lua_isnoneornil(L, i)) continue; - result = sEluna->CHECKVAL(sEluna->L, i, result); + result = CHECKVAL(L, i, result); } - sEluna->PlayerEventBindings.EndCall(); + ENDCALL(); return result; } -void HookMgr::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid) +void Eluna::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOOT_ITEM)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_ITEM); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, count); - sEluna->Push(sEluna->L, guid); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LOOT_ITEM, return); + Push(L, pPlayer); + Push(L, pItem); + Push(L, count); + Push(L, guid); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnLootMoney(Player* pPlayer, uint32 amount) +void Eluna::OnLootMoney(Player* pPlayer, uint32 amount) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOOT_MONEY)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_MONEY); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, amount); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LOOT_MONEY, return); + Push(L, pPlayer); + Push(L, amount); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnFirstLogin(Player* pPlayer) +void Eluna::OnFirstLogin(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_FIRST_LOGIN)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_FIRST_LOGIN); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_FIRST_LOGIN, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnRepop(Player* pPlayer) +void Eluna::OnRepop(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_REPOP)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPOP); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_REPOP, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnResurrect(Player* pPlayer) +void Eluna::OnResurrect(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_RESURRECT)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_RESURRECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_RESURRECT, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnQuestAbandon(Player* pPlayer, uint32 questId) +void Eluna::OnQuestAbandon(Player* pPlayer, uint32 questId) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_QUEST_ABANDON)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_QUEST_ABANDON); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, questId); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_QUEST_ABANDON, return); + Push(L, pPlayer); + Push(L, questId); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) +void Eluna::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_EQUIP)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EQUIP); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, bag); - sEluna->Push(sEluna->L, slot); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_EQUIP, return); + Push(L, pPlayer); + Push(L, pItem); + Push(L, bag); + Push(L, slot); + EVENT_EXECUTE(0); + ENDCALL(); } -InventoryResult HookMgr::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) +InventoryResult Eluna::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) { InventoryResult result = EQUIP_ERR_OK; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CAN_USE_ITEM)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_CAN_USE_ITEM, return result); + Push(L, pPlayer); + Push(L, itemEntry); + EVENT_EXECUTE(1); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CAN_USE_ITEM); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, itemEntry); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - uint32 res = lua_tounsigned(sEluna->L, i); - if (res != EQUIP_ERR_OK) - result = (InventoryResult)res; - } - sEluna->PlayerEventBindings.EndCall(); + if (lua_isnoneornil(L, i)) + continue; + uint32 res = CHECKVAL(L, i, EQUIP_ERR_OK); + if (res != EQUIP_ERR_OK) + result = (InventoryResult)res; } + ENDCALL(); return result; } -void HookMgr::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) +void Eluna::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_ENTER_COMBAT)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_ENTER_COMBAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pEnemy); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_ENTER_COMBAT, return); + Push(L, pPlayer); + Push(L, pEnemy); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnPlayerLeaveCombat(Player* pPlayer) +void Eluna::OnPlayerLeaveCombat(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LEAVE_COMBAT)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEAVE_COMBAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LEAVE_COMBAT, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnPVPKill(Player* pKiller, Player* pKilled) +void Eluna::OnPVPKill(Player* pKiller, Player* pKilled) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILL_PLAYER)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_PLAYER); - sEluna->Push(sEluna->L, pKiller); - sEluna->Push(sEluna->L, pKilled); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_KILL_PLAYER, return); + Push(L, pKiller); + Push(L, pKilled); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnCreatureKill(Player* pKiller, Creature* pKilled) +void Eluna::OnCreatureKill(Player* pKiller, Creature* pKilled) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILL_CREATURE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_CREATURE); - sEluna->Push(sEluna->L, pKiller); - sEluna->Push(sEluna->L, pKilled); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_KILL_CREATURE, return); + Push(L, pKiller); + Push(L, pKilled); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) +void Eluna::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILLED_BY_CREATURE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILLED_BY_CREATURE); - sEluna->Push(sEluna->L, pKiller); - sEluna->Push(sEluna->L, pKilled); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_KILLED_BY_CREATURE, return); + Push(L, pKiller); + Push(L, pKilled); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnLevelChanged(Player* pPlayer, uint8 oldLevel) +void Eluna::OnLevelChanged(Player* pPlayer, uint8 oldLevel) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LEVEL_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEVEL_CHANGE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, oldLevel); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LEVEL_CHANGE, return); + Push(L, pPlayer); + Push(L, oldLevel); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) +void Eluna::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TALENTS_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_CHANGE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, newPoints); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_TALENTS_CHANGE, return); + Push(L, pPlayer); + Push(L, newPoints); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnTalentsReset(Player* pPlayer, bool noCost) +void Eluna::OnTalentsReset(Player* pPlayer, bool noCost) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TALENTS_RESET)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_RESET); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, noCost); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_TALENTS_RESET, return); + Push(L, pPlayer); + Push(L, noCost); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnMoneyChanged(Player* pPlayer, int32& amount) +void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_MONEY_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MONEY_CHANGE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, amount); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_MONEY_CHANGE, return); + Push(L, pPlayer); + Push(L, amount); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) +void Eluna::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GIVE_XP)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GIVE_XP); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, amount); - sEluna->Push(sEluna->L, pVictim); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_GIVE_XP, return); + Push(L, pPlayer); + Push(L, amount); + Push(L, pVictim); + EVENT_EXECUTE(1); + FOR_RETS(i) { - if (lua_isnoneornil(sEluna->L, i)) + if (lua_isnoneornil(L, i)) continue; - amount = sEluna->CHECKVAL(sEluna->L, i, 0); + amount = CHECKVAL(L, i, amount); } - sEluna->PlayerEventBindings.EndCall(); + ENDCALL(); } -void HookMgr::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental) +void Eluna::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_REPUTATION_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPUTATION_CHANGE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, factionID); - sEluna->Push(sEluna->L, standing); - sEluna->Push(sEluna->L, incremental); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_REPUTATION_CHANGE, return); + Push(L, pPlayer); + Push(L, factionID); + Push(L, standing); + Push(L, incremental); + EVENT_EXECUTE(1); + FOR_RETS(i) { - if (lua_isnoneornil(sEluna->L, i)) + if (lua_isnoneornil(L, i)) continue; - standing = sEluna->CHECKVAL(sEluna->L, i, 0); + standing = CHECKVAL(L, i, standing); } - sEluna->PlayerEventBindings.EndCall(); + ENDCALL(); } -void HookMgr::OnDuelRequest(Player* pTarget, Player* pChallenger) +void Eluna::OnDuelRequest(Player* pTarget, Player* pChallenger) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_REQUEST)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_REQUEST); - sEluna->Push(sEluna->L, pTarget); - sEluna->Push(sEluna->L, pChallenger); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_DUEL_REQUEST, return); + Push(L, pTarget); + Push(L, pChallenger); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDuelStart(Player* pStarter, Player* pChallenger) +void Eluna::OnDuelStart(Player* pStarter, Player* pChallenger) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_START)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_START); - sEluna->Push(sEluna->L, pStarter); - sEluna->Push(sEluna->L, pChallenger); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_DUEL_START, return); + Push(L, pStarter); + Push(L, pChallenger); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) +void Eluna::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_END)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_END); - sEluna->Push(sEluna->L, pWinner); - sEluna->Push(sEluna->L, pLoser); - sEluna->Push(sEluna->L, type); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_DUEL_END, return); + Push(L, pWinner); + Push(L, pLoser); + Push(L, type); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnEmote(Player* pPlayer, uint32 emote) +void Eluna::OnEmote(Player* pPlayer, uint32 emote) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_EMOTE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EMOTE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, emote); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_EMOTE, return); + Push(L, pPlayer); + Push(L, emote); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid) +void Eluna::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TEXT_EMOTE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TEXT_EMOTE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, textEmote); - sEluna->Push(sEluna->L, emoteNum); - sEluna->Push(sEluna->L, guid); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_TEXT_EMOTE, return); + Push(L, pPlayer); + Push(L, textEmote); + Push(L, emoteNum); + Push(L, guid); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) +void Eluna::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_SPELL_CAST)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SPELL_CAST); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pSpell); - sEluna->Push(sEluna->L, skipCheck); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_SPELL_CAST, return); + Push(L, pPlayer); + Push(L, pSpell); + Push(L, skipCheck); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnLogin(Player* pPlayer) +void Eluna::OnLogin(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOGIN)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGIN); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LOGIN, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnLogout(Player* pPlayer) +void Eluna::OnLogout(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOGOUT)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGOUT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_LOGOUT, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnCreate(Player* pPlayer) +void Eluna::OnCreate(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHARACTER_CREATE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_CREATE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_CHARACTER_CREATE, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDelete(uint32 guidlow) +void Eluna::OnDelete(uint32 guidlow) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHARACTER_DELETE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_DELETE); - sEluna->Push(sEluna->L, guidlow); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_CHARACTER_DELETE, return); + Push(L, guidlow); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnSave(Player* pPlayer) +void Eluna::OnSave(Player* pPlayer) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_SAVE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SAVE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_SAVE, return); + Push(L, pPlayer); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent) +void Eluna::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_BIND_TO_INSTANCE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_BIND_TO_INSTANCE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, difficulty); - sEluna->Push(sEluna->L, mapid); - sEluna->Push(sEluna->L, permanent); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_BIND_TO_INSTANCE, return); + Push(L, pPlayer); + Push(L, difficulty); + Push(L, mapid); + Push(L, permanent); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) +void Eluna::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_UPDATE_ZONE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_UPDATE_ZONE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, newZone); - sEluna->Push(sEluna->L, newArea); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_UPDATE_ZONE, return); + Push(L, pPlayer); + Push(L, newZone); + Push(L, newArea); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnMapChanged(Player* player) +void Eluna::OnMapChanged(Player* player) { - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_MAP_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MAP_CHANGE); - sEluna->Push(sEluna->L, player); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_MAP_CHANGE, return); + Push(L, player); + EVENT_EXECUTE(0); + ENDCALL(); } -bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) +bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) { if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, NULL)) return true; bool result = true; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHAT)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_CHAT, return result); + Push(L, pPlayer); + Push(L, msg); + Push(L, type); + Push(L, lang); + EVENT_EXECUTE(2); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, msg); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, lang); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + if (lua_isnoneornil(L, i)) + continue; + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (!CHECKVAL(L, i, true)) { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (const char* c_str = sEluna->CHECKVAL(sEluna->L, i, NULL)) - msg = std::string(c_str); - else if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } + result = false; + break; } - sEluna->PlayerEventBindings.EndCall(); } + ENDCALL(); return result; } -bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup) +bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup) { if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, pGroup, NULL)) return true; bool result = true; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GROUP_CHAT)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_GROUP_CHAT, return result); + Push(L, pPlayer); + Push(L, msg); + Push(L, type); + Push(L, lang); + Push(L, pGroup); + EVENT_EXECUTE(2); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GROUP_CHAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, msg); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, lang); - sEluna->Push(sEluna->L, pGroup); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + if (lua_isnoneornil(L, i)) + continue; + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (!CHECKVAL(L, i, true)) { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (const char* c_str = sEluna->CHECKVAL(sEluna->L, i, NULL)) - msg = std::string(c_str); - else if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } + result = false; + break; } - sEluna->PlayerEventBindings.EndCall(); } + ENDCALL(); return result; } -bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild) +bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild) { if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, pGuild, NULL, NULL)) return true; bool result = true; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GUILD_CHAT)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_GUILD_CHAT, return result); + Push(L, pPlayer); + Push(L, msg); + Push(L, type); + Push(L, lang); + Push(L, pGuild); + EVENT_EXECUTE(2); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GUILD_CHAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, msg); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, lang); - sEluna->Push(sEluna->L, pGuild); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + if (lua_isnoneornil(L, i)) + continue; + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (!CHECKVAL(L, i, true)) { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (const char* c_str = sEluna->CHECKVAL(sEluna->L, i, NULL)) - msg = std::string(c_str); - else if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } + result = false; + break; } - sEluna->PlayerEventBindings.EndCall(); } + ENDCALL(); return result; } -bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel) +bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel) { if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, pChannel)) return true; bool result = true; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHANNEL_CHAT)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_CHANNEL_CHAT, return result); + Push(L, pPlayer); + Push(L, msg); + Push(L, type); + Push(L, lang); + Push(L, pChannel->GetChannelId()); + EVENT_EXECUTE(2); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHANNEL_CHAT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, msg); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, lang); - sEluna->Push(sEluna->L, pChannel->GetChannelId()); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + if (lua_isnoneornil(L, i)) + continue; + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (!CHECKVAL(L, i, true)) { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (const char* c_str = sEluna->CHECKVAL(sEluna->L, i, NULL)) - msg = std::string(c_str); - else if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } + result = false; + break; } - sEluna->PlayerEventBindings.EndCall(); } + ENDCALL(); return result; } -bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver) +bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver) { if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, pReceiver, NULL, NULL, NULL)) return true; bool result = true; - if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_WHISPER)) + EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_WHISPER, return result); + Push(L, pPlayer); + Push(L, msg); + Push(L, type); + Push(L, lang); + Push(L, pReceiver); + EVENT_EXECUTE(2); + FOR_RETS(i) { - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_WHISPER); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, msg); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, lang); - sEluna->Push(sEluna->L, pReceiver); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + if (lua_isnoneornil(L, i)) + continue; + if (const char* c_str = CHECKVAL(L, i, NULL)) + msg = std::string(c_str); + else if (!CHECKVAL(L, i, true)) { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (const char* c_str = sEluna->CHECKVAL(sEluna->L, i, NULL)) - msg = std::string(c_str); - else if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } + result = false; + break; } - sEluna->PlayerEventBindings.EndCall(); } + ENDCALL(); return result; } #ifndef CLASSIC #ifndef TBC // Vehicle -void HookMgr::OnInstall(Vehicle* vehicle) +void Eluna::OnInstall(Vehicle* vehicle) { - if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_INSTALL)) - return; - ELUNA_GUARD(); - sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL); - sEluna->Push(sEluna->L, vehicle); - sEluna->VehicleEventBindings.ExecuteCall(); - sEluna->VehicleEventBindings.EndCall(); + EVENT_BEGIN(VehicleEventBindings, VEHICLE_EVENT_ON_INSTALL, return); + Push(L, vehicle); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnUninstall(Vehicle* vehicle) +void Eluna::OnUninstall(Vehicle* vehicle) { - if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_UNINSTALL)) - return; - ELUNA_GUARD(); - sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_UNINSTALL); - sEluna->Push(sEluna->L, vehicle); - sEluna->VehicleEventBindings.ExecuteCall(); - sEluna->VehicleEventBindings.EndCall(); + EVENT_BEGIN(VehicleEventBindings, VEHICLE_EVENT_ON_UNINSTALL, return); + Push(L, vehicle); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) +void Eluna::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) { - if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_INSTALL_ACCESSORY)) - return; - ELUNA_GUARD(); - sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL_ACCESSORY); - sEluna->Push(sEluna->L, vehicle); - sEluna->Push(sEluna->L, accessory); - sEluna->VehicleEventBindings.ExecuteCall(); - sEluna->VehicleEventBindings.EndCall(); + EVENT_BEGIN(VehicleEventBindings, VEHICLE_EVENT_ON_INSTALL_ACCESSORY, return); + Push(L, vehicle); + Push(L, accessory); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) +void Eluna::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) { - if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_ADD_PASSENGER)) - return; - ELUNA_GUARD(); - sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_ADD_PASSENGER); - sEluna->Push(sEluna->L, vehicle); - sEluna->Push(sEluna->L, passenger); - sEluna->Push(sEluna->L, seatId); - sEluna->VehicleEventBindings.ExecuteCall(); - sEluna->VehicleEventBindings.EndCall(); + EVENT_BEGIN(VehicleEventBindings, VEHICLE_EVENT_ON_ADD_PASSENGER, return); + Push(L, vehicle); + Push(L, passenger); + Push(L, seatId); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) +void Eluna::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) { - if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_REMOVE_PASSENGER)) - return; - ELUNA_GUARD(); - sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_REMOVE_PASSENGER); - sEluna->Push(sEluna->L, vehicle); - sEluna->Push(sEluna->L, passenger); - sEluna->VehicleEventBindings.ExecuteCall(); - sEluna->VehicleEventBindings.EndCall(); + EVENT_BEGIN(VehicleEventBindings, VEHICLE_EVENT_ON_REMOVE_PASSENGER, return); + Push(L, vehicle); + Push(L, passenger); + EVENT_EXECUTE(0); + ENDCALL(); } #endif #endif -void HookMgr::OnAddMember(Guild* guild, Player* player, uint32 plRank) +void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_ADD_MEMBER)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ADD_MEMBER); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, plRank); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_ADD_MEMBER, return); + Push(L, guild); + Push(L, player); + Push(L, plRank); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) +void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_REMOVE_MEMBER)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_REMOVE_MEMBER); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, isDisbanding); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_REMOVE_MEMBER, return); + Push(L, guild); + Push(L, player); + Push(L, isDisbanding); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnMOTDChanged(Guild* guild, const std::string& newMotd) +void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MOTD_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MOTD_CHANGE); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, newMotd); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MOTD_CHANGE, return); + Push(L, guild); + Push(L, newMotd); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnInfoChanged(Guild* guild, const std::string& newInfo) +void Eluna::OnInfoChanged(Guild* guild, const std::string& newInfo) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_INFO_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_INFO_CHANGE); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, newInfo); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_INFO_CHANGE, return); + Push(L, guild); + Push(L, newInfo); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnCreate(Guild* guild, Player* leader, const std::string& name) +void Eluna::OnCreate(Guild* guild, Player* leader, const std::string& name) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_CREATE)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_CREATE); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, leader); - sEluna->Push(sEluna->L, name); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_CREATE, return); + Push(L, guild); + Push(L, leader); + Push(L, name); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDisband(Guild* guild) +void Eluna::OnDisband(Guild* guild) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_DISBAND)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_DISBAND); - sEluna->Push(sEluna->L, guild); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_DISBAND, return); + Push(L, guild); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair) // isRepair not a part of Mangos, implement? +void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair) // isRepair not a part of Mangos, implement? { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MONEY_WITHDRAW)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_WITHDRAW); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, amount); - sEluna->Push(sEluna->L, isRepair); // isRepair not a part of Mangos, implement? - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_WITHDRAW, return); + Push(L, guild); + Push(L, player); + Push(L, amount); + Push(L, isRepair); // isRepair not a part of Mangos, implement? + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) +void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MONEY_DEPOSIT)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_DEPOSIT); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, amount); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_DEPOSIT, return); + Push(L, guild); + Push(L, player); + Push(L, amount); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, - bool isDestBank, uint8 destContainer, uint8 destSlotId) +void Eluna::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, + bool isDestBank, uint8 destContainer, uint8 destSlotId) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_ITEM_MOVE)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ITEM_MOVE); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, isSrcBank); - sEluna->Push(sEluna->L, srcContainer); - sEluna->Push(sEluna->L, srcSlotId); - sEluna->Push(sEluna->L, isDestBank); - sEluna->Push(sEluna->L, destContainer); - sEluna->Push(sEluna->L, destSlotId); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_ITEM_MOVE, return); + Push(L, guild); + Push(L, player); + Push(L, pItem); + Push(L, isSrcBank); + Push(L, srcContainer); + Push(L, srcSlotId); + Push(L, isDestBank); + Push(L, destContainer); + Push(L, destSlotId); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank) +void Eluna::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_EVENT)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_EVENT); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, eventType); - sEluna->Push(sEluna->L, playerGuid1); - sEluna->Push(sEluna->L, playerGuid2); - sEluna->Push(sEluna->L, newRank); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_EVENT, return); + Push(L, guild); + Push(L, eventType); + Push(L, playerGuid1); + Push(L, playerGuid2); + Push(L, newRank); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) +void Eluna::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) { - if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_BANK_EVENT)) - return; - ELUNA_GUARD(); - sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_BANK_EVENT); - sEluna->Push(sEluna->L, guild); - sEluna->Push(sEluna->L, eventType); - sEluna->Push(sEluna->L, tabId); - sEluna->Push(sEluna->L, playerGuid); - sEluna->Push(sEluna->L, itemOrMoney); - sEluna->Push(sEluna->L, itemStackCount); - sEluna->Push(sEluna->L, destTabId); - sEluna->GuildEventBindings.ExecuteCall(); - sEluna->GuildEventBindings.EndCall(); + EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_BANK_EVENT, return); + Push(L, guild); + Push(L, eventType); + Push(L, tabId); + Push(L, playerGuid); + Push(L, itemOrMoney); + Push(L, itemStackCount); + Push(L, destTabId); + EVENT_EXECUTE(0); + ENDCALL(); } // Group -void HookMgr::OnAddMember(Group* group, uint64 guid) +void Eluna::OnAddMember(Group* group, uint64 guid) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_ADD)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_ADD); - sEluna->Push(sEluna->L, group); - sEluna->Push(sEluna->L, guid); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_MEMBER_ADD, return); + Push(L, group); + Push(L, guid); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnInviteMember(Group* group, uint64 guid) +void Eluna::OnInviteMember(Group* group, uint64 guid) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_INVITE)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_INVITE); - sEluna->Push(sEluna->L, group); - sEluna->Push(sEluna->L, guid); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_MEMBER_INVITE, return); + Push(L, group); + Push(L, guid); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnRemoveMember(Group* group, uint64 guid, uint8 method) +void Eluna::OnRemoveMember(Group* group, uint64 guid, uint8 method) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_REMOVE)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_REMOVE); - sEluna->Push(sEluna->L, group); - sEluna->Push(sEluna->L, guid); - sEluna->Push(sEluna->L, method); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_MEMBER_REMOVE, return); + Push(L, group); + Push(L, guid); + Push(L, method); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid) +void Eluna::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_LEADER_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_LEADER_CHANGE); - sEluna->Push(sEluna->L, group); - sEluna->Push(sEluna->L, newLeaderGuid); - sEluna->Push(sEluna->L, oldLeaderGuid); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_LEADER_CHANGE, return); + Push(L, group); + Push(L, newLeaderGuid); + Push(L, oldLeaderGuid); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDisband(Group* group) +void Eluna::OnDisband(Group* group) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_DISBAND)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_DISBAND); - sEluna->Push(sEluna->L, group); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_DISBAND, return); + Push(L, group); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType) +void Eluna::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType) { - if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_CREATE)) - return; - ELUNA_GUARD(); - sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_CREATE); - sEluna->Push(sEluna->L, group); - sEluna->Push(sEluna->L, leaderGuid); - sEluna->Push(sEluna->L, groupType); - sEluna->GroupEventBindings.ExecuteCall(); - sEluna->GroupEventBindings.EndCall(); + EVENT_BEGIN(GroupEventBindings, GROUP_EVENT_ON_CREATE, return); + Push(L, group); + Push(L, leaderGuid); + Push(L, groupType); + EVENT_EXECUTE(0); + ENDCALL(); } /* Map */ -void HookMgr::OnCreate(Map* map) +void Eluna::OnCreate(Map* map) { - if (!sEluna->ServerEventBindings.HasEvents(MAP_EVENT_ON_CREATE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(MAP_EVENT_ON_CREATE); - sEluna->Push(sEluna->L, map); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_CREATE, return); + Push(L, map); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDestroy(Map* map) +void Eluna::OnDestroy(Map* map) { - if (!sEluna->ServerEventBindings.HasEvents(MAP_EVENT_ON_DESTROY)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(MAP_EVENT_ON_DESTROY); - sEluna->Push(sEluna->L, map); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_DESTROY, return); + Push(L, map); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnPlayerEnter(Map* map, Player* player) +void Eluna::OnPlayerEnter(Map* map, Player* player) { - if (!sEluna->ServerEventBindings.HasEvents(MAP_EVENT_ON_PLAYER_ENTER)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(MAP_EVENT_ON_PLAYER_ENTER); - sEluna->Push(sEluna->L, map); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_PLAYER_ENTER, return); + Push(L, map); + Push(L, player); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnPlayerLeave(Map* map, Player* player) +void Eluna::OnPlayerLeave(Map* map, Player* player) { - if (!sEluna->ServerEventBindings.HasEvents(MAP_EVENT_ON_PLAYER_LEAVE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(MAP_EVENT_ON_PLAYER_LEAVE); - sEluna->Push(sEluna->L, map); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_PLAYER_LEAVE, return); + Push(L, map); + Push(L, player); + EVENT_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnUpdate(Map* map, uint32 diff) +void Eluna::OnUpdate(Map* map, uint32 diff) { - if (!sEluna->ServerEventBindings.HasEvents(MAP_EVENT_ON_UPDATE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(MAP_EVENT_ON_UPDATE); - sEluna->Push(sEluna->L, map); - sEluna->Push(sEluna->L, diff); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); + EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_UPDATE, return); + Push(L, map); + Push(L, diff); + EVENT_EXECUTE(0); + ENDCALL(); } // creature -bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) +bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) { - int bind = sEluna->CreatureEventBindings.GetBind(pTarget->GetEntry(), CREATURE_EVENT_ON_DUMMY_EFFECT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DUMMY_EFFECT); - sEluna->Push(sEluna->L, pCaster); - sEluna->Push(sEluna->L, spellId); - sEluna->Push(sEluna->L, effIndex); - sEluna->Push(sEluna->L, pTarget); - sEluna->ExecuteCall(5, 0); + ENTRY_BEGIN(CreatureEventBindings, pTarget->GetEntry(), CREATURE_EVENT_ON_DUMMY_EFFECT, return false); + Push(L, pCaster); + Push(L, spellId); + Push(L, effIndex); + Push(L, pTarget); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) +bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature) { - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_HELLO); - if (!bind) - return false; - ELUNA_GUARD(); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), GOSSIP_EVENT_ON_HELLO, return false); + Push(L, pPlayer); + Push(L, pCreature); + ENTRY_EXECUTE(0); + ENDCALL(); + return true; +} + +bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) +{ + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT, return false); pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->ExecuteCall(3, 0); + Push(L, pPlayer); + Push(L, pCreature); + Push(L, sender); + Push(L, action); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) +bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) { - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - ELUNA_GUARD(); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT, return false); pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->ExecuteCall(5, 0); + Push(L, pPlayer); + Push(L, pCreature); + Push(L, sender); + Push(L, action); + Push(L, code); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) +bool Eluna::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) { - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - ELUNA_GUARD(); - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->Push(sEluna->L, code); - sEluna->ExecuteCall(6, 0); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_ACCEPT, return false); + Push(L, pPlayer); + Push(L, pCreature); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +bool Eluna::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) { - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_ACCEPT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_ACCEPT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE, return false); + Push(L, pPlayer); + Push(L, pCreature); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +bool Eluna::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest) { - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_COMPLETE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_REWARD, return false); + Push(L, pPlayer); + Push(L, pCreature); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +uint32 Eluna::GetDialogStatus(Player* pPlayer, Creature* pCreature) { - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_REWARD); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_REWARD); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -uint32 HookMgr::GetDialogStatus(Player* pPlayer, Creature* pCreature) -{ - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_DIALOG_STATUS); - if (!bind) - return 0; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIALOG_STATUS); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_DIALOG_STATUS, return 0); + Push(L, pPlayer); + Push(L, pCreature); + ENTRY_EXECUTE(0); + ENDCALL(); return DIALOG_STATUS_SCRIPTED_NO_STATUS; } -void HookMgr::OnSummoned(Creature* pCreature, Unit* pSummoner) +void Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner) { - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pSummoner); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED, return); + Push(L, pCreature); + Push(L, pSummoner); + ENTRY_EXECUTE(0); + ENDCALL(); } struct ElunaCreatureAI : ScriptedAI @@ -1616,15 +1342,11 @@ struct ElunaCreatureAI : ScriptedAI if (!me->HasReactState(REACT_PASSIVE)) ScriptedAI::UpdateAI(diff); #endif - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_AIUPDATE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, diff); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE, return); + Eluna::Push(L, me); + Eluna::Push(L, diff); + ENTRY_EXECUTE(0); + ENDCALL(); } //Called for reaction at enter to combat if not in combat yet (enemy can be NULL) @@ -1632,31 +1354,23 @@ struct ElunaCreatureAI : ScriptedAI void EnterCombat(Unit* target) override { ScriptedAI::EnterCombat(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ENTER_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT, return); + Eluna::Push(L, me); + Eluna::Push(L, target); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called at any Damage from any attacker (before damage apply) void DamageTaken(Unit* attacker, uint32& damage) override { ScriptedAI::DamageTaken(attacker, damage); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DAMAGE_TAKEN); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->Push(sEluna->L, damage); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN, return); + Eluna::Push(L, me); + Eluna::Push(L, attacker); + Eluna::Push(L, damage); + ENTRY_EXECUTE(0); + ENDCALL(); } //Called at creature death @@ -1664,91 +1378,67 @@ struct ElunaCreatureAI : ScriptedAI { ScriptedAI::JustDied(killer); On_Reset(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DIED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, killer); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DIED, return); + Eluna::Push(L, me); + Eluna::Push(L, killer); + ENTRY_EXECUTE(0); + ENDCALL(); } //Called at creature killing another unit void KilledUnit(Unit* victim) override { ScriptedAI::KilledUnit(victim); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_TARGET_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, victim); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED, return); + Eluna::Push(L, me); + Eluna::Push(L, victim); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when the creature summon successfully other creature void JustSummoned(Creature* summon) override { ScriptedAI::JustSummoned(summon); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, return); + Eluna::Push(L, me); + Eluna::Push(L, summon); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when a summoned creature is despawned void SummonedCreatureDespawn(Creature* summon) override { ScriptedAI::SummonedCreatureDespawn(summon); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, return); + Eluna::Push(L, me); + Eluna::Push(L, summon); + ENTRY_EXECUTE(0); + ENDCALL(); } //Called at waypoint reached or PointMovement end void MovementInform(uint32 type, uint32 id) override { ScriptedAI::MovementInform(type, id); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_WP); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_WP); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, id); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_WP, return); + Eluna::Push(L, me); + Eluna::Push(L, type); + Eluna::Push(L, id); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called before EnterCombat even before the creature is in combat. void AttackStart(Unit* target) override { ScriptedAI::AttackStart(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PRE_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT, return); + Eluna::Push(L, me); + Eluna::Push(L, target); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called for reaction at stopping attack at no attackers or targets @@ -1756,29 +1446,21 @@ struct ElunaCreatureAI : ScriptedAI { ScriptedAI::EnterEvadeMode(); On_Reset(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_LEAVE_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return); + Eluna::Push(L, me); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) void AttackedBy(Unit* attacker) override { ScriptedAI::AttackedBy(attacker); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ATTACKED_AT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT, return); + Eluna::Push(L, me); + Eluna::Push(L, attacker); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when creature is spawned or respawned (for reseting variables) @@ -1786,59 +1468,43 @@ struct ElunaCreatureAI : ScriptedAI { ScriptedAI::JustRespawned(); On_Reset(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPAWN); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPAWN); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return); + Eluna::Push(L, me); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called at reaching home after evade void JustReachedHome() override { ScriptedAI::JustReachedHome(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_HOME); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return); + Eluna::Push(L, me); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called at text emote receive from player void ReceiveEmote(Player* player, uint32 emoteId) override { ScriptedAI::ReceiveEmote(player, emoteId); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RECEIVE_EMOTE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, emoteId); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE, return); + Eluna::Push(L, me); + Eluna::Push(L, player); + Eluna::Push(L, emoteId); + ENTRY_EXECUTE(0); + ENDCALL(); } // called when the corpse of this creature gets removed void CorpseRemoved(uint32& respawnDelay) override { ScriptedAI::CorpseRemoved(respawnDelay); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CORPSE_REMOVED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, respawnDelay); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED, return); + Eluna::Push(L, me); + Eluna::Push(L, respawnDelay); + ENTRY_EXECUTE(0); + ENDCALL(); } #ifdef MANGOS @@ -1852,60 +1518,44 @@ struct ElunaCreatureAI : ScriptedAI void MoveInLineOfSight(Unit* who) override { ScriptedAI::MoveInLineOfSight(who); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_MOVE_IN_LOS); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, who); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS, return); + Eluna::Push(L, me); + Eluna::Push(L, who); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called on creature initial spawn, respawn, death, evade (leave combat) void On_Reset() // Not an override, custom { - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RESET); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RESET); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RESET, return); + Eluna::Push(L, me); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when hit by a spell void SpellHit(Unit* caster, SpellInfo const* spell) override { ScriptedAI::SpellHit(caster, spell); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_HIT_BY_SPELL); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, caster); - sEluna->Push(sEluna->L, spell->Id); // Pass spell object? - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL, return); + Eluna::Push(L, me); + Eluna::Push(L, caster); + Eluna::Push(L, spell->Id); // Pass spell object? + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when spell hits a target void SpellHitTarget(Unit* target, SpellInfo const* spell) override { ScriptedAI::SpellHitTarget(target, spell); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_HIT_TARGET); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->Push(sEluna->L, spell->Id); // Pass spell object? - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET, return); + Eluna::Push(L, me); + Eluna::Push(L, target); + Eluna::Push(L, spell->Id); // Pass spell object? + ENTRY_EXECUTE(0); + ENDCALL(); } #ifndef MANGOS @@ -1914,52 +1564,40 @@ struct ElunaCreatureAI : ScriptedAI void IsSummonedBy(Unit* summoner) override { ScriptedAI::IsSummonedBy(summoner); - sHookMgr->OnSummoned(me, summoner); + sEluna->OnSummoned(me, summoner); } void SummonedCreatureDies(Creature* summon, Unit* killer) override { ScriptedAI::SummonedCreatureDies(summon, killer); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->Push(sEluna->L, killer); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, return); + Eluna::Push(L, me); + Eluna::Push(L, summon); + Eluna::Push(L, killer); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when owner takes damage void OwnerAttackedBy(Unit* attacker) override { ScriptedAI::OwnerAttackedBy(attacker); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED_AT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT, return); + Eluna::Push(L, me); + Eluna::Push(L, attacker); + ENTRY_EXECUTE(0); + ENDCALL(); } // Called when owner attacks something void OwnerAttacked(Unit* target) override { ScriptedAI::OwnerAttacked(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED, return); + Eluna::Push(L, me); + Eluna::Push(L, target); + ENTRY_EXECUTE(0); + ENDCALL(); } #endif @@ -1969,222 +1607,159 @@ struct ElunaCreatureAI : ScriptedAI }; // gameobject -bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) +bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) { - int bind = sEluna->GameObjectEventBindings.GetBind(pTarget->GetEntry(), GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); - sEluna->Push(sEluna->L, pCaster); - sEluna->Push(sEluna->L, spellId); - sEluna->Push(sEluna->L, effIndex); - sEluna->Push(sEluna->L, pTarget); - sEluna->ExecuteCall(5, 0); + ENTRY_BEGIN(GameObjectEventBindings, pTarget->GetEntry(), GAMEOBJECT_EVENT_ON_DUMMY_EFFECT, return false); + Push(L, pCaster); + Push(L, spellId); + Push(L, effIndex); + Push(L, pTarget); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) +bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject) { - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_HELLO); - if (!bind) - return false; - ELUNA_GUARD(); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GOSSIP_EVENT_ON_HELLO, return false); pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->ExecuteCall(3, 0); + Push(L, pPlayer); + Push(L, pGameObject); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) +bool Eluna::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) { - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - ELUNA_GUARD(); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT, return false); pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->ExecuteCall(5, 0); + Push(L, pPlayer); + Push(L, pGameObject); + Push(L, sender); + Push(L, action); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) +bool Eluna::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) { - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - ELUNA_GUARD(); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT, return false); pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->Push(sEluna->L, code); - sEluna->ExecuteCall(6, 0); + Push(L, pPlayer); + Push(L, pGameObject); + Push(L, sender); + Push(L, action); + Push(L, code); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +bool Eluna::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_ACCEPT, return false); + Push(L, pPlayer); + Push(L, pGameObject); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -bool HookMgr::OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +bool Eluna::OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_COMPLETE, return false); + Push(L, pPlayer); + Push(L, pGameObject); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -void HookMgr::UpdateAI(GameObject* pGameObject, uint32 diff) +void Eluna::UpdateAI(GameObject* pGameObject, uint32 diff) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_AIUPDATE); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_AIUPDATE); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, diff); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_AIUPDATE, return); + Push(L, pGameObject); + Push(L, diff); + ENTRY_EXECUTE(0); + ENDCALL(); } -bool HookMgr::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +bool Eluna::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_REWARD); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_REWARD); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_REWARD, return false); + Push(L, pPlayer); + Push(L, pGameObject); + Push(L, pQuest); + ENTRY_EXECUTE(0); + ENDCALL(); return true; } -uint32 HookMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) +uint32 Eluna::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DIALOG_STATUS); - if (!bind) - return 0; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DIALOG_STATUS); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DIALOG_STATUS, return 0); + Push(L, pPlayer); + Push(L, pGameObject); + ENTRY_EXECUTE(0); + ENDCALL(); return DIALOG_STATUS_SCRIPTED_NO_STATUS; // DIALOG_STATUS_UNDEFINED } #ifndef CLASSIC #ifndef TBC -void HookMgr::OnDestroyed(GameObject* pGameObject, Player* pPlayer) +void Eluna::OnDestroyed(GameObject* pGameObject, Player* pPlayer) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DESTROYED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DESTROYED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pPlayer); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DESTROYED, return); + Push(L, pGameObject); + Push(L, pPlayer); + ENTRY_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnDamaged(GameObject* pGameObject, Player* pPlayer) +void Eluna::OnDamaged(GameObject* pGameObject, Player* pPlayer) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DAMAGED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DAMAGED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pPlayer); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DAMAGED, return); + Push(L, pGameObject); + Push(L, pPlayer); + ENTRY_EXECUTE(0); + ENDCALL(); } #endif #endif -void HookMgr::OnLootStateChanged(GameObject* pGameObject, uint32 state) +void Eluna::OnLootStateChanged(GameObject* pGameObject, uint32 state) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, state); - sEluna->ExecuteCall(4, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE, return); + Push(L, pGameObject); + Push(L, state); + ENTRY_EXECUTE(0); + ENDCALL(); } -void HookMgr::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) +void Eluna::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) { - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, state); - sEluna->ExecuteCall(3, 0); + ENTRY_BEGIN(GameObjectEventBindings, pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED, return); + Push(L, pGameObject); + Push(L, state); + ENTRY_EXECUTE(0); + ENDCALL(); } -CreatureAI* HookMgr::GetAI(Creature* creature) +void Eluna::OnSpawn(GameObject* gameobject) { - if (!sEluna->CreatureEventBindings.GetBindMap(creature->GetEntry())) + ENTRY_BEGIN(GameObjectEventBindings, gameobject->GetEntry(), GAMEOBJECT_EVENT_ON_SPAWN, return); + Push(L, gameobject); + ENTRY_EXECUTE(0); + ENDCALL(); +} + +CreatureAI* Eluna::GetAI(Creature* creature) +{ + if (!CreatureEventBindings->GetBindMap(creature->GetEntry())) return NULL; return new ElunaCreatureAI(creature); } - -void HookMgr::OnSpawn(GameObject* gameobject) -{ - int bind = sEluna->GameObjectEventBindings.GetBind(gameobject->GetEntry(), GAMEOBJECT_EVENT_ON_SPAWN); - if (!bind) - return; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_SPAWN); - sEluna->Push(sEluna->L, gameobject); - sEluna->ExecuteCall(2, 0); -} - -void AddElunaScripts() -{ -#ifndef MANGOS - new ElunaWorldAI(); -#endif -} diff --git a/HookMgr.h b/HookMgr.h index a63a89b..6f66170 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -7,67 +7,6 @@ #ifndef LUAHOOKS_H #define LUAHOOKS_H -// Base -#include "Common.h" -#include "SharedDefines.h" -#include -#include -// enums -#ifdef MANGOS -#include "Player.h" -#else -#include "GameObjectAI.h" -#endif -#include "Group.h" -#include "Item.h" -#include "Weather.h" - -#ifdef MANGOS -typedef SpellEffectIndex SpellEffIndex; -typedef SpellEntry SpellInfo; -typedef ItemPrototype ItemTemplate; -#define GetTemplate GetProto -#ifdef CLASSIC -typedef int Difficulty; -#endif -#endif - -struct AreaTriggerEntry; -#ifdef MANGOS -class ReactorAI; -typedef ReactorAI ScriptedAI; -#else -#undef UNORDERED_MAP -#define UNORDERED_MAP std::unordered_map -struct ScriptedAI; -#endif -class AuctionHouseObject; -class Channel; -class Creature; -class CreatureAI; -class GameObject; -class Guild; -class Group; -class Item; -class Player; -class Quest; -class Spell; -class SpellCastTargets; -class Transport; -class Unit; -class Weather; -class WorldPacket; -#ifndef CLASSIC -#ifndef TBC -#ifdef TRINITY -class Vehicle; -#else -class VehicleInfo; -typedef VehicleInfo Vehicle; -#endif -#endif -#endif - enum RegisterTypes { REGTYPE_PACKET, @@ -86,7 +25,7 @@ enum RegisterTypes REGTYPE_COUNT }; -// RegisterPacketEvent(Opcode, function) +// RegisterPacketEvent(Opcode, event, function) // SERVER_EVENT_ON_PACKET_RECEIVE = 5, // (event, packet, player) - Player only if accessible. Can return false or a new packet // SERVER_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6, // Not Implemented // SERVER_EVENT_ON_PACKET_SEND = 7, // (event, packet, player) - Player only if accessible. Can return false or a new packet @@ -114,7 +53,7 @@ enum ServerEvents WORLD_EVENT_ON_SHUTDOWN = 15, // (event) // Eluna - ELUNA_EVENT_ON_RESTART = 16, // (event) + ELUNA_EVENT_ON_LUA_STATE_CLOSE = 16, // (event) // Map MAP_EVENT_ON_CREATE = 17, // (event, map) @@ -319,164 +258,4 @@ enum GossipEvents GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip GOSSIP_EVENT_COUNT }; - -class HookMgr -{ -public: - int userdata_table; - void RemoveRef(const void* obj) const; - - CreatureAI* GetAI(Creature* creature); - -#ifndef MANGOS - GameObjectAI* GetAI(GameObject* gameObject); -#endif - - /* Custom */ - bool OnCommand(Player* player, const char* text); - void OnWorldUpdate(uint32 diff); - void OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid); - void OnLootMoney(Player* pPlayer, uint32 amount); - void OnFirstLogin(Player* pPlayer); - void OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot); - void OnRepop(Player* pPlayer); - void OnResurrect(Player* pPlayer); - void OnQuestAbandon(Player* pPlayer, uint32 questId); - InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry); - void OnEngineRestart(); - bool OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); - - /* Item */ - bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget); - bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest); - bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); - bool OnExpire(Player* pPlayer, ItemTemplate const* pProto); - bool OnRemove(Player* pPlayer, Item* item); - void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code); - - /* Creature */ - bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget); - bool OnGossipHello(Player* pPlayer, Creature* pCreature); - bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action); - bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code); - bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); - bool OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest); - bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest); - uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); - void OnSummoned(Creature* creature, Unit* summoner); - - /* GameObject */ - bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget); - bool OnGossipHello(Player* pPlayer, GameObject* pGameObject); - bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action); - bool OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code); - bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); - bool OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); - bool OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); - uint32 GetDialogStatus(Player* pPlayer, GameObject* pGameObject); -#ifndef CLASSIC -#ifndef TBC - void OnDestroyed(GameObject* pGameObject, Player* pPlayer); - void OnDamaged(GameObject* pGameObject, Player* pPlayer); -#endif -#endif - void OnLootStateChanged(GameObject* pGameObject, uint32 state); - void OnGameObjectStateChanged(GameObject* pGameObject, uint32 state); - void UpdateAI(GameObject* pGameObject, uint32 diff); - void OnSpawn(GameObject* gameobject); - - /* Packet */ - bool OnPacketSend(WorldSession* session, WorldPacket& packet); - bool OnPacketReceive(WorldSession* session, WorldPacket& packet); - - /* Player */ - void OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy); - void OnPlayerLeaveCombat(Player* pPlayer); - void OnPVPKill(Player* pKiller, Player* pKilled); - void OnCreatureKill(Player* pKiller, Creature* pKilled); - void OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled); - void OnLevelChanged(Player* pPlayer, uint8 oldLevel); - void OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints); - void OnTalentsReset(Player* pPlayer, bool noCost); - void OnMoneyChanged(Player* pPlayer, int32& amount); - void OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim); - void OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental); - void OnDuelRequest(Player* pTarget, Player* pChallenger); - void OnDuelStart(Player* pStarter, Player* pChallenger); - void OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type); - bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg); - bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup); - bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild); - bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel); - bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver); - void OnEmote(Player* pPlayer, uint32 emote); - void OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid); - void OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck); - void OnLogin(Player* pPlayer); - void OnLogout(Player* pPlayer); - void OnCreate(Player* pPlayer); - void OnDelete(uint32 guid); - void OnSave(Player* pPlayer); - void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent); - void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea); - void OnMapChanged(Player* pPlayer); - void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code); - -#ifndef CLASSIC -#ifndef TBC - /* Vehicle */ - void OnInstall(Vehicle* vehicle); - void OnUninstall(Vehicle* vehicle); - void OnInstallAccessory(Vehicle* vehicle, Creature* accessory); - void OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId); - void OnRemovePassenger(Vehicle* vehicle, Unit* passenger); -#endif -#endif - - /* AreaTrigger */ - bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger); - - /* Weather */ - void OnChange(Weather* weather, WeatherState state, float grade); - - /* Auction House */ - void OnAdd(AuctionHouseObject* auctionHouse); - void OnRemove(AuctionHouseObject* auctionHouse); - void OnSuccessful(AuctionHouseObject* auctionHouse); - void OnExpire(AuctionHouseObject* auctionHouse); - - /* Guild */ - void OnAddMember(Guild* guild, Player* player, uint32 plRank); - void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding); - void OnMOTDChanged(Guild* guild, const std::string& newMotd); - void OnInfoChanged(Guild* guild, const std::string& newInfo); - void OnCreate(Guild* guild, Player* leader, const std::string& name); - void OnDisband(Guild* guild); - void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair); - void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount); - void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId); - void OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank); - void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId); - - /* Group */ - void OnAddMember(Group* group, uint64 guid); - void OnInviteMember(Group* group, uint64 guid); - void OnRemoveMember(Group* group, uint64 guid, uint8 method); - void OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid); - void OnDisband(Group* group); - void OnCreate(Group* group, uint64 leaderGuid, GroupType groupType); - - /* Map */ - void OnCreate(Map* map); - void OnDestroy(Map* map); - void OnPlayerEnter(Map* map, Player* player); - void OnPlayerLeave(Map* map, Player* player); - void OnUpdate(Map* map, uint32 diff); -}; -#ifdef MANGOS -#define sHookMgr (&MaNGOS::Singleton::Instance()) -#else -#define sHookMgr ACE_Singleton::instance() -#endif - #endif diff --git a/Includes.h b/Includes.h new file mode 100644 index 0000000..1b74901 --- /dev/null +++ b/Includes.h @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// Required +#include "AccountMgr.h" +#include "AuctionHouseMgr.h" +#include "Cell.h" +#include "CellImpl.h" +#include "Chat.h" +#include "Channel.h" +#include "Config.h" +#include "DBCStores.h" +#include "GossipDef.h" +#include "GridNotifiers.h" +#include "GridNotifiersImpl.h" +#include "Group.h" +#include "Guild.h" +#include "GuildMgr.h" +#include "Language.h" +#include "Mail.h" +#include "MapManager.h" +#include "ObjectAccessor.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "Player.h" +#include "Pet.h" +#include "ReputationMgr.h" +#include "revision.h" +#include "ScriptMgr.h" +#include "Spell.h" +#include "SpellAuras.h" +#include "SpellMgr.h" +#include "TemporarySummon.h" +#include "WorldPacket.h" +#include "WorldSession.h" +#ifdef MANGOS +#include "ReactorAI.h" +#include "revision_nr.h" +#else +#include "ScriptedCreature.h" +#include "SpellInfo.h" +#include "WeatherMgr.h" +#endif +#if (!defined(TBC) && !defined(CLASSIC)) +#include "Vehicle.h" +#endif +#ifndef CLASSIC +#include "ArenaTeam.h" +#endif diff --git a/ItemMethods.h b/ItemMethods.h index ae1800c..6d222b4 100644 --- a/ItemMethods.h +++ b/ItemMethods.h @@ -12,134 +12,134 @@ namespace LuaItem /* BOOLEAN */ int IsSoulBound(lua_State* L, Item* item) { - sEluna->Push(L, item->IsSoulBound()); + Eluna::Push(L, item->IsSoulBound()); return 1; } #if (!defined(TBC) && !defined(CLASSIC)) int IsBoundAccountWide(lua_State* L, Item* item) { - sEluna->Push(L, item->IsBoundAccountWide()); + Eluna::Push(L, item->IsBoundAccountWide()); return 1; } #endif int IsBoundByEnchant(lua_State* L, Item* item) { - sEluna->Push(L, item->IsBoundByEnchant()); + Eluna::Push(L, item->IsBoundByEnchant()); return 1; } int IsNotBoundToPlayer(lua_State* L, Item* item) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, item->IsBindedNotWith(player)); + Eluna::Push(L, item->IsBindedNotWith(player)); return 1; } int IsLocked(lua_State* L, Item* item) { - sEluna->Push(L, item->IsLocked()); + Eluna::Push(L, item->IsLocked()); return 1; } int IsBag(lua_State* L, Item* item) { - sEluna->Push(L, item->IsBag()); + Eluna::Push(L, item->IsBag()); return 1; } #ifndef CLASSIC int IsCurrencyToken(lua_State* L, Item* item) { - sEluna->Push(L, item->IsCurrencyToken()); + Eluna::Push(L, item->IsCurrencyToken()); return 1; } #endif int IsNotEmptyBag(lua_State* L, Item* item) { - sEluna->Push(L, item->IsNotEmptyBag()); + Eluna::Push(L, item->IsNotEmptyBag()); return 1; } int IsBroken(lua_State* L, Item* item) { - sEluna->Push(L, item->IsBroken()); + Eluna::Push(L, item->IsBroken()); return 1; } int CanBeTraded(lua_State* L, Item* item) { #if (defined(TBC) || defined(CLASSIC)) - sEluna->Push(L, item->CanBeTraded()); + Eluna::Push(L, item->CanBeTraded()); #else - bool mail = sEluna->CHECKVAL(L, 2, false); - sEluna->Push(L, item->CanBeTraded(mail)); + bool mail = Eluna::CHECKVAL(L, 2, false); + Eluna::Push(L, item->CanBeTraded(mail)); #endif return 1; } int IsInTrade(lua_State* L, Item* item) { - sEluna->Push(L, item->IsInTrade()); + Eluna::Push(L, item->IsInTrade()); return 1; } int IsInBag(lua_State* L, Item* item) { - sEluna->Push(L, item->IsInBag()); + Eluna::Push(L, item->IsInBag()); return 1; } int IsEquipped(lua_State* L, Item* item) { - sEluna->Push(L, item->IsEquipped()); + Eluna::Push(L, item->IsEquipped()); return 1; } int HasQuest(lua_State* L, Item* item) { - uint32 quest = sEluna->CHECKVAL(L, 2); + uint32 quest = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, item->HasQuest(quest)); + Eluna::Push(L, item->HasQuest(quest)); #else - sEluna->Push(L, item->hasQuest(quest)); + Eluna::Push(L, item->hasQuest(quest)); #endif return 1; } int IsPotion(lua_State* L, Item* item) { - sEluna->Push(L, item->IsPotion()); + Eluna::Push(L, item->IsPotion()); return 1; } #ifndef CATA int IsWeaponVellum(lua_State* L, Item* item) { - sEluna->Push(L, item->IsWeaponVellum()); + Eluna::Push(L, item->IsWeaponVellum()); return 1; } int IsArmorVellum(lua_State* L, Item* item) { - sEluna->Push(L, item->IsArmorVellum()); + Eluna::Push(L, item->IsArmorVellum()); return 1; } #endif int IsConjuredConsumable(lua_State* L, Item* item) { - sEluna->Push(L, item->IsConjuredConsumable()); + Eluna::Push(L, item->IsConjuredConsumable()); return 1; } /* int IsRefundExpired(lua_State* L, Item* item)// TODO: Implement core support { - sEluna->Push(L, item->IsRefundExpired()); + Eluna::Push(L, item->IsRefundExpired()); return 1; } */ @@ -157,7 +157,7 @@ namespace LuaItem // LOCALE_esMX = 7, // LOCALE_ruRU = 8 - int loc_idx = sEluna->CHECKVAL(L, 2, DEFAULT_LOCALE); + int loc_idx = Eluna::CHECKVAL(L, 2, DEFAULT_LOCALE); if (loc_idx < 0 || loc_idx >= MAX_LOCALES) return luaL_argerror(L, 2, "valid LocaleConstant expected"); @@ -211,212 +211,212 @@ namespace LuaItem item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" << (uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r"; - sEluna->Push(L, oss.str()); + Eluna::Push(L, oss.str()); return 1; } int GetGUID(lua_State* L, Item* item) { - sEluna->Push(L, item->GetGUIDLow()); + Eluna::Push(L, item->GetGUIDLow()); return 1; } int GetOwnerGUID(lua_State* L, Item* item) { #ifdef MANGOS - sEluna->Push(L, item->GetOwnerGuid()); + Eluna::Push(L, item->GetOwnerGuid()); #else - sEluna->Push(L, item->GetOwnerGUID()); + Eluna::Push(L, item->GetOwnerGUID()); #endif return 1; } int GetOwner(lua_State* L, Item* item) { - sEluna->Push(L, item->GetOwner()); + Eluna::Push(L, item->GetOwner()); return 1; } int GetCount(lua_State* L, Item* item) { - sEluna->Push(L, item->GetCount()); + Eluna::Push(L, item->GetCount()); return 1; } int GetMaxStackCount(lua_State* L, Item* item) { - sEluna->Push(L, item->GetMaxStackCount()); + Eluna::Push(L, item->GetMaxStackCount()); return 1; } int GetSlot(lua_State* L, Item* item) { - sEluna->Push(L, item->GetSlot()); + Eluna::Push(L, item->GetSlot()); return 1; } int GetBagSlot(lua_State* L, Item* item) { - sEluna->Push(L, item->GetBagSlot()); + Eluna::Push(L, item->GetBagSlot()); return 1; } int GetGUIDLow(lua_State* L, Item* item) { - sEluna->Push(L, item->GetGUIDLow()); + Eluna::Push(L, item->GetGUIDLow()); return 1; } int GetEnchantmentId(lua_State* L, Item* item) { - uint32 enchant_slot = sEluna->CHECKVAL(L, 2); + uint32 enchant_slot = Eluna::CHECKVAL(L, 2); if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); - sEluna->Push(L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); + Eluna::Push(L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); return 1; } int GetSpellId(lua_State* L, Item* item) { - uint32 index = sEluna->CHECKVAL(L, 2); + uint32 index = Eluna::CHECKVAL(L, 2); if (index >= MAX_ITEM_PROTO_SPELLS) return luaL_argerror(L, 2, "valid SpellIndex expected"); - sEluna->Push(L, item->GetTemplate()->Spells[index].SpellId); + Eluna::Push(L, item->GetTemplate()->Spells[index].SpellId); return 1; } int GetSpellTrigger(lua_State* L, Item* item) { - uint32 index = sEluna->CHECKVAL(L, 2); + uint32 index = Eluna::CHECKVAL(L, 2); if (index >= MAX_ITEM_PROTO_SPELLS) return luaL_argerror(L, 2, "valid SpellIndex expected"); - sEluna->Push(L, item->GetTemplate()->Spells[index].SpellTrigger); + Eluna::Push(L, item->GetTemplate()->Spells[index].SpellTrigger); return 1; } int GetClass(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->Class); + Eluna::Push(L, item->GetTemplate()->Class); return 1; } int GetSubClass(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->SubClass); + Eluna::Push(L, item->GetTemplate()->SubClass); return 1; } int GetName(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->Name1); + Eluna::Push(L, item->GetTemplate()->Name1); return 1; } int GetDisplayId(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->DisplayInfoID); + Eluna::Push(L, item->GetTemplate()->DisplayInfoID); return 1; } int GetQuality(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->Quality); + Eluna::Push(L, item->GetTemplate()->Quality); return 1; } int GetBuyCount(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->BuyCount); + Eluna::Push(L, item->GetTemplate()->BuyCount); return 1; } int GetBuyPrice(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->BuyPrice); + Eluna::Push(L, item->GetTemplate()->BuyPrice); return 1; } int GetSellPrice(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->SellPrice); + Eluna::Push(L, item->GetTemplate()->SellPrice); return 1; } int GetInventoryType(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->InventoryType); + Eluna::Push(L, item->GetTemplate()->InventoryType); return 1; } int GetAllowableClass(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->AllowableClass); + Eluna::Push(L, item->GetTemplate()->AllowableClass); return 1; } int GetAllowableRace(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->AllowableRace); + Eluna::Push(L, item->GetTemplate()->AllowableRace); return 1; } int GetItemLevel(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->ItemLevel); + Eluna::Push(L, item->GetTemplate()->ItemLevel); return 1; } int GetRequiredLevel(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->RequiredLevel); + Eluna::Push(L, item->GetTemplate()->RequiredLevel); return 1; } #ifdef WOTLK int GetStatsCount(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->StatsCount); + Eluna::Push(L, item->GetTemplate()->StatsCount); return 1; } #endif int GetRandomProperty(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->RandomProperty); + Eluna::Push(L, item->GetTemplate()->RandomProperty); return 1; } #ifndef CLASSIC int GetRandomSuffix(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->RandomSuffix); + Eluna::Push(L, item->GetTemplate()->RandomSuffix); return 1; } #endif int GetItemSet(lua_State* L, Item* item) { - sEluna->Push(L, item->GetTemplate()->ItemSet); + Eluna::Push(L, item->GetTemplate()->ItemSet); return 1; } int GetBagSize(lua_State* L, Item* item) { if (Bag* bag = item->ToBag()) - sEluna->Push(L, bag->GetBagSize()); + Eluna::Push(L, bag->GetBagSize()); else - sEluna->Push(L, 0); + Eluna::Push(L, 0); return 1; } /* SETTERS */ int SetOwner(lua_State* L, Item* item) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS item->SetOwnerGuid(player->GET_GUID()); #else @@ -427,7 +427,7 @@ namespace LuaItem int SetBinding(lua_State* L, Item* item) { - bool soulbound = sEluna->CHECKVAL(L, 2); + bool soulbound = Eluna::CHECKVAL(L, 2); item->SetBinding(soulbound); return 0; @@ -435,7 +435,7 @@ namespace LuaItem int SetCount(lua_State* L, Item* item) { - uint32 count = sEluna->CHECKVAL(L, 2); + uint32 count = Eluna::CHECKVAL(L, 2); item->SetCount(count); return 0; } @@ -445,25 +445,25 @@ namespace LuaItem Player* owner = item->GetOwner(); if (!owner) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } - uint32 enchant = sEluna->CHECKVAL(L, 2); + uint32 enchant = Eluna::CHECKVAL(L, 2); if (!sSpellItemEnchantmentStore.LookupEntry(enchant)) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } - EnchantmentSlot slot = (EnchantmentSlot)sEluna->CHECKVAL(L, 3); + EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL(L, 3); if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); owner->ApplyEnchantment(item, slot, false); item->SetEnchantment(slot, enchant, 0, 0); owner->ApplyEnchantment(item, slot, true); - sEluna->Push(L, true); + Eluna::Push(L, true); return 1; } @@ -473,23 +473,23 @@ namespace LuaItem Player* owner = item->GetOwner(); if (!owner) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } - EnchantmentSlot slot = (EnchantmentSlot)sEluna->CHECKVAL(L, 2); + EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL(L, 2); if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); if (!item->GetEnchantmentId(slot)) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } owner->ApplyEnchantment(item, slot, false); item->ClearEnchantment(slot); - sEluna->Push(L, true); + Eluna::Push(L, true); return 1; } diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 02a25e7..2e91442 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -6,83 +6,21 @@ #include #include +#include "HookMgr.h" #include "LuaEngine.h" +#include "Includes.h" -#ifdef MANGOS -INSTANTIATE_SINGLETON_1(Eluna); -#endif +Eluna::ScriptPaths Eluna::scripts; +Eluna* Eluna::GEluna = NULL; extern void RegisterFunctions(lua_State* L); -extern void AddElunaScripts(); -// Start or restart eluna. Returns true if started -bool StartEluna() +void Eluna::Initialize() { -#ifndef ELUNA -#ifndef MANGOS - { - ELUNA_LOG_ERROR("[Eluna]: LuaEngine is Disabled. (If you want to use it please enable in cmake)"); - return false; - } -#endif -#endif + uint32 oldMSTime = getMSTime(); - ELUNA_GUARD(); - bool restart = false; - if (sEluna->L) - { - restart = true; - sHookMgr->OnEngineRestart(); - ELUNA_LOG_INFO("[Eluna]: Stopping Lua Engine"); + scripts.clear(); - // Unregisters and stops all timed events - sEluna->m_EventMgr.RemoveEvents(); - - // Remove bindings - sEluna->PacketEventBindings.Clear(); - sEluna->ServerEventBindings.Clear(); - sEluna->PlayerEventBindings.Clear(); - sEluna->GuildEventBindings.Clear(); - sEluna->GroupEventBindings.Clear(); - - sEluna->CreatureEventBindings.Clear(); - sEluna->CreatureGossipBindings.Clear(); - sEluna->GameObjectEventBindings.Clear(); - sEluna->GameObjectGossipBindings.Clear(); - sEluna->ItemEventBindings.Clear(); - sEluna->ItemGossipBindings.Clear(); - sEluna->playerGossipBindings.Clear(); - sEluna->VehicleEventBindings.Clear(); - - lua_close(sEluna->L); - } - else - AddElunaScripts(); - -#ifdef MANGOS - // Check config file for eluna is enabled or disabled - if (!sWorld->getConfig(CONFIG_BOOL_ELUNA_ENABLED)) - { - ELUNA_LOG_ERROR("[Eluna]: LuaEngine is Disabled. (If you want to use it please set config in 'mangosd.conf')"); - return false; - } -#endif - - ELUNA_LOG_INFO("[Eluna]: Starting Lua Engine"); - - sEluna->L = luaL_newstate(); - luaL_openlibs(sEluna->L); - RegisterFunctions(sEluna->L); - - // Create hidden table with weak values - lua_newtable(sEluna->L); - lua_newtable(sEluna->L); - lua_pushstring(sEluna->L, "v"); - lua_setfield(sEluna->L, -2, "__mode"); - lua_setmetatable(sEluna->L, -2); - sHookMgr->userdata_table = luaL_ref(sEluna->L, LUA_REGISTRYINDEX); - - ScriptPaths scripts; std::string folderpath = sConfigMgr->GetStringDefault("Eluna.ScriptPath", "lua_scripts"); #if PLATFORM == PLATFORM_UNIX || PLATFORM == PLATFORM_APPLE if (folderpath[0] == '~') @@ -90,39 +28,92 @@ bool StartEluna() folderpath.replace(0, 1, home); #endif ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", folderpath.c_str()); - sEluna->GetScripts(folderpath, scripts); - sEluna->GetScripts(folderpath + "/extensions", scripts); - sEluna->RunScripts(scripts); + GetScripts(folderpath, scripts); + GetScripts(folderpath + "/extensions", scripts); - /* - if (restart) - { - //! Iterate over every supported source type (creature and gameobject) - //! Not entirely sure how this will affect units in non-loaded grids. - { - HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); - HashMapHolder::MapType& m = HashMapHolder::GetContainer(); - for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) - { - if (itr->second->IsInWorld()) // must check? - // if(sEluna->CreatureEventBindings->GetBindMap(iter->second->GetEntry())) // update all AI or just Eluna? - itr->second->AIM_Initialize(); - } - } + ELUNA_LOG_INFO("[Eluna]: Loaded %u scripts in %u ms", uint32(scripts.size()), GetMSTimeDiffToNow(oldMSTime)); - { - HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); - HashMapHolder::MapType& m = HashMapHolder::GetContainer(); - for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) - { - if (itr->second->IsInWorld()) // must check? - // if(sEluna->GameObjectEventBindings->GetBindMap(iter->second->GetEntry())) // update all AI or just Eluna? - itr->second->AIM_Initialize(); - } - } - } - */ - return true; + // Create global eluna + new Eluna(); +} + +void Eluna::Uninitialize() +{ + delete GEluna; +} + +void Eluna::ReloadEluna() +{ + Uninitialize(); + Initialize(); +} + +Eluna::Eluna(): +L(luaL_newstate()), + +m_EventMgr(new EventMgr(*this)), + +ServerEventBindings(new EventBind(*this)), +PlayerEventBindings(new EventBind(*this)), +GuildEventBindings(new EventBind(*this)), +GroupEventBindings(new EventBind(*this)), +VehicleEventBindings(new EventBind(*this)), + +PacketEventBindings(new EntryBind(*this)), +CreatureEventBindings(new EntryBind(*this)), +CreatureGossipBindings(new EntryBind(*this)), +GameObjectEventBindings(new EntryBind(*this)), +GameObjectGossipBindings(new EntryBind(*this)), +ItemEventBindings(new EntryBind(*this)), +ItemGossipBindings(new EntryBind(*this)), +playerGossipBindings(new EntryBind(*this)) +{ + // open base lua + luaL_openlibs(L); + RegisterFunctions(L); + + // Create hidden table with weak values + lua_newtable(L); + lua_newtable(L); + lua_pushstring(L, "v"); + lua_setfield(L, -2, "__mode"); + lua_setmetatable(L, -2); + userdata_table = luaL_ref(L, LUA_REGISTRYINDEX); + + // Replace this with map insert if making multithread version + ASSERT(!Eluna::GEluna); + Eluna::GEluna = this; + + // run scripts + RunScripts(scripts); +} + +Eluna::~Eluna() +{ + OnLuaStateClose(); + + // Replace this with map remove if making multithread version + Eluna::GEluna = NULL; + + delete m_EventMgr; + + delete ServerEventBindings; + delete PlayerEventBindings; + delete GuildEventBindings; + delete GroupEventBindings; + delete VehicleEventBindings; + + delete PacketEventBindings; + delete CreatureEventBindings; + delete CreatureGossipBindings; + delete GameObjectEventBindings; + delete GameObjectGossipBindings; + delete ItemEventBindings; + delete ItemGossipBindings; + delete playerGossipBindings; + + // Must close lua state after deleting stores and mgr + lua_close(L); } // Finds lua script files from given path (including subdirectories) and pushes them to scripts @@ -187,7 +178,21 @@ void Eluna::RunScripts(ScriptPaths& scripts) ELUNA_LOG_ERROR("[Eluna]: Error loading file `%s`", it->c_str()); report(L); } - ELUNA_LOG_INFO("[Eluna]: Loaded %u Lua scripts", count); + ELUNA_LOG_DEBUG("[Eluna]: Loaded %u Lua scripts", count); +} + +void Eluna::RemoveRef(const void* obj) +{ + lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, sEluna->userdata_table); + lua_pushfstring(sEluna->L, "%p", obj); + lua_gettable(sEluna->L, -2); + if (!lua_isnoneornil(sEluna->L, -1)) + { + lua_pushfstring(sEluna->L, "%p", obj); + lua_pushnil(sEluna->L); + lua_settable(sEluna->L, -4); + } + lua_pop(sEluna->L, 2); } void Eluna::report(lua_State* L) @@ -201,47 +206,12 @@ void Eluna::report(lua_State* L) } } -void Eluna::BeginCall(int fReference) +void Eluna::ExecuteCall(lua_State* L, int params, int res) { - lua_settop(L, 0); // stack should be empty - lua_rawgeti(L, LUA_REGISTRYINDEX, (fReference)); -} - -bool Eluna::ExecuteCall(int params, int res) -{ - bool ret = true; int top = lua_gettop(L); - - if (lua_type(L, top - params) == LUA_TFUNCTION) // is function - { - if (lua_pcall(L, params, res, 0)) - { - report(L); - ret = false; - } - } - else - { - ret = false; - if (params > 0) - { - for (int i = top; i >= (top - params); i--) - { - if (!lua_isnone(L, i)) - lua_remove(L, i); - } - } - } - return ret; -} - -void Eluna::EndCall(int res) -{ - for (int i = res; i > 0; i--) - { - if (!lua_isnone(L, res)) - lua_remove(L, res); - } + luaL_checktype(L, top - params, LUA_TFUNCTION); + if (lua_pcall(L, params, res, 0)) + report(L); } void Eluna::Push(lua_State* L) @@ -252,13 +222,13 @@ void Eluna::Push(lua_State* L, const uint64 l) { std::ostringstream ss; ss << l; - sEluna->Push(L, ss.str()); + Push(L, ss.str()); } void Eluna::Push(lua_State* L, const int64 l) { std::ostringstream ss; ss << l; - sEluna->Push(L, ss.str()); + Push(L, ss.str()); } void Eluna::Push(lua_State* L, const uint32 u) { @@ -558,7 +528,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_PACKET: if (evt < NUM_MSG_TYPES) { - PacketEventBindings.Insert(evt, functionRef); + PacketEventBindings->Insert(id, evt, functionRef); return; } break; @@ -566,7 +536,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_SERVER: if (evt < SERVER_EVENT_COUNT) { - ServerEventBindings.Insert(evt, functionRef); + ServerEventBindings->Insert(evt, functionRef); return; } break; @@ -574,7 +544,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_PLAYER: if (evt < PLAYER_EVENT_COUNT) { - PlayerEventBindings.Insert(evt, functionRef); + PlayerEventBindings->Insert(evt, functionRef); return; } break; @@ -582,7 +552,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_GUILD: if (evt < GUILD_EVENT_COUNT) { - GuildEventBindings.Insert(evt, functionRef); + GuildEventBindings->Insert(evt, functionRef); return; } break; @@ -590,7 +560,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_GROUP: if (evt < GROUP_EVENT_COUNT) { - GroupEventBindings.Insert(evt, functionRef); + GroupEventBindings->Insert(evt, functionRef); return; } break; @@ -598,7 +568,7 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_VEHICLE: if (evt < VEHICLE_EVENT_COUNT) { - VehicleEventBindings.Insert(evt, functionRef); + VehicleEventBindings->Insert(evt, functionRef); return; } break; @@ -608,12 +578,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetCreatureTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a creature with (ID: %d)!", id); return; } - sEluna->CreatureEventBindings.Insert(id, evt, functionRef); + CreatureEventBindings->Insert(id, evt, functionRef); return; } break; @@ -623,12 +593,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetCreatureTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a creature with (ID: %d)!", id); return; } - sEluna->CreatureGossipBindings.Insert(id, evt, functionRef); + CreatureGossipBindings->Insert(id, evt, functionRef); return; } break; @@ -638,12 +608,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetGameObjectTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", id); return; } - sEluna->GameObjectEventBindings.Insert(id, evt, functionRef); + GameObjectEventBindings->Insert(id, evt, functionRef); return; } break; @@ -653,12 +623,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetGameObjectTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", id); return; } - sEluna->GameObjectGossipBindings.Insert(id, evt, functionRef); + GameObjectGossipBindings->Insert(id, evt, functionRef); return; } break; @@ -668,12 +638,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetItemTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a item with (ID: %d)!", id); return; } - sEluna->ItemEventBindings.Insert(id, evt, functionRef); + ItemEventBindings->Insert(id, evt, functionRef); return; } break; @@ -683,12 +653,12 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) { if (!sObjectMgr->GetItemTemplate(id)) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Couldn't find a item with (ID: %d)!", id); return; } - sEluna->ItemGossipBindings.Insert(id, evt, functionRef); + ItemGossipBindings->Insert(id, evt, functionRef); return; } break; @@ -696,32 +666,32 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) case REGTYPE_PLAYER_GOSSIP: if (evt < GOSSIP_EVENT_COUNT) { - sEluna->playerGossipBindings.Insert(id, evt, functionRef); + playerGossipBindings->Insert(id, evt, functionRef); return; } break; } - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_unref(L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt); } -void Eluna::EventBind::Clear() +void EventBind::Clear() { for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) { for (ElunaBindingMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it) - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, (*it)); + luaL_unref(E.L, LUA_REGISTRYINDEX, (*it)); itr->second.clear(); } Bindings.clear(); } -void Eluna::EventBind::Insert(int eventId, int funcRef) +void EventBind::Insert(int eventId, int funcRef) { Bindings[eventId].push_back(funcRef); } -bool Eluna::EventBind::HasEvents(int eventId) const +bool EventBind::HasEvents(int eventId) const { if (Bindings.empty()) return false; @@ -730,61 +700,33 @@ bool Eluna::EventBind::HasEvents(int eventId) const return true; } -void Eluna::EventBind::BeginCall(int eventId) const -{ - lua_settop(sEluna->L, 0); // stack should be empty - sEluna->Push(sEluna->L, eventId); -} - -void Eluna::EventBind::ExecuteCall() -{ - int eventId = sEluna->CHECKVAL(sEluna->L, 1); - int params = lua_gettop(sEluna->L); - for (ElunaBindingMap::const_iterator it = Bindings[eventId].begin(); it != Bindings[eventId].end(); ++it) - { - lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, (*it)); // Fetch function - for (int i = 1; i <= params; ++i) // Copy original pushed params - lua_pushvalue(sEluna->L, i); - sEluna->ExecuteCall(params, LUA_MULTRET); // Do call and leave results to stack - } - for (int i = params; i > 0; --i) // Remove original pushed params - if (!lua_isnone(sEluna->L, i)) - lua_remove(sEluna->L, i); - // Results in stack, otherwise stack clean -} - -void Eluna::EventBind::EndCall() const -{ - lua_settop(sEluna->L, 0); // stack should be empty -}; - -void Eluna::EntryBind::Clear() +void EntryBind::Clear() { for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) { for (ElunaBindingMap::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, it->second); + luaL_unref(E.L, LUA_REGISTRYINDEX, it->second); itr->second.clear(); } Bindings.clear(); } -void Eluna::EntryBind::Insert(uint32 entryId, int eventId, int funcRef) +void EntryBind::Insert(uint32 entryId, int eventId, int funcRef) { if (Bindings[entryId][eventId]) { - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, funcRef); // free the unused ref - luaL_error(sEluna->L, "A function is already registered for entry (%d) event (%d)", entryId, eventId); + luaL_unref(E.L, LUA_REGISTRYINDEX, funcRef); // free the unused ref + luaL_error(E.L, "A function is already registered for entry (%d) event (%d)", entryId, eventId); } else Bindings[entryId][eventId] = funcRef; } -EventMgr::LuaEvent::LuaEvent(EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj): -events(_events), funcRef(_funcRef), delay(_delay), calls(_calls), obj(_obj) +EventMgr::LuaEvent::LuaEvent(Eluna& _E, EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj): +E(_E), events(_events), funcRef(_funcRef), delay(_delay), calls(_calls), obj(_obj) { if (_events) - sEluna->m_EventMgr.LuaEvents[_events].insert(this); // Able to access the event if we have the processor + E.m_EventMgr->LuaEvents[_events].insert(this); // Able to access the event if we have the processor } EventMgr::LuaEvent::~LuaEvent() @@ -792,79 +734,25 @@ EventMgr::LuaEvent::~LuaEvent() if (events) { // Attempt to remove the pointer from LuaEvents - EventMgr::EventMap::const_iterator it = sEluna->m_EventMgr.LuaEvents.find(events); // Get event set - if (it != sEluna->m_EventMgr.LuaEvents.end()) - sEluna->m_EventMgr.LuaEvents[events].erase(this);// Remove pointer + EventMgr::EventMap::const_iterator it = E.m_EventMgr->LuaEvents.find(events); // Get event set + if (it != E.m_EventMgr->LuaEvents.end()) + E.m_EventMgr->LuaEvents[events].erase(this);// Remove pointer } - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, funcRef); // Free lua function ref + luaL_unref(E.L, LUA_REGISTRYINDEX, funcRef); // Free lua function ref } bool EventMgr::LuaEvent::Execute(uint64 time, uint32 diff) { - ELUNA_GUARD(); bool remove = (calls == 1); if (!remove) events->AddEvent(this, events->CalculateTime(delay)); // Reschedule before calling incase RemoveEvents used - sEluna->BeginCall(funcRef); - sEluna->Push(sEluna->L, funcRef); - sEluna->Push(sEluna->L, delay); - sEluna->Push(sEluna->L, calls); + lua_rawgeti(E.L, LUA_REGISTRYINDEX, funcRef); + Eluna::Push(E.L, funcRef); + Eluna::Push(E.L, delay); + Eluna::Push(E.L, calls); if (!remove && calls) --calls; - sEluna->Push(sEluna->L, obj); - sEluna->ExecuteCall(4, 0); + Eluna::Push(E.L, obj); + Eluna::ExecuteCall(E.L, 4, 0); return remove; // Destory (true) event if not run } - -// Lua taxi helper functions -uint32 LuaTaxiMgr::nodeId = 500; -void LuaTaxiMgr::StartTaxi(Player* player, uint32 pathid) -{ - if (pathid >= sTaxiPathNodesByPath.size()) - return; - - TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathid]; - if (path.size() < 2) - return; - - std::vector nodes; - nodes.resize(2); - nodes[0] = path[0].index; - nodes[1] = path[path.size() - 1].index; - - player->ActivateTaxiPathTo(nodes); -} - -uint32 LuaTaxiMgr::AddPath(std::list nodes, uint32 mountA, uint32 mountH, uint32 price, uint32 pathId) -{ - if (nodes.size() < 2) - return 0; - if (!pathId) - pathId = sTaxiPathNodesByPath.size(); - if (sTaxiPathNodesByPath.size() <= pathId) - sTaxiPathNodesByPath.resize(pathId + 1); - sTaxiPathNodesByPath[pathId].clear(); - sTaxiPathNodesByPath[pathId].resize(nodes.size()); - uint32 startNode = nodeId; - uint32 index = 0; - for (std::list::const_iterator it = nodes.begin(); it != nodes.end(); ++it) - { - TaxiPathNodeEntry entry = *it; - entry.path = pathId; - TaxiNodesEntry* nodeEntry = new TaxiNodesEntry(); - nodeEntry->ID = index; - nodeEntry->map_id = entry.mapid; - nodeEntry->MountCreatureID[0] = mountH; - nodeEntry->MountCreatureID[1] = mountA; - nodeEntry->x = entry.x; - nodeEntry->y = entry.y; - nodeEntry->z = entry.z; - sTaxiNodesStore.SetEntry(nodeId, nodeEntry); - entry.index = nodeId++; - sTaxiPathNodesByPath[pathId].set(index++, TaxiPathNodePtr(new TaxiPathNodeEntry(entry))); - } - if (startNode >= nodeId) - return 0; - sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); - return pathId; -} diff --git a/LuaEngine.h b/LuaEngine.h index dd58cab..a6834a1 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -14,61 +14,67 @@ extern "C" #include "lauxlib.h" }; -#include "HookMgr.h" - -// Required -#include "AccountMgr.h" -#include "AuctionHouseMgr.h" -#include "Cell.h" -#include "CellImpl.h" -#include "Chat.h" -#include "Channel.h" +// Base +#include "Common.h" +#include "SharedDefines.h" +#include +#include +// enums #ifdef MANGOS -#include "Config/Config.h" -#else -#include "Config.h" -#endif -#include "DBCStores.h" -#include "GossipDef.h" -#include "GridNotifiers.h" -#include "GridNotifiersImpl.h" -#include "Group.h" -#include "Guild.h" -#include "GuildMgr.h" -#include "Language.h" -#include "Mail.h" -#include "MapManager.h" -#include "ObjectAccessor.h" -#include "ObjectMgr.h" -#include "Opcodes.h" #include "Player.h" -#include "Pet.h" -#include "ReputationMgr.h" -#include "revision.h" -#include "ScriptMgr.h" -#include "Spell.h" -#include "SpellAuras.h" -#include "SpellMgr.h" -#include "TemporarySummon.h" -#include "World.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#ifdef MANGOS -#include "ReactorAI.h" -#include "revision_nr.h" #else -#include "ScriptedCreature.h" -#include "SpellInfo.h" -#include "WeatherMgr.h" +#include "GameObjectAI.h" #endif -#if (!defined(TBC) && !defined(CLASSIC)) -#include "Vehicle.h" +#include "Group.h" +#include "Item.h" +#include "Weather.h" +#include "World.h" + +#ifdef MANGOS +typedef SpellEffectIndex SpellEffIndex; +typedef SpellEntry SpellInfo; +typedef ItemPrototype ItemTemplate; +#define GetTemplate GetProto +#ifdef CLASSIC +typedef int Difficulty; #endif -#ifndef CLASSIC -#include "ArenaTeam.h" #endif -typedef std::set ScriptPaths; +struct AreaTriggerEntry; +#ifdef MANGOS +class ReactorAI; +typedef ReactorAI ScriptedAI; +#else +#undef UNORDERED_MAP +#define UNORDERED_MAP std::unordered_map +struct ScriptedAI; +#endif +class AuctionHouseObject; +class Channel; +class Creature; +class CreatureAI; +class GameObject; +class Guild; +class Group; +class Item; +class Player; +class Quest; +class Spell; +class SpellCastTargets; +class Transport; +class Unit; +class Weather; +class WorldPacket; +#ifndef CLASSIC +#ifndef TBC +#ifdef TRINITY +class Vehicle; +#else +class VehicleInfo; +typedef VehicleInfo Vehicle; +#endif +#endif +#endif #ifdef MANGOS #undef sWorld @@ -138,6 +144,8 @@ typedef ThreatContainer::StorageType ThreatList; #endif #endif +class Eluna; + template struct ElunaRegister { @@ -152,6 +160,7 @@ struct EventMgr typedef std::set EventSet; typedef std::map EventMap; // typedef UNORDERED_MAP ProcessorMap; + Eluna& E; EventMap LuaEvents; // LuaEvents[processor] = {LuaEvent, LuaEvent...} // ProcessorMap Processors; // Processors[guid] = processor @@ -159,13 +168,14 @@ struct EventMgr struct LuaEvent : public BasicEvent { - LuaEvent(EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj); + LuaEvent(Eluna& _E, EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj); ~LuaEvent(); // Should never execute on dead events bool Execute(uint64 time, uint32 diff); + Eluna& E; EventProcessor* events; // Pointer to events (holds the timed event) int funcRef; // Lua function reference ID, also used as event ID uint32 delay; // Delay between event calls @@ -173,6 +183,15 @@ struct EventMgr Object* obj; // Object to push }; + EventMgr(Eluna& _E) : E(_E) + { + } + + ~EventMgr() + { + RemoveEvents(); + } + // Should be run on world tick void Update(uint32 diff) { @@ -243,7 +262,7 @@ struct EventMgr { if (!events || funcRef <= 0) // If funcRef <= 0, function reference failed return 0; // on fail always return 0. funcRef can be negative. - events->AddEvent(new LuaEvent(events, funcRef, delay, calls, obj), events->CalculateTime(delay)); + events->AddEvent(new LuaEvent(E, events, funcRef, delay, calls, obj), events->CalculateTime(delay)); return funcRef; // return the event ID } @@ -308,169 +327,168 @@ struct EventMgr if (RemoveEvent((it++)->first, eventId)) break; // succesfully remove the event, stop loop. } +}; - ~EventMgr() +struct EventBind +{ + typedef std::vector ElunaBindingMap; + typedef std::map ElunaEntryMap; + Eluna& E; + + EventBind(Eluna& _E): E(_E) { - RemoveEvents(); } + + ~EventBind() + { + Clear(); + } + + void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) + void Insert(int eventId, int funcRef); // Inserts a new registered event + + // Gets the binding std::map containing all registered events with the function refs for the entry + ElunaBindingMap* GetBindMap(int eventId) + { + if (Bindings.empty()) + return NULL; + ElunaEntryMap::iterator itr = Bindings.find(eventId); + if (itr == Bindings.end()) + return NULL; + + return &itr->second; + } + + // Checks if there are events for ID + bool HasEvents(int eventId) const; + + ElunaEntryMap Bindings; // Binding store Bindings[eventId] = {funcRef}; +}; + +struct EntryBind +{ + typedef std::map ElunaBindingMap; + typedef UNORDERED_MAP ElunaEntryMap; + Eluna& E; + + EntryBind(Eluna& _E): E(_E) + { + } + + ~EntryBind() + { + Clear(); + } + + void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) + void Insert(uint32 entryId, int eventId, int funcRef); // Inserts a new registered event + + // Gets the function ref of an entry for an event + int GetBind(uint32 entryId, int eventId) const + { + if (Bindings.empty()) + return 0; + ElunaEntryMap::const_iterator itr = Bindings.find(entryId); + if (itr == Bindings.end() || itr->second.empty()) + return 0; + ElunaBindingMap::const_iterator itr2 = itr->second.find(eventId); + if (itr2 == itr->second.end()) + return 0; + return itr2->second; + } + + // Gets the binding std::map containing all registered events with the function refs for the entry + const ElunaBindingMap* GetBindMap(uint32 entryId) const + { + if (Bindings.empty()) + return NULL; + ElunaEntryMap::const_iterator itr = Bindings.find(entryId); + if (itr == Bindings.end()) + return NULL; + + return &itr->second; + } + + // Returns true if the entry has registered binds + bool HasBinds(uint32 entryId) const + { + if (Bindings.empty()) + return false; + return Bindings.find(entryId) != Bindings.end(); + } + + ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef; }; class Eluna { public: friend class ScriptMgr; - // friend class ACE_Singleton; + typedef std::set ScriptPaths; + + static Eluna* GEluna; lua_State* L; - EventMgr m_EventMgr; - // ACE_Recursive_Thread_Mutex lock; + int userdata_table; - Eluna() - { - L = NULL; - } - - ~Eluna() - { - } - - struct EventBind - { - typedef std::vector ElunaBindingMap; - typedef std::map ElunaEntryMap; - - ~EventBind() - { - Clear(); - } - - void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) - void Insert(int eventId, int funcRef); // Inserts a new registered event - - // Gets the binding std::map containing all registered events with the function refs for the entry - ElunaBindingMap* GetBindMap(int eventId) - { - if (Bindings.empty()) - return NULL; - ElunaEntryMap::iterator itr = Bindings.find(eventId); - if (itr == Bindings.end()) - return NULL; - - return &itr->second; - } - - // Checks if there are events for ID - bool HasEvents(int eventId) const; - // Cleans stack and pushes eventId - void BeginCall(int eventId) const; - // Loops through all registered events for the eventId at stack index 1 - // Copies the whole stack as arguments for the called function. Before Executing, push all params to stack! - // Leaves return values from all functions in order to the stack. - void ExecuteCall(); - void EndCall() const; - - ElunaEntryMap Bindings; // Binding store Bindings[eventId] = {funcRef}; - }; - - struct EntryBind - { - typedef std::map ElunaBindingMap; - typedef UNORDERED_MAP ElunaEntryMap; - - ~EntryBind() - { - Clear(); - } - - void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) - void Insert(uint32 entryId, int eventId, int funcRef); // Inserts a new registered event - - // Gets the function ref of an entry for an event - int GetBind(uint32 entryId, int eventId) const - { - if (Bindings.empty()) - return 0; - ElunaEntryMap::const_iterator itr = Bindings.find(entryId); - if (itr == Bindings.end() || itr->second.empty()) - return 0; - ElunaBindingMap::const_iterator itr2 = itr->second.find(eventId); - if (itr2 == itr->second.end()) - return 0; - return itr2->second; - } - - // Gets the binding std::map containing all registered events with the function refs for the entry - const ElunaBindingMap* GetBindMap(uint32 entryId) const - { - if (Bindings.empty()) - return NULL; - ElunaEntryMap::const_iterator itr = Bindings.find(entryId); - if (itr == Bindings.end()) - return NULL; - - return &itr->second; - } - - // Returns true if the entry has registered binds - bool HasBinds(uint32 entryId) const - { - if (Bindings.empty()) - return false; - return Bindings.find(entryId) != Bindings.end(); - } - - ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef; - }; + EventMgr* m_EventMgr; // Use templates for EventBind - EventBind PacketEventBindings; - EventBind ServerEventBindings; - EventBind PlayerEventBindings; - EventBind GuildEventBindings; - EventBind GroupEventBindings; - EventBind VehicleEventBindings; + EventBind* ServerEventBindings; + EventBind* PlayerEventBindings; + EventBind* GuildEventBindings; + EventBind* GroupEventBindings; + EventBind* VehicleEventBindings; - EntryBind CreatureEventBindings; - EntryBind CreatureGossipBindings; - EntryBind GameObjectEventBindings; - EntryBind GameObjectGossipBindings; - EntryBind ItemEventBindings; - EntryBind ItemGossipBindings; - EntryBind playerGossipBindings; + EntryBind* PacketEventBindings; + EntryBind* CreatureEventBindings; + EntryBind* CreatureGossipBindings; + EntryBind* GameObjectEventBindings; + EntryBind* GameObjectGossipBindings; + EntryBind* ItemEventBindings; + EntryBind* ItemGossipBindings; + EntryBind* playerGossipBindings; + + Eluna(); + ~Eluna(); + + static ScriptPaths scripts; + static void Initialize(); + static void Uninitialize(); + static void ReloadEluna(); + void static GetScripts(std::string path, ScriptPaths& scripts); static void report(lua_State*); + static void ExecuteCall(lua_State* L, int params, int res); void Register(uint8 reg, uint32 id, uint32 evt, int func); - void BeginCall(int fReference); - bool ExecuteCall(int params, int res); - void EndCall(int res); - void GetScripts(std::string path, ScriptPaths& scripts); void RunScripts(ScriptPaths& scripts); + static void RemoveRef(const void* obj); // Pushes - void Push(lua_State*); // nil - void Push(lua_State*, const uint64); - void Push(lua_State*, const int64); - void Push(lua_State*, const uint32); - void Push(lua_State*, const int32); - void Push(lua_State*, const bool); - void Push(lua_State*, const float); - void Push(lua_State*, const double); - void Push(lua_State*, const char*); - void Push(lua_State*, const std::string); - template void Push(lua_State* L, T const* ptr) + static void Push(lua_State*); // nil + static void Push(lua_State*, const uint64); + static void Push(lua_State*, const int64); + static void Push(lua_State*, const uint32); + static void Push(lua_State*, const int32); + static void Push(lua_State*, const bool); + static void Push(lua_State*, const float); + static void Push(lua_State*, const double); + static void Push(lua_State*, const char*); + static void Push(lua_State*, const std::string); + template static void Push(lua_State* L, T const* ptr) { ElunaTemplate::push(L, ptr); } - void Push(lua_State* L, Object const* obj); - void Push(lua_State* L, WorldObject const* obj); - void Push(lua_State* L, Unit const* unit); - void Push(lua_State* L, Pet const* pet); - void Push(lua_State* L, TempSummon const* summon); + static void Push(lua_State* L, Object const* obj); + static void Push(lua_State* L, WorldObject const* obj); + static void Push(lua_State* L, Unit const* unit); + static void Push(lua_State* L, Pet const* pet); + static void Push(lua_State* L, TempSummon const* summon); // Checks - template T CHECKVAL(lua_State* L, int narg); - template T CHECKVAL(lua_State* L, int narg, T def); - template T* CHECKOBJ(lua_State* L, int narg, bool error = true) + template static T CHECKVAL(lua_State* L, int narg); + template static T CHECKVAL(lua_State* L, int narg, T def); + template static T* CHECKOBJ(lua_State* L, int narg, bool error = true) { return ElunaTemplate::check(L, narg, error); } @@ -550,6 +568,167 @@ public: WorldObjectInRangeCheck(WorldObjectInRangeCheck const&); }; + + CreatureAI* GetAI(Creature* creature); +#ifndef MANGOS + GameObjectAI* GetAI(GameObject* gameObject); +#endif + + /* Custom */ + bool OnCommand(Player* player, const char* text); + void OnWorldUpdate(uint32 diff); + void OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid); + void OnLootMoney(Player* pPlayer, uint32 amount); + void OnFirstLogin(Player* pPlayer); + void OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot); + void OnRepop(Player* pPlayer); + void OnResurrect(Player* pPlayer); + void OnQuestAbandon(Player* pPlayer, uint32 questId); + InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry); + void OnLuaStateClose(); + bool OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); + + /* Item */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget); + bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest); + bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); + bool OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); + bool OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); + bool OnExpire(Player* pPlayer, ItemTemplate const* pProto); + bool OnRemove(Player* pPlayer, Item* item); + void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code); + + /* Creature */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget); + bool OnGossipHello(Player* pPlayer, Creature* pCreature); + bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action); + bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code); + bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + bool OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); + void OnSummoned(Creature* creature, Unit* summoner); + + /* GameObject */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget); + bool OnGossipHello(Player* pPlayer, GameObject* pGameObject); + bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action); + bool OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code); + bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + bool OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + bool OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + uint32 GetDialogStatus(Player* pPlayer, GameObject* pGameObject); +#ifndef CLASSIC +#ifndef TBC + void OnDestroyed(GameObject* pGameObject, Player* pPlayer); + void OnDamaged(GameObject* pGameObject, Player* pPlayer); +#endif +#endif + void OnLootStateChanged(GameObject* pGameObject, uint32 state); + void OnGameObjectStateChanged(GameObject* pGameObject, uint32 state); + void UpdateAI(GameObject* pGameObject, uint32 diff); + void OnSpawn(GameObject* gameobject); + + /* Packet */ + bool OnPacketSend(WorldSession* session, WorldPacket& packet); + void OnPacketSendAny(Player* player, WorldPacket& packet, bool& result); + void OnPacketSendOne(Player* player, WorldPacket& packet, bool& result); + bool OnPacketReceive(WorldSession* session, WorldPacket& packet); + void OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result); + void OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result); + + /* Player */ + void OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy); + void OnPlayerLeaveCombat(Player* pPlayer); + void OnPVPKill(Player* pKiller, Player* pKilled); + void OnCreatureKill(Player* pKiller, Creature* pKilled); + void OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled); + void OnLevelChanged(Player* pPlayer, uint8 oldLevel); + void OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints); + void OnTalentsReset(Player* pPlayer, bool noCost); + void OnMoneyChanged(Player* pPlayer, int32& amount); + void OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim); + void OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental); + void OnDuelRequest(Player* pTarget, Player* pChallenger); + void OnDuelStart(Player* pStarter, Player* pChallenger); + void OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver); + void OnEmote(Player* pPlayer, uint32 emote); + void OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid); + void OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck); + void OnLogin(Player* pPlayer); + void OnLogout(Player* pPlayer); + void OnCreate(Player* pPlayer); + void OnDelete(uint32 guid); + void OnSave(Player* pPlayer); + void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent); + void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea); + void OnMapChanged(Player* pPlayer); + void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code); + +#ifndef CLASSIC +#ifndef TBC + /* Vehicle */ + void OnInstall(Vehicle* vehicle); + void OnUninstall(Vehicle* vehicle); + void OnInstallAccessory(Vehicle* vehicle, Creature* accessory); + void OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId); + void OnRemovePassenger(Vehicle* vehicle, Unit* passenger); +#endif +#endif + + /* AreaTrigger */ + bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger); + + /* Weather */ + void OnChange(Weather* weather, WeatherState state, float grade); + + /* Auction House */ + void OnAdd(AuctionHouseObject* auctionHouse); + void OnRemove(AuctionHouseObject* auctionHouse); + void OnSuccessful(AuctionHouseObject* auctionHouse); + void OnExpire(AuctionHouseObject* auctionHouse); + + /* Guild */ + void OnAddMember(Guild* guild, Player* player, uint32 plRank); + void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding); + void OnMOTDChanged(Guild* guild, const std::string& newMotd); + void OnInfoChanged(Guild* guild, const std::string& newInfo); + void OnCreate(Guild* guild, Player* leader, const std::string& name); + void OnDisband(Guild* guild); + void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair); + void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount); + void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId); + void OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank); + void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId); + + /* Group */ + void OnAddMember(Group* group, uint64 guid); + void OnInviteMember(Group* group, uint64 guid); + void OnRemoveMember(Group* group, uint64 guid, uint8 method); + void OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid); + void OnDisband(Group* group); + void OnCreate(Group* group, uint64 leaderGuid, GroupType groupType); + + /* Map */ + void OnCreate(Map* map); + void OnDestroy(Map* map); + void OnPlayerEnter(Map* map, Player* player); + void OnPlayerLeave(Map* map, Player* player); + void OnUpdate(Map* map, uint32 diff); + + /* World */ + void OnOpenStateChange(bool open); + void OnConfigLoad(bool reload); + void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask); + void OnShutdownCancel(); + void OnUpdate(uint32 diff); + void OnStartup(); + void OnShutdown(); }; template<> Unit* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); template<> Player* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); @@ -557,13 +736,9 @@ template<> Creature* Eluna::CHECKOBJ(lua_State* L, int narg, bool erro template<> GameObject* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); -#ifdef MANGOS -#define sEluna (&MaNGOS::Singleton::Instance()) -#else -#define sEluna ACE_Singleton::instance() -#endif +#define sEluna Eluna::GEluna -#define ELUNA_GUARD() // ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); +// #define ELUNA_GUARD() ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); template class ElunaTemplate @@ -679,7 +854,7 @@ public: if (!manageMemory) { - lua_rawgeti(L, LUA_REGISTRYINDEX, sHookMgr->userdata_table); + lua_rawgeti(L, LUA_REGISTRYINDEX, sEluna->userdata_table); lua_pushfstring(L, "%p", obj); lua_gettable(L, -2); if (!lua_isnoneornil(L, -1) && luaL_checkudata(L, -1, tname)) @@ -692,11 +867,11 @@ public: } // Create new userdata - T const** ptrHold = (T const**)lua_newuserdata(L, sizeof(T const**)); + T const** ptrHold = static_cast(lua_newuserdata(L, sizeof(T const*))); if (!ptrHold) { ELUNA_LOG_ERROR("%s could not create new userdata", tname); - lua_remove(L, -1); + lua_pop(L, manageMemory ? 1 : 2); lua_pushnil(L); return 1; } @@ -707,18 +882,17 @@ public: if (!lua_istable(L, -1)) { ELUNA_LOG_ERROR("%s missing metatable", tname); - lua_pop(L, 2); + lua_pop(L, manageMemory ? 2 : 3); lua_pushnil(L); return 1; } lua_setmetatable(L, -2); - if (!manageMemory) { lua_pushfstring(L, "%p", obj); lua_pushvalue(L, -2); - lua_settable(L, -3); + lua_settable(L, -4); lua_remove(L, -2); } return 1; @@ -741,7 +915,7 @@ public: if (!manageMemory) { // Check pointer validity - lua_rawgeti(L, LUA_REGISTRYINDEX, sHookMgr->userdata_table); + lua_rawgeti(L, LUA_REGISTRYINDEX, sEluna->userdata_table); lua_pushfstring(L, "%p", *ptrHold); lua_gettable(L, -2); lua_remove(L, -2); @@ -767,7 +941,7 @@ public: static int thunk(lua_State* L) { - T* obj = sEluna->CHECKOBJ(L, 1); // get self + T* obj = Eluna::CHECKOBJ(L, 1); // get self if (!obj) return 0; ElunaRegister* l = static_cast*>(lua_touserdata(L, lua_upvalueindex(1))); @@ -785,7 +959,7 @@ public: static int tostringT(lua_State* L) { - T* obj = sEluna->CHECKOBJ(L, 1); // get self + T* obj = Eluna::CHECKOBJ(L, 1); // get self if (obj) { lua_pushfstring(L, "%s: (%p)", tname, obj); @@ -798,12 +972,4 @@ public: } }; -class LuaTaxiMgr -{ -private: - static uint32 nodeId; -public: - static void StartTaxi(Player* player, uint32 pathid); - static uint32 AddPath(std::list nodes, uint32 mountA, uint32 mountH, uint32 price = 0, uint32 pathId = 0); -}; #endif diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 48cc639..5b7f8f3 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -5,7 +5,9 @@ */ // Eluna +#include "HookMgr.h" #include "LuaEngine.h" +#include "Includes.h" // Methods #include "GlobalMethods.h" #include "ObjectMethods.h" @@ -30,7 +32,7 @@ void RegisterGlobals(lua_State* L) { // Hooks - lua_register(L, "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent); // RegisterPacketEvent(opcodeID, function) + lua_register(L, "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent); // RegisterPacketEvent(opcodeID, event, function) lua_register(L, "RegisterServerEvent", &LuaGlobalFunctions::RegisterServerEvent); // RegisterServerEvent(event, function) lua_register(L, "RegisterPlayerEvent", &LuaGlobalFunctions::RegisterPlayerEvent); // RegisterPlayerEvent(event, function) lua_register(L, "RegisterGuildEvent", &LuaGlobalFunctions::RegisterGuildEvent); // RegisterGuildEvent(event, function) @@ -75,7 +77,7 @@ void RegisterGlobals(lua_State* L) lua_register(L, "GetMapById", &LuaGlobalFunctions::GetMapById); // GetMapById(mapId, instance) - Returns map object of id specified. UNDOCUMENTED // Other - // lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); // ReloadEluna() - Reload's Eluna engine. Returns true if reload succesful. + lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); // ReloadEluna() - Reload's Eluna engine. lua_register(L, "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage); // SendWorldMessage(msg) - Sends a broadcast message to everyone lua_register(L, "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery); // WorldDBQuery(sql) - Executes given SQL query to world database instantly and returns a QueryResult object lua_register(L, "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute); // WorldDBExecute(sql) - Executes given SQL query to world database (not instant) @@ -1193,7 +1195,7 @@ void RegisterFunctions(lua_State* L) { RegisterGlobals(L); - // You should add sHookMgr->RemoveRef(this); to all destructors for objects that are NOT mem managed (gc) by lua. + // You should add Eluna::RemoveRef(this); to all destructors for objects that are NOT mem managed (gc) by lua. // Exceptions being Quest type static data structs that will never be destructed (during runtime), though they can have it as well. ElunaTemplate::Register(L, "Object"); diff --git a/MapMethods.h b/MapMethods.h index 2517a84..7cb8669 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -13,7 +13,7 @@ namespace LuaMap #ifndef CLASSIC int IsArena(lua_State* L, Map* map) { - sEluna->Push(L, map->IsBattleArena()); + Eluna::Push(L, map->IsBattleArena()); return 1; } #endif @@ -21,99 +21,99 @@ namespace LuaMap int IsBattleground(lua_State* L, Map* map) { #ifdef MANGOS - sEluna->Push(L, map->IsBattleGround()); + Eluna::Push(L, map->IsBattleGround()); #else - sEluna->Push(L, map->IsBattleground()); + Eluna::Push(L, map->IsBattleground()); #endif return 1; } int IsDungeon(lua_State* L, Map* map) { - sEluna->Push(L, map->IsDungeon()); + Eluna::Push(L, map->IsDungeon()); return 1; } int IsEmpty(lua_State* L, Map* map) { - sEluna->Push(L, map->isEmpty()); + Eluna::Push(L, map->isEmpty()); return 1; } #ifndef CLASSIC int IsHeroic(lua_State* L, Map* map) { - sEluna->Push(L, map->IsHeroic()); + Eluna::Push(L, map->IsHeroic()); return 1; } #endif int IsRaid(lua_State* L, Map* map) { - sEluna->Push(L, map->IsRaid()); + Eluna::Push(L, map->IsRaid()); return 1; } /* GETTERS */ int GetName(lua_State* L, Map* map) { - sEluna->Push(L, map->GetMapName()); + Eluna::Push(L, map->GetMapName()); return 1; } int GetHeight(lua_State* L, Map* map) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); #if (defined(TBC) || defined(CLASSIC)) float z = map->GetHeight(x, y, MAX_HEIGHT); #else - uint32 phasemask = sEluna->CHECKVAL(L, 4, 1); + uint32 phasemask = Eluna::CHECKVAL(L, 4, 1); float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT); #endif if (z != INVALID_HEIGHT) - sEluna->Push(L, z); + Eluna::Push(L, z); return 1; } int GetDifficulty(lua_State* L, Map* map) { #ifndef CLASSIC - sEluna->Push(L, map->GetDifficulty()); + Eluna::Push(L, map->GetDifficulty()); #else - sEluna->Push(L, (Difficulty)0); + Eluna::Push(L, (Difficulty)0); #endif return 1; } int GetInstanceId(lua_State* L, Map* map) { - sEluna->Push(L, map->GetInstanceId()); + Eluna::Push(L, map->GetInstanceId()); return 1; } int GetPlayerCount(lua_State* L, Map* map) { - sEluna->Push(L, map->GetPlayersCountExceptGMs()); + Eluna::Push(L, map->GetPlayersCountExceptGMs()); return 1; } int GetMapId(lua_State* L, Map* map) { - sEluna->Push(L, map->GetId()); + Eluna::Push(L, map->GetId()); return 1; } int GetAreaId(lua_State* L, Map* map) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - float z = sEluna->CHECKVAL(L, 4); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); #ifdef MANGOS - sEluna->Push(L, map->GetTerrain()->GetAreaId(x, y, z)); + Eluna::Push(L, map->GetTerrain()->GetAreaId(x, y, z)); #else - sEluna->Push(L, map->GetAreaId(x, y, z)); + Eluna::Push(L, map->GetAreaId(x, y, z)); #endif return 1; } diff --git a/ObjectMethods.h b/ObjectMethods.h index f5cc0e3..2f6f2ac 100644 --- a/ObjectMethods.h +++ b/ObjectMethods.h @@ -12,90 +12,90 @@ namespace LuaObject /* BOOLEAN */ int HasFlag(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint32 flag = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 3); - sEluna->Push(L, obj->HasFlag(index, flag)); + Eluna::Push(L, obj->HasFlag(index, flag)); return 1; } int IsInWorld(lua_State* L, Object* obj) { - sEluna->Push(L, obj->IsInWorld()); + Eluna::Push(L, obj->IsInWorld()); return 1; } /* GETTERS */ int GetInt32Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, obj->GetInt32Value(index)); + uint16 index = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, obj->GetInt32Value(index)); return 1; } int GetUInt32Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, obj->GetUInt32Value(index)); + uint16 index = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, obj->GetUInt32Value(index)); return 1; } int GetFloatValue(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, obj->GetFloatValue(index)); + uint16 index = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, obj->GetFloatValue(index)); return 1; } int GetByteValue(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint8 offset = sEluna->CHECKVAL(L, 3); - sEluna->Push(L, obj->GetByteValue(index, offset)); + uint16 index = Eluna::CHECKVAL(L, 2); + uint8 offset = Eluna::CHECKVAL(L, 3); + Eluna::Push(L, obj->GetByteValue(index, offset)); return 1; } int GetUInt16Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint8 offset = sEluna->CHECKVAL(L, 3); - sEluna->Push(L, obj->GetUInt16Value(index, offset)); + uint16 index = Eluna::CHECKVAL(L, 2); + uint8 offset = Eluna::CHECKVAL(L, 3); + Eluna::Push(L, obj->GetUInt16Value(index, offset)); return 1; } int GetScale(lua_State* L, Object* obj) { - sEluna->Push(L, obj->GetObjectScale()); + Eluna::Push(L, obj->GetObjectScale()); return 1; } int GetEntry(lua_State* L, Object* obj) { - sEluna->Push(L, obj->GetEntry()); + Eluna::Push(L, obj->GetEntry()); return 1; } int GetGUID(lua_State* L, Object* obj) { - sEluna->Push(L, obj->GET_GUID()); + Eluna::Push(L, obj->GET_GUID()); return 1; } int GetGUIDLow(lua_State* L, Object* obj) { - sEluna->Push(L, obj->GetGUIDLow()); + Eluna::Push(L, obj->GetGUIDLow()); return 1; } int GetTypeId(lua_State* L, Object* obj) { - sEluna->Push(L, obj->GetTypeId()); + Eluna::Push(L, obj->GetTypeId()); return 1; } int GetUInt64Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); + uint16 index = Eluna::CHECKVAL(L, 2); obj->GetUInt64Value(index); return 0; } @@ -103,8 +103,8 @@ namespace LuaObject /* SETTERS */ int SetFlag(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint32 flag = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 3); obj->SetFlag(index, flag); return 0; @@ -112,24 +112,24 @@ namespace LuaObject int SetInt32Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - int32 value = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + int32 value = Eluna::CHECKVAL(L, 3); obj->SetInt32Value(index, value); return 0; } int SetUInt32Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint32 value = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint32 value = Eluna::CHECKVAL(L, 3); obj->SetUInt32Value(index, value); return 0; } int SetFloatValue(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - float value = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + float value = Eluna::CHECKVAL(L, 3); obj->SetFloatValue(index, value); return 0; @@ -137,34 +137,34 @@ namespace LuaObject int SetByteValue(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint8 offset = sEluna->CHECKVAL(L, 3); - uint8 value = sEluna->CHECKVAL(L, 4); + uint16 index = Eluna::CHECKVAL(L, 2); + uint8 offset = Eluna::CHECKVAL(L, 3); + uint8 value = Eluna::CHECKVAL(L, 4); obj->SetByteValue(index, offset, value); return 0; } int SetUInt16Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint8 offset = sEluna->CHECKVAL(L, 3); - uint16 value = sEluna->CHECKVAL(L, 4); + uint16 index = Eluna::CHECKVAL(L, 2); + uint8 offset = Eluna::CHECKVAL(L, 3); + uint16 value = Eluna::CHECKVAL(L, 4); obj->SetUInt16Value(index, offset, value); return 0; } int SetInt16Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint8 offset = sEluna->CHECKVAL(L, 3); - int16 value = sEluna->CHECKVAL(L, 4); + uint16 index = Eluna::CHECKVAL(L, 2); + uint8 offset = Eluna::CHECKVAL(L, 3); + int16 value = Eluna::CHECKVAL(L, 4); obj->SetInt16Value(index, offset, value); return 0; } int SetScale(lua_State* L, Object* obj) { - float size = sEluna->CHECKVAL(L, 2); + float size = Eluna::CHECKVAL(L, 2); obj->SetObjectScale(size); return 0; @@ -172,8 +172,8 @@ namespace LuaObject int SetUInt64Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint64 value = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint64 value = Eluna::CHECKVAL(L, 3); obj->SetUInt64Value(index, value); return 0; } @@ -181,8 +181,8 @@ namespace LuaObject /* OTHER */ int RemoveFlag(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint32 flag = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 3); obj->RemoveFlag(index, flag); return 0; @@ -190,39 +190,39 @@ namespace LuaObject int UpdateUInt32Value(lua_State* L, Object* obj) { - uint16 index = sEluna->CHECKVAL(L, 2); - uint32 value = sEluna->CHECKVAL(L, 3); + uint16 index = Eluna::CHECKVAL(L, 2); + uint32 value = Eluna::CHECKVAL(L, 3); obj->UpdateUInt32Value(index, value); return 0; } int ToCorpse(lua_State* L, Object* obj) { - sEluna->Push(L, obj->ToCorpse()); + Eluna::Push(L, obj->ToCorpse()); return 1; } int ToGameObject(lua_State* L, Object* obj) { - sEluna->Push(L, obj->ToGameObject()); + Eluna::Push(L, obj->ToGameObject()); return 1; } int ToUnit(lua_State* L, Object* obj) { - sEluna->Push(L, obj->ToUnit()); + Eluna::Push(L, obj->ToUnit()); return 1; } int ToCreature(lua_State* L, Object* obj) { - sEluna->Push(L, obj->ToCreature()); + Eluna::Push(L, obj->ToCreature()); return 1; } int ToPlayer(lua_State* L, Object* obj) { - sEluna->Push(L, obj->ToPlayer()); + Eluna::Push(L, obj->ToPlayer()); return 1; } }; diff --git a/PlayerMethods.h b/PlayerMethods.h index 2a41dfc..27e5764 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -13,27 +13,27 @@ namespace LuaPlayer #if (!defined(TBC) && !defined(CLASSIC)) int CanTitanGrip(lua_State* L, Player* player) { - sEluna->Push(L, player->CanTitanGrip()); + Eluna::Push(L, player->CanTitanGrip()); return 1; } int HasTalent(lua_State* L, Player* player) { - uint32 talentId = sEluna->CHECKVAL(L, 2); - uint8 spec = sEluna->CHECKVAL(L, 3); + uint32 talentId = Eluna::CHECKVAL(L, 2); + uint8 spec = Eluna::CHECKVAL(L, 3); if (spec < MAX_TALENT_SPECS) return 1; - sEluna->Push(L, player->HasTalent(talentId, spec)); + Eluna::Push(L, player->HasTalent(talentId, spec)); return 1; } int HasAchieved(lua_State* L, Player* player) { - uint32 achievementId = sEluna->CHECKVAL(L, 2); + uint32 achievementId = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, player->GetAchievementMgr().HasAchievement(achievementId)); + Eluna::Push(L, player->GetAchievementMgr().HasAchievement(achievementId)); #else - sEluna->Push(L, player->HasAchieved(achievementId)); + Eluna::Push(L, player->HasAchieved(achievementId)); #endif return 1; } @@ -41,121 +41,121 @@ namespace LuaPlayer int HasQuest(lua_State* L, Player* player) { - uint32 quest = sEluna->CHECKVAL(L, 2); + uint32 quest = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->IsActiveQuest(quest)); + Eluna::Push(L, player->IsActiveQuest(quest)); return 1; } int HasSkill(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasSkill(skill)); + Eluna::Push(L, player->HasSkill(skill)); return 1; } int HasSpell(lua_State* L, Player* player) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasSpell(id)); + Eluna::Push(L, player->HasSpell(id)); return 1; } int HasAtLoginFlag(lua_State* L, Player* player) { - uint32 flag = sEluna->CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasAtLoginFlag((AtLoginFlags)flag)); + Eluna::Push(L, player->HasAtLoginFlag((AtLoginFlags)flag)); return 1; } int HasQuestForGO(lua_State* L, Player* player) { - int32 entry = sEluna->CHECKVAL(L, 2); + int32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasQuestForGO(entry)); + Eluna::Push(L, player->HasQuestForGO(entry)); return 1; } #ifndef CLASSIC int HasTitle(lua_State* L, Player* player) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); if (titleInfo) - sEluna->Push(L, player->HasTitle(titleInfo)); + Eluna::Push(L, player->HasTitle(titleInfo)); return 1; } #endif int HasItem(lua_State* L, Player* player) { - uint32 itemId = sEluna->CHECKVAL(L, 2); - uint32 count = sEluna->CHECKVAL(L, 3, 1); - bool check_bank = sEluna->CHECKVAL(L, 4, false); - sEluna->Push(L, player->HasItemCount(itemId, count, check_bank)); + uint32 itemId = Eluna::CHECKVAL(L, 2); + uint32 count = Eluna::CHECKVAL(L, 3, 1); + bool check_bank = Eluna::CHECKVAL(L, 4, false); + Eluna::Push(L, player->HasItemCount(itemId, count, check_bank)); return 1; } int HasQuestForItem(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasQuestForItem(entry)); + Eluna::Push(L, player->HasQuestForItem(entry)); return 1; } int CanUseItem(lua_State* L, Player* player) { - Item* item = sEluna->CHECKOBJ(L, 2, false); + Item* item = Eluna::CHECKOBJ(L, 2, false); if (item) - sEluna->Push(L, player->CanUseItem(item)); + Eluna::Push(L, player->CanUseItem(item)); else { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry); if (temp) - sEluna->Push(L, player->CanUseItem(temp)); + Eluna::Push(L, player->CanUseItem(temp)); else - sEluna->Push(L, EQUIP_ERR_ITEM_NOT_FOUND); + Eluna::Push(L, EQUIP_ERR_ITEM_NOT_FOUND); } return 1; } int HasSpellCooldown(lua_State* L, Player* player) { - uint32 spellId = sEluna->CHECKVAL(L, 2); + uint32 spellId = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->HasSpellCooldown(spellId)); + Eluna::Push(L, player->HasSpellCooldown(spellId)); return 1; } int CanShareQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->CanShareQuest(entry)); + Eluna::Push(L, player->CanShareQuest(entry)); return 1; } int CanSpeak(lua_State* L, Player* player) { - sEluna->Push(L, player->CanSpeak()); + Eluna::Push(L, player->CanSpeak()); return 1; } int CanUninviteFromGroup(lua_State* L, Player* player) { - sEluna->Push(L, player->CanUninviteFromGroup() == ERR_PARTY_RESULT_OK); + Eluna::Push(L, player->CanUninviteFromGroup() == ERR_PARTY_RESULT_OK); return 1; } #ifndef CLASSIC int CanFly(lua_State* L, Player* player) { - sEluna->Push(L, player->CanFly()); + Eluna::Push(L, player->CanFly()); return 1; } #endif @@ -163,34 +163,34 @@ namespace LuaPlayer #ifdef CLASSIC int GetHonorStoredKills(lua_State* L, Player* player) { - bool honorable = sEluna->CHECKVAL(L, 2, true); + bool honorable = Eluna::CHECKVAL(L, 2, true); - sEluna->Push(L, player->GetHonorStoredKills(honorable)); + Eluna::Push(L, player->GetHonorStoredKills(honorable)); return 0; } int GetRankPoints(lua_State* L, Player* player) { - sEluna->Push(L, player->GetRankPoints()); + Eluna::Push(L, player->GetRankPoints()); return 1; } int GetHonorLastWeekStandingPos(lua_State* L, Player* player) { - sEluna->Push(L, player->GetHonorLastWeekStandingPos()); + Eluna::Push(L, player->GetHonorLastWeekStandingPos()); return 1; } #endif int IsInWater(lua_State* L, Player* player) { - sEluna->Push(L, player->IsInWater()); + Eluna::Push(L, player->IsInWater()); return 1; } int IsMoving(lua_State* L, Player* player) // enable for unit when mangos support it { - sEluna->Push(L, player->isMoving()); + Eluna::Push(L, player->isMoving()); return 1; } @@ -217,29 +217,29 @@ namespace LuaPlayer #ifndef CLASSIC int IsFlying(lua_State* L, Player* player) // enable for unit when mangos support it { - sEluna->Push(L, player->IsFlying()); + Eluna::Push(L, player->IsFlying()); return 1; } #endif int IsInGroup(lua_State* L, Player* player) { - sEluna->Push(L, (player->GetGroup() != NULL)); + Eluna::Push(L, (player->GetGroup() != NULL)); return 1; } int IsInGuild(lua_State* L, Player* player) { - sEluna->Push(L, (player->GetGuildId() != 0)); + Eluna::Push(L, (player->GetGuildId() != 0)); return 1; } int IsGM(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->isGameMaster()); + Eluna::Push(L, player->isGameMaster()); #else - sEluna->Push(L, player->IsGameMaster()); + Eluna::Push(L, player->IsGameMaster()); #endif return 1; } @@ -247,126 +247,126 @@ namespace LuaPlayer #ifndef CLASSIC int IsInArenaTeam(lua_State* L, Player* player) { - uint32 type = sEluna->CHECKVAL(L, 2); + uint32 type = Eluna::CHECKVAL(L, 2); if (type < MAX_ARENA_SLOT && player->GetArenaTeamId(type)) - sEluna->Push(L, true); + Eluna::Push(L, true); else - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } #endif int IsHorde(lua_State* L, Player* player) { - sEluna->Push(L, (player->GetTeam() == HORDE)); + Eluna::Push(L, (player->GetTeam() == HORDE)); return 1; } int IsAlliance(lua_State* L, Player* player) { - sEluna->Push(L, (player->GetTeam() == ALLIANCE)); + Eluna::Push(L, (player->GetTeam() == ALLIANCE)); return 1; } int IsDND(lua_State* L, Player* player) { - sEluna->Push(L, player->isDND()); + Eluna::Push(L, player->isDND()); return 1; } int IsAFK(lua_State* L, Player* player) { - sEluna->Push(L, player->isAFK()); + Eluna::Push(L, player->isAFK()); return 1; } int IsFalling(lua_State* L, Player* player) { - sEluna->Push(L, player->IsFalling()); + Eluna::Push(L, player->IsFalling()); return 1; } int IsActiveQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->IsActiveQuest(entry)); + Eluna::Push(L, player->IsActiveQuest(entry)); return 1; } int IsGroupVisibleFor(lua_State* L, Player* player) { - Player* target = sEluna->CHECKOBJ(L, 2); - sEluna->Push(L, player->IsGroupVisibleFor(target)); + Player* target = Eluna::CHECKOBJ(L, 2); + Eluna::Push(L, player->IsGroupVisibleFor(target)); return 1; } int IsInSameRaidWith(lua_State* L, Player* player) { - Player* target = sEluna->CHECKOBJ(L, 2); - sEluna->Push(L, player->IsInSameRaidWith(target)); + Player* target = Eluna::CHECKOBJ(L, 2); + Eluna::Push(L, player->IsInSameRaidWith(target)); return 1; } int IsInSameGroupWith(lua_State* L, Player* player) { - Player* target = sEluna->CHECKOBJ(L, 2); - sEluna->Push(L, player->IsInSameGroupWith(target)); + Player* target = Eluna::CHECKOBJ(L, 2); + Eluna::Push(L, player->IsInSameGroupWith(target)); return 1; } int IsHonorOrXPTarget(lua_State* L, Player* player) { - Unit* victim = sEluna->CHECKOBJ(L, 2); + Unit* victim = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, player->isHonorOrXPTarget(victim)); + Eluna::Push(L, player->isHonorOrXPTarget(victim)); return 1; } int IsVisibleForPlayer(lua_State* L, Player* player) { - Player* target = sEluna->CHECKOBJ(L, 2); + Player* target = Eluna::CHECKOBJ(L, 2); - sEluna->Push(L, player->IsVisibleGloballyFor(target)); + Eluna::Push(L, player->IsVisibleGloballyFor(target)); return 1; } int IsGMVisible(lua_State* L, Player* player) { - sEluna->Push(L, player->isGMVisible()); + Eluna::Push(L, player->isGMVisible()); return 1; } int IsTaxiCheater(lua_State* L, Player* player) { - sEluna->Push(L, player->isTaxiCheater()); + Eluna::Push(L, player->isTaxiCheater()); return 1; } int IsGMChat(lua_State* L, Player* player) { - sEluna->Push(L, player->isGMChat()); + Eluna::Push(L, player->isGMChat()); return 1; } int IsAcceptingWhispers(lua_State* L, Player* player) { - sEluna->Push(L, player->isAcceptWhispers()); + Eluna::Push(L, player->isAcceptWhispers()); return 1; } int IsRested(lua_State* L, Player* player) { - sEluna->Push(L, player->isRested()); + Eluna::Push(L, player->isRested()); return 1; } int InBattlegroundQueue(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->InBattleGroundQueue()); + Eluna::Push(L, player->InBattleGroundQueue()); #else - sEluna->Push(L, player->InBattlegroundQueue()); + Eluna::Push(L, player->InBattlegroundQueue()); #endif return 1; } @@ -374,7 +374,7 @@ namespace LuaPlayer #ifndef CLASSIC int InArena(lua_State* L, Player* player) { - sEluna->Push(L, player->InArena()); + Eluna::Push(L, player->InArena()); return 1; } #endif @@ -382,81 +382,81 @@ namespace LuaPlayer int InBattleground(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->InBattleGround()); + Eluna::Push(L, player->InBattleGround()); #else - sEluna->Push(L, player->InBattleground()); + Eluna::Push(L, player->InBattleground()); #endif return 1; } int CanBlock(lua_State* L, Player* player) { - sEluna->Push(L, player->CanBlock()); + Eluna::Push(L, player->CanBlock()); return 1; } int CanParry(lua_State* L, Player* player) { - sEluna->Push(L, player->CanParry()); + Eluna::Push(L, player->CanParry()); return 1; } /*int HasReceivedQuestReward(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->IsQuestRewarded(entry)); + Eluna::Push(L, player->IsQuestRewarded(entry)); return 1; }*/ /*int IsOutdoorPvPActive(lua_State* L, Player* player) { - sEluna->Push(L, player->IsOutdoorPvPActive()); + Eluna::Push(L, player->IsOutdoorPvPActive()); return 1; }*/ /*int IsImmuneToEnvironmentalDamage(lua_State* L, Player* player) { - sEluna->Push(L, player->IsImmuneToEnvironmentalDamage()); + Eluna::Push(L, player->IsImmuneToEnvironmentalDamage()); return 1; }*/ /*int InRandomLfgDungeon(lua_State* L, Player* player) { - sEluna->Push(L, player->inRandomLfgDungeon()); + Eluna::Push(L, player->inRandomLfgDungeon()); return 1; }*/ /*int IsUsingLfg(lua_State* L, Player* player) { - sEluna->Push(L, player->isUsingLfg()); + Eluna::Push(L, player->isUsingLfg()); return 1; }*/ /*int IsNeverVisible(lua_State* L, Player* player) { - sEluna->Push(L, player->IsNeverVisible()); + Eluna::Push(L, player->IsNeverVisible()); return 1; }*/ /*int CanFlyInZone(lua_State* L, Player* player) { - uint32 mapid = sEluna->CHECKVAL(L, 2); - uint32 zone = sEluna->CHECKVAL(L, 2); + uint32 mapid = Eluna::CHECKVAL(L, 2); + uint32 zone = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->IsKnowHowFlyIn(mapid, zone)); + Eluna::Push(L, player->IsKnowHowFlyIn(mapid, zone)); return 1; }*/ /*int HasPendingBind(lua_State* L, Player* player) { - sEluna->Push(L, player->PendingHasPendingBind()); + Eluna::Push(L, player->PendingHasPendingBind()); return 1; }*/ /*int IsARecruiter(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->IsARecruiter() || (player->GetSession()->GetRecruiterId() != 0)); + Eluna::Push(L, player->GetSession()->IsARecruiter() || (player->GetSession()->GetRecruiterId() != 0)); return 1; }*/ @@ -464,13 +464,13 @@ namespace LuaPlayer #if (!defined(TBC) && !defined(CLASSIC)) int GetSpecsCount(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSpecsCount()); + Eluna::Push(L, player->GetSpecsCount()); return 1; } int GetActiveSpec(lua_State* L, Player* player) { - sEluna->Push(L, player->GetActiveSpec()); + Eluna::Push(L, player->GetActiveSpec()); return 1; } #endif @@ -478,7 +478,7 @@ namespace LuaPlayer #ifdef WOTLK int GetPhaseMaskForSpawn(lua_State* L, Player* player) { - sEluna->Push(L, player->GetPhaseMaskForSpawn()); + Eluna::Push(L, player->GetPhaseMaskForSpawn()); return 1; } #endif @@ -487,98 +487,98 @@ namespace LuaPlayer #ifndef CLASSIC int GetArenaPoints(lua_State* L, Player* player) { - sEluna->Push(L, player->GetArenaPoints()); + Eluna::Push(L, player->GetArenaPoints()); return 1; } int GetHonorPoints(lua_State* L, Player* player) { - sEluna->Push(L, player->GetHonorPoints()); + Eluna::Push(L, player->GetHonorPoints()); return 1; } #endif int GetShieldBlockValue(lua_State* L, Player* player) { - sEluna->Push(L, player->GetShieldBlockValue()); + Eluna::Push(L, player->GetShieldBlockValue()); return 1; } #endif int GetSpellCooldownDelay(lua_State* L, Player* player) { - uint32 spellId = sEluna->CHECKVAL(L, 2); + uint32 spellId = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, uint32(player->GetSpellCooldownDelay(spellId))); + Eluna::Push(L, uint32(player->GetSpellCooldownDelay(spellId))); return 1; } int GetLatency(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetLatency()); + Eluna::Push(L, player->GetSession()->GetLatency()); return 1; } #ifndef MANGOS int GetChampioningFaction(lua_State* L, Player* player) { - sEluna->Push(L, player->GetChampioningFaction()); + Eluna::Push(L, player->GetChampioningFaction()); return 1; } #endif int GetOriginalSubGroup(lua_State* L, Player* player) { - sEluna->Push(L, player->GetOriginalSubGroup()); + Eluna::Push(L, player->GetOriginalSubGroup()); return 1; } int GetOriginalGroup(lua_State* L, Player* player) { - sEluna->Push(L, player->GetOriginalGroup()); + Eluna::Push(L, player->GetOriginalGroup()); return 1; } int GetNextRandomRaidMember(lua_State* L, Player* player) { - float radius = sEluna->CHECKVAL(L, 2); + float radius = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetNextRandomRaidMember(radius)); + Eluna::Push(L, player->GetNextRandomRaidMember(radius)); return 1; } int GetSubGroup(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSubGroup()); + Eluna::Push(L, player->GetSubGroup()); return 1; } int GetGroupInvite(lua_State* L, Player* player) { - sEluna->Push(L, player->GetGroupInvite()); + Eluna::Push(L, player->GetGroupInvite()); return 1; } int GetRestTime(lua_State* L, Player* player) { - sEluna->Push(L, player->GetRestTime()); + Eluna::Push(L, player->GetRestTime()); return 1; } int GetXPRestBonus(lua_State* L, Player* player) { - uint32 xp = sEluna->CHECKVAL(L, 2); + uint32 xp = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetXPRestBonus(xp)); + Eluna::Push(L, player->GetXPRestBonus(xp)); return 1; } int GetBattlegroundTypeId(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->GetBattleGroundTypeId()); + Eluna::Push(L, player->GetBattleGroundTypeId()); #else - sEluna->Push(L, player->GetBattlegroundTypeId()); + Eluna::Push(L, player->GetBattlegroundTypeId()); #endif return 1; } @@ -586,24 +586,24 @@ namespace LuaPlayer int GetBattlegroundId(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->GetBattleGroundId()); + Eluna::Push(L, player->GetBattleGroundId()); #else - sEluna->Push(L, player->GetBattlegroundId()); + Eluna::Push(L, player->GetBattlegroundId()); #endif return 1; } int GetReputationRank(lua_State* L, Player* player) { - uint32 faction = sEluna->CHECKVAL(L, 2); + uint32 faction = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetReputationRank(faction)); + Eluna::Push(L, player->GetReputationRank(faction)); return 1; } int GetDrunkValue(lua_State* L, Player* player) { - sEluna->Push(L, player->GetDrunkValue()); + Eluna::Push(L, player->GetDrunkValue()); return 1; } @@ -616,8 +616,8 @@ namespace LuaPlayer for (SpellCooldowns::const_iterator it = player->GetSpellCooldownMap().begin(); it != player->GetSpellCooldownMap().end(); ++it) { ++i; - sEluna->Push(L, it->first); - sEluna->Push(L, uint32(it->second.end)); + Eluna::Push(L, it->first); + Eluna::Push(L, uint32(it->second.end)); lua_settable(L, tbl); } @@ -627,94 +627,94 @@ namespace LuaPlayer int GetSkillTempBonusValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetSkillTempBonusValue(skill)); + Eluna::Push(L, player->GetSkillTempBonusValue(skill)); return 1; } int GetSkillPermBonusValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetSkillPermBonusValue(skill)); + Eluna::Push(L, player->GetSkillPermBonusValue(skill)); return 1; } int GetPureSkillValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetPureSkillValue(skill)); + Eluna::Push(L, player->GetPureSkillValue(skill)); return 1; } int GetBaseSkillValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetBaseSkillValue(skill)); + Eluna::Push(L, player->GetBaseSkillValue(skill)); return 1; } int GetSkillValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetSkillValue(skill)); + Eluna::Push(L, player->GetSkillValue(skill)); return 1; } int GetPureMaxSkillValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetPureMaxSkillValue(skill)); + Eluna::Push(L, player->GetPureMaxSkillValue(skill)); return 1; } int GetMaxSkillValue(lua_State* L, Player* player) { - uint32 skill = sEluna->CHECKVAL(L, 2); + uint32 skill = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetMaxSkillValue(skill)); + Eluna::Push(L, player->GetMaxSkillValue(skill)); return 1; } int GetManaBonusFromIntellect(lua_State* L, Player* player) { - sEluna->Push(L, player->GetManaBonusFromIntellect()); + Eluna::Push(L, player->GetManaBonusFromIntellect()); return 1; } int GetHealthBonusFromStamina(lua_State* L, Player* player) { - sEluna->Push(L, player->GetHealthBonusFromStamina()); + Eluna::Push(L, player->GetHealthBonusFromStamina()); return 1; } int GetDifficulty(lua_State* L, Player* player) { #ifdef TBC - sEluna->Push(L, player->GetDifficulty()); + Eluna::Push(L, player->GetDifficulty()); #elif defined(CLASSIC) - sEluna->Push(L, (Difficulty)0); + Eluna::Push(L, (Difficulty)0); #else - bool isRaid = sEluna->CHECKVAL(L, 2, true); - sEluna->Push(L, player->GetDifficulty(isRaid)); + bool isRaid = Eluna::CHECKVAL(L, 2, true); + Eluna::Push(L, player->GetDifficulty(isRaid)); #endif return 1; } int GetGuildRank(lua_State* L, Player* player) // TODO: Move to Guild Methods { - sEluna->Push(L, player->GetRank()); + Eluna::Push(L, player->GetRank()); return 1; } int GetFreeTalentPoints(lua_State* L, Player* player) { - sEluna->Push(L, player->GetFreeTalentPoints()); + Eluna::Push(L, player->GetFreeTalentPoints()); return 1; } @@ -722,111 +722,111 @@ namespace LuaPlayer { if (!player->GetGuildId()) return 1; - sEluna->Push(L, sGuildMgr->GetGuildNameById(player->GetGuildId())); + Eluna::Push(L, sGuildMgr->GetGuildNameById(player->GetGuildId())); return 1; } int GetReputation(lua_State* L, Player* player) { - uint32 faction = sEluna->CHECKVAL(L, 2); + uint32 faction = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetReputationMgr().GetReputation(faction)); + Eluna::Push(L, player->GetReputationMgr().GetReputation(faction)); return 1; } int GetComboTarget(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->GetMap()->GetUnit(player->GetComboTargetGuid())); + Eluna::Push(L, player->GetMap()->GetUnit(player->GetComboTargetGuid())); #else - sEluna->Push(L, Unit::GetUnit(*player, player->GetComboTarget())); + Eluna::Push(L, Unit::GetUnit(*player, player->GetComboTarget())); #endif return 1; } int GetComboPoints(lua_State* L, Player* player) { - sEluna->Push(L, player->GetComboPoints()); + Eluna::Push(L, player->GetComboPoints()); return 1; } int GetInGameTime(lua_State* L, Player* player) { - sEluna->Push(L, player->GetInGameTime()); + Eluna::Push(L, player->GetInGameTime()); return 1; } int GetQuestStatus(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetQuestStatus(entry)); + Eluna::Push(L, player->GetQuestStatus(entry)); return 1; } int GetQuestRewardStatus(lua_State* L, Player* player) { - uint32 questId = sEluna->CHECKVAL(L, 2); + uint32 questId = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetQuestRewardStatus(questId)); + Eluna::Push(L, player->GetQuestRewardStatus(questId)); return 1; } int GetReqKillOrCastCurrentCount(lua_State* L, Player* player) { - uint32 questId = sEluna->CHECKVAL(L, 2); - int32 entry = sEluna->CHECKVAL(L, 3); + uint32 questId = Eluna::CHECKVAL(L, 2); + int32 entry = Eluna::CHECKVAL(L, 3); - sEluna->Push(L, player->GetReqKillOrCastCurrentCount(questId, entry)); + Eluna::Push(L, player->GetReqKillOrCastCurrentCount(questId, entry)); return 1; } int GetQuestLevel(lua_State* L, Player* player) { - Quest* quest = sEluna->CHECKOBJ(L, 2); + Quest* quest = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS - sEluna->Push(L, player->GetQuestLevelForPlayer(quest)); + Eluna::Push(L, player->GetQuestLevelForPlayer(quest)); #else - sEluna->Push(L, player->GetQuestLevel(quest)); + Eluna::Push(L, player->GetQuestLevel(quest)); #endif return 1; } int GetItemByEntry(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, player->GetItemByEntry(entry)); + Eluna::Push(L, player->GetItemByEntry(entry)); return 1; } int GetEquippedItemBySlot(lua_State* L, Player* player) { - uint8 slot = sEluna->CHECKVAL(L, 2); + uint8 slot = Eluna::CHECKVAL(L, 2); if (slot >= EQUIPMENT_SLOT_END) return 1; Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); - sEluna->Push(L, item); + Eluna::Push(L, item); return 1; } int GetRestType(lua_State* L, Player* player) { - sEluna->Push(L, player->GetRestType()); + Eluna::Push(L, player->GetRestType()); return 1; } int GetRestBonus(lua_State* L, Player* player) { - sEluna->Push(L, player->GetRestBonus()); + Eluna::Push(L, player->GetRestBonus()); return 1; } int GiveLevel(lua_State* L, Player* player) { - uint8 level = sEluna->CHECKVAL(L, 2); + uint8 level = Eluna::CHECKVAL(L, 2); player->GiveLevel(level); return 0; @@ -834,7 +834,7 @@ namespace LuaPlayer int GetChatTag(lua_State* L, Player* player) { - sEluna->Push(L, player->GetChatTag()); + Eluna::Push(L, player->GetChatTag()); return 1; } @@ -847,101 +847,101 @@ namespace LuaPlayer slots 23-38 backpack slots 0-35 other bags */ - uint8 bag = sEluna->CHECKVAL(L, 2); - uint8 slot = sEluna->CHECKVAL(L, 3); + uint8 bag = Eluna::CHECKVAL(L, 2); + uint8 slot = Eluna::CHECKVAL(L, 3); - sEluna->Push(L, player->GetItemByPos(bag, slot)); + Eluna::Push(L, player->GetItemByPos(bag, slot)); return 1; } int GetGossipTextId(lua_State* L, Player* player) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); - sEluna->Push(L, player->GetGossipTextId(obj)); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); + Eluna::Push(L, player->GetGossipTextId(obj)); return 1; } int GetSelection(lua_State* L, Player* player) { #ifdef MANGOS - sEluna->Push(L, player->GetMap()->GetUnit(player->GetSelectionGuid())); + Eluna::Push(L, player->GetMap()->GetUnit(player->GetSelectionGuid())); #else - sEluna->Push(L, player->GetSelectedUnit()); + Eluna::Push(L, player->GetSelectedUnit()); #endif return 1; } int GetGMRank(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetSecurity()); + Eluna::Push(L, player->GetSession()->GetSecurity()); return 1; } int GetCoinage(lua_State* L, Player* player) { - sEluna->Push(L, player->GetMoney()); + Eluna::Push(L, player->GetMoney()); return 1; } int GetGuildId(lua_State* L, Player* player) { - sEluna->Push(L, player->GetGuildId()); + Eluna::Push(L, player->GetGuildId()); return 1; } int GetTeam(lua_State* L, Player* player) { - sEluna->Push(L, player->GetTeamId()); + Eluna::Push(L, player->GetTeamId()); return 1; } int GetItemCount(lua_State* L, Player* player) { - int id = sEluna->CHECKVAL(L, 2); - bool checkinBank = sEluna->CHECKVAL(L, 3, false); - sEluna->Push(L, player->GetItemCount(id, checkinBank)); + int id = Eluna::CHECKVAL(L, 2); + bool checkinBank = Eluna::CHECKVAL(L, 3, false); + Eluna::Push(L, player->GetItemCount(id, checkinBank)); return 1; } int GetLifetimeKills(lua_State* L, Player* player) { - sEluna->Push(L, player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)); + Eluna::Push(L, player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)); return 1; } int GetPlayerIP(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetRemoteAddress()); + Eluna::Push(L, player->GetSession()->GetRemoteAddress()); return 1; } int GetLevelPlayedTime(lua_State* L, Player* player) { - sEluna->Push(L, player->GetLevelPlayedTime()); + Eluna::Push(L, player->GetLevelPlayedTime()); return 1; } int GetTotalPlayedTime(lua_State* L, Player* player) { - sEluna->Push(L, player->GetTotalPlayedTime()); + Eluna::Push(L, player->GetTotalPlayedTime()); return 1; } int GetGuild(lua_State* L, Player* player) { - sEluna->Push(L, sGuildMgr->GetGuildById(player->GetGuildId())); + Eluna::Push(L, sGuildMgr->GetGuildById(player->GetGuildId())); return 1; } int GetGroup(lua_State* L, Player* player) { - sEluna->Push(L, player->GetGroup()); + Eluna::Push(L, player->GetGroup()); return 1; } int GetAccountId(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetAccountId()); + Eluna::Push(L, player->GetSession()->GetAccountId()); return 1; } @@ -949,56 +949,56 @@ namespace LuaPlayer { std::string accName; if (sAccountMgr->GetName(player->GetSession()->GetAccountId(), accName)) - sEluna->Push(L, accName); + Eluna::Push(L, accName); return 1; } int GetCorpse(lua_State* L, Player* player) { - sEluna->Push(L, player->GetCorpse()); + Eluna::Push(L, player->GetCorpse()); return 1; } int GetDbLocaleIndex(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetSessionDbLocaleIndex()); + Eluna::Push(L, player->GetSession()->GetSessionDbLocaleIndex()); return 1; } int GetDbcLocale(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetSessionDbcLocale()); + Eluna::Push(L, player->GetSession()->GetSessionDbcLocale()); return 1; } /*int GetRecruiterId(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSession()->GetRecruiterId()); + Eluna::Push(L, player->GetSession()->GetRecruiterId()); return 1; }*/ /*int GetSelectedPlayer(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSelectedPlayer()); + Eluna::Push(L, player->GetSelectedPlayer()); return 1; }*/ /*int GetSelectedUnit(lua_State* L, Player* player) { - sEluna->Push(L, player->GetSelectedUnit()); + Eluna::Push(L, player->GetSelectedUnit()); return 1; }*/ /*int GetNearbyGameObject(lua_State* L, Player* player) { - sEluna->Push(L, ChatHandler(player->GetSession()).GetNearbyGameObject()); + Eluna::Push(L, ChatHandler(player->GetSession()).GetNearbyGameObject()); return 1; }*/ /* SETTERS */ int SetPlayerLock(lua_State* L, Player* player) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); if (apply) { @@ -1015,7 +1015,7 @@ namespace LuaPlayer int SetAtLoginFlag(lua_State* L, Player* player) { - uint32 flag = sEluna->CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 2); player->SetAtLoginFlag((AtLoginFlags)flag); return 0; @@ -1023,7 +1023,7 @@ namespace LuaPlayer int SetSheath(lua_State* L, Player* player) { - uint32 sheathed = sEluna->CHECKVAL(L, 2); + uint32 sheathed = Eluna::CHECKVAL(L, 2); if (sheathed >= MAX_SHEATH_STATE) return 0; @@ -1033,7 +1033,7 @@ namespace LuaPlayer int SetRestTime(lua_State* L, Player* player) { - uint32 value = sEluna->CHECKVAL(L, 2); + uint32 value = Eluna::CHECKVAL(L, 2); player->SetRestTime(value); return 0; @@ -1041,7 +1041,7 @@ namespace LuaPlayer int SetDrunkValue(lua_State* L, Player* player) { - uint8 newDrunkValue = sEluna->CHECKVAL(L, 2); + uint8 newDrunkValue = Eluna::CHECKVAL(L, 2); player->SetDrunkValue(newDrunkValue); return 0; @@ -1049,7 +1049,7 @@ namespace LuaPlayer int SetFactionForRace(lua_State* L, Player* player) { - uint8 race = sEluna->CHECKVAL(L, 2); + uint8 race = Eluna::CHECKVAL(L, 2); player->setFactionForRace(race); return 0; @@ -1057,10 +1057,10 @@ namespace LuaPlayer int SetSkill(lua_State* L, Player* player) { - uint16 id = sEluna->CHECKVAL(L, 2); - uint16 step = sEluna->CHECKVAL(L, 3); - uint16 currVal = sEluna->CHECKVAL(L, 4); - uint16 maxVal = sEluna->CHECKVAL(L, 5); + uint16 id = Eluna::CHECKVAL(L, 2); + uint16 step = Eluna::CHECKVAL(L, 3); + uint16 currVal = Eluna::CHECKVAL(L, 4); + uint16 maxVal = Eluna::CHECKVAL(L, 5); player->SetSkill(id, step, currVal, maxVal); return 0; @@ -1068,7 +1068,7 @@ namespace LuaPlayer int SetGuildRank(lua_State* L, Player* player) // TODO: Move to Guild Methods { - uint8 rank = sEluna->CHECKVAL(L, 2); + uint8 rank = Eluna::CHECKVAL(L, 2); if (!player->GetGuildId()) return 0; @@ -1079,7 +1079,7 @@ namespace LuaPlayer int SetFreeTalentPoints(lua_State* L, Player* player) { - uint32 points = sEluna->CHECKVAL(L, 2); + uint32 points = Eluna::CHECKVAL(L, 2); player->SetFreeTalentPoints(points); #if (!defined(TBC) && !defined(CLASSIC)) @@ -1090,8 +1090,8 @@ namespace LuaPlayer int SetReputation(lua_State* L, Player* player) { - uint32 faction = sEluna->CHECKVAL(L, 2); - int32 value = sEluna->CHECKVAL(L, 3); + uint32 faction = Eluna::CHECKVAL(L, 2); + int32 value = Eluna::CHECKVAL(L, 3); FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); player->GetReputationMgr().SetReputation(factionEntry, value); @@ -1100,8 +1100,8 @@ namespace LuaPlayer int SetQuestStatus(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); - uint32 status = sEluna->CHECKVAL(L, 3); + uint32 entry = Eluna::CHECKVAL(L, 2); + uint32 status = Eluna::CHECKVAL(L, 3); if (status >= MAX_QUEST_STATUS) return 0; @@ -1111,7 +1111,7 @@ namespace LuaPlayer int SetRestType(lua_State* L, Player* player) { - int type = sEluna->CHECKVAL(L, 2); + int type = Eluna::CHECKVAL(L, 2); player->SetRestType((RestType)type); return 0; @@ -1119,7 +1119,7 @@ namespace LuaPlayer int SetRestBonus(lua_State* L, Player* player) { - float bonus = sEluna->CHECKVAL(L, 2); + float bonus = Eluna::CHECKVAL(L, 2); player->SetRestBonus(bonus); return 0; @@ -1127,7 +1127,7 @@ namespace LuaPlayer int SetAcceptWhispers(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetAcceptWhispers(on); return 0; @@ -1135,7 +1135,7 @@ namespace LuaPlayer int SetPvPDeath(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetPvPDeath(on); return 0; @@ -1143,7 +1143,7 @@ namespace LuaPlayer int SetGMVisible(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetGMVisible(on); return 0; @@ -1151,7 +1151,7 @@ namespace LuaPlayer int SetTaxiCheat(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetTaxiCheater(on); return 0; @@ -1159,7 +1159,7 @@ namespace LuaPlayer int SetGMChat(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetGMChat(on); return 0; @@ -1167,7 +1167,7 @@ namespace LuaPlayer int SetGameMaster(lua_State* L, Player* player) { - bool on = sEluna->CHECKVAL(L, 2, true); + bool on = Eluna::CHECKVAL(L, 2, true); player->SetGameMaster(on); return 0; @@ -1175,7 +1175,7 @@ namespace LuaPlayer int SetGender(lua_State* L, Player* player) { - uint32 _gender = sEluna->CHECKVAL(L, 2); + uint32 _gender = Eluna::CHECKVAL(L, 2); Gender gender; switch (_gender) @@ -1200,14 +1200,14 @@ namespace LuaPlayer #ifndef CLASSIC int SetArenaPoints(lua_State* L, Player* player) { - uint32 arenaP = sEluna->CHECKVAL(L, 2); + uint32 arenaP = Eluna::CHECKVAL(L, 2); player->SetArenaPoints(arenaP); return 0; } int SetHonorPoints(lua_State* L, Player* player) { - uint32 honorP = sEluna->CHECKVAL(L, 2); + uint32 honorP = Eluna::CHECKVAL(L, 2); player->SetHonorPoints(honorP); return 0; } @@ -1217,8 +1217,8 @@ namespace LuaPlayer #ifdef CLASSIC int SetHonorStoredKills(lua_State* L, Player* player) { - uint32 kills = sEluna->CHECKVAL(L, 2); - bool honorable = sEluna->CHECKVAL(L, 3, true); + uint32 kills = Eluna::CHECKVAL(L, 2); + bool honorable = Eluna::CHECKVAL(L, 3, true); player->SetHonorStoredKills(kills, honorable); return 0; @@ -1226,7 +1226,7 @@ namespace LuaPlayer int SetRankPoints(lua_State* L, Player* player) { - float rankPoints = sEluna->CHECKVAL(L, 2); + float rankPoints = Eluna::CHECKVAL(L, 2); player->SetRankPoints(rankPoints); return 0; @@ -1234,7 +1234,7 @@ namespace LuaPlayer int SetHonorLastWeekStandingPos(lua_State* L, Player* player) { - int32 standingPos = sEluna->CHECKVAL(L, 2); + int32 standingPos = Eluna::CHECKVAL(L, 2); player->SetHonorLastWeekStandingPos(standingPos); return 0; @@ -1243,25 +1243,25 @@ namespace LuaPlayer int SetLifetimeKills(lua_State* L, Player* player) { - uint32 val = sEluna->CHECKVAL(L, 2); + uint32 val = Eluna::CHECKVAL(L, 2); player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, val); return 0; } int SetCoinage(lua_State* L, Player* player) { - uint32 amt = sEluna->CHECKVAL(L, 2); + uint32 amt = Eluna::CHECKVAL(L, 2); player->SetMoney(amt); return 0; } int SetBindPoint(lua_State* L, Player* player) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - float z = sEluna->CHECKVAL(L, 4); - uint32 mapId = sEluna->CHECKVAL(L, 5); - uint32 areaId = sEluna->CHECKVAL(L, 6); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); + uint32 mapId = Eluna::CHECKVAL(L, 5); + uint32 areaId = Eluna::CHECKVAL(L, 6); WorldLocation loc(mapId, x, y, z); #ifdef MANGOS @@ -1275,7 +1275,7 @@ namespace LuaPlayer #ifndef CLASSIC int SetKnownTitle(lua_State* L, Player* player) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); if (t) player->SetTitle(t, false); @@ -1286,7 +1286,7 @@ namespace LuaPlayer #ifdef MANGOS int SetFFA(lua_State* L, Player* player) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); player->SetFFAPvP(apply); return 0; @@ -1295,7 +1295,7 @@ namespace LuaPlayer /*int SetMovement(lua_State* L, Player* player) { - int32 pType = sEluna->CHECKVAL(L, 2); + int32 pType = Eluna::CHECKVAL(L, 2); player->SetMovement((PlayerMovementType)pType); return 0; @@ -1330,7 +1330,7 @@ namespace LuaPlayer int SendShowMailBox(lua_State* L, Player* player) { - uint64 guid = sEluna->CHECKVAL(L, 2, player->GET_GUID()); + uint64 guid = Eluna::CHECKVAL(L, 2, player->GET_GUID()); #if (defined(CLASSIC) || defined(TBC)) WorldPacket data(CMSG_GET_MAIL_LIST, 8); @@ -1346,7 +1346,7 @@ namespace LuaPlayer #ifndef CLASSIC int ModifyArenaPoints(lua_State* L, Player* player) { - int32 amount = sEluna->CHECKVAL(L, 2); + int32 amount = Eluna::CHECKVAL(L, 2); player->ModifyArenaPoints(amount); return 0; @@ -1354,7 +1354,7 @@ namespace LuaPlayer int ModifyHonorPoints(lua_State* L, Player* player) { - int32 amount = sEluna->CHECKVAL(L, 2); + int32 amount = Eluna::CHECKVAL(L, 2); player->ModifyHonorPoints(amount); return 0; @@ -1370,13 +1370,13 @@ namespace LuaPlayer int SummonPlayer(lua_State* L, Player* player) { - Player* target = sEluna->CHECKOBJ(L, 2); - uint32 map = sEluna->CHECKVAL(L, 3); - float x = sEluna->CHECKVAL(L, 4); - float y = sEluna->CHECKVAL(L, 5); - float z = sEluna->CHECKVAL(L, 6); - float zoneId = sEluna->CHECKVAL(L, 7); - uint32 delay = sEluna->CHECKVAL(L, 8, 0); + Player* target = Eluna::CHECKOBJ(L, 2); + uint32 map = Eluna::CHECKVAL(L, 3); + float x = Eluna::CHECKVAL(L, 4); + float y = Eluna::CHECKVAL(L, 5); + float z = Eluna::CHECKVAL(L, 6); + float zoneId = Eluna::CHECKVAL(L, 7); + uint32 delay = Eluna::CHECKVAL(L, 8, 0); if (!MapManager::IsValidMapCoord(map, x, y, z)) return 0; @@ -1391,7 +1391,7 @@ namespace LuaPlayer int Mute(lua_State* L, Player* player) { - uint32 muteseconds = sEluna->CHECKVAL(L, 2); + uint32 muteseconds = Eluna::CHECKVAL(L, 2); /*const char* reason = luaL_checkstring(L, 2);*/ // Mangos does not have a reason field in database. uint64 muteTime = time(NULL) + muteseconds; @@ -1408,7 +1408,7 @@ namespace LuaPlayer int RewardQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); if (quest) @@ -1418,7 +1418,7 @@ namespace LuaPlayer int SendAuctionMenu(lua_State* L, Player* player) { - Unit* unit = sEluna->CHECKOBJ(L, 2); + Unit* unit = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit); @@ -1438,7 +1438,7 @@ namespace LuaPlayer int SendTaxiMenu(lua_State* L, Player* player) { - Creature* creature = sEluna->CHECKOBJ(L, 2); + Creature* creature = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendTaxiMenu(creature); return 0; @@ -1452,7 +1452,7 @@ namespace LuaPlayer int SendTabardVendorActivate(lua_State* L, Player* player) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendTabardVendorActivate(obj->GET_GUID()); return 0; @@ -1460,7 +1460,7 @@ namespace LuaPlayer int SendShowBank(lua_State* L, Player* player) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendShowBank(obj->GET_GUID()); return 0; @@ -1468,7 +1468,7 @@ namespace LuaPlayer int SendListInventory(lua_State* L, Player* player) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendListInventory(obj->GET_GUID()); return 0; @@ -1476,7 +1476,7 @@ namespace LuaPlayer int SendTrainerList(lua_State* L, Player* player) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendTrainerList(obj->GET_GUID()); return 0; @@ -1484,7 +1484,7 @@ namespace LuaPlayer int SendGuildInvite(lua_State* L, Player* player) { - Player* plr = sEluna->CHECKOBJ(L, 2); + Player* plr = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS player->GetSession()->SendGuildInvite(plr); @@ -1497,7 +1497,7 @@ namespace LuaPlayer int LogoutPlayer(lua_State* L, Player* player) { - bool save = sEluna->CHECKVAL(L, 2, true); + bool save = Eluna::CHECKVAL(L, 2, true); player->GetSession()->LogoutPlayer(save); return 0; @@ -1515,9 +1515,9 @@ namespace LuaPlayer int UnbindInstance(lua_State* L, Player* player) { - uint32 map = sEluna->CHECKVAL(L, 2); + uint32 map = Eluna::CHECKVAL(L, 2); #ifndef CLASSIC - uint32 difficulty = sEluna->CHECKVAL(L, 3); + uint32 difficulty = Eluna::CHECKVAL(L, 3); if (difficulty < MAX_DIFFICULTY) player->UnbindInstance(map, (Difficulty)difficulty); @@ -1529,7 +1529,7 @@ namespace LuaPlayer int LeaveBattleground(lua_State* L, Player* player) { - bool teleToEntryPoint = sEluna->CHECKVAL(L, 2, true); + bool teleToEntryPoint = Eluna::CHECKVAL(L, 2, true); player->LeaveBattleground(teleToEntryPoint); return 0; @@ -1537,36 +1537,36 @@ namespace LuaPlayer int DurabilityRepair(lua_State* L, Player* player) { - uint16 position = sEluna->CHECKVAL(L, 2); - bool cost = sEluna->CHECKVAL(L, 3, true); - float discountMod = sEluna->CHECKVAL(L, 4); - bool guildBank = sEluna->CHECKVAL(L, 5, false); + uint16 position = Eluna::CHECKVAL(L, 2); + bool cost = Eluna::CHECKVAL(L, 3, true); + float discountMod = Eluna::CHECKVAL(L, 4); + bool guildBank = Eluna::CHECKVAL(L, 5, false); #ifdef CLASSIC - sEluna->Push(L, player->DurabilityRepair(position, cost, discountMod)); + Eluna::Push(L, player->DurabilityRepair(position, cost, discountMod)); #else - sEluna->Push(L, player->DurabilityRepair(position, cost, discountMod, guildBank)); + Eluna::Push(L, player->DurabilityRepair(position, cost, discountMod, guildBank)); #endif return 1; } int DurabilityRepairAll(lua_State* L, Player* player) { - bool cost = sEluna->CHECKVAL(L, 2, true); - float discountMod = sEluna->CHECKVAL(L, 3); - bool guildBank = sEluna->CHECKVAL(L, 4, false); + bool cost = Eluna::CHECKVAL(L, 2, true); + float discountMod = Eluna::CHECKVAL(L, 3); + bool guildBank = Eluna::CHECKVAL(L, 4, false); #ifdef CLASSIC - sEluna->Push(L, player->DurabilityRepairAll(cost, discountMod)); + Eluna::Push(L, player->DurabilityRepairAll(cost, discountMod)); #else - sEluna->Push(L, player->DurabilityRepairAll(cost, discountMod, guildBank)); + Eluna::Push(L, player->DurabilityRepairAll(cost, discountMod, guildBank)); #endif return 1; } int DurabilityPointLossForEquipSlot(lua_State* L, Player* player) { - int32 slot = sEluna->CHECKVAL(L, 2); + int32 slot = Eluna::CHECKVAL(L, 2); if (slot >= EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END) player->DurabilityPointLossForEquipSlot((EquipmentSlots)slot); @@ -1575,8 +1575,8 @@ namespace LuaPlayer int DurabilityPointsLossAll(lua_State* L, Player* player) { - int32 points = sEluna->CHECKVAL(L, 2); - bool inventory = sEluna->CHECKVAL(L, 3, true); + int32 points = Eluna::CHECKVAL(L, 2); + bool inventory = Eluna::CHECKVAL(L, 3, true); player->DurabilityPointsLossAll(points, inventory); return 0; @@ -1584,8 +1584,8 @@ namespace LuaPlayer int DurabilityPointsLoss(lua_State* L, Player* player) { - Item* item = sEluna->CHECKOBJ(L, 2); - int32 points = sEluna->CHECKVAL(L, 3); + Item* item = Eluna::CHECKOBJ(L, 2); + int32 points = Eluna::CHECKVAL(L, 3); player->DurabilityPointsLoss(item, points); return 0; @@ -1593,8 +1593,8 @@ namespace LuaPlayer int DurabilityLoss(lua_State* L, Player* player) { - Item* item = sEluna->CHECKOBJ(L, 2); - double percent = sEluna->CHECKVAL(L, 3); + Item* item = Eluna::CHECKOBJ(L, 2); + double percent = Eluna::CHECKVAL(L, 3); player->DurabilityLoss(item, percent); return 0; @@ -1602,8 +1602,8 @@ namespace LuaPlayer int DurabilityLossAll(lua_State* L, Player* player) { - double percent = sEluna->CHECKVAL(L, 2); - bool inventory = sEluna->CHECKVAL(L, 3, true); + double percent = Eluna::CHECKVAL(L, 2); + bool inventory = Eluna::CHECKVAL(L, 3, true); player->DurabilityLossAll(percent, inventory); return 0; @@ -1627,16 +1627,16 @@ namespace LuaPlayer int ResetTalentsCost(lua_State* L, Player* player) { #ifdef CATA - sEluna->Push(L, player->GetNextResetTalentsCost()); + Eluna::Push(L, player->GetNextResetTalentsCost()); #else - sEluna->Push(L, player->resetTalentsCost()); + Eluna::Push(L, player->resetTalentsCost()); #endif return 1; } int ResetTalents(lua_State* L, Player* player) { - bool no_cost = sEluna->CHECKVAL(L, 2, true); + bool no_cost = Eluna::CHECKVAL(L, 2, true); #ifdef CATA player->ResetTalents(no_cost); @@ -1651,9 +1651,9 @@ namespace LuaPlayer int RemoveSpell(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); - bool disabled = sEluna->CHECKVAL(L, 3, false); - bool learn_low_rank = sEluna->CHECKVAL(L, 4, true); + uint32 entry = Eluna::CHECKVAL(L, 2); + bool disabled = Eluna::CHECKVAL(L, 3, false); + bool learn_low_rank = Eluna::CHECKVAL(L, 4, true); player->removeSpell(entry, disabled, learn_low_rank); return 0; @@ -1667,8 +1667,8 @@ namespace LuaPlayer int AddComboPoints(lua_State* L, Player* player) { - Unit* target = sEluna->CHECKOBJ(L, 2); - int8 count = sEluna->CHECKVAL(L, 3); + Unit* target = Eluna::CHECKOBJ(L, 2); + int8 count = Eluna::CHECKVAL(L, 3); player->AddComboPoints(target, count); return 0; @@ -1676,8 +1676,8 @@ namespace LuaPlayer int TalkedToCreature(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); - Creature* creature = sEluna->CHECKOBJ(L, 3); + uint32 entry = Eluna::CHECKVAL(L, 2); + Creature* creature = Eluna::CHECKOBJ(L, 3); player->TalkedToCreature(entry, creature->GET_GUID()); return 0; @@ -1685,7 +1685,7 @@ namespace LuaPlayer int KilledMonsterCredit(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->KilledMonsterCredit(entry, player->GET_GUID()); return 0; @@ -1693,8 +1693,8 @@ namespace LuaPlayer int GroupEventHappens(lua_State* L, Player* player) { - uint32 questId = sEluna->CHECKVAL(L, 2); - WorldObject* obj = sEluna->CHECKOBJ(L, 3); + uint32 questId = Eluna::CHECKVAL(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 3); player->GroupEventHappens(questId, obj); return 0; @@ -1702,7 +1702,7 @@ namespace LuaPlayer int AreaExploredOrEventHappens(lua_State* L, Player* player) { - uint32 questId = sEluna->CHECKVAL(L, 2); + uint32 questId = Eluna::CHECKVAL(L, 2); player->AreaExploredOrEventHappens(questId); return 0; @@ -1710,7 +1710,7 @@ namespace LuaPlayer int FailQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->FailQuest(entry); return 0; @@ -1718,7 +1718,7 @@ namespace LuaPlayer int IncompleteQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->IncompleteQuest(entry); return 0; @@ -1726,7 +1726,7 @@ namespace LuaPlayer int CompleteQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->CompleteQuest(entry); return 0; @@ -1734,9 +1734,9 @@ namespace LuaPlayer int Whisper(lua_State* L, Player* player) { - std::string text = sEluna->CHECKVAL(L, 2); - uint32 lang = sEluna->CHECKVAL(L, 3); - uint64 guid = sEluna->CHECKVAL(L, 4); + std::string text = Eluna::CHECKVAL(L, 2); + uint32 lang = Eluna::CHECKVAL(L, 3); + uint64 guid = Eluna::CHECKVAL(L, 4); player->Whisper(text, lang, ObjectGuid(guid)); return 0; @@ -1744,7 +1744,7 @@ namespace LuaPlayer int TextEmote(lua_State* L, Player* player) { - std::string text = sEluna->CHECKVAL(L, 2); + std::string text = Eluna::CHECKVAL(L, 2); player->TextEmote(text); return 0; @@ -1752,8 +1752,8 @@ namespace LuaPlayer int Yell(lua_State* L, Player* player) { - std::string text = sEluna->CHECKVAL(L, 2); - uint32 lang = sEluna->CHECKVAL(L, 3); + std::string text = Eluna::CHECKVAL(L, 2); + uint32 lang = Eluna::CHECKVAL(L, 3); player->Yell(text, lang); return 0; @@ -1761,8 +1761,8 @@ namespace LuaPlayer int Say(lua_State* L, Player* player) { - std::string text = sEluna->CHECKVAL(L, 2); - uint32 lang = sEluna->CHECKVAL(L, 3); + std::string text = Eluna::CHECKVAL(L, 2); + uint32 lang = Eluna::CHECKVAL(L, 3); player->Say(text, lang); return 0; @@ -1770,8 +1770,8 @@ namespace LuaPlayer int GiveXP(lua_State* L, Player* player) { - uint32 xp = sEluna->CHECKVAL(L, 2); - Unit* victim = sEluna->CHECKOBJ(L, 3, false); + uint32 xp = Eluna::CHECKVAL(L, 2); + Unit* victim = Eluna::CHECKOBJ(L, 3, false); player->GiveXP(xp, victim); return 0; @@ -1792,15 +1792,15 @@ namespace LuaPlayer int EquipItem(lua_State* L, Player* player) { uint16 dest = 0; - Item* item = sEluna->CHECKOBJ(L, 2, false); - uint32 slot = sEluna->CHECKVAL(L, 3); + Item* item = Eluna::CHECKOBJ(L, 2, false); + uint32 slot = Eluna::CHECKVAL(L, 3); if (slot >= INVENTORY_SLOT_BAG_END) return 1; if (!item) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); item = Item::CreateItem(entry, 1, player); if (!item) return 1; @@ -1824,28 +1824,28 @@ namespace LuaPlayer player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true); } - sEluna->Push(L, player->EquipItem(dest, item, true)); + Eluna::Push(L, player->EquipItem(dest, item, true)); return 1; } int CanEquipItem(lua_State* L, Player* player) { - Item* item = sEluna->CHECKOBJ(L, 2, false); - uint32 slot = sEluna->CHECKVAL(L, 3); + Item* item = Eluna::CHECKOBJ(L, 2, false); + uint32 slot = Eluna::CHECKVAL(L, 3); if (slot >= EQUIPMENT_SLOT_END) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } if (!item) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); uint16 dest; InventoryResult msg = player->CanEquipNewItem(slot, dest, entry, false); if (msg != EQUIP_ERR_OK) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } } @@ -1855,18 +1855,18 @@ namespace LuaPlayer InventoryResult msg = player->CanEquipItem(slot, dest, item, false); if (msg != EQUIP_ERR_OK) { - sEluna->Push(L, false); + Eluna::Push(L, false); return 1; } } - sEluna->Push(L, true); + Eluna::Push(L, true); return 1; } #ifndef CLASSIC int UnsetKnownTitle(lua_State* L, Player* player) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); if (t) player->SetTitle(t, true); @@ -1882,7 +1882,7 @@ namespace LuaPlayer int AdvanceAllSkills(lua_State* L, Player* player) { - uint32 step = sEluna->CHECKVAL(L, 2); + uint32 step = Eluna::CHECKVAL(L, 2); if (!step) return 0; @@ -1909,8 +1909,8 @@ namespace LuaPlayer int AdvanceSkill(lua_State* L, Player* player) { - uint32 _skillId = sEluna->CHECKVAL(L, 2); - uint32 _step = sEluna->CHECKVAL(L, 3); + uint32 _skillId = Eluna::CHECKVAL(L, 2); + uint32 _step = Eluna::CHECKVAL(L, 3); if (_skillId && _step) { if (player->HasSkill(_skillId)) @@ -1921,11 +1921,11 @@ namespace LuaPlayer int Teleport(lua_State* L, Player* player) { - uint32 mapId = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - float o = sEluna->CHECKVAL(L, 6); + uint32 mapId = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + float o = Eluna::CHECKVAL(L, 6); #ifdef MANGOS if (player->IsTaxiFlying()) #else @@ -1935,13 +1935,13 @@ namespace LuaPlayer player->GetMotionMaster()->MovementExpired(); player->m_taxi.ClearTaxiDestinations(); } - sEluna->Push(L, player->TeleportTo(mapId, x, y, z, o)); + Eluna::Push(L, player->TeleportTo(mapId, x, y, z, o)); return 1; } int AddLifetimeKills(lua_State* L, Player* player) { - uint32 val = sEluna->CHECKVAL(L, 2); + uint32 val = Eluna::CHECKVAL(L, 2); uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS); player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills + val); return 0; @@ -1949,23 +1949,23 @@ namespace LuaPlayer int AddItem(lua_State* L, Player* player) { - uint32 itemId = sEluna->CHECKVAL(L, 2); - uint32 itemCount = sEluna->CHECKVAL(L, 3); + uint32 itemId = Eluna::CHECKVAL(L, 2); + uint32 itemCount = Eluna::CHECKVAL(L, 3); #ifdef MANGOS - sEluna->Push(L, player->StoreNewItemInInventorySlot(itemId, itemCount) ? true : false); + Eluna::Push(L, player->StoreNewItemInInventorySlot(itemId, itemCount) ? true : false); #else - sEluna->Push(L, player->AddItem(itemId, itemCount)); + Eluna::Push(L, player->AddItem(itemId, itemCount)); #endif return 1; } int RemoveItem(lua_State* L, Player* player) { - Item* item = sEluna->CHECKOBJ(L, 2, false); - uint32 itemCount = sEluna->CHECKVAL(L, 3); + Item* item = Eluna::CHECKOBJ(L, 2, false); + uint32 itemCount = Eluna::CHECKVAL(L, 3); if (!item) { - uint32 itemId = sEluna->CHECKVAL(L, 2); + uint32 itemId = Eluna::CHECKVAL(L, 2); player->DestroyItemCount(itemId, itemCount, true); } else @@ -1975,7 +1975,7 @@ namespace LuaPlayer int RemoveLifetimeKills(lua_State* L, Player* player) { - uint32 val = sEluna->CHECKVAL(L, 2); + uint32 val = Eluna::CHECKVAL(L, 2); uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS); if (val > currentKills) val = currentKills; @@ -1985,16 +1985,16 @@ namespace LuaPlayer int ResetSpellCooldown(lua_State* L, Player* player) { - uint32 spellId = sEluna->CHECKVAL(L, 2); - bool update = sEluna->CHECKVAL(L, 3, true); + uint32 spellId = Eluna::CHECKVAL(L, 2); + bool update = Eluna::CHECKVAL(L, 3, true); player->RemoveSpellCooldown(spellId, update); return 0; } int ResetTypeCooldowns(lua_State* L, Player* player) { - uint32 category = sEluna->CHECKVAL(L, 2); - bool update = sEluna->CHECKVAL(L, 3, true); + uint32 category = Eluna::CHECKVAL(L, 2); + bool update = Eluna::CHECKVAL(L, 3, true); player->RemoveSpellCategoryCooldown(category, update); return 0; } @@ -2007,8 +2007,8 @@ namespace LuaPlayer int SendClearCooldowns(lua_State* L, Player* player) { - uint32 spellId = sEluna->CHECKVAL(L, 2); - Unit* target = sEluna->CHECKOBJ(L, 3); + uint32 spellId = Eluna::CHECKVAL(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 3); player->SendClearCooldown(spellId, target); return 0; @@ -2016,7 +2016,7 @@ namespace LuaPlayer int SendBroadcastMessage(lua_State* L, Player* player) { - const char* message = sEluna->CHECKVAL(L, 2); + const char* message = Eluna::CHECKVAL(L, 2); if (std::string(message).length() > 0) ChatHandler(player->GetSession()).SendSysMessage(message); return 0; @@ -2024,7 +2024,7 @@ namespace LuaPlayer int SendAreaTriggerMessage(lua_State* L, Player* player) { - std::string msg = sEluna->CHECKVAL(L, 2); + std::string msg = Eluna::CHECKVAL(L, 2); if (msg.length() > 0) player->GetSession()->SendAreaTriggerMessage("%s", msg.c_str()); return 0; @@ -2032,7 +2032,7 @@ namespace LuaPlayer int SendNotification(lua_State* L, Player* player) { - std::string msg = sEluna->CHECKVAL(L, 2); + std::string msg = Eluna::CHECKVAL(L, 2); if (msg.length() > 0) player->GetSession()->SendNotification("%s", msg.c_str()); return 0; @@ -2040,15 +2040,15 @@ namespace LuaPlayer int SendPacketToPlayer(lua_State* L, Player* player) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendPacket(data); return 0; } int SendPacket(lua_State* L, Player* player) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); - bool selfOnly = sEluna->CHECKVAL(L, 3, true); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); + bool selfOnly = Eluna::CHECKVAL(L, 3, true); if (selfOnly) player->GetSession()->SendPacket(data); else @@ -2058,10 +2058,10 @@ namespace LuaPlayer int SendAddonMessage(lua_State* L, Player* player) { - std::string prefix = sEluna->CHECKVAL(L, 2); - std::string message = sEluna->CHECKVAL(L, 3); - uint8 channel = sEluna->CHECKVAL(L, 4); - Player* receiver = sEluna->CHECKOBJ(L, 5); + std::string prefix = Eluna::CHECKVAL(L, 2); + std::string message = Eluna::CHECKVAL(L, 3); + uint8 channel = Eluna::CHECKVAL(L, 4); + Player* receiver = Eluna::CHECKOBJ(L, 5); std::string fullmsg = prefix + "\t" + message; @@ -2082,7 +2082,7 @@ namespace LuaPlayer int SendVendorWindow(lua_State* L, Player* player) { - Unit* sendTo = sEluna->CHECKOBJ(L, 2); + Unit* sendTo = Eluna::CHECKOBJ(L, 2); player->GetSession()->SendListInventory(sendTo->GET_GUID()); return 0; } @@ -2095,7 +2095,7 @@ namespace LuaPlayer int ModifyMoney(lua_State* L, Player* player) { - int32 amt = sEluna->CHECKVAL(L, 2); + int32 amt = Eluna::CHECKVAL(L, 2); player->ModifyMoney(amt); return 1; @@ -2103,15 +2103,15 @@ namespace LuaPlayer int LearnSpell(lua_State* L, Player* player) { - uint32 id = sEluna->CHECKVAL(L, 2); + uint32 id = Eluna::CHECKVAL(L, 2); player->learnSpell(id, false); return 0; } int ResurrectPlayer(lua_State* L, Player* player) { - float percent = sEluna->CHECKVAL(L, 2, 100.0f); - bool sickness = sEluna->CHECKVAL(L, 3, false); + float percent = Eluna::CHECKVAL(L, 2, 100.0f); + bool sickness = Eluna::CHECKVAL(L, 3, false); player->ResurrectPlayer(percent, sickness); player->SpawnCorpseBones(); return 0; @@ -2119,13 +2119,13 @@ namespace LuaPlayer int GossipMenuAddItem(lua_State* L, Player* player) { - uint32 _icon = sEluna->CHECKVAL(L, 2); - const char* msg = sEluna->CHECKVAL(L, 3); - uint32 _sender = sEluna->CHECKVAL(L, 4); - uint32 _intid = sEluna->CHECKVAL(L, 5); - bool _code = sEluna->CHECKVAL(L, 6, false); - const char* _promptMsg = sEluna->CHECKVAL(L, 7, ""); - uint32 _money = sEluna->CHECKVAL(L, 8, 0); + uint32 _icon = Eluna::CHECKVAL(L, 2); + const char* msg = Eluna::CHECKVAL(L, 3); + uint32 _sender = Eluna::CHECKVAL(L, 4); + uint32 _intid = Eluna::CHECKVAL(L, 5); + bool _code = Eluna::CHECKVAL(L, 6, false); + const char* _promptMsg = Eluna::CHECKVAL(L, 7, ""); + uint32 _money = Eluna::CHECKVAL(L, 8, 0); #ifdef MANGOS #ifndef CLASSIC player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _money, _code); @@ -2150,11 +2150,11 @@ namespace LuaPlayer int GossipSendMenu(lua_State* L, Player* player) { - uint32 _npcText = sEluna->CHECKVAL(L, 2); - WorldObject* sender = sEluna->CHECKOBJ(L, 3); + uint32 _npcText = Eluna::CHECKVAL(L, 2); + WorldObject* sender = Eluna::CHECKOBJ(L, 3); if (sender->GetTypeId() == TYPEID_PLAYER) { - uint32 menu_id = sEluna->CHECKVAL(L, 4); + uint32 menu_id = Eluna::CHECKVAL(L, 4); player->PlayerTalkClass->GetGossipMenu().SetMenuId(menu_id); } player->PlayerTalkClass->SendGossipMenu(_npcText, sender->GET_GUID()); @@ -2169,7 +2169,7 @@ namespace LuaPlayer int PlaySoundToPlayer(lua_State* L, Player* player) { - uint32 soundId = sEluna->CHECKVAL(L, 2); + uint32 soundId = Eluna::CHECKVAL(L, 2); SoundEntriesEntry const* soundEntry = sSoundEntriesStore.LookupEntry(soundId); if (!soundEntry) return 0; @@ -2180,20 +2180,32 @@ namespace LuaPlayer int StartTaxi(lua_State* L, Player* player) { - uint32 pathId = sEluna->CHECKVAL(L, 2); + uint32 pathId = Eluna::CHECKVAL(L, 2); - LuaTaxiMgr::StartTaxi(player, pathId); + if (pathId >= sTaxiPathNodesByPath.size()) + return 0; + + TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathId]; + if (path.size() < 2) + return 0; + + std::vector nodes; + nodes.resize(2); + nodes[0] = path[0].index; + nodes[1] = path[path.size() - 1].index; + + player->ActivateTaxiPathTo(nodes); return 0; } int GossipSendPOI(lua_State* L, Player* player) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - uint32 icon = sEluna->CHECKVAL(L, 4); - uint32 flags = sEluna->CHECKVAL(L, 5); - uint32 data = sEluna->CHECKVAL(L, 6); - std::string iconText = sEluna->CHECKVAL(L, 6); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + uint32 icon = Eluna::CHECKVAL(L, 4); + uint32 flags = Eluna::CHECKVAL(L, 5); + uint32 data = Eluna::CHECKVAL(L, 6); + std::string iconText = Eluna::CHECKVAL(L, 6); WorldPacket packet(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10); packet << flags; @@ -2208,7 +2220,7 @@ namespace LuaPlayer int GossipAddQuests(lua_State* L, Player* player) { - WorldObject* source = sEluna->CHECKOBJ(L, 2); + WorldObject* source = Eluna::CHECKOBJ(L, 2); if (source->GetTypeId() == TYPEID_UNIT) { @@ -2225,8 +2237,8 @@ namespace LuaPlayer int SendQuestTemplate(lua_State* L, Player* player) { - uint32 questId = sEluna->CHECKVAL(L, 2); - bool activeAccept = sEluna->CHECKVAL(L, 3, true); + uint32 questId = Eluna::CHECKVAL(L, 2); + bool activeAccept = Eluna::CHECKVAL(L, 3, true); Quest const* quest = sObjectMgr->GetQuestTemplate(questId); if (!quest) @@ -2244,7 +2256,7 @@ namespace LuaPlayer int RemovedInsignia(lua_State* L, Player* player) { - Player* looter = sEluna->CHECKOBJ(L, 2); + Player* looter = Eluna::CHECKOBJ(L, 2); player->RemovedInsignia(looter); return 0; } @@ -2257,19 +2269,19 @@ namespace LuaPlayer /*int AddTalent(lua_State* L, Player* player) { - uint32 spellId = sEluna->CHECKVAL(L, 2); - uint8 spec = sEluna->CHECKVAL(L, 3); - bool learning = sEluna->CHECKVAL(L, 4, true); + uint32 spellId = Eluna::CHECKVAL(L, 2); + uint8 spec = Eluna::CHECKVAL(L, 3); + bool learning = Eluna::CHECKVAL(L, 4, true); if (spec >= MAX_TALENT_SPECS) - sEluna->Push(L, false); + Eluna::Push(L, false); else - sEluna->Push(L, player->AddTalent(spellId, spec, learning)); + Eluna::Push(L, player->AddTalent(spellId, spec, learning)); return 1; }*/ /*int GainSpellComboPoints(lua_State* L, Player* player) { - int8 count = sEluna->CHECKVAL(L, 2); + int8 count = Eluna::CHECKVAL(L, 2); player->GainSpellComboPoints(count); return 0; @@ -2277,8 +2289,8 @@ namespace LuaPlayer /*int KillGOCredit(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); - uint64 guid = sEluna->CHECKVAL(L, 3); + uint32 entry = Eluna::CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 3); player->KillCreditGO(entry, guid); return 0; }*/ @@ -2291,7 +2303,7 @@ namespace LuaPlayer /*int RemoveRewardedQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->RemoveRewardedQuest(entry); return 0; @@ -2299,7 +2311,7 @@ namespace LuaPlayer /*int RemoveActiveQuest(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 entry = Eluna::CHECKVAL(L, 2); player->RemoveActiveQuest(entry); return 0; @@ -2307,13 +2319,13 @@ namespace LuaPlayer /*int SummonPet(lua_State* L, Player* player) { - uint32 entry = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - float o = sEluna->CHECKVAL(L, 6); - uint32 petType = sEluna->CHECKVAL(L, 7); - uint32 despwtime = sEluna->CHECKVAL(L, 8); + uint32 entry = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + float o = Eluna::CHECKVAL(L, 6); + uint32 petType = Eluna::CHECKVAL(L, 7); + uint32 despwtime = Eluna::CHECKVAL(L, 8); if (petType >= MAX_PET_TYPE) return 0; @@ -2324,8 +2336,8 @@ namespace LuaPlayer /*int RemovePet(lua_State* L, Player* player) { - int mode = sEluna->CHECKVAL(L, 2, PET_SAVE_AS_DELETED); - bool returnreagent = sEluna->CHECKVAL(L, 2, false); + int mode = Eluna::CHECKVAL(L, 2, PET_SAVE_AS_DELETED); + bool returnreagent = Eluna::CHECKVAL(L, 2, false); if (!player->GetPet()) return 0; diff --git a/QueryMethods.h b/QueryMethods.h index c93ed9f..3625815 100644 --- a/QueryMethods.h +++ b/QueryMethods.h @@ -17,13 +17,13 @@ namespace LuaQuery /* BOOLEAN */ int IsNull(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); #ifdef MANGOS if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].IsNULL()); + Eluna::Push(L, RESULT->Fetch()[col].IsNULL()); #else if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].IsNull()); + Eluna::Push(L, RESULT->Fetch()[col].IsNull()); #endif return 1; } @@ -31,119 +31,119 @@ namespace LuaQuery /* GETTERS */ int GetColumnCount(lua_State* L, QueryResult* result) { - sEluna->Push(L, RESULT->GetFieldCount()); + Eluna::Push(L, RESULT->GetFieldCount()); return 1; } int GetRowCount(lua_State* L, QueryResult* result) { if (RESULT->GetRowCount() > (uint32)-1) - sEluna->Push(L, (uint32)-1); + Eluna::Push(L, (uint32)-1); else - sEluna->Push(L, RESULT->GetRowCount()); + Eluna::Push(L, RESULT->GetRowCount()); return 1; } int GetBool(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetBool()); + Eluna::Push(L, RESULT->Fetch()[col].GetBool()); return 1; } int GetUInt8(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetUInt8()); + Eluna::Push(L, RESULT->Fetch()[col].GetUInt8()); return 1; } int GetUInt16(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetUInt16()); + Eluna::Push(L, RESULT->Fetch()[col].GetUInt16()); return 1; } int GetUInt32(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetUInt32()); + Eluna::Push(L, RESULT->Fetch()[col].GetUInt32()); return 1; } int GetUInt64(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetUInt64()); + Eluna::Push(L, RESULT->Fetch()[col].GetUInt64()); return 1; } int GetInt8(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetInt8()); + Eluna::Push(L, RESULT->Fetch()[col].GetInt8()); return 1; } int GetInt16(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetInt16()); + Eluna::Push(L, RESULT->Fetch()[col].GetInt16()); return 1; } int GetInt32(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetInt32()); + Eluna::Push(L, RESULT->Fetch()[col].GetInt32()); return 1; } int GetInt64(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetInt64()); + Eluna::Push(L, RESULT->Fetch()[col].GetInt64()); return 1; } int GetFloat(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetFloat()); + Eluna::Push(L, RESULT->Fetch()[col].GetFloat()); return 1; } int GetDouble(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetDouble()); + Eluna::Push(L, RESULT->Fetch()[col].GetDouble()); return 1; } int GetString(lua_State* L, QueryResult* result) { - uint32 col = sEluna->CHECKVAL(L, 2); + uint32 col = Eluna::CHECKVAL(L, 2); if (col < RESULT->GetFieldCount()) - sEluna->Push(L, RESULT->Fetch()[col].GetString()); + Eluna::Push(L, RESULT->Fetch()[col].GetString()); return 1; } /* OTHER */ int NextRow(lua_State* L, QueryResult* result) { - sEluna->Push(L, RESULT->NextRow()); + Eluna::Push(L, RESULT->NextRow()); return 1; } }; diff --git a/QuestMethods.h b/QuestMethods.h index 94bdfad..f417d82 100644 --- a/QuestMethods.h +++ b/QuestMethods.h @@ -12,11 +12,11 @@ namespace LuaQuest /* BOOLEAN */ int HasFlag(lua_State* L, Quest* quest) { - uint32 flag = sEluna->CHECKVAL(L, 2); + uint32 flag = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, quest->HasQuestFlag((QuestFlags)flag)); + Eluna::Push(L, quest->HasQuestFlag((QuestFlags)flag)); #else - sEluna->Push(L, quest->HasFlag(flag)); + Eluna::Push(L, quest->HasFlag(flag)); #endif return 1; } @@ -24,73 +24,73 @@ namespace LuaQuest #ifndef CLASSIC int IsDaily(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->IsDaily()); + Eluna::Push(L, quest->IsDaily()); return 1; } #endif int IsRepeatable(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->IsRepeatable()); + Eluna::Push(L, quest->IsRepeatable()); return 1; } /* GETTERS */ int GetId(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetQuestId()); + Eluna::Push(L, quest->GetQuestId()); return 1; } int GetLevel(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetQuestLevel()); + Eluna::Push(L, quest->GetQuestLevel()); return 1; } int GetMinLevel(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetMinLevel()); + Eluna::Push(L, quest->GetMinLevel()); return 1; } int GetNextQuestId(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetNextQuestId()); + Eluna::Push(L, quest->GetNextQuestId()); return 1; } int GetPrevQuestId(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetPrevQuestId()); + Eluna::Push(L, quest->GetPrevQuestId()); return 1; } int GetNextQuestInChain(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetNextQuestInChain()); + Eluna::Push(L, quest->GetNextQuestInChain()); return 1; } int GetFlags(lua_State* L, Quest* quest) { #ifdef MANGOS - sEluna->Push(L, quest->GetQuestFlags()); + Eluna::Push(L, quest->GetQuestFlags()); #else - sEluna->Push(L, quest->GetFlags()); + Eluna::Push(L, quest->GetFlags()); #endif return 1; } int GetType(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetType()); + Eluna::Push(L, quest->GetType()); return 1; } /*int GetMaxLevel(lua_State* L, Quest* quest) { - sEluna->Push(L, quest->GetMaxLevel()); + Eluna::Push(L, quest->GetMaxLevel()); return 1; }*/ }; diff --git a/SpellMethods.h b/SpellMethods.h index d87a644..9bbab15 100644 --- a/SpellMethods.h +++ b/SpellMethods.h @@ -12,41 +12,41 @@ namespace LuaSpell /* BOOLEAN */ int IsAutoRepeat(lua_State* L, Spell* spell) { - sEluna->Push(L, spell->IsAutoRepeat()); + Eluna::Push(L, spell->IsAutoRepeat()); return 1; } /* GETTERS */ int GetCaster(lua_State* L, Spell* spell) { - sEluna->Push(L, spell->GetCaster()); + Eluna::Push(L, spell->GetCaster()); return 1; } int GetCastTime(lua_State* L, Spell* spell) { - sEluna->Push(L, spell->GetCastTime()); + Eluna::Push(L, spell->GetCastTime()); return 1; } int GetId(lua_State* L, Spell* spell) { - sEluna->Push(L, spell->m_spellInfo->Id); + Eluna::Push(L, spell->m_spellInfo->Id); return 1; } int GetPowerCost(lua_State* L, Spell* spell) { - sEluna->Push(L, spell->GetPowerCost()); + Eluna::Push(L, spell->GetPowerCost()); return 1; } int GetDuration(lua_State* L, Spell* spell) { #ifdef MANGOS - sEluna->Push(L, GetSpellDuration(spell->m_spellInfo)); + Eluna::Push(L, GetSpellDuration(spell->m_spellInfo)); #else - sEluna->Push(L, spell->GetSpellInfo()->GetDuration()); + Eluna::Push(L, spell->GetSpellInfo()->GetDuration()); #endif return 1; } @@ -64,9 +64,9 @@ namespace LuaSpell float x, y, z; spell->m_targets.GetDstPos()->GetPosition(x, y, z); #endif - sEluna->Push(L, x); - sEluna->Push(L, y); - sEluna->Push(L, z); + Eluna::Push(L, x); + Eluna::Push(L, y); + Eluna::Push(L, z); return 3; } @@ -74,24 +74,24 @@ namespace LuaSpell { #ifdef MANGOS if (GameObject* target = spell->m_targets.getGOTarget()) - sEluna->Push(sEluna->L, target); + Eluna::Push(L, target); else if (Item* target = spell->m_targets.getItemTarget()) - sEluna->Push(sEluna->L, target); + Eluna::Push(L, target); else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid())) - sEluna->Push(sEluna->L, target); + Eluna::Push(L, target); else if (Unit* target = spell->m_targets.getUnitTarget()) - sEluna->Push(sEluna->L, target); + Eluna::Push(L, target); #else if (GameObject* target = spell->m_targets.GetGOTarget()) - sEluna->Push(L, target); + Eluna::Push(L, target); else if (Item* target = spell->m_targets.GetItemTarget()) - sEluna->Push(L, target); + Eluna::Push(L, target); else if (Corpse* target = spell->m_targets.GetCorpseTarget()) - sEluna->Push(L, target); + Eluna::Push(L, target); else if (Unit* target = spell->m_targets.GetUnitTarget()) - sEluna->Push(L, target); + Eluna::Push(L, target); else if (WorldObject* target = spell->m_targets.GetObjectTarget()) - sEluna->Push(L, target); + Eluna::Push(L, target); #endif return 1; } @@ -99,7 +99,7 @@ namespace LuaSpell /* SETTERS */ int SetAutoRepeat(lua_State* L, Spell* spell) { - bool repeat = sEluna->CHECKVAL(L, 2); + bool repeat = Eluna::CHECKVAL(L, 2); spell->SetAutoRepeat(repeat); return 0; } @@ -107,7 +107,7 @@ namespace LuaSpell /* OTHER */ int Cast(lua_State* L, Spell* spell) { - bool skipCheck = sEluna->CHECKVAL(L, 2); + bool skipCheck = Eluna::CHECKVAL(L, 2); spell->cast(skipCheck); return 0; } diff --git a/UnitMethods.h b/UnitMethods.h index fcc35b5..fc1f49e 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -12,74 +12,74 @@ namespace LuaUnit /* BOOLEAN */ int Attack(lua_State* L, Unit* unit) { - Unit* who = sEluna->CHECKOBJ(L, 2); - bool meleeAttack = sEluna->CHECKVAL(L, 3, false); + Unit* who = Eluna::CHECKOBJ(L, 2); + bool meleeAttack = Eluna::CHECKVAL(L, 3, false); - sEluna->Push(L, unit->Attack(who, meleeAttack)); + Eluna::Push(L, unit->Attack(who, meleeAttack)); return 1; } int AttackStop(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->AttackStop()); + Eluna::Push(L, unit->AttackStop()); return 1; } int IsStandState(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsStandState()); + Eluna::Push(L, unit->IsStandState()); return 1; } int IsMounted(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsMounted()); + Eluna::Push(L, unit->IsMounted()); return 1; } int IsWithinLoS(lua_State* L, Unit* unit) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - float z = sEluna->CHECKVAL(L, 4); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); - sEluna->Push(L, unit->IsWithinLOS(x, y, z)); + Eluna::Push(L, unit->IsWithinLOS(x, y, z)); return 1; } int IsRooted(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isInRoots() || unit->IsRooted()); + Eluna::Push(L, unit->isInRoots() || unit->IsRooted()); #else - sEluna->Push(L, unit->isInRoots() || unit->HasUnitMovementFlag(MOVEMENTFLAG_ROOT)); + Eluna::Push(L, unit->isInRoots() || unit->HasUnitMovementFlag(MOVEMENTFLAG_ROOT)); #endif return 1; } int IsFullHealth(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsFullHealth()); + Eluna::Push(L, unit->IsFullHealth()); return 1; } int IsWithinDistInMap(lua_State* L, Unit* unit) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); - float radius = sEluna->CHECKVAL(L, 3); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); + float radius = Eluna::CHECKVAL(L, 3); - sEluna->Push(L, unit->IsWithinDistInMap(obj, radius)); + Eluna::Push(L, unit->IsWithinDistInMap(obj, radius)); return 1; } int IsInAccessiblePlaceFor(lua_State* L, Unit* unit) { - Creature* creature = sEluna->CHECKOBJ(L, 2); + Creature* creature = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS - sEluna->Push(L, unit->isInAccessablePlaceFor(creature)); + Eluna::Push(L, unit->isInAccessablePlaceFor(creature)); #else - sEluna->Push(L, unit->isInAccessiblePlaceFor(creature)); + Eluna::Push(L, unit->isInAccessiblePlaceFor(creature)); #endif return 1; } @@ -87,9 +87,9 @@ namespace LuaUnit int IsAuctioneer(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isAuctioner()); + Eluna::Push(L, unit->isAuctioner()); #else - sEluna->Push(L, unit->IsAuctioner()); + Eluna::Push(L, unit->IsAuctioner()); #endif return 1; } @@ -97,9 +97,9 @@ namespace LuaUnit int IsGuildMaster(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isGuildMaster()); + Eluna::Push(L, unit->isGuildMaster()); #else - sEluna->Push(L, unit->IsGuildMaster()); + Eluna::Push(L, unit->IsGuildMaster()); #endif return 1; } @@ -107,9 +107,9 @@ namespace LuaUnit int IsInnkeeper(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isInnkeeper()); + Eluna::Push(L, unit->isInnkeeper()); #else - sEluna->Push(L, unit->IsInnkeeper()); + Eluna::Push(L, unit->IsInnkeeper()); #endif return 1; } @@ -117,9 +117,9 @@ namespace LuaUnit int IsTrainer(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isTrainer()); + Eluna::Push(L, unit->isTrainer()); #else - sEluna->Push(L, unit->IsTrainer()); + Eluna::Push(L, unit->IsTrainer()); #endif return 1; } @@ -127,9 +127,9 @@ namespace LuaUnit int IsGossip(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isGossip()); + Eluna::Push(L, unit->isGossip()); #else - sEluna->Push(L, unit->IsGossip()); + Eluna::Push(L, unit->IsGossip()); #endif return 1; } @@ -137,9 +137,9 @@ namespace LuaUnit int IsTaxi(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isTaxi()); + Eluna::Push(L, unit->isTaxi()); #else - sEluna->Push(L, unit->IsTaxi()); + Eluna::Push(L, unit->IsTaxi()); #endif return 1; } @@ -147,9 +147,9 @@ namespace LuaUnit int IsSpiritHealer(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isSpiritHealer()); + Eluna::Push(L, unit->isSpiritHealer()); #else - sEluna->Push(L, unit->IsSpiritHealer()); + Eluna::Push(L, unit->IsSpiritHealer()); #endif return 1; } @@ -157,9 +157,9 @@ namespace LuaUnit int IsSpiritGuide(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isSpiritGuide()); + Eluna::Push(L, unit->isSpiritGuide()); #else - sEluna->Push(L, unit->IsSpiritGuide()); + Eluna::Push(L, unit->IsSpiritGuide()); #endif return 1; } @@ -167,9 +167,9 @@ namespace LuaUnit int IsTabardDesigner(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isTabardDesigner()); + Eluna::Push(L, unit->isTabardDesigner()); #else - sEluna->Push(L, unit->IsTabardDesigner()); + Eluna::Push(L, unit->IsTabardDesigner()); #endif return 1; } @@ -177,9 +177,9 @@ namespace LuaUnit int IsServiceProvider(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isServiceProvider()); + Eluna::Push(L, unit->isServiceProvider()); #else - sEluna->Push(L, unit->IsServiceProvider()); + Eluna::Push(L, unit->IsServiceProvider()); #endif return 1; } @@ -187,9 +187,9 @@ namespace LuaUnit int IsSpiritService(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isSpiritService()); + Eluna::Push(L, unit->isSpiritService()); #else - sEluna->Push(L, unit->IsSpiritService()); + Eluna::Push(L, unit->IsSpiritService()); #endif return 1; } @@ -197,31 +197,31 @@ namespace LuaUnit int IsAlive(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isAlive()); + Eluna::Push(L, unit->isAlive()); #else - sEluna->Push(L, unit->IsAlive()); + Eluna::Push(L, unit->IsAlive()); #endif return 1; } int IsDead(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->isDead()); + Eluna::Push(L, unit->isDead()); return 1; } int IsDying(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->isDying()); + Eluna::Push(L, unit->isDying()); return 1; } int IsBanker(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isBanker()); + Eluna::Push(L, unit->isBanker()); #else - sEluna->Push(L, unit->IsBanker()); + Eluna::Push(L, unit->IsBanker()); #endif return 1; } @@ -229,9 +229,9 @@ namespace LuaUnit int IsVendor(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isVendor()); + Eluna::Push(L, unit->isVendor()); #else - sEluna->Push(L, unit->IsVendor()); + Eluna::Push(L, unit->IsVendor()); #endif return 1; } @@ -239,9 +239,9 @@ namespace LuaUnit int IsBattleMaster(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isBattleMaster()); + Eluna::Push(L, unit->isBattleMaster()); #else - sEluna->Push(L, unit->IsBattleMaster()); + Eluna::Push(L, unit->IsBattleMaster()); #endif return 1; } @@ -249,9 +249,9 @@ namespace LuaUnit int IsCharmed(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isCharmed()); + Eluna::Push(L, unit->isCharmed()); #else - sEluna->Push(L, unit->IsCharmed()); + Eluna::Push(L, unit->IsCharmed()); #endif return 1; } @@ -259,28 +259,28 @@ namespace LuaUnit int IsArmorer(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isArmorer()); + Eluna::Push(L, unit->isArmorer()); #else - sEluna->Push(L, unit->IsArmorer()); + Eluna::Push(L, unit->IsArmorer()); #endif return 1; } int IsAttackingPlayer(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->isAttackingPlayer()); + Eluna::Push(L, unit->isAttackingPlayer()); return 1; } int IsInWorld(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsInWorld()); + Eluna::Push(L, unit->IsInWorld()); return 1; } int IsPvPFlagged(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsPvP()); + Eluna::Push(L, unit->IsPvP()); return 1; } @@ -288,9 +288,9 @@ namespace LuaUnit int IsOnVehicle(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->IsBoarded()); + Eluna::Push(L, unit->IsBoarded()); #else - sEluna->Push(L, unit->GetVehicle()); + Eluna::Push(L, unit->GetVehicle()); #endif return 1; } @@ -299,103 +299,103 @@ namespace LuaUnit int IsInCombat(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isInCombat()); + Eluna::Push(L, unit->isInCombat()); #else - sEluna->Push(L, unit->IsInCombat()); + Eluna::Push(L, unit->IsInCombat()); #endif return 1; } int IsUnderWater(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsUnderWater()); + Eluna::Push(L, unit->IsUnderWater()); return 1; } int IsInWater(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsInWater()); + Eluna::Push(L, unit->IsInWater()); return 1; } int IsStopped(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsStopped()); + Eluna::Push(L, unit->IsStopped()); return 1; } int IsQuestGiver(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->isQuestGiver()); + Eluna::Push(L, unit->isQuestGiver()); #else - sEluna->Push(L, unit->IsQuestGiver()); + Eluna::Push(L, unit->IsQuestGiver()); #endif return 1; } int HealthBelowPct(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->HealthBelowPct(sEluna->CHECKVAL(L, 2))); + Eluna::Push(L, unit->HealthBelowPct(Eluna::CHECKVAL(L, 2))); return 1; } int HealthAbovePct(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->HealthAbovePct(sEluna->CHECKVAL(L, 2))); + Eluna::Push(L, unit->HealthAbovePct(Eluna::CHECKVAL(L, 2))); return 1; } int HasAura(lua_State* L, Unit* unit) { - uint32 spell = sEluna->CHECKVAL(L, 2); + uint32 spell = Eluna::CHECKVAL(L, 2); - sEluna->Push(L, unit->HasAura(spell)); + Eluna::Push(L, unit->HasAura(spell)); return 1; } int HasUnitState(lua_State* L, Unit* unit) { - uint32 state = sEluna->CHECKVAL(L, 2); + uint32 state = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, unit->hasUnitState(state)); + Eluna::Push(L, unit->hasUnitState(state)); #else - sEluna->Push(L, unit->HasUnitState(state)); + Eluna::Push(L, unit->HasUnitState(state)); #endif return 1; } /*int IsVisible(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsVisible()); + Eluna::Push(L, unit->IsVisible()); return 1; }*/ /*int IsMoving(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->isMoving()); + Eluna::Push(L, unit->isMoving()); return 1; }*/ /*int IsFlying(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->IsFlying()); + Eluna::Push(L, unit->IsFlying()); return 1; }*/ /* GETTERS */ int GetOwner(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetOwner()); + Eluna::Push(L, unit->GetOwner()); return 1; } int GetOwnerGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetOwnerGuid()); + Eluna::Push(L, unit->GetOwnerGuid()); #else - sEluna->Push(L, unit->GetOwnerGUID()); + Eluna::Push(L, unit->GetOwnerGUID()); #endif return 1; } @@ -403,27 +403,27 @@ namespace LuaUnit int GetMap(lua_State* L, Unit* unit) { Map* map = unit->GetMap(); - sEluna->Push(L, map); + Eluna::Push(L, map); return 1; } int GetMountId(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetMountID()); + Eluna::Push(L, unit->GetMountID()); return 1; } int GetDistance(lua_State* L, Unit* unit) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2, false); + WorldObject* obj = Eluna::CHECKOBJ(L, 2, false); if (obj && obj->IsInWorld()) - sEluna->Push(L, unit->GetDistance(obj)); + Eluna::Push(L, unit->GetDistance(obj)); else { - float X = sEluna->CHECKVAL(L, 2); - float Y = sEluna->CHECKVAL(L, 3); - float Z = sEluna->CHECKVAL(L, 4); - sEluna->Push(L, unit->GetDistance(X, Y, Z)); + float X = Eluna::CHECKVAL(L, 2); + float Y = Eluna::CHECKVAL(L, 3); + float Z = Eluna::CHECKVAL(L, 4); + Eluna::Push(L, unit->GetDistance(X, Y, Z)); } return 1; } @@ -431,9 +431,9 @@ namespace LuaUnit int GetCreatorGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCreatorGuid()); + Eluna::Push(L, unit->GetCreatorGuid()); #else - sEluna->Push(L, unit->GetCreatorGUID()); + Eluna::Push(L, unit->GetCreatorGUID()); #endif return 1; } @@ -441,9 +441,9 @@ namespace LuaUnit int GetMinionGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetPetGuid()); + Eluna::Push(L, unit->GetPetGuid()); #else - sEluna->Push(L, unit->GetPetGUID()); + Eluna::Push(L, unit->GetPetGUID()); #endif return 1; } @@ -451,9 +451,9 @@ namespace LuaUnit int GetCharmerGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCharmerGuid()); + Eluna::Push(L, unit->GetCharmerGuid()); #else - sEluna->Push(L, unit->GetCharmerGUID()); + Eluna::Push(L, unit->GetCharmerGUID()); #endif return 1; } @@ -461,9 +461,9 @@ namespace LuaUnit int GetCharmGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCharmGuid()); + Eluna::Push(L, unit->GetCharmGuid()); #else - sEluna->Push(L, unit->GetCharmGUID()); + Eluna::Push(L, unit->GetCharmGUID()); #endif return 1; } @@ -471,9 +471,9 @@ namespace LuaUnit int GetPetGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetPetGuid()); + Eluna::Push(L, unit->GetPetGuid()); #else - sEluna->Push(L, unit->GetPetGUID()); + Eluna::Push(L, unit->GetPetGUID()); #endif return 1; } @@ -481,9 +481,9 @@ namespace LuaUnit int GetControllerGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCharmerOrOwnerGuid()); + Eluna::Push(L, unit->GetCharmerOrOwnerGuid()); #else - sEluna->Push(L, unit->GetCharmerOrOwnerGUID()); + Eluna::Push(L, unit->GetCharmerOrOwnerGUID()); #endif return 1; } @@ -491,87 +491,87 @@ namespace LuaUnit int GetControllerGUIDS(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCharmerOrOwnerOrOwnGuid()); + Eluna::Push(L, unit->GetCharmerOrOwnerOrOwnGuid()); #else - sEluna->Push(L, unit->GetCharmerOrOwnerOrOwnGUID()); + Eluna::Push(L, unit->GetCharmerOrOwnerOrOwnGUID()); #endif return 1; } int GetStat(lua_State* L, Unit* unit) { - uint32 stat = sEluna->CHECKVAL(L, 2); + uint32 stat = Eluna::CHECKVAL(L, 2); if (stat >= MAX_STATS) return 1; - sEluna->Push(L, unit->GetStat((Stats)stat)); + Eluna::Push(L, unit->GetStat((Stats)stat)); return 1; } int GetBaseSpellPower(lua_State* L, Unit* unit) { - uint32 spellschool = sEluna->CHECKVAL(L, 2); + uint32 spellschool = Eluna::CHECKVAL(L, 2); if (spellschool >= MAX_SPELL_SCHOOL) return 1; - sEluna->Push(L, unit->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + spellschool)); + Eluna::Push(L, unit->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + spellschool)); return 1; } int GetVictim(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->getVictim()); + Eluna::Push(L, unit->getVictim()); #else - sEluna->Push(L, unit->GetVictim()); + Eluna::Push(L, unit->GetVictim()); #endif return 1; } int GetCurrentSpell(lua_State* L, Unit* unit) { - uint32 type = sEluna->CHECKVAL(L, 2); + uint32 type = Eluna::CHECKVAL(L, 2); if (type >= CURRENT_MAX_SPELL) return luaL_argerror(L, 2, "valid CurrentSpellTypes expected"); - sEluna->Push(L, unit->GetCurrentSpell(type)); + Eluna::Push(L, unit->GetCurrentSpell(type)); return 1; } int GetStandState(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getStandState()); + Eluna::Push(L, unit->getStandState()); return 0; } int GetDisplayId(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetDisplayId()); + Eluna::Push(L, unit->GetDisplayId()); return 1; } int GetNativeDisplayId(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetNativeDisplayId()); + Eluna::Push(L, unit->GetNativeDisplayId()); return 1; } int GetLevel(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getLevel()); + Eluna::Push(L, unit->getLevel()); return 1; } int GetHealth(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetHealth()); + Eluna::Push(L, unit->GetHealth()); return 1; } int GetPower(lua_State* L, Unit* unit) { - int type = sEluna->CHECKVAL(L, 2, -1); + int type = Eluna::CHECKVAL(L, 2, -1); if (type == -1) { @@ -604,13 +604,13 @@ namespace LuaUnit else if (type < 0 || type >= POWER_ALL) return luaL_argerror(L, 2, "valid Powers expected"); - sEluna->Push(L, unit->GetPower((Powers)type)); + Eluna::Push(L, unit->GetPower((Powers)type)); return 1; } int GetMaxPower(lua_State* L, Unit* unit) { - int type = sEluna->CHECKVAL(L, 2, -1); + int type = Eluna::CHECKVAL(L, 2, -1); if (type == -1) { @@ -643,32 +643,32 @@ namespace LuaUnit else if (type < 0 || type >= POWER_ALL) return luaL_argerror(L, 2, "valid Powers expected"); - sEluna->Push(L, unit->GetMaxPower((Powers)type)); + Eluna::Push(L, unit->GetMaxPower((Powers)type)); return 1; } int GetPowerType(lua_State* L, Unit* unit) { #if (defined(MANGOS) && defined(WOTLK)) - sEluna->Push(L, unit->GetPowerType()); + Eluna::Push(L, unit->GetPowerType()); #else - sEluna->Push(L, unit->getPowerType()); + Eluna::Push(L, unit->getPowerType()); #endif return 1; } int GetMaxHealth(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetMaxHealth()); + Eluna::Push(L, unit->GetMaxHealth()); return 1; } int GetHealthPct(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetHealthPercent()); + Eluna::Push(L, unit->GetHealthPercent()); #else - sEluna->Push(L, unit->GetHealthPct()); + Eluna::Push(L, unit->GetHealthPct()); #endif return 1; } @@ -680,31 +680,31 @@ namespace LuaUnit #else float percent = (unit->GetPower(unit->getPowerType()) / unit->GetMaxPower(unit->getPowerType())) * 100; #endif - sEluna->Push(L, percent); + Eluna::Push(L, percent); return 1; } int GetGender(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getGender()); + Eluna::Push(L, unit->getGender()); return 1; } int GetRace(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getRace()); + Eluna::Push(L, unit->getRace()); return 1; } int GetClass(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getClass()); + Eluna::Push(L, unit->getClass()); return 1; } int GetCreatureType(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetCreatureType()); + Eluna::Push(L, unit->GetCreatureType()); return 1; } @@ -748,36 +748,36 @@ namespace LuaUnit break; } - sEluna->Push(L, str); + Eluna::Push(L, str); return 1; } int GetFaction(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->getFaction()); + Eluna::Push(L, unit->getFaction()); return 1; } int GetAura(lua_State* L, Unit* unit) { - uint32 spellID = sEluna->CHECKVAL(L, 2); + uint32 spellID = Eluna::CHECKVAL(L, 2); #ifdef MANGOS - sEluna->Push(L, unit->GetAura(spellID, EFFECT_INDEX_0)); + Eluna::Push(L, unit->GetAura(spellID, EFFECT_INDEX_0)); #else - sEluna->Push(L, unit->GetAura(spellID)); + Eluna::Push(L, unit->GetAura(spellID)); #endif return 1; } int GetCombatTime(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->GetCombatTimer()); + Eluna::Push(L, unit->GetCombatTimer()); return 1; } int GetFriendlyUnitsInRange(lua_State* L, Unit* unit) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); std::list list; #ifdef MANGOS @@ -798,8 +798,8 @@ namespace LuaUnit for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -809,7 +809,7 @@ namespace LuaUnit int GetUnfriendlyUnitsInRange(lua_State* L, Unit* unit) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); std::list list; #ifdef MANGOS @@ -830,8 +830,8 @@ namespace LuaUnit for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -843,25 +843,25 @@ namespace LuaUnit int GetVehicleKit(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetVehicleInfo()); + Eluna::Push(L, unit->GetVehicleInfo()); #else - sEluna->Push(L, unit->GetVehicleKit()); + Eluna::Push(L, unit->GetVehicleKit()); #endif return 1; } int GetVehicle(lua_State* L, Unit* unit) { - // sEluna->Push(L, unit->GetVehicle()); + // Eluna::Push(L, unit->GetVehicle()); return 1; } int GetCritterGUID(lua_State* L, Unit* unit) { #ifdef MANGOS - sEluna->Push(L, unit->GetCritterGuid()); + Eluna::Push(L, unit->GetCritterGuid()); #else - sEluna->Push(L, unit->GetCritterGUID()); + Eluna::Push(L, unit->GetCritterGUID()); #endif return 1; } @@ -870,7 +870,7 @@ namespace LuaUnit /* SETTERS */ int SetOwnerGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetOwnerGuid(ObjectGuid(guid)); @@ -882,7 +882,7 @@ namespace LuaUnit int SetPvP(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetPvP(apply); return 0; @@ -890,7 +890,7 @@ namespace LuaUnit int SetSheath(lua_State* L, Unit* unit) { - uint32 sheathed = sEluna->CHECKVAL(L, 2); + uint32 sheathed = Eluna::CHECKVAL(L, 2); if (sheathed >= MAX_SHEATH_STATE) return luaL_argerror(L, 2, "valid SheathState expected"); @@ -900,7 +900,7 @@ namespace LuaUnit int SetName(lua_State* L, Unit* unit) { - const char* name = sEluna->CHECKVAL(L, 2); + const char* name = Eluna::CHECKVAL(L, 2); if (std::string(name).length() > 0) unit->SetName(name); return 0; @@ -908,9 +908,9 @@ namespace LuaUnit int SetSpeed(lua_State* L, Unit* unit) { - uint32 type = sEluna->CHECKVAL(L, 2); - float rate = sEluna->CHECKVAL(L, 3); - bool forced = sEluna->CHECKVAL(L, 4, false); + uint32 type = Eluna::CHECKVAL(L, 2); + float rate = Eluna::CHECKVAL(L, 3); + bool forced = Eluna::CHECKVAL(L, 4, false); if (type >= MAX_MOVE_TYPE) return luaL_argerror(L, 2, "valid UnitMoveType expected"); #ifdef MANGOS @@ -923,36 +923,36 @@ namespace LuaUnit int SetFaction(lua_State* L, Unit* unit) { - uint32 factionId = sEluna->CHECKVAL(L, 2); + uint32 factionId = Eluna::CHECKVAL(L, 2); unit->setFaction(factionId); return 0; } int SetLevel(lua_State* L, Unit* unit) { - uint32 newLevel = sEluna->CHECKVAL(L, 2); + uint32 newLevel = Eluna::CHECKVAL(L, 2); unit->SetLevel(newLevel); return 0; } int SetHealth(lua_State* L, Unit* unit) { - uint32 amt = sEluna->CHECKVAL(L, 2); + uint32 amt = Eluna::CHECKVAL(L, 2); unit->SetHealth(amt); return 0; } int SetMaxHealth(lua_State* L, Unit* unit) { - uint32 amt = sEluna->CHECKVAL(L, 2); + uint32 amt = Eluna::CHECKVAL(L, 2); unit->SetMaxHealth(amt); return 0; } int SetPower(lua_State* L, Unit* unit) { - int type = sEluna->CHECKVAL(L, 2); - uint32 amt = sEluna->CHECKVAL(L, 3); + int type = Eluna::CHECKVAL(L, 2); + uint32 amt = Eluna::CHECKVAL(L, 3); switch (type) { @@ -979,8 +979,8 @@ namespace LuaUnit int SetMaxPower(lua_State* L, Unit* unit) { - int type = sEluna->CHECKVAL(L, 2); - uint32 amt = sEluna->CHECKVAL(L, 3); + int type = Eluna::CHECKVAL(L, 2); + uint32 amt = Eluna::CHECKVAL(L, 3); switch (type) { @@ -1007,35 +1007,35 @@ namespace LuaUnit int SetDisplayId(lua_State* L, Unit* unit) { - uint32 model = sEluna->CHECKVAL(L, 2); + uint32 model = Eluna::CHECKVAL(L, 2); unit->SetDisplayId(model); return 0; } int SetNativeDisplayId(lua_State* L, Unit* unit) { - uint32 model = sEluna->CHECKVAL(L, 2); + uint32 model = Eluna::CHECKVAL(L, 2); unit->SetNativeDisplayId(model); return 0; } int SetFacing(lua_State* L, Unit* unit) { - float o = sEluna->CHECKVAL(L, 2); + float o = Eluna::CHECKVAL(L, 2); unit->SetFacingTo(o); return 0; } int SetFacingToObject(lua_State* L, Unit* unit) { - WorldObject* obj = sEluna->CHECKOBJ(L, 2); + WorldObject* obj = Eluna::CHECKOBJ(L, 2); unit->SetFacingToObject(obj); return 0; } int SetCreatorGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetOwnerGuid(ObjectGuid(guid)); #else @@ -1046,7 +1046,7 @@ namespace LuaUnit int SetMinionGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetPetGuid(ObjectGuid(guid)); #else @@ -1057,7 +1057,7 @@ namespace LuaUnit int SetCharmerGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetCharmerGuid(ObjectGuid(guid)); #else @@ -1068,7 +1068,7 @@ namespace LuaUnit int SetPetGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetPetGuid(ObjectGuid(guid)); #else @@ -1079,7 +1079,7 @@ namespace LuaUnit int SetWaterWalk(lua_State* L, Unit* unit) { - bool enable = sEluna->CHECKVAL(L, 2, true); + bool enable = Eluna::CHECKVAL(L, 2, true); #ifdef MANGOS unit->SetWaterWalk(enable); #else @@ -1090,7 +1090,7 @@ namespace LuaUnit int SetStandState(lua_State* L, Unit* unit) { - uint8 state = sEluna->CHECKVAL(L, 2); + uint8 state = Eluna::CHECKVAL(L, 2); unit->SetStandState(state); return 0; } @@ -1098,7 +1098,7 @@ namespace LuaUnit #if (!defined(TBC) && !defined(CLASSIC)) int SetFFA(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); #ifdef MANGOS unit->SetFFAPvP(apply); @@ -1121,7 +1121,7 @@ namespace LuaUnit int SetSanctuary(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); if (apply) { @@ -1137,15 +1137,15 @@ namespace LuaUnit int SetPhaseMask(lua_State* L, Unit* unit) { - uint32 phaseMask = sEluna->CHECKVAL(L, 2); - bool Update = sEluna->CHECKVAL(L, 3, true); + uint32 phaseMask = Eluna::CHECKVAL(L, 2); + bool Update = Eluna::CHECKVAL(L, 3, true); unit->SetPhaseMask(phaseMask, Update); return 0; } int SetCritterGUID(lua_State* L, Unit* unit) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->SetCritterGuid(ObjectGuid(guid)); #else @@ -1157,42 +1157,42 @@ namespace LuaUnit /*int SetStunned(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetControlled(apply, UNIT_STATE_STUNNED); return 0; }*/ /*int SetRooted(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetControlled(apply, UNIT_STATE_ROOT); return 0; }*/ /*int SetConfused(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetControlled(apply, UNIT_STATE_CONFUSED); return 0; }*/ /*int SetFeared(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetControlled(apply, UNIT_STATE_FLEEING); return 0; }*/ /*int SetCanFly(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); unit->SetCanFly(apply); return 0; }*/ /*int SetVisible(lua_State* L, Unit* unit) { - bool x = sEluna->CHECKVAL(L, 2, true); + bool x = Eluna::CHECKVAL(L, 2, true); unit->SetVisible(x); return 0; }*/ @@ -1206,7 +1206,7 @@ namespace LuaUnit int Mount(lua_State* L, Unit* unit) { - uint32 displayId = sEluna->CHECKVAL(L, 2); + uint32 displayId = Eluna::CHECKVAL(L, 2); unit->Mount(displayId); return 0; @@ -1230,28 +1230,28 @@ namespace LuaUnit int Emote(lua_State* L, Unit* unit) { - unit->HandleEmoteCommand(sEluna->CHECKVAL(L, 2)); + unit->HandleEmoteCommand(Eluna::CHECKVAL(L, 2)); return 0; } int CountPctFromCurHealth(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->CountPctFromCurHealth(sEluna->CHECKVAL(L, 2))); + Eluna::Push(L, unit->CountPctFromCurHealth(Eluna::CHECKVAL(L, 2))); return 1; } int CountPctFromMaxHealth(lua_State* L, Unit* unit) { - sEluna->Push(L, unit->CountPctFromMaxHealth(sEluna->CHECKVAL(L, 2))); + Eluna::Push(L, unit->CountPctFromMaxHealth(Eluna::CHECKVAL(L, 2))); return 1; } int SendChatMessageToPlayer(lua_State* L, Unit* unit) { - uint8 type = sEluna->CHECKVAL(L, 2); - uint32 lang = sEluna->CHECKVAL(L, 3); - std::string msg = sEluna->CHECKVAL(L, 4); - Player* target = sEluna->CHECKOBJ(L, 5); + uint8 type = Eluna::CHECKVAL(L, 2); + uint32 lang = Eluna::CHECKVAL(L, 3); + std::string msg = Eluna::CHECKVAL(L, 4); + Player* target = Eluna::CHECKOBJ(L, 5); if (type >= MAX_CHAT_MSG_TYPE) return luaL_argerror(L, 2, "valid ChatMsg expected"); @@ -1283,14 +1283,14 @@ namespace LuaUnit int MoveExpire(lua_State* L, Unit* unit) { - bool reset = sEluna->CHECKVAL(L, 2, true); + bool reset = Eluna::CHECKVAL(L, 2, true); unit->GetMotionMaster()->MovementExpired(reset); return 0; } int MoveClear(lua_State* L, Unit* unit) { - bool reset = sEluna->CHECKVAL(L, 2, true); + bool reset = Eluna::CHECKVAL(L, 2, true); unit->GetMotionMaster()->Clear(reset); return 0; } @@ -1303,7 +1303,7 @@ namespace LuaUnit int MoveRandom(lua_State* L, Unit* unit) { - float radius = sEluna->CHECKVAL(L, 2); + float radius = Eluna::CHECKVAL(L, 2); float x, y, z; unit->GetPosition(x, y, z); #ifdef MANGOS @@ -1322,18 +1322,18 @@ namespace LuaUnit int MoveFollow(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - float dist = sEluna->CHECKVAL(L, 3, 0.0f); - float angle = sEluna->CHECKVAL(L, 4, 0.0f); + Unit* target = Eluna::CHECKOBJ(L, 2); + float dist = Eluna::CHECKVAL(L, 3, 0.0f); + float angle = Eluna::CHECKVAL(L, 4, 0.0f); unit->GetMotionMaster()->MoveFollow(target, dist, angle); return 0; } int MoveChase(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - float dist = sEluna->CHECKVAL(L, 3, 0.0f); - float angle = sEluna->CHECKVAL(L, 4, 0.0f); + Unit* target = Eluna::CHECKOBJ(L, 2); + float dist = Eluna::CHECKVAL(L, 3, 0.0f); + float angle = Eluna::CHECKVAL(L, 4, 0.0f); unit->GetMotionMaster()->MoveChase(target, dist, angle); return 0; } @@ -1346,19 +1346,19 @@ namespace LuaUnit int MoveFleeing(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - uint32 time = sEluna->CHECKVAL(L, 3, 0); + Unit* target = Eluna::CHECKOBJ(L, 2); + uint32 time = Eluna::CHECKVAL(L, 3, 0); unit->GetMotionMaster()->MoveFleeing(target, time); return 0; } int MoveTo(lua_State* L, Unit* unit) { - uint32 id = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - bool genPath = sEluna->CHECKVAL(L, 6, true); + uint32 id = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + bool genPath = Eluna::CHECKVAL(L, 6, true); unit->GetMotionMaster()->MovePoint(id, x, y, z, genPath); return 0; } @@ -1366,12 +1366,12 @@ namespace LuaUnit #if (!defined(TBC) && !defined(CLASSIC)) int MoveJump(lua_State* L, Unit* unit) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - float z = sEluna->CHECKVAL(L, 4); - float zSpeed = sEluna->CHECKVAL(L, 5); - float maxHeight = sEluna->CHECKVAL(L, 6); - uint32 id = sEluna->CHECKVAL(L, 7, 0); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); + float zSpeed = Eluna::CHECKVAL(L, 5); + float maxHeight = Eluna::CHECKVAL(L, 6); + uint32 id = Eluna::CHECKVAL(L, 7, 0); unit->GetMotionMaster()->MoveJump(x, y, z, zSpeed, maxHeight, id); return 0; } @@ -1379,9 +1379,9 @@ namespace LuaUnit int SendUnitWhisper(lua_State* L, Unit* unit) { - const char* msg = sEluna->CHECKVAL(L, 2); - Player* receiver = sEluna->CHECKOBJ(L, 3); - bool bossWhisper = sEluna->CHECKVAL(L, 4, false); + const char* msg = Eluna::CHECKVAL(L, 2); + Player* receiver = Eluna::CHECKOBJ(L, 3); + bool bossWhisper = Eluna::CHECKVAL(L, 4, false); if (std::string(msg).length() > 0) unit->MonsterWhisper(msg, receiver, bossWhisper); return 0; @@ -1389,9 +1389,9 @@ namespace LuaUnit int SendUnitEmote(lua_State* L, Unit* unit) { - const char* msg = sEluna->CHECKVAL(L, 2); - Unit* receiver = sEluna->CHECKOBJ(L, 3, false); - bool bossEmote = sEluna->CHECKVAL(L, 4, false); + const char* msg = Eluna::CHECKVAL(L, 2); + Unit* receiver = Eluna::CHECKOBJ(L, 3, false); + bool bossEmote = Eluna::CHECKVAL(L, 4, false); if (std::string(msg).length() > 0) unit->MonsterTextEmote(msg, receiver, bossEmote); return 0; @@ -1399,8 +1399,8 @@ namespace LuaUnit int SendUnitSay(lua_State* L, Unit* unit) { - const char* msg = sEluna->CHECKVAL(L, 2); - uint32 language = sEluna->CHECKVAL(L, 3); + const char* msg = Eluna::CHECKVAL(L, 2); + uint32 language = Eluna::CHECKVAL(L, 3); if (std::string(msg).length() > 0) unit->MonsterSay(msg, language, unit); return 0; @@ -1408,8 +1408,8 @@ namespace LuaUnit int SendUnitYell(lua_State* L, Unit* unit) { - const char* msg = sEluna->CHECKVAL(L, 2); - uint32 language = sEluna->CHECKVAL(L, 3); + const char* msg = Eluna::CHECKVAL(L, 2); + uint32 language = Eluna::CHECKVAL(L, 3); if (std::string(msg).length() > 0) unit->MonsterYell(msg, language, unit); return 0; @@ -1423,9 +1423,9 @@ namespace LuaUnit int CastSpell(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - uint32 spell = sEluna->CHECKVAL(L, 3); - bool triggered = sEluna->CHECKVAL(L, 4, false); + Unit* target = Eluna::CHECKOBJ(L, 2); + uint32 spell = Eluna::CHECKVAL(L, 3); + bool triggered = Eluna::CHECKVAL(L, 4, false); SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); if (!spellEntry) return 0; @@ -1436,11 +1436,11 @@ namespace LuaUnit int CastSpellAoF(lua_State* L, Unit* unit) { - float _x = sEluna->CHECKVAL(L, 2); - float _y = sEluna->CHECKVAL(L, 3); - float _z = sEluna->CHECKVAL(L, 4); - uint32 spell = sEluna->CHECKVAL(L, 5); - bool triggered = sEluna->CHECKVAL(L, 6, true); + float _x = Eluna::CHECKVAL(L, 2); + float _y = Eluna::CHECKVAL(L, 3); + float _z = Eluna::CHECKVAL(L, 4); + uint32 spell = Eluna::CHECKVAL(L, 5); + bool triggered = Eluna::CHECKVAL(L, 6, true); unit->CastSpell(_x, _y, _z, spell, triggered); return 0; } @@ -1453,15 +1453,15 @@ namespace LuaUnit int StopSpellCast(lua_State* L, Unit* unit) { - uint32 spellId = sEluna->CHECKVAL(L, 2, 0); + uint32 spellId = Eluna::CHECKVAL(L, 2, 0); unit->CastStop(spellId); return 0; } int InterruptSpell(lua_State* L, Unit* unit) { - int spellType = sEluna->CHECKVAL(L, 2); - bool delayed = sEluna->CHECKVAL(L, 3, true); + int spellType = Eluna::CHECKVAL(L, 2); + bool delayed = Eluna::CHECKVAL(L, 3, true); switch (spellType) { case 0: @@ -1483,8 +1483,8 @@ namespace LuaUnit int AddAura(lua_State* L, Unit* unit) { - uint32 spellId = sEluna->CHECKVAL(L, 2); - Unit* target = sEluna->CHECKOBJ(L, 3); + uint32 spellId = Eluna::CHECKVAL(L, 2); + Unit* target = Eluna::CHECKOBJ(L, 3); SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); if (!spellInfo) return 1; @@ -1508,16 +1508,16 @@ namespace LuaUnit holder->AddAura(aur, SpellEffIndex(i)); } } - sEluna->Push(L, target->AddSpellAuraHolder(holder)); + Eluna::Push(L, target->AddSpellAuraHolder(holder)); #else - sEluna->Push(L, unit->AddAura(spellId, target)); + Eluna::Push(L, unit->AddAura(spellId, target)); #endif return 1; } int RemoveAura(lua_State* L, Unit* unit) { - uint32 spellId = sEluna->CHECKVAL(L, 2); + uint32 spellId = Eluna::CHECKVAL(L, 2); unit->RemoveAurasDueToSpell(spellId); return 0; } @@ -1530,8 +1530,8 @@ namespace LuaUnit int PlayDirectSound(lua_State* L, Unit* unit) { - uint32 soundId = sEluna->CHECKVAL(L, 2); - Player* player = sEluna->CHECKOBJ(L, 3, false); + uint32 soundId = Eluna::CHECKVAL(L, 2); + Player* player = Eluna::CHECKOBJ(L, 3, false); if (!sSoundEntriesStore.LookupEntry(soundId)) return 0; @@ -1544,8 +1544,8 @@ namespace LuaUnit int PlayDistanceSound(lua_State* L, Unit* unit) { - uint32 soundId = sEluna->CHECKVAL(L, 2); - Player* player = sEluna->CHECKOBJ(L, 3, false); + uint32 soundId = Eluna::CHECKVAL(L, 2); + Player* player = Eluna::CHECKOBJ(L, 3, false); if (!sSoundEntriesStore.LookupEntry(soundId)) return 0; @@ -1559,33 +1559,33 @@ namespace LuaUnit int RegisterEvent(lua_State* L, Unit* unit) { luaL_checktype(L, 2, LUA_TFUNCTION); - uint32 delay = sEluna->CHECKVAL(L, 3); - uint32 repeats = sEluna->CHECKVAL(L, 4); + uint32 delay = Eluna::CHECKVAL(L, 3); + uint32 repeats = Eluna::CHECKVAL(L, 4); lua_pushvalue(L, 2); int functionRef = lua_ref(L, true); - functionRef = sEluna->m_EventMgr.AddEvent(&unit->m_Events, functionRef, delay, repeats, unit); + functionRef = sEluna->m_EventMgr->AddEvent(&unit->m_Events, functionRef, delay, repeats, unit); if (functionRef) - sEluna->Push(L, functionRef); + Eluna::Push(L, functionRef); return 1; } int RemoveEventById(lua_State* L, Unit* unit) { - int eventId = sEluna->CHECKVAL(L, 2); - sEluna->m_EventMgr.RemoveEvent(&unit->m_Events, eventId); + int eventId = Eluna::CHECKVAL(L, 2); + sEluna->m_EventMgr->RemoveEvent(&unit->m_Events, eventId); return 0; } int RemoveEvents(lua_State* L, Unit* unit) { - sEluna->m_EventMgr.RemoveEvents(&unit->m_Events); + sEluna->m_EventMgr->RemoveEvents(&unit->m_Events); return 0; } int AddUnitState(lua_State* L, Unit* unit) { - uint32 state = sEluna->CHECKVAL(L, 2); + uint32 state = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->addUnitState(state); @@ -1597,7 +1597,7 @@ namespace LuaUnit int ClearUnitState(lua_State* L, Unit* unit) { - uint32 state = sEluna->CHECKVAL(L, 2); + uint32 state = Eluna::CHECKVAL(L, 2); #ifdef MANGOS unit->clearUnitState(state); @@ -1609,10 +1609,10 @@ namespace LuaUnit int NearTeleport(lua_State* L, Unit* unit) { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - float z = sEluna->CHECKVAL(L, 4); - float o = sEluna->CHECKVAL(L, 5); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); + float o = Eluna::CHECKVAL(L, 5); unit->NearTeleportTo(x, y, z, o); return 1; @@ -1620,8 +1620,8 @@ namespace LuaUnit /*int DealDamage(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - uint32 amount = sEluna->CHECKVAL(L, 3); + Unit* target = Eluna::CHECKOBJ(L, 2); + uint32 amount = Eluna::CHECKVAL(L, 3); unit->DealDamage(target, amount); return 0; @@ -1629,8 +1629,8 @@ namespace LuaUnit /*int Kill(lua_State* L, Unit* unit) { - Unit* target = sEluna->CHECKOBJ(L, 2); - bool durLoss = sEluna->CHECKVAL(L, 3, true); + Unit* target = Eluna::CHECKOBJ(L, 2); + bool durLoss = Eluna::CHECKVAL(L, 3, true); unit->Kill(target, durLoss); return 0; }*/ @@ -1661,7 +1661,7 @@ namespace LuaUnit /*int DisableMelee(lua_State* L, Unit* unit) { - bool apply = sEluna->CHECKVAL(L, 2, true); + bool apply = Eluna::CHECKVAL(L, 2, true); if (apply) unit->AddUnitState(UNIT_STATE_CANNOT_AUTOATTACK); @@ -1672,12 +1672,12 @@ namespace LuaUnit /*int SummonGuardian(lua_State* L, Unit* unit) { - uint32 entry = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - float o = sEluna->CHECKVAL(L, 6); - uint32 desp = sEluna->CHECKVAL(L, 7, 0); + uint32 entry = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + float o = Eluna::CHECKVAL(L, 6); + uint32 desp = Eluna::CHECKVAL(L, 7, 0); SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(61); if (!properties) @@ -1706,7 +1706,7 @@ namespace LuaUnit } summon->AI()->EnterEvadeMode(); - sEluna->Push(L, summon); + Eluna::Push(L, summon); return 1; }*/ }; diff --git a/VehicleMethods.h b/VehicleMethods.h index 2345948..33b0d0a 100644 --- a/VehicleMethods.h +++ b/VehicleMethods.h @@ -14,11 +14,11 @@ namespace LuaVehicle /* BOOLEAN */ int IsOnBoard(lua_State* L, Vehicle* vehicle) { - Unit* passenger = sEluna->CHECKOBJ(L, 2); + Unit* passenger = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS - sEluna->Push(L, vehicle->HasOnBoard(passenger)); + Eluna::Push(L, vehicle->HasOnBoard(passenger)); #else - sEluna->Push(L, passenger->IsOnVehicle(vehicle->GetBase())); + Eluna::Push(L, passenger->IsOnVehicle(vehicle->GetBase())); #endif return 1; } @@ -27,9 +27,9 @@ namespace LuaVehicle int GetOwner(lua_State* L, Vehicle* vehicle) { #ifdef MANGOS - sEluna->Push(L, vehicle->GetOwner()); + Eluna::Push(L, vehicle->GetOwner()); #else - sEluna->Push(L, vehicle->GetBase()); + Eluna::Push(L, vehicle->GetBase()); #endif return 1; } @@ -37,25 +37,25 @@ namespace LuaVehicle int GetEntry(lua_State* L, Vehicle* vehicle) { #ifdef MANGOS - sEluna->Push(L, vehicle->GetVehicleEntry()->m_ID); + Eluna::Push(L, vehicle->GetVehicleEntry()->m_ID); #else - sEluna->Push(L, vehicle->GetVehicleInfo()->m_ID); + Eluna::Push(L, vehicle->GetVehicleInfo()->m_ID); #endif return 1; } int GetPassenger(lua_State* L, Vehicle* vehicle) { - int8 seatId = sEluna->CHECKVAL(L, 2); - sEluna->Push(L, vehicle->GetPassenger(seatId)); + int8 seatId = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, vehicle->GetPassenger(seatId)); return 1; } /* OTHER */ int AddPassenger(lua_State* L, Vehicle* vehicle) { - Unit* passenger = sEluna->CHECKOBJ(L, 2); - int8 seatId = sEluna->CHECKVAL(L, 3); + Unit* passenger = Eluna::CHECKOBJ(L, 2); + int8 seatId = Eluna::CHECKVAL(L, 3); #ifdef MANGOS if (vehicle->CanBoard(passenger)) vehicle->Board(passenger, seatId); @@ -67,7 +67,7 @@ namespace LuaVehicle int RemovePassenger(lua_State* L, Vehicle* vehicle) { - Unit* passenger = sEluna->CHECKOBJ(L, 2); + Unit* passenger = Eluna::CHECKOBJ(L, 2); #ifdef MANGOS vehicle->UnBoard(passenger, false); #else diff --git a/WeatherMethods.h b/WeatherMethods.h index 117eeae..60b3757 100644 --- a/WeatherMethods.h +++ b/WeatherMethods.h @@ -12,15 +12,15 @@ namespace LuaWeather /* GETTERS */ int GetZoneId(lua_State* L, Weather* weather) { - sEluna->Push(L, weather->GetZone()); + Eluna::Push(L, weather->GetZone()); return 1; } /* SETTERS */ int SetWeather(lua_State* L, Weather* weather) { - uint32 weatherType = sEluna->CHECKVAL(L, 2); - float grade = sEluna->CHECKVAL(L, 3); + uint32 weatherType = Eluna::CHECKVAL(L, 2); + float grade = Eluna::CHECKVAL(L, 3); weather->SetWeather((WeatherType)weatherType, grade); return 0; @@ -28,7 +28,7 @@ namespace LuaWeather int SendWeatherUpdateToPlayer(lua_State* L, Weather* weather) { - Player* player = sEluna->CHECKOBJ(L, 2); + Player* player = Eluna::CHECKOBJ(L, 2); weather->SendWeatherUpdateToPlayer(player); return 0; @@ -37,13 +37,13 @@ namespace LuaWeather /* OTHER */ int Regenerate(lua_State* L, Weather* weather) { - sEluna->Push(L, weather->ReGenerate()); + Eluna::Push(L, weather->ReGenerate()); return 1; } int UpdateWeather(lua_State* L, Weather* weather) { - sEluna->Push(L, weather->UpdateWeather()); + Eluna::Push(L, weather->UpdateWeather()); return 1; } }; diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index 2c00a92..e6a1f51 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -12,84 +12,84 @@ namespace LuaWorldObject /* GETTERS */ int GetName(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetName()); + Eluna::Push(L, obj->GetName()); return 1; } int GetMap(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetMap()); + Eluna::Push(L, obj->GetMap()); return 1; } #if (!defined(TBC) && !defined(CLASSIC)) int GetPhaseMask(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetPhaseMask()); + Eluna::Push(L, obj->GetPhaseMask()); return 1; } #endif int GetInstanceId(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetInstanceId()); + Eluna::Push(L, obj->GetInstanceId()); return 1; } int GetAreaId(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetAreaId()); + Eluna::Push(L, obj->GetAreaId()); return 1; } int GetZoneId(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetZoneId()); + Eluna::Push(L, obj->GetZoneId()); return 1; } int GetMapId(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetMapId()); + Eluna::Push(L, obj->GetMapId()); return 1; } int GetX(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetPositionX()); + Eluna::Push(L, obj->GetPositionX()); return 1; } int GetY(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetPositionY()); + Eluna::Push(L, obj->GetPositionY()); return 1; } int GetZ(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetPositionZ()); + Eluna::Push(L, obj->GetPositionZ()); return 1; } int GetO(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetOrientation()); + Eluna::Push(L, obj->GetOrientation()); return 1; } int GetLocation(lua_State* L, WorldObject* obj) { - sEluna->Push(L, obj->GetPositionX()); - sEluna->Push(L, obj->GetPositionY()); - sEluna->Push(L, obj->GetPositionZ()); - sEluna->Push(L, obj->GetOrientation()); + Eluna::Push(L, obj->GetPositionX()); + Eluna::Push(L, obj->GetPositionY()); + Eluna::Push(L, obj->GetPositionZ()); + Eluna::Push(L, obj->GetOrientation()); return 4; } int GetNearestPlayer(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); Unit* target = NULL; Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER); @@ -101,14 +101,14 @@ namespace LuaWorldObject obj->VisitNearbyObject(range, searcher); #endif - sEluna->Push(L, target); + Eluna::Push(L, target); return 1; } int GetNearestGameObject(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); - uint32 entry = sEluna->CHECKVAL(L, 3, 0); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = Eluna::CHECKVAL(L, 3, 0); GameObject* target = NULL; Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_GAMEOBJECT, entry); @@ -120,14 +120,14 @@ namespace LuaWorldObject obj->VisitNearbyObject(range, searcher); #endif - sEluna->Push(L, target); + Eluna::Push(L, target); return 1; } int GetNearestCreature(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); - uint32 entry = sEluna->CHECKVAL(L, 3, 0); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = Eluna::CHECKVAL(L, 3, 0); Creature* target = NULL; Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry); @@ -139,13 +139,13 @@ namespace LuaWorldObject obj->VisitNearbyObject(range, searcher); #endif - sEluna->Push(L, target); + Eluna::Push(L, target); return 1; } int GetPlayersInRange(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); std::list list; Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER); @@ -163,8 +163,8 @@ namespace LuaWorldObject for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -174,8 +174,8 @@ namespace LuaWorldObject int GetCreaturesInRange(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); - uint32 entry = sEluna->CHECKVAL(L, 3, 0); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = Eluna::CHECKVAL(L, 3, 0); std::list list; Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry); @@ -193,8 +193,8 @@ namespace LuaWorldObject for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -204,8 +204,8 @@ namespace LuaWorldObject int GetGameObjectsInRange(lua_State* L, WorldObject* obj) { - float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); - uint32 entry = sEluna->CHECKVAL(L, 3, 0); + float range = Eluna::CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = Eluna::CHECKVAL(L, 3, 0); std::list list; Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_GAMEOBJECT, entry); @@ -223,8 +223,8 @@ namespace LuaWorldObject for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -234,11 +234,11 @@ namespace LuaWorldObject int GetNearObject(lua_State* L, WorldObject* obj) { - bool nearest = sEluna->CHECKVAL(L, 2, true); - float range = sEluna->CHECKVAL(L, 3, SIZE_OF_GRIDS); - uint16 type = sEluna->CHECKVAL(L, 4, 0); // TypeMask - uint32 entry = sEluna->CHECKVAL(L, 5, 0); - uint32 hostile = sEluna->CHECKVAL(L, 6, 0); // 0 none, 1 hostile, 2 friendly + bool nearest = Eluna::CHECKVAL(L, 2, true); + float range = Eluna::CHECKVAL(L, 3, SIZE_OF_GRIDS); + uint16 type = Eluna::CHECKVAL(L, 4, 0); // TypeMask + uint32 entry = Eluna::CHECKVAL(L, 5, 0); + uint32 hostile = Eluna::CHECKVAL(L, 6, 0); // 0 none, 1 hostile, 2 friendly float x, y, z; obj->GetPosition(x, y, z); @@ -254,7 +254,7 @@ namespace LuaWorldObject obj->VisitNearbyObject(range, searcher); #endif - sEluna->Push(L, target); + Eluna::Push(L, target); return 1; } else @@ -274,8 +274,8 @@ namespace LuaWorldObject for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) { - sEluna->Push(L, ++i); - sEluna->Push(L, *it); + Eluna::Push(L, ++i); + Eluna::Push(L, *it); lua_settable(L, tbl); } @@ -288,31 +288,31 @@ namespace LuaWorldObject int GetWorldObject(lua_State* L, WorldObject* obj) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); #ifdef MANGOS switch (GUID_HIPART(guid)) { - case HIGHGUID_PLAYER: sEluna->Push(L, obj->GetMap()->GetPlayer(ObjectGuid(guid))); break; + case HIGHGUID_PLAYER: Eluna::Push(L, obj->GetMap()->GetPlayer(ObjectGuid(guid))); break; case HIGHGUID_TRANSPORT: case HIGHGUID_MO_TRANSPORT: - case HIGHGUID_GAMEOBJECT: sEluna->Push(L, obj->GetMap()->GetGameObject(ObjectGuid(guid))); break; + case HIGHGUID_GAMEOBJECT: Eluna::Push(L, obj->GetMap()->GetGameObject(ObjectGuid(guid))); break; #if (!defined(TBC) && !defined(CLASSIC)) case HIGHGUID_VEHICLE: #endif case HIGHGUID_UNIT: - case HIGHGUID_PET: sEluna->Push(L, obj->GetMap()->GetAnyTypeCreature(ObjectGuid(guid))); break; + case HIGHGUID_PET: Eluna::Push(L, obj->GetMap()->GetAnyTypeCreature(ObjectGuid(guid))); break; } #else switch (GUID_HIPART(guid)) { - case HIGHGUID_PLAYER: sEluna->Push(L, sObjectAccessor->GetPlayer(*obj, ObjectGuid(guid))); break; + case HIGHGUID_PLAYER: Eluna::Push(L, sObjectAccessor->GetPlayer(*obj, ObjectGuid(guid))); break; case HIGHGUID_TRANSPORT: case HIGHGUID_MO_TRANSPORT: - case HIGHGUID_GAMEOBJECT: sEluna->Push(L, sObjectAccessor->GetGameObject(*obj, ObjectGuid(guid))); break; + case HIGHGUID_GAMEOBJECT: Eluna::Push(L, sObjectAccessor->GetGameObject(*obj, ObjectGuid(guid))); break; case HIGHGUID_VEHICLE: - case HIGHGUID_UNIT: sEluna->Push(L, sObjectAccessor->GetCreature(*obj, ObjectGuid(guid))); break; - case HIGHGUID_PET: sEluna->Push(L, sObjectAccessor->GetPet(*obj, ObjectGuid(guid))); break; + case HIGHGUID_UNIT: Eluna::Push(L, sObjectAccessor->GetCreature(*obj, ObjectGuid(guid))); break; + case HIGHGUID_PET: Eluna::Push(L, sObjectAccessor->GetPet(*obj, ObjectGuid(guid))); break; } #endif return 1; @@ -320,44 +320,44 @@ namespace LuaWorldObject int GetDistance(lua_State* L, WorldObject* obj) { - WorldObject* target = sEluna->CHECKOBJ(L, 2, false); + WorldObject* target = Eluna::CHECKOBJ(L, 2, false); if (target && target->IsInWorld()) - sEluna->Push(L, obj->GetDistance(target)); + Eluna::Push(L, obj->GetDistance(target)); else { - float X = sEluna->CHECKVAL(L, 2); - float Y = sEluna->CHECKVAL(L, 3); - float Z = sEluna->CHECKVAL(L, 4); - sEluna->Push(L, obj->GetDistance(X, Y, Z)); + float X = Eluna::CHECKVAL(L, 2); + float Y = Eluna::CHECKVAL(L, 3); + float Z = Eluna::CHECKVAL(L, 4); + Eluna::Push(L, obj->GetDistance(X, Y, Z)); } return 1; } int GetRelativePoint(lua_State* L, WorldObject* obj) { - float dist = sEluna->CHECKVAL(L, 2); - float rad = sEluna->CHECKVAL(L, 3); + float dist = Eluna::CHECKVAL(L, 2); + float rad = Eluna::CHECKVAL(L, 3); float x, y, z; obj->GetClosePoint(x, y, z, 0.0f, dist, rad); - sEluna->Push(L, x); - sEluna->Push(L, y); - sEluna->Push(L, z); + Eluna::Push(L, x); + Eluna::Push(L, y); + Eluna::Push(L, z); return 3; } int GetAngle(lua_State* L, WorldObject* obj) { - WorldObject* target = sEluna->CHECKOBJ(L, 2, false); + WorldObject* target = Eluna::CHECKOBJ(L, 2, false); if (target && target->IsInWorld()) - sEluna->Push(L, obj->GetAngle(target)); + Eluna::Push(L, obj->GetAngle(target)); else { - float x = sEluna->CHECKVAL(L, 2); - float y = sEluna->CHECKVAL(L, 3); - sEluna->Push(L, obj->GetAngle(x, y)); + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + Eluna::Push(L, obj->GetAngle(x, y)); } return 1; } @@ -365,36 +365,36 @@ namespace LuaWorldObject /* OTHER */ int SendPacket(lua_State* L, WorldObject* obj) { - WorldPacket* data = sEluna->CHECKOBJ(L, 2); + WorldPacket* data = Eluna::CHECKOBJ(L, 2); obj->SendMessageToSet(data, true); return 0; } int SummonGameObject(lua_State* L, WorldObject* obj) { - uint32 entry = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - float o = sEluna->CHECKVAL(L, 6); - uint32 respawnDelay = sEluna->CHECKVAL(L, 7, 30); + uint32 entry = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + float o = Eluna::CHECKVAL(L, 6); + uint32 respawnDelay = Eluna::CHECKVAL(L, 7, 30); #ifdef MANGOS - sEluna->Push(L, obj->SummonGameObject(entry, x, y, z, o, respawnDelay)); + Eluna::Push(L, obj->SummonGameObject(entry, x, y, z, o, respawnDelay)); #else - sEluna->Push(L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay)); + Eluna::Push(L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay)); #endif return 1; } int SpawnCreature(lua_State* L, WorldObject* obj) { - uint32 entry = sEluna->CHECKVAL(L, 2); - float x = sEluna->CHECKVAL(L, 3); - float y = sEluna->CHECKVAL(L, 4); - float z = sEluna->CHECKVAL(L, 5); - float o = sEluna->CHECKVAL(L, 6); - uint32 spawnType = sEluna->CHECKVAL(L, 7, 8); - uint32 despawnTimer = sEluna->CHECKVAL(L, 8, 0); + uint32 entry = Eluna::CHECKVAL(L, 2); + float x = Eluna::CHECKVAL(L, 3); + float y = Eluna::CHECKVAL(L, 4); + float z = Eluna::CHECKVAL(L, 5); + float o = Eluna::CHECKVAL(L, 6); + uint32 spawnType = Eluna::CHECKVAL(L, 7, 8); + uint32 despawnTimer = Eluna::CHECKVAL(L, 8, 0); TempSummonType type; switch (spawnType) @@ -423,7 +423,7 @@ namespace LuaWorldObject default: return luaL_argerror(L, 7, "valid SpawnType expected"); } - sEluna->Push(L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); + Eluna::Push(L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); return 1; } }; diff --git a/WorldPacketMethods.h b/WorldPacketMethods.h index 16a1633..38d20ef 100644 --- a/WorldPacketMethods.h +++ b/WorldPacketMethods.h @@ -12,21 +12,21 @@ namespace LuaPacket // GetOpcode() int GetOpcode(lua_State* L, WorldPacket* packet) { - sEluna->Push(L, packet->GetOpcode()); + Eluna::Push(L, packet->GetOpcode()); return 1; } // GetSize() int GetSize(lua_State* L, WorldPacket* packet) { - sEluna->Push(L, packet->size()); + Eluna::Push(L, packet->size()); return 1; } // SetOpcode(opcode) int SetOpcode(lua_State* L, WorldPacket* packet) { - uint32 opcode = sEluna->CHECKVAL(L, 2); + uint32 opcode = Eluna::CHECKVAL(L, 2); if (opcode >= NUM_MSG_TYPES) return luaL_argerror(L, 2, "valid opcode expected"); packet->SetOpcode((Opcodes)opcode); @@ -38,7 +38,7 @@ namespace LuaPacket { int8 byte; (*packet) >> byte; - sEluna->Push(L, byte); + Eluna::Push(L, byte); return 1; } @@ -47,7 +47,7 @@ namespace LuaPacket { uint8 byte; (*packet) >> byte; - sEluna->Push(L, byte); + Eluna::Push(L, byte); return 1; } @@ -56,7 +56,7 @@ namespace LuaPacket { int16 _short; (*packet) >> _short; - sEluna->Push(L, _short); + Eluna::Push(L, _short); return 1; } @@ -65,7 +65,7 @@ namespace LuaPacket { uint16 _ushort; (*packet) >> _ushort; - sEluna->Push(L, _ushort); + Eluna::Push(L, _ushort); return 1; } @@ -74,7 +74,7 @@ namespace LuaPacket { int32 _long; (*packet) >> _long; - sEluna->Push(L, _long); + Eluna::Push(L, _long); return 1; } @@ -83,7 +83,7 @@ namespace LuaPacket { uint32 _ulong; (*packet) >> _ulong; - sEluna->Push(L, _ulong); + Eluna::Push(L, _ulong); return 1; } @@ -92,7 +92,7 @@ namespace LuaPacket { float _val; (*packet) >> _val; - sEluna->Push(L, _val); + Eluna::Push(L, _val); return 1; } @@ -101,7 +101,7 @@ namespace LuaPacket { double _val; (*packet) >> _val; - sEluna->Push(L, _val); + Eluna::Push(L, _val); return 1; } @@ -110,7 +110,7 @@ namespace LuaPacket { uint64 guid; (*packet) >> guid; - sEluna->Push(L, guid); + Eluna::Push(L, guid); return 1; } @@ -119,14 +119,14 @@ namespace LuaPacket { std::string _val; (*packet) >> _val; - sEluna->Push(L, _val); + Eluna::Push(L, _val); return 1; } // WriteGUID(guid) int WriteGUID(lua_State* L, WorldPacket* packet) { - uint64 guid = sEluna->CHECKVAL(L, 2); + uint64 guid = Eluna::CHECKVAL(L, 2); (*packet) << guid; return 0; } @@ -134,7 +134,7 @@ namespace LuaPacket // WriteString(string) int WriteString(lua_State* L, WorldPacket* packet) { - std::string _val = sEluna->CHECKVAL(L, 2); + std::string _val = Eluna::CHECKVAL(L, 2); (*packet) << _val; return 0; } @@ -142,7 +142,7 @@ namespace LuaPacket // WriteBye(byte) int WriteByte(lua_State* L, WorldPacket* packet) { - int8 byte = sEluna->CHECKVAL(L, 2); + int8 byte = Eluna::CHECKVAL(L, 2); (*packet) << byte; return 0; } @@ -150,7 +150,7 @@ namespace LuaPacket // WriteUByte(byte) int WriteUByte(lua_State* L, WorldPacket* packet) { - uint8 byte = sEluna->CHECKVAL(L, 2); + uint8 byte = Eluna::CHECKVAL(L, 2); (*packet) << byte; return 0; } @@ -158,7 +158,7 @@ namespace LuaPacket // WriteUShort(short) int WriteUShort(lua_State* L, WorldPacket* packet) { - uint16 _ushort = sEluna->CHECKVAL(L, 2); + uint16 _ushort = Eluna::CHECKVAL(L, 2); (*packet) << _ushort; return 0; } @@ -166,7 +166,7 @@ namespace LuaPacket // WriteShort(short) int WriteShort(lua_State* L, WorldPacket* packet) { - int16 _short = sEluna->CHECKVAL(L, 2); + int16 _short = Eluna::CHECKVAL(L, 2); (*packet) << _short; return 0; } @@ -174,7 +174,7 @@ namespace LuaPacket // WriteLong(long) int WriteLong(lua_State* L, WorldPacket* packet) { - int32 _long = sEluna->CHECKVAL(L, 2); + int32 _long = Eluna::CHECKVAL(L, 2); (*packet) << _long; return 0; } @@ -182,7 +182,7 @@ namespace LuaPacket // WriteULong(long) int WriteULong(lua_State* L, WorldPacket* packet) { - uint32 _ulong = sEluna->CHECKVAL(L, 2); + uint32 _ulong = Eluna::CHECKVAL(L, 2); (*packet) << _ulong; return 0; } @@ -190,7 +190,7 @@ namespace LuaPacket // WriteFloat(float) int WriteFloat(lua_State* L, WorldPacket* packet) { - float _val = sEluna->CHECKVAL(L, 2); + float _val = Eluna::CHECKVAL(L, 2); (*packet) << _val; return 0; } @@ -198,7 +198,7 @@ namespace LuaPacket // WriteDouble(double) int WriteDouble(lua_State* L, WorldPacket* packet) { - double _val = sEluna->CHECKVAL(L, 2); + double _val = Eluna::CHECKVAL(L, 2); (*packet) << _val; return 0; }