diff --git a/common/eq_constants.h b/common/eq_constants.h index 6c3e28da0..4cc61c0b4 100644 --- a/common/eq_constants.h +++ b/common/eq_constants.h @@ -459,4 +459,9 @@ enum ChatChannelNames : uint16 ChatChannel_Emotes = 22 }; +namespace ZoneBlockedSpellTypes { + const uint8 ZoneWide = 1; + const uint8 Region = 2; +}; + #endif /*COMMON_EQ_CONSTANTS_H*/ diff --git a/zone/api_service.cpp b/zone/api_service.cpp index b8ae1149e..807b7fd6c 100644 --- a/zone/api_service.cpp +++ b/zone/api_service.cpp @@ -803,7 +803,7 @@ Json::Value ApiGetZoneAttributes(EQ::Net::WebsocketServerConnection *connection, row["mobs_aggro_count"] = zone->MobsAggroCount(); row["save_zone_cfg"] = zone->SaveZoneCFG(); row["short_name"] = zone->GetShortName(); - row["total_blocked_spells"] = zone->GetTotalBlockedSpells(); + row["total_blocked_spells"] = zone->GetZoneTotalBlockedSpells(); row["zone_id"] = zone->GetZoneID(); row["zone_type"] = zone->GetZoneType(); diff --git a/zone/zone.cpp b/zone/zone.cpp index 789f400ea..1804e311f 100755 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -822,11 +822,11 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name) Weather_Timer = new Timer(60000); Weather_Timer->Start(); Log(Logs::General, Logs::None, "The next weather check for zone: %s will be in %i seconds.", short_name, Weather_Timer->GetRemainingTime()/1000); - zone_weather = 0; - weather_intensity = 0; - blocked_spells = nullptr; - totalBS = 0; - zone_has_current_time = false; + zone_weather = 0; + weather_intensity = 0; + blocked_spells = nullptr; + zone_total_blocked_spells = 0; + zone_has_current_time = false; Instance_Shutdown_Timer = nullptr; bool is_perma = false; @@ -972,7 +972,7 @@ bool Zone::Init(bool iStaticZone) { //load up the zone's doors (prints inside) zone->LoadZoneDoors(zone->GetShortName(), zone->GetInstanceVersion()); - zone->LoadBlockedSpells(zone->GetZoneID()); + zone->LoadZoneBlockedSpells(zone->GetZoneID()); //clear trader items if we are loading the bazaar if(strncasecmp(short_name,"bazaar",6)==0) { @@ -1880,17 +1880,21 @@ bool ZoneDatabase::GetDecayTimes(npcDecayTimes_Struct *npcCorpseDecayTimes) return true; } -void Zone::weatherSend(Client* client) +void Zone::weatherSend(Client *client) { auto outapp = new EQApplicationPacket(OP_Weather, 8); - if(zone_weather>0) - outapp->pBuffer[0] = zone_weather-1; - if(zone_weather>0) + if (zone_weather > 0) { + outapp->pBuffer[0] = zone_weather - 1; + } + if (zone_weather > 0) { outapp->pBuffer[4] = zone->weather_intensity; - if (client) + } + if (client) { client->QueuePacket(outapp); - else + } + else { entity_list.QueueClients(0, outapp); + } safe_delete(outapp); } @@ -1908,15 +1912,13 @@ void Zone::SetGraveyard(uint32 zoneid, const glm::vec4& graveyardPosition) { m_Graveyard = graveyardPosition; } -void Zone::LoadBlockedSpells(uint32 zoneid) +void Zone::LoadZoneBlockedSpells(uint32 zone_id) { - if(!blocked_spells) - { - totalBS = database.GetBlockedSpellsCount(zoneid); - if(totalBS > 0){ - blocked_spells = new ZoneSpellsBlocked[totalBS]; - if(!database.LoadBlockedSpells(totalBS, blocked_spells, zoneid)) - { + if (!blocked_spells) { + zone_total_blocked_spells = database.GetBlockedSpellsCount(zone_id); + if (zone_total_blocked_spells > 0) { + blocked_spells = new ZoneSpellsBlocked[zone_total_blocked_spells]; + if (!database.LoadBlockedSpells(zone_total_blocked_spells, blocked_spells, zone_id)) { Log(Logs::General, Logs::Error, "... Failed to load blocked spells."); ClearBlockedSpells(); } @@ -1926,93 +1928,89 @@ void Zone::LoadBlockedSpells(uint32 zoneid) void Zone::ClearBlockedSpells() { - if(blocked_spells){ + if (blocked_spells) { safe_delete_array(blocked_spells); - totalBS = 0; + zone_total_blocked_spells = 0; } } -bool Zone::IsSpellBlocked(uint32 spell_id, const glm::vec3& location) +bool Zone::IsSpellBlocked(uint32 spell_id, const glm::vec3 &location) { - if (blocked_spells) - { + if (blocked_spells) { bool exception = false; bool block_all = false; - for (int x = 0; x < totalBS; x++) - { - if (blocked_spells[x].spellid == spell_id) - { + + for (int x = 0; x < GetZoneTotalBlockedSpells(); x++) { + if (blocked_spells[x].spellid == spell_id) { exception = true; } - if (blocked_spells[x].spellid == 0) - { + if (blocked_spells[x].spellid == 0) { block_all = true; } } - // If all spells are blocked and this is an exception, it is not blocked - if (block_all && exception) - { - return false; - } + // If all spells are blocked and this is an exception, it is not blocked + if (block_all && exception) { + return false; + } - for (int x = 0; x < totalBS; x++) - { - // Spellid of 0 matches all spells - if (0 != blocked_spells[x].spellid && spell_id != blocked_spells[x].spellid) - { + for (int x = 0; x < GetZoneTotalBlockedSpells(); x++) { + // Spellid of 0 matches all spells + if (0 != blocked_spells[x].spellid && spell_id != blocked_spells[x].spellid) { continue; } - switch (blocked_spells[x].type) - { - case 1: - { + switch (blocked_spells[x].type) { + case ZoneBlockedSpellTypes::ZoneWide: { return true; break; } - case 2: - { - if (IsWithinAxisAlignedBox(location, blocked_spells[x].m_Location - blocked_spells[x].m_Difference, blocked_spells[x].m_Location + blocked_spells[x].m_Difference)) + case ZoneBlockedSpellTypes::Region: { + if (IsWithinAxisAlignedBox( + location, + blocked_spells[x].m_Location - blocked_spells[x].m_Difference, + blocked_spells[x].m_Location + blocked_spells[x].m_Difference + )) { return true; + } break; } - default: - { + default: { continue; break; } } } } + return false; } -const char* Zone::GetSpellBlockedMessage(uint32 spell_id, const glm::vec3& location) +const char *Zone::GetSpellBlockedMessage(uint32 spell_id, const glm::vec3 &location) { - if(blocked_spells) - { - for(int x = 0; x < totalBS; x++) - { - if(spell_id != blocked_spells[x].spellid && blocked_spells[x].spellid != 0) + if (blocked_spells) { + for (int x = 0; x < GetZoneTotalBlockedSpells(); x++) { + if (spell_id != blocked_spells[x].spellid && blocked_spells[x].spellid != 0) { continue; + } - switch(blocked_spells[x].type) - { - case 1: - { + switch (blocked_spells[x].type) { + case ZoneBlockedSpellTypes::ZoneWide: { return blocked_spells[x].message; break; } - case 2: - { - if(IsWithinAxisAlignedBox(location, blocked_spells[x].m_Location - blocked_spells[x].m_Difference, blocked_spells[x].m_Location + blocked_spells[x].m_Difference)) + case ZoneBlockedSpellTypes::Region: { + if (IsWithinAxisAlignedBox( + location, + blocked_spells[x].m_Location - blocked_spells[x].m_Difference, + blocked_spells[x].m_Location + blocked_spells[x].m_Difference + )) { return blocked_spells[x].message; + } break; } - default: - { + default: { continue; break; } diff --git a/zone/zone.h b/zone/zone.h index 176fe0cb3..c6da2642e 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -162,7 +162,7 @@ public: inline void SetZoneHasCurrentTime(bool time) { zone_has_current_time = time; } inline void ShowNPCGlobalLoot(Client *to, NPC *who) { m_global_loot.ShowNPCGlobalLoot(to, who); } inline void ShowZoneGlobalLoot(Client *to) { m_global_loot.ShowZoneGlobalLoot(to); } - int GetTotalBlockedSpells() { return totalBS; } + int GetZoneTotalBlockedSpells() { return zone_total_blocked_spells; } int SaveTempItem(uint32 merchantid, uint32 npcid, uint32 item, int32 charges, bool sold = false); int32 MobsAggroCount() { return aggroedmobs; } @@ -234,7 +234,7 @@ public: void LoadAdventureFlavor(); void LoadAlternateAdvancement(); void LoadAlternateCurrencies(); - void LoadBlockedSpells(uint32 zoneid); + void LoadZoneBlockedSpells(uint32 zone_id); void LoadLDoNTrapEntries(); void LoadLDoNTraps(); void LoadLevelEXPMods(); @@ -348,7 +348,7 @@ private: glm::vec3 m_SafePoint; glm::vec4 m_Graveyard; int default_ruleset; - int totalBS; + int zone_total_blocked_spells; int npc_position_update_distance; int32 aggroedmobs; uint8 zone_type;