Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void COfflineShopManager::DestroyOfflineShop(LPCHARACTER ch, DWORD dwVID, bool bDestroyAll)
- {
- LPCHARACTER myShopChar = CHARACTER_MANAGER::Instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
- if (!myShopChar ||myShopChar->GetMapIndex() != ch->GetMapIndex() || DISTANCE_APPROX(myShopChar->GetX() - ch->GetX(), myShopChar->GetY() - ch->GetY()) > 20000)
- {
- ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("YOU_CANNOT_TAKE_ITEMS_FROM_MYSHOP_FROM_FAR_AWAY"));
- return;
- }
- if (dwVID == 0 && ch)
- {
- std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex, channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
- if (pMsg->Get()->uiNumRows == 0)
- {
- ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't use this option because you don't have offline shop npc!"));
- return;
- }
- ch->SetOfflineShopVID(0);
- ch->SetOfflineShopStatus(OFFLINE_SHOP_AVAILABLE);
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- long lMapIndex = 0;
- str_to_number(lMapIndex, row[0]);
- TPacketGGRemoveOfflineShop p;
- p.bHeader = HEADER_GG_REMOVE_OFFLINE_SHOP;
- p.lMapIndex = lMapIndex;
- // Set offline shop name
- char szNpcName[CHARACTER_NAME_MAX_LEN + 1];
- snprintf(szNpcName, sizeof(szNpcName), "%s's offline shop", ch->GetName());
- strlcpy(p.szNpcName, szNpcName, sizeof(p.szNpcName));
- // End Of Set offline shop name
- P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGRemoveOfflineShop));
- DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
- }
- else if (dwVID && ch)
- {
- ch->SetOfflineShopVID(0);
- ch->SetOfflineShopStatus(OFFLINE_SHOP_AVAILABLE);
- LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(dwVID);
- if (!npc)
- npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
- if (!npc)
- {
- std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex,channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
- if (pMsg->Get()->uiNumRows == 0)
- {
- ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't use this option because you don't have offline shop npc!"));
- return;
- }
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- long lMapIndex = 0;
- str_to_number(lMapIndex, row[0]);
- BYTE bChannel = 0;
- str_to_number(bChannel, row[1]);
- if (g_bChannel != bChannel)
- {
- ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't close your offline shop from %d channel. You must login %d channel"), g_bChannel, bChannel);
- return;
- }
- char szName[CHARACTER_NAME_MAX_LEN + 1];
- snprintf(szName, sizeof(szName), "%s's offline shop", ch->GetName());
- LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(lMapIndex);
- FFindOfflineShop offlineShop(szName);
- pMap->for_each(offlineShop);
- if (bDestroyAll)
- {
- DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
- m_map_pkOfflineShopByNPC.erase(offlineShop.dwVID);
- m_Map_pkOfflineShopByNPC2.erase(offlineShop.dwRealOwner);
- DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), offlineShop.dwRealOwner);
- return;
- }
- }
- LPOFFLINESHOP pkOfflineShop = FindOfflineShop(dwVID);
- if (!pkOfflineShop)
- pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
- if (!pkOfflineShop)
- return;
- if (npc->GetOfflineShopChannel() != g_bChannel)
- {
- ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't close your offline shop from %d channel. You must login %d channel"), g_bChannel, npc->GetOfflineShopChannel());
- return;
- }
- if (bDestroyAll)
- {
- DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
- pkOfflineShop->Destroy(npc);
- }
- char szQuery3[1024];
- snprintf(szQuery3, sizeof(szQuery3),"SELECT * FROM player.offline_shop_search WHERE vid=%d",ch->GetPlayerID());
- std::auto_ptr<SQLMsg> pMsg3(DBManager::Instance().DirectQuery(szQuery3));
- if (pMsg3->Get()->uiNumRows > 0)
- {
- while (MYSQL_ROW row_vid = mysql_fetch_row(pMsg3->Get()->pSQLResult))
- {
- DWORD ID_Vid = 0;
- const char * Id_Vid_0 = row_vid[1];
- str_to_number(ID_Vid, Id_Vid_0);
- LPCHARACTER pChar = CHARACTER_MANAGER::Instance().FindByPID(ID_Vid);
- if (pChar == NULL) {
- return;
- }
- LPEVENT pkEvent = CTargetManager::instance().GetTargetEvent(pChar->GetPlayerID(), ch->GetPlayerID(), "_WorldArd_");
- if (pkEvent){
- CTargetManager::instance().DeleteTarget(pChar->GetPlayerID(), ch->GetPlayerID(), "_WorldArd_");
- }
- }
- DBManager::instance().DirectQuery("DELETE FROM player.offline_shop_search WHERE vid = %d", ch->GetPlayerID());
- }
- m_map_pkOfflineShopByNPC.erase(npc->GetVID());
- m_Map_pkOfflineShopByNPC2.erase(npc->GetOfflineShopRealOwner());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement