This commit is contained in:
Robert Allen 2023-01-13 04:16:38 -06:00
commit 7757bc249a
4 changed files with 41 additions and 29 deletions

View file

@ -6151,12 +6151,13 @@ void Commands::Command_Grid(Client* client, Seperator* sep)
if(sep->IsNumber(1))
grid = atoul(sep->arg[1]);
std::vector<Spawn*> spawns = client->GetPlayer()->GetZone()->GetSpawnsInGrid(grid);
client->Message(CHANNEL_COLOR_RED, "Grid ID %u has %u spawns.", grid, spawns.size());
for(int i=0;i<spawns.size();i++) {
Spawn* spawn = spawns.at(i);
std::vector<Spawn*>* spawns = client->GetPlayer()->GetZone()->GetSpawnsInGrid(grid);
client->Message(CHANNEL_COLOR_RED, "Grid ID %u has %u spawns.", grid, spawns->size());
for(int i=0;i<spawns->size();i++) {
Spawn* spawn = spawns->at(i);
client->Message(CHANNEL_COLOR_YELLOW, "Spawn %s (%u), Loc X/Y/Z: %f/%f/%f.", spawn->GetName(), spawn->GetID(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
}
safe_delete(spawns);
}
else {
client->Message(CHANNEL_COLOR_YELLOW, "Your Grid ID is %u", client->GetPlayer()->appearance.pos.grid_id);

View file

@ -2522,10 +2522,9 @@ void SpellProcess::GetSpellTargetsTrueAOE(LuaSpell* luaspell) {
}
}
int32 ignore_target = 0;
vector<Spawn*> spawns = luaspell->caster->GetZone()->GetAttackableSpawnsByDistance(luaspell->caster, luaspell->spell->GetSpellData()->radius);
vector<int32> spawns = luaspell->caster->GetZone()->GetAttackableSpawnsByDistance(luaspell->caster, luaspell->spell->GetSpellData()->radius);
luaspell->MSpellTargets.writelock(__FUNCTION__, __LINE__);
for (int8 i = 0; i < spawns.size(); i++) {
Spawn* spawn = spawns.at(i);
if (i == 0){
if (luaspell->initial_target && luaspell->caster->GetID() != luaspell->initial_target){
//this is the "Direct" target and aoe can't be avoided
@ -2535,13 +2534,15 @@ void SpellProcess::GetSpellTargetsTrueAOE(LuaSpell* luaspell) {
if (luaspell->targets.size() >= luaspell->spell->GetSpellData()->max_aoe_targets)
break;
}
int32 target_id = spawns.at(i);
Spawn* spawn = luaspell->caster->GetZone()->GetSpawnByID(target_id);
if(!spawn) {
LogWrite(SPELL__ERROR, 0, "Spell", "Error: Spell target is NULL! SpellProcess::ProcessSpell for Spell '%s' target id %u", (luaspell->spell != nullptr) ? luaspell->spell->GetName() : "Unknown", target_id);
}
//If we have already added this spawn, check the next spawn in the list
if (spawn && spawn->GetID() == ignore_target){
i++;
if (i < spawns.size())
spawn = spawns.at(i);
else
break;
continue;
}
if (spawn){
//If this spawn is immune to aoe, continue

View file

@ -4165,9 +4165,9 @@ void ZoneServer::KillSpawnByDistance(Spawn* spawn, float max_distance, bool incl
return;
Spawn* test_spawn = 0;
std::vector<Spawn*> ret_list = GetSpawnsInGrid(spawn->GetLocation());
std::vector<Spawn*>* ret_list = GetSpawnsInGrid(spawn->GetLocation());
std::vector<Spawn*>::iterator itr;
for (itr = ret_list.begin(); itr != ret_list.end(); itr++) {
for (itr = ret_list->begin(); itr != ret_list->end(); itr++) {
test_spawn = *itr;
if(test_spawn && test_spawn->Alive() && test_spawn->GetID() > 0 && test_spawn->GetID() != spawn->GetID() && test_spawn->IsEntity() &&
(!test_spawn->IsPlayer() || include_players)){
@ -4175,6 +4175,7 @@ void ZoneServer::KillSpawnByDistance(Spawn* spawn, float max_distance, bool incl
KillSpawn(true, test_spawn, spawn, send_packet);
}
}
safe_delete(ret_list);
}
void ZoneServer::SpawnSetByDistance(Spawn* spawn, float max_distance, string field, string value){
@ -4186,9 +4187,9 @@ void ZoneServer::SpawnSetByDistance(Spawn* spawn, float max_distance, string fie
if(type == 0xFFFFFFFF)
return;
std::vector<Spawn*> ret_list = GetSpawnsInGrid(spawn->GetLocation());
std::vector<Spawn*>* ret_list = GetSpawnsInGrid(spawn->GetLocation());
std::vector<Spawn*>::iterator itr;
for (itr = ret_list.begin(); itr != ret_list.end(); itr++) {
for (itr = ret_list->begin(); itr != ret_list->end(); itr++) {
test_spawn = *itr;
if(test_spawn && test_spawn->GetID() > 0 && test_spawn->GetID() != spawn->GetID() && !test_spawn->IsPlayer()){
if(test_spawn->GetDistance(spawn) < max_distance){
@ -4196,6 +4197,7 @@ void ZoneServer::SpawnSetByDistance(Spawn* spawn, float max_distance, string fie
}
}
}
safe_delete(ret_list);
}
void ZoneServer::AddSpawnScriptTimer(SpawnScriptTimer* timer){
@ -7023,17 +7025,25 @@ void ZoneServer::RemovePlayerPassenger(int32 char_id) {
MTransportSpawns.releasereadlock(__FUNCTION__, __LINE__);
}
vector<Spawn*> ZoneServer::GetAttackableSpawnsByDistance(Spawn* caster, float distance) {
vector<Spawn*> ret;
vector<int32> ZoneServer::GetAttackableSpawnsByDistance(Spawn* caster, float distance) {
vector<int32> ret;
Spawn* spawn = 0;
std::vector<Spawn*> ret_list = GetSpawnsInGrid(caster->GetLocation());
std::vector<Spawn*>::iterator itr;
for (itr = ret_list.begin(); itr != ret_list.end(); itr++) {
spawn = *itr;
if (spawn && spawn->IsNPC() && spawn->appearance.attackable > 0 && spawn->GetID() > 0 && spawn->GetID() != caster->GetID() &&
spawn->Alive() && spawn->GetDistance(caster, true) <= distance)
ret.push_back(spawn);
std::shared_lock lock(MGridMaps);
std::map<int32, GridMap*>::iterator grids = grid_maps.find(caster->GetLocation());
if(grids != grid_maps.end()) {
grids->second->MSpawns.lock();
typedef map <int32, Spawn*> SpawnMapType;
for( SpawnMapType::iterator it = grids->second->spawns.begin(); it != grids->second->spawns.end(); ++it ) {
Spawn* spawn = it->second;
if (spawn && spawn->IsNPC() && spawn->appearance.attackable > 0 && spawn->GetID() > 0 && spawn->GetID() != caster->GetID() &&
spawn->Alive() && spawn->GetDistance(caster, true) <= distance) {
ret.push_back(spawn->GetID());
}
}
grids->second->MSpawns.unlock();
}
return ret;
}
@ -8552,8 +8562,8 @@ int32 ZoneServer::GetSpawnCountInGrid(int32 grid_id) {
return count;
}
std::vector<Spawn*> ZoneServer::GetSpawnsInGrid(int32 grid_id) {
std::vector<Spawn*> ret;
std::vector<Spawn*>* ZoneServer::GetSpawnsInGrid(int32 grid_id) {
std::vector<Spawn*>* ret = new std::vector<Spawn*>();
int32 count = 0;
std::shared_lock lock(MGridMaps);
std::map<int32, GridMap*>::iterator grids = grid_maps.find(grid_id);
@ -8561,7 +8571,7 @@ std::vector<Spawn*> ZoneServer::GetSpawnsInGrid(int32 grid_id) {
grids->second->MSpawns.lock();
typedef map <int32, Spawn*> SpawnMapType;
for( SpawnMapType::iterator it = grids->second->spawns.begin(); it != grids->second->spawns.end(); ++it ) {
ret.push_back( it->second );
ret->push_back( it->second );
}
grids->second->MSpawns.unlock();
}

View file

@ -441,7 +441,7 @@ public:
Client* GetClientByCharID(int32 charid);
/// <summary>Gets spawns for a true AoE spell</summary>
vector<Spawn*> GetAttackableSpawnsByDistance(Spawn* spawn, float distance);
vector<int32> GetAttackableSpawnsByDistance(Spawn* spawn, float distance);
void StartZoneSpawnsForLevelThread(Client* client);
@ -713,7 +713,7 @@ public:
void AddSpawnToGrid(Spawn* spawn, int32 grid_id);
void RemoveSpawnFromGrid(Spawn* spawn, int32 grid_id);
int32 GetSpawnCountInGrid(int32 grid_id);
std::vector<Spawn*> GetSpawnsInGrid(int32 grid_id);
std::vector<Spawn*>* GetSpawnsInGrid(int32 grid_id);
private:
#ifndef WIN32
pthread_t ZoneThread;