📄 potion.cpp
字号:
// a b ca //////////////////////////////////////////////////////////// a = effect.find_first_of('(', e); b = effect.find_first_of(',', a+1); c = effect.find_first_of(',', b+1); d = effect.find_first_of(',', c+1); e = effect.find_first_of(')', d+1); if (a > b || b > c || c > d || d > e) break; string recover = trim(effect.substr(a+1, b-a-1)); uint amount = atoi(effect.substr(b+1, c-b-1).c_str()); uint delay = atoi(effect.substr(c+1, d-c-1).c_str()); uint unit = atoi(effect.substr(d+1, e-d-1).c_str()); if (recover == "HP") { m_HPAmount =(int)amount; m_HPDelay =(int)delay; m_HPRecoveryUnit =(int)unit; } else if (recover == "MP") { m_MPAmount =(int)amount; m_MPDelay =(int)delay; m_MPRecoveryUnit =(int)unit; } } __END_CATCH}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string PotionInfo::toString() const throw(){ StringStream msg; msg << "PotionInfo(" << "ItemType:" <<(int)m_ItemType << ",Name:" << m_Name << ",EName:" << m_EName << ",Price:" <<(int)m_Price << ",VolumeType:" << Volume2String[m_VolumeType] << ",Weight:" <<(int)m_Weight << ",Description:" << m_Description << ",HPAmount:" <<(int)m_HPAmount << ",MPAmount:" <<(int)m_MPAmount << ")"; return msg.toString();}//--------------------------------------------------------------------------------// load from DB//--------------------------------------------------------------------------------void PotionInfoManager::load() throw(Error){ __BEGIN_TRY Statement* pStmt; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery("SELECT MAX(ItemType) FROM PotionInfo"); 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, ItemLevel, Effect FROM PotionInfo" ); while (pResult->next()) { uint i = 0; PotionInfo* pPotionInfo = new PotionInfo(); pPotionInfo->setItemType(pResult->getInt(++i)); pPotionInfo->setName(pResult->getString(++i)); pPotionInfo->setEName(pResult->getString(++i)); pPotionInfo->setPrice(pResult->getInt(++i)); pPotionInfo->setVolumeType(pResult->getInt(++i)); pPotionInfo->setWeight(pResult->getInt(++i)); pPotionInfo->setRatio(pResult->getInt(++i)); pPotionInfo->setItemLevel(pResult->getInt(++i)); pPotionInfo->parseEffect(pResult->getString(++i)); addItemInfo(pPotionInfo); } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// load to creature//--------------------------------------------------------------------------------void PotionLoader::load(Creature* pCreature) throw(Error){ __BEGIN_TRY Assert(pCreature != NULL); Statement* pStmt; BEGIN_DB { //pStmt = g_pDatabaseManager->getConnection("DIST_DARKEDEN")->createStatement(); pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "SELECT ItemID, ObjectID, ItemType, Storage, StorageID, X, Y, Num FROM PotionObject" << " WHERE OwnerID = '" << pCreature->getName() << "' AND Storage IN(" <<(int)STORAGE_INVENTORY << ", " <<(int)STORAGE_GEAR << ", " <<(int)STORAGE_BELT << ", " <<(int)STORAGE_EXTRASLOT << ", " <<(int)STORAGE_MOTORCYCLE << ", " <<(int)STORAGE_STASH << ", " <<(int)STORAGE_GARBAGE << ")"; Result* pResult = pStmt->executeQuery(sql.toString()); */ Result* pResult = pStmt->executeQuery( "SELECT ItemID, ObjectID, ItemType, Storage, StorageID, X, Y, Num FROM PotionObject WHERE OwnerID = '%s' AND Storage IN(0, 1, 2, 3, 4, 9)", pCreature->getName().c_str() ); while (pResult->next()) { try { uint i = 0; Potion* pPotion = new Potion(); pPotion->setItemID(pResult->getDWORD(++i)); pPotion->setObjectID(pResult->getDWORD(++i)); pPotion->setItemType(pResult->getDWORD(++i)); Storage storage =(Storage)pResult->getInt(++i); StorageID_t storageID = pResult->getDWORD(++i); BYTE x = pResult->getBYTE(++i); BYTE y = pResult->getBYTE(++i); pPotion->setNum(pResult->getBYTE(++i)); Inventory* pInventory = NULL; Slayer* pSlayer = NULL; Vampire* pVampire = NULL; Motorcycle* pMotorcycle = NULL; Inventory* pMotorInventory = NULL; Item* pItem = NULL; Stash* pStash = NULL; Belt* pBelt = NULL; Inventory* pBeltInventory = NULL; if (pCreature->isSlayer()) { pSlayer = dynamic_cast<Slayer*>(pCreature); pInventory = pSlayer->getInventory(); pStash = pSlayer->getStash(); pMotorcycle = pSlayer->getMotorcycle(); if (pMotorcycle) pMotorInventory = pMotorcycle->getInventory(); } else if (pCreature->isVampire()) { pVampire = dynamic_cast<Vampire*>(pCreature); pInventory = pVampire->getInventory(); pStash = pVampire->getStash(); } else throw UnsupportedError("Monster,NPC 牢亥配府狼 历厘篮 酒流 瘤盔登瘤 臼嚼聪促."); switch(storage) { case STORAGE_INVENTORY: if (pInventory->canAddingEx(x, y, pPotion)) { pInventory->addItemEx(x, y, pPotion); } else { processItemBugEx(pCreature, pPotion); } break; case STORAGE_GEAR: processItemBugEx(pCreature, pPotion); break; case STORAGE_BELT : if (pCreature->isSlayer()) { pItem = pSlayer->findBeltIID(storageID); if (pItem != NULL && pItem->getItemClass() == Item::ITEM_CLASS_BELT) { pBelt = dynamic_cast<Belt*>(pItem); pBeltInventory = pBelt->getInventory(); if (pBeltInventory->canAddingEx(x, 0, pPotion)) { pBeltInventory->addItem(x, 0, pPotion); } else { processItemBugEx(pCreature, pPotion); } } else { processItemBugEx(pCreature, pPotion); } } else if (pCreature->isVampire()) { pItem = pVampire->findBeltIID(storageID); if (pItem != NULL && pItem->getItemClass() == Item::ITEM_CLASS_BELT) { pBelt = dynamic_cast<Belt*>(pItem); pBeltInventory = pBelt->getInventory(); if (pBeltInventory->canAddingEx(x, 0, pPotion)) { pBeltInventory->addItemEx(x, 0, pPotion); } else { processItemBugEx(pCreature, pPotion); } } else { processItemBugEx(pCreature, pPotion); } } break; case STORAGE_EXTRASLOT : if (pCreature->isSlayer()) pSlayer->addItemToExtraInventorySlot(pPotion); else if (pCreature->isVampire()) pVampire->addItemToExtraInventorySlot(pPotion); break; case STORAGE_MOTORCYCLE: processItemBugEx(pCreature, pPotion); break; case STORAGE_STASH: if (pStash->isExist(x, y)) { processItemBugEx(pCreature, pPotion); } else pStash->insert(x, y, pPotion); break; case STORAGE_GARBAGE: processItemBug(pCreature, pPotion); break; default : SAFE_DELETE(pStmt); // by sigi throw Error("invalid storage or OwnerID must be NULL"); } } catch (Error& error) { filelog("itemLoadError.txt", "[%s] %s", getItemClassName().c_str(), error.toString().c_str()); throw; } catch (Throwable& t) { filelog("itemLoadError.txt", "[%s] %s", getItemClassName().c_str(), t.toString().c_str()); } } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// load to zone//--------------------------------------------------------------------------------void PotionLoader::load(Zone* pZone) throw(Error){ __BEGIN_TRY Assert(pZone != NULL); Statement* pStmt; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); StringStream sql; sql << "SELECT ItemID, ObjectID, ItemType, Storage, StorageID, X, Y, Num FROM PotionObject" << " WHERE Storage = " <<(int)STORAGE_ZONE << " AND StorageID = " << pZone->getZoneID(); Result* pResult = pStmt->executeQuery(sql.toString()); while (pResult->next()) { uint i = 0; Potion* pPotion = new Potion(); pPotion->setItemID(pResult->getInt(++i)); pPotion->setObjectID(pResult->getInt(++i)); pPotion->setItemType(pResult->getInt(++i)); Storage storage =(Storage)pResult->getInt(++i); StorageID_t storageID = pResult->getInt(++i); BYTE x = pResult->getInt(++i); BYTE y = pResult->getInt(++i); pPotion->setNum(pResult->getBYTE(++i)); switch(storage) { case STORAGE_ZONE : { Tile & pTile = pZone->getTile(x,y); Assert(!pTile.hasItem()); pTile.addItem(pPotion); } break; case STORAGE_STASH : case STORAGE_CORPSE : throw UnsupportedError("惑磊 棺 矫眉救狼 酒捞袍狼 历厘篮 酒流 瘤盔登瘤 臼嚼聪促."); default : throw Error("Storage must be STORAGE_ZONE"); } } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// load to inventory//--------------------------------------------------------------------------------void PotionLoader::load(StorageID_t storageID, Inventory* pInventory) throw(Error){ __BEGIN_TRY Statement* pStmt; BEGIN_DB { } END_DB(pStmt) __END_CATCH}PotionLoader* g_pPotionLoader = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -