diff --git a/src/main.cpp b/src/main.cpp index a773377..ada649a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,5 +26,13 @@ int main(int argc, char* argv[]) { auto whoami = oro_api.who_am_i(); std::cout << "master id: " << whoami.second.master_id << '\n'; } + + { + auto items = oro_api.items_list(); + for (const auto& item : items.second.items) { + std::cout << "Item ID " << item.item_id << ' ' << item.name << '\n'; + } + std::cout << "Total items in DB: " << items.second.items.size() << '\n'; + } return 0; } diff --git a/src/meson.build b/src/meson.build index 1c30a8d..2e954a4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -23,6 +23,7 @@ executable(meson.project_name(), 'oro/datatypes.cpp', 'oro/api.cpp', 'oro/dateconv.cpp', + 'oro/items.cpp', project_config_file, install: true, dependencies: [restc_cpp_dep], diff --git a/src/oro/api.cpp b/src/oro/api.cpp index be11db6..944d22c 100644 --- a/src/oro/api.cpp +++ b/src/oro/api.cpp @@ -21,10 +21,29 @@ BOOST_FUSION_ADAPT_STRUCT( (unsigned int, master_id) ) +BOOST_FUSION_ADAPT_STRUCT( + oro::Item, + (unsigned int, item_id) + (std::string, unique_name) + (std::string, name) + (oro::ItemTypeWrapper, type) + (boost::optional, subtype) + (unsigned int, npc_price) + (boost::optional, slots) +) + +BOOST_FUSION_ADAPT_STRUCT( + oro::Items, + (oro::Timestamp, generation_timestamp) + (int, version) + (std::vector, items) +) + namespace oro { namespace { constexpr const char g_endpoint_ping[] = "api/v1/ping"; constexpr const char g_endpoint_whoami[] = "api/v1/whoami"; + constexpr const char g_endpoint_items_list[] = "api/v1/items/list"; template std::pair call_rest_api ( @@ -96,4 +115,8 @@ std::pair Api::who_am_i() { return call_rest_api(*m_client, m_prefix + g_endpoint_whoami, m_api_key, m_client_name, m_client_purpose); } +std::pair Api::items_list() { + return call_rest_api(*m_client, m_prefix + g_endpoint_items_list, m_api_key, m_client_name, m_client_purpose); +} + } //namespace oro diff --git a/src/oro/api.hpp b/src/oro/api.hpp index fccc70e..e008191 100644 --- a/src/oro/api.hpp +++ b/src/oro/api.hpp @@ -2,6 +2,7 @@ #include "ping.hpp" #include "whoami.hpp" +#include "items.hpp" #include #include #include @@ -56,6 +57,7 @@ public: std::pair ping(); std::pair who_am_i(); + std::pair items_list(); private: std::string m_prefix; diff --git a/src/oro/items.cpp b/src/oro/items.cpp new file mode 100644 index 0000000..f569c3f --- /dev/null +++ b/src/oro/items.cpp @@ -0,0 +1,120 @@ +#include "items.hpp" +#include + +namespace oro { +ItemTypeWrapper::ItemTypeWrapper (const std::string& str) { + *this = str; +} + +ItemTypeWrapper& ItemTypeWrapper::operator= (const std::string& str) { + if ("IT_HEALING" == str) + value = ItemType::Healing; + else if ("IT_UNKNOWN" == str) + value = ItemType::Unknown; + else if ("IT_USABLE" == str) + value = ItemType::Usable; + else if ("IT_ETC" == str) + value = ItemType::Etc; + else if ("IT_WEAPON" == str) + value = ItemType::Weapon; + else if ("IT_ARMOR" == str) + value = ItemType::Armor; + else if ("IT_CARD" == str) + value = ItemType::Card; + else if ("IT_PETEGG" == str) + value = ItemType::PetEgg; + else if ("IT_PETARMOR" == str) + value = ItemType::PetArmor; + else if ("IT_UNKNOWN2" == str) + value = ItemType::Unknown2; + else if ("IT_AMMO" == str) + value = ItemType::Ammo; + else if ("IT_DELAYCONSUME" == str) + value = ItemType::DelayConsume; + else if ("IT_CASH" == str) + value = ItemType::Cash; + else + throw std::runtime_error("Unknown item type \"" + str + "\""); + return *this; +} + +ItemSubtypeWrapper::ItemSubtypeWrapper (const std::string& str) { + *this = str; +} + +ItemSubtypeWrapper& ItemSubtypeWrapper::operator= (const std::string& str) { + //For IT_WEAPON: + if ("W_FIST" == str) + value = ItemSubtype::Fist; + else if ("W_DAGGER" == str) + value = ItemSubtype::Dagger; + else if ("W_1HSWORD" == str) + value = ItemSubtype::OneHSword; + else if ("W_2HSWORD" == str) + value = ItemSubtype::TwoHSword; + else if ("W_1HSPEAR" == str) + value = ItemSubtype::OneHSpear; + else if ("W_2HSPEAR" == str) + value = ItemSubtype::TwoHSpear; + else if ("W_1HAXE" == str) + value = ItemSubtype::OneHAxe; + else if ("W_2HAXE" == str) + value = ItemSubtype::TwoHAxe; + else if ("W_MACE" == str) + value = ItemSubtype::Mace; + else if ("W_2HMACE" == str) + value = ItemSubtype::TwoHMace; + else if ("W_STAFF" == str) + value = ItemSubtype::Staff; + else if ("W_2HSTAFF" == str) + value = ItemSubtype::TwoHStaff; + else if ("W_BOW" == str) + value = ItemSubtype::Bow; + else if ("W_KNUCKLE" == str) + value = ItemSubtype::Knuckle; + else if ("W_MUSICAL" == str) + value = ItemSubtype::Musical; + else if ("W_WHIP" == str) + value = ItemSubtype::Whip; + else if ("W_BOOK" == str) + value = ItemSubtype::Book; + else if ("W_KATAR" == str) + value = ItemSubtype::Katar; + else if ("W_REVOLVER" == str) + value = ItemSubtype::Revolver; + else if ("W_RIFLE" == str) + value = ItemSubtype::Rifle; + else if ("W_GATLING" == str) + value = ItemSubtype::Gatling; + else if ("W_SHOTGUN" == str) + value = ItemSubtype::Shotgun; + else if ("W_GRENADE" == str) + value = ItemSubtype::Grenade; + else if ("W_HUUMA" == str) + value = ItemSubtype::Huuma; + + //For IT_AMMO: + else if ("A_ARROW" == str) + value = ItemSubtype::Arrow; + else if ("A_DAGGER" == str) + value = ItemSubtype::ThrowingDagger; + else if ("A_BULLET" == str) + value = ItemSubtype::Bullet; + else if ("A_SHELL" == str) + value = ItemSubtype::Shell; + else if ("A_GRENADE" == str) + value = ItemSubtype::GrenadeAmmo; + else if ("A_SHURIKEN" == str) + value = ItemSubtype::Shuriken; + else if ("A_KUNAI" == str) + value = ItemSubtype::Kunai; + else if ("A_CANNONBALL" == str) + value = ItemSubtype::Cannonball; + else if ("A_THROWWEAPON" == str) + value = ItemSubtype::ThrowWeapon; + + else + throw std::runtime_error("Unknown item subtype \"" + str + "\""); + return *this; +} +} //namespace oro diff --git a/src/oro/items.hpp b/src/oro/items.hpp new file mode 100644 index 0000000..24ba555 --- /dev/null +++ b/src/oro/items.hpp @@ -0,0 +1,95 @@ +#pragma once + +#include "datatypes.hpp" +#include +#include +#include + +namespace oro { + enum class ItemType { + Healing, //Healing items + Unknown, //Unknown item type + Usable, //Other usable items + Etc, //Misc items + Weapon, //Weapons + Armor, //Armors + Card, //Cards + PetEgg, //Pet eggs + PetArmor, //Pet accessories + Unknown2, //Unknown items (unused) + Ammo, //Ammunitions + DelayConsume, //Consumable items (triggering additional actions) + Cash //Cash shop items + }; + + enum class ItemSubtype { + //For IT_WEAPON: + Fist, //Unknown weapon (unused) + Dagger, //Daggers + OneHSword, //1-hand swords + TwoHSword, //2-hand swords + OneHSpear, //1-hand spears + TwoHSpear, //2-hand spears + OneHAxe, //1-hand axes + TwoHAxe, //2-hand axes + Mace, //1-hand maces + TwoHMace, //2-hand maces + Staff, //Staves + TwoHStaff, //2-hand staves + Bow, //Bows + Knuckle, //Knuckles + Musical, //Musical instruments + Whip, //Whips + Book, //Books + Katar, //Katars + Revolver, //Pistols + Rifle, //Rifles + Gatling, //Gatling guns + Shotgun, //Shotguns + Grenade, //Grenades + Huuma, //Huuma shuriken + + //For IT_AMMO: + Arrow, //Arrows + ThrowingDagger, //Throwing daggers + Bullet, //Bullets + Shell, //Shells + GrenadeAmmo, //Grenades + Shuriken, //Shuriken + Kunai, //Kunai + Cannonball, //Cannon balls + ThrowWeapon, //Other throwing weapons + + Unknown + }; + + struct ItemTypeWrapper { + ItemTypeWrapper() = default; + ItemTypeWrapper (const std::string& str); + ItemTypeWrapper& operator= (const std::string& str); + operator ItemType() const {return value;} + ItemType value {ItemType::Unknown}; + }; + + struct ItemSubtypeWrapper { + ItemSubtypeWrapper() = default; + ItemSubtypeWrapper (const std::string& str); + ItemSubtypeWrapper& operator= (const std::string& str); + operator ItemSubtype() const {return value;} + ItemSubtype value {ItemSubtype::Unknown}; + }; + + struct Item { + unsigned int item_id; + std::string unique_name; + std::string name; + ItemTypeWrapper type; + boost::optional subtype; + unsigned int npc_price; + boost::optional slots; + }; + + struct Items : BaseJsonReply { + std::vector items; + }; +} //namespace oro