mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-02 22:03:52 +00:00
[Repository] Modernize character recipe list (#2385)
This commit is contained in:
parent
295ec0e1b4
commit
893d53425a
@ -477,8 +477,6 @@ SET(repositories
|
||||
repositories/zone_repository.h
|
||||
repositories/zone_points_repository.h
|
||||
|
||||
# Non-Comformative
|
||||
repositories/character_recipe_list_repository.h
|
||||
)
|
||||
|
||||
SET(common_headers
|
||||
|
||||
@ -45,6 +45,20 @@ public:
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
static CharRecipeList GetCharRecipeListEntry(
|
||||
const std::vector<CharRecipeList> &recipe_list,
|
||||
uint32 recipe_id
|
||||
)
|
||||
{
|
||||
for (auto &e : recipe_list) {
|
||||
if (e.recipe_id == recipe_id) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_CHAR_RECIPE_LIST_REPOSITORY_H
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
#ifndef EQEMU_CHARACTER_RECIPE_LIST_REPOSITORY_H
|
||||
#define EQEMU_CHARACTER_RECIPE_LIST_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
|
||||
class CharacterRecipeListRepository {
|
||||
public:
|
||||
struct CharacterRecipeList {
|
||||
int character_id;
|
||||
int recipe_id;
|
||||
int made_count;
|
||||
};
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"char_id",
|
||||
"recipe_id",
|
||||
"madecount",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("char_recipe_list");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return std::string(
|
||||
fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
ColumnsRaw(),
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static CharacterRecipeList NewEntity()
|
||||
{
|
||||
CharacterRecipeList character_recipe_list_entry;
|
||||
|
||||
character_recipe_list_entry.character_id = 0;
|
||||
character_recipe_list_entry.made_count = 0;
|
||||
character_recipe_list_entry.recipe_id = 0;
|
||||
|
||||
return character_recipe_list_entry;
|
||||
}
|
||||
|
||||
static std::vector<CharacterRecipeList> GetLearnedRecipeList(int character_id)
|
||||
{
|
||||
std::vector<CharacterRecipeList> character_recipe_list;
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE char_id = {}",
|
||||
BaseSelect(),
|
||||
character_id
|
||||
)
|
||||
);
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterRecipeList character_recipe_list_entry;
|
||||
|
||||
character_recipe_list_entry.character_id = character_id;
|
||||
character_recipe_list_entry.recipe_id = atoi(row[1]);
|
||||
character_recipe_list_entry.made_count = atoi(row[2]);
|
||||
|
||||
character_recipe_list.push_back(character_recipe_list_entry);
|
||||
}
|
||||
|
||||
return character_recipe_list;
|
||||
}
|
||||
|
||||
static CharacterRecipeList GetRecipe(
|
||||
std::vector<CharacterRecipeList> character_recipe_list,
|
||||
int recipe_id
|
||||
)
|
||||
{
|
||||
for (auto &row : character_recipe_list) {
|
||||
if (row.recipe_id == recipe_id) {
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_CHARACTER_RECIPE_LIST_REPOSITORY_H
|
||||
@ -132,7 +132,6 @@ foreach my $table_to_generate (@tables) {
|
||||
"character_enabledtasks",
|
||||
# "grid", # Manually created
|
||||
# "tradeskill_recipe", # Manually created
|
||||
# "character_recipe_list", # Manually created
|
||||
"guild_bank",
|
||||
"inventory_versions",
|
||||
"raid_leaders",
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
#include "titles.h"
|
||||
#include "zonedb.h"
|
||||
#include "zone_store.h"
|
||||
#include "../common/repositories/character_recipe_list_repository.h"
|
||||
#include "../common/repositories/char_recipe_list_repository.h"
|
||||
#include "../common/repositories/tradeskill_recipe_repository.h"
|
||||
|
||||
extern QueryServ* QServ;
|
||||
@ -758,7 +758,11 @@ void Client::SendTradeskillSearchResults(
|
||||
return;
|
||||
}
|
||||
|
||||
auto character_learned_recipe_list = CharacterRecipeListRepository::GetLearnedRecipeList(CharacterID());
|
||||
|
||||
auto character_learned_recipe_list = CharRecipeListRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("char_id = {}", CharacterID())
|
||||
);
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
if (row == nullptr || row[0] == nullptr || row[1] == nullptr || row[2] == nullptr || row[3] == nullptr ||
|
||||
@ -777,8 +781,7 @@ void Client::SendTradeskillSearchResults(
|
||||
// Skip the recipes that exceed the threshold in skill difference
|
||||
// Recipes that have either been made before or were
|
||||
// explicitly learned are excempt from that limit
|
||||
|
||||
auto character_learned_recipe = CharacterRecipeListRepository::GetRecipe(
|
||||
auto character_learned_recipe = CharRecipeListRepository::GetCharRecipeListEntry(
|
||||
character_learned_recipe_list,
|
||||
recipe_id
|
||||
);
|
||||
@ -789,7 +792,7 @@ void Client::SendTradeskillSearchResults(
|
||||
|
||||
LogTradeskills("Checking limit recipe_id [{}] name [{}]", recipe_id, name);
|
||||
|
||||
if (character_learned_recipe.made_count == 0) {
|
||||
if (character_learned_recipe.madecount == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -1484,17 +1487,16 @@ bool ZoneDatabase::GetTradeRecipe(
|
||||
spec->madecount = 0;
|
||||
spec->recipe_id = recipe_id;
|
||||
|
||||
auto character_learned_recipe_list = CharacterRecipeListRepository::GetLearnedRecipeList(char_id);
|
||||
auto character_learned_recipe = CharacterRecipeListRepository::GetRecipe(
|
||||
character_learned_recipe_list,
|
||||
recipe_id
|
||||
auto r = CharRecipeListRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("char_id = {} and recipe_id = {}", char_id, recipe_id)
|
||||
);
|
||||
|
||||
if (character_learned_recipe.recipe_id) { //If this exists we learned it
|
||||
LogTradeskills("[GetTradeRecipe] made_count [{}]", character_learned_recipe.made_count);
|
||||
if (!r.empty() && r[0].recipe_id) { //If this exists we learned it
|
||||
LogTradeskills("[GetTradeRecipe] made_count [{}]", r[0].madecount);
|
||||
|
||||
spec->has_learnt = true;
|
||||
spec->madecount = (uint32)character_learned_recipe.made_count;
|
||||
spec->madecount = (uint32) r[0].madecount;
|
||||
}
|
||||
|
||||
//Pull the on-success items...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user