diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 207 | ||||
-rw-r--r-- | src/map/atcommand.h | 2 | ||||
-rw-r--r-- | src/map/clif.c | 199 | ||||
-rw-r--r-- | src/map/clif.h | 4 | ||||
-rw-r--r-- | src/map/duel.c | 23 | ||||
-rw-r--r-- | src/map/duel.h | 2 | ||||
-rw-r--r-- | src/map/instance.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 4 | ||||
-rw-r--r-- | src/map/map.h | 1 | ||||
-rw-r--r-- | src/map/messages_main.h | 63 | ||||
-rw-r--r-- | src/map/messages_re.h | 63 | ||||
-rw-r--r-- | src/map/messages_zero.h | 79 | ||||
-rw-r--r-- | src/map/mob.c | 852 | ||||
-rw-r--r-- | src/map/mob.h | 9 | ||||
-rw-r--r-- | src/map/npc.c | 680 | ||||
-rw-r--r-- | src/map/npc.h | 25 | ||||
-rw-r--r-- | src/map/packets.h | 5 | ||||
-rw-r--r-- | src/map/packets_keys_main.h | 13 | ||||
-rw-r--r-- | src/map/packets_keys_zero.h | 10 | ||||
-rw-r--r-- | src/map/packets_shuffle_main.h | 13 | ||||
-rw-r--r-- | src/map/packets_shuffle_re.h | 10 | ||||
-rw-r--r-- | src/map/packets_shuffle_zero.h | 10 | ||||
-rw-r--r-- | src/map/packets_struct.h | 87 | ||||
-rw-r--r-- | src/map/script.c | 539 | ||||
-rw-r--r-- | src/map/script.h | 1 | ||||
-rw-r--r-- | src/map/skill.c | 132 | ||||
-rw-r--r-- | src/map/skill.h | 6 |
27 files changed, 2249 insertions, 792 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 3cd26079d..c9191d27d 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4483,59 +4483,90 @@ ACMD(loadnpc) return true; } +/** + * Unloads a specific NPC. + * + * @code{.herc} + * @unloadnpc <NPC_name> {<flag>} + * @endcode + * + **/ ACMD(unloadnpc) { - struct npc_data *nd; - char NPCname[NAME_LENGTH+1]; - - memset(NPCname, '\0', sizeof(NPCname)); + char npc_name[NAME_LENGTH + 1] = {'\0'}; + int flag = 1; - if (!*message || sscanf(message, "%24[^\n]", NPCname) < 1) { - clif->message(fd, msg_fd(fd,1133)); // Please enter a NPC name (usage: @npcoff <NPC_name>). + if (*message == '\0' || sscanf(message, "%24s %1d", npc_name, &flag) < 1) { + clif->message(fd, msg_fd(fd, 1133)); /// Please enter a NPC name (Usage: @unloadnpc <NPC_name> {<flag>}). return false; } - - if ((nd = npc->name2id(NPCname)) == NULL) { - clif->message(fd, msg_fd(fd,111)); // This NPC doesn't exist. + + struct npc_data *nd = npc->name2id(npc_name); + + if (nd == NULL) { + clif->message(fd, msg_fd(fd, 111)); /// This NPC doesn't exist. return false; } - npc->unload_duplicates(nd); - npc->unload(nd,true); + npc->unload_duplicates(nd, (flag != 0)); + npc->unload(nd, true, (flag != 0)); npc->read_event_script(); - clif->message(fd, msg_fd(fd,112)); // Npc Disabled. + clif->message(fd, msg_fd(fd, 112)); /// Npc Disabled. return true; } -/// Unload existing NPC within the NPC file and reload it. -/// Usage: @reloadnpc npc/sample_npc.txt +/** + * Unloads a script file and reloads it. + * Note: Be aware that some changes made by NPC are not reverted on unload. See doc/atcommands.txt for details. + * + * @code{.herc} + * @reloadnpc <path> {<flag>} + * @endcode + * + **/ ACMD(reloadnpc) { - if (!*message) { - clif->message(fd, msg_fd(fd, 1385)); // Usage: @unloadnpcfile <file name> + char format[20]; + + snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH); + + char file_path[MAX_DIR_PATH + 1] = {'\0'}; + int flag = 1; + + if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) { + clif->message(fd, msg_fd(fd, 1516)); /// Usage: @reloadnpc <path> {<flag>} return false; - } else if (npc->unloadfile(message) == true) { - clif->message(fd, msg_fd(fd, 1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed. + } - FILE *fp = fopen(message, "r"); - // check if script file exists - if (fp == NULL) { - clif->message(fd, msg_fd(fd, 261)); - return false; - } - fclose(fp); + if (!exists(file_path)) { + clif->message(fd, msg_fd(fd, 1387)); /// File not found. + return false; + } + + if (!is_file(file_path)) { + clif->message(fd, msg_fd(fd, 1518)); /// Not a file. + return false; + } - // add to list of script sources and run it - npc->addsrcfile(message); - npc->parsesrcfile(message, true); - npc->read_event_script(); + FILE *fp = fopen(file_path, "r"); - clif->message(fd, msg_fd(fd, 262)); - } else { - clif->message(fd, msg_fd(fd, 1387)); // File not found. + if (fp == NULL) { + clif->message(fd, msg_fd(fd, 1519)); /// Can't open file. return false; } + fclose(fp); + + if (!npc->unloadfile(file_path, (flag != 0))) { + clif->message(fd, msg_fd(fd, 1517)); /// Script could not be unloaded. + return false; + } + + clif->message(fd, msg_fd(fd, 1386)); /// File unloaded. Be aware that... + npc->addsrcfile(file_path); + npc->parsesrcfile(file_path, true); + npc->read_event_script(); + clif->message(fd, msg_fd(fd, 262)); /// Script loaded. return true; } @@ -6576,47 +6607,52 @@ ACMD(reset) /*========================================== * *------------------------------------------*/ + +/** + * Spawns mobs which treats the invoking as its master. + * + * @code{.herc} + * @summon <monster name/ID> {<duration>} + * @endcode + * + **/ ACMD(summon) { - char name[NAME_LENGTH]; - int mob_id = 0; + char name[NAME_LENGTH + 1] = {'\0'}; int duration = 0; - struct mob_data *md; - int64 tick=timer->gettick(); - if (!*message || sscanf(message, "%23s %12d", name, &duration) < 1) - { - clif->message(fd, msg_fd(fd,1225)); // Please enter a monster name (usage: @summon <monster name> {duration}). + if (*message == '\0' || sscanf(message, "%24s %12d", name, &duration) < 1) { + clif->message(fd, msg_fd(fd, 1225)); /// Please enter a monster name (usage: @summon <monster name> {duration}). return false; } - if (duration < 1) - duration =1; - else if (duration > 60) - duration =60; + int mob_id = atoi(name); - if ((mob_id = atoi(name)) == 0) + if (mob_id == 0) mob_id = mob->db_searchname(name); - if(mob_id == 0 || mob->db_checkid(mob_id) == 0) - { - clif->message(fd, msg_fd(fd,40)); // Invalid monster ID or name. + + if (mob_id == 0 || mob->db_checkid(mob_id) == 0) { + clif->message(fd, msg_fd(fd, 40)); /// Invalid monster ID or name. return false; } - md = mob->once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, DEFAULT_MOB_JNAME, mob_id, "", SZ_SMALL, AI_NONE); + struct mob_data *md = mob->once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, DEFAULT_MOB_JNAME, mob_id, "", + SZ_SMALL, AI_NONE, 0); - if(!md) + if (md == NULL) return false; md->master_id = sd->bl.id; md->special_state.ai = AI_ATTACK; - md->deletetimer = timer->add(tick+(duration*60000),mob->timer_delete,md->bl.id,0); - clif->specialeffect(&md->bl,344,AREA); - mob->spawn(md); - sc_start4(NULL,&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); - clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick); - clif->message(fd, msg_fd(fd,39)); // All monster summoned! + const int64 tick = timer->gettick(); + + md->deletetimer = timer->add(tick + (int64)cap_value(duration, 1, 60) * 60000, mob->timer_delete, md->bl.id, 0); + clif->specialeffect(&md->bl, 344, AREA); + mob->spawn(md); + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); + clif->skill_poseffect(&sd->bl, AM_CALLHOMUN, 1, md->bl.x, md->bl.y, tick); + clif->message(fd, msg_fd(fd, 39)); /// All monster summoned! return true; } @@ -8048,10 +8084,11 @@ ACMD(duel) return false; } - if (!duel->checktime(sd)) { + int64 diff = duel->difftime(sd); + if (diff > 0) { char output[CHAT_SIZE_MAX]; - // "Duel: You can take part in duel only one time per %d minutes." - sprintf(output, msg_fd(fd,356), battle_config.duel_time_interval); + // "Duel: You can take part in duel again after %d secconds." + sprintf(output, msg_fd(fd,356), (int)diff); clif->message(fd, output); return false; } @@ -8101,10 +8138,11 @@ ACMD(leave) ACMD(accept) { - if (!duel->checktime(sd)) { + int64 diff = duel->difftime(sd); + if (diff > 0) { char output[CHAT_SIZE_MAX]; - // "Duel: You can take part in duel only one time per %d minutes." - sprintf(output, msg_fd(fd,356), battle_config.duel_time_interval); + // "Duel: You can take part in duel again after %d seconds." + sprintf(output, msg_fd(fd,356), (int)diff); clif->message(fd, output); return false; } @@ -9007,19 +9045,54 @@ ACMD(addperm) return true; } +/** + * Unloads a script file. + * Note: Be aware that some changes made by NPC are not reverted on unload. See doc/atcommands.txt for details. + * + * @code{.herc} + * @unloadnpcfile <path> {<flag>} + * @endcode + * + **/ ACMD(unloadnpcfile) { - if (!*message) { - clif->message(fd, msg_fd(fd,1385)); // Usage: @unloadnpcfile <file name> + char format[20]; + + snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH); + + char file_path[MAX_DIR_PATH + 1] = {'\0'}; + int flag = 1; + + if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) { + clif->message(fd, msg_fd(fd, 1385)); /// Usage: @unloadnpcfile <path> {<flag>} return false; } - if (npc->unloadfile(message)) { - clif->message(fd, msg_fd(fd,1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed. - } else { - clif->message(fd, msg_fd(fd,1387)); // File not found. + if (!exists(file_path)) { + clif->message(fd, msg_fd(fd, 1387)); /// File not found. return false; } + + if (!is_file(file_path)) { + clif->message(fd, msg_fd(fd, 1518)); /// Not a file. + return false; + } + + FILE *fp = fopen(file_path, "r"); + + if (fp == NULL) { + clif->message(fd, msg_fd(fd, 1519)); /// Can't open file. + return false; + } + + fclose(fp); + + if (!npc->unloadfile(file_path, (flag != 0))) { + clif->message(fd, msg_fd(fd, 1517)); /// Script could not be unloaded. + return false; + } + + clif->message(fd, msg_fd(fd, 1386)); /// File unloaded. Be aware that... return true; } diff --git a/src/map/atcommand.h b/src/map/atcommand.h index f3b1be51b..66827b3b2 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -41,7 +41,7 @@ struct config_setting_t; * Defines **/ #define ATCOMMAND_LENGTH 50 -#define MAX_MSG 1516 +#define MAX_MSG 1520 #define msg_txt(idx) atcommand->msg(idx) #define msg_sd(sd,msg_number) atcommand->msgsd((sd),(msg_number)) #define msg_fd(fd,msg_number) atcommand->msgfd((fd),(msg_number)) diff --git a/src/map/clif.c b/src/map/clif.c index 3dff01523..868117a96 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -4032,51 +4032,58 @@ static void clif_misceffect(struct block_list *bl, int type) /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3) static void clif_changeoption(struct block_list *bl) { - unsigned char buf[32]; - struct status_change *sc; - struct map_session_data* sd; - nullpo_retv(bl); - if ( !(sc = status->get_sc(bl)) && bl->type != BL_NPC ) return; //How can an option change if there's no sc? + struct status_change *sc = status->get_sc(bl); - sd = BL_CAST(BL_PC, bl); + if (sc == NULL && bl->type != BL_NPC) // How can an option change if there's no sc? + return; -#if PACKETVER >= 7 - WBUFW(buf,0) = 0x229; - WBUFL(buf,2) = bl->id; - WBUFW(buf,6) = (sc) ? sc->opt1 : 0; - WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); - WBUFB(buf,14) = (sd)? sd->status.karma : 0; + struct map_session_data *sd = BL_CAST(BL_PC, bl); + struct PACKET_ZC_STATE_CHANGE p; + p.packetType = HEADER_ZC_STATE_CHANGE; + p.AID = bl->id; + p.bodyState = (sc != NULL) ? sc->opt1 : 0; + p.healthState = (sc != NULL) ? sc->opt2 : 0; + p.effectState = (sc != NULL) ? sc->option : BL_UCCAST(BL_NPC, bl)->option; + p.isPKModeON = (sd != NULL) ? sd->status.karma : 0; if (clif->isdisguised(bl)) { - clif->send(buf,packet_len(0x229),bl,AREA_WOS); - WBUFL(buf,2) = -bl->id; - clif->send(buf,packet_len(0x229),bl,SELF); - WBUFL(buf,2) = bl->id; - WBUFL(buf,10) = OPTION_INVISIBLE; - clif->send(buf,packet_len(0x229),bl,SELF); + clif->send(&p, sizeof(p), bl, AREA_WOS); + p.AID = -bl->id; + clif->send(&p, sizeof(p), bl, SELF); + p.AID = bl->id; + p.effectState = OPTION_INVISIBLE; + clif->send(&p, sizeof(p), bl, SELF); } else { - clif->send(buf,packet_len(0x229),bl,AREA); + clif->send(&p, sizeof(p), bl, AREA); } -#else - WBUFW(buf,0) = 0x119; - WBUFL(buf,2) = bl->id; - WBUFW(buf,6) = (sc) ? sc->opt1 : 0; - WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); - WBUFB(buf,12) = (sd)? sd->status.karma : 0; +} + +static void clif_changeoption_target(struct block_list *bl, struct block_list *target_bl, enum send_target target) +{ + nullpo_retv(bl); + nullpo_retv(target_bl); + + struct status_change *sc = status->get_sc(bl); + + if (sc == NULL && bl->type != BL_NPC) // How can an option change if there's no sc? + return; + + struct map_session_data *sd = BL_CAST(BL_PC, bl); + struct PACKET_ZC_STATE_CHANGE p; + p.packetType = HEADER_ZC_STATE_CHANGE; + p.AID = bl->id; + p.bodyState = (sc != NULL) ? sc->opt1 : 0; + p.healthState = (sc != NULL) ? sc->opt2 : 0; + p.effectState = (sc != NULL) ? sc->option : BL_UCCAST(BL_NPC, bl)->option; + p.isPKModeON = (sd != NULL) ? sd->status.karma : 0; if (clif->isdisguised(bl)) { - clif->send(buf,packet_len(0x119),bl,AREA_WOS); - WBUFL(buf,2) = -bl->id; - clif->send(buf,packet_len(0x119),bl,SELF); - WBUFL(buf,2) = bl->id; - WBUFW(buf,10) = OPTION_INVISIBLE; - clif->send(buf,packet_len(0x119),bl,SELF); - } else { - clif->send(buf,packet_len(0x119),bl,AREA); + p.AID = -bl->id; + clif->send(&p, sizeof(p), target_bl, target); + p.AID = bl->id; + p.effectState = OPTION_INVISIBLE; } -#endif + clif->send(&p, sizeof(p), target_bl, target); } /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE). @@ -15273,8 +15280,8 @@ static void clif_parse_GMKick(int fd, struct map_session_data *sd) clif->GM_kickack(sd, 0); return; } - npc->unload_duplicates(nd); - npc->unload(nd,true); + npc->unload_duplicates(nd, true); + npc->unload(nd, true, true); npc->read_event_script(); } break; @@ -20028,7 +20035,7 @@ static void clif_cashShopOpen(int fd, struct map_session_data *sd, int tab) p->packetType = HEADER_ZC_SE_CASHSHOP_OPEN; p->cashPoints = sd->cashPoints; //[Ryuuzaki] - switched positions to reflect proper values p->kafraPoints = sd->kafraPoints; -#if PACKETVER_ZERO_NUM >= 20191224 +#if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224 p->tab = tab; #endif WFIFOSET(fd, sizeof(struct PACKET_ZC_SE_CASHSHOP_OPEN)); @@ -23209,6 +23216,116 @@ static void clif_parse_NPCBarterPurchase(int fd, struct map_session_data *sd) #endif } +static void clif_parse_npc_expanded_barter_closed(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); +static void clif_parse_npc_expanded_barter_closed(int fd, struct map_session_data *sd) +{ +} + +#if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127 +#define NEXT_EXPANDED_BARTER_ITEM(var, count) \ + var = (struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub *)((char*)item + \ + sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub) + \ + count * sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2)) +#endif + +static void clif_npc_expanded_barter_open(struct map_session_data *sd, struct npc_data *nd) +{ +#if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127 + nullpo_retv(sd); + nullpo_retv(nd); + struct npc_item_list *shop = nd->u.scr.shop->item; + const int shop_size = nd->u.scr.shop->items; + + int items_count = 0; + int currencies_count = 0; + struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN *packet = (struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN*)&packet_buf[0]; + STATIC_ASSERT(sizeof(packet_buf) > sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN), "packet_buf size too small"); + int buf_left = sizeof(packet_buf) - sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN); + packet->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_OPEN; + struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub *item = &packet->items[0]; + + for (int i = 0; i < shop_size && buf_left >= sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub); i++) { + if (shop[i].nameid) { + struct item_data *id = itemdb->exists(shop[i].nameid); + if (id == NULL) + continue; + + item->nameid = shop[i].nameid; + item->type = itemtype(id->type); + item->amount = shop[i].qty; + item->weight = id->weight * 10; + item->index = i; + item->zeny = shop[i].value; + item->currency_count = 0; + buf_left -= sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub); + items_count ++; + int count = shop[i].value2; + if (buf_left < sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2) * count) { + NEXT_EXPANDED_BARTER_ITEM(item, 0); + break; + } + for (int j = 0; j < count; j ++) { + struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2 *packet_currency = &item->currencies[j]; + struct npc_barter_currency *currency = &shop[i].currency[j]; + struct item_data *id2 = itemdb->exists(currency->nameid); + if (id2 == NULL) + continue; + packet_currency->nameid = currency->nameid; + if (currency->refine == -1) + packet_currency->refine_level = 0; + else + packet_currency->refine_level = currency->refine; + packet_currency->amount = currency->amount; + packet_currency->type = itemtype(id2->type); + currencies_count ++; + item->currency_count ++; + } + NEXT_EXPANDED_BARTER_ITEM(item, item->currency_count); + } + } + + packet->items_count = items_count; + packet->packetLength = sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN) + + sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub) * items_count + + sizeof(struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2) * currencies_count; + clif->send(packet, packet->packetLength, &sd->bl, SELF); +#endif +} + +#undef NEXT_EXPANDED_BARTER_ITEM + +static void clif_parse_npc_expanded_barter_purchase(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); +static void clif_parse_npc_expanded_barter_purchase(int fd, struct map_session_data *sd) +{ +#if PACKETVER_MAIN_NUM >= 20190904 || PACKETVER_RE_NUM >= 20190904 || PACKETVER_ZERO_NUM >= 20190828 + if (sd->state.trading || pc_isdead(sd) || pc_isvending(sd)) + return; + + const struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE *const p = RP2PTR(fd); + int count = (p->packetLength - sizeof(struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE)) / sizeof p->list[0]; + struct barteritemlist item_list; + + Assert_retv(count >= 0 && count <= sd->status.inventorySize); + + VECTOR_INIT(item_list); + VECTOR_ENSURE(item_list, count, 1); + + for (int i = 0; i < count; i++) { + struct barter_itemlist_entry entry = { 0 }; + entry.addId = p->list[i].itemId; + entry.addAmount = p->list[i].amount; + entry.removeIndex = -1; + entry.shopIndex = p->list[i].shopIndex; + VECTOR_PUSH(item_list, entry); + } + + int response = npc->expanded_barter_buylist(sd, &item_list); + clif->npc_buy_result(sd, response); + + VECTOR_CLEAR(item_list); +#endif +} + static void clif_parse_clientVersion(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); static void clif_parse_clientVersion(int fd, struct map_session_data *sd) { @@ -24102,6 +24219,7 @@ void clif_defaults(void) /* visual effects client-side */ clif->misceffect = clif_misceffect; clif->changeoption = clif_changeoption; + clif->changeoption_target = clif_changeoption_target; clif->changeoption2 = clif_changeoption2; clif->emotion = clif_emotion; clif->talkiebox = clif_talkiebox; @@ -24766,6 +24884,9 @@ void clif_defaults(void) clif->npc_barter_open = clif_npc_barter_open; clif->pNPCBarterClosed = clif_parse_NPCBarterClosed; clif->pNPCBarterPurchase = clif_parse_NPCBarterPurchase; + clif->npc_expanded_barter_open = clif_npc_expanded_barter_open; + clif->pNPCExpandedBarterPurchase = clif_parse_npc_expanded_barter_purchase; + clif->pNPCExpandedBarterClosed = clif_parse_npc_expanded_barter_closed; clif->pClientVersion = clif_parse_clientVersion; clif->pPing = clif_parse_ping; clif->ping = clif_ping; diff --git a/src/map/clif.h b/src/map/clif.h index b61772bba..25ac65af5 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1006,6 +1006,7 @@ struct clif_interface { /* visual effects client-side */ void (*misceffect) (struct block_list* bl,int type); void (*changeoption) (struct block_list* bl); + void (*changeoption_target) (struct block_list *bl, struct block_list *target_bl, enum send_target target); void (*changeoption2) (struct block_list* bl); void (*emotion) (struct block_list *bl,int type); void (*talkiebox) (struct block_list* bl, const char* talkie); @@ -1663,6 +1664,9 @@ struct clif_interface { void (*npc_barter_open) (struct map_session_data *sd, struct npc_data *nd); void (*pNPCBarterClosed) (int fd, struct map_session_data *sd); void (*pNPCBarterPurchase) (int fd, struct map_session_data *sd); + void (*pNPCExpandedBarterClosed) (int fd, struct map_session_data *sd); + void (*pNPCExpandedBarterPurchase) (int fd, struct map_session_data *sd); + void (*npc_expanded_barter_open) (struct map_session_data *sd, struct npc_data *nd); void (*pClientVersion) (int fd, struct map_session_data *sd); void (*pPing) (int fd, struct map_session_data *sd); void (*ping) (struct map_session_data *sd); diff --git a/src/map/duel.c b/src/map/duel.c index dca040f83..c66fd6fc2 100644 --- a/src/map/duel.c +++ b/src/map/duel.c @@ -41,27 +41,12 @@ struct duel_interface *duel; *------------------------------------------*/ static void duel_savetime(struct map_session_data *sd) { - time_t clock; - struct tm *t; - - time(&clock); - t = localtime(&clock); - - pc_setglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME"), t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min); + pc_setglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME"), (int)time(NULL)); } -static int duel_checktime(struct map_session_data *sd) +static int64 duel_difftime(struct map_session_data *sd) { - int diff; - time_t clock; - struct tm *t; - - time(&clock); - t = localtime(&clock); - - diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME") ); - - return !(diff >= 0 && diff < battle_config.duel_time_interval); + return (pc_readglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME")) + battle_config.duel_time_interval - (int)time(NULL)); } static int duel_showinfo_sub(struct map_session_data *sd, va_list va) @@ -233,7 +218,7 @@ void duel_defaults(void) duel->reject = duel_reject; duel->leave = duel_leave; duel->showinfo = duel_showinfo; - duel->checktime = duel_checktime; + duel->difftime = duel_difftime; duel->init = do_init_duel; duel->final = do_final_duel; diff --git a/src/map/duel.h b/src/map/duel.h index 4e8985b96..1620ca891 100644 --- a/src/map/duel.h +++ b/src/map/duel.h @@ -52,7 +52,7 @@ struct duel_interface { void (*reject) (const unsigned int did, struct map_session_data* sd); void (*leave) (const unsigned int did, struct map_session_data* sd); void (*showinfo) (const unsigned int did, struct map_session_data* sd); - int (*checktime) (struct map_session_data* sd); + int64 (*difftime) (struct map_session_data* sd); void (*init) (bool minimal); void (*final) (void); diff --git a/src/map/instance.c b/src/map/instance.c index 90f2217b1..1104b7e88 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -446,7 +446,7 @@ static int instance_cleanup_sub(struct block_list *bl, va_list ap) map->quit(BL_UCAST(BL_PC, bl)); break; case BL_NPC: - npc->unload(BL_UCAST(BL_NPC, bl), true); + npc->unload(BL_UCAST(BL_NPC, bl), true, true); break; case BL_MOB: unit->free(bl,CLR_OUTSIGHT); diff --git a/src/map/map.c b/src/map/map.c index afdc2ed41..8b52fc761 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4452,6 +4452,7 @@ static bool inter_config_read_database_names(const char *filename, const struct libconfig->setting_lookup_mutable_string(setting, "autotrade_data_db", map->autotrade_data_db, sizeof(map->autotrade_data_db)); libconfig->setting_lookup_mutable_string(setting, "npc_market_data_db", map->npc_market_data_db, sizeof(map->npc_market_data_db)); libconfig->setting_lookup_mutable_string(setting, "npc_barter_data_db", map->npc_barter_data_db, sizeof(map->npc_barter_data_db)); + libconfig->setting_lookup_mutable_string(setting, "npc_expanded_barter_data_db", map->npc_expanded_barter_data_db, sizeof(map->npc_expanded_barter_data_db)); if (!mapreg->config_read(filename, setting, imported)) retval = false; @@ -6091,7 +6092,7 @@ static int cleanup_sub(struct block_list *bl, va_list ap) map->quit(BL_UCAST(BL_PC, bl)); break; case BL_NPC: - npc->unload(BL_UCAST(BL_NPC, bl), false); + npc->unload(BL_UCAST(BL_NPC, bl), false, true); break; case BL_MOB: unit->free(bl,CLR_OUTSIGHT); @@ -6749,6 +6750,7 @@ int do_init(int argc, char *argv[]) npc->event_do_oninit( false ); // Init npcs (OnInit) npc->market_fromsql(); /* after OnInit */ npc->barter_fromsql(); /* after OnInit */ + npc->expanded_barter_fromsql(); /* after OnInit */ if (battle_config.pk_mode) ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n"); diff --git a/src/map/map.h b/src/map/map.h index 78f1a3c89..dbd9c0fba 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1056,6 +1056,7 @@ struct map_interface { char autotrade_data_db[32]; char npc_market_data_db[32]; char npc_barter_data_db[32]; + char npc_expanded_barter_data_db[32]; char default_codepage[32]; char default_lang_str[64]; diff --git a/src/map/messages_main.h b/src/map/messages_main.h index b2b67f08c..6fc0310e7 100644 --- a/src/map/messages_main.h +++ b/src/map/messages_main.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ /* This file is autogenerated, please do not commit manual changes -Latest version: 20200108 +Latest version: 20200129 */ enum clif_messages { @@ -22464,6 +22464,63 @@ Search */ MSG_ID_EC1 = 0xec1, #endif +#if PACKETVER >= 20200122 +/*20200122 to latest +리서치 리포트 상태가 됩니다. +*/ + MSG_ID_EC2 = 0xec2, +/*20200122 to latest +리서치 리포트 상태가 해제됩니다. +*/ + MSG_ID_EC3 = 0xec3, +/*20200122 to latest +제조에 성공 했습니다. +*/ + MSG_ID_EC4 = 0xec4, +/*20200122 to latest +제조에 실패 했습니다. +*/ + MSG_ID_EC5 = 0xec5, +/*20200122 to latest +쉐도우 장비가 파괴 및 해제에서 보호됩니다. +*/ + MSG_ID_EC6 = 0xec6, +/*20200122 to latest +풀 쉐도우 프로텍션이 해제됩니다. +*/ + MSG_ID_EC7 = 0xec7, +/*20200122 to latest +식물형, 무형 몬스터에게 주는 데미지가 증가합니다. +*/ + MSG_ID_EC8 = 0xec8, +/*20200122 to latest +지옥 나무의 가루효과가 사라집니다. +*/ + MSG_ID_EC9 = 0xec9, +#endif +#if PACKETVER >= 20200129 +/*20200129 to latest +공격 장치가 활성화되었습니다. +*/ + MSG_ID_ECA = 0xeca, +/*20200129 to latest +공격 장치가 해제되었습니다. +*/ + MSG_ID_ECB = 0xecb, +/*20200129 to latest +물리 방어력 및 물리 저항력이 증가되었습니다. +*/ + MSG_ID_ECC = 0xecc, +/*20200129 to latest +방어 장치가 해제되었습니다. +*/ + MSG_ID_ECD = 0xecd, +/*20200129 to latest +검색 +Search +*/ + MSG_ID_ECE = 0xece, +#endif }; #endif /* MAP_MESSAGES_MAIN_H */ diff --git a/src/map/messages_re.h b/src/map/messages_re.h index 8cb3b6624..f4cc62d68 100644 --- a/src/map/messages_re.h +++ b/src/map/messages_re.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ /* This file is autogenerated, please do not commit manual changes -Latest version: 20200108 +Latest version: 20200205 */ enum clif_messages { @@ -21941,6 +21941,63 @@ Search */ MSG_ID_EC1 = 0xec1, #endif +#if PACKETVER >= 20200122 +/*20200122 to latest +리서치 리포트 상태가 됩니다. +*/ + MSG_ID_EC2 = 0xec2, +/*20200122 to latest +리서치 리포트 상태가 해제됩니다. +*/ + MSG_ID_EC3 = 0xec3, +/*20200122 to latest +제조에 성공 했습니다. +*/ + MSG_ID_EC4 = 0xec4, +/*20200122 to latest +제조에 실패 했습니다. +*/ + MSG_ID_EC5 = 0xec5, +/*20200122 to latest +쉐도우 장비가 파괴 및 해제에서 보호됩니다. +*/ + MSG_ID_EC6 = 0xec6, +/*20200122 to latest +풀 쉐도우 프로텍션이 해제됩니다. +*/ + MSG_ID_EC7 = 0xec7, +/*20200122 to latest +식물형, 무형 몬스터에게 주는 데미지가 증가합니다. +*/ + MSG_ID_EC8 = 0xec8, +/*20200122 to latest +지옥 나무의 가루효과가 사라집니다. +*/ + MSG_ID_EC9 = 0xec9, +#endif +#if PACKETVER >= 20200205 +/*20200205 to latest +공격 장치가 활성화되었습니다. +*/ + MSG_ID_ECA = 0xeca, +/*20200205 to latest +공격 장치가 해제되었습니다. +*/ + MSG_ID_ECB = 0xecb, +/*20200205 to latest +물리 방어력 및 물리 저항력이 증가되었습니다. +*/ + MSG_ID_ECC = 0xecc, +/*20200205 to latest +방어 장치가 해제되었습니다. +*/ + MSG_ID_ECD = 0xecd, +/*20200205 to latest +검색 +Search +*/ + MSG_ID_ECE = 0xece, +#endif }; #endif /* MAP_MESSAGES_RE_H */ diff --git a/src/map/messages_zero.h b/src/map/messages_zero.h index 18aed7d5b..55c0329ee 100644 --- a/src/map/messages_zero.h +++ b/src/map/messages_zero.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ /* This file is autogenerated, please do not commit manual changes -Latest version: 20191224 +Latest version: 20200129 */ enum clif_messages { @@ -6734,9 +6734,11 @@ The Memorial Dungeon's entry time limit expired; it has been destroyed. The Memorial Dungeon has been removed. */ MSG_MEMORIAL_DUN_DESTROY_REQUEST = 0x544, -/*20171018 to latest +/*20171018 to 20191224 메모리얼 던전에 시스템 오류가 발생하였습니다. 정상적인 게임 진행을 위해 재접속을 해주십시오. A system error has occurred in the Memorial Dungeon. Please relog in to the game to continue playing. +20200115 to latest +메모리얼 던전에 통신 장애가 발생하였습니다. 정상적인 게임 진행을 위해 잠시 후, 재접속을 해주십시오. */ MSG_MEMORIAL_DUN_ERROR = 0x545, /*20171018 to latest @@ -18319,8 +18321,10 @@ VTC 인증에 실패하였습니다. 가나다 정렬 */ MSG_ID_E8A = 0xe8a, -/*20191113 to latest +/*20191113 to 20191224 기본 결과물은 %s %d개 이나, 낮은 확률로 최대 %d개까지 생성될 수 있습니다. +20200115 to latest +※[%s] %d~%d개 제작 */ MSG_ID_E8B = 0xe8b, /*20191113 to latest @@ -18536,6 +18540,71 @@ https://member.gnjoy.com.tw/billing.aspx */ MSG_ID_EBE = 0xebe, #endif +#if PACKETVER >= 20200115 +/*20200115 to latest +역순 정렬 +*/ + MSG_ID_EBF = 0xebf, +/*20200115 to latest +검색 내용 입력 +*/ + MSG_ID_EC0 = 0xec0, +/*20200115 to latest +검색 +Search +*/ + MSG_ID_EC1 = 0xec1, +/*20200115 to latest +리서치 리포트 상태가 됩니다. +*/ + MSG_ID_EC2 = 0xec2, +/*20200115 to latest +리서치 리포트 상태가 해제됩니다. +*/ + MSG_ID_EC3 = 0xec3, +/*20200115 to latest +제조에 성공 했습니다. +*/ + MSG_ID_EC4 = 0xec4, +/*20200115 to latest +제조에 실패 했습니다. +*/ + MSG_ID_EC5 = 0xec5, +/*20200115 to latest +쉐도우 장비가 파괴 및 해제에서 보호됩니다. +*/ + MSG_ID_EC6 = 0xec6, +/*20200115 to latest +풀 쉐도우 프로텍션이 해제됩니다. +*/ + MSG_ID_EC7 = 0xec7, +/*20200115 to latest +식물형, 무형 몬스터에게 주는 데미지가 증가합니다. +*/ + MSG_ID_EC8 = 0xec8, +/*20200115 to latest +지옥 나무의 가루효과가 사라집니다. +*/ + MSG_ID_EC9 = 0xec9, +#endif +#if PACKETVER >= 20200129 +/*20200129 to latest +공격 장치가 활성화되었습니다. +*/ + MSG_ID_ECA = 0xeca, +/*20200129 to latest +공격 장치가 해제되었습니다. +*/ + MSG_ID_ECB = 0xecb, +/*20200129 to latest +물리 방어력 및 물리 저항력이 증가되었습니다. +*/ + MSG_ID_ECC = 0xecc, +/*20200129 to latest +방어 장치가 해제되었습니다. +*/ + MSG_ID_ECD = 0xecd, +#endif }; #endif /* MAP_MESSAGES_ZERO_H */ diff --git a/src/map/mob.c b/src/map/mob.c index 4b74abc8f..6c1076114 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -337,15 +337,23 @@ static int mob_parse_dataset(struct spawn_data *data) return 1; } -/*========================================== - * Generates the basic mob data using the spawn_data provided. - *------------------------------------------*/ -static struct mob_data *mob_spawn_dataset(struct spawn_data *data) + +/** + * Generates basic mob data by using the passed spawn data. + * + * @param data The mobs spawn data. + * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC. + * @return The generated mob data, later used to spawn the mob. + * + **/ +static struct mob_data *mob_spawn_dataset(struct spawn_data *data, int npc_id) { - struct mob_data *md = NULL; nullpo_retr(NULL, data); - CREATE(md, struct mob_data, 1); - md->bl.id= npc->get_new_npc_id(); + + struct mob_data *md = (struct mob_data *)aCalloc(1, sizeof(struct mob_data)); + + memcpy(md->name, data->name, NAME_LENGTH); + md->bl.id = npc->get_new_npc_id(); md->bl.type = BL_MOB; md->bl.m = data->m; md->bl.x = data->x; @@ -353,24 +361,29 @@ static struct mob_data *mob_spawn_dataset(struct spawn_data *data) md->class_ = data->class_; md->state.boss = data->state.boss; md->db = mob->db(md->class_); + md->npc_id = npc_id; + md->spawn_timer = INVALID_TIMER; + md->deletetimer = INVALID_TIMER; + md->skill_idx = -1; + if (data->level > 0 && data->level <= MAX_LEVEL) md->level = data->level; - memcpy(md->name, data->name, NAME_LENGTH); - if (data->state.ai) + + if (data->state.ai > 0) md->special_state.ai = data->state.ai; - if (data->state.size) + + if (data->state.size > 0) md->special_state.size = data->state.size; - if (data->eventname[0] && strlen(data->eventname) >= 4) + + if (data->eventname[0] != '\0' && strlen(data->eventname) >= 4) memcpy(md->npc_event, data->eventname, 50); - if(md->db->status.mode&MD_LOOTER) - md->lootitem = (struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item)); - md->spawn_timer = INVALID_TIMER; - md->deletetimer = INVALID_TIMER; - md->skill_idx = -1; + + if ((md->db->status.mode & MD_LOOTER) == MD_LOOTER) + md->lootitem = (struct item *)aCalloc(LOOTITEM_SIZE, sizeof(struct item)); + status->set_viewdata(&md->bl, md->class_); status->change_init(&md->bl); unit->dataset(&md->bl); - map->addiddb(&md->bl); return md; } @@ -503,7 +516,24 @@ static bool mob_ksprotected(struct block_list *src, struct block_list *target) return false; } -static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai) +/** + * Prepares a mob's spawn data. + * + * @param bl The invoking character's block list. + * @param m The ID of the map where the mob should be spawned. + * @param x The x coordinate where the mob should be spawned. + * @param y The y coordinate where the mob should be spawned. + * @param mobname The mob's display name. + * @param class_ The mob's ID in database. + * @param event The name of the event which should be executed when the mob is killed. + * @param size The mob's size. + * @param ai The mob's AI. + * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC. + * @return The mob data generated by mob->spawn_dataset(). + * + **/ +static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, + const char *event, unsigned int size, unsigned int ai, int npc_id) { struct spawn_data data; @@ -521,76 +551,100 @@ static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 else strcpy(data.name, DEFAULT_MOB_JNAME); - if (event) + if (event != NULL) safestrncpy(data.eventname, event, sizeof(data.eventname)); - // Locate spot next to player. - if (bl && (x < 0 || y < 0)) + /** Locate spot next to player. **/ + if (bl != NULL && (x < 0 || y < 0)) map->search_freecell(bl, m, &x, &y, 1, 1, 0); - // if none found, pick random position on map + /** If none found, pick random position on map. **/ if (x <= 0 || x >= map->list[m].xs || y <= 0 || y >= map->list[m].ys) map->search_freecell(NULL, m, &x, &y, -1, -1, 1); data.x = x; data.y = y; - if (!mob->parse_dataset(&data)) + if (mob->parse_dataset(&data) == 0) return NULL; - return mob->spawn_dataset(&data); + return mob->spawn_dataset(&data, npc_id); } -/*========================================== - * Spawn a single mob on the specified coordinates. - *------------------------------------------*/ -static int mob_once_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai) +/** + * Spawns a given amount of mobs. + * + * @param sd The invoking character. + * @param m The ID of the map where the mob should be spawned. + * @param x The x coordinate where the mob should be spawned. + * @param y The y coordinate where the mob should be spawned. + * @param mobname The mob's display name. + * @param class_ The mob's ID in database. + * @param amount The amount of mobs to spawn. + * @param event The name of the event which should be executed when the mob is killed. + * @param size The mob's size. + * @param ai The mob's AI. + * @return The last spawned mob's GID, or 0 if spawning failed. + * + **/ +static int mob_once_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_, + int amount, const char *event, unsigned int size, unsigned int ai) { - struct mob_data* md = NULL; - int count, lv; bool no_guardian_data = false; - if( ai && ai&0x200 ) { + if (ai > 0 && (ai & 0x200) == 0x200) { no_guardian_data = true; - ai &=~ 0x200; + ai &= ~0x200; } if (m < 0 || amount <= 0) - return 0; // invalid input + return 0; - lv = (sd) ? sd->status.base_level : 255; + struct mob_data *md = NULL; + + for (int i = 0; i < amount; i++) { + int mob_id = class_; + + if (mob_id < 0) { + mob_id = mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv == 1) ? 3 : 1, + (sd != NULL) ? sd->status.base_level : 255); + } - for (count = 0; count < amount; count++) { - int c = (class_ >= 0) ? class_ : mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv); - md = mob->once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai); + md = mob->once_spawn_sub((sd != NULL) ? &sd->bl : NULL, m, x, y, mobname, mob_id, event, size, ai, + (sd != NULL) ? sd->npc_id : 0); - if (!md) + if (md == NULL) continue; if (class_ == MOBID_EMPELIUM && !no_guardian_data) { - struct guild_castle* gc = guild->mapindex2gc(map_id2index(m)); - struct guild* g = (gc) ? guild->search(gc->guild_id) : NULL; - if( gc ) { + struct guild_castle *gc = guild->mapindex2gc(map_id2index(m)); + + if (gc != NULL) { + struct guild *g = guild->search(gc->guild_id); + md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data)); md->guardian_data->castle = gc; md->guardian_data->number = MAX_GUARDIANS; - if( g ) + + if (g != NULL) md->guardian_data->g = g; - else if( gc->guild_id ) //Guild not yet available, retry in 5. - timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id); + else if (gc->guild_id > 0) /// Guild not yet available, retry in 5s. + timer->add(timer->gettick() + 5000, mob->spawn_guardian_sub, md->bl.id, + gc->guild_id); } - } // end addition [Valaris] + } mob->spawn(md); - if (class_ < 0 && battle_config.dead_branch_active) { - //Behold Aegis's masterful decisions yet again... - //"I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" - Poki#3 - sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, 0, 60000); + if (class_ < 0 && battle_config.dead_branch_active == 1) { + /// Behold Aegis' masterful decisions yet again... + /// "I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" [Poki] + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, + 0, 60000); } } - return (md) ? md->bl.id : 0; // id of last spawned mob + return (md != NULL) ? md->bl.id : 0; /// ID of last spawned mob. } /*========================================== @@ -649,196 +703,236 @@ static int mob_once_spawn_area(struct map_session_data *sd, int16 m, int16 x0, i } /** - * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data - * @param data (int)guild_id - * @retval Always 0 + * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data. + * Required because the guild data may not be available at guardian spawn time. + * + * @param tid Required parameter for timer functions. Unused inside the function. + * @param tick Required parameter for timer functions. Unused inside the function. + * @param id The guardian mob's GID. + * @param data The guild ID. + * @return 1 on success, 0 on failure. + * * @author Skotlex + * **/ static int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data) { - //Needed because the guild data may not be available at guardian spawn time. - struct block_list* bl = map->id2bl(id); - struct mob_data* md; - struct guild* g; + struct block_list *bl = map->id2bl(id); - if( bl == NULL ) //It is possible mob was already removed from map when the castle has no owner. [Skotlex] + if (bl == NULL || bl->type != BL_MOB) /// It is possible mob was already removed from map when the castle has no owner. [Skotlex] return 0; - Assert_ret(bl->type == BL_MOB); - md = BL_UCAST(BL_MOB, bl); + struct mob_data *md = BL_UCAST(BL_MOB, bl); - nullpo_ret(md->guardian_data); - g = guild->search((int)data); + if (md->guardian_data == NULL) + return 0; + + struct guild *g = guild->search((int)data); - if( g == NULL ) { //Liberate castle, if the guild is not found this is an error! [Skotlex] + if (g == NULL) { /// Liberate castle, if the guild is not found this is an error! [Skotlex] ShowError("mob_spawn_guardian_sub: Couldn't load guild %d!\n", (int)data); - //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on. - if (md->class_ == MOBID_EMPELIUM && md->guardian_data) { + + /// Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on. + if (md->class_ == MOBID_EMPELIUM) { md->guardian_data->g = NULL; - if( md->guardian_data->castle->guild_id ) {//Free castle up. - ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name); + + if (md->guardian_data->castle->guild_id > 0) { /// Free castle up. + ShowNotice("mob_spawn_guardian_sub: Clearing ownership of castle %d (%s).\n", + md->guardian_data->castle->castle_id, + md->guardian_data->castle->castle_name); guild->castledatasave(md->guardian_data->castle->castle_id, 1, 0); } } else { - if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS - && md->guardian_data->castle->guardian[md->guardian_data->number].visible ) - guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0); + if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && + md->guardian_data->castle->guardian[md->guardian_data->number].visible == 1) + guild->castledatasave(md->guardian_data->castle->castle_id, + 10 + md->guardian_data->number, 0); - unit->free(&md->bl,CLR_OUTSIGHT); // Remove guardian. + unit->free(&md->bl, CLR_OUTSIGHT); /// Remove guardian. } + return 0; } - if( guild->checkskill(g,GD_GUARDUP) ) - status_calc_mob(md, SCO_NONE); // Give bonuses. + if (guild->checkskill(g, GD_GUARDUP) > 0) + status_calc_mob(md, SCO_NONE); /// Give bonuses. - return 0; + return 1; } -/*========================================== - * Summoning Guardians [Valaris] - *------------------------------------------*/ -static int mob_spawn_guardian(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, int guardian, bool has_index) +/** + * Summons a castle guardian mob. + * + * @param mapname The name of the map where the guardian should be spawned. + * @param x The x coordinate where the guardian should be spawned. + * @param y The y coordinate where the guardian should be spawned. + * @param mobname The guardian's display name. + * @param class_ The guardian's mob ID in database. + * @param event The name of the event which should be executed when the guardian is killed. + * @param guardian The guardian's index. + * @param has_index If false, the guardian will be temporarily. + * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC. + * @return The spawned guardian's GID, or 0 if spawning failed. + * + * @author Valaris + * + **/ +static int mob_spawn_guardian(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, + int guardian, bool has_index, int npc_id) { - struct mob_data *md=NULL; - struct spawn_data data; - struct guild *g=NULL; - struct guild_castle *gc; - int16 m; - nullpo_ret(mapname); nullpo_ret(mobname); nullpo_ret(event); - memset(&data, 0, sizeof(struct spawn_data)); - data.num = 1; + const int map_id = map->mapname2mapid(mapname); - m=map->mapname2mapid(mapname); - - if(m<0) - { + if (map_id == INDEX_NOT_FOUND) { ShowWarning("mob_spawn_guardian: Map [%s] not found.\n", mapname); return 0; } - data.m = m; - data.num = 1; - if(class_<=0) { - class_ = mob->get_random_id(-class_-1, 1, 99); - if (!class_) return 0; + + if ((x <= 0 || y <= 0) && map->search_freecell(NULL, map_id, &x, &y, -1, -1, 1) == 0) { + ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) on castle map %s.\n", + class_, guardian, mapname); + return 0; } - data.class_ = class_; + if (class_ <= 0 && (class_ = mob->get_random_id(-class_ - 1, 1, 99)) == 0) + return 0; - if( !has_index ) { + if (!has_index) { guardian = -1; - } else if( guardian < 0 || guardian >= MAX_GUARDIANS ) { - ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d (castle map %s)\n", guardian, class_, map->list[m].name); + } else if (guardian < 0 || guardian >= MAX_GUARDIANS) { + ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d on castle map %s.\n", + guardian, class_, mapname); return 0; } - if((x<=0 || y<=0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1)) { - ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) at castle map %s\n",class_, guardian, map->list[m].name); - return 0; - } + struct spawn_data data; + + memset(&data, 0, sizeof(struct spawn_data)); + data.num = 1; + data.m = map_id; + data.class_ = class_; data.x = x; data.y = y; safestrncpy(data.name, mobname, sizeof(data.name)); safestrncpy(data.eventname, event, sizeof(data.eventname)); - if (!mob->parse_dataset(&data)) + + if (mob->parse_dataset(&data) == 0) return 0; - gc=guild->mapname2gc(map->list[m].name); + struct guild_castle *gc = guild->mapname2gc(mapname); + if (gc == NULL) { - ShowError("mob_spawn_guardian: No castle set at map %s\n", map->list[m].name); + ShowError("mob_spawn_guardian: No castle set on map %s.\n", mapname); return 0; } - if (!gc->guild_id) - ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle with no guild (castle map %s)\n", class_, map->list[m].name); + + struct guild *g = NULL; + + if (gc->guild_id == 0) + ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle map %s with no guild.\n", + class_, mapname); else g = guild->search(gc->guild_id); - if( has_index && gc->guardian[guardian].id ) { - //Check if guardian already exists, refuse to spawn if so. - struct block_list *bl2 = map->id2bl(gc->guardian[guardian].id); // TODO: Why does this not use map->id2md? - struct mob_data *md2 = BL_CAST(BL_MOB, bl2); - if (md2 != NULL && md2->guardian_data != NULL && md2->guardian_data->number == guardian) { - ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian (castle map %s)\n", guardian, map->list[m].name); + if (has_index && gc->guardian[guardian].id != 0) { /// Check if guardian already exists, refuse to spawn if so. + struct mob_data *md = map->id2md(gc->guardian[guardian].id); + + if (md != NULL && md->guardian_data != NULL && md->guardian_data->number == guardian) { + ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian on castle map %s.\n", + guardian, mapname); return 0; } } - md = mob->spawn_dataset(&data); + struct mob_data *md = mob->spawn_dataset(&data, npc_id); + md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data)); md->guardian_data->number = guardian; md->guardian_data->castle = gc; - if( has_index ) - {// permanent guardian + + if (has_index) { /// Permanent guardian. gc->guardian[guardian].id = md->bl.id; - } - else - {// temporary guardian + } else { /// Temporary guardian. int i; + ARR_FIND(0, gc->temp_guardians_max, i, gc->temp_guardians[i] == 0); - if( i == gc->temp_guardians_max ) - { + + if (i == gc->temp_guardians_max) { ++(gc->temp_guardians_max); RECREATE(gc->temp_guardians, int, gc->temp_guardians_max); } + gc->temp_guardians[i] = md->bl.id; } - if( g ) + + if (g != NULL) md->guardian_data->g = g; - else if( gc->guild_id ) - timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id); - mob->spawn(md); + else if (gc->guild_id > 0) + timer->add(timer->gettick() + 5000, mob->spawn_guardian_sub, md->bl.id, gc->guild_id); + mob->spawn(md); return md->bl.id; } -/*========================================== - * Summoning BattleGround [Zephyrus] - *------------------------------------------*/ -static int mob_spawn_bg(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, unsigned int bg_id) +/** + * Spawn a mob with allegiance to the given battle group. + * + * @param mapname The name of the map where the mob should be spawned. + * @param x The x coordinate where the mob should be spawned. + * @param y The y coordinate where the mob should be spawned. + * @param mobname The mob's display name. + * @param class_ The mob's mob ID in database. + * @param event The name of the event which should be executed when the mob is killed. + * @param bg_id The battle group ID. + * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC. + * @return The spawned mob's GID, or 0 if spawning failed. + * + * @author Zephyrus + * + **/ +static int mob_spawn_bg(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, + unsigned int bg_id, int npc_id) { - struct mob_data *md = NULL; - struct spawn_data data; - int16 m; - nullpo_ret(mapname); nullpo_ret(mobname); nullpo_ret(event); - if( (m = map->mapname2mapid(mapname)) < 0 ) { + const int map_id = map->mapname2mapid(mapname); + + if (map_id == INDEX_NOT_FOUND) { ShowWarning("mob_spawn_bg: Map [%s] not found.\n", mapname); return 0; } - memset(&data, 0, sizeof(struct spawn_data)); - data.m = m; - data.num = 1; - if( class_ <= 0 ) - { - class_ = mob->get_random_id(-class_-1,1,99); - if( !class_ ) return 0; + if ((x <= 0 || y <= 0) && map->search_freecell(NULL, map_id, &x, &y, -1, -1, 1) == 0) { + ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %u) on map %s.\n", class_, bg_id, mapname); + return 0; } - data.class_ = class_; - if( (x <= 0 || y <= 0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1) ) { - ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %u) at map %s\n", class_, bg_id, map->list[m].name); + if (class_ <= 0 && (class_ = mob->get_random_id(-class_ - 1, 1, 99)) == 0) return 0; - } + struct spawn_data data; + + memset(&data, 0, sizeof(struct spawn_data)); + data.num = 1; + data.m = map_id; + data.class_ = class_; data.x = x; data.y = y; safestrncpy(data.name, mobname, sizeof(data.name)); safestrncpy(data.eventname, event, sizeof(data.eventname)); - if( !mob->parse_dataset(&data) ) + + if (mob->parse_dataset(&data) == 0) return 0; - md = mob->spawn_dataset(&data); - mob->spawn(md); - md->bg_id = bg_id; // BG Team ID + struct mob_data *md = mob->spawn_dataset(&data, npc_id); + mob->spawn(md); + md->bg_id = bg_id; return md->bl.id; } @@ -3100,18 +3194,25 @@ static int mob_countslave(struct block_list *bl) return map->foreachinmap(mob->countslave_sub, bl->m, BL_MOB,bl->id); } -/*========================================== - * Summons amount slaves contained in the value[5] array using round-robin. [adapted by Skotlex] - *------------------------------------------*/ +/** + * Summons amount slaves contained in the value[5] array using round-robin. + * + * @param md2 The mob which summons the slaves. + * @param value Array with slave mob IDs. + * @param amount The amount of slaves to spawn. + * @param skill_id The Id of the skill which summons the slaves. + * @return 1 on success, 0 on failure. + * + * @author Skotlex + * + **/ static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16 skill_id) { - struct mob_data *md; - struct spawn_data data; - int count = 0,k=0,hp_rate=0; - nullpo_ret(md2); nullpo_ret(value); + struct spawn_data data; + memset(&data, 0, sizeof(struct spawn_data)); data.m = md2->bl.m; data.x = md2->bl.x; @@ -3120,31 +3221,42 @@ static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16 data.state.size = md2->special_state.size; data.state.ai = md2->special_state.ai; - if(mob->db_checkid(value[0]) == 0) + if (mob->db_checkid(value[0]) == 0) return 0; - /** - * Flags this monster is able to summon; saves a worth amount of memory upon deletion - **/ - md2->can_summon = 1; - while(count < 5 && mob->db_checkid(value[count])) count++; - if(count < 1) return 0; - if (amount > 0 && amount < count) { //Do not start on 0, pick some random sub subset [Skotlex] - k = rnd()%count; - amount+=k; //Increase final value by same amount to preserve total number to summon. + md2->can_summon = 1; /// Flags this monster is able to summon; saves a worth amount of memory upon deletion. + + int count = 0; + + while (count < 5 && mob->db_checkid(value[count]) != 0) + count++; + + if (count < 1) + return 0; + + int k = 0; + + if (amount > 0 && amount < count) { /// Do not start on 0, pick some random sub subset. [Skotlex] + k = rnd() % count; + amount += k; /// Increase final value by same amount to preserve total number to summon. } - if (!battle_config.monster_class_change_recover && - (skill_id == NPC_TRANSFORMATION || skill_id == NPC_METAMORPHOSIS)) + int hp_rate = 0; + + if ((skill_id == NPC_TRANSFORMATION || skill_id == NPC_METAMORPHOSIS) && + battle_config.monster_class_change_recover == 0) hp_rate = get_percentage(md2->status.hp, md2->status.max_hp); - for(;k<amount;k++) { - short x,y; - data.class_ = value[k%count]; //Summon slaves in round-robin fashion. [Skotlex] + for (; k < amount; k++) { + data.class_ = value[k % count]; /// Summon slaves in round-robin fashion. [Skotlex] + if (mob->db_checkid(data.class_) == 0) continue; - if (map->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0)) { + short x; + short y; + + if (map->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0) != 0) { data.x = x; data.y = y; } else { @@ -3152,49 +3264,52 @@ static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16 data.y = md2->bl.y; } - //These two need to be loaded from the db for each slave. if (battle_config.override_mob_names == 1) strcpy(data.name, DEFAULT_MOB_NAME); else strcpy(data.name, DEFAULT_MOB_JNAME); - if (!mob->parse_dataset(&data)) + if (mob->parse_dataset(&data) == 0) continue; - md= mob->spawn_dataset(&data); - if(skill_id == NPC_SUMMONSLAVE){ - md->master_id=md2->bl.id; + struct mob_data *md = mob->spawn_dataset(&data, 0); + + if (skill_id == NPC_SUMMONSLAVE) { + md->master_id = md2->bl.id; md->special_state.ai = md2->special_state.ai; } + mob->spawn(md); - if (hp_rate) //Scale HP - md->status.hp = md->status.max_hp*hp_rate/100; + if (hp_rate > 0) /// Scale HP. + md->status.hp = md->status.max_hp * hp_rate / 100; - //Inherit the aggressive mode of the master. - if (battle_config.slaves_inherit_mode && md->master_id) { + /** Inherit the aggressive mode of the master. **/ + if (battle_config.slaves_inherit_mode > 0 && md->master_id > 0) { switch (battle_config.slaves_inherit_mode) { - case 1: //Always aggressive - if (!(md->status.mode&MD_AGGRESSIVE)) - sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0); + case 1: /// Always aggressive. + if ((md->status.mode & MD_AGGRESSIVE) == 0) + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 0); + break; - case 2: //Always passive - if (md->status.mode&MD_AGGRESSIVE) - sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0); + case 2: /// Always passive. + if ((md->status.mode & MD_AGGRESSIVE) == MD_AGGRESSIVE) + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, 0, MD_AGGRESSIVE, 0); + break; - default: //Copy master. - if (md2->status.mode&MD_AGGRESSIVE) - sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0); + default: /// Copy master. + if ((md2->status.mode & MD_AGGRESSIVE) == MD_AGGRESSIVE) + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 0); else - sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0); + sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, 0, MD_AGGRESSIVE, 0); break; } } - clif->skill_nodamage(&md->bl,&md->bl,skill_id,amount,1); + clif->skill_nodamage(&md->bl, &md->bl, skill_id, amount, 1); } - return 0; + return 1; } /*========================================== @@ -3588,211 +3703,238 @@ static int mob_is_clone(int class_) return class_; } -//Flag values: -//&1: Set special AI (fight mobs, not players) -//If mode is not passed, a default aggressive mode is used. -//If master_id is passed, clone is attached to him. -//Returns: ID of newly crafted copy. -static int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, uint32 mode, int flag, unsigned int duration) +/** + * Spawns a mob which is a clone of another character. + * + * @param sd The character which should be cloned. + * @param m The ID of the map where the clone should be spawned. + * @param x The x coordinate where the clone should be spawned. + * @param y The y coordinate where the clone should be spawned. + * @param event The name of the event which should be executed when the clone is killed. + * @param master_id If passed, the clone will be attached to this account ID. + * @param mode The clone's mob mode(s). (Defaults to MD_CANMOVE|MD_AGGRESSIVE|MD_ASSIST|MD_CANATTACK.) + * @param flag 0 - target characters; 1 - target mobs. + * @param duration How long the clone will live before it is auto-removed. (ms) + * @return The spawned clone's GID, or 0 if spawning failed. + * + **/ +static int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, + uint32 mode, int flag, unsigned int duration) { - int class_; - int i,j,h,inf, fd; - struct mob_data *md; - struct mob_skill *ms; - struct mob_db* db; - struct status_data *mstatus; - nullpo_ret(sd); - if(pc_isdead(sd) && master_id && flag&1) + if (pc_isdead(sd) && master_id != 0 && flag == 1) return 0; - ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL ); - if(class_ < 0 || class_ >= MOB_CLONE_END) + int class_; + + ARR_FIND(MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL); + + if (class_ < 0 || class_ >= MOB_CLONE_END) return 0; - db = mob->db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db)); - mstatus = &db->status; - strcpy(db->sprite,sd->status.name); - strcpy(db->name,sd->status.name); - strcpy(db->jname,sd->status.name); - db->lv=status->get_lv(&sd->bl); + mob->db_data[class_] = (struct mob_db*)aCalloc(1, sizeof(struct mob_db)); + + struct mob_db *db = mob->db_data[class_]; + struct status_data *mstatus = &db->status; + + strcpy(db->sprite, sd->status.name); + strcpy(db->name, sd->status.name); + strcpy(db->jname, sd->status.name); + db->lv = status->get_lv(&sd->bl); memcpy(mstatus, &sd->base_status, sizeof(struct status_data)); - mstatus->rhw.atk2= mstatus->dex + mstatus->rhw.atk + mstatus->rhw.atk2; //Max ATK - mstatus->rhw.atk = mstatus->dex; //Min ATK - if (mstatus->lhw.atk) { - mstatus->lhw.atk2= mstatus->dex + mstatus->lhw.atk + mstatus->lhw.atk2; //Max ATK - mstatus->lhw.atk = mstatus->dex; //Min ATK + mstatus->rhw.atk2 = mstatus->dex + mstatus->rhw.atk + mstatus->rhw.atk2; /// Max ATK. + mstatus->rhw.atk = mstatus->dex; /// Min ATK. + + if (mstatus->lhw.atk > 0) { + mstatus->lhw.atk2 = mstatus->dex + mstatus->lhw.atk + mstatus->lhw.atk2; /// Max ATK. + mstatus->lhw.atk = mstatus->dex; /// Min ATK. } - if (mode != MD_NONE) //User provided mode. + + if (mode != MD_NONE) /// User provided mode. mstatus->mode = mode; - else if (flag&1) //Friendly Character, remove looting. + else if (flag == 1) /// Friendly Character, remove looting. mstatus->mode &= ~MD_LOOTER; + mstatus->hp = mstatus->max_hp; mstatus->sp = mstatus->max_sp; memcpy(&db->vd, &sd->vd, sizeof(struct view_data)); - db->base_exp=1; - db->job_exp=1; - db->range2=AREA_SIZE; //Let them have the same view-range as players. - db->range3=AREA_SIZE; //Min chase of a screen. - db->option=sd->sc.option; + db->base_exp = 1; + db->job_exp = 1; + db->range2 = AREA_SIZE; /// Let them have the same view-range as players. + db->range3 = AREA_SIZE; /// Min chase of a screen. + db->option = sd->sc.option; - //Skill copy [Skotlex] - ms = &db->skill[0]; + const int fd = sd->fd; - /** - * We temporarily disable sd's fd so it doesn't receive the messages from skill_check_condition_castbegin - **/ - fd = sd->fd; - sd->fd = 0; - - //Go Backwards to give better priority to advanced skills. - for (i=0,j = MAX_SKILL_TREE-1;j>=0 && i< MAX_MOBSKILL ;j--) { - int idx = pc->skill_tree[pc->class2idx(sd->status.class)][j].idx; - int skill_id = pc->skill_tree[pc->class2idx(sd->status.class)][j].id; - if (!skill_id || sd->status.skill[idx].lv < 1 || - (skill->dbs->db[idx].inf2&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL)) - ) + sd->fd = 0; /// Temporarily disable sd's fd so it doesn't receive the messages from skill_check_condition_castbegin. + + struct mob_skill *mob_skills = &db->skill[0]; + + /// Go Backwards to give better priority to advanced skills. + for (int i = 0, j = MAX_SKILL_TREE - 1; j >= 0 && i < MAX_MOBSKILL; j--) { + const int idx = pc->skill_tree[pc->class2idx(sd->status.class)][j].idx; + const int skill_id = pc->skill_tree[pc->class2idx(sd->status.class)][j].id; + + if (skill_id == 0 || sd->status.skill[idx].lv < 1 || + (skill->dbs->db[idx].inf2 & (INF2_WEDDING_SKILL | INF2_GUILD_SKILL)) > 0) continue; - for(h = 0; h < map->list[sd->bl.m].zone->disabled_skills_count; h++) { - if( skill_id == map->list[sd->bl.m].zone->disabled_skills[h]->nameid && map->list[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE ) { + + int h; + + for (h = 0; h < map->list[sd->bl.m].zone->disabled_skills_count; h++) { + if (skill_id == map->list[sd->bl.m].zone->disabled_skills[h]->nameid && + map->list[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE) break; - } } - if( h < map->list[sd->bl.m].zone->disabled_skills_count ) + + if (h < map->list[sd->bl.m].zone->disabled_skills_count) continue; - //Normal aggressive mob, disable skills that cannot help them fight - //against players (those with flags UF_NOMOB and UF_NOPC are specific - //to always aid players!) [Skotlex] - if (!(flag&1) && - skill->get_unit_id(skill_id, 0) && - skill->get_unit_flag(skill_id)&(UF_NOMOB|UF_NOPC)) + + /// Normal aggressive mob. Disable skills that cannot help fighting against players. (Those with flags UF_NOMOB and UF_NOPC are specific to always aid players!) [Skotlex] + if (flag == 0 && skill->get_unit_id(skill_id, 0) != 0 && + (skill->get_unit_flag(skill_id) & (UF_NOMOB | UF_NOPC)) > 0) continue; - /** - * The clone should be able to cast the skill (e.g. have the required weapon) bugreport:5299) - **/ - if( !skill->check_condition_castbegin(sd,skill_id,sd->status.skill[idx].lv) ) + + /// The clone should be able to cast the skill. (E.g. have the required weapon.) [bugreport:5299] + if (skill->check_condition_castbegin(sd, skill_id, sd->status.skill[idx].lv) == 0) continue; - memset (&ms[i], 0, sizeof(struct mob_skill)); - ms[i].skill_id = skill_id; - ms[i].skill_lv = sd->status.skill[idx].lv; - ms[i].state = MSS_ANY; - ms[i].permillage = 500*battle_config.mob_skill_rate/100; //Default chance of all skills: 5% - ms[i].emotion = -1; - ms[i].cancel = 0; - ms[i].casttime = skill->cast_fix(&sd->bl,skill_id, ms[i].skill_lv); - ms[i].delay = 5000+skill->delay_fix(&sd->bl,skill_id, ms[i].skill_lv); - - inf = skill->dbs->db[idx].inf; - if (inf&INF_ATTACK_SKILL) { - ms[i].target = MST_TARGET; - ms[i].cond1 = MSC_ALWAYS; - if (skill->get_range(skill_id, ms[i].skill_lv) > 3) - ms[i].state = MSS_ANYTARGET; + memset(&mob_skills[i], 0, sizeof(struct mob_skill)); + mob_skills[i].skill_id = skill_id; + mob_skills[i].skill_lv = sd->status.skill[idx].lv; + mob_skills[i].state = MSS_ANY; + mob_skills[i].permillage = 500 * battle_config.mob_skill_rate / 100; /// Default chance of all skills: 5% + mob_skills[i].emotion = -1; + mob_skills[i].cancel = 0; + mob_skills[i].casttime = skill->cast_fix(&sd->bl, skill_id, mob_skills[i].skill_lv); + mob_skills[i].delay = 5000 + skill->delay_fix(&sd->bl, skill_id, mob_skills[i].skill_lv); + + const int inf = skill->dbs->db[idx].inf; + + if ((inf & INF_ATTACK_SKILL) == INF_ATTACK_SKILL) { + mob_skills[i].target = MST_TARGET; + mob_skills[i].cond1 = MSC_ALWAYS; + + if (skill->get_range(skill_id, mob_skills[i].skill_lv) > 3) + mob_skills[i].state = MSS_ANYTARGET; else - ms[i].state = MSS_BERSERK; - } else if(inf&INF_GROUND_SKILL) { - if (skill->get_inf2(skill_id)&INF2_TRAP) { //Traps! - ms[i].state = MSS_IDLE; - ms[i].target = MST_AROUND2; - ms[i].delay = 60000; - } else if (skill->get_unit_target(skill_id) == BCT_ENEMY) { //Target Enemy - ms[i].state = MSS_ANYTARGET; - ms[i].target = MST_TARGET; - ms[i].cond1 = MSC_ALWAYS; - } else { //Target allies - ms[i].target = MST_FRIEND; - ms[i].cond1 = MSC_FRIENDHPLTMAXRATE; - ms[i].cond2 = 95; + mob_skills[i].state = MSS_BERSERK; + } else if ((inf & INF_GROUND_SKILL) == INF_GROUND_SKILL) { + if ((skill->get_inf2(skill_id) & INF2_TRAP) == INF2_TRAP) { /// Traps! + mob_skills[i].state = MSS_IDLE; + mob_skills[i].target = MST_AROUND2; + mob_skills[i].delay = 60000; + } else if (skill->get_unit_target(skill_id) == BCT_ENEMY) { /// Target Enemy. + mob_skills[i].state = MSS_ANYTARGET; + mob_skills[i].target = MST_TARGET; + mob_skills[i].cond1 = MSC_ALWAYS; + } else { /// Target allies. + mob_skills[i].target = MST_FRIEND; + mob_skills[i].cond1 = MSC_FRIENDHPLTMAXRATE; + mob_skills[i].cond2 = 95; } - } else if (inf&INF_SELF_SKILL) { - if (skill->get_inf2(skill_id)&INF2_NO_TARGET_SELF) { //auto-select target skill. - ms[i].target = MST_TARGET; - ms[i].cond1 = MSC_ALWAYS; - if (skill->get_range(skill_id, ms[i].skill_lv) > 3) { - ms[i].state = MSS_ANYTARGET; - } else { - ms[i].state = MSS_BERSERK; - } - } else { //Self skill - ms[i].target = MST_SELF; - ms[i].cond1 = MSC_MYHPLTMAXRATE; - ms[i].cond2 = 90; - ms[i].permillage = 2000; - //Delay: Remove the stock 5 secs and add half of the support time. - ms[i].delay += -5000 +(skill->get_time(skill_id, ms[i].skill_lv) + skill->get_time2(skill_id, ms[i].skill_lv))/2; - if (ms[i].delay < 5000) - ms[i].delay = 5000; //With a minimum of 5 secs. + } else if ((inf & INF_SELF_SKILL) == INF_SELF_SKILL) { + if ((skill->get_inf2(skill_id) & INF2_NO_TARGET_SELF) == INF2_NO_TARGET_SELF) { /// Auto-select target skill. + mob_skills[i].target = MST_TARGET; + mob_skills[i].cond1 = MSC_ALWAYS; + + if (skill->get_range(skill_id, mob_skills[i].skill_lv) > 3) + mob_skills[i].state = MSS_ANYTARGET; + else + mob_skills[i].state = MSS_BERSERK; + } else { /// Self skill. + mob_skills[i].target = MST_SELF; + mob_skills[i].cond1 = MSC_MYHPLTMAXRATE; + mob_skills[i].cond2 = 90; + mob_skills[i].permillage = 2000; + + const int time1 = skill->get_time(skill_id, mob_skills[i].skill_lv); + const int time2 = skill->get_time2(skill_id, mob_skills[i].skill_lv); + + /** Delay: Remove the stock 5 secs and add half of the support time. **/ + mob_skills[i].delay += -5000 + (time1 + time2) / 2; + + if (mob_skills[i].delay < 5000) + mob_skills[i].delay = 5000; /// With a minimum of 5 seconds. } - } else if (inf&INF_SUPPORT_SKILL) { - ms[i].target = MST_FRIEND; - ms[i].cond1 = MSC_FRIENDHPLTMAXRATE; - ms[i].cond2 = 90; + } else if ((inf & INF_SUPPORT_SKILL) == INF_SUPPORT_SKILL) { + mob_skills[i].target = MST_FRIEND; + mob_skills[i].cond1 = MSC_FRIENDHPLTMAXRATE; + mob_skills[i].cond2 = 90; + if (skill_id == AL_HEAL) - ms[i].permillage = 5000; //Higher skill rate usage for heal. + mob_skills[i].permillage = 5000; /// Higher skill rate usage for heal. else if (skill_id == ALL_RESURRECTION) - ms[i].cond2 = 1; - //Delay: Remove the stock 5 secs and add half of the support time. - ms[i].delay += -5000 +(skill->get_time(skill_id, ms[i].skill_lv) + skill->get_time2(skill_id, ms[i].skill_lv))/2; - if (ms[i].delay < 2000) - ms[i].delay = 2000; //With a minimum of 2 secs. - - if (i+1 < MAX_MOBSKILL) { //duplicate this so it also triggers on self. - memcpy(&ms[i+1], &ms[i], sizeof(struct mob_skill)); + mob_skills[i].cond2 = 1; + + const int time1 = skill->get_time(skill_id, mob_skills[i].skill_lv); + const int time2 = skill->get_time2(skill_id, mob_skills[i].skill_lv); + + /** Delay: Remove the stock 5 secs and add half of the support time. **/ + mob_skills[i].delay += -5000 + (time1 + time2) / 2; + + if (mob_skills[i].delay < 2000) + mob_skills[i].delay = 2000; /// With a minimum of 2 seconds. + + if (i + 1 < MAX_MOBSKILL) { /// Duplicate this so it also triggers on self. + memcpy(&mob_skills[i + 1], &mob_skills[i], sizeof(struct mob_skill)); db->maxskill = ++i; - ms[i].target = MST_SELF; - ms[i].cond1 = MSC_MYHPLTMAXRATE; + mob_skills[i].target = MST_SELF; + mob_skills[i].cond1 = MSC_MYHPLTMAXRATE; } } else { - switch (skill_id) { //Certain Special skills that are passive, and thus, never triggered. - case MO_TRIPLEATTACK: - case TF_DOUBLE: - case GS_CHAINACTION: - ms[i].state = MSS_BERSERK; - ms[i].target = MST_TARGET; - ms[i].cond1 = MSC_ALWAYS; - ms[i].permillage = skill_id==MO_TRIPLEATTACK?(3000-ms[i].skill_lv*100):(ms[i].skill_lv*500); - ms[i].delay -= 5000; //Remove the added delay as these could trigger on "all hits". - break; - default: //Untreated Skill - continue; + switch (skill_id) { /// Certain special skills that are passive, and thus, never triggered. + case MO_TRIPLEATTACK: + FALLTHROUGH + case TF_DOUBLE: + FALLTHROUGH + case GS_CHAINACTION: + mob_skills[i].state = MSS_BERSERK; + mob_skills[i].target = MST_TARGET; + mob_skills[i].cond1 = MSC_ALWAYS; + + if (skill_id == MO_TRIPLEATTACK) + mob_skills[i].permillage = 3000 - mob_skills[i].skill_lv * 100; + else + mob_skills[i].permillage = mob_skills[i].skill_lv * 500; + + mob_skills[i].delay -= 5000; /// Remove the added delay as these could trigger on "all hits". + break; + default: /// Untreated skill. + continue; } } - if (battle_config.mob_skill_rate!= 100) - ms[i].permillage = ms[i].permillage*battle_config.mob_skill_rate/100; - if (battle_config.mob_skill_delay != 100) - ms[i].delay = ms[i].delay*battle_config.mob_skill_delay/100; + mob_skills[i].permillage *= battle_config.mob_skill_rate / 100; + mob_skills[i].delay *= battle_config.mob_skill_delay / 100; db->maxskill = ++i; } - /** - * We grant the session it's fd value back. - **/ - sd->fd = fd; + sd->fd = fd; /// We grant the session it's fd value back. + + /// Finally spawn it. + struct mob_data *md = mob->once_spawn_sub(&sd->bl, m, x, y, DEFAULT_MOB_NAME, class_, event, SZ_SMALL, AI_NONE, 0); - //Finally, spawn it. - md = mob->once_spawn_sub(&sd->bl, m, x, y, DEFAULT_MOB_NAME, class_, event, SZ_SMALL, AI_NONE); - if (!md) return 0; //Failed? + if (md == NULL) + return 0; /// Failed? md->special_state.clone = 1; - if (master_id || flag || duration) { //Further manipulate crafted char. - if (flag&1) //Friendly Character - md->special_state.ai = AI_ATTACK; - if (master_id) //Attach to Master - md->master_id = master_id; - if (duration) //Auto Delete after a while. - { - if( md->deletetimer != INVALID_TIMER ) - timer->delete(md->deletetimer, mob->timer_delete); - md->deletetimer = timer->add(timer->gettick() + duration, mob->timer_delete, md->bl.id, 0); - } + if (flag == 1) /// Friendly character. + md->special_state.ai = AI_ATTACK; + + if (master_id != 0) /// Attach to master. + md->master_id = master_id; + + if (duration > 0) { /// Auto delete after a while. + if (md->deletetimer != INVALID_TIMER) + timer->delete(md->deletetimer, mob->timer_delete); + + md->deletetimer = timer->add(timer->gettick() + duration, mob->timer_delete, md->bl.id, 0); } mob->spawn(md); - return md->bl.id; } diff --git a/src/map/mob.h b/src/map/mob.h index 8fd16f191..8839809f2 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -255,6 +255,7 @@ struct mob_data { int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs) unsigned int bg_id; // BattleGround System int clan_id; // Clan System + int npc_id; // NPC ID if spawned with monster/areamonster/guardian/bg_monster/atcommand("@monster xy") (Used to kill mob on NPC unload.) int64 next_walktime, last_thinktime, last_linktime, last_pcneartime, dmgtick; short move_fail_count; @@ -507,14 +508,14 @@ struct mob_interface { int (*db_checkid) (const int id); struct view_data* (*get_viewdata) (int class_); int (*parse_dataset) (struct spawn_data *data); - struct mob_data* (*spawn_dataset) (struct spawn_data *data); + struct mob_data* (*spawn_dataset) (struct spawn_data *data, int npc_id); int (*get_random_id) (int type, int flag, int lv); bool (*ksprotected) (struct block_list *src, struct block_list *target); - struct mob_data* (*once_spawn_sub) (struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai); + struct mob_data* (*once_spawn_sub) (struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai, int npc_id); int (*once_spawn) (struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai); int (*once_spawn_area) (struct map_session_data *sd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai); - int (*spawn_guardian) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, int guardian, bool has_index); - int (*spawn_bg) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, unsigned int bg_id); + int (*spawn_guardian) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, int guardian, bool has_index, int npc_id); + int (*spawn_bg) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, unsigned int bg_id, int npc_id); int (*can_reach) (struct mob_data *md, struct block_list *bl, int range, int state); int (*linksearch) (struct block_list *bl, va_list ap); int (*delayspawn) (int tid, int64 tick, int id, intptr_t data); diff --git a/src/map/npc.c b/src/map/npc.c index cc588e52c..d369aca82 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1457,7 +1457,11 @@ static int npc_cashshop_buylist(struct map_session_data *sd, int points, struct return ERROR_TYPE_NPC; if( nd->subtype != CASHSHOP ) { - if (nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER) { + if (nd->subtype == SCRIPT && nd->u.scr.shop && + nd->u.scr.shop->type != NST_ZENY && + nd->u.scr.shop->type != NST_MARKET && + nd->u.scr.shop->type != NST_BARTER && + nd->u.scr.shop->type != NST_EXPANDED_BARTER) { shop = nd->u.scr.shop->item; shop_size = nd->u.scr.shop->items; } else { @@ -1623,7 +1627,7 @@ static void npc_market_tosql(struct npc_data *nd, int index) { nullpo_retv(nd); Assert_retv(index >= 0 && index < nd->u.scr.shop->items); - if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s','%d','%u')", + if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s','%d','%d')", map->npc_market_data_db, nd->exname, nd->u.scr.shop->item[index].nameid, nd->u.scr.shop->item[index].qty)) Sql_ShowDebug(map->mysql_handle); } @@ -1716,7 +1720,9 @@ static void npc_barter_tosql(struct npc_data *nd, int index) nullpo_retv(nd); Assert_retv(index >= 0 && index < nd->u.scr.shop->items); const struct npc_item_list *const item = &nd->u.scr.shop->item[index]; - if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s', '%d', '%u', '%u', '%d')", + if (item->qty == -1) + return; + if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s', '%d', '%d', '%u', '%d')", map->npc_barter_data_db, nd->exname, item->nameid, item->qty, item->value, item->value2)) { Sql_ShowDebug(map->mysql_handle); } @@ -1753,6 +1759,178 @@ static void npc_barter_delfromsql(struct npc_data *nd, int index) } } + +/** + * Loads persistent NPC Expanded Barter Data from SQL + **/ +static void npc_expanded_barter_fromsql(void) +{ + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + char name[NAME_LENGTH + 1]; + int itemid; + int amount; + int zeny; + StringBuf buf; + + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `name`, `itemId`, `amount`, `zeny`"); + for (int k = 1; k < 11; k ++) { + StrBuf->Printf(&buf, ", `currencyId%d`, `currencyAmount%d`, `currencyRefine%d`", k, k, k); + } + StrBuf->Printf(&buf, " FROM `%s`", map->npc_expanded_barter_data_db); + + if (SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) + || SQL_ERROR == SQL->StmtExecute(stmt) + ) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return; + } + + struct npc_barter_currency tempCurrency[10]; + SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name, sizeof name, NULL, NULL); + SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &itemid, sizeof itemid, NULL, NULL); + SQL->StmtBindColumn(stmt, 2, SQLDT_UINT32, &amount, sizeof amount, NULL, NULL); + SQL->StmtBindColumn(stmt, 3, SQLDT_UINT32, &zeny, sizeof zeny, NULL, NULL); + for (int k = 0; k < 10; k ++) { + SQL->StmtBindColumn(stmt, k * 3 + 4, SQLDT_INT, &tempCurrency[k].nameid, sizeof tempCurrency[k].nameid, NULL, NULL); + SQL->StmtBindColumn(stmt, k * 3 + 5, SQLDT_INT, &tempCurrency[k].amount, sizeof tempCurrency[k].amount, NULL, NULL); + SQL->StmtBindColumn(stmt, k * 3 + 6, SQLDT_INT, &tempCurrency[k].refine, sizeof tempCurrency[k].refine, NULL, NULL); + } + + while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { + struct npc_data *nd = NULL; + unsigned short i; + + if ((nd = npc->name2id(name)) == NULL) { + ShowError("npc_expanded_barter_fromsql: NPC '%s' not found! skipping...\n",name); + npc->expanded_barter_delfromsql_sub(name, INT_MAX, 0, 0, NULL); + continue; + } else if (nd->subtype != SCRIPT || nd->u.scr.shop == NULL || nd->u.scr.shop->items == 0 || nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + ShowError("npc_expanded_barter_fromsql: NPC '%s' is not proper for barter, skipping...\n",name); + npc->expanded_barter_delfromsql_sub(name, INT_MAX, 0, 0, NULL); + continue; + } + + for (i = 0; i < nd->u.scr.shop->items; i++) { + struct npc_item_list *const item = &nd->u.scr.shop->item[i]; + if (item->nameid == itemid && item->value == zeny) { + int count = nd->u.scr.shop->item[i].value2; + if (count > 10) + count = 10; + int curIndex; + for (curIndex = 0; curIndex < count; curIndex ++) { + struct npc_barter_currency *currency = &nd->u.scr.shop->item[i].currency[curIndex]; + struct npc_barter_currency *currency2 = &tempCurrency[curIndex]; + if (currency->nameid != currency2->nameid || + currency->amount != currency2->amount || + currency->refine != currency2->refine) { + break; + } + } + if (curIndex == count) { + item->qty = amount; + break; + } + } + } + + if (i == nd->u.scr.shop->items) { + ShowError("npc_expanded_barter_fromsql: NPC '%s' does not sell item %d (qty %d), deleting...\n", name, itemid, amount); + npc->expanded_barter_delfromsql_sub(name, itemid, zeny, 10, &tempCurrency[0]); + continue; + } + } + SQL->StmtFree(stmt); + StrBuf->Destroy(&buf); +} + +/** + * Saves persistent NPC Expanded Barter Data into SQL + **/ +static void npc_expanded_barter_tosql(struct npc_data *nd, int index) +{ + nullpo_retv(nd); + Assert_retv(index >= 0 && index < nd->u.scr.shop->items); + const struct npc_item_list *const item = &nd->u.scr.shop->item[index]; + if (item->qty == -1) + return; + + npc->expanded_barter_delfromsql(nd, index); + + StringBuf buf; + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` VALUES ('%s', '%d', '%d', '%u'", map->npc_expanded_barter_data_db, nd->exname, item->nameid, item->qty, item->value); + int currencyCount = item->value2; + if (currencyCount > 10) + currencyCount = 10; + int k; + for (k = 0; k < currencyCount; k++) { + struct npc_barter_currency *currency = &item->currency[k]; + StrBuf->Printf(&buf, ", '%d', '%d', '%d'", currency->nameid, currency->amount, currency->refine); + } + for (; k < 10; k ++) { + StrBuf->Printf(&buf, ", '0', '0', '0'"); + } + StrBuf->AppendStr(&buf, ")"); + + if (SQL_ERROR == SQL->QueryStr(map->mysql_handle, StrBuf->Value(&buf))) { + Sql_ShowDebug(map->mysql_handle); + } + StrBuf->Destroy(&buf); +} + +/** + * Removes persistent NPC Expanded Barter Data from SQL + */ +static void npc_expanded_barter_delfromsql_sub(const char *npcname, int itemId, int zeny, int currencyCount, struct npc_barter_currency* currency) +{ + if (itemId == INT_MAX) { + if (SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `name`='%s'", map->npc_expanded_barter_data_db, npcname)) + Sql_ShowDebug(map->mysql_handle); + } else { + StringBuf buf; + + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "DELETE FROM `%s` WHERE `name`='%s' AND `itemId`='%d' AND `zeny`='%d'", + map->npc_expanded_barter_data_db, npcname, itemId, zeny); + int k = 0; + if (currencyCount > 10) + currencyCount = 10; + for (k = 0; k < currencyCount; k++) { + struct npc_barter_currency *currency1 = ¤cy[k]; + StrBuf->Printf(&buf, " AND currencyId%d='%d' and currencyAmount%d='%d' and currencyRefine%d='%d'", + k + 1, currency1->nameid, k + 1, currency1->amount, k + 1, currency1->refine); + } + for (; k < 10; k ++) { + StrBuf->Printf(&buf, " AND currencyId%d='0' and currencyAmount%d='0' and currencyRefine%d='0'", + k + 1, k + 1, k + 1); + } + StrBuf->AppendStr(&buf, " LIMIT 1"); + + if (SQL_ERROR == SQL->QueryStr(map->mysql_handle, StrBuf->Value(&buf))) { + Sql_ShowDebug(map->mysql_handle); + } + StrBuf->Destroy(&buf); + } +} + + +/** + * Removes persistent NPC Expanded Barter Data from SQL + **/ +static void npc_expanded_barter_delfromsql(struct npc_data *nd, int index) +{ + nullpo_retv(nd); + if (index == INT_MAX) { + npc->expanded_barter_delfromsql_sub(nd->exname, INT_MAX, 0, 0, NULL); + } else { + Assert_retv(index >= 0 && index < nd->u.scr.shop->items); + const struct npc_item_list *const item = &nd->u.scr.shop->item[index]; + npc->expanded_barter_delfromsql_sub(nd->exname, item->nameid, item->value, item->value2, &item->currency[0]); + } +} + /** * Judges whether to allow and spawn a trader's window. **/ @@ -1788,6 +1966,9 @@ static bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) case NST_BARTER: clif->npc_barter_open(sd, nd); break; + case NST_EXPANDED_BARTER: + clif->npc_expanded_barter_open(sd, nd); + break; default: clif->cashshop_show(sd,nd); break; @@ -1914,7 +2095,11 @@ static int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, return ERROR_TYPE_ITEM_ID; // Invalid Item if( nd->subtype != CASHSHOP ) { - if (nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER) { + if (nd->subtype == SCRIPT && nd->u.scr.shop && + nd->u.scr.shop->type != NST_ZENY && + nd->u.scr.shop->type != NST_MARKET && + nd->u.scr.shop->type != NST_BARTER && + nd->u.scr.shop->type != NST_EXPANDED_BARTER) { shop = nd->u.scr.shop->item; shop_size = nd->u.scr.shop->items; } else { @@ -2262,6 +2447,9 @@ static int npc_barter_buylist(struct map_session_data *sd, struct barteritemlist if (n < 0 || n >= sd->status.inventorySize) return 11; // wrong inventory index + if (entry->addAmount <= 0) + return 14; // not enough item amount in inventory + int removeId = sd->status.inventory[n].nameid; const int j = entry->shopIndex; if (j < 0 || j >= shop_size) @@ -2355,6 +2543,152 @@ static int npc_barter_buylist(struct map_session_data *sd, struct barteritemlist return 12; } + +/** + * Processes incoming npc expanded barter purchase list + **/ +static int npc_expanded_barter_buylist(struct map_session_data *sd, struct barteritemlist *item_list) +{ + nullpo_retr(1, sd); + nullpo_retr(1, item_list); + + struct npc_data* nd = npc->checknear(sd, map->id2bl(sd->npc_shopid)); + + if (nd == NULL || nd->subtype != SCRIPT || VECTOR_LENGTH(*item_list) == 0 || + !nd->u.scr.shop || nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + return 11; + } + + struct npc_item_list *shop = nd->u.scr.shop->item; + unsigned short shop_size = nd->u.scr.shop->items; + int w = 0; + int new_ = 0; + int64 z = 0; + int items[MAX_INVENTORY] = { 0 }; + + // process entries in buy list, one by one + for (int i = 0; i < VECTOR_LENGTH(*item_list); ++i) { + struct barter_itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); + + if (entry->addAmount <= 0) + return 14; // not enough item amount in inventory + + const int j = entry->shopIndex; + if (j < 0 || j >= shop_size) + return 13; // no such item in shop + if (entry->addId != shop[j].nameid && entry->addId != itemdb_viewid(shop[j].nameid)) + return 13; // no such item in shop + entry->addId = shop[j].nameid; // item_avail replacement + if (!itemdb->exists(entry->addId)) + return 13; // item no longer in itemdb + + if ((int)shop[j].qty != -1 && entry->addAmount > (int)shop[j].qty) + return 14; // not enough item amount in shop + + int currencyCount = shop[j].value2; + for (int currencyIndex = 0; currencyIndex < currencyCount; currencyIndex ++) { + struct npc_barter_currency *currency = &shop[j].currency[currencyIndex]; + const int currencyItemId = currency->nameid; + const int currencyRefine = currency->refine; + int removeAmount = currency->amount * entry->addAmount; + if (removeAmount <= 0) + continue; + for (int n = 0; n < sd->status.inventorySize && removeAmount > 0; ++n) { + // check item id and existing amount + if (sd->status.inventory[n].nameid == currencyItemId && sd->status.inventory[n].amount > 0) { + // check item refine level + if (currencyRefine != -1 && sd->status.inventory[n].refine != currencyRefine) + continue; + if (sd->status.inventory[n].amount >= removeAmount) { + items[n] += removeAmount; + removeAmount = 0; + w -= itemdb_weight(currencyItemId) * removeAmount; + break; + } else { + items[n] += sd->status.inventory[n].amount; + removeAmount -= sd->status.inventory[n].amount; + w -= itemdb_weight(currencyItemId) * sd->status.inventory[n].amount; + } + } + if (items[n] > sd->status.inventory[n].amount) + return 14; // not enough item amount in inventory + } + if (removeAmount != 0) { + return 14; // not enough item amount in inventory + } + } + + entry->addId = shop[j].nameid; //item_avail replacement + + npc_market_qty[i] = j; + + if (!itemdb->isstackable(entry->addId) && entry->addAmount > 1) { + //Exploit? You can't buy more than 1 of equipment types o.O + ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy %d of non-stackable item %d!\n", + sd->status.name, sd->status.account_id, sd->status.char_id, entry->addAmount, entry->addId); + entry->addAmount = 1; + } + + switch (pc->checkadditem(sd, entry->addId, entry->addAmount)) { + case ADDITEM_EXIST: + break; + case ADDITEM_NEW: + new_++; + break; + case ADDITEM_OVERAMOUNT: /* TODO find official response for this */ + return 1; + } + + z += (int64)shop[j].value * entry->addAmount; + w += itemdb_weight(entry->addId) * entry->addAmount; + } + + if (z > sd->status.zeny) + return 3; // Not enough Zeny + + if ((int64)w + sd->weight > sd->max_weight) + return 2; // Too heavy + + if (pc->inventoryblank(sd) < new_) + return 3; // Not enough space to store items + + for (int i = 0; i < sd->status.inventorySize; ++i) { + const int removeAmountTotal = items[i]; + if (removeAmountTotal == 0) + continue; + if (pc->delitem(sd, i, removeAmountTotal, 0, DELITEM_SOLD, LOG_TYPE_NPC) != 0) { + return 11; // unknown exploit + } + } + + pc->payzeny(sd, (int)z, LOG_TYPE_NPC, NULL); + + for (int i = 0; i < VECTOR_LENGTH(*item_list); ++i) { + struct barter_itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); + const int shopIdx = npc_market_qty[i]; + + if ((int)shop[shopIdx].qty != -1) { + if (entry->addAmount > (int)shop[shopIdx].qty) /* wohoo someone tampered with the packet. */ + return 14; + shop[shopIdx].qty -= entry->addAmount; + } + + npc->expanded_barter_tosql(nd, shopIdx); + + if (itemdb_type(entry->addId) == IT_PETEGG) { + pet->create_egg(sd, entry->addId); + } else { + struct item item_tmp; + memset(&item_tmp, 0, sizeof(item_tmp)); + item_tmp.nameid = entry->addId; + item_tmp.identify = 1; + pc->additem(sd, &item_tmp, entry->addAmount, LOG_TYPE_NPC); + } + } + + return 12; +} + /// npc_selllist for script-controlled shops static int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd) { @@ -2601,121 +2935,193 @@ static int npc_unload_ev_label(union DBKey key, struct DBData *data, va_list ap) return 0; } -//Chk if npc matches src_id, then unload. -//Sub-function used to find duplicates. +/** + * Unloads a NPC if it's a duplicate of the passed one. + * + * @param nd The NPC to check. + * @param args List of arguments. + * @return Always 0. + * + **/ static int npc_unload_dup_sub(struct npc_data *nd, va_list args) { - int src_id; - nullpo_ret(nd); - src_id = va_arg(args, int); + + const int src_id = va_arg(args, int); + const int unload_mobs = va_arg(args, int); + if (nd->src_id == src_id) - npc->unload(nd, true); + npc->unload(nd, true, (unload_mobs == 1)); + return 0; } -//Removes all npcs that are duplicates of the passed one. [Skotlex] -static void npc_unload_duplicates(struct npc_data *nd) +/** + * Unloads all NPCs which are duplicates of the passed one. + * + * @param nd The source NPC. + * @param unload_mobs If true, mobs spawned by duplicates will be removed. + * + * @author Skotlex + * + **/ +static void npc_unload_duplicates(struct npc_data *nd, bool unload_mobs) { nullpo_retv(nd); - map->foreachnpc(npc->unload_dup_sub,nd->bl.id); + + map->foreachnpc(npc->unload_dup_sub, nd->bl.id, unload_mobs); } -//Removes an npc from map and db. -//Single is to free name (for duplicates). -static int npc_unload(struct npc_data *nd, bool single) +/** + * Removes a mob, which was spawned by a NPC (monster/areamonster/guardian/bg_monster/atcommand("@monster xy")). + * + * @param md The mob to remove. + * @param args List of arguments. + * @return 1 on success, 0 on failure. + * + * @author Kenpachi + * + **/ +static int npc_unload_mob(struct mob_data *md, va_list args) +{ + nullpo_ret(md); + + const int npc_id = va_arg(args, int); + + if (md->npc_id == npc_id) { + md->state.npc_killmonster = 1; + status_kill(&md->bl); + return 1; + } + + return 0; +} + +/** + * Removes a NPC from map and database. + * + * @param nd The NPC which should be removed. + * @param single If true, names are freed. (For duplicates.) + * @param unload_mobs If true, mobs spawned by the NPC will be removed. + * @return Always 0. + * + **/ +static int npc_unload(struct npc_data *nd, bool single, bool unload_mobs) { nullpo_ret(nd); - if( nd->ud && nd->ud != &npc->base_ud ) { + if (nd->ud != NULL && nd->ud != &npc->base_ud) skill->clear_unitgroup(&nd->bl); - } npc->remove_map(nd); map->deliddb(&nd->bl); - if( single ) + + if (single) strdb_remove(npc->name_db, nd->exname); - if (nd->chat_id) // remove npc chatroom object and kick users + if (nd->chat_id != 0) /// Remove NPC chatroom object and kick users. chat->delete_npc_chat(nd); - npc_chat->finalize(nd); // deallocate npc PCRE data structures + npc_chat->finalize(nd); /// Deallocate NPC PCRE data structures. if (single && nd->path != NULL) { npc->releasepathreference(nd->path); nd->path = NULL; } - if (single && nd->bl.m != -1) + if (single && nd->bl.m != INDEX_NOT_FOUND) map->remove_questinfo(nd->bl.m, nd); + npc->questinfo_clear(nd); - if (nd->src_id == 0 && ( nd->subtype == SHOP || nd->subtype == CASHSHOP)) { - //src check for duplicate shops [Orcao] - aFree(nd->u.shop.shop_item); + if (nd->src_id == 0 && (nd->subtype == SHOP || nd->subtype == CASHSHOP)) { + aFree(nd->u.shop.shop_item); /// src check for duplicate shops. [Orcao] } else if (nd->subtype == SCRIPT) { - struct s_mapiterator *iter; - struct map_session_data *sd = NULL; + char evname[EVENT_NAME_LENGTH]; + + snprintf(evname, ARRAYLENGTH(evname), "%s::OnNPCUnload", nd->exname); + + struct event_data *ev = strdb_get(npc->ev_db, evname); + + if (ev != NULL) + script->run_npc(nd->u.scr.script, ev->pos, 0, nd->bl.id); /// Run OnNPCUnload. - if( single ) { - npc->ev_db->foreach(npc->ev_db,npc->unload_ev,nd->exname); //Clean up all events related - npc->ev_label_db->foreach(npc->ev_label_db,npc->unload_ev_label,nd); + if (single) { + npc->ev_db->foreach(npc->ev_db, npc->unload_ev, nd->exname); /// Clean up all related events. + npc->ev_label_db->foreach(npc->ev_label_db, npc->unload_ev_label, nd); } - iter = mapit_geteachpc(); - for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { - if (sd->npc_timer_id != INVALID_TIMER ) { + struct s_mapiterator *iter = mapit_geteachpc(); + struct map_session_data *sd = BL_UCAST(BL_PC, mapit->first(iter)); + + for (; mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (sd->npc_timer_id != INVALID_TIMER) { const struct TimerData *td = timer->get(sd->npc_timer_id); - if( td && td->id != nd->bl.id ) + if (td != NULL && td->id != nd->bl.id) continue; - if( td && td->data ) + if (td != NULL && td->data != 0) ers_free(npc->timer_event_ers, (void*)td->data); + timer->delete(sd->npc_timer_id, npc->timerevent); sd->npc_timer_id = INVALID_TIMER; } } + mapit->free(iter); if (nd->u.scr.timerid != INVALID_TIMER) { - const struct TimerData *td; - td = timer->get(nd->u.scr.timerid); - if (td && td->data) + const struct TimerData *td = timer->get(nd->u.scr.timerid); + + if (td != NULL && td->data != 0) ers_free(npc->timer_event_ers, (void*)td->data); + timer->delete(nd->u.scr.timerid, npc->timerevent); } - if (nd->u.scr.timer_event) + + if (nd->u.scr.timer_event != NULL) aFree(nd->u.scr.timer_event); + if (nd->src_id == 0) { - if(nd->u.scr.script) { + if (nd->u.scr.script != NULL) { script->free_code(nd->u.scr.script); nd->u.scr.script = NULL; } - if (nd->u.scr.label_list) { + + if (nd->u.scr.label_list != NULL) { aFree(nd->u.scr.label_list); nd->u.scr.label_list = NULL; nd->u.scr.label_list_num = 0; } - if(nd->u.scr.shop) { - if(nd->u.scr.shop->item) + + if (nd->u.scr.shop != NULL) { + if (nd->u.scr.shop->item != NULL) { + for (int i = 0; i < nd->u.scr.shop->items; i ++) { + if (nd->u.scr.shop->item[i].currency != NULL) + aFree(nd->u.scr.shop->item[i].currency); + } aFree(nd->u.scr.shop->item); + } + aFree(nd->u.scr.shop); } } - if( nd->u.scr.guild_id ) + + if (nd->u.scr.guild_id > 0) guild->flag_remove(nd); } - if( nd->ud && nd->ud != &npc->base_ud ) { + if (nd->ud != NULL && nd->ud != &npc->base_ud) { aFree(nd->ud); nd->ud = NULL; } - HPM->data_store_destroy(&nd->hdata); + if (unload_mobs) + map->foreachmob(npc->unload_mob, nd->bl.id); + HPM->data_store_destroy(&nd->hdata); aFree(nd); - return 0; } @@ -4092,18 +4498,23 @@ static const char *npc_parse_function(const char *w1, const char *w2, const char return end; } -/*========================================== - * Parse Mob 1 - Parse mob list into each map - * Parse Mob 2 - Actually Spawns Mob - * [Wizputer] - *------------------------------------------*/ +/** + * Spawns a mob by using the passed spawn data. (Permanent mob spawns.) + * npc_parse_mob() - Parses mob list into each map. + * npc_parse_mob2() - Actually spawns mob. + * + * @param mobspawn The mobs spawn data. + * + * @author Wizputer + * + **/ static void npc_parse_mob2(struct spawn_data *mobspawn) { - int i; - nullpo_retv(mobspawn); - for( i = mobspawn->active; i < mobspawn->num; ++i ) { - struct mob_data* md = mob->spawn_dataset(mobspawn); + + for (int i = mobspawn->active; i < mobspawn->num; ++i) { + struct mob_data *md = mob->spawn_dataset(mobspawn, 0); + md->spawn = mobspawn; md->spawn->active++; mob->spawn(md); @@ -5160,128 +5571,143 @@ static void npc_process_files(int npc_min) npc->npc_id - npc_min, npc->npc_warp, npc->npc_shop, npc->npc_script, npc->npc_mob, npc->npc_cache_mob, npc->npc_delay_mob); } -//Clear then reload npcs files +/** + * Clears and then reloads all NPC files. + * + * @return Always 0. + * + **/ static int npc_reload(void) { - int npc_new_min = npc->npc_id; - struct s_mapiterator* iter; - struct block_list* bl; - - if (map->retval == EXIT_FAILURE) - map->retval = EXIT_SUCCESS; // Clear return status in case something failed before. - - /* clear guild flag cache */ - guild->flags_clear(); + if (map->retval == EXIT_FAILURE) /// Clear return status in case something failed before. + map->retval = EXIT_SUCCESS; + guild->flags_clear(); /// Clear guild flag cache. npc->path_db->clear(npc->path_db, npc->path_db_clear_sub); - db_clear(npc->name_db); db_clear(npc->ev_db); npc->ev_label_db->clear(npc->ev_label_db, npc->ev_label_db_clear_sub); - npc->npc_last_npd = NULL; npc->npc_last_path = NULL; npc->npc_last_ref = NULL; + + const int npc_new_min = npc->npc_id; + struct s_mapiterator *iter = mapit_geteachiddb(); - //Remove all npcs/mobs. [Skotlex] - iter = mapit_geteachiddb(); - for (bl = mapit->first(iter); mapit->exists(iter); bl = mapit->next(iter)) { - switch(bl->type) { - case BL_NPC: - if( bl->id != npc->fake_nd->bl.id )// don't remove fake_nd - npc->unload(BL_UCAST(BL_NPC, bl), false); - break; - case BL_MOB: - unit->free(bl,CLR_OUTSIGHT); - break; + /** Remove all NPCs/mobs. [Skotlex] **/ + for (struct block_list *bl = mapit->first(iter); mapit->exists(iter); bl = mapit->next(iter)) { + switch (bl->type) { + case BL_NPC: + if (bl->id != npc->fake_nd->bl.id) /// Don't remove fake_nd. + npc->unload(BL_UCAST(BL_NPC, bl), false, false); + + break; + case BL_MOB: + unit->free(bl, CLR_OUTSIGHT); + break; + default: + break; } } + mapit->free(iter); - if(battle_config.dynamic_mobs) {// dynamic check by [random] - int16 m; - for (m = 0; m < map->count; m++) { - int16 i; - for (i = 0; i < MAX_MOB_LIST_PER_MAP; i++) { + if (battle_config.dynamic_mobs) { /// Dynamic check. [random] + for (int m = 0; m < map->count; m++) { + for (int i = 0; i < MAX_MOB_LIST_PER_MAP; i++) { if (map->list[m].moblist[i] != NULL) { aFree(map->list[m].moblist[i]); map->list[m].moblist[i] = NULL; } - if( map->list[m].mob_delete_timer != INVALID_TIMER ) - { // Mobs were removed anyway,so delete the timer [Inkfish] + + if (map->list[m].mob_delete_timer != INVALID_TIMER) { /// Mobs were removed anyway, so delete the timer. [Inkfish] timer->delete(map->list[m].mob_delete_timer, map->removemobs_timer); map->list[m].mob_delete_timer = INVALID_TIMER; } } + if (map->list[m].npc_num > 0) - ShowWarning("npc_reload: %d npcs weren't removed at map %s!\n", map->list[m].npc_num, map->list[m].name); + ShowWarning("npc_reload: %d NPCs weren't removed from map %s!\n", + map->list[m].npc_num, map->list[m].name); } } - // clear mob spawn lookup index mob->clear_spawninfo(); - - npc->npc_warp = npc->npc_shop = npc->npc_script = 0; - npc->npc_mob = npc->npc_cache_mob = npc->npc_delay_mob = 0; - - // reset mapflags + npc->npc_warp = 0; + npc->npc_shop = 0; + npc->npc_script = 0; + npc->npc_mob = 0; + npc->npc_cache_mob = 0; + npc->npc_delay_mob = 0; map->zone_reload(); map->flags_init(); - - // Reprocess npc files and reload constants itemdb->name_constants(); clan->set_constants(); - npc_process_files( npc_new_min ); - + npc_process_files(npc_new_min); instance->reload(); - map->zone_init(); - - npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */ - - //Re-read the NPC Script Events cache. + npc->motd = npc->name2id("HerculesMOTD"); /// [Ind/Hercules] npc->read_event_script(); - // Execute main initialisation events - // The correct initialisation order is: - // OnInit -> OnInterIfInit -> OnInterIfInitOnce -> OnAgitInit -> OnAgitInit2 - npc->event_do_oninit( true ); + /** + * Execute main initialization events + * The correct initialization order is: + * OnInit -> OnInterIfInit -> OnInterIfInitOnce -> OnAgitInit -> OnAgitInit2 + * + **/ + npc->event_do_oninit(true); + npc->market_fromsql(); npc->barter_fromsql(); - // Execute rest of the startup events if connected to char-server. [Lance] - // Executed when connection is established with char-server in chrif_connectack - if( !intif->CheckForCharServer() ) { - ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInit")); - ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInitOnce")); - } - // Refresh guild castle flags on both woe setups - // These events are only executed after receiving castle information from char-server + npc->expanded_barter_fromsql(); + + /* + * Execute rest of the startup events if connected to char-server. [Lance] + * Executed when connection is established with char-server in chrif_connectack(). + */ + if (intif->CheckForCharServer() == 0) { + ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", + npc->event_doall("OnInterIfInit")); + ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", + npc->event_doall("OnInterIfInitOnce")); + } + + /* + * Refresh guild castle flags on both WoE setups. + * These events are only executed after receiving castle information from char-server. + */ npc->event_doall("OnAgitInit"); npc->event_doall("OnAgitInit2"); return 0; } -//Unload all npc in the given file -static bool npc_unloadfile(const char *filepath) +/** + * Unloads all NPCs in the given file. + * + * @param filepath Path to the file which should be unloaded. + * @param unload_mobs If true, mobs spawned by NPCs in the file will be removed. + * @return true if at least one NPC was unloaded, otherwise false. + * + **/ +static bool npc_unloadfile(const char *filepath, bool unload_mobs) { + nullpo_retr(false, filepath); + struct DBIterator *iter = db_iterator(npc->name_db); - struct npc_data* nd = NULL; bool found = false; - nullpo_retr(false, filepath); - - for( nd = dbi_first(iter); dbi_exists(iter); nd = dbi_next(iter) ) { - if( nd->path && strcasecmp(nd->path,filepath) == 0 ) { // FIXME: This can break in case-sensitive file systems + for (struct npc_data *nd = dbi_first(iter); dbi_exists(iter); nd = dbi_next(iter)) { + if (nd->path != NULL && strcasecmp(nd->path, filepath) == 0) { // FIXME: This can break in case-sensitive file systems. found = true; - npc->unload_duplicates(nd);/* unload any npcs which could duplicate this but be in a different file */ - npc->unload(nd, true); + npc->unload_duplicates(nd, unload_mobs); /// Unload any NPC which could duplicate this but be in a different file. + npc->unload(nd, true, unload_mobs); } } dbi_destroy(iter); - if( found ) /* refresh event cache */ + if (found) /// Refresh event cache. npc->read_event_script(); return found; @@ -5514,6 +5940,7 @@ void npc_defaults(void) npc->unload_ev_label = npc_unload_ev_label; npc->unload_dup_sub = npc_unload_dup_sub; npc->unload_duplicates = npc_unload_duplicates; + npc->unload_mob = npc_unload_mob; npc->unload = npc_unload; npc->clearsrcfile = npc_clearsrcfile; npc->addsrcfile = npc_addsrcfile; @@ -5567,6 +5994,7 @@ void npc_defaults(void) npc->trader_update = npc_trader_update; npc->market_buylist = npc_market_buylist; npc->barter_buylist = npc_barter_buylist; + npc->expanded_barter_buylist = npc_expanded_barter_buylist; npc->trader_open = npc_trader_open; npc->market_fromsql = npc_market_fromsql; npc->market_tosql = npc_market_tosql; @@ -5576,6 +6004,10 @@ void npc_defaults(void) npc->barter_tosql = npc_barter_tosql; npc->barter_delfromsql = npc_barter_delfromsql; npc->barter_delfromsql_sub = npc_barter_delfromsql_sub; + npc->expanded_barter_fromsql = npc_expanded_barter_fromsql; + npc->expanded_barter_tosql = npc_expanded_barter_tosql; + npc->expanded_barter_delfromsql = npc_expanded_barter_delfromsql; + npc->expanded_barter_delfromsql_sub = npc_expanded_barter_delfromsql_sub; npc->db_checkid = npc_db_checkid; npc->refresh = npc_refresh; npc->questinfo_clear = npc_questinfo_clear; diff --git a/src/map/npc.h b/src/map/npc.h index c5f44f0e0..65c9796d9 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -48,6 +48,7 @@ enum npc_shop_types { NST_MARKET, /* official npc market type */ NST_CUSTOM, NST_BARTER, /* official npc barter type */ + NST_EXPANDED_BARTER, /* official npc expanded barter type */ /* */ NST_MAX, }; @@ -60,17 +61,25 @@ struct npc_label_list { int pos; }; +struct npc_barter_currency { + int nameid; + int refine; + int amount; +}; + struct npc_item_list { int nameid; unsigned int value; // price or barter currency item id - int value2; // barter currency item amount - unsigned int qty; + int value2; // barter currency item amount / expanded barter currency size + int qty; + struct npc_barter_currency *currency; }; struct npc_shop_data { unsigned char type;/* what am i */ struct npc_item_list *item;/* list */ unsigned int items;/* total */ + int shop_last_index; // only for NST_EXPANDED_BARTER }; struct npc_parse; struct npc_data { @@ -261,8 +270,9 @@ struct npc_interface { int (*unload_ev) (union DBKey key, struct DBData *data, va_list ap); int (*unload_ev_label) (union DBKey key, struct DBData *data, va_list ap); int (*unload_dup_sub) (struct npc_data *nd, va_list args); - void (*unload_duplicates) (struct npc_data *nd); - int (*unload) (struct npc_data *nd, bool single); + void (*unload_duplicates) (struct npc_data *nd, bool unload_mobs); + int (*unload_mob) (struct mob_data *md, va_list args); + int (*unload) (struct npc_data *nd, bool single, bool unload_mobs); void (*clearsrcfile) (void); void (*addsrcfile) (const char *name); void (*delsrcfile) (const char *name); @@ -304,7 +314,7 @@ struct npc_interface { int (*path_db_clear_sub) (union DBKey key, struct DBData *data, va_list args); int (*ev_label_db_clear_sub) (union DBKey key, struct DBData *data, va_list args); int (*reload) (void); - bool (*unloadfile) (const char *filepath); + bool (*unloadfile) (const char *filepath, bool unload_mobs); void (*do_clear_npc) (void); void (*debug_warps_sub) (struct npc_data *nd); void (*debug_warps) (void); @@ -314,6 +324,7 @@ struct npc_interface { void (*trader_update) (int master); enum market_buy_result (*market_buylist) (struct map_session_data *sd, struct itemlist *item_list); int (*barter_buylist) (struct map_session_data *sd, struct barteritemlist *item_list); + int (*expanded_barter_buylist) (struct map_session_data *sd, struct barteritemlist *item_list); bool (*trader_open) (struct map_session_data *sd, struct npc_data *nd); void (*market_fromsql) (void); void (*market_tosql) (struct npc_data *nd, int index); @@ -323,6 +334,10 @@ struct npc_interface { void (*barter_tosql) (struct npc_data *nd, int index); void (*barter_delfromsql) (struct npc_data *nd, int index); void (*barter_delfromsql_sub) (const char *npcname, int itemId, int itemId2, int amount2); + void (*expanded_barter_fromsql) (void); + void (*expanded_barter_tosql) (struct npc_data *nd, int index); + void (*expanded_barter_delfromsql) (struct npc_data *nd, int index); + void (*expanded_barter_delfromsql_sub) (const char *npcname, int itemId, int zeny, int currencyCount, struct npc_barter_currency* currency); bool (*db_checkid) (const int id); void (*refresh) (struct npc_data* nd); void (*questinfo_clear) (struct npc_data *nd); diff --git a/src/map/packets.h b/src/map/packets.h index 90b9beeb7..1e6dc71bc 100644 --- a/src/map/packets.h +++ b/src/map/packets.h @@ -1983,6 +1983,11 @@ packet(0x96e,clif->ackmergeitems); packet(0x0b4c,clif->pCashShopLimitedReq); #endif +#if PACKETVER_MAIN_NUM >= 20190904 || PACKETVER_RE_NUM >= 20190904 || PACKETVER_ZERO_NUM >= 20190828 + packet(0x0b57,clif->pNPCExpandedBarterPurchase); + packet(0x0b58,clif->pNPCExpandedBarterClosed); +#endif + #if PACKETVER >= 20191224 packet(0x0b6d,clif->pCashShopOpen2); #endif diff --git a/src/map/packets_keys_main.h b/src/map/packets_keys_main.h index 1d5f96ee9..a72d9bf5f 100644 --- a/src/map/packets_keys_main.h +++ b/src/map/packets_keys_main.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ packetKeys(0x49357d72,0x22c370a1,0x5f836591); #endif -// 2010-11-23aRagexeRE, 2010-11-24aRagexeRE, 2010-11-24bRagexeRE, 2010-11-25aRagexeRE, 2010-11-26aRagexeRE, 2010-11-30aRagexeRE, 2010-12-07aRagexeRE, 2010-12-14aRagexeRE, 2010-12-21aRagexeRE, 2010-12-23aRagexeRE, 2010-12-28aRagexeRE, 2011-01-04aRagexeRE, 2011-01-05aRagexeRE, 2011-01-11aRagexeRE, 2011-01-18aRagexeRE, 2011-01-25aRagexeRE, 2011-01-26aRagexeRE, 2011-01-26bRagexeRE, 2011-01-31aRagexeRE, 2011-01-31bRagexeRE, 2011-01-31cRagexeRE, 2011-02-08aRagexeRE, 2011-02-15aRagexeRE, 2011-02-22aRagexeRE, 2011-02-23aRagexeRE, 2011-02-23bRagexeRE, 2011-02-24aRagexeRE, 2011-02-25aRagexeRE, 2011-02-28aRagexeRE, 2011-03-08aRagexeRE, 2011-03-09aRagexeRE, 2011-03-09bRagexeRE, 2011-03-09cRagexeRE, 2011-03-09dRagexeRE, 2011-03-15aRagexeRE, 2011-03-22aRagexeRE, 2011-03-29aRagexeRE, 2011-03-30aRagexeRE, 2011-03-30cRagexeRE, 2011-04-05aRagexeRE, 2011-04-12aRagexeRE, 2011-04-19aRagexeRE, 2011-04-20aRagexeRE, 2011-04-26aRagexeRE, 2011-04-27aRagexeRE, 2011-05-03aRagexeRE, 2011-05-11aRagexeRE, 2011-05-17bRagexeRE, 2011-05-24aRagexeRE, 2011-05-26aRagexeRE, 2011-05-31aRagexeRE, 2011-06-07aRagexeRE, 2011-06-08aRagexeRE, 2011-06-08bRagexeRE, 2011-06-08cRagexeRE, 2011-06-09aRagexeRE, 2011-06-14bRagexeRE, 2011-06-22aRagexeRE, 2011-06-28aRagexeRE, 2011-07-06aRagexeRE, 2011-07-13aRagexeRE, 2011-07-13bRagexeRE, 2011-07-13cRagexeRE, 2011-07-19aRagexeRE, 2011-07-26aRagexeRE, 2011-08-03aRagexeRE, 2011-08-03bRagexeRE, 2011-08-10aRagexeRE, 2013-12-23aRagexeRE, 2014-05-08aRagexe, 2014-05-08aRagexeRE, 2014-06-11eRagexe, 2015-02-25hRagexe, 2018-03-15aRagexe, 2018-03-21aRagexe, 2018-03-21aRagexeRE, 2018-03-28bRagexe, 2018-03-28bRagexeRE, 2018-04-04bRagexe, 2018-04-04cRagexeRE, 2018-04-18aRagexe, 2018-04-18bRagexeRE, 2018-04-25cRagexe, 2018-04-25cRagexeRE, 2018-05-02bRagexe, 2018-05-02bRagexeRE, 2018-05-02dRagexeRE, 2018-05-09aRagexe, 2018-05-16cRagexe, 2018-05-16cRagexeRE, 2018-05-23aRagexe, 2018-05-23aRagexeRE, 2018-05-30aRagexe, 2018-05-30bRagexeRE, 2018-05-30cRagexeRE, 2018-06-05bRagexe, 2018-06-05bRagexeRE, 2018-06-12aRagexeRE, 2018-06-12bRagexeRE, 2018-06-20cRagexe, 2018-06-20dRagexeRE, 2018-06-20eRagexe, 2018-06-20eRagexeRE, 2018-06-21aRagexe, 2018-06-21aRagexeRE, 2018-07-04aRagexe, 2018-07-04aRagexeRE, 2018-07-11aRagexeRE, 2018-07-18bRagexe, 2018-07-18bRagexeRE, 2018-07-18bRagexeRE1, 2018-07-18cRagexe, 2018-07-18cRagexeRE, 2018-08-01cRagexe, 2018-08-01cRagexeRE, 2018-08-08bRagexe, 2018-08-08bRagexeRE, 2018-08-22cRagexe, 2018-08-22cRagexeRE, 2018-08-29aRagexe, 2018-08-29aRagexeRE, 2018-08-29bRagexeRE, 2018-08-31aRagexe, 2018-09-12dRagexe, 2018-09-12dRagexeRE, 2018-09-19aRagexe, 2018-09-19aRagexeRE, 2018-10-02aRagexe, 2018-10-02aRagexeRE, 2018-10-02bRagexe, 2018-10-02bRagexeRE, 2018-10-17_02aRagexe, 2018-10-17_02aRagexeRE, 2018-10-17_03aRagexe, 2018-10-17_03aRagexeRE, 2018-10-17bRagexe, 2018-10-17bRagexeRE, 2018-10-24bRagexe, 2018-10-31aRagexe, 2018-10-31bRagexe, 2018-10-31cRagexeRE, 2018-11-07aRagexe, 2018-11-07aRagexeRE, 2018-11-14cRagexe, 2018-11-14cRagexeRE, 2018-11-14dRagexe, 2018-11-14dRagexeRE, 2018-11-21bRagexe, 2018-11-21cRagexeRE, 2018-11-28aRagexe, 2018-11-28aRagexeRE, 2018-11-28bRagexe, 2018-11-28cRagexe, 2018-12-05aRagexe, 2018-12-05bRagexeRE, 2018-12-12aRagexe, 2018-12-12aRagexeRE, 2018-12-12bRagexe, 2018-12-12bRagexeRE, 2018-12-19bRagexe, 2018-12-19bRagexeRE, 2018-12-26aRagexe, 2018-12-26aRagexeRE, 2019-01-09aRagexe, 2019-01-09bRagexeRE, 2019-01-16bRagexe, 2019-01-16bRagexeRE, 2019-01-16cRagexe, 2019-01-16cRagexeRE, 2019-01-23dRagexe, 2019-01-23dRagexeRE, 2019-02-13IRagexeRE, 2019-02-13bRagexe, 2019-02-13eRagexe, 2019-02-20aRagexeRE, 2019-02-27aRagexe, 2019-02-27bRagexeRE, 2019-02-28aRagexe, 2019-02-28aRagexeRE, 2019-03-06bRagexe, 2019-03-06bRagexeRE, 2019-03-06cRagexe, 2019-03-06cRagexeRE, 2019-03-13aRagexe, 2019-03-20aRagexe, 2019-03-20aRagexeRE, 2019-03-22aRagexe, 2019-03-22aRagexeRE, 2019-03-27bRagexe, 2019-03-27bRagexeRE, 2019-04-03aRagexe, 2019-04-03bRagexeRE, 2019-04-03cRagexeRE, 2019-04-17aRagexe, 2019-04-17cRagexeRE, 2019-04-18aRagexe, 2019-04-18aRagexeRE, 2019-05-08cRagexe, 2019-05-08dRagexeRE, 2019-05-08eRagexeRE, 2019-05-22bRagexe, 2019-05-22bRagexeRE, 2019-05-22cRagexe, 2019-05-22cRagexeRE, 2019-05-23aRagexe, 2019-05-29aRagexe, 2019-05-29bRagexeRE, 2019-05-29cRagexe, 2019-05-29cRagexeRE, 2019-05-30aRagexe, 2019-05-30aRagexeRE, 2019-06-05JRagexeRE, 2019-06-05KRagexe, 2019-06-05LRagexeRE, 2019-06-05fRagexe, 2019-06-05hRagexeRE, 2019-06-19bRagexe, 2019-06-19cRagexeRE, 2019-06-19eRagexe, 2019-06-19hRagexe, 2019-06-26bRagexeRE, 2019-07-03aRagexe, 2019-07-03bRagexeRE, 2019-07-17aRagexe, 2019-07-17cRagexeRE, 2019-07-17dRagexe, 2019-07-17dRagexeRE, 2019-07-24aRagexe, 2019-07-24bRagexeRE, 2019-07-31bRagexe, 2019-07-31bRagexeRE, 2019-08-02aRagexe, 2019-08-02aRagexeRE, 2019-08-07aRagexe, 2019-08-07dRagexeRE, 2019-08-21aRagexe, 2019-08-21cRagexeRE, 2019-08-21dRagexeRE, 2019-08-28aRagexe, 2019-08-28aRagexeRE, 2019-09-04aRagexe, 2019-09-04bRagexe, 2019-09-04bRagexeRE, 2019-09-18bRagexe, 2019-09-18cRagexeRE, 2019-09-25aRagexe, 2019-09-25aRagexeRE, 2019-09-25bRagexe, 2019-09-25bRagexeRE, 2019-10-02bRagexeRE, 2019-10-02cRagexe, 2019-10-02dRagexe, 2019-10-02dRagexeRE, 2019-10-02dRagexeRE_2, 2019-10-16fRagexe, 2019-10-16fRagexeRE, 2019-10-16gRagexe, 2019-10-16gRagexeRE, 2019-10-18aRagexe, 2019-10-23aRagexe, 2019-10-23aRagexeRE, 2019-10-30bRagexeRE, 2019-10-30cRagexe, 2019-11-06aRagexe, 2019-11-06bRagexeRE, 2019-11-07aRagexe, 2019-11-07aRagexeRE, 2019-11-13cRagexe, 2019-11-13eRagexe, 2019-11-13eRagexeRE, 2019-11-20aRagexe, 2019-11-20cRagexeRE, 2019-11-20dRagexe, 2019-11-27aRagexe, 2019-11-27aRagexeRE, 2019-11-27bRagexe, 2019-12-04aRagexe, 2019-12-04aRagexeRE, 2019-12-04bRagexe, 2019-12-04bRagexeRE, 2019-12-04cRagexeRE, 2019-12-11aRagexe, 2019-12-11fRagexeRE, 2019-12-18bRagexe, 2019-12-18bRagexeRE, 2019-12-24aRagexe, 2019-12-24aRagexeRE, 2019-12-24bRagexe, 2019-12-24bRagexeRE, 2020-01-08aRagexe, 2020-01-08bRagexeRE +// 2010-11-23aRagexeRE, 2010-11-24aRagexeRE, 2010-11-24bRagexeRE, 2010-11-25aRagexeRE, 2010-11-26aRagexeRE, 2010-11-30aRagexeRE, 2010-12-07aRagexeRE, 2010-12-14aRagexeRE, 2010-12-21aRagexeRE, 2010-12-23aRagexeRE, 2010-12-28aRagexeRE, 2011-01-04aRagexeRE, 2011-01-05aRagexeRE, 2011-01-11aRagexeRE, 2011-01-18aRagexeRE, 2011-01-25aRagexeRE, 2011-01-26aRagexeRE, 2011-01-26bRagexeRE, 2011-01-31aRagexeRE, 2011-01-31bRagexeRE, 2011-01-31cRagexeRE, 2011-02-08aRagexeRE, 2011-02-15aRagexeRE, 2011-02-22aRagexeRE, 2011-02-23aRagexeRE, 2011-02-23bRagexeRE, 2011-02-24aRagexeRE, 2011-02-25aRagexeRE, 2011-02-28aRagexeRE, 2011-03-08aRagexeRE, 2011-03-09aRagexeRE, 2011-03-09bRagexeRE, 2011-03-09cRagexeRE, 2011-03-09dRagexeRE, 2011-03-15aRagexeRE, 2011-03-22aRagexeRE, 2011-03-29aRagexeRE, 2011-03-30aRagexeRE, 2011-03-30cRagexeRE, 2011-04-05aRagexeRE, 2011-04-12aRagexeRE, 2011-04-19aRagexeRE, 2011-04-20aRagexeRE, 2011-04-26aRagexeRE, 2011-04-27aRagexeRE, 2011-05-03aRagexeRE, 2011-05-11aRagexeRE, 2011-05-17bRagexeRE, 2011-05-24aRagexeRE, 2011-05-26aRagexeRE, 2011-05-31aRagexeRE, 2011-06-07aRagexeRE, 2011-06-08aRagexeRE, 2011-06-08bRagexeRE, 2011-06-08cRagexeRE, 2011-06-09aRagexeRE, 2011-06-14bRagexeRE, 2011-06-22aRagexeRE, 2011-06-28aRagexeRE, 2011-07-06aRagexeRE, 2011-07-13aRagexeRE, 2011-07-13bRagexeRE, 2011-07-13cRagexeRE, 2011-07-19aRagexeRE, 2011-07-26aRagexeRE, 2011-08-03aRagexeRE, 2011-08-03bRagexeRE, 2011-08-10aRagexeRE, 2013-12-23aRagexeRE, 2014-05-08aRagexe, 2014-05-08aRagexeRE, 2014-06-11eRagexe, 2015-02-25hRagexe, 2018-03-15aRagexe, 2018-03-21aRagexe, 2018-03-21aRagexeRE, 2018-03-28bRagexe, 2018-03-28bRagexeRE, 2018-04-04bRagexe, 2018-04-04cRagexeRE, 2018-04-18aRagexe, 2018-04-18bRagexeRE, 2018-04-25cRagexe, 2018-04-25cRagexeRE, 2018-05-02bRagexe, 2018-05-02bRagexeRE, 2018-05-02dRagexeRE, 2018-05-09aRagexe, 2018-05-16cRagexe, 2018-05-16cRagexeRE, 2018-05-23aRagexe, 2018-05-23aRagexeRE, 2018-05-30aRagexe, 2018-05-30bRagexeRE, 2018-05-30cRagexeRE, 2018-06-05bRagexe, 2018-06-05bRagexeRE, 2018-06-12aRagexeRE, 2018-06-12bRagexeRE, 2018-06-20cRagexe, 2018-06-20dRagexeRE, 2018-06-20eRagexe, 2018-06-20eRagexeRE, 2018-06-21aRagexe, 2018-06-21aRagexeRE, 2018-07-04aRagexe, 2018-07-04aRagexeRE, 2018-07-11aRagexeRE, 2018-07-18bRagexe, 2018-07-18bRagexeRE, 2018-07-18bRagexeRE1, 2018-07-18cRagexe, 2018-07-18cRagexeRE, 2018-08-01cRagexe, 2018-08-01cRagexeRE, 2018-08-08bRagexe, 2018-08-08bRagexeRE, 2018-08-22cRagexe, 2018-08-22cRagexeRE, 2018-08-29aRagexe, 2018-08-29aRagexeRE, 2018-08-29bRagexeRE, 2018-08-31aRagexe, 2018-09-12dRagexe, 2018-09-12dRagexeRE, 2018-09-19aRagexe, 2018-09-19aRagexeRE, 2018-10-02aRagexe, 2018-10-02aRagexeRE, 2018-10-02bRagexe, 2018-10-02bRagexeRE, 2018-10-17_02aRagexe, 2018-10-17_02aRagexeRE, 2018-10-17_03aRagexe, 2018-10-17_03aRagexeRE, 2018-10-17bRagexe, 2018-10-17bRagexeRE, 2018-10-24bRagexe, 2018-10-31aRagexe, 2018-10-31bRagexe, 2018-10-31cRagexeRE, 2018-11-07aRagexe, 2018-11-07aRagexeRE, 2018-11-14cRagexe, 2018-11-14cRagexeRE, 2018-11-14dRagexe, 2018-11-14dRagexeRE, 2018-11-21bRagexe, 2018-11-21cRagexeRE, 2018-11-28aRagexe, 2018-11-28aRagexeRE, 2018-11-28bRagexe, 2018-11-28cRagexe, 2018-12-05aRagexe, 2018-12-05bRagexeRE, 2018-12-12aRagexe, 2018-12-12aRagexeRE, 2018-12-12bRagexe, 2018-12-12bRagexeRE, 2018-12-19bRagexe, 2018-12-19bRagexeRE, 2018-12-26aRagexe, 2018-12-26aRagexeRE, 2019-01-09aRagexe, 2019-01-09bRagexeRE, 2019-01-16bRagexe, 2019-01-16bRagexeRE, 2019-01-16cRagexe, 2019-01-16cRagexeRE, 2019-01-23dRagexe, 2019-01-23dRagexeRE, 2019-02-13IRagexeRE, 2019-02-13bRagexe, 2019-02-13eRagexe, 2019-02-20aRagexeRE, 2019-02-27aRagexe, 2019-02-27bRagexeRE, 2019-02-28aRagexe, 2019-02-28aRagexeRE, 2019-03-06bRagexe, 2019-03-06bRagexeRE, 2019-03-06cRagexe, 2019-03-06cRagexeRE, 2019-03-13aRagexe, 2019-03-20aRagexe, 2019-03-20aRagexeRE, 2019-03-22aRagexe, 2019-03-22aRagexeRE, 2019-03-27bRagexe, 2019-03-27bRagexeRE, 2019-04-03aRagexe, 2019-04-03bRagexeRE, 2019-04-03cRagexeRE, 2019-04-17aRagexe, 2019-04-17cRagexeRE, 2019-04-18aRagexe, 2019-04-18aRagexeRE, 2019-05-08cRagexe, 2019-05-08dRagexeRE, 2019-05-08eRagexeRE, 2019-05-22bRagexe, 2019-05-22bRagexeRE, 2019-05-22cRagexe, 2019-05-22cRagexeRE, 2019-05-23aRagexe, 2019-05-29aRagexe, 2019-05-29bRagexeRE, 2019-05-29cRagexe, 2019-05-29cRagexeRE, 2019-05-30aRagexe, 2019-05-30aRagexeRE, 2019-06-05JRagexeRE, 2019-06-05KRagexe, 2019-06-05LRagexeRE, 2019-06-05fRagexe, 2019-06-05hRagexeRE, 2019-06-19bRagexe, 2019-06-19cRagexeRE, 2019-06-19eRagexe, 2019-06-19hRagexe, 2019-06-26bRagexeRE, 2019-07-03aRagexe, 2019-07-03bRagexeRE, 2019-07-17aRagexe, 2019-07-17cRagexeRE, 2019-07-17dRagexe, 2019-07-17dRagexeRE, 2019-07-24aRagexe, 2019-07-24bRagexeRE, 2019-07-31bRagexe, 2019-07-31bRagexeRE, 2019-08-02aRagexe, 2019-08-02aRagexeRE, 2019-08-07aRagexe, 2019-08-07dRagexeRE, 2019-08-21aRagexe, 2019-08-21cRagexeRE, 2019-08-21dRagexeRE, 2019-08-28aRagexe, 2019-08-28aRagexeRE, 2019-09-04aRagexe, 2019-09-04bRagexe, 2019-09-04bRagexeRE, 2019-09-18bRagexe, 2019-09-18cRagexeRE, 2019-09-25aRagexe, 2019-09-25aRagexeRE, 2019-09-25bRagexe, 2019-09-25bRagexeRE, 2019-10-02bRagexeRE, 2019-10-02cRagexe, 2019-10-02dRagexe, 2019-10-02dRagexeRE, 2019-10-02dRagexeRE_2, 2019-10-16fRagexe, 2019-10-16fRagexeRE, 2019-10-16gRagexe, 2019-10-16gRagexeRE, 2019-10-18aRagexe, 2019-10-23aRagexe, 2019-10-23aRagexeRE, 2019-10-30bRagexeRE, 2019-10-30cRagexe, 2019-11-06aRagexe, 2019-11-06bRagexeRE, 2019-11-07aRagexe, 2019-11-07aRagexeRE, 2019-11-13cRagexe, 2019-11-13eRagexe, 2019-11-13eRagexeRE, 2019-11-20aRagexe, 2019-11-20cRagexeRE, 2019-11-20dRagexe, 2019-11-27aRagexe, 2019-11-27aRagexeRE, 2019-11-27bRagexe, 2019-12-04aRagexe, 2019-12-04aRagexeRE, 2019-12-04bRagexe, 2019-12-04bRagexeRE, 2019-12-04cRagexeRE, 2019-12-11aRagexe, 2019-12-11fRagexeRE, 2019-12-18bRagexe, 2019-12-18bRagexeRE, 2019-12-24aRagexe, 2019-12-24aRagexeRE, 2019-12-24bRagexe, 2019-12-24bRagexeRE, 2020-01-08aRagexe, 2020-01-08bRagexeRE, 2020-01-22cRagexe, 2020-01-22cRagexeRE, 2020-01-29bRagexe, 2020-01-30aRagexe, 2020-02-05aRagexe, 2020-02-05aRagexeRE, 2020-02-06aRagexe #if PACKETVER == 20101123 || \ PACKETVER == 20101124 || \ PACKETVER == 20101125 || \ @@ -181,7 +181,12 @@ PACKETVER == 20191211 || \ PACKETVER == 20191218 || \ PACKETVER == 20191224 || \ - PACKETVER >= 20200108 + PACKETVER == 20200108 || \ + PACKETVER == 20200122 || \ + PACKETVER == 20200129 || \ + PACKETVER == 20200130 || \ + PACKETVER == 20200205 || \ + PACKETVER >= 20200206 packetKeys(0x00000000,0x00000000,0x00000000); #endif diff --git a/src/map/packets_keys_zero.h b/src/map/packets_keys_zero.h index d4c96beca..90d226c92 100644 --- a/src/map/packets_keys_zero.h +++ b/src/map/packets_keys_zero.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ /* This file is autogenerated, please do not commit manual changes */ -// 2017-10-18aRagexe_zero, 2017-10-19aRagexe_zero, 2017-10-23aRagexe_zero, 2017-10-23bRagexe_zero, 2017-10-23cRagexe_zero, 2017-10-24aRagexe_2_zero, 2017-10-24aRagexe_zero, 2017-10-25bRagexe_zero, 2017-10-27aRagexe_zero, 2017-10-27bRagexe_zero, 2017-10-30aRagexe_zero, 2017-10-31aRagexe_zero, 2017-11-09aRagexe_zero, 2017-11-13aRagexe_zero, 2017-11-13bRagexe_zero, 2018-03-15aRagexe_zero, 2018-03-21aRagexe_zero, 2018-03-21bRagexe_zero, 2018-03-28_1aRagexe_zero, 2018-03-28cRagexe_zero, 2018-04-11aRagexe_zero, 2018-04-25_3aRagexe_zero, 2018-05-09_3aRagexe_zero, 2018-05-23aRagexe_zero, 2018-06-05bRagexe_zero, 2018-06-05cRagexe_zero, 2018-06-27aRagexe_zero, 2018-07-03aRagexe_zero, 2018-07-11_2aRagexe_zero, 2018-07-25_2aRagexe_zero, 2018-08-01aRagexe_zero, 2018-08-08_2aRagexe_zero, 2018-08-22aRagexe_zero, 2018-08-29aRagexe_zero, 2018-09-05aRagexe_zero, 2018-09-12aRagexe_zero, 2018-09-19aRagexe_zero, 2018-09-28aRagexe_zero, 2018-10-10_2aRagexe_zero, 2018-10-24_2aRagexe_zero, 2018-11-14aRagexe_zero, 2018-11-20aRagexe_zero, 2018-11-28aRagexe_zero, 2018-12-12aRagexe_zero, 2018-12-19aRagexe_zero, 2018-12-26_2aRagexe_zero, 2019-01-16_2aRagexe_zero, 2019-01-17_1aRagexe_zero, 2019-01-30_2aRagexe_zero, 2019-02-13aRagexe_zero, 2019-02-20aRagexe_zero, 2019-02-27aRagexe_zero, 2019-03-13aRagexe_zero, 2019-03-27_2aRagexe_zero, 2019-03-27_3aRagexe_zero, 2019-04-03aRagexe_zero, 2019-04-10bRagexe_zero, 2019-04-24aRagexe_zero, 2019-05-02aRagexe_zero, 2019-05-08_2aRagexe_zero, 2019-05-08aRagexe_zero, 2019-05-15aRagexe_zero, 2019-05-29aRagexe_zero, 2019-05-30aRagexe_zero, 2019-06-05_2aRagexe_zero, 2019-06-26_2aRagexe_zero, 2019-06-26_3aRagexe_zero, 2019-07-09aRagexe_zero, 2019-07-10_3aRagexe_zero, 2019-07-17aRagexe_zero, 2019-07-24aRagexe_zero, 2019-08-14_3aRagexe_zero, 2019-08-28_2aRagexe_zero, 2019-08-28_3aRagexe_zero, 2019-09-11aRagexe_zero, 2019-09-18_2aRagexe_zero, 2019-09-18aRagexe_zero, 2019-09-25_3aRagexe_zero, 2019-09-25_5aRagexe_zero, 2019-10-08_2aRagexe_zero, 2019-10-23_2aRagexe_zero, 2019-11-06aRagexe_zero, 2019-11-13aRagexe_zero, 2019-11-27_2aRagexe_zero, 2019-11-27aRagexe_zero, 2019-12-04aRagexe_zero, 2019-12-11_2aRagexe_zero, 2019-12-24_4aRagexe_zero, 2019-12-24_5aRagexe_zero +// 2017-10-18aRagexe_zero, 2017-10-19aRagexe_zero, 2017-10-23aRagexe_zero, 2017-10-23bRagexe_zero, 2017-10-23cRagexe_zero, 2017-10-24aRagexe_2_zero, 2017-10-24aRagexe_zero, 2017-10-25bRagexe_zero, 2017-10-27aRagexe_zero, 2017-10-27bRagexe_zero, 2017-10-30aRagexe_zero, 2017-10-31aRagexe_zero, 2017-11-09aRagexe_zero, 2017-11-13aRagexe_zero, 2017-11-13bRagexe_zero, 2018-03-15aRagexe_zero, 2018-03-21aRagexe_zero, 2018-03-21bRagexe_zero, 2018-03-28_1aRagexe_zero, 2018-03-28cRagexe_zero, 2018-04-11aRagexe_zero, 2018-04-25_3aRagexe_zero, 2018-05-09_3aRagexe_zero, 2018-05-23aRagexe_zero, 2018-06-05bRagexe_zero, 2018-06-05cRagexe_zero, 2018-06-27aRagexe_zero, 2018-07-03aRagexe_zero, 2018-07-11_2aRagexe_zero, 2018-07-25_2aRagexe_zero, 2018-08-01aRagexe_zero, 2018-08-08_2aRagexe_zero, 2018-08-22aRagexe_zero, 2018-08-29aRagexe_zero, 2018-09-05aRagexe_zero, 2018-09-12aRagexe_zero, 2018-09-19aRagexe_zero, 2018-09-28aRagexe_zero, 2018-10-10_2aRagexe_zero, 2018-10-24_2aRagexe_zero, 2018-11-14aRagexe_zero, 2018-11-20aRagexe_zero, 2018-11-28aRagexe_zero, 2018-12-12aRagexe_zero, 2018-12-19aRagexe_zero, 2018-12-26_2aRagexe_zero, 2019-01-16_2aRagexe_zero, 2019-01-17_1aRagexe_zero, 2019-01-30_2aRagexe_zero, 2019-02-13aRagexe_zero, 2019-02-20aRagexe_zero, 2019-02-27aRagexe_zero, 2019-03-13aRagexe_zero, 2019-03-27_2aRagexe_zero, 2019-03-27_3aRagexe_zero, 2019-04-03aRagexe_zero, 2019-04-10bRagexe_zero, 2019-04-24aRagexe_zero, 2019-05-02aRagexe_zero, 2019-05-08_2aRagexe_zero, 2019-05-08aRagexe_zero, 2019-05-15aRagexe_zero, 2019-05-29aRagexe_zero, 2019-05-30aRagexe_zero, 2019-06-05_2aRagexe_zero, 2019-06-26_2aRagexe_zero, 2019-06-26_3aRagexe_zero, 2019-07-09aRagexe_zero, 2019-07-10_3aRagexe_zero, 2019-07-17aRagexe_zero, 2019-07-24aRagexe_zero, 2019-08-14_3aRagexe_zero, 2019-08-28_2aRagexe_zero, 2019-08-28_3aRagexe_zero, 2019-09-11aRagexe_zero, 2019-09-18_2aRagexe_zero, 2019-09-18aRagexe_zero, 2019-09-25_3aRagexe_zero, 2019-09-25_5aRagexe_zero, 2019-10-08_2aRagexe_zero, 2019-10-23_2aRagexe_zero, 2019-11-06aRagexe_zero, 2019-11-13aRagexe_zero, 2019-11-27_2aRagexe_zero, 2019-11-27aRagexe_zero, 2019-12-04aRagexe_zero, 2019-12-11_2aRagexe_zero, 2019-12-24_4aRagexe_zero, 2019-12-24_5aRagexe_zero, 2020-01-15_2aRagexe_zero, 2020-01-15aRagexe_zero, 2020-01-29_2aRagexe_zero, 2020-01-29aRagexe_zero #if PACKETVER == 20171018 || \ PACKETVER == 20171019 || \ PACKETVER == 20171023 || \ @@ -103,7 +103,9 @@ PACKETVER == 20191127 || \ PACKETVER == 20191204 || \ PACKETVER == 20191211 || \ - PACKETVER >= 20191224 + PACKETVER == 20191224 || \ + PACKETVER == 20200115 || \ + PACKETVER >= 20200129 packetKeys(0x00000000,0x00000000,0x00000000); #endif diff --git a/src/map/packets_shuffle_main.h b/src/map/packets_shuffle_main.h index 83a9107f2..2d7f1d6ec 100644 --- a/src/map/packets_shuffle_main.h +++ b/src/map/packets_shuffle_main.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -9794,7 +9794,7 @@ packet(0x083c,clif->pSearchStoreInfoListItemClick,2,6,10); // CZ_SSILIST_ITEM_CLICK // 14 #endif -// 2019-09-04aRagexe, 2019-09-04bRagexe, 2019-09-18bRagexe, 2019-09-25aRagexe, 2019-09-25bRagexe, 2019-10-02cRagexe, 2019-10-02dRagexe, 2019-10-16fRagexe, 2019-10-16gRagexe, 2019-10-18aRagexe, 2019-10-23aRagexe, 2019-10-30cRagexe, 2019-11-06aRagexe, 2019-11-07aRagexe, 2019-11-13cRagexe, 2019-11-13eRagexe, 2019-11-20aRagexe, 2019-11-20dRagexe, 2019-11-27aRagexe, 2019-11-27bRagexe, 2019-12-04aRagexe, 2019-12-04bRagexe, 2019-12-11aRagexe, 2019-12-18bRagexe, 2019-12-24aRagexe, 2019-12-24bRagexe, 2020-01-08aRagexe +// 2019-09-04aRagexe, 2019-09-04bRagexe, 2019-09-18bRagexe, 2019-09-25aRagexe, 2019-09-25bRagexe, 2019-10-02cRagexe, 2019-10-02dRagexe, 2019-10-16fRagexe, 2019-10-16gRagexe, 2019-10-18aRagexe, 2019-10-23aRagexe, 2019-10-30cRagexe, 2019-11-06aRagexe, 2019-11-07aRagexe, 2019-11-13cRagexe, 2019-11-13eRagexe, 2019-11-20aRagexe, 2019-11-20dRagexe, 2019-11-27aRagexe, 2019-11-27bRagexe, 2019-12-04aRagexe, 2019-12-04bRagexe, 2019-12-11aRagexe, 2019-12-18bRagexe, 2019-12-24aRagexe, 2019-12-24bRagexe, 2020-01-08aRagexe, 2020-01-22cRagexe, 2020-01-29bRagexe, 2020-01-30aRagexe, 2020-02-05aRagexe, 2020-02-06aRagexe #if PACKETVER == 20190904 || \ PACKETVER == 20190918 || \ PACKETVER == 20190925 || \ @@ -9812,7 +9812,12 @@ PACKETVER == 20191211 || \ PACKETVER == 20191218 || \ PACKETVER == 20191224 || \ - PACKETVER == 20200108 + PACKETVER == 20200108 || \ + PACKETVER == 20200122 || \ + PACKETVER == 20200129 || \ + PACKETVER == 20200130 || \ + PACKETVER == 20200205 || \ + PACKETVER == 20200206 packet(0x0202,clif->pFriendsListAdd,2); // CZ_ADD_FRIENDS // 26 packet(0x022d,clif->pHomMenu,2,4); // CZ_COMMAND_MER // 5 packet(0x023b,clif->pStoragePassword,0); // CZ_ACK_STORE_PASSWORD // 36 diff --git a/src/map/packets_shuffle_re.h b/src/map/packets_shuffle_re.h index 9c9df85ed..757cfee55 100644 --- a/src/map/packets_shuffle_re.h +++ b/src/map/packets_shuffle_re.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -9744,7 +9744,7 @@ packet(0x083c,clif->pSearchStoreInfoListItemClick,2,6,10); // CZ_SSILIST_ITEM_CLICK // 14 #endif -// 2019-09-04bRagexeRE, 2019-09-18cRagexeRE, 2019-09-25aRagexeRE, 2019-09-25bRagexeRE, 2019-10-02bRagexeRE, 2019-10-02dRagexeRE, 2019-10-02dRagexeRE_2, 2019-10-16fRagexeRE, 2019-10-16gRagexeRE, 2019-10-23aRagexeRE, 2019-10-30bRagexeRE, 2019-11-06bRagexeRE, 2019-11-07aRagexeRE, 2019-11-13eRagexeRE, 2019-11-20cRagexeRE, 2019-11-27aRagexeRE, 2019-12-04aRagexeRE, 2019-12-04bRagexeRE, 2019-12-04cRagexeRE, 2019-12-11fRagexeRE, 2019-12-18bRagexeRE, 2019-12-24aRagexeRE, 2019-12-24bRagexeRE, 2020-01-08bRagexeRE +// 2019-09-04bRagexeRE, 2019-09-18cRagexeRE, 2019-09-25aRagexeRE, 2019-09-25bRagexeRE, 2019-10-02bRagexeRE, 2019-10-02dRagexeRE, 2019-10-02dRagexeRE_2, 2019-10-16fRagexeRE, 2019-10-16gRagexeRE, 2019-10-23aRagexeRE, 2019-10-30bRagexeRE, 2019-11-06bRagexeRE, 2019-11-07aRagexeRE, 2019-11-13eRagexeRE, 2019-11-20cRagexeRE, 2019-11-27aRagexeRE, 2019-12-04aRagexeRE, 2019-12-04bRagexeRE, 2019-12-04cRagexeRE, 2019-12-11fRagexeRE, 2019-12-18bRagexeRE, 2019-12-24aRagexeRE, 2019-12-24bRagexeRE, 2020-01-08bRagexeRE, 2020-01-22cRagexeRE, 2020-02-05aRagexeRE #if PACKETVER == 20190904 || \ PACKETVER == 20190918 || \ PACKETVER == 20190925 || \ @@ -9761,7 +9761,9 @@ PACKETVER == 20191211 || \ PACKETVER == 20191218 || \ PACKETVER == 20191224 || \ - PACKETVER == 20200108 + PACKETVER == 20200108 || \ + PACKETVER == 20200122 || \ + PACKETVER == 20200205 packet(0x0202,clif->pFriendsListAdd,2); // CZ_ADD_FRIENDS // 26 packet(0x022d,clif->pHomMenu,2,4); // CZ_COMMAND_MER // 5 packet(0x023b,clif->pStoragePassword,0); // CZ_ACK_STORE_PASSWORD // 36 diff --git a/src/map/packets_shuffle_zero.h b/src/map/packets_shuffle_zero.h index 91b0c1e89..602264a8f 100644 --- a/src/map/packets_shuffle_zero.h +++ b/src/map/packets_shuffle_zero.h @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2013-2020 Hercules Dev Team - * Copyright (C) 2018-2020 Andrei Karas (4144) + * Copyright (C) 2013-2020 Hercules Dev Team + * Copyright (C) 2018-2020 Andrei Karas (4144) * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -803,7 +803,7 @@ packet(0x083c,clif->pSearchStoreInfoListItemClick,2,6,10); // CZ_SSILIST_ITEM_CLICK // 14 #endif -// 2019-08-28_2aRagexe_zero, 2019-08-28_3aRagexe_zero, 2019-09-11aRagexe_zero, 2019-09-18_2aRagexe_zero, 2019-09-18aRagexe_zero, 2019-09-25_3aRagexe_zero, 2019-09-25_5aRagexe_zero, 2019-10-08_2aRagexe_zero, 2019-10-23_2aRagexe_zero, 2019-11-06aRagexe_zero, 2019-11-13aRagexe_zero, 2019-11-27_2aRagexe_zero, 2019-11-27aRagexe_zero, 2019-12-04aRagexe_zero, 2019-12-11_2aRagexe_zero, 2019-12-24_4aRagexe_zero, 2019-12-24_5aRagexe_zero +// 2019-08-28_2aRagexe_zero, 2019-08-28_3aRagexe_zero, 2019-09-11aRagexe_zero, 2019-09-18_2aRagexe_zero, 2019-09-18aRagexe_zero, 2019-09-25_3aRagexe_zero, 2019-09-25_5aRagexe_zero, 2019-10-08_2aRagexe_zero, 2019-10-23_2aRagexe_zero, 2019-11-06aRagexe_zero, 2019-11-13aRagexe_zero, 2019-11-27_2aRagexe_zero, 2019-11-27aRagexe_zero, 2019-12-04aRagexe_zero, 2019-12-11_2aRagexe_zero, 2019-12-24_4aRagexe_zero, 2019-12-24_5aRagexe_zero, 2020-01-15_2aRagexe_zero, 2020-01-15aRagexe_zero, 2020-01-29_2aRagexe_zero, 2020-01-29aRagexe_zero #if PACKETVER == 20190828 || \ PACKETVER == 20190911 || \ PACKETVER == 20190918 || \ @@ -815,7 +815,9 @@ PACKETVER == 20191127 || \ PACKETVER == 20191204 || \ PACKETVER == 20191211 || \ - PACKETVER == 20191224 + PACKETVER == 20191224 || \ + PACKETVER == 20200115 || \ + PACKETVER == 20200129 packet(0x0202,clif->pFriendsListAdd,2); // CZ_ADD_FRIENDS // 26 packet(0x022d,clif->pHomMenu,2,4); // CZ_COMMAND_MER // 5 packet(0x023b,clif->pStoragePassword,0); // CZ_ACK_STORE_PASSWORD // 36 diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 0fa602ba5..31b28e831 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -3770,7 +3770,7 @@ struct PACKET_CZ_SE_CASHSHOP_LIMITED_REQ { DEFINE_PACKET_HEADER(CZ_SE_CASHSHOP_LIMITED_REQ, 0x0b4c); #endif -#if PACKETVER_ZERO_NUM >= 20191224 +#if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224 struct PACKET_ZC_SE_CASHSHOP_OPEN { int16 packetType; uint32 cashPoints; @@ -3788,6 +3788,91 @@ struct PACKET_ZC_SE_CASHSHOP_OPEN { DEFINE_PACKET_HEADER(ZC_SE_CASHSHOP_OPEN, 0x0845); #endif +#if PACKETVER_MAIN_NUM >= 20190904 || PACKETVER_RE_NUM >= 20190904 || PACKETVER_ZERO_NUM >= 20190828 +struct PACKET_CZ_NPC_EXPANDED_BARTER_CLOSE { + int16 packetType; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(CZ_NPC_EXPANDED_BARTER_CLOSE, 0x0b58); +#endif + +#if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127 +struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2 { +#if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114 + uint32 nameid; +#else + uint16 nameid; +#endif + uint16 refine_level; + uint32 amount; + uint16 type; +} __attribute__((packed)); + +struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub { +#if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114 + uint32 nameid; +#else + uint16 nameid; +#endif + uint16 type; + uint32 amount; + uint32 weight; + uint32 index; + uint32 zeny; + uint32 currency_count; + struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2 currencies[]; +} __attribute__((packed)); + +struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN { + int16 packetType; + int16 packetLength; + int32 items_count; + struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub items[]; +} __attribute__((packed)); + +DEFINE_PACKET_HEADER(ZC_NPC_EXPANDED_BARTER_OPEN, 0x0b56); +#endif + +#if PACKETVER_MAIN_NUM >= 20190904 || PACKETVER_RE_NUM >= 20190904 || PACKETVER_ZERO_NUM >= 20190828 +struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE_sub { +#if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114 + uint32 itemId; +#else + uint16 itemId; +#endif + uint32 shopIndex; + uint32 amount; +} __attribute__((packed)); + +struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE { + int16 packetType; + int16 packetLength; + struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE_sub list[]; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(CZ_NPC_EXPANDED_BARTER_PURCHASE, 0x0b57); +#endif + +#if PACKETVER >= 7 +struct PACKET_ZC_STATE_CHANGE { + int16 packetType; + uint32 AID; + int16 bodyState; + int16 healthState; + int32 effectState; + int8 isPKModeON; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_STATE_CHANGE, 0x0229); +#else +struct PACKET_ZC_STATE_CHANGE { + int16 PacketType; + uint32 AID; + int16 bodyState; + int16 healthState; + int16 effectState; + int8 isPKModeON; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_STATE_CHANGE, 0x0119); +#endif + #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute #pragma pack(pop) #endif // not NetBSD < 6 / Solaris diff --git a/src/map/script.c b/src/map/script.c index 26bd678fe..b89176dba 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -12489,6 +12489,56 @@ static BUILDIN(hideonnpc) npc->enable(str,4); return true; } +/*========================================== + *------------------------------------------*/ +static BUILDIN(cloakonnpc) +{ + struct npc_data *nd = npc->name2id(script_getstr(st, 2)); + if (nd == NULL) { + ShowError("buildin_cloakonnpc: invalid npc name '%s'.\n", script_getstr(st, 2)); + return false; + } + + if (script_hasdata(st, 3)) { + struct map_session_data *sd = map->id2sd(script_getnum(st, 3)); + if (sd == NULL) + return false; + + uint32 val = nd->option; + nd->option |= OPTION_CLOAK; + clif->changeoption_target(&nd->bl, &sd->bl, SELF); + nd->option = val; + } else { + nd->option |= OPTION_CLOAK; + clif->changeoption(&nd->bl); + } + return true; +} +/*========================================== + *------------------------------------------*/ +static BUILDIN(cloakoffnpc) +{ + struct npc_data *nd = npc->name2id(script_getstr(st, 2)); + if (nd == NULL) { + ShowError("buildin_cloakoffnpc: invalid npc name '%s'.\n", script_getstr(st, 2)); + return false; + } + + if (script_hasdata(st, 3)) { + struct map_session_data *sd = map->id2sd(script_getnum(st, 3)); + if (sd == NULL) + return false; + + uint32 val = nd->option; + nd->option &= ~OPTION_CLOAK; + clif->changeoption_target(&nd->bl, &sd->bl, SELF); + nd->option = val; + } else { + nd->option &= ~OPTION_CLOAK; + clif->changeoption(&nd->bl); + } + return true; +} /* Starts a status effect on the target unit or on the attached player. * @@ -14526,47 +14576,53 @@ static BUILDIN(strmobinfo) return true; } -/*========================================== - * Summon guardians [Valaris] - * guardian("<map name>",<x>,<y>,"<name to show>",<mob id>{,"<event label>"}{,<guardian index>}) -> <id> - *------------------------------------------*/ +/** + * Summons a castle guardian mob. + * + * @code{.herc} + * guardian("<map name>", <x>, <y>, "<name to show>", <mob id>{, <guardian index>}); + * guardian("<map name>", <x>, <y>, "<name to show>", <mob id>{, "<event label>"{, <guardian index>}}); + * @endcode + * + * @author Valaris + * + **/ static BUILDIN(guardian) { - int class_ = 0, x = 0, y = 0, guardian = 0; - const char *str, *mapname, *evt=""; bool has_index = false; + int guardian = 0; + const char *event = ""; - mapname = script_getstr(st,2); - x = script_getnum(st,3); - y = script_getnum(st,4); - str = script_getstr(st,5); - class_ = script_getnum(st,6); - - if( script_hasdata(st,8) ) - {// "<event label>",<guardian index> - evt=script_getstr(st,7); - guardian=script_getnum(st,8); + if (script_hasdata(st, 8)) { /// "<event label>", <guardian index> + event = script_getstr(st, 7); + script->check_event(st, event); + guardian = script_getnum(st, 8); has_index = true; - } else if( script_hasdata(st,7) ) { - struct script_data *data = script_getdata(st,7); - script->get_val(st,data); // Dereference if it's a variable - if( data_isstring(data) ) { - // "<event label>" - evt=script_getstr(st,7); - } else if( data_isint(data) ) { - // <guardian index> - guardian=script_getnum(st,7); + } else if (script_hasdata(st, 7)) { + struct script_data *data = script_getdata(st, 7); + + script->get_val(st, data); /// Dereference if it's a variable. + + if (data_isstring(data)) { /// "<event label>" + event = script_getstr(st, 7); + script->check_event(st, event); + } else if (data_isint(data)) { /// <guardian index> + guardian = script_getnum(st, 7); has_index = true; } else { - ShowError("script:guardian: invalid data type for argument #6 (from 1)\n"); + ShowError("script:guardian: Invalid data type for argument #6!\n"); script->reportdata(data); return false; } } - script->check_event(st, evt); - script_pushint(st, mob->spawn_guardian(mapname,x,y,str,class_,evt,guardian,has_index)); + const char *mapname = script_getstr(st, 2); + const char *name = script_getstr(st, 5); + const int x = script_getnum(st, 3); + const int y = script_getnum(st, 4); + const int mob_id = script_getnum(st, 6); + script_pushint(st, mob->spawn_guardian(mapname, x, y, name, mob_id, event, guardian, has_index, st->oid)); return true; } /*========================================== @@ -16894,38 +16950,54 @@ static BUILDIN(logmes) return true; } +/** + * Summons a mob which will act as a slave for the invoking character. + * + * @code{.herc} + * summon("mob name", <mob id>{, <timeout>{, "event label"}}); + * @endcode + * + * @author Celest + * + **/ static BUILDIN(summon) { - int class_, timeout=0; - const char *str,*event=""; - struct mob_data *md; - int64 tick = timer->gettick(); struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; - str = script_getstr(st,2); - class_ = script_getnum(st,3); - if( script_hasdata(st,4) ) - timeout=script_getnum(st,4); - if( script_hasdata(st,5) ) { - event=script_getstr(st,5); + const int64 tick = timer->gettick(); + + clif->skill_poseffect(&sd->bl, AM_CALLHOMUN, 1, sd->bl.x, sd->bl.y, tick); + + const char *event = ""; + + if (script_hasdata(st, 5)) { + event = script_getstr(st, 5); script->check_event(st, event); } - clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick); + const char *name = script_getstr(st, 2); + const int mob_id = script_getnum(st, 3); + struct mob_data *md = mob->once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, name, mob_id, event, + SZ_SMALL, AI_NONE, 0); - md = mob->once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, class_, event, SZ_SMALL, AI_NONE); - if (md) { - md->master_id=sd->bl.id; + if (md != NULL) { + md->master_id = sd->bl.id; md->special_state.ai = AI_ATTACK; - if( md->deletetimer != INVALID_TIMER ) + + if (md->deletetimer != INVALID_TIMER) timer->delete(md->deletetimer, mob->timer_delete); - md->deletetimer = timer->add(tick+(timeout>0?timeout*1000:60000),mob->timer_delete,md->bl.id,0); - mob->spawn (md); //Now it is ready for spawning. - clif->specialeffect(&md->bl,344,AREA); + + const int timeout = script_hasdata(st, 4) ? script_getnum(st, 4) * 1000 : 60000; + + md->deletetimer = timer->add(tick + ((timeout == 0) ? 60000 : timeout), mob->timer_delete, md->bl.id, 0); + mob->spawn(md); + clif->specialeffect(&md->bl, 344, AREA); sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); } + return true; } @@ -22219,6 +22291,23 @@ static BUILDIN(achievement_progress) return true; } +static BUILDIN(achievement_iscompleted) +{ + struct map_session_data *sd = script_hasdata(st, 3) ? map->id2sd(script_getnum(st, 3)) : script->rid2sd(st); + if (sd == NULL) + return false; + + int aid = script_getnum(st, 2); + const struct achievement_data *ad = achievement->get(aid); + if (ad == NULL) { + ShowError("buildin_achievement_iscompleted: Invalid Achievement %d provided.\n", aid); + return false; + } + + script_pushint(st, achievement->check_complete(sd, ad)); + return true; +} + /*========================================== * BattleGround System *------------------------------------------*/ @@ -22340,20 +22429,31 @@ static BUILDIN(bg_warp) return true; } +/** + * Spawns a mob with allegiance to the given battle group. + * + * @code{.herc} + * bg_monster(<battle group>, "<map name>", <x>, <y>, "<name to show>", <mob id>{, "<event label>"}); + * @endcode + * + **/ static BUILDIN(bg_monster) { - int class_ = 0, x = 0, y = 0, bg_id = 0; - const char *str, *mapname, *evt=""; + const char *event = ""; - bg_id = script_getnum(st,2); - mapname = script_getstr(st,3); - x = script_getnum(st,4); - y = script_getnum(st,5); - str = script_getstr(st,6); - class_ = script_getnum(st,7); - if( script_hasdata(st,8) ) evt = script_getstr(st,8); - script->check_event(st, evt); - script_pushint(st, mob->spawn_bg(mapname,x,y,str,class_,evt,bg_id)); + if (script_hasdata(st, 8)) { + event = script_getstr(st, 8); + script->check_event(st, event); + } + + const char *mapname = script_getstr(st, 3); + const char *name = script_getstr(st, 6); + const int bg_id = script_getnum(st, 2); + const int x = script_getnum(st, 4); + const int y = script_getnum(st, 5); + const int mob_id = script_getnum(st, 7); + + script_pushint(st, mob->spawn_bg(mapname, x, y, name, mob_id, event, bg_id, st->oid)); return true; } @@ -24677,6 +24777,133 @@ static BUILDIN(openshop) return true; } +static bool script_sellitemcurrency_add(struct npc_data *nd, struct script_state* st, int argIndex) +{ + nullpo_retr(false, nd); + nullpo_retr(false, st); + + if (!script_hasdata(st, argIndex + 1)) + return false; + + int id = script_getnum(st, argIndex); + struct item_data *it; + if (!(it = itemdb->exists(id))) { + ShowWarning("buildin_sellitemcurrency: unknown item id '%d'!\n", id); + return false; + } + int qty = 0; + if ((qty = script_getnum(st, argIndex + 1)) <= 0) { + ShowError("buildin_sellitemcurrency: invalid 'qty'!\n"); + return false; + } + int refine_level = -1; + if (script_hasdata(st, argIndex + 2)) { + refine_level = script_getnum(st, argIndex + 2); + } + int items = nd->u.scr.shop->items; + if (nd->u.scr.shop == NULL || items == 0) { + ShowWarning("buildin_sellitemcurrency: shop not have items!\n"); + return false; + } + if (nd->u.scr.shop->shop_last_index >= items || nd->u.scr.shop->shop_last_index < 0) { + ShowWarning("buildin_sellitemcurrency: wrong selected shop index!\n"); + return false; + } + + struct npc_item_list *item_list = &nd->u.scr.shop->item[nd->u.scr.shop->shop_last_index]; + int index = item_list->value2; + if (item_list->currency == NULL) { + CREATE(item_list->currency, struct npc_barter_currency, 1); + item_list->value2 ++; + } else { + RECREATE(item_list->currency, struct npc_barter_currency, ++item_list->value2); + } + struct npc_barter_currency *currency = &item_list->currency[index]; + currency->nameid = id; + currency->refine = refine_level; + currency->amount = qty; + return true; +} + +/** + * @call sellitemcurrency <Item_ID>,qty{,refine}}; + * + * adds <Item_ID> to last item in expanded barter shop + **/ +static BUILDIN(sellitemcurrency) +{ + struct npc_data *nd; + if ((nd = map->id2nd(st->oid)) == NULL) { + ShowWarning("buildin_sellitemcurrency: trying to run without a proper NPC!\n"); + return false; + } + if (nd->u.scr.shop == NULL || nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + ShowWarning("buildin_sellitemcurrency: this command can be used only with expanded barter shops!\n"); + return false; + } + + script->sellitemcurrency_add(nd, st, 2); + return true; +} + +/** + * @call endsellitem; + * + * complete sell item in expanded barter shop (NST_EXPANDED_BARTER) + **/ +static BUILDIN(endsellitem) +{ + struct npc_data *nd; + if ((nd = map->id2nd(st->oid)) == NULL) { + ShowWarning("buildin_endsellitem: trying to run without a proper NPC!\n"); + return false; + } + if (nd->u.scr.shop == NULL || nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + ShowWarning("buildin_endsellitem: this command can be used only with expanded barter shops!\n"); + return false; + } + + int newIndex = nd->u.scr.shop->shop_last_index; + const struct npc_item_list *const newItem = &nd->u.scr.shop->item[newIndex]; + int i = 0; + for (i = 0; i < nd->u.scr.shop->items - 1; i++) { + const struct npc_item_list *const item = &nd->u.scr.shop->item[i]; + if (item->nameid != newItem->nameid || item->value != newItem->value) + continue; + if (item->value2 != newItem->value2) + continue; + bool found = true; + for (int k = 0; k < item->value2; k ++) { + struct npc_barter_currency *currency = &item->currency[k]; + struct npc_barter_currency *newCurrency = &newItem->currency[k]; + if (currency->nameid != newCurrency->nameid || + currency->amount != newCurrency->amount || + currency->refine != newCurrency->refine) { + found = false; + break; + } + } + if (!found) + continue; + break; + } + + if (i != nd->u.scr.shop->items - 1) { + if (nd->u.scr.shop->item[i].qty != -1) { + nd->u.scr.shop->item[i].qty += nd->u.scr.shop->item[newIndex].qty; + npc->expanded_barter_tosql(nd, i); + } + nd->u.scr.shop->shop_last_index --; + nd->u.scr.shop->items--; + if (nd->u.scr.shop->item[newIndex].currency != NULL) { + aFree(nd->u.scr.shop->item[newIndex].currency); + nd->u.scr.shop->item[newIndex].currency = NULL; + } + } + + return true; +} + /** * @call sellitem <Item_ID>,{,price{,qty}}; * @@ -24700,30 +24927,65 @@ static BUILDIN(sellitem) return false; } - if (!nd->u.scr.shop) { + const bool have_shop = (nd->u.scr.shop != NULL); + if (!have_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); + } + + 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_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 if (nd->u.scr.shop->type == NST_EXPANDED_BARTER) { + if (!script_hasdata(st, 4)) { + ShowError("buildin_sellitem: invalid number of parameters for expanded barter type shop!\n"); + return false; + } + if ((qty = script_getnum(st, 4)) <= 0 && qty != -1) { + ShowError("buildin_sellitem: invalid 'qty' for expanded barter type shop!\n"); + return false; } - } else {/* no need to run this if its empty */ + } + + if (have_shop) { 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 if (nd->u.scr.shop->type == NST_EXPANDED_BARTER) { + 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) + continue; + if (item->value2 != (script_lastdata(st) - 4) / 3) + continue; + bool found = true; + for (int k = 0; k < item->value2; k ++) { + const int scriptOffset = k * 3 + 5; + struct npc_barter_currency *currency = &item->currency[k]; + if (currency->nameid != script_getnum(st, scriptOffset) || + currency->amount != script_getnum(st, scriptOffset + 1) || + currency->refine != script_getnum(st, scriptOffset + 2)) { + found = false; + break; + } + } + if (!found) + continue; + break; + } } else { for (i = 0; i < nd->u.scr.shop->items; i++) { if (nd->u.scr.shop->item[i].nameid == id) { @@ -24733,12 +24995,6 @@ static BUILDIN(sellitem) } } - 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"); @@ -24759,7 +25015,8 @@ static BUILDIN(sellitem) } } - if (i != nd->u.scr.shop->items) { + bool foundInShop = (i != nd->u.scr.shop->items); + if (foundInShop) { 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 */ @@ -24785,8 +25042,84 @@ static BUILDIN(sellitem) nd->u.scr.shop->item[i].value = value; nd->u.scr.shop->item[i].value2 = value2; nd->u.scr.shop->item[i].qty = qty; + nd->u.scr.shop->item[i].currency = NULL; + } + nd->u.scr.shop->shop_last_index = i; + + if (!foundInShop) { + for (int k = 5; k <= script_lastdata(st); k += 3) { + script->sellitemcurrency_add(nd, st, k); + } + } + + if (foundInShop) { + if (nd->u.scr.shop->type == NST_EXPANDED_BARTER) { /* has been manually updated, make it reflect on sql */ + npc->expanded_barter_tosql(nd, i); + } + } + return true; +} + +/** + * @call startsellitem <Item_ID>,{,price{,qty}}; + * + * Starts adding item into expanded barter shop (NST_EXPANDED_BARTER) + **/ +static BUILDIN(startsellitem) +{ + struct npc_data *nd; + struct item_data *it; + int i = 0, id = script_getnum(st,2); + int value2 = 0; + int qty = 0; + + if (!(nd = map->id2nd(st->oid))) { + ShowWarning("buildin_startsellitem: trying to run without a proper NPC!\n"); + return false; + } else if (!(it = itemdb->exists(id))) { + ShowWarning("buildin_startsellitem: unknown item id '%d'!\n", id); + return false; + } + + const bool have_shop = (nd->u.scr.shop != NULL); + if (!have_shop) { + npc->trader_update(nd->src_id ? nd->src_id : nd->bl.id); } + if (nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + ShowWarning("script_startsellitem: can works only for NST_EXPANDED_BARTER shops"); + return false; + } + + int value = script_hasdata(st, 3) ? script_getnum(st, 3) : it->value_buy; + if (value == -1) + value = it->value_buy; + + if ((qty = script_getnum(st, 4)) <= 0 && qty != -1) { + ShowError("buildin_startsellitem: invalid 'qty' for expanded barter type shop!\n"); + return false; + } + + 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) { + ShowWarning("buildin_startsellitem: Can't add %s (%s/%s), shop list is full!\n", it->name, nd->exname, nd->path); + return false; + } + i = nd->u.scr.shop->items; + RECREATE(nd->u.scr.shop->item, struct npc_item_list, ++nd->u.scr.shop->items); + } + + 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; + nd->u.scr.shop->item[i].currency = NULL; + nd->u.scr.shop->shop_last_index = i; return true; } @@ -24820,6 +25153,18 @@ static BUILDIN(stopselling) break; } } + } else if (nd->u.scr.shop->type == NST_EXPANDED_BARTER) { + if (!script_hasdata(st, 3)) { + ShowError("buildin_stopselling: called with wrong number of arguments\n"); + return false; + } + const int price = script_getnum(st, 3); + 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 == price) { + break; + } + } } else { for (i = 0; i < nd->u.scr.shop->items; i++) { if (nd->u.scr.shop->item[i].nameid == id) { @@ -24833,13 +25178,19 @@ static BUILDIN(stopselling) if (nd->u.scr.shop->type == NST_MARKET) npc->market_delfromsql(nd, i); - if (nd->u.scr.shop->type == NST_BARTER) + else if (nd->u.scr.shop->type == NST_BARTER) npc->barter_delfromsql(nd, i); + else if (nd->u.scr.shop->type == NST_EXPANDED_BARTER) + npc->expanded_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; + if (nd->u.scr.shop->item[i].currency != NULL) { + aFree(nd->u.scr.shop->item[i].currency); + nd->u.scr.shop->item[i].currency = NULL; + } for (i = 0, cursor = 0; i < nd->u.scr.shop->items; i++) { if (nd->u.scr.shop->item[i].nameid == 0) @@ -24850,14 +25201,18 @@ static BUILDIN(stopselling) 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; + nd->u.scr.shop->item[cursor].currency = nd->u.scr.shop->item[i].currency; } cursor++; } + nd->u.scr.shop->items--; + nd->u.scr.shop->item[nd->u.scr.shop->items].currency = NULL; script_pushint(st, 1); - } else + } else { script_pushint(st, 0); + } return true; } @@ -24916,6 +25271,7 @@ static BUILDIN(tradertype) } npc->market_delfromsql(nd, INT_MAX); npc->barter_delfromsql(nd, INT_MAX); + npc->expanded_barter_delfromsql(nd, INT_MAX); } #if PACKETVER < 20131223 @@ -24930,6 +25286,12 @@ static BUILDIN(tradertype) script->reportsrc(st); } #endif +#if PACKETVER_MAIN_NUM < 20191120 && PACKETVER_RE_NUM < 20191106 && PACKETVER_ZERO_NUM < 20191127 + if (type == NST_EXPANDED_BARTER) { + ShowWarning("buildin_tradertype: NST_EXPANDED_BARTER is only available with PACKETVER_ZERO_NUM 20191127 or PACKETVER_MAIN_NUM 20191120 or PACKETVER_RE_NUM 20191106 or newer!\n"); + script->reportsrc(st); + } +#endif if( nd->u.scr.shop ) nd->u.scr.shop->type = type; @@ -24973,8 +25335,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 && 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); + } else if (nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER && nd->u.scr.shop->type != NST_EXPANDED_BARTER) { + ShowWarning("buildin_shopcount(%d): trying to use on a non-NST_MARKET and non-NST_BARTER and non-NST_EXPANDED_BARTER shop!\n",id); return false; } @@ -26410,6 +26772,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(disablenpc,"s"), BUILDIN_DEF(hideoffnpc,"s"), BUILDIN_DEF(hideonnpc,"s"), + BUILDIN_DEF(cloakonnpc,"s?"), + BUILDIN_DEF(cloakoffnpc,"s?"), BUILDIN_DEF(sc_start,"iii???"), BUILDIN_DEF2(sc_start,"sc_start2","iiii???"), BUILDIN_DEF2(sc_start,"sc_start4","iiiiii???"), @@ -26692,6 +27056,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(agitcheck2,""), // Achievements [Smokexyz/Hercules] BUILDIN_DEF(achievement_progress, "iiii?"), + BUILDIN_DEF(achievement_iscompleted, "i?"), // BattleGround BUILDIN_DEF(waitingroom2bg,"siiss?"), BUILDIN_DEF(waitingroom2bg_single,"isiis"), @@ -26803,7 +27168,10 @@ static void script_parse_builtin(void) /* New Shop Support */ BUILDIN_DEF(openshop,"?"), - BUILDIN_DEF(sellitem,"i???"), + BUILDIN_DEF(sellitem, "i???*"), + BUILDIN_DEF(sellitemcurrency, "ii?"), + BUILDIN_DEF(startsellitem, "iii"), + BUILDIN_DEF(endsellitem, ""), BUILDIN_DEF(stopselling,"i??"), BUILDIN_DEF(setcurrency,"i?"), BUILDIN_DEF(tradertype,"i"), @@ -27364,6 +27732,7 @@ static void script_hardcoded_constants(void) 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->set_constant("NST_EXPANDED_BARTER", NST_EXPANDED_BARTER, false, false); script->constdb_comment("script unit data types"); script->set_constant("UDT_TYPE", UDT_TYPE, false, false); @@ -27812,4 +28181,6 @@ void script_defaults(void) script->run_item_rental_start_script = script_run_item_rental_start_script; script->run_item_rental_end_script = script_run_item_rental_end_script; script->run_item_lapineddukddak_script = script_run_item_lapineddukddak_script; + + script->sellitemcurrency_add = script_sellitemcurrency_add; } diff --git a/src/map/script.h b/src/map/script.h index d652f2155..00a206ce3 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -1054,6 +1054,7 @@ struct script_interface { void (*run_item_rental_end_script) (struct map_session_data *sd, struct item_data *data, int oid); void (*run_item_rental_start_script) (struct map_session_data *sd, struct item_data *data, int oid); void (*run_item_lapineddukddak_script) (struct map_session_data *sd, struct item_data *data, int oid); + bool (*sellitemcurrency_add) (struct npc_data *nd, struct script_state* st, int argIndex); }; #ifdef HERCULES_CORE diff --git a/src/map/skill.c b/src/map/skill.c index 6106f84ad..ede3a4c52 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -67,20 +67,6 @@ #define SKILLUNITTIMER_INTERVAL 100 -// ranges reserved for mapping skill ids to skilldb offsets -#define HM_SKILLRANGEMIN 750 -#define HM_SKILLRANGEMAX (HM_SKILLRANGEMIN + MAX_HOMUNSKILL) -#define MC_SKILLRANGEMIN (HM_SKILLRANGEMAX + 1) -#define MC_SKILLRANGEMAX (MC_SKILLRANGEMIN + MAX_MERCSKILL) -#define EL_SKILLRANGEMIN (MC_SKILLRANGEMAX + 1) -#define EL_SKILLRANGEMAX (EL_SKILLRANGEMIN + MAX_ELEMENTALSKILL) -#define GD_SKILLRANGEMIN (EL_SKILLRANGEMAX + 1) -#define GD_SKILLRANGEMAX (GD_SKILLRANGEMIN + MAX_GUILDSKILL) - -#if GD_SKILLRANGEMAX > 999 - #error GD_SKILLRANGEMAX is greater than 999 -#endif - static struct skill_interface skill_s; static struct s_skill_dbs skilldbs; @@ -110,41 +96,55 @@ static int skill_name2id(const char *name) /// Returns the skill's array index, or 0 (Unknown Skill). static int skill_get_index(int skill_id) { - // avoid ranges reserved for mapping guild/homun/mercenary skills - if( (skill_id >= GD_SKILLRANGEMIN && skill_id <= GD_SKILLRANGEMAX) - || (skill_id >= HM_SKILLRANGEMIN && skill_id <= HM_SKILLRANGEMAX) - || (skill_id >= MC_SKILLRANGEMIN && skill_id <= MC_SKILLRANGEMAX) - || (skill_id >= EL_SKILLRANGEMIN && skill_id <= EL_SKILLRANGEMAX) ) + int skillRange[] = { NV_BASIC, NPC_LEX_AETERNA, + KN_CHARGEATK, SA_ELEMENTWIND, + RK_ENCHANTBLADE, AB_SILENTIUM, + WL_WHITEIMPRISON, SC_FEINTBOMB, + LG_CANNONSPEAR, SR_GENTLETOUCH_REVITALIZE, + WA_SWING_DANCE, WA_MOONLIT_SERENADE, + MI_RUSH_WINDMILL, MI_HARMONIZE, + WM_LESSON, WM_UNLIMITED_HUMMING_VOICE, + SO_FIREWALK, SO_EARTH_INSIGNIA, + GN_TRAINING_SWORD, GN_SLINGITEM_RANGEMELEEATK, + AB_SECRAMENT, LG_OVERBRAND_PLUSATK, + ALL_ODINS_RECALL, ALL_LIGHTGUARD, + RL_GLITTERING_GREED, RL_GLITTERING_GREED_ATK, + KO_YAMIKUMO, OB_AKAITSUKI, + ECL_SNOWFLIP, ALL_THANATOS_RECALL, + GC_DARKCROW, NC_MAGMA_ERUPTION_DOTDAMAGE, + SU_BASIC_SKILL, SU_SPIRITOFSEA, + HLIF_HEAL, MH_VOLCANIC_ASH, + MS_BASH, MER_INVINCIBLEOFF2, + EL_CIRCLE_OF_FIRE, EL_STONE_RAIN, + GD_APPROVAL, GD_DEVELOPMENT + CUSTOM_SKILL_RANGES}; + int length = sizeof(skillRange) / sizeof(int); + STATIC_ASSERT(sizeof(skillRange) / sizeof(int) % 2 == 0, "skill_get_index: skillRange should be multiple of 2"); + + + if (skill_id < skillRange[0] || skill_id > skillRange[length - 1]) { + ShowWarning("skill_get_index: skill id '%d' is not being handled!\n", skill_id); return 0; + } - // map skill id to skill db index - if( skill_id >= GD_SKILLBASE ) - skill_id = GD_SKILLRANGEMIN + skill_id - GD_SKILLBASE; - else if( skill_id >= EL_SKILLBASE ) - skill_id = EL_SKILLRANGEMIN + skill_id - EL_SKILLBASE; - else if( skill_id >= MC_SKILLBASE ) - skill_id = MC_SKILLRANGEMIN + skill_id - MC_SKILLBASE; - else if( skill_id >= HM_SKILLBASE ) - skill_id = HM_SKILLRANGEMIN + skill_id - HM_SKILLBASE; - //[Ind/Hercules] GO GO GO LESS! - http://herc.ws/board/topic/512-skill-id-processing-overhaul/ - else if( skill_id > 1019 && skill_id < 8001 ) { - if( skill_id < 2058 ) // 1020 - 2000 are empty - skill_id = 1020 + skill_id - 2001; - else if( skill_id < 2549 ) // 2058 - 2200 are empty - 1020+57 - skill_id = (1077) + skill_id - 2201; - else if ( skill_id < 3036 ) // 2549 - 3000 are empty - 1020+57+348 - skill_id = (1425) + skill_id - 3001; - else if ( skill_id < 5044 ) // 3036 - 5000 are empty - 1020+57+348+35 - skill_id = (1460) + skill_id - 5001; - else - ShowWarning("skill_get_index: skill id '%d' is not being handled!\n",skill_id); + int skill_idx = 0; + // Map Skill ID to Skill Indexes (in reverse order) + for (int i = 0; i < length; i += 2) { + // Check if SkillID belongs to this range. + if (skill_id <= skillRange[i + 1] && skill_id >= skillRange[i]) { + skill_idx += (skillRange[i + 1] - skill_id); + break; + } + // Add the difference of current range + skill_idx += (skillRange[i + 1] - skillRange[i] + 1); } - // validate result - if (skill_id <= 0|| skill_id >= MAX_SKILL_DB) + if (skill_idx >= MAX_SKILL_DB) { + ShowWarning("skill_get_index: skill id '%d'(idx: %d) is not being handled as it exceeds MAX_SKILL_DB!\n", skill_id, skill_idx); return 0; + } - return skill_id; + return skill_idx; } static const char *skill_get_name(int skill_id) @@ -5613,6 +5613,8 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) // Use a do so that you can break out of it when the skill fails. do { + bool is_asura = (ud->skill_id == MO_EXTREMITYFIST); + if(!target || target->prev==NULL) break; if(src->m != target->m || status->isdead(src)) break; @@ -5845,7 +5847,8 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) ud->skill_lv = ud->skilltarget = 0; } - if (src->id != target->id) + // Asura Strike caster doesn't look to their target in the end + if (src->id != target->id && !is_asura) unit->setdir(src, map->calc_dir(src, target->x, target->y)); map->freeblock_unlock(); @@ -5870,19 +5873,30 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) if (target && target->m == src->m) { //Move character to target anyway. int dir, x, y; + int dist = 3; // number of cells that asura caster will walk + dir = map->calc_dir(src,target->x,target->y); - if( dir > 0 && dir < 4) x = -2; - else if( dir > 4 ) x = 2; - else x = 0; - if( dir > 2 && dir < 6 ) y = -2; - else if( dir == 7 || dir < 2 ) y = 2; - else y = 0; - if (unit->movepos(src, src->x+x, src->y+y, 1, 1)) { + if (dir > 0 && dir < 4) + x = -dist; + else if (dir > 4) + x = dist; + else + x = 0; + + if (dir > 2 && dir < 6) + y = -dist; + else if (dir == 7 || dir < 2) + y = dist; + else + y = 0; + + if (unit->movepos(src, src->x + x, src->y + y, 1, 1) == 1) { //Display movement + animation. - clif->slide(src,src->x,src->y); + clif->slide(src, src->x, src->y); clif->spiritball(src); } - clif->skill_fail(sd, ud->skill_id, USESKILL_FAIL_LEVEL, 0, 0); + // "Skill Failed" message was already shown when checking that target is invalid + //clif->skill_fail(sd, ud->skill_id, USESKILL_FAIL_LEVEL, 0, 0); } } @@ -10410,7 +10424,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * if(sd) { struct mob_data *summon_md; - summon_md = mob->once_spawn_sub(src, src->m, src->x, src->y, clif->get_bl_name(src), MOBID_KO_KAGE, "", SZ_SMALL, AI_NONE); + summon_md = mob->once_spawn_sub(src, src->m, src->x, src->y, clif->get_bl_name(src), MOBID_KO_KAGE, "", SZ_SMALL, AI_NONE, 0); if( summon_md ) { summon_md->master_id = src->id; summon_md->special_state.ai = AI_ZANZOU; @@ -10593,7 +10607,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * for (i = 0; i < summons[skill_lv-1].quantity; i++) { struct mob_data *summon_md = mob->once_spawn_sub(src, src->m, src->x, src->y, clif->get_bl_name(src), - summons[skill_lv-1].mob_id, "", SZ_SMALL, AI_ATTACK); + summons[skill_lv-1].mob_id, "", SZ_SMALL, AI_ATTACK, 0); if (summon_md != NULL) { summon_md->master_id = src->id; if (summon_md->deletetimer != INVALID_TIMER) @@ -11376,7 +11390,7 @@ static int skill_castend_pos2(struct block_list *src, int x, int y, uint16 skill } // Correct info, don't change any of this! [Celest] - md = mob->once_spawn_sub(src, src->m, x, y, clif->get_bl_name(src), class_, "", SZ_SMALL, AI_NONE); + md = mob->once_spawn_sub(src, src->m, x, y, clif->get_bl_name(src), class_, "", SZ_SMALL, AI_NONE, 0); if (md) { md->master_id = src->id; md->special_state.ai = (skill_id == AM_SPHEREMINE) ? AI_SPHERE : AI_FLORA; @@ -11478,7 +11492,7 @@ static int skill_castend_pos2(struct block_list *src, int x, int y, uint16 skill clif->skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0, 0); } else { int mob_id = skill_lv < 2 ? MOBID_BLACK_MUSHROOM + rnd()%2 : MOBID_RED_PLANT + rnd()%6; - struct mob_data *md = mob->once_spawn_sub(src, src->m, x, y, DEFAULT_MOB_JNAME, mob_id, "", SZ_SMALL, AI_NONE); + struct mob_data *md = mob->once_spawn_sub(src, src->m, x, y, DEFAULT_MOB_JNAME, mob_id, "", SZ_SMALL, AI_NONE, 0); int i; if (md == NULL) break; @@ -11624,7 +11638,7 @@ static int skill_castend_pos2(struct block_list *src, int x, int y, uint16 skill case NC_SILVERSNIPER: { - struct mob_data *md = mob->once_spawn_sub(src, src->m, x, y, clif->get_bl_name(src), MOBID_SILVERSNIPER, "", SZ_SMALL, AI_NONE); + struct mob_data *md = mob->once_spawn_sub(src, src->m, x, y, clif->get_bl_name(src), MOBID_SILVERSNIPER, "", SZ_SMALL, AI_NONE, 0); if (md) { md->master_id = src->id; md->special_state.ai = AI_FLORA; @@ -18786,7 +18800,7 @@ static int skill_magicdecoy(struct map_session_data *sd, int nameid) break; } - md = mob->once_spawn_sub(&sd->bl, sd->bl.m, x, y, sd->status.name, class_, "", SZ_SMALL, AI_NONE); + md = mob->once_spawn_sub(&sd->bl, sd->bl.m, x, y, sd->status.name, class_, "", SZ_SMALL, AI_NONE, 0); if( md ) { md->master_id = sd->bl.id; md->special_state.ai = AI_FLORA; diff --git a/src/map/skill.h b/src/map/skill.h index dbda6470f..188a1c927 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -59,6 +59,12 @@ struct status_change_entry; #define MAX_SKILLUNITGROUPTICKSET 25 #define MAX_SKILL_NAME_LENGTH 32 +// Custom Skill Ranges is used in skill_get_index, to allocate indexes based on ID and gaps between 2 SkillID +#ifndef CUSTOM_SKILL_RANGES + #define CUSTOM_SKILL_RANGES +#endif // CUSTOM_SKILL_RANGES + + // (Epoque:) To-do: replace this macro with some sort of skill tree check (rather than hard-coded skill names) #define skill_ischangesex(id) ( \ ((id) >= BD_ADAPTATION && (id) <= DC_SERVICEFORYOU) || ((id) >= CG_ARROWVULCAN && (id) <= CG_MARIONETTE) || \ |