Skip to content

Commit

Permalink
Implement s_mob_db constructor (rathena#7799)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
aleos89 authored Oct 25, 2023
1 parent ba1ed0f commit 2487d2b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 120 deletions.
128 changes: 22 additions & 106 deletions src/map/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<e_mode>(MONSTER_TYPE_06);

vd.class_ = id;
}

/**
* Reads and parses an entry from the mob_db.
* @param node: YAML node containing the entry.
Expand Down Expand Up @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -4474,9 +4483,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
return 0;

mob->base_exp = static_cast<t_exp>(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")) {
Expand All @@ -4486,9 +4492,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
return 0;

mob->job_exp = static_cast<t_exp>(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")) {
Expand All @@ -4498,9 +4501,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
return 0;

mob->mexp = static_cast<t_exp>(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")) {
Expand All @@ -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")) {
Expand All @@ -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
}

Expand All @@ -4547,9 +4537,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.def = static_cast<defType>(def);
} else {
if (!exists)
mob->status.def = 0;
}

if (this->nodeExists(node, "MagicDefense")) {
Expand All @@ -4564,9 +4551,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.mdef = static_cast<defType>(def);
} else {
if (!exists)
mob->status.mdef = 0;
}

if (this->nodeExists(node, "Resistance")) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -4723,9 +4672,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.size = static_cast<e_size>(constant);
} else {
if (!exists)
mob->status.size = SZ_SMALL;
}

if (this->nodeExists(node, "Race")) {
Expand All @@ -4748,9 +4694,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.race = static_cast<e_race>(constant);
} else {
if (!exists)
mob->status.race = RC_FORMLESS;
}

if (this->nodeExists(node, "RaceGroups")) {
Expand Down Expand Up @@ -4804,9 +4747,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.def_ele = static_cast<e_element>(constant);
} else {
if (!exists)
mob->status.def_ele = ELE_NEUTRAL;
}

if (this->nodeExists(node, "ElementLevel")) {
Expand All @@ -4821,9 +4761,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.ele_lv = static_cast<uint8>(level);
} else {
if (!exists)
mob->status.ele_lv = 1;
}

if (this->nodeExists(node, "WalkSpeed")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -4914,9 +4836,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.mode = static_cast<e_mode>(constant);
} else {
if (!exists)
mob->status.mode = static_cast<e_mode>(MONSTER_TYPE_06);
}

if (this->nodeExists(node, "Class")) {
Expand All @@ -4939,9 +4858,6 @@ uint64 MobDatabase::parseBodyNode(const ryml::NodeRef& node) {
}

mob->status.class_ = static_cast<uint8>(constant);
} else {
if (!exists)
mob->status.class_ = CLASS_NORMAL;
}

if (this->nodeExists(node, "Modes")) {
Expand Down
Loading

0 comments on commit 2487d2b

Please sign in to comment.