// Client-called function to play a card from the player's hand public void PlayCardFromHand(int player, int cardID) { if (m_turnState == CGTurnState.WAIT_FOR_PLAY_CARD_FROM_HAND && m_activePlayerID == player) { if (m_activePlayer.CanPlayCard(cardID)) { // Play the card from hand, adding any "OnPlay" effects to the stack m_activePlayer.PlayCardFromHand(cardID); // Add any "PlayCard" triggered effects to the stack TriggerEvent("PlayCard"); ResolveStack(); // Return to game logic once a card has been played m_turnState = CGTurnState.CARD_PLAYED_FROM_HAND; RunGameLogic(); return; } // Tell client to highlight playable cards and keep waiting for a valid card List <int> playableCardIDs = m_activePlayer.m_hand.GetPlayableCardIDs(); CGC_WaitForPlayFromHand command = new CGC_WaitForPlayFromHand(playableCardIDs, m_activePlayerID); m_connection.TransmitStream(command.PackCommand(), m_activePlayerID); } }
/**************** * Flow Control * ****************/ // TODO: This gets called from all over the place and is confusing and not nice... public bool RunGameLogic() { if (m_turnState == CGTurnState.WAITING_FOR_PLAYER_DECKS) { // CGC_RequestDeck command = new CGC_RequestDeck(); // m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0); // m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1); // return true; m_turnState = CGTurnState.DEFAULT; } if (!m_gameInProgress) { StartGame(); } while (m_gameInProgress) { if (m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase0(); // Beginning m_turnState = Phase1(); // Channel m_turnState = Phase2(); // Draw m_turnState = Phase3(); // Play if (m_turnState == CGTurnState.WAIT_FOR_PLAY_CARD_FROM_HAND) { Debug.Log("Waiting for action from players..."); return(true); // Wait for the player to play a card from their hand } } if (m_turnState == CGTurnState.CARD_PLAYED_FROM_HAND || m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase4(); // Cast if (m_turnState == CGTurnState.WAIT_FOR_CAST_ORDER) { //if (m_activePlayer == m_players[1]) //{ // Tell AI to play all their spells // m_turnState = TellAIToCastAllSpells(); //} //else { Debug.Log("Waiting for action from players..."); return(true); // Wait for the player to cast a spell from channel 0 } } } if (m_turnState == CGTurnState.ALL_SPELLS_CAST || m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase5(); } } return(true); }
public void CastSpellFromChannel0(int spellCardID, int targetCardID) { // Ideally this would only listen to requests from the active player if (m_turnState == CGTurnState.WAIT_FOR_CAST_ORDER) { CGCardObject spell = m_activePlayer.GetSpell(spellCardID); if (spell == null) { Debug.LogError("Requested spell not found!"); m_turnState = TellClientToCastSpell(); return; } if (!spell.m_data.hasTargets) { // Cast spell with no targets CastSpell(spell); } else if (!SpellHasValidTargets(spell)) { // Spell with no valid targets fizzles FizzleSpell(spell); } else if (IsTargetValid(spell, targetCardID)) { // Cast spell with target CGCardObject target = FindCard(targetCardID); if (target != null) { spell.SetTarget(target); } CastSpell(spell); } else { Debug.LogError("Requested spell not given valid target when at least one exists"); m_turnState = TellClientToCastSpell(); return; } // Spell has been cast, continue gameplay if (m_activePlayerID == 0) // @TODO: Update this for multiplayer { m_turnState = TellClientToCastSpell(); if (m_turnState == CGTurnState.ALL_SPELLS_CAST) { RunGameLogic(); } } } }
public void AssignDeck(PackedDeck deck, int playerID) { m_players[playerID].AssignDeck(deck); if (m_players[0].m_hasDeck && m_players[1].m_hasDeck) { // Both players have decks - start the game! if (m_turnState == CGTurnState.WAITING_FOR_PLAYER_DECKS) { m_turnState = CGTurnState.DEFAULT; RunGameLogic(); } } }
// Client-called function to skip playing a card from the player's hand public void SkipCardFromHand(int player) { if (m_activePlayerID == player && m_turnState == CGTurnState.WAIT_FOR_PLAY_CARD_FROM_HAND) { TriggerEvent("SkipCard"); ResolveStack(); m_turnState = CGTurnState.CARD_PLAYED_FROM_HAND; RunGameLogic(); return; } }
public void PlayCardForAI() { if (m_turnState == CGTurnState.WAIT_FOR_PLAY_CARD_FROM_HAND && m_activePlayerID != 0) { // Play the card from hand, adding any "OnPlay" effects to the stack m_activePlayer.PlayRandomCardFromHand(); // Add any "PlayCard" triggered effects to the stack TriggerEvent("PlayCard"); ResolveStack(); // Return to game logic once a card has been played m_turnState = CGTurnState.CARD_PLAYED_FROM_HAND; RunGameLogic(); return; } }
/**************** * Flow Control * ****************/ void RunGameLogic() { while (m_gameInProgress) { if (m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase0(); // Beginning m_turnState = Phase1(); // Channel m_turnState = Phase2(); // Draw m_turnState = Phase3(); // Play if (m_turnState == CGTurnState.WAIT_FOR_PLAY_CARD_FROM_HAND) { return; // Wait for the player to play a card from their hand } } if (m_turnState == CGTurnState.CARD_PLAYED_FROM_HAND || m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase4(); // Cast if (m_turnState == CGTurnState.WAIT_FOR_CAST_ORDER) { if (m_activePlayer == m_players[1]) { // Tell AI to play all their spells m_turnState = TellAIToCastAllSpells(); } else { return; // Wait for the player to cast a spell from channel 0 } } } if (m_turnState == CGTurnState.ALL_SPELLS_CAST || m_turnState == CGTurnState.DEFAULT) { m_turnState = Phase5(); } } }