Guest User

Untitled

a guest
Oct 18th, 2019
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void CHARACTER::UpdateShopItems()
  2. {
  3. LPSHOP npcshop = GetMyShop();
  4. LPCHARACTER owner = CHARACTER_MANAGER::instance().FindByPID(GetPrivShopOwner());
  5. if (!npcshop || !IsPrivShop())
  6. return;
  7. npcshop->RemoveGuests(owner);
  8. npcshop->SetLocked(true);
  9. npcshop->ClearItems();
  10. std::vector<TShopItemTable *> map_shop;
  11. char szSockets[1024] = { '\0' };
  12. char *tempSockets = szSockets;
  13. for (int i = 0; i < ITEM_SOCKET_MAX_NUM; i++)
  14. {
  15. tempSockets += sprintf(tempSockets, "socket%d", i);
  16.  
  17. if (i<ITEM_SOCKET_MAX_NUM - 1)
  18. tempSockets += sprintf(tempSockets, ",");
  19. }
  20. char szAttrs[1024] = { '\0' };
  21. char *tempAttrs = szAttrs;
  22. for (int i = 0; i < ITEM_ATTRIBUTE_MAX_NUM; i++)
  23. {
  24. if (i < 7)
  25. tempAttrs += sprintf(tempAttrs, "attrtype%d,attrvalue%d", i, i);
  26. else
  27. tempAttrs += sprintf(tempAttrs, "applytype%d,applyvalue%d", i - 7, i - 7);
  28. if (i<ITEM_ATTRIBUTE_MAX_NUM - 1)
  29. tempAttrs += sprintf(tempAttrs, ",");
  30. }
  31. SQLMsg * Msg(DBManager::instance().DirectQuery("SELECT id,vnum,count,display_pos,price,%s,%s,type from player_shop_items where shop_id='%d'",szSockets,szAttrs, GetPrivShop()));
  32. SQLResult * Res = Msg->Get();
  33. if (Res->uiNumRows > 0)
  34. {
  35. MYSQL_ROW row;
  36. while ((row = mysql_fetch_row(Res->pSQLResult)) != NULL)
  37. {
  38.  
  39. int col = 0;
  40.  
  41.  
  42.  
  43. TShopItemTable *shop = new TShopItemTable;
  44. memset(shop, 0, sizeof(TShopItemTable));
  45. DWORD id;
  46. shop->pos.window_type = INVENTORY;
  47. str_to_number(id, row[col++]);
  48. str_to_number(shop->vnum, row[col++]);
  49. str_to_number(shop->count, row[col++]);
  50. str_to_number(shop->display_pos, row[col++]);
  51. //col++;
  52. str_to_number(shop->price, row[col++]);
  53.  
  54. const TItemTable * item_table = ITEM_MANAGER::instance().GetTable(shop->vnum);
  55.  
  56.  
  57. if (!item_table)
  58. {
  59. sys_err("Shop: no item table by item vnum #%d", shop->vnum);
  60. continue;
  61. }
  62. for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
  63. {
  64. if (NULL != GetInventoryItem(i) && GetInventoryItem(i)->GetRealID() == id)
  65. GetInventoryItem(i)->RemoveFromCharacter();
  66. }
  67. LPITEM item = ITEM_MANAGER::instance().CreateItem(shop->vnum, shop->count, id, false, -1, true);
  68. if (-1 == (shop->pos.cell = GetEmptyInventory(item_table->bSize)))
  69. {
  70. sys_err("no empty position in npc inventory");
  71. return;
  72. }
  73. if (item)
  74. {
  75. item->ClearAttribute();
  76. item->SetRealID(id);
  77. for (int s = 0;s<ITEM_SOCKET_MAX_NUM;s++)
  78. {
  79. DWORD soc;
  80. str_to_number(soc, row[col++]);
  81. item->SetSocket(s, soc, false);
  82. }
  83. for (int at = 0;at<ITEM_ATTRIBUTE_MAX_NUM;at++)
  84. {
  85. DWORD attr;
  86. long val;
  87. str_to_number(attr, row[col++]);
  88. str_to_number(val, row[col++]);
  89. item->SetForceAttribute(at, attr, val);
  90. }
  91.  
  92. item->AddToCharacter(this, shop->pos);
  93. }
  94. else
  95. {
  96. sys_err("%d is not item", shop->vnum);
  97. continue;
  98. }
  99. str_to_number(shop->type, row[25]);
  100. map_shop.push_back(shop);
  101. }
  102. }
  103.  
  104.  
  105.  
  106. if (map_shop.size() == 0 || map_shop.size() > SHOP_HOST_ITEM_MAX_NUM)
  107. {
  108. DeleteMyShop();
  109. return;
  110. }
  111. npcshop->SetPrivShopItems(map_shop);
  112. npcshop->SetLocked(false);
  113. for (int i = 0;i < SHOP_HOST_ITEM_MAX_NUM;i++)
  114. npcshop->BroadcastUpdateItem(i);
  115.  
  116. if (owner)
  117. {
  118. owner->LoadPrivShops();
  119. owner->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_EDIT_SUCCESS"));
  120. }
  121. }
RAW Paste Data