diff options
author | shennetsind <ind@henn.et> | 2013-11-07 16:04:51 -0200 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-11-07 16:04:51 -0200 |
commit | b9b32ac7609e33c21b488d722103cc0eea16b12c (patch) | |
tree | a2d96930f2f608a14374434e487c1f06ea703728 /src/map/script.c | |
parent | 52864b40d6f9df5682b257ac2f36d645895364be (diff) | |
download | hercules-b9b32ac7609e33c21b488d722103cc0eea16b12c.tar.gz hercules-b9b32ac7609e33c21b488d722103cc0eea16b12c.tar.bz2 hercules-b9b32ac7609e33c21b488d722103cc0eea16b12c.tar.xz hercules-b9b32ac7609e33c21b488d722103cc0eea16b12c.zip |
Item Bound Fixes/Adjustments/Improvements
Special Thanks to Haruna
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 252 |
1 files changed, 60 insertions, 192 deletions
diff --git a/src/map/script.c b/src/map/script.c index 6dce018ef..cf3c3fb50 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3779,6 +3779,17 @@ int script_reload(void) { return 0; } +/* returns name of current function being run, from within the stack [Ind/Hercules] */ +const char *script_getfuncname(struct script_state *st) { + struct script_data *data; + + data = &st->stack->stack_data[st->start]; + + if( data->type == C_NAME && script->str_data[data->u.num].type == C_FUNC ) + return script->get_str(data->u.num); + + return NULL; +} //----------------------------------------------------------------------------- // buildin functions @@ -5763,10 +5774,13 @@ BUILDIN(checkweight2) /*========================================== * getitem <item id>,<amount>{,<account ID>}; * getitem "<item name>",<amount>{,<account ID>}; + * + * getitembound <item id>,<amount>,<type>{,<account ID>}; + * getitembound "<item id>",<amount>,<type>{,<account ID>}; *------------------------------------------*/ BUILDIN(getitem) { - int nameid,amount,get_count,i,flag = 0; + int nameid,amount,get_count,i,flag = 0, offset = 0; struct item it; TBL_PC *sd; struct script_data *data; @@ -5778,7 +5792,7 @@ BUILDIN(getitem) {// "<item name>" const char *name=script->conv_str(st,data); if( (item_data = itemdb->search_name(name)) == NULL ){ - ShowError("buildin_getitem: Nonexistant item %s requested.\n", name); + ShowError("buildin_%s: Nonexistant item %s requested.\n", script->getfuncname(st), name); return false; //No item created. } nameid=item_data->nameid; @@ -5790,11 +5804,11 @@ BUILDIN(getitem) flag = 1; } if( nameid <= 0 || !(item_data = itemdb->exists(nameid)) ){ - ShowError("buildin_getitem: Nonexistant item %d requested.\n", nameid); + ShowError("buildin_%s: Nonexistant item %d requested.\n", script->getfuncname(st), nameid); return false; //No item created. } } else { - ShowError("buildin_getitem: invalid data type for argument #1 (%d).", data->type); + ShowError("buildin_%s: invalid data type for argument #1 (%d).", script->getfuncname(st), data->type); return false; } @@ -5804,13 +5818,28 @@ BUILDIN(getitem) memset(&it,0,sizeof(it)); it.nameid=nameid; + if(!flag) it.identify=1; else it.identify=itemdb->isidentified2(item_data); - if( script_hasdata(st,4) ) - sd=map->id2sd(script_getnum(st,4)); // <Account ID> + if( !strcmp(script->getfuncname(st),"getitembound") ) { + int bound = script_getnum(st,4); + if( bound < IBT_MIN || bound > IBT_MAX ) { //Not a correct bound type + ShowError("script_getitembound: Not a correct bound type! Type=%d\n",bound); + return false; + } + if( item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR ) { + ShowError("script_getitembound: can't bind a pet egg/armor!\n",bound); + return false; + } + it.bound = (unsigned char)bound; + offset += 1; + } + + if( script_hasdata(st,4+offset) ) + sd=map->id2sd(script_getnum(st,4+offset)); // <Account ID> else sd=script->rid2sd(st); // Attached player @@ -5842,15 +5871,24 @@ BUILDIN(getitem) *------------------------------------------*/ BUILDIN(getitem2) { - int nameid,amount,get_count,i,flag = 0; - int iden,ref,attr,c1,c2,c3,c4; + int nameid,amount,get_count,i,flag = 0, offset = 0; + int iden,ref,attr,c1,c2,c3,c4, bound = 0; struct item_data *item_data; struct item item_tmp; TBL_PC *sd; struct script_data *data; - if( script_hasdata(st,11) ) - sd=map->id2sd(script_getnum(st,11)); // <Account ID> + if( !strcmp(script->getfuncname(st),"getitembound2") ) { + bound = script_getnum(st,11); + if( bound < IBT_MIN || bound > IBT_MAX ) { //Not a correct bound type + ShowError("script_getitembound2: Not a correct bound type! Type=%d\n",bound); + return false; + } + offset += 1; + } + + if( script_hasdata(st,11+offset) ) + sd=map->id2sd(script_getnum(st,11+offset)); // <Account ID> else sd=script->rid2sd(st); // Attached player @@ -5878,6 +5916,11 @@ BUILDIN(getitem2) c3=(short)script_getnum(st,9); c4=(short)script_getnum(st,10); + if( bound && (itemdb_type(nameid) == IT_PETEGG || itemdb_type(nameid) == IT_PETARMOR) ) { + ShowError("script_getitembound2: can't bind a pet egg/armor!\n",bound); + return false; + } + if(nameid<0) { // Invalide nameid nameid = -nameid; flag = 1; @@ -5907,6 +5950,7 @@ BUILDIN(getitem2) item_tmp.identify=0; item_tmp.refine=ref; item_tmp.attribute=attr; + item_tmp.bound=(unsigned char)bound; item_tmp.card[0]=(short)c1; item_tmp.card[1]=(short)c2; item_tmp.card[2]=(short)c3; @@ -17562,185 +17606,6 @@ BUILDIN(bg_join_team) { return true; } - -/*==============[Mhalicot]================== - * getitembound <item id>,<amount>,<type>{,<account ID>}; - * getitembound "<item id>",<amount>,<type>{,<account ID>}; - * Type: - * 1 - Account Bound - * 2 - Guild Bound - * 3 - Party Bound - * 4 - Character Bound - *------------------------------------------*/ -BUILDIN(getitembound) -{ - int nameid, amount, i, flag; - struct item it; - struct script_data *data; - char bound = script_getnum(st,4); - TBL_PC *sd; - - data = script_getdata(st,2); - get_val(st,data); - if( data_isstring(data) ) { // "<item name>" - const char *name = script->conv_str(st,data); - struct item_data *item_data = itemdb->search_name(name); - if( item_data == NULL ) { - ShowError("buildin_getitembound: Nonexistant item %s requested.\n", name); - return 1; //No item created. - } - nameid = item_data->nameid; - } else if( data_isint(data) ) { // <item id> - nameid = script->conv_num(st,data); - if( nameid <= 0 || !itemdb->exists(nameid) ) { - ShowError("buildin_getitembound: Nonexistant item %d requested.\n", nameid); - return 1; //No item created. - } - } else { - ShowError("buildin_getitembound: invalid data type for argument #1 (%d).", data->type); - return 1; - } - - if( itemdb->isstackable(nameid) || itemdb_type(nameid) == IT_PETEGG ) { - ShowError("buildin_getitembound: invalid item type. Bound only work for non stackeable items (Item %d).", nameid); - return 1; - } - - if( (amount = script_getnum(st,3)) <= 0) - return 0; //return if amount <=0, skip the useless iteration - - memset(&it,0,sizeof(it)); - it.nameid = nameid; - it.identify = 1; - it.bound = bound; - - if( bound < 1 || bound > 4) { //Not a correct bound type - ShowError("script_getitembound: Not a correct bound type! Type=%d\n",bound); - return 1; - } - - if( script_hasdata(st,5) ) - sd=map->id2sd(script_getnum(st,5)); // Account ID - else - sd=script->rid2sd(st); // Attached player - - if( sd == NULL ) // no target - return 0; - - for( i = 0; i < amount; i++ ) { - if( (flag = pc->additem(sd, &it, 1, LOG_TYPE_SCRIPT)) ) { - clif->additem(sd, 0, 0, flag); - if( pc->candrop(sd,&it) ) - map->addflooritem(&it,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); - } - } - - return 0; -} - -/*==============[Mhalicot]================== - * getitembound2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>,<bound type>; - * getitembound2 "<item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>,<bound type>; - *------------------------------------------*/ -BUILDIN(getitembound2) -{ - int nameid,amount,get_count,i,flag = 0; - int iden,ref,attr,c1,c2,c3,c4; - char bound=0; - struct item_data *item_data; - struct item item_tmp; - TBL_PC *sd; - struct script_data *data; - - bound = script_getnum(st,11); - if( bound < 1 || bound > 4) { //Not a correct bound type - ShowError("script_getitembound2: Not a correct bound type! Type=%d\n",bound); - return 1; - } - if( script_hasdata(st,12) ) - sd=map->id2sd(script_getnum(st,12)); - else - sd=script->rid2sd(st); // Attached player - - if( sd == NULL ) // no target - return true; - - data=script_getdata(st,2); - script->get_val(st,data); - if( data_isstring(data) ){ - const char *name=script->conv_str(st,data); - struct item_data *item_data = itemdb->search_name(name); - if( item_data ) - nameid=item_data->nameid; - else - nameid=UNKNOWN_ITEM_ID; - }else - nameid=script->conv_num(st,data); - - amount=script_getnum(st,3); - iden=script_getnum(st,4); - ref=script_getnum(st,5); - attr=script_getnum(st,6); - c1=(short)script_getnum(st,7); - c2=(short)script_getnum(st,8); - c3=(short)script_getnum(st,9); - c4=(short)script_getnum(st,10); - - if(nameid<0) { // Invalide nameid - nameid = -nameid; - flag = 1; - } - - if(nameid > 0) { - memset(&item_tmp,0,sizeof(item_tmp)); - item_data=itemdb->exists(nameid); - if (item_data == NULL) - return -1; - if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR){ - if(ref > MAX_REFINE) ref = MAX_REFINE; - } - else if(item_data->type==IT_PETEGG) { - iden = 1; - ref = 0; - } - else { - iden = 1; - ref = attr = 0; - } - - item_tmp.nameid=nameid; - if(!flag) - item_tmp.identify=iden; - else if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR) - item_tmp.identify=0; - item_tmp.refine=ref; - item_tmp.attribute=attr; - item_tmp.card[0]=(short)c1; - item_tmp.card[1]=(short)c2; - item_tmp.card[2]=(short)c3; - item_tmp.card[3]=(short)c4; - item_tmp.bound=bound; - - //Check if it's stackable. - if (!itemdb->isstackable(nameid)) - get_count = 1; - else - get_count = amount; - - for (i = 0; i < amount; i += get_count) { - // if not pet egg - if (!pet->create_egg(sd, nameid)) { - if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { - clif->additem(sd, 0, 0, flag); - if( pc->candrop(sd,&item_tmp) ) - map->addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); - } - } - } - } - - return true; -} /*==============[Mhalicot]================== * countbound {<type>}; * Creates an array of bounded item IDs @@ -17749,6 +17614,7 @@ BUILDIN(getitembound2) * 1 - Account Bound * 2 - Guild Bound * 3 - Party Bound + * 4 - Character Bound *------------------------------------------*/ BUILDIN(countbound) { @@ -18355,11 +18221,12 @@ void script_parse_builtin(void) { BUILDIN_DEF(bindatcmd, "ss???"), BUILDIN_DEF(unbindatcmd, "s"), BUILDIN_DEF(useatcmd, "s"), + /** - * Item bound [Mhalicot\Hercules] + * Item bound [Xantara] [Akinari] [Mhalicot/Hercules] **/ - BUILDIN_DEF(getitembound,"vii?"), - BUILDIN_DEF(getitembound2,"viiiiiiiii?"), + BUILDIN_DEF2(getitem,"getitembound","vii?"), + BUILDIN_DEF2(getitem2,"getitembound2","viiiiiiiii?"), BUILDIN_DEF(countbound, "?"), //Quest Log System [Inkfish] @@ -18652,6 +18519,7 @@ void script_defaults(void) { script->buildin_mobuseskill_sub = buildin_mobuseskill_sub; script->cleanfloor_sub = script_cleanfloor_sub; script->run_func = run_func; + script->getfuncname = script_getfuncname; /* script_config base */ script->config.warn_func_mismatch_argtypes = 1; |