local i=game:GetService("\087\111\114\107\115\112\097\099\101")local M=game:GetService("\080\108\097\121\101\114\115")local D=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local p=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local x=p:WaitForChild("\108\105\098")local K=M.LocalPlayer local o=TweenInfo.new(.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)local j=TweenInfo.new(.5,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out)local w=require(x:WaitForChild("\080\105\122\122\097\065\108\112\097\099\097"))local R=2 local U=w.GameModule:extend("\067\097\110\110\111\110\115")local e=false local function d()return(i:WaitForChild("\099\097\110\110\111\110\115")):GetChildren()end local function h(i)local D=i.Parent return M:GetPlayerFromCharacter(D)end local function k(i)local M=i.Mesh.Scale;(D:Create(i.Mesh,o,{Scale=M*1.3333333333333})):Play()wait(.5);(D:Create(i.Mesh,j,{Scale=M})):Play()end local function L(i)local M=i:WaitForChild("\067\097\110\110\111\110")local D=i:WaitForChild("\072\105\103\104")local p=i:WaitForChild("\071\111\097\108")local x=D.Position local o=p.Position local j=30 if not e then e=true local i=K.Character if i and i.PrimaryPart then local D=i.PrimaryPart local p=i.Humanoid p:ChangeState(Enum.HumanoidStateType.Seated)local K=Instance.new("\066\111\100\121\080\111\115\105\116\105\111\110",D)K.Position=M.Position K.MaxForce=Vector3.new(300000,300000,300000)K.P=20000 K.D=800 k(M)for i=0,1,1/j do K.Position=(M.Position:lerp(x,i)):lerp(o,i)wait(R/j)end K:Destroy()end e=false end end local function A(i)local M=false local D=i:WaitForChild("\067\097\110\110\111\110")local p=i:WaitForChild("\072\105\103\104")local x=i:WaitForChild("\071\111\097\108")p.Transparency=1 x.Transparency=1 D.Touched:Connect(function(D)if not M then M=true local p=h(D)if p==K then L(i)wait(1)end M=false end end)print("\067\097\110\110\111\110",i,"\099\114\101\097\116\101\100\046")end function U.init(i)local M=d()for i,M in pairs(M)do A(M)end end return U
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local lib = ReplicatedStorage:WaitForChild("lib")

local LocalPlayer = Players.LocalPlayer
local GrowTweenInfo = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local WobbleTweenInfo = TweenInfo.new(0.5,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out)

local PizzaAlpaca = require(lib:WaitForChild("PizzaAlpaca"))

local FLY_TIME = 2

local Cannons = PizzaAlpaca.GameModule:extend("Cannons")

local shooting = false

local function getCannons()
    return Workspace:WaitForChild("cannons"):GetChildren()
end

local function playerFromPart(part)
    local Char = part.Parent
    return Players:GetPlayerFromCharacter(Char)
end

local function blastTween(part)
    local OriginalSize = part.Mesh.Scale

    TweenService:Create(part.Mesh,GrowTweenInfo,{Scale = OriginalSize*(4/3)}):Play()
    wait(0.5)
    TweenService:Create(part.Mesh,WobbleTweenInfo,{Scale = OriginalSize}):Play()
end

local function cannonShoot(model)

    local cannon = model:WaitForChild("Cannon")
    local highPointPart = model:WaitForChild("High")
    local goalPart = model:WaitForChild("Goal")

    local highPoint = highPointPart.Position
    local goal = goalPart.Position

    local steps = 30

    if not shooting then
        shooting = true

        local character = LocalPlayer.Character

        if character and character.PrimaryPart then
            local rootPart = character.PrimaryPart
            local humanoid = character.Humanoid

            humanoid:ChangeState(Enum.HumanoidStateType.Seated)

            local bodyPosition = Instance.new("BodyPosition",rootPart)
            bodyPosition.Position = cannon.Position
            bodyPosition.MaxForce = Vector3.new(300000,300000,300000)
            bodyPosition.P = 20000
            bodyPosition.D = 800

            blastTween(cannon)

            for i = 0,1,1/steps do
                bodyPosition.Position = cannon.Position:lerp(highPoint,i):lerp(goal,i)

                wait(FLY_TIME/steps)
            end

            bodyPosition:Destroy()
        end

        shooting = false
    end
end

local function createCannon(model)
    local debounce = false

    local cannon = model:WaitForChild("Cannon")
    local highPointPart = model:WaitForChild("High")
    local goalPart = model:WaitForChild("Goal")

    highPointPart.Transparency = 1
    goalPart.Transparency = 1

    cannon.Touched:Connect(function(hit)
        if not debounce then
            debounce = true
            local touchedPlayer = playerFromPart(hit)

            if touchedPlayer == LocalPlayer then
                cannonShoot(model)
                wait(1)
            end
            debounce = false
        end
    end)

    print("Cannon",model,"created.")
end

function Cannons:init()
    local cannonModels = getCannons()

    for _, cannon in pairs(cannonModels) do
        createCannon(cannon)
    end
end

return Cannons