📄 petitem.cpp
字号:
Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery("SELECT MAX(ItemType) FROM PetItemInfo"); 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 PetItemInfo" ); while (pResult->next()) { uint i = 0; PetItemInfo* pPetItemInfo = new PetItemInfo(); pPetItemInfo->setItemType(pResult->getInt(++i)); pPetItemInfo->setName(pResult->getString(++i)); pPetItemInfo->setEName(pResult->getString(++i)); pPetItemInfo->setPrice(pResult->getInt(++i)); pPetItemInfo->setVolumeType(pResult->getInt(++i)); pPetItemInfo->setWeight(pResult->getInt(++i)); pPetItemInfo->setRatio(pResult->getInt(++i)); addItemInfo(pPetItemInfo); } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//////////////////////////////////////////////////////////////////////////////// class PetItemLoader member methods//////////////////////////////////////////////////////////////////////////////void PetItemLoader::load(Creature* pCreature) throw(Error){ __BEGIN_TRY Assert(pCreature != NULL); Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "SELECT ItemID, ObjectID, ItemType, Storage, StorageID, X, Y, Num FROM PetItemObject" << " 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, ItemFlag, " "PetCreatureType, PetLevel, PetExp, PetHP, PetAttr, PetAttrLevel, PetOption, FoodType, " "CanGamble, CanCutHead, CanAttack, LastFeedTime " "FROM PetItemObject WHERE OwnerID = '%s' AND Storage IN(0, 1, 2, 3, 4, 9, 13)", pCreature->getName().c_str() ); while (pResult->next()) { try { uint i = 0; PetItem* pPetItem = new PetItem(); pPetItem->setItemID(pResult->getDWORD(++i)); pPetItem->setObjectID(pResult->getDWORD(++i)); pPetItem->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); pPetItem->setCreateType((Item::CreateType)pResult->getInt(++i)); PetInfo* pPetInfo = new PetInfo; pPetInfo->setPetType( pPetItem->getItemType() ); pPetInfo->setPetCreatureType( pResult->getInt(++i) ); pPetInfo->setPetLevel( pResult->getInt(++i) ); pPetInfo->setPetExp( pResult->getInt(++i) ); pPetInfo->setPetHP( pResult->getInt(++i) ); pPetInfo->setPetAttr( pResult->getInt(++i) ); pPetInfo->setPetAttrLevel( pResult->getInt(++i) ); pPetInfo->setPetOption( pResult->getInt(++i) ); pPetInfo->setFoodType( pResult->getInt(++i) ); pPetInfo->setGamble( pResult->getInt(++i) ); pPetInfo->setCutHead( pResult->getInt(++i) ); pPetInfo->setAttack( pResult->getInt(++i) ); pPetInfo->setFeedTime( VSDateTime(pResult->getString(++i)) ); // 剧规氢 傅农 pPetItem->setPetInfo( pPetInfo ); pPetInfo->setPetItem( pPetItem ); if ( storage == STORAGE_PET_STASH ) { refreshHP( pPetInfo, 50 ); pPetInfo->setFeedTurn(2); } else { refreshHP( pPetInfo ); pPetInfo->setFeedTurn(1); } PetTypeInfo* pPetTypeInfo = PetTypeInfoManager::getInstance()->getPetTypeInfo( pPetInfo->getPetType() ); if ( pPetTypeInfo != NULL ) { pPetInfo->setPetCreatureType( pPetTypeInfo->getPetCreatureType( pPetInfo->getPetLevel() ) ); } Inventory* pInventory = NULL; Slayer* pSlayer = NULL; Vampire* pVampire = NULL; Ousters* pOusters = 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 if (pCreature->isOusters()) { pOusters = dynamic_cast<Ousters*>(pCreature); pInventory = pOusters->getInventory(); pStash = pOusters->getStash(); } else throw UnsupportedError("Monster,NPC 牢亥配府狼 历厘篮 酒流 瘤盔登瘤 臼嚼聪促."); PlayerCreature* pPC = dynamic_cast<PlayerCreature*>(pCreature); Assert( pPC != NULL ); switch(storage) { case STORAGE_INVENTORY: if (pInventory->canAddingEx(x, y, pPetItem)) { pInventory->addItemEx(x, y, pPetItem); pPetItem->whenPCTake( pPC ); } else { processItemBugEx(pCreature, pPetItem); } break; case STORAGE_GEAR: processItemBugEx(pCreature, pPetItem); break; case STORAGE_BELT : processItemBugEx(pCreature, pPetItem); break; case STORAGE_EXTRASLOT : if (pCreature->isSlayer()) pSlayer->addItemToExtraInventorySlot(pPetItem); else if (pCreature->isVampire()) pVampire->addItemToExtraInventorySlot(pPetItem); else if (pCreature->isOusters()) pOusters->addItemToExtraInventorySlot(pPetItem); pPetItem->whenPCTake( pPC ); break; case STORAGE_MOTORCYCLE: processItemBugEx(pCreature, pPetItem); break; case STORAGE_STASH: if (pStash->isExist(x, y)) { processItemBugEx(pCreature, pPetItem); } else { pStash->insert(x, y, pPetItem); pPetItem->whenPCTake( pPC ); } break; case STORAGE_GARBAGE: processItemBug(pCreature, pPetItem); break; case STORAGE_PET_STASH: /* 脐阑 阂矾促啊 pCreature俊 持绢具 登唱?...*/ if ( pPC->getPetStashItem( storageID ) == NULL ) pPC->addPetStashItem( storageID, pPetItem ); else processItemBug(pCreature, pPetItem); 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}void PetItemLoader::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, ItemFlag FROM PetItemObject" << " WHERE Storage = " <<(int)STORAGE_ZONE << " AND StorageID = " << pZone->getZoneID(); Result* pResult = pStmt->executeQuery(sql.toString()); while (pResult->next()) { uint i = 0; PetItem* pPetItem = new PetItem(); pPetItem->setItemID(pResult->getInt(++i)); pPetItem->setObjectID(pResult->getInt(++i)); pPetItem->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); pPetItem->setCreateType((Item::CreateType)pResult->getInt(++i)); switch(storage) { case STORAGE_ZONE : { Tile & pTile = pZone->getTile(x,y); Assert(!pTile.hasItem()); pTile.addItem(pPetItem); } 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}void PetItemLoader::load(StorageID_t storageID, Inventory* pInventory) throw(Error){ __BEGIN_TRY Statement* pStmt; BEGIN_DB { } END_DB(pStmt) __END_CATCH}PetItemLoader* g_pPetItemLoader = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -