deyan4you

Untitled

Oct 27th, 2016
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "../../libgame/include/grid.h"
  3. #include "constants.h"
  4. #include "utils.h"
  5. #include "config.h"
  6. #include "offline_shop.h"
  7. #include "desc.h"
  8. #include "desc_manager.h"
  9. #include "char.h"
  10. #include "char_manager.h"
  11. #include "item.h"
  12. #include "item_manager.h"
  13. #include "buffer_manager.h"
  14. #include "packet.h"
  15. #include "log.h"
  16. #include "db.h"
  17. #include "questmanager.h"
  18. #include "monarch.h"
  19. #include "mob_manager.h"
  20. #include "locale_service.h"
  21. #include "desc_client.h"
  22. #include "group_text_parse_tree.h"
  23. #include <boost/algorithm/string/predicate.hpp>
  24. #include <cctype>
  25. #include "offlineshop_manager.h"
  26. #include "p2p.h"
  27. #include "entity.h"
  28. #include "sectree_manager.h"
  29. #include "offlineshop_config.h"
  30.  
  31.  
  32. COfflineShopManager::COfflineShopManager()
  33. {
  34. }
  35.  
  36.  
  37. COfflineShopManager::~COfflineShopManager()
  38. {
  39. }
  40.  
  41. struct FFindOfflineShop
  42. {
  43. const char * szName;
  44.  
  45. DWORD dwVID, dwRealOwner;
  46. FFindOfflineShop(const char * c_szName) : szName(c_szName), dwVID(0), dwRealOwner(0) {};
  47.  
  48. void operator()(LPENTITY ent)
  49. {
  50. if (!ent)
  51. return;
  52.  
  53. if (ent->IsType(ENTITY_CHARACTER))
  54. {
  55. LPCHARACTER ch = (LPCHARACTER)ent;
  56. if (ch->IsOfflineShopNPC() && !strcmp(szName, ch->GetName()))
  57. {
  58. dwVID = ch->GetVID();
  59. dwRealOwner = ch->GetOfflineShopRealOwner();
  60. M2_DESTROY_CHARACTER(ch);
  61. }
  62. }
  63. }
  64. };
  65.  
  66. bool COfflineShopManager::StartShopping(LPCHARACTER pkChr, LPCHARACTER pkChrShopKeeper)
  67. {
  68. if (pkChr->GetOfflineShopOwner() == pkChrShopKeeper)
  69. return false;
  70.  
  71. if (pkChrShopKeeper->IsPC())
  72. return false;
  73.  
  74. sys_log(0, "OFFLINE_SHOP: START: %s", pkChr->GetName());
  75. return true;
  76. }
  77.  
  78. LPOFFLINESHOP COfflineShopManager::CreateOfflineShop(LPCHARACTER npc, DWORD dwOwnerPID)
  79. {
  80. if (FindOfflineShop(npc->GetVID()))
  81. return NULL;
  82.  
  83. LPOFFLINESHOP pkOfflineShop = M2_NEW COfflineShop;
  84. pkOfflineShop->SetOfflineShopNPC(npc);
  85.  
  86. m_map_pkOfflineShopByNPC.insert(TShopMap::value_type(npc->GetVID(), pkOfflineShop));
  87. m_Map_pkOfflineShopByNPC2.insert(TOfflineShopMap::value_type(dwOwnerPID, npc->GetVID()));
  88. return pkOfflineShop;
  89. }
  90.  
  91. LPOFFLINESHOP COfflineShopManager::FindOfflineShop(DWORD dwVID)
  92. {
  93. TShopMap::iterator it = m_map_pkOfflineShopByNPC.find(dwVID);
  94.  
  95. if (it == m_map_pkOfflineShopByNPC.end())
  96. return NULL;
  97.  
  98. return it->second;
  99. }
  100.  
  101. void COfflineShopManager::DestroyOfflineShop(LPCHARACTER ch, DWORD dwVID, bool bDestroyAll)
  102. {
  103. if (dwVID == 0 && ch)
  104. {
  105. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex, channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  106. if (pMsg->Get()->uiNumRows == 0)
  107. {
  108. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi aceasta optiune pentru ca nu ai facut un magazin offline!");
  109. return;
  110. }
  111.  
  112. ch->SetOfflineShopVID(0);
  113. ch->SetOfflineShopStatus(0);
  114.  
  115. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  116. long lMapIndex = 0;
  117. str_to_number(lMapIndex, row[0]);
  118.  
  119. TPacketGGRemoveOfflineShop p;
  120. p.bHeader = HEADER_GG_REMOVE_OFFLINE_SHOP;
  121. p.lMapIndex = lMapIndex;
  122.  
  123. // Set offline shop name
  124. char szNpcName[CHARACTER_NAME_MAX_LEN + 1];
  125. snprintf(szNpcName, sizeof(szNpcName), "%s ,magazin", ch->GetName());
  126. strlcpy(p.szNpcName, szNpcName, sizeof(p.szNpcName));
  127. // End Of Set offline shop name
  128.  
  129. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGRemoveOfflineShop));
  130. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  131. }
  132. else if (dwVID && ch)
  133. {
  134. ch->SetOfflineShopVID(0);
  135. ch->SetOfflineShopStatus(0);
  136.  
  137. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(dwVID);
  138. if (!npc)
  139. npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  140.  
  141. if (!npc)
  142. {
  143. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex,channel FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  144. if (pMsg->Get()->uiNumRows == 0)
  145. {
  146. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi aceasta optiune pentru ca nu ai facut un magazin offline!");
  147. return;
  148. }
  149.  
  150. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  151.  
  152. long lMapIndex = 0;
  153. str_to_number(lMapIndex, row[0]);
  154.  
  155. BYTE bChannel = 0;
  156. str_to_number(bChannel, row[1]);
  157.  
  158. if (g_bChannel != bChannel)
  159. {
  160. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti inchide magazinul offline de pe CH %d. Trebuie sa intri pe CH %d!", g_bChannel, bChannel);
  161. return;
  162. }
  163.  
  164. char szName[CHARACTER_NAME_MAX_LEN + 1];
  165. snprintf(szName, sizeof(szName), "%s ,magazin", ch->GetName());
  166. LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(lMapIndex);
  167. FFindOfflineShop offlineShop(szName);
  168. pMap->for_each(offlineShop);
  169.  
  170. if (bDestroyAll)
  171. {
  172. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  173. m_map_pkOfflineShopByNPC.erase(offlineShop.dwVID);
  174. m_Map_pkOfflineShopByNPC2.erase(offlineShop.dwRealOwner);
  175. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), offlineShop.dwRealOwner);
  176. return;
  177. }
  178. }
  179.  
  180. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(dwVID);
  181. if (!pkOfflineShop)
  182. pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
  183.  
  184. if (!pkOfflineShop)
  185. return;
  186.  
  187. if (npc->GetOfflineShopChannel() != g_bChannel)
  188. {
  189. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti inchide magazinul offline de pe CH %d. Trebuie sa intri pe CH %d!", g_bChannel, npc->GetOfflineShopChannel());
  190. return;
  191. }
  192.  
  193. if (bDestroyAll)
  194. {
  195. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  196. pkOfflineShop->Destroy(npc);
  197. }
  198.  
  199. m_map_pkOfflineShopByNPC.erase(npc->GetVID());
  200. m_Map_pkOfflineShopByNPC2.erase(npc->GetOfflineShopRealOwner());
  201. }
  202. }
  203.  
  204. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  205. void COfflineShopManager::AddItem(LPCHARACTER ch, BYTE bDisplayPos, BYTE bPos, long long llPrice)
  206. #else
  207. void COfflineShopManager::AddItem(LPCHARACTER ch, BYTE bDisplayPos, BYTE bPos, int iPrice)
  208. #endif
  209. {
  210. if (!ch)
  211. return;
  212.  
  213. // Fixed bug 6.21.2015
  214. if (bDisplayPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  215. {
  216. sys_err("Overflow offline shop slot count [%s]", ch->GetName());
  217. return;
  218. }
  219. // End Of fixed bug 6.21.2015
  220.  
  221. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  222. if (llPrice >= GOLD_MAX)
  223. {
  224. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti adauga acest obiect deoarece depasesti limita de yang!");
  225. return;
  226. }
  227. #else
  228. if (iPrice >= GOLD_MAX - 1)
  229. {
  230. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti adauga acest obiect deoarece depasesti limita de yang!");
  231. return;
  232. }
  233. #endif
  234.  
  235. // Check player has offline shop or not
  236. std::auto_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM player2.offline_shop_npc WHERE owner_id = %u", ch->GetPlayerID()));
  237. MYSQL_ROW row = mysql_fetch_row(pmsg->Get()->pSQLResult);
  238.  
  239. BYTE bResult = 0;
  240. str_to_number(bResult, row[0]);
  241.  
  242. if (!bResult)
  243. {
  244. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi aceasta optiune deoarece nu ai facut un magazin offline!");
  245. return;
  246. }
  247. // End Of Check player has offline shop or not
  248.  
  249. LPITEM pkItem = ch->GetInventoryItem(bPos);
  250.  
  251. if (!pkItem)
  252. return;
  253.  
  254. // Check
  255. const TItemTable * itemTable = pkItem->GetProto();
  256. if (IS_SET(itemTable->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MY_OFFLINE_SHOP))
  257. {
  258. ch->ChatPacket(CHAT_TYPE_INFO, "Acest obiect nu este negociabil!");
  259. return;
  260. }
  261.  
  262. if (pkItem->isLocked())
  263. return;
  264.  
  265. if (pkItem->IsEquipped())
  266. {
  267. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti vinde obiectele echipate!");
  268. return;
  269. }
  270.  
  271. char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
  272.  
  273. int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,vnum");
  274. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  275. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%lld,%u", pkItem->GetID(), ch->GetPlayerID(), bDisplayPos, pkItem->GetCount(), llPrice, pkItem->GetVnum());
  276. #else
  277. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%d,%u", pkItem->GetID(), ch->GetPlayerID(), bDisplayPos, pkItem->GetCount(), iPrice, pkItem->GetVnum());
  278. #endif
  279.  
  280. if (g_bOfflineShopSocketMax == 3)
  281. {
  282. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
  283. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
  284. }
  285. else if(g_bOfflineShopSocketMax == 4)
  286. {
  287. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3");
  288. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2), pkItem->GetSocket(3));
  289. }
  290. else if(g_bOfflineShopSocketMax == 5)
  291. {
  292. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3,socket4");
  293. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2), pkItem->GetSocket(3), pkItem->GetSocket(4));
  294. }
  295. else if(g_bOfflineShopSocketMax == 6)
  296. {
  297. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3,socket4,socket5");
  298. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld,%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2), pkItem->GetSocket(3), pkItem->GetSocket(4), pkItem->GetSocket(5));
  299. }
  300.  
  301. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ", attrtype0, attrvalue0, attrtype1, attrvalue1, attrtype2, attrvalue2, attrtype3, attrvalue3, attrtype4, attrvalue4, attrtype5, attrvalue5, attrtype6, attrvalue6, applytype0, applyvalue0, applytype1, applyvalue1, applytype2, applyvalue2, applytype3, applyvalue3, applytype4, applyvalue4, applytype5, applyvalue5, applytype6, applyvalue6, applytype7, applyvalue7");
  302. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d, %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  303. pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
  304. pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
  305. pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
  306. pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
  307. pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
  308. pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
  309. pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6),
  310. pkItem->GetAttributeType(7), pkItem->GetAttributeValue(7),
  311. pkItem->GetAttributeType(8), pkItem->GetAttributeValue(8),
  312. pkItem->GetAttributeType(9), pkItem->GetAttributeValue(9),
  313. pkItem->GetAttributeType(10), pkItem->GetAttributeValue(10),
  314. pkItem->GetAttributeType(11), pkItem->GetAttributeValue(11),
  315. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(12),
  316. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(13),
  317. pkItem->GetAttributeType(14), pkItem->GetAttributeValue(14));
  318.  
  319. char szInsertQuery[QUERY_MAX_LEN];
  320. snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO %soffline_shop_item (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
  321. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
  322. ch->ChatPacket(CHAT_TYPE_INFO, "Ai adaugat %s in magazinul tau offline.", pkItem->GetName());
  323. pkItem->RemoveFromCharacter();
  324.  
  325. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  326. if (!npc)
  327. return;
  328.  
  329. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(npc->GetVID());
  330. if (!pkOfflineShop)
  331. return;
  332.  
  333. pkOfflineShop->BroadcastUpdateItem(bDisplayPos, ch->GetPlayerID());
  334. LogManager::instance().ItemLog(ch, pkItem, "ADD ITEM OFFLINE SHOP", "");
  335. }
  336.  
  337. void COfflineShopManager::RemoveItem(LPCHARACTER ch, BYTE bPos)
  338. {
  339. if (!ch)
  340. return;
  341.  
  342. if (bPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  343. {
  344. sys_log(0, "OfflineShopManager::RemoveItem - Overflow slot! [%s]", ch->GetName());
  345. return;
  346. }
  347.  
  348. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  349.  
  350. // Check npc
  351. if (!npc)
  352. {
  353. char szQuery[1024];
  354.  
  355. if (g_bOfflineShopSocketMax == 3)
  356. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  357. else if(g_bOfflineShopSocketMax == 4)
  358. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  359. else if(g_bOfflineShopSocketMax == 5)
  360. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  361. else if(g_bOfflineShopSocketMax == 6)
  362. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,socket5,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  363.  
  364. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  365. if (pMsg->Get()->uiNumRows == 0)
  366. {
  367. sys_log(0, "OfflineShopManager::RemoveItem - This slot is empty! [%s]", ch->GetName());
  368. return;
  369. }
  370.  
  371. TPlayerItem item;
  372. int rows;
  373. if (!(rows = mysql_num_rows(pMsg->Get()->pSQLResult)))
  374. return;
  375.  
  376. for (int i = 0; i < rows; ++i)
  377. {
  378. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  379. int cur = 0;
  380.  
  381. str_to_number(item.pos, row[cur++]);
  382. str_to_number(item.count, row[cur++]);
  383. str_to_number(item.vnum, row[cur++]);
  384. for (BYTE a = 0; a < ITEM_SOCKET_MAX_NUM; a++)
  385. str_to_number(item.alSockets[a], row[cur++]);
  386.  
  387. for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
  388. {
  389. str_to_number(item.aAttr[j].bType, row[cur++]);
  390. str_to_number(item.aAttr[j].sValue, row[cur++]);
  391. }
  392. }
  393.  
  394. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  395. if (!pItem)
  396. {
  397. ch->ChatPacket(CHAT_TYPE_INFO, "Este o problema la magazinul offline,incearca mai tarziu!");
  398. return;
  399. }
  400.  
  401. pItem->SetAttributes(item.aAttr);
  402. pItem->SetSockets(item.alSockets);
  403.  
  404. int iEmptyPos;
  405. if (pItem->IsDragonSoul())
  406. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  407. else
  408. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  409.  
  410. if (iEmptyPos < 0)
  411. {
  412. ch->ChatPacket(CHAT_TYPE_INFO, "Nu ai suficient spatiu in magazinul offline!");
  413. return;
  414. }
  415.  
  416. if (pItem->IsDragonSoul())
  417. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  418. else
  419. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  420.  
  421. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  422. LogManager::instance().ItemLog(ch, pItem, "DELETE OFFLINE SHOP ITEM", "");
  423. ch->ChatPacket(CHAT_TYPE_INFO, "Ai scos %s din magazinul tau offline.", pItem->GetName());
  424. }
  425. else
  426. {
  427. LPOFFLINESHOP pkOfflineShop = npc->GetOfflineShop();
  428.  
  429. // Check pkOfflineShop
  430. if (!pkOfflineShop)
  431. return;
  432.  
  433. char szQuery[1024];
  434. if (g_bOfflineShopSocketMax == 3)
  435. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  436. else if(g_bOfflineShopSocketMax == 4)
  437. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  438. else if(g_bOfflineShopSocketMax == 5)
  439. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  440. else if(g_bOfflineShopSocketMax == 6)
  441. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,socket5,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  442.  
  443. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  444. if (pMsg->Get()->uiNumRows == 0)
  445. {
  446. sys_log(0, "OfflineShopManager::RemoveItem - This slot is empty! [%s]", ch->GetName());
  447. return;
  448. }
  449.  
  450. TPlayerItem item;
  451. int rows;
  452. if (!(rows = mysql_num_rows(pMsg->Get()->pSQLResult)))
  453. return;
  454.  
  455. for (int i = 0; i < rows; ++i)
  456. {
  457. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  458. int cur = 0;
  459.  
  460. str_to_number(item.pos, row[cur++]);
  461. str_to_number(item.count, row[cur++]);
  462. str_to_number(item.vnum, row[cur++]);
  463. for (BYTE a = 0; a < ITEM_SOCKET_MAX_NUM; a++)
  464. str_to_number(item.alSockets[a], row[cur++]);
  465.  
  466. for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
  467. {
  468. str_to_number(item.aAttr[j].bType, row[cur++]);
  469. str_to_number(item.aAttr[j].sValue, row[cur++]);
  470. }
  471. }
  472.  
  473. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  474. if (!pItem)
  475. {
  476. ch->ChatPacket(CHAT_TYPE_INFO, "Magazinul offline are o problema,incearca mai tarziu!");
  477. return;
  478. }
  479.  
  480. pItem->SetAttributes(item.aAttr);
  481. pItem->SetSockets(item.alSockets);
  482.  
  483. int iEmptyPos;
  484. if (pItem->IsDragonSoul())
  485. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  486. else
  487. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  488.  
  489. if (iEmptyPos < 0)
  490. {
  491. ch->ChatPacket(CHAT_TYPE_INFO, "Nu ai suficient spatiu in magazinul tau offline pentru acest obiect!");
  492. return;
  493. }
  494.  
  495. if (pItem->IsDragonSoul())
  496. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  497. else
  498. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  499.  
  500. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  501. pkOfflineShop->BroadcastUpdateItem(bPos, ch->GetPlayerID(), true);
  502.  
  503. if (LeftItemCount(ch) == 0)
  504. pkOfflineShop->Destroy(npc);
  505.  
  506. LogManager::instance().ItemLog(ch, pItem, "DELETE OFFLINE SHOP ITEM", "");
  507. ch->ChatPacket(CHAT_TYPE_INFO, "Ai scos %s din magazinul tau offline.", pItem->GetName());
  508. }
  509. }
  510.  
  511. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  512. void COfflineShopManager::ChangePrice(LPCHARACTER ch, BYTE bPos, long long llPrice)
  513. #else
  514. void COfflineShopManager::ChangePrice(LPCHARACTER ch, BYTE bPos, DWORD dwPrice)
  515. #endif
  516. {
  517. if (!ch)
  518. return;
  519.  
  520. if (bPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  521. {
  522. sys_err("Offlineshop overflow slot count [%s][%d]", ch->GetName(), bPos);
  523. return;
  524. }
  525.  
  526. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  527. if (llPrice >= GOLD_MAX)
  528. {
  529. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti schimba pretul obiectului,depasesti limita de yang!");
  530. return;
  531. }
  532. #else
  533. if (dwPrice >= GOLD_MAX - 1)
  534. {
  535. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti schimba pretul obiectului,depasesti limita de yang!");
  536. return;
  537. }
  538. #endif
  539.  
  540. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
  541. if (pkOfflineShop)
  542. {
  543. pkOfflineShop->RemoveAllGuest();
  544. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  545. pkOfflineShop->BroadcastUpdatePrice(bPos, llPrice);
  546. #else
  547. pkOfflineShop->BroadcastUpdatePrice(bPos, dwPrice);
  548. #endif
  549. }
  550.  
  551. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  552. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET price = %lld WHERE owner_id = %u and pos = %d", get_table_postfix(), llPrice, ch->GetPlayerID(), bPos);
  553. #else
  554. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET price = %u WHERE owner_id = %u and pos = %d", get_table_postfix(), dwPrice, ch->GetPlayerID(), bPos);
  555. #endif
  556. }
  557.  
  558. void COfflineShopManager::Refresh(LPCHARACTER ch)
  559. {
  560. if (!ch)
  561. return;
  562.  
  563. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  564. if (!npc)
  565. {
  566. TPacketGCShop pack;
  567. pack.header = HEADER_GC_OFFLINE_SHOP;
  568. pack.subheader = SHOP_SUBHEADER_GC_UPDATE_ITEM2;
  569.  
  570. TPacketGCOfflineShopStart pack2;
  571. memset(&pack2, 0, sizeof(pack2));
  572. pack2.owner_vid = 0;
  573.  
  574. char szQuery[1024];
  575. if (g_bOfflineShopSocketMax == 3)
  576. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  577. else if(g_bOfflineShopSocketMax == 4)
  578. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  579. else if(g_bOfflineShopSocketMax == 5)
  580. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,socket4,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  581. else if(g_bOfflineShopSocketMax == 6)
  582. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,socket4,socket5,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 0", get_table_postfix(), ch->GetPlayerID());
  583.  
  584. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  585.  
  586. MYSQL_ROW row;
  587. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  588. {
  589. BYTE bPos = 0;
  590. str_to_number(bPos, row[0]);
  591.  
  592. str_to_number(pack2.items[bPos].count, row[1]);
  593. str_to_number(pack2.items[bPos].vnum, row[2]);
  594. str_to_number(pack2.items[bPos].price, row[3]);
  595.  
  596. DWORD alSockets[ITEM_SOCKET_MAX_NUM];
  597. for (int i = 0, n = 4; i < ITEM_SOCKET_MAX_NUM; ++i, n++)
  598. str_to_number(alSockets[i], row[n]);
  599.  
  600. TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
  601. for (int i = 0, iStartType = 7, iStartValue = 8; i < ITEM_ATTRIBUTE_MAX_NUM; ++i, iStartType += 2, iStartValue += 2)
  602. {
  603. str_to_number(aAttr[i].bType, row[iStartType]);
  604. str_to_number(aAttr[i].sValue, row[iStartValue]);
  605. }
  606.  
  607. thecore_memcpy(pack2.items[bPos].alSockets, alSockets, sizeof(pack2.items[bPos].alSockets));
  608. thecore_memcpy(pack2.items[bPos].aAttr, aAttr, sizeof(pack2.items[bPos].aAttr));
  609. }
  610.  
  611. pack.size = sizeof(pack) + sizeof(pack2);
  612.  
  613. if (ch->GetDesc())
  614. {
  615. ch->GetDesc()->BufferedPacket(&pack, sizeof(TPacketGCShop));
  616. ch->GetDesc()->Packet(&pack2, sizeof(TPacketGCOfflineShopStart));
  617. }
  618. }
  619. else
  620. {
  621. LPOFFLINESHOP pkOfflineShop = npc->GetOfflineShop();
  622. if (!pkOfflineShop)
  623. return;
  624.  
  625. pkOfflineShop->Refresh(ch);
  626. }
  627. }
  628.  
  629. void COfflineShopManager::RefreshMoney(LPCHARACTER ch)
  630. {
  631. if (!ch)
  632. return;
  633.  
  634. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT money FROM player2.player WHERE id = %u", ch->GetPlayerID()));
  635.  
  636. TPacketGCShop p;
  637. TPacketGCOfflineShopMoney p2;
  638.  
  639. p.header = HEADER_GC_OFFLINE_SHOP;
  640. p.subheader = SHOP_SUBHEADER_GC_REFRESH_MONEY;
  641.  
  642. if (pMsg->Get()->uiNumRows == 0)
  643. {
  644. p2.llMoney = 0;
  645. p.size = sizeof(p) + sizeof(p2);
  646. if (ch->GetDesc())
  647. {
  648. ch->GetDesc()->BufferedPacket(&p, sizeof(TPacketGCShop));
  649. ch->GetDesc()->Packet(&p2, sizeof(TPacketGCOfflineShopMoney));
  650. }
  651. }
  652. else
  653. {
  654. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  655. str_to_number(p2.llMoney, row[0]);
  656. p.size = sizeof(p) + sizeof(p2);
  657. if (ch->GetDesc())
  658. {
  659. ch->GetDesc()->BufferedPacket(&p, sizeof(TPacketGCShop));
  660. ch->GetDesc()->Packet(&p2, sizeof(TPacketGCOfflineShopMoney));
  661. }
  662. }
  663. }
  664.  
  665. void COfflineShopManager::RefreshUnsoldItems(LPCHARACTER ch)
  666. {
  667. TPacketGCShop pack;
  668. pack.header = HEADER_GC_OFFLINE_SHOP;
  669. pack.subheader = SHOP_SUBHEADER_GC_UPDATE_ITEM2;
  670.  
  671. TPacketGCOfflineShopStart pack2;
  672. memset(&pack2, 0, sizeof(pack2));
  673. pack2.owner_vid = 0;
  674.  
  675. char szQuery[1024];
  676. if (g_bOfflineShopSocketMax == 3)
  677. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), ch->GetPlayerID());
  678. else if (g_bOfflineShopSocketMax == 4)
  679. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), ch->GetPlayerID());
  680. else if (g_bOfflineShopSocketMax == 5)
  681. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,socket4,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), ch->GetPlayerID());
  682. else if (g_bOfflineShopSocketMax == 6)
  683. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,price,socket0,socket1,socket2,socket3,socket4,socket5,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), ch->GetPlayerID());
  684.  
  685. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  686.  
  687. MYSQL_ROW row;
  688. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  689. {
  690. BYTE bPos = 0;
  691. str_to_number(bPos, row[0]);
  692.  
  693. str_to_number(pack2.items[bPos].count, row[1]);
  694. str_to_number(pack2.items[bPos].vnum, row[2]);
  695. str_to_number(pack2.items[bPos].price, row[3]);
  696.  
  697. DWORD alSockets[ITEM_SOCKET_MAX_NUM];
  698. for (int i = 0, n = 4; i < ITEM_SOCKET_MAX_NUM; ++i, n++)
  699. str_to_number(alSockets[i], row[n]);
  700.  
  701. TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
  702. for (int i = 0, iStartType = 7, iStartValue = 8; i < ITEM_ATTRIBUTE_MAX_NUM; ++i, iStartType += 2, iStartValue += 2)
  703. {
  704. str_to_number(aAttr[i].bType, row[iStartType]);
  705. str_to_number(aAttr[i].sValue, row[iStartValue]);
  706. }
  707.  
  708. thecore_memcpy(pack2.items[bPos].alSockets, alSockets, sizeof(pack2.items[bPos].alSockets));
  709. thecore_memcpy(pack2.items[bPos].aAttr, aAttr, sizeof(pack2.items[bPos].aAttr));
  710. }
  711.  
  712. pack.size = sizeof(pack) + sizeof(pack2);
  713.  
  714. if (ch->GetDesc())
  715. {
  716. ch->GetDesc()->BufferedPacket(&pack, sizeof(TPacketGCShop));
  717. ch->GetDesc()->Packet(&pack2, sizeof(TPacketGCOfflineShopStart));
  718. }
  719. }
  720.  
  721. void COfflineShopManager::TakeItem(LPCHARACTER ch, BYTE bPos)
  722. {
  723. if (bPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  724. return;
  725.  
  726. if (ch->GetOfflineShop() || ch->GetOfflineShopOwner())
  727. return;
  728.  
  729. char szQuery[1024];
  730.  
  731. if (g_bOfflineShopSocketMax == 3)
  732. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  733. else if (g_bOfflineShopSocketMax == 4)
  734. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  735. else if (g_bOfflineShopSocketMax == 5)
  736. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  737. else if (g_bOfflineShopSocketMax == 6)
  738. snprintf(szQuery, sizeof(szQuery), "SELECT pos,count,vnum,socket0,socket1,socket2,socket3,socket4,socket5,attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,applytype3,applyvalue3,applytype4,applyvalue4,applytype5,applyvalue5,applytype6,applyvalue6,applytype7,applyvalue7 FROM %soffline_shop_item WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  739.  
  740. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  741. if (pMsg->Get()->uiNumRows == 0)
  742. {
  743. sys_log(0, "OfflineShopManager::RemoveItem - This slot is empty! [%s]", ch->GetName());
  744. return;
  745. }
  746.  
  747. TPlayerItem item;
  748. int rows;
  749. if (!(rows = mysql_num_rows(pMsg->Get()->pSQLResult)))
  750. return;
  751.  
  752. for (int i = 0; i < rows; ++i)
  753. {
  754. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  755. int cur = 0;
  756.  
  757. str_to_number(item.pos, row[cur++]);
  758. str_to_number(item.count, row[cur++]);
  759. str_to_number(item.vnum, row[cur++]);
  760. for (BYTE a = 0; a < ITEM_SOCKET_MAX_NUM; a++)
  761. str_to_number(item.alSockets[a], row[cur++]);
  762.  
  763. for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
  764. {
  765. str_to_number(item.aAttr[j].bType, row[cur++]);
  766. str_to_number(item.aAttr[j].sValue, row[cur++]);
  767. }
  768. }
  769.  
  770. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  771. if (!pItem)
  772. {
  773. ch->ChatPacket(CHAT_TYPE_INFO, "Magazinul offline are o problema,incearca mai tarziu!");
  774. return;
  775. }
  776.  
  777. pItem->SetAttributes(item.aAttr);
  778. pItem->SetSockets(item.alSockets);
  779.  
  780. int iEmptyPos;
  781. if (pItem->IsDragonSoul())
  782. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  783. else
  784. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  785.  
  786. if (iEmptyPos < 0)
  787. {
  788. ch->ChatPacket(CHAT_TYPE_INFO, "Nu ai suficient spatiu pentru a depozita acest item!");
  789. return;
  790. }
  791.  
  792. if (pItem->IsDragonSoul())
  793. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  794. else
  795. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  796.  
  797. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_item WHERE owner_id = %u and pos = %d and status = 1", get_table_postfix(), ch->GetPlayerID(), bPos);
  798. LogManager::instance().ItemLog(ch, pItem, "TAKE OFFLINE SHOP ITEM", "");
  799. }
  800.  
  801. DWORD COfflineShopManager::FindMyOfflineShop(DWORD dwPID)
  802. {
  803. TOfflineShopMap::iterator it = m_Map_pkOfflineShopByNPC2.find(dwPID);
  804. if (m_Map_pkOfflineShopByNPC2.end() == it)
  805. return 0;
  806.  
  807. return it->second;
  808. }
  809.  
  810. void COfflineShopManager::ChangeOfflineShopTime(LPCHARACTER ch, BYTE bTime)
  811. {
  812. if (!ch)
  813. return;
  814.  
  815. // Remember
  816. DWORD dwOfflineShopVID = FindMyOfflineShop(ch->GetPlayerID());
  817.  
  818. if (!dwOfflineShopVID)
  819. {
  820. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi aceasta optiune,nu ai facut un magazin offline!");
  821. return;
  822. }
  823.  
  824. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  825. if (npc)
  826. {
  827. if (npc->GetOfflineShopTimer() == 0 && bTime == 4)
  828. {
  829. ch->ChatPacket(CHAT_TYPE_INFO, "Timpul magazinului tau offline este setat deja ca NELIMITAT.");
  830. return;
  831. }
  832.  
  833. if (g_wCoinsForUnlimited > 0 && bTime == 4)
  834. {
  835. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = %u", ch->GetAID()));
  836. if (pMsg->Get()->uiNumRows == 0) return;
  837. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  838. long lCoins = 0;
  839. str_to_number(lCoins, row[0]);
  840.  
  841. if (lCoins < static_cast<long>(g_wCoinsForUnlimited))
  842. {
  843. ch->ChatPacket(CHAT_TYPE_INFO, "Ca sa-ti poti creea un magazin offline cu timpul NELIMITAT,");
  844. ch->ChatPacket(CHAT_TYPE_INFO, "Ai nevoie de %d Monede Dragon(MD) ,care le poti cumpara doar din ITEM-SHOP.", g_wCoinsForUnlimited);
  845. return;
  846. }
  847.  
  848. DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins - %d where id = %u", g_wCoinsForUnlimited, ch->GetAID());
  849. }
  850.  
  851. if (bTime == 4)
  852. {
  853. ch->ChatPacket(CHAT_TYPE_INFO, "Ai schimbat timpul magazinului tau in NELIMITAT!");
  854. npc->StopOfflineShopUpdateEvent();
  855. }
  856. else
  857. {
  858. int iTime = 0;
  859. switch (bTime)
  860. {
  861. case 1:
  862. iTime = 2 * 60 * 60;
  863. break;
  864. case 2:
  865. iTime = 6 * 60 * 60;
  866. break;
  867. case 3:
  868. iTime = 12 * 60 * 60;
  869. break;
  870. }
  871. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("UPDATE %soffline_shop_npc SET time = %d WHERE owner_id = %u", get_table_postfix(), iTime, ch->GetPlayerID()));
  872. npc->StopOfflineShopUpdateEvent();
  873. npc->SetOfflineShopTimer(iTime);
  874. npc->StartOfflineShopUpdateEvent();
  875. LogManager::instance().CharLog(ch, 0, "OFFLINE SHOP", "CHANGE TIME");
  876. ch->ChatPacket(CHAT_TYPE_INFO, "Ai schimbat timpul magazinului tau offline,acesta va expira in %d ore", iTime / 60 / 60);
  877. }
  878. }
  879. else
  880. {
  881. if (g_wCoinsForUnlimited > 0 && bTime == 4)
  882. {
  883. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = %u", ch->GetAID()));
  884. if (pMsg->Get()->uiNumRows == 0) return;
  885. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  886. long lCoins = 0;
  887. str_to_number(lCoins, row[0]);
  888.  
  889. if (lCoins < static_cast<long>(g_wCoinsForUnlimited))
  890. {
  891. ch->ChatPacket(CHAT_TYPE_INFO, "Ca sa-ti poti creea un magazin offline cu timpul NELIMITAT,");
  892. ch->ChatPacket(CHAT_TYPE_INFO, "Ai nevoie de %d Monede Dragon(MD) ,care le poti cumpara doar din ITEM-SHOP.", g_wCoinsForUnlimited);
  893. return;
  894. }
  895.  
  896. DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins - %d where id = %u", g_wCoinsForUnlimited, ch->GetAID());
  897. }
  898.  
  899. TPacketGGChangeOfflineShopTime p;
  900. p.bHeader = HEADER_GG_CHANGE_OFFLINE_SHOP_TIME;
  901. p.bTime = bTime;
  902. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  903. if (pMsg->Get()->uiNumRows == 0)
  904. {
  905. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi aceasta optiune!");
  906. return;
  907. }
  908.  
  909. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  910. str_to_number(p.lMapIndex, row[0]);
  911. p.dwOwnerPID = ch->GetPlayerID();
  912. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGChangeOfflineShopTime));
  913. if (bTime != 4)
  914. ch->ChatPacket(CHAT_TYPE_INFO, "Ai schimbat timpul magazinului tau offline.");
  915. else
  916. ch->ChatPacket(CHAT_TYPE_INFO, "Ai schimbat timpul magazinului tau offline in NELIMITAT.");
  917. }
  918. }
  919.  
  920. void COfflineShopManager::StopShopping(LPCHARACTER ch)
  921. {
  922. LPOFFLINESHOP pkOfflineShop;
  923.  
  924. if (!(pkOfflineShop = ch->GetOfflineShop()))
  925. return;
  926.  
  927. pkOfflineShop->RemoveGuest(ch);
  928. sys_log(0, "OFFLINE_SHOP: END: %s", ch->GetName());
  929.  
  930. ///
  931. TPacketGCShop pack;
  932. pack.header = HEADER_GC_OFFLINE_SHOP;
  933. pack.subheader = SHOP_SUBHEADER_GC_UPDATE_ITEM2;
  934.  
  935. TPacketGCOfflineShopStart pack2;
  936. memset(&pack2, 0, sizeof(pack2));
  937. pack2.owner_vid = 0;
  938. for (BYTE i = 0; i < OFFLINE_SHOP_HOST_ITEM_MAX_NUM; ++i)
  939. pack2.items[i].vnum = 0;
  940.  
  941. pack.size = sizeof(pack) + sizeof(pack2);
  942.  
  943. if (ch->GetDesc())
  944. {
  945. ch->GetDesc()->BufferedPacket(&pack, sizeof(TPacketGCShop));
  946. ch->GetDesc()->Packet(&pack2, sizeof(TPacketGCOfflineShopStart));
  947. }
  948. }
  949.  
  950. void COfflineShopManager::Buy(LPCHARACTER ch, BYTE pos)
  951. {
  952. if (!ch->GetOfflineShop())
  953. return;
  954.  
  955. if (!ch->GetOfflineShopOwner())
  956. return;
  957.  
  958. if (DISTANCE_APPROX(ch->GetX() - ch->GetOfflineShopOwner()->GetX(), ch->GetY() - ch->GetOfflineShopOwner()->GetY()) > 1500)
  959. {
  960. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("»óÁ¡°úÀÇ °Å¸®°¡ ³Ê¹« ¸Ö¾î ¹°°ÇÀ» »ì ¼ö ¾ø½À´Ï´Ù."));
  961. return;
  962. }
  963.  
  964. LPOFFLINESHOP pkOfflineShop = ch->GetOfflineShop();
  965.  
  966. if (!pkOfflineShop)
  967. return;
  968.  
  969. int ret = pkOfflineShop->Buy(ch, pos);
  970.  
  971. // The result is not equal to SHOP_SUBHEADER_GC_OK, send the error to the character.
  972. if (SHOP_SUBHEADER_GC_OK != ret)
  973. {
  974. TPacketGCShop pack;
  975. pack.header = HEADER_GC_OFFLINE_SHOP;
  976. pack.subheader = ret;
  977. pack.size = sizeof(TPacketGCShop);
  978.  
  979. if (ch->GetDesc())
  980. ch->GetDesc()->Packet(&pack, sizeof(pack));
  981. }
  982. }
  983.  
  984. void COfflineShopManager::WithdrawMoney(LPCHARACTER ch, long long llRequiredMoney)
  985. {
  986. if (llRequiredMoney < 0)
  987. return;
  988.  
  989. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT money FROM player2.player WHERE id = %u", ch->GetPlayerID()));
  990. if (pMsg->Get()->uiNumRows == 0)
  991. return;
  992.  
  993. long long llCurrentMoney = 0;
  994. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  995. str_to_number(llCurrentMoney, row[0]);
  996.  
  997. if (llRequiredMoney > llCurrentMoney)
  998. {
  999. ch->ChatPacket(CHAT_TYPE_INFO, "Ai introdus o suma prea mare!");
  1000. return;
  1001. }
  1002.  
  1003. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  1004. bool isOverFlow = static_cast<long long>(ch->GetGold()) + llRequiredMoney > GOLD_MAX - 1 ? true : false;
  1005. #else
  1006. bool isOverFlow = ch->GetGold() + llRequiredMoney > GOLD_MAX - 1 ? true : false;
  1007. #endif
  1008.  
  1009. if (isOverFlow)
  1010. {
  1011. ch->ChatPacket(CHAT_TYPE_INFO, "Nu poti retrage yang deocamdata!");
  1012. return;
  1013. }
  1014.  
  1015. ch->PointChange(POINT_GOLD, llRequiredMoney, false);
  1016. ch->ChatPacket(CHAT_TYPE_INFO, "Ai primit %lld yang", llRequiredMoney);
  1017. DBManager::instance().DirectQuery("UPDATE player2.player SET money = money - %lld WHERE id = %u", llRequiredMoney, ch->GetPlayerID());
  1018. LogManager::instance().CharLog(ch, 0, "OFFLINE SHOP", "WITHDRAW MONEY");
  1019. }
  1020.  
  1021. BYTE COfflineShopManager::LeftItemCount(LPCHARACTER ch)
  1022. {
  1023. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  1024. if (pMsg->Get()->uiNumRows == 0)
  1025. return 0;
  1026.  
  1027. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  1028. BYTE bCount = 0;
  1029. str_to_number(bCount, row[0]);
  1030. return bCount;
  1031. }
  1032.  
  1033. bool COfflineShopManager::HasOfflineShop(LPCHARACTER ch)
  1034. {
  1035. BYTE bHasOfflineShop = 0;
  1036. TPacketGCShop p;
  1037. p.header = HEADER_GC_OFFLINE_SHOP;
  1038. p.subheader = SHOP_SUBHEADER_GC_CHECK_RESULT;
  1039. p.size = sizeof(p);
  1040.  
  1041. if (ch->GetOfflineShopVID())
  1042. {
  1043. bHasOfflineShop = 1;
  1044. ch->SetOfflineShopStatus(2);
  1045. if (ch->GetDesc())
  1046. {
  1047. ch->GetDesc()->Packet(&p, sizeof(p));
  1048. ch->GetDesc()->Packet(&bHasOfflineShop, sizeof(BYTE));
  1049. }
  1050. return true;
  1051. }
  1052. else
  1053. {
  1054. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT owner_id FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  1055. if (pMsg->Get()->uiNumRows == 0)
  1056. {
  1057. ch->SetOfflineShopStatus(bHasOfflineShop);
  1058. if (ch->GetDesc())
  1059. {
  1060. ch->GetDesc()->Packet(&p, sizeof(p));
  1061. ch->GetDesc()->Packet(&bHasOfflineShop, sizeof(BYTE));
  1062. }
  1063. return false;
  1064. }
  1065. else
  1066. {
  1067. bHasOfflineShop = 1;
  1068. ch->SetOfflineShopStatus(2);
  1069. if (ch->GetDesc())
  1070. {
  1071. ch->GetDesc()->Packet(&p, sizeof(p));
  1072. ch->GetDesc()->Packet(&bHasOfflineShop, sizeof(BYTE));
  1073. }
  1074. return true;
  1075. }
  1076. }
  1077. return false;
  1078. }
RAW Paste Data