[Feature] Add Expansion and Content Flag support to Blocked Spells (#3638)

* [Feature] Add Expansion and Content Flag support to Blocked Spells

# Notes
- Allows operators to filter blocked spells behind expansions or content flags.
- Requested in https://github.com/EQEmu/Server/issues/3582

* [Tradeskills] Add learned_by_item_id field (#3637)

* [Feature] Add Expansion and Content Flag support to Blocked Spells

- Allows operators to filter blocked spells behind expansions or content flags.
- Requested in https://github.com/EQEmu/Server/issues/3582

---------

Co-authored-by: Chris Miles <akkadius1@gmail.com>
This commit is contained in:
Alex King 2023-10-20 18:45:58 -04:00 committed by GitHub
parent 0667fe435f
commit 52d64781b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 40 deletions

View File

@ -4967,6 +4967,20 @@ ALTER TABLE `items`
.sql = R"(
ALTER TABLE `tradeskill_recipe`
ADD COLUMN `learned_by_item_id` int(11) NOT NULL DEFAULT 0 AFTER `must_learn`;
)"
},
ManifestEntry{
.version = 9239,
.description = "2023_10_18_blocked_spells_expansions_content_flags.sql",
.check = "SHOW COLUMNS FROM `blocked_spells` LIKE 'min_expansion'",
.condition = "",
.match = "empty",
.sql = R"(
ALTER TABLE `blocked_spells`
ADD COLUMN `min_expansion` tinyint(4) NOT NULL DEFAULT -1 AFTER `description`,
ADD COLUMN `max_expansion` tinyint(4) NOT NULL DEFAULT -1 AFTER `min_expansion`,
ADD COLUMN `content_flags` varchar(100) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL AFTER `max_expansion`,
ADD COLUMN `content_flags_disabled` varchar(100) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL AFTER `content_flags`;
)"
},

View File

@ -42,7 +42,7 @@
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/
#define CURRENT_BINARY_DATABASE_VERSION 9238
#define CURRENT_BINARY_DATABASE_VERSION 9239
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9040

View File

@ -2197,12 +2197,21 @@ void Zone::LoadZoneBlockedSpells()
if (zone_total_blocked_spells > 0) {
blocked_spells = new ZoneSpellsBlocked[zone_total_blocked_spells];
if (!content_db.LoadBlockedSpells(zone_total_blocked_spells, blocked_spells, GetZoneID())) {
LogError(" Failed to load blocked spells");
LogError(
"Failed to load blocked spells for {} ({}).",
zone_store.GetZoneName(GetZoneID(), true),
GetZoneID()
);
ClearBlockedSpells();
}
}
LogInfo("Loaded [{}] blocked spells(s)", Strings::Commify(zone_total_blocked_spells));
LogInfo(
"Loaded [{}] blocked spells(s) for {} ({}).",
Strings::Commify(zone_total_blocked_spells),
zone_store.GetZoneName(GetZoneID(), true),
GetZoneID()
);
}
}

View File

@ -11,6 +11,7 @@
#include "zone.h"
#include "zonedb.h"
#include "aura.h"
#include "../common/repositories/blocked_spells_repository.h"
#include "../common/repositories/character_tribute_repository.h"
#include "../common/repositories/character_disciplines_repository.h"
#include "../common/repositories/npc_types_repository.h"
@ -19,6 +20,7 @@
#include "../common/repositories/character_pet_inventory_repository.h"
#include "../common/repositories/character_pet_info_repository.h"
#include "../common/repositories/character_buffs_repository.h"
#include "../common/repositories/criteria/content_filter_criteria.h"
#include <ctime>
#include <iostream>
@ -2845,50 +2847,55 @@ uint8 ZoneDatabase::RaidGroupCount(uint32 raidid, uint32 groupid) {
return Strings::ToInt(row[0]);
}
int32 ZoneDatabase::GetBlockedSpellsCount(uint32 zoneid)
int64 ZoneDatabase::GetBlockedSpellsCount(uint32 zone_id)
{
std::string query = StringFormat("SELECT count(*) FROM blocked_spells WHERE zoneid = %d", zoneid);
auto results = QueryDatabase(query);
if (!results.Success()) {
return -1;
}
if (results.RowCount() == 0)
return -1;
auto& row = results.begin();
return Strings::ToInt(row[0]);
return BlockedSpellsRepository::Count(
database,
fmt::format(
"zoneid = {} {}",
zone_id,
ContentFilterCriteria::apply()
)
);
}
bool ZoneDatabase::LoadBlockedSpells(int32 blockedSpellsCount, ZoneSpellsBlocked* into, uint32 zoneid)
bool ZoneDatabase::LoadBlockedSpells(int64 blocked_spells_count, ZoneSpellsBlocked* into, uint32 zone_id)
{
LogInfo("Loading Blocked Spells from database");
LogInfo("Loading Blocked Spells from database for {} ({}).", zone_store.GetZoneName(zone_id, true), zone_id);
std::string query = StringFormat("SELECT id, spellid, type, x, y, z, x_diff, y_diff, z_diff, message "
"FROM blocked_spells WHERE zoneid = %d ORDER BY id ASC", zoneid);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
}
const auto& l = BlockedSpellsRepository::GetWhere(
database,
fmt::format(
"zoneid = {} {} ORDER BY id ASC",
zone_id,
ContentFilterCriteria::apply()
)
);
if (results.RowCount() == 0)
if (l.empty()) {
return true;
}
int32 index = 0;
for(auto& row = results.begin(); row != results.end(); ++row, ++index) {
if(index >= blockedSpellsCount) {
std::cerr << "Error, Blocked Spells Count of " << blockedSpellsCount << " exceeded." << std::endl;
break;
}
int64 i = 0;
memset(&into[index], 0, sizeof(ZoneSpellsBlocked));
into[index].spellid = Strings::ToInt(row[1]);
into[index].type = Strings::ToInt(row[2]);
into[index].m_Location = glm::vec3(Strings::ToFloat(row[3]), Strings::ToFloat(row[4]), Strings::ToFloat(row[5]));
into[index].m_Difference = glm::vec3(Strings::ToFloat(row[6]), Strings::ToFloat(row[7]), Strings::ToFloat(row[8]));
strn0cpy(into[index].message, row[9], 255);
}
for (const auto& e : l) {
if (i >= blocked_spells_count) {
LogError(
"Blocked spells count of {} exceeded for {} ({}).",
blocked_spells_count,
zone_store.GetZoneName(zone_id, true),
zone_id
);
break;
}
memset(&into[i], 0, sizeof(ZoneSpellsBlocked));
into[i].spellid = e.spellid;
into[i].type = e.type;
into[i].m_Location = glm::vec3(e.x, e.y, e.z);
into[i].m_Difference = glm::vec3(e.x_diff, e.y_diff, e.z_diff);
strn0cpy(into[i].message, e.message.c_str(), sizeof(into[i].message));
}
return true;
}

View File

@ -619,8 +619,8 @@ public:
int GetDoorsDBCountPlusOne(std::string zone_short_name, int16 version);
/* Blocked Spells */
int32 GetBlockedSpellsCount(uint32 zoneid);
bool LoadBlockedSpells(int32 blockedSpellsCount, ZoneSpellsBlocked* into, uint32 zoneid);
int64 GetBlockedSpellsCount(uint32 zone_id);
bool LoadBlockedSpells(int64 blocked_spells_count, ZoneSpellsBlocked* into, uint32 zone_id);
/* Traps */
bool LoadTraps(const char* zonename, int16 version);