Advertisement
ddson888

Untitled

Nov 8th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 KB | None | 0 0
  1. Cards = {}
  2. Cards["Zero Initiative Token"]={x="0",y="5",z="0", GUID=nil,player="Black",init=0,hexcolor="b1d629"}
  3. Cards["Leadership"]={x="-9",y="2.2",z="-16",GUID=nil,player="Black",init=1,hexcolor="b81d02"}
  4. Cards["Diplomacy"]={x="-9",y="2.2",z="-12", GUID=nil,player="Black",init=2,hexcolor="db7807"}
  5. Cards["Politics"]={x="-9",y="2.2",z="-8", GUID=nil,player="Black",init=3,hexcolor="faf200"}
  6. Cards["Construction"]={x="-9",y="2.2",z="-4", GUID=nil,player="Black",init=4,hexcolor="00bf30"}
  7. Cards["Trade"]={x="-9",y="2.2",z="0", GUID=nil,player="Black",init=5,hexcolor="12c9c9"}
  8. Cards["Warfare"]={x="-9",y="2.2",z="4", GUID=nil,player="Black",init=6,hexcolor="0041cf"}
  9. Cards["Technology"]={x="-9",y="2.2",z="8", GUID=nil,player="Black",init=7,hexcolor="060080"}
  10. Cards["Imperial"]={x="-9",y="2.2",z="12", GUID=nil,player="Black",init=8,hexcolor="3f0066"}
  11.  
  12. function onLoad()
  13. --Wait.time(function() Turns.enable = true end, 1)
  14. self.createButton(button_parameters)
  15. button_parameters.click_function = 'RecalculateInitiative'
  16. button_parameters.position = {0,0.11,2.15}
  17. button_parameters.label = 'Update'
  18. self.createButton(button_parameters)
  19.  
  20. local allObjects = getAllObjects()
  21. for i,v in pairs(allObjects) do
  22. for i2,v2 in pairs(Cards) do
  23. --print("comparing "..i2.." with "..v.getName())
  24. if tostring(i2) == tostring(v.getName()) then
  25. Cards[i2].GUID = v.getGUID()
  26. end
  27. end
  28. end
  29. PassedPlayers = {}
  30. end
  31.  
  32. function Nada()
  33. end
  34.  
  35. function HexColor(colorString)
  36. local colorTable = stringColorToRGB(colorString)
  37. colorTable = {colorTable[1]*255,colorTable[2]*255,colorTable[3]*255}
  38. local colorHex = string.format('%02x%02x%02x', unpack(colorTable))
  39. return colorHex
  40. end
  41.  
  42. function RecalculateInitiative()
  43. Turns.enable = false
  44. ClearTable(PassedPlayers)
  45. local Printed = {}
  46. RecalculatedOrder = {}
  47. for i,v in pairs(Cards) do
  48. if Cards[i].player ~= "Black"
  49. and TableContains(RecalculatedOrder, Cards[i].player) == false
  50. then
  51. table.insert(RecalculatedOrder, Cards[i].player)
  52. end
  53. end
  54. printToAll("[bd0055]------ [bd0055]ORDER [bd0055]-------")
  55. for i,v in pairs(Cards) do
  56. if Cards[i].player ~= "Black"
  57. and TableContains(Printed, Cards[i].player) == false
  58. and IsPlayerSeated(Cards[i].player) == true
  59. then
  60. if Player[Cards[i].player].steam_name ~= nil then
  61. PrintingPlayer = Player[Cards[i].player].steam_name
  62. else
  63. PrintingPlayer = Cards[i].player
  64. end
  65. printToAll("["..HexColor(Cards[i].player).."]"..PrintingPlayer.."[ffffff] goes at initiative "..PlayerInitiative(Cards[i].player).." with ".."["..Cards[i].hexcolor.."]"..i..".")
  66. table.insert(Printed, Cards[i].player)
  67. end
  68.  
  69. end
  70. printToAll("[bd0055]---------------------")
  71.  
  72. for i,v in pairs(getSeatedPlayers()) do
  73. --print(v.."[c2f536] test is "..v.."in RecalculatedOrder... "..tostring(IsPlayerInOrder(v)))
  74. if TableContains(RecalculatedOrder, v) == false then
  75. table.insert(RecalculatedOrder, v)
  76. print(v.."[c2f536] didn't have a strategy card so inserted at cleanup. This shouldn't happen.")
  77. end
  78. end
  79.  
  80. --Turns.enable = true
  81. Turns.type = 2
  82. Turns.skip_empty_hands = false
  83. Turns.order = RecalculatedOrder
  84. Wait.time(function() print("Setting turn to "..RecalculatedOrder[1]) end, 0.2)
  85. Wait.time(function() Turns.turn_color = RecalculatedOrder[1] end, 0.2)
  86. Wait.time(function() Turns.enable = true end, 0.3)
  87. for i,v in pairs(Cards) do
  88. if i ~= "Zero Initiative Token" then
  89. --getObjectFromGUID(Cards[i].GUID).highlightOff()
  90. end
  91. end
  92. end
  93.  
  94. function IsPlayerSeated(p)
  95. for i,v in pairs(getSeatedPlayers()) do
  96. if v == p then
  97. return true
  98. end
  99. end
  100. return false
  101. end
  102.  
  103. function IsPlayerInOrder(p)
  104. for i,v in pairs(RecalculatedOrder) do
  105. if v == p then
  106. return true
  107. end
  108. end
  109. return false
  110. end
  111.  
  112. function LowestInitiativePlayer()
  113. for i,v in pairs(Cards) do
  114. if Cards[i].player ~= "Black" then
  115. return Cards[i].player
  116. end
  117. end
  118. print("LowestInitiativePlayer loop ended without returning. This is the one thing we didn't want to happen.")
  119. end
  120.  
  121.  
  122. function PlayerInitiative(c)
  123. local LowerInit = 99
  124. for i,v in pairs(Cards) do
  125. if Cards[i].player == c then
  126. if Cards[i].init < LowerInit then
  127. LowerInit = Cards[i].init
  128. end
  129. end
  130. end
  131. return LowerInit
  132. end
  133.  
  134. function TableContains(table, element)
  135. for _, value in pairs(table) do
  136. if value == element then
  137. return true
  138. end
  139. end
  140. return false
  141. end
  142.  
  143. function ResetStrategyCards()
  144. self.editButton({index=0, click_function = 'Nada', label="Sure?", color = {0.4,0.1,0.1}})
  145. Timer.create({identifier = 't2'..self.getGUID(), function_name = 'Unlock', delay = 0.5})
  146. Timer.create({identifier = 't3'..self.getGUID(), function_name = 'ResetResetStrategyCardsButton', delay = 3})
  147. end
  148.  
  149. function Unlock()
  150. self.editButton({index=0, click_function = 'ActuallyResetStrategyCards', label="Confirm", color = {0.1,0.4,0.1}})
  151. end
  152.  
  153. function ResetResetStrategyCardsButton()
  154. self.editButton({index=0, click_function = 'ResetStrategyCards', label="Return", color = {0,0,0}})
  155. end
  156.  
  157. function ActuallyResetStrategyCards()
  158. for i,v in pairs(Cards) do
  159. if i ~= "Zero Initiative Token" then
  160. getObjectFromGUID(Cards[i].GUID).highlightOff()
  161. getObjectFromGUID(Cards[i].GUID).highlightOn({0.4,0.5,0.4})
  162. end
  163. end
  164.  
  165. for i,v in pairs(Cards) do
  166. if i ~= "Zero Initiative Token" then
  167. Cards[i].player = "Black"
  168. end
  169. end
  170.  
  171. for i,v in pairs(Cards) do
  172. if i ~= "Zero Initiative Token" then
  173. getObjectFromGUID(Cards[i].GUID).flip()
  174. getObjectFromGUID(Cards[i].GUID).setPosition{Cards[i].x,Cards[i].y,Cards[i].z}
  175. getObjectFromGUID(Cards[i].GUID).translate{0,1,0}
  176. getObjectFromGUID(Cards[i].GUID).setRotation{0,90,180}
  177. end
  178. end
  179. ClearTable(PassedPlayers)
  180. ResetResetStrategyCardsButton()
  181. Turns.enable = false
  182. end
  183.  
  184. function ClearTable(t)
  185. for k in pairs (t) do
  186. t [k] = nil
  187. end
  188. end
  189.  
  190. function ClearValueFromTable(t, v)
  191. for k in pairs (t) do
  192. if v == t[k] then
  193. t[k] = nil
  194. end
  195. end
  196. end
  197.  
  198. button_parameters = {}
  199. button_parameters.click_function = 'ResetStrategyCards'
  200. button_parameters.function_owner = self
  201. button_parameters.label = 'Return'
  202. button_parameters.position = {0,0.11,1.15}
  203. button_parameters.rotation = {0,0,0}
  204. button_parameters.width = 1000
  205. button_parameters.height = 400
  206. button_parameters.color = {0,0,0}
  207. button_parameters.font_size= 250
  208. button_parameters.font_color= {1,1,1}
  209.  
  210. function onObjectRandomize(o, c)
  211. if string.find(o.getDescription(), "Initiative", 1, 0) ~= nil then
  212. AssignCardToPlayer(o.getName(),c,o)
  213. end
  214.  
  215.  
  216.  
  217. end
  218.  
  219. function AssignCardToPlayer(Cardname,Assignee,CardObject)
  220. if Cards[Cardname].player ~= Assignee then
  221. Cards[Cardname].player = Assignee
  222. PC = stringColorToRGB(Assignee)
  223. CardObject.highlightOn(PC)
  224. if Player[Cards[Cardname].player].steam_name ~= nil then
  225. PrintingPlayerAssignee = Player[Cards[Cardname].player].steam_name
  226. else
  227. PrintingPlayerAssignee = Cards[Cardname].player
  228. end
  229. local PickMessage = "["..HexColor(Cards[Cardname].player).."]"..PrintingPlayerAssignee.."[ffffff] picked ["..Cards[Cardname].hexcolor.."]"..Cardname.."."
  230.  
  231. broadcastToAll(PickMessage)
  232.  
  233. else
  234. Cards[Cardname].player = "Black"
  235. CardObject.highlightOn({0.4,0.4,0.4})
  236.  
  237. end
  238. end
  239.  
  240. function ReturnPlayerCards(p)
  241. --print("calling ReturnPlayerCards")
  242. local MyCards = {}
  243. for i,v in pairs(Cards) do
  244. --print("comparing "..Cards[i].player)
  245. --print(" with "..p)
  246. if Cards[i].player == p then
  247. table.insert(MyCards, Cards[i])
  248. end
  249. end
  250. --print(TableLength(MyCards).." is the length of MyCards.")
  251. return MyCards
  252. end
  253.  
  254.  
  255. function onChat(message, p)
  256. if message == "Pass" or message == "pass" or message == "P" or message == "p" then
  257. if IsPlayerPassed(p.color) == false then
  258. table.insert(PassedPlayers, p.color)
  259. for i,v in pairs (ReturnPlayerCards(p.color)) do
  260. --print(v.player.." AAAGH "..p.color)
  261. getObjectFromGUID(v.GUID).highlightOn{0.4,0.5,0.4}
  262. end
  263.  
  264. if p.steam_name ~= nil then
  265. PrintingPlayerPass = p.steam_name
  266. else
  267. PrintingPlayerPass = p.color
  268. end
  269. PassMessage = "["..HexColor(p.color).."]"..PrintingPlayerPass.." passed."
  270. local x = TableLength(PassedPlayers)
  271. local y = TableLength(getSeatedPlayers())
  272. broadcastToAll(PassMessage.." ("..x.."/"..y.." players passed)")
  273. end
  274. end
  275. --
  276. if message == "unpass" or message == "Unpass" then
  277. if IsPlayerPassed(p.color) == true then
  278. ClearValueFromTable(PassedPlayers, p.color)
  279. for i,v in pairs (ReturnPlayerCards(p.color)) do
  280. --print(v.player.." AAAGH "..p.color)
  281. getObjectFromGUID(v.GUID).highlightOn(stringColorToRGB(p.color))
  282. end
  283.  
  284. if p.steam_name ~= nil then
  285. PrintingPlayerPass = p.steam_name
  286. else
  287. PrintingPlayerPass = p.color
  288. end
  289. PassMessage = "["..HexColor(p.color).."]"..PrintingPlayerPass.." undid passing."
  290. local x = TableLength(PassedPlayers)
  291. local y = TableLength(getSeatedPlayers())
  292. broadcastToAll(PassMessage.." ("..x.."/"..y.." players passed)")
  293. end
  294. end
  295.  
  296.  
  297. if message == "Reset" or message == "reset" then
  298. ClearTable(PassedPlayers)
  299. local x = TableLength(PassedPlayers)
  300. local y = TableLength(getSeatedPlayers())
  301. broadcastToAll("Passed players reset, "..x.."/"..y.." players passed.")
  302. end
  303.  
  304. if message == "rundown" or message == "Rundown" then
  305. QuickRundown()
  306. end
  307.  
  308. end
  309.  
  310.  
  311.  
  312.  
  313. function IsPlayerPassed(p)
  314. --QuickRundown()
  315. result = false
  316. for i,v in pairs (PassedPlayers) do
  317. --print("Comparing "..v.." with "..p)
  318. if v == p then
  319. result = true
  320. end
  321. end
  322. return result
  323. end
  324.  
  325. function TableLength(T)
  326. local count = 0
  327. for _ in pairs(T) do
  328. count = count + 1
  329. end
  330. return count
  331. end
  332.  
  333. function onPlayerTurn(c)
  334. --print("The next turn belongs to "..tostring(Turns.getNextTurnColor()))
  335. --msg = "'s turn begins. IsPlayerPassed = "..tostring(IsPlayerPassed(c.color))
  336.  
  337. if IsPlayerPassed(c.color) == true then
  338. --print("IsPlayerPassed came back true.")
  339. msg = "["..HexColor(c.color).."]"..c.color.."[ffffff] already passed, moving turn to ".."["..HexColor(Turns.getNextTurnColor()).."]"..Turns.getNextTurnColor()
  340. Wait.time(function() print(msg) end, 0.5)
  341. Wait.time(function() Turns.turn_color = Turns.getNextTurnColor() end, 0.5)
  342. end
  343.  
  344.  
  345. end
  346.  
  347.  
  348.  
  349.  
  350. function QuickRundown()
  351. for i,v in pairs(RecalculatedOrder) do
  352. msg2 = "[a7c7a1] has not "
  353. if IsPlayerPassed(v) == true then
  354. msg2 = "[968181] has "
  355. end
  356.  
  357.  
  358. if v.steam_name ~= nil then
  359. PrintingPlayerPass2 = Player[v].steam_name
  360. else
  361. PrintingPlayerPass2 = Player[v].color
  362. end
  363.  
  364. printToAll("["..HexColor(Player[v].color).."]"..PrintingPlayerPass2..msg2.."passed. They had initiative "..PlayerInitiative(v))
  365.  
  366. end
  367. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement