local Q=4 local h=10 local N=game:GetService("\087\111\114\107\115\112\097\099\101")local H=game:GetService("\080\108\097\121\101\114\115")local O=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local U=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local T=require((O: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 J=require((H.LocalPlayer.PlayerScripts:WaitForChild("\080\108\097\121\101\114\077\111\100\117\108\101")):WaitForChild("\067\111\110\116\114\111\108\077\111\100\117\108\101"))local t=(T:GetResource("\083\116\097\116\101\046\081\117\101\115\116\115")).new(H.LocalPlayer)local P=T:GetResource("\085\073\046\066\117\116\116\111\110\046\073\109\097\103\101\069\118\101\110\116\066\105\110\100\101\114")local b=T:GetResource("\085\073\046\065\115\112\101\099\116\082\097\116\105\111\083\119\105\116\099\104\101\114")local B=T:GetResource("\085\073\046\073\116\101\109\065\119\097\114\100\065\110\105\109\097\116\105\111\110")local L=T:GetResource("\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110\046\081\117\101\115\116\082\101\112\108\105\099\097\116\105\111\110\046\083\116\097\114\116\081\117\101\115\116")local K=T:GetResource("\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110\046\081\117\101\115\116\082\101\112\108\105\099\097\116\105\111\110\046\084\117\114\110\073\110\081\117\101\115\116")local W=T:GetResource("\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110\046\081\117\101\115\116\082\101\112\108\105\099\097\116\105\111\110\046\068\105\115\112\108\097\121\073\116\101\109\065\119\097\114\100\115")local g=Q local u=true local q=false local I=Instance.new("\083\099\114\101\101\110\071\117\105")I.Name="\068\105\097\108\111\103\086\105\101\119"I.DisplayOrder=20 I.Parent=script.Parent local r=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")r.Name="\083\116\097\114\116\068\105\097\108\111\103"r.Parent=I local p=Instance.new("\066\105\108\108\098\111\097\114\100\071\117\105")p.Name="\078\080\067\068\105\097\108\111\103"p.AlwaysOnTop=true p.Enabled=false p.SizeOffset=Vector2.new(.5,.5)p.Parent=script.Parent local y=Instance.new("\073\109\097\103\101\076\097\098\101\108")y.BackgroundTransparency=1 y.Size=UDim2.new(1,0,1,0)y.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\055\050\054\049\049\054"y.Parent=p local v=Instance.new("\084\101\120\116\076\097\098\101\108")v.BackgroundTransparency=1 v.AnchorPoint=Vector2.new(.5,.5)v.Position=UDim2.new(.35,0,.42,0)v.Size=UDim2.new(.6,0,.54,0)v.Font=Enum.Font.Antique v.TextColor3=Color3.new(0,0,0)v.TextWrapped=true v.TextXAlignment=Enum.TextXAlignment.Left v.Parent=y local function n()local Q=I.AbsoluteSize.Y p.Size=UDim2.new(0,Q*.6,0,Q*.3)v.TextSize=(112/g)*((Q*.3)/256)end;(I:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(n)n()local l=Instance.new("\073\109\097\103\101\076\097\098\101\108")l.BackgroundTransparency=1 l.Position=UDim2.new(.5,0,1.5,0)l.AnchorPoint=Vector2.new(.3175,.48)l.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\055\050\053\054\055\049"l.Parent=I b.new(I,1.1,function()l.Size=UDim2.new(1.4,0,.7,0)l.SizeConstraint="\082\101\108\097\116\105\118\101\089\089"end,function()l.Size=UDim2.new(.8,0,.4,0)l.SizeConstraint="\082\101\108\097\116\105\118\101\088\088"end)local d={}for Q=1,5,1 do local h=Instance.new("\073\109\097\103\101\076\097\098\101\108")h.BackgroundTransparency=1 h.Size=UDim2.new(1,0,.0625,0)h.Position=UDim2.new(.039,0,.03+Q*.07,0)h.Parent=l local N=P.new(h,UDim2.new(.547,0,.9,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\055\050\053\055\048\054","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\056\052\048\052\054\048","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\056\052\048\052\056\048")local H=Instance.new("\084\101\120\116\076\097\098\101\108")H.BackgroundTransparency=1 H.Size=UDim2.new(.53,0,.8,0)H.Position=UDim2.new(.01,0,-0.05,0)H.Font=Enum.Font.Antique H.TextColor3=Color3.new(0,0,0)H.TextScaled=true H.TextXAlignment=Enum.TextXAlignment.Left H.Parent=h table.insert(d,{h;N,H})end local function E()q=false p.Enabled=false l:TweenPosition(UDim2.new(.5,0,1.5,0),"\079\117\116","\081\117\097\100",.5,true)J:Enable()end local function w(N,H)if N.TurnIn then K:FireServer(H,N.TurnIn)end if N.Quest then t:AddQuest(N.Quest)L:FireServer(H,N.Quest)end v.Text=N.Text for Q=Q,h,.25 do g=Q local h=U:GetTextSize(N.Text,28*(4/Q),Enum.Font.Antique,Vector2.new(307.2,2000))if h.Y<138.24 then break end end n()if N.Alternatives then local Q={}for h,O in pairs(d)do local U=N.Alternatives[h]if U then O[1].Visible=true O[3].Text=U.Text table.insert(Q,O[2].Button.MouseButton1Down:Connect(function()if u then u=false for Q,h in pairs(Q)do h:Disconnect()end if U.Quest then t:AddQuest(U.Quest)L:FireServer(H,U.Quest)end if U.Response then w(U.Response,H)else E()end wait()u=true end end))else O[1].Visible=false end end else E()p.Enabled=true local Q=v.Text delay(5,function()if Q==v.Text then p.Enabled=false end end)end end local function c(Q,h,N)q=true p.Enabled=true p.Adornee=N l:TweenPosition(UDim2.new(.5,0,1,0),"\079\117\116","\081\117\097\100",.5,true)J:Disable()w(Q,h)end local function Z(Q)if q then return end local h=t:GetDialogForNPC(Q)if not h then return end c(h,Q,(N:WaitForChild(Q)):WaitForChild("\072\101\097\100"))end r.Event:Connect(Z)W.OnClientEvent:Connect(function(Q)for Q,h in pairs(Q)do if h.Type=="\073\116\101\109"then B.DisplayItemAwardFromPosition(h.Name,UDim2.new(.5,0,.9,0))elseif h.Type=="\066\108\111\120\107\105\110"then B.DisplayBloxkinAwardFromPosition(h.Name,UDim2.new(.5,0,.9,0))end wait(.25)end end)
--[[
TheNexusAvenger

Performs dialogs for quests.
--]]

local MIN_DIALOG_LINES = 4
local MAX_DIALOG_LINES = 10



local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local ControlModule = require(Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"):WaitForChild("ControlModule"))
local Quests = ReplicatedStorageProject:GetResource("State.Quests").new(Players.LocalPlayer)
local ImageEventBinder = ReplicatedStorageProject:GetResource("UI.Button.ImageEventBinder")
local AspectRatioSwitcher = ReplicatedStorageProject:GetResource("UI.AspectRatioSwitcher")
local ItemAwardAnimation = ReplicatedStorageProject:GetResource("UI.ItemAwardAnimation")
local StartQuest = ReplicatedStorageProject:GetResource("GameReplication.QuestReplication.StartQuest")
local TurnInQuest = ReplicatedStorageProject:GetResource("GameReplication.QuestReplication.TurnInQuest")
local DisplayItemAwards = ReplicatedStorageProject:GetResource("GameReplication.QuestReplication.DisplayItemAwards")



--Create the ScreenGui.
local DialogLines = MIN_DIALOG_LINES
local DB = true
local DialogActive = false
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "DialogView"
ScreenGui.DisplayOrder = 20
ScreenGui.Parent = script.Parent

local StartDialogEvent = Instance.new("BindableEvent")
StartDialogEvent.Name = "StartDialog"
StartDialogEvent.Parent = ScreenGui

--Create the dialog billboard Gui.
local NPCDialogBillboardGui = Instance.new("BillboardGui")
NPCDialogBillboardGui.Name = "NPCDialog"
NPCDialogBillboardGui.AlwaysOnTop = true
NPCDialogBillboardGui.Enabled = false
NPCDialogBillboardGui.SizeOffset = Vector2.new(0.5,0.5)
NPCDialogBillboardGui.Parent = script.Parent

local NPCDialogBackground = Instance.new("ImageLabel")
NPCDialogBackground.BackgroundTransparency = 1
NPCDialogBackground.Size = UDim2.new(1,0,1,0)
NPCDialogBackground.Image = "rbxassetid://132726116"
NPCDialogBackground.Parent = NPCDialogBillboardGui

local NPCDialogText = Instance.new("TextLabel")
NPCDialogText.BackgroundTransparency = 1
NPCDialogText.AnchorPoint = Vector2.new(0.5,0.5)
NPCDialogText.Position = UDim2.new(0.35,0,0.42,0)
NPCDialogText.Size = UDim2.new(0.6,0,0.54,0)
NPCDialogText.Font = Enum.Font.Antique
NPCDialogText.TextColor3 = Color3.new(0,0,0)
NPCDialogText.TextWrapped = true
NPCDialogText.TextXAlignment = Enum.TextXAlignment.Left
NPCDialogText.Parent = NPCDialogBackground

local function ResizeNPCDialog()
    local WindowHeight = ScreenGui.AbsoluteSize.Y
    NPCDialogBillboardGui.Size = UDim2.new(0,WindowHeight * 0.6,0,WindowHeight * 0.3)
    NPCDialogText.TextSize = ((28 * 4)/DialogLines) * ((WindowHeight * 0.3)/256)
end
ScreenGui:GetPropertyChangedSignal("AbsoluteSize"):Connect(ResizeNPCDialog)
ResizeNPCDialog()

--Create the container.
local Background = Instance.new("ImageLabel")
Background.BackgroundTransparency = 1
Background.Position = UDim2.new(0.5,0,1.5,0)
Background.AnchorPoint = Vector2.new(0.3175,0.48)
Background.Image = "rbxassetid://132725671"
Background.Parent = ScreenGui

AspectRatioSwitcher.new(ScreenGui,1.1,function()
    Background.Size = UDim2.new(1.4,0,0.7,0)
    Background.SizeConstraint = "RelativeYY"
end,function()
    Background.Size = UDim2.new(0.8,0,0.4,0)
    Background.SizeConstraint = "RelativeXX"
end)

--Create the buttons.
local DialogButtons = {}
for i = 1,5 do
    local Image = Instance.new("ImageLabel")
    Image.BackgroundTransparency = 1
    Image.Size = UDim2.new(1,0,32/512,0)
    Image.Position = UDim2.new(0.039,0,0.03 + (i * 0.07),0)
    Image.Parent = Background
    local Button = ImageEventBinder.new(Image,UDim2.new(0.547,0,0.9,0),"rbxassetid://132725706","rbxassetid://132840460","rbxassetid://132840480")

    local ButtonText = Instance.new("TextLabel")
    ButtonText.BackgroundTransparency = 1
    ButtonText.Size = UDim2.new(0.53,0,0.8,0)
    ButtonText.Position = UDim2.new(0.01,0,-0.05,0)
    ButtonText.Font = Enum.Font.Antique
    ButtonText.TextColor3 = Color3.new(0,0,0)
    ButtonText.TextScaled = true
    ButtonText.TextXAlignment = Enum.TextXAlignment.Left
    ButtonText.Parent = Image
    table.insert(DialogButtons,{Image,Button,ButtonText})
end



--[[
Ends the dialog.
--]]
local function EndDialog()
    --Hide the dialog.
    DialogActive = false
    NPCDialogBillboardGui.Enabled = false
    Background:TweenPosition(UDim2.new(0.5,0,1.5,0),"Out","Quad",0.5,true)

    --Unlock the player.
    ControlModule:Enable()
end

--[[
Runs the dialog for a specific step.
--]]
local function RunDialogSection(DialogData,NPCName)
    --Turn in a quest if there is one to turn in.
    if DialogData.TurnIn then
        TurnInQuest:FireServer(NPCName,DialogData.TurnIn)
    end

    --Claim the quest.
    if DialogData.Quest then
        Quests:AddQuest(DialogData.Quest)
        StartQuest:FireServer(NPCName,DialogData.Quest)
    end

    --Update the text bubble.
    NPCDialogText.Text = DialogData.Text
    for i = MIN_DIALOG_LINES,MAX_DIALOG_LINES,0.25 do
        DialogLines = i
        local TextBounds = TextService:GetTextSize(DialogData.Text,28 * (4/i),Enum.Font.Antique,Vector2.new(512 * 0.6,2000))
        if TextBounds.Y < 256 * 0.54 then
            break
        end
    end
    ResizeNPCDialog()

    if DialogData.Alternatives then
        --Set up the buttons.
        local ResponseEvents = {}
        for i,ButtonData in pairs(DialogButtons) do
            local RepsonseData = DialogData.Alternatives[i]
            if RepsonseData then
                --Show and update the button.
                ButtonData[1].Visible = true
                ButtonData[3].Text = RepsonseData.Text

                --Connect the button.
                table.insert(ResponseEvents,ButtonData[2].Button.MouseButton1Down:Connect(function()
                    if DB then
                        DB = false
                        --Disconnect the button events.
                        for _,Event in pairs(ResponseEvents) do
                            Event:Disconnect()
                        end

                        --Claim the quest.
                        if RepsonseData.Quest then
                            Quests:AddQuest(RepsonseData.Quest)
                            StartQuest:FireServer(NPCName,RepsonseData.Quest)
                        end

                        if RepsonseData.Response then
                            --Run the next dialog.
                            RunDialogSection(RepsonseData.Response,NPCName)
                        else
                            --End the dialog.
                            EndDialog()
                        end

                        wait()
                        DB = true
                    end
                end))
            else
                --Hide the button.
                ButtonData[1].Visible = false
            end
        end
    else
        --Hide the dialog.
        EndDialog()
        NPCDialogBillboardGui.Enabled = true
        local OriginalText = NPCDialogText.Text
        delay(5,function()
            if OriginalText == NPCDialogText.Text then
                NPCDialogBillboardGui.Enabled = false
            end
        end)
    end
end

--[[
Starts a dialog.
--]]
local function RunDialog(DialogData,NPCName,Adornee)
    --Show the GUIs.
    DialogActive = true
    NPCDialogBillboardGui.Enabled = true
    NPCDialogBillboardGui.Adornee = Adornee
    Background:TweenPosition(UDim2.new(0.5,0,1,0),"Out","Quad",0.5,true)

    --Lock the player.
    ControlModule:Disable()

    --Run the dialog.
    RunDialogSection(DialogData,NPCName)
end

--[[
Starts a dialog for a given NPC.
--]]
local function RunDialogForNPC(NPCName)
    --Return if a dialog is in progress.
    if DialogActive then
        return
    end

    --Get the dialog and return if there is no valid dialog.
    local DialogData = Quests:GetDialogForNPC(NPCName)
    if not DialogData then
        return
    end

    --Run the dialog.
    RunDialog(DialogData,NPCName,Workspace:WaitForChild(NPCName):WaitForChild("Head"))
end



--Connect starting dialogs.
StartDialogEvent.Event:Connect(RunDialogForNPC)

--Connect displaying rewards.
DisplayItemAwards.OnClientEvent:Connect(function(Items)
    for _,Item in pairs(Items) do
        if Item.Type == "Item" then
            ItemAwardAnimation.DisplayItemAwardFromPosition(Item.Name,UDim2.new(0.5,0,0.9,0))
        elseif Item.Type == "Bloxkin" then
            ItemAwardAnimation.DisplayBloxkinAwardFromPosition(Item.Name,UDim2.new(0.5,0,0.9,0))
        end
        wait(0.25)
    end
end)