{ "Id": "", "GameId": "", "EntryKey": "codeblock://SlayDeckController", "ContentType": "x-mod/codeblock", "Content": "", "Usage": 0, "UsePublish": 1, "UseService": 0, "CoreVersion": "26.5.0.0", "StudioVersion": "", "DynamicLoading": 0, "ContentProto": { "Use": "Json", "Json": { "CoreVersion": { "Major": 0, "Minor": 2 }, "ScriptVersion": { "Major": 1, "Minor": 0 }, "Description": "", "Id": "SlayDeckController", "Language": 1, "Name": "SlayDeckController", "Type": 1, "Source": 0, "Target": null, "Properties": [ { "Type": "any", "DefaultValue": "nil", "SyncDirection": 0, "Attributes": [], "Name": "DrawPile" }, { "Type": "any", "DefaultValue": "nil", "SyncDirection": 0, "Attributes": [], "Name": "DiscardPile" }, { "Type": "any", "DefaultValue": "nil", "SyncDirection": 0, "Attributes": [], "Name": "Hand" }, { "Type": "number", "DefaultValue": "0", "SyncDirection": 0, "Attributes": [], "Name": "Energy" }, { "Type": "number", "DefaultValue": "3", "SyncDirection": 0, "Attributes": [], "Name": "MaxEnergy" }, { "Type": "number", "DefaultValue": "0", "SyncDirection": 0, "Attributes": [], "Name": "Turn" }, { "Type": "number", "DefaultValue": "0", "SyncDirection": 0, "Attributes": [], "Name": "TweenEventId" }, { "Type": "any", "DefaultValue": "nil", "SyncDirection": 0, "Attributes": [], "Name": "EndTurnHandler" }, { "Type": "any", "DefaultValue": "nil", "SyncDirection": 0, "Attributes": [], "Name": "Cards" } ], "Methods": [ { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "self:StartCombat()", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "OnBeginPlay" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "self.MaxEnergy = 3\nself.Turn = 0\nself.DiscardPile = {}\nself.Hand = {}\nself.Cards = {\n\tStrike = { name = \"타격\", cost = 1, desc = \"피해 6\", kind = \"Attack\" },\n\tDefend = { name = \"방어\", cost = 1, desc = \"방어도 5\", kind = \"Skill\" },\n\tBash = { name = \"강타\", cost = 2, desc = \"피해 10\", kind = \"Attack\" },\n}\nself.DrawPile = { \"Strike\", \"Strike\", \"Strike\", \"Strike\", \"Strike\", \"Defend\", \"Defend\", \"Defend\", \"Defend\", \"Bash\" }\nself:Shuffle(self.DrawPile)\nself:BindButtons()\nself:StartPlayerTurn()", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "StartCombat" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "any", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "list" } ], "Code": "if list == nil then\n\treturn\nend\nfor i = #list, 2, -1 do\n\tlocal j = math.random(1, i)\n\tlist[i], list[j] = list[j], list[i]\nend", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "Shuffle" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "local endTurn = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/DeckHud/EndTurnButton\")\nif endTurn ~= nil and endTurn.ButtonComponent ~= nil then\n\tif self.EndTurnHandler ~= nil then\n\t\tendTurn:DisconnectEvent(ButtonClickEvent, self.EndTurnHandler)\n\t\tself.EndTurnHandler = nil\n\tend\n\tself.EndTurnHandler = endTurn:ConnectEvent(ButtonClickEvent, function() self:EndPlayerTurn() end)\nend\nfor i = 1, 5 do\n\tlocal cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(i))\n\tif cardEntity ~= nil and cardEntity.ButtonComponent ~= nil then\n\t\tcardEntity:ConnectEvent(ButtonClickEvent, function() self:PlayCard(i) end)\n\tend\nend", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "BindButtons" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "self.Turn = self.Turn + 1\nself.Energy = self.MaxEnergy\nself:DrawCards(5)\nself:RenderHand(true)", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "StartPlayerTurn" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "for i = 1, #self.Hand do\n\ttable.insert(self.DiscardPile, self.Hand[i])\nend\nself.Hand = {}\nself:RenderHand(false)\nself:RenderPiles()\n_TimerService:SetTimerOnce(function() self:StartPlayerTurn() end, 0.45)", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "EndPlayerTurn" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "number", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "amount" } ], "Code": "for i = 1, amount do\n\tif #self.DrawPile <= 0 then\n\t\tself:RecycleDiscardIntoDraw()\n\tend\n\tif #self.DrawPile <= 0 then\n\t\tbreak\n\tend\n\tlocal cardId = table.remove(self.DrawPile)\n\ttable.insert(self.Hand, cardId)\nend\nself:RenderPiles()", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "DrawCards" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "if self.DiscardPile == nil or #self.DiscardPile <= 0 then\n\treturn\nend\nself.DrawPile = {}\nfor i = 1, #self.DiscardPile do\n\tself.DrawPile[i] = self.DiscardPile[i]\nend\nself.DiscardPile = {}\nself:Shuffle(self.DrawPile)", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "RecycleDiscardIntoDraw" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [], "Code": "self:SetText(\"/ui/DefaultGroup/DeckHud/DrawPile/Count\", tostring(#self.DrawPile))\nself:SetText(\"/ui/DefaultGroup/DeckHud/DiscardPile/Count\", tostring(#self.DiscardPile))\nself:SetText(\"/ui/DefaultGroup/DeckHud/Energy\", \"에너지 \" .. tostring(self.Energy) .. \"/\" .. tostring(self.MaxEnergy))", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "RenderPiles" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "boolean", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "animate" } ], "Code": "local drawStart = Vector2(-590, 8)\nfor i = 1, 5 do\n\tlocal cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(i))\n\tif cardEntity ~= nil then\n\t\tlocal cardId = self.Hand[i]\n\t\tif cardId == nil then\n\t\t\tcardEntity.Enable = false\n\t\telse\n\t\t\tcardEntity.Enable = true\n\t\t\tself:ApplyCardVisual(i, cardId)\n\t\t\tif animate == true then\n\t\t\t\tself:AnimateCardFrom(i, drawStart, Vector2((i - 3) * 200, 0), 0.16 + i * 0.045)\n\t\t\tend\n\t\tend\n\tend\nend\nself:RenderPiles()", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "RenderHand" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "number", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "slot" }, { "Type": "string", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "cardId" } ], "Code": "local c = self.Cards[cardId]\nif c == nil then\n\tc = { name = cardId, cost = 0, desc = \"\", kind = \"Skill\" }\nend\nself:SetText(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot) .. \"/Cost\", tostring(c.cost))\nself:SetText(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot) .. \"/Name\", c.name)\nself:SetText(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot) .. \"/Desc\", c.desc)\nlocal cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot))\nif cardEntity ~= nil and cardEntity.SpriteGUIRendererComponent ~= nil then\n\tif c.kind == \"Attack\" then\n\t\tcardEntity.SpriteGUIRendererComponent.Color = Color(0.86, 0.42, 0.38, 1)\n\telseif c.kind == \"Skill\" then\n\t\tcardEntity.SpriteGUIRendererComponent.Color = Color(0.42, 0.55, 0.85, 1)\n\telse\n\t\tcardEntity.SpriteGUIRendererComponent.Color = Color(0.46, 0.68, 0.52, 1)\n\tend\nend", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "ApplyCardVisual" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "string", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "path" }, { "Type": "string", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "value" } ], "Code": "local entity = _EntityService:GetEntityByPath(path)\nif entity ~= nil and entity.TextComponent ~= nil then\n\tentity.TextComponent.Text = value\nend", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "SetText" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "number", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "slot" }, { "Type": "any", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "fromPos" }, { "Type": "any", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "toPos" }, { "Type": "number", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "duration" } ], "Code": "local cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot))\nif cardEntity == nil or cardEntity.UITransformComponent == nil then\n\treturn\nend\nlocal tr = cardEntity.UITransformComponent\ntr.anchoredPosition = fromPos\nlocal elapsed = 0\nlocal eventId = 0\neventId = _TimerService:SetTimerRepeat(function()\n\telapsed = elapsed + 1 / 60\n\tlocal t = math.min(elapsed / duration, 1)\n\tlocal eased = _TweenLogic:Ease(0, 1, 1, EaseType.SineEaseOut, t)\n\ttr.anchoredPosition = Vector2(fromPos.x + (toPos.x - fromPos.x) * eased, fromPos.y + (toPos.y - fromPos.y) * eased)\n\tif t >= 1 then\n\t\t_TimerService:ClearTimer(eventId)\n\tend\nend, 1 / 60)", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "AnimateCardFrom" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "number", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "slot" } ], "Code": "if self.Hand == nil then\n\treturn\nend\nlocal cardId = self.Hand[slot]\nif cardId == nil then\n\treturn\nend\nlocal c = self.Cards[cardId]\nif c == nil then\n\treturn\nend\nif self.Energy < c.cost then\n\tself:Toast(\"에너지가 부족합니다\")\n\treturn\nend\nself.Energy = self.Energy - c.cost\nself:Toast(c.name .. \" — \" .. c.desc)\ntable.remove(self.Hand, slot)\ntable.insert(self.DiscardPile, cardId)\nself:RenderHand(false)\nself:RenderPiles()", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "PlayCard" }, { "Return": { "Type": "void", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": null }, "Arguments": [ { "Type": "string", "DefaultValue": null, "SyncDirection": 0, "Attributes": [], "Name": "message" } ], "Code": "log(message)", "Scope": 2, "ExecSpace": 6, "Attributes": [], "Name": "Toast" } ], "EntityEventHandlers": [] } } }