Advertisement
Guest User

Untitled

a guest
Jun 28th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.88 KB | None | 0 0
  1. diff --git a/src/map/clif.c b/src/map/clif.c
  2. index 15d6aeb..f74b728 100644
  3. --- a/src/map/clif.c
  4. +++ b/src/map/clif.c
  5. @@ -14742,7 +14742,7 @@ void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  6. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  7. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  8. {
  9. - int fd,i;
  10. + int fd,i,val = 0;
  11. #if PACKETVER < 20070711
  12. const int offset = 8;
  13. #else
  14. @@ -14757,7 +14757,22 @@ void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  15. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  16. WFIFOW(fd,0) = 0x287;
  17. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  18. - WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  19. + if( nd->subtype == ISHOP ) //[Dastgir Pojee]
  20. + {
  21. + if( (i = pc_search_inventory(sd,nd->ishop)) >= 0 )
  22. + {
  23. + char output[128];
  24. + val = sd->status.inventory[i].amount;
  25. + sprintf(output,"This is a Item Shop. You need %s (%d) to Buy items.", itemdb_search(nd->ishop)->jname, nd->ishop);
  26. + clif->colormes(fd,COLOR_RED,output);
  27. + }
  28. + }
  29. + else
  30. + {
  31. + val = sd->cashPoints;
  32. + }
  33. + WFIFOL(fd,4) = val; // Cash Points
  34. +
  35. #if PACKETVER >= 20070711
  36. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  37. #endif
  38. @@ -14786,12 +14801,23 @@ void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  39. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  40. /// 7 = You can purchase up to 10 items.
  41. /// 8 = Some items could not be purchased.
  42. -void clif_cashshop_ack(struct map_session_data* sd, int error) {
  43. +void clif_cashshop_ack(struct map_session_data* sd,struct npc_data *nd, int error) {
  44. int fd = sd->fd;
  45. + int i;
  46. + int val = 0; // Cash Points client slot
  47. +
  48. + if ( nd && nd->subtype == ISHOP) //[Dastgir Pojee]
  49. + {
  50. + if( (i = pc_search_inventory(sd,nd->ishop)) >= 0 )
  51. + val = sd->status.inventory[i].amount;
  52. + }
  53. + else{
  54. + val = sd->cashPoints;
  55. + }
  56.  
  57. WFIFOHEAD(fd, packet_len(0x289));
  58. WFIFOW(fd,0) = 0x289;
  59. - WFIFOL(fd,2) = sd->cashPoints;
  60. + WFIFOL(fd,2) = val;
  61. #if PACKETVER < 20070711
  62. WFIFOW(fd,6) = TOW(error);
  63. #else
  64. @@ -14809,8 +14835,12 @@ void clif_cashshop_ack(struct map_session_data* sd, int error) {
  65. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  66. {
  67. int fail = 0;
  68. + struct npc_data *nd;
  69. nullpo_retv(sd);
  70.  
  71. + if( (nd = (struct npc_data *)map_id2bl(sd->npc_shopid)) == NULL )
  72. + return;
  73. +
  74. if( sd->state.trading || !sd->npc_shopid )
  75. fail = 1;
  76. else {
  77. @@ -14835,7 +14865,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  78. #endif
  79. }
  80.  
  81. - clif->cashshop_ack(sd,fail);
  82. + clif->cashshop_ack(sd,nd,fail);
  83. }
  84.  
  85.  
  86. diff --git a/src/map/clif.h b/src/map/clif.h
  87. index 2aec335..3aede0d 100644
  88. --- a/src/map/clif.h
  89. +++ b/src/map/clif.h
  90. @@ -516,7 +516,7 @@ struct clif_interface {
  91. void (*cashshop_show) (struct map_session_data *sd, struct npc_data *nd);
  92. void (*npc_buy_result) (struct map_session_data* sd, unsigned char result);
  93. void (*npc_sell_result) (struct map_session_data* sd, unsigned char result);
  94. - void (*cashshop_ack) (struct map_session_data* sd, int error);
  95. + void (*cashshop_ack) (struct map_session_data* sd,struct npc_data *nd, int error);
  96. /* npc-script-related */
  97. void (*scriptmes) (struct map_session_data *sd, int npcid, const char *mes);
  98. void (*scriptnext) (struct map_session_data *sd,int npcid);
  99. diff --git a/src/map/map.h b/src/map/map.h
  100. index a7bcb08..7a7e6b8 100644
  101. --- a/src/map/map.h
  102. +++ b/src/map/map.h
  103. @@ -253,7 +253,7 @@ enum bl_type {
  104. //For common mapforeach calls. Since pets cannot be affected, they aren't included here yet.
  105. #define BL_CHAR (BL_PC|BL_MOB|BL_HOM|BL_MER|BL_ELEM)
  106.  
  107. -enum npc_subtype { WARP, SHOP, SCRIPT, CASHSHOP, TOMB };
  108. +enum npc_subtype { WARP, SHOP, SCRIPT, CASHSHOP, TOMB, ISHOP };
  109.  
  110. enum {
  111. RC_FORMLESS=0,
  112. diff --git a/src/map/npc.c b/src/map/npc.c
  113. index 77ee8d4..39dc377 100644
  114. --- a/src/map/npc.c
  115. +++ b/src/map/npc.c
  116. @@ -1213,6 +1213,7 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd)
  117. case SHOP:
  118. clif->npcbuysell(sd,nd->bl.id);
  119. break;
  120. + case ISHOP:
  121. case CASHSHOP:
  122. clif->cashshop_show(sd,nd);
  123. break;
  124. @@ -1317,7 +1318,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
  125. int i, j, nameid, amount, new_, w, vt;
  126. struct npc_data *nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  127.  
  128. - if( !nd || nd->subtype != CASHSHOP )
  129. + if( !nd || (nd->subtype != CASHSHOP && nd->subtype != ISHOP) )
  130. return 1;
  131.  
  132. if( sd->state.trading )
  133. @@ -1366,9 +1367,26 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
  134. if( points > vt ) points = vt;
  135.  
  136. // Payment Process ----------------------------------------------------
  137. - if( sd->kafraPoints < points || sd->cashPoints < (vt - points) )
  138. - return 6;
  139. - pc_paycash(sd,vt,points);
  140. + if (nd->subtype = ISHOP){ //[Dastgir Pojee]
  141. + if( points > 0 )
  142. + {
  143. + ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy with points from a IShop.\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  144. + return 6;
  145. + }
  146. + if (nd->ishop > 0)
  147. + {
  148. + i = pc_search_inventory(sd,nd->ishop);
  149. + if( i < 0 || sd->status.inventory[i].amount < vt )
  150. + return 6;
  151. + pc_delitem(sd,i,vt,0,0,LOG_TYPE_NPC);
  152. + }
  153. + }
  154. + else{
  155. + if( sd->kafraPoints < points || sd->cashPoints < (vt - points) )
  156. + return 6;
  157. + pc_paycash(sd,vt,points);
  158. + }
  159. +
  160.  
  161. // Delivery Process ----------------------------------------------------
  162. for( i = 0; i < count; i++ )
  163. @@ -1432,7 +1450,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
  164. if( points < 0 )
  165. return 6;
  166.  
  167. - if( !nd || nd->subtype != CASHSHOP )
  168. + if( !nd || ( nd->subtype != CASHSHOP && nd->subtype != ISHOP ))
  169. return 1;
  170.  
  171. if( sd->state.trading )
  172. @@ -1480,10 +1498,28 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
  173. if( points > price )
  174. points = price;
  175.  
  176. - if( (sd->kafraPoints < points) || (sd->cashPoints < price - points) )
  177. - return 6;
  178. + //Payment
  179. + if (nd->subtype == ISHOP){
  180. + if( points > 0 )
  181. + {
  182. + ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy with points from a IShop.\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  183. + return 6;
  184. + }
  185. + if (nd->ishop>0)
  186. + {
  187. + i = pc_search_inventory(sd,nd->ishop);
  188. + if( i < 0 || sd->status.inventory[i].amount < price )
  189. + return 6;
  190. + pc_delitem(sd,i,price,0,0,LOG_TYPE_NPC);
  191. + }
  192. + }
  193. + else{
  194. + if( (sd->kafraPoints < points) || (sd->cashPoints < price - points) )
  195. + return 6;
  196. +
  197. + pc_paycash(sd, price, points);
  198. + }
  199.  
  200. - pc_paycash(sd, price, points);
  201.  
  202. if( !pet_create_egg(sd, nameid) )
  203. {
  204. @@ -1842,7 +1878,7 @@ int npc_unload(struct npc_data* nd, bool single) {
  205. }
  206. }
  207.  
  208. - if( (nd->subtype == SHOP || nd->subtype == CASHSHOP) && nd->src_id == 0) //src check for duplicate shops [Orcao]
  209. + if( (nd->subtype == SHOP || nd->subtype == CASHSHOP || nd->subtype == ISHOP) && nd->src_id == 0) //src check for duplicate shops [Orcao]
  210. aFree(nd->u.shop.shop_item);
  211. else if( nd->subtype == SCRIPT ) {
  212. struct s_mapiterator* iter;
  213. @@ -2186,30 +2222,56 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
  214. struct npc_data *nd;
  215. enum npc_subtype type;
  216.  
  217. + //Item Shop
  218. + int ishop = 0;
  219. +
  220. + if( !strcasecmp(w2,"cashshop") )
  221. + type = CASHSHOP;
  222. + else if( !strcasecmp(w2,"ishop") )
  223. + type = ISHOP;
  224. + else
  225. + type = SHOP;
  226. +
  227. +
  228. if( strcmp(w1,"-") == 0 ) {// 'floating' shop?
  229. x = y = dir = 0;
  230. m = -1;
  231. } else {// w1=<map name>,<x>,<y>,<facing>
  232. char mapname[32];
  233. - if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4
  234. - || strchr(w4, ',') == NULL )
  235. - {
  236. - ShowError("npc_parse_shop: Invalid shop definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
  237. - return strchr(start,'\n');// skip and continue
  238. + switch (type){
  239. + case ISHOP:
  240. + if( sscanf(w1, "%31[^,],%d,%d,%d,%d", mapname, &x, &y, &dir,&ishop) != 5
  241. + || strchr(w4, ',') == NULL )
  242. + {
  243. + ShowError("npc_parse_shop: Invalid shop definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
  244. + return strchr(start,'\n');// skip and continue
  245. + }
  246. + break;
  247. + case SHOP:
  248. + case CASHSHOP:
  249. + if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4
  250. + || strchr(w4, ',') == NULL )
  251. + {
  252. + ShowError("npc_parse_shop: Invalid shop definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
  253. + return strchr(start,'\n');// skip and continue
  254. + }
  255. +
  256. + break;
  257. }
  258.  
  259. +
  260. m = map_mapname2mapid(mapname);
  261. }
  262. + if( type == ISHOP && ishop >= 0 && itemdb_exists(ishop) == NULL )
  263. + {
  264. + ShowError("npc_parse_shop: Invalid IShop item in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
  265. + return strchr(start,'\n');
  266. + }
  267.  
  268. if( m != -1 && ( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys ) ) {
  269. ShowError("npc_parse_shop: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d, in file '%s', line '%d'\n", map[m].name, x, y, map[m].xs, map[m].ys,filepath,strline(buffer,start-buffer));
  270. return strchr(start,'\n');;//try next
  271. }
  272. -
  273. - if( !strcasecmp(w2,"cashshop") )
  274. - type = CASHSHOP;
  275. - else
  276. - type = SHOP;
  277.  
  278. p = strchr(w4,',');
  279. for( i = 0; i < ARRAYLENGTH(items) && p; ++i )
  280. @@ -2275,6 +2337,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
  281. ++npc_shop;
  282. nd->bl.type = BL_NPC;
  283. nd->subtype = type;
  284. + nd->ishop = ishop;
  285. if( m >= 0 )
  286. {// normal shop npc
  287. map_addnpc(m,nd);
  288. @@ -2576,7 +2639,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
  289. type = dnd->subtype;
  290.  
  291. // get placement
  292. - if( (type==SHOP || type==CASHSHOP || type==SCRIPT) && strcmp(w1, "-") == 0 )
  293. + if( (type==SHOP || type==CASHSHOP || type==ISHOP || type==SCRIPT) && strcmp(w1, "-") == 0 )
  294. {// floating shop/chashshop/script
  295. x = y = dir = 0;
  296. m = -1;
  297. @@ -2629,6 +2692,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
  298. nd->u.scr.label_list_num = dnd->u.scr.label_list_num;
  299. break;
  300.  
  301. + case ISHOP:
  302. case SHOP:
  303. case CASHSHOP:
  304. ++npc_shop;
  305. @@ -3697,7 +3761,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
  306. {
  307. p = npc_parse_warp(w1,w2,w3,w4, p, buffer, filepath);
  308. }
  309. - else if( (!strcasecmp(w2,"shop") || !strcasecmp(w2,"cashshop")) && count > 3 )
  310. + else if( (!strcasecmp(w2,"shop") || !strcasecmp(w2,"cashshop") || !strcasecmp(w2,"ishop")) && count > 3 )
  311. {
  312. p = npc_parse_shop(w1,w2,w3,w4, p, buffer, filepath);
  313. }
  314. diff --git a/src/map/npc.h b/src/map/npc.h
  315. index 8800b4e..069a195 100644
  316. --- a/src/map/npc.h
  317. +++ b/src/map/npc.h
  318. @@ -37,6 +37,7 @@ struct npc_data {
  319. int touching_id;
  320. unsigned int next_walktime;
  321.  
  322. + int ishop; //ItemShop
  323. unsigned size : 2;
  324.  
  325. struct status_data status;
  326. diff --git a/src/map/script.c b/src/map/script.c
  327. index 76092f4..ca2486d 100644
  328. --- a/src/map/script.c
  329. +++ b/src/map/script.c
  330. @@ -14310,7 +14310,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
  331. if( script_hasdata(st,3) )
  332. flag = script_getnum(st,3);
  333. nd = npc_name2id(shopname);
  334. - if( !nd || nd->bl.type != BL_NPC || (nd->subtype != SHOP && nd->subtype != CASHSHOP) )
  335. + if( !nd || nd->bl.type != BL_NPC || (nd->subtype != SHOP && nd->subtype != CASHSHOP && nd->subtype != ISHOP) )
  336. {
  337. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)\n", shopname);
  338. script_pushint(st,0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement