From e239d9fb981310ef3e552631f599640136be2b7b Mon Sep 17 00:00:00 2001 From: Mat Date: Wed, 18 Mar 2020 05:48:40 +0200 Subject: [PATCH 1/2] Move armor protection to Core --- difficulties.lua | 59 ++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/difficulties.lua b/difficulties.lua index d47ab54..c3a9df0 100644 --- a/difficulties.lua +++ b/difficulties.lua @@ -73,38 +73,43 @@ function HandleDifficultyCommand ( Split, Player ) end function OnTakeDamage(Receiver, TDI) - if (TDI.Attacker == nil) then - return false - end + local Attacker - local Attacker = TDI.Attacker - local WorldDifficulty = GetWorldDifficulty(Attacker:GetWorld()) + if TDI.Attacker then + Attacker = TDI.Attacker + local WorldDifficulty = GetWorldDifficulty(Attacker:GetWorld()) - if Attacker:IsA("cZombie") then - -- The damage value from the zombie is computed from the zombie health. See http://minecraft.gamepedia.com/Zombie - if (WorldDifficulty == 1) then - if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 2 - elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 3 - elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 3 - else TDI.FinalDamage = 4 end - elseif (WorldDifficulty == 2) then - if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 3 - elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 4 - elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 5 - else TDI.FinalDamage = 6 end - elseif (WorldDifficulty == 3) then - if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 4 - elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 6 - elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 7 - else TDI.FinalDamage = 9 end + if Attacker:IsA("cZombie") then + -- The damage value from the zombie is computed from the zombie health. See http://minecraft.gamepedia.com/Zombie + if (WorldDifficulty == 1) then + if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 2 + elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 3 + elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 3 + else TDI.FinalDamage = 4 end + elseif (WorldDifficulty == 2) then + if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 3 + elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 4 + elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 5 + else TDI.FinalDamage = 6 end + elseif (WorldDifficulty == 3) then + if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 4 + elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 6 + elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 7 + else TDI.FinalDamage = 9 end + end + return false end - return false - end - local Damages = MobDamages[Attacker:GetClass()] - if (Damages ~= nil) then - TDI.FinalDamage = Damages[WorldDifficulty] + local Damages = MobDamages[Attacker:GetClass()] + if Damages then + TDI.FinalDamage = Damages[WorldDifficulty] + end end + + -- Apply armor protection + local ArmorCover = Receiver:GetArmorCoverAgainst(Attacker, TDI.DamageType, TDI.FinalDamage) + local EnchantmentCover = Receiver:GetEnchantmentCoverAgainst(Attacker, TDI.DamageType, TDI.FinalDamage) + TDI.FinalDamage = TDI.FinalDamage - ArmorCover - EnchantmentCover end function OnSpawningEntity(World, Entity) From 6d1d4a0b7f14a913ff7598003e30d8f62f87b747 Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 19 Mar 2020 22:25:53 +0200 Subject: [PATCH 2/2] Apply armor protection for zombie cases --- difficulties.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/difficulties.lua b/difficulties.lua index c3a9df0..665b4cc 100644 --- a/difficulties.lua +++ b/difficulties.lua @@ -97,12 +97,11 @@ function OnTakeDamage(Receiver, TDI) elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 7 else TDI.FinalDamage = 9 end end - return false - end - - local Damages = MobDamages[Attacker:GetClass()] - if Damages then - TDI.FinalDamage = Damages[WorldDifficulty] + else + local Damages = MobDamages[Attacker:GetClass()] + if Damages then + TDI.FinalDamage = Damages[WorldDifficulty] + end end end