Working working working on getting the basics setup

This commit is contained in:
KimLS
2015-02-21 15:21:45 -08:00
parent a90e9cf4c6
commit f511862004
10 changed files with 260 additions and 263 deletions
+4
View File
@@ -92,3 +92,7 @@ bool EQEmu::Inventory::Put(const InventorySlot &slot, std::shared_ptr<ItemInstan
return false;
}
bool EQEmu::Inventory::Swap(const InventorySlot &src, const InventorySlot &dest) {
return false;
}
+3 -1
View File
@@ -59,7 +59,9 @@ namespace EQEmu
std::shared_ptr<ItemInstance> Get(const InventorySlot &slot);
bool Put(const InventorySlot &slot, std::shared_ptr<ItemInstance> inst);
bool Swap(const InventorySlot &src, const InventorySlot &dest);
bool Swap(const InventorySlot &src, const InventorySlot &dest);
void Serialize();
private:
struct impl;
impl *impl_;
+3 -3
View File
@@ -23,7 +23,7 @@ EQEmu::ItemContainer::ItemContainer(ItemContainer &&other) {
other.impl_ = nullptr;
}
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemContainer::Get(int slot_id) {
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemContainer::Get(const int slot_id) {
auto iter = impl_->items.find(slot_id);
if(iter != impl_->items.end()) {
return iter->second;
@@ -32,7 +32,7 @@ std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemContainer::Get(int slot_id) {
return std::shared_ptr<EQEmu::ItemInstance>(nullptr);
}
bool EQEmu::ItemContainer::Put(int slot_id, std::shared_ptr<ItemInstance> inst) {
bool EQEmu::ItemContainer::Put(const int slot_id, std::shared_ptr<ItemInstance> inst) {
if(!inst)
return false;
@@ -46,7 +46,7 @@ bool EQEmu::ItemContainer::Put(int slot_id, std::shared_ptr<ItemInstance> inst)
return false;
}
bool EQEmu::ItemContainer::Delete(int slot_id) {
bool EQEmu::ItemContainer::Delete(const int slot_id) {
auto iter = impl_->items.find(slot_id);
if(iter == impl_->items.end()) {
return false;
+3 -3
View File
@@ -31,9 +31,9 @@ namespace EQEmu
~ItemContainer();
ItemContainer(ItemContainer &&other);
std::shared_ptr<ItemInstance> Get(int slot_id);
bool Put(int slot_id, std::shared_ptr<ItemInstance> inst);
bool Delete(int slot_id);
std::shared_ptr<ItemInstance> Get(const int slot_id);
bool Put(const int slot_id, std::shared_ptr<ItemInstance> inst);
bool Delete(const int slot_id);
private:
ItemContainer(const ItemContainer &other);
ItemContainer& operator=(const ItemContainer &other);
+43 -2
View File
@@ -31,6 +31,7 @@ struct EQEmu::ItemInstance::impl {
uint32 ornament_icon_;
uint32 ornament_hero_model_;
uint64 tracking_id_;
uint32 recast_timestamp_;
ItemContainer contents_;
};
@@ -44,6 +45,7 @@ EQEmu::ItemInstance::ItemInstance() {
impl_->ornament_idfile_ = 0;
impl_->ornament_icon_ = 0;
impl_->ornament_hero_model_ = 0;
impl_->recast_timestamp_ = 0;
impl_->tracking_id_ = 0;
}
@@ -57,6 +59,7 @@ EQEmu::ItemInstance::ItemInstance(const ItemData* idata) {
impl_->ornament_idfile_ = 0;
impl_->ornament_icon_ = 0;
impl_->ornament_hero_model_ = 0;
impl_->recast_timestamp_ = 0;
impl_->tracking_id_ = 0;
}
@@ -70,6 +73,7 @@ EQEmu::ItemInstance::ItemInstance(const ItemData* idata, int16 charges) {
impl_->ornament_idfile_ = 0;
impl_->ornament_icon_ = 0;
impl_->ornament_hero_model_ = 0;
impl_->recast_timestamp_ = 0;
impl_->tracking_id_ = 0;
}
@@ -81,7 +85,7 @@ const ItemData *EQEmu::ItemInstance::GetItem() {
return impl_->modified_item_ ? impl_->modified_item_ : impl_->base_item_;
}
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::Get(int index) {
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::Get(const int index) {
if(EQEmu::ValueWithin(index, 0, 255)) {
return impl_->contents_.Get(index);
}
@@ -89,7 +93,7 @@ std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::Get(int index) {
return std::shared_ptr<EQEmu::ItemInstance>(nullptr);
}
bool EQEmu::ItemInstance::Put(int index, std::shared_ptr<ItemInstance> inst) {
bool EQEmu::ItemInstance::Put(const int index, std::shared_ptr<ItemInstance> inst) {
if(!inst || !inst->GetItem()) {
return false;
}
@@ -126,3 +130,40 @@ bool EQEmu::ItemInstance::Put(int index, std::shared_ptr<ItemInstance> inst) {
return false;
}
void EQEmu::ItemInstance::SetCharges(const int16 charges) {
impl_->charges_ = charges;
}
void EQEmu::ItemInstance::SetColor(const uint32 color) {
impl_->color_ = color;
}
void EQEmu::ItemInstance::SetAttuned(const bool attuned) {
impl_->attuned_ = attuned;
}
void EQEmu::ItemInstance::SetCustomData(const std::string &custom_data) {
//We need to actually set the custom data stuff based on this string
impl_->custom_data_ = custom_data;
}
void EQEmu::ItemInstance::SetOrnamentIDFile(const uint32 ornament_idfile) {
impl_->ornament_idfile_ = ornament_idfile;
}
void EQEmu::ItemInstance::SetOrnamentIcon(const uint32 ornament_icon) {
impl_->ornament_icon_ = ornament_icon;
}
void EQEmu::ItemInstance::SetOrnamentHeroModel(const uint32 ornament_hero_model) {
impl_->ornament_hero_model_ = ornament_hero_model;
}
void EQEmu::ItemInstance::SetTrackingID(const uint64 tracking_id) {
impl_->tracking_id_ = tracking_id;
}
void EQEmu::ItemInstance::SetRecastTimestamp(const uint32 recast_timestamp) {
impl_->recast_timestamp_ = recast_timestamp;
}
+13 -3
View File
@@ -29,12 +29,22 @@ namespace EQEmu
public:
ItemInstance();
ItemInstance(const ItemData* idata);
ItemInstance(const ItemData* idata, int16 charges);
ItemInstance(const ItemData* idata, const int16 charges);
~ItemInstance();
const ItemData *GetItem();
std::shared_ptr<ItemInstance> Get(int index);
bool Put(int index, std::shared_ptr<ItemInstance> inst);
std::shared_ptr<ItemInstance> Get(const int index);
bool Put(const int index, std::shared_ptr<ItemInstance> inst);
void SetCharges(const int16 charges);
void SetColor(const uint32 color);
void SetAttuned(const bool attuned);
void SetCustomData(const std::string &custom_data);
void SetOrnamentIDFile(const uint32 ornament_idfile);
void SetOrnamentIcon(const uint32 ornament_icon);
void SetOrnamentHeroModel(const uint32 ornament_hero_model);
void SetTrackingID(const uint64 tracking_id);
void SetRecastTimestamp(const uint32 recast_timestamp);
private:
struct impl;
impl *impl_;
+57 -139
View File
@@ -487,145 +487,63 @@ bool SharedDatabase::GetSharedBank(uint32 id, InventoryOld *inv, bool is_charid)
// Overloaded: Retrieve character inventory based on character id
bool SharedDatabase::GetInventory(uint32 char_id, EQEmu::Inventory *inv)
{
return false;
//// Retrieve character inventory
//std::string query =
// StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, "
// "augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model FROM "
// "inventory WHERE charid = %i ORDER BY slotid",
// char_id);
//auto results = QueryDatabase(query);
//if (!results.Success()) {
// Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the "
// "following SQL Queries:\nalter table inventory add instnodrop "
// "tinyint(1) unsigned default 0 not null;\n");
// return false;
//}
//
//auto timestamps = GetItemRecastTimestamps(char_id);
//
//for (auto row = results.begin(); row != results.end(); ++row) {
// int16 slot_id = atoi(row[0]);
// uint32 item_id = atoi(row[1]);
// uint16 charges = atoi(row[2]);
// uint32 color = atoul(row[3]);
//
// uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
//
// aug[0] = (uint32)atoul(row[4]);
// aug[1] = (uint32)atoul(row[5]);
// aug[2] = (uint32)atoul(row[6]);
// aug[3] = (uint32)atoul(row[7]);
// aug[4] = (uint32)atoul(row[8]);
// aug[5] = (uint32)atoul(row[9]);
//
// bool instnodrop = (row[10] && (uint16)atoi(row[10])) ? true : false;
//
// uint32 ornament_icon = (uint32)atoul(row[12]);
// uint32 ornament_idfile = (uint32)atoul(row[13]);
// uint32 ornament_hero_model = (uint32)atoul(row[14]);
//
// const ItemData *item = GetItem(item_id);
//
// if (!item) {
// Log.Out(Logs::General, Logs::Error,
// "Warning: charid %i has an invalid item_id %i in inventory slot %i", char_id, item_id,
// slot_id);
// continue;
// }
//
// int16 put_slot_id = INVALID_INDEX;
//
// ItemInst *inst = CreateBaseItemOld(item, charges);
//
// if (inst == nullptr)
// continue;
//
// if (row[11]) {
// std::string data_str(row[11]);
// std::string idAsString;
// std::string value;
// bool use_id = true;
//
// for (int i = 0; i < data_str.length(); ++i) {
// if (data_str[i] == '^') {
// if (!use_id) {
// inst->SetCustomData(idAsString, value);
// idAsString.clear();
// value.clear();
// }
//
// use_id = !use_id;
// continue;
// }
//
// char v = data_str[i];
// if (use_id)
// idAsString.push_back(v);
// else
// value.push_back(v);
// }
// }
//
// inst->SetOrnamentIcon(ornament_icon);
// inst->SetOrnamentationIDFile(ornament_idfile);
// inst->SetOrnamentHeroModel(ornament_hero_model);
//
// if (instnodrop ||
// (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) ||
// slot_id == MainPowerSource) &&
// inst->GetItem()->Attuneable))
// inst->SetAttuned(true);
//
// if (color > 0)
// inst->SetColor(color);
//
// if (charges == 0x7FFF)
// inst->SetCharges(-1);
// else if (charges == 0 &&
// inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable.
// inst->SetCharges(1);
// else
// inst->SetCharges(charges);
//
// if (item->RecastDelay) {
// if (timestamps.count(item->RecastType))
// inst->SetRecastTimestamp(timestamps.at(item->RecastType));
// else
// inst->SetRecastTimestamp(0);
// }
//
// if (item->ItemClass == ItemClassCommon) {
// for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
// if (aug[i])
// inst->PutAugment(this, i, aug[i]);
// }
// }
//
// if (slot_id >= 8000 && slot_id <= 8999) {
// put_slot_id = inv->PushCursor(*inst);
// } else if (slot_id >= 3111 && slot_id <= 3179) {
// // Admins: please report any occurrences of this error
// Log.Out(Logs::General, Logs::Error, "Warning: Defunct location for item in inventory: "
// "charid=%i, item_id=%i, slot_id=%i .. pushing to cursor...",
// char_id, item_id, slot_id);
// put_slot_id = inv->PushCursor(*inst);
// } else {
// put_slot_id = inv->PutItem(slot_id, *inst);
// }
//
// safe_delete(inst);
//
// // Save ptr to item in inventory
// if (put_slot_id == INVALID_INDEX) {
// Log.Out(Logs::General, Logs::Error,
// "Warning: Invalid slot_id for item in inventory: charid=%i, item_id=%i, slot_id=%i",
// char_id, item_id, slot_id);
// }
//}
//
//// Retrieve shared inventory
//return GetSharedBank(char_id, inv, true);
std::string query = StringFormat("SELECT type, slot, bag_index, aug_index, item_id, charges, color, attuned, "
"custom_data, ornament_icon, ornament_idfile, ornament_hero_model, tracking_id "
"FROM character_inventory WHERE id=%u ORDER BY type, slot, bag_index, aug_index",
char_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "Error with query in SharedDatabase::GetInventory, could not get inventory"
" for character %u", char_id);
return false;
}
auto timestamps = GetItemRecastTimestamps(char_id);
for(auto row : results) {
int type = atoi(row[0]);
int slot = atoi(row[1]);
int bag_index = atoi(row[2]);
int aug_index = atoi(row[3]);
int item_id = atoi(row[4]);
int charges = atoi(row[5]);
auto inst = CreateItem(item_id, charges);
if(inst) {
uint32 color = (uint32)std::stoul(row[6]);
int attuned = atoi(row[7]);
uint32 ornament_icon = (uint32)std::stoul(row[9]);
uint32 ornament_idfile = (uint32)std::stoul(row[10]);
uint32 ornament_hero_model = (uint32)std::stoul(row[11]);
uint64 tracking_id = (uint64)std::stoull(row[12]);
inst->SetColor(color);
inst->SetAttuned(attuned ? true : false);
inst->SetCustomData(row[8]);
inst->SetOrnamentIcon(ornament_icon);
inst->SetOrnamentIDFile(ornament_idfile);
inst->SetOrnamentHeroModel(ornament_hero_model);
inst->SetTrackingID(tracking_id);
auto *item = inst->GetItem();
if(item->RecastDelay) {
if(timestamps.count(item->RecastType)) {
inst->SetRecastTimestamp(timestamps.at(item->RecastType));
}
}
if(!inv->Put(EQEmu::InventorySlot(type, slot, bag_index, aug_index), inst)) {
Log.Out(Logs::General, Logs::Error, "Error putting item %u into (%d, %d, %d, %d) for char %u.",
item_id, type, slot, bag_index, aug_index, char_id);
}
} else {
Log.Out(Logs::General, Logs::Error, "Error putting item %u into (%d, %d, %d, %d) for char %u. Item does not exist.",
item_id, type, slot, bag_index, aug_index, char_id);
}
}
return true;
}
// Overloaded: Retrieve character inventory based on account_id and character name