Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1.  
  2. local powerupsTable = {
  3. {"-1 from anyone's hand","+1 to anyone's hand","-3 from anyone's hand","+3 to anyone's hand","Help another player exit from the round","Exit from the round"},
  4. {"Swap hands with another player","Copy another player's hand","Discard your hand and stand on 19","Force the dealer to stand on two cards","Force the dealer to draw an additional card","Force the dealer to reveal their facedown card"},
  5. {"Swap hands with the dealer","Force the dealer to bust","+10 to your own hand","Sacrifice","Nothing","Give another player Blackjack"},
  6. {"Martyr","Bust another player","Spite","Backstab another player","Force a player to redraw their hand","Redraw all cards"},
  7. {"Turn a random card into Ace","Remove a random card from a player's hand","Steal a random card from another player","Force a player to draw an additional card","Shuffle hands with another player","Shuffle all player's cards"},
  8. {"Activate Bonus Round Timer","New bonus round","Copy a random player's hand","Swap hands with a random player","Save all other players","Discard the last drawn card"},
  9. {"Refresh","Random Subtract","View the next card","Minigame","Chaos","Mugging"},
  10. {"Give a card","Bump","Swap All","Swap Powerups","Flood","Explode"},
  11. {"Cracked Skull's Curse","Dragon's Heart","Deck's Blessing","Joker Powerup","Reward token","Random rupee pull"},
  12. {"Meme Token","Royal token","Collectable Token","Daily Token","Slot Machine Token","Andrew Token",}
  13. }
  14. local numPowerups = {}
  15. for i=1,#powerupsTable do
  16. for n=1,#powerupsTable[i] do
  17. numPowerups[powerupsTable[i][n]] = 0
  18. _G["doDeploy_"..tostring(powerupsTable[i][n])] = function(_,c)
  19. deployQueue(tostring(powerupsTable[i][n]), c)
  20. end
  21. end
  22. end
  23.  
  24. PendingDesc = nil
  25. buttons = {}
  26.  
  27. -- Initialization
  28. function onLoad(state)
  29. nextUpdate = os.time() + 2
  30.  
  31. buttons = {}
  32.  
  33. if state and state~="" then
  34. local decode = JSON.decode(state)
  35.  
  36. for k in pairs(numPowerups) do
  37. if decode[k] then
  38. numPowerups[k] = decode[k]
  39. end
  40. end
  41. end
  42. end
  43. function onSave()
  44. return JSON.encode(numPowerups)
  45. end
  46. function forceSave()
  47. self.script_state = JSON.encode(numPowerups)
  48. end
  49. function onDestroy()
  50. Timer.destroy("PowerupBoardRefresh_"..tostring(self.guid))
  51. end
  52.  
  53. local function ProcessQueue()
  54. if os.time()<nextUpdate then return end
  55.  
  56. if PendingDesc then
  57. self.setDescription( PendingDesc )
  58. PendingDesc = nil
  59. end
  60.  
  61. while #deployQueueData>0 do
  62. nextUpdate = nextUpdate+0.1
  63. if deployPowerup(deployQueueData[1]) then
  64. table.remove(deployQueueData, 1)
  65. break
  66. else
  67. table.remove(deployQueueData, 1)
  68. end
  69. end
  70. end
  71. function onUpdate()
  72. if os.time()<nextUpdate then return end
  73.  
  74. buttons = {}
  75. makeButtons()
  76.  
  77. Timer.create({ identifier = "PowerupBoardRefresh_"..tostring(self.guid), function_name = "countPowerups", delay = 2, repetitions = 0 })
  78.  
  79. deployQueueData = {}
  80. onUpdate = ProcessQueue
  81. end
  82.  
  83. function onObjectEnterContainer(bag,o)
  84. if bag==self then
  85. countPowerups()
  86. return
  87. end
  88. if o~=self then return end
  89.  
  90. Timer.destroy("PowerupBoardRefresh_"..tostring(self.guid))
  91. end
  92.  
  93. function GetZoneID( searchID )
  94. local ownerID = string.match(self.getDescription(), "^(%d+) %- .*")
  95. local otherID = string.match(searchID, "^(%d+) %- .*")
  96.  
  97. if not otherID then return false end
  98.  
  99. local seated = getSeatedPlayers()
  100. for i=1,#seated do
  101. seated[ seated[i] ] = true
  102. seated[i] = nil
  103. end
  104.  
  105. local objectSets = Global.getTable("objectSets")
  106. if not objectSets then return false end
  107.  
  108. local foundID = false
  109. for i=1,#objectSets do
  110. local set = objectSets[i]
  111. if set and seated[set.color] then
  112. for _,v in pairs({"zone","tbl","prestige"}) do
  113. for _,obj in pairs(set[v].getObjects()) do
  114. if obj==self then
  115. if Player[set.color].steam_id==ownerID then -- If there's an overlap, we prioritise our own zone
  116. return false
  117. end
  118.  
  119. if Player[set.color].steam_id==otherID then
  120. foundID = true
  121. break
  122. end
  123. end
  124. end
  125. end
  126. end
  127. end
  128.  
  129. return foundID
  130. end
  131.  
  132. -- Buttons
  133. function countPowerups()
  134. local objects = self.getObjects()
  135.  
  136. for i=1,#objects do
  137. local drawn = self.takeObject({position=pos})
  138. local name = drawn.getName()
  139. if numPowerups[name] then
  140. local meshData = drawn.getCustomObject()
  141.  
  142. local stackSize = (drawn.getQuantity()==(-1) and 1) or drawn.getQuantity()
  143.  
  144. numPowerups[name] = numPowerups[name] + stackSize
  145.  
  146. drawn.destruct()
  147. else
  148. if drawn.getName()==self.getName() then
  149. local pwups = JSON.decode(drawn.script_state or "") -- It's too early for obj.getTable(), script hasn't loaded
  150. if pwups then
  151. for k,v in pairs(pwups) do
  152. if numPowerups[k] then
  153. numPowerups[k] = numPowerups[k] + math.max( v or 0, 0 )
  154. end
  155. end
  156. end
  157.  
  158. local drawnDesc = drawn.getDescription()
  159. if drawnDesc~=self.getDescription() then
  160. if (self.held_by_color and self.held_by_color~="Black") or GetZoneID(drawnDesc) then
  161. self.setDescription(drawnDesc)
  162. self.translate({0,0.1,0})
  163. end
  164. end
  165.  
  166. destroyObject(drawn)
  167. else
  168. drawn.setPosition(getDeployPosition(drawn))
  169. drawn.setLock(false)
  170. drawn.interactable = true
  171.  
  172. Wait.frames(function()
  173. if drawn and not (drawn==nil) then
  174. drawn.setPosition(getDeployPosition(drawn))
  175. end
  176. end, 0)
  177. end
  178. end
  179. end
  180.  
  181. updateButtons()
  182. forceSave()
  183. end
  184. function makeButtons()
  185. self.clearButtons()
  186.  
  187. buttons = {}
  188. local buttonIndex = 0
  189. for row = 1,#powerupsTable do
  190. local numColumns = #powerupsTable[row]
  191. local startPos = (numColumns - 1) * (-0.5)
  192. local rowPos = (row*1.115)-5.61
  193.  
  194. buttons[row] = {}
  195.  
  196. for column = 1,#powerupsTable[row] do
  197. local name = powerupsTable[row][column]
  198. local obj = getPowerupObject(name)
  199.  
  200. local tooltip = obj and ("%s\n\n%s"):format(tostring(name), tostring(obj.getDescription()):gsub("[Cc]ollectable\n[Ss]et: Powerups\n\n","") ) or tostring(name)
  201. tooltip = tooltip:gsub("%s*$", ""):gsub("^%s*", "") or tooltip
  202.  
  203. local count = numPowerups[name] or 0
  204. self.createButton({
  205. label="", click_function="doDeploy_"..tostring(name), function_owner=self,
  206. position={startPos+(column-1),0.1,rowPos}, rotation={0,0,0}, width=450, height=500, font_size=150,
  207. color = count ==0 and {r=1,g=0,b=0, a=0.5} or {r=0,g=1,b=0, a=0.5}, tooltip=tooltip,
  208. })
  209.  
  210. -- Drop-shadow counter text. There's no way to draw text directly, this will hit performance.
  211. local str = "[b]"..tostring(count).."[-]"
  212. local btnPos = {x=startPos+(column-1)+0.3, y=0.1, z=rowPos+0.4}
  213. self.createButton({
  214. label=str, click_function="null", function_owner=self,
  215. position={btnPos.x+0.02,0.1,btnPos.z+0.02}, rotation={0,0,0}, width=0, height=0, font_size=150,
  216. font_color = {r=0,g=0,b=0},
  217. })
  218. self.createButton({
  219. label=str, click_function="null", function_owner=self,
  220. position=btnPos, rotation={0,0,0}, width=0, height=0, font_size=150,
  221. font_color = {r=1,g=1,b=1},
  222. })
  223.  
  224. buttons[row][column] = {btn=buttonIndex, txt=buttonIndex+2, shadow=buttonIndex+1, count=count, btnPos=btnPos}
  225. buttonIndex = buttonIndex + 3
  226. end
  227. end
  228. end
  229. function updateButtons()
  230. for row = 1,#buttons do
  231. for column = 1,#buttons[row] do
  232. local newCount = numPowerups[powerupsTable[row][column]] or 0
  233. local btnData = buttons[row][column]
  234. if newCount~=btnData.count then
  235. local str = "[b]"..tostring(newCount).."[-]"
  236. self.editButton({index=btnData.btn, color = (newCount==0 and {r=1,g=0,b=0, a=0.5} or {r=0,g=1,b=0, a=0.5})})
  237.  
  238. self.editButton({index=btnData.shadow, label = str})
  239. self.editButton({index=btnData.txt, label = str})
  240.  
  241. btnData.count = newCount
  242. end
  243. end
  244. end
  245.  
  246. end
  247.  
  248. -- Deploy Powerup
  249. function null() end
  250. function deployPowerup(name)
  251. if (not numPowerups[name]) then return end
  252.  
  253. if (numPowerups[name] or 0)>=1 then
  254. numPowerups[name] = numPowerups[name]-1
  255. local data = numPowerups[name]
  256. local pos = getDeployPosition()
  257.  
  258. local chosenObject = getPowerupObject(name)
  259. if not chosenObject then return false end
  260.  
  261. local params = {}
  262. params.position = getDeployPosition()
  263. local clone = chosenObject.clone(params)
  264. clone.interactable = true
  265. clone.unlock()
  266. clone.setPosition(params.position)
  267. clone.setRotation(self.getRotation())
  268.  
  269. countPowerups()
  270.  
  271. return true
  272. else -- Check contents
  273. local objects = self.getObjects()
  274.  
  275. for _,obj in pairs(objects) do
  276. if obj.name==name then
  277. local pos = getDeployPosition()
  278.  
  279. self.takeObject({position = pos, guid = obj.guid})
  280. countPowerups()
  281.  
  282. return true
  283. end
  284. end
  285. end
  286.  
  287. return false
  288. end
  289.  
  290. local storedPowerupObjects = {}
  291. function getPowerupObject( name )
  292. if storedPowerupObjects[name] and not (storedPowerupObjects[name]==nil) then
  293. return storedPowerupObjects[name]
  294. end
  295.  
  296. local chosenObject
  297.  
  298. local powerupTable = Global.getTable("powerupTable")
  299. if (powerupTable) and #powerupTable>0 then
  300. for i=1,#powerupTable do
  301. local chosenPowerup = powerupTable[i]
  302. local obj = getObjectFromGUID(chosenPowerup[1])
  303.  
  304. if obj and obj.getName()==name then
  305. chosenObject = obj
  306. end
  307. end
  308. end
  309. if not chosenObject then
  310. for _,obj in pairs(getAllObjects()) do
  311. if obj.getLock() and obj.getName()==name then
  312. chosenObject = obj
  313.  
  314. break
  315. end
  316. end
  317. end
  318. if not chosenObject then return end
  319.  
  320. storedPowerupObjects[name] = chosenObject
  321.  
  322. return chosenObject
  323. end
  324.  
  325. function deployQueue(name, col)
  326. if not name then return end
  327. if col and not Player[col].admin then
  328. local id = string.match(self.getDescription(), "^(%d+) %- .*")
  329.  
  330. if id and Player[col].steam_id~=id then
  331. Player[col].print("This isn't yours!", {r=1,g=0,b=0})
  332. return
  333. end
  334. end
  335.  
  336. if (not numPowerups[name]) then return end
  337.  
  338. table.insert(deployQueueData, name)
  339. end
  340.  
  341. function getDeployPosition(obj)
  342. if obj then
  343. local objBounds = obj.getBoundsNormalized()
  344. local objScale = obj.getScale()
  345. local zMod = math.max(objBounds.size.z, 1) * objScale.z
  346.  
  347. local scale = self.getScale()
  348. return self.positionToWorld({ 0, 1.5+scale.y, ((-1)/scale.z)-5 -(1.5*zMod) })
  349. else
  350. local scale = self.getScale()
  351. return self.positionToWorld({ 0, 1.5+scale.y, ((-1)/scale.z)-5 })
  352. end
  353. end
  354.  
  355. function onPickUp( col )
  356. if col~="Black" and self.getDescription()=="" and not PendingDesc then
  357. PendingDesc = Player[col].steam_id .." - ".. Player[col].steam_name
  358. end
  359.  
  360. local plyID = Player[col].steam_id
  361. local boardID = self.getDescription():match("^(%d+) %- .*")
  362.  
  363. if boardID and boardID~=plyID then return end -- Only manage our own boards
  364.  
  365. local holding = Player[col].getHoldingObjects()
  366. for i=1,#holding do
  367. if holding[i]~=self and holding[i].getLuaScript()==self.getLuaScript() then
  368. destroyObject(self)
  369. return
  370. end
  371. end
  372. end
  373.  
  374.  
  375. function onBlackjackDestroyItems(data)
  376. if data.destroyPowerups then
  377. local pwupTable = Global.getTable("powerupEffectTable")
  378. for name,v in pairs(numPowerups) do
  379. if pwupTable[name] then -- It's a powerup
  380. numPowerups[name] = 0
  381. end
  382. end
  383. forceSave()
  384. end
  385. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement