local j=import("\046\047\066\097\115\101\073\110\115\116\097\110\099\101")local A=import("\046\046\047\073\110\115\116\097\110\099\101\080\114\111\112\101\114\116\121")local n=import("\046\046\047\083\105\103\110\097\108")local Q=import("\046\046\047\118\097\108\105\100\097\116\101\084\121\112\101")local i=j:extend("\072\117\109\097\110\111\105\100",{creatable=true})function i.init(A,j)(getmetatable(j)).instance.died=false end i.properties.Died=A.readOnly({getDefault=n.new})i.properties.Health=A.normal({getDefault=function()return 100 end,set=function(j,A,n)Q("\072\101\097\108\116\104",n,"\110\117\109\098\101\114")local i=(getmetatable(j)).instance local D=math.min(math.max(0,n),j.MaxHealth)i.properties.Health=D if not i.died and(D==0 and j:FindFirstAncestorWhichIsA("\087\111\114\107\115\112\097\099\101")~=nil)then i.died=true j.Died:Fire()end end})i.properties.MaxHealth=A.normal({getDefault=function()return 100 end,set=function(j,A,n)Q("\077\097\120\072\101\097\108\116\104",n,"\110\117\109\098\101\114")local i=(getmetatable(j)).instance local D=math.max(0,n)i.properties.MaxHealth=D j.Health=math.min(j.Health,D)end})return i
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
