// End playing defense cards private void EndDefend() { // update the server Debug.Log("defend JSON"); Debug.Log(JsonUtility.ToJson(defendRequest)); RESTTemplate.AsyncPOST(SERVER_NAME + DEFEND_REQUEST, JsonUtility.ToJson(defendRequest)); // play attack animation new AttackCommand(opponentArea, playerArea, gameView.attackView.user, gameView.attackView.targets[0]).AddToQueue(); opponentArea.monsterVisual.turnOffAllHighlights(); // reset defend request defendRequest.cardAndTargets = new List <DefendTarget>(); }
// Game flow including start, syncing visuals, and finish public IEnumerator GameFlow() { // Start the match CoroutineWithData cd1 = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + START_REQUEST, JsonUtility.ToJson(playersRequest))); yield return(cd1.coroutine); // Start syncing the match while (true) { CoroutineWithData cd2 = new CoroutineWithData(this, GameSync()); yield return(cd2.coroutine); } // Finish the match? }
// Highlight all playable cards in hand public IEnumerator HighlightPlayableCards() { CoroutineWithData cd = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + PLAYABLE_REQUEST, JsonUtility.ToJson(playableRequest))); yield return(cd.coroutine); string resultBody = (string)cd.result; Debug.Log(resultBody); playableCardView = JsonUtility.FromJson <PlayableCardView>(resultBody); foreach (PlayableCard playableCard in playableCardView.playableCards) { new HighlightCommand(playerArea, playableCard.cardIndex, false).AddToQueue(); } }
// Attack public void MakeAttack() { // disable button playerArea.button.GetComponent <Button>().interactable = false; // update the server Debug.Log(JsonUtility.ToJson(attackRequest)); RESTTemplate.AsyncPOST(SERVER_NAME + ATTACK_REQUEST, JsonUtility.ToJson(attackRequest)); // draw targeting arrow foreach (int targetIndex in attackRequest.targets) { new DrawArrowCommand(playerArea, opponentArea, attackRequest.user, targetIndex).AddToQueue(); } // reset played cards playableRequest.playedCardIndexes = new List <int>(); }
// Sync game view with the server public IEnumerator GameSync() { // Get the new game view CoroutineWithData cd = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + SYNC_REQUEST, JsonUtility.ToJson(playersRequest))); yield return(cd.coroutine); string resultBody = (string)cd.result; GameView newGameView = JsonUtility.FromJson <GameView>(resultBody); // play monsters PlayMonsters(opponentArea, ref gameView.opponent.monsters, newGameView.opponent.monsters); PlayMonsters(playerArea, ref gameView.player.monsters, newGameView.player.monsters); // adjust guts SyncGuts(opponentArea, ref gameView.opponent.gutsPool, newGameView.opponent.gutsPool); SyncGuts(playerArea, ref gameView.player.gutsPool, newGameView.player.gutsPool); // draw SyncHand(opponentArea, ref gameView.opponent.hand, newGameView.opponent.hand, false); SyncHand(playerArea, ref gameView.player.hand, newGameView.player.hand, true); // adjust deck size SyncDeck(opponentArea, ref gameView.opponent.deckSize, newGameView.opponent.deckSize); SyncDeck(playerArea, ref gameView.player.deckSize, newGameView.player.deckSize); // play opponent attack request or defend request SyncTable(opponentArea, playerArea, ref gameView.attackView, newGameView.attackView, ref gameView.defendView, newGameView.defendView, ref gameView, newGameView); // sync monster state SyncMonsters(opponentArea, ref gameView.opponent.monsters, newGameView.opponent.monsters); SyncMonsters(playerArea, ref gameView.player.monsters, newGameView.player.monsters); // show game phase SyncPlayerAndPhase(playerArea, ref gameView.currentPlayer, newGameView.currentPlayer, ref gameView.phase, newGameView.phase); yield return(new WaitForSeconds(1)); }
// End playing attack cards private void EndAttack() { // update server Debug.Log(JsonUtility.ToJson(playersRequest)); RESTTemplate.AsyncPOST(SERVER_NAME + END_ATTACK_REQUEST, JsonUtility.ToJson(playersRequest)); }
// Convert played cards to guts private void MakeGuts() { // update the server gutsRequest.discards = playableRequest.playedCardIndexes; RESTTemplate.AsyncPOST(SERVER_NAME + GUTS_REQUEST, JsonUtility.ToJson(gutsRequest)); }