/*==========================================
* inv2stor,item_id,item_nb,attribute,refine,identify,c0,c1,c2,c3{,charid} [Lighta]
* interface pour pour la fonction de storage storage_storageadd
* transferant un item de l'inventaire au storage
* return
* -1 : invalid item
* 0 : fail
* 1 : success
*------------------------------------------*/
BUILDIN_FUNC(inv2stor) {
TBL_PC * sd = ((script_hasdata(st, 11)) ? map_id2sd(script_getnum(st, 11)) : script_rid2sd(st));
int i, j, ok=0;
struct item_data* item_data;
struct item tmp_it;
int item_id = script_getnum(st, 2);
int item_nb = script_getnum(st, 3);
int item_add=0;
nullpo_ret(sd);
if ((item_data = itemdb_exists(item_id)) != NULL) {
tmp_it.nameid = item_data->nameid;
tmp_it.identify = script_getnum(st, 4);
tmp_it.refine = script_getnum(st, 5);
tmp_it.attribute = script_getnum(st, 6);
tmp_it.card[0] = script_getnum(st, 7);
tmp_it.card[1] = script_getnum(st, 8);
tmp_it.card[2] = script_getnum(st, 9);
tmp_it.card[3] = script_getnum(st, 10);
if(!itemdb_isstackable2(item_data)){
item_add = 1;
}
else
item_add = item_nb;
for(j=0; j<item_nb; j+=item_add){
ARR_FIND(0, MAX_INVENTORY, i, ((&sd->status.inventory[i] != NULL)
&& compare_item(&sd->status.inventory[i], &tmp_it, 1)));
if (i < MAX_INVENTORY) ok = storage_storageadd(sd, i, item_add);
}
script_pushint(st, ok);
storage_storageclose(sd);
return ok;
}
script_pushint(st, -1);
return 0;
}
/* =========================================
* getStorageItem2 <item id>,<amount>,,<refine>,<attribut>,<c1>,<c2>,<c3>,<c3>{,<account ID>};
* getStorageItem2 "<item name>",<amount>,,<refine>,<attribut>,<c1>,<c2>,<c3>,<c3>{,<account ID>};
* [Lighta]
* ----------------------------------------- */
BUILDIN_FUNC(getstorageitem2){
TBL_PC * sd;
int nameid=0,amount,i;
int ref,attr,c1,c2,c3,c4;
struct script_data *data;
struct item_data * item_data;
struct item item_tmp;
data=script_getdata(st,2);
amount=script_getnum(st,3);
ref=script_getnum(st,4);
attr=script_getnum(st,5);
c1=(short)script_getnum(st,6);
c2=(short)script_getnum(st,7);
c3=(short)script_getnum(st,8);
c4=(short)script_getnum(st,9);
if( script_hasdata(st,10) )
sd=map_id2sd(script_getnum(st,10)); // <Account ID>
else
sd=script_rid2sd(st); // Attached player
if( sd == NULL ) // no target
return 0;
item_data = script_data2nameid(st,data);
if(item_data != NULL && sd != NULL){
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) {
ref = 0;
}
else {
ref = attr = 0;
}
memset(&item_tmp,0,sizeof(item_tmp));
item_tmp.nameid=nameid;
item_tmp.identify = 1;
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;
if(amount <= 0 || (!itemdb_isstackable2(item_data) && amount > 10) || (itemdb_isstackable2(item_data) && amount > MAX_AMOUNT))
amount = 1;
if(!itemdb_isstackable2(item_data) && amount > 1){
for(i = 0; i < amount; i++)
storage_additem2(sd,&item_tmp,amount);
} else {
storage_additem2(sd,&item_tmp,amount);
clif_storageclose(sd);
sd->state.storage_flag = 0;
}
log_pick_pc(sd, LOG_TYPE_NPC, amount, &item_tmp);
}
return 0;
}