[Commands] Add #setaltcurrency Command. (#1850)

* [Commands] Add #setaltcurrency Command.
- Add #setaltcurrency [Currency ID] [Amount] command to allow you to set a specific alternate currency to a value.
- Add Zone::GetCurrencyID() and Zone::GetCurrencyItemID() helper methods.
- Cleanup loops through zone->AlternateCurrencies.
- Utilize helper methods where necessary.
- Convert old methods parameters and return values from int to uint32 where necessary.

* Typo.
This commit is contained in:
Kinglykrab
2021-12-08 18:58:06 -05:00
committed by GitHub
parent 94166e0f95
commit 294e51fca7
12 changed files with 141 additions and 86 deletions
+33 -4
View File
@@ -2421,10 +2421,9 @@ void Zone::LoadAlternateCurrencies()
return;
}
for (auto row = results.begin(); row != results.end(); ++row)
{
current_currency.id = atoi(row[0]);
current_currency.item_id = atoi(row[1]);
for (auto row : results) {
current_currency.id = std::stoul(row[0]);
current_currency.item_id = std::stoul(row[1]);
AlternateCurrencies.push_back(current_currency);
}
@@ -2744,3 +2743,33 @@ DynamicZone* Zone::GetDynamicZone()
return nullptr;
}
uint32 Zone::GetCurrencyID(uint32 item_id)
{
if (!item_id) {
return 0;
}
for (const auto& alternate_currency : AlternateCurrencies) {
if (item_id == alternate_currency.item_id) {
return alternate_currency.id;
}
}
return 0;
}
uint32 Zone::GetCurrencyItemID(uint32 currency_id)
{
if (!currency_id) {
return 0;
}
for (const auto& alternate_currency : AlternateCurrencies) {
if (currency_id == alternate_currency.id) {
return alternate_currency.item_id;
}
}
return 0;
}