int ItemManager::getMaxAmount(string itemName) { Row* row = DATABASE->get("item", itemName); if (row == NULL) return 0; return atoi(row->find("maxamount")->second.c_str()); }
string ItemManager::getImageName(string itemName) { Row* row = DATABASE->get("item", itemName); if (row == NULL) return ""; return row->find("image")->second; }
Status serializeRow(const Row& r, const ColumnNames& cols, JSON& doc, rj::Value& obj) { if (cols.empty()) { for (const auto& i : r) { doc.addRef(i.first, i.second, obj); } } else { for (const auto& c : cols) { auto i = r.find(c); if (i != r.end()) { doc.addRef(c, i->second, obj); } } } return Status(); }
bool Database::modify(std::string tablename, std::string keyValue, Row &object) { Row* row = get(tablename, keyValue); if (row == NULL) { return false; } for (Row::iterator i = object.begin(), temp; i != object.end(); i++) { temp = row->find(i->first); if (temp != row->end()) { temp->second = i->second; } else { row->insert(make_pair(i->first, i->second)); } } return true; }
Item* ItemManager::createItem(std::string itemName, int amount) { Item* item = NULL; Row* row = DATABASE->get("item", itemName); if (row == NULL) return NULL; string imageName = row->find("image")->second; string spriteImageName = row->find("spriteimage")->second; ITEM_TYPE itemType = (ITEM_TYPE)atoi(row->find("itemtype")->second.c_str()); EQUIPMENT_TYPE equipType = (EQUIPMENT_TYPE)atoi(row->find("equiptype")->second.c_str()); int maxAmount = atoi(row->find("maxamount")->second.c_str()); int hp = atoi(row->find("hp")->second.c_str()); int mp = atoi(row->find("mp")->second.c_str()); int attack = atoi(row->find("attack")->second.c_str()); int defense = atoi(row->find("defense")->second.c_str()); int atkSpeed = atoi(row->find("atkspeed")->second.c_str()); int shootNum = atoi(row->find("shootnum")->second.c_str()); int mana = atoi(row->find("mana")->second.c_str()); bool doubleJump = atoi(row->find("doublejump")->second.c_str()); bool fastRun = atoi(row->find("fastrun")->second.c_str()); bool fly = atoi(row->find("fly")->second.c_str()); item = new Item; item->initialize(itemName, imageName, spriteImageName, itemType, equipType, maxAmount, hp, mp, attack, defense, atkSpeed, shootNum, mana, doubleJump, fastRun, fly); item->addAmount(amount); _vItem.push_back(item); return item; }