diff options
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 1521 |
1 files changed, 1092 insertions, 429 deletions
diff --git a/src/map/script.c b/src/map/script.c index b787d0138..5843ac292 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -52,6 +52,7 @@ #include "map/pet.h" #include "map/pet.h" #include "map/quest.h" +#include "map/refine.h" #include "map/skill.h" #include "map/status.h" #include "map/status.h" @@ -3316,95 +3317,28 @@ static void set_reg_npcscope_str(struct script_state *st, struct reg_db *n, int6 static void set_reg_pc_ref_str(struct script_state *st, struct reg_db *n, int64 num, const char *name, const char *str) { - struct script_reg_str *p = NULL; - unsigned int index = script_getvaridx(num); - - nullpo_retv(n); - - if ((p = i64db_get(n->vars, num)) != NULL) { - if (str[0]) { - if (p->value) { - aFree(p->value); - } else if (index) { - script->array_update(n, num, false); - } - p->value = aStrdup(str); - } else { - p->value = NULL; - if (index) { - script->array_update(n, num, true); - } - } + struct DBIterator *iter = db_iterator(map->pc_db); - if (!pc->reg_load) { - p->flag.update = 1; - } - } else if (str[0]) { - struct DBData prev; - if (index) { - script->array_update(n, num, false); - } - - p = ers_alloc(pc->str_reg_ers, struct script_reg_str); - p->value = aStrdup(str); - - if (!pc->reg_load) { - p->flag.update = 1; - } - p->flag.type = 1; - - if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) { - p = DB->data2ptr(&prev); - if (p->value) { - aFree(p->value); - } - ers_free(pc->str_reg_ers, p); + for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { + if (sd != NULL && n == &sd->regs) { + pc->setregistry_str(sd, num, str); + break; } } + dbi_destroy(iter); } static void set_reg_pc_ref_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val) { - struct script_reg_num *p = NULL; - unsigned int index = script_getvaridx(num); - - nullpo_retv(n); - - if ((p = i64db_get(n->vars, num)) != NULL) { - if (val) { - if (!p->value && index) { - script->array_update(n, num, false); - } - p->value = val; - } else { - p->value = 0; - if (index) { - script->array_update(n, num, true); - } - } - - if (!pc->reg_load) { - p->flag.update = 1; - } - } else if (val) { - struct DBData prev; - if (index) { - script->array_update(n, num, false); - } - - p = ers_alloc(pc->num_reg_ers, struct script_reg_num); - p->value = val; - - if (!pc->reg_load) { - p->flag.update = 1; - } - p->flag.type = 1; + struct DBIterator *iter = db_iterator(map->pc_db); - if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) { - p = DB->data2ptr(&prev); - ers_free(pc->num_reg_ers, p); + for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { + if (sd != NULL && n == &sd->regs) { + pc->setregistry(sd, num, val); + break; } } + dbi_destroy(iter); } static void set_reg_npcscope_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val) @@ -4688,6 +4622,9 @@ static void run_script_main(struct script_state *st) nullpo_retv(st); script->attach_state(st); + if (st->state != END && Assert_chk(st->state == RUN || st->state == STOP || st->state == RERUNLINE)) { + st->state = END; + } nd = map->id2nd(st->oid); if( nd && nd->bl.m >= 0 ) @@ -6166,11 +6103,11 @@ static BUILDIN(menu) sd->state.menu_or_input = 1; /* menus beyond this length crash the client (see bugreport:6402) */ - if( StrBuf->Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= MAX_MENU_LENGTH - 1 ) { struct npc_data * nd = map->id2nd(st->oid); char* menu; - CREATE(menu, char, 2048); - safestrncpy(menu, StrBuf->Value(&buf), 2047); + CREATE(menu, char, MAX_MENU_LENGTH); + safestrncpy(menu, StrBuf->Value(&buf), MAX_MENU_LENGTH - 1); ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); @@ -6179,13 +6116,13 @@ static BUILDIN(menu) StrBuf->Destroy(&buf); - if( sd->npc_menu >= 0xff ) + if( sd->npc_menu >= MAX_MENU_OPTIONS ) {// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow - ShowWarning("buildin_menu: Too many options specified (current=%d, max=254).\n", sd->npc_menu); + ShowWarning("buildin_menu: Too many options specified (current=%d, max=%d).\n", sd->npc_menu, MAX_MENU_OPTIONS - 1); script->reportsrc(st); } } - else if( sd->npc_menu == 0xff ) + else if( sd->npc_menu == MAX_MENU_OPTIONS ) {// Cancel was pressed sd->state.menu_or_input = 0; st->state = END; @@ -6267,11 +6204,11 @@ static BUILDIN(select) sd->state.menu_or_input = 1; /* menus beyond this length crash the client (see bugreport:6402) */ - if( StrBuf->Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= MAX_MENU_LENGTH - 1 ) { struct npc_data * nd = map->id2nd(st->oid); char* menu; - CREATE(menu, char, 2048); - safestrncpy(menu, StrBuf->Value(&buf), 2047); + CREATE(menu, char, MAX_MENU_LENGTH); + safestrncpy(menu, StrBuf->Value(&buf), MAX_MENU_LENGTH - 1); ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); @@ -6279,107 +6216,31 @@ static BUILDIN(select) clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); StrBuf->Destroy(&buf); - if( sd->npc_menu >= 0xff ) { - ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); + if( sd->npc_menu >= MAX_MENU_OPTIONS ) { + ShowWarning("buildin_select: Too many options specified (current=%d, max=%d).\n", sd->npc_menu, MAX_MENU_OPTIONS - 1); script->reportsrc(st); } - } else if( sd->npc_menu == 0xff ) {// Cancel was pressed - sd->state.menu_or_input = 0; - st->state = END; - } else {// return selected option - int menu = 0; - + } else if(sd->npc_menu == MAX_MENU_OPTIONS) { // Cancel was pressed sd->state.menu_or_input = 0; - for( i = 2; i <= script_lastdata(st); ++i ) { - text = script_getstr(st, i); - sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu); - if( sd->npc_menu <= 0 ) - break;// entry found - } - pc->setreg(sd, script->add_variable("@menu"), menu); - script_pushint(st, menu); - st->state = RUN; - } - return true; -} - -/// Displays a menu with options and returns the selected option. -/// Behaves like 'menu' without the target labels, except when cancel is -/// pressed. -/// When cancel is pressed, the script continues and 255 is returned. -/// -/// prompt(<option_text>{,<option_text>,...}) -> <selected_option> -/// -/// @see menu -static BUILDIN(prompt) -{ - int i; - const char *text; - struct map_session_data *sd = script->rid2sd(st); - if (sd == NULL) - return true; - -#ifdef SECURE_NPCTIMEOUT - sd->npc_idle_type = NPCT_MENU; -#endif - - if( sd->state.menu_or_input == 0 ) - { - struct StringBuf buf; - - StrBuf->Init(&buf); - sd->npc_menu = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { - text = script_getstr(st, i); - if( sd->npc_menu > 0 ) - StrBuf->AppendStr(&buf, ":"); - StrBuf->AppendStr(&buf, text); - sd->npc_menu += script->menu_countoptions(text, 0, NULL); - } - - st->state = RERUNLINE; - sd->state.menu_or_input = 1; - /* menus beyond this length crash the client (see bugreport:6402) */ - if( StrBuf->Length(&buf) >= 2047 ) { - struct npc_data * nd = map->id2nd(st->oid); - char* menu; - CREATE(menu, char, 2048); - safestrncpy(menu, StrBuf->Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); - clif->scriptmenu(sd, st->oid, menu); - aFree(menu); - } else - clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); - StrBuf->Destroy(&buf); - - if( sd->npc_menu >= 0xff ) - { - ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu); - script->reportsrc(st); + if (strncmp(get_buildin_name(st), "prompt", 6) == 0) { + pc->setreg(sd, script->add_variable("@menu"), MAX_MENU_OPTIONS); + script_pushint(st, MAX_MENU_OPTIONS); // XXX: we should really be pushing -1 instead + st->state = RUN; + } else { + st->state = END; } - } - else if( sd->npc_menu == 0xff ) - {// Cancel was pressed - sd->state.menu_or_input = 0; - pc->setreg(sd, script->add_variable("@menu"), 0xff); - script_pushint(st, 0xff); - st->state = RUN; - } - else - {// return selected option + } else {// return selected option int menu = 0; sd->state.menu_or_input = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { + for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu); if( sd->npc_menu <= 0 ) break;// entry found } - pc->setreg(sd, script->add_variable("@menu"), menu); + pc->setreg(sd, script->add_variable("@menu"), menu); // TODO: throw a deprecation warning for scripts using @menu script_pushint(st, menu); st->state = RUN; } @@ -6998,7 +6859,7 @@ static BUILDIN(heal) hp=script_getnum(st,2); sp=script_getnum(st,3); - status->heal(&sd->bl, hp, sp, 1); + status->heal(&sd->bl, hp, sp, STATUS_HEAL_FORCED); return true; } /*========================================== @@ -7696,7 +7557,6 @@ static BUILDIN(viewpoint) *------------------------------------------*/ static BUILDIN(countitem) { - int nameid, i; int count = 0; struct item_data* id = NULL; @@ -7718,11 +7578,12 @@ static BUILDIN(countitem) return false; } - nameid = id->nameid; + int nameid = id->nameid; - for(i = 0; i < MAX_INVENTORY; i++) - if(sd->status.inventory[i].nameid == nameid) + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].nameid == nameid) count += sd->status.inventory[i].amount; + } script_pushint(st,count); return true; @@ -7736,7 +7597,6 @@ static BUILDIN(countitem2) { int nameid, iden, ref, attr, c1, c2, c3, c4; int count = 0; - int i; struct item_data* id = NULL; struct map_session_data *sd = script->rid2sd(st); @@ -7766,7 +7626,7 @@ static BUILDIN(countitem2) c3 = script_getnum(st,8); c4 = script_getnum(st,9); - for(i = 0; i < MAX_INVENTORY; i++) + for (int i = 0; i < sd->status.inventorySize; i++) if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] != NULL && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].identify == iden && sd->status.inventory[i].refine == ref && @@ -7781,6 +7641,65 @@ static BUILDIN(countitem2) } /*========================================== + * countnameditem(item ID, { <Char Name / ID> }) + * returns number of named items. + *------------------------------------------*/ +static BUILDIN(countnameditem) +{ + int count = 0; + struct item_data* id = NULL; + struct map_session_data *sd; + + if (script_hasdata(st, 3)) { + if (script_isstringtype(st, 3)) { + // Character name was given + sd = script->nick2sd(st, script_getstr(st, 3)); + } else { + // Character ID was given + sd = script->charid2sd(st, script_getnum(st, 3)); + } + } else { + // Use RID by default if no name was provided + sd = script->rid2sd(st); + } + + // Player not attached + if (sd == NULL) { + return true; + } + + if (script_isstringtype(st, 2)) { + // Get item from DB via item name + id = itemdb->search_name(script_getstr(st, 2)); + } else { + // Get item from DB via item ID + id = itemdb->exists(script_getnum(st, 2)); + } + + if (id == NULL) { + ShowError("buildin_countnameditem: Invalid item '%s'.\n", script_getstr(st, 2)); // returns string, regardless of what it was + script_pushint(st, 0); + return false; + } + + for (int i = 0; i < MAX_INVENTORY; i++) { + if (sd->status.inventory[i].nameid > 0 && + sd->inventory_data[i] != NULL && + sd->status.inventory[i].amount > 0 && + sd->status.inventory[i].nameid == id->nameid && + sd->status.inventory[i].card[0] == CARD0_CREATE && + sd->status.inventory[i].card[2] == sd->status.char_id && + sd->status.inventory[i].card[3] == sd->status.char_id >> 16) + { + count += sd->status.inventory[i].amount; + } + } + + script_pushint(st, count); + return true; +} + +/*========================================== * Check if item with this amount can fit in inventory * Checking : weight, stack amount >32k, slots amount >(MAX_INVENTORY) * Return @@ -8259,12 +8178,12 @@ static BUILDIN(getnameditem) } memset(&item_tmp,0,sizeof(item_tmp)); - item_tmp.nameid=nameid; - item_tmp.amount=1; - item_tmp.identify=1; - item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus] - item_tmp.card[2]=tsd->status.char_id; - item_tmp.card[3]=tsd->status.char_id >> 16; + item_tmp.nameid = nameid; + item_tmp.amount = 1; + item_tmp.identify = 1; + item_tmp.card[0] = CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus] + item_tmp.card[2] = GetWord(tsd->status.char_id, 0); + item_tmp.card[3] = GetWord(tsd->status.char_id, 1); if(pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) { script_pushint(st,0); return true; //Failed to add item, we will not drop if they don't fit @@ -8841,32 +8760,23 @@ static BUILDIN(getcharid) return true; } + /*========================================== * returns the GID of an NPC *------------------------------------------*/ static BUILDIN(getnpcid) { - int num = script_getnum(st,2); - struct npc_data* nd = NULL; - - if( script_hasdata(st,3) ) - {// unique npc name - if( ( nd = npc->name2id(script_getstr(st,3)) ) == NULL ) - { - ShowError("buildin_getnpcid: No such NPC '%s'.\n", script_getstr(st,3)); - script_pushint(st,0); - return false; + if (script_hasdata(st, 2)) { + if (script_isinttype(st, 2)) { + // Deprecate old form - getnpcid(<type>{, <"npc name">}) + ShowWarning("buildin_getnpcid: Use of type is deprecated. Format - getnpcid({<\"npc name\">})\n"); + script_pushint(st, 0); + } else { + struct npc_data *nd = npc->name2id(script_getstr(st, 2)); + script_pushint(st, (nd != NULL) ? nd->bl.id : 0); } - } - - switch (num) { - case 0: - script_pushint(st,nd ? nd->bl.id : st->oid); - break; - default: - ShowError("buildin_getnpcid: invalid parameter (%d).\n", num); - script_pushint(st,0); - return false; + } else { + script_pushint(st, st->oid); } return true; @@ -9300,13 +9210,13 @@ static BUILDIN(getequipname) *------------------------------------------*/ static BUILDIN(getbrokenid) { - int i,num,id=0,brokencounter=0; + int num,id=0,brokencounter=0; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; num=script_getnum(st,2); - for(i=0; i<MAX_INVENTORY; i++) { + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].card[0] == CARD0_PET) continue; if ((sd->status.inventory[i].attribute & ATTR_BROKEN) != 0) { @@ -9333,7 +9243,7 @@ static BUILDIN(getbrokencount) if (sd == NULL) return true; - for (i = 0; i < MAX_INVENTORY; i++) { + for (i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].card[0] == CARD0_PET) continue; if ((sd->status.inventory[i].attribute & ATTR_BROKEN) != 0) @@ -9350,14 +9260,13 @@ static BUILDIN(getbrokencount) *------------------------------------------*/ static BUILDIN(repair) { - int i,num; int repaircounter=0; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; - num=script_getnum(st,2); - for(i=0; i<MAX_INVENTORY; i++) { + int num = script_getnum(st, 2); + for(int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].card[0] == CARD0_PET) continue; if ((sd->status.inventory[i].attribute & ATTR_BROKEN) != 0) { @@ -9381,12 +9290,12 @@ static BUILDIN(repair) *------------------------------------------*/ static BUILDIN(repairall) { - int i, repaircounter = 0; + int repaircounter = 0; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; - for(i = 0; i < MAX_INVENTORY; i++) + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].card[0] == CARD0_PET) continue; @@ -9597,7 +9506,7 @@ static BUILDIN(getequippercentrefinery) if (i >= 0 && sd->status.inventory[i].nameid != 0 && sd->status.inventory[i].refine < MAX_REFINE) script_pushint(st, - status->get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int) sd->status.inventory[i].refine, (enum refine_chance_type) type)); + refine->get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int) sd->status.inventory[i].refine, (enum refine_chance_type) type)); else script_pushint(st, 0); @@ -9809,6 +9718,25 @@ static BUILDIN(statusup2) return true; } + +/*========================================== +* Returns the number of stat points needed to change the specified stat by val. +* needed_status_point(<type>,<val>); [secretdataz] +*------------------------------------------*/ +static BUILDIN(needed_status_point) +{ + int type = script_getnum(st, 2); + int val = script_getnum(st, 3);; + struct map_session_data *sd = script->rid2sd(st); + + if (sd == NULL) + script_pushint(st, 0); + else + script_pushint(st, pc->need_status_point(sd, type, val)); + + return true; +} + /// See 'doc/item_bonus.txt' /// /// bonus <bonus type>,<val1>; @@ -10677,24 +10605,36 @@ static BUILDIN(gettime) return true; } -/*========================================== +/* * GetTimeStr("TimeFMT", Length); - *------------------------------------------*/ + */ static BUILDIN(gettimestr) { char *tmpstr; const char *fmtstr; int maxlen; - time_t now = time(NULL); + time_t now; + + fmtstr = script_getstr(st, 2); + maxlen = script_getnum(st, 3); + + if (script_hasdata(st, 4)) { + int timestamp = script_getnum(st, 4); + if (timestamp < 0) { + ShowWarning("buildin_gettimestr: UNIX timestamp must be in positive value.\n"); + return false; + } - fmtstr=script_getstr(st,2); - maxlen=script_getnum(st,3); + now = (time_t)timestamp; + } else { + now = time(NULL); + } - tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char)); - strftime(tmpstr,maxlen,fmtstr,localtime(&now)); - tmpstr[maxlen]='\0'; + tmpstr = (char *)aMalloc((maxlen +1)*sizeof(char)); + strftime(tmpstr, maxlen, fmtstr, localtime(&now)); + tmpstr[maxlen] = '\0'; - script_pushstr(st,tmpstr); + script_pushstr(st, tmpstr); return true; } @@ -10806,7 +10746,7 @@ static BUILDIN(makepet) if (pet_id >= 0 && sd) { sd->catch_target_class = pet->db[pet_id].class_; intif->create_pet(sd->status.account_id, sd->status.char_id, - (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv, + pet->db[pet_id].class_, mob->db(pet->db[pet_id].class_)->lv, pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate, 100, 0, 1, pet->db[pet_id].jname); } @@ -11168,6 +11108,21 @@ static BUILDIN(killmonsterall) return true; } +static BUILDIN(killmonstergid) +{ + int mobgid = script_getnum(st, 2); + struct mob_data *md = map->id2md(mobgid); + + if (md == NULL) { + ShowWarning("buildin_killmonstergid: Error in finding monster GID '%d' or the target is not a monster.\n", mobgid); + return false; + } + + md->state.npc_killmonster = 1; + status_kill(&md->bl); + return true; +} + /*========================================== * Creates a clone of a player. * clone map, x, y, event, char_id, master_id, mode, flag, duration @@ -11443,7 +11398,7 @@ static int buildin_getunits_sub(struct block_list *bl, va_list ap) (const void *)h64BPTRSIZE(bl->id), ref); (*count)++; - return 0; + return 1; } static int buildin_getunits_sub_pc(struct map_session_data *sd, va_list ap) @@ -11515,18 +11470,10 @@ static BUILDIN(getunits) int16 x2 = script_getnum(st, 8); int16 y2 = script_getnum(st, 9); - // FIXME: map_foreachinarea does NOT stop iterating when the callback - // function returns -1. we still limit the array size, but - // this doesn't break the loop. We need a foreach function - // that behaves like map_foreachiddb, but for areas - map->foreachinarea(buildin_getunits_sub, m, x1, y1, x2, y2, type, + map->forcountinarea(buildin_getunits_sub, m, x1, y1, x2, y2, limit, type, st, sd, id, start, &count, limit, name, ref, type); } else { - // FIXME: map_foreachinmap does NOT stop iterating when the callback - // function returns -1. we still limit the array size, but - // this doesn't break the loop. We need a foreach function - // that behaves like map_foreachiddb, but for maps - map->foreachinmap(buildin_getunits_sub, m, type, + map->forcountinmap(buildin_getunits_sub, m, limit, type, st, sd, id, start, &count, limit, name, ref, type); } } else { @@ -11811,6 +11758,18 @@ static BUILDIN(playerattached) } /*========================================== + * Used by OnTouchNPC: label to return monster GID + *------------------------------------------*/ +static BUILDIN(mobattached) +{ + if (st->rid == 0 || map->id2md(st->rid) == NULL) + script_pushint(st, 0); + else + script_pushint(st, st->rid); + return true; +} + +/*========================================== *------------------------------------------*/ static BUILDIN(announce) { @@ -12335,7 +12294,9 @@ static BUILDIN(sc_end) } //This should help status_change_end force disabling the SC in case it has no limit. - sce->val1 = sce->val2 = sce->val3 = sce->val4 = 0; + if (type != SC_BERSERK) + sce->val1 = 0; // SC_BERSERK requires skill_lv that's stored in sce->val1 when being removed [KirieZ] + sce->val2 = sce->val3 = sce->val4 = 0; status_change_end(bl, (sc_type)type, INVALID_TIMER); } else @@ -14480,6 +14441,9 @@ static BUILDIN(getiteminfo) case ITEMINFO_VIEWSPRITE: script_pushint(st, it->view_sprite); break; + case ITEMINFO_TRADE: + script_pushint(st, it->flag.trade_restriction); + break; default: ShowError("buildin_getiteminfo: Invalid item type %d.\n", n); script_pushint(st,-1); @@ -14746,6 +14710,9 @@ static BUILDIN(setiteminfo) case ITEMINFO_VIEWSPRITE: it->view_sprite = value; break; + case ITEMINFO_TRADE: + it->flag.trade_restriction = value; + break; default: ShowError("buildin_setiteminfo: invalid type %d.\n", n); script_pushint(st,-1); @@ -14866,47 +14833,55 @@ static BUILDIN(petloot) * Set arrays with info of all sd inventory : * @inventorylist_id, @inventorylist_amount, @inventorylist_equip, * @inventorylist_refine, @inventorylist_identify, @inventorylist_attribute, - * @inventorylist_card(0..3), @inventorylist_expire + * @inventorylist_card(0..3), + * @inventorylist_opt_id(0..MAX_ITEM_OPTIONS), + * @inventorylist_opt_val(0..MAX_ITEM_OPTIONS), + * @inventorylist_opt_param(0..MAX_ITEM_OPTIONS), + * @inventorylist_expire, @inventorylist_bound, @inventorylist_favorite, + * @inventorylist_idx * @inventorylist_count = scalar *------------------------------------------*/ static BUILDIN(getinventorylist) { struct map_session_data *sd = script->rid2sd(st); - char card_var[SCRIPT_VARNAME_LENGTH]; + char script_var[SCRIPT_VARNAME_LENGTH]; + int j = 0, k = 0; - int i,j=0,k; - if(!sd) return true; + if (sd == NULL) + return true; - for(i=0;i<MAX_INVENTORY;i++) { - if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0) { - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_id"), j),sd->status.inventory[i].nameid); - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_amount"), j),sd->status.inventory[i].amount); - if(sd->status.inventory[i].equip) { - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_equip"), j),pc->equippoint(sd,i)); + for (int i = 0; i < sd->status.inventorySize; i++) { + if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0) { + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_id"), j), sd->status.inventory[i].nameid); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_amount"), j), sd->status.inventory[i].amount); + if (sd->status.inventory[i].equip != 0) { + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_equip"), j), pc->equippoint(sd, i)); } else { - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_equip"), j),0); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_equip"), j), 0); } - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_refine"), j),sd->status.inventory[i].refine); - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_identify"), j),sd->status.inventory[i].identify); - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_attribute"), j),sd->status.inventory[i].attribute); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_refine"), j), sd->status.inventory[i].refine); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_identify"), j), sd->status.inventory[i].identify); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_attribute"), j), sd->status.inventory[i].attribute); for (k = 0; k < MAX_SLOTS; k++) { - sprintf(card_var, "@inventorylist_card%d",k+1); - pc->setreg(sd,reference_uid(script->add_variable(card_var), j),sd->status.inventory[i].card[k]); + sprintf(script_var, "@inventorylist_card%d", k + 1); + pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].card[k]); } for (k = 0; k < MAX_ITEM_OPTIONS; k++) { - sprintf(card_var, "@inventorylist_opt_id%d", k + 1); - pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].index); - sprintf(card_var, "@inventorylist_opt_val%d", k + 1); - pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].value); - sprintf(card_var, "@inventorylist_opt_param%d", k + 1); - pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].param); + sprintf(script_var, "@inventorylist_opt_id%d", k + 1); + pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].index); + sprintf(script_var, "@inventorylist_opt_val%d", k + 1); + pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].value); + sprintf(script_var, "@inventorylist_opt_param%d", k + 1); + pc->setreg(sd, reference_uid(script->add_variable(script_var), j), sd->status.inventory[i].option[k].param); } - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_expire"), j),sd->status.inventory[i].expire_time); - pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_bound"), j),sd->status.inventory[i].bound); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_expire"), j), sd->status.inventory[i].expire_time); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_bound"), j), sd->status.inventory[i].bound); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_favorite"), j), sd->status.inventory[i].favorite); + pc->setreg(sd, reference_uid(script->add_variable("@inventorylist_idx"), j), i); j++; } } - pc->setreg(sd,script->add_variable("@inventorylist_count"),j); + pc->setreg(sd, script->add_variable("@inventorylist_count"), j); return true; } @@ -14968,10 +14943,9 @@ static BUILDIN(getskilllist) static BUILDIN(clearitem) { struct map_session_data *sd = script->rid2sd(st); - int i; if (sd == NULL) return true; - for (i=0; i<MAX_INVENTORY; i++) { + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].amount) { pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_NORMAL, LOG_TYPE_SCRIPT); } @@ -15428,6 +15402,50 @@ static BUILDIN(specialeffect2) return true; } +static BUILDIN(removespecialeffect) +{ + struct block_list *bl = NULL; + int type = script_getnum(st, 2); + enum send_target target = AREA; + + if (script_hasdata(st, 3)) { + target = script_getnum(st, 3); + } + + if (script_hasdata(st, 4)) { + if (script_isstringtype(st, 4)) { + struct npc_data *nd = npc->name2id(script_getstr(st, 4)); + if (nd != NULL) { + bl = &nd->bl; + } + } else { + bl = map->id2bl(script_getnum(st, 4)); + } + } else { + bl = map->id2bl(st->oid); + } + + if (bl == NULL) { + return true; + } + + if (target == SELF) { + struct map_session_data *sd; + if (script_hasdata(st, 5)) { + sd = map->id2sd(script_getnum(st, 5)); + } else { + sd = script->rid2sd(st); + } + if (sd != NULL) { + clif->removeSpecialEffect_single(bl, type, &sd->bl); + } + } else { + clif->removeSpecialEffect(bl, type, target); + } + + return true; +} + /*========================================== * Nude [Valaris] *------------------------------------------*/ @@ -15576,36 +15594,74 @@ static BUILDIN(recovery) return true; } -/*========================================== - * Get your pet info: getpetinfo(n) - * n -> 0:pet_id 1:pet_class 2:pet_name - * 3:friendly 4:hungry, 5: rename flag. - *------------------------------------------*/ +/* + * Get your current pet information + */ static BUILDIN(getpetinfo) { struct map_session_data *sd = script->rid2sd(st); - struct pet_data *pd; - int type=script_getnum(st,2); + if (sd == NULL) + return true; - if (sd == NULL || sd->pd == NULL) { - if (type == 2) - script_pushconststr(st,"null"); + struct pet_data *pd = sd->pd; + int type = script_getnum(st, 2); + if (pd == NULL) { + if (type == PETINFO_NAME) + script_pushconststr(st, "null"); else - script_pushint(st,0); + script_pushint(st, 0); return true; } - pd = sd->pd; + switch(type) { - case 0: script_pushint(st,pd->pet.pet_id); break; - case 1: script_pushint(st,pd->pet.class_); break; - case 2: script_pushstrcopy(st,pd->pet.name); break; - case 3: script_pushint(st,pd->pet.intimate); break; - case 4: script_pushint(st,pd->pet.hungry); break; - case 5: script_pushint(st,pd->pet.rename_flag); break; - default: - script_pushint(st,0); - break; + case PETINFO_ID: + script_pushint(st, pd->pet.pet_id); + break; + case PETINFO_CLASS: + script_pushint(st, pd->pet.class_); + break; + case PETINFO_NAME: + script_pushstrcopy(st, pd->pet.name); + break; + case PETINFO_INTIMACY: + script_pushint(st, pd->pet.intimate); + break; + case PETINFO_HUNGRY: + script_pushint(st, pd->pet.hungry); + break; + case PETINFO_RENAME: + script_pushint(st, pd->pet.rename_flag); + break; + case PETINFO_GID: + script_pushint(st, pd->bl.id); + break; + case PETINFO_EGGITEM: + script_pushint(st, pd->pet.egg_id); + break; + case PETINFO_FOODITEM: + script_pushint(st, pd->petDB->FoodID); + break; + case PETINFO_ACCESSORYITEM: + script_pushint(st, pd->petDB->AcceID); + break; + case PETINFO_ACCESSORYFLAG: + script_pushint(st, (pd->pet.equip != 0)? 1:0); + break; + case PETINFO_EVO_EGGID: + if (VECTOR_DATA(pd->petDB->evolve_data) != NULL) + script_pushint(st, VECTOR_DATA(pd->petDB->evolve_data)->petEggId); + else + script_pushint(st, 0); + break; + case PETINFO_AUTOFEED: + script_pushint(st, pd->pet.autofeed); + break; + default: + ShowWarning("buildin_getpetinfo: Invalid type %d.\n", type); + script_pushint(st, 0); + return false; } + return true; } @@ -15643,20 +15699,15 @@ static BUILDIN(gethominfo) return true; } -/// Retrieves information about character's mercenary -/// getmercinfo <type>[,<char id>]; +/* + * Retrieves information about character's mercenary + * getmercinfo <type>{, <char id> }; + */ static BUILDIN(getmercinfo) { - int type; - struct map_session_data* sd; - struct mercenary_data* md; - - type = script_getnum(st,2); - - if (script_hasdata(st,3)) { - int char_id = script_getnum(st,3); - - if ((sd = script->charid2sd(st, char_id)) == NULL) { + struct map_session_data *sd; + if (script_hasdata(st, 3)) { + if ((sd = script->charid2sd(st, script_getnum(st, 3))) == NULL) { script_pushnil(st); return true; } @@ -15665,27 +15716,48 @@ static BUILDIN(getmercinfo) return true; } - md = ( sd->status.mer_id && sd->md ) ? sd->md : NULL; + struct mercenary_data *md = (sd->status.mer_id && sd->md)? sd->md : NULL; + int type = script_getnum(st, 2); + if (md == NULL) { + if (type == MERCINFO_NAME) + script_pushconststr(st, ""); + else + script_pushint(st, 0); + return true; + } - switch( type ) - { - case 0: script_pushint(st,md ? md->mercenary.mercenary_id : 0); break; - case 1: script_pushint(st,md ? md->mercenary.class_ : 0); break; - case 2: - if( md ) - script_pushstrcopy(st,md->db->name); - else - script_pushconststr(st,""); - break; - case 3: script_pushint(st,md ? mercenary->get_faith(md) : 0); break; - case 4: script_pushint(st,md ? mercenary->get_calls(md) : 0); break; - case 5: script_pushint(st,md ? md->mercenary.kill_count : 0); break; - case 6: script_pushint(st,md ? mercenary->get_lifetime(md) : 0); break; - case 7: script_pushint(st,md ? md->db->lv : 0); break; - default: - ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id); - script_pushnil(st); - return false; + switch (type) { + case MERCINFO_ID: + script_pushint(st, md->mercenary.mercenary_id); + break; + case MERCINFO_CLASS: + script_pushint(st, md->mercenary.class_); + break; + case MERCINFO_NAME: + script_pushstrcopy(st, md->db->name); + break; + case MERCINFO_FAITH: + script_pushint(st, mercenary->get_faith(md)); + break; + case MERCINFO_CALLS: + script_pushint(st, mercenary->get_calls(md)); + break; + case MERCINFO_KILLCOUNT: + script_pushint(st, md->mercenary.kill_count); + break; + case MERCINFO_LIFETIME: + script_pushint(st, mercenary->get_lifetime(md)); + break; + case MERCINFO_LEVEL: + script_pushint(st, md->db->lv); + break; + case MERCINFO_GID: + script_pushint(st, md->bl.id); + break; + default: + ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id); + script_pushnil(st); + return false; } return true; @@ -15698,19 +15770,18 @@ static BUILDIN(getmercinfo) *------------------------------------------*/ static BUILDIN(checkequipedcard) { - int n,i,c=0; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; - c = script_getnum(st,2); + int c = script_getnum(st,2); - for( i=0; i<MAX_INVENTORY; i++) { + for (int i = 0; i < sd->status.inventorySize; i++) { if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount && sd->inventory_data[i]) { if (itemdb_isspecial(sd->status.inventory[i].card[0])) continue; - for(n=0;n<sd->inventory_data[i]->slot;n++) { + for (int n = 0; n < sd->inventory_data[i]->slot; n++) { if(sd->status.inventory[i].card[n]==c) { script_pushint(st,1); return true; @@ -15786,6 +15857,29 @@ static BUILDIN(message) return true; } +static BUILDIN(servicemessage) +{ + struct map_session_data *sd = NULL; + + if (script_hasdata(st, 4)) { + if (script_isstringtype(st, 4)) + sd = script->nick2sd(st, script_getstr(st, 4)); + else + sd = script->id2sd(st, script_getnum(st, 4)); + } else { + sd = script->rid2sd(st); + } + + if (sd == NULL) + return true; + + const char *message = script_getstr(st, 2); + const int color = script_getnum(st, 3); + clif->serviceMessageColor(sd, color, message); + + return true; +} + /*========================================== * npctalk (sends message to surrounding area) * usage: npctalk("<message>"{, "<npc name>"{, <show_name>}}); @@ -16555,9 +16649,9 @@ static BUILDIN(equip) ShowError("wrong item ID : equipitem(%d)\n",nameid); return false; } - ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].equip == 0 ); - if( i < MAX_INVENTORY ) - pc->equipitem(sd,i,item_data->equip); + ARR_FIND(0, sd->status.inventorySize, i, sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].equip == 0); + if (i < sd->status.inventorySize) + pc->equipitem(sd, i, item_data->equip); return true; } @@ -16615,21 +16709,21 @@ static BUILDIN(equip2) c2 = script_getnum(st, 7); c3 = script_getnum(st, 8); - ARR_FIND( 0, MAX_INVENTORY, i,( sd->status.inventory[i].equip == 0 && + ARR_FIND(0, sd->status.inventorySize, i, (sd->status.inventory[i].equip == 0 && sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].refine == ref && sd->status.inventory[i].attribute == attr && sd->status.inventory[i].card[0] == c0 && sd->status.inventory[i].card[1] == c1 && sd->status.inventory[i].card[2] == c2 && - sd->status.inventory[i].card[3] == c3 ) ); + sd->status.inventory[i].card[3] == c3)); - if( i < MAX_INVENTORY ) { + if (i < sd->status.inventorySize) { script_pushint(st,1); pc->equipitem(sd,i,item_data->equip); - } - else + } else { script_pushint(st,0); + } return true; } @@ -16816,6 +16910,63 @@ static BUILDIN(getdatatype) return true; } +static BUILDIN(data_to_string) +{ + if (script_hasdata(st, 2)) { + struct script_data *data = script_getdata(st, 2); + + if (data_isstring(data)) { + script_pushcopy(st, 2); + } else if (data_isint(data)) { + char *str = NULL; + + CREATE(str, char, 20); + safesnprintf(str, 20, "%"PRId64"", data->u.num); + script_pushstr(st, str); + } else if (data_islabel(data)) { + const char *str = ""; + + // XXX: because all we have is the label pos we can't be sure which + // one is the correct label if more than one has the same pos. + // We might want to store both the pos and str_data index in + // data->u.num, similar to how C_NAME stores both the array + // index and str_data index in u.num with bitmasking. This + // would also avoid the awkward for() loops as we could + // directly access the string with script->get_str(). + + if (st->oid) { + struct npc_data *nd = map->id2nd(st->oid); + + for (int i = 0; i < nd->u.scr.label_list_num; ++i) { + if (nd->u.scr.label_list[i].pos == data->u.num) { + str = nd->u.scr.label_list[i].name; + break; + } + } + } else { + for (int i = LABEL_START; script->str_data[i].next != 0; i = script->str_data[i].next) { + if (script->str_data[i].label == data->u.num) { + str = script->get_str(i); + break; + } + } + } + + script_pushconststr(st, str); + } else if (data_isreference(data)) { + script_pushstrcopy(st, reference_getname(data)); + } else { + ShowWarning("script:data_to_string: unknown data type!\n"); + script->reportdata(data); + script_pushconststr(st, ""); + } + } else { + script_pushconststr(st, ""); // NIL + } + + return true; +} + //======================================================= // chr <int> //------------------------------------------------------- @@ -17870,7 +18021,9 @@ static BUILDIN(getd) id = script->add_variable(varname); - if (script->str_data[id].type != C_NAME) { + if (script->str_data[id].type != C_NAME && // variable + script->str_data[id].type != C_PARAM && // param + script->str_data[id].type != C_INT) { // constant ShowError("script:getd: `%s` is already used by something that is not a variable.\n", varname); st->state = END; return false; @@ -18585,6 +18738,10 @@ static BUILDIN(getunittype) * @param4 Value#2 Optional int value to be passed for certain data types. * @param5 Value#3 Optional int value to be passed for certain data types. * @return 1 on success, 0 on failure. + + Note: Please make this script command only modify ONE INTEGER value. + If need to modify string type data, or having multiple arguments, please + introduce a new script command. */ static BUILDIN(setunitdata) { @@ -18610,7 +18767,7 @@ static BUILDIN(setunitdata) return false; } - /* Mandatory Argument 3 */ + /* Mandatory Argument 3. Subject to deprecate. */ if (type == UDT_MAPIDXY) { if (!script_isstringtype(st, 4)) { ShowError("buildin_setunitdata: Invalid data type for argument #3.\n"); @@ -18805,6 +18962,20 @@ static BUILDIN(setunitdata) case UDT_ELELEVEL: setunitdata_check_bounds(4, 0, CHAR_MAX); break; + case UDT_GROUP: + { + setunitdata_check_bounds(4, 0, INT_MAX); + struct unit_data *ud = unit->bl2ud2(bl); + if (ud == NULL) { + ShowError("buildin_setunitdata: ud is NULL!\n"); + script_pushint(st, 0); + return false; + } + ud->groupId = script_getnum(st, 4); + clif->blname_ack(0, bl); // Send update to client. + script_pushint(st, 1); + return true; + } default: break; } @@ -18828,17 +18999,19 @@ static BUILDIN(setunitdata) break; case UDT_LEVEL: md->level = val; + if (battle_config.show_mob_info & 4) + clif->blname_ack(0, &md->bl); break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); - clif->charnameack(0, &md->bl); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); + clif->blname_ack(0, &md->bl); break; case UDT_MAXHP: md->status.max_hp = (unsigned int) val; - clif->charnameack(0, &md->bl); + clif->blname_ack(0, &md->bl); break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: md->status.max_sp = (unsigned int) val; @@ -18999,13 +19172,13 @@ static BUILDIN(setunitdata) hd->homunculus.level = (short) val; break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXHP: hd->homunculus.max_hp = val; break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: hd->homunculus.max_sp = val; @@ -19138,13 +19311,13 @@ static BUILDIN(setunitdata) pd->pet.level = (short) val; break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXHP: pd->status.max_hp = (unsigned int) val; break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: pd->status.max_sp = (unsigned int) val; @@ -19272,13 +19445,13 @@ static BUILDIN(setunitdata) mc->base_status.size = (unsigned char) val; break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXHP: mc->base_status.max_hp = (unsigned int) val; break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: mc->base_status.max_sp = (unsigned int) val; @@ -19406,13 +19579,13 @@ static BUILDIN(setunitdata) ed->base_status.size = (unsigned char) val; break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXHP: ed->base_status.max_hp = (unsigned int) val; break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: ed->base_status.max_sp = (unsigned int) val; @@ -19538,13 +19711,13 @@ static BUILDIN(setunitdata) nd->level = (unsigned short) val; break; case UDT_HP: - status->set_hp(bl, (unsigned int) val, 0); + status->set_hp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXHP: nd->status.max_hp = (unsigned int) val; break; case UDT_SP: - status->set_sp(bl, (unsigned int) val, 0); + status->set_sp(bl, (unsigned int) val, STATUS_HEAL_DEFAULT); break; case UDT_MAXSP: nd->status.max_sp = (unsigned int) val; @@ -19702,6 +19875,10 @@ static BUILDIN(setunitdata) * @param2 DataType Type of Data to be set for the unit. * @param3 Variable array reference to store data into. (used for UDT_MAPIDXY) * @return 0 on failure, <value> on success + + Note: Please make this script command only return ONE INTEGER value. + If the unit data having multiple arguments, or need to return in array, + please introduce a new script command. */ static BUILDIN(getunitdata) { @@ -19716,7 +19893,7 @@ static BUILDIN(getunitdata) if (bl == NULL) { ShowWarning("buildin_getunitdata: Error in finding object with given GID %d!\n", script_getnum(st, 2)); - script_pushint(st, 0); + script_pushint(st, -1); return false; } @@ -19725,15 +19902,15 @@ static BUILDIN(getunitdata) /* Type check */ if (type < UDT_TYPE || type >= UDT_MAX) { ShowError("buildin_getunitdata: Invalid unit data type %d provided.\n", type); - script_pushint(st, 0); + script_pushint(st, -1); return false; } - /* Argument checks */ + /* Argument checks. Subject to deprecate */ if (type == UDT_MAPIDXY) { if (data == NULL || !data_isreference(data)) { ShowWarning("buildin_getunitdata: Error in argument 3. Please provide a reference variable to store values in.\n"); - script_pushint(st, 0); + script_pushint(st, -1); return false; } @@ -19743,10 +19920,19 @@ static BUILDIN(getunitdata) sd = script->rid2sd(st); if (sd == NULL) { ShowWarning("buildin_getunitdata: Player not attached! Cannot use player variable %s.\n",name); - script_pushint(st, 0); + script_pushint(st, -1); return true;// no player attached } } + } else if (type == UDT_GROUP) { + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) { + ShowError("buildin_setunitdata: ud is NULL!\n"); + script_pushint(st, -1); + return false; + } + script_pushint(st, ud->groupId); + return true; } #define getunitdata_sub(idx__,var__) script->setd_sub(st,NULL,name,(idx__),(void *)h64BPTRSIZE((int)(var__)),data->ref); @@ -19813,7 +19999,7 @@ static BUILDIN(getunitdata) case UDT_DMOTION: script_pushint(st, md->status.dmotion); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for Mob unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } @@ -19870,7 +20056,7 @@ static BUILDIN(getunitdata) case UDT_INTIMACY: script_pushint(st, hd->homunculus.intimacy); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for Homunculus unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } @@ -19927,7 +20113,7 @@ static BUILDIN(getunitdata) case UDT_INTIMACY: script_pushint(st, pd->pet.intimate); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for Pet unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } @@ -19983,7 +20169,7 @@ static BUILDIN(getunitdata) case UDT_LIFETIME: script_pushint(st, mc->mercenary.life_time); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for Mercenary unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } @@ -20037,7 +20223,7 @@ static BUILDIN(getunitdata) case UDT_MASTERCID: script_pushint(st, ed->elemental.char_id); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for Elemental unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } @@ -20102,14 +20288,14 @@ static BUILDIN(getunitdata) case UDT_BODY2: script_pushint(st, nd->vd.body_style); break; default: ShowWarning("buildin_getunitdata: Invalid data type '%s' for NPC unit.\n", udtype); - script_pushint(st, 0); + script_pushint(st, -1); return false; } } break; default: ShowError("buildin_getunitdata: Unknown object!\n"); - script_pushint(st, 0); + script_pushint(st, -1); return false; } // end of bl->type switch @@ -20205,7 +20391,47 @@ static BUILDIN(setunitname) } script_pushint(st, 1); - clif->charnameack(0, bl); // Send update to client. + clif->blname_ack(0, bl); // Send update to client. + + return true; +} + +static BUILDIN(setunittitle) +{ + struct block_list *bl = map->id2bl(script_getnum(st, 2)); + if (bl == NULL) { + ShowWarning("buildin_setunittitle: Error in finding object with given game ID %d!\n", script_getnum(st, 2)); + return false; + } + + struct unit_data *ud = unit->bl2ud2(bl); + if (ud == NULL) { + ShowWarning("buildin_setunittitle: Error in finding unit_data for given game ID %d!\n", script_getnum(st, 2)); + return false; + } + + safestrncpy(ud->title, script_getstr(st, 3), NAME_LENGTH); + clif->blname_ack(0, bl); // Send update to client. + + return true; +} + +static BUILDIN(getunittitle) +{ + struct block_list *bl = map->id2bl(script_getnum(st, 2)); + if (bl == NULL) { + ShowWarning("buildin_getunitname: Error in finding object with given game ID %d!\n", script_getnum(st, 2)); + script_pushconststr(st, "Unknown"); + return false; + } + + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) { + ShowWarning("buildin_setunittitle: Error in finding unit_data for given game ID %d!\n", script_getnum(st, 2)); + return false; + } + + script_pushstrcopy(st, ud->title); return true; } @@ -20698,7 +20924,7 @@ static BUILDIN(getvariableofpc) } if (!sd->regs.vars) - sd->regs.vars = i64db_alloc(DB_OPT_RELEASE_DATA); + sd->regs.vars = i64db_alloc(DB_OPT_BASE); script->push_val(st->stack, C_NAME, reference_getuid(data), &sd->regs); return true; @@ -20855,7 +21081,7 @@ static BUILDIN(mercenary_heal) hp = script_getnum(st,2); sp = script_getnum(st,3); - status->heal(&sd->md->bl, hp, sp, 0); + status->heal(&sd->md->bl, hp, sp, STATUS_HEAL_DEFAULT); return true; } @@ -21190,6 +21416,17 @@ static BUILDIN(setquestinfo) VECTOR_PUSH(qi->quest_requirement, quest_req); break; } + case QINFO_MERCENARY_CLASS: + { + int mer_class = script_getnum(st, 3); + + if (!mercenary->class(mer_class)) { + ShowWarning("buildin_setquestinfo: invalid mercenary class given (%d).\n", mer_class); + return false; + } + qi->mercenary_class = mer_class; + break; + } default: ShowWarning("buildin_setquestinfo: invalid type given (%u).\n", type); return false; @@ -21343,18 +21580,7 @@ static BUILDIN(showevent) } } -#if PACKETVER >= 20170315 - if (icon < 0 || (icon > 10 && icon != 9999)) - icon = 9999; -#elif PACKETVER >= 20120410 - if (icon < 0 || (icon > 8 && icon != 9999) || icon == 7) - icon = 9999; // Default to nothing if icon id is invalid. -#else - if (icon < 0 || icon > 7) - icon = 0; - else - icon = icon + 1; -#endif + icon = quest->questinfo_validate_icon(icon); clif->quest_show_event(sd, &nd->bl, icon, color); return true; @@ -21584,7 +21810,7 @@ static BUILDIN(bg_monster_set_team) mob_stop_attack(md); mob_stop_walking(md, STOPWALKING_FLAG_NONE); md->target_id = md->attacked_id = 0; - clif->charnameack(0, &md->bl); + clif->blname_ack(0, &md->bl); return true; } @@ -23636,7 +23862,7 @@ static BUILDIN(bg_create_team) if( strcmp(map_name,"-") != 0 ) { map_index = script->mapindexname2id(st,map_name); if( map_index == 0 ) { // Invalid Map - script_pushint(st,0); + script_pushint(st, -1); return true; } } @@ -23684,7 +23910,7 @@ static BUILDIN(bg_join_team) *------------------------------------------*/ static BUILDIN(countbound) { - int i, type, j=0, k=0; + int type, j=0, k=0; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) @@ -23692,7 +23918,7 @@ static BUILDIN(countbound) type = script_hasdata(st,2)?script_getnum(st,2):0; - for(i=0;i<MAX_INVENTORY;i++) { + for (int i = 0; i < sd->status.inventorySize; i++) { if(sd->status.inventory[i].nameid > 0 && ( (!type && sd->status.inventory[i].bound > 0) || (type && sd->status.inventory[i].bound == type) @@ -23738,20 +23964,21 @@ static BUILDIN(checkbound) ShowError("script_checkbound: Not a valid bind type! Type=%d\n", bound_type); } - ARR_FIND( 0, MAX_INVENTORY, i, (sd->status.inventory[i].nameid == nameid && + ARR_FIND(0, sd->status.inventorySize, i, (sd->status.inventory[i].nameid == nameid && ( sd->status.inventory[i].refine == (script_hasdata(st,4)? script_getnum(st,4) : sd->status.inventory[i].refine) ) && ( sd->status.inventory[i].attribute == (script_hasdata(st,5)? script_getnum(st,5) : sd->status.inventory[i].attribute) ) && ( sd->status.inventory[i].card[0] == (script_hasdata(st,6)? script_getnum(st,6) : sd->status.inventory[i].card[0]) ) && ( sd->status.inventory[i].card[1] == (script_hasdata(st,7)? script_getnum(st,7) : sd->status.inventory[i].card[1]) ) && ( sd->status.inventory[i].card[2] == (script_hasdata(st,8)? script_getnum(st,8) : sd->status.inventory[i].card[2]) ) && ( sd->status.inventory[i].card[3] == (script_hasdata(st,9)? script_getnum(st,9) : sd->status.inventory[i].card[3]) ) && - ((sd->status.inventory[i].bound > 0 && !bound_type) || sd->status.inventory[i].bound == bound_type )) ); + ((sd->status.inventory[i].bound > 0 && !bound_type) || sd->status.inventory[i].bound == bound_type))); - if( i < MAX_INVENTORY ){ + if (i < sd->status.inventorySize) { script_pushint(st, sd->status.inventory[i].bound); return true; - } else + } else { script_pushint(st,0); + } return true; } @@ -23888,6 +24115,7 @@ static BUILDIN(sellitem) struct item_data *it; int i = 0, id = script_getnum(st,2); int value = 0; + int value2 = 0; int qty = 0; if( !(nd = map->id2nd(st->oid)) ) { @@ -23898,19 +24126,45 @@ static BUILDIN(sellitem) return false; } - value = script_hasdata(st,3) ? script_getnum(st, 3) : it->value_buy; - if( value == -1 ) - value = it->value_buy; - - if( !nd->u.scr.shop ) - npc->trader_update(nd->src_id?nd->src_id:nd->bl.id); - else {/* no need to run this if its empty */ - for( i = 0; i < nd->u.scr.shop->items; i++ ) { - if( nd->u.scr.shop->item[i].nameid == id ) - break; + if (!nd->u.scr.shop) { + npc->trader_update(nd->src_id ? nd->src_id : nd->bl.id); + if (nd->u.scr.shop->type == NST_BARTER) { + if (!script_hasdata(st, 5)) { + ShowError("buildin_sellitem: invalid number of parameters for barter-type shop!\n"); + return false; + } + value = script_getnum(st, 4); + value2 = script_getnum(st, 5); + } + } else {/* no need to run this if its empty */ + if (nd->u.scr.shop->type == NST_BARTER) { + if (!script_hasdata(st, 5)) { + ShowError("buildin_sellitem: invalid number of parameters for barter-type shop!\n"); + return false; + } + value = script_getnum(st, 4); + value2 = script_getnum(st, 5); + for (i = 0; i < nd->u.scr.shop->items; i++) { + const struct npc_item_list *const item = &nd->u.scr.shop->item[i]; + if (item->nameid == id && item->value == value && item->value2 == value2) { + break; + } + } + } else { + for (i = 0; i < nd->u.scr.shop->items; i++) { + if (nd->u.scr.shop->item[i].nameid == id) { + break; + } + } } } + if (nd->u.scr.shop->type != NST_BARTER) { + value = script_hasdata(st,3) ? script_getnum(st, 3) : it->value_buy; + if( value == -1 ) + value = it->value_buy; + } + if( nd->u.scr.shop->type == NST_MARKET ) { if( !script_hasdata(st,4) || ( qty = script_getnum(st, 4) ) <= 0 ) { ShowError("buildin_sellitem: invalid 'qty' for market-type shop!\n"); @@ -23923,19 +24177,29 @@ static BUILDIN(sellitem) it->name, id, value, (int)(value*0.75), it->value_sell, (int)(it->value_sell*1.24), nd->exname, nd->path); } - if( i != nd->u.scr.shop->items ) { + if (nd->u.scr.shop->type == NST_BARTER) { + qty = script_getnum(st, 3); + if (qty < -1 || value <= 0 || value2 <= 0) { + ShowError("buildin_sellitem: invalid parameters for barter-type shop!\n"); + return false; + } + } + + if (i != nd->u.scr.shop->items) { nd->u.scr.shop->item[i].value = value; nd->u.scr.shop->item[i].qty = qty; - if( nd->u.scr.shop->type == NST_MARKET ) /* has been manually updated, make it reflect on sql */ - npc->market_tosql(nd,i); + if (nd->u.scr.shop->type == NST_MARKET) /* has been manually updated, make it reflect on sql */ + npc->market_tosql(nd, i); + else if (nd->u.scr.shop->type == NST_BARTER) /* has been manually updated, make it reflect on sql */ + npc->barter_tosql(nd, i); } else { - for( i = 0; i < nd->u.scr.shop->items; i++ ) { - if( nd->u.scr.shop->item[i].nameid == 0 ) + for (i = 0; i < nd->u.scr.shop->items; i++) { + if (nd->u.scr.shop->item[i].nameid == 0) break; } - if( i == nd->u.scr.shop->items ) { - if( nd->u.scr.shop->items == USHRT_MAX ) { + if (i == nd->u.scr.shop->items) { + if (nd->u.scr.shop->items == USHRT_MAX) { ShowWarning("buildin_sellitem: Can't add %s (%s/%s), shop list is full!\n", it->name, nd->exname, nd->path); return false; } @@ -23945,6 +24209,7 @@ static BUILDIN(sellitem) nd->u.scr.shop->item[i].nameid = it->nameid; nd->u.scr.shop->item[i].value = value; + nd->u.scr.shop->item[i].value2 = value2; nd->u.scr.shop->item[i].qty = qty; } @@ -23961,35 +24226,55 @@ static BUILDIN(sellitem) static BUILDIN(stopselling) { struct npc_data *nd; - int i, id = script_getnum(st,2); + int i, id = script_getnum(st, 2); - if( !(nd = map->id2nd(st->oid)) || !nd->u.scr.shop ) { + if (!(nd = map->id2nd(st->oid)) || !nd->u.scr.shop) { ShowWarning("buildin_stopselling: trying to run without a proper NPC!\n"); return false; } - for( i = 0; i < nd->u.scr.shop->items; i++ ) { - if( nd->u.scr.shop->item[i].nameid == id ) - break; + if (nd->u.scr.shop->type == NST_BARTER) { + if (!script_hasdata(st, 4)) { + ShowError("buildin_stopselling: called with wrong number of arguments\n"); + return false; + } + const int id2 = script_getnum(st, 3); + const int amount2 = script_getnum(st, 4); + for (i = 0; i < nd->u.scr.shop->items; i++) { + const struct npc_item_list *const item = &nd->u.scr.shop->item[i]; + if (item->nameid == id && item->value == id2 && item->value2 == amount2) { + break; + } + } + } else { + for (i = 0; i < nd->u.scr.shop->items; i++) { + if (nd->u.scr.shop->item[i].nameid == id) { + break; + } + } } - if( i != nd->u.scr.shop->items ) { + if (i != nd->u.scr.shop->items) { int cursor; - if( nd->u.scr.shop->type == NST_MARKET ) - npc->market_delfromsql(nd,i); + if (nd->u.scr.shop->type == NST_MARKET) + npc->market_delfromsql(nd, i); + if (nd->u.scr.shop->type == NST_BARTER) + npc->barter_delfromsql(nd, i); nd->u.scr.shop->item[i].nameid = 0; nd->u.scr.shop->item[i].value = 0; + nd->u.scr.shop->item[i].value2 = 0; nd->u.scr.shop->item[i].qty = 0; - for( i = 0, cursor = 0; i < nd->u.scr.shop->items; i++ ) { - if( nd->u.scr.shop->item[i].nameid == 0 ) + for (i = 0, cursor = 0; i < nd->u.scr.shop->items; i++) { + if (nd->u.scr.shop->item[i].nameid == 0) continue; - if( cursor != i ) { + if (cursor != i) { nd->u.scr.shop->item[cursor].nameid = nd->u.scr.shop->item[i].nameid; nd->u.scr.shop->item[cursor].value = nd->u.scr.shop->item[i].value; + nd->u.scr.shop->item[cursor].value2 = nd->u.scr.shop->item[i].value2; nd->u.scr.shop->item[cursor].qty = nd->u.scr.shop->item[i].qty; } @@ -24055,7 +24340,8 @@ static BUILDIN(tradertype) nd->u.scr.shop->item[i].value = 0; nd->u.scr.shop->item[i].qty = 0; } - npc->market_delfromsql(nd,USHRT_MAX); + npc->market_delfromsql(nd, INT_MAX); + npc->barter_delfromsql(nd, INT_MAX); } #if PACKETVER < 20131223 @@ -24064,6 +24350,12 @@ static BUILDIN(tradertype) script->reportsrc(st); } #endif +#if PACKETVER_MAIN_NUM < 20190116 && PACKETVER_RE_NUM < 20190116 && PACKETVER_ZERO_NUM < 20181226 + if (type == NST_BARTER) { + ShowWarning("buildin_tradertype: NST_BARTER is only available with PACKETVER_ZERO_NUM 20181226 or PACKETVER_MAIN_NUM 20190116 or PACKETVER_RE_NUM 20190116 or newer!\n"); + script->reportsrc(st); + } +#endif if( nd->u.scr.shop ) nd->u.scr.shop->type = type; @@ -24107,8 +24399,8 @@ static BUILDIN(shopcount) } else if ( !nd->u.scr.shop || !nd->u.scr.shop->items ) { ShowWarning("buildin_shopcount(%d): trying to use without any items!\n",id); return false; - } else if ( nd->u.scr.shop->type != NST_MARKET ) { - ShowWarning("buildin_shopcount(%d): trying to use on a non-NST_MARKET shop!\n",id); + } else if (nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER) { + ShowWarning("buildin_shopcount(%d): trying to use on a non-NST_MARKET and non-NST_BARTER shop!\n",id); return false; } @@ -24209,7 +24501,7 @@ static BUILDIN(showscript) { struct block_list *bl = NULL; const char *msg = script_getstr(st, 2); - int id = 0; + int id = 0, flag = AREA; if (script_hasdata(st, 3)) { id = script_getnum(st, 3); @@ -24221,14 +24513,14 @@ static BUILDIN(showscript) if (!bl) { ShowError("buildin_showscript: Script not attached. (id=%d, rid=%d, oid=%d)\n", id, st->rid, st->oid); - script_pushint(st, 0); return false; } - clif->ShowScript(bl, msg); - - script_pushint(st, 1); - + if (script_hasdata(st, 4)) + if (script_getnum(st, 4) == SELF) + flag = SELF; + + clif->ShowScript(bl, msg, flag); return true; } @@ -24338,6 +24630,57 @@ static BUILDIN(getcalendartime) return true; } +enum consolemes_type { + CONSOLEMES_DEBUG = 0, + CONSOLEMES_ERROR = 1, + CONSOLEMES_WARNING = 2, + CONSOLEMES_INFO = 3, + CONSOLEMES_STATUS = 4, + CONSOLEMES_NOTICE = 5, +}; + +/*========================================== +* consolemes(<type>, "text") +*------------------------------------------*/ +static BUILDIN(consolemes) +{ + struct StringBuf buf; + StrBuf->Init(&buf); + int type = script_hasdata(st, 2) ? script_getnum(st, 2) : 0; + + if (!script->sprintf_helper(st, 3, &buf)) { + StrBuf->Destroy(&buf); + script_pushint(st, 0); + return false; + } + + switch (type) { + default: + case CONSOLEMES_DEBUG: + ShowDebug("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_ERROR: + ShowError("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_WARNING: + ShowWarning("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_INFO: + ShowInfo("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_STATUS: + ShowStatus("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_NOTICE: + ShowNotice("consolemes: %s\n", StrBuf->Value(&buf)); + break; + } + + StrBuf->Destroy(&buf); + script_pushint(st, 1); + return true; +} + /** place holder for the translation macro **/ static BUILDIN(_) { @@ -24803,6 +25146,165 @@ static BUILDIN(msgtable2) return true; } +// show/hide camera info +static BUILDIN(camerainfo) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + + clif->camera_showWindow(sd); + return true; +} + +// allow change some camera parameters +static BUILDIN(changecamera) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + + enum send_target target = SELF; + if (script_hasdata(st, 5)) { + target = script_getnum(st, 5); + } + clif->camera_change(sd, (float)script_getnum(st, 2), (float)script_getnum(st, 3), (float)script_getnum(st, 4), target); + return true; +} + +// update preview window to given item +static BUILDIN(itempreview) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + clif->item_preview(sd, script_getnum(st, 2)); + return true; +} + +// insert or remove card into equipped item +static BUILDIN(enchantitem) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + const int pos = script_getnum(st, 2); + if ((pos < EQI_ACC_L || pos > EQI_HAND_R) && pos != EQI_AMMO) { + ShowError("Wrong equip position: %d\n", pos); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int cardId = script_getnum(st, 4); + struct item_data *it = itemdb->exists(cardId); + if (it == NULL || it->type != IT_CARD) { + ShowError("Item id is not card or not exists: %d\n", cardId); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int n = sd->equip_index[pos]; + if (n < 0) { + ShowError("Item in equipment slot %d is not equipped\n", pos); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const int cardSlot = script_getnum(st, 3); + if (cardSlot < 0 || cardSlot >= MAX_SLOTS) { + ShowError("Wrong card slot %d. Must be in range 0-3.\n", cardSlot); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + const bool res = clif->enchant_equipment(sd, pc->equip_pos[pos], cardSlot, cardId); + if (res) { + logs->pick_pc(sd, LOG_TYPE_CARD, -1, &sd->status.inventory[n],sd->inventory_data[n]); + sd->status.inventory[n].card[cardSlot] = cardId; + logs->pick_pc(sd, LOG_TYPE_CARD, 1, &sd->status.inventory[n],sd->inventory_data[n]); + status_calc_pc(sd, SCO_NONE); + } + script_pushint(st, res); + return true; +} + +// send ack to inventory expand request +static BUILDIN(expandInventoryAck) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + int itemId = 0; + if (script_hasdata(st, 3)) { + itemId = script_getnum(st, 3); + } + clif->inventoryExpandAck(sd, script_getnum(st, 2), itemId); + return true; +} + +// send final ack to inventory expand request +static BUILDIN(expandInventoryResult) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + clif->inventoryExpandResult(sd, script_getnum(st, 2)); + return true; +} + +// adjust player inventory size to given value positive or negative +static BUILDIN(expandInventory) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + script_pushint(st, pc->expandInventory(sd, script_getnum(st, 2))); + return true; +} + +// return current player inventory size +static BUILDIN(getInventorySize) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + script_pushint(st, sd->status.inventorySize); + return true; +} + +// force close roulette window if it opened +static BUILDIN(closeroulette) +{ + struct map_session_data *sd = script_rid2sd(st); + if (sd == NULL) + return false; + clif->roulette_close(sd); + return true; +} + +static BUILDIN(openrefineryui) +{ + struct map_session_data *sd = script_rid2sd(st); + + if (sd == NULL) { + script_pushint(st, 0); + return true; + } + + if (battle_config.enable_refinery_ui == 0) { + script_pushint(st, 0); + return true; + } + + clif->OpenRefineryUI(sd); + script_pushint(st, 1); + return true; +} + /** * Adds a built-in script function. * @@ -24971,7 +25473,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(close2,""), BUILDIN_DEF(menu,"sl*"), BUILDIN_DEF(select,"s*"), //for future jA script compatibility - BUILDIN_DEF(prompt,"s*"), + BUILDIN_DEF2(select, "prompt", "s*"), // BUILDIN_DEF(goto,"l"), BUILDIN_DEF(callsub,"l*"), @@ -25015,12 +25517,13 @@ static void script_parse_builtin(void) BUILDIN_DEF(rand,"i?"), BUILDIN_DEF(countitem,"v"), BUILDIN_DEF(countitem2,"viiiiiii"), + BUILDIN_DEF(countnameditem,"v?"), BUILDIN_DEF(checkweight,"vi*"), BUILDIN_DEF(checkweight2,"rr"), BUILDIN_DEF(readparam,"i?"), BUILDIN_DEF(setparam,"ii?"), BUILDIN_DEF(getcharid,"i?"), - BUILDIN_DEF(getnpcid,"i?"), + BUILDIN_DEF(getnpcid, "?"), BUILDIN_DEF(getpartyname,"i"), BUILDIN_DEF(getpartymember,"i?"), BUILDIN_DEF(getpartyleader,"i?"), @@ -25048,6 +25551,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(downrefitem,"i?"), BUILDIN_DEF(statusup,"i"), BUILDIN_DEF(statusup2,"ii"), + BUILDIN_DEF(needed_status_point, "ii"), BUILDIN_DEF(bonus,"iv"), BUILDIN_DEF2(bonus,"bonus2","ivi"), BUILDIN_DEF2(bonus,"bonus3","ivii"), @@ -25078,7 +25582,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(savepoint,"sii"), BUILDIN_DEF(gettimetick,"i"), BUILDIN_DEF(gettime,"i"), - BUILDIN_DEF(gettimestr,"si"), + BUILDIN_DEF(gettimestr, "si?"), BUILDIN_DEF(openstorage,""), BUILDIN_DEF(guildopenstorage,""), BUILDIN_DEF(itemskill,"vi?"), @@ -25089,6 +25593,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(areamonster,"siiiisii???"), BUILDIN_DEF(killmonster,"ss?"), BUILDIN_DEF(killmonsterall,"s?"), + BUILDIN_DEF(killmonstergid, "i"), BUILDIN_DEF(clone,"siisi????"), BUILDIN_DEF(doevent,"s"), BUILDIN_DEF(donpcevent,"s"), @@ -25105,6 +25610,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(attachnpctimer,"?"), // attached the player id to the npc timer [Celest] BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest] BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex] + BUILDIN_DEF(mobattached, ""), BUILDIN_DEF(announce,"si?????"), BUILDIN_DEF(mapannounce,"ssi?????"), BUILDIN_DEF(areaannounce,"siiiisi?????"), @@ -25123,7 +25629,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(sc_end,"i?"), BUILDIN_DEF(getstatus, "i?"), BUILDIN_DEF(getscrate,"ii?"), - BUILDIN_DEF(debugmes,"v*"), + BUILDIN_DEF_DEPRECATED(debugmes,"v*"), + BUILDIN_DEF(consolemes,"iv*"), BUILDIN_DEF2(catchpet,"pet","i"), BUILDIN_DEF2(birthpet,"bpet",""), BUILDIN_DEF(resetlvl,"i"), @@ -25199,6 +25706,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(skilleffect,"vi"), // skill effect [Celest] BUILDIN_DEF(npcskilleffect,"viii"), // npc skill effect [Valaris] BUILDIN_DEF(specialeffect,"i???"), // npc skill effect [Valaris] + BUILDIN_DEF(removespecialeffect,"i???"), BUILDIN_DEF_DEPRECATED(specialeffect2,"i??"), // skill effect on players[Valaris] BUILDIN_DEF(nude,""), // nude command [Valaris] BUILDIN_DEF(mapwarp,"ssii??"), // Added by RoVeRT @@ -25206,6 +25714,7 @@ static void script_parse_builtin(void) BUILDIN_DEF2(atcommand,"charcommand","s"), // [MouseJstr] BUILDIN_DEF(movenpc,"sii?"), // [MouseJstr] BUILDIN_DEF(message,"vs"), // [MouseJstr] + BUILDIN_DEF(servicemessage, "si?"), BUILDIN_DEF(npctalk,"s??"), // [Valaris][Murilo BiO] BUILDIN_DEF(mobcount,"ss"), BUILDIN_DEF(getlook,"i"), @@ -25251,6 +25760,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(charat,"si"), BUILDIN_DEF(isstr,"v"), BUILDIN_DEF(getdatatype, "?"), + BUILDIN_DEF(data_to_string, "?"), + BUILDIN_DEF2(getd, "string_to_data", "?"), BUILDIN_DEF(chr,"i"), BUILDIN_DEF(ord,"s"), BUILDIN_DEF(setchar,"ssi"), @@ -25292,7 +25803,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(getd,"s"), BUILDIN_DEF(setd,"sv"), // <--- [zBuffer] List of dynamic var commands - BUILDIN_DEF(petstat,"i"), + BUILDIN_DEF_DEPRECATED(petstat, "i"), // Deprecated 2019-03-11 BUILDIN_DEF(callshop,"s?"), // [Skotlex] BUILDIN_DEF(npcshopitem,"sii*"), // [Lance] BUILDIN_DEF(npcshopadditem,"sii*"), @@ -25330,6 +25841,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(getunitdata,"ii?"), BUILDIN_DEF(getunitname,"i"), BUILDIN_DEF(setunitname,"is"), + BUILDIN_DEF(getunittitle,"i"), + BUILDIN_DEF(setunittitle,"is"), BUILDIN_DEF(unitwalk,"ii?"), BUILDIN_DEF(unitkill,"i"), BUILDIN_DEF(unitwarp,"isii"), @@ -25498,8 +26011,8 @@ static void script_parse_builtin(void) /* New Shop Support */ BUILDIN_DEF(openshop,"?"), - BUILDIN_DEF(sellitem,"i??"), - BUILDIN_DEF(stopselling,"i"), + BUILDIN_DEF(sellitem,"i???"), + BUILDIN_DEF(stopselling,"i??"), BUILDIN_DEF(setcurrency,"i?"), BUILDIN_DEF(tradertype,"i"), BUILDIN_DEF(purchaseok,""), @@ -25516,7 +26029,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(channelmes, "ss"), BUILDIN_DEF(addchannelhandler, "ss"), BUILDIN_DEF(removechannelhandler, "ss"), - BUILDIN_DEF(showscript, "s?"), + BUILDIN_DEF(showscript, "s??"), BUILDIN_DEF(mergeitem,""), BUILDIN_DEF(getcalendartime, "ii??"), @@ -25532,6 +26045,20 @@ static void script_parse_builtin(void) // -- HatEffect BUILDIN_DEF(hateffect, "ii"), + + // camera + BUILDIN_DEF(camerainfo, ""), + BUILDIN_DEF(changecamera, "iii?"), + + BUILDIN_DEF(itempreview, "i"), + BUILDIN_DEF(enchantitem, "iii"), + BUILDIN_DEF(expandInventoryAck, "i?"), + BUILDIN_DEF(expandInventoryResult, "i"), + BUILDIN_DEF(expandInventory, "i"), + BUILDIN_DEF(getInventorySize, ""), + + BUILDIN_DEF(closeroulette, ""), + BUILDIN_DEF(openrefineryui, ""), }; int i, len = ARRAYLENGTH(BUILDIN); RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up @@ -25571,13 +26098,19 @@ static void script_hardcoded_constants(void) script->set_constant("MAX_LEVEL",MAX_LEVEL,false, false); script->set_constant("MAX_STORAGE",MAX_STORAGE,false, false); script->set_constant("MAX_GUILD_STORAGE",MAX_GUILD_STORAGE,false, false); - script->set_constant("MAX_CART",MAX_INVENTORY,false, false); + script->set_constant("MAX_CART", MAX_CART, false, false); script->set_constant("MAX_INVENTORY",MAX_INVENTORY,false, false); + script->set_constant("FIXED_INVENTORY_SIZE", FIXED_INVENTORY_SIZE, false, false); script->set_constant("MAX_ZENY",MAX_ZENY,false, false); script->set_constant("MAX_BANK_ZENY", MAX_BANK_ZENY, false, false); script->set_constant("MAX_BG_MEMBERS",MAX_BG_MEMBERS,false, false); script->set_constant("MAX_CHAT_USERS",MAX_CHAT_USERS,false, false); script->set_constant("MAX_REFINE",MAX_REFINE,false, false); + script->set_constant("MAX_ITEM_ID",MAX_ITEM_ID,false, false); + script->set_constant("MAX_MENU_OPTIONS", MAX_MENU_OPTIONS, false, false); + script->set_constant("MAX_MENU_LENGTH", MAX_MENU_LENGTH, false, false); + script->set_constant("MOB_CLONE_START", MOB_CLONE_START, false, false); + script->set_constant("MOB_CLONE_END", MOB_CLONE_END, false, false); script->constdb_comment("status options"); script->set_constant("Option_Nothing",OPTION_NOTHING,false, false); @@ -25829,6 +26362,14 @@ static void script_hardcoded_constants(void) script->set_constant("MAPINFO_SIZE_Y", MAPINFO_SIZE_Y, false, false); script->set_constant("MAPINFO_ZONE", MAPINFO_ZONE, false, false); + script->constdb_comment("consolemes options"); + script->set_constant("CONSOLEMES_DEBUG", CONSOLEMES_DEBUG, false, false); + script->set_constant("CONSOLEMES_ERROR", CONSOLEMES_ERROR, false, false); + script->set_constant("CONSOLEMES_WARNING", CONSOLEMES_WARNING, false, false); + script->set_constant("CONSOLEMES_INFO", CONSOLEMES_INFO, false, false); + script->set_constant("CONSOLEMES_STATUS", CONSOLEMES_STATUS, false, false); + script->set_constant("CONSOLEMES_NOTICE", CONSOLEMES_NOTICE, false, false); + script->constdb_comment("set/getiteminfo options"); script->set_constant("ITEMINFO_BUYPRICE", ITEMINFO_BUYPRICE, false, false); script->set_constant("ITEMINFO_SELLPRICE", ITEMINFO_SELLPRICE, false, false); @@ -25847,6 +26388,33 @@ static void script_hardcoded_constants(void) script->set_constant("ITEMINFO_VIEWID", ITEMINFO_VIEWID, false, false); script->set_constant("ITEMINFO_MATK", ITEMINFO_MATK, false, false); script->set_constant("ITEMINFO_VIEWSPRITE", ITEMINFO_VIEWSPRITE, false, false); + script->set_constant("ITEMINFO_TRADE", ITEMINFO_TRADE, false, false); + + script->constdb_comment("getmercinfo options"); + script->set_constant("MERCINFO_ID,", MERCINFO_ID, false, false); + script->set_constant("MERCINFO_CLASS", MERCINFO_CLASS, false, false); + script->set_constant("MERCINFO_NAME", MERCINFO_NAME, false, false); + script->set_constant("MERCINFO_FAITH", MERCINFO_FAITH, false, false); + script->set_constant("MERCINFO_CALLS", MERCINFO_CALLS, false, false); + script->set_constant("MERCINFO_KILLCOUNT", MERCINFO_KILLCOUNT, false, false); + script->set_constant("MERCINFO_LIFETIME", MERCINFO_LIFETIME, false, false); + script->set_constant("MERCINFO_LEVEL", MERCINFO_LEVEL, false, false); + script->set_constant("MERCINFO_GID", MERCINFO_GID, false, false); + + script->constdb_comment("getpetinfo options"); + script->set_constant("PETINFO_ID", PETINFO_ID, false, false); + script->set_constant("PETINFO_CLASS", PETINFO_CLASS, false, false); + script->set_constant("PETINFO_NAME", PETINFO_NAME, false, false); + script->set_constant("PETINFO_INTIMACY", PETINFO_INTIMACY, false, false); + script->set_constant("PETINFO_HUNGRY", PETINFO_HUNGRY, false, false); + script->set_constant("PETINFO_RENAME", PETINFO_RENAME, false, false); + script->set_constant("PETINFO_GID", PETINFO_GID, false, false); + script->set_constant("PETINFO_EGGITEM", PETINFO_EGGITEM, false, false); + script->set_constant("PETINFO_FOODITEM", PETINFO_FOODITEM, false, false); + script->set_constant("PETINFO_ACCESSORYITEM", PETINFO_ACCESSORYITEM, false, false); + script->set_constant("PETINFO_ACCESSORYFLAG", PETINFO_ACCESSORYFLAG, false, false); + script->set_constant("PETINFO_EVO_EGGID", PETINFO_EVO_EGGID, false, false); + script->set_constant("PETINFO_AUTOFEED", PETINFO_AUTOFEED, false, false); script->constdb_comment("monster skill states"); script->set_constant("MSS_ANY", MSS_ANY, false, false); @@ -25930,6 +26498,7 @@ static void script_hardcoded_constants(void) script->set_constant("QINFO_HOMUN_LEVEL", QINFO_HOMUN_LEVEL, false, false); script->set_constant("QINFO_HOMUN_TYPE", QINFO_HOMUN_TYPE, false, false); script->set_constant("QINFO_QUEST", QINFO_QUEST, false, false); + script->set_constant("QINFO_MERCENARY_CLASS", QINFO_MERCENARY_CLASS, false, false); script->constdb_comment("function types"); script->set_constant("FUNCTION_IS_COMMAND", FUNCTION_IS_COMMAND, false, false); @@ -25937,6 +26506,100 @@ static void script_hardcoded_constants(void) script->set_constant("FUNCTION_IS_LOCAL", FUNCTION_IS_LOCAL, false, false); script->set_constant("FUNCTION_IS_LABEL", FUNCTION_IS_LABEL, false, false); + script->constdb_comment("item trade restrictions"); + script->set_constant("ITR_NONE", ITR_NONE, false, false); + script->set_constant("ITR_NODROP", ITR_NODROP, false, false); + script->set_constant("ITR_NOTRADE", ITR_NOTRADE, false, false); + script->set_constant("ITR_PARTNEROVERRIDE", ITR_PARTNEROVERRIDE, false, false); + script->set_constant("ITR_NOSELLTONPC", ITR_NOSELLTONPC, false, false); + script->set_constant("ITR_NOCART", ITR_NOCART, false, false); + script->set_constant("ITR_NOSTORAGE", ITR_NOSTORAGE, false, false); + script->set_constant("ITR_NOGSTORAGE", ITR_NOGSTORAGE, false, false); + script->set_constant("ITR_NOMAIL", ITR_NOMAIL, false, false); + script->set_constant("ITR_NOAUCTION", ITR_NOAUCTION, false, false); + script->set_constant("ITR_ALL", ITR_ALL, false, false); + + script->constdb_comment("inventory expand ack responds"); + script->set_constant("EXPAND_INV_ASK_CONFIRMATION", EXPAND_INVENTORY_ASK_CONFIRMATION, false, false); + script->set_constant("EXPAND_INV_FAILED", EXPAND_INVENTORY_FAILED, false, false); + script->set_constant("EXPAND_INV_OTHER_WORK", EXPAND_INVENTORY_OTHER_WORK, false, false); + script->set_constant("EXPAND_INV_MISSING_ITEM", EXPAND_INVENTORY_MISSING_ITEM, false, false); + script->set_constant("EXPAND_INV_MAX_SIZE", EXPAND_INVENTORY_MAX_SIZE, false, false); + + script->constdb_comment("inventory expand final responds"); + script->set_constant("EXPAND_INV_RESULT_SUCCESS", EXPAND_INVENTORY_RESULT_SUCCESS, false, false); + script->set_constant("EXPAND_INV_RESULT_FAILED", EXPAND_INVENTORY_RESULT_FAILED, false, false); + script->set_constant("EXPAND_INV_RESULT_OTHER_WORK", EXPAND_INVENTORY_RESULT_OTHER_WORK, false, false); + script->set_constant("EXPAND_INV_RESULT_MISSING_ITEM", EXPAND_INVENTORY_RESULT_MISSING_ITEM, false, false); + script->set_constant("EXPAND_INV_RESULT_MAX_SIZE", EXPAND_INVENTORY_RESULT_MAX_SIZE, false, false); + + script->constdb_comment("trader type"); + script->set_constant("NST_ZENY", NST_ZENY, false, false); + script->set_constant("NST_CASH", NST_CASH, false, false); + script->set_constant("NST_MARKET", NST_MARKET, false, false); + script->set_constant("NST_CUSTOM", NST_CUSTOM, false, false); + script->set_constant("NST_BARTER", NST_BARTER, false, false); + + script->constdb_comment("script unit data types"); + script->set_constant("UDT_TYPE", UDT_TYPE, false, false); + script->set_constant("UDT_SIZE", UDT_SIZE, false, false); + script->set_constant("UDT_LEVEL", UDT_LEVEL, false, false); + script->set_constant("UDT_HP", UDT_HP, false, false); + script->set_constant("UDT_MAXHP", UDT_MAXHP, false, false); + script->set_constant("UDT_SP", UDT_SP, false, false); + script->set_constant("UDT_MAXSP", UDT_MAXSP, false, false); + script->set_constant("UDT_MASTERAID", UDT_MASTERAID, false, false); + script->set_constant("UDT_MASTERCID", UDT_MASTERCID, false, false); + script->set_constant("UDT_MAPIDXY", UDT_MAPIDXY, false, true); // for setunitdata use *unitwarp, for getunitdata use *getmapxy + script->set_constant("UDT_WALKTOXY", UDT_WALKTOXY, false, true); // use *unitwalk + script->set_constant("UDT_SPEED", UDT_SPEED, false, false); + script->set_constant("UDT_MODE", UDT_MODE, false, false); + script->set_constant("UDT_AI", UDT_AI, false, false); + script->set_constant("UDT_SCOPTION", UDT_SCOPTION, false, false); + script->set_constant("UDT_SEX", UDT_SEX, false, false); + script->set_constant("UDT_CLASS", UDT_CLASS, false, false); + script->set_constant("UDT_HAIRSTYLE", UDT_HAIRSTYLE, false, false); + script->set_constant("UDT_HAIRCOLOR", UDT_HAIRCOLOR, false, false); + script->set_constant("UDT_HEADBOTTOM", UDT_HEADBOTTOM, false, false); + script->set_constant("UDT_HEADMIDDLE", UDT_HEADMIDDLE, false, false); + script->set_constant("UDT_HEADTOP", UDT_HEADTOP, false, false); + script->set_constant("UDT_CLOTHCOLOR", UDT_CLOTHCOLOR, false, false); + script->set_constant("UDT_SHIELD", UDT_SHIELD, false, false); + script->set_constant("UDT_WEAPON", UDT_WEAPON, false, false); + script->set_constant("UDT_LOOKDIR", UDT_LOOKDIR, false, false); + script->set_constant("UDT_CANMOVETICK", UDT_CANMOVETICK, false, false); + script->set_constant("UDT_STR", UDT_STR, false, false); + script->set_constant("UDT_AGI", UDT_AGI, false, false); + script->set_constant("UDT_VIT", UDT_VIT, false, false); + script->set_constant("UDT_INT", UDT_INT, false, false); + script->set_constant("UDT_DEX", UDT_DEX, false, false); + script->set_constant("UDT_LUK", UDT_LUK, false, false); + script->set_constant("UDT_ATKRANGE", UDT_ATKRANGE, false, false); + script->set_constant("UDT_ATKMIN", UDT_ATKMIN, false, false); + script->set_constant("UDT_ATKMAX", UDT_ATKMAX, false, false); + script->set_constant("UDT_MATKMIN", UDT_MATKMIN, false, false); + script->set_constant("UDT_MATKMAX", UDT_MATKMAX, false, false); + script->set_constant("UDT_DEF", UDT_DEF, false, false); + script->set_constant("UDT_MDEF", UDT_MDEF, false, false); + script->set_constant("UDT_HIT", UDT_HIT, false, false); + script->set_constant("UDT_FLEE", UDT_FLEE, false, false); + script->set_constant("UDT_PDODGE", UDT_PDODGE, false, false); + script->set_constant("UDT_CRIT", UDT_CRIT, false, false); + script->set_constant("UDT_RACE", UDT_RACE, false, false); + script->set_constant("UDT_ELETYPE", UDT_ELETYPE, false, false); + script->set_constant("UDT_ELELEVEL", UDT_ELELEVEL, false, false); + script->set_constant("UDT_AMOTION", UDT_AMOTION, false, false); + script->set_constant("UDT_ADELAY", UDT_ADELAY, false, false); + script->set_constant("UDT_DMOTION", UDT_DMOTION, false, false); + script->set_constant("UDT_HUNGER", UDT_HUNGER, false, false); + script->set_constant("UDT_INTIMACY", UDT_INTIMACY, false, false); + script->set_constant("UDT_LIFETIME", UDT_LIFETIME, false, false); + script->set_constant("UDT_MERC_KILLCOUNT", UDT_MERC_KILLCOUNT, false, false); + script->set_constant("UDT_STATPOINT", UDT_STATPOINT, false, false); + script->set_constant("UDT_ROBE", UDT_ROBE, false, false); + script->set_constant("UDT_BODY2", UDT_BODY2, false, false); + script->set_constant("UDT_GROUP", UDT_GROUP, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false); |