Guest User

int CShop::Buy(LPCHARACTER ch, BYTE pos)

a guest
Mar 19th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. int CShop::Buy(LPCHARACTER ch, BYTE pos)
  2. {
  3.     if (pos >= m_itemVector.size())
  4.     {
  5.         sys_log(0, "Shop::Buy : invalid position %d : %s", pos, ch->GetName());
  6.         return SHOP_SUBHEADER_GC_INVALID_POS;
  7.     }
  8.  
  9.     sys_log(0, "Shop::Buy : name %s pos %d", ch->GetName(), pos);
  10.  
  11.     GuestMapType::iterator it = m_map_guest.find(ch);
  12.  
  13.     if (it == m_map_guest.end())
  14.         return SHOP_SUBHEADER_GC_END;
  15.  
  16.     SHOP_ITEM& r_item = m_itemVector[pos];
  17.  
  18.  
  19. #ifdef ENABLE_CHEQUE_SYSTEM
  20.     if (r_item.price < 0 && r_item.cheque_price < 0)
  21. #else
  22.     if (r_item.price < 0)
  23. #endif
  24.     {
  25.         LogManager::instance().HackLog("SHOP_BUY_GOLD_OVERFLOW", ch);
  26.         return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
  27.     }
  28.  
  29.     LPITEM pkSelectedItem = ITEM_MANAGER::instance().Find(r_item.itemid);
  30.  
  31.     if (IsPCShop())
  32.     {
  33.         if (!pkSelectedItem)
  34.         {
  35.             sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
  36.                     ch->GetPlayerID(),
  37.                     m_pkPC->GetPlayerID());
  38.  
  39.             return SHOP_SUBHEADER_GC_SOLD_OUT;
  40.         }
  41.  
  42.         if ((pkSelectedItem->GetOwner() != m_pkPC))
  43.         {
  44.             sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
  45.                     ch->GetPlayerID(),
  46.                     m_pkPC->GetPlayerID());
  47.  
  48.             return SHOP_SUBHEADER_GC_SOLD_OUT;
  49.         }
  50.     }
  51.  
  52.     DWORD dwPrice = r_item.price;
  53.  
  54. #ifdef ENABLE_MULTISHOP
  55.     DWORD dwWItemVnum = r_item.wPriceVnum;
  56.     DWORD dwWItemPrice = r_item.wPrice;
  57. #endif
  58.  
  59. #ifdef ENABLE_CHEQUE_SYSTEM
  60.     BYTE byChequePrice = r_item.cheque_price;
  61. #endif
  62.     //if (it->second)   // if other empire, price is triple
  63.         //dwPrice *= 3;
  64.  
  65.     if (ch->GetGold() < (int) dwPrice)
  66.     {
  67.         sys_log(1, "Shop::Buy : Not enough money : %s has %d, price %d", ch->GetName(), ch->GetGold(), dwPrice);
  68.         return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
  69.     }
  70.  
  71. #ifdef ENABLE_MULTISHOP
  72.     if (dwWItemVnum > 0)
  73.     {
  74.         if (ch->CountSpecifyItem(dwWItemVnum) < (int)dwWItemPrice)
  75.             return SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM;
  76.     }
  77.     else if (ch->GetGold() < (int) dwPrice)
  78. #else
  79.     if (ch->GetGold() < (int) dwPrice)
  80. #endif
  81.  
  82. #ifdef ENABLE_CHEQUE_SYSTEM
  83.     if (ch->GetCheque() < byChequePrice)
  84.     {
  85.         sys_log(1, "Shop::Buy : Not enough cheque : %s has %d, price %d", ch->GetName(), ch->GetCheque(), byChequePrice);
  86.         return SHOP_SUBHEADER_GC_NOT_ENOUGH_CHEQUE;
  87.     }
  88. #endif
  89.  
  90.     LPITEM item;
  91.  
  92.     if (m_pkPC) // ÇǾ¾°¡ ¿î¿µÇÏ´Â ¼¥Àº ÇǾ¾°¡ ½ÇÁ¦ ¾ÆÀÌÅÛÀ» °¡Áö°íÀÖ¾î¾ß ÇÑ´Ù.
  93.         item = r_item.pkItem;
  94.     else
  95.         item = ITEM_MANAGER::instance().CreateItem(r_item.vnum, r_item.count);
  96.  
  97.     if (!item)
  98.         return SHOP_SUBHEADER_GC_SOLD_OUT;
  99.  
  100.     if (!m_pkPC)
  101.     {
  102.         /*if (quest::CQuestManager::instance().GetEventFlag("hivalue_item_sell") == 0)
  103.         {
  104.             //ÃູÀÇ ±¸½½ && ¸¸³âÇÑö À̺¥Æ®
  105.         if (item->GetVnum() == 70024 || item->GetVnum() == 70035)
  106.         {
  107.             return SHOP_SUBHEADER_GC_END;
  108.         }
  109.         }*/
  110.     }
Advertisement
Add Comment
Please, Sign In to add comment