-- Some cool functions idk
-- Andrew Bereza


local Utl = {}

function Utl.CurrentDay()
	return math.floor(os.time()/86400)
end

function Utl.GetPlayerData(PlayerId)
	local Module = game.ServerStorage.PlayerData:FindFirstChild(tostring(PlayerId))
	if Module then
		return require(Module)
	end
end

function Utl.NewPlayerData(Player, PlayerData)
	local Module = game.ServerStorage.PlayerData:FindFirstChild(tostring(Player.userId))
	if Module then 
		Module:Destroy()
	end
	local NewModule = game.ServerStorage.PlayerDataTemplate:Clone()
	NewModule.Name = tostring(Player.userId)
	NewModule.Parent = game.ServerStorage.PlayerData
	local FreshTable = require(NewModule)
	for Key,Value in pairs(PlayerData) do
		FreshTable[Key] = Value
	end
end

function Utl.IntToBool(Int)
	return (Int == 1 and true) or false
end

function Utl.BoolToInt(Bool)
	return (Bool and 1) or 0
end

function Utl.GetTycoon(Player)
	for i,Tycoon in pairs(workspace.Tycoons:GetChildren()) do
		if Tycoon.Owner.Value == Player then
			return Tycoon
		end
	end
end

function Utl.GetEmptyTycoon()
	for i,Tycoon in pairs(workspace.Tycoons:GetChildren()) do
		if Tycoon.Owner.Value == nil then
			return Tycoon
		elseif Tycoon.Owner.Value.Parent ~= game.Players then
			Tycoon.Owner.Value = nil -- Clears it up for the next person
		end
	end
end

function Utl.CreateTag(Player, Name)
	if Player:FindFirstChild(Name) == nil then
		local Tag = Instance.new("BoolValue")
		Tag.Name = Name
		Tag.Parent = Player
	end
end


Utl.ShuttingDown = false

return Utl
