# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/lighta/Documents/Myscript/RO/Servs/ra2 # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: doc/sample/npc_test_chekweight.txt --- doc/sample/npc_test_chekweight.txt No Base Revision +++ doc/sample/npc_test_chekweight.txt Locally New @@ -0,0 +1,94 @@ +//===== rAthena Script ======================================= +//= Sample: ChekWeight +//===== By: ================================================== +//= rAthena Dev Team +//===== Current Version: ===================================== +//= 20121113 +//===== Description: ========================================= +//= Demonstrates ChekWeight commands. +//============================================================ + +new_1-1,56,106,5 script ChkSpace 763,{ + +function ChkResult; +function FinalReport; + +L_RESET: + resetlvl(1); + getinventorylist; + for(set .@i,0; .@i < @inventorylist_count; set .@i,.@i+1){ + delitem(@inventorylist_id[.@i],@inventorylist_amount[.@i]); //clear inventory + } + + +L_TEST1: //basic backward chk + .@testid = 0; + .@succes = 0; + .@ret = checkweight(512,10); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight("Apple",10); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight(6320,33000); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount item weight=0 + .@ret = checkweight("Premium_Reset_Stone",33000); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount + .@ret = checkweight(717,500); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success weight based on max weight=2030 + .@ret = checkweight(717,1000); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure weight based on max weight=2030 + .@ret = checkweight(2794,100); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight(2794,101); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure (with MAX_INVENTORY = 100) + .@ret = checkweight(-1,1); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide item id + .@ret = checkweight(512,0); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide amount + + +L_TEST2: //basic backward chk + .@ret = checkweight(512,10,513,10); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight("Apple",10,"Banana",10); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight(512,80,513,33000); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure + .@ret = checkweight("Apple",80,"Banana",33000); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount + .@ret = checkweight("Apple",10,"Banana",21,512); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalid nb of args + .@ret = checkweight(717,500,716,100); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be succes weight 1800/2030 + .@ret = checkweight(717,500,716,500); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure weight 3000/2030 + .@ret = checkweight(2794,95,2795,5); + set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success + .@ret = checkweight(2794,95,2795,10); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure (with MAX_INVENTORY = 100) + .@ret = checkweight(512,1,-1,1); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide item id + .@ret = checkweight(512,1,513,0); + set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide amount + +L_FINAL: + FinalReport(.@testid,.@succes); + end; + + + function ChkResult { + .@tid = getarg(0); + .@expected = getarg(1); + .@ret = getarg(2); + .@sucess = (.@ret==.@expected); + debugmes "Test "+.@tid+" = "+(.@sucess?"Sucess":"Fail"); + return .@sucess; + } + + function FinalReport { + .@tdone = getarg(0); + .@succes = getarg(1); + debugmes "Results = Pass : "+.@succes+"/"+.@tdone+" Fails : "+(.@tdone-.@succes)+"/"+.@tdone; + if(.@succes != .@tdone) { debugmes "Some failure as occured, enable chkresult print to found out"; } + return; + } +} Index: src/map/script.c --- src/map/script.c Base (BASE) +++ src/map/script.c Locally Modified (Based On LOCAL) @@ -6115,48 +6115,47 @@ *------------------------------------------*/ BUILDIN_FUNC(checkweight) { - int nameid, amount, slots; - unsigned int weight; + int nameid, amount, slots, amount2=0; + unsigned int weight, i, nbargs; struct item_data* id = NULL; struct map_session_data* sd; struct script_data* data; - if( ( sd = script_rid2sd(st) ) == NULL ) - { + if( ( sd = script_rid2sd(st) ) == NULL ){ return 0; } + nbargs = script_lastdata(st)+1; + ShowInfo("nb args = %d\n",nbargs); + if(nbargs%2){ + ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n"); // returns string, regardless of what it was + script_pushint(st,0); + return 1; + } + slots = pc_inventoryblank(sd); //nb of empty slot - data = script_getdata(st,2); + for(i=2; inameid; - amount = script_getnum(st,3); - if( amount < 1 ) - { + amount = script_getnum(st,i+1); + if( amount < 1 ) { ShowError("buildin_checkweight: Invalid amount '%d'.\n", amount); script_pushint(st,0); return 1; } - weight = itemdb_weight(nameid)*amount; - + weight += itemdb_weight(nameid)*amount; //total weight for all chk if( weight + sd->weight > sd->max_weight ) {// too heavy script_pushint(st,0); @@ -6169,20 +6168,16 @@ // item is already in inventory, but there is still space for the requested amount break; case ADDITEM_NEW: - slots = pc_inventoryblank(sd); - - if( itemdb_isstackable(nameid) ) - {// stackable - if( slots < 1 ) - { + if( itemdb_isstackable(nameid) ) {// stackable + amount2++; + if( slots < amount2 ) { script_pushint(st,0); return 0; } } - else - {// non-stackable - if( slots < amount ) - { + else {// non-stackable + amount2 += amount; + if( slots < amount2){ script_pushint(st,0); return 0; } @@ -6192,7 +6187,7 @@ script_pushint(st,0); return 0; } - + } script_pushint(st,1); return 0; } @@ -17145,7 +17145,7 @@ BUILDIN_DEF(rand,"i?"), BUILDIN_DEF(countitem,"v"), BUILDIN_DEF(countitem2,"viiiiiii"), - BUILDIN_DEF(checkweight,"vi"), + BUILDIN_DEF(checkweight,"vi*"), BUILDIN_DEF(readparam,"i?"), BUILDIN_DEF(getcharid,"i?"), BUILDIN_DEF(getnpcid,"i?"),