diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 35 | ||||
-rw-r--r-- | src/map/atcommand.h | 2 | ||||
-rw-r--r-- | src/map/battle.c | 1 | ||||
-rw-r--r-- | src/map/battle.h | 2 | ||||
-rw-r--r-- | src/map/chat.c | 8 | ||||
-rw-r--r-- | src/map/intif.c | 50 | ||||
-rw-r--r-- | src/map/intif.h | 4 | ||||
-rw-r--r-- | src/map/mob.c | 361 | ||||
-rw-r--r-- | src/map/mob.h | 55 | ||||
-rw-r--r-- | src/map/pet.c | 15 | ||||
-rw-r--r-- | src/map/rodex.c | 94 | ||||
-rw-r--r-- | src/map/rodex.h | 2 | ||||
-rw-r--r-- | src/map/script.c | 62 |
13 files changed, 621 insertions, 70 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index a9bbff7bd..9ed56545c 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -5277,18 +5277,43 @@ ACMD(follow) } /*========================================== - * @dropall by [MouseJstr] - * Drop all your possession on the ground + * @dropall by [MouseJstr] and [Xantara] + * Drop all your possession on the ground based on item type *------------------------------------------*/ ACMD(dropall) { + int type = -1; + int count = 0; + + if (message[0] != '\0') { + type = atoi(message); + if (!((type >= IT_HEALING && type <= IT_DELAYCONSUME) || type == IT_CASH || type == -1)) { + clif->message(fd, msg_fd(fd, 1500)); + clif->message(fd, msg_fd(fd, 1501)); + return false; + } + } + for (int i = 0; i < sd->status.inventorySize; i++) { if (sd->status.inventory[i].amount) { - if(sd->status.inventory[i].equip != 0) - pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE); - pc->dropitem(sd, i, sd->status.inventory[i].amount); + struct item_data *item_data = itemdb->exists(sd->status.inventory[i].nameid); + if (item_data == NULL) { + ShowWarning("Non-existant item %d on dropall list (account_id: %d, char_id: %d)\n", sd->status.inventory[i].nameid, sd->status.account_id, sd->status.char_id); + continue; + } + if (!pc->candrop(sd, &sd->status.inventory[i])) + continue; + if (type == -1 || type == item_data->type) { + if (sd->status.inventory[i].equip != 0) + pc->unequipitem(sd, i, PCUNEQUIPITEM_RECALC | PCUNEQUIPITEM_FORCE); + count += sd->status.inventory[i].amount; + pc->dropitem(sd, i, sd->status.inventory[i].amount); + } } } + + sprintf(atcmd_output, msg_fd(fd, 1502), count); // %d items are dropped! + clif->message(fd, atcmd_output); return true; } diff --git a/src/map/atcommand.h b/src/map/atcommand.h index 1783e5dc6..4fbf6b93a 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 1500 +#define MAX_MSG 1503 #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/battle.c b/src/map/battle.c index fe7a64b51..ba7c1130d 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7417,6 +7417,7 @@ static const struct battle_data { { "features/enable_achievement_system", &battle_config.feature_enable_achievement, 1, 0, 1, }, { "ping_timer_inverval", &battle_config.ping_timer_interval, 30, 0, 99999999, }, { "ping_time", &battle_config.ping_time, 20, 0, 99999999, }, + { "option_drop_max_loop", &battle_config.option_drop_max_loop, 10, 1, 100000, }, }; static bool battle_set_value_sub(int index, int value) diff --git a/src/map/battle.h b/src/map/battle.h index 723a86874..a99e95c86 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -583,6 +583,8 @@ struct Battle_Config { int ping_timer_interval; int ping_time; + + int option_drop_max_loop; }; /* criteria for battle_config.idletime_critera */ diff --git a/src/map/chat.c b/src/map/chat.c index d9b642219..77a12a560 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -255,6 +255,14 @@ static int chat_leavechat(struct map_session_data *sd, bool kicked) } if( leavechar == 0 && cd->owner->type == BL_PC ) { + + // check if new location are CELL_CHKNOCHAT + if (map->getcell(cd->usersd[0]->bl.m, NULL, cd->usersd[0]->bl.x, cd->usersd[0]->bl.y, CELL_CHKNOCHAT)) { + for (i = (cd->users - 1); i >= 0; i--) + chat->leave(cd->usersd[i], false); + return 2; + } + // Set and announce new owner cd->owner = &cd->usersd[0]->bl; clif->changechatowner(cd, cd->usersd[0]); diff --git a/src/map/intif.c b/src/map/intif.c index 86bf07bce..e25f56b63 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -2754,16 +2754,21 @@ static void intif_parse_RodexNotifications(int fd) /// 2 - user got Items /// 3 - delete /// 4 - sender Read (returned mail) -static int intif_rodex_updatemail(int64 mail_id, int8 flag) +static int intif_rodex_updatemail(struct map_session_data *sd, int64 mail_id, uint8 opentype, int8 flag) { + nullpo_ret(sd); + if (intif->CheckForCharServer()) return 0; - WFIFOHEAD(inter_fd, 11); + WFIFOHEAD(inter_fd, 20); WFIFOW(inter_fd, 0) = 0x3097; - WFIFOQ(inter_fd, 2) = mail_id; - WFIFOB(inter_fd, 10) = flag; - WFIFOSET(inter_fd, 11); + WFIFOL(inter_fd, 2) = sd->status.account_id; + WFIFOL(inter_fd, 6) = sd->status.char_id; + WFIFOQ(inter_fd, 10) = mail_id; + WFIFOB(inter_fd, 18) = opentype; + WFIFOB(inter_fd, 19) = flag; + WFIFOSET(inter_fd, 20); return 0; } @@ -2855,6 +2860,35 @@ static void intif_parse_RodexCheckName(int fd) clif->rodex_checkname_result(sd, target_char_id, target_class, target_level, name); } +static void intif_parse_GetZenyAck(int fd) +{ + int char_id = RFIFOL(fd, 2); + int64 zeny = RFIFOL(fd, 6); + int64 mail_id = RFIFOQ(fd, 14); + uint8 opentype = RFIFOB(fd, 22); + struct map_session_data *sd = map->charid2sd(char_id); + + if (sd == NULL) // User is not online anymore + return; + rodex->getZenyAck(sd, mail_id, opentype, zeny); +} + +static void intif_parse_GetItemsAck(int fd) +{ + int char_id = RFIFOL(fd, 2); + + struct map_session_data *sd = map->charid2sd(char_id); + if (sd == NULL) // User is not online anymore + return; + + int64 mail_id = RFIFOQ(fd, 6); + uint8 opentype = RFIFOB(fd, 14); + int count = RFIFOB(fd, 15); + struct rodex_item items[RODEX_MAX_ITEM]; + memcpy(&items[0], RFIFOP(fd, 16), sizeof(struct rodex_item) * RODEX_MAX_ITEM); + rodex->getItemsAck(sd, mail_id, opentype, count, &items[0]); +} + //----------------------------------------------------------------- // Communication from the inter server // Return a 0 (false) if there were any errors. @@ -2972,6 +3006,8 @@ static int intif_parse(int fd) case 0x3896: intif->pRodexHasNew(fd); break; case 0x3897: intif->pRodexSendMail(fd); break; case 0x3898: intif->pRodexCheckName(fd); break; + case 0x3899: intif->pGetZenyAck(fd); break; + case 0x389a: intif->pGetItemsAck(fd); break; // Clan System case 0x3858: intif->pRecvClanMemberAction(fd); break; @@ -3001,7 +3037,7 @@ void intif_defaults(void) -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil] 14,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880 - -1,-1, 7, 3, 0,-1, 7, 15,18 + NAME_LENGTH, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] / RoDEX [KirieZ] + -1,-1, 7, 3, 0,-1, 7, 15,18 + NAME_LENGTH, 23, 16 + sizeof(struct rodex_item) * RODEX_MAX_ITEM, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] / RoDEX [KirieZ] }; intif = &intif_s; @@ -3171,6 +3207,8 @@ void intif_defaults(void) intif->pRodexHasNew = intif_parse_RodexNotifications; intif->pRodexSendMail = intif_parse_RodexSendMail; intif->pRodexCheckName = intif_parse_RodexCheckName; + intif->pGetZenyAck = intif_parse_GetZenyAck; + intif->pGetItemsAck = intif_parse_GetItemsAck; /* Clan System */ intif->pRecvClanMemberAction = intif_parse_RecvClanMemberAction; /* Achievement System */ diff --git a/src/map/intif.h b/src/map/intif.h index 425ab1d18..8df669217 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -135,9 +135,11 @@ struct intif_interface { // RoDEX int(*rodex_requestinbox) (int char_id, int account_id, int8 flag, int8 opentype, int64 mail_id); int(*rodex_checkhasnew) (struct map_session_data *sd); - int(*rodex_updatemail) (int64 mail_id, int8 flag); + int(*rodex_updatemail) (struct map_session_data *sd, int64 mail_id, uint8 opentype, int8 flag); int(*rodex_sendmail) (struct rodex_message *msg); int(*rodex_checkname) (struct map_session_data *sd, const char *name); + void (*pGetZenyAck) (int fd); + void (*pGetItemsAck) (int fd); /* Clan System */ int (*clan_kickoffline) (int clan_id, int kick_interval); int (*clan_membercount) (int clan_id, int kick_interval); diff --git a/src/map/mob.c b/src/map/mob.c index fed4d6c60..8dac1ea43 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1900,15 +1900,53 @@ static int mob_ai_hard(int tid, int64 tick, int id, intptr_t data) return 0; } +/** + * Adds random options of a given options drop group into item. + * + * @param item : item receiving random options + * @param options : Random Option Drop Group to be used + */ +static void mob_setdropitem_options(struct item *item, struct optdrop_group *options) +{ + nullpo_retv(item); + nullpo_retv(options); + + for (int i = 0; i < options->optslot_count; i++) { + if (rnd() % 10000 >= options->optslot_rate[i]) + continue; + + // count avoids a too long loop that would cause lag. + // if after option_drop_max_loop full iterations (running through all possibilities) + // it still fails to pick one, it'll stop at one random index in the next iteration + int count = battle_config.option_drop_max_loop * options->optslot[i].option_count + (rnd() % options->optslot[i].option_count); + int idx = 0; + while (count > 0 && rnd() % 10000 >= options->optslot[i].options[idx].rate) { + idx = (idx + 1) % options->optslot[i].option_count; + --count; + } + + item->option[i].index = options->optslot[i].options[idx].id; + + int min = options->optslot[i].options[idx].min; + int max = options->optslot[i].options[idx].max; + item->option[i].value = min + (rnd() % (max - min + 1)); + } +} + /*========================================== * Initializes the delay drop structure for mob-dropped items. *------------------------------------------*/ -static struct item_drop *mob_setdropitem(int nameid, int qty, struct item_data *data) +static struct item_drop *mob_setdropitem(int nameid, struct optdrop_group *options, int qty, struct item_data *data) { struct item_drop *drop = ers_alloc(item_drop_ers, struct item_drop); drop->item_data.nameid = nameid; drop->item_data.amount = qty; drop->item_data.identify = data ? itemdb->isidentified2(data) : itemdb->isidentified(nameid); + + // Set item options [KirieZ] + if (options != NULL) + mob->setdropitem_options(&drop->item_data, options); + drop->showdropeffect = true; drop->next = NULL; return drop; @@ -2521,7 +2559,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) continue; } - ditem = mob->setdropitem(md->db->dropitem[i].nameid, 1, it); + ditem = mob->setdropitem(md->db->dropitem[i].nameid, md->db->dropitem[i].options, 1, it); // Official Drop Announce [Jedzkie] if (mvp_sd != NULL) { @@ -2538,7 +2576,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) // Ore Discovery [Celest] if (sd == mvp_sd && pc->checkskill(sd,BS_FINDINGORE) > 0) { if( (temp = itemdb->chain_item(itemdb->chain_cache[ECC_ORE],&i)) ) { - ditem = mob->setdropitem(temp, 1, NULL); + ditem = mob->setdropitem(temp, NULL, 1, NULL); mob->item_drop(md, dlist, ditem, 0, i, homkillonly); } } @@ -2570,7 +2608,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) continue; itemid = (!sd->add_drop[i].is_group) ? sd->add_drop[i].id : itemdb->chain_item(sd->add_drop[i].id, &drop_rate); if( itemid ) - mob->item_drop(md, dlist, mob->setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly); + mob->item_drop(md, dlist, mob->setdropitem(itemid, NULL, 1, NULL), 0, drop_rate, homkillonly); } } @@ -2629,10 +2667,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) if (!(map->list[m].flag.nomvploot || type&1)) { /* pose them randomly in the list -- so on 100% drop servers it wont always drop the same item */ - struct { - int nameid; - int p; - } mdrop[MAX_MVP_DROP] = { { 0 } }; + struct mob_drop mdrop[MAX_MVP_DROP] = { { 0 } }; for (i = 0; i < MAX_MVP_DROP; i++) { int rpos; @@ -2644,6 +2679,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) mdrop[rpos].nameid = md->db->mvpitem[i].nameid; mdrop[rpos].p = md->db->mvpitem[i].p; + mdrop[rpos].options = md->db->mvpitem[i].options; } for (i = 0; i < MAX_MVP_DROP; i++) { @@ -2663,6 +2699,7 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type) item.nameid = mdrop[i].nameid; item.identify = itemdb->isidentified2(data); + mob->setdropitem_options(&item, mdrop[i].options); clif->mvp_item(mvp_sd, item.nameid); log_mvp[0] = item.nameid; @@ -3861,6 +3898,212 @@ static inline int mob_parse_dbrow_cap_value(int class_, int min, int max, int va } /** + * Reads one possible option for a option slot in a option drop group + * @param option : Libconfig entry + * @param entry : memory db entry for current slot + * @param idx : index of entry where this option should be inserted at + * @param calc_rate : if rates should be recalculated after reading all entries + * @param slot : option group slot being read (for messages) + * @param group : option group being read (for messages) + * @return true if it successfully read the entry, false otherwise + */ +static bool mob_read_optdrops_option(struct config_setting_t *option, struct optdrop_group_optslot *entry, int *idx, bool *calc_rate, int slot, const char *group) +{ + nullpo_retr(false, option); + nullpo_retr(false, entry); + nullpo_retr(false, idx); + nullpo_retr(false, calc_rate); + nullpo_retr(false, group); + + const char *name = config_setting_name(option); + int opt_id; + + if (strncmp(name, "Rate", 4) == 0) + return true; + + if (script->get_constant(name, &opt_id) == false) { + ShowWarning("mob_read_optdrops_option: Invalid option \"%s\" for option slot %d of %s group, skipping.\n", name, slot, group); + return false; + } + + int min = 0, max = 0, opt_rate = 0; + if (config_setting_is_number(option)) { + // OptionName: value + min = libconfig->setting_get_int(option); + } else if (config_setting_is_array(option)) { + // OptionName: [min, max] + // OptionName: [min, max, rate] + int slen = libconfig->setting_length(option); + + if (slen >= 2) { + // [min, max,...] + min = libconfig->setting_get_int_elem(option, 0); + max = libconfig->setting_get_int_elem(option, 1); + } + + if (slen == 3) { + // [min, max, rate] + opt_rate = libconfig->setting_get_int_elem(option, 2); + } + } else { + ShowWarning("mob_read_optdrops_option: Invalid value \"%s\" for option slot %d of %s group, skipping.\n", name, slot, group); + return false; + } + + if (max < min) + max = min; + + entry->options[*idx].id = opt_id; + entry->options[*idx].min = min; + entry->options[*idx].max = max; + entry->options[*idx].rate = opt_rate; + + if (entry->options[*idx].rate == 0) + *calc_rate = true; + + (*idx)++; + + return true; +} + +/** + * Reads the settings for one random option slot of a random option drop group. + * @param optslot : The slot entry from config file + * @param n : slot index + * @param group_id : Group index + * @param group : group name (used in messages) + * @return true if it succesfully read, false otherwise + */ +static bool mob_read_optdrops_optslot(struct config_setting_t *optslot, int n, int group_id, const char *group) +{ + nullpo_retr(false, optslot); + nullpo_retr(false, group); + Assert_retr(false, group_id >= 0 && group_id < mob->opt_drop_groups_count); + Assert_retr(false, n >= 0 && n < MAX_ITEM_OPTIONS); + + // Structure: + // { + // Rate: chance of option 1 (int) + // OptionName1: value + // OptionName2: [min, max] + // OptionName3: [min, max, rate] + // .... + // } + + int drop_rate; // The rate for this option to be dropped (Rate field) + if (libconfig->setting_lookup_int(optslot, "Rate", &drop_rate) == CONFIG_FALSE) { + ShowWarning("mob_read_optdrops_optslot: Missing option %d rate in group %s, skipping.\n", n, group); + return false; + } + + int count = libconfig->setting_length(optslot); + if (count <= 1) { // 1 = Rate + ShowWarning("mob_read_optdrops_optslot: Option %d of %s group doesn't contain any possible options, skipping.\n", n, group); + return false; + } + + struct optdrop_group_optslot *entry = &(mob->opt_drop_groups[group_id].optslot[n]); + entry->options = aCalloc(sizeof(struct optdrop_group_option), count); + + int idx = 0; + int i = 0; + struct config_setting_t *opt = NULL; + bool calc_rate = false; + while (i < count && (opt = libconfig->setting_get_elem(optslot, i)) != NULL) { + ++i; + mob->read_optdrops_option(opt, entry, &idx, &calc_rate, n, group); + } + entry->option_count = idx; + mob->opt_drop_groups[group_id].optslot_count++; + mob->opt_drop_groups[group_id].optslot_rate[n] = drop_rate; + + // If there're empty rates, calculate them + if (calc_rate == true) { + for (int j = 0; j < idx; ++j) { + if (entry->options[j].rate == 0) + entry->options[j].rate = 10000 / idx; + } + } + + return true; +} + +/** + * Reads one random option drop group. + * @param group : Drop Group entry from config file + * @param n : group index + * @return true if it successfuly read, false otherwise + */ +static bool mob_read_optdrops_group(struct config_setting_t *group, int n) +{ + /* Structure: + <Group Name>: ( + { <Option 1 drop data> }, + { <Option 2 drop data> }, + ... // Up to MAX_ITEM_OPTIONS + ) + */ + nullpo_retr(false, group); + + const char *group_name = config_setting_name(group); + + if (group_name == NULL || *group_name == '\0') { + ShowWarning("mob_read_optdrops_group: Invalid name for random option drop group, skipping group %d...\n", n); + return false; + } + + script->set_constant2(group_name, n, false, false); + + int i = 0; + struct config_setting_t *drop_data = NULL; + while (i < MAX_ITEM_OPTIONS && (drop_data = libconfig->setting_get_elem(group, i)) != NULL) { + mob->read_optdrops_optslot(drop_data, i, n, group_name); + i++; + } + + return true; +} + +/** + * Reads random option drop groups database. + */ +static bool mob_read_optdrops_db(void) +{ + const char *filename = "option_drop_groups.conf"; // FIXME hardcoded name + + char filepath[256]; + safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, filename); + + struct config_t option_groups; + if (libconfig->load_file(&option_groups, filepath) == CONFIG_FALSE) { + ShowError("Failed to load option drop groups\n"); + return false; + } + + struct config_setting_t *its = libconfig->lookup(&option_groups, "option_drop_group_db"); + struct config_setting_t *groups = NULL; + + int i = 0; + if (its != NULL && (groups = libconfig->setting_get_elem(its, 0)) != NULL) { + int count = libconfig->setting_length(groups); + mob->opt_drop_groups = aCalloc(sizeof(struct optdrop_group), count); + mob->opt_drop_groups_count = count; // maximum size (used by assertions) + + struct config_setting_t *group = NULL; + while ((group = libconfig->setting_get_elem(groups, i)) != NULL) { + mob->read_optdrops_group(group, i); + i++; + } + mob->opt_drop_groups_count = i; // number of entries used (should be the same amount) + } + + libconfig->destroy(&option_groups); + + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", i, filepath); + return true; +} + +/** * Processes the stats for a mob database entry. * * @param[in,out] entry The destination mob_db entry, already initialized @@ -3941,6 +4184,51 @@ static uint32 mob_read_db_mode_sub(struct mob_db *entry, struct config_setting_t } /** + * Process an entry of mob/mvp drops that contains a random option drop group. + * + * @param entry : mob db entry being read (used in error messages) + * @param item_name : AegisName of the item in this entry (used in error messages) + * @param drop : drop data entry + * @param drop_rate : used to return the entry drop_rate + * @returns a reference to the opt_drop_group to be used when creating this item drop + */ +static struct optdrop_group *mob_read_db_drops_option(struct mob_db *entry, const char *item_name, struct config_setting_t *drop, int *drop_rate) +{ + nullpo_retr(NULL, entry); + nullpo_retr(NULL, item_name); + nullpo_retr(NULL, drop); + nullpo_retr(NULL, drop_rate); + + // (Drop Rate, "Option Group") + if (!config_setting_is_list(drop) || config_setting_length(drop) != 2) { + ShowError("mob_read_db_optdrops: Invalid format for option drop group on item \"%s\" in monster %d, skipping.\n", item_name, entry->mob_id); + return NULL; + } + + int i32; + if (mob->get_const(libconfig->setting_get_elem(drop, 0), &i32) && i32 >= 0) + *drop_rate = i32; + + const char *group_name = libconfig->setting_get_string_elem(drop, 1); + if (group_name == NULL || *group_name == '\0') { + ShowError("mob_read_db_optdrops: Missing option drop group name on item \"%s\" in monster %d, skipping.\n", item_name, entry->mob_id); + return NULL; + } + + int opt_id; + if (script->get_constant(group_name, &opt_id) == false) { + ShowError("mob_read_db_optdrops: Invalid option drop group \"%s\" on item \"%s\" in monster %d, does this group really exists? Skipping...\n", group_name, item_name, entry->mob_id); + return NULL; + } + if (opt_id < 0 || opt_id >= mob->opt_drop_groups_count) { + ShowError("mob_read_db_optdrops: Invalid option drop group \"%s\" index \"%d\" on item \"%s\" in monster %d, does this group really exists? Skipping...\n", group_name, opt_id, item_name, entry->mob_id); + return NULL; + } + + return &mob->opt_drop_groups[opt_id]; +} + +/** * Processes the MVP drops for a mob_db entry. * * @param[in,out] entry The destination mob_db entry, already initialized @@ -3965,9 +4253,18 @@ static void mob_read_db_mvpdrops_sub(struct mob_db *entry, struct config_setting i++; continue; } - if (mob->get_const(drop, &i32) && i32 >= 0) { - value = i32; + + struct optdrop_group *drop_option = NULL; + if (config_setting_is_number(drop)) { + // Setting is a number, item doesn't contain options + if (mob->get_const(drop, &i32) && i32 >= 0) { + value = i32; + } + } else { + // (Drop Rate, "Opt Drop Group") + drop_option = mob->read_db_drops_option(entry, name, drop, &value); } + if (value <= 0) { ShowWarning("mob_read_db: wrong drop chance %d for mvp drop item %s in monster %d\n", value, name, entry->mob_id); i++; @@ -3981,6 +4278,7 @@ static void mob_read_db_mvpdrops_sub(struct mob_db *entry, struct config_setting } mob->item_dropratio_adjust(entry->mvpitem[idx].nameid, entry->mob_id, &rate_adjust); entry->mvpitem[idx].p = mob->drop_adjust(value, rate_adjust, battle_config.item_drop_mvp_min, battle_config.item_drop_mvp_max); + entry->mvpitem[idx].options = drop_option; //calculate and store Max available drop chance of the MVP item if (entry->mvpitem[idx].p) { @@ -4024,9 +4322,18 @@ static void mob_read_db_drops_sub(struct mob_db *entry, struct config_setting_t i++; continue; } - if (mob->get_const(drop, &i32) && i32 >= 0) { - value = i32; + + struct optdrop_group *drop_option = NULL; + if (config_setting_is_number(drop)) { + // Setting is a number, item doesn't contain options + if (mob->get_const(drop, &i32) && i32 >= 0) { + value = i32; + } + } else { + // (Drop Rate, "Opt Drop Group") + drop_option = mob->read_db_drops_option(entry, name, drop, &value); } + if (value <= 0) { ShowWarning("mob_read_db: wrong drop chance %d for drop item %s in monster %d\n", value, name, entry->mob_id); i++; @@ -4034,6 +4341,7 @@ static void mob_read_db_drops_sub(struct mob_db *entry, struct config_setting_t } entry->dropitem[idx].nameid = id->nameid; + entry->dropitem[idx].options = drop_option; if (!entry->dropitem[idx].nameid) { entry->dropitem[idx].p = 0; //No drop. i++; @@ -4301,6 +4609,8 @@ static int mob_read_db_sub(struct config_setting_t *mobt, int n, const char *sou * } * Drops: { * AegisName: chance + * // or + * AegisName: (chance, "Option Drop Group") * ... * } */ @@ -5213,6 +5523,7 @@ static void mob_load(bool minimal) return; } sv->readdb(map->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, mob->readdb_itemratio); // must be read before mobdb + mob->read_optdrops_db(); mob->readchatdb(); mob->readdb(); mob->readskilldb(); @@ -5254,6 +5565,8 @@ static void mob_reload(void) } mob->item_drop_ratio_other_db->clear(mob->item_drop_ratio_other_db, mob->final_ratio_sub); + mob->destroy_drop_groups(); + mob->load(false); } @@ -5309,6 +5622,22 @@ static void mob_destroy_mob_db(int index) mob->db_data[index] = NULL; } +/** + * Unloads option drop group database + */ +static void mob_destroy_drop_groups(void) +{ + for (int i = 0; i < mob->opt_drop_groups_count; i++) { + struct optdrop_group *group = &mob->opt_drop_groups[i]; + + for (int j = 0; j < group->optslot_count; j++) { + aFree(group->optslot[j].options); + } + } + + aFree(mob->opt_drop_groups); +} + /*========================================== * Clean memory usage. *------------------------------------------*/ @@ -5327,6 +5656,7 @@ static int do_final_mob(void) mob->destroy_mob_db(i); } } + mob->destroy_drop_groups(); for (i = 0; i <= MAX_MOB_CHAT; i++) { if (mob->chat_db[i] != NULL) @@ -5443,6 +5773,7 @@ void mob_defaults(void) mob->ai_sub_lazy = mob_ai_sub_lazy; mob->ai_lazy = mob_ai_lazy; mob->ai_hard = mob_ai_hard; + mob->setdropitem_options = mob_setdropitem_options; mob->setdropitem = mob_setdropitem; mob->setlootitem = mob_setlootitem; mob->delay_item_drop = mob_delay_item_drop; @@ -5476,6 +5807,10 @@ void mob_defaults(void) mob->clone_delete = mob_clone_delete; mob->drop_adjust = mob_drop_adjust; mob->item_dropratio_adjust = item_dropratio_adjust; + mob->read_optdrops_option = mob_read_optdrops_option; + mob->read_optdrops_optslot = mob_read_optdrops_optslot; + mob->read_optdrops_group = mob_read_optdrops_group; + mob->read_optdrops_db = mob_read_optdrops_db; mob->lookup_const = mob_lookup_const; mob->get_const = mob_get_const; mob->db_validate_entry = mob_db_validate_entry; @@ -5486,6 +5821,7 @@ void mob_defaults(void) mob->read_db_drops_sub = mob_read_db_drops_sub; mob->read_db_mvpdrops_sub = mob_read_db_mvpdrops_sub; mob->read_db_mode_sub = mob_read_db_mode_sub; + mob->read_db_drops_option = mob_read_db_drops_option; mob->read_db_stats_sub = mob_read_db_stats_sub; mob->name_constants = mob_name_constants; mob->readdb_mobavail = mob_readdb_mobavail; @@ -5501,6 +5837,7 @@ void mob_defaults(void) mob->final_ratio_sub = mob_final_ratio_sub; mob->clear_spawninfo = mob_clear_spawninfo; mob->destroy_mob_db = mob_destroy_mob_db; + mob->destroy_drop_groups = mob_destroy_drop_groups; mob->skill_db_libconfig = mob_skill_db_libconfig; mob->skill_db_libconfig_sub = mob_skill_db_libconfig_sub; mob->skill_db_libconfig_sub_skill = mob_skill_db_libconfig_sub_skill; diff --git a/src/map/mob.h b/src/map/mob.h index cdfc07c7d..b63efd272 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -152,6 +152,45 @@ struct spawn_info { unsigned short qty; }; +/** + * Information of one possible option that will fill + * an option slot (see optdrop_group_optslot) + */ +struct optdrop_group_option { + int id; //< Option ID + int min; //< Minimun value when this option drops + int max; //< Maximun value when this option drops + int rate; //< Chance of dropping this option +}; + +/** + * Information of possible options that will fill + * one option slot + */ +struct optdrop_group_optslot { + int option_count; //< Number of options in *options + struct optdrop_group_option *options; //< Array of possible options +}; + +/** + * A group of options to be random picked when + * dropping an item + */ +struct optdrop_group { + int optslot_count; //< How many option slots are configured by this group + int optslot_rate[MAX_ITEM_OPTIONS]; //< The rate to fill each of the configured slots + struct optdrop_group_optslot optslot[MAX_ITEM_OPTIONS]; //< Details of the options that will go in each slot +}; + +/** + * Stores data related to a monster drop (normal or mvp drop) + */ +struct mob_drop { + int nameid; //< Item ID + int p; //< Drop chance + struct optdrop_group *options; //< Option Drop Group associated with this drop (NULL if none) +}; + struct mob_db { int mob_id; char sprite[NAME_LENGTH],name[NAME_LENGTH],jname[NAME_LENGTH]; @@ -160,8 +199,8 @@ struct mob_db { short range2,range3; short race2; // celest unsigned short lv; - struct { int nameid,p; } dropitem[MAX_MOB_DROP]; - struct { int nameid,p; } mvpitem[MAX_MVP_DROP]; + struct mob_drop dropitem[MAX_MOB_DROP]; + struct mob_drop mvpitem[MAX_MVP_DROP]; struct status_data status; struct view_data vd; unsigned int option; @@ -436,6 +475,9 @@ struct mob_interface { struct mob_db *dummy; //Dummy mob to be returned when a non-existant one is requested. // Dynamic mob chat database struct mob_chat *chat_db[MAX_MOB_CHAT + 1]; + // Random Option Drop groups + struct optdrop_group *opt_drop_groups; + int opt_drop_groups_count; // Defines the Manuk/Splendide/Mora mob groups for the status reductions [Epoque & Frost] int manuk[8]; int splendide[5]; @@ -494,7 +536,8 @@ struct mob_interface { int (*ai_sub_lazy) (struct mob_data *md, va_list args); int (*ai_lazy) (int tid, int64 tick, int id, intptr_t data); int (*ai_hard) (int tid, int64 tick, int id, intptr_t data); - struct item_drop* (*setdropitem) (int nameid, int qty, struct item_data *data); + void (*setdropitem_options) (struct item *item, struct optdrop_group *options); + struct item_drop* (*setdropitem) (int nameid, struct optdrop_group *options, int qty, struct item_data *data); struct item_drop* (*setlootitem) (struct item *item); int (*delay_item_drop) (int tid, int64 tick, int id, intptr_t data); void (*item_drop) (struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag); @@ -527,6 +570,10 @@ struct mob_interface { int (*clone_delete) (struct mob_data *md); unsigned int (*drop_adjust) (int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max); void (*item_dropratio_adjust) (int nameid, int mob_id, int *rate_adjust); + bool (*read_optdrops_option) (struct config_setting_t *option, struct optdrop_group_optslot *entry, int *idx, bool *calc_rate, int slot, const char *group); + bool (*read_optdrops_optslot) (struct config_setting_t *optslot, int n, int group_id, const char *group); + bool (*read_optdrops_group) (struct config_setting_t *group, int n); + bool (*read_optdrops_db) (void); void (*readdb) (void); bool (*lookup_const) (const struct config_setting_t *it, const char *name, int *value); bool (*get_const) (const struct config_setting_t *it, int *value); @@ -537,6 +584,7 @@ struct mob_interface { void (*read_db_drops_sub) (struct mob_db *entry, struct config_setting_t *t); void (*read_db_mvpdrops_sub) (struct mob_db *entry, struct config_setting_t *t); uint32 (*read_db_mode_sub) (struct mob_db *entry, struct config_setting_t *t); + struct optdrop_group *(*read_db_drops_option) (struct mob_db *entry, const char *item_name, struct config_setting_t *drop, int *drop_rate); void (*read_db_stats_sub) (struct mob_db *entry, struct config_setting_t *t); void (*name_constants) (void); bool (*readdb_mobavail) (char *str[], int columns, int current); @@ -552,6 +600,7 @@ struct mob_interface { void (*set_item_drop_ratio) (int nameid, struct item_drop_ratio *ratio); int (*final_ratio_sub) (union DBKey key, struct DBData *data, va_list ap); void (*destroy_mob_db) (int index); + void (*destroy_drop_groups) (void); bool (*skill_db_libconfig) (const char *filename, bool ignore_missing); bool (*skill_db_libconfig_sub) (struct config_setting_t *it, int n); bool (*skill_db_libconfig_sub_skill) (struct config_setting_t *it, int n, int mob_id); diff --git a/src/map/pet.c b/src/map/pet.c index 96fe63c51..ce26b6cb1 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -348,6 +348,21 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) if (i != sd->status.inventorySize) { sd->status.inventory[i].attribute &= ~ATTR_BROKEN; sd->status.inventory[i].bound = IBT_NONE; + } else { + // The pet egg wasn't found: it was probably hatched with the old system that deleted the egg. + struct item tmp_item = {0}; + int flag; + + tmp_item.nameid = pd->petDB->EggID; + tmp_item.identify = 1; + tmp_item.card[0] = CARD0_PET; + tmp_item.card[1] = GetWord(pd->pet.pet_id, 0); + tmp_item.card[2] = GetWord(pd->pet.pet_id, 1); + tmp_item.card[3] = pd->pet.rename_flag; + if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_EGG)) != 0) { + clif->additem(sd, 0, 0, flag); + map->addflooritem(&sd->bl, &tmp_item, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0, false); + } } #if PACKETVER >= 20180704 clif->inventoryList(sd); diff --git a/src/map/rodex.c b/src/map/rodex.c index 33070c5f8..766fdc5ea 100644 --- a/src/map/rodex.c +++ b/src/map/rodex.c @@ -404,12 +404,12 @@ static void rodex_read_mail(struct map_session_data *sd, int64 mail_id) if (msg->opentype == RODEX_OPENTYPE_RETURN) { if (msg->sender_read == false) { - intif->rodex_updatemail(msg->id, 4); + intif->rodex_updatemail(sd, msg->id, 0, 4); msg->sender_read = true; } } else { if (msg->is_read == false) { - intif->rodex_updatemail(msg->id, 0); + intif->rodex_updatemail(sd, msg->id, 0, 0); msg->is_read = true; } } @@ -430,21 +430,36 @@ static void rodex_delete_mail(struct map_session_data *sd, int64 mail_id) nullpo_retv(msg); msg->is_deleted = true; - intif->rodex_updatemail(msg->id, 3); + intif->rodex_updatemail(sd, msg->id, 0, 3); clif->rodex_delete_mail(sd, msg->opentype, msg->id); } +/// give requested zeny from message to player +static void rodex_getZenyAck(struct map_session_data *sd, int64 mail_id, int8 opentype, int64 zeny) +{ + nullpo_retv(sd); + if (zeny <= 0) { + clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_FATAL_ERROR); + return; + } + + if (pc->getzeny(sd, (int)zeny, LOG_TYPE_MAIL, NULL) != 0) { + clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_FATAL_ERROR); + return; + } + + clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_SUCCESS); +} + /// Gets attached zeny /// @param sd : Who's getting /// @param mail_id : Mail ID that we're getting zeny from static void rodex_get_zeny(struct map_session_data *sd, int8 opentype, int64 mail_id) { - struct rodex_message *msg; - nullpo_retv(sd); - msg = rodex->get_mail(sd, mail_id); + struct rodex_message *msg = rodex->get_mail(sd, mail_id); if (msg == NULL) { clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_FATAL_ERROR); @@ -456,16 +471,31 @@ static void rodex_get_zeny(struct map_session_data *sd, int8 opentype, int64 mai return; } - if (pc->getzeny(sd, (int)msg->zeny, LOG_TYPE_MAIL, NULL) != 0) { - clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_FATAL_ERROR); - return; - } - msg->type &= ~MAIL_TYPE_ZENY; msg->zeny = 0; - intif->rodex_updatemail(mail_id, 1); + intif->rodex_updatemail(sd, mail_id, opentype, 1); +} - clif->rodex_request_zeny(sd, opentype, mail_id, RODEX_GET_ZENY_SUCCESS); +// give requested items from message to player +static void rodex_getItemsAck(struct map_session_data *sd, int64 mail_id, int8 opentype, int count, const struct rodex_item *items) +{ + nullpo_retv(sd); + nullpo_retv(items); + + for (int i = 0; i < count; ++i) { + const struct item *it = &items[i].item; + + if (it->nameid == 0) { + continue; + } + + if (pc->additem(sd, it, it->amount, LOG_TYPE_MAIL) != 0) { + clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FULL_ERROR); + return; + } + } + + clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEMS_SUCCESS); } /// Gets attached item @@ -473,14 +503,12 @@ static void rodex_get_zeny(struct map_session_data *sd, int8 opentype, int64 mai /// @param mail_id : Mail ID that we're getting items from static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 mail_id) { - struct rodex_message *msg; - int weight = 0; - int empty_slots = 0, required_slots; - int i; - nullpo_retv(sd); - msg = rodex->get_mail(sd, mail_id); + int weight = 0; + int empty_slots = 0; + + struct rodex_message *msg = rodex->get_mail(sd, mail_id); if (msg == NULL) { clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FATAL_ERROR); @@ -492,7 +520,7 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - for (i = 0; i < RODEX_MAX_ITEM; ++i) { + for (int i = 0; i < RODEX_MAX_ITEM; ++i) { if (msg->items[i].item.nameid != 0) { weight += itemdb->search(msg->items[i].item.nameid)->weight * msg->items[i].item.amount; } @@ -503,8 +531,8 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - required_slots = msg->items_count; - for (i = 0; i < sd->status.inventorySize; ++i) { + int required_slots = msg->items_count; + for (int i = 0; i < sd->status.inventorySize; ++i) { if (sd->status.inventory[i].nameid == 0) { empty_slots++; } else if (itemdb->isstackable(sd->status.inventory[i].nameid) == 1) { @@ -529,27 +557,9 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - for (i = 0; i < RODEX_MAX_ITEM; ++i) { - struct item *it = &msg->items[i].item; - - if (it->nameid == 0) { - continue; - } - - if (pc->additem(sd, it, it->amount, LOG_TYPE_MAIL) != 0) { - clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FULL_ERROR); - intif->rodex_updatemail(mail_id, 2); - return; - } else { - memset(it, 0x0, sizeof(*it)); - } - } - msg->type &= ~MAIL_TYPE_ITEM; msg->items_count = 0; - intif->rodex_updatemail(mail_id, 2); - - clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEMS_SUCCESS); + intif->rodex_updatemail(sd, mail_id, opentype, 2); } /// Cleans user's RoDEX related data @@ -668,4 +678,6 @@ void rodex_defaults(void) rodex->get_zeny = rodex_get_zeny; rodex->get_items = rodex_get_items; rodex->clean = rodex_clean; + rodex->getZenyAck = rodex_getZenyAck; + rodex->getItemsAck = rodex_getItemsAck; } diff --git a/src/map/rodex.h b/src/map/rodex.h index 56cc3a9d1..b6e7ca5b7 100644 --- a/src/map/rodex.h +++ b/src/map/rodex.h @@ -74,6 +74,8 @@ struct rodex_interface { void (*get_items) (struct map_session_data *sd, int8 opentype, int64 mail_id); void (*delete_mail) (struct map_session_data *sd, int64 mail_id); void (*clean) (struct map_session_data *sd, int8 flag); + void (*getZenyAck) (struct map_session_data *sd, int64 mail_id, int8 opentype, int64 zeny); + void (*getItemsAck) (struct map_session_data *sd, int64 mail_id, int8 opentype, int count, const struct rodex_item *items); }; #ifdef HERCULES_CORE diff --git a/src/map/script.c b/src/map/script.c index dea94c6a3..b4a955f09 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -24566,6 +24566,57 @@ static BUILDIN(getcalendartime) return true; } +enum consolemes_type { + CONSOLEMES_DEBUG = 0, + CONSOLEMES_ERROR = 1, + CONSOLEMES_WARNING = 2, + CONSOLEMES_INFO = 3, + CONSOLEMES_STATUS = 4, + CONSOLEMES_NOTICE = 5, +}; + +/*========================================== +* consolemes(<type>, "text") +*------------------------------------------*/ +static BUILDIN(consolemes) +{ + struct StringBuf buf; + StrBuf->Init(&buf); + int type = script_hasdata(st, 2) ? script_getnum(st, 2) : 0; + + if (!script->sprintf_helper(st, 3, &buf)) { + StrBuf->Destroy(&buf); + script_pushint(st, 0); + return false; + } + + switch (type) { + default: + case CONSOLEMES_DEBUG: + ShowDebug("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_ERROR: + ShowError("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_WARNING: + ShowWarning("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_INFO: + ShowInfo("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_STATUS: + ShowStatus("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_NOTICE: + ShowNotice("consolemes: %s\n", StrBuf->Value(&buf)); + break; + } + + StrBuf->Destroy(&buf); + script_pushint(st, 1); + return true; +} + /** place holder for the translation macro **/ static BUILDIN(_) { @@ -25485,7 +25536,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(sc_end,"i?"), BUILDIN_DEF(getstatus, "i?"), BUILDIN_DEF(getscrate,"ii?"), - BUILDIN_DEF(debugmes,"v*"), + BUILDIN_DEF_DEPRECATED(debugmes,"v*"), + BUILDIN_DEF(consolemes,"iv*"), BUILDIN_DEF2(catchpet,"pet","i"), BUILDIN_DEF2(birthpet,"bpet",""), BUILDIN_DEF(resetlvl,"i"), @@ -26212,6 +26264,14 @@ static void script_hardcoded_constants(void) script->set_constant("MAPINFO_SIZE_Y", MAPINFO_SIZE_Y, false, false); script->set_constant("MAPINFO_ZONE", MAPINFO_ZONE, false, false); + script->constdb_comment("consolemes options"); + script->set_constant("CONSOLEMES_DEBUG", CONSOLEMES_DEBUG, false, false); + script->set_constant("CONSOLEMES_ERROR", CONSOLEMES_ERROR, false, false); + script->set_constant("CONSOLEMES_WARNING", CONSOLEMES_WARNING, false, false); + script->set_constant("CONSOLEMES_INFO", CONSOLEMES_INFO, false, false); + script->set_constant("CONSOLEMES_STATUS", CONSOLEMES_STATUS, false, false); + script->set_constant("CONSOLEMES_NOTICE", CONSOLEMES_NOTICE, false, false); + script->constdb_comment("set/getiteminfo options"); script->set_constant("ITEMINFO_BUYPRICE", ITEMINFO_BUYPRICE, false, false); script->set_constant("ITEMINFO_SELLPRICE", ITEMINFO_SELLPRICE, false, false); |