From 020058b395d638871851c3a664a1997a2d9eb02d Mon Sep 17 00:00:00 2001 From: Emagi Date: Sun, 27 Jul 2025 17:40:05 -0400 Subject: [PATCH] LUA Functions Added, AttackAllowed, IsInRaid, InSameRaid, GetRaid AttackAllowed(Spawn, Target, Distance, RangeAttack) Distance default is 0.0f and just checks if you can attack the target. Otherwise distance greater than 0.0f relates to the distance between the Spawn and Target which you first obtain using GetDistance(Spawn, Target). RangeAttack is a boolean (default: false) when true we use range info for the ranged attack min/max distance versus max distance melee combat range. IsInRaid(Spawn, IsLeaderGroup) - Establishes if the Spawn is currently in a raid. IsLeaderGroup is boolean (default: false) returns true if Spawn is the leader group of the raid. InSameRaid(Spawn, Target, IsLeaderGroup) - determines if Spawn and Target are within the same raid groups. IsLeaderGroup is boolean (default: false) returns true if Spawn is the leader group of the raid. GetRaid(Spawn, PlayersOnly) - gets the array of all the members in the raid. PlayersOnly is boolean (default: false), if true we return only clients/players in the list for the raid. --- source/WorldServer/LuaFunctions.cpp | 99 +++++++++++++++++++++++++++++ source/WorldServer/LuaFunctions.h | 4 ++ source/WorldServer/LuaInterface.cpp | 4 ++ 3 files changed, 107 insertions(+) diff --git a/source/WorldServer/LuaFunctions.cpp b/source/WorldServer/LuaFunctions.cpp index 2b72136..253a0a6 100644 --- a/source/WorldServer/LuaFunctions.cpp +++ b/source/WorldServer/LuaFunctions.cpp @@ -14761,4 +14761,103 @@ int EQ2Emu_lua_ShowHouseShopMerchant(lua_State* state) { } return 0; +} + + +int EQ2Emu_lua_AttackAllowed(lua_State* state) { + Spawn* spawn = lua_interface->GetSpawn(state); + Spawn* target = lua_interface->GetSpawn(state, 2); + float distance = lua_interface->GetFloatValue(state, 3); + bool is_range_attack = lua_interface->GetBooleanValue(state, 4); + + lua_interface->ResetFunctionStack(state); + if (spawn && target && spawn->IsEntity() & target->IsEntity()) { + lua_interface->SetBooleanValue(state, ((Entity*)spawn)->AttackAllowed((Entity*)target, distance, is_range_attack)); + } + else { + lua_interface->SetBooleanValue(state, false); + } + return 1; +} + +int EQ2Emu_lua_IsInRaid(lua_State* state) { + Spawn* spawn = lua_interface->GetSpawn(state); + bool is_leader_group = lua_interface->GetBooleanValue(state, 2); + + lua_interface->ResetFunctionStack(state); + if (spawn->IsEntity() && ((Entity*)spawn)->GetGroupMemberInfo()) { + lua_interface->SetBooleanValue(state, world.GetGroupManager()->IsInRaidGroup(((Entity*)spawn)->GetGroupMemberInfo()->group_id, is_leader_group)); + } + else { + lua_interface->SetBooleanValue(state, false); + } + return 1; +} + +int EQ2Emu_lua_InSameRaid(lua_State* state) { + Spawn* spawn = lua_interface->GetSpawn(state); + Spawn* target = lua_interface->GetSpawn(state, 2); + bool is_leader_group = lua_interface->GetBooleanValue(state, 3); + + lua_interface->ResetFunctionStack(state); + if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetGroupMemberInfo() && + target && target->IsEntity() && ((Entity*)target)->GetGroupMemberInfo()) { + lua_interface->SetBooleanValue(state, world.GetGroupManager()->IsInRaidGroup(((Entity*)spawn)->GetGroupMemberInfo()->group_id, ((Entity*)target)->GetGroupMemberInfo()->group_id, is_leader_group)); + } + else { + lua_interface->SetBooleanValue(state, false); + } + return 1; +} + +int EQ2Emu_lua_GetRaid(lua_State* state) { + if (!lua_interface) + return 0; + + Spawn* spawn = lua_interface->GetSpawn(state); + bool players_only = lua_interface->GetBooleanValue(state, 2); + lua_interface->ResetFunctionStack(state); + if (!spawn) { + lua_interface->LogError("%s: LUA GetRaid command error: spawn is not valid", lua_interface->GetScriptName(state)); + return 0; + } + + vector groupMembers; + if (spawn->IsEntity() && ((Entity*)spawn)->GetGroupMemberInfo()) { + std::vector raidGroups; + world.GetGroupManager()->GetRaidGroups(((Entity*)spawn)->GetGroupMemberInfo()->group_id, &raidGroups); + world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__); + if(raidGroups.size() > 0) { + for (size_t i = 0; i < raidGroups.size(); i++) { + PlayerGroup* group = world.GetGroupManager()->GetGroup(raidGroups.at(i)); + deque::iterator itr; + if (group) + { + group->MGroupMembers.readlock(__FUNCTION__, __LINE__); + deque* members = group->GetMembers(); + GroupMemberInfo* info = 0; + for (itr = members->begin(); itr != members->end(); itr++) { + info = *itr; + if (info->client) + groupMembers.push_back(info->client->GetPlayer()); + else if(!players_only && info->member) + groupMembers.push_back((Spawn*)info->member); + } + group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__); + } + } + } + world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__); + } + else + return 0; + + lua_createtable(state, groupMembers.size(), 0); + int newTable = lua_gettop(state); + for (int32 i = 0; i < groupMembers.size(); i++) { + lua_interface->SetSpawnValue(state, groupMembers.at(i)); + lua_rawseti(state, newTable, i + 1); + } + return 1; + } \ No newline at end of file diff --git a/source/WorldServer/LuaFunctions.h b/source/WorldServer/LuaFunctions.h index 4a025da..3d480ec 100644 --- a/source/WorldServer/LuaFunctions.h +++ b/source/WorldServer/LuaFunctions.h @@ -693,4 +693,8 @@ int EQ2Emu_lua_GetPickupItemID(lua_State* state); int EQ2Emu_lua_SetHouseCharacterID(lua_State* state); int EQ2Emu_lua_GetHouseCharacterID(lua_State* state); int EQ2Emu_lua_ShowHouseShopMerchant(lua_State* state); +int EQ2Emu_lua_AttackAllowed(lua_State* state); +int EQ2Emu_lua_IsInRaid(lua_State* state); +int EQ2Emu_lua_InSameRaid(lua_State* state); +int EQ2Emu_lua_GetRaid(lua_State* state); #endif \ No newline at end of file diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index 17a37e8..1f96097 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -1832,6 +1832,10 @@ void LuaInterface::RegisterFunctions(lua_State* state) { lua_register(state,"SetHouseCharacterID", EQ2Emu_lua_SetHouseCharacterID); lua_register(state,"GetHouseCharacterID", EQ2Emu_lua_GetHouseCharacterID); lua_register(state,"ShowHouseShopMerchant", EQ2Emu_lua_ShowHouseShopMerchant); + lua_register(state,"AttackAllowed", EQ2Emu_lua_AttackAllowed); + lua_register(state,"IsInRaid", EQ2Emu_lua_IsInRaid); + lua_register(state,"InSameRaid", EQ2Emu_lua_InSameRaid); + lua_register(state,"GetRaid", EQ2Emu_lua_GetRaid); } void LuaInterface::LogError(const char* error, ...) {