local e=import("\046\047\066\097\115\101\073\110\115\116\097\110\099\101")local f=import("\046\046\047\073\110\115\116\097\110\099\101\080\114\111\112\101\114\116\121")local O=import("\046\046\047\083\105\103\110\097\108")local k=import("\046\046\047\118\097\108\105\100\097\116\101\084\121\112\101")local o=e:extend("\072\117\109\097\110\111\105\100",{creatable=true})function o.init(f,e)(getmetatable(e)).instance.died=false end o.properties.Died=f.readOnly({getDefault=O.new})o.properties.Health=f.normal({getDefault=function()return 100 end;set=function(e,f,O)k("\072\101\097\108\116\104",O,"\110\117\109\098\101\114")local o=(getmetatable(e)).instance local y=math.min(math.max(0,O),e.MaxHealth)o.properties.Health=y if not o.died and(y==0 and e:FindFirstAncestorWhichIsA("\087\111\114\107\115\112\097\099\101")~=nil)then o.died=true e.Died:Fire()end end})o.properties.MaxHealth=f.normal({getDefault=function()return 100 end,set=function(e,f,O)k("\077\097\120\072\101\097\108\116\104",O,"\110\117\109\098\101\114")local o=(getmetatable(e)).instance local y=math.max(0,O)o.properties.MaxHealth=y e.Health=math.min(e.Health,y)end})return o
local BaseInstance = import("./BaseInstance")
local InstanceProperty = import("../InstanceProperty")
local Signal = import("../Signal")
local validateType = import("../validateType")

local Humanoid = BaseInstance:extend("Humanoid", {
	creatable = true,
})

function Humanoid:init(instance)
	getmetatable(instance).instance.died = false
end

Humanoid.properties.Died = InstanceProperty.readOnly({
	getDefault = Signal.new
})

Humanoid.properties.Health = InstanceProperty.normal({
	getDefault = function()
		return 100
	end,

	set = function(self, key, value)
		validateType("Health", value, "number")
		local instance = getmetatable(self).instance
		local health = math.min(
			math.max(0, value),
			self.MaxHealth
		)

		instance.properties.Health = health

		if not instance.died and health == 0 and self:FindFirstAncestorWhichIsA("Workspace") ~= nil then
			instance.died = true
			self.Died:Fire()
		end
	end,
})

Humanoid.properties.MaxHealth = InstanceProperty.normal({
	getDefault = function()
		return 100
	end,

	set = function(self, key, value)
		validateType("MaxHealth", value, "number")
		local instance = getmetatable(self).instance
		local maxHealth = math.max(0, value)

		instance.properties.MaxHealth = maxHealth
		self.Health = math.min(self.Health, maxHealth)
	end,
})

return Humanoid
