mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 03:08:26 +00:00
[Feature] Faction Association (#2408)
* Add faction logging category Probably should use this for more things * Add FactionAssociation struct This is simply just a struct that contains an array of faction ids and multiplier. This can hold a maximum of 10 entries (Seru hit is 8, so 2 extra) this can be raised if need be. * Add database changes and other data point changes This is all the database changes and loading changes Included is an optional SQL that will be used as a starting point, there is likely errors or typos, but we will fix those as they are discovered. * Add Client::RewardFaction function This just takes the faction ID and the magnitude of the primary faction hit and calculates the rest. The minimum change will be either 1 or -1. We stop processing after we see an ID of 0 and assume there will be no later entries. The primary faction ID will always receive a hit even if there is no faction association entries * Add users of RewardFaction to NPC death, tasks, and QuestRewards This will only use the new system if the magnitude is set, otherwise we will just use the old system still * Add quest system calls and lua QuestReward support * Add #factionassociation command This just calls RewardFaction, mostly useful for debugging
This commit is contained in:
committed by
GitHub
parent
efe1879115
commit
2b4e555eae
@@ -197,6 +197,7 @@ SET(repositories
|
||||
repositories/base/base_eventlog_repository.h
|
||||
repositories/base/base_expeditions_repository.h
|
||||
repositories/base/base_expedition_lockouts_repository.h
|
||||
repositories/base/base_faction_association_repository.h
|
||||
repositories/base/base_faction_base_data_repository.h
|
||||
repositories/base/base_faction_list_repository.h
|
||||
repositories/base/base_faction_list_mod_repository.h
|
||||
@@ -373,6 +374,7 @@ SET(repositories
|
||||
repositories/eventlog_repository.h
|
||||
repositories/expeditions_repository.h
|
||||
repositories/expedition_lockouts_repository.h
|
||||
repositories/faction_association_repository.h
|
||||
repositories/faction_base_data_repository.h
|
||||
repositories/faction_list_repository.h
|
||||
repositories/faction_list_mod_repository.h
|
||||
|
||||
@@ -190,6 +190,7 @@ namespace DatabaseSchema {
|
||||
"damageshieldtypes",
|
||||
"doors",
|
||||
"dynamic_zone_templates",
|
||||
"faction_association",
|
||||
"faction_base_data",
|
||||
"faction_list",
|
||||
"faction_list_mod",
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace Logs {
|
||||
CombatRecord,
|
||||
Hate,
|
||||
Discord,
|
||||
Faction,
|
||||
MaxCategoryID /* Don't Remove this */
|
||||
};
|
||||
|
||||
@@ -220,6 +221,7 @@ namespace Logs {
|
||||
"CombatRecord",
|
||||
"Hate",
|
||||
"Discord",
|
||||
"Faction",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -736,6 +736,16 @@
|
||||
OutF(LogSys, Logs::Detail, Logs::Discord, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
|
||||
} while (0)
|
||||
|
||||
#define LogFaction(message, ...) do {\
|
||||
if (LogSys.log_settings[Logs::Faction].is_category_enabled == 1)\
|
||||
OutF(LogSys, Logs::General, Logs::Faction, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
|
||||
} while(0)
|
||||
|
||||
#define LogFactionDetail(message, ...) do {\
|
||||
if (LogSys.log_settings[Logs::Faction].is_category_enabled == 1)\
|
||||
OutF(LogSys, Logs::Detail, Logs::Faction, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
|
||||
} while(0)
|
||||
|
||||
#define Log(debug_level, log_category, message, ...) do {\
|
||||
if (LogSys.log_settings[log_category].is_category_enabled == 1)\
|
||||
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
|
||||
@@ -1180,6 +1190,12 @@
|
||||
#define LogHateDetail(message, ...) do {\
|
||||
} while (0)
|
||||
|
||||
#define LogFaction(message, ...) do {\
|
||||
} while (0)
|
||||
|
||||
#define LogFactionDetail(message, ...) do {\
|
||||
} while (0)
|
||||
|
||||
#define Log(debug_level, log_category, message, ...) do {\
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -75,6 +75,23 @@ struct NPCFaction
|
||||
uint8 temp;
|
||||
};
|
||||
|
||||
// Faction Associations give a much more live like faction system
|
||||
// Basically the primary faction and magnitude of a faction hit will generate the rest of them
|
||||
|
||||
// Largest faction I could find quickly was Lord Inquisitor Seru with 9 total hits (8 associations) so 8 + 2 for max for now
|
||||
#define MAX_FACTION_ASSOC 10
|
||||
|
||||
// this is the ID of a faction association and it's multiplier
|
||||
struct FactionAssociationHit {
|
||||
int id;
|
||||
float multiplier;
|
||||
};
|
||||
|
||||
struct FactionAssociations {
|
||||
// maybe there should be more data here, fine for now
|
||||
FactionAssociationHit hits[MAX_FACTION_ASSOC];
|
||||
};
|
||||
|
||||
const char *FactionValueToString(FACTION_VALUE faction_value);
|
||||
FACTION_VALUE CalculateFaction(FactionMods* fm, int32 tmpCharacter_value);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,523 @@
|
||||
/**
|
||||
* DO NOT MODIFY THIS FILE
|
||||
*
|
||||
* This repository was automatically generated and is NOT to be modified directly.
|
||||
* Any repository modifications are meant to be made to the repository extending the base.
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
#define EQEMU_BASE_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
class BaseFactionAssociationRepository {
|
||||
public:
|
||||
struct FactionAssociation {
|
||||
int32_t id;
|
||||
int32_t id_1;
|
||||
float mod_1;
|
||||
int32_t id_2;
|
||||
float mod_2;
|
||||
int32_t id_3;
|
||||
float mod_3;
|
||||
int32_t id_4;
|
||||
float mod_4;
|
||||
int32_t id_5;
|
||||
float mod_5;
|
||||
int32_t id_6;
|
||||
float mod_6;
|
||||
int32_t id_7;
|
||||
float mod_7;
|
||||
int32_t id_8;
|
||||
float mod_8;
|
||||
int32_t id_9;
|
||||
float mod_9;
|
||||
int32_t id_10;
|
||||
float mod_10;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"id_1",
|
||||
"mod_1",
|
||||
"id_2",
|
||||
"mod_2",
|
||||
"id_3",
|
||||
"mod_3",
|
||||
"id_4",
|
||||
"mod_4",
|
||||
"id_5",
|
||||
"mod_5",
|
||||
"id_6",
|
||||
"mod_6",
|
||||
"id_7",
|
||||
"mod_7",
|
||||
"id_8",
|
||||
"mod_8",
|
||||
"id_9",
|
||||
"mod_9",
|
||||
"id_10",
|
||||
"mod_10",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"id_1",
|
||||
"mod_1",
|
||||
"id_2",
|
||||
"mod_2",
|
||||
"id_3",
|
||||
"mod_3",
|
||||
"id_4",
|
||||
"mod_4",
|
||||
"id_5",
|
||||
"mod_5",
|
||||
"id_6",
|
||||
"mod_6",
|
||||
"id_7",
|
||||
"mod_7",
|
||||
"id_8",
|
||||
"mod_8",
|
||||
"id_9",
|
||||
"mod_9",
|
||||
"id_10",
|
||||
"mod_10",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string SelectColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", SelectColumns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("faction_association");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static FactionAssociation NewEntity()
|
||||
{
|
||||
FactionAssociation e{};
|
||||
|
||||
e.id = 0;
|
||||
e.id_1 = 0;
|
||||
e.mod_1 = 0;
|
||||
e.id_2 = 0;
|
||||
e.mod_2 = 0;
|
||||
e.id_3 = 0;
|
||||
e.mod_3 = 0;
|
||||
e.id_4 = 0;
|
||||
e.mod_4 = 0;
|
||||
e.id_5 = 0;
|
||||
e.mod_5 = 0;
|
||||
e.id_6 = 0;
|
||||
e.mod_6 = 0;
|
||||
e.id_7 = 0;
|
||||
e.mod_7 = 0;
|
||||
e.id_8 = 0;
|
||||
e.mod_8 = 0;
|
||||
e.id_9 = 0;
|
||||
e.mod_9 = 0;
|
||||
e.id_10 = 0;
|
||||
e.mod_10 = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static FactionAssociation GetFactionAssociation(
|
||||
const std::vector<FactionAssociation> &faction_associations,
|
||||
int faction_association_id
|
||||
)
|
||||
{
|
||||
for (auto &faction_association : faction_associations) {
|
||||
if (faction_association.id == faction_association_id) {
|
||||
return faction_association;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static FactionAssociation FindOne(
|
||||
Database& db,
|
||||
int faction_association_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
faction_association_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
FactionAssociation e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.id_1 = static_cast<int32_t>(atoi(row[1]));
|
||||
e.mod_1 = strtof(row[2], nullptr);
|
||||
e.id_2 = static_cast<int32_t>(atoi(row[3]));
|
||||
e.mod_2 = strtof(row[4], nullptr);
|
||||
e.id_3 = static_cast<int32_t>(atoi(row[5]));
|
||||
e.mod_3 = strtof(row[6], nullptr);
|
||||
e.id_4 = static_cast<int32_t>(atoi(row[7]));
|
||||
e.mod_4 = strtof(row[8], nullptr);
|
||||
e.id_5 = static_cast<int32_t>(atoi(row[9]));
|
||||
e.mod_5 = strtof(row[10], nullptr);
|
||||
e.id_6 = static_cast<int32_t>(atoi(row[11]));
|
||||
e.mod_6 = strtof(row[12], nullptr);
|
||||
e.id_7 = static_cast<int32_t>(atoi(row[13]));
|
||||
e.mod_7 = strtof(row[14], nullptr);
|
||||
e.id_8 = static_cast<int32_t>(atoi(row[15]));
|
||||
e.mod_8 = strtof(row[16], nullptr);
|
||||
e.id_9 = static_cast<int32_t>(atoi(row[17]));
|
||||
e.mod_9 = strtof(row[18], nullptr);
|
||||
e.id_10 = static_cast<int32_t>(atoi(row[19]));
|
||||
e.mod_10 = strtof(row[20], nullptr);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int faction_association_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
faction_association_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const FactionAssociation &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.id));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.id_1));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.mod_1));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.id_2));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.mod_2));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.id_3));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.mod_3));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.id_4));
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.mod_4));
|
||||
v.push_back(columns[9] + " = " + std::to_string(e.id_5));
|
||||
v.push_back(columns[10] + " = " + std::to_string(e.mod_5));
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.id_6));
|
||||
v.push_back(columns[12] + " = " + std::to_string(e.mod_6));
|
||||
v.push_back(columns[13] + " = " + std::to_string(e.id_7));
|
||||
v.push_back(columns[14] + " = " + std::to_string(e.mod_7));
|
||||
v.push_back(columns[15] + " = " + std::to_string(e.id_8));
|
||||
v.push_back(columns[16] + " = " + std::to_string(e.mod_8));
|
||||
v.push_back(columns[17] + " = " + std::to_string(e.id_9));
|
||||
v.push_back(columns[18] + " = " + std::to_string(e.mod_9));
|
||||
v.push_back(columns[19] + " = " + std::to_string(e.id_10));
|
||||
v.push_back(columns[20] + " = " + std::to_string(e.mod_10));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static FactionAssociation InsertOne(
|
||||
Database& db,
|
||||
FactionAssociation e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.id_1));
|
||||
v.push_back(std::to_string(e.mod_1));
|
||||
v.push_back(std::to_string(e.id_2));
|
||||
v.push_back(std::to_string(e.mod_2));
|
||||
v.push_back(std::to_string(e.id_3));
|
||||
v.push_back(std::to_string(e.mod_3));
|
||||
v.push_back(std::to_string(e.id_4));
|
||||
v.push_back(std::to_string(e.mod_4));
|
||||
v.push_back(std::to_string(e.id_5));
|
||||
v.push_back(std::to_string(e.mod_5));
|
||||
v.push_back(std::to_string(e.id_6));
|
||||
v.push_back(std::to_string(e.mod_6));
|
||||
v.push_back(std::to_string(e.id_7));
|
||||
v.push_back(std::to_string(e.mod_7));
|
||||
v.push_back(std::to_string(e.id_8));
|
||||
v.push_back(std::to_string(e.mod_8));
|
||||
v.push_back(std::to_string(e.id_9));
|
||||
v.push_back(std::to_string(e.mod_9));
|
||||
v.push_back(std::to_string(e.id_10));
|
||||
v.push_back(std::to_string(e.mod_10));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
e = NewEntity();
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
const std::vector<FactionAssociation> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.id_1));
|
||||
v.push_back(std::to_string(e.mod_1));
|
||||
v.push_back(std::to_string(e.id_2));
|
||||
v.push_back(std::to_string(e.mod_2));
|
||||
v.push_back(std::to_string(e.id_3));
|
||||
v.push_back(std::to_string(e.mod_3));
|
||||
v.push_back(std::to_string(e.id_4));
|
||||
v.push_back(std::to_string(e.mod_4));
|
||||
v.push_back(std::to_string(e.id_5));
|
||||
v.push_back(std::to_string(e.mod_5));
|
||||
v.push_back(std::to_string(e.id_6));
|
||||
v.push_back(std::to_string(e.mod_6));
|
||||
v.push_back(std::to_string(e.id_7));
|
||||
v.push_back(std::to_string(e.mod_7));
|
||||
v.push_back(std::to_string(e.id_8));
|
||||
v.push_back(std::to_string(e.mod_8));
|
||||
v.push_back(std::to_string(e.id_9));
|
||||
v.push_back(std::to_string(e.mod_9));
|
||||
v.push_back(std::to_string(e.id_10));
|
||||
v.push_back(std::to_string(e.mod_10));
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<FactionAssociation> All(Database& db)
|
||||
{
|
||||
std::vector<FactionAssociation> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
FactionAssociation e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.id_1 = static_cast<int32_t>(atoi(row[1]));
|
||||
e.mod_1 = strtof(row[2], nullptr);
|
||||
e.id_2 = static_cast<int32_t>(atoi(row[3]));
|
||||
e.mod_2 = strtof(row[4], nullptr);
|
||||
e.id_3 = static_cast<int32_t>(atoi(row[5]));
|
||||
e.mod_3 = strtof(row[6], nullptr);
|
||||
e.id_4 = static_cast<int32_t>(atoi(row[7]));
|
||||
e.mod_4 = strtof(row[8], nullptr);
|
||||
e.id_5 = static_cast<int32_t>(atoi(row[9]));
|
||||
e.mod_5 = strtof(row[10], nullptr);
|
||||
e.id_6 = static_cast<int32_t>(atoi(row[11]));
|
||||
e.mod_6 = strtof(row[12], nullptr);
|
||||
e.id_7 = static_cast<int32_t>(atoi(row[13]));
|
||||
e.mod_7 = strtof(row[14], nullptr);
|
||||
e.id_8 = static_cast<int32_t>(atoi(row[15]));
|
||||
e.mod_8 = strtof(row[16], nullptr);
|
||||
e.id_9 = static_cast<int32_t>(atoi(row[17]));
|
||||
e.mod_9 = strtof(row[18], nullptr);
|
||||
e.id_10 = static_cast<int32_t>(atoi(row[19]));
|
||||
e.mod_10 = strtof(row[20], nullptr);
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<FactionAssociation> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<FactionAssociation> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {}",
|
||||
BaseSelect(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
FactionAssociation e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.id_1 = static_cast<int32_t>(atoi(row[1]));
|
||||
e.mod_1 = strtof(row[2], nullptr);
|
||||
e.id_2 = static_cast<int32_t>(atoi(row[3]));
|
||||
e.mod_2 = strtof(row[4], nullptr);
|
||||
e.id_3 = static_cast<int32_t>(atoi(row[5]));
|
||||
e.mod_3 = strtof(row[6], nullptr);
|
||||
e.id_4 = static_cast<int32_t>(atoi(row[7]));
|
||||
e.mod_4 = strtof(row[8], nullptr);
|
||||
e.id_5 = static_cast<int32_t>(atoi(row[9]));
|
||||
e.mod_5 = strtof(row[10], nullptr);
|
||||
e.id_6 = static_cast<int32_t>(atoi(row[11]));
|
||||
e.mod_6 = strtof(row[12], nullptr);
|
||||
e.id_7 = static_cast<int32_t>(atoi(row[13]));
|
||||
e.mod_7 = strtof(row[14], nullptr);
|
||||
e.id_8 = static_cast<int32_t>(atoi(row[15]));
|
||||
e.mod_8 = strtof(row[16], nullptr);
|
||||
e.id_9 = static_cast<int32_t>(atoi(row[17]));
|
||||
e.mod_9 = strtof(row[18], nullptr);
|
||||
e.id_10 = static_cast<int32_t>(atoi(row[19]));
|
||||
e.mod_10 = strtof(row[20], nullptr);
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {}",
|
||||
TableName(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int Truncate(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"TRUNCATE TABLE {}",
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int64 GetMaxId(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COALESCE(MAX({}), 0) FROM {}",
|
||||
PrimaryKey(),
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
static int64 Count(Database& db, const std::string &where_filter = "")
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COUNT(*) FROM {} {}",
|
||||
TableName(),
|
||||
(where_filter.empty() ? "" : "WHERE " + where_filter)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
@@ -144,6 +144,7 @@ public:
|
||||
int8_t always_aggro;
|
||||
int32_t exp_mod;
|
||||
int32_t heroic_strikethrough;
|
||||
int32_t faction_amount;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
@@ -279,6 +280,7 @@ public:
|
||||
"always_aggro",
|
||||
"exp_mod",
|
||||
"heroic_strikethrough",
|
||||
"faction_amount",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -410,6 +412,7 @@ public:
|
||||
"always_aggro",
|
||||
"exp_mod",
|
||||
"heroic_strikethrough",
|
||||
"faction_amount",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -575,6 +578,7 @@ public:
|
||||
e.always_aggro = 0;
|
||||
e.exp_mod = 100;
|
||||
e.heroic_strikethrough = 0;
|
||||
e.faction_amount = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -735,6 +739,7 @@ public:
|
||||
e.always_aggro = static_cast<int8_t>(atoi(row[122]));
|
||||
e.exp_mod = static_cast<int32_t>(atoi(row[123]));
|
||||
e.heroic_strikethrough = static_cast<int32_t>(atoi(row[124]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[125]));
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -892,6 +897,7 @@ public:
|
||||
v.push_back(columns[122] + " = " + std::to_string(e.always_aggro));
|
||||
v.push_back(columns[123] + " = " + std::to_string(e.exp_mod));
|
||||
v.push_back(columns[124] + " = " + std::to_string(e.heroic_strikethrough));
|
||||
v.push_back(columns[125] + " = " + std::to_string(e.faction_amount));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -1038,6 +1044,7 @@ public:
|
||||
v.push_back(std::to_string(e.always_aggro));
|
||||
v.push_back(std::to_string(e.exp_mod));
|
||||
v.push_back(std::to_string(e.heroic_strikethrough));
|
||||
v.push_back(std::to_string(e.faction_amount));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -1192,6 +1199,7 @@ public:
|
||||
v.push_back(std::to_string(e.always_aggro));
|
||||
v.push_back(std::to_string(e.exp_mod));
|
||||
v.push_back(std::to_string(e.heroic_strikethrough));
|
||||
v.push_back(std::to_string(e.faction_amount));
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
@@ -1350,6 +1358,7 @@ public:
|
||||
e.always_aggro = static_cast<int8_t>(atoi(row[122]));
|
||||
e.exp_mod = static_cast<int32_t>(atoi(row[123]));
|
||||
e.heroic_strikethrough = static_cast<int32_t>(atoi(row[124]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[125]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
@@ -1499,6 +1508,7 @@ public:
|
||||
e.always_aggro = static_cast<int8_t>(atoi(row[122]));
|
||||
e.exp_mod = static_cast<int32_t>(atoi(row[123]));
|
||||
e.heroic_strikethrough = static_cast<int32_t>(atoi(row[124]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[125]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
uint32_t request_timer_seconds;
|
||||
uint32_t dz_template_id;
|
||||
int32_t lock_activity_id;
|
||||
int32_t faction_amount;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
@@ -83,6 +84,7 @@ public:
|
||||
"request_timer_seconds",
|
||||
"dz_template_id",
|
||||
"lock_activity_id",
|
||||
"faction_amount",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,6 +118,7 @@ public:
|
||||
"request_timer_seconds",
|
||||
"dz_template_id",
|
||||
"lock_activity_id",
|
||||
"faction_amount",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -183,6 +186,7 @@ public:
|
||||
e.request_timer_seconds = 0;
|
||||
e.dz_template_id = 0;
|
||||
e.lock_activity_id = -1;
|
||||
e.faction_amount = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -245,6 +249,7 @@ public:
|
||||
e.request_timer_seconds = static_cast<uint32_t>(strtoul(row[24], nullptr, 10));
|
||||
e.dz_template_id = static_cast<uint32_t>(strtoul(row[25], nullptr, 10));
|
||||
e.lock_activity_id = static_cast<int32_t>(atoi(row[26]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[27]));
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -305,6 +310,7 @@ public:
|
||||
v.push_back(columns[24] + " = " + std::to_string(e.request_timer_seconds));
|
||||
v.push_back(columns[25] + " = " + std::to_string(e.dz_template_id));
|
||||
v.push_back(columns[26] + " = " + std::to_string(e.lock_activity_id));
|
||||
v.push_back(columns[27] + " = " + std::to_string(e.faction_amount));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -353,6 +359,7 @@ public:
|
||||
v.push_back(std::to_string(e.request_timer_seconds));
|
||||
v.push_back(std::to_string(e.dz_template_id));
|
||||
v.push_back(std::to_string(e.lock_activity_id));
|
||||
v.push_back(std::to_string(e.faction_amount));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -409,6 +416,7 @@ public:
|
||||
v.push_back(std::to_string(e.request_timer_seconds));
|
||||
v.push_back(std::to_string(e.dz_template_id));
|
||||
v.push_back(std::to_string(e.lock_activity_id));
|
||||
v.push_back(std::to_string(e.faction_amount));
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
@@ -469,6 +477,7 @@ public:
|
||||
e.request_timer_seconds = static_cast<uint32_t>(strtoul(row[24], nullptr, 10));
|
||||
e.dz_template_id = static_cast<uint32_t>(strtoul(row[25], nullptr, 10));
|
||||
e.lock_activity_id = static_cast<int32_t>(atoi(row[26]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[27]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
@@ -520,6 +529,7 @@ public:
|
||||
e.request_timer_seconds = static_cast<uint32_t>(strtoul(row[24], nullptr, 10));
|
||||
e.dz_template_id = static_cast<uint32_t>(strtoul(row[25], nullptr, 10));
|
||||
e.lock_activity_id = static_cast<int32_t>(atoi(row[26]));
|
||||
e.faction_amount = static_cast<int32_t>(atoi(row[27]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef EQEMU_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
#define EQEMU_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_faction_association_repository.h"
|
||||
|
||||
class FactionAssociationRepository: public BaseFactionAssociationRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* This file was auto generated and can be modified and extended upon
|
||||
*
|
||||
* Base repository methods are automatically
|
||||
* generated in the "base" version of this repository. The base repository
|
||||
* is immutable and to be left untouched, while methods in this class
|
||||
* are used as extension methods for more specific persistence-layer
|
||||
* accessors or mutators.
|
||||
*
|
||||
* Base Methods (Subject to be expanded upon in time)
|
||||
*
|
||||
* Note: Not all tables are designed appropriately to fit functionality with all base methods
|
||||
*
|
||||
* InsertOne
|
||||
* UpdateOne
|
||||
* DeleteOne
|
||||
* FindOne
|
||||
* GetWhere(std::string where_filter)
|
||||
* DeleteWhere(std::string where_filter)
|
||||
* InsertMany
|
||||
* All
|
||||
*
|
||||
* Example custom methods in a repository
|
||||
*
|
||||
* FactionAssociationRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* FactionAssociationRepository::GetWhereNeverExpires()
|
||||
* FactionAssociationRepository::GetWhereXAndY()
|
||||
* FactionAssociationRepository::DeleteWhereXAndY()
|
||||
*
|
||||
* Most of the above could be covered by base methods, but if you as a developer
|
||||
* find yourself re-using logic for other parts of the code, its best to just make a
|
||||
* method that can be re-used easily elsewhere especially if it can use a base repository
|
||||
* method and encapsulate filters there
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_FACTION_ASSOCIATION_REPOSITORY_H
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "data_verification.h"
|
||||
#include "repositories/criteria/content_filter_criteria.h"
|
||||
#include "repositories/account_repository.h"
|
||||
#include "repositories/faction_association_repository.h"
|
||||
|
||||
namespace ItemField
|
||||
{
|
||||
@@ -1448,6 +1449,80 @@ bool SharedDatabase::LoadNPCFactionLists(const std::string &prefix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SharedDatabase::GetFactionAssociationInfo(uint32 &list_count, uint32 &max_lists)
|
||||
{
|
||||
list_count = static_cast<uint32>(FactionAssociationRepository::Count(*this));
|
||||
max_lists = static_cast<uint32>(FactionAssociationRepository::GetMaxId(*this));
|
||||
}
|
||||
|
||||
const FactionAssociations *SharedDatabase::GetFactionAssociationHit(int id)
|
||||
{
|
||||
if (!faction_associations_hash) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (faction_associations_hash->exists(id)) {
|
||||
return &(faction_associations_hash->at(id));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SharedDatabase::LoadFactionAssociation(void *data, uint32 size, uint32 list_count, uint32 max_lists)
|
||||
{
|
||||
EQ::FixedMemoryHashSet<FactionAssociations> hash(reinterpret_cast<uint8 *>(data), size, list_count, max_lists);
|
||||
FactionAssociations faction{};
|
||||
|
||||
auto results = FactionAssociationRepository::All(*this);
|
||||
for (auto &row : results) {
|
||||
faction.hits[0].id = row.id_1;
|
||||
faction.hits[0].multiplier = row.mod_1;
|
||||
faction.hits[1].id = row.id_2;
|
||||
faction.hits[1].multiplier = row.mod_2;
|
||||
faction.hits[2].id = row.id_3;
|
||||
faction.hits[2].multiplier = row.mod_3;
|
||||
faction.hits[3].id = row.id_4;
|
||||
faction.hits[3].multiplier = row.mod_4;
|
||||
faction.hits[4].id = row.id_5;
|
||||
faction.hits[4].multiplier = row.mod_5;
|
||||
faction.hits[5].id = row.id_6;
|
||||
faction.hits[5].multiplier = row.mod_6;
|
||||
faction.hits[6].id = row.id_7;
|
||||
faction.hits[6].multiplier = row.mod_7;
|
||||
faction.hits[7].id = row.id_8;
|
||||
faction.hits[7].multiplier = row.mod_8;
|
||||
faction.hits[8].id = row.id_9;
|
||||
faction.hits[8].multiplier = row.mod_9;
|
||||
faction.hits[9].id = row.id_10;
|
||||
faction.hits[9].multiplier = row.mod_10;
|
||||
|
||||
hash.insert(row.id, faction);
|
||||
}
|
||||
}
|
||||
|
||||
bool SharedDatabase::LoadFactionAssociation(const std::string &prefix)
|
||||
{
|
||||
faction_associations_mmf.reset(nullptr);
|
||||
faction_associations_hash.reset(nullptr);
|
||||
|
||||
try {
|
||||
auto Config = EQEmuConfig::get();
|
||||
EQ::IPCMutex mutex("factionassociation");
|
||||
mutex.Lock();
|
||||
std::string file_name = Config->SharedMemDir + prefix + std::string("factionassociations");
|
||||
faction_associations_mmf = std::unique_ptr<EQ::MemoryMappedFile>(new EQ::MemoryMappedFile(file_name));
|
||||
faction_associations_hash = std::unique_ptr<EQ::FixedMemoryHashSet<FactionAssociations>>(
|
||||
new EQ::FixedMemoryHashSet<FactionAssociations>(reinterpret_cast<uint8 *>(faction_associations_mmf->Get()),
|
||||
faction_associations_mmf->Size()));
|
||||
mutex.Unlock();
|
||||
} catch (std::exception &ex) {
|
||||
LogError("Error Loading faction associations: {}", ex.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create appropriate EQ::ItemInstance class
|
||||
EQ::ItemInstance* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ struct InspectMessage_Struct;
|
||||
struct PlayerProfile_Struct;
|
||||
struct SPDat_Spell_Struct;
|
||||
struct NPCFactionList;
|
||||
struct FactionAssociations;
|
||||
struct LootTable_Struct;
|
||||
struct LootDrop_Struct;
|
||||
|
||||
@@ -159,6 +160,14 @@ public:
|
||||
void LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists);
|
||||
bool LoadNPCFactionLists(const std::string &prefix);
|
||||
|
||||
/**
|
||||
* faction associations
|
||||
*/
|
||||
void GetFactionAssociationInfo(uint32 &list_count, uint32 &max_lists);
|
||||
const FactionAssociations *GetFactionAssociationHit(int id);
|
||||
void LoadFactionAssociation(void *data, uint32 size, uint32 list_count, uint32 max_lists);
|
||||
bool LoadFactionAssociation(const std::string &prefix);
|
||||
|
||||
/**
|
||||
* loot
|
||||
*/
|
||||
@@ -212,6 +221,8 @@ protected:
|
||||
std::unique_ptr<EQ::FixedMemoryHashSet<EQ::ItemData>> items_hash;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> faction_mmf;
|
||||
std::unique_ptr<EQ::FixedMemoryHashSet<NPCFactionList>> faction_hash;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> faction_associations_mmf;
|
||||
std::unique_ptr<EQ::FixedMemoryHashSet<FactionAssociations>> faction_associations_hash;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> loot_table_mmf;
|
||||
std::unique_ptr<EQ::FixedMemoryVariableHashSet<LootTable_Struct>> loot_table_hash;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> loot_drop_mmf;
|
||||
|
||||
+2
-1
@@ -217,7 +217,8 @@ struct TaskInformation {
|
||||
int reward_id{};
|
||||
int cash_reward{}; // Expressed in copper
|
||||
int experience_reward{};
|
||||
int faction_reward{}; // just a npc_faction_id
|
||||
int faction_reward{}; // npc_faction_id if amount == 0, otherwise primary faction ID
|
||||
int faction_amount{}; // faction hit value
|
||||
TaskMethodType reward_method;
|
||||
int reward_points;
|
||||
AltCurrencyType reward_point_type;
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
|
||||
*/
|
||||
|
||||
#define CURRENT_BINARY_DATABASE_VERSION 9203
|
||||
#define CURRENT_BINARY_DATABASE_VERSION 9204
|
||||
|
||||
#ifdef BOTS
|
||||
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9029
|
||||
|
||||
Reference in New Issue
Block a user