📄 itemdb.cpp
字号:
#include "itemdb.h"
#include <fstream>
#include <algorithm>
#include <set>
using namespace std;
char* ItemTypeNames[NUM_ITEM_TYPES] = {
"All",
"Helmets",
"Neck",
"Shoulder armor",
"Shirts",
"Chest armor",
"Belts",
"Pants",
"Boots",
"Bracers",
"Gloves",
"Rings",
"Accessories",
"Daggers",
"Shields",
"Bows",
"Capes",
"Two-handed weapons",
"Quivers",
"Tabards",
"Robes",
"One-handed weapons",
"Claws",
"Offhand",
"?", // unused?
"Thrown",
"Guns and wands"
};
// ItemDisplayInfo
ItemDisplayDB::Record ItemDisplayDB::getById(unsigned int id)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getUInt(ItemDisplayID)==id)
return (*i);
}
throw NotFound();
}
ItemVisualDB::Record ItemVisualDB::getById(unsigned int id)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getUInt(VisualID)==id)
return (*i);
}
throw NotFound();
}
ItemVisualEffectDB::Record ItemVisualEffectDB::getById(unsigned int id)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getUInt(EffectID)==id)
return (*i);
}
throw NotFound();
}
ItemSetDB::Record ItemSetDB::getById(unsigned int id)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getUInt(SetID)==id)
return (*i);
}
throw NotFound();
}
void ItemSetDB::cleanup(ItemDatabase &itemdb)
{
for(Iterator i=begin(); i!=end(); ++i) {
for (int j=0; j<NumItems; j++) {
int id = i->getUInt(ItemIDBase+j);
if (id > 0) {
const ItemRecord &r = itemdb.get(id);
if (r.type > 0) {
avail.insert(i->getUInt(SetID));
break;
}
}
}
}
}
bool ItemSetDB::available(unsigned int id)
{
return (avail.find(id)!=avail.end());
}
StartOutfitDB::Record StartOutfitDB::getById(unsigned int id)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getUInt(StartOutfitID)==id)
return (*i);
}
throw NotFound();
}
////////////////////
ItemRecord::ItemRecord(const char* line)
{
sscanf(line, "%u,%u,%u,%u,%u,%u", &id, &model, &itemclass, &subclass, &type, &sheath);
for (size_t i=strlen(line)-2; i>1; i--) {
if (line[i]==',') {
name = (line + i + 1);
break;
}
}
}
ItemDatabase::ItemDatabase(const char* filename)
{
ItemRecord all("---- None ----", IT_ALL);
items.push_back(all);
ifstream fin(filename);
char line[512];
while (fin.getline(line,512)) {
ItemRecord rec(line);
if (rec.type > 0) {
items.push_back(rec);
}
}
fin.close();
sort(items.begin(), items.end());
}
void ItemDatabase::open(const char* filename)
{
ItemRecord all("---- None ----", IT_ALL);
items.push_back(all);
ifstream fin(filename);
char line[512];
while (fin.getline(line,512)) {
ItemRecord rec(line);
if (rec.type > 0) {
items.push_back(rec);
}
}
fin.close();
sort(items.begin(), items.end());
}
void ItemDatabase::cleanup(ItemDisplayDB &itemdb)
{
set<unsigned int> itemset;
for (ItemDisplayDB::Iterator it = itemdb.begin(); it != itemdb.end(); ++it) {
itemset.insert(it->getUInt(ItemDisplayDB::ItemDisplayID));
}
for (unsigned int i=0; i<items.size(); ) {
bool keepItem = (items[i].type==0) || (itemset.find(items[i].model)!=itemset.end());
if (keepItem) {
itemLookup[items[i].id] = i;
i++;
}
else items.erase(items.begin() + i);
}
}
const ItemRecord& ItemDatabase::get(int id)
{
if (itemLookup.find(id)!=itemLookup.end()) return items[itemLookup[id]];
else return items[0];
}
int ItemDatabase::getItemNum(int id)
{
for (std::vector<ItemRecord>::iterator it = items.begin(); it != items.end(); ++it)
if(it->model == id) return it->id;
return 0;
}
///////////////////
ItemSubClassDB::Record ItemSubClassDB::getById(int id, int subid)
{
for(Iterator i=begin(); i!=end(); ++i)
{
if (i->getInt(ClassID)==id && i->getInt(SubClassID)==subid)
return (*i);
}
throw NotFound();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -