mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 02:11:30 +00:00
[Character] Convert Load/Update of Character Alternate Currencies to Repositories (#3856)
- Convert `LoadAltCurrencyValues` and `UpdateAltCurrencyValue` to repositories. - Cleanup some other code and logic as well. - Add `AlternateCurrencyMode` namespace for `AltCurrencyPopulate_Struct` opcode magic numbers.
This commit is contained in:
parent
2ca50b339d
commit
0ea825e9a4
@ -727,6 +727,11 @@ namespace BuffEffectType {
|
|||||||
constexpr uint8 InverseBuff = 4;
|
constexpr uint8 InverseBuff = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace AlternateCurrencyMode {
|
||||||
|
constexpr uint32 Update = 7;
|
||||||
|
constexpr uint32 Populate = 8;
|
||||||
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FilterNone = 0,
|
FilterNone = 0,
|
||||||
FilterGuildChat = 1, //0=hide, 1=show
|
FilterGuildChat = 1, //0=hide, 1=show
|
||||||
|
|||||||
@ -5134,8 +5134,6 @@ struct GroupMakeLeader_Struct
|
|||||||
//ex for a blank crowns window you would send:
|
//ex for a blank crowns window you would send:
|
||||||
//999999|1|999999|0
|
//999999|1|999999|0
|
||||||
//any items come after in much the same way adventure merchant items do except there is no theme included
|
//any items come after in much the same way adventure merchant items do except there is no theme included
|
||||||
#define ALT_CURRENCY_OP_POPULATE 8
|
|
||||||
#define ALT_CURRENCY_OP_UPDATE 7
|
|
||||||
|
|
||||||
//Server -> Client
|
//Server -> Client
|
||||||
//Populates the initial Alternate Currency Window
|
//Populates the initial Alternate Currency Window
|
||||||
|
|||||||
@ -202,7 +202,7 @@ namespace RoF
|
|||||||
unsigned char *emu_buffer = in->pBuffer;
|
unsigned char *emu_buffer = in->pBuffer;
|
||||||
uint32 opcode = *((uint32*)emu_buffer);
|
uint32 opcode = *((uint32*)emu_buffer);
|
||||||
|
|
||||||
if (opcode == 8) {
|
if (opcode == AlternateCurrencyMode::Populate) {
|
||||||
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(
|
auto outapp = new EQApplicationPacket(
|
||||||
|
|||||||
@ -274,7 +274,7 @@ namespace RoF2
|
|||||||
unsigned char *emu_buffer = in->pBuffer;
|
unsigned char *emu_buffer = in->pBuffer;
|
||||||
uint32 opcode = *((uint32*)emu_buffer);
|
uint32 opcode = *((uint32*)emu_buffer);
|
||||||
|
|
||||||
if (opcode == 8) {
|
if (opcode == AlternateCurrencyMode::Populate) {
|
||||||
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(
|
auto outapp = new EQApplicationPacket(
|
||||||
|
|||||||
@ -195,7 +195,7 @@ namespace UF
|
|||||||
unsigned char *emu_buffer = in->pBuffer;
|
unsigned char *emu_buffer = in->pBuffer;
|
||||||
uint32 opcode = *((uint32*)emu_buffer);
|
uint32 opcode = *((uint32*)emu_buffer);
|
||||||
|
|
||||||
if (opcode == 8) {
|
if (opcode == AlternateCurrencyMode::Populate) {
|
||||||
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(
|
auto outapp = new EQApplicationPacket(
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
* Any modifications to base repositories are to be made by the generator only
|
* Any modifications to base repositories are to be made by the generator only
|
||||||
*
|
*
|
||||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
* @docs https://docs.eqemu.io/developer/repositories
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EQEMU_BASE_CHARACTER_ALT_CURRENCY_REPOSITORY_H
|
#ifndef EQEMU_BASE_CHARACTER_ALT_CURRENCY_REPOSITORY_H
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include "../../strings.h"
|
#include "../../strings.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
class BaseCharacterAltCurrencyRepository {
|
class BaseCharacterAltCurrencyRepository {
|
||||||
public:
|
public:
|
||||||
struct CharacterAltCurrency {
|
struct CharacterAltCurrency {
|
||||||
@ -112,8 +113,9 @@ public:
|
|||||||
{
|
{
|
||||||
auto results = db.QueryDatabase(
|
auto results = db.QueryDatabase(
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"{} WHERE id = {} LIMIT 1",
|
"{} WHERE {} = {} LIMIT 1",
|
||||||
BaseSelect(),
|
BaseSelect(),
|
||||||
|
PrimaryKey(),
|
||||||
character_alt_currency_id
|
character_alt_currency_id
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -338,6 +340,66 @@ public:
|
|||||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string BaseReplace()
|
||||||
|
{
|
||||||
|
return fmt::format(
|
||||||
|
"REPLACE INTO {} ({}) ",
|
||||||
|
TableName(),
|
||||||
|
ColumnsRaw()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ReplaceOne(
|
||||||
|
Database& db,
|
||||||
|
const CharacterAltCurrency &e
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
v.push_back(std::to_string(e.char_id));
|
||||||
|
v.push_back(std::to_string(e.currency_id));
|
||||||
|
v.push_back(std::to_string(e.amount));
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"{} VALUES ({})",
|
||||||
|
BaseReplace(),
|
||||||
|
Strings::Implode(",", v)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (results.Success() ? results.RowsAffected() : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ReplaceMany(
|
||||||
|
Database& db,
|
||||||
|
const std::vector<CharacterAltCurrency> &entries
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::vector<std::string> insert_chunks;
|
||||||
|
|
||||||
|
for (auto &e: entries) {
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
v.push_back(std::to_string(e.char_id));
|
||||||
|
v.push_back(std::to_string(e.currency_id));
|
||||||
|
v.push_back(std::to_string(e.amount));
|
||||||
|
|
||||||
|
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"{} VALUES {}",
|
||||||
|
BaseReplace(),
|
||||||
|
Strings::Implode(",", insert_chunks)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (results.Success() ? results.RowsAffected() : 0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_BASE_CHARACTER_ALT_CURRENCY_REPOSITORY_H
|
#endif //EQEMU_BASE_CHARACTER_ALT_CURRENCY_REPOSITORY_H
|
||||||
|
|||||||
@ -6564,27 +6564,33 @@ void Client::RemoveFromInstance(uint16 instance_id)
|
|||||||
|
|
||||||
void Client::SendAltCurrencies() {
|
void Client::SendAltCurrencies() {
|
||||||
if (ClientVersion() >= EQ::versions::ClientVersion::SoF) {
|
if (ClientVersion() >= EQ::versions::ClientVersion::SoF) {
|
||||||
uint32 count = zone->AlternateCurrencies.size();
|
const uint32 currency_count = zone->AlternateCurrencies.size();
|
||||||
if(count == 0) {
|
if (!currency_count) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto outapp =
|
auto outapp = new EQApplicationPacket(
|
||||||
new EQApplicationPacket(OP_AltCurrency, sizeof(AltCurrencyPopulate_Struct) +
|
OP_AltCurrency,
|
||||||
sizeof(AltCurrencyPopulateEntry_Struct) * count);
|
sizeof(AltCurrencyPopulate_Struct) +
|
||||||
AltCurrencyPopulate_Struct *altc = (AltCurrencyPopulate_Struct*)outapp->pBuffer;
|
sizeof(AltCurrencyPopulateEntry_Struct) * currency_count
|
||||||
altc->opcode = ALT_CURRENCY_OP_POPULATE;
|
);
|
||||||
altc->count = count;
|
|
||||||
|
auto a = (AltCurrencyPopulate_Struct*) outapp->pBuffer;
|
||||||
|
|
||||||
|
a->opcode = AlternateCurrencyMode::Populate;
|
||||||
|
a->count = currency_count;
|
||||||
|
|
||||||
uint32 currency_id = 0;
|
uint32 currency_id = 0;
|
||||||
for (const auto& alternate_currency : zone->AlternateCurrencies) {
|
for (const auto& c : zone->AlternateCurrencies) {
|
||||||
const EQ::ItemData* item = database.GetItem(alternate_currency.item_id);
|
const auto* item = database.GetItem(c.item_id);
|
||||||
altc->entries[currency_id].currency_number = alternate_currency.id;
|
|
||||||
altc->entries[currency_id].unknown00 = 1;
|
a->entries[currency_id].currency_number = c.id;
|
||||||
altc->entries[currency_id].currency_number2 = alternate_currency.id;
|
a->entries[currency_id].unknown00 = 1;
|
||||||
altc->entries[currency_id].item_id = alternate_currency.item_id;
|
a->entries[currency_id].currency_number2 = c.id;
|
||||||
altc->entries[currency_id].item_icon = item ? item->Icon : 1000;
|
a->entries[currency_id].item_id = c.item_id;
|
||||||
altc->entries[currency_id].stack_size = item ? item->StackSize : 1000;
|
a->entries[currency_id].item_icon = item ? item->Icon : 1000;
|
||||||
|
a->entries[currency_id].stack_size = item ? item->StackSize : 1000;
|
||||||
|
|
||||||
currency_id++;
|
currency_id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6681,11 +6687,8 @@ void Client::SendAlternateCurrencyValue(uint32 currency_id, bool send_if_null)
|
|||||||
uint32 Client::GetAlternateCurrencyValue(uint32 currency_id) const
|
uint32 Client::GetAlternateCurrencyValue(uint32 currency_id) const
|
||||||
{
|
{
|
||||||
auto iter = alternate_currency.find(currency_id);
|
auto iter = alternate_currency.find(currency_id);
|
||||||
if(iter == alternate_currency.end()) {
|
|
||||||
return 0;
|
return iter == alternate_currency.end() ? 0 : (*iter).second;
|
||||||
} else {
|
|
||||||
return (*iter).second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::ProcessAlternateCurrencyQueue() {
|
void Client::ProcessAlternateCurrencyQueue() {
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
#include "../common/repositories/character_currency_repository.h"
|
#include "../common/repositories/character_currency_repository.h"
|
||||||
#include "../common/repositories/character_alternate_abilities_repository.h"
|
#include "../common/repositories/character_alternate_abilities_repository.h"
|
||||||
#include "../common/repositories/character_auras_repository.h"
|
#include "../common/repositories/character_auras_repository.h"
|
||||||
|
#include "../common/repositories/character_alt_currency_repository.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -2908,27 +2909,34 @@ void ZoneDatabase::QGlobalPurge()
|
|||||||
database.QueryDatabase(query);
|
database.QueryDatabase(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map<uint32, uint32> ¤cy) {
|
void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map<uint32, uint32> ¤cy)
|
||||||
|
{
|
||||||
|
const auto& l = CharacterAltCurrencyRepository::GetWhere(
|
||||||
|
*this,
|
||||||
|
fmt::format(
|
||||||
|
"`char_id` = {}",
|
||||||
|
char_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
std::string query = StringFormat("SELECT currency_id, amount "
|
if (l.empty()) {
|
||||||
"FROM character_alt_currency "
|
|
||||||
"WHERE char_id = '%u'", char_id);
|
|
||||||
auto results = QueryDatabase(query);
|
|
||||||
if (!results.Success()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& row = results.begin(); row != results.end(); ++row)
|
for (const auto& e : l) {
|
||||||
currency[Strings::ToInt(row[0])] = Strings::ToInt(row[1]);
|
currency[e.currency_id] = e.amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, uint32 value) {
|
void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, uint32 value)
|
||||||
|
{
|
||||||
|
auto e = CharacterAltCurrencyRepository::NewEntity();
|
||||||
|
|
||||||
std::string query = StringFormat("REPLACE INTO character_alt_currency (char_id, currency_id, amount) "
|
e.char_id = char_id;
|
||||||
"VALUES('%u', '%u', '%u')", char_id, currency_id, value);
|
e.currency_id = currency_id;
|
||||||
database.QueryDatabase(query);
|
e.amount = value;
|
||||||
|
|
||||||
|
CharacterAltCurrencyRepository::ReplaceOne(*this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::SaveBuffs(Client *client)
|
void ZoneDatabase::SaveBuffs(Client *client)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user