From 51298fcfa15b75423a631efea053bcad06b61479 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Wed, 14 Oct 2026 01:34:37 +0900 Subject: [PATCH] =?UTF-8?q?wip(bunsik):=20=EC=84=9C=EB=B2=84=20=EA=B0=9C?= =?UTF-8?q?=ED=8E=B8=20=E2=80=94=20=EA=B0=88=EB=9E=98=20=EC=97=85=EA=B7=B8?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EB=93=9C,=20=EB=B0=B0=EC=B9=98=ED=98=95=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=C2=B7=EC=9D=98=EC=9E=90=C2=B7?= =?UTF-8?q?=EC=A1=B0=EB=A6=AC=EB=8C=80,=20=EC=8B=A4=EB=82=B4=C2=B72?= =?UTF-8?q?=EC=B8=B5=20=EA=B1=B4=EB=AC=BC=EA=B3=BC=20=EB=94=94=EC=9E=90?= =?UTF-8?q?=EC=9D=B8=205=EC=A2=85,=20=EC=95=8C=EB=B0=94=EC=83=9D=20?= =?UTF-8?q?=EC=97=AD=ED=95=A0=C2=B7=EC=8B=9C=EA=B8=89,=20=ED=99=8D?= =?UTF-8?q?=EB=B3=B4=C2=B7=EC=AB=93=EC=95=84=EB=82=B4=EA=B8=B0=C2=B7?= =?UTF-8?q?=EC=86=90=EB=8B=98=20=EB=9F=AC=EC=8B=9C,=20=EA=B0=80=EA=B2=8C?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=ED=95=84=ED=84=B0=C2=B7=EB=AC=B4?= =?UTF-8?q?=EC=A7=80=EA=B0=9C,=20=EC=84=B8=EC=9D=B4=EB=B8=8C=20=EB=B2=84?= =?UTF-8?q?=EC=A0=84=202=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로블록스 서버 통합 테스트 tests/cloud/server.luau 1003개 통과(저장 버전 25). 화면 UI는 다음 커밋. Co-Authored-By: Claude Opus 5.5 --- bunsik-tycoon/NETWORK.md | 7 + bunsik-tycoon/src/server/Data.luau | 37 +- bunsik-tycoon/src/server/Game.luau | 429 ++++++- bunsik-tycoon/src/server/Neighbor.luau | 16 +- bunsik-tycoon/src/server/Npc.luau | 5 + bunsik-tycoon/src/server/PlotBuilder.luau | 1110 +++++++++++++----- bunsik-tycoon/src/server/PlotController.luau | 1025 +++++++++++++--- bunsik-tycoon/src/server/PlotLayout.luau | 52 - bunsik-tycoon/src/server/Transfers.luau | 61 + bunsik-tycoon/src/shared/Floor.luau | 19 +- bunsik-tycoon/src/shared/Products.luau | 6 + bunsik-tycoon/src/shared/Recipes.luau | 2 +- bunsik-tycoon/src/shared/Shop.luau | 14 +- bunsik-tycoon/tests/Recipes.spec.luau | 2 +- bunsik-tycoon/tests/cloud/server.luau | 512 ++++++++ 15 files changed, 2701 insertions(+), 596 deletions(-) delete mode 100644 bunsik-tycoon/src/server/PlotLayout.luau create mode 100644 bunsik-tycoon/src/server/Transfers.luau create mode 100644 bunsik-tycoon/tests/cloud/server.luau diff --git a/bunsik-tycoon/NETWORK.md b/bunsik-tycoon/NETWORK.md index 1ad1cb2..25cda6f 100644 --- a/bunsik-tycoon/NETWORK.md +++ b/bunsik-tycoon/NETWORK.md @@ -48,6 +48,13 @@ | Rainbow | 무지개 이름(게임패스 + 켜짐) | | Design | 건물 디자인 | | ShieldUntil | 손님 쫓아내기 보호가 끝나는 서버 시각 | +| Origin | 부지 기준 CFrame. 배치 좌표 (x, z, 층 f) → 월드: `Origin * CFrame.new(x, Floor.BASE_Y + (f == 2 and Floor.FLOOR2_Y or 0), z)` | + +## 배치 물건 모델 + +부지 안 `Upgrades/Furniture` 폴더에 서버가 짓습니다. 꾸미기 화면이 눌러서 고를 수 있게 모델마다 속성을 붙입니다. +- `ItemKind` = "table" | "chair" | "decor" | "stove", `ItemIndex` = Layout 목록 번호(조리대는 1) +- 조리대(포장마차 수레)는 `Plot.Base.Stall` 모델 그대로 옮깁니다(인스턴스가 바뀌지 않아서 조리대 버튼이 계속 붙어 있음). ## 요청 (Action kind, arg) diff --git a/bunsik-tycoon/src/server/Data.luau b/bunsik-tycoon/src/server/Data.luau index 58f027a..9d9df15 100644 --- a/bunsik-tycoon/src/server/Data.luau +++ b/bunsik-tycoon/src/server/Data.luau @@ -6,12 +6,22 @@ local RunService = game:GetService("RunService") local ServerScriptService = game:GetService("ServerScriptService") local ProfileStore = require(ServerScriptService.Vendor.ProfileStore) +local Economy = require(game:GetService("ReplicatedStorage").Shared.Economy) +local Floor = require(game:GetService("ReplicatedStorage").Shared.Floor) local Data = {} Data.TEMPLATE = { Money = 0, - Bought = 0, + Bought = 0, -- 예전(버전 1) 한 줄 업그레이드 수. 버전 2로 옮긴 뒤에는 쓰지 않음 + Levels = {} :: { [string]: number }, -- 업그레이드 갈래 레벨(Economy.TRACKS) + Layout = {} :: any, -- 배치(Floor.Layout). 빈 표면 기본 배치 + Staff = {} :: { [string]: number }, -- 고용한 알바 수 + ShopName = "", -- 가게 이름 원문("" = 기본 이름) + Rainbow = true, -- 무지개 이름 켜기(게임패스가 있을 때만 보임) + Design = "Basic", + RushLeft = 0, -- 손님 러시 남은 초 + KickCredits = 0, -- 산 "손님 쫓아내기" 남은 횟수 PurchaseIdCache = {} :: { string }, TutorialDone = false, Lang = "", -- "" = 계정 언어 자동 @@ -19,7 +29,7 @@ Data.TEMPLATE = { Sfx = true, -- 효과음 Served = 0, Earned = 0, - Version = 1, + Version = 2, } export type SaveData = typeof(Data.TEMPLATE) @@ -48,7 +58,10 @@ function Data.load(player: Player): any return nil end profile:AddUserId(player.UserId) + -- Reconcile 전에 버전을 봐야 합니다(빠진 Version은 템플릿 값 2로 채워지므로). + local version = profile.Data.Version profile:Reconcile() + Data.migrate(profile.Data, if typeof(version) == "number" then version else 1) profile.OnSessionEnd:Connect(function() profiles[player] = nil if player.Parent == Players then @@ -65,6 +78,26 @@ function Data.load(player: Player): any return profile end +-- 버전 1(한 줄 업그레이드 Bought) -> 버전 2(갈래 레벨, 배치, 알바생) +function Data.migrate(data: any, version: number) + if version >= 2 then + return + end + local levels, seats, tables, cooks = Economy.migrate(data.Bought or 0) + data.Levels = levels + data.Staff = { Cook = cooks } + local stage = Economy.stats(levels, seats).stage + local layout = Floor.default() + for _ = 2, tables do + Floor.addTable(layout, stage) + end + for _ = #layout.chairs + 1, seats do + Floor.addChair(layout, stage) + end + data.Layout = layout + data.Version = 2 +end + function Data.get(player: Player): any return profiles[player] end diff --git a/bunsik-tycoon/src/server/Game.luau b/bunsik-tycoon/src/server/Game.luau index 143e843..bfbc347 100644 --- a/bunsik-tycoon/src/server/Game.luau +++ b/bunsik-tycoon/src/server/Game.luau @@ -1,13 +1,16 @@ --!strict -- 서버 시작: 맵, 플레이어 입장·퇴장, 부지 배정, 이웃 가게, 손님 방문, 설정, 리모트, 결제를 연결합니다. +local AdService = game:GetService("AdService") local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") +local TextService = game:GetService("TextService") local Shared = ReplicatedStorage.Shared local Economy = require(Shared.Economy) +local Floor = require(Shared.Floor) local Locale = require(Shared.Locale) local Products = require(Shared.Products) @@ -16,8 +19,8 @@ local Neighbor = require(script.Parent.Neighbor) local Npc = require(script.Parent.Npc) local PlotBuilder = require(script.Parent.PlotBuilder) local PlotController = require(script.Parent.PlotController) -local PlotLayout = require(script.Parent.PlotLayout) local Receipts = require(script.Parent.Receipts) +local Transfers = require(script.Parent.Transfers) local World = require(script.Parent.World) local Game = {} @@ -29,9 +32,12 @@ local actionTimes: { [Player]: { number } } = {} local neighbors: { [number]: Neighbor.Neighbor } = {} -- 플레이어가 없는 부지의 이웃 가게 local guestAt: { [Player]: PlotController.PlotController } = {} -- 손님으로 앉아 있는 가게 local bonusAt: { [Player]: number } = {} -- 다음 시식 보너스를 받을 수 있는 시각 +local kickTarget: { [Player]: { index: number, expires: number } } = {} -- 결제 창을 띄운 쫓아내기 대상 +local adBusy: { [Player]: boolean } = {} local COOK_RANGE = 20 -- 요리 화면에서 만든 접시는 조리대에서 이만큼 안에 있어야 받습니다 -local VISIT_RANGE = 16 -- 입구에서 이만큼 안에 있어야 손님으로 들어갈 수 있습니다 +local VISIT_RANGE = 16 -- 입구에서 이만큼 안에 있어야 손님으로 들어가거나 쫓아낼 수 있습니다 +local KICK_TARGET_TTL = 120 -- 결제 창을 띄운 뒤 이 시간 안에 결제되면 그 부지에 씁니다 local Remotes = ReplicatedStorage:WaitForChild("Remotes") local ActionRemote = Remotes:WaitForChild("Action") :: RemoteEvent @@ -56,6 +62,17 @@ local function controllerAt(index: number): PlotController.PlotController? return n and n.controller end +local function allControllers(): { PlotController.PlotController } + local out = {} + for _, s in slots do + local c = controllerAt(s.index) + if c then + table.insert(out, c) + end + end + return out +end + local function notifyPlayer(player: Player, key: string, args: { [string]: any }?) NotifyRemote:FireClient(player, key, args) end @@ -106,7 +123,8 @@ local function applySettings(player: Player, data: any) player:SetAttribute("Sfx", data.Sfx ~= false) end -local function placeCharacter(player: Player, slot: World.Slot) +-- 조리대 앞에 세웁니다. +local function placeCharacter(player: Player, controller: PlotController.PlotController) local char = player.Character if not char then return @@ -115,21 +133,86 @@ local function placeCharacter(player: Player, slot: World.Slot) if not root then return end - local pos = PlotBuilder.world(slot.cf, PlotLayout.PLAYER_SPAWN) + Vector3.new(0, 4, 0) - local look = PlotBuilder.world(slot.cf, PlotLayout.STOVE) + local refs = controller.slot.refs + local pos = PlotBuilder.stallPoint(refs, { x = Floor.STOVE_FRONT.x, z = Floor.STOVE_FRONT.z + 4 }) + + Vector3.new(0, 4, 0) + local look = PlotBuilder.stallPoint(refs, Floor.STOVE_COOK) char:PivotTo(CFrame.lookAt(pos, Vector3.new(look.X, pos.Y, look.Z))) end -local function checkPass(player: Player, controller: PlotController.PlotController) - if Products.DOUBLE_MONEY_PASS == 0 then - return +local function ownsPass(player: Player, passId: number): boolean + if passId == 0 then + return false end local ok, owns = pcall(function() - return MarketplaceService:UserOwnsGamePassAsync(player.UserId, Products.DOUBLE_MONEY_PASS) + return MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId) end) - if ok and owns then + return ok and owns == true +end + +-- 게임패스: 2배 수익, 무지개 이름, 유료 디자인 +local function checkPasses(player: Player, controller: PlotController.PlotController) + if ownsPass(player, Products.DOUBLE_MONEY_PASS) then controller:setDouble(true) end + if ownsPass(player, Products.RAINBOW_NAME_PASS) then + controller:setRainbowOwned(true) + end + for _, d in Economy.DESIGNS do + if d.pass and ownsPass(player, (Products :: any)[d.pass] or 0) then + controller:setDesignOwned(d.id, true) + end + end +end + +-- 가게 이름을 필터에 거쳐 모두에게 보이게 합니다. 필터가 실패하면 기본 이름을 씁니다. +local function filterName(player: Player, raw: string): string? + if raw == "" then + return "" + end + local ok, shown = pcall(function() + local result = TextService:FilterStringAsync(raw, player.UserId, Enum.TextFilterContext.PublicChat) + return result:GetNonChatStringForBroadcastAsync() + end) + if not ok or typeof(shown) ~= "string" then + return nil + end + return shown +end + +-- 이름 정리: 앞뒤 공백·줄바꿈 제거, 글자 수(UTF-8 글자 기준) 자르기 +local function cleanName(raw: any): string? + if typeof(raw) ~= "string" then + return nil + end + local s = string.gsub(raw, "[%c]", " ") + s = string.match(s, "^%s*(.-)%s*$") or "" + if utf8.len(s) == nil then + return nil + end + if (utf8.len(s) :: number) > Economy.NAME_MAX then + local cut = utf8.offset(s, Economy.NAME_MAX + 1) + s = string.sub(s, 1, (cut or #s + 1) - 1) + end + return s +end + +local function rename(player: Player, controller: PlotController.PlotController, raw: any) + local name = cleanName(raw) + if name == nil then + controller:notify("nameRejected") + return + end + local shown = filterName(player, name) + if shown == nil or (name ~= "" and string.match(shown, "^[#%s]*$")) then + controller:notify("nameRejected") + return + end + if controllers[player] ~= controller then + return + end + controller:setShopName(name, shown) + controller:notify("renamed") end -- 게임 주인(개발자)만 쓰는 테스트 버튼. 결제 없이 기능을 확인할 수 있게 합니다. @@ -150,6 +233,12 @@ local function makeController(player: Player, slot: World.Slot, data: any): Plot }) end +local function nearVisit(player: Player, target: PlotController.PlotController): boolean + local char = player.Character + local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart? + return root ~= nil and (root.Position - target.slot.refs.visit.Position).Magnitude <= VISIT_RANGE +end + -- 다른 가게 입구에서 "손님으로 들어가기"를 눌렀을 때 local function visit(player: Player, index: any) if typeof(index) ~= "number" then @@ -157,12 +246,8 @@ local function visit(player: Player, index: any) end local own = controllers[player] local target = controllerAt(index) - if not own or not target or target == own then - return - end local char = player.Character - local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart? - if not char or not root or (root.Position - target.slot.refs.visit.Position).Magnitude > VISIT_RANGE then + if not own or not target or target == own or not char or not nearVisit(player, target) then return end local prev = guestAt[player] @@ -178,6 +263,137 @@ local function visit(player: Player, index: any) target:notify("guestArrived", { name = player.DisplayName }) end +-- 홍보 실행(광고 보상 또는 무료). 데려온 수를 돌려줍니다. +local function doPromote(controller: PlotController.PlotController): number + local sources = {} + for _, c in allControllers() do + if c ~= controller then + table.insert(sources, c) + end + end + local got, why = Transfers.promote(controller, sources) + if got > 0 then + controller:notify("promoted", { n = got }) + else + controller:notify(if why == "full" then "promoteFull" else "promoteNone") + end + return got +end + +local function promote(player: Player, controller: PlotController.PlotController, arg: any) + local now = workspace:GetServerTimeNow() + local wantAd = typeof(arg) == "table" and arg.ad == true + if wantAd then + if Products.PROMOTE_AD_PRODUCT == 0 or adBusy[player] then + controller:notify("adUnavailable") + return + end + if now < controller.promoteAdAt then + controller:notify("promoteWait", { sec = math.ceil(controller.promoteAdAt - now) }) + return + end + -- 광고를 보기 전에 데려올 손님이 있는지 먼저 봅니다(보상을 못 주는 광고를 보여 주지 않게). + local any = false + for _, c in allControllers() do + if c ~= controller then + for _, cust in c.shop.customers do + if cust.state ~= "eating" and not cust.guest then + any = true + end + end + end + end + if not any then + controller:notify("promoteNone") + return + end + adBusy[player] = true + task.spawn(function() + local ok, result = pcall(function() + local reward = AdService:CreateAdRewardFromDevProductId(Products.PROMOTE_AD_PRODUCT) + return AdService:ShowRewardedVideoAdAsync(player, reward) + end) + adBusy[player] = nil + -- 보상은 ProcessReceipt(광고 보상 채널)로 옵니다. 광고가 안 나왔으면 알립니다. + if not ok or result ~= Enum.ShowAdResult.ShowCompleted then + controller:notify("adUnavailable") + end + end) + return + end + if now < controller.promoteAt then + controller:notify("promoteWait", { sec = math.ceil(controller.promoteAt - now) }) + return + end + if doPromote(controller) > 0 then + controller.promoteAt = now + Economy.PROMOTE_COOLDOWN + controller:sync() + end +end + +-- 손님 쫓아내기 실행(산 횟수 1개 사용). 성공하면 true +local function doKick(player: Player, controller: PlotController.PlotController, index: number): boolean + local victim = controllerAt(index) + if not victim or victim == controller then + controller:notify("kickOwn") + return false + end + local now = workspace:GetServerTimeNow() + if now < victim.shieldUntil then + controller:notify("shielded") + return false + end + local kicked, got = Transfers.kick(controller, victim) + if kicked == 0 then + controller:notify("promoteNone") + return false + end + controller.data.KickCredits = math.max(0, (controller.data.KickCredits or 0) - 1) + victim.shieldUntil = now + Economy.KICK_SHIELD + victim.slot.model:SetAttribute("ShieldUntil", victim.shieldUntil) + controller:notify("kicked", { n = got }) + victim:notify("kickedBy", { name = player.DisplayName }) + controller:sync() + return true +end + +local function kick(player: Player, controller: PlotController.PlotController, index: any) + if typeof(index) ~= "number" then + return + end + local victim = controllerAt(index) + if not victim or victim == controller then + controller:notify("kickOwn") + return + end + if not nearVisit(player, victim) then + return + end + if workspace:GetServerTimeNow() < victim.shieldUntil then + controller:notify("shielded") + return + end + if (controller.data.KickCredits or 0) > 0 then + doKick(player, controller, index) + elseif Products.KICK_PRODUCT ~= 0 then + kickTarget[player] = { index = index, expires = os.clock() + KICK_TARGET_TTL } + MarketplaceService:PromptProductPurchase(player, Products.KICK_PRODUCT) + end +end + +local function resetData(data: any) + data.Money = 0 + data.Bought = 0 + data.Levels = Economy.emptyLevels() + data.Layout = Floor.default() + data.Staff = {} + data.TutorialDone = false + data.Served = 0 + data.Earned = 0 + data.RushLeft = 0 + data.Design = "Basic" +end + local function onPlayerAdded(player: Player) local profile = Data.load(player) if not profile then @@ -203,17 +419,26 @@ local function onPlayerAdded(player: Player) player.CharacterAdded:Connect(function() task.defer(function() - placeCharacter(player, slot) local current = controllers[player] if current then + placeCharacter(player, current) current:rebuildHand() end end) end) if player.Character then - task.defer(placeCharacter, player, slot) + task.defer(placeCharacter, player, controller) end - task.spawn(checkPass, player, controller) + task.spawn(checkPasses, player, controller) + task.spawn(function() + local raw = data.ShopName or "" + if raw ~= "" then + local shown = filterName(player, raw) + if shown and controllers[player] == controller then + controller:setShopName(raw, shown) + end + end + end) end local function onPlayerRemoving(player: Player) @@ -221,12 +446,15 @@ local function onPlayerRemoving(player: Player) controllers[player] = nil actionTimes[player] = nil bonusAt[player] = nil + kickTarget[player] = nil + adBusy[player] = nil local host = guestAt[player] if host then host:releaseGuestByUser(player.UserId) end guestAt[player] = nil if controller then + controller.data.RushLeft = controller.shop.rushLeft slotOwner[controller.slot.index] = nil controller:destroy() -- 빈 부지에는 다시 이웃 가게를 엽니다. @@ -250,6 +478,13 @@ local function allowAction(player: Player): boolean return true end +local function num(v: any): number? + if typeof(v) == "number" and v == v and math.abs(v) < 1e6 then + return v + end + return nil +end + local function onAction(player: Player, kind: any, arg: any) if typeof(kind) ~= "string" or not allowAction(player) then return @@ -273,14 +508,66 @@ local function onAction(player: Player, kind: any, arg: any) else controller:finishCook(menu, now) end - elseif kind == "buy" then - local ok, err = controller:buy() - if not ok and err == "money" then - local p = Economy.PURCHASES[controller.shop.bought + 1] - if p then - controller:notify("notEnough", { need = Locale.number(p.cost - controller.shop.money) }) + elseif kind == "upgrade" then + if typeof(arg) == "string" and Economy.track(arg) then + controller:upgrade(arg) + end + elseif kind == "buyOffer" then + if typeof(arg) == "string" and (arg == "Seat" or arg == "Table" or Economy.track(arg)) then + controller:buyOffer(arg) + end + elseif kind == "buySeat" then + controller:buySeat(num(arg)) + elseif kind == "buyTable" then + controller:buyTable() + elseif kind == "buyDecor" then + if typeof(arg) == "string" and Economy.decor(arg) then + controller:buyDecor(arg) + end + elseif kind == "move" then + if typeof(arg) == "table" and typeof(arg.kind) == "string" then + local i, x, z = num(arg.i), num(arg.x), num(arg.z) + if i and x and z then + controller:move({ kind = arg.kind, i = i, x = x, z = z, f = num(arg.f), r = num(arg.r) }) end end + elseif kind == "hire" or kind == "fire" then + if typeof(arg) == "string" and Economy.role(arg) then + if kind == "hire" then + controller:hire(arg) + else + controller:fire(arg) + end + end + elseif kind == "rename" then + task.spawn(rename, player, controller, arg) + elseif kind == "rainbow" then + if typeof(arg) == "boolean" then + if controller.rainbowOwned then + controller:setRainbow(arg) + elseif Products.RAINBOW_NAME_PASS ~= 0 then + MarketplaceService:PromptGamePassPurchase(player, Products.RAINBOW_NAME_PASS) + end + end + elseif kind == "design" then + if typeof(arg) == "string" then + local d = Economy.design(arg) + local ok, why = controller:setDesign(arg) + if not ok and why == "locked" and d and d.pass then + local passId = (Products :: any)[d.pass] or 0 + if passId ~= 0 then + MarketplaceService:PromptGamePassPurchase(player, passId) + end + end + end + elseif kind == "promote" then + promote(player, controller, arg) + elseif kind == "kick" then + kick(player, controller, arg) + elseif kind == "rush" then + if Products.RUSH_PRODUCT ~= 0 then + MarketplaceService:PromptProductPurchase(player, Products.RUSH_PRODUCT) + end elseif kind == "visit" then visit(player, arg) elseif kind == "lang" then @@ -303,38 +590,69 @@ local function onAction(player: Player, kind: any, arg: any) elseif kind == "dev_double" and isDev(player) then controller:setDouble(controller.shop.moneyMult == 1) elseif kind == "dev_reset" and isDev(player) then - local data = controller.data - data.Money = 0 - data.Bought = 0 - data.TutorialDone = false - data.Served = 0 - data.Earned = 0 + resetData(controller.data) local slot = controller.slot + local passes = { rainbow = controller.rainbowOwned, designs = controller.designsOwned } controller:destroy() - local fresh = makeController(player, slot, data) + local fresh = makeController(player, slot, controller.data) + fresh.rainbowOwned = passes.rainbow + fresh.designsOwned = passes.designs controllers[player] = fresh - placeCharacter(player, slot) + placeCharacter(player, fresh) + fresh:sync() fresh:notify("devResetDone") elseif kind == "boost" then - if Products.MONEY_BOOST_PRODUCT ~= 0 and Economy.PURCHASES[controller.shop.bought + 1] then + if Products.MONEY_BOOST_PRODUCT ~= 0 then MarketplaceService:PromptProductPurchase(player, Products.MONEY_BOOST_PRODUCT) end end end --- 개발자 상품 지급(결제 1회 = 지급 1회) +-- 개발자 상품 지급(결제 1회 = 지급 1회). 광고 보상도 여기로 옵니다. function Game.processReceipt(info: { [string]: any }): Enum.ProductPurchaseDecision local player = Players:GetPlayerByUserId(info.PlayerId) local profile = player and Data.get(player) local controller = player and controllers[player] local decision = Receipts.process(profile, tostring(info.PurchaseId), function() - if info.ProductId ~= Products.MONEY_BOOST_PRODUCT or not controller then + if not controller or not player then return false end - local amount = Economy.boostAmount(controller.shop.stats) - controller:addMoney(amount) - controller:notify("boostGot", { amount = Locale.number(amount) }) - return true + local id = info.ProductId + if id == Products.MONEY_BOOST_PRODUCT then + local amount = Economy.boostAmount(controller.shop.stats) + controller:addMoney(amount) + controller:notify("boostGot", { amount = Locale.number(amount) }) + return true + elseif id == Products.RUSH_PRODUCT and id ~= 0 then + controller:addRush(Economy.RUSH_SECONDS) + controller:notify("rushOn", { min = math.floor(Economy.RUSH_SECONDS / 60) }) + return true + elseif id == Products.KICK_PRODUCT and id ~= 0 then + -- 횟수를 먼저 주고, 결제 창을 띄운 대상이 있으면 바로 씁니다. + controller.data.KickCredits = (controller.data.KickCredits or 0) + 1 + local t = kickTarget[player] + kickTarget[player] = nil + if t and os.clock() <= t.expires then + local target = player + task.defer(function() + local c = controllers[target] + if c then + doKick(target, c, t.index) + end + end) + end + controller:sync() + return true + elseif id == Products.PROMOTE_AD_PRODUCT and id ~= 0 then + -- 광고 보상: 데려올 손님이 없으면 짧은 손님 러시로 대신 줍니다. + if doPromote(controller) == 0 then + controller:addRush(60) + end + controller.promoteAdAt = workspace:GetServerTimeNow() + Economy.PROMOTE_AD_COOLDOWN + controller:sync() + return true + end + return false end) if decision == "Granted" then return Enum.ProductPurchaseDecision.PurchaseGranted @@ -342,6 +660,26 @@ function Game.processReceipt(info: { [string]: any }): Enum.ProductPurchaseDecis return Enum.ProductPurchaseDecision.NotProcessedYet end +local function onPassBought(player: Player, passId: number, purchased: boolean) + local controller = controllers[player] + if not purchased or not controller or passId == 0 then + return + end + if passId == Products.DOUBLE_MONEY_PASS then + controller:setDouble(true) + elseif passId == Products.RAINBOW_NAME_PASS then + controller:setRainbowOwned(true) + controller:setRainbow(true) + else + for _, d in Economy.DESIGNS do + if d.pass and (Products :: any)[d.pass] == passId then + controller:setDesignOwned(d.id, true) + controller:setDesign(d.id) + end + end + end +end + function Game.start() slots = World.build() task.spawn(Npc.preload) @@ -357,12 +695,7 @@ function Game.start() ActionRemote.OnServerEvent:Connect(onAction) MarketplaceService.ProcessReceipt = Game.processReceipt - MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, purchased) - local controller = controllers[player] - if purchased and passId == Products.DOUBLE_MONEY_PASS and controller then - controller:setDouble(true) - end - end) + MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPassBought) local acc = 0 RunService.Heartbeat:Connect(function(dt) @@ -379,7 +712,11 @@ function Game.start() Neighbor.update(n, now) end end) - print(`[Bunsik] server ready, {#Economy.PURCHASES} purchases, {#slots} plots`) + print(`[Bunsik] server ready, {#Economy.TRACKS} upgrade tracks, {#slots} plots`) end +-- 테스트용: 홍보·쫓아내기 실행을 바로 부릅니다(원격 테스트에서 가짜 플레이어로). +Game._doPromote = doPromote +Game._cleanName = cleanName + return Game diff --git a/bunsik-tycoon/src/server/Neighbor.luau b/bunsik-tycoon/src/server/Neighbor.luau index daa8e9c..c6f5d92 100644 --- a/bunsik-tycoon/src/server/Neighbor.luau +++ b/bunsik-tycoon/src/server/Neighbor.luau @@ -7,16 +7,17 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage") local Shop = require(ReplicatedStorage.Shared.Shop) +local Data = require(script.Parent.Data) local Npc = require(script.Parent.Npc) local PlotBuilder = require(script.Parent.PlotBuilder) local PlotController = require(script.Parent.PlotController) -local PlotLayout = require(script.Parent.PlotLayout) local Neighbor = {} -- 부지 번호별 이웃 가게 크기(산 업그레이드 수). 처음 온 플레이어보다 큰 가게가 많아서 "나도 저렇게 키우고 싶다"를 노립니다. Neighbor.LEVELS = { 14, 7, 20, 10, 17, 4 } Neighbor.SERVE_GAP = 1 -- 사장님이 접시를 내려놓는 간격(초) +Neighbor.DESIGNS = { "Mint", "Basic", "Brick", "Basic", "Mint", "Basic" } -- 무료 디자인만 export type Neighbor = { controller: PlotController.PlotController, @@ -28,13 +29,16 @@ export type Slot = PlotController.Slot function Neighbor.open(slot: Slot, now: number, guestEvent: PlotController.GuestEvent?): Neighbor local owner = Instance.new("Folder") owner.Name = "Neighbor" .. slot.index - local data = { - Money = 0, + -- 예전 한 줄 업그레이드 수로 크기를 정하고 새 구조(갈래·배치·알바)로 옮깁니다. + local data: any = { + Money = 1e12, -- 시급을 못 내서 쉬는 일이 없게 Bought = Neighbor.LEVELS[slot.index] or 10, TutorialDone = true, Served = 0, Earned = 0, + Design = Neighbor.DESIGNS[slot.index] or "Basic", } + Data.migrate(data, 1) local controller = PlotController.new(slot, owner, { userId = -slot.index, displayName = "", @@ -44,8 +48,8 @@ function Neighbor.open(slot: Slot, now: number, guestEvent: PlotController.Guest guestEvent = guestEvent, }) -- 포장마차 뒤에 서 있는 사장님 - local pos = PlotBuilder.world(slot.cf, PlotLayout.HELPER + Vector3.new(6, 0, 0)) - local look = PlotBuilder.world(slot.cf, PlotLayout.PLAYER_SPAWN) + local pos = PlotBuilder.stallPoint(slot.refs, { x = 3, z = -4 }) + local look = PlotBuilder.stallPoint(slot.refs, { x = 3, z = 10 }) local keeper = Npc.spawn(slot.refs.dynamic, CFrame.new(pos), controller.rng, Color3.fromRGB(240, 110, 40)) keeper.model.Name = "Keeper" keeper.root.CFrame = Npc.standCFrame(keeper, pos, look) @@ -60,7 +64,7 @@ function Neighbor.update(n: Neighbor, now: number) return end local shop = c.shop - if shop.stats.helper then + if (shop.staff.Cook or 0) > 0 then c:pickup() elseif not Shop.handFull(shop) and Shop.nextCookMenu(shop) then c:cook() diff --git a/bunsik-tycoon/src/server/Npc.luau b/bunsik-tycoon/src/server/Npc.luau index 8924630..b2b6d31 100644 --- a/bunsik-tycoon/src/server/Npc.luau +++ b/bunsik-tycoon/src/server/Npc.luau @@ -174,6 +174,11 @@ function Npc.spawn(parent: Instance, cf: CFrame, rng: Random, shirt: Color3?): H return h end +-- 손님 NPC(외형을 여러 가지로). 지금은 색만 바꾼 기본 아바타. +function Npc.spawnCustomer(parent: Instance, cf: CFrame, rng: Random): Handle + return Npc.spawn(parent, cf, rng) +end + function Npc.play(h: Handle, name: string) for n, t in h.tracks do if n ~= name and t.IsPlaying then diff --git a/bunsik-tycoon/src/server/PlotBuilder.luau b/bunsik-tycoon/src/server/PlotBuilder.luau index 3340213..b966c10 100644 --- a/bunsik-tycoon/src/server/PlotBuilder.luau +++ b/bunsik-tycoon/src/server/PlotBuilder.luau @@ -1,21 +1,31 @@ --!strict --- 부지 모형: 기본(바닥·포장마차·조리대)과 업그레이드(테이블·간판·화구·실내 확장 등)를 파트로 짓습니다. +-- 부지 모형을 파트로 짓습니다. +-- 기본(부지마다 한 번): 바닥·울타리·입구 이름판, 포장마차 수레(Stall, 조리대 배치에 따라 통째로 옮김) +-- 건물(단계·디자인이 바뀔 때): 2단계 실내 분식집(벽·천장·지붕), 3단계 2층(바닥·계단·벽·지붕) +-- 배치 물건(배치가 바뀔 때): 테이블·의자·소품(Floor.Layout) +-- 수레 장식(업그레이드가 바뀔 때): 화구 불, 양념 통, 쟁반, 간판, 새 메뉴 진열대 + +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Economy = require(ReplicatedStorage.Shared.Economy) +local Floor = require(ReplicatedStorage.Shared.Floor) local Build = require(script.Parent.Build) local Food = require(script.Parent.Food) -local PlotLayout = require(script.Parent.PlotLayout) -local Economy = require(game:GetService("ReplicatedStorage").Shared.Economy) local PlotBuilder = {} --- 이름판·메뉴판 글자는 보는 사람 언어에 맞춰 클라이언트(PlotSigns)가 씁니다. 서버는 부지 모델 속성만 바꿉니다. +-- 이름판·메뉴판 글자는 보는 사람 언어에 맞춰 클라이언트(Plots)가 씁니다. 서버는 부지 모델 속성만 바꿉니다. export type BaseRefs = { + stall: Model, stove: BasePart, counter: BasePart, nameBoard: BasePart, menuBoard: BasePart, visit: BasePart, -- "손님으로 들어가기" 버튼이 붙는 입구 지점 upgrades: Model, + building: Model, + furniture: Folder, dynamic: Folder, } @@ -23,10 +33,139 @@ local function rgb(r: number, g: number, b: number): Color3 return Color3.fromRGB(r, g, b) end -local Y = PlotLayout.FLOOR_Y +local Y = Floor.BASE_Y +PlotBuilder.STALL_HOME = CFrame.new(0, 0, -26) -- 수레 기본 자리(부지 기준) + +-- 디자인별 색. 유료 디자인(Candy, Hanok)은 장식이 더 붙습니다(buildDesignExtras). +export type Palette = { + wall: Color3, + wallMat: Enum.Material, + trim: Color3, + floor: Color3, + floorMat: Enum.Material, + floor2: Color3?, -- 체크무늬 바닥 둘째 색 + roof: Color3, + roofMat: Enum.Material, + awning: Color3, + awning2: Color3?, -- 줄무늬 차양 둘째 색 + sign: Color3, + signText: Color3, + glass: Color3, + beam: Color3, + lamp: Color3, +} + +PlotBuilder.PALETTES = { + Basic = { + wall = rgb(250, 236, 205), + wallMat = Enum.Material.SmoothPlastic, + trim = rgb(190, 75, 55), + floor = rgb(235, 225, 205), + floorMat = Enum.Material.Marble, + roof = rgb(150, 70, 55), + roofMat = Enum.Material.Slate, + awning = rgb(240, 110, 40), + sign = rgb(200, 40, 30), + signText = rgb(255, 240, 200), + glass = rgb(170, 220, 255), + beam = rgb(140, 95, 60), + lamp = rgb(255, 225, 150), + }, + Mint = { + wall = rgb(214, 245, 234), + wallMat = Enum.Material.SmoothPlastic, + trim = rgb(60, 170, 140), + floor = rgb(232, 214, 186), + floorMat = Enum.Material.WoodPlanks, + roof = rgb(70, 150, 130), + roofMat = Enum.Material.Slate, + awning = rgb(120, 210, 190), + awning2 = rgb(255, 255, 255), + sign = rgb(40, 140, 120), + signText = rgb(255, 255, 240), + glass = rgb(190, 240, 255), + beam = rgb(200, 170, 130), + lamp = rgb(255, 245, 210), + }, + Brick = { + wall = rgb(178, 92, 70), + wallMat = Enum.Material.Brick, + trim = rgb(85, 58, 48), + floor = rgb(205, 195, 182), + floorMat = Enum.Material.Slate, + roof = rgb(70, 62, 62), + roofMat = Enum.Material.Slate, + awning = rgb(215, 55, 50), + awning2 = rgb(255, 245, 230), + sign = rgb(45, 40, 40), + signText = rgb(255, 210, 90), + glass = rgb(200, 225, 240), + beam = rgb(90, 60, 45), + lamp = rgb(255, 210, 130), + }, + Candy = { + wall = rgb(255, 205, 228), + wallMat = Enum.Material.SmoothPlastic, + trim = rgb(255, 110, 165), + floor = rgb(255, 240, 248), + floorMat = Enum.Material.SmoothPlastic, + floor2 = rgb(255, 180, 210), + roof = rgb(196, 160, 255), + roofMat = Enum.Material.SmoothPlastic, + awning = rgb(255, 120, 170), + awning2 = rgb(255, 255, 255), + sign = rgb(255, 94, 132), + signText = rgb(255, 255, 255), + glass = rgb(220, 200, 255), + beam = rgb(255, 170, 205), + lamp = rgb(255, 200, 240), + }, + Hanok = { + wall = rgb(246, 236, 214), + wallMat = Enum.Material.Plaster, + trim = rgb(92, 60, 40), + floor = rgb(190, 148, 100), + floorMat = Enum.Material.WoodPlanks, + roof = rgb(58, 64, 76), + roofMat = Enum.Material.Slate, + awning = rgb(150, 40, 35), + sign = rgb(110, 72, 45), + signText = rgb(255, 215, 110), + glass = rgb(250, 240, 215), + beam = rgb(92, 60, 40), + lamp = rgb(255, 120, 80), + }, +} :: { [string]: Palette } + +function PlotBuilder.palette(design: string?): Palette + return PlotBuilder.PALETTES[design or "Basic"] or PlotBuilder.PALETTES.Basic +end + +-- 부지 좌표(x, z, 층) -> 월드 CFrame(바닥 높이) +function PlotBuilder.floorCFrame(cf: CFrame, x: number, z: number, f: number?): CFrame + local y = Y + (if f == 2 then Floor.FLOOR2_Y else 0) + return cf * CFrame.new(x, y, z) +end + +function PlotBuilder.world(cf: CFrame, p: { x: number, z: number, f: number? }): Vector3 + return PlotBuilder.floorCFrame(cf, p.x, p.z, p.f).Position +end + +-- 조리대(수레) 기준 CFrame(바닥 높이 0 = 부지 원점 높이) +function PlotBuilder.stallCFrame(cf: CFrame, stove: Floor.Stove): CFrame + return cf * CFrame.new(stove.x, 0, stove.z) * CFrame.Angles(0, stove.r * math.pi / 2, 0) +end + +-- 이름 글자를 붙입니다. 클라이언트가 ShopNameLabel 이름으로 찾아 가게 이름·무지개를 씁니다. +local function nameLabel(part: BasePart, face: Enum.NormalId, color: Color3): TextLabel + local label = Build.label(part, face, "", color) + label.Name = "ShopNameLabel" + return label +end -- 바닥과 포장마차. 부지마다 한 번만 짓습니다. function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs + plot:SetAttribute("Origin", cf) local base = Build.model(plot, "Base") local function at(x: number, y: number, z: number): CFrame return cf * CFrame.new(x, y, z) @@ -83,44 +222,47 @@ function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs visit.CanQuery = false visit.CanTouch = false - -- 포장마차: 수레 몸통, 조리대 상판 + -- 포장마차 수레(조리대). 기본 자리에서 짓고, 배치에 따라 PivotTo로 통째로 옮깁니다. + local home = cf * PlotBuilder.STALL_HOME local stall = Build.model(base, "Stall") - local sz = PlotLayout.STALL_Z + stall:SetAttribute("ItemKind", "stove") + stall:SetAttribute("ItemIndex", 1) + local function st(x: number, y: number, z: number): CFrame + return home * CFrame.new(x, y, z) + end Build.part(stall, { size = Vector3.new(18, 3.4, 4), - cf = at(0, Y + 1.7, sz), + cf = st(0, Y + 1.7, 0), color = rgb(160, 105, 60), material = Enum.Material.Wood, }) Build.part(stall, { size = Vector3.new(18.6, 0.4, 4.6), - cf = at(0, Y + 3.6, sz), + cf = st(0, Y + 3.6, 0), color = rgb(200, 205, 210), material = Enum.Material.Metal, }) for _, x in { -7.5, 7.5 } do - Build.cylinder(stall, at(x, Y + 0.6, sz + 2), 0.5, 1.4, rgb(40, 40, 40), { collide = false }) + Build.cylinder(stall, st(x, Y + 0.6, 2), 0.5, 1.4, rgb(40, 40, 40), { collide = false }) end -- 화구(프롬프트가 붙는 곳) + local cook = Floor.STOVE_COOK local stove = Build.part(stall, { name = "Stove", size = Vector3.new(5, 0.6, 3.4), - cf = at(PlotLayout.STOVE.X, Y + 4.1, sz), + cf = st(cook.x, Y + 4.1, cook.z), color = rgb(60, 60, 65), material = Enum.Material.DiamondPlate, }) - Build.cylinder(stall, at(PlotLayout.STOVE.X, Y + 4.6, sz), 0.4, 4, rgb(30, 30, 30), { collide = false }) - Build.cylinder(stall, at(PlotLayout.STOVE.X, Y + 4.8, sz), 0.1, 3.5, rgb(205, 45, 25), { collide = false }) + Build.cylinder(stall, st(cook.x, Y + 4.6, 0), 0.4, 4, rgb(30, 30, 30), { collide = false }) + Build.cylinder(stall, st(cook.x, Y + 4.8, 0), 0.1, 3.5, rgb(205, 45, 25), { collide = false }) for i = 0, 8 do local a = i * 0.7 Build.part(stall, { size = Vector3.new(1.1, 0.35, 0.35), - cf = at( - PlotLayout.STOVE.X + math.cos(a) * (0.4 + (i % 3) * 0.45), - Y + 5, - sz + math.sin(a) * (0.4 + (i % 3) * 0.45) - ) * CFrame.Angles(0, a * 2, 0), + cf = st(cook.x + math.cos(a) * (0.4 + (i % 3) * 0.45), Y + 5, math.sin(a) * (0.4 + (i % 3) * 0.45)) + * CFrame.Angles(0, a * 2, 0), color = rgb(235, 90, 50), collide = false, }) @@ -132,58 +274,54 @@ function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs steam.Size = 1.5 steam.Parent = stove - -- 알바생이 만든 접시를 두는 카운터 + -- 요리 알바가 만든 접시를 두는 카운터 local counter = Build.part(stall, { name = "Counter", size = Vector3.new(6, 0.3, 3.4), - cf = at(PlotLayout.COUNTER.X, Y + 3.95, sz), + cf = st(Floor.STOVE_COUNTER.x, Y + 3.95, 0), color = rgb(235, 215, 175), material = Enum.Material.Wood, }) -- 천막: 기둥 4개, 주황 지붕(박공), 앞 가림막 for _, x in { -10, 10 } do - for _, z in { sz - 5, sz + 6 } do + for _, z in { -5, 6 } do Build.part(stall, { size = Vector3.new(0.5, 11, 0.5), - cf = at(x, Y + 5.5, z), + cf = st(x, Y + 5.5, z), color = rgb(170, 170, 175), material = Enum.Material.Metal, }) end end - local roofCf = at(0, Y + 11.2, sz + 0.5) + local roofCf = st(0, Y + 11.2, 0.5) Build.part(stall, { size = Vector3.new(22, 0.3, 12.6), cf = roofCf, color = rgb(240, 110, 40), material = Enum.Material.Fabric, }) - Build.part(stall, { - size = Vector3.new(22, 2.6, 6.3), - cf = roofCf * CFrame.new(0, 1.45, 3.15), - color = rgb(240, 110, 40), - material = Enum.Material.Fabric, - wedge = true, - }) - Build.part(stall, { - size = Vector3.new(22, 2.6, 6.3), - cf = roofCf * CFrame.new(0, 1.45, -3.15) * CFrame.Angles(0, math.pi, 0), - color = rgb(240, 110, 40), - material = Enum.Material.Fabric, - wedge = true, - }) + for _, side in { 1, -1 } do + Build.part(stall, { + size = Vector3.new(22, 2.6, 6.3), + cf = roofCf * CFrame.new(0, 1.45, side * 3.15) * CFrame.Angles(0, if side < 0 then math.pi else 0, 0), + color = rgb(240, 110, 40), + material = Enum.Material.Fabric, + wedge = true, + }) + end local valance = Build.part(stall, { + name = "Valance", size = Vector3.new(22, 1.8, 0.2), - cf = at(0, Y + 10.2, sz + 6.3), + cf = st(0, Y + 10.2, 6.3), color = rgb(255, 230, 90), material = Enum.Material.Fabric, }) - Build.label(valance, Enum.NormalId.Front, "떡볶이 · 김밥 · 순대 BUNSIK", rgb(200, 40, 30)) + nameLabel(valance, Enum.NormalId.Front, rgb(200, 40, 30)) -- 뒤쪽 투명 비닐 가림막 Build.part(stall, { size = Vector3.new(20, 9, 0.1), - cf = at(0, Y + 5.8, sz - 5.2), + cf = st(0, Y + 5.8, -5.2), color = rgb(255, 200, 150), transparency = 0.6, material = Enum.Material.Glass, @@ -192,7 +330,7 @@ function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs local menuBoard = Build.part(stall, { name = "MenuBoard", size = Vector3.new(9, 4.2, 0.3), - cf = at(0, Y + 7.6, sz - 4.8), + cf = st(0, Y + 7.6, -4.8), color = rgb(40, 60, 45), material = Enum.Material.Wood, }) @@ -203,7 +341,7 @@ function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs for i = -4, 4 do local bulb = Build.part(stall, { size = Vector3.new(0.6, 0.6, 0.6), - cf = at(i * 2.4, Y + 9.1, sz + 6.4), + cf = st(i * 2.4, Y + 9.1, 6.4), color = rgb(255, 210, 120), shape = Enum.PartType.Ball, neon = true, @@ -217,122 +355,108 @@ function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs light.Parent = bulb end end + stall.WorldPivot = home local upgrades = Build.model(plot, "Upgrades") + local building = Build.model(upgrades, "Building") + local furniture = Instance.new("Folder") + furniture.Name = "Furniture" + furniture.Parent = upgrades local dynamic = Instance.new("Folder") dynamic.Name = "Dynamic" dynamic.Parent = plot return { + stall = stall, stove = stove, counter = counter, nameBoard = board, menuBoard = menuBoard, visit = visit, upgrades = upgrades, + building = building, + furniture = furniture, dynamic = dynamic, } end --- 테이블 한 개와 의자 -local function buildTable(parent: Instance, cf: CFrame, seat: number) - local m = Build.model(parent, "Table" .. seat) - local t = PlotLayout.TABLES[seat] - local s = PlotLayout.stool(seat) - local tableTop = cf * CFrame.new(t.X, Y + 2.6, t.Z) - Build.cylinder(m, cf * CFrame.new(t.X, Y + 1.25, t.Z), 2.5, 0.6, rgb(160, 160, 165)) - Build.cylinder(m, cf * CFrame.new(t.X, Y + 0.1, t.Z), 0.2, 2.6, rgb(160, 160, 165)) - Build.cylinder(m, tableTop, 0.3, 5, if seat % 2 == 0 then rgb(225, 60, 50) else rgb(240, 120, 40)) - local stoolColor = if seat % 2 == 0 then rgb(60, 120, 225) else rgb(225, 60, 50) - Build.cylinder(m, cf * CFrame.new(s.X, Y + 0.9, s.Z), 1.8, 2, stoolColor) +-- 줄무늬 차양: 색 두 개를 번갈아 붙입니다. +local function awning(m: Instance, cf: CFrame, width: number, p: Palette) + local n = math.max(1, math.floor(width / 2)) + local w = width / n + for i = 0, n - 1 do + local color = if p.awning2 and i % 2 == 1 then p.awning2 else p.awning + Build.part(m, { + size = Vector3.new(w, 0.4, 4), + cf = cf * CFrame.new(-width / 2 + w * (i + 0.5), 0, 0), + color = color, + material = Enum.Material.Fabric, + }) + end end --- 실내 분식집 건물(2단계) -local function buildIndoor(parent: Instance, cf: CFrame) - local m = Build.model(parent, "Expand") +-- 한 층의 벽(앞에 문 또는 창). y0 = 그 층 바닥 높이, h = 벽 높이 +local function walls(m: Model, cf: CFrame, y0: number, h: number, p: Palette, door: boolean) local function at(x: number, y: number, z: number): CFrame return cf * CFrame.new(x, y, z) end - local wall = rgb(250, 236, 205) - local trim = rgb(190, 75, 55) - local H = 14 - Build.part(m, { - size = Vector3.new(68, 0.1, 58), - cf = at(0, Y + 0.05, -9), - color = rgb(235, 225, 205), - material = Enum.Material.Marble, - collide = false, - }) - -- 뒤, 옆 벽 - Build.part(m, { size = Vector3.new(70, H, 1), cf = at(0, Y + H / 2, -38.5), color = wall }) + local function wall(size: Vector3, c: CFrame) + Build.part(m, { size = size, cf = c, color = p.wall, material = p.wallMat }) + end + wall(Vector3.new(70, h, 1), at(0, y0 + h / 2, -38.5)) for _, side in { -1, 1 } do - Build.part(m, { size = Vector3.new(1, H, 58), cf = at(side * 34.5, Y + H / 2, -9), color = wall }) + wall(Vector3.new(1, h, 58), at(side * 34.5, y0 + h / 2, -9)) -- 옆 창문 Build.part(m, { - size = Vector3.new(1.1, 5, 30), - cf = at(side * 34.5, Y + 7, -6), - color = rgb(170, 220, 255), + size = Vector3.new(1.1, h * 0.36, 30), + cf = at(side * 34.5, y0 + h * 0.5, -6), + color = p.glass, material = Enum.Material.Glass, transparency = 0.5, }) - Build.part(m, { size = Vector3.new(1.2, 2.2, 58), cf = at(side * 34.5, Y + 1.1, -9), color = trim }) + Build.part(m, { size = Vector3.new(1.2, 2.2, 58), cf = at(side * 34.5, y0 + 1.1, -9), color = p.trim }) end - -- 앞 벽(가운데 문, 양쪽 큰 창) + -- 앞 벽(가운데 문 또는 창, 양쪽 큰 창) for _, side in { -1, 1 } do + wall(Vector3.new(29, h, 1), at(side * 20.5, y0 + h / 2, 20.5)) Build.part(m, { - size = Vector3.new(29, H, 1), - cf = at(side * 20.5, Y + H / 2, 20.5), - color = wall, - }) - Build.part(m, { - size = Vector3.new(20, 6, 1.1), - cf = at(side * 20.5, Y + 6.5, 20.5), - color = rgb(170, 220, 255), + size = Vector3.new(20, h * 0.43, 1.1), + cf = at(side * 20.5, y0 + h * 0.46, 20.5), + color = p.glass, material = Enum.Material.Glass, transparency = 0.45, }) - Build.part(m, { size = Vector3.new(29, 2.2, 1.2), cf = at(side * 20.5, Y + 1.1, 20.5), color = trim }) + Build.part(m, { size = Vector3.new(29, 2.2, 1.2), cf = at(side * 20.5, y0 + 1.1, 20.5), color = p.trim }) end - Build.part(m, { size = Vector3.new(12, 4, 1), cf = at(0, Y + H - 2, 20.5), color = wall }) - -- 문 위 차양 - Build.part(m, { - size = Vector3.new(14, 0.4, 4), - cf = at(0, Y + 10.5, 22.5) * CFrame.Angles(math.rad(-12), 0, 0), - color = rgb(240, 110, 40), - material = Enum.Material.Fabric, - }) - -- 천장과 지붕(바깥에서 보면 평지붕 + 둘레 난간) - Build.part(m, { - name = "Ceiling", - size = Vector3.new(70, 0.6, 60), - cf = at(0, Y + H + 0.3, -9), - color = rgb(255, 248, 235), - }) - Build.part(m, { - name = "Roof", - size = Vector3.new(71, 0.6, 61), - cf = at(0, Y + H + 0.9, -9), - color = rgb(150, 70, 55), - material = Enum.Material.Slate, - }) - for _, side in { -1, 1 } do - Build.part(m, { size = Vector3.new(1.2, 1.6, 61), cf = at(side * 35, Y + H + 2, -9), color = trim }) - Build.part(m, { size = Vector3.new(71, 1.6, 1.2), cf = at(0, Y + H + 2, -9 + side * 30), color = trim }) + if door then + wall(Vector3.new(12, h - 10, 1), at(0, y0 + 10 + (h - 10) / 2, 20.5)) + else + wall(Vector3.new(12, h, 1), at(0, y0 + h / 2, 20.5)) + Build.part(m, { + size = Vector3.new(8, h * 0.43, 1.1), + cf = at(0, y0 + h * 0.46, 20.5), + color = p.glass, + material = Enum.Material.Glass, + transparency = 0.45, + }) end - -- 천장 들보와 조명 +end + +-- 천장 들보와 조명(그 층 천장 높이 yTop 아래) +local function ceilingLights(m: Model, cf: CFrame, yTop: number, p: Palette) for i = 0, 4 do local z = -34 + i * 13 Build.part(m, { size = Vector3.new(68, 0.8, 0.8), - cf = at(0, Y + H - 0.4, z), - color = rgb(140, 95, 60), + cf = cf * CFrame.new(0, yTop - 0.4, z), + color = p.beam, material = Enum.Material.Wood, }) for _, x in { -18, 0, 18 } do local lamp = Build.part(m, { size = Vector3.new(1.4, 1.4, 1.4), - cf = at(x, Y + H - 1.6, z), - color = rgb(255, 225, 150), + cf = cf * CFrame.new(x, yTop - 1.6, z), + color = p.lamp, shape = Enum.PartType.Ball, neon = true, collide = false, @@ -344,172 +468,577 @@ local function buildIndoor(parent: Instance, cf: CFrame) light.Parent = lamp end end - -- 지붕 간판 +end + +-- 평지붕 + 둘레 난간 + 앞 간판(가게 이름) +local function roof(m: Model, cf: CFrame, yTop: number, p: Palette, design: string) + local function at(x: number, y: number, z: number): CFrame + return cf * CFrame.new(x, y, z) + end + Build.part(m, { + name = "Ceiling", + size = Vector3.new(70, 0.6, 60), + cf = at(0, yTop + 0.3, -9), + color = rgb(255, 248, 235), + }) + Build.part(m, { + name = "Roof", + size = Vector3.new(71, 0.6, 61), + cf = at(0, yTop + 0.9, -9), + color = p.roof, + material = p.roofMat, + }) + if design == "Hanok" then + -- 한옥 기와지붕: 가운데가 높고 처마가 밖으로 나온 경사 지붕 + for _, side in { -1, 1 } do + Build.part(m, { + size = Vector3.new(76, 7, 34), + cf = at(0, yTop + 4.7, -9 + side * 17) * CFrame.Angles(0, if side < 0 then math.pi else 0, 0), + color = p.roof, + material = p.roofMat, + wedge = true, + }) + end + Build.part(m, { + size = Vector3.new(78, 1.2, 1.6), + cf = at(0, yTop + 8.4, -9), + color = rgb(40, 44, 52), + material = p.roofMat, + }) + for _, x in { -39, 39 } do + Build.part(m, { + size = Vector3.new(2, 1.2, 1.6), + cf = at(x, yTop + 9, -9) * CFrame.Angles(0, 0, math.rad(if x < 0 then 25 else -25)), + color = rgb(40, 44, 52), + }) + end + else + for _, side in { -1, 1 } do + Build.part(m, { size = Vector3.new(1.2, 1.6, 61), cf = at(side * 35, yTop + 2, -9), color = p.trim }) + Build.part(m, { size = Vector3.new(71, 1.6, 1.2), cf = at(0, yTop + 2, -9 + side * 30), color = p.trim }) + end + end + -- 지붕 간판(가게 이름) local sign = Build.part(m, { name = "RoofSign", size = Vector3.new(30, 5, 1), - cf = at(0, Y + H + 2.5, 20.5), - color = rgb(200, 40, 30), + cf = at(0, yTop + 3.4, 21.2), + color = p.sign, }) - Build.label(sign, Enum.NormalId.Front, "분식천국 BUNSIK HEAVEN", rgb(255, 240, 200)) - -- 화분 + nameLabel(sign, Enum.NormalId.Front, p.signText) +end + +-- 바닥(디자인 색, 체크무늬 디자인은 칸마다 색을 번갈아) +local function floorTiles(m: Model, cf: CFrame, y: number, p: Palette, thick: number) + if p.floor2 then + local size = 4 + for i = 0, 16 do + for j = 0, 13 do + Build.part(m, { + size = Vector3.new(size, thick, size), + cf = cf * CFrame.new(-34 + size * (i + 0.5), y, -38 + size * (j + 0.5)), + color = if (i + j) % 2 == 0 then p.floor else p.floor2 :: Color3, + material = p.floorMat, + collide = false, + }) + end + end + else + Build.part(m, { + size = Vector3.new(68, thick, 58), + cf = cf * CFrame.new(0, y, -9), + color = p.floor, + material = p.floorMat, + collide = false, + }) + end +end + +-- 유료 디자인 장식 +local function designExtras(m: Model, cf: CFrame, stage: number, design: string, p: Palette) + local function at(x: number, y: number, z: number): CFrame + return cf * CFrame.new(x, y, z) + end + local top = if stage >= 3 then Floor.FLOOR2_Y + 12 else 14 + if design == "Candy" then + -- 입구 양쪽 큰 막대사탕, 벽의 하트, 반짝이 + for _, x in { -9, 9 } do + Build.part(m, { + size = Vector3.new(0.6, 9, 0.6), + cf = at(x, Y + 4.5, 24), + color = rgb(255, 255, 255), + }) + local candy = Build.cylinder(m, at(x, Y + 10, 24) * CFrame.Angles(math.rad(90), 0, 0), 0.8, 5, p.trim) + local sp = Instance.new("Sparkles") + sp.SparkleColor = rgb(255, 200, 240) + sp.Parent = candy + Build.cylinder(m, at(x, Y + 10, 24.1) * CFrame.Angles(math.rad(90), 0, 0), 0.85, 2.6, rgb(255, 250, 255)) + end + for _, x in { -27, -14, 14, 27 } do + for _, dx in { -0.7, 0.7 } do + Build.part(m, { + size = Vector3.new(1.8, 1.8, 0.6), + cf = at(x + dx, Y + top - 3, 21.2), + color = rgb(255, 80, 140), + shape = Enum.PartType.Ball, + collide = false, + }) + end + Build.part(m, { + size = Vector3.new(1.8, 1.8, 0.5), + cf = at(x, Y + top - 4, 21.2) * CFrame.Angles(0, 0, math.rad(45)), + color = rgb(255, 80, 140), + collide = false, + }) + end + elseif design == "Hanok" then + -- 나무 기둥·들보 격자, 빨간 등롱 + for _, x in { -34.6, -20, -6.5, 6.5, 20, 34.6 } do + Build.part(m, { + size = Vector3.new(1.4, top, 1.4), + cf = at(x, Y + top / 2, 21.2), + color = p.trim, + material = Enum.Material.Wood, + }) + end + Build.part(m, { + size = Vector3.new(71, 1.2, 1.4), + cf = at(0, Y + 10.6, 21.2), + color = p.trim, + material = Enum.Material.Wood, + }) + for _, x in { -13, 13 } do + local lantern = Build.part(m, { + size = Vector3.new(2, 2.6, 2), + cf = at(x, Y + 9, 23), + color = rgb(220, 50, 40), + shape = Enum.PartType.Ball, + neon = true, + collide = false, + }) + local light = Instance.new("PointLight") + light.Color = rgb(255, 120, 80) + light.Range = 12 + light.Parent = lantern + Build.part(m, { + size = Vector3.new(0.15, 1.6, 0.15), + cf = at(x, Y + 11, 23), + color = rgb(40, 30, 20), + collide = false, + }) + end + end +end + +-- 2층 바닥(계단 구멍 빼고), 계단, 난간 +local function secondFloor(m: Model, cf: CFrame, p: Palette) + local function at(x: number, y: number, z: number): CFrame + return cf * CFrame.new(x, y, z) + end + local yTop = Y + Floor.FLOOR2_Y + local holeX0 = Floor.STAIR_X - Floor.STAIR_HALF_W - 0.5 -- -33.5 + local holeX1 = Floor.STAIR_X + Floor.STAIR_HALF_W + 0.5 -- -27.5 + local holeZ0, holeZ1 = Floor.STAIR_TOP.z, Floor.STAIR_BOTTOM.z -- -23 ~ 9 + local function slab(x0: number, x1: number, z0: number, z1: number) + Build.part(m, { + name = "Floor2", + size = Vector3.new(x1 - x0, 0.6, z1 - z0), + cf = at((x0 + x1) / 2, yTop - 0.3, (z0 + z1) / 2), + color = p.floor, + material = p.floorMat, + }) + end + slab(holeX1, 35, -39, 21) + slab(-35, holeX1, -39, holeZ0) + slab(-35, holeX1, holeZ1, 21) + -- 1층 천장 마감(아래에서 보이는 면) + Build.part(m, { + size = Vector3.new(35 - holeX1, 0.1, 60), + cf = at((holeX1 + 35) / 2, yTop - 0.65, -9), + color = rgb(255, 248, 235), + collide = false, + }) + -- 계단: 아래(앞, z=9)에서 위(뒤, z=-23)로. 디딤판 + 경사(걷기 편하게 보이지 않는 쐐기) + local steps = 30 + local run = (holeZ1 - holeZ0) / steps + local rise = Floor.FLOOR2_Y / steps + local width = Floor.STAIR_HALF_W * 2 + for i = 1, steps do + local h = rise * i + Build.part(m, { + size = Vector3.new(width, h, run), + cf = at(Floor.STAIR_X, Y + h / 2, holeZ1 - run * (i - 0.5)), + color = if i % 2 == 0 then p.beam else p.trim, + material = Enum.Material.Wood, + }) + end + -- 난간(계단 안쪽 + 2층 구멍 둘레) + Build.part(m, { + size = Vector3.new(0.4, 3, holeZ1 - holeZ0), + cf = at(holeX1, yTop + 1.5, (holeZ0 + holeZ1) / 2), + color = p.trim, + material = Enum.Material.Wood, + }) + Build.part(m, { + size = Vector3.new(holeX1 - holeX0, 3, 0.4), + cf = at((holeX0 + holeX1) / 2, yTop + 1.5, holeZ1), + color = p.trim, + material = Enum.Material.Wood, + }) +end + +-- 건물(2단계 이상)을 단계·디자인에 맞게 다시 짓습니다. +function PlotBuilder.buildBuilding(refs: BaseRefs, cf: CFrame, stage: number, design: string) + local m = refs.building + m:ClearAllChildren() + if stage < 2 then + return + end + local p = PlotBuilder.palette(design) + local H1 = Floor.FLOOR2_Y - 0.6 -- 1층 벽 높이(2층 바닥 아래까지) + floorTiles(m, cf, Y + 0.05, p, 0.1) + walls(m, cf, Y, if stage >= 3 then Floor.FLOOR2_Y else H1, p, true) + -- 문 위 차양 + awning(m, cf * CFrame.new(0, Y + 10.5, 22.5) * CFrame.Angles(math.rad(-12), 0, 0), 14, p) + if stage >= 3 then + secondFloor(m, cf, p) + local y2 = Y + Floor.FLOOR2_Y + walls(m, cf * CFrame.new(0, y2 - Y, 0), Y, 12, p, false) + ceilingLights(m, cf, y2 - 0.6, p) + ceilingLights(m, cf, y2 + 12, p) + roof(m, cf, y2 + 12, p, design) + else + ceilingLights(m, cf, Y + H1, p) + roof(m, cf, Y + H1, p, design) + end + -- 입구 화분 for _, x in { -30, 30 } do - Build.cylinder(m, at(x, Y + 1, 16), 2, 2.4, rgb(180, 110, 70)) + Build.cylinder(m, cf * CFrame.new(x, Y + 1, 16), 2, 2.4, rgb(180, 110, 70)) Build.part(m, { size = Vector3.new(3.2, 3.2, 3.2), - cf = at(x, Y + 3.4, 16), + cf = cf * CFrame.new(x, Y + 3.4, 16), color = rgb(70, 150, 70), shape = Enum.PartType.Ball, material = Enum.Material.LeafyGrass, }) end + designExtras(m, cf, stage, design, p) end --- 메뉴 해금 업그레이드 id(모형 이름으로 써서 산 직후 반짝이게 합니다) -local function unlockId(menu: string): string - for _, p in Economy.PURCHASES do - if p.effect.menu == menu then - return p.id +local TABLE_COLORS = { rgb(225, 60, 50), rgb(240, 120, 40), rgb(80, 170, 230), rgb(120, 200, 120) } +local STOOL_COLORS = { rgb(60, 120, 225), rgb(225, 60, 50), rgb(250, 190, 50), rgb(170, 100, 220) } + +local function tagItem(m: Model, kind: string, index: number) + m:SetAttribute("ItemKind", kind) + m:SetAttribute("ItemIndex", index) +end + +local function buildDecor(parent: Instance, base: CFrame, d: Floor.Decor, index: number) + local m = Build.model(parent, "Decor" .. index) + tagItem(m, "decor", index) + local cf = base * CFrame.Angles(0, d.r * math.pi / 2, 0) + local function at(x: number, y: number, z: number): CFrame + return cf * CFrame.new(x, y, z) + end + if d.k == "Plant" then + Build.cylinder(m, at(0, 0.9, 0), 1.8, 1.8, rgb(200, 120, 80)) + Build.part(m, { + size = Vector3.new(2.6, 2.6, 2.6), + cf = at(0, 3, 0), + color = rgb(80, 165, 80), + shape = Enum.PartType.Ball, + material = Enum.Material.LeafyGrass, + }) + elseif d.k == "Rug" then + local fp = Floor.FOOTPRINT.Rug + Build.part(m, { + size = Vector3.new(fp.w, 0.08, fp.d), + cf = at(0, 0.06, 0), + color = rgb(255, 150, 180), + material = Enum.Material.Fabric, + collide = false, + }) + for i = -1, 1 do + Build.part(m, { + size = Vector3.new(fp.w - 1, 0.1, 0.6), + cf = at(0, 0.07, i * 1.6), + color = rgb(255, 230, 120), + material = Enum.Material.Fabric, + collide = false, + }) + end + elseif d.k == "Balloons" then + Build.cylinder(m, at(0, 0.3, 0), 0.6, 1.4, rgb(120, 120, 130)) + local colors = { rgb(255, 90, 120), rgb(90, 180, 255), rgb(255, 210, 60) } + for i, c in colors do + local a = i * 2.1 + local pos = at(math.cos(a) * 0.6, 6 + i * 0.4, math.sin(a) * 0.6) + Build.part(m, { + size = Vector3.new(1.6, 1.9, 1.6), + cf = pos, + color = c, + shape = Enum.PartType.Ball, + collide = false, + reflectance = 0.1, + }) + Build.part(m, { + size = Vector3.new(0.06, 5.5, 0.06), + cf = at(math.cos(a) * 0.3, 3, math.sin(a) * 0.3), + color = rgb(240, 240, 240), + collide = false, + }) + end + elseif d.k == "Lamp" then + Build.cylinder(m, at(0, 0.15, 0), 0.3, 1.6, rgb(60, 60, 65)) + Build.part(m, { size = Vector3.new(0.3, 6, 0.3), cf = at(0, 3, 0), color = rgb(60, 60, 65) }) + local shade = Build.part(m, { + size = Vector3.new(1.8, 1.8, 1.8), + cf = at(0, 6.4, 0), + color = rgb(255, 230, 160), + shape = Enum.PartType.Ball, + neon = true, + collide = false, + }) + local light = Instance.new("PointLight") + light.Color = rgb(255, 220, 160) + light.Range = 14 + light.Brightness = 0.9 + light.Parent = shade + elseif d.k == "Teddy" then + local fur = rgb(190, 130, 80) + local ball = function(size: number, x: number, y: number, z: number, c: Color3?) + Build.part(m, { + size = Vector3.new(size, size, size), + cf = at(x, y, z), + color = c or fur, + shape = Enum.PartType.Ball, + material = Enum.Material.Fabric, + }) + end + ball(2.6, 0, 1.4, 0) + ball(2, 0, 3.4, 0) + ball(0.8, -0.8, 4.3, 0) + ball(0.8, 0.8, 4.3, 0) + ball(0.8, 0, 3.2, 0.85, rgb(240, 210, 170)) + ball(0.9, -1.3, 1.6, 0.3) + ball(0.9, 1.3, 1.6, 0.3) + ball(0.25, -0.35, 3.6, 0.95, rgb(30, 20, 20)) + ball(0.25, 0.35, 3.6, 0.95, rgb(30, 20, 20)) + elseif d.k == "Fridge" then + Build.part(m, { + size = Vector3.new(3.8, 6, 1.8), + cf = at(0, 3, 0), + color = rgb(240, 245, 250), + material = Enum.Material.Metal, + }) + Build.part(m, { + size = Vector3.new(3.2, 4.6, 0.1), + cf = at(0, 3.4, 0.92), + color = rgb(200, 235, 255), + material = Enum.Material.Glass, + transparency = 0.3, + collide = false, + }) + local cans = { rgb(230, 60, 50), rgb(60, 160, 230), rgb(250, 200, 50), rgb(90, 200, 110) } + for row = 0, 2 do + for col = 0, 3 do + Build.cylinder( + m, + at(-1.2 + col * 0.8, 1.8 + row * 1.4, 0.5), + 0.9, + 0.5, + cans[(row + col) % #cans + 1], + { collide = false } + ) + end end end - return "Menu_" .. menu end --- 진열대 한 칸: 나무 받침, 메뉴별 조리 도구(뒤), 완성 접시(앞), 머리 위 메뉴 그림 -local function buildMenuStand(parent: Instance, cf: CFrame, menu: string, slot: number) - local m = Build.model(parent, unlockId(menu)) - local z = -31 + (slot - 1) * 3.6 - local x = -15.5 +-- 테이블·의자·소품을 배치대로 다시 짓습니다. +function PlotBuilder.buildFurniture(refs: BaseRefs, cf: CFrame, layout: Floor.Layout) + local folder = refs.furniture + folder:ClearAllChildren() + for i, t in layout.tables do + local m = Build.model(folder, "Table" .. i) + tagItem(m, "table", i) + local base = PlotBuilder.floorCFrame(cf, t.x, t.z, t.f) + Build.cylinder(m, base * CFrame.new(0, 1.25, 0), 2.5, 0.6, rgb(160, 160, 165)) + Build.cylinder(m, base * CFrame.new(0, 0.1, 0), 0.2, 2.6, rgb(160, 160, 165)) + Build.cylinder( + m, + base * CFrame.new(0, 2.6, 0), + 0.3, + Floor.TABLE_SIZE, + TABLE_COLORS[(i - 1) % #TABLE_COLORS + 1] + ) + end + for i in layout.chairs do + local p = Floor.chairPos(layout, i) + if p then + local m = Build.model(folder, "Chair" .. i) + tagItem(m, "chair", i) + Build.cylinder( + m, + PlotBuilder.floorCFrame(cf, p.x, p.z, p.f) * CFrame.new(0, 0.9, 0), + 1.8, + Floor.CHAIR_SIZE, + STOOL_COLORS[(i - 1) % #STOOL_COLORS + 1] + ) + end + end + for i, d in layout.decor do + buildDecor(folder, PlotBuilder.floorCFrame(cf, d.x, d.z, d.f), d, i) + end +end + +-- 수레를 배치된 자리로 옮깁니다. +function PlotBuilder.placeStall(refs: BaseRefs, cf: CFrame, stove: Floor.Stove) + refs.stall:PivotTo(PlotBuilder.stallCFrame(cf, stove)) +end + +-- 새 메뉴 진열대 한 칸: 수레 뒤쪽에 나란히. 메뉴별 조리 도구와 완성 접시, 머리 위 메뉴 그림 +local function buildMenuStand(parent: Instance, stall: CFrame, menu: string, slot: number) + local m = Build.model(parent, "Menu_" .. menu) + local x = -6 + (slot - 1) * 4 local function at(dx: number, y: number, dz: number): CFrame - return cf * CFrame.new(x + dx, Y + y, z + dz) + return stall * CFrame.new(x + dx, Y + y, -7 + dz) end local stand = Build.part(m, { name = "Stand", - size = Vector3.new(4, 3, 3.2), + size = Vector3.new(3.4, 3, 2.6), cf = at(0, 1.5, 0), color = rgb(170, 115, 70), material = Enum.Material.Wood, }) Build.part(m, { - size = Vector3.new(4.2, 0.2, 3.4), + size = Vector3.new(3.6, 0.2, 2.8), cf = at(0, 3.1, 0), color = rgb(240, 235, 225), material = Enum.Material.Marble, }) local metal = rgb(195, 195, 200) if menu == "Gimbap" then - -- 김발 위에 통김밥 한 줄 Build.part( m, - { size = Vector3.new(1.6, 0.06, 2.6), cf = at(-1, 3.23, 0), color = rgb(120, 150, 70), collide = false } + { size = Vector3.new(1.4, 0.06, 2.2), cf = at(-0.8, 3.23, 0), color = rgb(120, 150, 70), collide = false } ) Build.part(m, { - size = Vector3.new(2.2, 0.7, 0.7), - cf = at(-1, 3.6, 0) * CFrame.Angles(0, math.rad(90), 0), + size = Vector3.new(1.8, 0.6, 0.6), + cf = at(-0.8, 3.55, 0) * CFrame.Angles(0, math.rad(90), 0), color = rgb(25, 35, 25), shape = Enum.PartType.Cylinder, collide = false, }) elseif menu == "Sundae" then - -- 찜기와 뚜껑 - Build.cylinder(m, at(-1, 3.8, 0), 1.2, 1.8, metal, { material = Enum.Material.Metal, collide = false }) + Build.cylinder(m, at(-0.8, 3.8, 0), 1.2, 1.5, metal, { material = Enum.Material.Metal, collide = false }) Build.cylinder( m, - at(-1, 4.5, 0), + at(-0.8, 4.5, 0), 0.25, - 1.9, + 1.6, rgb(225, 225, 230), { material = Enum.Material.Metal, collide = false } ) - local steam = Instance.new("Smoke") - steam.Color = Color3.new(1, 1, 1) - steam.Opacity = 0.06 - steam.RiseVelocity = 2 - steam.Size = 1 - steam.Parent = stand elseif menu == "Eomuk" then - -- 국물 통과 꼬치 Build.part(m, { - size = Vector3.new(1.6, 0.9, 2.6), - cf = at(-1, 3.65, 0), + size = Vector3.new(1.4, 0.9, 2.2), + cf = at(-0.8, 3.65, 0), color = metal, material = Enum.Material.Metal, collide = false, }) - Build.part( - m, - { size = Vector3.new(1.4, 0.05, 2.4), cf = at(-1, 4.1, 0), color = rgb(190, 140, 80), collide = false } - ) for k = -1, 1 do Build.part(m, { size = Vector3.new(0.08, 1.6, 0.08), - cf = at(-1, 4.6, k * 0.7) * CFrame.Angles(0, 0, math.rad(15)), + cf = at(-0.8, 4.6, k * 0.6) * CFrame.Angles(0, 0, math.rad(15)), color = rgb(190, 150, 100), collide = false, }) - Build.part(m, { - size = Vector3.new(0.12, 0.5, 0.4), - cf = at(-1, 4.3, k * 0.7), - color = rgb(225, 185, 120), - collide = false, - }) end elseif menu == "Twigim" then - -- 튀김기(기름)와 튀김 바구니 손잡이 Build.part(m, { - size = Vector3.new(1.6, 1, 2.6), - cf = at(-1, 3.7, 0), + size = Vector3.new(1.4, 1, 2.2), + cf = at(-0.8, 3.7, 0), color = metal, material = Enum.Material.Metal, collide = false, }) Build.part( m, - { size = Vector3.new(1.4, 0.05, 2.4), cf = at(-1, 4.2, 0), color = rgb(230, 180, 60), collide = false } - ) - Build.part( - m, - { size = Vector3.new(1.2, 0.12, 0.12), cf = at(-0.2, 4.5, 0), color = rgb(40, 40, 40), collide = false } + { size = Vector3.new(1.2, 0.05, 2), cf = at(-0.8, 4.2, 0), color = rgb(230, 180, 60), collide = false } ) end - local dish = Food.dish(menu, at(0.9, 3.2, 0), m) + local dish = Food.dish(menu, at(0.8, 3.2, 0), m) dish.Name = "Display" - local icon = Build.orderBubble(stand, menu, 56, Vector3.new(0, 4.6, 0)) + local icon = Build.orderBubble(stand, menu, 48, Vector3.new(0, 4.4, 0)) icon.Name = "MenuIcon" icon.MaxDistance = 70 end --- 산 업그레이드에 맞게 Upgrades 모형을 다시 짓습니다. -function PlotBuilder.buildUpgrades(refs: BaseRefs, cf: CFrame, bought: number) - local up = refs.upgrades - up:ClearAllChildren() - local stats = Economy.statsAt(bought) - local function has(id: string): boolean - for i = 1, bought do - if Economy.PURCHASES[i].id == id then - return true - end - end - return false +-- 수레에 붙는 업그레이드 장식(화구 불, 양념 통, 쟁반, 간판, 새 메뉴 진열대)을 다시 짓습니다. +function PlotBuilder.buildStallExtras(refs: BaseRefs, levels: Economy.Levels, stats: Economy.Stats) + local stall = refs.stall + local old = stall:FindFirstChild("Extras") + if old then + old:Destroy() end + local m = Build.model(stall, "Extras") + local home = stall:GetPivot() local function at(x: number, y: number, z: number): CFrame - return cf * CFrame.new(x, y, z) + return home * CFrame.new(x, y, z) end - local sz = PlotLayout.STALL_Z - - for seat = 1, stats.seats do - buildTable(up, cf, seat) + local cookX = Floor.STOVE_COOK.x + local stoveLv = levels.Stove or 0 + if stoveLv >= 1 then + local burner = Build.part(m, { + size = Vector3.new(1, 0.2, 1), + cf = at(cookX, Y + 4.4, 1.4), + color = rgb(30, 30, 30), + collide = false, + }) + local fire = Instance.new("Fire") + local blue = stoveLv >= 3 + fire.Size = if stoveLv >= 2 then 3.5 else 2.5 + fire.Heat = 1 + fire.Color = if blue then rgb(80, 160, 255) else rgb(255, 140, 40) + fire.SecondaryColor = if blue then rgb(200, 230, 255) else rgb(255, 220, 80) + fire.Parent = burner end - - if stats.stage >= 2 then - buildIndoor(up, cf) + if stoveLv >= 2 then + Build.cylinder(m, at(cookX - 4.5, Y + 4.9, 0), 1.2, 2.6, rgb(190, 190, 195), { material = Enum.Material.Metal }) end - - if has("Sign1") then - local m = Build.model(up, "Sign1") + -- 양념 통: 판매 금액 단계마다 하나씩(최대 3개) + local priceLv = levels.Price or 0 + local pots = { rgb(180, 40, 30), rgb(230, 180, 40), rgb(240, 120, 160) } + for i = 1, math.min(3, math.ceil(priceLv / 2)) do + local pot = Build.cylinder( + m, + at(-8.4 + (i - 1) * 1.8, Y + 4.9, -1), + 2, + 1.6, + pots[i], + { material = Enum.Material.Metal } + ) + if i == 3 then + local sp = Instance.new("Sparkles") + sp.SparkleColor = rgb(255, 220, 90) + sp.Parent = pot + end + end + if stats.carry >= 2 then + Build.part(m, { + size = Vector3.new(2.6, 0.15 + (stats.carry - 2) * 0.2, 1.8), + cf = at(8.6, Y + 4.2, 1), + color = if stats.carry >= 3 then rgb(250, 200, 70) else rgb(120, 170, 230), + collide = false, + }) + end + -- 손님 오는 속도 2단계 이상: 수레 위 분홍 네온 간판 + if (levels.Speed or 0) >= 2 then local sign = Build.part(m, { size = Vector3.new(12, 3.2, 0.6), - cf = at(0, Y + 15.6, sz + 3), + cf = at(0, Y + 15.6, 3), color = rgb(255, 80, 120), neon = true, }) @@ -519,141 +1048,90 @@ function PlotBuilder.buildUpgrades(refs: BaseRefs, cf: CFrame, bought: number) light.Range = 18 light.Parent = sign for _, x in { -4, 4 } do - Build.part(m, { - size = Vector3.new(0.3, 2.4, 0.3), - cf = at(x, Y + 13.4, sz + 3), - color = rgb(120, 120, 120), - }) + Build.part(m, { size = Vector3.new(0.3, 2.4, 0.3), cf = at(x, Y + 13.4, 3), color = rgb(120, 120, 120) }) end end - if has("Sign2") then - local m = Build.model(up, "Sign2") - for _, x in { -22, 22 } do - local post = Build.part(m, { - size = Vector3.new(1, 18, 1), - cf = at(x, Y + 9, 30), - color = rgb(80, 80, 85), - material = Enum.Material.Metal, - }) - local balloon = Build.part(m, { - size = Vector3.new(4, 4, 4), - cf = at(x, Y + 20, 30), - color = if x < 0 then rgb(255, 90, 90) else rgb(255, 200, 60), - shape = Enum.PartType.Ball, - neon = true, - collide = false, - }) - local sparkle = Instance.new("Sparkles") - sparkle.SparkleColor = rgb(255, 230, 150) - sparkle.Parent = balloon - local _ = post - end - local banner = Build.part(m, { - size = Vector3.new(40, 3, 0.4), - cf = at(0, Y + 16, 30), - color = rgb(255, 240, 120), - neon = true, - }) - Build.label(banner, Enum.NormalId.Front, "★ 오늘도 맛있는 분식 ★ OPEN", rgb(200, 40, 30)) - end - if has("Stove1") then - local m = Build.model(up, "Stove1") - local burner = Build.part(m, { - size = Vector3.new(1, 0.2, 1), - cf = at(PlotLayout.STOVE.X, Y + 4.4, sz + 1.4), - color = rgb(30, 30, 30), - collide = false, - }) - local fire = Instance.new("Fire") - fire.Size = if has("Stove2") then 4 else 2.5 - fire.Heat = 1 - fire.Color = if has("Stove2") then rgb(80, 160, 255) else rgb(255, 140, 40) - fire.SecondaryColor = if has("Stove2") then rgb(200, 230, 255) else rgb(255, 220, 80) - fire.Parent = burner - end - if has("Stove2") then - local m = Build.model(up, "Stove2") - Build.cylinder( - m, - at(PlotLayout.STOVE.X - 4.5, Y + 4.9, sz), - 1.2, - 2.6, - rgb(190, 190, 195), - { material = Enum.Material.Metal } - ) - local fire = Instance.new("Fire") - fire.Size = 3 - fire.Color = rgb(80, 160, 255) - fire.SecondaryColor = rgb(200, 230, 255) - fire.Parent = Build.part(m, { - size = Vector3.new(1, 0.2, 1), - cf = at(PlotLayout.STOVE.X - 4.5, Y + 4.2, sz), - transparency = 1, - collide = false, - }) - end - for _, id in { "Sauce1", "Sauce2" } do - if has(id) then - local m = Build.model(up, id) - local x = if id == "Sauce1" then -8.4 else -6.6 - local pot = Build.cylinder( - m, - at(x, Y + 4.9, sz - 1), - 2, - 1.8, - if id == "Sauce1" then rgb(180, 40, 30) else rgb(230, 180, 40), - { - material = Enum.Material.Metal, - } - ) - Build.cylinder(m, at(x, Y + 5.95, sz - 1), 0.1, 1.5, rgb(210, 30, 20)) - if id == "Sauce2" then - local sp = Instance.new("Sparkles") - sp.SparkleColor = rgb(255, 220, 90) - sp.Parent = pot - end - end - end - for _, id in { "Tray1", "Tray2" } do - if has(id) then - local m = Build.model(up, id) - Build.part(m, { - size = Vector3.new(2.6, 0.15, 1.8), - cf = at(8.6, Y + 4.2 + (if id == "Tray2" then 0.2 else 0), sz + 1), - color = if id == "Tray1" then rgb(120, 170, 230) else rgb(250, 200, 70), - collide = false, - }) - end - end - - -- 새 메뉴 진열대(포장마차 왼쪽). 산 메뉴마다 조리 도구와 완성 접시가 생깁니다. for i, key in Economy.MENU_ORDER do if i > 1 and table.find(stats.menus, key) then - buildMenuStand(up, cf, key, i - 1) + buildMenuStand(m, home, key, i - 1) end end end --- 손님 의자 위(앉는 위치)와 테이블 위 접시 위치(월드 좌표) -function PlotBuilder.seatCFrame(cf: CFrame, seat: number): CFrame - local s = PlotLayout.stool(seat) - local t = PlotLayout.TABLES[seat] - local pos = (cf * CFrame.new(s.X, Y + 1.8, s.Z)).Position - local look = (cf * CFrame.new(t.X, Y + 1.8, t.Z)).Position +-- 부지 입구 쪽 업그레이드 장식(손님 오는 속도 4단계 이상: 풍선 기둥과 현수막) +function PlotBuilder.buildEntrance(refs: BaseRefs, cf: CFrame, levels: Economy.Levels) + local old = refs.upgrades:FindFirstChild("Entrance") + if old then + old:Destroy() + end + if (levels.Speed or 0) < 4 then + return + end + local m = Build.model(refs.upgrades, "Entrance") + local function at(x: number, y: number, z: number): CFrame + return cf * CFrame.new(x, y, z) + end + for _, x in { -22, 22 } do + Build.part(m, { + size = Vector3.new(1, 18, 1), + cf = at(x, Y + 9, 30), + color = rgb(80, 80, 85), + material = Enum.Material.Metal, + }) + local balloon = Build.part(m, { + size = Vector3.new(4, 4, 4), + cf = at(x, Y + 20, 30), + color = if x < 0 then rgb(255, 90, 90) else rgb(255, 200, 60), + shape = Enum.PartType.Ball, + neon = true, + collide = false, + }) + local sparkle = Instance.new("Sparkles") + sparkle.SparkleColor = rgb(255, 230, 150) + sparkle.Parent = balloon + end + local banner = Build.part(m, { + size = Vector3.new(40, 3, 0.4), + cf = at(0, Y + 16, 30), + color = rgb(255, 240, 120), + neon = true, + }) + Build.label(banner, Enum.NormalId.Front, "★ 오늘도 맛있는 분식 ★ OPEN", rgb(200, 40, 30)) +end + +-- 손님 의자 위(앉는 위치, 테이블을 봄)와 테이블 위 접시 위치(월드 좌표) +function PlotBuilder.seatCFrame(cf: CFrame, layout: Floor.Layout, seat: number): CFrame + local p = Floor.chairPos(layout, seat) + local c = layout.chairs[seat] + local t = c and layout.tables[c.t] + if not p or not t then + return PlotBuilder.floorCFrame(cf, 0, 0, 1) + end + local pos = (PlotBuilder.floorCFrame(cf, p.x, p.z, p.f) * CFrame.new(0, 1.8, 0)).Position + local look = (PlotBuilder.floorCFrame(cf, t.x, t.z, t.f) * CFrame.new(0, 1.8, 0)).Position return CFrame.lookAt(pos, look) end -function PlotBuilder.dishCFrame(cf: CFrame, seat: number): CFrame - local t = PlotLayout.TABLES[seat] - return cf * CFrame.new(t.X, Y + 2.75, t.Z + 1.2) +function PlotBuilder.dishCFrame(cf: CFrame, layout: Floor.Layout, seat: number): CFrame + local c = layout.chairs[seat] + local t = c and layout.tables[c.t] + local d = c and Floor.SIDES[c.s] + if not t or not d then + return PlotBuilder.floorCFrame(cf, 0, 0, 1) + end + return PlotBuilder.floorCFrame(cf, t.x + d.x * 1.3, t.z + d.z * 1.3, t.f) * CFrame.new(0, 2.75, 0) end -function PlotBuilder.counterSlot(cf: CFrame, i: number): CFrame - return cf * CFrame.new(PlotLayout.COUNTER.X - 2 + (i - 1) * 2, Y + 4.1, PlotLayout.STALL_Z) +-- 카운터 위 i번째 접시 자리(3개씩 두 줄) +function PlotBuilder.counterSlot(refs: BaseRefs, i: number): CFrame + local col = (i - 1) % 3 + local row = ((i - 1) // 3) % 2 + return refs.stall:GetPivot() * CFrame.new(Floor.STOVE_COUNTER.x - 2 + col * 2, Y + 4.1, -0.7 + row * 1.4) end -function PlotBuilder.world(cf: CFrame, v: Vector3): Vector3 - return (cf * CFrame.new(v.X, Y + v.Y, v.Z)).Position +-- 수레 기준 상대 위치(Floor.STOVE_*)의 월드 바닥 위치 +function PlotBuilder.stallPoint(refs: BaseRefs, p: { x: number, z: number }): Vector3 + return (refs.stall:GetPivot() * CFrame.new(p.x, Y, p.z)).Position end return PlotBuilder diff --git a/bunsik-tycoon/src/server/PlotController.luau b/bunsik-tycoon/src/server/PlotController.luau index 0fc66ca..d707cd8 100644 --- a/bunsik-tycoon/src/server/PlotController.luau +++ b/bunsik-tycoon/src/server/PlotController.luau @@ -1,27 +1,36 @@ --!strict --- 플레이어 한 명의 가게를 움직입니다: Shop 로직의 이벤트를 받아 손님 NPC, 접시, 효과를 그리고, --- 조리대 버튼·자동 서빙·구매를 처리합니다. 실제 Player 대신 Folder를 넣어도 돌아가서 원격 테스트에 씁니다. +-- 가게 한 곳을 움직입니다: Shop 로직의 이벤트를 받아 손님 NPC, 알바생 NPC, 접시, 효과를 그리고, +-- 자동 서빙·업그레이드·배치·알바 고용·옆 가게 손님 주고받기를 처리합니다. +-- 실제 Player 대신 Folder를 넣어도 돌아가서 원격 테스트에 씁니다. +local HttpService = game:GetService("HttpService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local SoundService = game:GetService("SoundService") local TweenService = game:GetService("TweenService") local Shared = ReplicatedStorage.Shared +local Codec = require(Shared.Codec) local Economy = require(Shared.Economy) -local Shop = require(Shared.Shop) +local Floor = require(Shared.Floor) local Locale = require(Shared.Locale) local Recipes = require(Shared.Recipes) +local Shop = require(Shared.Shop) local Sounds = require(Shared.Sounds) local Build = require(script.Parent.Build) local Food = require(script.Parent.Food) local Npc = require(script.Parent.Npc) local PlotBuilder = require(script.Parent.PlotBuilder) -local PlotLayout = require(script.Parent.PlotLayout) local SERVE_RANGE = 8.5 +local SERVE_HEIGHT = 6 -- 2층 손님을 1층에서 서빙하지 못하게 local COOK_SLACK = 0.8 -- 요리 최소 시간 검사의 네트워크 지연 오차 local PICKUP_RANGE = 8 +local WALK_SPEED = 18 -- 손님이 걷는 속도(stud/초). 자리까지 걷는 시간 = 길 길이 / 속도 +local TRANSFER_SPEED = 20 +local MAX_WALK = 9 +local MAX_TRANSFER = 16 +local STREET_Z = 44 -- 부지 앞 길(부지 기준 z) export type Slot = { index: number, @@ -38,6 +47,14 @@ type CustomerView = { dish: Model?, } +-- 옆 가게로 넘겨주는 손님(NPC 모형째로 걸어서 옮겨 갑니다) +export type Transfer = { + menu: string, + npc: Npc.Handle, + bubble: BillboardGui, + exit: { Vector3 }, -- 원래 자리에서 원래 가게 앞 길까지 +} + -- 플레이어 손님 소식: "served"(info.price = 손님이 받을 시식 보너스), "left"(info.reason = ate|hungry|stood|closed) export type GuestEvent = (kind: string, userId: number, info: { [string]: any }) -> () @@ -62,60 +79,96 @@ export type PlotController = typeof(setmetatable( opts: Options, data: any, shop: Shop.Shop, + layout: Floor.Layout, views: { [number]: CustomerView }, handModels: { Model }, counterModels: { Model }, + tripDish: { [number]: Model }, -- 서빙 알바 번호 -> 나르는 접시 cookSession: { menu: string, start: number }?, -- 요리 창에서 메뉴를 고른 때(서버 시계) - helper: Npc.Handle?, + staffNpcs: { [string]: { Npc.Handle } }, guide: BasePart, guideValue: ObjectValue, rng: Random, tut: number, destroyed: boolean, - connections: { RBXScriptConnection }, + shieldUntil: number, -- 서버 시각(workspace:GetServerTimeNow) + promoteAt: number, + promoteAdAt: number, + rainbowOwned: boolean, + designsOwned: { [string]: boolean }, + shopNameShown: string, + lastRushSync: number, }, PlotController )) -local function makeSound(parent: Instance, id: string, volume: number, looped: boolean?): Sound +local function makeSound(parent: Instance, id: string, volume: number): Sound local s = Instance.new("Sound") s.SoundId = id s.Volume = volume - s.Looped = looped == true s.RollOffMaxDistance = 80 s.SoundGroup = SoundService:FindFirstChild("Sfx") :: SoundGroup? s.Parent = parent return s end +local function serverNow(): number + return workspace:GetServerTimeNow() +end + function PlotController.new(slot: Slot, owner: Instance, opts: Options): PlotController local data = opts.data + local levels = Economy.cleanLevels(data.Levels) + local stage = Economy.stats(levels, 1).stage + local layout = Floor.repair(Floor.clean(data.Layout), stage) + data.Levels = levels + data.Layout = layout local self = setmetatable({ slot = slot, owner = owner, opts = opts, data = data, - shop = Shop.new(data.Money, data.Bought, opts.now), + shop = Shop.new({ + money = data.Money or 0, + levels = levels, + seats = #layout.chairs, + staff = data.Staff, + now = opts.now, + rushLeft = data.RushLeft, + }), + layout = layout, views = {}, handModels = {}, counterModels = {}, + tripDish = {}, cookSession = nil, - helper = nil :: Npc.Handle?, + staffNpcs = { Cook = {}, Server = {}, Promoter = {} }, guide = Instance.new("Part") :: BasePart, guideValue = Instance.new("ObjectValue"), rng = Random.new(opts.userId + slot.index), tut = if data.TutorialDone then 0 else 1, destroyed = false, - connections = {}, + shieldUntil = 0, + promoteAt = 0, + promoteAdAt = 0, + rainbowOwned = false, + designsOwned = {}, + shopNameShown = "", + lastRushSync = 0, }, PlotController) + data.Staff = self.shop.staff - -- 이름판은 클라이언트가 이 속성으로 보는 사람 언어에 맞게 씁니다(PlotSigns). + -- 이름판은 클라이언트가 이 속성으로 보는 사람 언어에 맞게 씁니다(Plots). + local model = slot.model if opts.npc then - slot.model:SetAttribute("Npc", opts.npc) + model:SetAttribute("Npc", opts.npc) else - slot.model:SetAttribute("OwnerId", opts.userId) - slot.model:SetAttribute("OwnerName", opts.displayName) + model:SetAttribute("OwnerId", opts.userId) + model:SetAttribute("OwnerName", opts.displayName) end + model:SetAttribute("ShopName", "") + model:SetAttribute("Rainbow", false) + model:SetAttribute("ShieldUntil", 0) -- 튜토리얼 화살표가 가리킬 보이지 않는 표시 local guide = self.guide @@ -135,8 +188,10 @@ function PlotController.new(slot: Slot, owner: Instance, opts: Options): PlotCon slot.refs.stove:SetAttribute("OwnerId", opts.userId) end - PlotBuilder.buildUpgrades(slot.refs, slot.cf, self.shop.bought) - self:refreshHelper() + self:rebuildAll() + -- luau-lsp가 아래에서 정의한 refreshStaff를 생성자 안에서 못 찾아서 any로 부릅니다. + local untyped: any = self + untyped:refreshStaff() self:refreshPrompt() self:sync() return self @@ -162,24 +217,65 @@ function PlotController.notify(self: PlotController, key: string, args: { [strin end end --- 화면에 필요한 값을 Player 속성으로 내보내고 세이브 데이터에 적습니다. +function PlotController.stage(self: PlotController): number + return self.shop.stats.stage +end + +-- 화면에 필요한 값을 Player 속성으로 내보내고 세이브 데이터에 적습니다(NETWORK.md). function PlotController.sync(self: PlotController) local shop = self.shop + local stats = shop.stats self.data.Money = shop.money - self.data.Bought = shop.bought - self.data.Served = (self.data.Served or 0) + self.data.Levels = shop.levels + self.data.Staff = shop.staff + self.data.RushLeft = shop.rushLeft local o = self.owner o:SetAttribute("Money", shop.money) - o:SetAttribute("Bought", shop.bought) - o:SetAttribute("Stage", shop.stats.stage) + o:SetAttribute("Levels", Codec.encodeMap(shop.levels, Economy.TRACK_ORDER)) + o:SetAttribute("Stage", stats.stage) + o:SetAttribute("Seats", #self.layout.chairs) + o:SetAttribute("Tables", #self.layout.tables) + local roles = {} + for _, r in Economy.ROLES do + table.insert(roles, r.id) + end + o:SetAttribute("Staff", Codec.encodeMap(shop.staff, roles)) + o:SetAttribute("Strike", shop.strike) + o:SetAttribute("Wage", Economy.totalWage(shop.staff, stats)) o:SetAttribute("Double", shop.moneyMult > 1) - o:SetAttribute("Boost", Economy.boostAmount(shop.stats)) + o:SetAttribute("Boost", Economy.boostAmount(stats)) o:SetAttribute("Tut", self.tut) o:SetAttribute("Plot", self.slot.index) o:SetAttribute("Carry", #shop.hand) o:SetAttribute("Hand", table.concat(shop.hand, ",")) o:SetAttribute("Earned", self.data.Earned or 0) - self.slot.model:SetAttribute("Level", shop.bought) + o:SetAttribute("RushUntil", if shop.rushLeft > 0 then serverNow() + shop.rushLeft else 0) + o:SetAttribute("PromoteAt", self.promoteAt) + o:SetAttribute("PromoteAdAt", self.promoteAdAt) + o:SetAttribute("KickCredits", self.data.KickCredits or 0) + o:SetAttribute("ShopName", self.data.ShopName or "") + o:SetAttribute("Rainbow", self.data.Rainbow ~= false) + o:SetAttribute("RainbowOwned", self.rainbowOwned) + o:SetAttribute("Design", self.data.Design or "Basic") + local owned = {} + for _, d in Economy.DESIGNS do + if d.pass and self.designsOwned[d.id] then + table.insert(owned, d.id) + end + end + o:SetAttribute("DesignsOwned", table.concat(owned, ",")) + local model = self.slot.model + model:SetAttribute("Level", Economy.shopLevel(shop.levels, #self.layout.chairs)) + model:SetAttribute("Stage", stats.stage) + model:SetAttribute("Menus", table.concat(stats.menus, ",")) + model:SetAttribute("PriceMult", stats.price) + model:SetAttribute("Design", self.data.Design or "Basic") + model:SetAttribute("Rainbow", self.rainbowOwned and self.data.Rainbow ~= false) +end + +function PlotController.syncLayout(self: PlotController) + self.data.Layout = self.layout + self.owner:SetAttribute("Layout", HttpService:JSONEncode(self.layout)) end -- 조리대 속성: CookMenu(먼저 만들 메뉴, 없으면 ""), CookTime(화구 수준), HandFull @@ -202,60 +298,186 @@ function PlotController.refreshPrompt(self: PlotController) self.owner:SetAttribute("Orders", table.concat(parts, ",")) end -function PlotController.refreshHelper(self: PlotController) - if self.shop.stats.helper and not self.helper then - local pos = PlotBuilder.world(self.slot.cf, PlotLayout.HELPER) - local look = PlotBuilder.world(self.slot.cf, PlotLayout.STOVE) - local h = Npc.spawn(self.slot.refs.dynamic, CFrame.new(pos), self.rng, Color3.fromRGB(250, 250, 250)) - h.model.Name = "Helper" - h.root.CFrame = Npc.standCFrame(h, pos, look) - local tag = Build.billboard( - h.root, - "👩‍🍳", - UDim2.fromOffset(60, 60), - Vector3.new(0, 3.5, 0), - Color3.new(1, 1, 1) - ) - tag.Name = "HelperTag" - self.helper = h +-- 의자마다 입구에서 걷는 시간(길 길이 / 속도)을 Shop에 알려 줍니다. +function PlotController.computeWalks(self: PlotController) + table.clear(self.shop.seatWalk) + for i in self.layout.chairs do + local len = Floor.pathLength(Floor.pathToChair(self.layout, self:stage(), i)) + self.shop.seatWalk[i] = math.clamp(len / WALK_SPEED, 1.5, MAX_WALK) end end +-- 부지 좌표 경로 -> 월드 바닥 점 +function PlotController.worldPath(self: PlotController, path: { Floor.Pos }): { Vector3 } + local out = {} + for _, p in path do + table.insert(out, PlotBuilder.world(self.slot.cf, p)) + end + return out +end + +function PlotController.entryPath(self: PlotController, seat: number): { Vector3 } + return self:worldPath(Floor.pathToChair(self.layout, self:stage(), seat)) +end + +-- 의자에서 가게 앞 길까지(나갈 때) +function PlotController.exitPath(self: PlotController, seat: number): { Vector3 } + local path = self:entryPath(seat) + local out = {} + for i = #path, 1, -1 do + table.insert(out, path[i]) + end + table.insert(out, PlotBuilder.world(self.slot.cf, { x = 0, z = STREET_Z, f = 1 })) + return out +end + +-- 건물·수레·배치·장식을 모두 다시 짓습니다. +function PlotController.rebuildAll(self: PlotController) + local refs = self.slot.refs + local cf = self.slot.cf + PlotBuilder.placeStall(refs, cf, self.layout.stove) + PlotBuilder.buildStallExtras(refs, self.shop.levels, self.shop.stats) + PlotBuilder.buildEntrance(refs, cf, self.shop.levels) + PlotBuilder.buildBuilding(refs, cf, self:stage(), self:designShown()) + PlotBuilder.buildFurniture(refs, cf, self.layout) + self:computeWalks() + self:syncLayout() +end + +function PlotController.designShown(self: PlotController): string + local id = self.data.Design or "Basic" + local d = Economy.design(id) + if not d or (d.pass and not self.designsOwned[id]) then + return "Basic" + end + return id +end + +local function staffTag(h: Npc.Handle, text: string) + local old = h.root:FindFirstChild("StaffTag") + if old then + old:Destroy() + end + local tag = Build.billboard(h.root, text, UDim2.fromOffset(56, 56), Vector3.new(0, 3.6, 0), Color3.new(1, 1, 1)) + tag.Name = "StaffTag" +end + +local STAFF_SHIRT = { + Cook = Color3.fromRGB(250, 250, 250), + Server = Color3.fromRGB(255, 150, 190), + Promoter = Color3.fromRGB(255, 210, 60), +} +local STAFF_ICON = { Cook = "👩‍🍳", Server = "🍽️", Promoter = "📣" } + +-- 알바생이 서는 곳(월드 바닥)과 보는 곳 +function PlotController.staffSpot(self: PlotController, role: string, i: number): (Vector3, Vector3) + local refs = self.slot.refs + if role == "Cook" then + local p = Floor.STOVE_BACK + local pos = PlotBuilder.stallPoint(refs, { x = p.x + (i - 1) * 5, z = p.z }) + return pos, PlotBuilder.stallPoint(refs, { x = p.x + (i - 1) * 5, z = 0 }) + elseif role == "Server" then + local pos = PlotBuilder.stallPoint(refs, { x = 9 + (i - 1) * 2.5, z = 4.5 }) + return pos, PlotBuilder.stallPoint(refs, { x = 9 + (i - 1) * 2.5, z = 10 }) + end + local pos = PlotBuilder.world(self.slot.cf, { x = 6, z = 34, f = 1 }) + return pos, PlotBuilder.world(self.slot.cf, { x = 6, z = 44, f = 1 }) +end + +-- 고용한 수만큼 알바생 NPC를 세웁니다(쉬는 중이면 💤). +function PlotController.refreshStaff(self: PlotController) + local shop = self.shop + for _, r in Economy.ROLES do + local list = self.staffNpcs[r.id] + local want = if shop.stats.staffUnlocked then shop.staff[r.id] or 0 else 0 + while #list > want do + local h = table.remove(list) :: Npc.Handle + h.model:Destroy() + end + while #list < want do + local i = #list + 1 + local pos, look = self:staffSpot(r.id, i) + local h = Npc.spawn(self.slot.refs.dynamic, CFrame.new(pos), self.rng, STAFF_SHIRT[r.id]) + h.model.Name = "Staff_" .. r.id .. i + h.root.CFrame = Npc.standCFrame(h, pos, look) + if r.id == "Promoter" then + -- 전단지 팻말 + local sign = Build.part(h.model, { + name = "Sign", + size = Vector3.new(3, 2, 0.2), + cf = h.root.CFrame * CFrame.new(1.4, 2.4, -0.6), + color = Color3.fromRGB(255, 240, 120), + collide = false, + }) + sign.Anchored = false + sign.Massless = true + Build.label(sign, Enum.NormalId.Back, "분식 🌶️ BUNSIK", Color3.fromRGB(220, 50, 40)) + local w = Instance.new("WeldConstraint") + w.Part0 = h.root + w.Part1 = sign + w.Parent = sign + end + table.insert(list, h) + end + for i, h in list do + staffTag(h, if shop.strike then "💤" else STAFF_ICON[r.id]) + if not h.tween then + local pos, look = self:staffSpot(r.id, i) + h.root.CFrame = Npc.standCFrame(h, pos, look) + end + end + end +end + +local function unweld(m: Model) + for _, d in m:GetDescendants() do + if d:IsA("WeldConstraint") then + d:Destroy() + end + end +end + +local function anchorAll(m: Model) + for _, d in m:GetDescendants() do + if d:IsA("BasePart") then + d.Anchored = true + end + end +end + +-- 접시 모형을 캐릭터·NPC 앞에 붙입니다(i = 몇 번째 접시, 위로 쌓음). +local function holdDish(m: Model, root: BasePart, parent: Instance, i: number) + local plate = m.PrimaryPart :: BasePart + unweld(m) + m:PivotTo(root.CFrame * CFrame.new(0, -0.4 + (i - 1) * 0.6, -1.9)) + Build.weldAll(m, plate) + for _, d in m:GetDescendants() do + if d:IsA("BasePart") then + d.Massless = true + d.CanCollide = false + end + end + plate.Anchored = false + local w = Instance.new("WeldConstraint") + w.Part0 = root + w.Part1 = plate + w.Parent = plate + m.Parent = parent +end + -- 손에 든 접시 모형을 캐릭터 앞에 붙입니다. function PlotController.layoutHand(self: PlotController) local char = self:character() local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart? for i, m in self.handModels do - local plate = m.PrimaryPart :: BasePart - for _, d in m:GetDescendants() do - if d:IsA("WeldConstraint") then - d:Destroy() - end - end - if root then - m:PivotTo(root.CFrame * CFrame.new(0, -0.4 + (i - 1) * 0.6, -1.9)) - Build.weldAll(m, plate) - for _, d in m:GetDescendants() do - if d:IsA("BasePart") then - d.Massless = true - d.CanCollide = false - end - end - plate.Anchored = false - local w = Instance.new("WeldConstraint") - w.Part0 = root - w.Part1 = plate - w.Parent = plate - m.Parent = char + if root and char then + holdDish(m, root, char, i) else -- 캐릭터가 없을 때(테스트)는 조리대 위에 둡니다. - for _, d in m:GetDescendants() do - if d:IsA("BasePart") then - d.Anchored = true - end - end + unweld(m) + anchorAll(m) m.Parent = self.slot.refs.dynamic - m:PivotTo(PlotBuilder.counterSlot(self.slot.cf, 1) * CFrame.new(0, 1 + i * 0.6, 1.4)) + m:PivotTo(PlotBuilder.counterSlot(self.slot.refs, 1) * CFrame.new(0, 1 + i * 0.6, 1.4)) end end end @@ -267,14 +489,20 @@ function PlotController.rebuildHand(self: PlotController) end table.clear(self.handModels) for _, menu in self.shop.hand do - table.insert(self.handModels, Food.dish(menu, PlotBuilder.counterSlot(self.slot.cf, 1), self.slot.refs.dynamic)) + table.insert( + self.handModels, + Food.dish(menu, PlotBuilder.counterSlot(self.slot.refs, 1), self.slot.refs.dynamic) + ) end self:layoutHand() end function PlotController.layoutCounter(self: PlotController) for i, m in self.counterModels do - m:PivotTo(PlotBuilder.counterSlot(self.slot.cf, i)) + unweld(m) + anchorAll(m) + m.Parent = self.slot.refs.dynamic + m:PivotTo(PlotBuilder.counterSlot(self.slot.refs, i)) end end @@ -298,9 +526,8 @@ function PlotController.updateGuide(self: PlotController) -- 든 접시를 기다리는 손님 자리 for id, c in self.shop.customers do if c.state ~= "eating" and table.find(self.shop.hand, c.menu) then - local v = self.views[id] - if v then - target = PlotBuilder.seatCFrame(self.slot.cf, c.seat).Position + Vector3.new(0, 1, 0) + if self.views[id] then + target = PlotBuilder.seatCFrame(self.slot.cf, self.layout, c.seat).Position + Vector3.new(0, 1, 0) end break end @@ -319,7 +546,7 @@ function PlotController.cook(self: PlotController, choice: string?): string? if not menu then return nil end - local dish = Food.dish(menu, PlotBuilder.counterSlot(self.slot.cf, 1), self.slot.refs.dynamic) + local dish = Food.dish(menu, PlotBuilder.counterSlot(self.slot.refs, 1), self.slot.refs.dynamic) table.insert(self.handModels, dish) self:layoutHand() if self.tut == 1 then @@ -394,33 +621,18 @@ local function floatText(parent: BasePart, text: string) end) end -function PlotController.serve(self: PlotController, id: number): number? - local c = self.shop.customers[id] - local earn = Shop.serve(self.shop, id) - if not earn or not c then - return nil - end - local view = self.views[id] - -- 손에 든 같은 메뉴 접시 모형을 테이블로 옮깁니다. - for i, m in self.handModels do - if m.Name == "Dish_" .. c.menu then - table.remove(self.handModels, i) - for _, d in m:GetDescendants() do - if d:IsA("WeldConstraint") then - d:Destroy() - elseif d:IsA("BasePart") then - d.Anchored = true - end - end - m.Parent = self.slot.refs.dynamic - m:PivotTo(PlotBuilder.dishCFrame(self.slot.cf, c.seat)) - if view then - view.dish = m - end - break +-- 손님이 접시를 받았을 때의 화면(접시를 테이블에, 하트, 돈 글자, 동전 소리) +function PlotController.showServed(self: PlotController, c: Shop.Customer, dish: Model?, earn: number) + local view = self.views[c.id] + if dish then + unweld(dish) + anchorAll(dish) + dish.Parent = self.slot.refs.dynamic + dish:PivotTo(PlotBuilder.dishCFrame(self.slot.cf, self.layout, c.seat)) + if view then + view.dish = dish end end - self:layoutHand() if view then Build.setBubbleIcon(view.bubble, "heart") local anchor = if view.npc then view.npc.root else view.seat @@ -439,6 +651,24 @@ function PlotController.serve(self: PlotController, id: number): number? end self.data.Served = (self.data.Served or 0) + 1 self.data.Earned = (self.data.Earned or 0) + earn +end + +function PlotController.serve(self: PlotController, id: number): number? + local c = self.shop.customers[id] + local earn = Shop.serve(self.shop, id) + if not earn or not c then + return nil + end + -- 손에 든 같은 메뉴 접시 모형을 테이블로 옮깁니다. + local dish: Model? = nil + for i, m in self.handModels do + if m.Name == "Dish_" .. c.menu then + dish = table.remove(self.handModels, i) + break + end + end + self:layoutHand() + self:showServed(c, dish, earn) if self.tut == 2 then self:setTut(3) end @@ -447,24 +677,137 @@ function PlotController.serve(self: PlotController, id: number): number? return earn end -function PlotController.onEvent(self: PlotController, e: Shop.Event) - local cf = self.slot.cf - if e.kind == "spawn" then - local path = {} - for _, p in PlotLayout.pathTo(e.seat) do - table.insert(path, PlotBuilder.world(cf, p)) +-- 서빙 알바 경로: 수레 앞에서 손님 의자 앞까지 +function PlotController.serverPath(self: PlotController, seat: number): { Vector3 } + local refs = self.slot.refs + local from = PlotBuilder.stallPoint(refs, Floor.STOVE_FRONT) + local path = self:entryPath(seat) + -- 입구 쪽 앞부분(문까지)은 빼고, 수레 앞에서 바로 출발합니다. + local out = { from } + for i = 4, #path - 1 do + table.insert(out, path[i]) + end + if #out == 1 then + table.insert(out, path[#path]) + end + return out +end + +-- 서빙 알바가 접시를 들고 손님에게 갑니다. +function PlotController.startTrip(self: PlotController, staff: number, id: number, index: number) + local h = self.staffNpcs.Server[staff] + local c = self.shop.customers[id] + local dish = table.remove(self.counterModels, index) + self:layoutCounter() + if not dish then + return + end + if not h or not c then + dish:Destroy() + return + end + holdDish(dish, h.root, h.model, 1) + self.tripDish[staff] = dish + local trip = self.shop.trips[staff] + local duration = if trip then math.max(0.5, trip.doneT - self.shop.now) else 2 + local path = { h.root.Position - Vector3.new(0, h.root.Position.Y - self:serverPath(c.seat)[1].Y, 0) } + for _, p in self:serverPath(c.seat) do + table.insert(path, p) + end + Npc.walk(h, path, duration) +end + +function PlotController.endTrip(self: PlotController, staff: number, earnFor: Shop.Customer?, earn: number?) + local h = self.staffNpcs.Server[staff] + local dish = self.tripDish[staff] + self.tripDish[staff] = nil + if earnFor and earn then + self:showServed(earnFor, dish, earn) + elseif dish then + table.insert(self.counterModels, dish) + self:layoutCounter() + end + if h then + -- 수레 옆 자리로 돌아갑니다. + local home = self:staffSpot("Server", staff) + local back = { h.root.Position - Vector3.new(0, h.humanoid.HipHeight + h.root.Size.Y / 2, 0) } + local c = earnFor + if c then + local p = self:serverPath(c.seat) + for i = #p, 1, -1 do + table.insert(back, p[i]) + end end - local npc = Npc.spawn(self.slot.refs.dynamic, CFrame.new(path[1]), self.rng) - npc.root.CFrame = Npc.standCFrame(npc, path[1], path[2]) - local bubble = Build.orderBubble(npc.root, e.menu, 64, Vector3.new(0, 4, 0)) - bubble.Name = "Order" - self.views[e.id] = { npc = npc, seat = nil, bubble = bubble, dish = nil } - Npc.walk(npc, path, Economy.WALK_IN) + table.insert(back, home) + Npc.walk(h, back, 2, function() + local pos, look = self:staffSpot("Server", staff) + h.root.CFrame = Npc.standCFrame(h, pos, look) + end) + end +end + +-- 서빙 알바가 나르던 손님이 사라졌으면(옆 가게로 감) 접시를 카운터로 돌립니다. +function PlotController.fixTrips(self: PlotController) + for i, dish in self.tripDish do + if not self.shop.trips[i] then + self.tripDish[i] = nil + table.insert(self.counterModels, dish) + end + end + -- 카운터 모형 수를 로직과 맞춥니다(나르기 취소로 카운터에 돌아온 접시). + while #self.counterModels < #self.shop.counter do + local menu = self.shop.counter[#self.counterModels + 1] + table.insert( + self.counterModels, + Food.dish(menu, PlotBuilder.counterSlot(self.slot.refs, 1), self.slot.refs.dynamic) + ) + end + while #self.counterModels > #self.shop.counter do + local m = table.remove(self.counterModels) + if m then + m:Destroy() + end + end + for i, m in self.counterModels do + local want = self.shop.counter[i] + if m.Name ~= "Dish_" .. want then + m:Destroy() + self.counterModels[i] = Food.dish(want, PlotBuilder.counterSlot(self.slot.refs, i), self.slot.refs.dynamic) + end + end + self:layoutCounter() +end + +function PlotController.spawnView(self: PlotController, id: number, seat: number, menu: string) + local path = self:entryPath(seat) + local npc = Npc.spawnCustomer(self.slot.refs.dynamic, CFrame.new(path[1]), self.rng) + npc.root.CFrame = Npc.standCFrame(npc, path[1], path[2]) + local bubble = Build.orderBubble(npc.root, menu, 64, Vector3.new(0, 4, 0)) + bubble.Name = "Order" + self.views[id] = { npc = npc, seat = nil, bubble = bubble, dish = nil } + Npc.walk(npc, path, self.shop.seatWalk[seat] or Economy.WALK_IN) +end + +-- NPC를 길을 따라 내보내고 없앱니다. +local function walkAway(npc: Npc.Handle, path: { Vector3 }, duration: number) + Npc.walk(npc, path, duration, function() + npc.model:Destroy() + end) + task.delay(duration + 1, function() + if npc.model.Parent then + npc.model:Destroy() + end + end) +end + +function PlotController.onEvent(self: PlotController, e: Shop.Event) + if e.kind == "spawn" then + self:spawnView(e.id, e.seat, e.menu) elseif e.kind == "seated" then local c = self.shop.customers[e.id] local v = self.views[e.id] if c and v and v.npc then - Npc.sit(v.npc, PlotBuilder.seatCFrame(cf, c.seat)) + Npc.sit(v.npc, PlotBuilder.seatCFrame(self.slot.cf, self.layout, c.seat)) end elseif e.kind == "leave" then if e.guest then @@ -474,30 +817,31 @@ function PlotController.onEvent(self: PlotController, e: Shop.Event) local v = self.views[e.id] self.views[e.id] = nil if v and v.npc then - local npc = v.npc if v.dish then v.dish:Destroy() end v.bubble:Destroy() - local path = PlotLayout.pathTo(e.seat) - local back = {} - for i = #path, 1, -1 do - table.insert(back, PlotBuilder.world(cf, path[i])) - end - Npc.walk(npc, back, Economy.WALK_IN, function() - npc.model:Destroy() - end) - task.delay(Economy.WALK_IN + 1, function() - if npc.model.Parent then - npc.model:Destroy() - end - end) + walkAway(v.npc, self:exitPath(e.seat), self.shop.seatWalk[e.seat] or Economy.WALK_IN) end elseif e.kind == "counter" then local i = #self.counterModels + 1 - local m = Food.dish(e.menu, PlotBuilder.counterSlot(cf, i), self.slot.refs.dynamic) + local m = Food.dish(e.menu, PlotBuilder.counterSlot(self.slot.refs, i), self.slot.refs.dynamic) table.insert(self.counterModels, m) self:layoutCounter() + elseif e.kind == "deliver" then + self:startTrip(e.staff, e.id, e.index) + elseif e.kind == "delivered" then + local c = self.shop.customers[e.id] + self:endTrip(e.staff, c, e.earn) + self:sync() + elseif e.kind == "returned" then + self:endTrip(e.staff, nil, nil) + elseif e.kind == "wage" then + self:sync() + elseif e.kind == "strike" then + self:notify(if e.on then "strike" else "strikeOver") + self:refreshStaff() + self:sync() end end @@ -506,6 +850,7 @@ function PlotController.update(self: PlotController, now: number) if self.destroyed then return end + local hadRush = self.shop.rushLeft > 0 local events = Shop.tick(self.shop, now) for _, e in events do self:onEvent(e) @@ -523,8 +868,9 @@ function PlotController.update(self: PlotController, now: number) if #self.shop.hand > 0 then for id, c in self.shop.customers do if c.state == "waiting" and table.find(self.shop.hand, c.menu) then - local seat = PlotBuilder.seatCFrame(self.slot.cf, c.seat).Position - if (Vector3.new(pos.X, seat.Y, pos.Z) - seat).Magnitude < SERVE_RANGE then + local seat = PlotBuilder.seatCFrame(self.slot.cf, self.layout, c.seat).Position + local flat = Vector3.new(pos.X, seat.Y, pos.Z) - seat + if flat.Magnitude < SERVE_RANGE and math.abs(pos.Y - seat.Y) < SERVE_HEIGHT then self:serve(id) end end @@ -534,44 +880,387 @@ function PlotController.update(self: PlotController, now: number) if #events > 0 then self:refreshPrompt() end + -- 손님 러시가 끝나면 화면에 알립니다. 남은 시간은 10초마다 저장 데이터에 적습니다. + if hadRush and self.shop.rushLeft <= 0 then + self:sync() + elseif self.shop.rushLeft > 0 and now - self.lastRushSync > 10 then + self.lastRushSync = now + self.data.RushLeft = self.shop.rushLeft + end self:updateGuide() end -function PlotController.buy(self: PlotController): (boolean, string?) - local before = self.shop.stats - local p, err = Shop.buyNext(self.shop) - if not p then - return false, err - end - PlotBuilder.buildUpgrades(self.slot.refs, self.slot.cf, self.shop.bought) - local fresh = self.slot.refs.upgrades:FindFirstChild(p.id) - if fresh then - local hl = Instance.new("Highlight") - hl.FillColor = Color3.fromRGB(255, 230, 120) - hl.OutlineColor = Color3.fromRGB(255, 255, 255) - hl.FillTransparency = 0.4 - hl.Parent = fresh - task.delay(2.5, function() - hl:Destroy() - end) - end - self:refreshHelper() - self:refreshPrompt() +-- 구매 공통: 튜토리얼 마무리 +function PlotController.afterPurchase(self: PlotController) if self.tut == 3 then self:setTut(0) end - -- 이름은 클라이언트가 자기 언어로 바꿔 씁니다(item, menu 키). - if self.shop.stats.stage > before.stage then - self:notify("expanded") - elseif p.effect.menu then - self:notify("newMenu", { menu = p.effect.menu }) + self:refreshPrompt() + self:sync() +end + +local function flash(target: Instance?) + if not target then + return + end + local hl = Instance.new("Highlight") + hl.FillColor = Color3.fromRGB(255, 230, 120) + hl.OutlineColor = Color3.fromRGB(255, 255, 255) + hl.FillTransparency = 0.4 + hl.Parent = target + task.delay(2.5, function() + hl:Destroy() + end) +end + +-- 업그레이드 갈래 구매. 실패하면 (false, 이유) +function PlotController.upgrade(self: PlotController, trackId: string): (boolean, string?) + local beforeStage = self:stage() + local lv, err = Shop.buyLevel(self.shop, trackId) + if not lv then + if err == "money" then + local nl = Economy.nextLevel(self.shop.levels, trackId) + if nl then + self:notify("notEnough", { need = Locale.number(nl.cost - self.shop.money) }) + end + elseif err == "stage" then + self:notify("needStage") + end + return false, err + end + local refs = self.slot.refs + if self:stage() ~= beforeStage then + -- 건물이 바뀌면 배치를 새 건물에 맞추고(2층 계단 자리 비우기) 모두 다시 짓습니다. + self.layout = Floor.repair(self.layout, self:stage()) + self:rebuildAll() + self:resettleCustomers() + flash(refs.building) + self:notify(if self:stage() >= 3 then "floor2" else "expanded") else - self:notify("purchased", { item = p.id }) + PlotBuilder.buildStallExtras(refs, self.shop.levels, self.shop.stats) + PlotBuilder.buildEntrance(refs, self.slot.cf, self.shop.levels) + if trackId == "Menu" then + flash(refs.stall:FindFirstChild("Extras")) + self:notify("newMenu", { menu = lv.value }) + else + flash(refs.stall) + self:notify("upgraded", { track = trackId, level = self.shop.levels[trackId] }) + end + end + if trackId == "Staff" then + self:refreshStaff() + end + self:afterPurchase() + return true, nil +end + +-- 자리 값이 모자랄 때 알림 +function PlotController.needMoney(self: PlotController, cost: number) + self:notify("notEnough", { need = Locale.number(cost - self.shop.money) }) +end + +-- 배치가 바뀐 뒤: 모형·걷는 시간·앉은 손님·접시 위치를 다시 맞춥니다. +function PlotController.applyLayout(self: PlotController) + local refs = self.slot.refs + PlotBuilder.placeStall(refs, self.slot.cf, self.layout.stove) + PlotBuilder.buildStallExtras(refs, self.shop.levels, self.shop.stats) + PlotBuilder.buildFurniture(refs, self.slot.cf, self.layout) + self:computeWalks() + self:syncLayout() + self:resettleCustomers() + self:layoutCounter() + self:refreshStaff() +end + +-- 의자·테이블이 옮겨지면 앉아 있는 손님과 접시도 옮깁니다. +function PlotController.resettleCustomers(self: PlotController) + for id, c in self.shop.customers do + local v = self.views[id] + if v then + local seatCf = PlotBuilder.seatCFrame(self.slot.cf, self.layout, c.seat) + if v.npc and c.state ~= "walking" then + Npc.sit(v.npc, seatCf) + elseif v.seat then + v.seat.CFrame = seatCf * CFrame.new(0, 0.2, 0) + end + if v.dish then + v.dish:PivotTo(PlotBuilder.dishCFrame(self.slot.cf, self.layout, c.seat)) + end + end + end +end + +-- 의자 1개 사기(빈 쪽에 자동 배치) +function PlotController.buySeat(self: PlotController, tableIndex: number?): boolean + local seats = #self.layout.chairs + local stage = self:stage() + if seats >= Economy.seatCap(stage) then + self:notify("seatMax") + return false + end + if seats >= #self.layout.tables * Economy.CHAIRS_PER_TABLE then + self:notify("tableFull") + return false + end + local cost = Economy.seatCost(seats + 1) + if self.shop.money < cost then + self:needMoney(cost) + return false + end + local test = Floor.clone(self.layout) + local ci = Floor.addChair(test, stage, tableIndex) + if not ci then + self:notify("noSpace") + return false + end + Shop.spend(self.shop, cost) + self.layout = test + Shop.setSeats(self.shop, #self.layout.chairs) + self:applyLayout() + flash(self.slot.refs.furniture:FindFirstChild("Chair" .. ci)) + self:notify("seatAdded") + self:afterPurchase() + return true +end + +-- 테이블(+의자 1개) 사기 +function PlotController.buyTable(self: PlotController): boolean + local seats = #self.layout.chairs + local tables = #self.layout.tables + local stage = self:stage() + if tables >= Economy.tableCap(stage) then + self:notify("tableMax") + return false + end + if seats >= Economy.seatCap(stage) then + self:notify("seatMax") + return false + end + local cost = Economy.tableCost(tables, seats) + if self.shop.money < cost then + self:needMoney(cost) + return false + end + local test = Floor.clone(self.layout) + local ti = Floor.addTable(test, stage) + if not ti then + self:notify("noSpace") + return false + end + Shop.spend(self.shop, cost) + self.layout = test + Shop.setSeats(self.shop, #self.layout.chairs) + self:applyLayout() + flash(self.slot.refs.furniture:FindFirstChild("Table" .. ti)) + self:notify("tableAdded") + self:afterPurchase() + return true +end + +function PlotController.buyDecor(self: PlotController, kind: string): boolean + local d = Economy.decor(kind) + if not d then + return false + end + if #self.layout.decor >= Economy.DECOR_MAX then + self:notify("noSpace") + return false + end + if self.shop.money < d.cost then + self:needMoney(d.cost) + return false + end + local test = Floor.clone(self.layout) + local di = Floor.addDecor(test, self:stage(), kind) + if not di then + self:notify("noSpace") + return false + end + Shop.spend(self.shop, d.cost) + self.layout = test + self:applyLayout() + flash(self.slot.refs.furniture:FindFirstChild("Decor" .. di)) + self:notify("decorAdded", { kind = kind }) + self:afterPurchase() + return true +end + +-- 화면 아래 추천 막대의 [사기] +function PlotController.buyOffer(self: PlotController, id: string): boolean + if id == "Seat" then + return self:buySeat(nil) + elseif id == "Table" then + return self:buyTable() + end + return (self:upgrade(id)) +end + +-- 옮기기(꾸미기 화면). 검사는 Floor.move +function PlotController.move(self: PlotController, m: Floor.Move): boolean + local layout, why = Floor.move(self.layout, self:stage(), m) + if not layout then + self:notify("placeFail", { why = why or "bounds" }) + self:syncLayout() -- 클라이언트 미리보기를 서버 배치로 되돌립니다. + return false + end + self.layout = layout + self:applyLayout() + return true +end + +function PlotController.hire(self: PlotController, role: string): boolean + local ok, err = Shop.hire(self.shop, role) + if not ok then + if err == "money" then + local r = Economy.role(role) + if r then + self:needMoney(r.hire) + end + elseif err == "locked" then + self:notify("staffLocked") + elseif err == "max" then + self:notify("staffMax") + end + return false + end + self:refreshStaff() + self:notify("hired", { role = role }) + self:afterPurchase() + return true +end + +function PlotController.fire(self: PlotController, role: string): boolean + if not Shop.fire(self.shop, role) then + return false + end + local n = (self.shop.staff[role] or 0) + 1 + if role == "Server" and self.tripDish[n] then + self.tripDish[n]:Destroy() + self.tripDish[n] = nil + end + self:fixTrips() + self:refreshStaff() + self:notify("fired", { role = role }) + self:sync() + return true +end + +-- 가게 이름(필터를 거친 글)을 모두에게 보이게 합니다. raw는 세이브에 적는 원문. +function PlotController.setShopName(self: PlotController, raw: string, shown: string) + self.data.ShopName = raw + self.shopNameShown = shown + self.slot.model:SetAttribute("ShopName", shown) + self:sync() +end + +function PlotController.setRainbow(self: PlotController, on: boolean) + self.data.Rainbow = on + self:sync() +end + +function PlotController.setRainbowOwned(self: PlotController, owned: boolean) + self.rainbowOwned = owned + self:sync() +end + +function PlotController.setDesignOwned(self: PlotController, id: string, owned: boolean) + local before = self:designShown() + self.designsOwned[id] = owned + if self:designShown() ~= before then + PlotBuilder.buildBuilding(self.slot.refs, self.slot.cf, self:stage(), self:designShown()) end self:sync() +end + +-- 디자인 바꾸기. 실패 이유: "stage", "locked"(유료인데 없음), "none" +function PlotController.setDesign(self: PlotController, id: string): (boolean, string?) + local d = Economy.design(id) + if not d then + return false, "none" + end + if self:stage() < 2 then + self:notify("designLocked") + return false, "stage" + end + if d.pass and not self.designsOwned[id] then + return false, "locked" + end + self.data.Design = id + PlotBuilder.buildBuilding(self.slot.refs, self.slot.cf, self:stage(), self:designShown()) + flash(self.slot.refs.building) + self:notify("designSet", { design = id }) + self:sync() return true, nil end +function PlotController.addRush(self: PlotController, seconds: number) + Shop.addRush(self.shop, seconds) + self:sync() +end + +-- 옆 가게로 손님을 내줍니다(홍보·쫓아내기). NPC 모형째로 넘깁니다. +function PlotController.giveCustomers(self: PlotController, n: number): { Transfer } + local out: { Transfer } = {} + for _, c in Shop.takeCustomers(self.shop, n) do + local v = self.views[c.id] + self.views[c.id] = nil + if v and v.npc then + local exit = self:exitPath(c.seat) + -- 걷는 중이었으면 지금 자리에서 바로 나갑니다. + exit[1] = v.npc.root.Position - Vector3.new(0, v.npc.humanoid.HipHeight + v.npc.root.Size.Y / 2, 0) + table.insert(out, { menu = c.menu, npc = v.npc, bubble = v.bubble, exit = exit }) + elseif v then + v.bubble:Destroy() + end + end + if #out > 0 then + self:fixTrips() + self:refreshPrompt() + self:sync() + end + return out +end + +-- 옆 가게에서 온 손님을 받습니다. 자리가 없는 손님은 길로 나가 사라집니다. 받은 수를 돌려줍니다. +function PlotController.receiveCustomers(self: PlotController, list: { Transfer }): number + local got = 0 + local street = PlotBuilder.world(self.slot.cf, { x = 0, z = STREET_Z, f = 1 }) + for _, t in list do + local npc = t.npc + npc.model.Parent = self.slot.refs.dynamic + local seat = Shop.freeSeat(self.shop) + if seat then + local path = table.clone(t.exit) + table.insert(path, street) + for _, p in self:entryPath(seat) do + table.insert(path, p) + end + local len = 0 + for i = 2, #path do + len += (path[i] - path[i - 1]).Magnitude + end + local walk = math.clamp(len / TRANSFER_SPEED, 2, MAX_TRANSFER) + local c = Shop.addTransfer(self.shop, t.menu, walk) + if c then + got += 1 + if c.menu ~= t.menu then + Build.setBubbleIcon(t.bubble, c.menu) + end + self.views[c.id] = { npc = npc, seat = nil, bubble = t.bubble, dish = nil } + Npc.walk(npc, path, walk) + continue + end + end + t.bubble:Destroy() + walkAway(npc, t.exit, 4) + end + if got > 0 then + self:refreshPrompt() + self:sync() + end + return got +end + -- 다른 플레이어를 빈자리에 앉힙니다. 앉힌 손님(Shop.Customer)을 돌려주고, 자리가 없으면 nil. function PlotController.addGuest(self: PlotController, userId: number, character: Model): any local humanoid = character:FindFirstChildOfClass("Humanoid") @@ -589,7 +1278,7 @@ function PlotController.addGuest(self: PlotController, userId: number, character seat.CanTouch = false -- 지나가다 밟아서 앉지 않게 seat.Transparency = 1 seat.Size = Vector3.new(2, 0.4, 2) - seat.CFrame = PlotBuilder.seatCFrame(self.slot.cf, c.seat) * CFrame.new(0, 0.2, 0) + seat.CFrame = PlotBuilder.seatCFrame(self.slot.cf, self.layout, c.seat) * CFrame.new(0, 0.2, 0) seat.Parent = self.slot.refs.dynamic local bubble = Build.orderBubble(seat, c.menu, 64, Vector3.new(0, 5, 0)) bubble.Name = "Order" @@ -656,18 +1345,28 @@ function PlotController.destroy(self: PlotController) self:releaseGuest(id, c.guest, "closed") end end - for _, c in self.connections do - c:Disconnect() - end - self.slot.refs.stove:SetAttribute("OwnerId", nil) - self.slot.refs.stove:SetAttribute("CookMenu", nil) + local refs = self.slot.refs + refs.stove:SetAttribute("OwnerId", nil) + refs.stove:SetAttribute("CookMenu", nil) self.guideValue:Destroy() for _, m in self.handModels do m:Destroy() end - self.slot.refs.dynamic:ClearAllChildren() - self.slot.refs.upgrades:ClearAllChildren() - for _, key in { "OwnerId", "OwnerName", "Npc", "Level" } do + refs.dynamic:ClearAllChildren() + refs.building:ClearAllChildren() + refs.furniture:ClearAllChildren() + local extras = refs.stall:FindFirstChild("Extras") + if extras then + extras:Destroy() + end + local entrance = refs.upgrades:FindFirstChild("Entrance") + if entrance then + entrance:Destroy() + end + PlotBuilder.placeStall(refs, self.slot.cf, Floor.default().stove) + for _, key in + { "OwnerId", "OwnerName", "Npc", "Level", "Stage", "Menus", "PriceMult", "ShopName", "Rainbow", "Design" } + do self.slot.model:SetAttribute(key, nil) end end diff --git a/bunsik-tycoon/src/server/PlotLayout.luau b/bunsik-tycoon/src/server/PlotLayout.luau deleted file mode 100644 index 997a1b8..0000000 --- a/bunsik-tycoon/src/server/PlotLayout.luau +++ /dev/null @@ -1,52 +0,0 @@ ---!strict --- 부지 한 칸의 배치 좌표(부지 기준 상대 좌표, 단위 stud). --- 부지 원점은 바닥 가운데, +Z가 길(입구) 쪽입니다. 포장마차는 -Z 쪽 끝에 있습니다. - -local PlotLayout = {} - -PlotLayout.SIZE = Vector3.new(72, 0, 80) -PlotLayout.FLOOR_Y = 0.2 -- 부지 바닥 윗면 높이 - --- 조리대(플레이어가 서서 누르는 곳은 조리대 앞 +Z 쪽) -PlotLayout.STALL_Z = -26 -PlotLayout.STOVE = Vector3.new(-3, 0, -26) -PlotLayout.COUNTER = Vector3.new(5.5, 0, -26) -PlotLayout.HELPER = Vector3.new(-3, 0, -30) - --- 손님 입구와 통로 -PlotLayout.ENTRANCE = Vector3.new(0, 0, 32) -PlotLayout.PLAYER_SPAWN = Vector3.new(0, 0, -16) - --- 테이블 위치(1~4: 포장마차 앞, 5~8: 실내 확장 뒤 양옆) -PlotLayout.TABLES = { - Vector3.new(-9, 0, -10), - Vector3.new(9, 0, -10), - Vector3.new(-9, 0, 4), - Vector3.new(9, 0, 4), - Vector3.new(-25, 0, -10), - Vector3.new(25, 0, -10), - Vector3.new(-25, 0, 4), - Vector3.new(25, 0, 4), -} - -PlotLayout.STOOL_OFFSET = 3.5 -- 의자는 테이블에서 +Z 쪽으로 -PlotLayout.LANE_OFFSET = 3 -- 걷는 통로는 의자 뒤로 - -function PlotLayout.stool(seat: number): Vector3 - local t = PlotLayout.TABLES[seat] - return t + Vector3.new(0, 0, PlotLayout.STOOL_OFFSET) -end - --- 입구 -> 가운데 통로 -> 줄 통로 -> 의자 순서로 걷는 길(상대 좌표) -function PlotLayout.pathTo(seat: number): { Vector3 } - local stool = PlotLayout.stool(seat) - local laneZ = stool.Z + PlotLayout.LANE_OFFSET - return { - PlotLayout.ENTRANCE, - Vector3.new(0, 0, laneZ), - Vector3.new(stool.X, 0, laneZ), - stool, - } -end - -return PlotLayout diff --git a/bunsik-tycoon/src/server/Transfers.luau b/bunsik-tycoon/src/server/Transfers.luau new file mode 100644 index 0000000..5d0da22 --- /dev/null +++ b/bunsik-tycoon/src/server/Transfers.luau @@ -0,0 +1,61 @@ +--!strict +-- 옆 가게 손님 주고받기(홍보, 손님 쫓아내기). 손님 NPC는 원래 가게에서 일어나 길을 따라 걸어옵니다. + +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Economy = require(ReplicatedStorage.Shared.Economy) +local Shop = require(ReplicatedStorage.Shared.Shop) + +local PlotController = require(script.Parent.PlotController) + +type Controller = PlotController.PlotController + +local Transfers = {} + +-- 홍보: 옆 가게들에서 아직 음식을 못 받은 손님을 빈자리만큼(최대 PROMOTE_MAX) 데려옵니다. +-- NPC 이웃 가게 손님부터 데려와서 다른 플레이어 가게는 되도록 건드리지 않습니다. +-- 돌려주는 값: 데려온 수, 실패 이유("full" | "none") +function Transfers.promote(target: Controller, sources: { Controller }): (number, string?) + local free = Shop.freeSeatCount(target.shop) + if free <= 0 then + return 0, "full" + end + local want = math.min(Economy.PROMOTE_MAX, free) + local ordered = table.clone(sources) + table.sort(ordered, function(a, b) + local an = if a.opts.npc then 0 else 1 + local bn = if b.opts.npc then 0 else 1 + if an ~= bn then + return an < bn + end + -- 가까운 가게부터 + local ta = (a.slot.cf.Position - target.slot.cf.Position).Magnitude + local tb = (b.slot.cf.Position - target.slot.cf.Position).Magnitude + return ta < tb + end) + local got = 0 + for _, src in ordered do + if got >= want then + break + end + if src ~= target and not src.destroyed then + local list = src:giveCustomers(want - got) + got += target:receiveCustomers(list) + end + end + if got == 0 then + return 0, "none" + end + return got, nil +end + +-- 손님 쫓아내기: 그 가게의 아직 음식을 못 받은 NPC 손님이 모두 일어납니다. +-- 우리 가게 빈자리만큼은 우리 가게로 오고, 나머지는 길로 나갑니다. +-- 돌려주는 값: 쫓아낸 수, 우리 가게로 온 수 +function Transfers.kick(kicker: Controller, victim: Controller): (number, number) + local list = victim:giveCustomers(math.huge) + local got = kicker:receiveCustomers(list) + return #list, got +end + +return Transfers diff --git a/bunsik-tycoon/src/shared/Floor.luau b/bunsik-tycoon/src/shared/Floor.luau index 3c20f5d..6900d73 100644 --- a/bunsik-tycoon/src/shared/Floor.luau +++ b/bunsik-tycoon/src/shared/Floor.luau @@ -32,6 +32,7 @@ Floor.X0 = -33 Floor.X1 = 33 Floor.Z0 = -37 Floor.Z1 = 19 +Floor.BASE_Y = 0.2 -- 부지 바닥 윗면 높이(부지 원점 기준) Floor.FLOOR2_Y = 15 -- 2층 바닥 높이(1층 바닥 기준) Floor.CELL = 1 @@ -468,7 +469,19 @@ end -- 새 테이블(+의자 1개)을 놓을 곳을 찾아 layout에 넣습니다. 놓으면 테이블 번호를 돌려줍니다. function Floor.addTable(layout: Layout, stage: number): number? - local floors = if stage >= 3 then { 1, 2 } else { 1 } + local floors: { number } = { 1 } + if stage >= 3 then + -- 2층 건물이면 테이블이 적은 층부터 채웁니다(2층이 바로 쓰이게). + local n1, n2 = 0, 0 + for _, t in layout.tables do + if t.f == 2 then + n2 += 1 + else + n1 += 1 + end + end + floors = if n2 < n1 then { 2, 1 } else { 1, 2 } + end for _, f in floors do for _, c in candidates(f) do local test = Floor.clone(layout) @@ -515,7 +528,7 @@ function Floor.addDecor(layout: Layout, stage: number, kind: string): number? if not Floor.FOOTPRINT[kind] or kind == "Stove" then return nil end - local floors = if stage >= 3 then { 1, 2 } else { 1 } + local floors: { number } = if stage >= 3 then { 1, 2 } else { 1 } for _, f in floors do -- 소품은 벽 쪽부터 찾습니다. local list = {} @@ -636,7 +649,7 @@ function Floor.repair(layout: Layout, stage: number): Layout end end local placed = false - local floors = if stage >= 3 then { 2, 1 } else { 1 } + local floors: { number } = if stage >= 3 then { 2, 1 } else { 1 } for _, f in floors do if placed then break diff --git a/bunsik-tycoon/src/shared/Products.luau b/bunsik-tycoon/src/shared/Products.luau index 9d2c1f0..54be71e 100644 --- a/bunsik-tycoon/src/shared/Products.luau +++ b/bunsik-tycoon/src/shared/Products.luau @@ -4,4 +4,10 @@ return { DOUBLE_MONEY_PASS = 2026574937, MONEY_BOOST_PRODUCT = 3717970589, + RAINBOW_NAME_PASS = 0, -- 가게 이름 무지개 + CANDY_DESIGN_PASS = 0, -- 건물 디자인: 사탕 궁전 + HANOK_DESIGN_PASS = 0, -- 건물 디자인: 한옥 분식집 + RUSH_PRODUCT = 0, -- 손님 러시 10분(소모성) + KICK_PRODUCT = 0, -- 옆 가게 손님 쫓아내기 1회(소모성) + PROMOTE_AD_PRODUCT = 0, -- 보상형 광고 보상(홍보 1회). 광고 보상은 개발자 상품으로 받습니다 } diff --git a/bunsik-tycoon/src/shared/Recipes.luau b/bunsik-tycoon/src/shared/Recipes.luau index 2e5346c..3495854 100644 --- a/bunsik-tycoon/src/shared/Recipes.luau +++ b/bunsik-tycoon/src/shared/Recipes.luau @@ -22,7 +22,7 @@ export type Recipe = { steps: { Step }, } -Recipes.BASE_COOK = 2.5 -- Economy.START.cook과 같음 +Recipes.BASE_COOK = 2.5 -- Economy.START_COOK과 같음 Recipes.RUB_UNIT = 260 -- 문지르기 1번 = 기준 단위 260만큼 움직이기 Recipes.LIST = { diff --git a/bunsik-tycoon/src/shared/Shop.luau b/bunsik-tycoon/src/shared/Shop.luau index 4b4c8d3..c063be3 100644 --- a/bunsik-tycoon/src/shared/Shop.luau +++ b/bunsik-tycoon/src/shared/Shop.luau @@ -9,8 +9,10 @@ local Economy: typeof(require(script.Parent.Economy)) = if script then require(script.Parent.Economy) else (require :: any)("./Economy") -type Stats = Economy.Stats -type Levels = Economy.Levels +type Stats = typeof(Economy.stats({}, 1)) +type Levels = { [string]: number } +type Staff = { [string]: number } +type Level = typeof(Economy.TRACKS[1].levels[1]) export type CustomerState = "walking" | "waiting" | "eating" @@ -54,7 +56,7 @@ export type Shop = { hand: { string }, counter: { string }, trips: { [number]: Trip }, -- 서빙 알바 번호 -> 나르는 중 - staff: Economy.Staff, + staff: Staff, strike: boolean, -- 시급이 모자라 알바생이 쉬는 중 wageDue: number, -- 다음 시급 주는 시각 cookNext: { [number]: number }, -- 요리 알바 번호 -> 다음에 만들 수 있는 시각 @@ -71,7 +73,7 @@ export type Options = { money: number, levels: Levels?, seats: number?, - staff: Economy.Staff?, + staff: Staff?, now: number, rushLeft: number?, } @@ -81,7 +83,7 @@ local Shop = {} function Shop.new(opts: Options): Shop local levels = Economy.cleanLevels(opts.levels) local seats = math.max(1, opts.seats or 1) - local staff: Economy.Staff = {} + local staff: Staff = {} for _, r in Economy.ROLES do local n = if opts.staff then opts.staff[r.id] else nil staff[r.id] = if typeof(n) == "number" then math.clamp(math.floor(n), 0, r.max) else 0 @@ -461,7 +463,7 @@ end -- 업그레이드 갈래의 다음 단계를 삽니다. 성공하면 산 단계(Level)를 돌려줍니다. -- 실패 이유: "max"(다 삼), "stage"(건물 단계 부족), "money" -function Shop.buyLevel(self: Shop, trackId: string): (Economy.Level?, string?) +function Shop.buyLevel(self: Shop, trackId: string): (Level?, string?) local nl = Economy.nextLevel(self.levels, trackId) if not nl then return nil, "max" diff --git a/bunsik-tycoon/tests/Recipes.spec.luau b/bunsik-tycoon/tests/Recipes.spec.luau index 3beabe8..a45faa3 100644 --- a/bunsik-tycoon/tests/Recipes.spec.luau +++ b/bunsik-tycoon/tests/Recipes.spec.luau @@ -3,7 +3,7 @@ local Economy = require("../src/shared/Economy") local Recipes = require("../src/shared/Recipes") local T = require("./check") -T.eq(Recipes.BASE_COOK, Economy.START.cook, "기준 화구 수준 = 처음 조리 시간") +T.eq(Recipes.BASE_COOK, Economy.START_COOK, "기준 화구 수준 = 처음 조리 시간") for _, menu in Economy.MENU_ORDER do local r = Recipes.LIST[menu] T.check(r ~= nil, `{menu} 요리 과정 있음`) diff --git a/bunsik-tycoon/tests/cloud/server.luau b/bunsik-tycoon/tests/cloud/server.luau new file mode 100644 index 0000000..3d62096 --- /dev/null +++ b/bunsik-tycoon/tests/cloud/server.luau @@ -0,0 +1,512 @@ +-- 로블록스 서버(Open Cloud Luau Execution)에서 돌리는 서버 통합 테스트(2026-10-14 개편 구조). +-- python3 tools/cloud.py run tests/cloud/server.luau --version <저장 버전> +-- 플레이어가 없고 물리가 돌지 않으며 Script가 자동 실행되지 않으므로, +-- 모듈을 직접 불러 가짜 플레이어(Folder)와 가상 시계로 가게를 돌립니다. + +local HttpService = game:GetService("HttpService") +local Players = game:GetService("Players") +local ReplicatedStorage = game:GetService("ReplicatedStorage") +local ServerScriptService = game:GetService("ServerScriptService") + +local Server = ServerScriptService.Server +local failures = {} +local count = 0 +local function check(cond: any, msg: string) + count += 1 + if not cond then + table.insert(failures, msg) + print("FAIL " .. msg) + end +end +local function eq(a: any, b: any, msg: string) + check(a == b, `{msg} (기대 {tostring(b)}, 실제 {tostring(a)})`) +end +local function section(name: string) + print("== " .. name) +end + +local Economy = require(ReplicatedStorage.Shared.Economy) +local Floor = require(ReplicatedStorage.Shared.Floor) +local Icons = require(ReplicatedStorage.Shared.Icons) +local Recipes = require(ReplicatedStorage.Shared.Recipes) +local Shop = require(ReplicatedStorage.Shared.Shop) + +section("맵") +local World = require(Server.World) +local slots = World.build() +eq(#slots, 6, "부지 6칸") +for i, s in slots do + check(s.refs.stove and s.refs.stove:IsDescendantOf(workspace), `부지 {i} 조리대`) + check(typeof(s.model:GetAttribute("Origin")) == "CFrame", `부지 {i} Origin 속성`) + for j, o in slots do + if i < j then + check((s.cf.Position - o.cf.Position).Magnitude >= 76, `부지 {i},{j} 겹치지 않음`) + end + end + local front = s.cf:PointToWorldSpace(Vector3.new(0, 0, 40)) + check(math.abs(front.Z) < math.abs(s.cf.Position.Z), `부지 {i} 입구가 길 쪽`) +end + +section("NPC") +local Npc = require(Server.Npc) +Npc.preload() +local npc = Npc.spawnCustomer(workspace, CFrame.new(0, 5, 0), Random.new(1)) +check(npc.model:FindFirstChild("HumanoidRootPart") ~= nil, "손님 NPC 몸") +check(npc.tracks.walk ~= nil and npc.tracks.sit ~= nil and npc.tracks.idle ~= nil, "NPC 애니메이션 3종 로드") +npc.model:Destroy() + +local PlotController = require(Server.PlotController) +local PlotBuilder = require(Server.PlotBuilder) +local Data = require(Server.Data) +local function newData() + local d = table.clone(Data.TEMPLATE) + d.PurchaseIdCache = {} + d.Levels = {} + d.Staff = {} + d.Layout = {} + return d +end +local function count_(folder: Instance, prefix: string): number + local n = 0 + for _, ch in folder:GetChildren() do + if string.sub(ch.Name, 1, #prefix) == prefix then + n += 1 + end + end + return n +end + +section("가게 1: 튜토리얼 흐름") +local owner = Instance.new("Folder") +owner.Name = "FakePlayer" +owner.Parent = ServerScriptService +local notes = {} +local data = newData() +local c = PlotController.new(slots[1], owner, { + userId = 111, + displayName = "Tester", + data = data, + now = 0, + notify = function(k, args) + table.insert(notes, { k, args }) + end, +}) +local function noted(key: string): boolean + for _, n in notes do + if n[1] == key then + return true + end + end + return false +end +eq(owner:GetAttribute("Tut"), 1, "튜토리얼 1단계") +eq(owner:GetAttribute("Money"), 0, "돈 0") +eq(owner:GetAttribute("Stage"), 1, "포장마차") +eq(owner:GetAttribute("Seats"), 1, "의자 1") +eq(owner:GetAttribute("Tables"), 1, "테이블 1") +eq(owner:GetAttribute("Levels"), "Stage=0,Menu=0,Price=0,Speed=0,Stove=0,Tray=0,Staff=0", "갈래 레벨 속성") +check(typeof(owner:GetAttribute("Layout")) == "string", "배치 JSON 속성") +local decoded = Floor.clean(HttpService:JSONDecode(owner:GetAttribute("Layout"))) +eq(#decoded.chairs, 1, "배치 JSON 읽기") +eq(slots[1].model:GetAttribute("OwnerId"), 111, "부지 주인 속성") +eq(slots[1].model:GetAttribute("Menus"), "Tteokbokki", "메뉴판 속성") +local furniture = slots[1].refs.furniture +check( + furniture:FindFirstChild("Table1") ~= nil and furniture:FindFirstChild("Chair1") ~= nil, + "테이블·의자 모형" +) +eq(furniture.Table1:GetAttribute("ItemKind"), "table", "꾸미기 선택 속성") +eq(#slots[1].refs.building:GetChildren(), 0, "포장마차 단계엔 건물 없음") +c:update(0) +local dyn = slots[1].refs.dynamic +eq(count_(dyn, "Customer"), 1, "첫 손님 NPC 1명") +local bubble = dyn:FindFirstChild("Customer"):FindFirstChild("Order", true) +local icon = bubble and bubble:FindFirstChild("Icon", true) :: ImageLabel? +eq(icon and icon.ImageRectOffset, Icons.OFFSET.Tteokbokki, "말풍선에 떡볶이 그림") +eq(slots[1].refs.stove:GetAttribute("CookMenu"), "Tteokbokki", "조리대에 떡볶이 주문") +local walk = c.shop.seatWalk[1] +check(walk and walk >= 1.5 and walk <= 9, `자리까지 걷는 시간 ({walk})`) +c:update(walk + 0.1) +eq(c.shop.customers[1].state, "waiting", "손님이 앉음") +eq(c:finishCook("Tteokbokki", 10), nil, "메뉴를 고르지 않고 완성만 보내면 거절") +check(c:startCook("Tteokbokki", 10), "주문 있는 메뉴로 시작") +local minT = Recipes.minTime("Tteokbokki", c.shop.stats.cook) +eq(c:finishCook("Tteokbokki", 10 + minT * 0.5), nil, "조리 과정 최소 시간보다 빠르면 거절") +local t = walk + 0.1 +check(c:startCook("Tteokbokki", t - Recipes.expectedTime("Tteokbokki", c.shop.stats.cook)), "다시 시작") +eq(c:finishCook("Tteokbokki", t), "Tteokbokki", "정상 시간이면 조리") +eq(owner:GetAttribute("Tut"), 2, "튜토리얼 2단계") +-- 접시가 똑바로 놓이는지(예전에 세로로 서던 문제) +local held = dyn:FindFirstChild("Dish_Tteokbokki") :: Model +check(held ~= nil, "접시 모형") +eq(c:serve(1), 15, "서빙 15원") +local onTable = dyn:FindFirstChild("Dish_Tteokbokki") :: Model +local up = onTable and onTable:GetPivot().UpVector +check(up and up.Y > 0.99, `테이블 위 접시가 똑바로 놓임 (UpVector.Y {up and up.Y})`) +local plate = onTable and onTable:FindFirstChild("Plate") :: BasePart? +check(plate and math.abs(plate.CFrame.RightVector.Y) > 0.99, "접시 원기둥 축이 세로(평평한 접시)") +eq(owner:GetAttribute("Tut"), 3, "튜토리얼 3단계") +-- 첫 추천 구매: 의자(10원) +local offers = Economy.offers(c.shop.levels, #c.layout.tables, #c.layout.chairs) +eq(offers[1].id, "Seat", "처음 추천은 의자") +check(c:buyOffer("Seat"), "의자 구매") +eq(owner:GetAttribute("Seats"), 2, "의자 2") +eq(c.shop.stats.seats, 2, "손님 자리 2") +check(furniture:FindFirstChild("Chair2") ~= nil, "의자 모형") +eq(owner:GetAttribute("Tut"), 0, "튜토리얼 끝") +eq(data.TutorialDone, true, "튜토리얼 저장") +eq(#data.Layout.chairs, 2, "세이브에 배치") + +section("가게 1: 갈래 업그레이드") +c:addMoney(40) +check(c:upgrade("Menu"), "김밥 해금") +check(slots[1].refs.stall.Extras:FindFirstChild("Menu_Gimbap") ~= nil, "김밥 진열대 모형") +check(noted("newMenu"), "새 메뉴 알림") +eq(slots[1].model:GetAttribute("Menus"), "Tteokbokki,Gimbap", "메뉴판 속성에 김밥") +local ok, why = c:upgrade("Tray") +check(not ok and why == "stage", "쟁반은 실내 분식집부터") +check(noted("needStage"), "건물 단계 알림") +c:addMoney(1_000_000) +check(c:upgrade("Speed"), "손님 속도") +check(c:upgrade("Speed"), "손님 속도 2") +check(slots[1].refs.stall.Extras:FindFirstChild("Part") ~= nil, "수레 장식") +check(c:upgrade("Stage"), "실내 분식집 확장") +eq(owner:GetAttribute("Stage"), 2, "2단계") +check(noted("expanded"), "확장 알림") +check(slots[1].refs.building:FindFirstChild("Roof") ~= nil, "실내 건물 지붕") +check(slots[1].refs.building:FindFirstChild("Ceiling") ~= nil, "실내 건물 천장") +check(slots[1].refs.building:FindFirstChild("RoofSign") ~= nil, "지붕 간판") + +section("가게 1: 꾸미기(테이블·의자·소품·옮기기)") +for _ = 1, 4 do + check(c:buyTable(), "테이블 구매") +end +eq(#c.layout.tables, 5, "테이블 5") +for _ = 1, 5 do + check(c:buySeat(nil), "의자 구매") +end +eq(owner:GetAttribute("Seats"), 11, "의자 11") +eq(Floor.validate(c.layout, 2), nil, "배치 검사 통과") +check(c:buyDecor("Plant"), "화분 구매") +check(c:buyDecor("Balloons"), "풍선 구매") +check(furniture:FindFirstChild("Decor1") ~= nil, "소품 모형") +-- 옮기기 +local t1 = c.layout.tables[1] +check( + c:move({ kind = "table", i = 1, x = 25, z = 10 }) or c:move({ kind = "table", i = 1, x = 26, z = 12 }), + "테이블 옮기기" +) +check(c.layout.tables[1].x ~= t1.x, "옮긴 자리 저장") +check(not c:move({ kind = "table", i = 1, x = 0, z = 17 }), "문 앞에는 못 놓음") +check(noted("placeFail"), "못 놓는 이유 알림") +local stallBefore = slots[1].refs.stall:GetPivot().Position +check(c:move({ kind = "stove", i = 1, x = 4, z = -28, r = 0 }), "조리대 옮기기") +check((slots[1].refs.stall:GetPivot().Position - stallBefore).Magnitude > 3, "수레 모형이 옮겨짐") +check(slots[1].refs.stove:IsDescendantOf(slots[1].refs.stall), "조리대 인스턴스는 그대로(버튼 유지)") +-- 의자 1을 빈 쪽이 있는 다른 테이블로 옮기기(테이블 1은 네 쪽이 다 찼을 수 있음) +local sideMoved = false +for ti in c.layout.tables do + for side = 1, 4 do + if not sideMoved and ti ~= c.layout.chairs[1].t then + sideMoved = c:move({ kind = "chair", i = 1, x = side, z = ti }) + end + end +end +check(sideMoved, "의자를 다른 테이블·다른 쪽으로 옮기기") +c.shop.money = 0 +check(not c:buyTable(), "돈 모자라면 테이블 못 삼") +check(noted("notEnough"), "모자란 돈 알림") +c:addMoney(1_000_000) + +section("가게 1: 디자인") +check(c:setDesign("Mint"), "무료 디자인") +eq(slots[1].model:GetAttribute("Design"), "Mint", "디자인 속성") +local okCandy, whyCandy = c:setDesign("Candy") +check(not okCandy and whyCandy == "locked", "유료 디자인은 게임패스가 있어야") +c:setDesignOwned("Candy", true) +check(c:setDesign("Candy"), "게임패스 있으면 유료 디자인") +check(slots[1].refs.building:FindFirstChild("Roof") ~= nil, "디자인 바꾼 건물") +c:setDesignOwned("Hanok", true) +check(c:setDesign("Hanok"), "한옥 디자인") + +section("가게 1: 이름·무지개") +c:setShopName("떡볶이 천국", "떡볶이 천국") +eq(slots[1].model:GetAttribute("ShopName"), "떡볶이 천국", "모두에게 보이는 이름") +eq(data.ShopName, "떡볶이 천국", "세이브에 이름") +eq(slots[1].model:GetAttribute("Rainbow"), false, "게임패스 없으면 무지개 아님") +c:setRainbowOwned(true) +eq(slots[1].model:GetAttribute("Rainbow"), true, "게임패스 있으면 무지개") +c:setRainbow(false) +eq(slots[1].model:GetAttribute("Rainbow"), false, "무지개 끄기") +local Game = require(Server.Game) +eq(Game._cleanName(" 가나다\n라 "), "가나다 라", "이름 공백 정리") +eq(utf8.len(Game._cleanName(string.rep("가", 30)) :: string), Economy.NAME_MAX, "이름 길이 자르기") + +section("가게 1: 2층") +check(c:upgrade("Stage"), "2층 확장") +eq(owner:GetAttribute("Stage"), 3, "3단계") +check(noted("floor2"), "2층 알림") +check(slots[1].refs.building:FindFirstChild("Floor2") ~= nil, "2층 바닥") +eq(Floor.validate(c.layout, 3), nil, "2층 건물에 맞게 배치 정리") +local before2 = #c.layout.tables +local placed2 = false +for _ = 1, 7 do + if c:buyTable() then + placed2 = true + end +end +check(placed2, "2층 건물에서 테이블 추가") +local on2 = nil +for i, tb in c.layout.tables do + if tb.f == 2 then + on2 = i + end +end +check(#c.layout.tables > before2, "테이블 늘어남") +check(on2 ~= nil, "2층에 테이블") +if on2 then + local chair2 = nil + for ci, ch in c.layout.chairs do + if ch.t == on2 then + chair2 = ci + end + end + local seatCf = PlotBuilder.seatCFrame(slots[1].cf, c.layout, chair2) + check(seatCf.Position.Y > slots[1].cf.Position.Y + Floor.FLOOR2_Y, "2층 의자 높이") + local path = c:entryPath(chair2) + local top = 0 + for _, p in path do + top = math.max(top, p.Y) + end + check(top > slots[1].cf.Position.Y + Floor.FLOOR2_Y - 1, "2층 손님 길이 계단을 올라감") +end + +section("가게 1: 알바생") +check(not c:hire("Cook"), "알바생 기능 전에는 고용 못 함") +check(noted("staffLocked"), "잠김 알림") +check(c:upgrade("Staff"), "알바생 기능") +check(c:hire("Cook"), "요리 알바") +check(c:hire("Server"), "서빙 알바") +check(c:hire("Promoter"), "홍보 알바") +eq(owner:GetAttribute("Staff"), "Cook=1,Server=1,Promoter=1", "알바 속성") +check(owner:GetAttribute("Wage") > 0, "시급 합계") +check(dyn:FindFirstChild("Staff_Cook1") ~= nil, "요리 알바 NPC") +check(dyn:FindFirstChild("Staff_Server1") ~= nil, "서빙 알바 NPC") +check(dyn:FindFirstChild("Staff_Promoter1") ~= nil, "홍보 알바 NPC") +check(c:fire("Promoter"), "해고") +eq(dyn:FindFirstChild("Staff_Promoter1"), nil, "해고하면 NPC 사라짐") + +section("가게 1: 가상 5분 영업(서빙 알바가 나름)") +local now = 100 +c.shop.now = now +c.shop.nextSpawn = now +local served0 = c.shop.served +local money0 = c.shop.money +local delivered = false +while now < 400 do + now += 0.1 + c:update(now) + if c.tripDish[1] then + delivered = true + end +end +local served = c.shop.served - served0 +print(`5분 영업(알바만): 서빙 {served}회, 돈 {c.shop.money - money0}`) +check(delivered, "서빙 알바가 접시를 들고 감") +check(served > 20, "알바만으로 5분 동안 20회 넘게 서빙") +check(c.shop.money > money0, "시급을 내고도 돈이 늘어남") +task.wait(Economy.WALK_IN + 2) +check(count_(dyn, "Customer") <= Economy.seatCap(3) + 6, "손님 NPC가 쌓이지 않음") + +section("가게 2: 예전 세이브 옮기기 + 캐릭터 자동 서빙") +local charModel = + Players:CreateHumanoidModelFromDescription(Instance.new("HumanoidDescription"), Enum.HumanoidRigType.R15) +charModel.Name = "FakeCharacter" +charModel.Parent = workspace +local hrp = charModel:FindFirstChild("HumanoidRootPart") :: BasePart +hrp.Anchored = true +local owner2 = Instance.new("Folder") +owner2.Parent = ServerScriptService +local old = newData() +old.Bought = 8 -- 예전 구조: 알바생까지 산 상태 +old.Money = 5 +old.Version = nil +Data.migrate(old, 1) +eq(old.Version, 2, "버전 2로 옮김") +eq(old.Levels.Staff, 1, "알바생 기능") +eq(old.Staff.Cook, 1, "요리 알바 1명") +eq(#old.Layout.chairs, 3, "자리 3") +local c2 = PlotController.new(slots[2], owner2, { + userId = 222, + displayName = "Tester2", + data = old, + now = 0, + getCharacter = function() + return charModel + end, +}) +eq(owner2:GetAttribute("Money"), 5, "저장된 돈 불러옴") +c2:update(0) +eq(#c2.shop.counter, 1, "요리 알바가 카운터에 접시") +hrp.CFrame = slots[2].refs.counter.CFrame + Vector3.new(0, 3, 4) +c2:update(0.2) +eq(#c2.shop.hand, 1, "카운터 근처에서 자동으로 집음") +eq(count_(charModel, "Dish_"), 1, "손에 접시 모형") +local held2 = charModel:FindFirstChild("Dish_Tteokbokki") :: Model? +check(held2 and held2:GetPivot().UpVector.Y > 0.99, "손에 든 접시도 똑바로") +c2:update(5) +local seat = c2.shop.customers[1].seat +hrp.CFrame = PlotBuilder.seatCFrame(slots[2].cf, c2.layout, seat) + Vector3.new(0, 2, 2) +local before = c2.shop.money +c2:update(5.2) +check(c2.shop.money > before, "손님 근처에서 자동 서빙") +c2:rebuildHand() + +section("홍보·쫓아내기(옆 가게 손님 데려오기)") +local Neighbor = require(Server.Neighbor) +local Transfers = require(Server.Transfers) +local nb = Neighbor.open(slots[5], 0) +eq(slots[5].model:GetAttribute("Npc"), 5, "이웃 가게 속성") +check(slots[5].refs.dynamic:FindFirstChild("Keeper") ~= nil, "사장님 NPC") +-- 이웃 가게에 손님이 찰 때까지 +local nt = 0 +while nt < 15 do + nt += 0.1 + nb.controller:update(nt) +end +local waiting = 0 +for _, cust in nb.controller.shop.customers do + if cust.state ~= "eating" then + waiting += 1 + end +end +check(waiting >= 1, `이웃 가게 손님 ({waiting})`) +-- 가게 2 자리를 비워 둡니다. +for id in c2.shop.customers do + c2.shop.customers[id] = nil +end +table.clear(c2.shop.seatTaken) +c2.shop.now = 20 +local got = Transfers.promote(c2, { nb.controller }) +check(got >= 1, `홍보로 손님이 옴 ({got})`) +local transferred = 0 +for _, cust in c2.shop.customers do + if cust.transfer then + transferred += 1 + check(c2.views[cust.id] and c2.views[cust.id].npc ~= nil, "데려온 손님 NPC") + check( + c2.views[cust.id].npc.model:IsDescendantOf(slots[2].refs.dynamic), + "NPC가 우리 가게 폴더로 옮겨짐" + ) + end +end +eq(transferred, got, "데려온 손님 수") +-- 데려온 손님도 걸어와서 앉음 +local tt = 20 +while tt < 40 do + tt += 0.2 + c2:update(tt) +end +for _, cust in c2.shop.customers do + if cust.transfer then + check(cust.state ~= "walking", "데려온 손님이 자리에 도착") + end +end +-- 자리가 꽉 차면 홍보 실패 +local full = Shop.freeSeatCount(c2.shop) +for _ = 1, full do + Shop.addTransfer(c2.shop, "Tteokbokki", 1) +end +local got2, why2 = Transfers.promote(c2, { nb.controller }) +eq(got2, 0, "빈자리 없으면 못 데려옴") +eq(why2, "full", "이유 full") +-- 쫓아내기: 가게 1(빈자리 많음)이 이웃 가게 손님을 쫓아냄 +while nt < 60 do + nt += 0.1 + nb.controller:update(nt) +end +c.shop.now = now +local kicked, came = Transfers.kick(c, nb.controller) +print(`쫓아내기: {kicked}명 쫓아냄, {came}명 옴`) +check(kicked >= 0 and came <= kicked, "쫓아낸 수 >= 온 수") +for _, cust in nb.controller.shop.customers do + check(cust.state == "eating", "이웃 가게에는 먹는 손님만 남음") +end +task.wait(5) +c2:destroy() +charModel:Destroy() +Neighbor.close(nb) + +section("다른 플레이어가 손님으로 방문") +local guestChar = + Players:CreateHumanoidModelFromDescription(Instance.new("HumanoidDescription"), Enum.HumanoidRigType.R15) +guestChar.Parent = workspace +local hostOwner = Instance.new("Folder") +hostOwner.Parent = ServerScriptService +local hostData = newData() +hostData.TutorialDone = true +hostData.Layout = Floor.default() +Floor.addChair(hostData.Layout, 1) +Floor.addChair(hostData.Layout, 1) +local guestEvents = {} +local host = PlotController.new(slots[3], hostOwner, { + userId = 333, + displayName = "Host", + data = hostData, + now = 0, + guestEvent = function(kind, userId, info) + table.insert(guestEvents, { kind, userId, info }) + end, +}) +eq(host.shop.stats.seats, 3, "자리 3") +local gc = host:addGuest(444, guestChar) +check(gc ~= nil, "빈자리에 손님으로 앉음") +host.shop.now = 0.5 +eq(host:cook(), gc and gc.menu, "손님 메뉴 조리") +local guestEarn = host:serve(gc.id) +eq(guestEarn, Economy.dishPrice(gc.menu, host.shop.stats, 1) * Economy.GUEST_MULT, "손님 접시는 2배 값") +eq(guestEvents[1] and guestEvents[1][1], "served", "손님에게 서빙 소식") +host:update(0.6 + Economy.EAT + 0.5) +eq(guestEvents[2] and guestEvents[2][3].reason, "ate", "다 먹고 일어남") +check(host:addGuest(444, guestChar) ~= nil, "다시 앉음") +host:destroy() +eq(guestEvents[#guestEvents][3].reason, "closed", "가게가 닫히면 일어남") +guestChar:Destroy() + +section("이웃 가게 스스로 영업") +local nb2 = Neighbor.open(slots[6], 0) +local n2 = 0 +while n2 < 90 do + n2 += 0.1 + Neighbor.update(nb2, n2) +end +print(`이웃 가게 90초: 서빙 {nb2.controller.shop.served}회`) +check(nb2.controller.shop.served >= 5, "이웃 가게가 스스로 서빙") +Neighbor.close(nb2) +eq(slots[6].model:GetAttribute("Npc"), nil, "닫으면 속성 해제") +eq(#slots[6].refs.dynamic:GetChildren(), 0, "닫으면 가게 비움") +eq(#slots[6].refs.furniture:GetChildren(), 0, "닫으면 배치 물건 비움") + +section("파트 수·Union") +local parts = 0 +for _, d in workspace.BunsikWorld:GetDescendants() do + if d:IsA("BasePart") then + parts += 1 + check(not d:IsA("PartOperation"), "Union 없음(업로드 제한)") + end +end +print("맵 파트 수(가게 1 2층·한옥 포함)", parts) +check(parts < 12000, "파트 12000개 미만") + +section("결제(Game.processReceipt, 플레이어 없음)") +eq( + Game.processReceipt({ PlayerId = 1, PurchaseId = "x", ProductId = 1 }), + Enum.ProductPurchaseDecision.NotProcessedYet, + "플레이어가 없으면 나중에" +) + +c:destroy() +print(`checks: {count}, failures: {#failures}`) +if #failures > 0 then + error(`{#failures} failures:\n` .. table.concat(failures, "\n")) +end