// Functions public void DrawCards(int numCards) { Debug.Log("Drawing " + numCards + " cards"); for (int i = 0; i < numCards; i++) { CGCardObject card = m_deck.GetTopCard(); if (card == null) { // This player loses the game return; } m_hand.MoveCardToHere(card); // Create the 'card draw' client command if (m_ID == 0) { CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID); CGVisualManager.instance.AddCommand(command); } else { CGC_OpponentDrawCard command = new CGC_OpponentDrawCard(); CGVisualManager.instance.AddCommand(command); } } }
public void PlayRandomCardFromHand() { CGCardObject card = m_hand.GetRandomPlayableCard(); if (card != null) { card.PlayFromHand(this); if (m_ID == 0) { CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); CGVisualManager.instance.AddCommand(command); } else { CGC_OpponentPlayCardFromHand command = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); CGVisualManager.instance.AddCommand(command); } Debug.Log("Played card: " + card.m_cardName); // Add any "OnPlay" effect to the stack m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_PLAY)); } }
public void SetScriptData(CardData data, CardGameManager cgManager, CGCardObject card) { m_data = data; m_cgManager = cgManager; m_card = card; m_attributes = m_data.cardAttributes; }
/** Create a spell from the card in the player's hand, adding any "OnPlay" effect to the stack */ public void PlayCardFromHand(int cardID) { // Create a spell from the chosen card CGCardObject card = m_hand.GetCardWithID(cardID); if (card != null) { card.PlayFromHand(this); if (m_ID == 0) { CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0); CGC_OpponentPlayCardFromHand oppCommand = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 1); } else { CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1); CGC_OpponentPlayCardFromHand oppCommand = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining()); m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 0); } Debug.Log("Played card: " + card.m_cardName); // Add any "OnPlay" effect to the stack m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_PLAY)); } }
void FizzleSpell(CGCardObject spell) { // CGC_FizzleSpell(spell.m_cardID); m_spellsCastThisTurn++; spell.Remove(); ResolveStack(); }
/************************ ** DEFAULT BEHAVIOURS ** ************************/ /** Called when playing the card from hand to put the spell into play */ public void PlayFromHand(CGCardObject card, CGPlayerLogic player) { m_owner = player; card.SetTimeRemaining(m_data.channelCost); player.m_spells.MoveCardToHere(card); m_cgManager.AddEffectToStack(OnPlay); }
protected bool IsCardASpell(CGCardObject card) { if (card.m_isSpell) { return(true); } return(false); }
void CastSpell(CGCardObject spell) { spell.Cast(); m_spellsCastThisTurn++; ResolveStack(); spell.Remove(); ResolveStack(); }
public void Populate(CardData[] cards) { foreach (CardData data in cards) { CGCardObject card = new CGCardObject(data, m_cgManager, m_player); MoveCardToHere(card); } Shuffle(); }
public CGCardObject GetTopCard() { if (m_cards.Count > 0) { CGCardObject card = m_cards[0]; return(card); } return(null); }
public CGSpellObject(CGCardObject card, int playerID) { m_turnsRemaining = card.m_channelCost; m_card = card; m_playerID = playerID; m_spellID = m_allSpellIDs.Count; m_allSpellIDs.Add(m_spellID); }
public bool CanPlayCard(int cardID) { CGCardObject card = m_hand.GetCardWithID(cardID); if (card != null) { //if (CardGameManager.IsCardPlayable(card) return(true); } return(false); }
public override bool CheckValidTarget(CGCardObject thisCard, CGCardObject target) { if (IsCardASpell(target)) { if (target.m_controller != thisCard.m_controller) { return(true); } } return(false); }
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(); } } } }
protected override void OnCardEnter(CGCardObject card) { if (card.m_isSpell) { m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_REMOVE)); m_cgManager.TriggerEvent("SpellRemoved"); CGC_MoveCardToGraveyard command = new CGC_MoveCardToGraveyard(card.m_owner.m_ID, card.m_cardID); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1); } card.SetIsSpell(false); }
public void MoveCardToHere(CGCardObject card) { if (card.m_currentZone != null) { // Remove the card from its last zone's list card.m_currentZone.MoveCardFromZone(card); card.m_currentZone.OnCardExit(card); } card.m_currentZone = this; // Add the card to this zone's list m_cards.Add(card); OnCardEnter(card); return; }
public CGCardObject RemoveCardWithID(int cardID) { int i = 0; foreach (CGCardObject card in m_cards) { if (card.m_cardID == cardID) { break; } i++; } CGCardObject removedCard = m_cards[i]; m_cards.RemoveAt(i); return(removedCard); }
/************* * Targeting * *************/ List <int> GetAllValidTargetsForSpell(CGCardObject spell) { List <int> targetIDs = new List <int>(); // Check every card in every zone for targets int controllerID = spell.m_controller.m_ID; int opponentID = (controllerID + 1) % 2; // Controller's hand foreach (CGCardObject target in m_players[controllerID].m_hand.m_cards) { if (target != spell && spell.m_script.CheckValidTarget(spell, target)) { targetIDs.Add(target.m_cardID); } } // Controller's spells foreach (CGCardObject target in m_players[controllerID].m_spells.m_cards) { if (target != spell && spell.m_script.CheckValidTarget(spell, target)) { targetIDs.Add(target.m_cardID); } } // Opponent's spells foreach (CGCardObject target in m_players[opponentID].m_spells.m_cards) { if (target != spell && spell.m_script.CheckValidTarget(spell, target)) { targetIDs.Add(target.m_cardID); } } return(targetIDs); }
// Functions public void DrawCards(int numCards) { Debug.Log("Drawing " + numCards + " cards"); for (int i = 0; i < numCards; i++) { CGCardObject card = m_deck.GetTopCard(); if (card == null) { // This player loses the game return; } m_hand.MoveCardToHere(card); // Create the 'card draw' client command if (m_ID == 0) { // Tell player 0 what card they drew CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0); // Tell player 1 that player 0 drew a card CGC_OpponentDrawCard oppCommand = new CGC_OpponentDrawCard(); m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 1); } else { // Tell player 1 what card they drew CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID); m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1); // Tell player 0 that player 1 drew a card CGC_OpponentDrawCard oppCommand = new CGC_OpponentDrawCard(); m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 0); } } }
protected override void OnCardEnter(CGCardObject card) { card.SetIsSpell(true); }
public override bool CheckValidTarget(CGCardObject thisCard, CGCardObject target) { return(IsCardASpell(target)); }
public void SetTarget(CGCardObject target) { m_script.SetTarget(target); }
public void AddCard(CGCardObject card) { m_cards.Add(card); }
/** A check on a given card, returning true if it is a valid target */ public virtual bool CheckValidTarget(CGCardObject thisCard, CGCardObject target) { return(false); }
/** Called at the start of the "Channel phase" to decrease the time remaining on the spell */ public void ChannelSpell(CGCardObject card) { card.DecreaseTimeRemaining(1); m_cgManager.AddEffectToStack(OnChannel); }
/** Called when the spell is to be removed from the board */ public void RemoveSpell(CGCardObject card, CGPlayerLogic owner) { owner.m_graveyard.MoveCardToHere(card); }
public void CastSpell(CGCardObject card) { card.Cast(); }
protected virtual void OnCardExit(CGCardObject card) { }
protected virtual void OnCardEnter(CGCardObject card) { }
/** Called when a card moves from this zone to remove it from the cards list */ private void MoveCardFromZone(CGCardObject card) { m_cards.Remove(card); }