📄 belt.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : Belt.cpp// Written By : Elca// Description : //////////////////////////////////////////////////////////////////////////////#include "Belt.h"#include "DB.h"#include "Slayer.h"#include "Vampire.h"#include "Belt.h"#include "Motorcycle.h"#include "ItemInfoManager.h"#include "Stash.h"#include "ItemUtil.h"#include "PCItemInfo.h"// global variable declarationBeltInfoManager* g_pBeltInfoManager = NULL;ItemID_t Belt::m_ItemIDRegistry = 0;Mutex Belt::m_Mutex;//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------Belt::Belt() throw()//: m_ItemType(0), m_Durability(0), m_pInventory(NULL){ setItemType(0); setDurability(0); m_pInventory = NULL; m_EnchantLevel = 0;}Belt::Belt(ItemType_t itemType, const list<OptionType_t>& optionType) throw(Error)//: m_ItemType(itemType), m_OptionType(optionType), m_Durability(0), m_pInventory(NULL){ __BEGIN_TRY setItemType(itemType); setOptionType(optionType); BeltInfo* pBeltInfo = dynamic_cast<BeltInfo*>(g_pBeltInfoManager->getItemInfo(getItemType())); m_pInventory = new Inventory(pBeltInfo->getPocketCount(), 1); m_EnchantLevel = 0; setDurability(computeMaxDurability(this)); if (!g_pItemInfoManager->isPossibleItem(getItemClass(), getItemType(), getOptionTypeList())) { filelog("itembug.log", "Belt::Belt() : Invalid item type or option type"); throw ("Belt::Belt() : Invalid item type or optionType"); } __END_CATCH}//--------------------------------------------------------------------------------// destructor//--------------------------------------------------------------------------------Belt::~Belt() throw(){ SAFE_DELETE(m_pInventory);}//--------------------------------------------------------------------------------// create item//--------------------------------------------------------------------------------void Belt::create(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y, ItemID_t itemID) throw(Error){ __BEGIN_TRY Statement* pStmt; if (itemID==0) { __ENTER_CRITICAL_SECTION(m_Mutex) m_ItemIDRegistry += g_pItemInfoManager->getItemIDSuccessor(); m_ItemID = m_ItemIDRegistry; __LEAVE_CRITICAL_SECTION(m_Mutex) } else { m_ItemID = itemID; } BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "INSERT INTO BeltObject " << "(ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID ," << " X, Y, OptionType, Durability)" << " VALUES(" << m_ItemID << ", " << m_ObjectID << ", " << m_ItemType << ", '" << ownerID << "', " <<(int)storage << ", " << storageID << ", " <<(int)x << ", " <<(int)y << ", " <<(int)m_OptionType << ", " << m_Durability << ")"; pStmt->executeQuery(sql.toString()); */ string optionField; setOptionTypeToField( getOptionTypeList(), optionField ); pStmt->executeQuery( "INSERT INTO BeltObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, OptionType, Durability, Grade, ItemFlag) VALUES(%ld, %ld, %d, '%s', %d, %ld, %d, %d, '%s', %d, %d, %d)", m_ItemID, m_ObjectID, getItemType(), ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, optionField.c_str(), getDurability(), getGrade(), (int)m_CreateType ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// destroy item//--------------------------------------------------------------------------------bool Belt::destroy() throw(Error){ __BEGIN_TRY Statement* pStmt; //------------------------------------------------------- // 骇飘俊 巢酒乐绰 酒捞袍捞 乐促搁 救俊 乐绰 酒捞袍甸档 // destroy 秦拎具 茄促. // 骇飘 鞍篮 版快绰 困俊辑 delete窍搁辑 酒捞袍阑 昏力 // 窍扁 锭巩俊 咯扁辑绰 delete秦林瘤 臼扁肺 茄促... // 镜葛啊 绝促搁 困俊辑 鞘洒 骇飘甫 瘤况具 茄促. //------------------------------------------------------- for (int i = 0; i < m_pInventory->getHeight(); i++) { for (int j = 0; j < m_pInventory->getWidth(); j++) { Item* pItem = m_pInventory->getItem(j, i); if (pItem != NULL) { pItem->destroy(); } } } BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("DELETE FROM BeltObject WHERE ItemID = %ld", m_ItemID); if (pStmt->getAffectedRowCount()==0) { SAFE_DELETE(pStmt); return false; } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH return true;}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Belt::tinysave(const char* field) const throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE BeltObject SET %s WHERE ItemID=%ld", field, m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Belt::save(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y) throw(Error){ __BEGIN_TRY Statement* pStmt; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "UPDATE BeltObject SET " << "ObjectID = " << m_ObjectID << ",ItemType = " << m_ItemType << ",OwnerID = '" << ownerID << "'" << ",Storage = " <<(int)storage << ",StorageID = " << storageID << ",X = " <<(int)x << ",Y = " <<(int)y << ",OptionType = " <<(int)m_OptionType << ",Durability = " << m_Durability << ",EnchantLevel = " <<(int)m_EnchantLevel << " WHERE ItemID = " << m_ItemID; pStmt->executeQuery(sql.toString()); */ string optionField; setOptionTypeToField( getOptionTypeList(), optionField ); pStmt->executeQuery( "UPDATE BeltObject SET ObjectID=%ld, ItemType=%d, OwnerID= '%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, OptionType='%s', Durability=%d, Grade=%d, EnchantLevel=%d WHERE ItemID=%ld", m_ObjectID, getItemType(), ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, optionField.c_str(), getDurability(), getGrade(), (int)m_EnchantLevel, m_ItemID); // 老老捞 酒捞袍阑 窍唱究 波郴辑 官肺 UPDATE 窍档废 茄促. for (int i = 0; i < m_pInventory->getHeight(); i++) { for (int j = 0; j < m_pInventory->getWidth(); j++) { Item* pItem = m_pInventory->getItem(j, 0); if (pItem != NULL) { pItem->save(ownerID, STORAGE_BELT, m_ItemID, j, 0); } } } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}void Belt::makePCItemInfo(PCItemInfo& result) const{ Item::makePCItemInfo(result); BYTE SubItemCount = 0; // 器南狼 箭磊父怒 酒捞袍狼 沥焊甫 佬绢 甸牢促. for (int i = 0; i < getPocketCount() ; i++) { Item* pBeltItem = getInventory()->getItem(i, 0); if (pBeltItem != NULL) { SubItemInfo* pSubItemInfo = new SubItemInfo(); pSubItemInfo->setObjectID(pBeltItem->getObjectID()); pSubItemInfo->setItemClass(pBeltItem->getItemClass()); pSubItemInfo->setItemType(pBeltItem->getItemType()); pSubItemInfo->setItemNum(pBeltItem->getNum()); pSubItemInfo->setSlotID(i); result.addListElement(pSubItemInfo); SubItemCount++; } } result.setListNum(SubItemCount);}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string Belt::toString() const throw(){ StringStream msg; msg << "Belt(" << "ItemID:" << m_ItemID << ",ItemType:" <<(int)getItemType() << ",OptionType:" <<getOptionTypeToString(getOptionTypeList()).c_str() << ",Durability:" <<(int)getDurability() << ",EnchantLevel:" <<(int)m_EnchantLevel << ")"; return msg.toString();}/*//--------------------------------------------------------------------------------// get width//--------------------------------------------------------------------------------VolumeWidth_t Belt::getVolumeWidth() const throw(Error){ __BEGIN_TRY return g_pBeltInfoManager->getItemInfo(m_ItemType)->getVolumeWidth(); __END_CATCH} //--------------------------------------------------------------------------------// get height//--------------------------------------------------------------------------------VolumeHeight_t Belt::getVolumeHeight() const throw(Error){ __BEGIN_TRY return g_pBeltInfoManager->getItemInfo(m_ItemType)->getVolumeHeight(); __END_CATCH} //--------------------------------------------------------------------------------// get weight//--------------------------------------------------------------------------------Weight_t Belt::getWeight() const throw(Error){ __BEGIN_TRY return g_pBeltInfoManager->getItemInfo(m_ItemType)->getWeight(); __END_CATCH}*///--------------------------------------------------------------------------------// get pocket count//--------------------------------------------------------------------------------PocketNum_t Belt::getPocketCount(void) const throw(){ __BEGIN_TRY BeltInfo* pBeltInfo = dynamic_cast<BeltInfo*>(g_pBeltInfoManager->getItemInfo(getItemType())); Assert(pBeltInfo != NULL); return pBeltInfo->getPocketCount(); __END_CATCH}/*Defense_t Belt::getDefenseBonus() const throw(Error){ __BEGIN_TRY return g_pBeltInfoManager->getItemInfo(m_ItemType)->getDefenseBonus(); __END_CATCH}Protection_t Belt::getProtectionBonus() const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -