Bugs in mod return values fixed

This commit is contained in:
KimLS 2017-06-16 23:12:54 -07:00
parent 233ce5cf03
commit 8df8d7c3f6
5 changed files with 67 additions and 67 deletions

View File

@ -50,7 +50,7 @@ function MeleeMitigation(e)
end end
e.hit.damage_done = 2 * e.hit.base_damage * GetDamageTable(e.other, e.hit.skill) / 100; 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; return e;
end end
@ -582,9 +582,9 @@ function ClientGetMeleeMitDmg(defender, attacker, damage, min_damage, mitigation
local d = 10; local d = 10;
local dmg_interval = (damage - min_damage) / 19.0; local dmg_interval = (damage - min_damage) / 19.0;
local dmg_bonus = min_damage - dmg_interval; 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 if (defender:GetClass() == Class.WARRIOR) then
spellMeleeMit = spellMeleeMit + 0.05; spellMeleeMit = spellMeleeMit - 0.05;
end end
dmg_bonus = dmg_bonus - (dmg_bonus * (defender:GetItemBonuses():MeleeMitigation() / 100.0)); 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 elseif (d > 20.0) then
d = 20.0; d = 20.0;
end 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 - (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; return damage;
end end
@ -731,3 +731,22 @@ function ApplyDamageTable(e)
e.IgnoreDefault = true; e.IgnoreDefault = true;
return e; return e;
end 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

View File

@ -398,19 +398,23 @@ void Client::SetEXP(uint32 set_exp, uint32 set_aaxp, bool isrezzexp) {
} }
if (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 Message_StringID(MT_Experience, REZ_REGAIN);
} else { } else {
if (membercount > 1) { 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 Message_StringID(MT_Experience, GAIN_GROUPXP);
} }
else if (IsRaidGrouped()) { 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 Message_StringID(MT_Experience, GAIN_RAIDEXP);
} }
else { 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); else Message_StringID(MT_Experience, GAIN_XP);
} }
} }

View File

@ -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) { void LuaMod::MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) {
int start = lua_gettop(L); int start = lua_gettop(L);
ignoreDefault = false;
try { try {
if (!m_has_melee_mitigation) { 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) { void LuaMod::ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault) {
int start = lua_gettop(L); int start = lua_gettop(L);
ignoreDefault = false;
try { try {
if (!m_has_apply_damage_table) { 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); int start = lua_gettop(L);
ignoreDefault = false;
bool retval = false;
try { try {
if (!m_has_avoid_damage) { if (!m_has_avoid_damage) {
return retval; return;
} }
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); 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); std::string error = lua_tostring(L, -1);
parser_->AddError(error); parser_->AddError(error);
lua_pop(L, 1); lua_pop(L, 1);
return retval; return;
} }
if (lua_type(L, -1) == LUA_TTABLE) { 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"]; auto returnValueObj = ret["ReturnValue"];
if (luabind::type(returnValueObj) == LUA_TBOOLEAN) { if (luabind::type(returnValueObj) == LUA_TBOOLEAN) {
retval = luabind::object_cast<bool>(returnValueObj); returnValue = luabind::object_cast<bool>(returnValueObj);
} }
GetDamageHitInfo(ret, hit); GetDamageHitInfo(ret, hit);
@ -331,18 +327,14 @@ bool LuaMod::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignore
if (n > 0) { if (n > 0) {
lua_pop(L, n); 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); int start = lua_gettop(L);
ignoreDefault = false;
bool retval = false;
try { try {
if (!m_has_check_hit_chance) { if (!m_has_check_hit_chance) {
return retval; return;
} }
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); 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); std::string error = lua_tostring(L, -1);
parser_->AddError(error); parser_->AddError(error);
lua_pop(L, 1); lua_pop(L, 1);
return retval; return;
} }
if (lua_type(L, -1) == LUA_TTABLE) { 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"]; auto returnValueObj = ret["ReturnValue"];
if (luabind::type(returnValueObj) == LUA_TBOOLEAN) { if (luabind::type(returnValueObj) == LUA_TBOOLEAN) {
retval = luabind::object_cast<bool>(returnValueObj); returnValue = luabind::object_cast<bool>(returnValueObj);
} }
GetDamageHitInfo(ret, hit); GetDamageHitInfo(ret, hit);
@ -388,14 +380,11 @@ bool LuaMod::CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, bool &ign
if (n > 0) { if (n > 0) {
lua_pop(L, n); lua_pop(L, n);
} }
return retval;
} }
void LuaMod::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) void LuaMod::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault)
{ {
int start = lua_gettop(L); int start = lua_gettop(L);
ignoreDefault = false;
try { try {
if (!m_has_common_outgoing_hit_success) { 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) { void LuaMod::TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) {
int start = lua_gettop(L); int start = lua_gettop(L);
ignoreDefault = false;
try { try {
if (!m_has_try_critical_hit) { 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); int start = lua_gettop(L);
ignoreDefault = false;
uint32 retval = 0;
try { try {
if (!m_has_get_required_aa_experience) { if (!m_has_get_required_aa_experience) {
return retval; return;
} }
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); 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); std::string error = lua_tostring(L, -1);
parser_->AddError(error); parser_->AddError(error);
lua_pop(L, 1); lua_pop(L, 1);
return retval; return;
} }
if (lua_type(L, -1) == LUA_TTABLE) { if (lua_type(L, -1) == LUA_TTABLE) {
@ -530,7 +516,7 @@ uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault)
auto returnValueObj = ret["ReturnValue"]; auto returnValueObj = ret["ReturnValue"];
if (luabind::type(returnValueObj) == LUA_TNUMBER) { if (luabind::type(returnValueObj) == LUA_TNUMBER) {
retval = luabind::object_cast<uint32>(returnValueObj); returnValue = luabind::object_cast<uint32>(returnValueObj);
} }
} }
} }
@ -543,18 +529,14 @@ uint32 LuaMod::GetRequiredAAExperience(Client *self, bool &ignoreDefault)
if (n > 0) { if (n > 0) {
lua_pop(L, n); 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); int start = lua_gettop(L);
ignoreDefault = false;
uint32 retval = 0;
try { try {
if (!m_has_get_exp_for_level) { if (!m_has_get_exp_for_level) {
return retval; return;
} }
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); 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); std::string error = lua_tostring(L, -1);
parser_->AddError(error); parser_->AddError(error);
lua_pop(L, 1); lua_pop(L, 1);
return retval; return;
} }
if (lua_type(L, -1) == LUA_TTABLE) { if (lua_type(L, -1) == LUA_TTABLE) {
@ -582,7 +564,7 @@ uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) {
auto returnValueObj = ret["ReturnValue"]; auto returnValueObj = ret["ReturnValue"];
if (luabind::type(returnValueObj) == LUA_TNUMBER) { if (luabind::type(returnValueObj) == LUA_TNUMBER) {
retval = luabind::object_cast<uint32>(returnValueObj); returnValue = luabind::object_cast<uint32>(returnValueObj);
} }
} }
} }
@ -595,19 +577,16 @@ uint32 LuaMod::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) {
if (n > 0) { if (n > 0) {
lua_pop(L, n); 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); int start = lua_gettop(L);
ignoreDefault = false;
uint32 retval = 0; uint32 retval = 0;
try { try {
if (!m_has_get_experience_for_kill) { if (!m_has_get_experience_for_kill) {
return retval; return;
} }
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str()); 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); std::string error = lua_tostring(L, -1);
parser_->AddError(error); parser_->AddError(error);
lua_pop(L, 1); lua_pop(L, 1);
return retval; return;
} }
if (lua_type(L, -1) == LUA_TTABLE) { if (lua_type(L, -1) == LUA_TTABLE) {
@ -636,7 +615,7 @@ uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefa
auto returnValueObj = ret["ReturnValue"]; auto returnValueObj = ret["ReturnValue"];
if (luabind::type(returnValueObj) == LUA_TNUMBER) { if (luabind::type(returnValueObj) == LUA_TNUMBER) {
retval = luabind::object_cast<uint32>(returnValueObj); returnValue = luabind::object_cast<uint32>(returnValueObj);
} }
} }
} }
@ -649,6 +628,4 @@ uint32 LuaMod::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefa
if (n > 0) { if (n > 0) {
lua_pop(L, n); lua_pop(L, n);
} }
return retval;
} }

View File

@ -19,13 +19,13 @@ public:
void MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault); void MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault);
void ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault); void ApplyDamageTable(Mob *self, DamageHitInfo &hit, bool &ignoreDefault);
bool AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &ignoreDefault); void AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool &returnValue, bool &ignoreDefault);
bool CheckHitChance(Mob *self, Mob* other, DamageHitInfo &hit, 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 CommonOutgoingHitSuccess(Mob *self, Mob* other, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault);
void TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault); void TryCriticalHit(Mob *self, Mob *defender, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault);
uint32 GetRequiredAAExperience(Client *self, bool &ignoreDefault); void GetRequiredAAExperience(Client *self, uint32 &returnValue, bool &ignoreDefault);
uint32 GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault); void GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, bool &ignoreDefault);
uint32 GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault); void GetExperienceForKill(Client *self, Mob *against, uint32 &returnValue, bool &ignoreDefault);
private: private:
LuaParser *parser_; LuaParser *parser_;
lua_State *L; lua_State *L;

View File

@ -1312,7 +1312,7 @@ bool LuaParser::AvoidDamage(Mob *self, Mob *other, DamageHitInfo &hit, bool & ig
{ {
bool retval = false; bool retval = false;
for (auto &mod : mods_) { for (auto &mod : mods_) {
retval = mod.AvoidDamage(self, other, hit, ignoreDefault); mod.AvoidDamage(self, other, hit, retval, ignoreDefault);
} }
return retval; return retval;
} }
@ -1321,7 +1321,7 @@ bool LuaParser::CheckHitChance(Mob *self, Mob *other, DamageHitInfo &hit, bool &
{ {
bool retval = false; bool retval = false;
for (auto &mod : mods_) { for (auto &mod : mods_) {
retval = mod.CheckHitChance(self, other, hit, ignoreDefault); mod.CheckHitChance(self, other, hit, retval, ignoreDefault);
} }
return retval; return retval;
} }
@ -1342,27 +1342,27 @@ void LuaParser::CommonOutgoingHitSuccess(Mob *self, Mob *other, DamageHitInfo &h
uint32 LuaParser::GetRequiredAAExperience(Client *self, bool &ignoreDefault) uint32 LuaParser::GetRequiredAAExperience(Client *self, bool &ignoreDefault)
{ {
uint32 retval = false; uint32 retval = 0;
for (auto &mod : mods_) { for (auto &mod : mods_) {
retval = mod.GetRequiredAAExperience(self, ignoreDefault); mod.GetRequiredAAExperience(self, retval, ignoreDefault);
} }
return retval; return retval;
} }
uint32 LuaParser::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault) uint32 LuaParser::GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault)
{ {
uint32 retval = false; uint32 retval = 0;
for (auto &mod : mods_) { for (auto &mod : mods_) {
retval = mod.GetEXPForLevel(self, level, ignoreDefault); mod.GetEXPForLevel(self, level, retval, ignoreDefault);
} }
return retval; return retval;
} }
uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault) uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault)
{ {
uint32 retval = false; uint32 retval = 0;
for (auto &mod : mods_) { for (auto &mod : mods_) {
retval = mod.GetExperienceForKill(self, against, ignoreDefault); mod.GetExperienceForKill(self, against, retval, ignoreDefault);
} }
return retval; return retval;
} }