📄 vampirecouplering.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : VampireCoupleRing.cpp// Written By : excel96// Description ://////////////////////////////////////////////////////////////////////////////#include "VampireCoupleRing.h"#include "DB.h"#include "Slayer.h"#include "Vampire.h"#include "Belt.h"#include "Motorcycle.h"#include "Stash.h"#include "ItemInfoManager.h"#include "ItemUtil.h"#include "PlayerCreature.h"#include "FlagSet.h"#include "couple/CoupleManager.h"#include <stdio.h>VampireCoupleRingInfoManager* g_pVampireCoupleRingInfoManager = NULL;ItemID_t VampireCoupleRing::m_ItemIDRegistry = 0;Mutex VampireCoupleRing::m_Mutex;//////////////////////////////////////////////////////////////////////////////// class VampireCoupleRing member methods//////////////////////////////////////////////////////////////////////////////VampireCoupleRing::VampireCoupleRing() throw(){ m_ItemType = 0;}VampireCoupleRing::VampireCoupleRing(ItemType_t itemType, const list<OptionType_t>& optionType) throw(): m_ItemType(itemType), m_OptionType( optionType ){ __BEGIN_TRY if (!g_pItemInfoManager->isPossibleItem(getItemClass(), m_ItemType, optionType)) { filelog("itembug.log", "VampireCoupleRing::VampireCoupleRing() : Invalid item type or option type"); throw ("VampireCoupleRing::VampireCoupleRing() : Invalid item type or optionType"); } __END_CATCH}void VampireCoupleRing::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 { string optionField; setOptionTypeToField( m_OptionType, optionField ); StringStream sql; sql << "INSERT INTO VampireCoupleRingObject " << "(ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, OptionType, Name, PartnerItemID)" << " VALUES(" << m_ItemID << ", " << m_ObjectID << ", " << m_ItemType << ", '" << ownerID << "', " <<(int)storage << ", " << storageID << ", " <<(int)x << ", " <<(int)y << ", '" << optionField.c_str() << "', '" << getName().c_str() << "', " << getPartnerItemID() << ")"; pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery(sql.toString()); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH} //--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void VampireCoupleRing::tinysave(const char* field) const throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE VampireCoupleRingObject SET %s WHERE ItemID=%ld", field, m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}void VampireCoupleRing::save(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y) throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { /* StringStream sql; sql << "UPDATE VampireCoupleRingObject SET " << "ObjectID = " << m_ObjectID << ",ItemType = " << m_ItemType << ",OwnerID = '" << ownerID << "'" << ",Storage = " <<(int)storage << ",StorageID = " << storageID << ",X = " <<(int)x << ",Y = " <<(int)y << " WHERE ItemID = " << m_ItemID; pStmt->executeQuery(sql.toString()); */ pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE VampireCoupleRingObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, Name='%s', PartnerItemID=%ld WHERE ItemID=%ld", m_ObjectID, m_ItemType, ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, getName().c_str(), getPartnerItemID(), m_ItemID ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}string VampireCoupleRing::toString() const throw(){ StringStream msg; msg << "VampireCoupleRing(" << "ItemID:" << m_ItemID << ",ItemType:" << m_ItemType << ")"; return msg.toString();}VolumeWidth_t VampireCoupleRing::getVolumeWidth() const throw(Error){ __BEGIN_TRY return g_pVampireCoupleRingInfoManager->getItemInfo(m_ItemType)->getVolumeWidth(); __END_CATCH} VolumeHeight_t VampireCoupleRing::getVolumeHeight() const throw(Error){ __BEGIN_TRY return g_pVampireCoupleRingInfoManager->getItemInfo(m_ItemType)->getVolumeHeight(); __END_CATCH} Weight_t VampireCoupleRing::getWeight() const throw(Error){ __BEGIN_TRY return g_pVampireCoupleRingInfoManager->getItemInfo(m_ItemType)->getWeight(); __END_CATCH}bool VampireCoupleRing::hasPartnerItem() throw(Error){ __BEGIN_TRY bool bRet = false; Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery( "SELECT count(*) from VampireCoupleRingObject where ItemID=%ld and Storage IN(0, 1, 2, 3, 4, 9)", getPartnerItemID() ); // UPDATE牢 版快绰 Result* 措脚俊.. pStmt->getAffectedRowCount() if (pResult->next()) { int count = pResult->getInt(1); Assert( count >= 0 ); Assert( count <= 1 ); if ( count == 1 ) bRet = true; } else { bRet = false; } SAFE_DELETE(pStmt); } END_DB(pStmt) return bRet; __END_CATCH}//////////////////////////////////////////////////////////////////////////////// class VampireCoupleRingInfo member methods//////////////////////////////////////////////////////////////////////////////string VampireCoupleRingInfo::toString() const throw(){ StringStream msg; msg << "VampireCoupleRingInfo(" << "ItemType:" << m_ItemType << ",Name:" << m_Name << ",EName:" << m_EName << ",Price:" << m_Price << ",VolumeType:" << Volume2String[m_VolumeType] << ",Weight:" << m_Weight << ",Description:" << m_Description << ")"; return msg.toString();}void VampireCoupleRingInfoManager::load() throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery("SELECT MAX(ItemType) FROM VampireCoupleRingInfo"); pResult->next(); m_InfoCount = pResult->getInt(1); m_pItemInfos = new ItemInfo*[m_InfoCount+1]; for (uint i = 0 ; i <= m_InfoCount ; i ++) m_pItemInfos[i] = NULL; pResult = pStmt->executeQuery( "SELECT ItemType, Name, EName, Price, Volume, Weight, Ratio FROM VampireCoupleRingInfo" ); while (pResult->next()) { uint i = 0; VampireCoupleRingInfo* pVampireCoupleRingInfo = new VampireCoupleRingInfo(); pVampireCoupleRingInfo->setItemType(pResult->getInt(++i)); pVampireCoupleRingInfo->setName(pResult->getString(++i)); pVampireCoupleRingInfo->setEName(pResult->getString(++i)); pVampireCoupleRingInfo->setPrice(pResult->getInt(++i));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -