Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move armor protection to Core #218

Merged
merged 2 commits into from
Mar 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions difficulties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,42 @@ 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
else
local Damages = MobDamages[Attacker:GetClass()]
if Damages then
TDI.FinalDamage = Damages[WorldDifficulty]
end
end
return false
end

local Damages = MobDamages[Attacker:GetClass()]
if (Damages ~= nil) then
TDI.FinalDamage = Damages[WorldDifficulty]
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)
Expand Down