mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-02 08:26:36 +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:
+24
-21
@@ -6564,27 +6564,33 @@ void Client::RemoveFromInstance(uint16 instance_id)
|
||||
|
||||
void Client::SendAltCurrencies() {
|
||||
if (ClientVersion() >= EQ::versions::ClientVersion::SoF) {
|
||||
uint32 count = zone->AlternateCurrencies.size();
|
||||
if(count == 0) {
|
||||
const uint32 currency_count = zone->AlternateCurrencies.size();
|
||||
if (!currency_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto outapp = new EQApplicationPacket(
|
||||
OP_AltCurrency,
|
||||
sizeof(AltCurrencyPopulate_Struct) +
|
||||
sizeof(AltCurrencyPopulateEntry_Struct) * currency_count
|
||||
);
|
||||
|
||||
auto outapp =
|
||||
new EQApplicationPacket(OP_AltCurrency, sizeof(AltCurrencyPopulate_Struct) +
|
||||
sizeof(AltCurrencyPopulateEntry_Struct) * count);
|
||||
AltCurrencyPopulate_Struct *altc = (AltCurrencyPopulate_Struct*)outapp->pBuffer;
|
||||
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;
|
||||
for (const auto& alternate_currency : zone->AlternateCurrencies) {
|
||||
const EQ::ItemData* item = database.GetItem(alternate_currency.item_id);
|
||||
altc->entries[currency_id].currency_number = alternate_currency.id;
|
||||
altc->entries[currency_id].unknown00 = 1;
|
||||
altc->entries[currency_id].currency_number2 = alternate_currency.id;
|
||||
altc->entries[currency_id].item_id = alternate_currency.item_id;
|
||||
altc->entries[currency_id].item_icon = item ? item->Icon : 1000;
|
||||
altc->entries[currency_id].stack_size = item ? item->StackSize : 1000;
|
||||
for (const auto& c : zone->AlternateCurrencies) {
|
||||
const auto* item = database.GetItem(c.item_id);
|
||||
|
||||
a->entries[currency_id].currency_number = c.id;
|
||||
a->entries[currency_id].unknown00 = 1;
|
||||
a->entries[currency_id].currency_number2 = c.id;
|
||||
a->entries[currency_id].item_id = c.item_id;
|
||||
a->entries[currency_id].item_icon = item ? item->Icon : 1000;
|
||||
a->entries[currency_id].stack_size = item ? item->StackSize : 1000;
|
||||
|
||||
currency_id++;
|
||||
}
|
||||
|
||||
@@ -6681,11 +6687,8 @@ void Client::SendAlternateCurrencyValue(uint32 currency_id, bool send_if_null)
|
||||
uint32 Client::GetAlternateCurrencyValue(uint32 currency_id) const
|
||||
{
|
||||
auto iter = alternate_currency.find(currency_id);
|
||||
if(iter == alternate_currency.end()) {
|
||||
return 0;
|
||||
} else {
|
||||
return (*iter).second;
|
||||
}
|
||||
|
||||
return iter == alternate_currency.end() ? 0 : (*iter).second;
|
||||
}
|
||||
|
||||
void Client::ProcessAlternateCurrencyQueue() {
|
||||
|
||||
+23
-15
@@ -34,6 +34,7 @@
|
||||
#include "../common/repositories/character_currency_repository.h"
|
||||
#include "../common/repositories/character_alternate_abilities_repository.h"
|
||||
#include "../common/repositories/character_auras_repository.h"
|
||||
#include "../common/repositories/character_alt_currency_repository.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@@ -2908,27 +2909,34 @@ void ZoneDatabase::QGlobalPurge()
|
||||
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 "
|
||||
"FROM character_alt_currency "
|
||||
"WHERE char_id = '%u'", char_id);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& row = results.begin(); row != results.end(); ++row)
|
||||
currency[Strings::ToInt(row[0])] = Strings::ToInt(row[1]);
|
||||
if (l.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& e : l) {
|
||||
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) "
|
||||
"VALUES('%u', '%u', '%u')", char_id, currency_id, value);
|
||||
database.QueryDatabase(query);
|
||||
e.char_id = char_id;
|
||||
e.currency_id = currency_id;
|
||||
e.amount = value;
|
||||
|
||||
CharacterAltCurrencyRepository::ReplaceOne(*this, e);
|
||||
}
|
||||
|
||||
void ZoneDatabase::SaveBuffs(Client *client)
|
||||
|
||||
Reference in New Issue
Block a user