bool buyingstore_setup(struct map_session_data* sd, unsigned char slots) { if( !battle_config.feature_buying_store || sd->state.vending || sd->state.buyingstore || sd->state.trading || slots == 0 ) { return false; } if( sd->sc.data[SC_NOCHAT] && (sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM) ) {// custom: mute limitation return false; } if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING) ) {// custom: no vending maps/cells clif_displaymessage(sd->fd, msg_txt(276)); // "You can't open a shop on this map" return false; } if( slots > MAX_BUYINGSTORE_SLOTS ) { ShowWarning("buyingstore_setup: Requested %d slots, but server supports only %d slots.\n", (int)slots, MAX_BUYINGSTORE_SLOTS); slots = MAX_BUYINGSTORE_SLOTS; } sd->buyingstore.slots = slots; clif_buyingstore_open(sd); return true; }
/** * Player chat room creation. * @param sd : player requesting * @param title : title of chat room * @param pass : password for chat room * @param limit : amount allowed to enter * @param pub : public or private * @return 0 */ int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) { struct chat_data* cd; nullpo_ret(sd); if( sd->chatID ) return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex] if( sd->state.vending || sd->state.buyingstore ) // not chat, when you already have a store open return 0; if( map_getmapflag(sd->bl.m, MF_NOCHAT) ) { clif_displaymessage(sd->fd, msg_txt(sd,281)); return 0; //Can't create chatrooms on this map. } if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) ) { clif_displaymessage (sd->fd, msg_txt(sd,665)); return 0; } pc_stop_walking(sd,1); cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL); if( cd ) { cd->users = 1; cd->usersd[0] = sd; pc_setchatid(sd,cd->bl.id); pc_stop_attack(sd); clif_createchat(sd,0); clif_dispchat(cd,0); if (status_isdead(&sd->bl)) achievement_update_objective(sd, AG_CHAT_DYING, 1, 1); else achievement_update_objective(sd, AG_CHAT_CREATE, 1, 1); } else clif_createchat(sd,1); return 0; }
/*========================================== * player chatroom creation *------------------------------------------*/ int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) { struct chat_data* cd; nullpo_ret(sd); if( sd->chatID ) return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex] if( sd->state.vending || sd->state.buyingstore ) {// not chat, when you already have a store open return 0; } if( map[sd->bl.m].flag.nochat ) { clif_displaymessage(sd->fd, msg_txt(281)); return 0; //Can't create chatrooms on this map. } if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) ) { clif_displaymessage (sd->fd, "Can't create chat rooms in this Area."); return 0; } pc_stop_walking(sd,1); cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL, 0); if( cd ) { cd->users = 1; cd->usersd[0] = sd; pc_setchatid(sd,cd->bl.id); clif_createchat(sd,0); clif_dispchat(cd,0); } else clif_createchat(sd,1); return 0; }
void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned char result, const char* storename, const uint8* itemlist, unsigned int count) { unsigned int i, weight, listidx; struct item_data* id; if( !result || count == 0 ) {// canceled, or no items return; } if( !battle_config.feature_buying_store || pc_istrading(sd) || sd->buyingstore.slots == 0 || count > sd->buyingstore.slots || zenylimit <= 0 || zenylimit > sd->status.zeny || !storename[0] ) {// disabled or invalid input sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return; } if( !pc_can_give_items(pc_isGM(sd)) ) {// custom: GM is not allowed to buy (give zeny) sd->buyingstore.slots = 0; clif_displaymessage(sd->fd, msg_txt(246)); clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return; } if( sd->sc.data[SC_NOCHAT] && (sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM) ) {// custom: mute limitation return; } if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING) ) {// custom: no vending maps/cells clif_displaymessage(sd->fd, msg_txt(276)); // "You can't open a shop on this map" return; } weight = sd->weight; // check item list for( i = 0; i < count; i++ ) {// itemlist: <name id>.W <amount>.W <price>.L unsigned short nameid, amount; int price, idx; nameid = RBUFW(itemlist,i*8+0); amount = RBUFW(itemlist,i*8+2); price = RBUFL(itemlist,i*8+4); if( ( id = itemdb_exists(nameid) ) == NULL || amount == 0 ) {// invalid input break; } if( price <= 0 || price > BUYINGSTORE_MAX_PRICE ) {// invalid price: unlike vending, items cannot be bought at 0 Zeny break; } if( !id->flag.buyingstore || !itemdb_cantrade_sub(id, pc_isGM(sd), pc_isGM(sd)) || ( idx = pc_search_inventory(sd, nameid) ) == -1 ) {// restrictions: allowed, no character-bound items and at least one must be owned break; } if( sd->status.inventory[idx].amount+amount > BUYINGSTORE_MAX_AMOUNT ) {// too many items of same kind break; } if( i ) {// duplicate check. as the client does this too, only malicious intent should be caught here ARR_FIND( 0, i, listidx, sd->buyingstore.items[listidx].nameid == nameid ); if( listidx != i ) {// duplicate ShowWarning("buyingstore_create: Found duplicate item on buying list (nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n", nameid, amount, sd->status.account_id, sd->status.char_id); break; } } weight+= id->weight*amount; sd->buyingstore.items[i].nameid = nameid; sd->buyingstore.items[i].amount = amount; sd->buyingstore.items[i].price = price; } if( i != count ) {// invalid item/amount/price sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return; } if( (sd->max_weight*90)/100 < weight ) {// not able to carry all wanted items without getting overweight (90%) sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE_OVERWEIGHT, weight); return; } // success sd->state.buyingstore = true; sd->buyer_id = buyingstore_getuid(); sd->buyingstore.zenylimit = zenylimit; sd->buyingstore.slots = i; // store actual amount of items safestrncpy(sd->message, storename, sizeof(sd->message)); clif_buyingstore_myitemlist(sd); clif_buyingstore_entry(sd); }
/** * Attempt to create new buying store * @param sd * @param zenylimit * @param result * @param storename * @param *itemlist { <nameid>.W, <amount>.W, <price>.L }* * @param count Number of item on the itemlist * @return 0 If success, 1 - Cannot open, 2 - Manner penalty, 3 - Mapflag restiction, 4 - Cell restriction, 5 - Invalid count/result, 6 - Cannot give item, 7 - Will be overweight */ char buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned char result, const char* storename, const uint8* itemlist, unsigned int count) { unsigned int i, weight, listidx; char message_sql[MESSAGE_SIZE*2]; nullpo_retr(1, sd); if( !result || count == 0 ) {// canceled, or no items return 5; } if( !battle_config.feature_buying_store || pc_istrading(sd) || sd->buyingstore.slots == 0 || count > sd->buyingstore.slots || zenylimit <= 0 || zenylimit > sd->status.zeny || !storename[0] ) {// disabled or invalid input sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return 1; } if( !pc_can_give_items(sd) ) {// custom: GM is not allowed to buy (give zeny) sd->buyingstore.slots = 0; clif_displaymessage(sd->fd, msg_txt(sd,246)); clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return 6; } if( sd->sc.data[SC_NOCHAT] && (sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM) ) {// custom: mute limitation return 2; } if( map[sd->bl.m].flag.novending ) {// custom: no vending maps clif_displaymessage(sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map" return 3; } if( map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING) ) {// custom: no vending cells clif_displaymessage(sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell." return 4; } weight = sd->weight; // check item list for( i = 0; i < count; i++ ) {// itemlist: <name id>.W <amount>.W <price>.L unsigned short nameid, amount; int price, idx; struct item_data* id; nameid = RBUFW(itemlist,i*8+0); amount = RBUFW(itemlist,i*8+2); price = RBUFL(itemlist,i*8+4); if( ( id = itemdb_exists(nameid) ) == NULL || amount == 0 ) {// invalid input break; } if( price <= 0 || price > BUYINGSTORE_MAX_PRICE ) {// invalid price: unlike vending, items cannot be bought at 0 Zeny break; } if( !id->flag.buyingstore || !itemdb_cantrade_sub(id, pc_get_group_level(sd), pc_get_group_level(sd)) || ( idx = pc_search_inventory(sd, nameid) ) == -1 ) {// restrictions: allowed, no character-bound items and at least one must be owned break; } if( sd->status.inventory[idx].amount+amount > BUYINGSTORE_MAX_AMOUNT ) {// too many items of same kind break; } if( i ) {// duplicate check. as the client does this too, only malicious intent should be caught here ARR_FIND( 0, i, listidx, sd->buyingstore.items[listidx].nameid == nameid ); if( listidx != i ) {// duplicate ShowWarning("buyingstore_create: Found duplicate item on buying list (nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n", nameid, amount, sd->status.account_id, sd->status.char_id); break; } } weight+= id->weight*amount; sd->buyingstore.items[i].nameid = nameid; sd->buyingstore.items[i].amount = amount; sd->buyingstore.items[i].price = price; } if( i != count ) {// invalid item/amount/price sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0); return 5; } if( (sd->max_weight*90)/100 < weight ) {// not able to carry all wanted items without getting overweight (90%) sd->buyingstore.slots = 0; clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE_OVERWEIGHT, weight); return 7; } // success sd->state.buyingstore = true; sd->buyer_id = buyingstore_getuid(); sd->buyingstore.zenylimit = zenylimit; sd->buyingstore.slots = i; // store actual amount of items safestrncpy(sd->message, storename, sizeof(sd->message)); Sql_EscapeString( mmysql_handle, message_sql, sd->message ); if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`id`,`account_id`,`char_id`,`sex`,`map`,`x`,`y`,`title`,`limit`,`autotrade`, `body_direction`, `head_direction`, `sit`) " "VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, %d, '%d', '%d', '%d' );", buyingstores_db, sd->buyer_id, sd->status.account_id, sd->status.char_id, sd->status.sex == 0 ? 'F' : 'M', map[sd->bl.m].name, sd->bl.x, sd->bl.y, message_sql, sd->buyingstore.zenylimit, sd->state.autotrade, sd->ud.dir, sd->head_dir, pc_issit(sd) ) != SQL_SUCCESS ){ Sql_ShowDebug(mmysql_handle); } for( i = 0; i < sd->buyingstore.slots; i++ ){ if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`buyingstore_id`,`index`,`item_id`,`amount`,`price`) VALUES( %d, %d, %hu, %d, %d );", buyingstore_items_db, sd->buyer_id, i, sd->buyingstore.items[i].nameid, sd->buyingstore.items[i].amount, sd->buyingstore.items[i].price ) != SQL_SUCCESS ){ Sql_ShowDebug(mmysql_handle); } } clif_buyingstore_myitemlist(sd); clif_buyingstore_entry(sd); idb_put(buyingstore_db, sd->status.char_id, sd); return 0; }
int map_is_solid (int m, int x, int y) { return (IS_SOLID (map_getcell (m, x, y))); }
int hom_surf(struct map_session_data *sd, int homid) { int d, ny, nx; d = unit_getdir(&sd->bl); switch(d) { case 0: //cima CELL_CHKNOREACH ny = (sd->bl.y) +3; if(map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,sd->bl.x,ny-2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny-1,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,sd->bl.x,ny-2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny-1,CELL_CHKREACH) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,sd->bl.x,ny-2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,sd->bl.x,ny-2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny,CELL_CHKREACH)){ if(pc_readglobalreg(sd,"surf") == 0){ pc_disguise(sd, homid); pc_setglobalreg(sd, "surf", homid); pc_setpos(sd,map[sd->bl.m].index,sd->bl.x,ny,CLR_TELEPORT); break; }else if(pc_readglobalreg(sd,"surf") > 0){ pc_setglobalreg(sd, "surf", 0); pc_disguise(sd, 0); pc_setpos(sd,map[sd->bl.m].index,sd->bl.x,ny,CLR_TELEPORT); break; } }else{ clif_displaymessage(sd->fd, "Você não pode usar Surf neste local."); break; } //-------------------------------------------------------------------------------------------- case 2: //esquerda nx = (sd->bl.x) -3; if(map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,nx+2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx+1,sd->bl.y,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,nx+2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx+1,sd->bl.y,CELL_CHKREACH) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,nx+2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx,sd->bl.y,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,nx+2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH)){ if(pc_readglobalreg(sd,"surf")){ pc_disguise(sd, homid); pc_setglobalreg(sd, "surf", homid); pc_setpos(sd,map[sd->bl.m].index,nx,sd->bl.y,CLR_TELEPORT); break; }else if(pc_readglobalreg(sd,"surf") > 0){ pc_setglobalreg(sd, "surf", 0); pc_disguise(sd, 0); pc_setpos(sd,map[sd->bl.m].index,nx,sd->bl.y,CLR_TELEPORT); break; } }else{ clif_displaymessage(sd->fd, "Você não pode usar Surf neste local."); break; } //-------------------------------------------------------------------------------------------- case 4: //baixo ny = (sd->bl.y) -3; if(map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,sd->bl.x,ny+2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny+1,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,sd->bl.x,ny+2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny+1,CELL_CHKREACH) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,sd->bl.x,ny+2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,sd->bl.x,ny+2,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,ny,CELL_CHKREACH)){ if(pc_readglobalreg(sd,"surf") == 0){ pc_disguise(sd, homid); pc_setglobalreg(sd, "surf", homid); pc_setpos(sd,map[sd->bl.m].index,sd->bl.x,ny,CLR_TELEPORT); break; }else if(pc_readglobalreg(sd,"surf") > 0){ pc_setglobalreg(sd, "surf", 0); pc_disguise(sd, 0); pc_setpos(sd,map[sd->bl.m].index,sd->bl.x,ny,CLR_TELEPORT); break; } }else{ clif_displaymessage(sd->fd, "Você não pode usar Surf neste local."); break; } //-------------------------------------------------------------------------------------------- case 6: //direita nx = (sd->bl.x) +3; if(map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,nx-2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx-1,sd->bl.y,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,nx-2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx-1,sd->bl.y,CELL_CHKREACH) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH) && map_getcell(sd->bl.m,nx-2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,nx,sd->bl.y,CELL_CHKWATER) || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKWATER) && map_getcell(sd->bl.m,nx-2,sd->bl.y,CELL_CHKNOREACH) && map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKREACH)){ if(pc_readglobalreg(sd,"surf") == 0){ pc_disguise(sd, homid); pc_setglobalreg(sd, "surf", homid); pc_setpos(sd,map[sd->bl.m].index,nx,sd->bl.y,CLR_TELEPORT); break; }else if(pc_readglobalreg(sd,"surf") > 0){ pc_setglobalreg(sd, "surf", 0); pc_disguise(sd, 0); pc_setpos(sd,map[sd->bl.m].index,nx,sd->bl.y,CLR_TELEPORT); break; } }else{ clif_displaymessage(sd->fd, "Você não pode usar Surf neste local."); break; } } return 0; }