sr2lua/gmb_poker.lua

  1. Gmb_poker = {} 
  2.  
  3. Gmb_poker_thread = -1 
  4.  
  5. GMB_INPUT_STATES = { 
  6. 	BET = 0, 
  7. 	HOLDING = 10, 
  8. 	COMPLETE = 20, 
  9. } 
  10.  
  11. GMB_POKER_HANDS = { 
  12. 	NONE = -1, 
  13. 	JACKS_OR_HIGHER  = 0, 
  14. 	TWO_PAIR = 1, 
  15. 	THREE_OF_A_KIND = 2, 
  16. 	STRAIGHT = 3, 
  17. 	FLUSH = 4, 
  18. 	FULL_HOUSE = 5, 
  19. 	FOUR_OF_A_KIND = 6, 
  20. 	STRAIGHT_FLUSH  = 7, 
  21. 	ROYAL_FLUSH  = 8, 
  22. } 
  23.  
  24.  
  25. GMB_POKER_HANDS_STRINGS = { 
  26. 	[-1] = 	"DIVERSION_POKER_LOSE", 
  27. 	[0] = 	"DIVERSION_POKER_JACKS_OR_HIGHER", 
  28. 	[1] =		"DIVERSION_POKER_TWO_PAIR", 
  29. 	[2] =		"DIVERSION_POKER_THREE_OF_A_KIND", 
  30. 	[3] = 	"DIVERSION_POKER_STRAIGHT", 
  31. 	[4] = 	"DIVERSION_POKER_FLUSH", 
  32. 	[5] = 	"DIVERSION_POKER_FULL_HOUSE", 
  33. 	[6] = 	"DIVERSION_POKER_FOUR_OF_A_KIND", 
  34. 	[7] = 	"DIVERSION_POKER_STRAIGHT_FLUSH", 
  35. 	[8] = 	"DIVERSION_POKER_ROYAL_FLUSH", 
  36. } 
  37.  
  38. GMB_SUIT_ENUMS = { 
  39. 	BLANK = -1, 
  40. 	SPADE = 0, 
  41. 	CLUB = 1, 
  42. 	DIAMOND = 2, 
  43. 	HEART = 3, 
  44. } 
  45.  
  46. GMB_CARD_ENUMS = { 
  47. 	[1] = "A", 
  48. 	[11] = "J", 
  49. 	[12] = "Q", 
  50. 	[13] = "K", 
  51. } 
  52.  
  53. --Initialize sound 
  54. GMB_POKER_AUDIO = {}	 
  55. GMB_POKER_AUDIO.THEME 		= audio_get_audio_id("SYS_VPOKER_POKERTHEME") 
  56. GMB_POKER_AUDIO.NAV 			= audio_get_audio_id("SYS_VPOKER_UDLR") 
  57. GMB_POKER_AUDIO.SELECT 		= audio_get_audio_id("SYS_VPOKER_SELECT") 
  58. GMB_POKER_AUDIO.DEAL_CARD 	= audio_get_audio_id("SYS_VPOKER_DEALCARD") 
  59. GMB_POKER_AUDIO.WIN 			= audio_get_audio_id("SYS_VPOKER_WIN") 
  60. GMB_POKER_AUDIO.LOSE 		= audio_get_audio_id("SYS_VPOKER_LOSE") 
  61.  
  62.  
  63. GMB_CARD_SPACING = 120	-- Spacing of cards 
  64. GMB_POKER_CARD_FADE_IN_DELAY = .2 --Every deal it waits this long in seconds before starting to fade in the cards 
  65. function gmb_poker_init() 
  66.  
  67. 	vint_object_destroy(vint_object_find("card_select_blink")) 
  68.  
  69. 	--Set buttons for console specific things 
  70. 	local confirm_button_h = vint_object_find("btn_a") 
  71. 	vint_set_property(confirm_button_h, "image", get_a_button()) 
  72. 	local back_button_h = vint_object_find("btn_b") 
  73. 	vint_set_property(back_button_h, "image", get_b_button()) 
  74. 	 
  75. 	--Align Button Tips 
  76. 	gmb_poker_btntips_align() 
  77.  
  78. 	peg_load("ui_gambling") 
  79. 	--Find objects 
  80. 	Gmb_poker.handles = {} 
  81. 	Gmb_poker.handles.cash = vint_object_find("player_cash") 
  82. 	Gmb_poker.handles.winnings = vint_object_find("winnings_grp") 
  83. 	Gmb_poker.handles.winnings_cash_txt = vint_object_find("cash_winnings_txt") 
  84. 	Gmb_poker.handles.winnings_hand_txt = vint_object_find("hand_type_txt") 
  85. 	 
  86. 	Gmb_poker.handles.winnings_box_nw 	= vint_object_find("nw", Gmb_poker.handles.winnings) 
  87. 	Gmb_poker.handles.winnings_box_n 	= vint_object_find("n", Gmb_poker.handles.winnings) 
  88. 	Gmb_poker.handles.winnings_box_ne 	= vint_object_find("ne", Gmb_poker.handles.winnings) 
  89. 	Gmb_poker.handles.winnings_box_w 	= vint_object_find("w", Gmb_poker.handles.winnings) 
  90. 	Gmb_poker.handles.winnings_box_c 	= vint_object_find("c", Gmb_poker.handles.winnings) 
  91. 	Gmb_poker.handles.winnings_box_e 	= vint_object_find("e", Gmb_poker.handles.winnings) 
  92. 	Gmb_poker.handles.winnings_box_sw 	= vint_object_find("sw", Gmb_poker.handles.winnings) 
  93. 	Gmb_poker.handles.winnings_box_s 	= vint_object_find("s", Gmb_poker.handles.winnings) 
  94. 	Gmb_poker.handles.winnings_box_se	= vint_object_find("se", Gmb_poker.handles.winnings) 
  95. 	 
  96. 	Gmb_poker.handles.cards = {} 
  97. 	Gmb_poker.handles.cards[GMB_SUIT_ENUMS.BLANK] = vint_object_find("card_back") 
  98. 	Gmb_poker.handles.cards[GMB_SUIT_ENUMS.SPADE] = vint_object_find("card_spade") 
  99. 	Gmb_poker.handles.cards[GMB_SUIT_ENUMS.CLUB] = vint_object_find("card_club") 
  100. 	Gmb_poker.handles.cards[GMB_SUIT_ENUMS.DIAMOND] = vint_object_find("card_diamond") 
  101. 	Gmb_poker.handles.cards[GMB_SUIT_ENUMS.HEART] = vint_object_find("card_heart") 
  102. 	 
  103. 	Gmb_poker.handles.card_select = vint_object_find("card_select") 
  104. 	Gmb_poker.handles.cards_grp = vint_object_find("cards_grp") 
  105. 	Gmb_poker.handles.hold_box = vint_object_find("hold_grp") 
  106. 	 
  107. 	Gmb_poker.handles.btn_action = vint_object_find("btn_action") 
  108. 	Gmb_poker.handles.btn_action_text = vint_object_find("text", Gmb_poker.handles.btn_action) 
  109. 	Gmb_poker.handles.btn_action_highlight = vint_object_find("highlight", Gmb_poker.handles.btn_action) 
  110. 	Gmb_poker.handles.btn_action_mid = vint_object_find("mid", Gmb_poker.handles.btn_action) 
  111. 	Gmb_poker.handles.btn_action_right = vint_object_find("right", Gmb_poker.handles.btn_action) 
  112. 	 
  113. 	Gmb_poker.handles.btn_action_highlight_mid = vint_object_find("highlight_mid", Gmb_poker.handles.btn_action) 
  114. 	Gmb_poker.handles.btn_action_highlight_right = vint_object_find("highlight_right", Gmb_poker.handles.btn_action) 
  115. 	 
  116. 	Gmb_poker.handles.btn_bet = vint_object_find("btn_bet") 
  117. 	Gmb_poker.handles.btn_bet_arrows = vint_object_find("bet_arrows", Gmb_poker.handles.btn_bet) 
  118. 	Gmb_poker.handles.btn_bet_highlight = vint_object_find("highlight", Gmb_poker.handles.btn_bet) 
  119. 	 
  120. 	--Payout Objects 
  121. 	local h = vint_object_find("payouts") 
  122. 	Gmb_poker.handles.payouts_grp = h 
  123. 	Gmb_poker.handles.payouts = {} 
  124. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.ROYAL_FLUSH] = { val_h = vint_object_find("c_1", h), text_h = vint_object_find("t_1", h)} 
  125. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.STRAIGHT_FLUSH] = { val_h = vint_object_find("c_2", h), text_h = vint_object_find("t_2", h)} 
  126. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.FOUR_OF_A_KIND] = { val_h = vint_object_find("c_3", h), text_h = vint_object_find("t_3", h)} 
  127. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.FULL_HOUSE] = { val_h = vint_object_find("c_4", h), text_h = vint_object_find("t_4", h)} 
  128. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.FLUSH] = { val_h = vint_object_find("c_5", h), text_h = vint_object_find("t_5", h)} 
  129. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.STRAIGHT] = { val_h = vint_object_find("c_6", h), text_h = vint_object_find("t_6", h)} 
  130. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.THREE_OF_A_KIND] = { val_h = vint_object_find("c_7", h), text_h = vint_object_find("t_7", h)} 
  131. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.TWO_PAIR] = { val_h = vint_object_find("c_8", h), text_h = vint_object_find("t_8", h)} 
  132. 	Gmb_poker.handles.payouts[GMB_POKER_HANDS.JACKS_OR_HIGHER] = { val_h = vint_object_find("c_9", h), text_h = vint_object_find("t_9", h)} 
  133. 	 
  134.  
  135. 	--Anim Objects 
  136. 	local h = vint_object_find("cards_fade_in") 
  137. 	Gmb_poker.anims = {} 
  138. 	Gmb_poker.anims.cards_fade_in = vint_object_find("cards_fade_in") 
  139.  
  140. 	Gmb_poker.anims.card_twn_fade_in = vint_object_find("card_twn_fade_in", Gmb_poker.anims.cards_fade_in) 
  141. 	 
  142. 	Gmb_poker.handles.results_anim = vint_object_find("winnings_blink") 
  143. 	local twn_h = vint_object_find("t_cash_tint_twn_2") 
  144. 	vint_set_property(twn_h, "end_event", "gmb_poker_loop_cash_anim") 
  145. 	 
  146. 	--Glowing Button Animation 
  147. 	Gmb_poker.handles.glow_btn_anim = vint_object_find("btn_glow_anim") 
  148. 	Gmb_poker.handles.glow_btn_twn = vint_object_find("btn_glow_twn", Gmb_poker.handles.glow_btn_anim) 
  149. 	 
  150. 	 
  151. 	--Data initialization 
  152. 	Gmb_poker.current_bet 	= 0 
  153. 	Gmb_poker.cash 			= 0 
  154. 	Gmb_poker.cards_dealt 	= 0 
  155. 	Gmb_poker.cur_idx 		= 0 
  156. 	 
  157. 	Gmb_poker.cards = {}					--Card Data 
  158. 	Gmb_poker.card_twns = {}			--Card Tweens 
  159. 	Gmb_poker.payout_data = {}			--Payout Data 
  160.  
  161. 	--Set input stat to betting state 
  162. 	gmb_poker_screen_state_set(GMB_INPUT_STATES.BET) 
  163. 	 
  164. 	--Increment and decrement bet 
  165. 	vint_dataresponder_request("poker_responder", "gmb_poker_bet_change_cb", 0, 1) 
  166. 	vint_dataresponder_request("poker_responder", "gmb_poker_bet_change_cb", 0, 0) 
  167. 	 
  168. 	--Subscribe to data 
  169. 	vint_datagroup_add_subscription("poker_hands", "insert", "gmb_poker_payouts_update") 
  170. 	vint_datagroup_add_subscription("poker_hands", "update", "gmb_poker_payouts_update") 
  171. 	 
  172. 	--Subscribe to data 
  173. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "gmb_poker_cash_update") 
  174. 	 
  175. 	--Create cards 
  176. 	gmb_poker_card_update("reset") 
  177. 	 
  178. 	--Subscribe to inputs 
  179. 	gmb_poker_input_subscribe() 
  180. 	 
  181. 	--Process  
  182. 	--cash process 
  183. 	Gmb_poker_thread = thread_new("gmb_poker_process") 
  184. 		 
  185. 	--Play theme sound 
  186. 	audio_play(GMB_POKER_AUDIO.THEME) 
  187. 	 
  188. 	--Event Tracking 
  189. 	event_tracking_interface_enter("Gambling: Poker") 
  190. end 
  191.  
  192. function gmb_poker_loop_cash_anim() 
  193. 	lua_play_anim(Gmb_poker.handles.results_anim, 0) 
  194. end 
  195.  
  196. function gmb_poker_input_subscribe() 
  197. 	--Subscribe to input 
  198. 	local g = Gmb_poker 
  199. 	g.input_subs = {	 
  200. 		vint_subscribe_to_input_event(nil, "nav_up",				"gmb_poker_input_event", 50), 
  201. 		vint_subscribe_to_input_event(nil, "nav_down",			"gmb_poker_input_event", 50), 
  202. 		vint_subscribe_to_input_event(nil, "nav_right",			"gmb_poker_input_event", 50), 
  203. 		vint_subscribe_to_input_event(nil, "nav_left",			"gmb_poker_input_event", 50), 
  204. 		vint_subscribe_to_input_event(nil, "select",				"gmb_poker_input_event", 50), 
  205. 		vint_subscribe_to_input_event(nil, "pause",				"gmb_poker_input_event", 50), 
  206. 		vint_subscribe_to_input_event(nil, "back",				"gmb_poker_input_event", 100), 
  207. 		vint_subscribe_to_input_event(nil, "map",				"gmb_poker_input_event", 100), 
  208. 	} 
  209. 	 
  210. 	--Make repeat rate super high 
  211. 	vint_set_input_params(g.input_subs[5], 120, nil, nil, nil) 
  212. 	vint_set_input_params(g.input_subs[6], 120, nil, nil, nil) 
  213. 	vint_set_input_params(g.input_subs[7], 120, nil, nil, nil) 
  214. end 
  215.  
  216. function gmb_poker_input_desubscribe() 
  217. 	--	Unsubscribe to input 
  218. 	local g = Gmb_poker 
  219. 	for idx, val in g.input_subs do 
  220. 		vint_unsubscribe_to_input_event(val) 
  221. 	end 
  222. 	g.input_subs = nil 
  223. end 
  224.  
  225. function gmb_poker_input_event(target, event, accelleration) 
  226. 	 
  227. 	--Is input blocked? 
  228. 	if gmb_poker_input_is_bocked() then 
  229. 		return 
  230. 	end 
  231. 	 
  232. 	if Gmb_poker.input_state == GMB_INPUT_STATES.BET then 
  233. 		if event == "nav_up" then 
  234. 			--Increase bet 
  235. 			audio_play(GMB_POKER_AUDIO.NAV) 
  236. 			vint_dataresponder_request("poker_responder", "gmb_poker_bet_change_cb", 0, 0) 
  237. 		elseif event == "nav_down" then 
  238. 			--Decrease bet 
  239. 			audio_play(GMB_POKER_AUDIO.NAV) 
  240. 			vint_dataresponder_request("poker_responder", "gmb_poker_bet_change_cb", 0, 1) 
  241. 			 
  242. 		elseif event == "select" then 
  243. 			--Check to make sure the player has enough cash to make current bet 
  244. 			if Gmb_poker.current_bet > Gmb_poker.cash then 
  245. 				gmb_poker_not_enough_cash_dialog() 
  246. 				return 
  247. 			end 
  248. 			--Select bet 
  249. 			audio_play(GMB_POKER_AUDIO.SELECT) 
  250. 			gmb_poker_deal_first() 
  251. 		end 
  252. 	elseif Gmb_poker.input_state == GMB_INPUT_STATES.HOLDING then 
  253. 		if event == "nav_up" or event == "nav_down" then 
  254. 			--swap between deal and hold 
  255. 			local new_idx  
  256. 			if Gmb_poker.cur_idx > 0 then 
  257. 				new_idx = 0 
  258. 			else 
  259. 				new_idx = 1 
  260. 			end 
  261. 			audio_play(GMB_POKER_AUDIO.NAV) 
  262. 			gmb_poker_hold_nav(new_idx) 
  263. 		elseif event == "nav_right" then 
  264. 			local new_idx  
  265. 			if Gmb_poker.cur_idx == 0 then 
  266. 				--if not on a card select furthest right card 
  267. 				new_idx  = 5 
  268. 			else 
  269. 				new_idx = Gmb_poker.cur_idx + 1 
  270. 				if new_idx > 5 then 
  271. 					--Wrap around to left card 
  272. 					new_idx = 1 
  273. 				end 
  274. 			end		 
  275. 			audio_play(GMB_POKER_AUDIO.NAV) 
  276. 			gmb_poker_hold_nav(new_idx) 
  277. 		elseif event == "nav_left" then 
  278. 			--if not on a card select furthest left card 
  279. 			local new_idx  
  280. 			if Gmb_poker.cur_idx == 0 then 
  281. 				new_idx = 1 
  282. 			else 
  283. 				new_idx = Gmb_poker.cur_idx - 1 
  284. 				if new_idx < 1 then 
  285. 					--Wrap around to left card 
  286. 					new_idx = 5 
  287. 				end 
  288. 			end	 
  289. 			audio_play(GMB_POKER_AUDIO.NAV)			 
  290. 			gmb_poker_hold_nav(new_idx) 
  291. 		elseif event == "select" then 
  292. 		 
  293. 			audio_play(GMB_POKER_AUDIO.SELECT) 
  294. 			if Gmb_poker.cur_idx == 0 then 
  295. 				--deal 
  296. 				gmb_poker_deal_second() 
  297. 			else 
  298. 				--hold toggle 
  299. 				gmb_poker_hold_select() 
  300. 			end 
  301. 		end 
  302. 	elseif Gmb_poker.input_state == GMB_INPUT_STATES.COMPLETE then 
  303. 		if event == "select" then 
  304. 			audio_play(GMB_POKER_AUDIO.SELECT) 
  305. 			vint_dataresponder_request("poker_responder", "gmb_poker_restart", 0, 7) 
  306. 		end 
  307. 	end 
  308. 	 
  309. 	--No where to pause 
  310. 	if event == "pause" then  
  311. 		dialog_open_pause_display() 
  312. 	end 
  313. 	 
  314. 	--Always able to quit 
  315. 	if event == "back" then 
  316. 		--Indicate to C that we've quit 
  317. 		gmb_poker_quit_dialog() 
  318. 	end 
  319. end 
  320.  
  321. function gmb_poker_bet_change_cb(new_bet) 
  322. 	--Update betting string in button 
  323. 	Gmb_poker.current_bet = new_bet 
  324. 	 
  325. 	local btn_bet_h = vint_object_find("btn_bet") 
  326. 	local cash_h = vint_object_find("cash", btn_bet_h) 
  327. 	vint_set_property(cash_h, "text_tag", "$" .. format_cash(new_bet)) 
  328. 	 
  329. 	 
  330. 	gmb_poker_payouts_update_screen() 
  331. end 
  332.  
  333. --[[ 
  334. first parameter - message type 
  335. 	0 - increment bet 
  336. 	1 - decrement bet 
  337. 	2 - hold card 
  338. 		- second parameter - which card (0 - 4) 
  339. 	3 - unhold 
  340. 		- second parameter - which card (0 - 4) 
  341. 	3 - first deal 
  342. 	4 - second deal 
  343. 	5 - quit 
  344. 	6 - start new game 
  345. ]] 
  346.  
  347.  
  348. function gmb_poker_cleanup() 
  349. 	gmb_poker_input_desubscribe() 
  350. 	--Kill process thread 
  351. 	if Gmb_poker_thread ~= -1 then 
  352. 		thread_kill(Gmb_poker_thread) 
  353. 		Gmb_poker_thread = -1 
  354. 	end 
  355. 	--Unload Gambling Peg 
  356. 	peg_unload("ui_gambling") 
  357. 	 
  358. 	--Event Tracking (Exit gambling) 
  359. 	event_tracking_interface_exit() 
  360. end 
  361.  
  362. function gmb_poker_screen_state_set(state) 
  363.  
  364. 	 
  365. 	if state == GMB_INPUT_STATES.BET then 
  366. 		vint_set_property(Gmb_poker.handles.winnings, "visible", false) 
  367. 		--Set action button Text 
  368. 		gmb_poker_action_btn_set_text("DIVERSION_POKER_DEAL") 
  369. 		gmb_poker_action_btn_set_state(true) 
  370. 		 
  371. 		--Show arrows on betting and highlight btn 
  372. 		vint_set_property(Gmb_poker.handles.btn_bet_arrows, "visible", true) 
  373. 		vint_set_property(Gmb_poker.handles.btn_bet_highlight, "visible", false) 
  374. 		 
  375. 	elseif state == GMB_INPUT_STATES.HOLDING then 
  376. 		--Reset cursor index 
  377. 		Gmb_poker.cur_idx = 0 
  378. 		gmb_poker_action_btn_set_text("DIVERSION_POKER_DEAL") 
  379. 		gmb_poker_action_btn_set_state(true) 
  380. 	elseif state == GMB_INPUT_STATES.COMPLETE then 
  381. 		gmb_poker_action_btn_set_text("DIVERSION_POKER_PLAY_AGAIN") 
  382. 		gmb_poker_action_btn_set_state(true) 
  383. 	end 
  384. 	 
  385. 	--Set input state 
  386. 	Gmb_poker.input_state = state 
  387. end 
  388.  
  389.  
  390. function gmb_poker_payouts_update(di_h) 
  391. 	--Event from game dumps data into stored data and updates the item 
  392. 	local hand_enum, value_multiplier, is_active = vint_dataitem_get(di_h) 
  393. 	Gmb_poker.payout_data[hand_enum] = {hand_enum = hand_enum, value_multiplier = value_multiplier, is_active = is_active} 
  394. 	gmb_poker_payouts_update_item(hand_enum) 
  395. 	 
  396. 	if is_active == true then 
  397. 		--mark active 
  398. 	else 
  399. 		--mark normal 
  400. 	end 
  401. end 
  402.  
  403. function gmb_poker_payouts_update_screen() 
  404. 	for idx, val in Gmb_poker.payout_data do  
  405. 		gmb_poker_payouts_update_item(idx) 
  406. 	end 
  407. end 
  408.  
  409. function gmb_poker_payouts_update_item(hand_enum) 
  410. 	--Updates the payout item with current data 
  411. 	local payout_val_h = Gmb_poker.handles.payouts[hand_enum].val_h 
  412. 	local hand_value = Gmb_poker.payout_data[hand_enum].value_multiplier * Gmb_poker.current_bet  
  413. 	vint_set_property(payout_val_h, "text_tag", "$" .. format_cash(hand_value)) 
  414. end 
  415.  
  416. function gmb_poker_deal_first() 
  417. 	--block input 
  418. 	gmb_poker_input_block(true) 
  419.  
  420. 	--Deals hand 
  421. 	--Remove all cards 
  422. 	gmb_poker_card_clear_all() 
  423. 	 
  424. 	Gmb_poker.cards_dealt = 0 
  425. 	vint_dataresponder_request("poker_responder", "gmb_poker_deal_cb", 0, 4) 
  426. 	 
  427. 	--Set callback of master tween 
  428. 	vint_set_property(Gmb_poker.anims.card_twn_fade_in, "end_event", "gmb_poker_deal_first_complete") 
  429. 	 
  430. 	--Set callback of master tween ot fire after last tween 
  431. 	vint_set_property(Gmb_poker.anims.card_twn_fade_in, "start_time", Gmb_poker.cards_dealt*.1) 
  432. 	 
  433. 	--Play card fade in animation 
  434. 	lua_play_anim(Gmb_poker.anims.cards_fade_in, GMB_POKER_CARD_FADE_IN_DELAY) 
  435. 	 
  436. 	--Hide betting arrows and update betting state 
  437. 	vint_set_property(Gmb_poker.handles.btn_bet_arrows , "visible", false) 
  438. 	vint_set_property(Gmb_poker.handles.btn_bet_highlight , "visible", false) 
  439. end 
  440.  
  441. function gmb_poker_deal_first_complete() 
  442. 	--Cards have faded in now lets reset some status markers 
  443. 	 
  444. 	--clear all the tweens 
  445. 	for idx, val in Gmb_poker.card_twns do 
  446. 		vint_object_destroy(idx) 
  447. 	end 
  448. 	Gmb_poker.card_twns = {} 
  449. 	 
  450. 	--Set Hold status on all the cards 
  451. 	for idx, val in Gmb_poker.cards do 
  452. 		if val.is_held == true then		 
  453. 			vint_set_property(val.hold_h, "visible", true) 
  454. 		else 
  455. 			vint_set_property(val.hold_h, "visible", false) 
  456. 		end 
  457. 	end 
  458. 	 
  459. 	--Cards are dealt and visible now.. unblock input and change screen state. 
  460. 	gmb_poker_screen_state_set(GMB_INPUT_STATES.HOLDING) 
  461. 	--Unblock input 
  462. 	gmb_poker_input_block(false) 
  463. end 
  464.  
  465. function gmb_poker_deal_second() 
  466. 	--block input 
  467. 	gmb_poker_input_block(true) 
  468.  
  469. 	--Clear out unheld cards 
  470. 	for idx, val in Gmb_poker.cards do 
  471. 		if val.is_held == false then 
  472. 			vint_object_destroy(val.hold_h) 
  473. 			vint_object_destroy(val.grp_h) 
  474. 			Gmb_poker.cards[idx] = nil 
  475. 			Gmb_poker.cards_dealt = Gmb_poker.cards_dealt - 1 
  476. 		end 
  477. 		--Clear out hold status  
  478. 		if val.is_held == true then 
  479. 			vint_object_destroy(val.hold_h) 
  480. 			Gmb_poker.cards[idx].hold_h = nil 
  481. 			Gmb_poker.cards[idx].is_held = false 
  482. 		end 
  483. 	end 
  484. 	 
  485. 	--Reset how many cards are delt this round 
  486. 	Gmb_poker.cards_dealt = 0 
  487. 	 
  488. 	--Deal new cards 
  489. 	vint_dataresponder_request("poker_responder", "gmb_poker_deal_cb", 0, 5) 
  490. 	 
  491. 	--Set callback of master tween 
  492. 	vint_set_property(Gmb_poker.anims.card_twn_fade_in, "end_event", "gmb_poker_deal_second_complete") 
  493. 	 
  494. 	--Set callback of master tween ot fire after last tween 
  495. 	vint_set_property(Gmb_poker.anims.card_twn_fade_in, "start_time", Gmb_poker.cards_dealt*.1) 
  496. 	 
  497. 	--Play card fade in animation 
  498. 	lua_play_anim(Gmb_poker.anims.cards_fade_in, GMB_POKER_CARD_FADE_IN_DELAY)	 
  499. end 
  500.  
  501.  
  502. function gmb_poker_deal_cb(card_slot, suit_enum, card_enum, is_held) 
  503.  
  504. 	--Card already exists in slot... do not replace  
  505. 	--However, we need to set its hold status 
  506. 	if Gmb_poker.cards[card_slot] ~= nil then 
  507. 		Gmb_poker.cards[card_slot].is_held = is_held 
  508. 		return 
  509. 	end 
  510. 	 
  511. 	--Update data 
  512. 	local h = vint_object_clone(Gmb_poker.handles.cards[suit_enum]) 
  513. 	local hold_h = vint_object_clone(Gmb_poker.handles.hold_box) 
  514. 	 
  515. 	--Resolve the card number for the card 
  516. 	local card_number 
  517. 	if GMB_CARD_ENUMS[card_enum] ~= nil then 
  518. 		--Use specified string for the enum 
  519. 		card_number = GMB_CARD_ENUMS[card_enum]  
  520. 	else 
  521. 		--Use normal number 
  522. 		card_number = card_enum 
  523. 	end 
  524. 	 
  525. 	--Set text on card 
  526. 	local card_num_1_h = vint_object_find("card_num_1", h) 
  527. 	local card_num_2_h = vint_object_find("card_num_2", h) 
  528. 	vint_set_property(card_num_1_h, "text_tag", card_number) 
  529. 	vint_set_property(card_num_2_h, "text_tag", card_number) 
  530. 	 
  531. 	--Store into table 
  532. 	Gmb_poker.cards[card_slot] = { 
  533. 		grp_h = h, 
  534. 		hold_h = hold_h, 
  535. 		suite = suit_enum, 
  536. 		card = card_enum, 
  537. 		is_held = is_held, 
  538. 	} 
  539. 	 
  540. 	--Position cards and hold status 
  541. 	local x 
  542. 	local y = 0 
  543. 	local x = card_slot * GMB_CARD_SPACING 
  544. 	vint_set_property(Gmb_poker.cards[card_slot].grp_h, "anchor", x, y) 
  545. 	vint_set_property(Gmb_poker.cards[card_slot].hold_h, "anchor", x, y) 
  546. 	vint_set_property(Gmb_poker.cards[card_slot].hold_h, "visible", false) 
  547.  
  548. 	--Create a tween for the card 
  549. 	local twn_h = vint_object_clone(Gmb_poker.anims.card_twn_fade_in) 
  550. 	 
  551. 	--Offset time based on how many cards are delt this round 
  552. 	vint_set_property(twn_h, "start_time", .1 * Gmb_poker.cards_dealt) 
  553. 	 
  554. 	--Retarget 
  555. 	vint_set_property(twn_h, "target_handle", Gmb_poker.cards[card_slot].grp_h) 
  556. 	 
  557. 	--Hide object 
  558. 	vint_set_property(Gmb_poker.cards[card_slot].grp_h, "alpha", 0) 
  559. 	 
  560. 	vint_set_property(twn_h, "end_event", "gmb_poker_deal_card_sound") 
  561. 	 
  562. 	--Store tween for cleanup 
  563. 	Gmb_poker.card_twns[twn_h] = true 
  564. 	 
  565. 	Gmb_poker.cards_dealt = Gmb_poker.cards_dealt + 1 
  566. end 
  567.  
  568. function gmb_poker_deal_second_complete() 
  569.  
  570. 	local x, y 
  571. 	 
  572. 	--Replace held card status with glowing highlights 
  573. 	for idx, val in Gmb_poker.cards do 
  574. 		if val.is_held == true then 
  575. 		 
  576. 			--Only clone a new one if we have another one 
  577. 			if Gmb_poker.cards[idx].hold_h == nil then 
  578. 				Gmb_poker.cards[idx].hold_h = vint_object_clone(Gmb_poker.handles.card_select) 
  579. 			end 
  580. 			 
  581. 			vint_set_property(Gmb_poker.cards[idx].hold_h, "visible", true) 
  582. 			x, y = vint_get_property(val.grp_h, "anchor") 
  583. 			vint_set_property(Gmb_poker.cards[idx].hold_h, "anchor", x, y) 
  584. 		end 
  585. 	end 
  586. 	 
  587. 	vint_dataresponder_request("poker_responder", "gmb_poker_winnings_cb", 0, 8) 
  588. 	 
  589. 	--Show winnings 
  590. 	vint_set_property(Gmb_poker.handles.winnings, "visible", true) 
  591. 	 
  592. 	gmb_poker_screen_state_set(GMB_INPUT_STATES.COMPLETE) 
  593. 	gmb_poker_input_block(false) 
  594. end 
  595.  
  596.  
  597. function gmb_poker_winnings_cb(hand_enum, dollars_winnings) 
  598.  
  599. 	--Show winnings information 
  600. 	vint_set_property(Gmb_poker.handles.winnings_hand_txt, "text_tag", var_to_string(GMB_POKER_HANDS_STRINGS[hand_enum])) 
  601. 	vint_set_property(Gmb_poker.handles.winnings_cash_txt, "text_tag", "$" .. format_cash(dollars_winnings)) 
  602. 	 
  603. 	local width, height = element_get_actual_size(Gmb_poker.handles.winnings_hand_txt) 
  604. 	width = floor(width) 
  605. 	height = floor(height) 
  606. 	local x = floor(width/2) 
  607. 	local y = floor(height/2) 
  608. 	local box_shrink = 36 
  609. 	 
  610. 	local x_minus, y_minus 
  611. 	x_minus = x * -1 
  612. 	y_minus = y * -1 
  613. 	 
  614. 	local source_se_width, source_se_height 
  615. 	 
  616. 	--Everything based on center 
  617. 	element_set_actual_size(Gmb_poker.handles.winnings_box_c, width, height) 
  618. 	 
  619. 	vint_set_property(Gmb_poker.handles.winnings_box_nw, "anchor", x_minus, y_minus) 
  620. 	vint_set_property(Gmb_poker.handles.winnings_box_n, "anchor", x_minus, y_minus) 
  621. 	 
  622. 	source_se_width, source_se_height = vint_get_property(Gmb_poker.handles.winnings_box_n, "source_se") 
  623. 	 
  624. 	if dollars_winnings == 0 then 
  625. 		vint_set_property(Gmb_poker.handles.winnings_cash_txt, "visible", false) 
  626. 		vint_set_property(Gmb_poker.handles.winnings_box_c, "source_se", source_se_width, 8) 
  627. 	else 
  628. 		vint_set_property(Gmb_poker.handles.winnings_cash_txt, "visible", true) 
  629. 		vint_set_property(Gmb_poker.handles.winnings_box_c, "source_se", source_se_width, height) 
  630. 		box_shrink = 0 
  631. 	end 
  632. 		 
  633. 	vint_set_property(Gmb_poker.handles.winnings_box_n, "source_se", width, source_se_height) 
  634. 	vint_set_property(Gmb_poker.handles.winnings_box_ne, "anchor", x, y_minus) 
  635. 	 
  636. 	vint_set_property(Gmb_poker.handles.winnings_box_w, "anchor", x_minus, y_minus) 
  637. 	vint_set_property(Gmb_poker.handles.winnings_box_w, "source_se", width, height - box_shrink) 
  638. 	vint_set_property(Gmb_poker.handles.winnings_box_e, "anchor", x, y_minus) 
  639. 	vint_set_property(Gmb_poker.handles.winnings_box_e, "source_se", width, height - box_shrink)	 
  640. 	 
  641. 	vint_set_property(Gmb_poker.handles.winnings_box_sw, "anchor", x_minus, y - box_shrink) 
  642. 	vint_set_property(Gmb_poker.handles.winnings_box_s, "anchor", x_minus, y - box_shrink) 
  643. 	vint_set_property(Gmb_poker.handles.winnings_box_s, "source_se", width, height - box_shrink) 
  644. 	vint_set_property(Gmb_poker.handles.winnings_box_se, "anchor", x, y - box_shrink) 
  645. 	 
  646. 	if hand_enum >= 0 then 
  647. 		--Win 
  648. 		audio_play(GMB_POKER_AUDIO.WIN) 
  649. 		 
  650. 	else 
  651. 		--lose 
  652. 		audio_play(GMB_POKER_AUDIO.LOSE) 
  653. 	end 
  654. end 
  655.  
  656. function gmb_poker_deal_card_sound() 
  657. 	audio_play(GMB_POKER_AUDIO.DEAL_CARD) 
  658. end 
  659.  
  660. function gmb_poker_card_update(action) 
  661. 	if action == "reset" then 
  662. 		--Clear cards out of slots 
  663. 		gmb_poker_card_clear_all() 
  664. 		 
  665. 		--Create 5 blank cards 
  666. 		local card_idx, h, x, y  
  667. 		y = 0 
  668. 		for card_idx = 0, 4 do 
  669. 			h = vint_object_clone(Gmb_poker.handles.cards[GMB_SUIT_ENUMS.BLANK]) 
  670. 			Gmb_poker.cards[card_idx] = { 
  671. 				grp_h = h, 
  672. 				suite = GMB_SUIT_ENUMS.BLANK, 
  673. 				is_held = false, 
  674. 				card = -1 
  675. 			} 
  676. 			x = card_idx * GMB_CARD_SPACING 
  677. 			vint_set_property(h, "anchor", x, y) 
  678. 		end 
  679.  
  680. 	elseif action == "flip" then 
  681. 	 
  682. 	end 
  683. end 
  684.  
  685.  
  686. function gmb_poker_card_clear_all() 
  687. 	for idx, val in Gmb_poker.cards do 
  688. 		vint_object_destroy(val.grp_h) 
  689. 		--Destroy hold card if it exists 
  690. 		if val.hold_h ~= nil then 
  691. 			vint_object_destroy(val.hold_h) 
  692. 		end 
  693. 	end 
  694. 	Gmb_poker.cards = {} 
  695. end 
  696.  
  697. --================================= 
  698. --Poker Hold Interface 
  699. --================================= 
  700. function gmb_poker_hold_nav(new_idx) 
  701.  
  702. 	if new_idx == 0 then 
  703. 		--hide selector 
  704. 		vint_set_property(Gmb_poker.handles.card_select, "visible", false) 
  705. 		 
  706. 		--Show deal highlight btn 
  707. 		gmb_poker_action_btn_set_state(true) 
  708. 	else 
  709. 		--show Selector 
  710. 		vint_set_property(Gmb_poker.handles.card_select, "visible", true) 
  711. 		 
  712. 		vint_set_property(Gmb_poker.handles.glow_btn_twn, "target_handle", Gmb_poker.handles.card_select) 
  713. 		 
  714. 		--move selector 
  715. 		local target_card = Gmb_poker.cards[new_idx - 1].grp_h 
  716. 		local x, y = vint_get_property(target_card, "anchor") 
  717. 		vint_set_property(Gmb_poker.handles.card_select, "anchor", x, y) 
  718. 		 
  719. 		--Unhighlight deal btn 
  720. 		gmb_poker_action_btn_set_state(false) 
  721. 	end 
  722. 	 
  723. 	Gmb_poker.cur_idx = new_idx 
  724. end 
  725.  
  726. function gmb_poker_hold_select() 
  727. 	--Toggle hold 
  728. 	--Make sure our index is greater than 0 
  729. 	if Gmb_poker.cur_idx < 1 then 
  730. 		return 
  731. 	end 
  732. 	 
  733. 	local card_slot = Gmb_poker.cur_idx - 1 
  734. 	local selected_card = Gmb_poker.cards[card_slot]  
  735.  
  736. 	--Get card status 
  737. 	if selected_card.is_held == true then 
  738. 		--hold card 
  739. 		vint_dataresponder_request("poker_responder", "gmb_poker_hold_cb", 0, 2, card_slot) 
  740. 	else 
  741. 		--unhold card 
  742. 		vint_dataresponder_request("poker_responder", "gmb_poker_hold_cb", 0, 3, card_slot) 
  743. 	end 
  744. end 
  745.  
  746. function gmb_poker_hold_cb(success) 
  747. 	if success == true then 
  748. 		local card_slot = Gmb_poker.cur_idx - 1 
  749. 		local selected_card = Gmb_poker.cards[card_slot]  
  750. 	 
  751. 		--based on card status flip the is_held toggle 
  752. 		if selected_card.is_held == true then 
  753. 			--hide hold status and set data 
  754. 			vint_set_property(selected_card.hold_h, "visible", false) 
  755. 			selected_card.is_held = false  
  756. 		else 
  757. 			--Show hold status and set data 
  758. 			vint_set_property(selected_card.hold_h, "visible", true) 
  759. 			selected_card.is_held = true 
  760. 		end 
  761. 	end 
  762. end 
  763.  
  764. function gmb_poker_restart(success) 
  765. 	--mm... what do i do? 
  766. 	gmb_poker_card_update("reset") 
  767. 	gmb_poker_screen_state_set(GMB_INPUT_STATES.BET) 
  768. end 
  769.  
  770. --================================= 
  771. --CASH UPDATES 
  772. --================================= 
  773. function gmb_poker_cash_update(di_h) 
  774. 	local cash = vint_dataitem_get(di_h) 
  775. 	Gmb_poker.cash = floor(cash) 
  776. end 
  777.  
  778. function gmb_poker_process() 
  779.  
  780. 	local display_cash = Gmb_poker.cash - 1 --Subtract one so it gets formatted in the loop. 
  781. 	while true do 
  782. 		thread_yield() 
  783. 		 
  784. 		-- Animate Cash 
  785. 		if display_cash ~= Gmb_poker.cash  then 
  786. 			local diff_cash = Gmb_poker.cash  - display_cash 
  787. 			 
  788. 			if diff_cash > 5 or diff_cash < -5 then 
  789. 				diff_cash = floor(diff_cash * 0.5) 
  790. 			end 
  791. 			 
  792. 			display_cash = display_cash + diff_cash 
  793. 			vint_set_property(Gmb_poker.handles.cash, "text_tag", "$" .. format_cash(display_cash)) 
  794. 		end 
  795. 	end 
  796. end 
  797.  
  798. --================================== 
  799. --ACTION BUTTON 
  800. --================================== 
  801. function gmb_poker_action_btn_set_text(text_string) 
  802. 	 
  803. 	--Set text tag 
  804. 	vint_set_property(Gmb_poker.handles.btn_action_text, "text_tag", text_string) 
  805. 	 
  806. 	--Adjust widths 
  807. 	local width, height = element_get_actual_size(Gmb_poker.handles.btn_action_text) 
  808. 	width = floor(width) 
  809. 	height = floor(height) 
  810. 	local x, y 
  811. 	vint_set_property(Gmb_poker.handles.btn_action_mid, "source_se", width, 200) 
  812.    x, y = vint_get_property(Gmb_poker.handles.btn_action_mid , "anchor") 
  813. 	vint_set_property(Gmb_poker.handles.btn_action_right, "anchor", x + width, y) 
  814. 	vint_set_property(Gmb_poker.handles.btn_action_highlight_mid, "source_se", width, 200) 
  815. 	vint_set_property(Gmb_poker.handles.btn_action_highlight_right, "anchor",  x + width, y)	 
  816. end 
  817.  
  818. function gmb_poker_action_btn_set_state(active) 
  819. 	if active == true then 
  820. 		vint_set_property(Gmb_poker.handles.glow_btn_twn, "target_handle", Gmb_poker.handles.btn_action_highlight) 
  821. 		vint_set_property(Gmb_poker.handles.btn_action_highlight, "visible", true) 
  822. 		vint_set_property(Gmb_poker.handles.btn_action_text, "tint", .9, .74, .05) 
  823. 	else 
  824. 		vint_set_property(Gmb_poker.handles.btn_action_highlight, "visible", false) 
  825. 		vint_set_property(Gmb_poker.handles.btn_action_highlight, "tint", 1, 1, 1) 
  826. 		vint_set_property(Gmb_poker.handles.btn_action_text, "tint", .77, .8, .81) 
  827. 	end	 
  828. end 
  829.  
  830. --================================= 
  831. --QUIT POKER 
  832. --================================= 
  833. function gmb_poker_quit(success) 
  834. 	if success == true then 
  835. 		vint_document_unload(vint_document_find("gmb_poker")) 
  836. 	end	 
  837. end 
  838.  
  839. --================================ 
  840. --DIALOG BOXES 
  841. --================================ 
  842. function gmb_poker_quit_dialog() 
  843. 	dialog_box_confirmation("GAMBLING_POKER_DIALOG_QUIT_HEADER", "GAMBLING_POKER_DIALOG_QUIT_BODY", "gmb_poker_quit_dialog_cb") 
  844. end 
  845.  
  846. function gmb_poker_quit_dialog_cb(result, action) 
  847. 	if action ~= DIALOG_ACTION_CLOSE then 
  848. 		return 
  849. 	end 
  850. 	if result == 0 then 
  851. 		--Quit Request 
  852. 		vint_dataresponder_request("poker_responder", "gmb_poker_quit", 0, 6) 
  853. 	else 
  854. 		--do nothing 
  855. 	end 
  856. end 
  857.  
  858. function gmb_poker_not_enough_cash_dialog() 
  859. 	dialog_box_message("GAMBLING_POKER_DIALOG_NO_CASH_HEADER","GAMBLING_POKER_DIALOG_NO_CASH_BODY") 
  860. end 
  861.  
  862. --================================= 
  863. --INPUT BLOCK 
  864. --================================= 
  865. Gmb_poker_input_blocked = 0 
  866. function gmb_poker_input_block(block) 
  867. 	if block == true then 
  868. 		Gmb_poker_input_blocked = Gmb_poker_input_blocked + 1 
  869. 	else 
  870. 		Gmb_poker_input_blocked = Gmb_poker_input_blocked - 1 
  871. 	end 
  872. end 
  873.  
  874. function gmb_poker_input_is_bocked() 
  875. 	if Gmb_poker_input_blocked > 0 then 
  876. 		return true 
  877. 	else 
  878. 		return false 
  879. 	end 
  880. end 
  881.  
  882.  
  883.  
  884. --================================= 
  885. --ALIGN BUTTONS 
  886. --================================= 
  887. function gmb_poker_btntips_align() 
  888. 	local btn_spacing = 1 
  889. 	local grp_spacing = 30 
  890. 	local h = vint_object_find("btn_tips") 
  891. 	local btn_b_h = vint_object_find("btn_b", h) 
  892. 	local text_b_h = vint_object_find("b_text", h) 
  893. 	local a_text_h = vint_object_find("a_text", h) 
  894. 	local a_text_width, a_text_height = element_get_actual_size(a_text_h) 
  895. 	local btn_b_width, btn_b_height = element_get_actual_size(btn_b_h) 
  896. 	local a_text_x, a_text_y = vint_get_property(a_text_h, "anchor") 
  897. 	 
  898. 	--B Btn  
  899. 	local x = a_text_x + a_text_width + grp_spacing 
  900. 	local y = a_text_y 
  901. 	vint_set_property(btn_b_h, "anchor", x, y) 
  902. 	 
  903. 	--B Text 
  904. 	local x = x + btn_b_width/2 + btn_spacing 
  905. 	vint_set_property(text_b_h, "anchor", x, y) 
  906. end 
  907.