local ZomboWinDefeat = require("ZomboWinDefeat/ZomboWinDefeat")
local ZomboWinDefeatConfig = ZomboWinDefeatConfig

--[[

Codes within here are MOSTLY from Toad's MoreTraits.

--]]

function MEPlayerHit(player, _, __)
	if player:isZombie() then
		return
	end
	
	if ZomboWinDefeatConfig.ModOptions.options.box0 then
	--^if player:HasTrait("evasive") then^
		if player:getCurrentState() == PlayerHitReactionState.instance() then
			for i = 0, player:getBodyDamage():getBodyParts():size() - 1 do
				local bodypart = player:getBodyDamage():getBodyParts():get(i);
				if bodypart:HasInjury() == true then
					if ZomboWinDefeatConfig.ModOptions.options.box1 then
						--HaloTextHelper.addTextWithArrow(player, getText("UI_trait_dodgesay"), true, HaloTextHelper.getColorGreen());
						if bodypart:IsInfected() then
								-- local isNotGroin = player:getBodyDamage():getBodyPart((BodyPartType.FromString("Groin")) <-- This could be a future feature!
								-- if bodypart ~= isNotGroin and  <-- This could be a future feature!
								bodypart:SetInfected(false);
								player:getBodyDamage():setInfected(false);
								player:getBodyDamage():setInfectionMortalityDuration(-1);
								player:getBodyDamage():setInfectionTime(-1);
								player:getBodyDamage():setInfectionLevel(0);
								player:getBodyDamage():setInfectionGrowthRate(0);
								--end <-- This could be a future feature!
						end
						bodypart:setBleedingTime(0);
						bodypart:setBleeding(false);
						if bodypart:scratched() then
							bodypart:setScratchTime(0);
							bodypart:setScratched(false, false);
						end
						if bodypart:isCut() then
							bodypart:setCutTime(0);
							bodypart:setCut(false, false);
						end
						if bodypart:bitten() then
							bodypart:setBandaged(true, 10, true, "Base.AlcoholBandage");
							bodypart:setBiteTime(0);
							bodypart:setBandaged(false, 0, true, "Base.AlcoholBandage");
							--bodypart:RestoreToFullHealth();
						end
					end
				end
			end
		end
	end
end

Events.OnPlayerGetDamage.Add(MEPlayerHit)