Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. void COfflineShopManager::DestroyOfflineShop(LPCHARACTER ch, DWORD dwVID, bool bDestroyAll)
  2. {
  3.  
  4. LPCHARACTER myShopChar = CHARACTER_MANAGER::Instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  5. if (!myShopChar ||myShopChar->GetMapIndex() != ch->GetMapIndex() || DISTANCE_APPROX(myShopChar->GetX() - ch->GetX(), myShopChar->GetY() - ch->GetY()) > 20000)
  6. {
  7. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("YOU_CANNOT_TAKE_ITEMS_FROM_MYSHOP_FROM_FAR_AWAY"));
  8.  
  9. return;
  10. }
  11.  
  12. if (dwVID == 0 && ch)
  13. {
  14. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex, channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  15. if (pMsg->Get()->uiNumRows == 0)
  16. {
  17. ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't use this option because you don't have offline shop npc!"));
  18. return;
  19. }
  20.  
  21. ch->SetOfflineShopVID(0);
  22. ch->SetOfflineShopStatus(OFFLINE_SHOP_AVAILABLE);
  23.  
  24. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  25. long lMapIndex = 0;
  26. str_to_number(lMapIndex, row[0]);
  27.  
  28. TPacketGGRemoveOfflineShop p;
  29. p.bHeader = HEADER_GG_REMOVE_OFFLINE_SHOP;
  30. p.lMapIndex = lMapIndex;
  31.  
  32. // Set offline shop name
  33. char szNpcName[CHARACTER_NAME_MAX_LEN + 1];
  34. snprintf(szNpcName, sizeof(szNpcName), "%s's offline shop", ch->GetName());
  35. strlcpy(p.szNpcName, szNpcName, sizeof(p.szNpcName));
  36. // End Of Set offline shop name
  37.  
  38. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGRemoveOfflineShop));
  39. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  40. }
  41. else if (dwVID && ch)
  42. {
  43. ch->SetOfflineShopVID(0);
  44. ch->SetOfflineShopStatus(OFFLINE_SHOP_AVAILABLE);
  45.  
  46. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(dwVID);
  47. if (!npc)
  48. npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  49.  
  50. if (!npc)
  51. {
  52. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex,channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  53. if (pMsg->Get()->uiNumRows == 0)
  54. {
  55. ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("You can't use this option because you don't have offline shop npc!"));
  56. return;
  57. }
  58.  
  59. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  60.  
  61. long lMapIndex = 0;
  62. str_to_number(lMapIndex, row[0]);
  63.  
  64. BYTE bChannel = 0;
  65. str_to_number(bChannel, row[1]);
  66.  
  67. if (g_bChannel != bChannel)
  68. {
  69. 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);
  70. return;
  71. }
  72.  
  73. char szName[CHARACTER_NAME_MAX_LEN + 1];
  74. snprintf(szName, sizeof(szName), "%s's offline shop", ch->GetName());
  75. LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(lMapIndex);
  76. FFindOfflineShop offlineShop(szName);
  77. pMap->for_each(offlineShop);
  78.  
  79. if (bDestroyAll)
  80. {
  81. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  82. m_map_pkOfflineShopByNPC.erase(offlineShop.dwVID);
  83. m_Map_pkOfflineShopByNPC2.erase(offlineShop.dwRealOwner);
  84. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), offlineShop.dwRealOwner);
  85. return;
  86. }
  87. }
  88.  
  89. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(dwVID);
  90. if (!pkOfflineShop)
  91. pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
  92.  
  93. if (!pkOfflineShop)
  94. return;
  95.  
  96. if (npc->GetOfflineShopChannel() != g_bChannel)
  97. {
  98. 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());
  99. return;
  100. }
  101.  
  102. if (bDestroyAll)
  103. {
  104. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  105. pkOfflineShop->Destroy(npc);
  106. }
  107. char szQuery3[1024];
  108. snprintf(szQuery3, sizeof(szQuery3),"SELECT * FROM player.offline_shop_search WHERE vid=%d",ch->GetPlayerID());
  109. std::auto_ptr<SQLMsg> pMsg3(DBManager::Instance().DirectQuery(szQuery3));
  110. if (pMsg3->Get()->uiNumRows > 0)
  111. {
  112. while (MYSQL_ROW row_vid = mysql_fetch_row(pMsg3->Get()->pSQLResult))
  113. {
  114. DWORD ID_Vid = 0;
  115. const char * Id_Vid_0 = row_vid[1];
  116. str_to_number(ID_Vid, Id_Vid_0);
  117.  
  118. LPCHARACTER pChar = CHARACTER_MANAGER::Instance().FindByPID(ID_Vid);
  119.  
  120. if (pChar == NULL) {
  121. return;
  122. }
  123.  
  124. LPEVENT pkEvent = CTargetManager::instance().GetTargetEvent(pChar->GetPlayerID(), ch->GetPlayerID(), "_WorldArd_");
  125. if (pkEvent){
  126. CTargetManager::instance().DeleteTarget(pChar->GetPlayerID(), ch->GetPlayerID(), "_WorldArd_");
  127. }
  128. }
  129. DBManager::instance().DirectQuery("DELETE FROM player.offline_shop_search WHERE vid = %d", ch->GetPlayerID());
  130. }
  131. m_map_pkOfflineShopByNPC.erase(npc->GetVID());
  132. m_Map_pkOfflineShopByNPC2.erase(npc->GetOfflineShopRealOwner());
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement