From 2b64bfc3927bcc3ccbe0ec9816daa1bab000134d Mon Sep 17 00:00:00 2001 From: EJClaw Date: Tue, 13 Oct 2026 16:20:00 +0900 Subject: [PATCH] =?UTF-8?q?fix(bunsik):=20=EC=9A=94=EB=A6=AC=20=EC=B0=BD?= =?UTF-8?q?=20=EC=84=9C=EB=B2=84=20=EA=B2=80=EC=A6=9D=20=E2=80=94=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=20=EA=B3=A0=EB=A6=84(cookStart)=EB=B6=80?= =?UTF-8?q?=ED=84=B0=20=EC=A1=B0=EB=A6=AC=20=EA=B3=BC=EC=A0=95=20=EC=B5=9C?= =?UTF-8?q?=EC=86=8C=20=EC=8B=9C=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=98?= =?UTF-8?q?=EC=95=BC=20=EC=99=84=EC=84=B1=20=EC=9D=B8=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PlotController.startCook/finishCook: 고른 메뉴 일치, 주문·손 자리, 조리대 거리, Recipes.minTime 확인 - 원격 이벤트만 보내 조리 과정을 건너뛰면 거절(통합 테스트 추가), 쓰지 않게 된 lastCook 제거 - 통합 테스트 822/822, Recipes.spec 101 Co-Authored-By: Claude Opus 5.5 --- bunsik-tycoon/src/client/Kitchen.luau | 2 ++ bunsik-tycoon/src/server/Game.luau | 15 +++++---- bunsik-tycoon/src/server/PlotController.luau | 32 ++++++++++++++++++-- bunsik-tycoon/src/shared/Recipes.luau | 21 +++++++++++++ bunsik-tycoon/tests/Recipes.spec.luau | 9 ++++++ bunsik-tycoon/tests/cloud/integration.luau | 24 ++++++++++++--- 6 files changed, 90 insertions(+), 13 deletions(-) diff --git a/bunsik-tycoon/src/client/Kitchen.luau b/bunsik-tycoon/src/client/Kitchen.luau index b4c7d1a..09be7b9 100644 --- a/bunsik-tycoon/src/client/Kitchen.luau +++ b/bunsik-tycoon/src/client/Kitchen.luau @@ -853,6 +853,8 @@ function Kitchen.build(root: Frame, state: Instance, send: (string, any?) -> ()) if not Recipes.choose(flow, menu) then return false end + -- 서버가 조리 시작 시각을 적어 두고, 다 만들었을 때 걸린 시간을 검사합니다. + send("cookStart", menu) setPage("cook") drawCook() local s = Recipes.current(flow) diff --git a/bunsik-tycoon/src/server/Game.luau b/bunsik-tycoon/src/server/Game.luau index f3c08d0..143e843 100644 --- a/bunsik-tycoon/src/server/Game.luau +++ b/bunsik-tycoon/src/server/Game.luau @@ -258,17 +258,20 @@ local function onAction(player: Player, kind: any, arg: any) if not controller then return end - if kind == "cook" then - -- 요리 화면에서 다 만들었을 때(arg = 고른 메뉴). 요리 과정을 아주 빨리 해도 걸리는 시간은 지나야 다음 접시를 만들 수 있고, - -- 조리대 가까이 있어야 합니다. + if kind == "cookStart" or kind == "cook" then + -- 요리 창: cookStart(메뉴 고름) → cook(다 만듦). 서버가 고른 메뉴·주문·손 자리·조리대 거리· + -- 조리 과정 최소 시간을 다시 검사합니다(PlotController.startCook/finishCook). local now = os.clock() local menu = if typeof(arg) == "string" and Economy.MENUS[arg] then arg else nil local char = player.Character local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart? local near = not root or (root.Position - controller.slot.refs.stove.Position).Magnitude <= COOK_RANGE - if menu and near and now - controller.lastCook >= controller.shop.stats.cook * 0.4 then - controller.shop.now = now - controller:cook(menu) + if not menu or not near then + controller.cookSession = nil + elseif kind == "cookStart" then + controller:startCook(menu, now) + else + controller:finishCook(menu, now) end elseif kind == "buy" then local ok, err = controller:buy() diff --git a/bunsik-tycoon/src/server/PlotController.luau b/bunsik-tycoon/src/server/PlotController.luau index efdd7b6..0fc66ca 100644 --- a/bunsik-tycoon/src/server/PlotController.luau +++ b/bunsik-tycoon/src/server/PlotController.luau @@ -10,6 +10,7 @@ local Shared = ReplicatedStorage.Shared local Economy = require(Shared.Economy) local Shop = require(Shared.Shop) local Locale = require(Shared.Locale) +local Recipes = require(Shared.Recipes) local Sounds = require(Shared.Sounds) local Build = require(script.Parent.Build) @@ -19,6 +20,7 @@ local PlotBuilder = require(script.Parent.PlotBuilder) local PlotLayout = require(script.Parent.PlotLayout) local SERVE_RANGE = 8.5 +local COOK_SLACK = 0.8 -- 요리 최소 시간 검사의 네트워크 지연 오차 local PICKUP_RANGE = 8 export type Slot = { @@ -63,7 +65,7 @@ export type PlotController = typeof(setmetatable( views: { [number]: CustomerView }, handModels: { Model }, counterModels: { Model }, - lastCook: number, + cookSession: { menu: string, start: number }?, -- 요리 창에서 메뉴를 고른 때(서버 시계) helper: Npc.Handle?, guide: BasePart, guideValue: ObjectValue, @@ -97,7 +99,7 @@ function PlotController.new(slot: Slot, owner: Instance, opts: Options): PlotCon views = {}, handModels = {}, counterModels = {}, - lastCook = 0, + cookSession = nil, helper = nil :: Npc.Handle?, guide = Instance.new("Part") :: BasePart, guideValue = Instance.new("ObjectValue"), @@ -317,7 +319,6 @@ function PlotController.cook(self: PlotController, choice: string?): string? if not menu then return nil end - self.lastCook = self.shop.now local dish = Food.dish(menu, PlotBuilder.counterSlot(self.slot.cf, 1), self.slot.refs.dynamic) table.insert(self.handModels, dish) self:layoutHand() @@ -329,6 +330,31 @@ function PlotController.cook(self: PlotController, choice: string?): string? return menu end +-- 요리 창에서 메뉴를 골랐을 때. 만들 수 있는 메뉴(주문 있음, 손에 자리 있음)면 시작 시각을 적어 둡니다. +function PlotController.startCook(self: PlotController, menu: string, now: number): boolean + if Recipes.LIST[menu] == nil or Shop.handFull(self.shop) or not Shop.openCounts(self.shop)[menu] then + self.cookSession = nil + return false + end + self.cookSession = { menu = menu, start = now } + return true +end + +-- 요리 창에서 다 만들었을 때. 고른 메뉴와 같고, 조리 과정을 실제로 할 만큼의 시간(Recipes.minTime)이 +-- 지났을 때만 접시를 만듭니다. 원격 이벤트만 보내 조리 과정을 건너뛰는 것을 막습니다. +function PlotController.finishCook(self: PlotController, menu: string, now: number): string? + local session = self.cookSession + self.cookSession = nil + if not session or session.menu ~= menu then + return nil + end + if now - session.start < Recipes.minTime(menu, self.shop.stats.cook) * COOK_SLACK then + return nil + end + self.shop.now = now + return self:cook(menu) +end + function PlotController.pickup(self: PlotController): number local n = Shop.pickup(self.shop) for _ = 1, n do diff --git a/bunsik-tycoon/src/shared/Recipes.luau b/bunsik-tycoon/src/shared/Recipes.luau index a97fe22..2e5346c 100644 --- a/bunsik-tycoon/src/shared/Recipes.luau +++ b/bunsik-tycoon/src/shared/Recipes.luau @@ -100,6 +100,27 @@ function Recipes.expectedTime(menu: string, cook: number): number return t end +-- 서버 검사용: 아주 빠른 사람이 쉬지 않고 했을 때의 최소 시간(초). 꾹 누르기는 정해진 시간을 다 채워야 하고, +-- 톡톡·문지르기는 한 번에 MIN_TAP·MIN_RUB초로 봅니다. 메뉴 고르기·완성 연출은 빼서 정상 플레이는 늘 이보다 깁니다. +Recipes.MIN_TAP = 0.08 +Recipes.MIN_RUB = 0.08 + +function Recipes.minTime(menu: string, cook: number): number + local r = Recipes.LIST[menu] + local t = 0 + for _, s in r.steps do + local n = Recipes.need(s, cook) + if s.kind == "tap" then + t += n * Recipes.MIN_TAP + elseif s.kind == "rub" then + t += n * Recipes.MIN_RUB + else + t += n + end + end + return t +end + -- 요리 화면 한 번의 진행 상태 export type Phase = "menu" | "cook" | "done" export type Flow = { diff --git a/bunsik-tycoon/tests/Recipes.spec.luau b/bunsik-tycoon/tests/Recipes.spec.luau index 1ffa0ad..3beabe8 100644 --- a/bunsik-tycoon/tests/Recipes.spec.luau +++ b/bunsik-tycoon/tests/Recipes.spec.luau @@ -23,6 +23,15 @@ for _, menu in Economy.MENU_ORDER do local t2 = Recipes.expectedTime(menu, 1) T.check(t0 >= 3 and t0 <= 7, `{menu} 처음 {t0}초`) T.check(t2 < t0 * 0.75, `{menu} 화구 Lv2면 {t2}초로 빨라짐`) + -- 서버 최소 시간: 정상 플레이(아이 속도)보다 넉넉히 짧고, 0보다는 커서 조리 과정 건너뛰기를 막음 + for _, cook in { 2.5, 1.5, 1 } do + local m = Recipes.minTime(menu, cook) + T.check(m > 0.3, `{menu} 화구 {cook}: 최소 시간 {m}초 > 0.3`) + T.check( + m < Recipes.expectedTime(menu, cook) * 0.6, + `{menu} 화구 {cook}: 최소 시간이 보통 시간보다 넉넉히 짧음` + ) + end end -- 서로 다른 메뉴는 과정이 다름 diff --git a/bunsik-tycoon/tests/cloud/integration.luau b/bunsik-tycoon/tests/cloud/integration.luau index c35e987..719511b 100644 --- a/bunsik-tycoon/tests/cloud/integration.luau +++ b/bunsik-tycoon/tests/cloud/integration.luau @@ -114,7 +114,19 @@ c:update(3) eq(c.shop.customers[1].state, "waiting", "손님이 앉음") eq(owner:GetAttribute("Orders"), "Tteokbokki=1", "요리 창에 보여 줄 주문 수") eq(c:cook("Gimbap"), nil, "주문 없는 메뉴(김밥)는 못 만듦") -eq(c:cook("Tteokbokki"), "Tteokbokki", "고른 메뉴로 조리") +-- 요리 창 세션: 원격 이벤트만 보내 조리 과정을 건너뛰지 못함 +eq(c:finishCook("Tteokbokki", 10), nil, "메뉴를 고르지 않고 완성만 보내면 거절") +eq(c:startCook("Gimbap", 10), false, "주문 없는 메뉴로는 시작 못 함") +check(c:startCook("Tteokbokki", 10), "주문 있는 메뉴로 시작") +eq(c:finishCook("Gimbap", 20), nil, "고른 메뉴와 다른 메뉴로 완성하면 거절") +check(c:startCook("Tteokbokki", 10), "다시 시작") +local minT = Recipes.minTime("Tteokbokki", c.shop.stats.cook) +eq(c:finishCook("Tteokbokki", 10 + minT * 0.5), nil, `조리 과정 최소 시간({minT}초)보다 빠르면 거절`) +eq(c:finishCook("Tteokbokki", 10 + minT), nil, "거절된 세션은 다시 못 씀") +eq(owner:GetAttribute("Carry"), 0, "거절되면 접시 없음") +-- (가상 시계를 3초에 맞춰 끝냅니다. 뒤의 식사 시간 검사가 3초 기준) +check(c:startCook("Tteokbokki", 3 - Recipes.expectedTime("Tteokbokki", c.shop.stats.cook)), "다시 시작") +eq(c:finishCook("Tteokbokki", 3), "Tteokbokki", "정상 시간이면 조리") eq(owner:GetAttribute("Hand"), "Tteokbokki", "손에 든 접시 종류") eq(owner:GetAttribute("Orders"), "", "주문이 다 채워짐") eq(owner:GetAttribute("Tut"), 2, "튜토리얼 2단계") @@ -635,10 +647,12 @@ eq((cookPage:FindFirstChild("Instruction") :: TextLabel).Text, "돌돌 말아요 eq((cookPage:FindFirstChild("Gesture") :: TextLabel).Text, "문질문질!", "문지르기 안내") eq(kitchen.input("rub", flowK.need), "step", "다 문지름 → 3단계") check((cookPage:FindFirstChild("Roll", true) :: ImageLabel).Visible, "김밥이 말림") -eq(#ksent, 0, "완성 전에는 서버에 안 보냄") +eq(#ksent, 1, "완성 전에는 시작만 보냄") eq(kitchen.input("tap", flowK.need), "done", "썰기 끝 → 완성") -eq(ksent[1] and ksent[1][1], "cook", "서버에 cook") -eq(ksent[1] and ksent[1][2], "Gimbap", "고른 메뉴를 보냄") +eq(ksent[1] and ksent[1][1], "cookStart", "메뉴를 고르면 서버에 cookStart") +eq(ksent[1] and ksent[1][2], "Gimbap", "고른 메뉴로 시작") +eq(ksent[2] and ksent[2][1], "cook", "다 만들면 서버에 cook") +eq(ksent[2] and ksent[2][2], "Gimbap", "고른 메뉴를 보냄") local donePage = kframe:FindFirstChild("DonePage", true) :: Frame check(donePage.Visible, "완성 화면") eq((donePage:FindFirstChild("Dish") :: ImageLabel).ImageRectOffset, Icons.OFFSET.Gimbap, "완성 접시 그림") @@ -683,7 +697,9 @@ for _, m in Economy.MENU_ORDER do guard += 1 end eq(kitchen.flow().phase, "done", `{m} 완성`) + eq(ksent[#ksent][1], "cook", `{m} 완성 보냄`) eq(ksent[#ksent][2], m, `{m} 서버에 보냄`) + eq(ksent[#ksent - 1][1], "cookStart", `{m} 시작 보냄`) khud.open(nil) check(not kitchen.isOpen(), `{m} 창 닫기`) end