diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a6d9e5f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,131 @@ +name: build + +on: + push: + pull_request: + +jobs: + TC-Eluna: + strategy: + fail-fast: false + matrix: + eluna: [ON, OFF] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: false + repository: ElunaLuaEngine/ElunaTrinityWotlk + - uses: actions/checkout@v2 + with: + path: src/server/game/LuaEngine + - name: Dependencies + run: | + sudo apt-get update && sudo apt-get install -yq libboost-all-dev + - name: Setup + env: + ELUNA: ${{ matrix.eluna }} + run: | + mkdir bin + cd bin + cmake ../ -DELUNA=$ELUNA -DWITH_WARNINGS=1 -DWITH_COREDEBUG=0 -DUSE_COREPCH=1 -DUSE_SCRIPTPCH=1 -DTOOLS=1 -DSCRIPTS=dynamic -DSERVERS=1 -DNOJEM=0 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_CXX_FLAGS_DEBUG="-DNDEBUG" -DCMAKE_INSTALL_PREFIX=check_install -DBUILD_TESTING=1 + cd .. + - name: Build + run: | + cd bin + make -j 4 -k && make install + - name: Unit tests + run: | + cd bin + make test + - name: Check executables + run: | + cd bin/check_install/bin + ./authserver --version + ./worldserver --version + + AC-Eluna: + strategy: + fail-fast: false + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + repository: azerothcore/azerothcore-wotlk + ref: 'master' + - uses: actions/checkout@v2 + with: + submodules: false + repository: azerothcore/mod-eluna-lua-engine + path: modules/mod-eluna-lua-engine + - uses: actions/checkout@v2 + with: + path: modules/mod-eluna-lua-engine/LuaEngine + - name: Configure OS + run: | + # Copy paste of https://github.com/azerothcore/azerothcore-wotlk/blob/master/apps/ci/ci-install.sh + + cat >>conf/config.sh <> ./conf/config.sh + echo "CCOMPILERCXX=\"clang++-10\"" >> ./conf/config.sh + - name: Import db + run: source ./apps/ci/ci-import-db.sh + - name: Build + run: source ./apps/ci/ci-compile.sh + - name: Dry run + run: source ./apps/ci/ci-worldserver-dry-run.sh + - name: Check startup errors + run: source ./apps/ci/ci-error-check.sh + + mangos-Eluna: + strategy: + fail-fast: false + matrix: + eluna: [ON, OFF] + patch: [zero, one, two] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + repository: mangos${{ matrix.patch }}/server + ref: master + - uses: actions/checkout@v2 + with: + path: src/modules/Eluna + - name: Configure + env: + ELUNA: ${{ matrix.eluna }} + run: | + mkdir bin + cd bin + cmake .. -DELUNA=$ELUNA -DCMAKE_INSTALL_PREFIX=install -DSOAP=1 -DPLAYERBOTS=0 -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ + cd .. + - name: Build + run: | + cd bin + make -j4 + make install diff --git a/CreatureHooks.cpp b/CreatureHooks.cpp index 1d7afcf..e2bd6d1 100644 --- a/CreatureHooks.cpp +++ b/CreatureHooks.cpp @@ -282,7 +282,7 @@ void Eluna::On_Reset(Creature* me) // Not an override, custom } // Called when hit by a spell -bool Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell) +bool Eluna::SpellHit(Creature* me, WorldObject* caster, SpellInfo const* spell) { START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_HIT_BY_SPELL, me, false); Push(me); @@ -292,7 +292,7 @@ bool Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell) } // Called when spell hits a target -bool Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell) +bool Eluna::SpellHitTarget(Creature* me, WorldObject* target, SpellInfo const* spell) { START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_SPELL_HIT_TARGET, me, false); Push(me); diff --git a/CreatureMethods.h b/CreatureMethods.h index a13ff82..b3db467 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -37,7 +37,7 @@ namespace LuaCreature { uint32 quest_id = Eluna::CHECKVAL(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->hasInvolvedQuest(quest_id)); #else Eluna::Push(L, creature->HasInvolvedQuest(quest_id)); @@ -105,7 +105,7 @@ namespace LuaCreature { Player* player = Eluna::CHECKOBJ(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->isTappedBy(player)); #else Eluna::Push(L, creature->IsTappedBy(player)); @@ -121,7 +121,7 @@ namespace LuaCreature */ int HasLootRecipient(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->hasLootRecipient()); #else Eluna::Push(L, creature->HasLootRecipient()); @@ -137,7 +137,7 @@ namespace LuaCreature */ int CanAggro(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, !creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)); #else // Eluna::Push(L, creature->CanInitiateAttack()); @@ -190,7 +190,7 @@ namespace LuaCreature */ int IsElite(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->isElite()); #else Eluna::Push(L, creature->IsElite()); @@ -242,7 +242,7 @@ namespace LuaCreature */ int IsWorldBoss(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->isWorldBoss()); #else Eluna::Push(L, creature->IsWorldBoss()); @@ -261,12 +261,12 @@ namespace LuaCreature { uint32 spell = Eluna::CHECKVAL(L, 2); -#if defined TRINITY +#if defined(TRINITY) if (const SpellInfo* info = sSpellMgr->GetSpellInfo(spell)) Eluna::Push(L, info->GetCategory() && creature->GetSpellHistory()->HasCooldown(spell)); else Eluna::Push(L, false); -#elif AZEROTHCORE +#elif defined(AZEROTHCORE) if (const SpellInfo* info = sSpellMgr->GetSpellInfo(spell)) Eluna::Push(L, info->GetCategory() && creature->HasSpellCooldown(spell)); else @@ -303,7 +303,7 @@ namespace LuaCreature { uint32 questId = Eluna::CHECKVAL(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->hasQuest(questId)); #else Eluna::Push(L, creature->HasQuest(questId)); @@ -322,7 +322,7 @@ namespace LuaCreature { uint32 spellId = Eluna::CHECKVAL(L, 2); -#ifdef TRINITY +#if defined(TRINITY) Eluna::Push(L, creature->GetSpellHistory()->HasCooldown(spellId)); #else Eluna::Push(L, creature->HasSpellCooldown(spellId)); @@ -342,7 +342,7 @@ namespace LuaCreature return 1; } -#if defined(TRINITY) || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) /** * Returns `true` if the [Creature] is an invisible trigger, * and returns `false` otherwise. @@ -423,7 +423,7 @@ namespace LuaCreature */ int GetWanderRadius(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->GetWanderDistance()); #else Eluna::Push(L, creature->GetRespawnRadius()); @@ -431,7 +431,7 @@ namespace LuaCreature return 1; } -#if defined(TRINITY) || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) /** * Returns the current waypoint path ID of the [Creature]. * @@ -451,9 +451,9 @@ namespace LuaCreature */ int GetCurrentWaypointId(lua_State* L, Creature* creature) { -#ifdef TRINITY +#if defined(TRINITY) Eluna::Push(L, creature->GetCurrentWaypointInfo().first); -#elif AZEROTHCORE +#elif defined(AZEROTHCORE) Eluna::Push(L, creature->GetCurrentWaypointID()); #else Eluna::Push(L, creature->GetMotionMaster()->getLastReachedWaypoint()); @@ -482,7 +482,7 @@ namespace LuaCreature { Unit* target = Eluna::CHECKOBJ(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->GetAggroRange(target)); #else float AttackDist = creature->GetAttackDistance(target); @@ -518,7 +518,7 @@ namespace LuaCreature */ int GetLootRecipientGroup(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->GetLootRecipientGroup()); #else Eluna::Push(L, creature->GetGroupLootRecipient()); @@ -591,12 +591,12 @@ namespace LuaCreature { uint32 spell = Eluna::CHECKVAL(L, 2); -#ifdef TRINITY +#if defined(TRINITY) if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell)) Eluna::Push(L, creature->GetSpellHistory()->GetRemainingCooldown(spellInfo)); else Eluna::Push(L, 0); -#elif AZEROTHCORE +#elif defined(AZEROTHCORE) if (sSpellMgr->GetSpellInfo(spell)) Eluna::Push(L, creature->GetSpellCooldown(spell)); else @@ -630,7 +630,7 @@ namespace LuaCreature int GetHomePosition(lua_State* L, Creature* creature) { float x, y, z, o; -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->GetHomePosition(x, y, z, o); #else creature->GetRespawnCoord(x, y, z, &o); @@ -659,7 +659,7 @@ namespace LuaCreature float z = Eluna::CHECKVAL(L, 4); float o = Eluna::CHECKVAL(L, 5); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->SetHomePosition(x, y, z, o); #else creature->SetRespawnCoord(x, y, z, o); @@ -711,29 +711,30 @@ namespace LuaCreature float dist = Eluna::CHECKVAL(L, 5, 0.0f); int32 aura = Eluna::CHECKVAL(L, 6, 0); -#ifdef CMANGOS +#if defined(CMANGOS) ThreatList const& threatlist = creature->getThreatManager().getThreatList(); -#endif -#ifdef MANGOS +#elif defined(MANGOS) ThreatList const& threatlist = creature->GetThreatManager().getThreatList(); -#endif -#ifdef TRINITY - auto const& threatlist = creature->GetThreatManager().GetThreatenedByMeList(); -#endif -#ifdef AZEROTHCORE +#elif defined(TRINITY) + auto const& threatlist = creature->GetThreatManager().GetSortedThreatList(); +#elif defined(AZEROTHCORE) auto const& threatlist = creature->getThreatManager().getThreatList(); #endif - +#ifndef TRINITY if (threatlist.empty()) return 1; if (position >= threatlist.size()) return 1; - +#endif std::list targetList; +#if defined(TRINITY) + for (ThreatReference const* itr : threatlist) +#else for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) - { -#ifdef TRINITY - Unit* target = itr->second->GetOwner(); +#endif + { +#if defined(TRINITY) + Unit* target = itr->GetVictim(); #else Unit* target = (*itr)->getTarget(); #endif @@ -805,9 +806,9 @@ namespace LuaCreature */ int GetAITargets(lua_State* L, Creature* creature) { -#ifdef TRINITY +#if defined(TRINITY) auto const& threatlist = creature->GetThreatManager().GetThreatenedByMeList(); -#elif defined AZEROTHCORE +#elif defined(AZEROTHCORE) auto const& threatlist = creature->getThreatManager().getThreatList(); #else ThreatList const& threatlist = creature->GetThreatManager().getThreatList(); @@ -817,7 +818,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); uint32 i = 0; for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) { -#ifdef TRINITY +#if defined(TRINITY) Unit* target = itr->second->GetOwner(); #else Unit* target = (*itr)->getTarget(); @@ -839,9 +840,9 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); */ int GetAITargetsCount(lua_State* L, Creature* creature) { -#ifdef TRINITY +#if defined(TRINITY) Eluna::Push(L, creature->GetThreatManager().GetThreatenedByMeList().size()); -#elif AZEROTHCORE +#elif defined(AZEROTHCORE) Eluna::Push(L, creature->getThreatManager().getThreatList().size()); #else Eluna::Push(L, creature->GetThreatManager().getThreatList().size()); @@ -876,7 +877,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); } #endif -#if defined(TRINITY) || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) int GetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { Eluna::Push(L, creature->GetLootMode()); @@ -891,7 +892,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); */ int GetDBTableGUIDLow(lua_State* L, Creature* creature) { -#ifdef TRINITY +#if defined(TRINITY) Eluna::Push(L, creature->GetSpawnId()); #else // on mangos based this is same as lowguid @@ -923,7 +924,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { bool disable = Eluna::CHECKVAL(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->SetDisableGravity(disable); #else creature->SetLevitate(disable); @@ -931,7 +932,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); return 0; } -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) int SetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features { uint16 lootMode = Eluna::CHECKVAL(L, 2); @@ -950,7 +951,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { int32 state = Eluna::CHECKVAL(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->setDeathState((DeathState)state); #else creature->SetDeathState((DeathState)state); @@ -984,7 +985,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); uint32 off_hand = Eluna::CHECKVAL(L, 3); uint32 ranged = Eluna::CHECKVAL(L, 4); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, main_hand); creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, off_hand); creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, ranged); @@ -1005,7 +1006,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { bool allow = Eluna::CHECKVAL(L, 2, true); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) if (allow) creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC); else @@ -1041,10 +1042,10 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); */ int SetInCombatWithZone(lua_State* /*L*/, Creature* creature) { -#if defined AZEROTHCORE +#if defined(AZEROTHCORE) if (creature->IsAIEnabled) creature->AI()->DoZoneInCombat(); -#elif defined TRINITY +#elif defined(TRINITY) if (creature->IsAIEnabled()) creature->AI()->DoZoneInCombat(); #else @@ -1062,7 +1063,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { float dist = Eluna::CHECKVAL(L, 2); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->SetWanderDistance(dist); #else creature->SetRespawnRadius(dist); @@ -1131,7 +1132,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { bool enable = Eluna::CHECKVAL(L, 2, true); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->SetHover(enable); #else // Copy paste from Aura::HandleAuraHover @@ -1143,7 +1144,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); data.Initialize(SMSG_MOVE_UNSET_HOVER, 8 + 4); data << creature->GetPackGUID(); data << uint32(0); -#ifdef CMANGOS +#if defined(CMANGOS) creature->SendMessageToSet(data, true); #else creature->SendMessageToSet(&data, true); @@ -1161,7 +1162,9 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { uint32 msTimeToDespawn = Eluna::CHECKVAL(L, 2, 0); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) + creature->DespawnOrUnsummon(Milliseconds(msTimeToDespawn)); +#elif defined(AZEROTHCORE) creature->DespawnOrUnsummon(msTimeToDespawn); #else creature->ForcedDespawn(msTimeToDespawn); @@ -1192,7 +1195,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); */ int MoveWaypoint(lua_State* /*L*/, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->GetMotionMaster()->MovePath(creature->GetWaypointPath(), true); #else creature->GetMotionMaster()->MoveWaypoint(); @@ -1260,7 +1263,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); */ int SelectVictim(lua_State* L, Creature* creature) { -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) Eluna::Push(L, creature->SelectVictim()); #else Eluna::Push(L, creature->SelectHostileTarget()); @@ -1279,7 +1282,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); uint32 entry = Eluna::CHECKVAL(L, 2); uint32 dataGuidLow = Eluna::CHECKVAL(L, 3, 0); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) creature->UpdateEntry(entry, dataGuidLow ? eObjectMgr->GetCreatureData(dataGuidLow) : NULL); #else creature->UpdateEntry(entry, ALLIANCE, dataGuidLow ? eObjectMgr->GetCreatureData(dataGuidLow) : NULL); @@ -1287,7 +1290,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); return 0; } -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) /** * Resets [Creature]'s loot mode to default */ @@ -1382,7 +1385,7 @@ auto const& threatlist = creature->getThreatManager().getThreatList(); { uint32 entry = creature->GetEntry(); -#if defined TRINITY || AZEROTHCORE +#if defined(TRINITY) || defined(AZEROTHCORE) CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(entry); if (cInfo) Eluna::Push(L, cInfo->family); diff --git a/ElunaCreatureAI.h b/ElunaCreatureAI.h index f813c10..877c936 100644 --- a/ElunaCreatureAI.h +++ b/ElunaCreatureAI.h @@ -217,14 +217,22 @@ struct ElunaCreatureAI : ScriptedAI } // Called when hit by a spell +#if defined TRINITY + void SpellHit(WorldObject* caster, SpellInfo const* spell) override +#else void SpellHit(Unit* caster, SpellInfo const* spell) override +#endif { if (!sEluna->SpellHit(me, caster, spell)) ScriptedAI::SpellHit(caster, spell); } // Called when spell hits a target +#if defined TRINITY + void SpellHitTarget(WorldObject* target, SpellInfo const* spell) override +#else void SpellHitTarget(Unit* target, SpellInfo const* spell) override +#endif { if (!sEluna->SpellHitTarget(me, target, spell)) ScriptedAI::SpellHitTarget(target, spell); diff --git a/ElunaIncludes.h b/ElunaIncludes.h index b9e226e..bf5ac2b 100644 --- a/ElunaIncludes.h +++ b/ElunaIncludes.h @@ -42,8 +42,6 @@ #if defined TRINITY #include "GitRevision.h" #include "SpellHistory.h" -#include -#include #endif #if defined TRINITY || defined AZEROTHCORE diff --git a/ElunaInstanceAI.cpp b/ElunaInstanceAI.cpp index 9f99616..7c0155a 100644 --- a/ElunaInstanceAI.cpp +++ b/ElunaInstanceAI.cpp @@ -9,6 +9,7 @@ #include "lmarshal.h" +#ifndef TRINITY void ElunaInstanceAI::Initialize() { LOCK_ELUNA; @@ -22,6 +23,7 @@ void ElunaInstanceAI::Initialize() sEluna->OnInitialize(this); } +#endif void ElunaInstanceAI::Load(const char* data) { @@ -82,7 +84,9 @@ void ElunaInstanceAI::Load(const char* data) lua_pop(L, 1); // Stack: (empty) +#ifndef TRINITY Initialize(); +#endif } } else @@ -92,7 +96,9 @@ void ElunaInstanceAI::Load(const char* data) lua_pop(L, 1); // Stack: (empty) +#ifndef TRINITY Initialize(); +#endif } delete[] decodedData; @@ -100,7 +106,10 @@ void ElunaInstanceAI::Load(const char* data) else { ELUNA_LOG_ERROR("Error while decoding instance data: Data is not valid base-64"); + +#ifndef TRINITY Initialize(); +#endif } } diff --git a/ElunaInstanceAI.h b/ElunaInstanceAI.h index 2d532f7..e950eaf 100644 --- a/ElunaInstanceAI.h +++ b/ElunaInstanceAI.h @@ -65,7 +65,9 @@ public: { } +#ifndef TRINITY void Initialize() override; +#endif /* * These are responsible for serializing/deserializing the instance's diff --git a/GlobalMethods.h b/GlobalMethods.h index 26a4e5d..332dbb8 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -51,6 +51,24 @@ namespace LuaGlobalFunctions return 1; } + /** + * Returns emulator .conf RealmID + * + * - for MaNGOS returns the realmID as it is stored in the core. + * - for TrinityCore returns the realmID as it is in the conf file. + * @return uint32 realm ID + */ + + int GetRealmID(lua_State* L) + { +#ifdef MANGOS + Eluna::Push(L, realmID); +#else + Eluna::Push(L, sConfigMgr->GetIntDefault("RealmID", 1)); +#endif + return 1; + } + /** * Returns emulator version * @@ -181,7 +199,7 @@ namespace LuaGlobalFunctions #else { #ifdef TRINITY - boost::shared_lock lock(*HashMapHolder::GetLock()); + std::shared_lock lock(*HashMapHolder::GetLock()); #elif defined(AZEROTHCORE) ACORE_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); #else @@ -477,7 +495,11 @@ namespace LuaGlobalFunctions if (!areaEntry) return luaL_argerror(L, 1, "valid Area or Zone ID expected"); +#if defined(TRINITY) + Eluna::Push(L, areaEntry->AreaName[locale]); +#else Eluna::Push(L, areaEntry->area_name[locale]); +#endif return 1; } @@ -2300,10 +2322,10 @@ namespace LuaGlobalFunctions TaxiPathNodeEntry entry; #ifdef TRINITY // mandatory - entry.MapID = Eluna::CHECKVAL(L, start); - entry.LocX = Eluna::CHECKVAL(L, start + 1); - entry.LocY = Eluna::CHECKVAL(L, start + 2); - entry.LocZ = Eluna::CHECKVAL(L, start + 3); + entry.ContinentID = Eluna::CHECKVAL(L, start); + entry.Loc.X = Eluna::CHECKVAL(L, start + 1); + entry.Loc.Y = Eluna::CHECKVAL(L, start + 2); + entry.Loc.Z = Eluna::CHECKVAL(L, start + 3); // optional entry.Flags = Eluna::CHECKVAL(L, start + 4, 0); entry.Delay = Eluna::CHECKVAL(L, start + 5, 0); @@ -2351,10 +2373,10 @@ namespace LuaGlobalFunctions entry.PathID = pathId; entry.NodeIndex = nodeId; nodeEntry->ID = index; - nodeEntry->map_id = entry.MapID; - nodeEntry->x = entry.LocX; - nodeEntry->y = entry.LocY; - nodeEntry->z = entry.LocZ; + nodeEntry->ContinentID = entry.ContinentID; + nodeEntry->Pos.X = entry.Loc.X; + nodeEntry->Pos.Y = entry.Loc.Y; + nodeEntry->Pos.Z = entry.Loc.Z; nodeEntry->MountCreatureID[0] = mountH; nodeEntry->MountCreatureID[1] = mountA; sTaxiNodesStore.SetEntry(nodeId++, nodeEntry); @@ -2381,10 +2403,16 @@ namespace LuaGlobalFunctions return 1; sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); TaxiPathEntry* pathEntry = new TaxiPathEntry(); +#ifdef TRINITY + pathEntry->FromTaxiNode = startNode; + pathEntry->ToTaxiNode = nodeId - 1; + pathEntry->Cost = price; +#else pathEntry->from = startNode; pathEntry->to = nodeId - 1; - pathEntry->ID = pathId; pathEntry->price = price; +#endif + pathEntry->ID = pathId; sTaxiPathStore.SetEntry(pathId, pathEntry); Eluna::Push(L, pathId); return 1; diff --git a/GuildMethods.h b/GuildMethods.h index 16e7433..3a2b6be 100644 --- a/GuildMethods.h +++ b/GuildMethods.h @@ -37,7 +37,7 @@ namespace LuaGuild #else { #ifdef TRINITY - boost::shared_lock lock(*HashMapHolder::GetLock()); + std::shared_lock lock(*HashMapHolder::GetLock()); #elif defined(AZEROTHCORE) ACORE_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); #else diff --git a/ItemMethods.h b/ItemMethods.h index 4aed44e..2dafc3b 100644 --- a/ItemMethods.h +++ b/ItemMethods.h @@ -273,25 +273,41 @@ namespace LuaItem { #if defined(CATA) || defined (MISTS) char* suffix = NULL; +#else +#ifdef TRINITY + std::array const* suffix = NULL; #else char* const* suffix = NULL; +#endif #endif if (itemRandPropId < 0) { const ItemRandomSuffixEntry* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId()); if (itemRandEntry) +#ifdef TRINITY + suffix = &itemRandEntry->Name; +#else suffix = itemRandEntry->nameSuffix; +#endif } else { const ItemRandomPropertiesEntry* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId()); if (itemRandEntry) +#ifdef TRINITY + suffix = &itemRandEntry->Name; +#else suffix = itemRandEntry->nameSuffix; +#endif } if (suffix) { name += ' '; +#if defined TRINITY + name += (*suffix)[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)]; +#else name += suffix[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)]; +#endif } } #endif diff --git a/LuaEngine.h b/LuaEngine.h index f96953d..bc64940 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -393,8 +393,8 @@ public: bool ReceiveEmote(Creature* me, Player* player, uint32 emoteId); bool CorpseRemoved(Creature* me, uint32& respawnDelay); bool MoveInLineOfSight(Creature* me, Unit* who); - bool SpellHit(Creature* me, Unit* caster, SpellInfo const* spell); - bool SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell); + bool SpellHit(Creature* me, WorldObject* caster, SpellInfo const* spell); + bool SpellHitTarget(Creature* me, WorldObject* target, SpellInfo const* spell); bool SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer); bool OwnerAttackedBy(Creature* me, Unit* attacker); bool OwnerAttacked(Creature* me, Unit* target); diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index c3375dd..d5448c9 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -77,6 +77,7 @@ luaL_Reg GlobalMethods[] = // Getters { "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine }, { "GetCoreName", &LuaGlobalFunctions::GetCoreName }, + { "GetRealmID", &LuaGlobalFunctions::GetRealmID }, { "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion }, { "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion }, { "GetQuest", &LuaGlobalFunctions::GetQuest }, @@ -399,7 +400,7 @@ ElunaRegister UnitMethods[] = { "StopSpellCast", &LuaUnit::StopSpellCast }, { "InterruptSpell", &LuaUnit::InterruptSpell }, { "SendChatMessageToPlayer", &LuaUnit::SendChatMessageToPlayer }, - { "Emote", &LuaUnit::Emote }, + { "PerformEmote", &LuaUnit::PerformEmote }, { "EmoteState", &LuaUnit::EmoteState }, { "CountPctFromCurHealth", &LuaUnit::CountPctFromCurHealth }, { "CountPctFromMaxHealth", &LuaUnit::CountPctFromMaxHealth }, @@ -600,6 +601,9 @@ ElunaRegister PlayerMethods[] = // {"HasPendingBind", &LuaPlayer::HasPendingBind}, // :HasPendingBind() - UNDOCUMENTED - Returns true if the player has a pending instance bind #if (!defined(TBC) && !defined(CLASSIC)) { "HasAchieved", &LuaPlayer::HasAchieved }, +#if defined(TRINITY) || defined(AZEROTHCORE) + { "SetAchievement", &LuaPlayer::SetAchievement }, +#endif #endif { "CanUninviteFromGroup", &LuaPlayer::CanUninviteFromGroup }, { "IsRested", &LuaPlayer::IsRested }, diff --git a/MapMethods.h b/MapMethods.h index a9a7799..d1513e6 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -182,6 +182,7 @@ namespace LuaMap * @param float x * @param float y * @param float z + * @param uint32 phasemask = PHASEMASK_NORMAL * @return uint32 areaId */ int GetAreaId(lua_State* L, Map* map) @@ -189,8 +190,11 @@ namespace LuaMap float x = Eluna::CHECKVAL(L, 2); float y = Eluna::CHECKVAL(L, 3); float z = Eluna::CHECKVAL(L, 4); +#if defined TRINITY + float phasemask = Eluna::CHECKVAL(L, 5, PHASEMASK_NORMAL); -#if defined TRINITY || AZEROTHCORE + Eluna::Push(L, map->GetAreaId(phasemask, x, y, z)); +#elif defined AZEROTHCORE Eluna::Push(L, map->GetAreaId(x, y, z)); #else Eluna::Push(L, map->GetTerrain()->GetAreaId(x, y, z)); diff --git a/PlayerMethods.h b/PlayerMethods.h index 10e9034..b581727 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -2057,6 +2057,24 @@ namespace LuaPlayer player->SetTitle(t, false); return 0; } + + +#if defined(TRINITY) || defined(AZEROTHCORE) + /** + * Adds the specified achievement to the [Player]s + * + * @param uint32 achievementid + */ + int SetAchievement(lua_State* L, Player* player) + { + uint32 id = Eluna::CHECKVAL(L, 2); + AchievementEntry const* t = sAchievementStore.LookupEntry(id); + if (t) + player->CompletedAchievement(t); + return 0; + } +#endif + #endif #if !defined TRINITY && !AZEROTHCORE @@ -2262,10 +2280,11 @@ namespace LuaPlayer WorldPacket data(MSG_AUCTION_HELLO, 12); #ifdef TRINITY data << uint64(unit->GetGUID().GetCounter()); + data << uint32(ahEntry->ID); #else data << uint64(unit->GetGUIDLow()); -#endif data << uint32(ahEntry->houseId); +#endif data << uint8(1); #ifdef CMANGOS player->GetSession()->SendPacket(data); @@ -3312,11 +3331,19 @@ namespace LuaPlayer { if (SkillLineEntry const* entry = sSkillLineStore.LookupEntry(i)) { +#ifdef TRINITY + if (entry->CategoryID == SKILL_CATEGORY_LANGUAGES || entry->CategoryID == SKILL_CATEGORY_GENERIC) + continue; + + if (player->HasSkill(entry->ID)) + player->UpdateSkill(entry->ID, step); +#else if (entry->categoryId == SKILL_CATEGORY_LANGUAGES || entry->categoryId == SKILL_CATEGORY_GENERIC) continue; if (player->HasSkill(entry->id)) player->UpdateSkill(entry->id, step); +#endif } } diff --git a/ServerHooks.cpp b/ServerHooks.cpp index b420d35..a11ce6a 100644 --- a/ServerHooks.cpp +++ b/ServerHooks.cpp @@ -116,10 +116,13 @@ bool Eluna::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) { START_HOOK_WITH_RETVAL(TRIGGER_EVENT_ON_TRIGGER, false); Push(pPlayer); -#ifndef AZEROTHCORE - Push(pTrigger->id); -#else +#ifdef TRINITY + Push(pTrigger->ID); +#elif AZEROTHCORE Push(pTrigger->entry); +#else + Push(pTrigger->id); + #endif return CallAllFunctionsBool(ServerEventBindings, key); } diff --git a/UnitMethods.h b/UnitMethods.h index 38d6a40..5c42396 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -1163,7 +1163,11 @@ namespace LuaUnit if (!entry) return 1; +#ifdef TRINITY + Eluna::Push(L, entry->Name[locale]); +#else Eluna::Push(L, entry->name[locale]); +#endif return 1; } @@ -1202,7 +1206,11 @@ namespace LuaUnit if (!entry) return 1; +#ifdef TRINITY + Eluna::Push(L, entry->Name[locale]); +#else Eluna::Push(L, entry->name[locale]); +#endif return 1; } @@ -2033,9 +2041,14 @@ namespace LuaUnit * * @param uint32 emoteId */ - int Emote(lua_State* L, Unit* unit) + int PerformEmote(lua_State* L, Unit* unit) { +#ifdef TRINITY + Emote emote = static_cast(Eluna::CHECKVAL(L, 2)); + unit->HandleEmoteCommand(emote); +#else unit->HandleEmoteCommand(Eluna::CHECKVAL(L, 2)); +#endif return 0; } diff --git a/VehicleMethods.h b/VehicleMethods.h index 6dc78b2..3bbfea5 100644 --- a/VehicleMethods.h +++ b/VehicleMethods.h @@ -53,7 +53,9 @@ namespace LuaVehicle */ int GetEntry(lua_State* L, Vehicle* vehicle) { -#if defined TRINITY || AZEROTHCORE +#ifdef TRINITY + Eluna::Push(L, vehicle->GetVehicleInfo()->ID); +#elif AZEROTHCORE Eluna::Push(L, vehicle->GetVehicleInfo()->m_ID); #else Eluna::Push(L, vehicle->GetVehicleEntry()->m_ID); diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index 6205efe..f52b804 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -717,7 +717,7 @@ namespace LuaWorldObject uint32 respawnDelay = Eluna::CHECKVAL(L, 7, 30); #ifdef TRINITY QuaternionData rot = QuaternionData::fromEulerAnglesZYX(o, 0.f, 0.f); - Eluna::Push(L, obj->SummonGameObject(entry, Position(x, y, z, o), rot, respawnDelay)); + Eluna::Push(L, obj->SummonGameObject(entry, Position(x, y, z, o), rot, Seconds(respawnDelay))); #elif AZEROTHCORE Eluna::Push(L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay)); #else @@ -804,7 +804,11 @@ namespace LuaWorldObject default: return luaL_argerror(L, 7, "valid SpawnType expected"); } +#ifdef TRINITY + Eluna::Push(L, obj->SummonCreature(entry, x, y, z, o, type, Seconds(despawnTimer))); +#else Eluna::Push(L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); +#endif return 1; }