Advertisement
Slowhand-VI

TUT: blackjack_dialogues.fos

Jan 19th, 2016
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**<
  2.  *  Dialogue calls for the Blackjack module.
  3.  */
  4.  
  5.  
  6. #include "blackjack_h.fos"
  7. //#include "blackjack.fos"
  8. #include "blackjack_manager.fos"
  9.  
  10. /**< Init */
  11.  
  12. void r_Init(Critter& player, Critter@ dealer)
  13. {
  14.     blackjackManager.RemovePlayerGame(player.Id);
  15.     if (valid(dealer))
  16.     {
  17.         blackjackManager.CreateNewGame(player.Id, dealer.Id, Random(BLACKJACK_MIN_DECKS_IN_SHOE, BLACKJACK_MAX_DECKS_IN_SHOE));  //  For different casinos to use different deck size in shoe, replace default decks in shoe.
  18.     }
  19.     else
  20.     {
  21.         Log("Invalid dealer. ");
  22.     }
  23. }
  24.  
  25. /**< Leave Blackjack table */
  26. void r_LeaveBlackjackTable(Critter& player, Critter@ dealer)
  27. {
  28.     blackjackManager.RemovePlayerGame(player.Id);
  29. }
  30.  
  31. /**< Side bet related. */
  32.  
  33. void r_SetSidebetType(Critter& player, Critter@ dealer, int sidebetType)
  34. {
  35.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  36.     if (valid(bj))
  37.     {
  38.         bj.SetSidebetType(sidebetType);
  39.     }
  40.     else
  41.     {
  42.         Log("Blackjack module failed: Can't find player's game.");
  43.     }
  44. }
  45.  
  46. void r_SetSidebetValue(Critter& player, Critter@ dealer, int sidebetValue)
  47. {
  48.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  49.     if (valid(bj))
  50.     {
  51.         bj.SetSidebetValue(sidebetValue);
  52.     }
  53.     else
  54.     {
  55.         Log("Blackjack module failed: Can't find player's game.");
  56.     }
  57. }
  58.  
  59. bool d_IsSidebetAvailable(Critter& player, Critter@ dealer)
  60. {
  61.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  62.     if (valid(bj))
  63.     {
  64.         return bj.IsSidebetAvailable();
  65.     }
  66.     else
  67.     {
  68.         Log("Blackjack module failed: Can't find player's game.");
  69.     }
  70.     return false;
  71. }
  72.  
  73. /**< Bet related. */
  74.  
  75. void r_SetBetValue(Critter& player, Critter@ dealer, int value)
  76. {
  77.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  78.     if (valid(bj))
  79.     {
  80.         bj.SetBetValue(value);
  81.     }
  82.     else
  83.     {
  84.         Log("Blackjack module failed: Can't find player's game.");
  85.     }
  86. }
  87.  
  88. /**< First action related. */
  89.  
  90. bool d_IsHitAvailable(Critter& player, Critter@ dealer)
  91. {
  92.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  93.     if (valid(bj))
  94.     {
  95.         return bj.IsHitAvailable();
  96.     }
  97.     else
  98.     {
  99.         Log("Blackjack module failed: Can't find player's game.");
  100.     }
  101.     return false;
  102. }
  103.  
  104. void r_Hit(Critter& player, Critter@ dealer)
  105. {
  106.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  107.     if (valid(bj))
  108.     {
  109.         bj.Hit();
  110.     }
  111.     else
  112.     {
  113.         Log("Blackjack module failed: Can't find player's game.");
  114.     }
  115. }
  116.  
  117. bool d_IsStandAvailable(Critter& player, Critter@ dealer)
  118. {
  119.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  120.     if (valid(bj))
  121.     {
  122.         return bj.IsStandAvailable();
  123.     }
  124.     else
  125.     {
  126.         Log("Blackjack module failed: Can't find player's game.");
  127.     }
  128.     return false;
  129. }
  130.  
  131. void r_Stand(Critter& player, Critter@ dealer)
  132. {
  133.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  134.     if (valid(bj))
  135.     {
  136.         bj.Stand();
  137.     }
  138.     else
  139.     {
  140.         Log("Blackjack module failed: Can't find player's game.");
  141.     }
  142. }
  143.  
  144. bool d_IsPlayerBusted(Critter& player, Critter@ dealer)
  145. {
  146.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  147.     if (valid(bj))
  148.     {
  149.         return bj.IsPlayerBust();
  150.     }
  151.     else
  152.     {
  153.         Log("Blackjack module failed: Can't find player's game.");
  154.     }
  155.     return false;
  156. }
  157.  
  158. bool d_IsDoubleDownContinueAvailable(Critter& player, Critter@ dealer)
  159. {
  160.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  161.     if (valid(bj))
  162.     {
  163.         return !bj.IsPlayerBust();
  164.     }
  165.     else
  166.     {
  167.         Log("Blackjack module failed: Can't find player's game.");
  168.     }
  169.     return false;
  170. }
  171.  
  172. bool d_IsDoubleDownAvailable(Critter& player, Critter@ dealer)
  173. {
  174.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  175.     if (valid(bj))
  176.     {
  177.         return bj.IsDoubleDownAvailable();
  178.     }
  179.     else
  180.     {
  181.         Log("Blackjack module failed: Can't find player's game.");
  182.     }
  183.     return false;
  184. }
  185.  
  186. void r_DoubleDown(Critter& player, Critter@ dealer)
  187. {
  188.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  189.     if (valid(bj))
  190.     {
  191.         bj.DoubleDown();
  192.     }
  193.     else
  194.     {
  195.         Log("Blackjack module failed: Can't find player's game.");
  196.     }
  197. }
  198.  
  199. bool d_IsSplitPairsAvailable(Critter& player, Critter@ dealer)
  200. {
  201.     return false;
  202. }
  203.  
  204. bool d_IsInsuranceAvailable(Critter& player, Critter@ dealer)
  205. {
  206.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  207.     if (valid(bj))
  208.     {
  209.         return bj.IsInsuranceAvailable();
  210.     }
  211.     else
  212.     {
  213.         Log("Blackjack module failed: Can't find player's game.");
  214.     }
  215.     return false;
  216. }
  217.  
  218. void r_Insurance(Critter& player, Critter@ dealer)
  219. {
  220.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  221.     if (valid(bj))
  222.     {
  223.         bj.Insurance();
  224.     }
  225.     else
  226.     {
  227.         Log("Blackjack module failed: Can't find player's game.");
  228.     }
  229. }
  230.  
  231. bool d_IsEvenMoneyAvailable(Critter& player, Critter@ dealer)
  232. {
  233.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  234.     if (valid(bj))
  235.     {
  236.         return bj.IsEvenMoneyAvailable();
  237.     }
  238.     else
  239.     {
  240.         Log("Blackjack module failed: Can't find player's game.");
  241.     }
  242.     return false;
  243. }
  244.  
  245. bool d_IsSurrenderAvailable(Critter& player, Critter@ dealer)
  246. {
  247.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  248.     if (valid(bj))
  249.     {
  250.         return bj.IsSurrenderAvailable();
  251.     }
  252.     else
  253.     {
  254.         Log("Blackjack module failed: Can't find player's game.");
  255.     }
  256.     return false;
  257. }
  258.  
  259. void r_Surrender(Critter& player, Critter@ dealer)
  260. {
  261.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  262.     if (valid(bj))
  263.     {
  264.         bj.Surrender();
  265.     }
  266.     else
  267.     {
  268.         Log("Blackjack module failed: Can't find player's game.");
  269.     }
  270. }
  271.  
  272. void r_NewRound(Critter& player, Critter@ dealer)
  273. {
  274.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  275.     if (valid(bj))
  276.     {
  277.         bj.ResetVariables();
  278.     }
  279.     else
  280.     {
  281.         Log("Blackjack module failed: Can't find player's game.");
  282.     }
  283. }
  284.  
  285. void r_EvenMoney(Critter& player, Critter@ dealer)
  286. {
  287.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  288.     if (valid(bj))
  289.     {
  290.         bj.EvenMoney();
  291.     }
  292.     else
  293.     {
  294.         Log("Blackjack module failed: Can't find player's game.");
  295.     }
  296. }
  297.  
  298. void r_DealerTakesCard(Critter& player, Critter@ dealer)
  299. {
  300.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  301.     if (valid(bj))
  302.     {
  303.         bj.DealerTakesCard();
  304.     }
  305.     else
  306.     {
  307.         Log("Blackjack module failed: Can't find player's game.");
  308.     }
  309. }
  310.  
  311. bool d_IsDealerDone(Critter& player, Critter@ dealer)
  312. {
  313.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  314.     if (valid(bj))
  315.     {
  316.         return bj.IsDealerDone();
  317.     }
  318.     else
  319.     {
  320.         Log("Blackjack module failed: Can't find player's game.");
  321.     }
  322.     return false;
  323. }
  324.  
  325. bool d_IsDealerNotDone(Critter& player, Critter@ dealer)
  326. {
  327.         CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  328.     if (valid(bj))
  329.     {
  330.         return !bj.IsDealerDone();
  331.     }
  332.     else
  333.     {
  334.         Log("Blackjack module failed: Can't find player's game.");
  335.     }
  336.     return false;
  337. }
  338.  
  339. void r_DealerFinishedTurn(Critter& player, Critter@ dealer)
  340. {
  341.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  342.     if (valid(bj))
  343.     {
  344.         bj.DealerFinishedTurn();
  345.     }
  346.     else
  347.     {
  348.         Log("Blackjack module failed: Can't find player's game.");
  349.     }
  350. }
  351.  
  352. void dlg_ShowInfo(Critter& player, Critter@ npc, string@ text)
  353. {
  354.     CBlackjack@ bj = blackjackManager.GetPlayerGame(player.Id);
  355.     if (valid(bj))
  356.     {
  357.         if(!IS_DIALOG_GENERATED(text))
  358.             return;
  359.  
  360.         text += "$lastAction" + bj.GetLastAction();
  361.         text += "$playerHand" + bj.GetPlayerHand();
  362.         text += "$dealerHand" + bj.GetDealerHand();
  363.         text += "$sidebetType" + bj.GetSidebetType();
  364.         text += "$result" + bj.GetResult();
  365.         text += "$sidebetResult" + bj.GetSidebetResult();
  366.     }
  367.     else
  368.     {
  369.         //  Shall not log error here, because this function get's called after client clicked exit, this error always happens.
  370.         //  Log("Blackjack module failed at dlg_ShowInfo: Can't find player's game.");
  371.  
  372.     }
  373. }
Advertisement
RAW Paste Data Copied
Advertisement