Advertisement
thelegend14532

my restaurant scrit

Aug 6th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.84 KB | None | 0 0
  1. if not getconnections then return end
  2.  
  3. for i,v in next, getconnections(game.Players.LocalPlayer.Idled) do
  4.  
  5. v:Disable()
  6.  
  7. end
  8.  
  9.  
  10.  
  11. local petNet = loadstring(game:HttpGet("https://rawscripts.net/raw/Pet-Simulator-X!-PSX-Safe-Networking-3732"))()
  12.  
  13.  
  14.  
  15. local Food = petNet:getPath("Food")
  16.  
  17. local Entity = petNet:getPath("Entity")
  18.  
  19. local Customer = petNet:getPath("Customer")
  20.  
  21. local Waiter = petNet:getPath("Waiter")
  22.  
  23. local Appliance = petNet:getPath("Appliance")
  24.  
  25.  
  26.  
  27. local _L = require(game:GetService("ReplicatedStorage"):WaitForChild("Framework",10):WaitForChild("Library",10));
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. Food.RandomFoodChoice = function(customerOwnerUID, customerOwnerID, isRichCustomer, isPirateCustomer, isNearTree)
  44.  
  45. local spoof = Food.new("45", customerOwnerUID, customerOwnerID, true, true)
  46.  
  47. spoof.IsGold = true
  48.  
  49. return spoof
  50.  
  51. end
  52.  
  53.  
  54.  
  55.  
  56.  
  57. function Entity:WalkThroughWaypoints(voxelpoints, waypoints, startX, startZ)
  58.  
  59. self:PlayLoadedAnimation("walking")
  60.  
  61.  
  62.  
  63. if #voxelpoints == 0 then
  64.  
  65. return
  66.  
  67. end
  68.  
  69.  
  70.  
  71. if not self:BelongsToMyBakery() and self.stateData.walkingThroughWaypoints then
  72.  
  73. repeat wait() until self.isDeleted or not self.stateData.walkingThroughWaypoints
  74.  
  75. if self.isDeleted then
  76.  
  77. return
  78.  
  79. end
  80.  
  81. end
  82.  
  83. if not self:BelongsToMyBakery() then
  84.  
  85. self.stateData.walkingThroughWaypoints = true
  86.  
  87. end
  88.  
  89.  
  90.  
  91. -- replication fix?
  92.  
  93. if not self:BelongsToMyBakery() then
  94.  
  95. self.model.HumanoidRootPart.Anchored = false
  96.  
  97. end
  98.  
  99.  
  100.  
  101. for i, v in ipairs(waypoints) do
  102.  
  103.  
  104.  
  105. self.model.HumanoidRootPart.CFrame = CFrame.new(v)
  106.  
  107. --self.humanoid.MoveToFinished:Wait()
  108.  
  109. local oldX, oldZ = self.xVoxel, self.zVoxel
  110.  
  111. self.xVoxel = voxelpoints[i].x
  112.  
  113. self.zVoxel = voxelpoints[i].y
  114.  
  115.  
  116.  
  117. -- no need for position table updates if it's not my client.
  118.  
  119. -- only the owner of the bakery does pathfinding calculations.
  120.  
  121. -- if replication occurs, the host client sends the pathfinding
  122.  
  123. -- data.... it is not recalculated
  124.  
  125. if self:BelongsToMyBakery() then
  126.  
  127. self:GetMyFloor():BroadcastNPCPositionChange(self, oldX, oldZ)
  128.  
  129. end
  130.  
  131. end
  132.  
  133.  
  134.  
  135. if not self:BelongsToMyBakery() then
  136.  
  137. self.stateData.walkingThroughWaypoints = false
  138.  
  139. end
  140.  
  141.  
  142.  
  143. self:StopLoadedAnimation("walking")
  144.  
  145. self:PlayLoadedAnimation("idle")
  146.  
  147. end
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. function Customer:ChangeToWaitForOrderState()
  162.  
  163.  
  164.  
  165. if self.state ~= "WalkingToSeat" then
  166.  
  167. return
  168.  
  169. end
  170.  
  171.  
  172.  
  173. local seatLeaf = self:EntityTable()[self.stateData.seatUID]
  174.  
  175. local tableLeaf = self:EntityTable()[self.stateData.tableUID]
  176.  
  177.  
  178.  
  179. if seatLeaf.isDeleted or tableLeaf.isDeleted then
  180.  
  181. self:ForcedToLeave()
  182.  
  183. return
  184.  
  185. end
  186.  
  187.  
  188.  
  189. self:SetCustomerState("ThinkingAboutOrder")
  190.  
  191.  
  192.  
  193. -- make the humanoid sit
  194.  
  195. self:SitInSeat(seatLeaf).Completed:Connect(function()
  196.  
  197. self.humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, true)
  198.  
  199.  
  200.  
  201. -- change voxel position to match the seat
  202.  
  203. self.xVoxel = seatLeaf.xVoxel
  204.  
  205. self.zVoxel = seatLeaf.zVoxel
  206.  
  207.  
  208.  
  209. coroutine.wrap(function()
  210.  
  211.  
  212.  
  213. -- start reading the menu
  214.  
  215. self:ReadMenu()
  216.  
  217. if self.isDeleted or self.state ~= "ThinkingAboutOrder" then
  218.  
  219. return
  220.  
  221. end
  222.  
  223.  
  224.  
  225. -- stop reading the menu
  226.  
  227. self:StopReadingMenu()
  228.  
  229.  
  230.  
  231. -- advance to next state
  232.  
  233. self:SetCustomerState("DecidedOnOrder")
  234.  
  235.  
  236.  
  237. -- only set my entire group to ready to order when everybody has decided on the order
  238.  
  239. local myGroup = {self}
  240.  
  241. for _, partner in ipairs(self.stateData.queueGroup) do
  242.  
  243. if not partner.isDeleted then
  244.  
  245. table.insert(myGroup, partner)
  246.  
  247. end
  248.  
  249. end
  250.  
  251. local foundUndecidedMember = false
  252.  
  253. for _, groupMember in ipairs(myGroup) do
  254.  
  255. if groupMember.state ~= "DecidedOnOrder" then
  256.  
  257. foundUndecidedMember = true
  258.  
  259. break
  260.  
  261. end
  262.  
  263. end
  264.  
  265.  
  266.  
  267. -- if the entire group is ready, then have them say it in sync
  268.  
  269. if not foundUndecidedMember then
  270.  
  271. for _, groupMember in ipairs(myGroup) do
  272.  
  273. groupMember:ReadyToOrder()
  274.  
  275. end
  276.  
  277. end
  278.  
  279.  
  280.  
  281. end)()
  282.  
  283. end)
  284.  
  285.  
  286.  
  287. end
  288.  
  289.  
  290.  
  291.  
  292.  
  293. function Customer:ChangeToEatingState()
  294.  
  295.  
  296.  
  297. coroutine.wrap(function()
  298.  
  299. if self.state == "EatingFood" then
  300.  
  301. return
  302.  
  303. end
  304.  
  305.  
  306.  
  307. -- first, check for silverware
  308.  
  309. local myFloor = self:GetMyFloor()
  310.  
  311. table.sort(myFloor.silverwareTrays, function(a, b)
  312.  
  313. local aDist = math.abs(self.xVoxel - a.xVoxel) + math.abs(self.zVoxel - a.zVoxel)
  314.  
  315. local bDist = math.abs(self.xVoxel - b.xVoxel) + math.abs(self.zVoxel - b.zVoxel)
  316.  
  317. return aDist < bDist
  318.  
  319. end)
  320.  
  321. table.sort(myFloor.goldSilverwareTrays, function(a, b)
  322.  
  323. local aDist = math.abs(self.xVoxel - a.xVoxel) + math.abs(self.zVoxel - a.zVoxel)
  324.  
  325. local bDist = math.abs(self.xVoxel - b.xVoxel) + math.abs(self.zVoxel - b.zVoxel)
  326.  
  327. return aDist < bDist
  328.  
  329. end)
  330.  
  331.  
  332.  
  333. self:SetCustomerState("EatingFood")
  334.  
  335.  
  336.  
  337. -- if there's a path to me, delete it
  338.  
  339. if self.stateData.pathToMe then
  340.  
  341. _L.Variables.MyBakery:CleanupAnimatedPath()
  342.  
  343. self.stateData.pathToMe = nil
  344.  
  345. end
  346.  
  347.  
  348.  
  349. local didSaladCheck = false
  350.  
  351. local function checkForSaladBars(isWalkingFromSilverware, doWalkBackToSeat)
  352.  
  353. didSaladCheck = true
  354.  
  355. local didWalkToSalad = false
  356.  
  357. -- walk to salad bar sometimes
  358.  
  359. local isWalkingToSaladBar = false
  360.  
  361. for _, saladBar in ipairs(myFloor.saladBars) do
  362.  
  363. if math.random() < 0.20 then
  364.  
  365.  
  366.  
  367. if not isWalkingFromSilverware then
  368.  
  369. self:StandUp()
  370.  
  371. end
  372.  
  373.  
  374.  
  375. isWalkingToSaladBar = true
  376.  
  377. didWalkToSalad = true
  378.  
  379. local sx, sy, sz = self.xVoxel, self.yVoxel, self.zVoxel
  380.  
  381. self:WalkToPoint(saladBar.xVoxel, saladBar.yVoxel, saladBar.zVoxel, function()
  382.  
  383. if saladBar.isDeleted then
  384.  
  385. isWalkingToSaladBar = false
  386.  
  387. self:ForcedToLeave()
  388.  
  389. return
  390.  
  391. end
  392.  
  393.  
  394.  
  395. self:FaceEntity(saladBar)
  396.  
  397. _L.SFX.Play(5708685167, saladBar.model.PrimaryPart)
  398.  
  399. _L.Network.Fire("AwardTipWithVerification", self.UID, saladBar.UID, self.stateData.foodOrder.ID, isWalkingFromSilverware)
  400.  
  401.  
  402.  
  403. if doWalkBackToSeat then
  404.  
  405. self:WalkToPoint(sx, sy, sz, function()
  406.  
  407. isWalkingToSaladBar = false
  408.  
  409. if self.stateData.mySeat.isDeleted then
  410.  
  411. self:ForcedToLeave()
  412.  
  413. return
  414.  
  415. end
  416.  
  417. self:SitInSeat(self.stateData.mySeat)
  418.  
  419. end)
  420.  
  421. else
  422.  
  423. isWalkingToSaladBar = false
  424.  
  425. end
  426.  
  427. end)
  428.  
  429. break
  430.  
  431. end
  432.  
  433. end
  434.  
  435. if isWalkingToSaladBar then
  436.  
  437. repeat wait() until not isWalkingToSaladBar
  438.  
  439. end
  440.  
  441. return didWalkToSalad
  442.  
  443. end
  444.  
  445.  
  446.  
  447. local didDessertCheck = false
  448.  
  449. local function checkForDessertBars(isWalkingFromSilverware, doWalkBackToSeat)
  450.  
  451. didDessertCheck = true
  452.  
  453. local didWalkToDessert = false
  454.  
  455. -- walk to salad bar sometimes
  456.  
  457. local isWalkingToDessertBar = false
  458.  
  459. for _, dessertBar in ipairs(myFloor.dessertBars) do
  460.  
  461. if math.random() < 0.20 then
  462.  
  463.  
  464.  
  465. if not isWalkingFromSilverware then
  466.  
  467. self:StandUp()
  468.  
  469. end
  470.  
  471.  
  472.  
  473. isWalkingToDessertBar = true
  474.  
  475. didWalkToDessert = true
  476.  
  477. local sx, sy, sz = self.xVoxel, self.yVoxel, self.zVoxel
  478.  
  479. self:WalkToPoint(dessertBar.xVoxel, dessertBar.yVoxel, dessertBar.zVoxel, function()
  480.  
  481. if dessertBar.isDeleted then
  482.  
  483. isWalkingToDessertBar = false
  484.  
  485. self:ForcedToLeave()
  486.  
  487. return
  488.  
  489. end
  490.  
  491.  
  492.  
  493. self:FaceEntity(dessertBar)
  494.  
  495. _L.SFX.Play(5708685167, dessertBar.model.PrimaryPart)
  496.  
  497. _L.Network.Fire("AwardTipWithVerification", self.UID, dessertBar.UID, self.stateData.foodOrder.ID, isWalkingFromSilverware)
  498.  
  499.  
  500.  
  501. if doWalkBackToSeat then
  502.  
  503. self:WalkToPoint(sx, sy, sz, function()
  504.  
  505. isWalkingToDessertBar = false
  506.  
  507. if self.stateData.mySeat.isDeleted then
  508.  
  509. self:ForcedToLeave()
  510.  
  511. return
  512.  
  513. end
  514.  
  515. self:SitInSeat(self.stateData.mySeat)
  516.  
  517. end)
  518.  
  519. else
  520.  
  521. isWalkingToDessertBar = false
  522.  
  523. end
  524.  
  525. end)
  526.  
  527. break
  528.  
  529. end
  530.  
  531. end
  532.  
  533. if isWalkingToDessertBar then
  534.  
  535. repeat wait() until not isWalkingToDessertBar
  536.  
  537. end
  538.  
  539. return didWalkToDessert
  540.  
  541. end
  542.  
  543.  
  544.  
  545. -- create food model for the customer
  546.  
  547. if not self.stateData.foodOrder then
  548.  
  549. self:ForcedToLeave()
  550.  
  551. return
  552.  
  553. end
  554.  
  555. local myTable = self:EntityTable()[self.stateData.tableUID]
  556.  
  557. local mySeat = self:EntityTable()[self.stateData.seatUID]
  558.  
  559. if not myTable or not mySeat then
  560.  
  561. _L.Print("CRITICAL: COULDN'T FIND CUSTOMERS TABLE WHEN EATING", true)
  562.  
  563. return
  564.  
  565. end
  566.  
  567. local myFloor = myTable:GetMyFloor()
  568.  
  569. local worldPos = myFloor:WorldPositionFromVoxel(mySeat:GetFacePosition())
  570.  
  571. local tableRoot = myTable.model.PrimaryPart
  572.  
  573. local tableTop = Vector3.new(worldPos.X, tableRoot.Position.Y + tableRoot.Size.Y/2, worldPos.Z)
  574.  
  575. local foodOffset = (-1.1)*mySeat:GetFaceDirection() + Vector3.new(0, self.stateData.foodOrder.data.model.PrimaryPart.Size.Y/2, 0)
  576.  
  577. local foodCF = CFrame.new(tableTop + foodOffset)
  578.  
  579. self:CreateMyFoodModel(foodCF)
  580.  
  581.  
  582.  
  583. local isWalkingToTray = false
  584.  
  585. local wasWalkingToTray = false
  586.  
  587. local trayUID = false
  588.  
  589. local forkModel = nil
  590.  
  591. local spoonModel = nil
  592.  
  593. local welds = {}
  594.  
  595. local function walkToTray(tray)
  596.  
  597. isWalkingToTray = true
  598.  
  599. wasWalkingToTray = true
  600.  
  601. trayUID = tray.UID
  602.  
  603. self:StandUp()
  604.  
  605. local sx, sy, sz = self.xVoxel, self.yVoxel, self.zVoxel
  606.  
  607. self:WalkToPoint(tray.xVoxel, tray.yVoxel, tray.zVoxel, function()
  608.  
  609. if tray.isDeleted then
  610.  
  611. isWalkingToTray = false
  612.  
  613. self:ForcedToLeave()
  614.  
  615. return
  616.  
  617. end
  618.  
  619. local sounds = {5601560377, 5601560515, 5601560641}
  620.  
  621. _L.SFX.Play(sounds[math.random(#sounds)], tray.model.PrimaryPart)
  622.  
  623. self:FaceEntity(tray)
  624.  
  625.  
  626.  
  627. if not checkForSaladBars(true, false) then
  628.  
  629. checkForDessertBars(true, false)
  630.  
  631. end
  632.  
  633.  
  634.  
  635. self:WalkToPoint(sx, sy, sz, function()
  636.  
  637. isWalkingToTray = false
  638.  
  639. if self.stateData.mySeat.isDeleted then
  640.  
  641. self:ForcedToLeave()
  642.  
  643. return
  644.  
  645. end
  646.  
  647. self:SitInSeat(self.stateData.mySeat)
  648.  
  649.  
  650.  
  651. -- hold silverware
  652.  
  653. local isGold = tray.ID == "25"
  654.  
  655. local function weldToHand(part, hand)
  656.  
  657. local weld = Instance.new("Weld", part)
  658.  
  659. weld.Part0 = part
  660.  
  661. weld.Part1 = hand
  662.  
  663. weld.C0 = CFrame.Angles(-math.pi/2, 0, 0)
  664.  
  665. table.insert(welds, weld)
  666.  
  667. end
  668.  
  669. if isGold then
  670.  
  671. forkModel = game.ReplicatedStorage.Assets.Models["Luxury Fork"]:Clone()
  672.  
  673. spoonModel = game.ReplicatedStorage.Assets.Models["Luxury Spoon"]:Clone()
  674.  
  675. forkModel.Parent = self.model
  676.  
  677. spoonModel.Parent = self.model
  678.  
  679. weldToHand(forkModel, self.model.RightHand)
  680.  
  681. weldToHand(spoonModel, self.model.LeftHand)
  682.  
  683. else
  684.  
  685. forkModel = game.ReplicatedStorage.Assets.Models["Default Fork"]:Clone()
  686.  
  687. spoonModel = game.ReplicatedStorage.Assets.Models["Default Spoon"]:Clone()
  688.  
  689. forkModel.Parent = self.model
  690.  
  691. spoonModel.Parent = self.model
  692.  
  693. weldToHand(forkModel, self.model.RightHand)
  694.  
  695. weldToHand(spoonModel, self.model.LeftHand)
  696.  
  697. end
  698.  
  699. end)
  700.  
  701. end)
  702.  
  703. end
  704.  
  705.  
  706.  
  707. if #myFloor.goldSilverwareTrays > 0 then
  708.  
  709. walkToTray(myFloor.goldSilverwareTrays[1])
  710.  
  711. elseif #myFloor.silverwareTrays > 0 then
  712.  
  713. local goodRoll = false
  714.  
  715. for i = 1, #myFloor.silverwareTrays do
  716.  
  717. if true then
  718.  
  719. goodRoll = true
  720.  
  721. end
  722.  
  723. end
  724.  
  725. if goodRoll then
  726.  
  727. walkToTray(myFloor.silverwareTrays[1])
  728.  
  729. end
  730.  
  731. end
  732.  
  733.  
  734.  
  735. if isWalkingToTray then
  736.  
  737. repeat wait() until not isWalkingToTray
  738.  
  739. end
  740.  
  741.  
  742.  
  743. if not didSaladCheck then
  744.  
  745. if not checkForSaladBars(false, true) then
  746.  
  747. checkForDessertBars(false, true)
  748.  
  749. end
  750.  
  751. end
  752.  
  753.  
  754.  
  755. -- play eating animation
  756.  
  757. self:PlayLoadedAnimation("eating")
  758.  
  759.  
  760.  
  761. -- play served sound
  762.  
  763. _L.SFX.Play(5205174537, self.model.PrimaryPart, nil, 0.60)
  764.  
  765.  
  766.  
  767. -- play eating looped sound
  768.  
  769. local pitch = 1 + (math.random() - 0.50)*0.10
  770.  
  771. local eatSound = math.random() < 0.50 and 5029600710 or 5029600543
  772.  
  773. self.stateData.loopedEatingSound = _L.SFX.Play(eatSound, self.model.PrimaryPart, pitch, 0.85, 35, nil, true)
  774.  
  775.  
  776.  
  777. coroutine.wrap(function()
  778.  
  779.  
  780.  
  781. -- eat timing is determined by the server. //no, it's not, -bluwud
  782.  
  783. local forceLeaveTip = true
  784.  
  785. if not self.isDeleted and self.state == "EatingFood" then
  786.  
  787. if self.stateData.loopedEatingSound then
  788.  
  789. self.stateData.loopedEatingSound = self.stateData.loopedEatingSound:Destroy()
  790.  
  791. end
  792.  
  793. self.stateData.foodOrder:ChangeToDirtyDish()
  794.  
  795. self:StopLoadedAnimation("eating")
  796.  
  797. self:ChangeToReadyToExitState(forceLeaveTip)
  798.  
  799.  
  800.  
  801. if forkModel then
  802.  
  803. forkModel:Destroy()
  804.  
  805. spoonModel:Destroy()
  806.  
  807. for _, weld in ipairs(welds) do
  808.  
  809. weld:Destroy()
  810.  
  811. end
  812.  
  813. welds = {}
  814.  
  815. end
  816.  
  817. end
  818.  
  819. end)()
  820.  
  821. end)()
  822.  
  823.  
  824.  
  825. end
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833. function Customer:ChangeToExitingState(wasForcedToLeave, forcedToLeaveTip)
  834.  
  835.  
  836.  
  837. if self.isDeleted then
  838.  
  839. return
  840.  
  841. end
  842.  
  843.  
  844.  
  845. self.leaving = true
  846.  
  847. self:SetCustomerState("WalkingToExit")
  848.  
  849.  
  850.  
  851. -- remove customer from table
  852.  
  853. local myTable = self:EntityTable()[self.stateData.tableUID]
  854.  
  855. if myTable and not myTable.isDeleted then
  856.  
  857. myTable:RemoveCustomerFromTable(self)
  858.  
  859. end
  860.  
  861.  
  862.  
  863. local myFloor = self:GetMyFloor()
  864.  
  865.  
  866.  
  867. coroutine.wrap(function()
  868.  
  869. if wasForcedToLeave then
  870.  
  871. self:TimedEmoji("MadEmoji", 2)
  872.  
  873. else
  874.  
  875. if math.random() < 0.30 or _L.Variables.MyBakery.isTutorial then
  876.  
  877. self:TimedEmoji("HappyEmoji", 2.5)
  878.  
  879. end
  880.  
  881. end
  882.  
  883.  
  884.  
  885. -- make humanoid stand
  886.  
  887. self:StandUp()
  888.  
  889.  
  890.  
  891. local function goToExitAndLeave()
  892.  
  893. self:WalkToNewFloor(_L.Variables.MyBakery.floors[1], function()
  894.  
  895. local vx, vy, vz = _L.Variables.MyBakery:GetCustomerStartVoxel(1)
  896.  
  897. self:WalkToPoint(vx, vy, vz, function()
  898.  
  899. self:FadeTransparency(1, function()
  900.  
  901. self:LeaveBakery()
  902.  
  903. end)
  904.  
  905. end, nil, true)
  906.  
  907. end)
  908.  
  909. end
  910.  
  911.  
  912.  
  913. local isLeavingTip = false
  914.  
  915. local isGoingForGumball = false
  916.  
  917. local isGoingForCandy = false
  918.  
  919. local isGoingForArcade = false
  920.  
  921. local isGoingForPopcorn = false
  922.  
  923. local isGoingForSoda = false
  924.  
  925. local isGoingForBowl = false
  926.  
  927.  
  928.  
  929. -- is there a tip jar on this floor? if so, roll to leave tip
  930.  
  931. if not wasForcedToLeave then
  932.  
  933. local tipJars = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "Tip Jar")
  934.  
  935. if #tipJars > 0 then
  936.  
  937. for _, tipJar in ipairs(tipJars) do
  938.  
  939. local tipChance = tipJar.ID == "14" and 0.05 or tipJar.ID == "19" and 0.50 or tipJar.ID == "26" and 0.40 or 0
  940.  
  941. if true or forcedToLeaveTip or self:IsVIPCustomer() then
  942.  
  943. isLeavingTip = true
  944.  
  945. self:WalkToPoint(tipJar.xVoxel, tipJar.yVoxel, tipJar.zVoxel, function()
  946.  
  947. if tipJar.isDeleted or self.isDeleted or not self.stateData or not self.stateData.foodOrder then
  948.  
  949. goToExitAndLeave()
  950.  
  951. return
  952.  
  953. end
  954.  
  955.  
  956.  
  957. -- happy emoji at tip jar
  958.  
  959. self:TimedEmoji("VeryHappyEmoji", 2.5)
  960.  
  961.  
  962.  
  963. _L.Network.Fire("AwardTipWithVerification", self.UID, tipJar.UID, self.stateData.foodOrder.ID)
  964.  
  965. _L.SFX.Play(5839737230, tipJar.model.PrimaryPart)
  966.  
  967.  
  968.  
  969. self:FaceEntity(tipJar)
  970.  
  971. goToExitAndLeave()
  972.  
  973. end)
  974.  
  975. break
  976.  
  977. end
  978.  
  979. end
  980.  
  981. end
  982.  
  983. end
  984.  
  985.  
  986.  
  987. if not isLeavingTip then
  988.  
  989. local candyBowls = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "CandyBowl")
  990.  
  991. if #candyBowls > 0 then
  992.  
  993. for _, bowl in ipairs(candyBowls) do
  994.  
  995. if true and bowl.level and bowl.level > 0 then
  996.  
  997. isGoingForBowl = true
  998.  
  999. self:WalkToPoint(bowl.xVoxel, bowl.yVoxel, bowl.zVoxel, function()
  1000.  
  1001. if bowl.isDeleted or not self.stateData or not self.stateData.foodOrder or bowl.level <= 0 then
  1002.  
  1003. goToExitAndLeave()
  1004.  
  1005. return
  1006.  
  1007. end
  1008.  
  1009.  
  1010.  
  1011. -- happy emoji at tip jar
  1012.  
  1013. self:TimedEmoji("VeryHappyEmoji", 2.5)
  1014.  
  1015.  
  1016.  
  1017. _L.Network.Fire("AwardTipWithVerification", self.UID, bowl.UID, self.stateData.foodOrder.ID)
  1018.  
  1019. _L.SFX.Play(5057746151, bowl.model.PrimaryPart)
  1020.  
  1021.  
  1022.  
  1023. self:FaceEntity(bowl)
  1024.  
  1025. goToExitAndLeave()
  1026.  
  1027. end)
  1028.  
  1029. break
  1030.  
  1031. end
  1032.  
  1033. end
  1034.  
  1035. end
  1036.  
  1037. end
  1038.  
  1039.  
  1040.  
  1041. -- only go for gumball if we're not leaving a tip
  1042.  
  1043. if not isLeavingTip and not isGoingForBowl then
  1044.  
  1045.  
  1046.  
  1047. local gumballMachines = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "GumballMachine")
  1048.  
  1049. if #gumballMachines > 0 then
  1050.  
  1051. for _, gumballMachine in ipairs(gumballMachines) do
  1052.  
  1053. if true then
  1054.  
  1055. isGoingForGumball = true
  1056.  
  1057.  
  1058.  
  1059. local fx, fy, fz = gumballMachine:GetFacePosition()
  1060.  
  1061. if not myFloor:IsValidVoxel(fx, fy, fz) then
  1062.  
  1063. fx, fy, fz = gumballMachine.xVoxel, gumballMachine.yVoxel, gumballMachine.zVoxel
  1064.  
  1065. end
  1066.  
  1067. self:WalkToPoint(fx, fy, fz, function()
  1068.  
  1069. if gumballMachine.isDeleted or self.isDeleted then
  1070.  
  1071. goToExitAndLeave()
  1072.  
  1073. return
  1074.  
  1075. end
  1076.  
  1077.  
  1078.  
  1079. -- gumball tip
  1080.  
  1081. if self.stateData.foodOrder then
  1082.  
  1083. _L.Network.Fire("AwardTipWithVerification", self.UID, gumballMachine.UID, self.stateData.foodOrder.ID)
  1084.  
  1085. end
  1086.  
  1087.  
  1088.  
  1089. -- gumball sound
  1090.  
  1091. _L.SFX.Play(5205171179, gumballMachine.model.PrimaryPart.Position)
  1092.  
  1093.  
  1094.  
  1095. -- gumball emoji
  1096.  
  1097. self:TimedEmoji("VeryHappyEmoji", 2.5)
  1098.  
  1099. self:FaceEntity(gumballMachine)
  1100.  
  1101. goToExitAndLeave()
  1102.  
  1103. end)
  1104.  
  1105. break
  1106.  
  1107. end
  1108.  
  1109. end
  1110.  
  1111. end
  1112.  
  1113.  
  1114.  
  1115. end
  1116.  
  1117.  
  1118.  
  1119. if not isLeavingTip and not isGoingForGumball and not isGoingForBowl then
  1120.  
  1121. local candyMachines = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "CandyMachine")
  1122.  
  1123. if #candyMachines > 0 then
  1124.  
  1125. for _, candyMachine in ipairs(candyMachines) do
  1126.  
  1127. if true then
  1128.  
  1129. isGoingForCandy = true
  1130.  
  1131.  
  1132.  
  1133. local fx, fy, fz = candyMachine:GetFacePosition()
  1134.  
  1135. if not myFloor:IsValidVoxel(fx, fy, fz) then
  1136.  
  1137. fx, fy, fz = candyMachine.xVoxel, candyMachine.yVoxel, candyMachine.zVoxel
  1138.  
  1139. end
  1140.  
  1141. self:WalkToPoint(fx, fy, fz, function()
  1142.  
  1143. if candyMachine.isDeleted or self.isDeleted then
  1144.  
  1145. goToExitAndLeave()
  1146.  
  1147. return
  1148.  
  1149. end
  1150.  
  1151.  
  1152.  
  1153. _L.SFX.Play(5601560734, candyMachine.model.PrimaryPart)
  1154.  
  1155.  
  1156.  
  1157. -- gumball tip
  1158.  
  1159. if self.stateData.foodOrder then
  1160.  
  1161. _L.Network.Fire("AwardTipWithVerification", self.UID, candyMachine.UID, self.stateData.foodOrder.ID)
  1162.  
  1163. end
  1164.  
  1165.  
  1166.  
  1167. -- gumball emoji
  1168.  
  1169. self:TimedEmoji("VeryHappyEmoji", 2.5)
  1170.  
  1171. self:FaceEntity(candyMachine)
  1172.  
  1173. goToExitAndLeave()
  1174.  
  1175. end)
  1176.  
  1177. break
  1178.  
  1179. end
  1180.  
  1181. end
  1182.  
  1183. end
  1184.  
  1185. end
  1186.  
  1187.  
  1188.  
  1189. -- check for popcorn machine
  1190.  
  1191. if not isLeavingTip and not isGoingForGumball and not isGoingForCandy and not isGoingForBowl then
  1192.  
  1193.  
  1194.  
  1195. local popcornMachines = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "PopcornMachine")
  1196.  
  1197. if #popcornMachines > 0 then
  1198.  
  1199. for _, popcornMachine in ipairs(popcornMachines) do
  1200.  
  1201. if true then
  1202.  
  1203. isGoingForPopcorn = true
  1204.  
  1205.  
  1206.  
  1207. local fx, fy, fz = popcornMachine:GetFacePosition()
  1208.  
  1209. if not myFloor:IsValidVoxel(fx, fy, fz) then
  1210.  
  1211. fx, fy, fz = popcornMachine.xVoxel, popcornMachine.yVoxel, popcornMachine.zVoxel
  1212.  
  1213. end
  1214.  
  1215. self:WalkToPoint(fx, fy, fz, function()
  1216.  
  1217. if popcornMachine.isDeleted or self.isDeleted then
  1218.  
  1219. goToExitAndLeave()
  1220.  
  1221. return
  1222.  
  1223. end
  1224.  
  1225.  
  1226.  
  1227. _L.SFX.Play(5625433552, popcornMachine.model.PrimaryPart)
  1228.  
  1229.  
  1230.  
  1231. -- popcorn tip
  1232.  
  1233. if self.stateData.foodOrder then
  1234.  
  1235. _L.Network.Fire("AwardTipWithVerification", self.UID, popcornMachine.UID, self.stateData.foodOrder.ID)
  1236.  
  1237. end
  1238.  
  1239.  
  1240.  
  1241. -- gumball emoji
  1242.  
  1243. self:TimedEmoji("VeryHappyEmoji", 2.5)
  1244.  
  1245. self:FaceEntity(popcornMachine)
  1246.  
  1247. goToExitAndLeave()
  1248.  
  1249. end)
  1250.  
  1251. break
  1252.  
  1253. end
  1254.  
  1255. end
  1256.  
  1257. end
  1258.  
  1259.  
  1260.  
  1261. end
  1262.  
  1263.  
  1264.  
  1265. -- check for soda machine
  1266.  
  1267. if not isLeavingTip and not isGoingForGumball and not isGoingForCandy and not isGoingForPopcorn and not wasForcedToLeave and not isGoingForBowl then
  1268.  
  1269. local sodaMachines = myFloor:GetEntitiesFromClassAndSubClass("Appliance", "SodaMachine")
  1270.  
  1271. if #sodaMachines > 0 then
  1272.  
  1273. for _, sodaMachine in ipairs(sodaMachines) do
  1274.  
  1275. if true then
  1276.  
  1277. isGoingForSoda = true
  1278.  
  1279.  
  1280.  
  1281. local fx, fy, fz = sodaMachine:GetFacePosition()
  1282.  
  1283. if not myFloor:IsValidVoxel(fx, fy, fz) then
  1284.  
  1285. fx, fy, fz = sodaMachine.xVoxel, sodaMachine.yVoxel, sodaMachine.zVoxel
  1286.  
  1287. end
  1288.  
  1289. self:WalkToPoint(fx, fy, fz, function()
  1290.  
  1291. if sodaMachine.isDeleted or self.isDeleted then
  1292.  
  1293. goToExitAndLeave()
  1294.  
  1295. return
  1296.  
  1297. end
  1298.  
  1299.  
  1300.  
  1301. _L.SFX.Play(5708685354, sodaMachine.model.PrimaryPart)
  1302.  
  1303.  
  1304.  
  1305. -- soda tip
  1306.  
  1307. if self.stateData.foodOrder then
  1308.  
  1309. _L.Network.Fire("AwardTipWithVerification", self.UID, sodaMachine.UID, self.stateData.foodOrder.ID)
  1310.  
  1311. end
  1312.  
  1313.  
  1314.  
  1315. -- gumball emoji
  1316.  
  1317. self:TimedEmoji("VeryHappyEmoji", 2.5)
  1318.  
  1319. self:FaceEntity(sodaMachine)
  1320.  
  1321. goToExitAndLeave()
  1322.  
  1323. end)
  1324.  
  1325. break
  1326.  
  1327. end
  1328.  
  1329. end
  1330.  
  1331. end
  1332.  
  1333. end
  1334.  
  1335.  
  1336.  
  1337. -- check for arcade machine
  1338.  
  1339. if not isLeavingTip and not isGoingForGumball and not isGoingForCandy and not isGoingForPopcorn and not isGoingForSoda and not wasForcedToLeave and not isGoingForBowl then
  1340.  
  1341. local arcadeMachines = myFloor:GetEntitiesFromClassAndSubClass("Furniture", "ArcadeMachine")
  1342.  
  1343. if #arcadeMachines > 0 then
  1344.  
  1345. local indices = _L.Functions.RandomIndices(arcadeMachines)
  1346.  
  1347. for _, index in ipairs(indices) do
  1348.  
  1349. local arcadeMachine = arcadeMachines[index]
  1350.  
  1351. if arcadeMachine.arcadeState ~= "Highscore" then
  1352.  
  1353. continue
  1354.  
  1355. end
  1356.  
  1357. if arcadeMachine.busy then
  1358.  
  1359. continue
  1360.  
  1361. end
  1362.  
  1363. arcadeMachine.busy = true
  1364.  
  1365. isGoingForArcade = true
  1366.  
  1367. local fx, fy, fz = arcadeMachine:GetFacePosition()
  1368.  
  1369. if not myFloor:IsValidVoxel(fx, fy, fz) then
  1370.  
  1371. fx, fy, fz = arcadeMachine.xVoxel, arcadeMachine.yVoxel, arcadeMachine.zVoxel
  1372.  
  1373. end
  1374.  
  1375. self:WalkToPoint(fx, fy, fz, function()
  1376.  
  1377.  
  1378.  
  1379. if arcadeMachine.isDeleted or self.isDeleted then
  1380.  
  1381. goToExitAndLeave()
  1382.  
  1383. return
  1384.  
  1385. end
  1386.  
  1387.  
  1388.  
  1389. self:FaceEntity(arcadeMachine)
  1390.  
  1391.  
  1392.  
  1393. -- play game (halts thread until done)
  1394.  
  1395. arcadeMachine:PlayGameWithCustomer(self)
  1396.  
  1397.  
  1398.  
  1399. arcadeMachine.busy = false
  1400.  
  1401.  
  1402.  
  1403. goToExitAndLeave()
  1404.  
  1405.  
  1406.  
  1407. end)
  1408.  
  1409. break
  1410.  
  1411. end
  1412.  
  1413. end
  1414.  
  1415. end
  1416.  
  1417.  
  1418.  
  1419. -- check for celebrity customer
  1420.  
  1421. local isGoingForCelebrity = false
  1422.  
  1423. (function()
  1424.  
  1425. if isLeavingTip or isGoingForGumball or isGoingForCandy or isGoingForPopcorn or isGoingForArcade or isGoingForSoda or isGoingForBowl then
  1426.  
  1427. return
  1428.  
  1429. end
  1430.  
  1431. if _L.Variables.MyBakery.nameCounters["Celebrity Customer"] == 0 then
  1432.  
  1433. return
  1434.  
  1435. end
  1436.  
  1437.  
  1438.  
  1439. local celebrity = _L.Variables.MyBakery:SearchForCelebrity()
  1440.  
  1441. if not celebrity or celebrity.isDeleted or celebrity.stateData.celebrityApproachCount >= 3 then
  1442.  
  1443. return
  1444.  
  1445. end
  1446.  
  1447.  
  1448.  
  1449. local function isValidCelebState()
  1450.  
  1451. local validCelebStates = {
  1452.  
  1453. ThinkingAboutOrder = true,
  1454.  
  1455. DecidedOnOrder = true,
  1456.  
  1457. WaitingToOrder = true,
  1458.  
  1459. WaitingForFood = true,
  1460.  
  1461. EatingFood = true
  1462.  
  1463. }
  1464.  
  1465. return not celebrity.isDeleted and validCelebStates[celebrity.state]
  1466.  
  1467. end
  1468.  
  1469.  
  1470.  
  1471. if not isValidCelebState() then
  1472.  
  1473. return
  1474.  
  1475. end
  1476.  
  1477.  
  1478.  
  1479. isGoingForCelebrity = true
  1480.  
  1481. celebrity.stateData.celebrityApproachCount += 1
  1482.  
  1483.  
  1484.  
  1485. self:WalkToNewFloor(celebrity:GetMyFloor(), function()
  1486.  
  1487. if not isValidCelebState() then
  1488.  
  1489. if not celebrity.isDeleted then
  1490.  
  1491. celebrity.stateData.celebrityApproachCount -= 1
  1492.  
  1493. end
  1494.  
  1495. goToExitAndLeave()
  1496.  
  1497. return
  1498.  
  1499. end
  1500.  
  1501.  
  1502.  
  1503. self:WalkToPoint(celebrity.xVoxel, celebrity.yVoxel, celebrity.zVoxel, function()
  1504.  
  1505. if not isValidCelebState() then
  1506.  
  1507. if not celebrity.isDeleted then
  1508.  
  1509. celebrity.stateData.celebrityApproachCount -= 1
  1510.  
  1511. end
  1512.  
  1513. goToExitAndLeave()
  1514.  
  1515. return
  1516.  
  1517. end
  1518.  
  1519.  
  1520.  
  1521. celebrity.stateData.celebrityApproachCount -= 1
  1522.  
  1523.  
  1524.  
  1525. _L.SFX.Play(5278932469, celebrity.model.PrimaryPart.Position)
  1526.  
  1527. self:FaceEntity(celebrity)
  1528.  
  1529. self:TimedEmoji("Starstruck", 2.5)
  1530.  
  1531. self:PlayLoadedAnimation("wave")
  1532.  
  1533. goToExitAndLeave()
  1534.  
  1535. end)
  1536.  
  1537. end)
  1538.  
  1539. end)()
  1540.  
  1541. if not isLeavingTip and not isGoingForGumball and not isGoingForCelebrity and not isGoingForCandy and not isGoingForArcade and not isGoingForPopcorn and not isGoingForBowl then
  1542.  
  1543. goToExitAndLeave()
  1544.  
  1545. end
  1546.  
  1547. end)()
  1548.  
  1549. end
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555. function Waiter:StartActionLoop()
  1556.  
  1557. coroutine.wrap(function()
  1558.  
  1559. wait()
  1560.  
  1561. while not self.isDeleted do
  1562.  
  1563. self:PerformAction()
  1564.  
  1565. wait()
  1566.  
  1567. end
  1568.  
  1569. end)()
  1570.  
  1571. end
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577. function Waiter:CheckForDishPickup()
  1578.  
  1579.  
  1580.  
  1581. local myFloor = self:GetMyFloor()
  1582.  
  1583. local selectedDishChair, selectedDishChairFloor = nil
  1584.  
  1585.  
  1586.  
  1587. -- check other floors for dishes
  1588.  
  1589. local indices = _L.Functions.RandomIndices(_L.Variables.MyBakery.floors)
  1590.  
  1591.  
  1592.  
  1593. --check my floor first
  1594.  
  1595. if true then
  1596.  
  1597. for i, index in ipairs(indices) do
  1598.  
  1599. if index == myFloor.floorLevel then
  1600.  
  1601. table.remove(indices, i)
  1602.  
  1603. table.insert(indices, 1, myFloor.floorLevel)
  1604.  
  1605. break
  1606.  
  1607. end
  1608.  
  1609. end
  1610.  
  1611. end
  1612.  
  1613.  
  1614.  
  1615. for _, index in ipairs(indices) do
  1616.  
  1617. local thisFloor = _L.Variables.MyBakery.floors[index]
  1618.  
  1619. local dishIndices = _L.Functions.RandomIndices(thisFloor.dishChairs)
  1620.  
  1621. for _, dishIndex in ipairs(dishIndices) do
  1622.  
  1623. local dishChair = thisFloor.dishChairs[dishIndex]
  1624.  
  1625. if dishChair.isDeleted or dishChair.stateData.flaggedByWaiterForDishPickup or not dishChair.stateData.dish or dishChair.stateData.dish.isDeleted then
  1626.  
  1627. continue
  1628.  
  1629. end
  1630.  
  1631. selectedDishChair = dishChair
  1632.  
  1633. selectedDishChairFloor = dishChair:GetMyFloor()
  1634.  
  1635. break
  1636.  
  1637. end
  1638.  
  1639. if selectedDishChair then
  1640.  
  1641. break
  1642.  
  1643. end
  1644.  
  1645. end
  1646.  
  1647.  
  1648.  
  1649. if not selectedDishChair then
  1650.  
  1651. return false
  1652.  
  1653. end
  1654.  
  1655.  
  1656.  
  1657. local dishwashers = myFloor:GatherDishwashersOnAnyFloor()
  1658.  
  1659. if #dishwashers == 0 then
  1660.  
  1661. return false
  1662.  
  1663. end
  1664.  
  1665.  
  1666.  
  1667. -- chair that has an attached dish to go to
  1668.  
  1669. local dishChair = selectedDishChair
  1670.  
  1671. dishChair.stateData.flaggedByWaiterForDishPickup = true
  1672.  
  1673.  
  1674.  
  1675. local dishwasher = dishwashers[math.random(#dishwashers)]
  1676.  
  1677. dishwasher.stateData.dishWasherTargetCount += 1
  1678.  
  1679.  
  1680.  
  1681. -- flag the dish with the targeted dishwasher
  1682.  
  1683. dishChair.stateData.dish.flaggedDishwasherUID = dishwasher.UID
  1684.  
  1685.  
  1686.  
  1687. self.state = "WalkingToPickupDish"
  1688.  
  1689.  
  1690.  
  1691. self:WalkToNewFloor(dishChair:GetMyFloor(), function()
  1692.  
  1693.  
  1694.  
  1695. if dishChair.isDeleted or not dishChair.stateData.dish then
  1696.  
  1697. dishwasher.stateData.dishWasherTargetCount -= 1
  1698.  
  1699. self.state = "Idle"
  1700.  
  1701. return
  1702.  
  1703. end
  1704.  
  1705.  
  1706.  
  1707. self:WalkToPoint(dishChair.xVoxel, dishChair.yVoxel, dishChair.zVoxel, function()
  1708.  
  1709.  
  1710.  
  1711. if dishChair.isDeleted or not dishChair.stateData.dish then
  1712.  
  1713. dishwasher.stateData.dishWasherTargetCount -= 1
  1714.  
  1715. self.state = "Idle"
  1716.  
  1717. return
  1718.  
  1719. end
  1720.  
  1721.  
  1722.  
  1723. dishChair.stateData.flaggedByWaiterForDishPickup = false
  1724.  
  1725.  
  1726.  
  1727. if not dishChair.stateData.dish or dishChair.stateData.dish.isDeleted then
  1728.  
  1729. dishwasher.stateData.dishWasherTargetCount -= 1
  1730.  
  1731. self.state = "Idle"
  1732.  
  1733. return
  1734.  
  1735. end
  1736.  
  1737.  
  1738.  
  1739. -- dish is good. delete it and remove
  1740.  
  1741. if dishChair.stateData.dish and dishChair.stateData.dish.model then
  1742.  
  1743.  
  1744.  
  1745. -- remove dishChair from available
  1746.  
  1747. for i, dishChairEntry in ipairs(selectedDishChairFloor.dishChairs) do
  1748.  
  1749. if dishChairEntry == selectedDishChair then
  1750.  
  1751. table.remove(selectedDishChairFloor.dishChairs, i)
  1752.  
  1753. break
  1754.  
  1755. end
  1756.  
  1757. end
  1758.  
  1759.  
  1760.  
  1761. -- stop the interact
  1762.  
  1763. dishChair.stateData.dish:CleanupInteract()
  1764.  
  1765.  
  1766.  
  1767. -- play dish sound
  1768.  
  1769. if dishChair.stateData.dish.model and dishChair.stateData.dish.model.PrimaryPart then
  1770.  
  1771. local dishSounds = {5205173686, 5205173942}
  1772.  
  1773. _L.SFX.Play(dishSounds[math.random(#dishSounds)], dishChair.stateData.dish.model:GetPrimaryPartCFrame().p)
  1774.  
  1775. end
  1776.  
  1777.  
  1778.  
  1779. -- pick up the money and dish (if necessary)
  1780.  
  1781. dishChair.stateData.dish:MoneyPickedUp()
  1782.  
  1783. dishChair.stateData.dish:DestroyModel()
  1784.  
  1785. dishChair.stateData.dish = nil
  1786.  
  1787.  
  1788.  
  1789. -- hold the dish I'm delivering
  1790.  
  1791. self:HoldDirtyDish()
  1792.  
  1793.  
  1794.  
  1795. end
  1796.  
  1797.  
  1798.  
  1799. self:FaceEntity(dishChair)
  1800.  
  1801.  
  1802.  
  1803. if dishwasher.isDeleted then
  1804.  
  1805. self:StopLoadedAnimation("hold")
  1806.  
  1807. if self.stateData.heldDish then
  1808.  
  1809. self.stateData.heldDish = self.stateData.heldDish:Destroy()
  1810.  
  1811. end
  1812.  
  1813. self.state = "Idle"
  1814.  
  1815. return
  1816.  
  1817. end
  1818.  
  1819.  
  1820.  
  1821. -- walk to the dishwasher to deposit
  1822.  
  1823. -- TODO face direction
  1824.  
  1825. self:WalkToNewFloor(dishwasher:GetMyFloor(), function()
  1826.  
  1827.  
  1828.  
  1829. if dishwasher.isDeleted then
  1830.  
  1831. self:StopLoadedAnimation("hold")
  1832.  
  1833. if self.stateData.heldDish then
  1834.  
  1835. self.stateData.heldDish = self.stateData.heldDish:Destroy()
  1836.  
  1837. end
  1838.  
  1839. self.state = "Idle"
  1840.  
  1841. return
  1842.  
  1843. end
  1844.  
  1845.  
  1846.  
  1847. self:WalkToPoint(dishwasher.xVoxel, dishwasher.yVoxel, dishwasher.zVoxel, function()
  1848.  
  1849.  
  1850.  
  1851. -- put down the dish
  1852.  
  1853. self:DropFood()
  1854.  
  1855.  
  1856.  
  1857. if dishwasher.isDeleted then
  1858.  
  1859. self.state = "Idle"
  1860.  
  1861. return
  1862.  
  1863. end
  1864.  
  1865. dishwasher:AddDish()
  1866.  
  1867.  
  1868.  
  1869. self:FaceEntity(dishwasher)
  1870.  
  1871.  
  1872.  
  1873. self:ResetAllStates()
  1874.  
  1875.  
  1876.  
  1877. end)
  1878.  
  1879. end)
  1880.  
  1881. end)
  1882.  
  1883. end)
  1884.  
  1885.  
  1886.  
  1887. return true
  1888.  
  1889.  
  1890.  
  1891. end
  1892.  
  1893.  
  1894.  
  1895. function Waiter:CheckForFoodDelivery()
  1896.  
  1897.  
  1898.  
  1899. -- gather all order stands
  1900.  
  1901. local myFloor = self:GetMyFloor()
  1902.  
  1903. local orderStands = myFloor:GatherOrderStandsWithDeliveryReady()
  1904.  
  1905.  
  1906.  
  1907. if #orderStands == 0 then
  1908.  
  1909.  
  1910.  
  1911. -- if there are no order stands on my floor, search for floors that might need help
  1912.  
  1913. local indices = _L.Functions.RandomIndices(_L.Variables.MyBakery.floors)
  1914.  
  1915. for _, index in ipairs(indices) do
  1916.  
  1917. local floor = _L.Variables.MyBakery.floors[index]
  1918.  
  1919. if floor ~= myFloor then
  1920.  
  1921. if not floor:HasAtLeastOneIdleStateOfClass("Waiter") then
  1922.  
  1923. -- gather order stands on this floor
  1924.  
  1925. orderStands = floor:GatherOrderStandsWithDeliveryReady()
  1926.  
  1927. if #orderStands > 0 then
  1928.  
  1929. break
  1930.  
  1931. end
  1932.  
  1933. end
  1934.  
  1935. end
  1936.  
  1937. end
  1938.  
  1939.  
  1940.  
  1941. -- STILL nothing? abort
  1942.  
  1943. if #orderStands == 0 then
  1944.  
  1945. return false
  1946.  
  1947. end
  1948.  
  1949. end
  1950.  
  1951.  
  1952.  
  1953. -- select a random order stand to deliver from
  1954.  
  1955. local orderStand = orderStands[math.random(#orderStands)]
  1956.  
  1957. if not orderStand then
  1958.  
  1959. return false
  1960.  
  1961. end
  1962.  
  1963.  
  1964.  
  1965. orderStand.stateData.foodReadyTargetCount = orderStand.stateData.foodReadyTargetCount + 1
  1966.  
  1967.  
  1968.  
  1969. self.state = "WalkingToPickupFood"
  1970.  
  1971.  
  1972.  
  1973. -- walk to the order stand
  1974.  
  1975. self:WalkToNewFloor(orderStand:GetMyFloor(), function()
  1976.  
  1977.  
  1978.  
  1979. -- no need to kick out the customer, they've already been removed.
  1980.  
  1981. -- just reset the waiter back to idle
  1982.  
  1983. if orderStand.isDeleted then
  1984.  
  1985. self.state = "Idle"
  1986.  
  1987. return
  1988.  
  1989. end
  1990.  
  1991.  
  1992.  
  1993. self:WalkToPoint(orderStand.xVoxel, orderStand.yVoxel, orderStand.zVoxel, function()
  1994.  
  1995.  
  1996.  
  1997. if orderStand.isDeleted then
  1998.  
  1999. self.state = "Idle"
  2000.  
  2001. return
  2002.  
  2003. end
  2004.  
  2005.  
  2006.  
  2007. orderStand.stateData.foodReadyTargetCount = orderStand.stateData.foodReadyTargetCount - 1
  2008.  
  2009.  
  2010.  
  2011. -- it's possible that the user already cleared the queue...
  2012.  
  2013. if #orderStand.stateData.foodReadyList == 0 then
  2014.  
  2015. self.state = "Idle"
  2016.  
  2017. return
  2018.  
  2019. end
  2020.  
  2021.  
  2022.  
  2023. -- grab some food off of the top of the queue
  2024.  
  2025. local selectedFoodOrder = orderStand.stateData.foodReadyList[1]
  2026.  
  2027. selectedFoodOrder.isGold = orderStand:IsGoldOrderStand() and math.random() < 0.05
  2028.  
  2029. table.remove(orderStand.stateData.foodReadyList, 1)
  2030.  
  2031. if selectedFoodOrder.isGold then
  2032.  
  2033. _L.SFX.Play(5370840758, orderStand.model.PrimaryPart)
  2034.  
  2035. end
  2036.  
  2037.  
  2038.  
  2039. -- delete this list item
  2040.  
  2041. selectedFoodOrder:DestroyPopupListItemUI()
  2042.  
  2043.  
  2044.  
  2045. -- the customer that I should deliver to...
  2046.  
  2047. local customerOfOrder = self:EntityTable()[selectedFoodOrder.customerOwnerUID]
  2048.  
  2049. if not customerOfOrder then
  2050.  
  2051. _L.Print("CRITICAL: customer owner of food not found", true)
  2052.  
  2053. self.state = "Idle"
  2054.  
  2055. return false
  2056.  
  2057. end
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063. -- pause to face the order stand for a little bit
  2064.  
  2065. self:FaceEntity(orderStand)
  2066.  
  2067. -- hold the dish I'm delivering
  2068.  
  2069. self:HoldFood(selectedFoodOrder.ID, selectedFoodOrder.isGold)
  2070.  
  2071.  
  2072.  
  2073. self.state = "WalkingToDeliverFood"
  2074.  
  2075.  
  2076.  
  2077. if customerOfOrder.isDeleted then
  2078.  
  2079. self.state = "Idle"
  2080.  
  2081. self.stateData.heldDish = self.stateData.heldDish:Destroy()
  2082.  
  2083. return
  2084.  
  2085. end
  2086.  
  2087.  
  2088.  
  2089. -- walk to the customer to deliver...
  2090.  
  2091. self:WalkToNewFloor(customerOfOrder:GetMyFloor(), function()
  2092.  
  2093. self:WalkToPoint(customerOfOrder.xVoxel, customerOfOrder.yVoxel, customerOfOrder.zVoxel, function()
  2094.  
  2095.  
  2096.  
  2097. self:DropFood()
  2098.  
  2099.  
  2100.  
  2101. if customerOfOrder.isDeleted then
  2102.  
  2103. _L.Print("CRITICAL: walked to customer, but they were forced to leave. aborting", true)
  2104.  
  2105. self.state = "Idle"
  2106.  
  2107. return
  2108.  
  2109. end
  2110.  
  2111.  
  2112.  
  2113. customerOfOrder:ChangeToEatingState()
  2114.  
  2115.  
  2116.  
  2117. -- face the customer
  2118.  
  2119. self:FaceEntity(customerOfOrder)
  2120.  
  2121.  
  2122.  
  2123. -- award XP for delivering food
  2124.  
  2125. _L.Network.Fire("AwardWaiterExperienceForDeliveringOrderWithVerification", self.UID)
  2126.  
  2127. -- free the waiter back up
  2128.  
  2129. self.state = "Idle"
  2130.  
  2131. end)
  2132.  
  2133. end)
  2134.  
  2135. end)
  2136.  
  2137. end)
  2138.  
  2139.  
  2140.  
  2141. return true
  2142.  
  2143. end
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149. function Waiter:CheckForCustomerOrder()
  2150.  
  2151.  
  2152.  
  2153. local myFloor = self:GetMyFloor()
  2154.  
  2155.  
  2156.  
  2157. -- find a customer that is waiting to order
  2158.  
  2159. local waitingCustomer = myFloor:GetCustomerWaitingToOrder()
  2160.  
  2161.  
  2162.  
  2163. if not waitingCustomer then
  2164.  
  2165.  
  2166.  
  2167. -- if there's no customer on my current floor, check if other floors need help
  2168.  
  2169. local indices = _L.Functions.RandomIndices(_L.Variables.MyBakery.floors)
  2170.  
  2171. for _, index in ipairs(indices) do
  2172.  
  2173. local floor = _L.Variables.MyBakery.floors[index]
  2174.  
  2175. if floor ~= myFloor then
  2176.  
  2177. if not floor:HasAtLeastOneIdleStateOfClass("Waiter") then
  2178.  
  2179. waitingCustomer = floor:GetCustomerWaitingToOrder()
  2180.  
  2181. if waitingCustomer then
  2182.  
  2183. break
  2184.  
  2185. end
  2186.  
  2187. end
  2188.  
  2189. end
  2190.  
  2191. end
  2192.  
  2193.  
  2194.  
  2195. -- still nothing? abort
  2196.  
  2197. if not waitingCustomer then
  2198.  
  2199. return false
  2200.  
  2201. end
  2202.  
  2203. end
  2204.  
  2205.  
  2206.  
  2207. self.state = "WalkingToTakeOrder"
  2208.  
  2209.  
  2210.  
  2211. -- find the entire customer group
  2212.  
  2213. local customerGroup = {waitingCustomer}
  2214.  
  2215. for _, customerPartner in ipairs(waitingCustomer.stateData.queueGroup) do
  2216.  
  2217. if customerPartner.state == "WaitingToOrder" and not customerPartner.waiterIsAttendingToFoodOrder then
  2218.  
  2219. table.insert(customerGroup, customerPartner)
  2220.  
  2221. end
  2222.  
  2223. end
  2224.  
  2225.  
  2226.  
  2227. -- tag debounce, not allowing other waiters to interfere
  2228.  
  2229. for _, seatedCustomer in ipairs(customerGroup) do
  2230.  
  2231. seatedCustomer.waiterIsAttendingToFoodOrder = true
  2232.  
  2233. end
  2234.  
  2235.  
  2236.  
  2237. local function untagGroup()
  2238.  
  2239. for _, seatedCustomer in ipairs(customerGroup) do
  2240.  
  2241. seatedCustomer.waiterIsAttendingToFoodOrder = false
  2242.  
  2243. end
  2244.  
  2245. end
  2246.  
  2247.  
  2248.  
  2249. -- walk to the seated group
  2250.  
  2251. local firstCustomer = customerGroup[1]
  2252.  
  2253. local groupTable = self:EntityTable()[firstCustomer.stateData.tableUID]
  2254.  
  2255. if not groupTable or groupTable.isDeleted then
  2256.  
  2257. self.state = "Idle"
  2258.  
  2259. return
  2260.  
  2261. end
  2262.  
  2263. local tx, ty, tz = groupTable.xVoxel, groupTable.yVoxel, groupTable.zVoxel
  2264.  
  2265.  
  2266.  
  2267. local customerFloor = firstCustomer:GetMyFloor()
  2268.  
  2269. self:WalkToNewFloor(customerFloor, function()
  2270.  
  2271. if firstCustomer.leaving or firstCustomer.isDeleted then
  2272.  
  2273. self.state = "Idle"
  2274.  
  2275. return
  2276.  
  2277. end
  2278.  
  2279. self:WalkToPoint(tx, ty, tz, function()
  2280.  
  2281.  
  2282.  
  2283. if firstCustomer.isDeleted or firstCustomer.leaving then
  2284.  
  2285. self.state = "Idle"
  2286.  
  2287. return
  2288.  
  2289. end
  2290.  
  2291.  
  2292.  
  2293. -- order stand to deposit the orders in
  2294.  
  2295. local orderStand = customerFloor:FindOrderStandOnAnyFloor()
  2296.  
  2297. if not orderStand then
  2298.  
  2299. _L.Print("CRITICAL: NO ORDER STAND FOUND!", true)
  2300.  
  2301. untagGroup()
  2302.  
  2303. self.state = "Idle"
  2304.  
  2305. self:TimedEmoji("ConcernedEmoji", 2)
  2306.  
  2307. return
  2308.  
  2309. end
  2310.  
  2311.  
  2312.  
  2313. -- stop interacting
  2314.  
  2315. local firstCustomer = customerGroup[1]
  2316.  
  2317. if firstCustomer then
  2318.  
  2319. firstCustomer:StopGroupEmoji()
  2320.  
  2321. firstCustomer:CleanupGroupInteract()
  2322.  
  2323. end
  2324.  
  2325.  
  2326.  
  2327. -- check for customers in the group still waiting to have their
  2328.  
  2329. -- order taken. it's possible that the user took one or
  2330.  
  2331. -- more of their orders
  2332.  
  2333. local groupOrder = {}
  2334.  
  2335. local tookOrdersFrom = {}
  2336.  
  2337. for _, seatedCustomer in ipairs(customerGroup) do
  2338.  
  2339. if seatedCustomer.state == "WaitingToOrder" then
  2340.  
  2341. table.insert(tookOrdersFrom, seatedCustomer)
  2342.  
  2343. groupOrder[seatedCustomer.UID] = _L.Food.RandomFoodChoice(seatedCustomer.UID, seatedCustomer.ID, seatedCustomer:IsRichCustomer(), seatedCustomer:IsPirateCustomer(), seatedCustomer.isNearTree)
  2344.  
  2345. seatedCustomer.state = "WaitingForFood"
  2346.  
  2347. seatedCustomer:StopChat()
  2348.  
  2349. end
  2350.  
  2351. end
  2352.  
  2353.  
  2354.  
  2355. -- if no orders are taken, abort
  2356.  
  2357. if #tookOrdersFrom == 0 then
  2358.  
  2359. self.state = "Idle"
  2360.  
  2361. return
  2362.  
  2363. end
  2364.  
  2365.  
  2366.  
  2367. -- take order animation
  2368.  
  2369. self:PlayLoadedAnimation("write")
  2370.  
  2371. for _, customer in ipairs(customerGroup) do
  2372.  
  2373. self:FaceEntity(customer)
  2374.  
  2375. end
  2376.  
  2377. self:StopLoadedAnimation("write")
  2378.  
  2379.  
  2380.  
  2381. self.state = "WalkingToDropoffOrder"
  2382.  
  2383.  
  2384.  
  2385. self:WalkToNewFloor(orderStand:GetMyFloor(), function()
  2386.  
  2387.  
  2388.  
  2389. if orderStand.isDeleted then
  2390.  
  2391. for _, customer in ipairs(customerGroup) do
  2392.  
  2393. customer:ForcedToLeave()
  2394.  
  2395. end
  2396.  
  2397. self.state = "Idle"
  2398.  
  2399. return
  2400.  
  2401. end
  2402.  
  2403.  
  2404.  
  2405. self:WalkToPoint(orderStand.xVoxel, orderStand.yVoxel, orderStand.zVoxel, function()
  2406.  
  2407.  
  2408.  
  2409. if orderStand.isDeleted then
  2410.  
  2411. for _, customer in ipairs(customerGroup) do
  2412.  
  2413. customer:ForcedToLeave()
  2414.  
  2415. end
  2416.  
  2417. self.state = "Idle"
  2418.  
  2419. return
  2420.  
  2421. end
  2422.  
  2423.  
  2424.  
  2425. -- deposit each of the orders
  2426.  
  2427. for _, orderedCustomer in ipairs(tookOrdersFrom) do
  2428.  
  2429. if orderedCustomer.isDeleted then
  2430.  
  2431. continue
  2432.  
  2433. end
  2434.  
  2435. orderedCustomer:ChangeToWaitingForFoodState(groupOrder[orderedCustomer.UID])
  2436.  
  2437. orderStand:AddFoodToQueue(groupOrder[orderedCustomer.UID])
  2438.  
  2439. end
  2440.  
  2441.  
  2442.  
  2443. -- award XP for taking an order
  2444.  
  2445. _L.Network.Fire("AwardWaiterExperienceForTakingOrderWithVerification", self.UID)
  2446.  
  2447.  
  2448.  
  2449. -- face deposit location
  2450.  
  2451. self:FaceEntity(orderStand)
  2452.  
  2453.  
  2454.  
  2455. -- free up the waiter for more actions
  2456.  
  2457. self.state = "Idle"
  2458.  
  2459.  
  2460.  
  2461. end)
  2462.  
  2463. end)
  2464.  
  2465.  
  2466.  
  2467. end)
  2468.  
  2469. end)
  2470.  
  2471.  
  2472.  
  2473. return true
  2474.  
  2475.  
  2476.  
  2477. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement