📄 sg.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : SG.cpp// Written By : Elca// Description : //////////////////////////////////////////////////////////////////////////////// include files#include "SG.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"// global variable declarationSGInfoManager* g_pSGInfoManager = NULL;ItemID_t SG::m_ItemIDRegistry = 0;Mutex SG::m_Mutex;//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------SG::SG() throw(){ setItemType(0); setDurability(0); setEnchantLevel(0); setBulletCount(0); setBonusDamage(0); setSilver(0);}SG::SG(ItemType_t itemType, const list<OptionType_t>& optionType) throw()//: Gun(itemType, optionType){ setItemType(itemType); setOptionType(optionType); setDurability(computeMaxDurability(this)); if (!g_pItemInfoManager->isPossibleItem(getItemClass(), getItemType(), getOptionTypeList())) { filelog("itembug.log", "SG::SG() : Invalid item type or option type"); throw ("SG::SG() : Invalid item type or optionType"); }}//--------------------------------------------------------------------------------// destructor//--------------------------------------------------------------------------------SG::~SG() throw(){}//--------------------------------------------------------------------------------// create item//--------------------------------------------------------------------------------void SG::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; string optionField; setOptionTypeToField( getOptionTypeList(), optionField ); sql << "INSERT INTO SGObject " << "(ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID ," << " X, Y, OptionType, Durability, BulletCount, Grade, ItemFlag)" << " VALUES(" << m_ItemID << ", " << m_ObjectID << ", " << getItemType() << ", '" << ownerID << "', " <<(int)storage << ", " << storageID << ", " <<(int)x << ", " <<(int)y << ", '" << optionField.c_str() << "', " << getDurability() << ", " <<(int)getBulletCount() << ", " << (int)getGrade() << ", " << (int)m_CreateType << ")"; pStmt->executeQuery(sql.toString()); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void SG::tinysave(const char* field) const throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE SGObject SET %s, BulletCount=%d WHERE ItemID=%ld", field, (int)getBulletCount(), m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void SG::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 SGObject 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 << ",BulletCount = " <<(int)m_BulletCount << ",Silver = " <<(int)m_Silver << " WHERE ItemID = " << m_ItemID; pStmt->executeQuery(sql.toString()); */ string optionField; setOptionTypeToField( getOptionTypeList(), optionField ); pStmt->executeQuery( "UPDATE SGObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, OptionType='%s', Durability=%d, EnchantLevel=%d, BulletCount=%d, Silver=%d, Grade=%d WHERE ItemID=%ld", m_ObjectID, getItemType(), ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, optionField.c_str(), getDurability(), (int)m_EnchantLevel, (int)getBulletCount(), (int)getSilver(), (int)getGrade(), m_ItemID ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void SG::saveBullet() throw (Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("UPDATE SGObject SET BulletCount = %d WHERE ItemID = %d", getBulletCount(), m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}void SG::makePCItemInfo(PCItemInfo& result) const{ Item::makePCItemInfo(result); result.setItemNum( getBulletCount() );}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string SG::toString() const throw(){ StringStream msg; msg << "SG(" << "ItemID:" << m_ItemID << ",ItemType:" <<(int)getItemType() << ",OptionType:" <<getOptionTypeToString(getOptionTypeList()).c_str() << ",Durability:" <<(int)getDurability() << ",BulletCount:" <<(int)getBulletCount() << ",Silver:" <<(int)getSilver() << ",EnchantLevel:" <<(int)m_EnchantLevel << ")"; return msg.toString();}/*//--------------------------------------------------------------------------------// get width//--------------------------------------------------------------------------------VolumeWidth_t SG::getVolumeWidth() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getVolumeWidth(); __END_CATCH} //--------------------------------------------------------------------------------// get height//--------------------------------------------------------------------------------VolumeHeight_t SG::getVolumeHeight() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getVolumeHeight(); __END_CATCH} //--------------------------------------------------------------------------------// get weight//--------------------------------------------------------------------------------Weight_t SG::getWeight() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getWeight(); __END_CATCH}//--------------------------------------------------------------------------------// get/set weapon's minDamage//--------------------------------------------------------------------------------Damage_t SG::getMinDamage() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getMinDamage() + m_BonusDamage; __END_CATCH}//--------------------------------------------------------------------------------// get/set weapon's maxDamage//--------------------------------------------------------------------------------Damage_t SG::getMaxDamage() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getMaxDamage() + m_BonusDamage; __END_CATCH}//--------------------------------------------------------------------------------// get/set weapon's range//--------------------------------------------------------------------------------Range_t SG::getRange() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getRange(); __END_CATCH}//--------------------------------------------------------------------------------// get/set weapon's ToHit Bonus//--------------------------------------------------------------------------------ToHit_t SG::getToHitBonus() const throw(Error){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getToHitBonus(); __END_CATCH}//--------------------------------------------------------------------------------//--------------------------------------------------------------------------------int SG::getCriticalBonus(void) const throw(){ __BEGIN_TRY return g_pSGInfoManager->getItemInfo(m_ItemType)->getCriticalBonus(); __END_CATCH}*///--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string SGInfo::toString() const throw(){ StringStream msg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -