Advertisement
Guest User

offlineshop_manager.cpp

a guest
Sep 8th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.65 KB | None | 0 0
  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. COfflineShopManager::COfflineShopManager()
  32. {
  33. }
  34.  
  35. COfflineShopManager::~COfflineShopManager()
  36. {
  37. }
  38.  
  39. struct FFindOfflineShop
  40. {
  41. const char * szName;
  42.  
  43. DWORD dwVID, dwRealOwner;
  44. FFindOfflineShop(const char * c_szName) : szName(c_szName), dwVID(0), dwRealOwner(0) {};
  45.  
  46. void operator()(LPENTITY ent)
  47. {
  48. if (!ent)
  49. return;
  50.  
  51. if (ent->IsType(ENTITY_CHARACTER))
  52. {
  53. LPCHARACTER ch = (LPCHARACTER)ent;
  54. if (ch->IsOfflineShopNPC() && !strcmp(szName, ch->GetName()))
  55. {
  56. dwVID = ch->GetVID();
  57. dwRealOwner = ch->GetOfflineShopRealOwner();
  58. M2_DESTROY_CHARACTER(ch);
  59. }
  60. }
  61. }
  62. };
  63.  
  64. bool COfflineShopManager::StartShopping(LPCHARACTER pkChr, LPCHARACTER pkChrShopKeeper)
  65. {
  66. if (pkChr->GetOfflineShopOwner() == pkChrShopKeeper)
  67. return false;
  68.  
  69. if (pkChrShopKeeper->IsPC())
  70. return false;
  71.  
  72. sys_log(0, "OFFLINE_SHOP: START: %s", pkChr->GetName());
  73. return true;
  74. }
  75.  
  76. LPOFFLINESHOP COfflineShopManager::CreateOfflineShop(LPCHARACTER npc, DWORD dwOwnerPID)
  77. {
  78. if (FindOfflineShop(npc->GetVID()))
  79. return NULL;
  80.  
  81. LPOFFLINESHOP pkOfflineShop = M2_NEW COfflineShop;
  82. pkOfflineShop->SetOfflineShopNPC(npc);
  83.  
  84. m_map_pkOfflineShopByNPC.insert(TShopMap::value_type(npc->GetVID(), pkOfflineShop));
  85. m_Map_pkOfflineShopByNPC2.insert(TOfflineShopMap::value_type(dwOwnerPID, npc->GetVID()));
  86. return pkOfflineShop;
  87. }
  88.  
  89. LPOFFLINESHOP COfflineShopManager::FindOfflineShop(DWORD dwVID)
  90. {
  91. TShopMap::iterator it = m_map_pkOfflineShopByNPC.find(dwVID);
  92.  
  93. if (it == m_map_pkOfflineShopByNPC.end())
  94. return NULL;
  95.  
  96. return it->second;
  97. }
  98.  
  99. void COfflineShopManager::DestroyOfflineShop(LPCHARACTER ch, DWORD dwVID, bool bDestroyAll)
  100. {
  101. if (dwVID == 0)
  102. {
  103. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex, mapIndex,channel FROM offline_shop_npc%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  104. if (pMsg->Get()->uiNumRows == 0)
  105. {
  106. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin yok..");
  107. return;
  108. }
  109.  
  110. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  111.  
  112. long lMapIndex = 0;
  113. str_to_number(lMapIndex, row[0]);
  114.  
  115. TPacketGGRemoveOfflineShop p;
  116. p.bHeader = HEADER_GG_REMOVE_OFFLINE_SHOP;
  117. p.lMapIndex = lMapIndex;
  118.  
  119. // Set offline shop name
  120. char szNpcName[CHARACTER_NAME_MAX_LEN + 1];
  121. snprintf(szNpcName, sizeof(szNpcName), "%s", ch->GetName());
  122. strlcpy(p.szNpcName, szNpcName, sizeof(p.szNpcName));
  123. // End Of Set offline shop name
  124.  
  125. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGRemoveOfflineShop));
  126. Giveback(ch);
  127. }
  128. else
  129. {
  130. LPCHARACTER npc;
  131. if (!ch)
  132. npc = CHARACTER_MANAGER::instance().Find(dwVID);
  133. else
  134. npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  135.  
  136. if (!npc)
  137. {
  138. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex,channel FROM offline_shop_npc%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  139. if (pMsg->Get()->uiNumRows == 0)
  140. {
  141. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin yok..");
  142. return;
  143. }
  144.  
  145. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  146.  
  147. long lMapIndex = 0;
  148. str_to_number(lMapIndex, row[0]);
  149.  
  150. BYTE bChannel = 0;
  151. str_to_number(bChannel, row[1]);
  152.  
  153. if (g_bChannel != bChannel)
  154. {
  155. ch->ChatPacket(CHAT_TYPE_INFO, "Kanalda olmalisin %d pazari kapatman icin burda ol %d .", g_bChannel, bChannel);
  156. return;
  157. }
  158.  
  159. char szName[CHARACTER_NAME_MAX_LEN + 1];
  160. snprintf(szName, sizeof(szName), "%s", ch->GetName());
  161. LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(lMapIndex);
  162. FFindOfflineShop offlineShop(szName);
  163. pMap->for_each(offlineShop);
  164.  
  165. if (bDestroyAll)
  166. {
  167. Giveback(ch);
  168. m_map_pkOfflineShopByNPC.erase(offlineShop.dwVID);
  169. m_Map_pkOfflineShopByNPC2.erase(offlineShop.dwRealOwner);
  170. DBManager::instance().DirectQuery("DELETE FROM offline_shop_npc%s WHERE owner_id = %u", get_table_postfix(), offlineShop.dwRealOwner);
  171. return;
  172. }
  173. }
  174.  
  175. LPOFFLINESHOP pkOfflineShop;
  176. if (!ch)
  177. pkOfflineShop = FindOfflineShop(dwVID);
  178. else
  179. pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
  180.  
  181. if (!pkOfflineShop)
  182. return;
  183.  
  184. if (npc->GetOfflineShopChannel() != g_bChannel)
  185. {
  186. ch->ChatPacket(CHAT_TYPE_INFO, "Kanalda olmalisin %d pazari kapatman icin burda ol %d .", g_bChannel, npc->GetOfflineShopChannel());
  187. return;
  188. }
  189.  
  190. if (bDestroyAll)
  191. {
  192. Giveback(ch);
  193. pkOfflineShop->Destroy(npc);
  194. }
  195.  
  196. m_map_pkOfflineShopByNPC.erase(npc->GetVID());
  197. m_Map_pkOfflineShopByNPC2.erase(npc->GetOfflineShopRealOwner());
  198. M2_DELETE(pkOfflineShop);
  199. }
  200. }
  201.  
  202. void COfflineShopManager::Giveback(LPCHARACTER ch)
  203. {
  204. if (!ch)
  205. return;
  206.  
  207. char szQuery[1024];
  208. if (g_bOfflineShopSocketMax == 3)
  209. 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 offline_shop_item%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID());
  210. else if(g_bOfflineShopSocketMax == 4)
  211. 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 offline_shop_item%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID());
  212. else if(g_bOfflineShopSocketMax == 5)
  213. 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 offline_shop_item%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID());
  214. else if(g_bOfflineShopSocketMax == 6)
  215. 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 offline_shop_item%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID());
  216.  
  217. std::auto_ptr<SQLMsg> pMsg(DBManager::Instance().DirectQuery(szQuery));
  218.  
  219. if (pMsg->Get()->uiNumRows == 0)
  220. {
  221. sys_err("COfflineShopManager::GiveBack - There is nothing for this player [%s]", ch->GetName());
  222. return;
  223. }
  224.  
  225. MYSQL_ROW row;
  226. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  227. {
  228. TPlayerItem item;
  229.  
  230. str_to_number(item.pos, row[0]);
  231. str_to_number(item.count, row[1]);
  232. str_to_number(item.vnum, row[2]);
  233.  
  234. // Set Sockets
  235. for (int i = 0, n = 3; i < ITEM_SOCKET_MAX_NUM; ++i, n++)
  236. str_to_number(item.alSockets[i], row[n]);
  237. // End Of Set Sockets
  238.  
  239. // Set Attributes
  240. for (int i = 0, iStartAttributeType = 6, iStartAttributeValue = 7 ; i < ITEM_ATTRIBUTE_MAX_NUM; ++i, iStartAttributeType += 2, iStartAttributeValue += 2)
  241. {
  242. str_to_number(item.aAttr[i].bType, row[iStartAttributeType]);
  243. str_to_number(item.aAttr[i].sValue, row[iStartAttributeValue]);
  244. }
  245. // End Of Set Attributes
  246.  
  247. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  248. if (pItem)
  249. {
  250. int iEmptyPos = 0;
  251.  
  252. if (pItem->IsDragonSoul())
  253. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  254. else
  255. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  256.  
  257. if (iEmptyPos < 0)
  258. {
  259. ch->ChatPacket(CHAT_TYPE_INFO, "Deponda yer yok");
  260. return;
  261. }
  262.  
  263. pItem->SetSockets(item.alSockets);
  264. pItem->SetAttributes(item.aAttr);
  265.  
  266. if (pItem->IsDragonSoul())
  267. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  268. else
  269. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  270.  
  271. ch->ChatPacket(CHAT_TYPE_INFO, "Sizden %s alindi.", pItem->GetName());
  272. DBManager::instance().DirectQuery("DELETE FROM offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), item.pos);
  273. }
  274. }
  275. }
  276.  
  277. void COfflineShopManager::Giveback2(LPCHARACTER ch)
  278. {
  279. if (!ch)
  280. return;
  281.  
  282. char szQuery[1024];
  283. 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 offline_shop_item%s WHERE owner_id = %u and status = 1", get_table_postfix(), ch->GetPlayerID());
  284. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  285.  
  286. if (pMsg->Get()->uiNumRows == 0)
  287. return;
  288.  
  289. MYSQL_ROW row;
  290. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  291. {
  292. TPlayerItem item;
  293.  
  294. str_to_number(item.pos, row[0]);
  295. str_to_number(item.count, row[1]);
  296. str_to_number(item.vnum, row[2]);
  297.  
  298. // Set Sockets
  299. for (int i = 0, n = 3; i < ITEM_SOCKET_MAX_NUM; ++i, n++)
  300. str_to_number(item.alSockets[i], row[n]);
  301. // End Of Set Sockets
  302.  
  303. // Set Attributes
  304. for (int i = 0, iStartAttributeType = 6, iStartAttributeValue = ITEM_ATTRIBUTE_MAX_NUM; i < ITEM_ATTRIBUTE_MAX_NUM; ++i, iStartAttributeType += 2, iStartAttributeValue += 2)
  305. {
  306. str_to_number(item.aAttr[i].bType, row[iStartAttributeType]);
  307. str_to_number(item.aAttr[i].sValue, row[iStartAttributeValue]);
  308. }
  309. // End Of Set Attributes
  310.  
  311. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  312. if (pItem)
  313. {
  314. int iEmptyPos = 0;
  315.  
  316. if (pItem->IsDragonSoul())
  317. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  318. else
  319. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  320.  
  321. if (iEmptyPos < 0)
  322. {
  323. ch->ChatPacket(CHAT_TYPE_INFO, "Deponda yer yok");
  324. return;
  325. }
  326.  
  327. pItem->SetSockets(item.alSockets);
  328. pItem->SetAttributes(item.aAttr);
  329.  
  330. if (pItem->IsDragonSoul())
  331. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  332. else
  333. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  334.  
  335. ch->ChatPacket(CHAT_TYPE_INFO, "Sizden %s alindi.", pItem->GetName());
  336. DBManager::instance().DirectQuery("DELETE FROM offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), item.pos);
  337. }
  338. }
  339. }
  340.  
  341. void COfflineShopManager::AddItem(LPCHARACTER ch, BYTE bDisplayPos, BYTE bPos, int iPrice, int iPriceCheque)
  342. {
  343. if (!ch)
  344. return;
  345.  
  346. // Fixed bug 6.21.2015
  347. if (bDisplayPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  348. {
  349. sys_err("Overflow offline shop slot count [%s]", ch->GetName());
  350. return;
  351. }
  352. // End Of fixed bug 6.21.2015
  353.  
  354. // Check player has offline shop or not
  355. std::auto_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM offline_shop_npc%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  356. MYSQL_ROW row = mysql_fetch_row(pmsg->Get()->pSQLResult);
  357.  
  358. BYTE bResult = 0;
  359. str_to_number(bResult, row[0]);
  360.  
  361. if (!bResult)
  362. {
  363. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin yok");
  364. return;
  365. }
  366. // End Of Check player has offline shop or not
  367.  
  368. LPITEM pkItem = ch->GetInventoryItem(bPos);
  369.  
  370. if (!pkItem)
  371. return;
  372.  
  373. // Check
  374. const TItemTable * itemTable = pkItem->GetProto();
  375. if (IS_SET(itemTable->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MY_OFFLINE_SHOP))
  376. {
  377. ch->ChatPacket(CHAT_TYPE_INFO, "Bu item satilamaz");
  378. return;
  379. }
  380.  
  381. if (pkItem->isLocked())
  382. return;
  383.  
  384. if (pkItem->IsEquipped())
  385. {
  386. ch->ChatPacket(CHAT_TYPE_INFO, "Kilitli item satilamaz!");
  387. return;
  388. }
  389.  
  390. char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
  391.  
  392. int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,price_cheque,vnum");
  393. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%d,%d,%u", pkItem->GetID(), ch->GetPlayerID(), bDisplayPos, pkItem->GetCount(), iPrice, iPriceCheque, pkItem->GetVnum());
  394.  
  395. if (g_bOfflineShopSocketMax == 3)
  396. {
  397. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
  398. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
  399. }
  400. else if(g_bOfflineShopSocketMax == 4)
  401. {
  402. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3");
  403. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2), pkItem->GetSocket(3));
  404. }
  405. else if(g_bOfflineShopSocketMax == 5)
  406. {
  407. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3,socket4");
  408. 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));
  409. }
  410. else if(g_bOfflineShopSocketMax == 6)
  411. {
  412. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2,socket3,socket4,socket5");
  413. 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));
  414. }
  415.  
  416. 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");
  417. 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",
  418. pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
  419. pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
  420. pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
  421. pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
  422. pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
  423. pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
  424. pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6),
  425. pkItem->GetAttributeType(7), pkItem->GetAttributeValue(7),
  426. pkItem->GetAttributeType(8), pkItem->GetAttributeValue(8),
  427. pkItem->GetAttributeType(9), pkItem->GetAttributeValue(9),
  428. pkItem->GetAttributeType(10), pkItem->GetAttributeValue(10),
  429. pkItem->GetAttributeType(11), pkItem->GetAttributeValue(11),
  430. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(12),
  431. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(13),
  432. pkItem->GetAttributeType(14), pkItem->GetAttributeValue(14));
  433.  
  434. char szInsertQuery[QUERY_MAX_LEN];
  435. snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO offline_shop_item%s (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
  436. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
  437. pkItem->RemoveFromCharacter();
  438.  
  439. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  440. if (!npc)
  441. return;
  442.  
  443. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(npc->GetVID());
  444. if (!pkOfflineShop)
  445. return;
  446.  
  447. pkOfflineShop->BroadcastUpdateItem(bDisplayPos, ch->GetPlayerID());
  448. LogManager::instance().ItemLog(ch, pkItem, "ADD ITEM OFFLINE SHOP", "");
  449. }
  450.  
  451. void COfflineShopManager::RemoveItem(LPCHARACTER ch, BYTE bPos)
  452. {
  453. if (!ch)
  454. return;
  455.  
  456. if (bPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  457. {
  458. sys_log(0, "OfflineShopManager::RemoveItem - Overflow slot! [%s]", ch->GetName());
  459. return;
  460. }
  461.  
  462. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  463.  
  464. // Check npc
  465. if (!npc)
  466. {
  467. char szQuery[1024];
  468.  
  469. if (g_bOfflineShopSocketMax == 3)
  470. 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 offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  471. else if(g_bOfflineShopSocketMax == 4)
  472. 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 offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  473. else if(g_bOfflineShopSocketMax == 5)
  474. 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 offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  475. else if(g_bOfflineShopSocketMax == 6)
  476. 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 offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  477.  
  478. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
  479. if (pMsg->Get()->uiNumRows == 0)
  480. {
  481. sys_log(0, "OfflineShopManager::RemoveItem - This slot is empty! [%s]", ch->GetName());
  482. return;
  483. }
  484.  
  485. TPlayerItem item;
  486. int rows;
  487. if (!(rows = mysql_num_rows(pMsg->Get()->pSQLResult)))
  488. return;
  489.  
  490. for (int i = 0; i < rows; ++i)
  491. {
  492. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  493. int cur = 0;
  494.  
  495. str_to_number(item.pos, row[cur++]);
  496. str_to_number(item.count, row[cur++]);
  497. str_to_number(item.vnum, row[cur++]);
  498. str_to_number(item.alSockets[0], row[cur++]);
  499. str_to_number(item.alSockets[1], row[cur++]);
  500. str_to_number(item.alSockets[2], row[cur++]);
  501.  
  502. for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
  503. {
  504. str_to_number(item.aAttr[j].bType, row[cur++]);
  505. str_to_number(item.aAttr[j].sValue, row[cur++]);
  506. }
  507. }
  508.  
  509. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  510. if (!pItem)
  511. {
  512. ch->ChatPacket(CHAT_TYPE_INFO, "Lutfen tekrar deneyin!");
  513. return;
  514. }
  515.  
  516. pItem->SetAttributes(item.aAttr);
  517. pItem->SetSockets(item.alSockets);
  518.  
  519. int iEmptyPos;
  520. if (pItem->IsDragonSoul())
  521. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  522. else
  523. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  524.  
  525. if (iEmptyPos < 0)
  526. {
  527. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin burada mevcut degil!");
  528. return;
  529. }
  530.  
  531. if (pItem->IsDragonSoul())
  532. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  533. else
  534. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  535.  
  536. DBManager::instance().DirectQuery("DELETE FROM offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  537. LogManager::instance().ItemLog(ch, pItem, "DELETE OFFLINE SHOP ITEM", "");
  538. }
  539. else
  540. {
  541. LPOFFLINESHOP pkOfflineShop = npc->GetOfflineShop();
  542.  
  543. // Check pkOfflineShop
  544. if (!pkOfflineShop)
  545. return;
  546.  
  547. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("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 offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos));
  548. if (pMsg->Get()->uiNumRows == 0)
  549. {
  550. sys_log(0, "OfflineShopManager::RemoveItem - This slot is empty! [%s]", ch->GetName());
  551. return;
  552. }
  553.  
  554. TPlayerItem item;
  555. int rows;
  556. if (!(rows = mysql_num_rows(pMsg->Get()->pSQLResult)))
  557. return;
  558.  
  559. for (int i = 0; i < rows; ++i)
  560. {
  561. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  562. int cur = 0;
  563.  
  564. str_to_number(item.pos, row[cur++]);
  565. str_to_number(item.count, row[cur++]);
  566. str_to_number(item.vnum, row[cur++]);
  567. str_to_number(item.alSockets[0], row[cur++]);
  568. str_to_number(item.alSockets[1], row[cur++]);
  569. str_to_number(item.alSockets[2], row[cur++]);
  570.  
  571. for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
  572. {
  573. str_to_number(item.aAttr[j].bType, row[cur++]);
  574. str_to_number(item.aAttr[j].sValue, row[cur++]);
  575. }
  576. }
  577.  
  578. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(item.vnum, item.count);
  579. if (!pItem)
  580. {
  581. ch->ChatPacket(CHAT_TYPE_INFO, "Lutfen tekrer deneyin!");
  582. return;
  583. }
  584.  
  585. pItem->SetAttributes(item.aAttr);
  586. pItem->SetSockets(item.alSockets);
  587.  
  588. int iEmptyPos;
  589. if (pItem->IsDragonSoul())
  590. iEmptyPos = ch->GetEmptyDragonSoulInventory(pItem);
  591. else
  592. iEmptyPos = ch->GetEmptyInventory(pItem->GetSize());
  593.  
  594. if (iEmptyPos < 0)
  595. {
  596. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin burada mevcut degil!");
  597. return;
  598. }
  599.  
  600. if (pItem->IsDragonSoul())
  601. pItem->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
  602. else
  603. pItem->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
  604.  
  605. DBManager::instance().DirectQuery("DELETE FROM offline_shop_item%s WHERE owner_id = %u and pos = %d", get_table_postfix(), ch->GetPlayerID(), bPos);
  606. pkOfflineShop->BroadcastUpdateItem(bPos, ch->GetPlayerID(), true);
  607.  
  608. if (LeftItemCount(ch) == 0)
  609. pkOfflineShop->Destroy(npc);
  610.  
  611. LogManager::instance().ItemLog(ch, pItem, "DELETE OFFLINE SHOP ITEM", "");
  612. }
  613. }
  614.  
  615. void COfflineShopManager::ChangePrice(LPCHARACTER ch, BYTE bPos, DWORD dwPrice, DWORD dwPriceCheque)
  616. {
  617. if (!ch)
  618. return;
  619.  
  620. if (bPos >= OFFLINE_SHOP_HOST_ITEM_MAX_NUM)
  621. {
  622. sys_err("Offlineshop overflow slot count [%s][%d]", ch->GetName(), bPos);
  623. return;
  624. }
  625.  
  626. LPOFFLINESHOP pkOfflineShop = FindOfflineShop(FindMyOfflineShop(ch->GetPlayerID()));
  627. if (pkOfflineShop)
  628. pkOfflineShop->BroadcastUpdatePrice(bPos, dwPrice, dwPriceCheque);
  629.  
  630. DBManager::instance().DirectQuery("UPDATE offline_shop_item%s SET price = %u, price_cheque = %u WHERE owner_id = %u and pos = %d", get_table_postfix(), dwPrice, dwPriceCheque, ch->GetPlayerID(), bPos);
  631.  
  632. sys_log(0, "PRET GOLD: %u | PRET CHEQUE: %u | ITEM ID: %u | POZITIE: %d", dwPrice, dwPriceCheque, ch->GetPlayerID(), bPos);
  633. }
  634.  
  635. void COfflineShopManager::Refresh(LPCHARACTER ch)
  636. {
  637. if (!ch)
  638. return;
  639.  
  640. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  641. if (!npc)
  642. {
  643. TPacketGCShop pack;
  644. pack.header = HEADER_GC_OFFLINE_SHOP;
  645. pack.subheader = SHOP_SUBHEADER_GC_UPDATE_ITEM2;
  646.  
  647. TPacketGCOfflineShopStart pack2;
  648. memset(&pack2, 0, sizeof(pack2));
  649. pack2.owner_vid = 0;
  650.  
  651. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("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 offline_shop_item%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  652.  
  653. MYSQL_ROW row;
  654. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  655. {
  656. BYTE bPos = 0;
  657. str_to_number(bPos, row[0]);
  658.  
  659. str_to_number(pack2.items[bPos].count, row[1]);
  660. str_to_number(pack2.items[bPos].vnum, row[2]);
  661. str_to_number(pack2.items[bPos].price, row[3]);
  662.  
  663. DWORD alSockets[ITEM_SOCKET_MAX_NUM];
  664. for (int i = 0, n = 4; i < ITEM_SOCKET_MAX_NUM; ++i, n++)
  665. str_to_number(alSockets[i], row[n]);
  666.  
  667. TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
  668. for (int i = 0, iStartType = 7, iStartValue = 8; i < ITEM_ATTRIBUTE_MAX_NUM; ++i, iStartType += 2, iStartValue += 2)
  669. {
  670. str_to_number(aAttr[i].bType, row[iStartType]);
  671. str_to_number(aAttr[i].sValue, row[iStartValue]);
  672. }
  673.  
  674. thecore_memcpy(pack2.items[bPos].alSockets, alSockets, sizeof(pack2.items[bPos].alSockets));
  675. thecore_memcpy(pack2.items[bPos].aAttr, aAttr, sizeof(pack2.items[bPos].aAttr));
  676. }
  677.  
  678. pack.size = sizeof(pack) + sizeof(pack2);
  679. ch->GetDesc()->BufferedPacket(&pack, sizeof(TPacketGCShop));
  680. ch->GetDesc()->Packet(&pack2, sizeof(TPacketGCOfflineShopStart));
  681. }
  682. else
  683. {
  684. LPOFFLINESHOP pkOfflineShop = npc->GetOfflineShop();
  685. if (!pkOfflineShop)
  686. return;
  687.  
  688. pkOfflineShop->Refresh(ch);
  689. }
  690. }
  691.  
  692. void COfflineShopManager::RefreshMoney(LPCHARACTER ch)
  693. {
  694. if (!ch)
  695. return;
  696.  
  697. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT shop_gold, shop_cheque FROM player%s WHERE id = %u", get_table_postfix(), ch->GetPlayerID()));
  698.  
  699. TPacketGCShop p;
  700. TPacketGCOfflineShopMoney p2;
  701.  
  702. p.header = HEADER_GC_OFFLINE_SHOP;
  703. p.subheader = SHOP_SUBHEADER_GC_REFRESH_MONEY;
  704.  
  705. if (pMsg->Get()->uiNumRows == 0)
  706. {
  707. p2.dwMoney = 0;
  708. p2.dwCheque = 0;
  709.  
  710. p.size = sizeof(p) + sizeof(p2);
  711. ch->GetDesc()->BufferedPacket(&p, sizeof(TPacketGCShop));
  712. ch->GetDesc()->Packet(&p2, sizeof(TPacketGCOfflineShopMoney));
  713. }
  714. else
  715. {
  716. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  717. str_to_number(p2.dwMoney, row[0]);
  718. str_to_number(p2.dwCheque, row[1]);
  719.  
  720. p.size = sizeof(p) + sizeof(p2);
  721. ch->GetDesc()->BufferedPacket(&p, sizeof(TPacketGCShop));
  722. ch->GetDesc()->Packet(&p2, sizeof(TPacketGCOfflineShopMoney));
  723. }
  724. }
  725.  
  726. DWORD COfflineShopManager::FindMyOfflineShop(DWORD dwPID)
  727. {
  728. TOfflineShopMap::iterator it = m_Map_pkOfflineShopByNPC2.find(dwPID);
  729. if (m_Map_pkOfflineShopByNPC2.end() == it)
  730. return 0;
  731.  
  732. return it->second;
  733. }
  734.  
  735. void COfflineShopManager::ChangeOfflineShopTime(LPCHARACTER ch, BYTE bTime)
  736. {
  737. if (!ch)
  738. return;
  739.  
  740. // Remember
  741. DWORD dwOfflineShopVID = FindMyOfflineShop(ch->GetPlayerID());
  742.  
  743. if (!dwOfflineShopVID)
  744. {
  745. ch->ChatPacket(CHAT_TYPE_INFO, "Cevrimdisi pazarin yok!");
  746. return;
  747. }
  748.  
  749. LPCHARACTER npc = CHARACTER_MANAGER::instance().Find(FindMyOfflineShop(ch->GetPlayerID()));
  750. if (npc)
  751. {
  752. if (test_server)
  753. SendNotice("#DEBUG - Offline Shop NPC Found!");
  754.  
  755. if (bTime == 4)
  756. {
  757. npc->StopOfflineShopUpdateEvent();
  758. }
  759. else
  760. {
  761. int iTime = 0;
  762. switch (bTime)
  763. {
  764. case 1:
  765. iTime = 6 * 60 * 60;
  766. break;
  767. case 2:
  768. iTime = 12 * 60 * 60;
  769. break;
  770. case 3:
  771. iTime = 24 * 60 * 60;
  772. break;
  773. }
  774. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("UPDATE offline_shop_npc%s SET time = %d WHERE owner_id = %u", get_table_postfix(), iTime, ch->GetPlayerID()));
  775. ch->ChatPacket(CHAT_TYPE_INFO, "Zaman degisti: %u saat", iTime / 3600);
  776. sys_log(0, "TIMP: %u | PLAYER ID: %u", iTime, ch->GetPlayerID());
  777. npc->StopOfflineShopUpdateEvent();
  778. npc->SetOfflineShopTimer(iTime);
  779. npc->StartOfflineShopUpdateEvent();
  780. LogManager::instance().CharLog(ch, 0, "OFFLINE SHOP", "CHANGE TIME");
  781. }
  782. }
  783. else
  784. {
  785. TPacketGGChangeOfflineShopTime p;
  786. p.bHeader = HEADER_GG_CHANGE_OFFLINE_SHOP_TIME;
  787. p.bTime = bTime;
  788. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT mapIndex FROM offline_shop_npc%s WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  789. if (pMsg->Get()->uiNumRows == 0)
  790. {
  791. ch->ChatPacket(CHAT_TYPE_INFO, "Bu secenegi kullanamazsiniz!");
  792. return;
  793. }
  794.  
  795. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  796. str_to_number(p.lMapIndex, row[0]);
  797. p.dwOwnerPID = ch->GetPlayerID();
  798.  
  799. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGChangeOfflineShopTime));
  800. }
  801. }
  802.  
  803. void COfflineShopManager::StopShopping(LPCHARACTER ch)
  804. {
  805. LPOFFLINESHOP pkOfflineShop;
  806.  
  807. if (!(pkOfflineShop = ch->GetOfflineShop()))
  808. return;
  809.  
  810. pkOfflineShop->RemoveGuest(ch);
  811. sys_log(0, "OFFLINE_SHOP: END: %s", ch->GetName());
  812. }
  813.  
  814. void COfflineShopManager::Buy(LPCHARACTER ch, BYTE pos)
  815. {
  816. if (!ch->GetOfflineShop())
  817. return;
  818.  
  819. if (!ch->GetOfflineShopOwner())
  820. return;
  821.  
  822. if (DISTANCE_APPROX(ch->GetX() - ch->GetOfflineShopOwner()->GetX(), ch->GetY() - ch->GetOfflineShopOwner()->GetY()) > 1500)
  823. {
  824. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상점과의 거리가 너무 멀어 물건을 살 수 없습니다."));
  825. return;
  826. }
  827.  
  828. LPOFFLINESHOP pkOfflineShop = ch->GetOfflineShop();
  829.  
  830. if (!pkOfflineShop)
  831. return;
  832.  
  833. int ret = pkOfflineShop->Buy(ch, pos);
  834.  
  835. // The result is not equal to SHOP_SUBHEADER_GC_OK, send the error to the character.
  836. if (SHOP_SUBHEADER_GC_OK != ret)
  837. {
  838. TPacketGCShop pack;
  839. pack.header = HEADER_GC_OFFLINE_SHOP;
  840. pack.subheader = ret;
  841. pack.size = sizeof(TPacketGCShop);
  842.  
  843. ch->GetDesc()->Packet(&pack, sizeof(pack));
  844. }
  845. }
  846.  
  847. void COfflineShopManager::WithdrawMoney(LPCHARACTER ch, DWORD dwRequiredMoney)
  848. {
  849. if (!ch)
  850. return;
  851.  
  852. if (dwRequiredMoney < 0)
  853. return;
  854.  
  855. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT money2 FROM player.player WHERE id = %u", ch->GetPlayerID()));
  856. if (pMsg->Get()->uiNumRows == 0)
  857. return;
  858.  
  859. DWORD dwCurrentMoney = 0;
  860. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  861. str_to_number(dwCurrentMoney, row[0]);
  862.  
  863. if (dwRequiredMoney >= dwCurrentMoney)
  864. {
  865. if (test_server)
  866. ch->ChatPacket(CHAT_TYPE_INFO, "dwCurrentMoney(%lu) - dwRequiredMoney(%lu)", dwCurrentMoney, dwRequiredMoney);
  867.  
  868. ch->ChatPacket(CHAT_TYPE_INFO, "Senin yang az lutfen tekrar kontrol edin!");
  869. return;
  870. }
  871.  
  872. bool isOverFlow = ch->GetGold() + dwRequiredMoney > GOLD_MAX - 1 ? true : false;
  873. if (isOverFlow)
  874. {
  875. ch->ChatPacket(CHAT_TYPE_INFO, "Lutfen istenilen miktarin - 1 rakam eskik girin.");
  876. return;
  877. }
  878.  
  879. ch->PointChange(POINT_GOLD, dwRequiredMoney, false);
  880. ch->ChatPacket(CHAT_TYPE_INFO, "Alinan %u yang.", dwRequiredMoney);
  881. DBManager::instance().DirectQuery("UPDATE player.player SET money2 = money2 - %u WHERE id = %u", dwRequiredMoney, ch->GetPlayerID());
  882. LogManager::instance().CharLog(ch, 0, "OFFLINE SHOP", "WITHDRAW MONEY");
  883. }
  884.  
  885. void COfflineShopManager::WithdrawCheque(LPCHARACTER ch, DWORD dwSacarCheque)
  886. {
  887. if (!ch)
  888. return;
  889.  
  890. if (dwSacarCheque < 0)
  891. return;
  892.  
  893. int64_t nTotalCheque = 0;
  894.  
  895. nTotalCheque += static_cast<int64_t>(ch->GetCheque());
  896.  
  897. if (CHEQUE_MAX <= nTotalCheque)
  898. {
  899. sys_err("[OVERFLOW_GOLD] Overflow (CHEQUE_MAX) id %u name %s", ch->GetPlayerID(), ch->GetName());
  900. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("20¾i ³EA≫ AE°uCI¿ⓒ ≫oA¡A≫ ¿­¼o°¡ ¾ø½A´I´U"));
  901. return;
  902. }
  903.  
  904. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT shop_cheque FROM player%s WHERE id = %u", get_table_postfix(), ch->GetPlayerID()));
  905.  
  906. if (pMsg->Get()->uiNumRows == 0)
  907. return;
  908.  
  909. DWORD dwChequeAtual = 0;
  910. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  911. str_to_number(dwChequeAtual, row[0]);
  912.  
  913. if (dwSacarCheque > dwChequeAtual)
  914. {
  915. if (test_server)
  916. ch->ChatPacket(CHAT_TYPE_INFO, "dwChequeAtual(%lu) - dwSacarCheque(%lu)", dwChequeAtual, dwSacarCheque);
  917.  
  918. ch->ChatPacket(CHAT_TYPE_INFO, "Voce digitou um valor maior do que a corrente de soma!");
  919. return;
  920. }
  921.  
  922. // bool isOverFlow = ch->GetGold() + dwSacarGold > GOLD_MAX - 1 ? true : false;
  923. // if (isOverFlow)
  924. // {
  925. // ch->ChatPacket(CHAT_TYPE_INFO, "Valoare introdusa trebuie sa fie SUMA dorita - 1.");
  926. // return;
  927. // }
  928.  
  929. ch->PointChange(POINT_CHEQUE, dwSacarCheque, false);
  930. ch->ChatPacket(CHAT_TYPE_INFO, "Voce recebeu %u Won.", dwSacarCheque);
  931.  
  932. DBManager::instance().DirectQuery("UPDATE player%s SET shop_cheque = shop_cheque - %u WHERE id = %u", get_table_postfix(), dwSacarCheque, ch->GetPlayerID());
  933.  
  934. LogManager::instance().CharLog(ch, 0, "OFFLINE SHOP", "WITHDRAW CHEQUE");
  935. }
  936.  
  937. BYTE COfflineShopManager::LeftItemCount(LPCHARACTER ch)
  938. {
  939. if (!ch)
  940. return -1;
  941.  
  942. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u", get_table_postfix(), ch->GetPlayerID()));
  943. if (pMsg->Get()->uiNumRows == 0)
  944. return 0;
  945.  
  946. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  947. BYTE bCount = 0;
  948. str_to_number(bCount, row[0]);
  949. return bCount;
  950. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement