From 2487d2bf790e19fe41a0926d25fa3887b79fbaf3 Mon Sep 17 00:00:00 2001 From: Aleos Date: Wed, 25 Oct 2023 08:58:04 -0400 Subject: [PATCH] Implement s_mob_db constructor (#7799) * Follow up to 65200eb. * Removes a lot of else cases when parsing monster data. * Fixes an issue where the damagetaken value of monsters would be reset after issuing a mob_spawn(). Thanks to @Lemongrass3110, @mplaten, and @vstumpf! --- src/map/mob.cpp | 128 +++++++++--------------------------------------- src/map/mob.hpp | 29 +++++------ 2 files changed, 37 insertions(+), 120 deletions(-) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index d157f14163e..c38d1840272 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -4212,7 +4212,6 @@ int mob_clone_spawn(map_session_data *sd, int16 m, int16 x, int16 y, const char if (!md) return 0; //Failed? md->special_state.clone = 1; - md->damagetaken = 100; // Avoid Green Aura reduction calculation. if (master_id || flag || duration) { //Further manipulate crafted char. if (flag&1) //Friendly Character @@ -4358,6 +4357,28 @@ bool MobDatabase::parseDropNode(std::string nodeName, const ryml::NodeRef& node, return true; } +/** + * Mob DB constructor + */ +s_mob_db::s_mob_db() +{ + status.max_hp = 1; + status.max_sp = 1; + status.str = 1; + status.agi = 1; + status.vit = 1; + status.int_ = 1; + status.dex = 1; + status.luk = 1; + status.ele_lv = 1; + status.speed = DEFAULT_WALK_SPEED; + status.adelay = cap_value(0, battle_config.monster_max_aspd * 2, 4000); + status.amotion = cap_value(0, battle_config.monster_max_aspd, 2000); + status.mode = static_cast(MONSTER_TYPE_06); + + vd.class_ = id; +} + /** * Reads and parses an entry from the mob_db. * @param node: YAML node containing the entry. @@ -4426,9 +4447,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { name.resize(NAME_LENGTH); mob->jname = name; - } else { - if (!exists) - mob->jname = mob->name; } if (this->nodeExists(node, "Level")) { @@ -4438,9 +4456,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->lv = level; - } else { - if (!exists) - mob->lv = 1; } if (this->nodeExists(node, "Hp")) { @@ -4450,9 +4465,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.max_hp = hp; - } else { - if (!exists) - mob->status.max_hp = 1; } if (this->nodeExists(node, "Sp")) { @@ -4462,9 +4474,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.max_sp = sp; - } else { - if (!exists) - mob->status.max_sp = 1; } if (this->nodeExists(node, "BaseExp")) { @@ -4474,9 +4483,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->base_exp = static_cast(cap_value((double)exp * (double)battle_config.base_exp_rate / 100., 0, MAX_EXP)); - } else { - if (!exists) - mob->base_exp = 0; } if (this->nodeExists(node, "JobExp")) { @@ -4486,9 +4492,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->job_exp = static_cast(cap_value((double)exp * (double)battle_config.job_exp_rate / 100., 0, MAX_EXP)); - } else { - if (!exists) - mob->job_exp = 0; } if (this->nodeExists(node, "MvpExp")) { @@ -4498,9 +4501,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->mexp = static_cast(cap_value((double)exp * (double)battle_config.mvp_exp_rate / 100., 0, MAX_EXP)); - } else { - if (!exists) - mob->mexp = 0; } if (this->nodeExists(node, "Attack")) { @@ -4510,9 +4510,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.rhw.atk = atk; - } else { - if (!exists) - mob->status.rhw.atk = 0; } if (this->nodeExists(node, "Attack2")) { @@ -4525,13 +4522,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { mob->status.rhw.matk = atk; #else mob->status.rhw.atk2 = atk; -#endif - } else { - if (!exists) -#ifdef RENEWAL - mob->status.rhw.matk = 0; -#else - mob->status.rhw.atk2 = 0; #endif } @@ -4547,9 +4537,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.def = static_cast(def); - } else { - if (!exists) - mob->status.def = 0; } if (this->nodeExists(node, "MagicDefense")) { @@ -4564,9 +4551,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.mdef = static_cast(def); - } else { - if (!exists) - mob->status.mdef = 0; } if (this->nodeExists(node, "Resistance")) { @@ -4577,10 +4561,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { mob->status.res = res; } - else { - if (!exists) - mob->status.res = 0; - } if (this->nodeExists(node, "MagicResistance")) { uint16 mres; @@ -4590,10 +4570,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { mob->status.mres = mres; } - else { - if (!exists) - mob->status.mres = 0; - } if (this->nodeExists(node, "Str")) { uint16 stat; @@ -4602,9 +4578,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.str = max(1, stat); - } else { - if (!exists) - mob->status.str = 1; } if (this->nodeExists(node, "Agi")) { @@ -4614,9 +4587,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.agi = max(1, stat); - } else { - if (!exists) - mob->status.agi = 1; } if (this->nodeExists(node, "Vit")) { @@ -4626,9 +4596,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.vit = max(1, stat); - } else { - if (!exists) - mob->status.vit = 1; } if (this->nodeExists(node, "Int")) { @@ -4638,9 +4605,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.int_ = max(1, stat); - } else { - if (!exists) - mob->status.int_ = 1; } if (this->nodeExists(node, "Dex")) { @@ -4650,9 +4614,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.dex = max(1, stat); - } else { - if (!exists) - mob->status.dex = 1; } if (this->nodeExists(node, "Luk")) { @@ -4662,9 +4623,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.luk = max(1, stat); - } else { - if (!exists) - mob->status.luk = 1; } if (this->nodeExists(node, "AttackRange")) { @@ -4674,9 +4632,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.rhw.range = range; - } else { - if (!exists) - mob->status.rhw.range = 0; } if (this->nodeExists(node, "SkillRange")) { @@ -4686,9 +4641,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->range2 = range; - } else { - if (!exists) - mob->range2 = 0; } if (this->nodeExists(node, "ChaseRange")) { @@ -4698,9 +4650,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->range3 = range; - } else { - if (!exists) - mob->range3 = 0; } if (this->nodeExists(node, "Size")) { @@ -4723,9 +4672,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.size = static_cast(constant); - } else { - if (!exists) - mob->status.size = SZ_SMALL; } if (this->nodeExists(node, "Race")) { @@ -4748,9 +4694,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.race = static_cast(constant); - } else { - if (!exists) - mob->status.race = RC_FORMLESS; } if (this->nodeExists(node, "RaceGroups")) { @@ -4804,9 +4747,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.def_ele = static_cast(constant); - } else { - if (!exists) - mob->status.def_ele = ELE_NEUTRAL; } if (this->nodeExists(node, "ElementLevel")) { @@ -4821,9 +4761,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.ele_lv = static_cast(level); - } else { - if (!exists) - mob->status.ele_lv = 1; } if (this->nodeExists(node, "WalkSpeed")) { @@ -4838,9 +4775,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.speed = speed; - } else { - if (!exists) - mob->status.speed = DEFAULT_WALK_SPEED; } if (this->nodeExists(node, "AttackDelay")) { @@ -4850,9 +4784,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.adelay = cap_value(speed, battle_config.monster_max_aspd * 2, 4000); - } else { - if (!exists) - mob->status.adelay = cap_value(0, battle_config.monster_max_aspd * 2, 4000); } if (this->nodeExists(node, "AttackMotion")) { @@ -4862,9 +4793,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->status.amotion = cap_value(speed, battle_config.monster_max_aspd, 2000); - } else { - if (!exists) - mob->status.amotion = cap_value(0, battle_config.monster_max_aspd, 2000); } if (this->nodeExists(node, "DamageMotion")) { @@ -4877,9 +4805,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { speed = speed * battle_config.monster_damage_delay_rate / 100; mob->status.dmotion = speed; - } else { - if (!exists) - mob->status.dmotion = 0; } if (this->nodeExists(node, "DamageTaken")) { @@ -4889,9 +4814,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { return 0; mob->damagetaken = damage; - } else { - if (!exists) - mob->damagetaken = 100; } if (this->nodeExists(node, "Ai")) { @@ -4914,9 +4836,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.mode = static_cast(constant); - } else { - if (!exists) - mob->status.mode = static_cast(MONSTER_TYPE_06); } if (this->nodeExists(node, "Class")) { @@ -4939,9 +4858,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) { } mob->status.class_ = static_cast(constant); - } else { - if (!exists) - mob->status.class_ = CLASS_NORMAL; } if (this->nodeExists(node, "Modes")) { diff --git a/src/map/mob.hpp b/src/map/mob.hpp index 643f58c4fb7..37162ba2fc9 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -253,22 +253,23 @@ struct s_mob_drop { }; struct s_mob_db { - uint32 id; - std::string sprite, name, jname; - t_exp base_exp; - t_exp job_exp; - t_exp mexp; - uint16 range2, range3; - std::vector race2; // celest - uint16 lv; - s_mob_drop dropitem[MAX_MOB_DROP_TOTAL], mvpitem[MAX_MVP_DROP_TOTAL]; - status_data status; - view_data vd; - uint32 option; - std::vector> skill; - uint16 damagetaken; + uint32 id{}; + std::string sprite{}, name{}, jname{}; + t_exp base_exp{}; + t_exp job_exp{}; + t_exp mexp{}; + uint16 range2{}, range3{}; + std::vector race2{}; // celest + uint16 lv{ 1 }; + s_mob_drop dropitem[MAX_MOB_DROP_TOTAL]{}, mvpitem[MAX_MVP_DROP_TOTAL]{}; + status_data status{}; + view_data vd{}; + uint32 option{}; + std::vector> skill{}; + uint16 damagetaken{ 100 }; e_mob_bosstype get_bosstype(); + s_mob_db(); }; class MobDatabase : public TypesafeCachedYamlDatabase {