|
| 1 | +/* |
| 2 | +* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> |
| 3 | +* This program is free software licensed under GPL version 3 |
| 4 | +* Please see the included DOCS/LICENSE.md for more information |
| 5 | +*/ |
| 6 | + |
| 7 | +// Eluna |
| 8 | +#include "ElunaIncludes.h" |
| 9 | +#include "ElunaTemplate.h" |
| 10 | + |
| 11 | +#if defined TRACKABLE_PTR_NAMESPACE |
| 12 | +ElunaConstrainedObjectRef<Aura> GetWeakPtrFor(Aura const* obj) |
| 13 | +{ |
| 14 | +#if defined ELUNA_TRINITY |
| 15 | + Map* map = obj->GetOwner()->GetMap(); |
| 16 | +#elif defined ELUNA_CMANGOS |
| 17 | + Map* map = obj->GetTarget()->GetMap(); |
| 18 | +#endif |
| 19 | + return { obj->GetWeakPtr(), map }; |
| 20 | +} |
| 21 | +ElunaConstrainedObjectRef<BattleGround> GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; } |
| 22 | +ElunaConstrainedObjectRef<Group> GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; } |
| 23 | +ElunaConstrainedObjectRef<Guild> GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; } |
| 24 | +ElunaConstrainedObjectRef<Map> GetWeakPtrFor(Map const* obj) { return { obj->GetWeakPtr(), obj }; } |
| 25 | +ElunaConstrainedObjectRef<Object> GetWeakPtrForObjectImpl(Object const* obj) |
| 26 | +{ |
| 27 | + if (obj->isType(TYPEMASK_WORLDOBJECT)) |
| 28 | + return { obj->GetWeakPtr(), static_cast<WorldObject const*>(obj)->GetMap() }; |
| 29 | + |
| 30 | + if (obj->GetTypeId() == TYPEID_ITEM) |
| 31 | + if (Player const* player = static_cast<Item const*>(obj)->GetOwner()) |
| 32 | + return { obj->GetWeakPtr(), player->GetMap() }; |
| 33 | + |
| 34 | + // possibly dangerous item |
| 35 | + return { obj->GetWeakPtr(), nullptr }; |
| 36 | +} |
| 37 | +ElunaConstrainedObjectRef<Quest> GetWeakPtrFor(Quest const* obj) { return { obj->GetWeakPtr(), nullptr }; } |
| 38 | +ElunaConstrainedObjectRef<Spell> GetWeakPtrFor(Spell const* obj) { return { obj->GetWeakPtr(), obj->GetCaster()->GetMap() }; } |
| 39 | +#if ELUNA_EXPANSION >= EXP_WOTLK |
| 40 | +ElunaConstrainedObjectRef<Vehicle> GetWeakPtrFor(Vehicle const* obj) |
| 41 | +{ |
| 42 | +#if defined ELUNA_TRINITY |
| 43 | + Map* map = obj->GetBase()->GetMap(); |
| 44 | +#elif defined ELUNA_CMANGOS |
| 45 | + Map* map = obj->GetOwner()->GetMap(); |
| 46 | +#endif |
| 47 | + return { obj->GetWeakPtr(), map }; |
| 48 | +} |
| 49 | +#endif |
| 50 | +#endif |
| 51 | + |
| 52 | +template<> inline int ElunaTemplate<unsigned long long>::Add(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::plus()); } |
| 53 | +template<> inline int ElunaTemplate<unsigned long long>::Subtract(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::minus()); } |
| 54 | +template<> inline int ElunaTemplate<unsigned long long>::Multiply(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::multiplies()); } |
| 55 | +template<> inline int ElunaTemplate<unsigned long long>::Divide(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::divides()); } |
| 56 | +template<> inline int ElunaTemplate<unsigned long long>::Mod(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::modulus()); } |
| 57 | +template<> inline int ElunaTemplate<unsigned long long>::Equal(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::equal_to()); } |
| 58 | +template<> inline int ElunaTemplate<unsigned long long>::Less(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::less()); } |
| 59 | +template<> inline int ElunaTemplate<unsigned long long>::LessOrEqual(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::PerformOp(L, std::less_equal()); } |
| 60 | +template<> inline int ElunaTemplate<unsigned long long>::ToString(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::ToString(L); } |
| 61 | +template<> inline int ElunaTemplate<unsigned long long>::Pow(lua_State* L) { return ElunaTemplateHelper<unsigned long long>::Pow(L); } |
| 62 | + |
| 63 | +template<> inline int ElunaTemplate<long long>::Add(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::plus()); } |
| 64 | +template<> inline int ElunaTemplate<long long>::Subtract(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::minus()); } |
| 65 | +template<> inline int ElunaTemplate<long long>::Multiply(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::multiplies()); } |
| 66 | +template<> inline int ElunaTemplate<long long>::Divide(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::divides()); } |
| 67 | +template<> inline int ElunaTemplate<long long>::Mod(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::modulus()); } |
| 68 | +template<> inline int ElunaTemplate<long long>::UnaryMinus(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::negate()); } |
| 69 | +template<> inline int ElunaTemplate<long long>::Equal(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::equal_to()); } |
| 70 | +template<> inline int ElunaTemplate<long long>::Less(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::less()); } |
| 71 | +template<> inline int ElunaTemplate<long long>::LessOrEqual(lua_State* L) { return ElunaTemplateHelper<long long>::PerformOp(L, std::less_equal()); } |
| 72 | +template<> inline int ElunaTemplate<long long>::ToString(lua_State* L) { return ElunaTemplateHelper<long long>::ToString(L); } |
| 73 | +template<> inline int ElunaTemplate<long long>::Pow(lua_State* L) { return ElunaTemplateHelper<long long>::Pow(L); } |
| 74 | + |
| 75 | +template<> inline int ElunaTemplate<ObjectGuid>::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<ObjectGuid>(1) == E->CHECKVAL<ObjectGuid>(2)); return 1; } |
| 76 | +template<> inline int ElunaTemplate<ObjectGuid>::ToString(lua_State* L) |
| 77 | +{ |
| 78 | + Eluna* E = Eluna::GetEluna(L); |
| 79 | +#if defined ELUNA_TRINITY |
| 80 | + E->Push(E->CHECKVAL<ObjectGuid>(1).ToString()); |
| 81 | +#else |
| 82 | + E->Push(E->CHECKVAL<ObjectGuid>(1).GetString()); |
| 83 | +#endif |
| 84 | + return 1; |
| 85 | +} |
0 commit comments