server_src_client-server-shared_gameStates_1-selectDraftState.js.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Source: server/src/client-server-shared/gameStates/1-selectDraftState.js | 12 Heroes</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
  12. <link type="text/css" rel="stylesheet" href="styles/prettify-jsdoc.css">
  13. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  14. <link type="text/css" rel="stylesheet" href="styles/tui-doc.css">
  15. </head>
  16. <body>
  17. <nav class="lnb" id="lnb">
  18. <div class="logo" style="">
  19. <img src="img/toast-ui.png" width="100%" height="100%">
  20. </div>
  21. <div class="title">
  22. <h1><a href="index.html" class="link">12 Heroes</a></h1>
  23. </div>
  24. <div class="search-container" id="search-container">
  25. <input type="text" placeholder="Search">
  26. <ul></ul>
  27. </div>
  28. <div class="lnb-api hidden"><h3>Namespaces</h3><ul><li><a href="Constants.html">Constants</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants_sub"></div></li><li><a href="Constants.HERO.html">Constants.HERO</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.HERO_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.HERO.html#.HERO_ABILITY">HERO_ABILITY</a></li><li><a href="Constants.HERO.html#.HERO_DEPLOY">HERO_DEPLOY</a></li><li><a href="Constants.HERO.html#.HERO_DISCARD">HERO_DISCARD</a></li><li><a href="Constants.HERO.html#.HERO_DISMISS">HERO_DISMISS</a></li><li><a href="Constants.HERO.html#.HERO_MOVE">HERO_MOVE</a></li><li><a href="Constants.HERO.html#.HERO_RECRUIT">HERO_RECRUIT</a></li><li><a href="Constants.HERO.html#.HERO_REPLACE">HERO_REPLACE</a></li></ul></div></li><li><a href="Constants.PLAYER.html">Constants.PLAYER</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.PLAYER_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.PLAYER.html#.PLAYER_PASS">PLAYER_PASS</a></li><li><a href="Constants.PLAYER.html#.PLAYER_SUPPLY">PLAYER_SUPPLY</a></li></ul></div></li><li><a href="Constants.POS.html">Constants.POS</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.POS_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.POS.html#.POS_BATTLE_CENTER">POS_BATTLE_CENTER</a></li><li><a href="Constants.POS.html#.POS_BATTLE_LEFT">POS_BATTLE_LEFT</a></li><li><a href="Constants.POS.html#.POS_BATTLE_RIGHT">POS_BATTLE_RIGHT</a></li><li><a href="Constants.POS.html#.POS_CAMP">POS_CAMP</a></li><li><a href="Constants.POS.html#.POS_DISCARD">POS_DISCARD</a></li><li><a href="Constants.POS.html#.POS_HAND">POS_HAND</a></li><li><a href="Constants.POS.html#.POS_PILE">POS_PILE</a></li></ul></div></li><li><a href="Constants.REQ.html">Constants.REQ</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.REQ_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.REQ.html#.REQ_ERROR">REQ_ERROR</a></li><li><a href="Constants.REQ.html#.REQ_IDLE">REQ_IDLE</a></li><li><a href="Constants.REQ.html#.REQ_REQUESTED">REQ_REQUESTED</a></li><li><a href="Constants.REQ.html#.REQ_SUCCESS">REQ_SUCCESS</a></li></ul></div></li></ul></div><div class="lnb-api hidden"><h3>Global</h3><ul><li><a href="global.html#getDraftSets">getDraftSets</a></li><li><a href="global.html#getHeroesIdsByFaction">getHeroesIdsByFaction</a></li><li><a href="global.html#shuffleHeroes">shuffleHeroes</a></li><li><a href="global.html#TH_Ability">TH_Ability</a></li><li><a href="global.html#TH_AbilityHook">TH_AbilityHook</a></li><li><a href="global.html#TH_AdvRule">TH_AdvRule</a></li><li><a href="global.html#TH_BattleTile">TH_BattleTile</a></li><li><a href="global.html#TH_Color">TH_Color</a></li><li><a href="global.html#TH_CommStatus">TH_CommStatus</a></li><li><a href="global.html#TH_DeckMode">TH_DeckMode</a></li><li><a href="global.html#TH_Faction">TH_Faction</a></li><li><a href="global.html#TH_GameDataStore">TH_GameDataStore</a></li><li><a href="global.html#TH_GameGlobalState">TH_GameGlobalState</a></li><li><a href="global.html#TH_GameStateEnum">TH_GameStateEnum</a></li><li><a href="global.html#TH_HeroAction">TH_HeroAction</a></li><li><a href="global.html#TH_HeroCard">TH_HeroCard</a></li><li><a href="global.html#TH_HeroInGame">TH_HeroInGame</a></li><li><a href="global.html#TH_HeroPosition">TH_HeroPosition</a></li><li><a href="global.html#TH_MessageChatFrom">TH_MessageChatFrom</a></li><li><a href="global.html#TH_MessageDraftStep">TH_MessageDraftStep</a></li><li><a href="global.html#TH_MessageFaction">TH_MessageFaction</a></li><li><a href="global.html#TH_MessageTournamentDeckStep">TH_MessageTournamentDeckStep</a></li><li><a href="global.html#TH_PlayerAction">TH_PlayerAction</a></li><li><a href="global.html#TH_PlayerGameState">TH_PlayerGameState</a></li><li><a href="global.html#TH_Popularity">TH_Popularity</a></li><li><a href="global.html#TH_ReqStatus">TH_ReqStatus</a></li></ul></div>
  29. </nav>
  30. <div id="resizer"></div>
  31. <div class="main" id="main">
  32. <section>
  33. <article>
  34. <pre class="prettyprint source linenums"><code>'use strict';
  35. import { shuffleHeroes, getDraftSets } from '../heroesHelper';
  36. export default function selectDraftState(duelController) {
  37. let duelCtrl = duelController;
  38. let draftSets = [];
  39. // For draft there are two turns, we are at 0
  40. let draftTurn = 0;
  41. //Blue will get first 6 cards, and red following 6
  42. let blueDraftSetnb = 0;
  43. let redDraftSetnb = 1;
  44. let start = () => {
  45. /** @type {import('type/game').TH_GameDataStore} */
  46. let gameData = duelCtrl.getGameData();
  47. draftSets = getDraftSets(
  48. gameData.game.allHeroes,
  49. gameData.game.advRules.includes('popularity')
  50. );
  51. draftTurn = 1;
  52. gameData.bluePlayer.draftHeroesIds =
  53. draftSets[draftTurn - 1][blueDraftSetnb];
  54. gameData.redPlayer.draftHeroesIds = draftSets[draftTurn - 1][redDraftSetnb];
  55. gameData.game['waitingFor/blue'] = true;
  56. gameData.game['waitingFor/red'] = true;
  57. gameData.game.currentPlayer = 'both';
  58. duelCtrl.storeData(gameData);
  59. };
  60. let update = (
  61. /** @type {import('type/comm').TH_MessageDraftStep} */ payload = null
  62. ) => {
  63. /** @type {import('type/game').TH_GameDataStore} */
  64. let gameData = duelCtrl.getGameData();
  65. if (payload) {
  66. let player = payload.color + 'Player';
  67. gameData[player].twelveHeroes = payload.twelveHeroes;
  68. gameData[player].draftHeroesIds = payload.draftHeroesIds;
  69. gameData.game['waitingFor/' + payload.color] = false;
  70. duelCtrl.storeData(gameData);
  71. }
  72. // We finished waiting for both players to select 2 cards
  73. if (
  74. gameData.game['waitingFor/blue'] === false &amp;&amp;
  75. gameData.game['waitingFor/red'] === false
  76. ) {
  77. // Check if players completed their deck
  78. if (
  79. gameData.bluePlayer.twelveHeroes.length == 12 &amp;&amp;
  80. gameData.redPlayer.twelveHeroes.length == 12
  81. ) {
  82. shuffleHeroes(gameData.bluePlayer.twelveHeroes);
  83. shuffleHeroes(gameData.redPlayer.twelveHeroes);
  84. // End of state, decks are complete
  85. duelCtrl.endCurrentState();
  86. } else {
  87. // Check if set of 6 cards is done
  88. if (gameData.redPlayer.draftHeroesIds.length === 0) {
  89. // Deal next 6 cards
  90. draftTurn++;
  91. gameData.bluePlayer.draftHeroesIds =
  92. draftSets[draftTurn - 1][blueDraftSetnb];
  93. gameData.redPlayer.draftHeroesIds =
  94. draftSets[draftTurn - 1][redDraftSetnb];
  95. } else {
  96. // swap cards
  97. let temp = gameData.bluePlayer.draftHeroesIds;
  98. gameData.bluePlayer.draftHeroesIds =
  99. gameData.redPlayer.draftHeroesIds;
  100. gameData.redPlayer.draftHeroesIds = temp;
  101. }
  102. // Wait again for players to chose 2 more cards
  103. gameData.game['waitingFor/blue'] = true;
  104. gameData.game['waitingFor/red'] = true;
  105. duelCtrl.storeData(gameData);
  106. }
  107. }
  108. };
  109. let end = () => {
  110. console.log('Go to next game state : 2_CHANGE_UP_TO_3_CARDS');
  111. duelCtrl.setCurrentState('2_CHANGE_UP_TO_3_CARDS');
  112. duelCtrl.startCurrentState();
  113. };
  114. return {
  115. start,
  116. update,
  117. end
  118. };
  119. }
  120. </code></pre>
  121. </article>
  122. </section>
  123. </div>
  124. <footer>
  125. <img class="logo" src="img/toast-ui.png" style="">
  126. <div class="footer-text">NHN Entertainment. Frontend Development Lab</div>
  127. </footer>
  128. <script>prettyPrint();</script>
  129. <script src="scripts/jquery.min.js"></script>
  130. <script src="scripts/tui-doc.js"></script>
  131. <script src="scripts/linenumber.js"></script>
  132. <script>
  133. var id = '_sub'.replace(/"/g, '_');
  134. var selectedApi = document.getElementById(id); // do not use jquery selector
  135. var $selectedApi = $(selectedApi);
  136. $selectedApi.removeClass('hidden');
  137. $selectedApi.parent().find('.glyphicon').removeClass('glyphicon-plus').addClass('glyphicon-minus');
  138. showLnbApi();
  139. </script>
  140. </body>
  141. </html>