local H=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local u=game:GetService("\073\110\115\101\114\116\083\101\114\118\105\099\101")local z=require((H:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local A=(require((H:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\083\101\114\118\101\114\083\099\114\105\112\116\083\101\114\118\105\099\101"))):GetContext(script)local Z=(z:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\073\110\115\116\097\110\099\101")):Extend()Z:SetClassName("\078\080\067\083\101\114\118\105\099\101")A:SetContextResource(Z)local W=z:GetResource("\071\097\109\101\068\097\116\097\046\071\101\110\101\114\097\116\105\111\110\046\078\080\067\072\117\109\097\110\111\105\100\068\101\115\099\114\105\112\116\105\111\110\115")local s=z:GetResource("\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110")function Z.LoadNPCModels(z)local A=Instance.new("\070\111\108\100\101\114")A.Name="\078\080\067\077\111\100\101\108\115"A.Parent=H local Z,s=pcall(function()return((u:LoadAsset(1664543044)):GetChildren())[1]end)if not Z then warn("\070\097\105\108\101\100 \116\111 \105\110\115\101\114\116 \116\104\101 \100\101\102\097\117\108\116 \099\104\097\114\097\099\116\101\114 \109\111\100\101\108 \098\101\099\097\117\115\101 "..tostring(s))s=Instance.new("\077\111\100\101\108")local H=Instance.new("\072\117\109\097\110\111\105\100")H.Parent=s local u=Instance.new("\080\097\114\116")u.Name="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"u.Size=Vector3.new(4,5,1)u.Parent=s end s.Name="\082\049\053\067\104\097\114\097\099\116\101\114\077\111\100\101\108";(s:Clone()).Parent=H for u,z in pairs(W:GetChildren())do local Z=s:Clone()Z.Name=z.Name;(Z:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")).Anchored=true Z.Parent=H;(coroutine.wrap(function()local H,u=pcall(function()(Z:WaitForChild("\072\117\109\097\110\111\105\100")):ApplyDescription(z)end)if not H then warn("\070\097\105\108\101\100 \116\111 \108\111\097\100 \104\117\109\097\110\111\105\100 \100\101\115\099\114\105\112\116\105\111\110 \102\111\114 "..(tostring(z.Name)..(" \098\101\099\097\117\115\101"..tostring(u))))end Z.Parent=A end))()end end return Z
--[[
TheNexusAvenger

Controls loading NPC models and interactions with them.
Class is static (should not be created).
--]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InsertService = game:GetService("InsertService")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))
local ServerScriptServiceProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ServerScriptService")):GetContext(script)

local NPCService = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusInstance"):Extend()
NPCService:SetClassName("NPCService")
ServerScriptServiceProject:SetContextResource(NPCService)

local NPCHumanoidDescriptions = ReplicatedStorageProject:GetResource("GameData.Generation.NPCHumanoidDescriptions")
local GameReplication = ReplicatedStorageProject:GetResource("GameReplication")



--[[
Gets the state object for a house.
--]]
function NPCService:LoadNPCModels()
    --Create the container.
    local NPCModels = Instance.new("Folder")
    NPCModels.Name = "NPCModels"
    NPCModels.Parent = ReplicatedStorage

    --Load the character model.
    local LoadModelWorked,CharacterModel = pcall(function()
        return InsertService:LoadAsset(1664543044):GetChildren()[1]
    end)
    if not LoadModelWorked then
        warn("Failed to insert the default character model because "..tostring(CharacterModel))

        --Create the backup model.
        CharacterModel = Instance.new("Model")

        local Humanoid = Instance.new("Humanoid")
        Humanoid.Parent = CharacterModel

        local HumanoidRootPart = Instance.new("Part")
        HumanoidRootPart.Name = "HumanoidRootPart"
        HumanoidRootPart.Size = Vector3.new(4,5,1)
        HumanoidRootPart.Parent = CharacterModel
    end
    CharacterModel.Name = "R15CharacterModel"
    CharacterModel:Clone().Parent = ReplicatedStorage

    --Load the characters.
    for _,HumanoidDescription in pairs(NPCHumanoidDescriptions:GetChildren()) do
        local NewCharacter = CharacterModel:Clone()
        NewCharacter.Name = HumanoidDescription.Name
        NewCharacter:WaitForChild("HumanoidRootPart").Anchored = true
        NewCharacter.Parent = ReplicatedStorage

        --Apply the humanoid description.
        coroutine.wrap(function()
            local ApplyDescriptionWorked,Error = pcall(function()
                NewCharacter:WaitForChild("Humanoid"):ApplyDescription(HumanoidDescription)
            end)
            if not ApplyDescriptionWorked then
                warn("Failed to load humanoid description for "..tostring(HumanoidDescription.Name).." because"..tostring(Error))
            end
            NewCharacter.Parent = NPCModels
        end)()
    end
end




return NPCService