feat(bunsik): MVP 전체 구현 — 맵, 요리·서빙, 손님 NPC, 업그레이드 20개, 세이브, 결제, 한/영 UI
- Shop.luau: 손님·주문·조리·서빙·구매 순수 로직(lune 단위 테스트, 시뮬레이터 공용) - 서버: World(부지 6칸), PlotBuilder(파트 모형), PlotController, Npc(트윈 이동), Data(ProfileStore), Receipts(결제 1회 = 지급 1회), Game - 클라이언트: Hud(돈·다음 업그레이드·목록·결제·언어·튜토리얼), 내 조리대 전용 버튼, 튜토리얼 화살표, 주인 전용 테스트 버튼 - 2단계 업그레이드 10개 추가, 파이썬 시뮬레이터를 실제 로직 기반 tools/sim.luau로 교체 - tools/cloud.py: 업로드, 원격 Luau 실행, 게임패스·개발자 상품 생성, 서버 인원 설정 - tests/cloud/integration.luau: 로블록스 서버 통합 테스트 514개 통과 - check.sh에 luau-lsp 타입 검사 추가, ProfileStore 고정 버전 포함 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
58
bunsik-tycoon/src/client/Guide.luau
Normal file
58
bunsik-tycoon/src/client/Guide.luau
Normal file
@@ -0,0 +1,58 @@
|
||||
--!strict
|
||||
-- 튜토리얼 화살표: 캐릭터에서 목표(조리대, 손님 자리)까지 빛나는 줄과 위에서 통통 튀는 화살표.
|
||||
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local Guide = {}
|
||||
|
||||
function Guide.start(player: Player)
|
||||
local beam = Instance.new("Beam")
|
||||
beam.Color = ColorSequence.new(Color3.fromRGB(255, 230, 60))
|
||||
beam.Width0 = 0.6
|
||||
beam.Width1 = 0.6
|
||||
beam.FaceCamera = true
|
||||
beam.LightEmission = 1
|
||||
beam.Transparency = NumberSequence.new(0.2)
|
||||
beam.Segments = 1
|
||||
local a0 = Instance.new("Attachment")
|
||||
a0.Name = "GuideFrom"
|
||||
local a1 = Instance.new("Attachment")
|
||||
a1.Name = "GuideTo"
|
||||
beam.Attachment0 = a0
|
||||
beam.Attachment1 = a1
|
||||
|
||||
local arrow = Instance.new("BillboardGui")
|
||||
arrow.Name = "GuideArrow"
|
||||
arrow.Size = UDim2.fromOffset(70, 70)
|
||||
arrow.AlwaysOnTop = true
|
||||
arrow.LightInfluence = 0
|
||||
local label = Instance.new("TextLabel")
|
||||
label.Size = UDim2.fromScale(1, 1)
|
||||
label.BackgroundTransparency = 1
|
||||
label.Text = "⬇️"
|
||||
label.TextScaled = true
|
||||
label.Parent = arrow
|
||||
|
||||
RunService.RenderStepped:Connect(function()
|
||||
local value = player:FindFirstChild("Guide") :: ObjectValue?
|
||||
local target = value and value.Value :: BasePart?
|
||||
local char = player.Character
|
||||
local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart?
|
||||
local tut = player:GetAttribute("Tut")
|
||||
if target and root and (tut == 1 or tut == 2) then
|
||||
a0.Parent = root
|
||||
a1.Parent = target
|
||||
beam.Parent = target
|
||||
arrow.Adornee = target
|
||||
arrow.StudsOffset = Vector3.new(0, 3 + math.abs(math.sin(os.clock() * 4)) * 1.5, 0)
|
||||
arrow.Parent = target
|
||||
else
|
||||
beam.Parent = nil
|
||||
arrow.Parent = nil
|
||||
a0.Parent = nil
|
||||
a1.Parent = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return Guide
|
||||
466
bunsik-tycoon/src/client/Hud.luau
Normal file
466
bunsik-tycoon/src/client/Hud.luau
Normal file
@@ -0,0 +1,466 @@
|
||||
--!strict
|
||||
-- 화면 UI: 돈, 다음 업그레이드, 업그레이드 목록, 2배 수익·돈 부스트 버튼, 언어 전환, 안내 문구, 알림.
|
||||
-- 상태는 `state` 인스턴스(실제 게임에서는 Player)의 속성에서 읽습니다. 서버에서도 만들 수 있어서 원격 테스트로 검사합니다.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local Economy = require(Shared:WaitForChild("Economy"))
|
||||
local Locale = require(Shared:WaitForChild("Locale"))
|
||||
local Products = require(Shared:WaitForChild("Products"))
|
||||
|
||||
local Hud = {}
|
||||
|
||||
export type HudHandle = {
|
||||
gui: ScreenGui,
|
||||
refresh: () -> (),
|
||||
notify: (key: string, args: { [string]: any }?) -> (),
|
||||
setScale: (number) -> (),
|
||||
destroy: () -> (),
|
||||
}
|
||||
|
||||
local ORANGE = Color3.fromRGB(255, 130, 50)
|
||||
local GREEN = Color3.fromRGB(70, 190, 90)
|
||||
local GRAY = Color3.fromRGB(150, 150, 150)
|
||||
local DARK = Color3.fromRGB(45, 35, 35)
|
||||
local CREAM = Color3.fromRGB(255, 248, 235)
|
||||
|
||||
local function corner(parent: Instance, r: number)
|
||||
local c = Instance.new("UICorner")
|
||||
c.CornerRadius = UDim.new(0, r)
|
||||
c.Parent = parent
|
||||
end
|
||||
|
||||
local function stroke(parent: Instance, color: Color3, thickness: number): UIStroke
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = color
|
||||
s.Thickness = thickness
|
||||
s.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
s.Parent = parent
|
||||
return s
|
||||
end
|
||||
|
||||
local function frame(parent: Instance, name: string, size: UDim2, pos: UDim2, anchor: Vector2, color: Color3?): Frame
|
||||
local f = Instance.new("Frame")
|
||||
f.Name = name
|
||||
f.Size = size
|
||||
f.Position = pos
|
||||
f.AnchorPoint = anchor
|
||||
f.BackgroundColor3 = color or CREAM
|
||||
f.BackgroundTransparency = if color then 0 else 1
|
||||
f.BorderSizePixel = 0
|
||||
f.Parent = parent
|
||||
return f
|
||||
end
|
||||
|
||||
local function text(parent: Instance, name: string, size: UDim2, pos: UDim2, color: Color3?): TextLabel
|
||||
local t = Instance.new("TextLabel")
|
||||
t.Name = name
|
||||
t.Size = size
|
||||
t.Position = pos
|
||||
t.BackgroundTransparency = 1
|
||||
t.TextColor3 = color or DARK
|
||||
t.Font = Enum.Font.FredokaOne
|
||||
t.TextScaled = true
|
||||
t.AutoLocalize = false
|
||||
t.Text = ""
|
||||
t.Parent = parent
|
||||
return t
|
||||
end
|
||||
|
||||
local function button(
|
||||
parent: Instance,
|
||||
name: string,
|
||||
size: UDim2,
|
||||
pos: UDim2,
|
||||
anchor: Vector2,
|
||||
color: Color3
|
||||
): TextButton
|
||||
local b = Instance.new("TextButton")
|
||||
b.Name = name
|
||||
b.Size = size
|
||||
b.Position = pos
|
||||
b.AnchorPoint = anchor
|
||||
b.BackgroundColor3 = color
|
||||
b.TextColor3 = Color3.new(1, 1, 1)
|
||||
b.Font = Enum.Font.FredokaOne
|
||||
b.TextScaled = true
|
||||
b.AutoLocalize = false
|
||||
b.AutoButtonColor = true
|
||||
b.Text = ""
|
||||
b.Parent = parent
|
||||
corner(b, 14)
|
||||
stroke(b, Color3.fromRGB(255, 255, 255), 3)
|
||||
local pad = Instance.new("UIPadding")
|
||||
pad.PaddingTop = UDim.new(0.14, 0)
|
||||
pad.PaddingBottom = UDim.new(0.14, 0)
|
||||
pad.PaddingLeft = UDim.new(0, 8)
|
||||
pad.PaddingRight = UDim.new(0, 8)
|
||||
pad.Parent = b
|
||||
return b
|
||||
end
|
||||
|
||||
local function attr(state: Instance, key: string, default: any): any
|
||||
local v = state:GetAttribute(key)
|
||||
if v == nil then
|
||||
return default
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()): HudHandle
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "BunsikHud"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
gui.Parent = parent
|
||||
|
||||
local root = frame(gui, "Root", UDim2.fromScale(1, 1), UDim2.fromScale(0, 0), Vector2.zero)
|
||||
local scale = Instance.new("UIScale")
|
||||
scale.Parent = root
|
||||
-- UIScale은 자식 크기를 키우므로, 기준 화면(1100x620) 크기의 루트에 붙이고 가운데에 둡니다.
|
||||
root.Size = UDim2.fromOffset(1100, 620)
|
||||
root.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
root.Position = UDim2.fromScale(0.5, 0.5)
|
||||
|
||||
-- 돈
|
||||
local money = frame(root, "Money", UDim2.fromOffset(300, 62), UDim2.new(0.5, 0, 0, 6), Vector2.new(0.5, 0), ORANGE)
|
||||
corner(money, 31)
|
||||
stroke(money, Color3.new(1, 1, 1), 4)
|
||||
local moneyText = text(money, "Text", UDim2.new(1, -24, 1, -14), UDim2.fromOffset(12, 7), Color3.new(1, 1, 1))
|
||||
local carry = text(root, "Carry", UDim2.fromOffset(160, 28), UDim2.new(0.5, -80, 0, 72), DARK)
|
||||
|
||||
-- 안내 문구(튜토리얼)
|
||||
local hint = frame(
|
||||
root,
|
||||
"Hint",
|
||||
UDim2.fromOffset(640, 54),
|
||||
UDim2.new(0.5, 0, 0, 104),
|
||||
Vector2.new(0.5, 0),
|
||||
Color3.fromRGB(255, 235, 120)
|
||||
)
|
||||
corner(hint, 14)
|
||||
stroke(hint, ORANGE, 3)
|
||||
local hintText = text(hint, "Text", UDim2.new(1, -20, 1, -10), UDim2.fromOffset(10, 5))
|
||||
|
||||
-- 알림
|
||||
local toasts = frame(root, "Toasts", UDim2.fromOffset(560, 200), UDim2.new(0.5, 0, 0, 166), Vector2.new(0.5, 0))
|
||||
local list = Instance.new("UIListLayout")
|
||||
list.HorizontalAlignment = Enum.HorizontalAlignment.Center
|
||||
list.Padding = UDim.new(0, 6)
|
||||
list.Parent = toasts
|
||||
|
||||
-- 다음 업그레이드 카드(아래 가운데)
|
||||
local card = frame(root, "Next", UDim2.fromOffset(500, 96), UDim2.new(0.5, 0, 1, -8), Vector2.new(0.5, 1), CREAM)
|
||||
corner(card, 18)
|
||||
stroke(card, ORANGE, 4)
|
||||
local cardTitle = text(card, "Title", UDim2.new(1, -170, 0, 40), UDim2.fromOffset(14, 8))
|
||||
cardTitle.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local cardCost =
|
||||
text(card, "Cost", UDim2.new(1, -170, 0, 26), UDim2.fromOffset(14, 48), Color3.fromRGB(120, 90, 60))
|
||||
cardCost.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local barBg = frame(
|
||||
card,
|
||||
"Bar",
|
||||
UDim2.new(1, -170, 0, 10),
|
||||
UDim2.fromOffset(14, 78),
|
||||
Vector2.zero,
|
||||
Color3.fromRGB(230, 220, 200)
|
||||
)
|
||||
corner(barBg, 5)
|
||||
local barFill = frame(barBg, "Fill", UDim2.fromScale(0, 1), UDim2.fromScale(0, 0), Vector2.zero, GREEN)
|
||||
corner(barFill, 5)
|
||||
local buyBtn = button(card, "Buy", UDim2.fromOffset(140, 72), UDim2.new(1, -12, 0.5, 0), Vector2.new(1, 0.5), GREEN)
|
||||
local buyStroke = buyBtn:FindFirstChildOfClass("UIStroke") :: UIStroke
|
||||
|
||||
-- 업그레이드 목록 버튼과 창
|
||||
local listBtn =
|
||||
button(root, "ListButton", UDim2.fromOffset(150, 56), UDim2.new(1, -10, 0.5, -40), Vector2.new(1, 0.5), ORANGE)
|
||||
local panel =
|
||||
frame(root, "Panel", UDim2.fromOffset(520, 430), UDim2.fromScale(0.5, 0.48), Vector2.new(0.5, 0.5), CREAM)
|
||||
panel.Visible = false
|
||||
corner(panel, 20)
|
||||
stroke(panel, ORANGE, 4)
|
||||
local panelTitle = text(panel, "Title", UDim2.new(1, -120, 0, 44), UDim2.fromOffset(16, 10))
|
||||
panelTitle.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local closeBtn = button(
|
||||
panel,
|
||||
"Close",
|
||||
UDim2.fromOffset(90, 42),
|
||||
UDim2.new(1, -12, 0, 10),
|
||||
Vector2.new(1, 0),
|
||||
Color3.fromRGB(220, 80, 70)
|
||||
)
|
||||
local scroll = Instance.new("ScrollingFrame")
|
||||
scroll.Name = "List"
|
||||
scroll.Size = UDim2.new(1, -24, 1, -70)
|
||||
scroll.Position = UDim2.fromOffset(12, 62)
|
||||
scroll.BackgroundTransparency = 1
|
||||
scroll.BorderSizePixel = 0
|
||||
scroll.ScrollBarThickness = 8
|
||||
scroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
|
||||
scroll.CanvasSize = UDim2.new()
|
||||
scroll.Parent = panel
|
||||
local rows = Instance.new("UIListLayout")
|
||||
rows.Padding = UDim.new(0, 6)
|
||||
rows.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
rows.Parent = scroll
|
||||
|
||||
-- 왼쪽: 2배 수익, 돈 부스트
|
||||
local passBtn = button(
|
||||
root,
|
||||
"Double",
|
||||
UDim2.fromOffset(170, 64),
|
||||
UDim2.new(0, 10, 0.5, -40),
|
||||
Vector2.new(0, 0.5),
|
||||
Color3.fromRGB(150, 80, 220)
|
||||
)
|
||||
local boostBtn = button(
|
||||
root,
|
||||
"Boost",
|
||||
UDim2.fromOffset(170, 64),
|
||||
UDim2.new(0, 10, 0.5, 34),
|
||||
Vector2.new(0, 0.5),
|
||||
Color3.fromRGB(240, 170, 30)
|
||||
)
|
||||
|
||||
-- 개발자(게임 주인)만 보는 테스트 버튼
|
||||
local dev = frame(
|
||||
root,
|
||||
"Dev",
|
||||
UDim2.fromOffset(170, 150),
|
||||
UDim2.new(0, 10, 0.5, 80),
|
||||
Vector2.new(0, 0),
|
||||
Color3.fromRGB(40, 40, 50)
|
||||
)
|
||||
dev.BackgroundTransparency = 0.3
|
||||
corner(dev, 12)
|
||||
local devTitle = text(dev, "Title", UDim2.new(1, -10, 0, 22), UDim2.fromOffset(5, 4), Color3.new(1, 1, 1))
|
||||
local devButtons: { [string]: TextButton } = {}
|
||||
for i, key in { "devMoney", "devDouble", "devReset" } do
|
||||
local b = button(
|
||||
dev,
|
||||
key,
|
||||
UDim2.new(1, -16, 0, 34),
|
||||
UDim2.fromOffset(8, 30 + (i - 1) * 39),
|
||||
Vector2.zero,
|
||||
Color3.fromRGB(90, 90, 110)
|
||||
)
|
||||
devButtons[key] = b
|
||||
end
|
||||
|
||||
-- 오른쪽 위: 언어
|
||||
local langBtn = button(
|
||||
root,
|
||||
"Lang",
|
||||
UDim2.fromOffset(120, 44),
|
||||
UDim2.new(1, -10, 0, 6),
|
||||
Vector2.new(1, 0),
|
||||
Color3.fromRGB(80, 140, 230)
|
||||
)
|
||||
|
||||
local function lang(): string
|
||||
return attr(state, "Lang", "ko")
|
||||
end
|
||||
local function L(key: string, args: { [string]: any }?): string
|
||||
return Locale.t(lang(), key, args)
|
||||
end
|
||||
local function pname(p: Economy.Purchase): string
|
||||
return if lang() == "ko" then p.name else p.nameEn
|
||||
end
|
||||
|
||||
local pulse: Tween? = nil
|
||||
local listKey = ""
|
||||
|
||||
local function refresh()
|
||||
local m = attr(state, "Money", 0)
|
||||
local bought = attr(state, "Bought", 0)
|
||||
local stats = Economy.statsAt(bought)
|
||||
moneyText.Text = "💰 " .. L("money", { money = Locale.number(m) })
|
||||
local held = attr(state, "Carry", 0)
|
||||
carry.Text = if held > 0 then `🍽️ {held}/{stats.carry}` else ""
|
||||
|
||||
local nextP = Economy.PURCHASES[bought + 1]
|
||||
if nextP then
|
||||
cardTitle.Text = `{L("next")}: {pname(nextP)}`
|
||||
cardCost.Text = L("money", { money = Locale.number(nextP.cost) })
|
||||
barFill.Size = UDim2.fromScale(math.clamp(m / nextP.cost, 0, 1), 1)
|
||||
local can = m >= nextP.cost
|
||||
buyBtn.Text = L("buy")
|
||||
buyBtn.BackgroundColor3 = if can then GREEN else GRAY
|
||||
buyBtn.Visible = true
|
||||
else
|
||||
cardTitle.Text = L("maxed")
|
||||
cardCost.Text = ""
|
||||
barFill.Size = UDim2.fromScale(1, 1)
|
||||
buyBtn.Visible = false
|
||||
end
|
||||
|
||||
-- 튜토리얼 안내
|
||||
local tut = attr(state, "Tut", 0)
|
||||
if tut == 1 or tut == 2 or tut == 3 then
|
||||
hint.Visible = true
|
||||
hintText.Text = L("tut" .. tut)
|
||||
else
|
||||
hint.Visible = false
|
||||
end
|
||||
if tut == 3 and not pulse then
|
||||
buyStroke.Color = Color3.fromRGB(255, 220, 0)
|
||||
local tw = TweenService:Create(
|
||||
buyStroke,
|
||||
TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true),
|
||||
{ Thickness = 9 }
|
||||
)
|
||||
tw:Play()
|
||||
pulse = tw
|
||||
elseif tut ~= 3 and pulse then
|
||||
pulse:Cancel()
|
||||
pulse = nil
|
||||
buyStroke.Thickness = 3
|
||||
buyStroke.Color = Color3.new(1, 1, 1)
|
||||
end
|
||||
|
||||
dev.Visible = attr(state, "Dev", false) == true
|
||||
devTitle.Text = "🛠 " .. L("devTitle")
|
||||
for key, b in devButtons do
|
||||
b.Text = L(key)
|
||||
end
|
||||
|
||||
listBtn.Text = "📋 " .. L("shop")
|
||||
langBtn.Text = L("language")
|
||||
closeBtn.Text = L("close")
|
||||
|
||||
local double = attr(state, "Double", false)
|
||||
passBtn.Visible = Products.DOUBLE_MONEY_PASS ~= 0
|
||||
passBtn.Text = if double then "✅ " .. L("doubleOwned") else "💰x2 " .. L("double")
|
||||
passBtn.Active = not double
|
||||
passBtn.AutoButtonColor = not double
|
||||
boostBtn.Visible = Products.MONEY_BOOST_PRODUCT ~= 0 and nextP ~= nil
|
||||
boostBtn.Text = "⚡ " .. L("boost") .. "\n+" .. Locale.number(attr(state, "Boost", Economy.BOOST_MIN))
|
||||
|
||||
-- 업그레이드 목록(지금 단계 것만). 산 개수나 언어가 바뀔 때만 다시 그립니다.
|
||||
local key = `{bought}:{lang()}`
|
||||
if key == listKey then
|
||||
return
|
||||
end
|
||||
listKey = key
|
||||
local stage = stats.stage
|
||||
panelTitle.Text = L(if stage >= 2 then "stage2" else "stage1")
|
||||
for _, c in scroll:GetChildren() do
|
||||
if c:IsA("Frame") then
|
||||
c:Destroy()
|
||||
end
|
||||
end
|
||||
local from = if stage >= 2 then 11 else 1
|
||||
local to = if stage >= 2 then #Economy.PURCHASES else 10
|
||||
for i = from, to do
|
||||
local p = Economy.PURCHASES[i]
|
||||
local row =
|
||||
frame(scroll, "Row" .. i, UDim2.new(1, -12, 0, 46), UDim2.new(), Vector2.zero, Color3.new(1, 1, 1))
|
||||
row.LayoutOrder = i
|
||||
corner(row, 10)
|
||||
local done = i <= bought
|
||||
local isNext = i == bought + 1
|
||||
row.BackgroundColor3 = if done
|
||||
then Color3.fromRGB(215, 245, 215)
|
||||
elseif isNext then Color3.fromRGB(255, 240, 200)
|
||||
else Color3.fromRGB(240, 240, 240)
|
||||
local status = if done then "✅" elseif isNext then "👉" else "🔒"
|
||||
local name = text(row, "Name", UDim2.new(0.66, -10, 1, -12), UDim2.fromOffset(10, 6))
|
||||
name.TextXAlignment = Enum.TextXAlignment.Left
|
||||
name.Text = `{status} {pname(p)}`
|
||||
local cost =
|
||||
text(row, "Cost", UDim2.new(0.34, -10, 1, -12), UDim2.new(0.66, 0, 0, 6), Color3.fromRGB(120, 90, 60))
|
||||
cost.TextXAlignment = Enum.TextXAlignment.Right
|
||||
cost.Text = if done then L("bought") else L("money", { money = Locale.number(p.cost) })
|
||||
end
|
||||
end
|
||||
|
||||
local function notify(key: string, args: { [string]: any }?)
|
||||
local toast =
|
||||
frame(toasts, "Toast", UDim2.fromOffset(540, 46), UDim2.new(), Vector2.zero, Color3.fromRGB(45, 45, 60))
|
||||
corner(toast, 12)
|
||||
local t = text(toast, "Text", UDim2.new(1, -20, 1, -10), UDim2.fromOffset(10, 5), Color3.new(1, 1, 1))
|
||||
t.Text = L(key, args)
|
||||
task.delay(2.6, function()
|
||||
TweenService:Create(toast, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(t, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||||
task.wait(0.45)
|
||||
toast:Destroy()
|
||||
end)
|
||||
end
|
||||
|
||||
local conns: { RBXScriptConnection } = {}
|
||||
table.insert(
|
||||
conns,
|
||||
buyBtn.Activated:Connect(function()
|
||||
send("buy")
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
listBtn.Activated:Connect(function()
|
||||
panel.Visible = not panel.Visible
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
closeBtn.Activated:Connect(function()
|
||||
panel.Visible = false
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
langBtn.Activated:Connect(function()
|
||||
send("lang", if lang() == "ko" then "en" else "ko")
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
passBtn.Activated:Connect(function()
|
||||
if not attr(state, "Double", false) then
|
||||
send("pass")
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
boostBtn.Activated:Connect(function()
|
||||
send("boost")
|
||||
end)
|
||||
)
|
||||
local devKinds: { [string]: string } = { devMoney = "dev_money", devDouble = "dev_double", devReset = "dev_reset" }
|
||||
for key, kind in devKinds do
|
||||
table.insert(
|
||||
conns,
|
||||
devButtons[key].Activated:Connect(function()
|
||||
send(kind)
|
||||
end)
|
||||
)
|
||||
end
|
||||
table.insert(conns, state.AttributeChanged:Connect(refresh))
|
||||
refresh()
|
||||
|
||||
return {
|
||||
gui = gui,
|
||||
refresh = refresh,
|
||||
notify = notify,
|
||||
setScale = function(s: number)
|
||||
scale.Scale = s
|
||||
end,
|
||||
destroy = function()
|
||||
for _, c in conns do
|
||||
c:Disconnect()
|
||||
end
|
||||
gui:Destroy()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- 화면 크기에 맞춘 UI 배율(기준 1100x620)
|
||||
function Hud.scaleFor(viewport: Vector2): number
|
||||
return math.clamp(math.min(viewport.X / 1100, viewport.Y / 620), 0.5, 1.4)
|
||||
end
|
||||
|
||||
return Hud
|
||||
@@ -1,3 +1,42 @@
|
||||
-- 클라이언트 진입점: 화면 UI, 내 조리대 버튼, 튜토리얼 화살표.
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
print(`[Bunsik] client ready for {Players.LocalPlayer.Name}`)
|
||||
local Guide = require(script.Parent.Guide)
|
||||
local Hud = require(script.Parent.Hud)
|
||||
local Stove = require(script.Parent.Stove)
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local remotes = ReplicatedStorage:WaitForChild("Remotes")
|
||||
local action = remotes:WaitForChild("Action") :: RemoteEvent
|
||||
local notifyRemote = remotes:WaitForChild("Notify") :: RemoteEvent
|
||||
|
||||
local function send(kind: string, arg: any?)
|
||||
action:FireServer(kind, arg)
|
||||
end
|
||||
|
||||
-- 서버가 세이브를 불러오고 부지를 줄 때까지 기다립니다.
|
||||
while not player:GetAttribute("Ready") do
|
||||
player:GetAttributeChangedSignal("Ready"):Wait()
|
||||
end
|
||||
|
||||
local hud = Hud.build(player:WaitForChild("PlayerGui"), player, send)
|
||||
local camera = workspace.CurrentCamera
|
||||
local function rescale()
|
||||
hud.setScale(Hud.scaleFor(camera.ViewportSize))
|
||||
end
|
||||
camera:GetPropertyChangedSignal("ViewportSize"):Connect(rescale)
|
||||
rescale()
|
||||
notifyRemote.OnClientEvent:Connect(function(key, args)
|
||||
if typeof(key) == "string" then
|
||||
hud.notify(key, if typeof(args) == "table" then args else nil)
|
||||
end
|
||||
end)
|
||||
|
||||
local plotIndex = player:GetAttribute("Plot")
|
||||
local world = workspace:WaitForChild("BunsikWorld")
|
||||
local plot = world:WaitForChild("Plots"):WaitForChild("Plot" .. tostring(plotIndex))
|
||||
local stove = plot:WaitForChild("Base"):WaitForChild("Stall"):WaitForChild("Stove") :: BasePart
|
||||
Stove.attach(stove, player, send)
|
||||
|
||||
Guide.start(player)
|
||||
|
||||
60
bunsik-tycoon/src/client/Stove.luau
Normal file
60
bunsik-tycoon/src/client/Stove.luau
Normal file
@@ -0,0 +1,60 @@
|
||||
--!strict
|
||||
-- 내 가게 조리대에만 "요리하기" 버튼(ProximityPrompt)을 만듭니다. 다른 사람 가게에서는 버튼이 안 보입니다.
|
||||
-- 서버가 조리대 속성(CookMenu, CookTime)으로 알려 준 상태를 그대로 보여 주고, 다 누르면 서버에 "cook"을 보냅니다.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local Economy = require(Shared:WaitForChild("Economy"))
|
||||
local Locale = require(Shared:WaitForChild("Locale"))
|
||||
local Sounds = require(Shared:WaitForChild("Sounds"))
|
||||
|
||||
local Stove = {}
|
||||
|
||||
function Stove.attach(stove: BasePart, state: Instance, send: (string, any?) -> ()): ProximityPrompt
|
||||
local prompt = Instance.new("ProximityPrompt")
|
||||
prompt.Name = "CookPrompt"
|
||||
prompt.KeyboardKeyCode = Enum.KeyCode.E
|
||||
prompt.MaxActivationDistance = 10
|
||||
prompt.RequiresLineOfSight = false
|
||||
prompt.Exclusivity = Enum.ProximityPromptExclusivity.OneGlobally
|
||||
|
||||
local sizzle = Instance.new("Sound")
|
||||
sizzle.SoundId = Sounds.SIZZLE
|
||||
sizzle.Volume = 0.6
|
||||
sizzle.Looped = true
|
||||
sizzle.Parent = stove
|
||||
|
||||
local function refresh()
|
||||
local lang = (state:GetAttribute("Lang") :: string?) or "ko"
|
||||
local menu = stove:GetAttribute("CookMenu")
|
||||
prompt.HoldDuration = (stove:GetAttribute("CookTime") :: number?) or 2.5
|
||||
prompt.ObjectText = Locale.t(lang, "stoveObject")
|
||||
if typeof(menu) == "string" and Economy.MENUS[menu] then
|
||||
local m = Economy.MENUS[menu]
|
||||
local name = if lang == "ko" then m.name else m.nameEn
|
||||
prompt.ActionText = `{m.icon} ` .. Locale.t(lang, "cookAction", { menu = name })
|
||||
prompt.Enabled = true
|
||||
else
|
||||
prompt.Enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
stove.AttributeChanged:Connect(refresh)
|
||||
state:GetAttributeChangedSignal("Lang"):Connect(refresh)
|
||||
prompt.PromptButtonHoldBegan:Connect(function()
|
||||
sizzle:Play()
|
||||
end)
|
||||
prompt.PromptButtonHoldEnded:Connect(function()
|
||||
sizzle:Stop()
|
||||
end)
|
||||
prompt.Triggered:Connect(function()
|
||||
sizzle:Stop()
|
||||
send("cook")
|
||||
end)
|
||||
refresh()
|
||||
prompt.Parent = stove
|
||||
return prompt
|
||||
end
|
||||
|
||||
return Stove
|
||||
151
bunsik-tycoon/src/server/Build.luau
Normal file
151
bunsik-tycoon/src/server/Build.luau
Normal file
@@ -0,0 +1,151 @@
|
||||
--!strict
|
||||
-- 파트로 모형을 만드는 작은 도구. Union은 Place Publishing API로 못 올리므로 Part 조합만 씁니다.
|
||||
|
||||
local Build = {}
|
||||
|
||||
export type PartProps = {
|
||||
size: Vector3,
|
||||
cf: CFrame,
|
||||
color: Color3?,
|
||||
material: Enum.Material?,
|
||||
shape: Enum.PartType?,
|
||||
transparency: number?,
|
||||
collide: boolean?,
|
||||
name: string?,
|
||||
wedge: boolean?,
|
||||
neon: boolean?,
|
||||
reflectance: number?,
|
||||
}
|
||||
|
||||
function Build.part(parent: Instance, p: PartProps): BasePart
|
||||
local part: BasePart
|
||||
if p.wedge then
|
||||
part = Instance.new("WedgePart")
|
||||
else
|
||||
local np = Instance.new("Part")
|
||||
if p.shape then
|
||||
np.Shape = p.shape
|
||||
end
|
||||
part = np
|
||||
end
|
||||
part.Anchored = true
|
||||
part.Size = p.size
|
||||
part.CFrame = p.cf
|
||||
part.Color = p.color or Color3.fromRGB(200, 200, 200)
|
||||
part.Material = if p.neon then Enum.Material.Neon else (p.material or Enum.Material.SmoothPlastic)
|
||||
part.Transparency = p.transparency or 0
|
||||
part.CanCollide = if p.collide == nil then true else p.collide
|
||||
part.Reflectance = p.reflectance or 0
|
||||
part.TopSurface = Enum.SurfaceType.Smooth
|
||||
part.BottomSurface = Enum.SurfaceType.Smooth
|
||||
part.CastShadow = (p.transparency or 0) < 0.5
|
||||
part.Name = p.name or "Part"
|
||||
part.Parent = parent
|
||||
return part
|
||||
end
|
||||
|
||||
-- 원기둥(세로로 세운). Roblox 원기둥은 X축이 높이라서 Z축으로 90도 돌립니다.
|
||||
function Build.cylinder(
|
||||
parent: Instance,
|
||||
cf: CFrame,
|
||||
height: number,
|
||||
diameter: number,
|
||||
color: Color3,
|
||||
extra: { [string]: any }?
|
||||
): BasePart
|
||||
local props: PartProps = {
|
||||
size = Vector3.new(height, diameter, diameter),
|
||||
cf = cf * CFrame.Angles(0, 0, math.rad(90)),
|
||||
color = color,
|
||||
shape = Enum.PartType.Cylinder,
|
||||
}
|
||||
if extra then
|
||||
for k, v in extra do
|
||||
(props :: any)[k] = v
|
||||
end
|
||||
end
|
||||
return Build.part(parent, props)
|
||||
end
|
||||
|
||||
function Build.model(parent: Instance, name: string): Model
|
||||
local m = Instance.new("Model")
|
||||
m.Name = name
|
||||
m.Parent = parent
|
||||
return m
|
||||
end
|
||||
|
||||
-- 판(Part) 한 면에 글자를 씁니다.
|
||||
function Build.label(part: BasePart, face: Enum.NormalId, text: string, color: Color3?, bg: Color3?): TextLabel
|
||||
local gui = Instance.new("SurfaceGui")
|
||||
gui.Face = face
|
||||
gui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
|
||||
gui.PixelsPerStud = 40
|
||||
gui.LightInfluence = 0
|
||||
gui.Parent = part
|
||||
local label = Instance.new("TextLabel")
|
||||
label.Size = UDim2.fromScale(1, 1)
|
||||
label.BackgroundTransparency = if bg then 0 else 1
|
||||
label.BackgroundColor3 = bg or Color3.new(1, 1, 1)
|
||||
label.TextColor3 = color or Color3.new(1, 1, 1)
|
||||
label.Font = Enum.Font.FredokaOne
|
||||
label.TextScaled = true
|
||||
label.Text = text
|
||||
label.AutoLocalize = false
|
||||
label.Parent = gui
|
||||
local pad = Instance.new("UIPadding")
|
||||
pad.PaddingTop = UDim.new(0.08, 0)
|
||||
pad.PaddingBottom = UDim.new(0.08, 0)
|
||||
pad.PaddingLeft = UDim.new(0.04, 0)
|
||||
pad.PaddingRight = UDim.new(0.04, 0)
|
||||
pad.Parent = label
|
||||
return label
|
||||
end
|
||||
|
||||
-- 머리 위 말풍선
|
||||
function Build.billboard(adornee: Instance, text: string, size: UDim2, offset: Vector3, color: Color3?): BillboardGui
|
||||
local gui = Instance.new("BillboardGui")
|
||||
gui.Size = size
|
||||
gui.StudsOffset = offset
|
||||
gui.AlwaysOnTop = false
|
||||
gui.LightInfluence = 0
|
||||
gui.MaxDistance = 120
|
||||
gui.Adornee = adornee :: any
|
||||
gui.Parent = adornee
|
||||
local label = Instance.new("TextLabel")
|
||||
label.Name = "Text"
|
||||
label.Size = UDim2.fromScale(1, 1)
|
||||
label.BackgroundColor3 = Color3.new(1, 1, 1)
|
||||
label.BackgroundTransparency = if color then 1 else 0.05
|
||||
label.TextColor3 = color or Color3.fromRGB(40, 30, 30)
|
||||
label.Font = Enum.Font.FredokaOne
|
||||
label.TextScaled = true
|
||||
label.AutoLocalize = false
|
||||
label.Text = text
|
||||
label.Parent = gui
|
||||
if not color then
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0.3, 0)
|
||||
corner.Parent = label
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Thickness = 3
|
||||
stroke.Color = Color3.fromRGB(255, 140, 60)
|
||||
stroke.Parent = label
|
||||
end
|
||||
return gui
|
||||
end
|
||||
|
||||
-- 모델 전체를 하나로 묶습니다(첫 파트 기준). 손에 들기, 트윈 이동용.
|
||||
function Build.weldAll(model: Model, root: BasePart)
|
||||
for _, d in model:GetDescendants() do
|
||||
if d:IsA("BasePart") and d ~= root then
|
||||
local w = Instance.new("WeldConstraint")
|
||||
w.Part0 = root
|
||||
w.Part1 = d
|
||||
w.Parent = d
|
||||
d.Anchored = false
|
||||
end
|
||||
end
|
||||
model.PrimaryPart = root
|
||||
end
|
||||
|
||||
return Build
|
||||
83
bunsik-tycoon/src/server/Data.luau
Normal file
83
bunsik-tycoon/src/server/Data.luau
Normal file
@@ -0,0 +1,83 @@
|
||||
--!strict
|
||||
-- 세이브 데이터(ProfileStore). 세션 잠금으로 서버 이동 때 덮어쓰기·복사를 막습니다.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
local ServerScriptService = game:GetService("ServerScriptService")
|
||||
|
||||
local ProfileStore = require(ServerScriptService.Vendor.ProfileStore)
|
||||
|
||||
local Data = {}
|
||||
|
||||
Data.TEMPLATE = {
|
||||
Money = 0,
|
||||
Bought = 0,
|
||||
PurchaseIdCache = {} :: { string },
|
||||
TutorialDone = false,
|
||||
Lang = "",
|
||||
Served = 0,
|
||||
Earned = 0,
|
||||
Version = 1,
|
||||
}
|
||||
|
||||
export type SaveData = typeof(Data.TEMPLATE)
|
||||
|
||||
-- 데이터 구조를 바꾸면 store 이름을 올리지 말고 Version과 Reconcile로 이전합니다.
|
||||
local STORE_NAME = "PlayerData_v1"
|
||||
|
||||
local store = ProfileStore.New(STORE_NAME, Data.TEMPLATE)
|
||||
-- Studio 테스트는 실제 저장소를 건드리지 않습니다.
|
||||
local activeStore = if RunService:IsStudio() then store.Mock else store
|
||||
|
||||
local profiles: { [Player]: any } = {}
|
||||
|
||||
function Data.keyFor(userId: number): string
|
||||
return "Player_" .. userId
|
||||
end
|
||||
|
||||
-- 플레이어 데이터를 불러옵니다. 실패하거나 그 사이 나가면 nil.
|
||||
function Data.load(player: Player): any
|
||||
local profile = activeStore:StartSessionAsync(Data.keyFor(player.UserId), {
|
||||
Cancel = function()
|
||||
return player.Parent ~= Players
|
||||
end,
|
||||
})
|
||||
if profile == nil then
|
||||
return nil
|
||||
end
|
||||
profile:AddUserId(player.UserId)
|
||||
profile:Reconcile()
|
||||
profile.OnSessionEnd:Connect(function()
|
||||
profiles[player] = nil
|
||||
if player.Parent == Players then
|
||||
player:Kick(
|
||||
"세이브 세션이 다른 서버로 넘어갔어요. 다시 접속해 주세요 / Your save session moved. Please rejoin"
|
||||
)
|
||||
end
|
||||
end)
|
||||
if player.Parent ~= Players then
|
||||
profile:EndSession()
|
||||
return nil
|
||||
end
|
||||
profiles[player] = profile
|
||||
return profile
|
||||
end
|
||||
|
||||
function Data.get(player: Player): any
|
||||
return profiles[player]
|
||||
end
|
||||
|
||||
function Data.release(player: Player)
|
||||
local profile = profiles[player]
|
||||
profiles[player] = nil
|
||||
if profile then
|
||||
profile:EndSession()
|
||||
end
|
||||
end
|
||||
|
||||
-- 테스트용: 실제 저장소 대신 Mock 저장소를 씁니다.
|
||||
function Data.useMock()
|
||||
activeStore = store.Mock
|
||||
end
|
||||
|
||||
return Data
|
||||
128
bunsik-tycoon/src/server/Food.luau
Normal file
128
bunsik-tycoon/src/server/Food.luau
Normal file
@@ -0,0 +1,128 @@
|
||||
--!strict
|
||||
-- 메뉴별 접시 모형(파트 조합). 원점은 접시 바닥 가운데입니다.
|
||||
|
||||
local Build = require(script.Parent.Build)
|
||||
|
||||
local Food = {}
|
||||
|
||||
local PLATE = Color3.fromRGB(250, 250, 245)
|
||||
|
||||
local function rc(r: number, g: number, b: number): Color3
|
||||
return Color3.fromRGB(r, g, b)
|
||||
end
|
||||
|
||||
local builders: { [string]: (Model, CFrame) -> () } = {
|
||||
Tteokbokki = function(m, top)
|
||||
Build.cylinder(m, top * CFrame.new(0, 0.05, 0), 0.1, 2, rc(200, 40, 25), { collide = false })
|
||||
for i = 0, 6 do
|
||||
local a = i * math.pi * 2 / 7
|
||||
local r = if i % 2 == 0 then 0.55 else 0.35
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.9, 0.28, 0.28),
|
||||
cf = top * CFrame.new(math.cos(a) * r, 0.22, math.sin(a) * r) * CFrame.Angles(0, a * 1.7, 0),
|
||||
color = rc(235, 90, 50),
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.5, 0.12, 0.25),
|
||||
cf = top * CFrame.new(0.1, 0.4, -0.1) * CFrame.Angles(0, 0.6, 0),
|
||||
color = rc(240, 220, 160),
|
||||
collide = false,
|
||||
})
|
||||
end,
|
||||
Gimbap = function(m, top)
|
||||
for i = 0, 5 do
|
||||
local x = -0.75 + i * 0.3
|
||||
local cf = top * CFrame.new(x, 0.32, 0) * CFrame.Angles(0, 0, math.rad(80))
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.25, 0.62, 0.62),
|
||||
cf = cf,
|
||||
color = rc(25, 35, 25),
|
||||
shape = Enum.PartType.Cylinder,
|
||||
collide = false,
|
||||
})
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.27, 0.5, 0.5),
|
||||
cf = cf,
|
||||
color = rc(250, 248, 240),
|
||||
shape = Enum.PartType.Cylinder,
|
||||
collide = false,
|
||||
})
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.29, 0.2, 0.2),
|
||||
cf = cf,
|
||||
color = if i % 2 == 0 then rc(250, 200, 40) else rc(240, 120, 40),
|
||||
shape = Enum.PartType.Cylinder,
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
end,
|
||||
Sundae = function(m, top)
|
||||
for i = 0, 5 do
|
||||
local a = i * math.pi * 2 / 6
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.22, 0.55, 0.55),
|
||||
cf = top * CFrame.new(math.cos(a) * 0.55, 0.3, math.sin(a) * 0.55) * CFrame.Angles(0, -a, math.rad(70)),
|
||||
color = rc(70, 35, 45),
|
||||
shape = Enum.PartType.Cylinder,
|
||||
material = Enum.Material.Pebble,
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.4, 0.4, 0.4),
|
||||
cf = top * CFrame.new(0, 0.25, 0),
|
||||
color = rc(230, 200, 120),
|
||||
shape = Enum.PartType.Ball,
|
||||
collide = false,
|
||||
})
|
||||
end,
|
||||
Eomuk = function(m, top)
|
||||
for i = -1, 1 do
|
||||
local base = top * CFrame.new(i * 0.55, 0.2, 0)
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.08, 1.8, 0.08),
|
||||
cf = base * CFrame.new(0, 0.7, 0),
|
||||
color = rc(190, 150, 100),
|
||||
collide = false,
|
||||
})
|
||||
for j = 0, 2 do
|
||||
Build.part(m, {
|
||||
size = Vector3.new(0.45, 0.28, 0.12),
|
||||
cf = base * CFrame.new(if j % 2 == 0 then 0.06 else -0.06, 0.2 + j * 0.3, 0),
|
||||
color = rc(225, 185, 120),
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
Twigim = function(m, top)
|
||||
for i = 0, 3 do
|
||||
local a = i * math.pi / 2 + 0.4
|
||||
Build.part(m, {
|
||||
size = Vector3.new(1.0, 0.32, 0.4),
|
||||
cf = top
|
||||
* CFrame.new(math.cos(a) * 0.4, 0.22 + (i % 2) * 0.12, math.sin(a) * 0.4)
|
||||
* CFrame.Angles(0, a, 0),
|
||||
color = rc(230, 170, 60),
|
||||
material = Enum.Material.Sand,
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
-- cf: 접시 바닥 가운데 위치
|
||||
function Food.dish(menu: string, cf: CFrame, parent: Instance): Model
|
||||
local m = Instance.new("Model")
|
||||
m.Name = "Dish_" .. menu
|
||||
local plate = Build.cylinder(m, cf * CFrame.new(0, 0.1, 0), 0.2, 2.4, PLATE, { collide = false, name = "Plate" })
|
||||
local build = builders[menu] or builders.Tteokbokki
|
||||
build(m, cf * CFrame.new(0, 0.2, 0))
|
||||
m.PrimaryPart = plate
|
||||
m.Parent = parent
|
||||
return m
|
||||
end
|
||||
|
||||
return Food
|
||||
261
bunsik-tycoon/src/server/Game.luau
Normal file
261
bunsik-tycoon/src/server/Game.luau
Normal file
@@ -0,0 +1,261 @@
|
||||
--!strict
|
||||
-- 서버 시작: 맵, 플레이어 입장·퇴장, 부지 배정, 리모트, 결제를 연결합니다.
|
||||
|
||||
local MarketplaceService = game:GetService("MarketplaceService")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local Shared = ReplicatedStorage.Shared
|
||||
local Economy = require(Shared.Economy)
|
||||
local Locale = require(Shared.Locale)
|
||||
local Products = require(Shared.Products)
|
||||
|
||||
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 Receipts = require(script.Parent.Receipts)
|
||||
local World = require(script.Parent.World)
|
||||
|
||||
local Game = {}
|
||||
|
||||
local slots: { World.Slot } = {}
|
||||
local slotOwner: { [number]: Player } = {}
|
||||
local controllers: { [Player]: PlotController.PlotController } = {}
|
||||
local actionTimes: { [Player]: { number } } = {}
|
||||
|
||||
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
|
||||
local ActionRemote = Remotes:WaitForChild("Action") :: RemoteEvent
|
||||
local NotifyRemote = Remotes:WaitForChild("Notify") :: RemoteEvent
|
||||
|
||||
local function freeSlot(): World.Slot?
|
||||
for _, s in slots do
|
||||
if not slotOwner[s.index] then
|
||||
return s
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function placeCharacter(player: Player, slot: World.Slot)
|
||||
local char = player.Character
|
||||
if not char then
|
||||
return
|
||||
end
|
||||
local root = char:WaitForChild("HumanoidRootPart", 5) :: BasePart?
|
||||
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)
|
||||
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
|
||||
end
|
||||
local ok, owns = pcall(function()
|
||||
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, Products.DOUBLE_MONEY_PASS)
|
||||
end)
|
||||
if ok and owns then
|
||||
controller:setDouble(true)
|
||||
end
|
||||
end
|
||||
|
||||
-- 게임 주인(개발자)만 쓰는 테스트 버튼. 결제 없이 기능을 확인할 수 있게 합니다.
|
||||
local function isDev(player: Player): boolean
|
||||
return game.CreatorType == Enum.CreatorType.User and player.UserId == game.CreatorId
|
||||
end
|
||||
|
||||
local function makeController(player: Player, slot: World.Slot, data: any, lang: string): PlotController.PlotController
|
||||
return PlotController.new(slot, player, {
|
||||
userId = player.UserId,
|
||||
displayName = player.DisplayName,
|
||||
data = data,
|
||||
now = os.clock(),
|
||||
lang = lang,
|
||||
notify = function(key, args)
|
||||
NotifyRemote:FireClient(player, key, args)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function onPlayerAdded(player: Player)
|
||||
local profile = Data.load(player)
|
||||
if not profile then
|
||||
if player.Parent == Players then
|
||||
player:Kick(Locale.t("ko", "saveFail") .. " / " .. Locale.t("en", "saveFail"))
|
||||
end
|
||||
return
|
||||
end
|
||||
local slot = freeSlot()
|
||||
if not slot then
|
||||
Data.release(player)
|
||||
player:Kick("서버가 꽉 찼어요 / Server is full")
|
||||
return
|
||||
end
|
||||
slotOwner[slot.index] = player
|
||||
local data = profile.Data
|
||||
local lang = if data.Lang ~= "" then data.Lang else Locale.pick(player.LocaleId)
|
||||
player:SetAttribute("Lang", lang)
|
||||
local controller = makeController(player, slot, data, lang)
|
||||
controllers[player] = controller
|
||||
player:SetAttribute("Dev", isDev(player))
|
||||
player:SetAttribute("Ready", true)
|
||||
|
||||
player.CharacterAdded:Connect(function()
|
||||
task.defer(function()
|
||||
placeCharacter(player, slot)
|
||||
local current = controllers[player]
|
||||
if current then
|
||||
current:rebuildHand()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
if player.Character then
|
||||
task.defer(placeCharacter, player, slot)
|
||||
end
|
||||
task.spawn(checkPass, player, controller)
|
||||
end
|
||||
|
||||
local function onPlayerRemoving(player: Player)
|
||||
local controller = controllers[player]
|
||||
controllers[player] = nil
|
||||
actionTimes[player] = nil
|
||||
if controller then
|
||||
slotOwner[controller.slot.index] = nil
|
||||
controller:destroy()
|
||||
end
|
||||
Data.release(player)
|
||||
end
|
||||
|
||||
-- 초당 10회 넘는 요청은 무시합니다.
|
||||
local function allowAction(player: Player): boolean
|
||||
local now = os.clock()
|
||||
local list = actionTimes[player] or {}
|
||||
actionTimes[player] = list
|
||||
while list[1] and now - list[1] > 1 do
|
||||
table.remove(list, 1)
|
||||
end
|
||||
if #list >= 10 then
|
||||
return false
|
||||
end
|
||||
table.insert(list, now)
|
||||
return true
|
||||
end
|
||||
|
||||
local function onAction(player: Player, kind: any, arg: any)
|
||||
if typeof(kind) ~= "string" or not allowAction(player) then
|
||||
return
|
||||
end
|
||||
local controller = controllers[player]
|
||||
if not controller then
|
||||
return
|
||||
end
|
||||
if kind == "cook" then
|
||||
-- 버튼을 누르고 있는 시간만큼은 지나야 다음 접시를 만들 수 있습니다.
|
||||
local now = os.clock()
|
||||
if now - controller.lastCook >= controller.shop.stats.cook * 0.8 then
|
||||
controller.shop.now = now
|
||||
controller:cook()
|
||||
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) })
|
||||
end
|
||||
end
|
||||
elseif kind == "lang" then
|
||||
if typeof(arg) == "string" and table.find(Locale.LANGS, arg) then
|
||||
controller.data.Lang = arg
|
||||
player:SetAttribute("Lang", arg)
|
||||
controller:setLang(arg)
|
||||
end
|
||||
elseif kind == "pass" then
|
||||
if Products.DOUBLE_MONEY_PASS ~= 0 and controller.shop.moneyMult == 1 then
|
||||
MarketplaceService:PromptGamePassPurchase(player, Products.DOUBLE_MONEY_PASS)
|
||||
end
|
||||
elseif kind == "dev_money" and isDev(player) then
|
||||
controller:addMoney(1000)
|
||||
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
|
||||
local slot = controller.slot
|
||||
controller:destroy()
|
||||
local fresh = makeController(player, slot, data, controller.lang)
|
||||
controllers[player] = fresh
|
||||
placeCharacter(player, slot)
|
||||
fresh:notify("devResetDone")
|
||||
elseif kind == "boost" then
|
||||
if Products.MONEY_BOOST_PRODUCT ~= 0 and Economy.PURCHASES[controller.shop.bought + 1] then
|
||||
MarketplaceService:PromptProductPurchase(player, Products.MONEY_BOOST_PRODUCT)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 개발자 상품 지급(결제 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
|
||||
return false
|
||||
end
|
||||
local amount = Economy.boostAmount(controller.shop.stats)
|
||||
controller:addMoney(amount)
|
||||
controller:notify("boostGot", { amount = Locale.number(amount) })
|
||||
return true
|
||||
end)
|
||||
if decision == "Granted" then
|
||||
return Enum.ProductPurchaseDecision.PurchaseGranted
|
||||
end
|
||||
return Enum.ProductPurchaseDecision.NotProcessedYet
|
||||
end
|
||||
|
||||
function Game.start()
|
||||
slots = World.build()
|
||||
task.spawn(Npc.preload)
|
||||
|
||||
Players.PlayerAdded:Connect(onPlayerAdded)
|
||||
Players.PlayerRemoving:Connect(onPlayerRemoving)
|
||||
for _, p in Players:GetPlayers() do
|
||||
task.spawn(onPlayerAdded, p)
|
||||
end
|
||||
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)
|
||||
|
||||
local acc = 0
|
||||
RunService.Heartbeat:Connect(function(dt)
|
||||
acc += dt
|
||||
if acc < 0.1 then
|
||||
return
|
||||
end
|
||||
acc = 0
|
||||
local now = os.clock()
|
||||
for _, c in controllers do
|
||||
c:update(now)
|
||||
end
|
||||
end)
|
||||
print(`[Bunsik] server ready, {#Economy.PURCHASES} purchases, {#slots} plots`)
|
||||
end
|
||||
|
||||
return Game
|
||||
@@ -1,5 +1,2 @@
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Economy = require(ReplicatedStorage.Shared.Economy)
|
||||
|
||||
print(`[Bunsik] server ready, {#Economy.PURCHASES} purchases loaded`)
|
||||
-- 서버 진입점. 실제 로직은 Game 모듈에 있습니다(원격 테스트에서 모듈을 직접 불러 씁니다).
|
||||
require(script.Parent.Game).start()
|
||||
|
||||
253
bunsik-tycoon/src/server/Npc.luau
Normal file
253
bunsik-tycoon/src/server/Npc.luau
Normal file
@@ -0,0 +1,253 @@
|
||||
--!strict
|
||||
-- 손님·알바생 NPC. 로블록스 기본 아바타(R15)를 서버 시작 때 몇 개 만들어 두고 복제해서 씁니다.
|
||||
-- 물리로 걷게 하면 테이블에 걸리거나 늦게 도착하므로, 몸을 고정(Anchored)하고 트윈으로 옮깁니다.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local Npc = {}
|
||||
|
||||
local ANIM: { [string]: string } = {
|
||||
walk = "rbxassetid://507777826",
|
||||
idle = "rbxassetid://507766388",
|
||||
sit = "rbxassetid://2506281703",
|
||||
}
|
||||
|
||||
local SKIN = {
|
||||
Color3.fromRGB(255, 220, 190),
|
||||
Color3.fromRGB(240, 200, 160),
|
||||
Color3.fromRGB(205, 160, 120),
|
||||
Color3.fromRGB(150, 105, 75),
|
||||
}
|
||||
local SHIRT = {
|
||||
Color3.fromRGB(230, 70, 70),
|
||||
Color3.fromRGB(70, 130, 230),
|
||||
Color3.fromRGB(250, 200, 60),
|
||||
Color3.fromRGB(90, 190, 110),
|
||||
Color3.fromRGB(180, 100, 220),
|
||||
Color3.fromRGB(255, 150, 190),
|
||||
Color3.fromRGB(250, 250, 250),
|
||||
}
|
||||
local PANTS = {
|
||||
Color3.fromRGB(40, 50, 90),
|
||||
Color3.fromRGB(60, 60, 60),
|
||||
Color3.fromRGB(120, 90, 60),
|
||||
Color3.fromRGB(30, 90, 140),
|
||||
}
|
||||
|
||||
local template: Model? = nil
|
||||
local loading = false
|
||||
|
||||
local function makeBlockNpc(): Model
|
||||
-- 아바타를 못 불러올 때 쓰는 간단한 블록 사람
|
||||
local m = Instance.new("Model")
|
||||
m.Name = "Npc"
|
||||
local root = Instance.new("Part")
|
||||
root.Name = "HumanoidRootPart"
|
||||
root.Size = Vector3.new(2, 2, 1)
|
||||
root.Transparency = 1
|
||||
root.Parent = m
|
||||
local function piece(name: string, size: Vector3, offset: Vector3)
|
||||
local p = Instance.new("Part")
|
||||
p.Name = name
|
||||
p.Size = size
|
||||
p.CFrame = CFrame.new(offset)
|
||||
p.Parent = m
|
||||
end
|
||||
piece("UpperTorso", Vector3.new(2, 2, 1), Vector3.zero)
|
||||
piece("Head", Vector3.new(1.2, 1.2, 1.2), Vector3.new(0, 1.6, 0))
|
||||
piece("LeftUpperLeg", Vector3.new(0.9, 2, 1), Vector3.new(-0.5, -2, 0))
|
||||
piece("RightUpperLeg", Vector3.new(0.9, 2, 1), Vector3.new(0.5, -2, 0))
|
||||
m.PrimaryPart = root
|
||||
local h = Instance.new("Humanoid")
|
||||
h.Parent = m
|
||||
for _, p in m:GetChildren() do
|
||||
if p:IsA("BasePart") and p ~= root then
|
||||
local w = Instance.new("WeldConstraint")
|
||||
w.Part0 = root
|
||||
w.Part1 = p
|
||||
w.Parent = p
|
||||
end
|
||||
end
|
||||
return m
|
||||
end
|
||||
|
||||
-- 서버 시작 때 한 번 호출. 실패하면 블록 사람으로 대신합니다.
|
||||
function Npc.preload()
|
||||
if template then
|
||||
return
|
||||
end
|
||||
if loading then
|
||||
-- 다른 곳에서 이미 만드는 중이면 끝날 때까지 기다립니다.
|
||||
while loading do
|
||||
task.wait()
|
||||
end
|
||||
return
|
||||
end
|
||||
loading = true
|
||||
local ok, model = pcall(function()
|
||||
local desc = Instance.new("HumanoidDescription")
|
||||
return Players:CreateHumanoidModelFromDescription(desc, Enum.HumanoidRigType.R15)
|
||||
end)
|
||||
if ok and model then
|
||||
template = model
|
||||
else
|
||||
warn("[Bunsik] NPC 아바타 생성 실패, 블록 NPC 사용:", model)
|
||||
template = makeBlockNpc()
|
||||
end
|
||||
loading = false
|
||||
end
|
||||
|
||||
local function pick<T>(list: { T }, rng: Random): T
|
||||
return list[rng:NextInteger(1, #list)]
|
||||
end
|
||||
|
||||
local function colorize(m: Model, rng: Random, shirtOverride: Color3?)
|
||||
local skin = pick(SKIN, rng)
|
||||
local shirt = shirtOverride or pick(SHIRT, rng)
|
||||
local pants = pick(PANTS, rng)
|
||||
for _, p in m:GetDescendants() do
|
||||
if p:IsA("BasePart") then
|
||||
local n = p.Name
|
||||
if n == "Head" or string.find(n, "Hand") then
|
||||
p.Color = skin
|
||||
elseif string.find(n, "Torso") or string.find(n, "UpperArm") or string.find(n, "LowerArm") then
|
||||
p.Color = shirt
|
||||
elseif string.find(n, "Leg") or string.find(n, "Foot") then
|
||||
p.Color = pants
|
||||
end
|
||||
end
|
||||
end
|
||||
local bc = m:FindFirstChildOfClass("BodyColors")
|
||||
if bc then
|
||||
bc:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
export type Handle = {
|
||||
model: Model,
|
||||
root: BasePart,
|
||||
humanoid: Humanoid,
|
||||
tracks: { [string]: AnimationTrack },
|
||||
tween: Tween?,
|
||||
}
|
||||
|
||||
function Npc.spawn(parent: Instance, cf: CFrame, rng: Random, shirt: Color3?): Handle
|
||||
if not template then
|
||||
Npc.preload()
|
||||
end
|
||||
local m = (template :: Model):Clone()
|
||||
m.Name = "Customer"
|
||||
colorize(m, rng, shirt)
|
||||
local root = m:FindFirstChild("HumanoidRootPart") :: BasePart
|
||||
for _, p in m:GetDescendants() do
|
||||
if p:IsA("BasePart") then
|
||||
p.CanCollide = false
|
||||
p.CanQuery = false
|
||||
p.CanTouch = false
|
||||
p.Massless = true
|
||||
end
|
||||
end
|
||||
root.Anchored = true
|
||||
local humanoid = m:FindFirstChildOfClass("Humanoid") :: Humanoid
|
||||
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
|
||||
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
|
||||
humanoid.BreakJointsOnDeath = false
|
||||
humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
|
||||
m:PivotTo(cf)
|
||||
m.Parent = parent
|
||||
local h: Handle = { model = m, root = root, humanoid = humanoid, tracks = {}, tween = nil }
|
||||
local animator: Animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator")
|
||||
animator.Parent = humanoid
|
||||
for name: string, id: string in ANIM do
|
||||
local a = Instance.new("Animation")
|
||||
a.AnimationId = id
|
||||
local ok, track = pcall(function()
|
||||
return animator:LoadAnimation(a)
|
||||
end)
|
||||
if ok and track then
|
||||
track.Looped = true
|
||||
h.tracks[name] = track
|
||||
end
|
||||
end
|
||||
Npc.play(h, "idle")
|
||||
return h
|
||||
end
|
||||
|
||||
function Npc.play(h: Handle, name: string)
|
||||
for n, t in h.tracks do
|
||||
if n ~= name and t.IsPlaying then
|
||||
t:Stop(0.15)
|
||||
end
|
||||
end
|
||||
local t = h.tracks[name]
|
||||
if t and not t.IsPlaying then
|
||||
t:Play(0.15)
|
||||
end
|
||||
end
|
||||
|
||||
-- 높이(엉덩이 높이)를 맞춘 서 있는 자세 위치
|
||||
function Npc.standCFrame(h: Handle, floorPos: Vector3, lookAt: Vector3): CFrame
|
||||
local hip = h.humanoid.HipHeight + h.root.Size.Y / 2
|
||||
local pos = floorPos + Vector3.new(0, hip, 0)
|
||||
local look = Vector3.new(lookAt.X, pos.Y, lookAt.Z)
|
||||
if (look - pos).Magnitude < 0.01 then
|
||||
look = pos + Vector3.new(0, 0, -1)
|
||||
end
|
||||
return CFrame.lookAt(pos, look)
|
||||
end
|
||||
|
||||
-- 바닥 지점들을 차례로 걸어갑니다. 전체 걸리는 시간(초)을 맞춰 줍니다.
|
||||
function Npc.walk(h: Handle, points: { Vector3 }, duration: number, onDone: (() -> ())?)
|
||||
if h.tween then
|
||||
h.tween:Cancel()
|
||||
end
|
||||
local total = 0
|
||||
for i = 2, #points do
|
||||
total += (points[i] - points[i - 1]).Magnitude
|
||||
end
|
||||
Npc.play(h, "walk")
|
||||
local alive = true
|
||||
h.model.Destroying:Connect(function()
|
||||
alive = false
|
||||
end)
|
||||
task.spawn(function()
|
||||
for i = 2, #points do
|
||||
if not alive then
|
||||
return
|
||||
end
|
||||
local seg = (points[i] - points[i - 1]).Magnitude
|
||||
local t = if total > 0 then duration * seg / total else 0
|
||||
local target = Npc.standCFrame(h, points[i], points[i] + (points[i] - points[i - 1]))
|
||||
if t > 0.01 then
|
||||
local tw = TweenService:Create(h.root, TweenInfo.new(t, Enum.EasingStyle.Linear), { CFrame = target })
|
||||
h.tween = tw
|
||||
tw:Play()
|
||||
tw.Completed:Wait()
|
||||
else
|
||||
h.root.CFrame = target
|
||||
end
|
||||
end
|
||||
h.tween = nil
|
||||
if alive then
|
||||
Npc.play(h, "idle")
|
||||
if onDone then
|
||||
onDone()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Npc.sit(h: Handle, seat: CFrame)
|
||||
if h.tween then
|
||||
h.tween:Cancel()
|
||||
h.tween = nil
|
||||
end
|
||||
-- 앉은 자세에서 엉덩이가 의자 위에 오도록 살짝 낮춥니다.
|
||||
h.root.CFrame = seat * CFrame.new(0, h.root.Size.Y / 2 + 0.6, 0)
|
||||
if h.tracks.sit then
|
||||
Npc.play(h, "sit")
|
||||
end
|
||||
end
|
||||
|
||||
return Npc
|
||||
521
bunsik-tycoon/src/server/PlotBuilder.luau
Normal file
521
bunsik-tycoon/src/server/PlotBuilder.luau
Normal file
@@ -0,0 +1,521 @@
|
||||
--!strict
|
||||
-- 부지 모형: 기본(바닥·포장마차·조리대)과 업그레이드(테이블·간판·화구·실내 확장 등)를 파트로 짓습니다.
|
||||
|
||||
local Build = require(script.Parent.Build)
|
||||
local PlotLayout = require(script.Parent.PlotLayout)
|
||||
local Economy = require(game:GetService("ReplicatedStorage").Shared.Economy)
|
||||
|
||||
local PlotBuilder = {}
|
||||
|
||||
export type BaseRefs = {
|
||||
stove: BasePart,
|
||||
counter: BasePart,
|
||||
nameLabel: TextLabel,
|
||||
menuLabel: TextLabel,
|
||||
upgrades: Model,
|
||||
dynamic: Folder,
|
||||
}
|
||||
|
||||
local function rgb(r: number, g: number, b: number): Color3
|
||||
return Color3.fromRGB(r, g, b)
|
||||
end
|
||||
|
||||
local Y = PlotLayout.FLOOR_Y
|
||||
|
||||
-- 바닥과 포장마차. 부지마다 한 번만 짓습니다.
|
||||
function PlotBuilder.buildBase(plot: Model, cf: CFrame): BaseRefs
|
||||
local base = Build.model(plot, "Base")
|
||||
local function at(x: number, y: number, z: number): CFrame
|
||||
return cf * CFrame.new(x, y, z)
|
||||
end
|
||||
|
||||
-- 바닥, 길가 연석, 옆·뒤 울타리(나무 화단)
|
||||
Build.part(base, {
|
||||
name = "Floor",
|
||||
size = Vector3.new(72, 0.4, 80),
|
||||
cf = at(0, Y - 0.2, 0),
|
||||
color = rgb(214, 205, 190),
|
||||
material = Enum.Material.Concrete,
|
||||
})
|
||||
for _, side in { -1, 1 } do
|
||||
Build.part(base, {
|
||||
size = Vector3.new(2, 2.4, 80),
|
||||
cf = at(side * 35, Y + 1.2, 0),
|
||||
color = rgb(90, 160, 80),
|
||||
material = Enum.Material.LeafyGrass,
|
||||
})
|
||||
end
|
||||
Build.part(base, {
|
||||
size = Vector3.new(72, 2.4, 2),
|
||||
cf = at(0, Y + 1.2, -39),
|
||||
color = rgb(90, 160, 80),
|
||||
material = Enum.Material.LeafyGrass,
|
||||
})
|
||||
-- 입구 기둥과 이름판
|
||||
for _, side in { -1, 1 } do
|
||||
Build.part(base, {
|
||||
size = Vector3.new(1.2, 11, 1.2),
|
||||
cf = at(side * 8, Y + 5.5, 37),
|
||||
color = rgb(120, 80, 50),
|
||||
material = Enum.Material.Wood,
|
||||
})
|
||||
end
|
||||
local board = Build.part(base, {
|
||||
name = "NameBoard",
|
||||
size = Vector3.new(17, 3, 0.6),
|
||||
cf = at(0, Y + 10, 37),
|
||||
color = rgb(255, 245, 225),
|
||||
material = Enum.Material.Wood,
|
||||
})
|
||||
local nameLabel = Build.label(board, Enum.NormalId.Front, "", rgb(160, 50, 30))
|
||||
-- 앞뒤 둘 다 보이게: 앞면(+Z)은 길에서, 뒷면은 가게 안에서
|
||||
local backLabel = Build.label(board, Enum.NormalId.Back, "", rgb(160, 50, 30))
|
||||
nameLabel:GetPropertyChangedSignal("Text"):Connect(function()
|
||||
backLabel.Text = nameLabel.Text
|
||||
end)
|
||||
|
||||
-- 포장마차: 수레 몸통, 조리대 상판
|
||||
local stall = Build.model(base, "Stall")
|
||||
local sz = PlotLayout.STALL_Z
|
||||
Build.part(stall, {
|
||||
size = Vector3.new(18, 3.4, 4),
|
||||
cf = at(0, Y + 1.7, sz),
|
||||
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),
|
||||
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 })
|
||||
end
|
||||
|
||||
-- 화구(프롬프트가 붙는 곳)
|
||||
local stove = Build.part(stall, {
|
||||
name = "Stove",
|
||||
size = Vector3.new(5, 0.6, 3.4),
|
||||
cf = at(PlotLayout.STOVE.X, Y + 4.1, sz),
|
||||
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 })
|
||||
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),
|
||||
color = rgb(235, 90, 50),
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
local steam = Instance.new("Smoke")
|
||||
steam.Color = Color3.new(1, 1, 1)
|
||||
steam.Opacity = 0.08
|
||||
steam.RiseVelocity = 3
|
||||
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),
|
||||
color = rgb(235, 215, 175),
|
||||
material = Enum.Material.Wood,
|
||||
})
|
||||
|
||||
-- 천막: 기둥 4개, 주황 지붕(박공), 앞 가림막
|
||||
for _, x in { -10, 10 } do
|
||||
for _, z in { sz - 5, sz + 6 } do
|
||||
Build.part(stall, {
|
||||
size = Vector3.new(0.5, 11, 0.5),
|
||||
cf = at(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)
|
||||
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,
|
||||
})
|
||||
local valance = Build.part(stall, {
|
||||
size = Vector3.new(22, 1.8, 0.2),
|
||||
cf = at(0, Y + 10.2, sz + 6.3),
|
||||
color = rgb(255, 230, 90),
|
||||
material = Enum.Material.Fabric,
|
||||
})
|
||||
Build.label(valance, Enum.NormalId.Front, "떡볶이 · 김밥 · 순대 BUNSIK", rgb(200, 40, 30))
|
||||
-- 뒤쪽 투명 비닐 가림막
|
||||
Build.part(stall, {
|
||||
size = Vector3.new(20, 9, 0.1),
|
||||
cf = at(0, Y + 5.8, sz - 5.2),
|
||||
color = rgb(255, 200, 150),
|
||||
transparency = 0.6,
|
||||
material = Enum.Material.Glass,
|
||||
})
|
||||
-- 메뉴판
|
||||
local menuBoard = Build.part(stall, {
|
||||
name = "MenuBoard",
|
||||
size = Vector3.new(9, 4.2, 0.3),
|
||||
cf = at(0, Y + 7.6, sz - 4.8),
|
||||
color = rgb(40, 60, 45),
|
||||
material = Enum.Material.Wood,
|
||||
})
|
||||
local menuLabel = Build.label(menuBoard, Enum.NormalId.Front, "", rgb(255, 250, 230))
|
||||
menuLabel.TextXAlignment = Enum.TextXAlignment.Left
|
||||
menuLabel.Font = Enum.Font.GothamBold
|
||||
-- 앞 처마에 매단 전구
|
||||
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),
|
||||
color = rgb(255, 210, 120),
|
||||
shape = Enum.PartType.Ball,
|
||||
neon = true,
|
||||
collide = false,
|
||||
})
|
||||
if i % 2 == 0 then
|
||||
local light = Instance.new("PointLight")
|
||||
light.Color = rgb(255, 200, 130)
|
||||
light.Range = 10
|
||||
light.Brightness = 0.6
|
||||
light.Parent = bulb
|
||||
end
|
||||
end
|
||||
|
||||
local upgrades = Build.model(plot, "Upgrades")
|
||||
local dynamic = Instance.new("Folder")
|
||||
dynamic.Name = "Dynamic"
|
||||
dynamic.Parent = plot
|
||||
|
||||
return {
|
||||
stove = stove,
|
||||
counter = counter,
|
||||
nameLabel = nameLabel,
|
||||
menuLabel = menuLabel,
|
||||
upgrades = upgrades,
|
||||
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)
|
||||
end
|
||||
|
||||
-- 실내 분식집 건물(2단계)
|
||||
local function buildIndoor(parent: Instance, cf: CFrame)
|
||||
local m = Build.model(parent, "Expand")
|
||||
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 })
|
||||
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 })
|
||||
-- 옆 창문
|
||||
Build.part(m, {
|
||||
size = Vector3.new(1.1, 5, 30),
|
||||
cf = at(side * 34.5, Y + 7, -6),
|
||||
color = rgb(170, 220, 255),
|
||||
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 })
|
||||
end
|
||||
-- 앞 벽(가운데 문, 양쪽 큰 창)
|
||||
for _, side in { -1, 1 } do
|
||||
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),
|
||||
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 })
|
||||
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,
|
||||
})
|
||||
-- 천장 들보와 조명
|
||||
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),
|
||||
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),
|
||||
shape = Enum.PartType.Ball,
|
||||
neon = true,
|
||||
collide = false,
|
||||
})
|
||||
local light = Instance.new("PointLight")
|
||||
light.Color = rgb(255, 220, 160)
|
||||
light.Range = 16
|
||||
light.Brightness = 0.8
|
||||
light.Parent = lamp
|
||||
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),
|
||||
})
|
||||
Build.label(sign, Enum.NormalId.Front, "분식천국 BUNSIK HEAVEN", rgb(255, 240, 200))
|
||||
-- 화분
|
||||
for _, x in { -30, 30 } do
|
||||
Build.cylinder(m, at(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),
|
||||
color = rgb(70, 150, 70),
|
||||
shape = Enum.PartType.Ball,
|
||||
material = Enum.Material.LeafyGrass,
|
||||
})
|
||||
end
|
||||
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
|
||||
end
|
||||
local function at(x: number, y: number, z: number): CFrame
|
||||
return cf * CFrame.new(x, y, z)
|
||||
end
|
||||
local sz = PlotLayout.STALL_Z
|
||||
|
||||
for seat = 1, stats.seats do
|
||||
buildTable(up, cf, seat)
|
||||
end
|
||||
|
||||
if stats.stage >= 2 then
|
||||
buildIndoor(up, cf)
|
||||
end
|
||||
|
||||
if has("Sign1") then
|
||||
local m = Build.model(up, "Sign1")
|
||||
local sign = Build.part(m, {
|
||||
size = Vector3.new(12, 3.2, 0.6),
|
||||
cf = at(0, Y + 15.6, sz + 3),
|
||||
color = rgb(255, 80, 120),
|
||||
neon = true,
|
||||
})
|
||||
Build.label(sign, Enum.NormalId.Front, "분식 BUNSIK", rgb(255, 255, 255))
|
||||
local light = Instance.new("PointLight")
|
||||
light.Color = rgb(255, 120, 160)
|
||||
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),
|
||||
})
|
||||
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
|
||||
|
||||
-- 메뉴판 글자
|
||||
local lines = {}
|
||||
for _, key in Economy.MENU_ORDER do
|
||||
if table.find(stats.menus, key) then
|
||||
local m = Economy.MENUS[key]
|
||||
table.insert(lines, `{m.icon} {m.name} {Economy.dishPrice(key, stats, 1)}원`)
|
||||
end
|
||||
end
|
||||
refs.menuLabel.Text = table.concat(lines, "\n")
|
||||
refs.menuLabel.TextScaled = true
|
||||
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
|
||||
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)
|
||||
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)
|
||||
end
|
||||
|
||||
function PlotBuilder.world(cf: CFrame, v: Vector3): Vector3
|
||||
return (cf * CFrame.new(v.X, Y + v.Y, v.Z)).Position
|
||||
end
|
||||
|
||||
return PlotBuilder
|
||||
549
bunsik-tycoon/src/server/PlotController.luau
Normal file
549
bunsik-tycoon/src/server/PlotController.luau
Normal file
@@ -0,0 +1,549 @@
|
||||
--!strict
|
||||
-- 플레이어 한 명의 가게를 움직입니다: Shop 로직의 이벤트를 받아 손님 NPC, 접시, 효과를 그리고,
|
||||
-- 조리대 버튼·자동 서빙·구매를 처리합니다. 실제 Player 대신 Folder를 넣어도 돌아가서 원격 테스트에 씁니다.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local Shared = ReplicatedStorage.Shared
|
||||
local Economy = require(Shared.Economy)
|
||||
local Shop = require(Shared.Shop)
|
||||
local Locale = require(Shared.Locale)
|
||||
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 PICKUP_RANGE = 8
|
||||
|
||||
export type Slot = {
|
||||
index: number,
|
||||
cf: CFrame,
|
||||
model: Model,
|
||||
refs: PlotBuilder.BaseRefs,
|
||||
}
|
||||
|
||||
type CustomerView = {
|
||||
npc: Npc.Handle,
|
||||
bubble: BillboardGui,
|
||||
dish: Model?,
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
userId: number,
|
||||
displayName: string,
|
||||
data: any, -- 세이브 데이터(Data.TEMPLATE 모양)
|
||||
now: number,
|
||||
getCharacter: (() -> Model?)?,
|
||||
notify: ((key: string, args: { [string]: any }?) -> ())?,
|
||||
lang: string?,
|
||||
}
|
||||
|
||||
local PlotController = {}
|
||||
PlotController.__index = PlotController
|
||||
|
||||
export type PlotController = typeof(setmetatable(
|
||||
{} :: {
|
||||
slot: Slot,
|
||||
owner: Instance,
|
||||
opts: Options,
|
||||
data: any,
|
||||
shop: Shop.Shop,
|
||||
views: { [number]: CustomerView },
|
||||
handModels: { Model },
|
||||
counterModels: { Model },
|
||||
lastCook: number,
|
||||
coin: Sound,
|
||||
buySound: Sound,
|
||||
helper: Npc.Handle?,
|
||||
guide: BasePart,
|
||||
guideValue: ObjectValue,
|
||||
rng: Random,
|
||||
lang: string,
|
||||
tut: number,
|
||||
destroyed: boolean,
|
||||
connections: { RBXScriptConnection },
|
||||
},
|
||||
PlotController
|
||||
))
|
||||
|
||||
local function makeSound(parent: Instance, id: string, volume: number, looped: boolean?): Sound
|
||||
local s = Instance.new("Sound")
|
||||
s.SoundId = id
|
||||
s.Volume = volume
|
||||
s.Looped = looped == true
|
||||
s.RollOffMaxDistance = 80
|
||||
s.Parent = parent
|
||||
return s
|
||||
end
|
||||
|
||||
function PlotController.new(slot: Slot, owner: Instance, opts: Options): PlotController
|
||||
local data = opts.data
|
||||
local self = setmetatable({
|
||||
slot = slot,
|
||||
owner = owner,
|
||||
opts = opts,
|
||||
data = data,
|
||||
shop = Shop.new(data.Money, data.Bought, opts.now),
|
||||
views = {},
|
||||
handModels = {},
|
||||
counterModels = {},
|
||||
lastCook = 0,
|
||||
coin = makeSound(slot.refs.stove, Sounds.COIN, 0.7),
|
||||
buySound = makeSound(slot.refs.stove, Sounds.BUY, 0.8),
|
||||
helper = nil :: Npc.Handle?,
|
||||
guide = Instance.new("Part") :: BasePart,
|
||||
guideValue = Instance.new("ObjectValue"),
|
||||
rng = Random.new(opts.userId + slot.index),
|
||||
lang = opts.lang or "ko",
|
||||
tut = if data.TutorialDone then 0 else 1,
|
||||
destroyed = false,
|
||||
connections = {},
|
||||
}, PlotController)
|
||||
|
||||
slot.model:SetAttribute("OwnerId", opts.userId)
|
||||
slot.refs.nameLabel.Text = Locale.t("ko", "plotOwner", { name = opts.displayName })
|
||||
|
||||
-- 튜토리얼 화살표가 가리킬 보이지 않는 표시
|
||||
local guide = self.guide
|
||||
guide.Name = "Guide"
|
||||
guide.Anchored = true
|
||||
guide.CanCollide = false
|
||||
guide.CanQuery = false
|
||||
guide.CanTouch = false
|
||||
guide.Transparency = 1
|
||||
guide.Size = Vector3.new(1, 1, 1)
|
||||
guide.Parent = slot.refs.dynamic
|
||||
self.guideValue.Name = "Guide"
|
||||
self.guideValue.Parent = owner
|
||||
|
||||
-- 조리 버튼(ProximityPrompt)은 주인 화면에만 클라이언트가 만듭니다. 서버는 조리대 속성으로 상태만 알려 줍니다.
|
||||
slot.refs.stove:SetAttribute("OwnerId", opts.userId)
|
||||
|
||||
PlotBuilder.buildUpgrades(slot.refs, slot.cf, self.shop.bought)
|
||||
self:refreshHelper()
|
||||
self:refreshPrompt()
|
||||
self:sync()
|
||||
return self
|
||||
end
|
||||
|
||||
function PlotController.isOwner(self: PlotController, player: Player): boolean
|
||||
return player.UserId == self.opts.userId
|
||||
end
|
||||
|
||||
function PlotController.character(self: PlotController): Model?
|
||||
if self.opts.getCharacter then
|
||||
return self.opts.getCharacter()
|
||||
end
|
||||
if self.owner:IsA("Player") then
|
||||
return self.owner.Character
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function PlotController.notify(self: PlotController, key: string, args: { [string]: any }?)
|
||||
if self.opts.notify then
|
||||
self.opts.notify(key, args)
|
||||
end
|
||||
end
|
||||
|
||||
function PlotController.setLang(self: PlotController, lang: string)
|
||||
self.lang = lang
|
||||
self:refreshPrompt()
|
||||
end
|
||||
|
||||
-- 화면에 필요한 값을 Player 속성으로 내보내고 세이브 데이터에 적습니다.
|
||||
function PlotController.sync(self: PlotController)
|
||||
local shop = self.shop
|
||||
self.data.Money = shop.money
|
||||
self.data.Bought = shop.bought
|
||||
self.data.Served = (self.data.Served or 0)
|
||||
local o = self.owner
|
||||
o:SetAttribute("Money", shop.money)
|
||||
o:SetAttribute("Bought", shop.bought)
|
||||
o:SetAttribute("Stage", shop.stats.stage)
|
||||
o:SetAttribute("Double", shop.moneyMult > 1)
|
||||
o:SetAttribute("Boost", Economy.boostAmount(shop.stats))
|
||||
o:SetAttribute("Tut", self.tut)
|
||||
o:SetAttribute("Plot", self.slot.index)
|
||||
o:SetAttribute("Carry", #shop.hand)
|
||||
end
|
||||
|
||||
-- 조리대 속성: CookMenu(만들 메뉴, 없으면 ""), CookTime(누르는 시간), HandFull
|
||||
function PlotController.refreshPrompt(self: PlotController)
|
||||
local shop = self.shop
|
||||
local stove = self.slot.refs.stove
|
||||
local full = Shop.handFull(shop)
|
||||
local menu = if full then nil else Shop.nextCookMenu(shop)
|
||||
stove:SetAttribute("CookMenu", menu or "")
|
||||
stove:SetAttribute("CookTime", shop.stats.cook)
|
||||
stove:SetAttribute("HandFull", full)
|
||||
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
|
||||
end
|
||||
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
|
||||
else
|
||||
-- 캐릭터가 없을 때(테스트)는 조리대 위에 둡니다.
|
||||
for _, d in m:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
d.Anchored = true
|
||||
end
|
||||
end
|
||||
m.Parent = self.slot.refs.dynamic
|
||||
m:PivotTo(PlotBuilder.counterSlot(self.slot.cf, 1) * CFrame.new(0, 1 + i * 0.6, 1.4))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 캐릭터가 다시 생기면(리스폰) 손에 든 접시 모형을 다시 만듭니다.
|
||||
function PlotController.rebuildHand(self: PlotController)
|
||||
for _, m in self.handModels do
|
||||
m:Destroy()
|
||||
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))
|
||||
end
|
||||
self:layoutHand()
|
||||
end
|
||||
|
||||
function PlotController.layoutCounter(self: PlotController)
|
||||
for i, m in self.counterModels do
|
||||
m:PivotTo(PlotBuilder.counterSlot(self.slot.cf, i))
|
||||
end
|
||||
end
|
||||
|
||||
function PlotController.setTut(self: PlotController, step: number)
|
||||
if self.tut == step then
|
||||
return
|
||||
end
|
||||
self.tut = step
|
||||
if step == 0 then
|
||||
self.data.TutorialDone = true
|
||||
self:notify("tutDone")
|
||||
end
|
||||
self.owner:SetAttribute("Tut", step)
|
||||
end
|
||||
|
||||
function PlotController.updateGuide(self: PlotController)
|
||||
local target: Vector3? = nil
|
||||
if self.tut == 1 then
|
||||
target = self.slot.refs.stove.Position + Vector3.new(0, 1, 0)
|
||||
elseif self.tut == 2 then
|
||||
-- 든 접시를 기다리는 손님 자리
|
||||
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)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if target then
|
||||
self.guide.Position = target
|
||||
self.guideValue.Value = self.guide
|
||||
else
|
||||
self.guideValue.Value = nil
|
||||
end
|
||||
end
|
||||
|
||||
function PlotController.cook(self: PlotController): string?
|
||||
local menu = Shop.cook(self.shop)
|
||||
if not menu then
|
||||
return nil
|
||||
end
|
||||
self.lastCook = self.shop.now
|
||||
local dish = Food.dish(menu, PlotBuilder.counterSlot(self.slot.cf, 1), self.slot.refs.dynamic)
|
||||
table.insert(self.handModels, dish)
|
||||
self:layoutHand()
|
||||
if self.tut == 1 then
|
||||
self:setTut(2)
|
||||
end
|
||||
self:refreshPrompt()
|
||||
self:sync()
|
||||
return menu
|
||||
end
|
||||
|
||||
function PlotController.pickup(self: PlotController): number
|
||||
local n = Shop.pickup(self.shop)
|
||||
for _ = 1, n do
|
||||
local m = table.remove(self.counterModels, 1)
|
||||
if m then
|
||||
table.insert(self.handModels, m)
|
||||
end
|
||||
end
|
||||
if n > 0 then
|
||||
self:layoutHand()
|
||||
self:layoutCounter()
|
||||
if self.tut == 1 then
|
||||
self:setTut(2)
|
||||
end
|
||||
self:refreshPrompt()
|
||||
self:sync()
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local function floatText(parent: BasePart, text: string)
|
||||
local gui =
|
||||
Build.billboard(parent, text, UDim2.fromOffset(140, 60), Vector3.new(0, 2, 0), Color3.fromRGB(255, 215, 40))
|
||||
gui.AlwaysOnTop = true
|
||||
local label = gui:FindFirstChild("Text") :: TextLabel
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Thickness = 3
|
||||
stroke.Color = Color3.fromRGB(120, 60, 0)
|
||||
stroke.Parent = label
|
||||
TweenService:Create(gui, TweenInfo.new(1.2, Enum.EasingStyle.Quad), { StudsOffset = Vector3.new(0, 6, 0) }):Play()
|
||||
TweenService:Create(label, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
|
||||
TextTransparency = 1,
|
||||
}):Play()
|
||||
task.delay(1.3, function()
|
||||
gui:Destroy()
|
||||
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
|
||||
end
|
||||
end
|
||||
self:layoutHand()
|
||||
if view then
|
||||
local label = view.bubble:FindFirstChild("Text") :: TextLabel?
|
||||
if label then
|
||||
label.Text = "😋"
|
||||
end
|
||||
floatText(view.npc.root, "+" .. Locale.number(earn))
|
||||
end
|
||||
self.coin:Play()
|
||||
self.data.Served = (self.data.Served or 0) + 1
|
||||
self.data.Earned = (self.data.Earned or 0) + earn
|
||||
if self.tut == 2 then
|
||||
self:setTut(3)
|
||||
end
|
||||
self:refreshPrompt()
|
||||
self:sync()
|
||||
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))
|
||||
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 icon = Economy.MENUS[e.menu].icon
|
||||
local bubble = Build.billboard(npc.root, icon, UDim2.fromOffset(70, 70), Vector3.new(0, 4, 0))
|
||||
bubble.Name = "Order"
|
||||
self.views[e.id] = { npc = npc, bubble = bubble, dish = nil }
|
||||
Npc.walk(npc, path, Economy.WALK_IN)
|
||||
elseif e.kind == "seated" then
|
||||
local c = self.shop.customers[e.id]
|
||||
local v = self.views[e.id]
|
||||
if c and v then
|
||||
Npc.sit(v.npc, PlotBuilder.seatCFrame(cf, c.seat))
|
||||
end
|
||||
elseif e.kind == "leave" then
|
||||
local v = self.views[e.id]
|
||||
self.views[e.id] = nil
|
||||
if v then
|
||||
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(v.npc, back, Economy.WALK_IN, function()
|
||||
v.npc.model:Destroy()
|
||||
end)
|
||||
task.delay(Economy.WALK_IN + 1, function()
|
||||
if v.npc.model.Parent then
|
||||
v.npc.model:Destroy()
|
||||
end
|
||||
end)
|
||||
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)
|
||||
table.insert(self.counterModels, m)
|
||||
self:layoutCounter()
|
||||
end
|
||||
end
|
||||
|
||||
-- 매 프레임(0.1초 간격) 호출합니다.
|
||||
function PlotController.update(self: PlotController, now: number)
|
||||
if self.destroyed then
|
||||
return
|
||||
end
|
||||
local events = Shop.tick(self.shop, now)
|
||||
for _, e in events do
|
||||
self:onEvent(e)
|
||||
end
|
||||
local char = self:character()
|
||||
local root = char and char:FindFirstChild("HumanoidRootPart") :: BasePart?
|
||||
if root then
|
||||
local pos = root.Position
|
||||
if #self.shop.counter > 0 and not Shop.handFull(self.shop) then
|
||||
local counterPos = self.slot.refs.counter.Position
|
||||
if (Vector3.new(pos.X, counterPos.Y, pos.Z) - counterPos).Magnitude < PICKUP_RANGE then
|
||||
self:pickup()
|
||||
end
|
||||
end
|
||||
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
|
||||
self:serve(id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #events > 0 then
|
||||
self:refreshPrompt()
|
||||
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.buySound:Play()
|
||||
self:refreshHelper()
|
||||
self:refreshPrompt()
|
||||
if self.tut == 3 then
|
||||
self:setTut(0)
|
||||
end
|
||||
local name = if self.lang == "ko" then p.name else p.nameEn
|
||||
if self.shop.stats.stage > before.stage then
|
||||
self:notify("expanded")
|
||||
else
|
||||
self:notify("purchased", { name = name })
|
||||
end
|
||||
self:sync()
|
||||
return true, nil
|
||||
end
|
||||
|
||||
function PlotController.addMoney(self: PlotController, amount: number)
|
||||
Shop.addMoney(self.shop, amount)
|
||||
self:sync()
|
||||
end
|
||||
|
||||
function PlotController.setDouble(self: PlotController, on: boolean)
|
||||
self.shop.moneyMult = if on then 2 else 1
|
||||
self:sync()
|
||||
end
|
||||
|
||||
function PlotController.destroy(self: PlotController)
|
||||
self.destroyed = true
|
||||
for _, c in self.connections do
|
||||
c:Disconnect()
|
||||
end
|
||||
self.slot.refs.stove:SetAttribute("OwnerId", nil)
|
||||
self.slot.refs.stove:SetAttribute("CookMenu", nil)
|
||||
self.coin:Destroy()
|
||||
self.buySound:Destroy()
|
||||
self.guideValue:Destroy()
|
||||
for _, m in self.handModels do
|
||||
m:Destroy()
|
||||
end
|
||||
self.slot.refs.dynamic:ClearAllChildren()
|
||||
self.slot.refs.upgrades:ClearAllChildren()
|
||||
self.slot.refs.nameLabel.Text = Locale.t("ko", "plotEmpty") .. " / " .. Locale.t("en", "plotEmpty")
|
||||
self.slot.refs.menuLabel.Text = ""
|
||||
self.slot.model:SetAttribute("OwnerId", nil)
|
||||
end
|
||||
|
||||
return PlotController
|
||||
52
bunsik-tycoon/src/server/PlotLayout.luau
Normal file
52
bunsik-tycoon/src/server/PlotLayout.luau
Normal file
@@ -0,0 +1,52 @@
|
||||
--!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
|
||||
64
bunsik-tycoon/src/server/Receipts.luau
Normal file
64
bunsik-tycoon/src/server/Receipts.luau
Normal file
@@ -0,0 +1,64 @@
|
||||
--!strict
|
||||
-- 개발자 상품 결제 처리: 결제 한 번에 정확히 한 번만 지급합니다(DECISIONS.md 2절).
|
||||
-- 로블록스 API에 직접 기대지 않게 프로필과 지급 함수를 받아서, lune 단위 테스트로도 검증합니다.
|
||||
|
||||
local Receipts = {}
|
||||
|
||||
Receipts.CACHE_SIZE = 100
|
||||
|
||||
-- Enum.ProductPurchaseDecision 대신 문자열을 돌려주고, 호출하는 쪽에서 Enum으로 바꿉니다.
|
||||
export type Decision = "Granted" | "NotProcessedYet"
|
||||
|
||||
export type ProfileLike = {
|
||||
Data: { PurchaseIdCache: { string }? },
|
||||
LastSavedData: { PurchaseIdCache: { string }? },
|
||||
IsActive: (self: any) -> boolean,
|
||||
Save: (self: any) -> (),
|
||||
OnAfterSave: { Wait: (self: any) -> () },
|
||||
}
|
||||
|
||||
local function isSaved(profile: ProfileLike, purchaseId: string): boolean
|
||||
local saved = profile.LastSavedData and profile.LastSavedData.PurchaseIdCache
|
||||
return saved ~= nil and table.find(saved, purchaseId) ~= nil
|
||||
end
|
||||
|
||||
-- profile이 nil이면(아직 로드 안 됨, 이미 나감) 나중에 다시 시도하게 합니다.
|
||||
function Receipts.process(profile: ProfileLike?, purchaseId: string, grant: () -> boolean): Decision
|
||||
if profile == nil or not profile:IsActive() then
|
||||
return "NotProcessedYet"
|
||||
end
|
||||
local cache = profile.Data.PurchaseIdCache
|
||||
if cache == nil then
|
||||
return "NotProcessedYet"
|
||||
end
|
||||
if table.find(cache, purchaseId) == nil then
|
||||
local ok, granted = pcall(grant)
|
||||
if not ok or granted ~= true then
|
||||
if not ok then
|
||||
warn("[Bunsik] 상품 지급 오류:", granted)
|
||||
end
|
||||
return "NotProcessedYet"
|
||||
end
|
||||
while #cache >= Receipts.CACHE_SIZE do
|
||||
table.remove(cache, 1)
|
||||
end
|
||||
table.insert(cache, purchaseId)
|
||||
end
|
||||
-- 지급과 PurchaseId가 같이 저장된 것을 확인한 뒤에만 완료로 알립니다.
|
||||
if isSaved(profile, purchaseId) then
|
||||
return "Granted"
|
||||
end
|
||||
while profile:IsActive() do
|
||||
local last = profile.LastSavedData
|
||||
profile:Save()
|
||||
if profile.LastSavedData == last then
|
||||
profile.OnAfterSave:Wait()
|
||||
end
|
||||
if isSaved(profile, purchaseId) then
|
||||
return "Granted"
|
||||
end
|
||||
end
|
||||
return "NotProcessedYet"
|
||||
end
|
||||
|
||||
return Receipts
|
||||
179
bunsik-tycoon/src/server/World.luau
Normal file
179
bunsik-tycoon/src/server/World.luau
Normal file
@@ -0,0 +1,179 @@
|
||||
--!strict
|
||||
-- 맵: 가운데 "분식 거리"와 양쪽에 부지 6칸. 모두 코드로 지어서 리포가 원본이 됩니다.
|
||||
|
||||
local Lighting = game:GetService("Lighting")
|
||||
|
||||
local Build = require(script.Parent.Build)
|
||||
local PlotBuilder = require(script.Parent.PlotBuilder)
|
||||
local Locale = require(game:GetService("ReplicatedStorage").Shared.Locale)
|
||||
|
||||
local World = {}
|
||||
|
||||
World.PLOT_COUNT = 6
|
||||
World.STREET_HALF = 14 -- 길 폭의 절반
|
||||
local PLOT_X = { -80, 0, 80 }
|
||||
local PLOT_Z = 14 + 40 + 2 -- 길 가장자리 + 부지 반 길이 + 여유
|
||||
|
||||
local function rgb(r: number, g: number, b: number): Color3
|
||||
return Color3.fromRGB(r, g, b)
|
||||
end
|
||||
|
||||
-- i번째 부지의 기준 좌표. 입구(+Z)가 길을 봅니다.
|
||||
function World.plotCFrame(i: number): CFrame
|
||||
local col = ((i - 1) % 3) + 1
|
||||
local north = i <= 3
|
||||
local x = PLOT_X[col]
|
||||
if north then
|
||||
return CFrame.new(x, 0, -PLOT_Z)
|
||||
end
|
||||
return CFrame.new(x, 0, PLOT_Z) * CFrame.Angles(0, math.pi, 0)
|
||||
end
|
||||
|
||||
local function setupLighting()
|
||||
Lighting.ClockTime = 14.5
|
||||
Lighting.Brightness = 2.2
|
||||
Lighting.Ambient = rgb(120, 115, 110)
|
||||
Lighting.OutdoorAmbient = rgb(150, 145, 140)
|
||||
Lighting.EnvironmentDiffuseScale = 0.5
|
||||
Lighting.EnvironmentSpecularScale = 0.5
|
||||
Lighting.GlobalShadows = true
|
||||
if not Lighting:FindFirstChildOfClass("Atmosphere") then
|
||||
local a = Instance.new("Atmosphere")
|
||||
a.Density = 0.25
|
||||
a.Color = rgb(200, 220, 255)
|
||||
a.Decay = rgb(120, 140, 170)
|
||||
a.Parent = Lighting
|
||||
end
|
||||
if not Lighting:FindFirstChildOfClass("Sky") then
|
||||
Instance.new("Sky").Parent = Lighting
|
||||
end
|
||||
end
|
||||
|
||||
export type Slot = {
|
||||
index: number,
|
||||
cf: CFrame,
|
||||
model: Model,
|
||||
refs: PlotBuilder.BaseRefs,
|
||||
}
|
||||
|
||||
-- 맵을 짓고 부지 목록을 돌려줍니다. 여러 번 불러도 한 번만 짓습니다.
|
||||
function World.build(): { Slot }
|
||||
local existing = workspace:FindFirstChild("BunsikWorld")
|
||||
if existing then
|
||||
existing:Destroy()
|
||||
end
|
||||
setupLighting()
|
||||
local root = Instance.new("Folder")
|
||||
root.Name = "BunsikWorld"
|
||||
root.Parent = workspace
|
||||
|
||||
-- 잔디 바닥, 길, 인도, 차선
|
||||
Build.part(root, {
|
||||
name = "Ground",
|
||||
size = Vector3.new(400, 2, 260),
|
||||
cf = CFrame.new(0, -1, 0),
|
||||
color = rgb(110, 170, 90),
|
||||
material = Enum.Material.Grass,
|
||||
})
|
||||
Build.part(root, {
|
||||
name = "Street",
|
||||
size = Vector3.new(260, 0.2, World.STREET_HALF * 2),
|
||||
cf = CFrame.new(0, 0.1, 0),
|
||||
color = rgb(70, 70, 75),
|
||||
material = Enum.Material.Asphalt,
|
||||
})
|
||||
for i = -6, 6 do
|
||||
Build.part(root, {
|
||||
size = Vector3.new(8, 0.05, 0.6),
|
||||
cf = CFrame.new(i * 18, 0.22, 0),
|
||||
color = rgb(250, 240, 200),
|
||||
collide = false,
|
||||
})
|
||||
end
|
||||
-- 가로등
|
||||
for i = -3, 3 do
|
||||
for _, side in { -1, 1 } do
|
||||
local x = i * 40 + 20 * side
|
||||
local z = side * (World.STREET_HALF - 1)
|
||||
Build.part(root, {
|
||||
size = Vector3.new(0.6, 14, 0.6),
|
||||
cf = CFrame.new(x, 7, z),
|
||||
color = rgb(60, 60, 65),
|
||||
material = Enum.Material.Metal,
|
||||
})
|
||||
local lamp = Build.part(root, {
|
||||
size = Vector3.new(1.6, 1.6, 1.6),
|
||||
cf = CFrame.new(x, 14.5, z),
|
||||
color = rgb(255, 240, 200),
|
||||
shape = Enum.PartType.Ball,
|
||||
neon = true,
|
||||
collide = false,
|
||||
})
|
||||
local light = Instance.new("PointLight")
|
||||
light.Range = 24
|
||||
light.Brightness = 0.7
|
||||
light.Color = rgb(255, 230, 180)
|
||||
light.Parent = lamp
|
||||
end
|
||||
end
|
||||
-- 거리 입구 아치
|
||||
for _, x in { -128, 128 } do
|
||||
for _, side in { -1, 1 } do
|
||||
Build.part(root, {
|
||||
size = Vector3.new(2, 20, 2),
|
||||
cf = CFrame.new(x, 10, side * World.STREET_HALF),
|
||||
color = rgb(200, 50, 40),
|
||||
})
|
||||
end
|
||||
local arch = Build.part(root, {
|
||||
name = "Arch",
|
||||
size = Vector3.new(2, 5, World.STREET_HALF * 2 + 4),
|
||||
cf = CFrame.new(x, 21, 0),
|
||||
color = rgb(255, 215, 80),
|
||||
})
|
||||
local face = if x < 0 then Enum.NormalId.Right else Enum.NormalId.Left
|
||||
Build.label(arch, face, "분식 거리 · BUNSIK STREET", rgb(190, 40, 30))
|
||||
end
|
||||
-- 바깥 나무
|
||||
local rng = Random.new(7)
|
||||
for _ = 1, 40 do
|
||||
local x = rng:NextNumber(-190, 190)
|
||||
local z = (if rng:NextNumber() < 0.5 then -1 else 1) * rng:NextNumber(102, 125)
|
||||
Build.cylinder(root, CFrame.new(x, 3, z), 6, 1.6, rgb(120, 80, 50))
|
||||
Build.part(root, {
|
||||
size = Vector3.new(9, 9, 9),
|
||||
cf = CFrame.new(x, 9, z),
|
||||
color = rgb(70 + rng:NextInteger(0, 30), 150, 70),
|
||||
shape = Enum.PartType.Ball,
|
||||
material = Enum.Material.LeafyGrass,
|
||||
})
|
||||
end
|
||||
|
||||
-- 시작 지점(길 가운데). 들어오면 바로 자기 부지로 옮겨집니다.
|
||||
local spawn = Instance.new("SpawnLocation")
|
||||
spawn.Name = "Spawn"
|
||||
spawn.Anchored = true
|
||||
spawn.Size = Vector3.new(10, 0.4, 10)
|
||||
spawn.CFrame = CFrame.new(0, 0.3, 0)
|
||||
spawn.Duration = 0
|
||||
spawn.Transparency = 1
|
||||
spawn.CanCollide = false
|
||||
spawn.Parent = root
|
||||
|
||||
local plots = Instance.new("Folder")
|
||||
plots.Name = "Plots"
|
||||
plots.Parent = root
|
||||
local slots: { Slot } = {}
|
||||
for i = 1, World.PLOT_COUNT do
|
||||
local cf = World.plotCFrame(i)
|
||||
local model = Instance.new("Model")
|
||||
model.Name = "Plot" .. i
|
||||
model.Parent = plots
|
||||
local refs = PlotBuilder.buildBase(model, cf)
|
||||
refs.nameLabel.Text = Locale.t("ko", "plotEmpty") .. " / " .. Locale.t("en", "plotEmpty")
|
||||
table.insert(slots, { index = i, cf = cf, model = model, refs = refs })
|
||||
end
|
||||
return slots
|
||||
end
|
||||
|
||||
return World
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
-- 분식집 첫 10분 경제 수치. ECONOMY.md 표, tools/economy_sim.py 와 같은 숫자여야 합니다.
|
||||
-- 분식집 경제 수치. ECONOMY.md 표와 같은 숫자여야 합니다.
|
||||
-- 숫자를 바꾸면 `lune run tools/sim.luau` 로 구매 시점을 다시 확인합니다.
|
||||
|
||||
export type Effect = {
|
||||
seats: number?, -- 테이블 수
|
||||
@@ -8,19 +9,44 @@ export type Effect = {
|
||||
price: number?, -- 가격 배율
|
||||
helper: boolean?, -- 알바생(조리 자동)
|
||||
menu: string?, -- 해금할 메뉴
|
||||
carry: number?, -- 한 번에 드는 접시 수
|
||||
stage: number?, -- 가게 단계(2 = 실내 분식집)
|
||||
}
|
||||
|
||||
export type Purchase = {
|
||||
id: string,
|
||||
name: string,
|
||||
nameEn: string,
|
||||
cost: number,
|
||||
effect: Effect,
|
||||
}
|
||||
|
||||
export type Menu = {
|
||||
name: string,
|
||||
nameEn: string,
|
||||
price: number,
|
||||
icon: string,
|
||||
}
|
||||
|
||||
export type Stats = {
|
||||
seats: number,
|
||||
spawn: number,
|
||||
cook: number,
|
||||
price: number,
|
||||
helper: boolean,
|
||||
menus: { string },
|
||||
carry: number,
|
||||
stage: number,
|
||||
}
|
||||
|
||||
local Economy = {}
|
||||
|
||||
Economy.WALK = 5 -- 조리대 -> 테이블 -> 조리대 왕복(초)
|
||||
Economy.WALK = 5 -- 조리대 -> 테이블 -> 조리대 왕복(초, 시뮬레이터 가정)
|
||||
Economy.EAT = 6 -- 식사 시간(초)
|
||||
Economy.WALK_IN = 2.5 -- 손님이 입구에서 자리까지 걷는 시간(초)
|
||||
Economy.COUNTER_MAX = 3 -- 알바생이 미리 만들어 두는 접시 최대 수
|
||||
Economy.BOOST_MINUTES = 10 -- 돈 부스트 팩: 현재 1분 매출 x 10분
|
||||
Economy.BOOST_MIN = 100 -- 돈 부스트 팩 최소 지급액
|
||||
|
||||
Economy.START = {
|
||||
money = 0,
|
||||
@@ -30,25 +56,123 @@ Economy.START = {
|
||||
price = 1,
|
||||
helper = false,
|
||||
menus = { "Tteokbokki" },
|
||||
carry = 1,
|
||||
stage = 1,
|
||||
}
|
||||
|
||||
Economy.MENUS = {
|
||||
Tteokbokki = { name = "떡볶이", price = 10 },
|
||||
Gimbap = { name = "김밥", price = 20 },
|
||||
Sundae = { name = "순대", price = 35 },
|
||||
}
|
||||
Tteokbokki = { name = "떡볶이", nameEn = "Tteokbokki", price = 10, icon = "🌶️" },
|
||||
Gimbap = { name = "김밥", nameEn = "Gimbap", price = 20, icon = "🍙" },
|
||||
Sundae = { name = "순대", nameEn = "Sundae", price = 35, icon = "🌭" },
|
||||
Eomuk = { name = "어묵", nameEn = "Fish Cake", price = 50, icon = "🍢" },
|
||||
Twigim = { name = "튀김", nameEn = "Twigim", price = 70, icon = "🍤" },
|
||||
} :: { [string]: Menu }
|
||||
|
||||
-- 메뉴 표시 순서
|
||||
Economy.MENU_ORDER = { "Tteokbokki", "Gimbap", "Sundae", "Eomuk", "Twigim" }
|
||||
|
||||
-- 1~10: 첫 10분(1단계 포장마차). 11~20: 2단계 실내 분식집.
|
||||
Economy.PURCHASES = {
|
||||
{ id = "Table2", name = "테이블 2", cost = 10, effect = { seats = 2 } },
|
||||
{ id = "UnlockGimbap", name = "김밥 해금", cost = 40, effect = { menu = "Gimbap" } },
|
||||
{ id = "Sign1", name = "간판 Lv1", cost = 70, effect = { spawn = 5 } },
|
||||
{ id = "Stove1", name = "화구 Lv1", cost = 90, effect = { cook = 1.5 } },
|
||||
{ id = "Table3", name = "테이블 3", cost = 120, effect = { seats = 3 } },
|
||||
{ id = "UnlockSundae", name = "순대 해금", cost = 160, effect = { menu = "Sundae" } },
|
||||
{ id = "Sauce1", name = "양념 비법 Lv1", cost = 240, effect = { price = 1.5 } },
|
||||
{ id = "Helper", name = "알바생 고용", cost = 360, effect = { helper = true } },
|
||||
{ id = "Table4", name = "테이블 4", cost = 480, effect = { seats = 4, spawn = 4 } },
|
||||
{ id = "Expand", name = "실내 분식집 확장", cost = 600, effect = {} },
|
||||
{ id = "Table2", name = "테이블 2", nameEn = "Table 2", cost = 10, effect = { seats = 2 } },
|
||||
{ id = "UnlockGimbap", name = "김밥 해금", nameEn = "Unlock Gimbap", cost = 40, effect = { menu = "Gimbap" } },
|
||||
{ id = "Sign1", name = "간판 Lv1", nameEn = "Sign Lv1", cost = 70, effect = { spawn = 5 } },
|
||||
{ id = "Stove1", name = "화구 Lv1", nameEn = "Stove Lv1", cost = 90, effect = { cook = 1.5 } },
|
||||
{ id = "Table3", name = "테이블 3", nameEn = "Table 3", cost = 120, effect = { seats = 3 } },
|
||||
{ id = "UnlockSundae", name = "순대 해금", nameEn = "Unlock Sundae", cost = 160, effect = { menu = "Sundae" } },
|
||||
{ id = "Sauce1", name = "양념 비법 Lv1", nameEn = "Secret Sauce Lv1", cost = 240, effect = { price = 1.5 } },
|
||||
{ id = "Helper", name = "알바생 고용", nameEn = "Hire Helper", cost = 360, effect = { helper = true } },
|
||||
{ id = "Table4", name = "테이블 4", nameEn = "Table 4", cost = 480, effect = { seats = 4, spawn = 4 } },
|
||||
{ id = "Expand", name = "실내 분식집 확장", nameEn = "Indoor Shop", cost = 600, effect = { stage = 2 } },
|
||||
|
||||
{ id = "Tray1", name = "쟁반", nameEn = "Tray", cost = 700, effect = { carry = 2 } },
|
||||
{ id = "Table5", name = "테이블 5", nameEn = "Table 5", cost = 800, effect = { seats = 5 } },
|
||||
{
|
||||
id = "UnlockEomuk",
|
||||
name = "어묵 해금",
|
||||
nameEn = "Unlock Fish Cake",
|
||||
cost = 950,
|
||||
effect = { menu = "Eomuk" },
|
||||
},
|
||||
{ id = "Sign2", name = "간판 Lv2", nameEn = "Sign Lv2", cost = 1150, effect = { spawn = 3 } },
|
||||
{ id = "Table6", name = "테이블 6", nameEn = "Table 6", cost = 1400, effect = { seats = 6 } },
|
||||
{ id = "Stove2", name = "화구 Lv2", nameEn = "Stove Lv2", cost = 1700, effect = { cook = 1 } },
|
||||
{
|
||||
id = "UnlockTwigim",
|
||||
name = "튀김 해금",
|
||||
nameEn = "Unlock Twigim",
|
||||
cost = 2000,
|
||||
effect = { menu = "Twigim" },
|
||||
},
|
||||
{ id = "Sauce2", name = "양념 비법 Lv2", nameEn = "Secret Sauce Lv2", cost = 2500, effect = { price = 2 } },
|
||||
{ id = "Tray2", name = "큰 쟁반", nameEn = "Big Tray", cost = 3000, effect = { carry = 3 } },
|
||||
{ id = "Table8", name = "테이블 7·8", nameEn = "Tables 7-8", cost = 3600, effect = { seats = 8, spawn = 2.5 } },
|
||||
} :: { Purchase }
|
||||
|
||||
Economy.MAX_SEATS = 8
|
||||
|
||||
-- 앞에서부터 `bought`개를 산 상태의 능력치
|
||||
function Economy.statsAt(bought: number): Stats
|
||||
local s = Economy.START
|
||||
local stats: Stats = {
|
||||
seats = s.seats,
|
||||
spawn = s.spawn,
|
||||
cook = s.cook,
|
||||
price = s.price,
|
||||
helper = s.helper,
|
||||
menus = table.clone(s.menus),
|
||||
carry = s.carry,
|
||||
stage = s.stage,
|
||||
}
|
||||
for i = 1, math.min(bought, #Economy.PURCHASES) do
|
||||
local e = Economy.PURCHASES[i].effect
|
||||
if e.seats then
|
||||
stats.seats = e.seats
|
||||
end
|
||||
if e.spawn then
|
||||
stats.spawn = e.spawn
|
||||
end
|
||||
if e.cook then
|
||||
stats.cook = e.cook
|
||||
end
|
||||
if e.price then
|
||||
stats.price = e.price
|
||||
end
|
||||
if e.helper then
|
||||
stats.helper = true
|
||||
end
|
||||
if e.menu then
|
||||
table.insert(stats.menus, e.menu)
|
||||
end
|
||||
if e.carry then
|
||||
stats.carry = e.carry
|
||||
end
|
||||
if e.stage then
|
||||
stats.stage = e.stage
|
||||
end
|
||||
end
|
||||
return stats
|
||||
end
|
||||
|
||||
-- 한 접시 값(정수). moneyMult는 2배 수익 게임패스(1 또는 2)
|
||||
function Economy.dishPrice(menu: string, stats: Stats, moneyMult: number): number
|
||||
return math.floor(Economy.MENUS[menu].price * stats.price) * moneyMult
|
||||
end
|
||||
|
||||
-- 현재 능력치로 1분에 버는 돈(대략). 돈 부스트 팩 지급액 계산용
|
||||
function Economy.incomePerMinute(stats: Stats): number
|
||||
local total = 0
|
||||
for _, m in stats.menus do
|
||||
total += Economy.dishPrice(m, stats, 1)
|
||||
end
|
||||
local avg = total / #stats.menus
|
||||
-- 손님 수는 간격과 자리 회전(식사+이동+조리) 중 느린 쪽으로 제한
|
||||
local perSeat = 60 / (Economy.EAT + Economy.WALK_IN + Economy.WALK + stats.cook)
|
||||
local customers = math.min(60 / stats.spawn, perSeat * stats.seats)
|
||||
return math.floor(customers * avg)
|
||||
end
|
||||
|
||||
function Economy.boostAmount(stats: Stats): number
|
||||
return math.max(Economy.BOOST_MIN, Economy.incomePerMinute(stats) * Economy.BOOST_MINUTES)
|
||||
end
|
||||
|
||||
return Economy
|
||||
|
||||
127
bunsik-tycoon/src/shared/Locale.luau
Normal file
127
bunsik-tycoon/src/shared/Locale.luau
Normal file
@@ -0,0 +1,127 @@
|
||||
--!strict
|
||||
-- 화면 글자(한국어·영어). 키가 없으면 키 이름을 그대로 보여 줘서 빠진 번역이 바로 보입니다.
|
||||
|
||||
local Locale = {}
|
||||
|
||||
local STRINGS: { [string]: { [string]: string } } = {
|
||||
ko = {
|
||||
title = "분식집 타이쿤",
|
||||
money = "{money}원",
|
||||
shop = "업그레이드",
|
||||
buy = "사기",
|
||||
bought = "완료",
|
||||
locked = "잠김",
|
||||
notEnough = "돈이 {need}원 더 필요해요",
|
||||
maxed = "모든 업그레이드를 샀어요! 2호점은 다음 업데이트에서 열려요",
|
||||
stage1 = "1단계 · 포장마차",
|
||||
stage2 = "2단계 · 실내 분식집",
|
||||
next = "다음",
|
||||
close = "닫기",
|
||||
language = "English",
|
||||
cookAction = "{menu} 만들기",
|
||||
cookWait = "손님 기다리는 중",
|
||||
cookHandFull = "손이 꽉 찼어요",
|
||||
stoveObject = "조리대",
|
||||
tut1 = "손님이 왔어요! 빛나는 조리대로 가서 버튼을 꾹 누르세요",
|
||||
tut2 = "다 만들었어요! 접시를 손님 자리로 가져가세요",
|
||||
tut3 = "돈을 벌었어요! 아래 [사기] 버튼으로 테이블을 사세요",
|
||||
tutDone = "잘했어요! 계속 손님을 받고 가게를 키워 보세요",
|
||||
double = "2배 수익",
|
||||
doubleOwned = "2배 수익 적용 중",
|
||||
doubleDesc = "모든 판매 금액이 영원히 2배",
|
||||
boost = "돈 부스트",
|
||||
boostDesc = "지금 매출 10분치 {amount}원 즉시 받기",
|
||||
boostGot = "돈 부스트 {amount}원을 받았어요!",
|
||||
purchased = "{name} 구매 완료!",
|
||||
expanded = "실내 분식집으로 확장했어요! 새 업그레이드가 열렸어요",
|
||||
plotOwner = "{name}의 분식집",
|
||||
plotEmpty = "빈 가게 자리",
|
||||
helperNote = "알바생이 요리 중! 카운터에서 접시를 가져가세요",
|
||||
saveFail = "저장된 데이터를 불러오지 못했어요. 다시 접속해 주세요",
|
||||
visitor = "다른 친구의 가게예요",
|
||||
devTitle = "개발자 테스트",
|
||||
devMoney = "+1,000원",
|
||||
devDouble = "2배 켜기/끄기",
|
||||
devReset = "처음부터",
|
||||
devResetDone = "진행을 처음으로 되돌렸어요",
|
||||
},
|
||||
en = {
|
||||
title = "Bunsik Tycoon",
|
||||
money = "₩{money}",
|
||||
shop = "Upgrades",
|
||||
buy = "Buy",
|
||||
bought = "Done",
|
||||
locked = "Locked",
|
||||
notEnough = "Need ₩{need} more",
|
||||
maxed = "All upgrades bought! Shop #2 opens in the next update",
|
||||
stage1 = "Stage 1 · Street Stall",
|
||||
stage2 = "Stage 2 · Indoor Shop",
|
||||
next = "Next",
|
||||
close = "Close",
|
||||
language = "한국어",
|
||||
cookAction = "Cook {menu}",
|
||||
cookWait = "Waiting for customers",
|
||||
cookHandFull = "Hands are full",
|
||||
stoveObject = "Stove",
|
||||
tut1 = "A customer is here! Go to the glowing stove and hold the button",
|
||||
tut2 = "Done! Bring the dish to the customer's seat",
|
||||
tut3 = "You earned money! Tap [Buy] at the bottom to get a table",
|
||||
tutDone = "Great job! Keep serving and grow your shop",
|
||||
double = "Double Money",
|
||||
doubleOwned = "Double Money active",
|
||||
doubleDesc = "All sales are doubled forever",
|
||||
boost = "Money Boost",
|
||||
boostDesc = "Get 10 minutes of sales (₩{amount}) now",
|
||||
boostGot = "Money Boost: +₩{amount}!",
|
||||
purchased = "{name} bought!",
|
||||
expanded = "Your shop moved indoors! New upgrades unlocked",
|
||||
plotOwner = "{name}'s Bunsik Shop",
|
||||
plotEmpty = "Empty lot",
|
||||
helperNote = "Your helper is cooking! Grab dishes from the counter",
|
||||
saveFail = "Couldn't load your save. Please rejoin",
|
||||
visitor = "This is a friend's shop",
|
||||
devTitle = "Dev test",
|
||||
devMoney = "+₩1,000",
|
||||
devDouble = "Toggle x2",
|
||||
devReset = "Reset",
|
||||
devResetDone = "Progress reset",
|
||||
},
|
||||
}
|
||||
|
||||
Locale.LANGS = { "ko", "en" }
|
||||
|
||||
function Locale.pick(localeId: string): string
|
||||
if string.sub(string.lower(localeId), 1, 2) == "ko" then
|
||||
return "ko"
|
||||
end
|
||||
return "en"
|
||||
end
|
||||
|
||||
function Locale.t(lang: string, key: string, args: { [string]: any }?): string
|
||||
local tbl = STRINGS[lang] or STRINGS.en
|
||||
local s = tbl[key] or STRINGS.en[key] or key
|
||||
if args then
|
||||
s = string.gsub(s, "{(%w+)}", function(k)
|
||||
local v = args[k]
|
||||
return if v ~= nil then tostring(v) else "{" .. k .. "}"
|
||||
end)
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
function Locale.keys(lang: string): { string }
|
||||
local out = {}
|
||||
for k in STRINGS[lang] do
|
||||
table.insert(out, k)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- 숫자에 천 단위 쉼표
|
||||
function Locale.number(n: number): string
|
||||
local s = tostring(math.floor(n))
|
||||
local out = string.reverse((string.gsub(string.reverse(s), "(%d%d%d)", "%1,")))
|
||||
return (string.gsub(out, "^(-?),", "%1"))
|
||||
end
|
||||
|
||||
return Locale
|
||||
7
bunsik-tycoon/src/shared/Products.luau
Normal file
7
bunsik-tycoon/src/shared/Products.luau
Normal file
@@ -0,0 +1,7 @@
|
||||
--!strict
|
||||
-- 게임패스·개발자 상품 ID. tools/cloud.py products 로 만들고 여기에 적습니다. 0이면 버튼을 숨깁니다.
|
||||
|
||||
return {
|
||||
DOUBLE_MONEY_PASS = 2026574937,
|
||||
MONEY_BOOST_PRODUCT = 3717970589,
|
||||
}
|
||||
236
bunsik-tycoon/src/shared/Shop.luau
Normal file
236
bunsik-tycoon/src/shared/Shop.luau
Normal file
@@ -0,0 +1,236 @@
|
||||
--!strict
|
||||
-- 가게 한 곳의 규칙(손님, 주문, 조리, 서빙, 돈, 구매)을 담은 순수 로직입니다.
|
||||
-- 로블록스 API를 쓰지 않아서 lune 단위 테스트와 시뮬레이터에서 그대로 돌립니다.
|
||||
-- 화면(NPC, 접시 모형, 효과)은 서버의 PlotController가 이벤트를 받아 그립니다.
|
||||
|
||||
-- 로블록스에서는 script.Parent, lune(테스트)에서는 파일 경로로 불러옵니다.
|
||||
local Economy: typeof(require(script.Parent.Economy)) = if script
|
||||
then require(script.Parent.Economy)
|
||||
else (require :: any)("./Economy")
|
||||
|
||||
type Stats = typeof(Economy.statsAt(0))
|
||||
type Purchase = typeof(Economy.PURCHASES[1])
|
||||
|
||||
export type CustomerState = "walking" | "waiting" | "eating"
|
||||
|
||||
export type Customer = {
|
||||
id: number,
|
||||
seat: number,
|
||||
menu: string,
|
||||
state: CustomerState,
|
||||
untilT: number, -- walking/eating이 끝나는 시각
|
||||
}
|
||||
|
||||
export type Event =
|
||||
{ kind: "spawn", id: number, seat: number, menu: string }
|
||||
| { kind: "seated", id: number }
|
||||
| { kind: "leave", id: number, seat: number }
|
||||
| { kind: "counter", menu: string }
|
||||
|
||||
export type Shop = {
|
||||
money: number,
|
||||
bought: number,
|
||||
moneyMult: number,
|
||||
stats: Stats,
|
||||
customers: { [number]: Customer },
|
||||
seatTaken: { [number]: number },
|
||||
hand: { string },
|
||||
counter: { string },
|
||||
now: number,
|
||||
nextSpawn: number,
|
||||
nextHelper: number,
|
||||
menuIndex: number,
|
||||
lastId: number,
|
||||
served: number,
|
||||
earned: number,
|
||||
}
|
||||
|
||||
local Shop = {}
|
||||
|
||||
function Shop.new(money: number, bought: number, now: number): Shop
|
||||
return {
|
||||
money = money,
|
||||
bought = math.clamp(bought, 0, #Economy.PURCHASES),
|
||||
moneyMult = 1,
|
||||
stats = Economy.statsAt(bought),
|
||||
customers = {},
|
||||
seatTaken = {},
|
||||
hand = {},
|
||||
counter = {},
|
||||
now = now,
|
||||
nextSpawn = now, -- 접속하자마자 첫 손님
|
||||
nextHelper = now,
|
||||
menuIndex = 0,
|
||||
lastId = 0,
|
||||
served = 0,
|
||||
earned = 0,
|
||||
}
|
||||
end
|
||||
|
||||
local function freeSeat(self: Shop): number?
|
||||
for seat = 1, self.stats.seats do
|
||||
if self.seatTaken[seat] == nil then
|
||||
return seat
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- 아직 접시가 정해지지 않은 주문(먼저 온 손님부터). 걷는 중인 손님도 주문은 이미 정해져 있습니다.
|
||||
function Shop.openOrders(self: Shop): { Customer }
|
||||
local covered: { [string]: number } = {}
|
||||
for _, m in self.hand do
|
||||
covered[m] = (covered[m] or 0) + 1
|
||||
end
|
||||
for _, m in self.counter do
|
||||
covered[m] = (covered[m] or 0) + 1
|
||||
end
|
||||
local list = {}
|
||||
for _, c in self.customers do
|
||||
if c.state ~= "eating" then
|
||||
table.insert(list, c)
|
||||
end
|
||||
end
|
||||
table.sort(list, function(a, b)
|
||||
return a.id < b.id
|
||||
end)
|
||||
local open = {}
|
||||
for _, c in list do
|
||||
local n = covered[c.menu] or 0
|
||||
if n > 0 then
|
||||
covered[c.menu] = n - 1
|
||||
else
|
||||
table.insert(open, c)
|
||||
end
|
||||
end
|
||||
return open
|
||||
end
|
||||
|
||||
-- 지금 조리대에서 만들 메뉴(없으면 nil)
|
||||
function Shop.nextCookMenu(self: Shop): string?
|
||||
local open = Shop.openOrders(self)
|
||||
return if open[1] then open[1].menu else nil
|
||||
end
|
||||
|
||||
function Shop.handFull(self: Shop): boolean
|
||||
return #self.hand >= self.stats.carry
|
||||
end
|
||||
|
||||
-- 시간을 now까지 진행합니다. 일어난 일을 이벤트로 돌려줍니다.
|
||||
function Shop.tick(self: Shop, now: number): { Event }
|
||||
self.now = now
|
||||
local events: { Event } = {}
|
||||
|
||||
for id, c in self.customers do
|
||||
if c.state == "walking" and now >= c.untilT then
|
||||
c.state = "waiting"
|
||||
table.insert(events, { kind = "seated", id = id } :: Event)
|
||||
elseif c.state == "eating" and now >= c.untilT then
|
||||
self.customers[id] = nil
|
||||
self.seatTaken[c.seat] = nil
|
||||
table.insert(events, { kind = "leave", id = id, seat = c.seat } :: Event)
|
||||
end
|
||||
end
|
||||
|
||||
if now >= self.nextSpawn then
|
||||
local seat = freeSeat(self)
|
||||
if seat then
|
||||
self.lastId += 1
|
||||
local menus = self.stats.menus
|
||||
local menu = menus[(self.menuIndex % #menus) + 1]
|
||||
self.menuIndex += 1
|
||||
local c: Customer = {
|
||||
id = self.lastId,
|
||||
seat = seat,
|
||||
menu = menu,
|
||||
state = "walking",
|
||||
untilT = now + Economy.WALK_IN,
|
||||
}
|
||||
self.customers[c.id] = c
|
||||
self.seatTaken[seat] = c.id
|
||||
table.insert(events, { kind = "spawn", id = c.id, seat = seat, menu = menu } :: Event)
|
||||
end
|
||||
self.nextSpawn = now + self.stats.spawn
|
||||
end
|
||||
|
||||
if self.stats.helper and now >= self.nextHelper then
|
||||
local menu = Shop.nextCookMenu(self)
|
||||
if menu and #self.counter < Economy.COUNTER_MAX then
|
||||
table.insert(self.counter, menu)
|
||||
table.insert(events, { kind = "counter", menu = menu } :: Event)
|
||||
self.nextHelper = now + self.stats.cook
|
||||
end
|
||||
end
|
||||
|
||||
return events
|
||||
end
|
||||
|
||||
-- 플레이어가 조리대에서 다 만들었을 때. 만든 메뉴를 돌려줍니다.
|
||||
function Shop.cook(self: Shop): string?
|
||||
if Shop.handFull(self) then
|
||||
return nil
|
||||
end
|
||||
local menu = Shop.nextCookMenu(self)
|
||||
if menu then
|
||||
table.insert(self.hand, menu)
|
||||
end
|
||||
return menu
|
||||
end
|
||||
|
||||
-- 알바생이 만들어 둔 접시를 손에 듭니다. 든 접시 수를 돌려줍니다.
|
||||
function Shop.pickup(self: Shop): number
|
||||
local n = 0
|
||||
while #self.counter > 0 and not Shop.handFull(self) do
|
||||
table.insert(self.hand, table.remove(self.counter, 1) :: string)
|
||||
n += 1
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
-- 손에 든 접시를 손님에게 줍니다. 번 돈을 돌려줍니다(못 주면 nil).
|
||||
function Shop.serve(self: Shop, id: number): number?
|
||||
local c = self.customers[id]
|
||||
if not c or c.state ~= "waiting" then
|
||||
return nil
|
||||
end
|
||||
local idx = table.find(self.hand, c.menu)
|
||||
if not idx then
|
||||
return nil
|
||||
end
|
||||
table.remove(self.hand, idx)
|
||||
c.state = "eating"
|
||||
c.untilT = self.now + Economy.EAT
|
||||
local earn = Economy.dishPrice(c.menu, self.stats, self.moneyMult)
|
||||
self.money += earn
|
||||
self.earned += earn
|
||||
self.served += 1
|
||||
return earn
|
||||
end
|
||||
|
||||
function Shop.nextPurchase(self: Shop): Purchase?
|
||||
return Economy.PURCHASES[self.bought + 1]
|
||||
end
|
||||
|
||||
-- 다음 업그레이드를 삽니다. 성공하면 산 항목을 돌려줍니다.
|
||||
function Shop.buyNext(self: Shop): (Purchase?, string?)
|
||||
local p = Shop.nextPurchase(self)
|
||||
if not p then
|
||||
return nil, "max"
|
||||
end
|
||||
if self.money < p.cost then
|
||||
return nil, "money"
|
||||
end
|
||||
self.money -= p.cost
|
||||
self.bought += 1
|
||||
self.stats = Economy.statsAt(self.bought)
|
||||
if p.effect.spawn then
|
||||
self.nextSpawn = math.min(self.nextSpawn, self.now + p.effect.spawn)
|
||||
end
|
||||
return p, nil
|
||||
end
|
||||
|
||||
function Shop.addMoney(self: Shop, amount: number)
|
||||
self.money += amount
|
||||
end
|
||||
|
||||
return Shop
|
||||
8
bunsik-tycoon/src/shared/Sounds.luau
Normal file
8
bunsik-tycoon/src/shared/Sounds.luau
Normal file
@@ -0,0 +1,8 @@
|
||||
--!strict
|
||||
-- 효과음 ID. ProSoundEffects는 로블록스가 라이선스한 공개 효과음이라 누구나 쓸 수 있습니다.
|
||||
|
||||
return {
|
||||
SIZZLE = "rbxassetid://9114542867", -- Fry Or Sizzle 1 (SFX), ProSoundEffects
|
||||
COIN = "rbxasset://sounds/electronicpingshort.wav", -- 로블록스 기본 내장음
|
||||
BUY = "rbxasset://sounds/electronicpingshort.wav",
|
||||
}
|
||||
Reference in New Issue
Block a user