import { method, RUN_LENGTH, GOLD_PER_WIN, CARD_PRICE, REST_HEAL, RELIC_PRICE, ACT_COUNT, ACT_MAPS, LOBBY_MAP, LOBBY_SPAWN } from '../lib/codeblock.mjs'; import { CARDS, ENEMIES, CLASSES, JOBS, SOUL_UNLOCKS, CARDFRAMES, RARITIES, MAP_ROWS, MAP_COLS, CHEST_CLOSED_RUID, CHEST_OPEN_RUID, NODEICONS, CHARS, CAM, RELICS, POTIONS, luaSoulShopTable, frameRuid, luaFramesTable, luaNodeIconsTable, luaRelicsTable, luaPotionsTable, luaIntentsArray, luaEnemiesTable, luaStr, luaJobsTable, luaCardsTable, luaDeckTable } from '../lib/data.mjs'; import { UI_FILE, COMMON_FILE, UI_ROOT, GENERATED_UI_SECTIONS, UI_APPEND_ORDER, DISABLED_STOCK_CONTROLS, TRANSPARENT, DARK, GOLD, ATTACK, DEFEND, SKILL, DAMAGE_DIGIT_RUIDS, DAMAGE_POP_MAX_DIGITS, DAMAGE_POP_DIGIT_W, DAMAGE_POP_DIGIT_H, DAMAGE_POP_DIGIT_SPACING, MAX_MONSTERS, HEAD_OFFSET_Y, HP_BAR_W, WHITE, CARD_NAME_TEXT, CARD_DESC_TEXT, cardFaceLayout, CARD_W, CARD_H, CARD_SPACING, CARD_XS, ALIGN_CENTER, ALIGN_BOTTOM_CENTER, guid, transform, sprite, button, text, scrollLayoutGroup, popupLayerFor, uiOrderFor, displayOrderFor, applySortingOverride, entity, uiPath, sectionRoot, isGeneratedUiEntity, appendUiSection } from '../lib/ui-helpers.mjs'; export const shopMethods = [ method('ShowShop', `local pool = self:CardPool() self.ShopChoices = {} self.ShopBought = { false, false, false } for i = 1, 3 do self.ShopChoices[i] = pool[math.random(1, #pool)] end self.ShopRelic = self.RelicPool[math.random(1, #self.RelicPool)] self.ShopRelicBought = false local pkeys = {} for pid, _ in pairs(self.Potions) do table.insert(pkeys, pid) end table.sort(pkeys) self.ShopPotion = pkeys[math.random(1, #pkeys)] self.ShopPotionBought = false self:RenderShop() self:ShowState("shop")`), method('RenderShop', `self:SetText("/ui/RunUIGroup/ShopHud/Gold", "메소 " .. string.format("%d", self.Gold)) for i = 1, 3 do local cid = self.ShopChoices[i] local c = self.Cards[cid] local base = "/ui/RunUIGroup/ShopHud/Card" .. tostring(i) if c ~= nil then self:ApplyCardFace(base, cid) self:SetText(base .. "/Price", string.format("%d", ${CARD_PRICE}) .. " 메소") local e = _EntityService:GetEntityByPath(base) if e ~= nil and e.SpriteGUIRendererComponent ~= nil then if self.ShopBought[i] == true then e.SpriteGUIRendererComponent.Color = Color(0.2, 0.22, 0.26, 0.6) end end end end local rr = self.Relics[self.ShopRelic] if rr ~= nil then self:SetText("/ui/RunUIGroup/ShopHud/Relic/Label", rr.name .. " — " .. rr.desc) self:SetText("/ui/RunUIGroup/ShopHud/Relic/Price", string.format("%d", ${RELIC_PRICE}) .. " 메소") local re = _EntityService:GetEntityByPath("/ui/RunUIGroup/ShopHud/Relic") if re ~= nil and re.SpriteGUIRendererComponent ~= nil then if self.ShopRelicBought == true then re.SpriteGUIRendererComponent.Color = Color(0.2, 0.22, 0.26, 0.6) else re.SpriteGUIRendererComponent.Color = Color(0.7, 0.55, 0.85, 1) end end end local pp = self.Potions[self.ShopPotion] if pp ~= nil then self:SetText("/ui/RunUIGroup/ShopHud/Potion/Label", pp.name .. " — " .. pp.desc) self:SetText("/ui/RunUIGroup/ShopHud/Potion/Price", string.format("%d", ${POTIONS.shopPrice}) .. " 메소") local pe = _EntityService:GetEntityByPath("/ui/RunUIGroup/ShopHud/Potion") if pe ~= nil and pe.SpriteGUIRendererComponent ~= nil then if self.ShopPotionBought == true then pe.SpriteGUIRendererComponent.Color = Color(0.2, 0.22, 0.26, 0.6) else pe.SpriteGUIRendererComponent.Color = Color(0.45, 0.7, 0.55, 1) end end end`), method('BuyRelic', `if self.ShopRelicBought == true then return end if self.Gold < ${RELIC_PRICE} then return end self.Gold = self.Gold - ${RELIC_PRICE} self:AddRelic(self.ShopRelic) self.ShopRelicBought = true self:RenderShop() self:RenderRun()`), method('BuyPotion', `if self.ShopPotionBought == true then return end if self.Gold < ${POTIONS.shopPrice} then return end if self.RunPotions ~= nil and #self.RunPotions >= self.PotionSlots then self:Toast("물약 슬롯이 가득 찼습니다") return end if self:AddPotion(self.ShopPotion) == true then self.Gold = self.Gold - ${POTIONS.shopPrice} self.ShopPotionBought = true end self:RenderShop() self:RenderRun()`), method('BuyCard', `if self.ShopBought == nil or self.ShopBought[slot] == true then return end if self.Gold < ${CARD_PRICE} then return end self.Gold = self.Gold - ${CARD_PRICE} table.insert(self.RunDeck, self.ShopChoices[slot]) self.ShopBought[slot] = true self:RenderShop() self:RenderRun()`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]), method('ShowRest', `local old = self.PlayerHp self.PlayerHp = self.PlayerHp + ${REST_HEAL} if self.PlayerHp > self.PlayerMaxHp then self.PlayerHp = self.PlayerMaxHp end local healed = self.PlayerHp - old self:SetText("/ui/RunUIGroup/RestHud/Info", "HP " .. string.format("%d", old) .. " → " .. string.format("%d", self.PlayerHp) .. " (+" .. string.format("%d", healed) .. ")") self:RenderCombat() self:ShowState("rest")`), method('LeaveNode', `local s = _EntityService:GetEntityByPath("/ui/RunUIGroup/ShopHud") if s ~= nil then s.Enable = false end local r = _EntityService:GetEntityByPath("/ui/RunUIGroup/RestHud") if r ~= nil then r.Enable = false end local t = _EntityService:GetEntityByPath("/ui/RunUIGroup/TreasureHud") if t ~= nil then t.Enable = false end self:ShowMap()`), method('ShowTreasure', `self.ChestOpened = false local chest = _EntityService:GetEntityByPath("/ui/RunUIGroup/TreasureHud/Chest") if chest ~= nil then if chest.SpriteGUIRendererComponent ~= nil then chest.SpriteGUIRendererComponent.ImageRUID = "${CHEST_CLOSED_RUID}" end if chest.UITransformComponent ~= nil then chest.UITransformComponent.anchoredPosition = Vector2(0, 40) end end self:SetEntityEnabled("/ui/RunUIGroup/TreasureHud/Reward", false) self:SetEntityEnabled("/ui/RunUIGroup/TreasureHud/Hint", true) self:ShowState("treasure")`), method('OpenChest', `if self.ChestOpened == true then return end self.ChestOpened = true self:SetEntityEnabled("/ui/RunUIGroup/TreasureHud/Hint", false) local chest = _EntityService:GetEntityByPath("/ui/RunUIGroup/TreasureHud/Chest") local steps = { 10, -10, 8, -8, 5, 0 } for i = 1, #steps do local dx = steps[i] _TimerService:SetTimerOnce(function() if chest ~= nil and isvalid(chest) and chest.UITransformComponent ~= nil then chest.UITransformComponent.anchoredPosition = Vector2(dx, 40) end end, 0.08 * i) end _TimerService:SetTimerOnce(function() if chest ~= nil and isvalid(chest) and chest.SpriteGUIRendererComponent ~= nil then chest.SpriteGUIRendererComponent.ImageRUID = "${CHEST_OPEN_RUID}" end local g = 40 + math.random(0, 20) local nid = self:PickNewRelic() local msg = "" if nid ~= "" then self:AddRelic(nid) local nr = self.Relics[nid] msg = "유물 획득: " .. nr.name .. " · 메소 +" .. tostring(g) else g = g + 30 msg = "메소 +" .. tostring(g) end self.Gold = self.Gold + g self:RenderRun() self:SetText("/ui/RunUIGroup/TreasureHud/Reward", msg) self:SetEntityEnabled("/ui/RunUIGroup/TreasureHud/Reward", true) end, 0.55)`), ];