Fixed 2 bugs in DELITEM script command. [Lupus]

- added deleting priority: If you have some items with the same ID and want to delete some of them, then at first it'll delete common items then, if necessary, delete the rest items but upgraded/named/with cards.


git-svn-id: https://svn.code.sf.net/p/rathena/svn/athena@200 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
Lupus 2004-11-15 23:14:55 +00:00
parent d47ca1e41a
commit c5955bded3
2 changed files with 46 additions and 21 deletions

View File

@ -1,4 +1,11 @@
Date Added
11/16
* Fixed 2 bugs in DELITEM script command. [Lupus]
- added deleting priority: If you have some items with the same ID and want to delete some of them, then
at first it'll delete common items then, if necessary, delete the rest items but upgraded/named/with cards. [Lupus]
Added GM Command Logs & Added TXT Logs + TXT Log Options [Codemaster]
11/15
* Added GM Command Logs & Added TXT Logs + TXT Log Options [Codemaster]
* Added spawning of monsters at specific level by adding ,# after the spawn name. [Valaris]

View File

@ -2458,12 +2458,12 @@ int buildin_makeitem(struct script_state *st)
return 0;
}
/*==========================================
*
* script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
*------------------------------------------
*/
int buildin_delitem(struct script_state *st)
{
int nameid=0,amount,i;
int nameid=0,amount,i,important_item=0;
struct map_session_data *sd;
struct script_data *data;
@ -2487,34 +2487,52 @@ int buildin_delitem(struct script_state *st)
return 0;
}
sd=script_rid2sd(st);
//1st pass
//here we won't delete items with CARDS, named items but we count them
for(i=0;i<MAX_INVENTORY;i++){
//we don't delete wrong item or equipped item
if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
sd->inventory_data[i]->type!=7 ||
sd->status.inventory[i].amount<=0)
sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
continue;
if(sd->status.inventory[i].nameid == nameid){
if(sd->status.inventory[i].card[0] == (short)0xff00){
if(search_petDB_index(nameid, PET_EGG) >= 0){
//1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
intif_delete_petdata(*((long *)(&sd->status.inventory[i].card[1])));
break;
//clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
//now this egg'll be deleted as a common unimportant item
}
//is this item important? does it have cards? or Player's name? or Refined/Upgraded
if( sd->status.inventory[i].card[0] || sd->status.inventory[i].card[1] ||
sd->status.inventory[i].card[2] || sd->status.inventory[i].card[3] || sd->status.inventory[i].refine) {
//this is important item, count it
important_item++;
continue;
}
}
}
for(i=0;i<MAX_INVENTORY;i++){
if(sd->status.inventory[i].nameid==nameid){
if(sd->status.inventory[i].amount>=amount){
pc_delitem(sd,i,amount,0);
break;
return 0; //we deleted exact amount of items. now exit
} else {
amount-=sd->status.inventory[i].amount;
if(amount==0)
amount=sd->status.inventory[i].amount;
pc_delitem(sd,i,amount,0);
break;
pc_delitem(sd,i,sd->status.inventory[i].amount,0);
}
}
//2nd pass
//now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
if (important_item>0 && amount>0)
for(i=0;i<MAX_INVENTORY;i++){
//we don't delete wrong item
if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
continue;
if(sd->status.inventory[i].amount>=amount){
pc_delitem(sd,i,amount,0);
return 0; //we deleted exact amount of items. now exit
} else {
amount-=sd->status.inventory[i].amount;
pc_delitem(sd,i,sd->status.inventory[i].amount,0);
}
}
return 0;