Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CHARACTER::UpdateShopItems()
- {
- LPSHOP npcshop = GetMyShop();
- LPCHARACTER owner = CHARACTER_MANAGER::instance().FindByPID(GetPrivShopOwner());
- if (!npcshop || !IsPrivShop())
- return;
- npcshop->RemoveGuests(owner);
- npcshop->SetLocked(true);
- npcshop->ClearItems();
- std::vector<TShopItemTable *> map_shop;
- char szSockets[1024] = { '\0' };
- char *tempSockets = szSockets;
- for (int i = 0; i < ITEM_SOCKET_MAX_NUM; i++)
- {
- tempSockets += sprintf(tempSockets, "socket%d", i);
- if (i<ITEM_SOCKET_MAX_NUM - 1)
- tempSockets += sprintf(tempSockets, ",");
- }
- char szAttrs[1024] = { '\0' };
- char *tempAttrs = szAttrs;
- for (int i = 0; i < ITEM_ATTRIBUTE_MAX_NUM; i++)
- {
- if (i < 7)
- tempAttrs += sprintf(tempAttrs, "attrtype%d,attrvalue%d", i, i);
- else
- tempAttrs += sprintf(tempAttrs, "applytype%d,applyvalue%d", i - 7, i - 7);
- if (i<ITEM_ATTRIBUTE_MAX_NUM - 1)
- tempAttrs += sprintf(tempAttrs, ",");
- }
- 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()));
- SQLResult * Res = Msg->Get();
- if (Res->uiNumRows > 0)
- {
- MYSQL_ROW row;
- while ((row = mysql_fetch_row(Res->pSQLResult)) != NULL)
- {
- int col = 0;
- TShopItemTable *shop = new TShopItemTable;
- memset(shop, 0, sizeof(TShopItemTable));
- DWORD id;
- shop->pos.window_type = INVENTORY;
- str_to_number(id, row[col++]);
- str_to_number(shop->vnum, row[col++]);
- str_to_number(shop->count, row[col++]);
- str_to_number(shop->display_pos, row[col++]);
- //col++;
- str_to_number(shop->price, row[col++]);
- const TItemTable * item_table = ITEM_MANAGER::instance().GetTable(shop->vnum);
- if (!item_table)
- {
- sys_err("Shop: no item table by item vnum #%d", shop->vnum);
- continue;
- }
- for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
- {
- if (NULL != GetInventoryItem(i) && GetInventoryItem(i)->GetRealID() == id)
- GetInventoryItem(i)->RemoveFromCharacter();
- }
- LPITEM item = ITEM_MANAGER::instance().CreateItem(shop->vnum, shop->count, id, false, -1, true);
- if (-1 == (shop->pos.cell = GetEmptyInventory(item_table->bSize)))
- {
- sys_err("no empty position in npc inventory");
- return;
- }
- if (item)
- {
- item->ClearAttribute();
- item->SetRealID(id);
- for (int s = 0;s<ITEM_SOCKET_MAX_NUM;s++)
- {
- DWORD soc;
- str_to_number(soc, row[col++]);
- item->SetSocket(s, soc, false);
- }
- for (int at = 0;at<ITEM_ATTRIBUTE_MAX_NUM;at++)
- {
- DWORD attr;
- long val;
- str_to_number(attr, row[col++]);
- str_to_number(val, row[col++]);
- item->SetForceAttribute(at, attr, val);
- }
- item->AddToCharacter(this, shop->pos);
- }
- else
- {
- sys_err("%d is not item", shop->vnum);
- continue;
- }
- str_to_number(shop->type, row[25]);
- map_shop.push_back(shop);
- }
- }
- if (map_shop.size() == 0 || map_shop.size() > SHOP_HOST_ITEM_MAX_NUM)
- {
- DeleteMyShop();
- return;
- }
- npcshop->SetPrivShopItems(map_shop);
- npcshop->SetLocked(false);
- for (int i = 0;i < SHOP_HOST_ITEM_MAX_NUM;i++)
- npcshop->BroadcastUpdateItem(i);
- if (owner)
- {
- owner->LoadPrivShops();
- owner->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_EDIT_SUCCESS"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement