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