11 Commits

Author SHA1 Message Date
382ba03e4f Merge branch 'npcbots_3.3.5' 2024-08-15 21:56:25 -04:00
Kitzunu
ec0dbf76f3 Update LuaEngine.cpp (#192) 2024-08-10 11:40:16 -03:00
Kitzunu
68d0a09143 https://github.com/azerothcore/azerothcore-wotlk/pull/19491 (#189)
Co-authored-by: 55Honey <71938210+55Honey@users.noreply.github.com>
2024-08-08 21:36:23 -03:00
sudlud
b39869a556 Fix unused variable warning in GlobalMethods:Ban() (#183) 2024-07-07 17:10:45 +02:00
sudlud
e00386fa5b fix OnBeforeCreateInstanceScript() hook (#182) 2024-07-03 23:01:03 +02:00
AnchyDev
c652ee8e1a Update OnCommand for core hook changes. (#181) 2024-06-17 22:27:48 +02:00
Tralenor
36e1c715fc fix: gossip menu item overflow (#180)
Co-authored-by: 55Honey <71938210+55Honey@users.noreply.github.com>
2024-06-15 13:11:46 +02:00
Tralenor
3fea22bc41 feat: add player:RunCommand (#176) 2024-06-15 11:34:57 +02:00
Tralenor
067fa20bad feature: Add GetGlyph (#178)
Co-authored-by: 55Honey <71938210+55Honey@users.noreply.github.com>
2024-06-11 21:24:00 +02:00
Foe
cc442de602 feat: Add multistate compatibility methods (#175) 2024-06-05 06:19:41 +02:00
kabigon
152a491663 feat: add GetRank method for creatures (#173) 2024-05-04 21:23:51 +02:00
6 changed files with 115 additions and 15 deletions

View File

@@ -237,10 +237,10 @@ class Eluna_AllMapScript : public AllMapScript
public:
Eluna_AllMapScript() : AllMapScript("Eluna_AllMapScript") { }
void OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript* instanceData, bool /*load*/, std::string /*data*/, uint32 /*completedEncounterMask*/) override
{
instanceData = sEluna->GetInstanceData(instanceMap);
if (instanceData)
*instanceData = sEluna->GetInstanceData(instanceMap);
}
void OnDestroyInstance(MapInstanced* /*mapInstanced*/, Map* map) override
@@ -331,7 +331,7 @@ class Eluna_CommandSC : public CommandSC
public:
Eluna_CommandSC() : CommandSC("Eluna_CommandSC") { }
bool CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr) override
bool OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr) override
{
if (!sEluna->OnCommand(handler, std::string(cmdStr).c_str()))
{

View File

@@ -1213,6 +1213,17 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
return 1;
}
/**
* Returns the [Creature]'s rank.
*
* @return [Rank] rank
*/
int GetRank(lua_State* L, Creature* creature)
{
Eluna::Push(L, creature->GetCreatureTemplate()->rank);
return 1;
}
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
/**
* Returns the [Creature]'s shield block value.

View File

@@ -112,6 +112,42 @@ namespace LuaGlobalFunctions
#endif
return 1;
}
/**
* Returns the [Map] pointer of the Lua state. Returns null for the "World" state.
*
* @return [Map] map
*/
int GetStateMap(lua_State* L)
{
// Until AC supports multistate, this will always return nil
Eluna::Push(L);
return 1;
}
/**
* Returns the map ID of the Lua state. Returns -1 for the "World" state.
*
* @return int32 mapId
*/
int GetStateMapId(lua_State* L)
{
// Until AC supports multistate, this will always return -1
Eluna::Push(L, -1);
return 1;
}
/**
* Returns the instance ID of the Lua state. Returns 0 for continent maps and the world state.
*
* @return uint32 instanceId
*/
int GetStateInstanceId(lua_State* L)
{
// Until AC supports multistate, this will always return 0
Eluna::Push(L, 0);
return 1;
}
/**
* Returns [Quest] template
@@ -2123,8 +2159,6 @@ namespace LuaGlobalFunctions
const int BAN_CHARACTER = 1;
const int BAN_IP = 2;
BanMode mode = BanMode::BAN_ACCOUNT;
switch (banMode)
{
case BAN_ACCOUNT:
@@ -2135,26 +2169,20 @@ namespace LuaGlobalFunctions
if (!AccountMgr::normalizeString(nameOrIP))
return luaL_argerror(L, 2, "invalid account name");
#endif
mode = BanMode::BAN_ACCOUNT;
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
return luaL_argerror(L, 2, "invalid character name");
mode = BanMode::BAN_CHARACTER;
break;
case BAN_IP:
if (!IsIPAddress(nameOrIP.c_str()))
return luaL_argerror(L, 2, "invalid ip");
mode = BanMode::BAN_IP;
break;
default:
return luaL_argerror(L, 1, "unknown banmode");
}
BanReturn result;
#ifndef AZEROTHCORE
result = eWorld->BanAccount(mode, nameOrIP, duration, reason, whoBanned);
#else
switch (banMode)
{
case BAN_ACCOUNT:
@@ -2167,7 +2195,6 @@ namespace LuaGlobalFunctions
result = sBan->BanIP(nameOrIP, std::to_string(duration) + "s", reason, whoBanned);
break;
}
#endif
switch (result)
{
@@ -2565,6 +2592,18 @@ namespace LuaGlobalFunctions
return 1;
}
/**
* Returns `true` if Eluna is in compatibility mode, `false` if in multistate.
*
* @return bool isCompatibilityMode
*/
int IsCompatibilityMode(lua_State* L)
{
// Until AC supports multistate, this will always return true
Eluna::Push(L, true);
return 1;
}
/**
* Returns `true` if the bag and slot is a valid inventory position, otherwise `false`.
*

View File

@@ -7,6 +7,7 @@
#include "Hooks.h"
#include "LuaEngine.h"
#include "BindingMap.h"
#include "Chat.h"
#include "ElunaEventMgr.h"
#include "ElunaIncludes.h"
#include "ElunaTemplate.h"
@@ -136,7 +137,7 @@ void Eluna::_ReloadEluna()
if (eConfigMgr->GetOption<bool>("Eluna.PlayerAnnounceReload", false))
eWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna...");
else
eWorld->SendGMText(SERVER_MSG_STRING, "Reloading Eluna...");
ChatHandler(nullptr).SendGMText(SERVER_MSG_STRING, "Reloading Eluna...");
// Remove all timed events
sEluna->eventMgr->SetStates(LUAEVENT_STATE_ERASE);

View File

@@ -84,6 +84,9 @@ luaL_Reg GlobalMethods[] =
{ "GetRealmID", &LuaGlobalFunctions::GetRealmID },
{ "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion },
{ "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion },
{ "GetStateMap", &LuaGlobalFunctions::GetStateMap },
{ "GetStateMapId", &LuaGlobalFunctions::GetStateMapId },
{ "GetStateInstanceId", &LuaGlobalFunctions::GetStateInstanceId },
{ "GetQuest", &LuaGlobalFunctions::GetQuest },
{ "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID },
{ "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName },
@@ -118,6 +121,7 @@ luaL_Reg GlobalMethods[] =
{ "GetActiveGameEvents", &LuaGlobalFunctions::GetActiveGameEvents },
// Boolean
{ "IsCompatibilityMode", &LuaGlobalFunctions::IsCompatibilityMode },
{ "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos },
{ "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos },
{ "IsBankPos", &LuaGlobalFunctions::IsBankPos },
@@ -701,7 +705,10 @@ ElunaRegister<Player> PlayerMethods[] =
{ "ModifyMoney", &LuaPlayer::ModifyMoney },
{ "LearnSpell", &LuaPlayer::LearnSpell },
{ "LearnTalent", &LuaPlayer::LearnTalent },
{ "RunCommand", &LuaPlayer::RunCommand },
{ "SetGlyph", &LuaPlayer::SetGlyph },
{ "GetGlyph", &LuaPlayer::GetGlyph },
#if !defined(CLASSIC)
{ "RemoveArenaSpellCooldowns", &LuaPlayer::RemoveArenaSpellCooldowns },
#endif
@@ -831,6 +838,7 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "GetUnitFlags", &LuaCreature::GetUnitFlags },
{ "GetUnitFlagsTwo", &LuaCreature::GetUnitFlagsTwo },
{ "GetExtraFlags", &LuaCreature::GetExtraFlags },
{ "GetRank", &LuaCreature::GetRank },
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
{ "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue },
#endif

View File

@@ -7,7 +7,9 @@
#ifndef PLAYERMETHODS_H
#define PLAYERMETHODS_H
#include "Chat.h"
#include "GameTime.h"
#include "GossipDef.h"
/***
* Inherits all methods from: [Object], [WorldObject], [Unit]
@@ -3802,7 +3804,7 @@ namespace LuaPlayer
{
std::string msg = Eluna::CHECKVAL<std::string>(L, 2);
if (msg.length() > 0)
player->GetSession()->SendNotification("%s", msg.c_str());
ChatHandler(player->GetSession()).SendNotification("{}", msg);
return 0;
}
@@ -3935,6 +3937,25 @@ namespace LuaPlayer
#endif
return 0;
}
/**
* Run a chat command as if the player typed it into the chat
*
* @param string command: text to display in chat or console
*/
int RunCommand(lua_State* L, Player* player)
{
auto command = Eluna::CHECKVAL<std::string>(L, 2);
// In _ParseCommands which is used below no leading . or ! is allowed for the command string.
if (command[0] == '.' || command[0] == '!') {
command = command.substr(1);
}
auto handler = ChatHandler(player->GetSession());
handler._ParseCommands(command);
return 0;
}
/**
* Adds a glyph specified by `glyphId` to the [Player]'s current talent specialization into the slot with the index `slotIndex`
@@ -3953,6 +3974,18 @@ namespace LuaPlayer
return 0;
}
/**
* Get glyphId of the glyph slot specified by `slotIndex` off the [Player]'s current talent specialization.`
* @param uint32 slotIndex
* @return glyphId of the glyph in the selected glyph slot or 0 in case the glyph slot is empty
*/
int GetGlyph(lua_State* L, Player* player)
{
auto slotIndex = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L,player->GetGlyph(slotIndex));
return 1;
}
#if !defined(CLASSIC)
/**
* Remove cooldowns on spells that have less than 10 minutes of cooldown from the [Player], similarly to when you enter an arena.
@@ -4007,7 +4040,15 @@ namespace LuaPlayer
const char* _promptMsg = Eluna::CHECKVAL<const char*>(L, 7, "");
uint32 _money = Eluna::CHECKVAL<uint32>(L, 8, 0);
#if defined TRINITY || AZEROTHCORE
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, _icon, msg, _sender, _intid, _promptMsg, _money, _code);
if (player->PlayerTalkClass->GetGossipMenu().GetMenuItemCount() < GOSSIP_MAX_MENU_ITEMS)
{
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, _icon, msg, _sender, _intid, _promptMsg, _money,
_code);
}
else
{
return luaL_error(L, "GossipMenuItem not added. Reached Max amount of possible GossipMenuItems in this GossipMenu");
}
#else
#ifndef CLASSIC
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _money, _code);