From 8df8d7c3f66d4cbfa1c47f6e041b4623912cffa8 Mon Sep 17 00:00:00 2001 From: KimLS Date: Fri, 16 Jun 2017 23:12:54 -0700 Subject: [PATCH] Bugs in mod return values fixed --- utils/mods/legacy_combat.lua | 33 +++++++++++++++---- zone/exp.cpp | 12 ++++--- zone/lua_mod.cpp | 63 ++++++++++++------------------------ zone/lua_mod.h | 10 +++--- zone/lua_parser.cpp | 16 ++++----- 5 files changed, 67 insertions(+), 67 deletions(-) diff --git a/utils/mods/legacy_combat.lua b/utils/mods/legacy_combat.lua index a27435be9..90f07a742 100644 --- a/utils/mods/legacy_combat.lua +++ b/utils/mods/legacy_combat.lua @@ -50,7 +50,7 @@ function MeleeMitigation(e) end e.hit.damage_done = 2 * e.hit.base_damage * GetDamageTable(e.other, e.hit.skill) / 100; - e.hit = DoMeleeMitigation(e.self, e.other, e.hit, e.opts); + e.hit = DoMeleeMitigation(e.self, e.other, e.hit, e.opts); return e; end @@ -582,9 +582,9 @@ function ClientGetMeleeMitDmg(defender, attacker, damage, min_damage, mitigation local d = 10; local dmg_interval = (damage - min_damage) / 19.0; local dmg_bonus = min_damage - dmg_interval; - local spellMeleeMit = (defender:GetSpellBonuses():MeleeMitigationEffect() + defender:GetItemBonuses():MeleeMitigationEffect() + defender:GetAABonuses():MeleeMitigationEffect()) / 100.0; + local spellMeleeMit = (defender:GetSpellBonuses():MeleeMitigationEffect() + defender:GetItemBonuses():MeleeMitigationEffect() + defender:GetAABonuses():MeleeMitigationEffect()) / 100.0; if (defender:GetClass() == Class.WARRIOR) then - spellMeleeMit = spellMeleeMit + 0.05; + spellMeleeMit = spellMeleeMit - 0.05; end dmg_bonus = dmg_bonus - (dmg_bonus * (defender:GetItemBonuses():MeleeMitigation() / 100.0)); @@ -652,12 +652,12 @@ function MobGetMeleeMitDmg(defender, attacker, damage, min_damage, mitigation_ra elseif (d > 20.0) then d = 20.0; end - - local interval = (damage - min_damage) / 20.0; - damage = damage - (math.floor(d) * interval); + local interval = (damage - min_damage) / 20.0; + damage = damage - (math.floor(d) * interval); damage = damage - (min_damage * defender:GetItemBonuses():MeleeMitigation() / 100); - damage = damage - (damage * (defender:GetSpellBonuses():MeleeMitigationEffect() + defender:GetItemBonuses():MeleeMitigationEffect() + defender:GetAABonuses():MeleeMitigationEffect()) / 100); + damage = damage + (damage * (defender:GetSpellBonuses():MeleeMitigationEffect() + defender:GetItemBonuses():MeleeMitigationEffect() + defender:GetAABonuses():MeleeMitigationEffect()) / 100); + return damage; end @@ -731,3 +731,22 @@ function ApplyDamageTable(e) e.IgnoreDefault = true; return e; end + +function CommonOutgoingHitSuccess(e) + e = ApplyMeleeDamageBonus(e); + e.hit.damage_done = e.hit.damage_done + (e.hit.damage_done * e.other:GetSkillDmgTaken(e.hit.skill) / 100) + (e.self:GetSkillDmgAmt(e.hit.skill) + e.other:GetFcDamageAmtIncoming(e.self, 0, true, e.hit.skill)); + e = TryCriticalHit(e); + e.self:CheckNumHitsRemaining(5, -1, 65535); + e.IgnoreDefault = true; + return e; +end + +function ApplyMeleeDamageBonus(e) + local dmgbonusmod = e.self:GetMeleeDamageMod_SE(e.hit.skill); + if (opts) then + dmgbonusmod = dmgbonusmod + e.opts.melee_damage_bonus_flat; + end + + e.hit.damage_done = e.hit.damage_done + (e.hit.damage_done * dmgbonusmod / 100); + return e; +end \ No newline at end of file diff --git a/zone/exp.cpp b/zone/exp.cpp index fe2cfd543..7d9a02fa8 100644 --- a/zone/exp.cpp +++ b/zone/exp.cpp @@ -398,19 +398,23 @@ void Client::SetEXP(uint32 set_exp, uint32 set_aaxp, bool isrezzexp) { } if (isrezzexp) { - if (RuleI(Character, ShowExpValues) > 0) Message(MT_Experience, "You regain %s experience from resurrection. %s", exp_amount_message.c_str(), exp_percent_message.c_str()); + if (RuleI(Character, ShowExpValues) > 0) + Message(MT_Experience, "You regain %s experience from resurrection. %s", exp_amount_message.c_str(), exp_percent_message.c_str()); else Message_StringID(MT_Experience, REZ_REGAIN); } else { if (membercount > 1) { - if (RuleI(Character, ShowExpValues) > 0) Message(MT_Experience, "You have gained %s party experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); + if (RuleI(Character, ShowExpValues) > 0) + Message(MT_Experience, "You have gained %s party experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); else Message_StringID(MT_Experience, GAIN_GROUPXP); } else if (IsRaidGrouped()) { - if (RuleI(Character, ShowExpValues) > 0) Message(MT_Experience, "You have gained %s raid experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); + if (RuleI(Character, ShowExpValues) > 0) + Message(MT_Experience, "You have gained %s raid experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); else Message_StringID(MT_Experience, GAIN_RAIDEXP); } else { - if (RuleI(Character, ShowExpValues) > 0) Message(MT_Experience, "You have gained %s experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); + if (RuleI(Character, ShowExpValues) > 0) + Message(MT_Experience, "You have gained %s experience! %s", exp_amount_message.c_str(), exp_percent_message.c_str()); else Message_StringID(MT_Experience, GAIN_XP); } } diff --git a/zone/lua_mod.cpp b/zone/lua_mod.cpp index ba675c767..a891fb064 100644 --- a/zone/lua_mod.cpp +++ b/zone/lua_mod.cpp @@ -181,7 +181,6 @@ void GetExtraAttackOptions(luabind::adl::object &ret, ExtraAttackOptions *opts) void LuaMod::MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; try { if (!m_has_melee_mitigation) { @@ -233,7 +232,6 @@ void LuaMod::MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, Extra void LuaMod::ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; try { if (!m_has_apply_damage_table) { @@ -278,14 +276,12 @@ void LuaMod::ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault } } -bool LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignoreDefault) { +void LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &returnValue, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; - bool retval = false; try { if (!m_has_avoid_damage) { - return retval; + return; } lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); @@ -304,7 +300,7 @@ bool LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignore std::string error = lua_tostring(L, -1); parser_->AddError(error); lua_pop(L, 1); - return retval; + return; } if (lua_type(L, -1) == LUA_TTABLE) { @@ -316,7 +312,7 @@ bool LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignore auto returnValueObj = ret["ReturnValue"]; if (luabind::type(returnValueObj) == LUA_TBOOLEAN) { - retval = luabind::object_cast(returnValueObj); + returnValue = luabind::object_cast(returnValueObj); } GetDamageHitInfo(ret, hit); @@ -331,18 +327,14 @@ bool LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignore if (n > 0) { lua_pop(L, n); } - - return retval; } -bool LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ignoreDefault) { +void LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &returnValue, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; - bool retval = false; try { if (!m_has_check_hit_chance) { - return retval; + return; } lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); @@ -361,7 +353,7 @@ bool LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ign std::string error = lua_tostring(L, -1); parser_->AddError(error); lua_pop(L, 1); - return retval; + return; } if (lua_type(L, -1) == LUA_TTABLE) { @@ -373,7 +365,7 @@ bool LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ign auto returnValueObj = ret["ReturnValue"]; if (luabind::type(returnValueObj) == LUA_TBOOLEAN) { - retval = luabind::object_cast(returnValueObj); + returnValue = luabind::object_cast(returnValueObj); } GetDamageHitInfo(ret, hit); @@ -388,14 +380,11 @@ bool LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ign if (n > 0) { lua_pop(L, n); } - - return retval; } void LuaMod::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; try { if (!m_has_common_outgoing_hit_success) { @@ -446,7 +435,6 @@ void LuaMod::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &hit, void LuaMod::TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; try { if (!m_has_try_critical_hit) { @@ -495,15 +483,13 @@ void LuaMod::TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraA } } -uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault) +void LuaMod::GetRequiredAAExperience(Client *self, uint32 &returnValue, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; - uint32 retval = 0; try { if (!m_has_get_required_aa_experience) { - return retval; + return; } lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); @@ -518,7 +504,7 @@ uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault) std::string error = lua_tostring(L, -1); parser_->AddError(error); lua_pop(L, 1); - return retval; + return; } if (lua_type(L, -1) == LUA_TTABLE) { @@ -530,7 +516,7 @@ uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault) auto returnValueObj = ret["ReturnValue"]; if (luabind::type(returnValueObj) == LUA_TNUMBER) { - retval = luabind::object_cast(returnValueObj); + returnValue = luabind::object_cast(returnValueObj); } } } @@ -543,18 +529,14 @@ uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault) if (n > 0) { lua_pop(L, n); } - - return retval; } -uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) { +void LuaMod::GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; - uint32 retval = 0; try { if (!m_has_get_exp_for_level) { - return retval; + return; } lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); @@ -570,7 +552,7 @@ uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) { std::string error = lua_tostring(L, -1); parser_->AddError(error); lua_pop(L, 1); - return retval; + return; } if (lua_type(L, -1) == LUA_TTABLE) { @@ -582,7 +564,7 @@ uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) { auto returnValueObj = ret["ReturnValue"]; if (luabind::type(returnValueObj) == LUA_TNUMBER) { - retval = luabind::object_cast(returnValueObj); + returnValue = luabind::object_cast(returnValueObj); } } } @@ -595,19 +577,16 @@ uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) { if (n > 0) { lua_pop(L, n); } - - return retval; } -uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault) +void LuaMod::GetExperienceForKill(Client *self, Mob *against, uint32 &returnValue, bool &ignoreDefault) { int start = lua_gettop(L); - ignoreDefault = false; uint32 retval = 0; try { if (!m_has_get_experience_for_kill) { - return retval; + return; } lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); @@ -624,7 +603,7 @@ uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefa std::string error = lua_tostring(L, -1); parser_->AddError(error); lua_pop(L, 1); - return retval; + return; } if (lua_type(L, -1) == LUA_TTABLE) { @@ -636,7 +615,7 @@ uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefa auto returnValueObj = ret["ReturnValue"]; if (luabind::type(returnValueObj) == LUA_TNUMBER) { - retval = luabind::object_cast(returnValueObj); + returnValue = luabind::object_cast(returnValueObj); } } } @@ -649,6 +628,4 @@ uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefa if (n > 0) { lua_pop(L, n); } - - return retval; } diff --git a/zone/lua_mod.h b/zone/lua_mod.h index 04f991f05..defc5edab 100644 --- a/zone/lua_mod.h +++ b/zone/lua_mod.h @@ -19,13 +19,13 @@ public: void MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault); void ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault); - bool AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignoreDefault); - bool CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ignoreDefault); + void AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &returnValue, bool &ignoreDefault); + void CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &returnValue, bool &ignoreDefault); void CommonOutgoingHitSuccess(Mob *self, Mob* other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault); void TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault); - uint32 GetRequiredAAExperience(Client *self, bool &ignoreDefault); - uint32 GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault); - uint32 GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault); + void GetRequiredAAExperience(Client *self, uint32 &returnValue, bool &ignoreDefault); + void GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, bool &ignoreDefault); + void GetExperienceForKill(Client *self, Mob *against, uint32 &returnValue, bool &ignoreDefault); private: LuaParser *parser_; lua_State *L; diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 8f2eda66d..c315c54a1 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -1312,7 +1312,7 @@ bool LuaParser::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool & ig { bool retval = false; for (auto &mod : mods_) { - retval = mod.AvoidDamage(self, other, hit, ignoreDefault); + mod.AvoidDamage(self, other, hit, retval, ignoreDefault); } return retval; } @@ -1321,7 +1321,7 @@ bool LuaParser::CheckHitChance(Mob *self, Mob *other, DamageHitInfo &hit, bool & { bool retval = false; for (auto &mod : mods_) { - retval = mod.CheckHitChance(self, other, hit, ignoreDefault); + mod.CheckHitChance(self, other, hit, retval, ignoreDefault); } return retval; } @@ -1342,27 +1342,27 @@ void LuaParser::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &h uint32 LuaParser::GetRequiredAAExperience(Client *self, bool &ignoreDefault) { - uint32 retval = false; + uint32 retval = 0; for (auto &mod : mods_) { - retval = mod.GetRequiredAAExperience(self, ignoreDefault); + mod.GetRequiredAAExperience(self, retval, ignoreDefault); } return retval; } uint32 LuaParser::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) { - uint32 retval = false; + uint32 retval = 0; for (auto &mod : mods_) { - retval = mod.GetEXPForLevel(self, level, ignoreDefault); + mod.GetEXPForLevel(self, level, retval, ignoreDefault); } return retval; } uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault) { - uint32 retval = false; + uint32 retval = 0; for (auto &mod : mods_) { - retval = mod.GetExperienceForKill(self, against, ignoreDefault); + mod.GetExperienceForKill(self, against, retval, ignoreDefault); } return retval; }