eliminate using namespace
This commit is contained in:
+27
-29
@@ -4,9 +4,7 @@
|
||||
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomGenerator> rand_crypt) {
|
||||
void player_use_item(std::shared_ptr<Client> c, size_t item_index, std::shared_ptr<RandomGenerator> rand_crypt) {
|
||||
auto s = c->require_server_state();
|
||||
|
||||
// On PC (and presumably DC), the client sends a 6x29 after this to delete the used item. On GC and later versions,
|
||||
@@ -26,13 +24,13 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
auto item_parameter_table = s->item_parameter_table(c->version());
|
||||
uint8_t max_level = item_parameter_table->get_max_tech_level(player->disp.visual.char_class, item.data.data1[4]);
|
||||
if (item.data.data1[2] > max_level) {
|
||||
throw runtime_error("technique level too high");
|
||||
throw std::runtime_error("technique level too high");
|
||||
}
|
||||
player->set_technique_level(item.data.data1[4], item.data.data1[2]);
|
||||
|
||||
} else if ((primary_identifier & 0xFFFF0000) == 0x030A0000) { // Grinder
|
||||
if (item.data.data1[2] > 2) {
|
||||
throw runtime_error("incorrect grinder value");
|
||||
throw std::runtime_error("incorrect grinder value");
|
||||
}
|
||||
|
||||
auto& weapon = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::WEAPON)];
|
||||
@@ -40,9 +38,9 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
auto item_parameter_table = s->item_parameter_table(c->version());
|
||||
auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]);
|
||||
if (is_v4 && (weapon.data.data1[3] >= weapon_def.max_grind)) {
|
||||
throw runtime_error("weapon already at maximum grind");
|
||||
throw std::runtime_error("weapon already at maximum grind");
|
||||
}
|
||||
weapon.data.data1[3] = min<uint8_t>(weapon.data.data1[3] + item.data.data1[2] + 1, weapon_def.max_grind);
|
||||
weapon.data.data1[3] = std::min<uint8_t>(weapon.data.data1[3] + item.data.data1[2] + 1, weapon_def.max_grind);
|
||||
|
||||
} else if ((primary_identifier & 0xFFFF0000) == 0x030B0000) { // Material
|
||||
auto p = c->character_file();
|
||||
@@ -85,11 +83,11 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
if (!is_v3_or_later && (c->version() != Version::GC_NTE)) {
|
||||
p->disp.stats.char_stats.lck += 2;
|
||||
} else {
|
||||
throw runtime_error("unknown material used");
|
||||
throw std::runtime_error("unknown material used");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("unknown material used");
|
||||
throw std::runtime_error("unknown material used");
|
||||
}
|
||||
if (is_v3_or_later || (type == Type::HP) || (type == Type::TP)) {
|
||||
p->set_material_usage(type, p->get_material_usage(type) + 1);
|
||||
@@ -98,7 +96,7 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
} else if ((primary_identifier & 0xFFFF0000) == 0x030F0000) { // AddSlot
|
||||
auto& armor = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::ARMOR)];
|
||||
if (armor.data.data1[5] >= 4) {
|
||||
throw runtime_error("armor already at maximum slot count");
|
||||
throw std::runtime_error("armor already at maximum slot count");
|
||||
}
|
||||
armor.data.data1[5]++;
|
||||
|
||||
@@ -155,7 +153,7 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
mag.data.data1[1] = 0x2B;
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid mag cell used");
|
||||
throw std::runtime_error("invalid mag cell used");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +166,7 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
sum += table.first[z].probability;
|
||||
}
|
||||
if (sum == 0) {
|
||||
throw runtime_error("no unwrap results available for event");
|
||||
throw std::runtime_error("no unwrap results available for event");
|
||||
}
|
||||
// TODO: It seems that on non-BB, clients don't synchronize this at all, so they could end up thinking the
|
||||
// unwrapped item is something completely different. (They don't even use a fixed random seed, like for rares; they
|
||||
@@ -218,30 +216,30 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
auto item_parameter_table = s->item_parameter_table(c->version());
|
||||
const auto& combo = item_parameter_table->get_item_combination(item.data, inv_item.data);
|
||||
if (combo.char_class != 0xFF && combo.char_class != player->disp.visual.char_class) {
|
||||
throw runtime_error("item combination requires specific char_class");
|
||||
throw std::runtime_error("item combination requires specific char_class");
|
||||
}
|
||||
if (combo.mag_level != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 2) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped item is not a mag");
|
||||
throw std::runtime_error("item combination applies with mag level requirement, but equipped item is not a mag");
|
||||
}
|
||||
if (inv_item.data.compute_mag_level() < combo.mag_level) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped mag level is too low");
|
||||
throw std::runtime_error("item combination applies with mag level requirement, but equipped mag level is too low");
|
||||
}
|
||||
}
|
||||
if (combo.grind != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 0) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped item is not a weapon");
|
||||
throw std::runtime_error("item combination applies with grind requirement, but equipped item is not a weapon");
|
||||
}
|
||||
if (inv_item.data.data1[3] < combo.grind) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped weapon grind is too low");
|
||||
throw std::runtime_error("item combination applies with grind requirement, but equipped weapon grind is too low");
|
||||
}
|
||||
}
|
||||
if (combo.level != 0xFF && player->disp.stats.level + 1 < combo.level) {
|
||||
throw runtime_error("item combination applies with level requirement, but player level is too low");
|
||||
throw std::runtime_error("item combination applies with level requirement, but player level is too low");
|
||||
}
|
||||
// If we get here, then the combo applies
|
||||
if (combo_applied) {
|
||||
throw runtime_error("multiple combinations apply");
|
||||
throw std::runtime_error("multiple combinations apply");
|
||||
}
|
||||
combo_applied = true;
|
||||
|
||||
@@ -254,7 +252,7 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
inv_item.data.data1[4] = 0; // Flags + special
|
||||
}
|
||||
inv_item.flags &= (~8); // Unequip it
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,13 +267,13 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
void apply_mag_feed_result(
|
||||
ItemData& mag_item,
|
||||
const ItemData& fed_item,
|
||||
shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
shared_ptr<const MagEvolutionTable> mag_evolution_table,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
std::shared_ptr<const MagEvolutionTable> mag_evolution_table,
|
||||
uint8_t char_class,
|
||||
uint8_t section_id,
|
||||
bool version_has_rare_mags) {
|
||||
|
||||
static const unordered_map<uint32_t, size_t> result_index_for_fed_item({
|
||||
static const std::unordered_map<uint32_t, size_t> result_index_for_fed_item({
|
||||
{0x03000000, 0}, // Monomate
|
||||
{0x03000100, 1}, // Dimate
|
||||
{0x03000200, 2}, // Trimate
|
||||
@@ -298,7 +296,7 @@ void apply_mag_feed_result(
|
||||
if ((delta > 0) || ((delta < 0) && (-delta < existing_stat))) {
|
||||
uint16_t level = data.compute_mag_level();
|
||||
if (level > 200) {
|
||||
throw runtime_error("mag level is too high");
|
||||
throw std::runtime_error("mag level is too high");
|
||||
}
|
||||
if ((level == 200) && ((99 - existing_stat) < delta)) {
|
||||
delta = 99 - existing_stat;
|
||||
@@ -311,8 +309,8 @@ void apply_mag_feed_result(
|
||||
update_stat(mag_item, 3, feed_result.pow);
|
||||
update_stat(mag_item, 4, feed_result.dex);
|
||||
update_stat(mag_item, 5, feed_result.mind);
|
||||
mag_item.data2[0] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data2[0]) + feed_result.synchro, 0, 120);
|
||||
mag_item.data2[1] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data2[1]) + feed_result.iq, 0, 200);
|
||||
mag_item.data2[0] = std::clamp<ssize_t>(static_cast<ssize_t>(mag_item.data2[0]) + feed_result.synchro, 0, 120);
|
||||
mag_item.data2[1] = std::clamp<ssize_t>(static_cast<ssize_t>(mag_item.data2[1]) + feed_result.iq, 0, 200);
|
||||
|
||||
uint8_t mag_level = mag_item.compute_mag_level();
|
||||
mag_item.data1[2] = mag_level;
|
||||
@@ -347,7 +345,7 @@ void apply_mag_feed_result(
|
||||
mag_item.data1[1] = 0x19; // Vritra
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid character class");
|
||||
throw std::runtime_error("invalid character class");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,7 +399,7 @@ void apply_mag_feed_result(
|
||||
} else if (is_ranger) {
|
||||
table_index += 6;
|
||||
} else if (!is_hunter) {
|
||||
throw logic_error("char class is not any of the top-level classes");
|
||||
throw std::logic_error("char class is not any of the top-level classes");
|
||||
}
|
||||
|
||||
// Note: The original code checks the class (hunter/ranger/force) again here, and goes into 3 branches that
|
||||
@@ -433,7 +431,7 @@ void apply_mag_feed_result(
|
||||
bool is_ranger = char_class_is_ranger(char_class);
|
||||
bool is_force = char_class_is_force(char_class);
|
||||
if (is_hunter + is_ranger + is_force != 1) {
|
||||
throw logic_error("char class is not exactly one of the top-level classes");
|
||||
throw std::logic_error("char class is not exactly one of the top-level classes");
|
||||
}
|
||||
|
||||
if (is_hunter) {
|
||||
|
||||
Reference in New Issue
Block a user