diff options
author | Haru <haru@dotalux.com> | 2019-12-15 17:06:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-15 17:06:10 +0100 |
commit | 10e0436f36b8934772b9df575deb31ffad834f1d (patch) | |
tree | c8f6c6c86e019e7be5f092016670df27b1a7d48a /src | |
parent | ed80595290029d9f4909e50e07c99d9e7a6d6625 (diff) | |
parent | 5da4f38b15d6bd6b6dd68ab55a3cedfd8ae6ff25 (diff) | |
download | hercules-10e0436f36b8934772b9df575deb31ffad834f1d.tar.gz hercules-10e0436f36b8934772b9df575deb31ffad834f1d.tar.bz2 hercules-10e0436f36b8934772b9df575deb31ffad834f1d.tar.xz hercules-10e0436f36b8934772b9df575deb31ffad834f1d.zip |
Merge pull request #2572 from Asheraf/mobviewdatadb
Add support for overriding default view data in mob database
Diffstat (limited to 'src')
-rw-r--r-- | src/map/mob.c | 112 | ||||
-rw-r--r-- | src/map/mob.h | 3 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking.Defs.inc | 6 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc | 12 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc | 3 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 55 |
6 files changed, 130 insertions, 61 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index dce084a23..60b6977bb 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -4178,6 +4178,50 @@ static void mob_read_db_stats_sub(struct mob_db *entry, struct config_setting_t } /** + * Processes the view data for a mob_db entry. + * + * @param[in,out] entry The destination mob_db entry, already initialized + * (mob_id, status.mode are expected to be already set). + * @param[in] t The libconfig entry. + */ +static void mob_read_db_viewdata_sub(struct mob_db *entry, struct config_setting_t *t) +{ + nullpo_retv(entry); + nullpo_retv(t); + + struct config_setting_t *it; + int i32; + + if ((it = libconfig->setting_get_member(t, "SpriteId")) != NULL) + entry->vd.class = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "WeaponId")) != NULL) + entry->vd.weapon = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "ShieldId")) != NULL) + entry->vd.shield = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "RobeId")) != NULL) + entry->vd.robe = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "HeadTopId")) != NULL) + entry->vd.head_top = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "HeadMidId")) != NULL) + entry->vd.head_mid = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "HeadLowId")) != NULL) + entry->vd.head_bottom = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "HairStyleId")) != NULL) + entry->vd.hair_style = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "BodyStyleId")) != NULL) + entry->vd.body_style = libconfig->setting_get_int(it); + if ((it = libconfig->setting_get_member(t, "HairColorId")) != NULL) + entry->vd.hair_color = libconfig->setting_get_uint16(it); + if ((it = libconfig->setting_get_member(t, "BodyColorId")) != NULL) + entry->vd.cloth_color = libconfig->setting_get_uint16(it); + if (mob->lookup_const(t, "Gender", &i32) && i32 >= 0) { + entry->vd.sex = (char)i32; + } + if ((it = libconfig->setting_get_member(t, "Options")) != NULL) + entry->option = libconfig->setting_get_int(it) &~ (OPTION_HIDE | OPTION_CLOAK | OPTION_INVISIBLE); +} + +/** * Processes the mode for a mob_db entry. * * @param[in] entry The destination mob_db entry, already initialized. @@ -4657,6 +4701,22 @@ static int mob_read_db_sub(struct config_setting_t *mobt, int n, const char *sou * AegisName: (chance, "Option Drop Group") * ... * } + * DamageTakenRate: damage taken rate + * ViewData: { + * SpriteId: sprite id + * WeaponId: weapon id + * ShieldId: shield id + * RobeId: garment id + * HeadTopId: top headgear id + * HeadMidId: middle headgear id + * HeadLowId: lower headgear id + * HairStyleId: hair style id + * BodyStyleId: clothes id + * HairColorId: hair color id + * BodyColorId: clothes color id + * Gender: gender + * Options: options + * } */ if (!libconfig->setting_lookup_int(mobt, "Id", &i32)) { @@ -4886,6 +4946,12 @@ static int mob_read_db_sub(struct config_setting_t *mobt, int n, const char *sou md.dmg_taken_rate = 100; } + if ((t = libconfig->setting_get_member(mobt, "ViewData"))) { + if (config_setting_is_group(t)) { + mob->read_db_viewdata_sub(&md, t); + } + } + mob->read_db_additional_fields(&md, mobt, n, source); return mob->db_validate_entry(&md, n, source); @@ -5021,46 +5087,15 @@ static void mob_name_constants(void) #endif // ENABLE_CASE_CHECK } -/*========================================== - * MOB display graphic change data reading - *------------------------------------------*/ -static bool mob_readdb_mobavail(char *str[], int columns, int current) +static void mob_mobavail_removal_notice(void) { - int class_, view_class; - - nullpo_retr(false, str); - class_=atoi(str[0]); - - if(mob->db(class_) == mob->dummy) { - // invalid class (probably undefined in db) - ShowWarning("mob_readdb_mobavail: Unknown mob id %d.\n", class_); - return false; - } - - view_class = atoi(str[1]); + char filepath[256]; - memset(&mob->db_data[class_]->vd, 0, sizeof(struct view_data)); - mob->db_data[class_]->vd.class = view_class; + safesnprintf(filepath, sizeof(filepath), "%s/mob_avail.txt", map->db_path); - //Player sprites - if (pc->db_checkid(view_class) && columns == 12) { - mob->db_data[class_]->vd.sex=atoi(str[2]); - mob->db_data[class_]->vd.hair_style=atoi(str[3]); - mob->db_data[class_]->vd.hair_color=atoi(str[4]); - mob->db_data[class_]->vd.weapon=atoi(str[5]); - mob->db_data[class_]->vd.shield=atoi(str[6]); - mob->db_data[class_]->vd.head_top=atoi(str[7]); - mob->db_data[class_]->vd.head_mid=atoi(str[8]); - mob->db_data[class_]->vd.head_bottom=atoi(str[9]); - mob->db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE); - mob->db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris + if (exists(filepath)) { + ShowError("mob_mobavail_removal_notice: the usage of mob_avail.txt is no longer supported, move your data using tools/mobavailconverter.py and delete the database file to suspend this message.\n"); } - else if(columns==3) - mob->db_data[class_]->vd.head_bottom=atoi(str[2]); // mob equipment [Valaris] - else if( columns != 2 ) - return false; - - return true; } /*========================================== @@ -5578,7 +5613,7 @@ static void mob_load(bool minimal) mob->readchatdb(); mob->readdb(); mob->readskilldb(); - sv->readdb(map->db_path, "mob_avail.txt", ',', 2, 12, -1, mob->readdb_mobavail); + mob->mobavail_removal_notice(); mob->read_randommonster(); sv->readdb(map->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, mob->readdb_race2); } @@ -5900,8 +5935,9 @@ void mob_defaults(void) 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->read_db_viewdata_sub = mob_read_db_viewdata_sub; mob->name_constants = mob_name_constants; - mob->readdb_mobavail = mob_readdb_mobavail; + mob->mobavail_removal_notice = mob_mobavail_removal_notice; mob->read_randommonster = mob_read_randommonster; mob->parse_row_chatdb = mob_parse_row_chatdb; mob->readchatdb = mob_readchatdb; diff --git a/src/map/mob.h b/src/map/mob.h index 6c3aa938b..6693c3671 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -589,8 +589,9 @@ struct mob_interface { 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 (*read_db_viewdata_sub) (struct mob_db *entry, struct config_setting_t *t); void (*name_constants) (void); - bool (*readdb_mobavail) (char *str[], int columns, int current); + void (*mobavail_removal_notice) (void); int (*read_randommonster) (void); bool (*parse_row_chatdb) (char **str, const char *source, int line, int *last_msg_id); void (*readchatdb) (void); diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index f878f36b8..89c9024cc 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -5482,10 +5482,12 @@ typedef struct optdrop_group* (*HPMHOOK_pre_mob_read_db_drops_option) (struct mo typedef struct optdrop_group* (*HPMHOOK_post_mob_read_db_drops_option) (struct optdrop_group* retVal___, struct mob_db *entry, const char *item_name, struct config_setting_t *drop, int *drop_rate); typedef void (*HPMHOOK_pre_mob_read_db_stats_sub) (struct mob_db **entry, struct config_setting_t **t); typedef void (*HPMHOOK_post_mob_read_db_stats_sub) (struct mob_db *entry, struct config_setting_t *t); +typedef void (*HPMHOOK_pre_mob_read_db_viewdata_sub) (struct mob_db **entry, struct config_setting_t **t); +typedef void (*HPMHOOK_post_mob_read_db_viewdata_sub) (struct mob_db *entry, struct config_setting_t *t); typedef void (*HPMHOOK_pre_mob_name_constants) (void); typedef void (*HPMHOOK_post_mob_name_constants) (void); -typedef bool (*HPMHOOK_pre_mob_readdb_mobavail) (char **str[], int *columns, int *current); -typedef bool (*HPMHOOK_post_mob_readdb_mobavail) (bool retVal___, char *str[], int columns, int current); +typedef void (*HPMHOOK_pre_mob_mobavail_removal_notice) (void); +typedef void (*HPMHOOK_post_mob_mobavail_removal_notice) (void); typedef int (*HPMHOOK_pre_mob_read_randommonster) (void); typedef int (*HPMHOOK_post_mob_read_randommonster) (int retVal___); typedef bool (*HPMHOOK_pre_mob_parse_row_chatdb) (char ***str, const char **source, int *line, int **last_msg_id); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index ce716729a..9c4fe9b6f 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -4084,10 +4084,12 @@ struct { struct HPMHookPoint *HP_mob_read_db_drops_option_post; struct HPMHookPoint *HP_mob_read_db_stats_sub_pre; struct HPMHookPoint *HP_mob_read_db_stats_sub_post; + struct HPMHookPoint *HP_mob_read_db_viewdata_sub_pre; + struct HPMHookPoint *HP_mob_read_db_viewdata_sub_post; struct HPMHookPoint *HP_mob_name_constants_pre; struct HPMHookPoint *HP_mob_name_constants_post; - struct HPMHookPoint *HP_mob_readdb_mobavail_pre; - struct HPMHookPoint *HP_mob_readdb_mobavail_post; + struct HPMHookPoint *HP_mob_mobavail_removal_notice_pre; + struct HPMHookPoint *HP_mob_mobavail_removal_notice_post; struct HPMHookPoint *HP_mob_read_randommonster_pre; struct HPMHookPoint *HP_mob_read_randommonster_post; struct HPMHookPoint *HP_mob_parse_row_chatdb_pre; @@ -10919,10 +10921,12 @@ struct { int HP_mob_read_db_drops_option_post; int HP_mob_read_db_stats_sub_pre; int HP_mob_read_db_stats_sub_post; + int HP_mob_read_db_viewdata_sub_pre; + int HP_mob_read_db_viewdata_sub_post; int HP_mob_name_constants_pre; int HP_mob_name_constants_post; - int HP_mob_readdb_mobavail_pre; - int HP_mob_readdb_mobavail_post; + int HP_mob_mobavail_removal_notice_pre; + int HP_mob_mobavail_removal_notice_post; int HP_mob_read_randommonster_pre; int HP_mob_read_randommonster_post; int HP_mob_parse_row_chatdb_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index f29820952..99e3fd5a1 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -2091,8 +2091,9 @@ struct HookingPointData HookingPoints[] = { { HP_POP(mob->read_db_mode_sub, HP_mob_read_db_mode_sub) }, { HP_POP(mob->read_db_drops_option, HP_mob_read_db_drops_option) }, { HP_POP(mob->read_db_stats_sub, HP_mob_read_db_stats_sub) }, + { HP_POP(mob->read_db_viewdata_sub, HP_mob_read_db_viewdata_sub) }, { HP_POP(mob->name_constants, HP_mob_name_constants) }, - { HP_POP(mob->readdb_mobavail, HP_mob_readdb_mobavail) }, + { HP_POP(mob->mobavail_removal_notice, HP_mob_mobavail_removal_notice) }, { HP_POP(mob->read_randommonster, HP_mob_read_randommonster) }, { HP_POP(mob->parse_row_chatdb, HP_mob_parse_row_chatdb) }, { HP_POP(mob->readchatdb, HP_mob_readchatdb) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index bcbfb7c3e..147458d09 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -54163,6 +54163,32 @@ void HP_mob_read_db_stats_sub(struct mob_db *entry, struct config_setting_t *t) } return; } +void HP_mob_read_db_viewdata_sub(struct mob_db *entry, struct config_setting_t *t) { + int hIndex = 0; + if (HPMHooks.count.HP_mob_read_db_viewdata_sub_pre > 0) { + void (*preHookFunc) (struct mob_db **entry, struct config_setting_t **t); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_read_db_viewdata_sub_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_mob_read_db_viewdata_sub_pre[hIndex].func; + preHookFunc(&entry, &t); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.mob.read_db_viewdata_sub(entry, t); + } + if (HPMHooks.count.HP_mob_read_db_viewdata_sub_post > 0) { + void (*postHookFunc) (struct mob_db *entry, struct config_setting_t *t); + for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_read_db_viewdata_sub_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_mob_read_db_viewdata_sub_post[hIndex].func; + postHookFunc(entry, t); + } + } + return; +} void HP_mob_name_constants(void) { int hIndex = 0; if (HPMHooks.count.HP_mob_name_constants_pre > 0) { @@ -54189,32 +54215,31 @@ void HP_mob_name_constants(void) { } return; } -bool HP_mob_readdb_mobavail(char *str[], int columns, int current) { +void HP_mob_mobavail_removal_notice(void) { int hIndex = 0; - bool retVal___ = false; - if (HPMHooks.count.HP_mob_readdb_mobavail_pre > 0) { - bool (*preHookFunc) (char **str[], int *columns, int *current); + if (HPMHooks.count.HP_mob_mobavail_removal_notice_pre > 0) { + void (*preHookFunc) (void); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_readdb_mobavail_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_mob_readdb_mobavail_pre[hIndex].func; - retVal___ = preHookFunc(&str, &columns, ¤t); + for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_mobavail_removal_notice_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_mob_mobavail_removal_notice_pre[hIndex].func; + preHookFunc(); } if (*HPMforce_return) { *HPMforce_return = false; - return retVal___; + return; } } { - retVal___ = HPMHooks.source.mob.readdb_mobavail(str, columns, current); + HPMHooks.source.mob.mobavail_removal_notice(); } - if (HPMHooks.count.HP_mob_readdb_mobavail_post > 0) { - bool (*postHookFunc) (bool retVal___, char *str[], int columns, int current); - for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_readdb_mobavail_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_mob_readdb_mobavail_post[hIndex].func; - retVal___ = postHookFunc(retVal___, str, columns, current); + if (HPMHooks.count.HP_mob_mobavail_removal_notice_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_mob_mobavail_removal_notice_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_mob_mobavail_removal_notice_post[hIndex].func; + postHookFunc(); } } - return retVal___; + return; } int HP_mob_read_randommonster(void) { int hIndex = 0; |