Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EVENTFUNC(shop_event)
- {
- LPCHARACTER pc;
- CharacterVectorInteractor i;
- if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(30000, i))
- {
- CharacterVectorInteractor::iterator it = i.begin();
- while (it != i.end()) {
- LPCHARACTER pc = *it++;
- if (pc)
- {
- LPSHOP shop;
- if ((shop = pc->GetMyShop())) {
- if (pc->GetShopTime() < get_global_time() || shop->GetItemCount() <= 0)
- pc->DeleteMyShop();
- }
- else
- M2_DESTROY_CHARACTER(pc);
- }
- }
- }
- return PASSES_PER_SEC(SHOP_TIME_REFRESH);
- }
- EVENTFUNC(fix_shop_event)
- {
- char szSockets[1024] = { '\0' };
- char *tempSockets = szSockets;
- for (int i = 0; i < ITEM_SOCKET_MAX_NUM; i++)
- {
- tempSockets += sprintf(tempSockets, "ps.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, "ps.attrtype%d,attrvalue%d", i, i);
- else
- tempAttrs += sprintf(tempAttrs, "ps.applytype%d,applyvalue%d", i - 7, i - 7);
- if (i<ITEM_ATTRIBUTE_MAX_NUM - 1)
- tempAttrs += sprintf(tempAttrs, ",");
- }
- SQLMsg * pkMsg(DBManager::instance().DirectQuery("SELECT ps.id,ps.shop_id,ps.player_id,REPLACE('%s','#PLAYER_NAME#',p.name),ps.vnum,ps.count,ps.price,%s,%s FROM `player_shop_items` ps LEFT JOIN player p ON p.id=ps.player_id where not EXISTS(select name from player_shop WHERE id=ps.shop_id) and not ISNULL(p.name)", LC_TEXT("SHOP_NAME"), szSockets, szAttrs));
- SQLResult * pRes = pkMsg->Get();
- if (pRes->uiNumRows>0)
- {
- MYSQL_ROW row;
- while ((row = mysql_fetch_row(pRes->pSQLResult)) != NULL)
- {
- DWORD id,pid,vnum,count,socket[6],attr[7][2];
- int col = 0;
- str_to_number(id, row[col++]);
- str_to_number(pid, row[col++]);
- col++;
- str_to_number(vnum, row[col++]);
- str_to_number(count, row[col++]);
- for (int i = 0;i < ITEM_SOCKET_MAX_NUM;i++)
- str_to_number(socket[i], row[col++]);
- for (int i = 0;i < ITEM_ATTRIBUTE_MAX_NUM;i++)
- {
- str_to_number(attr[i][0], row[col++]);
- str_to_number(attr[i][1], row[col++]);
- }
- char query[1024];
- sprintf(query, "INSERT INTO player_gift SET owner_id=%d,vnum=%d,count=%d,reason='%s',`from`=replace(\"%s\",' ','_'),status='WAIT',date_add=NOW()",
- pid, vnum,count, LC_TEXT("SHOP_REASON"), row[3]);
- for (int s = 0; s < ITEM_SOCKET_MAX_NUM; s++)
- {
- sprintf(query, "%s, socket%d='%d'", query, s, socket[s]);
- }
- for (int ia = 0; ia < ITEM_ATTRIBUTE_MAX_NUM; ia++)
- {
- if (ia < 7)
- {
- sprintf(query, "%s, attrtype%d='%d'", query, ia, attr[ia][0]);
- sprintf(query, "%s, attrvalue%d='%d'", query, ia, attr[ia][1]);
- }
- else{
- sprintf(query, "%s, applytype%d='%d'", query, ia-7, attr[ia][0]);
- sprintf(query, "%s, applyvalue%d='%d'", query, ia-7, attr[ia][1]);
- }
- }
- DBManager::instance().DirectQuery(query);
- DBManager::instance().DirectQuery("delete from player_shop_items where id=%d",id);
- }
- }
- return PASSES_PER_SEC(SHOP_TIME_REFRESH*60);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement