Beispiel #1
0
    // Used by ShiftRow to shift the Master Market Grid rows
    // TODO: update to use animations
    private void ShiftMasterMarketGrid(int row, int units)
    {
        int marketWidth = Mathf.CeilToInt((float)MatchController.MasterDeck.marketCardDeck.Count
                                          / (float)config.GameGridHeight);

        for (int x = 0; x < marketWidth; x++)
        {
            for (int y = row; y < config.GameGridHeight; y++)
            {
                if (masterMarketGrid[x, y] != null)
                {
                    float oldX = masterMarketGrid[x, y].CardObject.transform.position.x;
                    float oldY = masterMarketGrid[x, y].CardObject.transform.position.y;
                    // float oldZ = masterMarketGrid[x, y].tileObj.transform.position.z;

                    StartCoroutine(CardAnimations.MoveTileCoroutine(masterMarketGrid[x, y].CardObject,
                                                                    new Vector3(0, shiftUnit, 0), .1f));

                    // masterMarketGrid[x, y].CardObject.transform.position = new Vector3(oldX,
                    //  (oldY += (shiftUnit * units)),
                    //  masterMarketGrid[x, y].CardObject.transform.position.z);
                }
            }
        }
    }
Beispiel #2
0
    private void CreateNewCardObject(int index, string cardStr)
    {
        if (cardStr != null)
        {
            float xOff = index * 11 + (((config.GameGridWidth - config.PlayerHandSize) / 2f) * 11);
            float yOff = -10;

            Vector3 finalPosition = new Vector3(xOff, yOff, 40);

            // If old card exists, destroy it
            GameObject oldCardObj = GameObject.Find(CardUtility.CreateCardObjectName("GameCard",
                                                                                     this.id, index));

            if (oldCardObj != null)
            {
                Debug.Log(debugTag + "Trying to destroy " + oldCardObj.name);
                Destroy(oldCardObj);
            }

            // Create new card
            // NOTE: In the future when there is an actual deck model, have it originate from that.
            GameObject cardObj = (GameObject)Instantiate(matchController.gameCardPrefab,
                                                         new Vector3(0, -40, 40),
                                                         Quaternion.identity);

            cardObj.GetComponent <CardViewController>().Card = JsonUtility.FromJson <Card>(cardStr);
            cardObj.transform.SetParent(GameObject.Find("PlayerHand").transform);

            StartCoroutine(CardAnimations.MoveCardCoroutine(cardObj, finalPosition, 0.1f));

            cardObj.name = (CardUtility.CreateCardObjectName("GameCard", this.id, index));
        }
    }
Beispiel #3
0
    }     //Start()

    void Update()
    {
        if (!isLocalPlayer || !initialzed)
        {
            return;
        }

        if (this.turnEventStr != matchDataBroadcaster.TurnEventStr &&
            this.turnEventStr != null)
        {
            HandleTurnEvent();
            // this.turnEventStr = gameMan.turnEventBroadcast; // Unnecessary, this gets done later.
        }

        if (this.lastKnownPriceList != matchDataBroadcaster.PriceListStr)
        {
            Debug.Log(debugTag + "Updating prices...");
            UpdateLocalPrices();
            UpdateMarketFooters();
            // this.lastKnownPriceList = gameMan.priceListStr; // Unnecessary, this gets done later.
        }

        // Highlight cards during Buying Phase
        if (CheckForNewMatchData(1))
        {
            if (this.matchData.Turn == this.id)
            {
                if (this.matchData.Round > matchController.Config.GraceRounds)
                {
                    Debug.Log(debugTag + "Highlighting " + GetNeighbors().Count
                              + " when there's " + GetUnownedCards().Count
                              + " card(s) left");
                    CardAnimations.HighlightCards(GetNeighbors(), this.id);
                }
                else
                {
                    CardAnimations.HighlightCards(GetUnownedCards(), this.id);
                }
            }
            else
            {
                CardAnimations.HighlightCards(GetUnownedCards(), 0);
            }
        }

        if (matchData.Winner >= 0)
        {
            // Debug.Log("WINNER WINNER CHICKED DINNER! CONGRATS PLAYER " + matchData.Winner);
            this.hudController.DisplayWinner(matchData.Winner);
        }

        // This is at the bottom so handlers can compare old data with new data
        UpdateKnownInfo();
    }     // Update()
Beispiel #4
0
 void Awake()
 {
     cards = new List <Card>();
     if (anim == null)
     {
         anim = FindObjectOfType <CardAnimations>();
     }
     if (hand == null)
     {
         hand = FindObjectOfType <Hand>();
     }
 }
    // METHODS #####################################################################################
    #region METHODS

    // Start is called before the first frame update.
    void Start()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        this.hand.Callback += OnHandUpdated;
        // connection = connectionToClient;

        if (TryToGrabComponents())
        {
            if (!initIdFlag)
            {
                InitId();
            }

            // CmdSpawnMouseManager();

            CmdGetHand();
            // Debug.Log(debug + "Hand size: " + this.hand.Count);
            // gridMan.CreateHandObjects(this.id, this.hand);
            this.knownOwnersList = new List <Coordinate2> [GameManager.playerCount];
            this.knownOwnersGrid = new int[GameManager.width, GameManager.height];

            for (int i = 0; i < GameManager.playerCount; i++)
            {
                this.knownOwnersList[i] = new List <Coordinate2>();
            }

            UpdateKnownRounds();

            // If this is Player 1 and it's the first Turn of the first Round
            if (this.id == 1 && this.lastKnownTurn == 1 &&
                this.lastKnownRound == 1 &&
                this.lastKnownPhase == 1)
            {
                CardAnimations.HighlightCards(GetUnownedCards(), this.id);
            }
        }
        else
        {
            Debug.LogError(debug + "ERROR: Could not grab all components!");
        }
    }     //Start()
        protected override IEnumerator execute()
        {
            Command presentMove = null;

            if (this.overrideCurve != null)
            {
                IDictionary <DataComposition, VisibilityConfiguration> cards = SampleUtil.GetCards(MatchCardLayer.GameplayAnimation);
                presentMove = new PlayCardAnimation(CardAnimations.Get().GetMoveAnimation(MatchCardLayer.GameplayAnimation, cards, this.card.get_Composition(), this.overrideCurve));
            }
            else if (this.isPlayerOne)
            {
                presentMove = MoveAnimations.Find().GetAnim(this.card, MatchCurves.EndPoint.Player1Deck, MatchCurves.EndPoint.Player1PresentRight, MatchCardLayer.GameplayAnimation);
            }
            else
            {
                presentMove = MoveAnimations.Find().GetAnim(this.card, MatchCurves.EndPoint.Player2Deck, MatchCurves.EndPoint.PresentCenter, MatchCardLayer.GameplayAnimation);
            }
            if (this.message != null)
            {
                Finder.FindOrThrow <FailFeedbackUGUI>().Show(new LocalizedString(this.message, new object[0]));
            }
            this.presentArea.set_Card(this.card);
            RendererManager render = Finder.FindOrThrow <RendererManager>();

            render.Register(this);
            while (presentMove.MoveNext())
            {
                object obj = presentMove.Current;
                yield return(obj);
            }
            yield return(new WaitForSeconds(0.75f));

            ShowCardDeath deathFX = new ShowCardDeath(this.card.get_Composition(), (this.message != null) ? (Constants.rO() + "2") : Constants.rO(), this.commandToRun);

            while (deathFX.MoveNext())
            {
                object obj2 = deathFX.Current;
                yield return(obj2);
            }
            this.presentArea.set_Card(null);
            render.Unregister(this);
            yield break;
            yield break;
        }
    }     //Start()

    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        // On New Turn
        if (PhaseCheck(1))
        {
            Debug.Log(debug + "It must be Phase 1 (" + this.lastKnownPhase + " - " + gameMan.phase);
            ColorPurchasedTile();
            // If the new turn is the player's turn and is past the grace rounds
            //&& gameMan.turn > GameManager.graceRounds
            if (gameMan.turn == this.id)
            {
                if (gameMan.round > GameManager.graceRounds)
                {
                    CardAnimations.HighlightCards(GetNeighbors(), this.id);
                }
                else
                {
                    CardAnimations.HighlightCards(GetUnownedCards(), this.id);
                }
            }
            else
            {
                CardAnimations.HighlightCards(GetUnownedCards(), 0);
            }
        }
        else if (PhaseCheck(2) && gameMan.turnEventBroadcast != this.turnEventStr)
        {
            HandleEvent(phase: 2);

            // Phase 2 Operations go here
            // if (gameMan.turn == this.id)
            // {
            //  Debug.Log("HEYO");
            //  HandleEvent(phase: 2);
            // }
        }
        UpdateKnownRounds();
    }     // Update()
Beispiel #8
0
    // Used by ShiftRow to shift the Master Grid rows
    private void ShiftMasterGrid(int row, int units)
    {
        for (int x = 0; x < config.GameGridWidth; x++)
        {
            for (int y = row; y < config.GameGridHeight; y++)
            {
                // Debug.Log(debugTag + "Looking for x" + x + ", y" + y);
                // Debug.Log(debug + "Shifting [" + x + ", " + y + "]");
                float oldX = knownOwnersGrid[x, y].CardObject.transform.position.x;
                float oldY = knownOwnersGrid[x, y].CardObject.transform.position.y;
                float oldZ = knownOwnersGrid[x, y].CardObject.transform.position.z;

                StartCoroutine(CardAnimations.MoveTileCoroutine(knownOwnersGrid[x, y].CardObject,
                                                                new Vector3(0, shiftUnit, 0), .1f));

                // knownOwnersGrid[x, y].CardObject.transform.position = new Vector3(oldX,
                //  (oldY += (shiftUnit * units)),
                //  knownOwnersGrid[x, y].CardObject.transform.position.z);
            }
        }
    }
Beispiel #9
0
    // Use this for initialization
//	void Start () {
//		cardAnim= GameObject.FindGameObjectWithTag("GamePlayPanel").GetComponent<CardAnimations> ();
//	}
    void Awake()
    {
        cardAnim = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CardAnimations> ();
    }
Beispiel #10
0
    }     // UpdateKnownRounds()

    private void HandleTurnEvent()
    {
        GameObject cardObj;

        //Handle an event during Phase 2 on your turn
        this.turnEventStr = matchDataBroadcaster.TurnEventStr;
        TurnEvent turnEvent = JsonUtility.FromJson <TurnEvent>(this.turnEventStr);

        Card     turnCard   = JsonUtility.FromJson <Card>(turnEvent.card);
        CardData targetCard = JsonUtility.FromJson <CardData>(turnEvent.card);

        Debug.Log(debugTag + "TurnEvent: " + turnEvent);
        Debug.Log(debugTag + "Target Category: " + targetCard.Category);

        // Check if the message should be addressed by this player
        // if (turnEvent.phase != phase || turnEvent.playerId != this.id)
        // {
        //  return;
        // }

        // Operations ==========================================================

        switch (turnEvent.operation)
        {
        case "Play":

            // Debug.Log(debugTag + "Trying to destroy " + cardObj.name);
            // Destroy(cardObj);

            // Debug.Log(debugTag + "Moving " + cardObj.name);

            // If the card is meant to be stacked
            if (!turnCard.DiscardFlag)
            {
                if (!hasAuthority)
                {
                    gridController.AddCardToStack(turnEvent.targetX, turnEvent.targetY, targetCard.Category, turnCard);
                }

                // Debug.Log(debugTag + "Running Shift Row Check on " + targetCard.Category + ", " + turnEvent.targetX+ ", " + turnEvent.targetY);
                if (gridController.ShiftRowCheck(targetCard.Category, turnEvent.targetX, turnEvent.targetY))
                {
                    gridController.IncrementStackSize(turnEvent.targetY, targetCard.Category);
                }

                Debug.Log(debugTag + "Trying to find " + CardUtility.CreateCardObjectName(targetCard.Category, turnEvent.targetX, turnEvent.targetY));
                GameObject targetObject = GameObject.Find(CardUtility.CreateCardObjectName(targetCard.Category, turnEvent.targetX, turnEvent.targetY));

                CardData tile = gridController.GetClientTile(targetCard.Category, turnEvent.targetX, turnEvent.targetY);

                // Debug.Log(debugTag.head + "Target Category: " + targetCard.Category);
                // Debug.Log(debugTag.head + targetObject.name + " Stack Size: " + tile.CardStack.Count);

                Vector3 gap = targetObject.transform.position - new Vector3(targetObject.transform.position.x,
                                                                            targetObject.transform.position.y
                                                                            - (gridController.shiftUnit * (tile.CardStack.Count)),
                                                                            (targetObject.transform.position.z)
                                                                            + (gridController.cardThickness * (tile.CardStack.Count)));

                if (turnEvent.playerId == this.id)
                {
                    cardObj = GameObject.Find(CardUtility.CreateCardObjectName(turnEvent.cardType,
                                                                               turnEvent.x, turnEvent.y));

                    Debug.Log(debugTag + "Trying to move " + cardObj.name + " under " + targetObject.name);
                    // gridController.GetTile(targetCard.x, targetCard.y)

                    cardObj.transform.name = CardUtility.CreateCardObjectName("Stacked", turnEvent.x, tile.CardStack.Count - 1);
                    cardObj.transform.SetParent(targetObject.transform);

                    StartCoroutine(CardAnimations.MoveCardCoroutine(cardObj, targetObject, gap, .1f));

                    CreateNewCardObject(turnEvent.y, turnEvent.topCard);
                }
                else
                {
                    GameObject otherPlayersCard = (GameObject)Instantiate(matchController.gameCardPrefab,
                                                                          new Vector3(0, 60, 40),
                                                                          Quaternion.identity);
                    otherPlayersCard.GetComponent <CardViewController>().Card = JsonUtility.FromJson <CardData>(turnEvent.playedCard);

                    otherPlayersCard.transform.name = CardUtility.CreateCardObjectName("Stacked", turnEvent.x, tile.CardStack.Count - 1);
                    otherPlayersCard.transform.SetParent(targetObject.transform);
                    StartCoroutine(CardAnimations.MoveCardCoroutine(otherPlayersCard, targetObject, gap, .1f));
                }
            }
            else                     // Cards that don't get stacked (like discards)
            {
                if (turnEvent.playerId == this.id)
                {
                    cardObj = GameObject.Find(CardUtility.CreateCardObjectName(turnEvent.cardType,
                                                                               turnEvent.x, turnEvent.y));
                    Destroy(cardObj);
                    CreateNewCardObject(turnEvent.y, turnEvent.topCard);
                }
            }

            // cardObj.transform.Translate(new Vector3(targetObject.transform.position.x,
            //      targetObject.transform.position.y
            //      - (gridController.shiftUnit * targetCard.CardStack.Count),
            //      (targetObject.transform.position.z)
            //      + (gridController.cardThickness * targetCard.CardStack.Count)));

            if (turnEvent.topCard != "empty")
            {
                // this.hand[turnEvent.y] = JsonUtility.FromJson<CardData>(turnEvent.topCard);
                // CreateNewCardObject(turnEvent.y, turnEvent.topCard);
            }
            else
            {
                Debug.Log(debugTag + "GameCard deck must be empty!");
            }

            // TODO: Add code to refresh a market card's footer value if a card was played on it.

            break;

        case "Buy":
            // Add bought Tile to local knowledge base
            gridController.KnownOwnersGrid[turnEvent.x, turnEvent.y].OwnerId = turnEvent.playerId;
            this.knownOwnersList[turnEvent.playerId - 1].Add(new Coordinate2(turnEvent.x, turnEvent.y));

            // Grab the Tile GameObject that was bought
            Debug.Log(debugTag + CardUtility.CreateCardObjectName(turnEvent.cardType,
                                                                  turnEvent.x,
                                                                  turnEvent.y));
            cardObj = GameObject.Find(CardUtility.CreateCardObjectName(turnEvent.cardType,
                                                                       turnEvent.x,
                                                                       turnEvent.y));

            CardData boughtCard = JsonUtility.FromJson <CardData>(turnEvent.card);

            boughtCard.CardObject = cardObj;
            gridController.KnownOwnersGrid[turnEvent.x, turnEvent.y]         = boughtCard;
            gridController.KnownOwnersGrid[turnEvent.x, turnEvent.y].OwnerId = turnEvent.playerId;

            CardAnimations.FlipCard(turnEvent.cardType, turnEvent.x, turnEvent.y);

            cardObj.GetComponent <CardViewController>().Card = JsonUtility.FromJson <Card>(turnEvent.card);

            // Depending on the player who bought the tile, change the Tile's color.
            cardObj.GetComponentsInChildren <Renderer>()[0].material.color = ColorPalette.GetDefaultPlayerColor(turnEvent.playerId, 500, true);
            cardObj.GetComponentsInChildren <Renderer>()[1].material.color = ColorPalette.GetDefaultPlayerColor(turnEvent.playerId, 500, true);
            break;
        }
    }
Beispiel #11
0
    }     // Update()

    private IEnumerator InitPlayer(string address)
    {
        // Grab Components
        yield return(StartCoroutine(GrabComponentsCoroutine()));

        // Determine of the main grid has been created yet
        GameObject testCard = GameObject.Find(CardUtility.CreateCardObjectName("Tile", 0, 0));

        while (testCard == null)
        {
            testCard = GameObject.Find(CardUtility.CreateCardObjectName("Tile", 0, 0));
            yield return(null);
        }

        // Get ID from MatchManager
        CmdInitId(address);
        while (this.id == -1)
        {
            yield return(null);
        }

        // Fetch username from PlayerDataController and send it serverside to MatchController
        InitUsername();

        // Send our ID to the HudController, then force an update from it.
        this.hudController.GetComponent <HudController>().ThisPlayerId = this.id;
        this.hudController.UpdateHud();

        // Grab the config from the broadcaster
        this.config = JsonUtility.FromJson <MatchConfig>(matchDataBroadcaster.MatchConfigStr);
        while (this.config == null)
        {
            yield return(null);
        }

        // Create hand card objects
        Debug.Log(debugTag + "Creating hand card objects for Player " + this.id);
        gridController.CreatePlayerHandObjects(this.id);

        // CmdGetHand(this.id);
        // Debug.Log(debug + "Hand size: " + this.hand.Count);
        // gridMan.CreateHandObjects(this.id, this.hand);
        this.knownOwnersList = new List <Coordinate2> [config.MaxPlayerCount];
        // this.knownOwnersGrid = new int[config.GameGridWidth, config.GameGridHeight];

        for (int i = 0; i < config.MaxPlayerCount; i++)
        {
            this.knownOwnersList[i] = new List <Coordinate2>();
        }

        InitLocalResourcePrices();

        this.matchData    = JsonUtility.FromJson <MatchData>(matchDataBroadcaster.MatchDataStr);
        this.turnEventStr = matchDataBroadcaster.TurnEventStr;

        // InitLocalMarketGrid();
        UpdateKnownInfo();

        while (this.id == -1)
        {
            yield return(null);
        }

        for (int i = 0; i < config.PlayerHandSize; i++)
        {
            CmdGetHandCard(this.id, i);
        }

        // If this is Player 1 and it's the first Turn of the first Round
        if (this.id == 1 && this.matchData.Turn == 1 &&
            this.matchData.Round == 1 &&
            this.matchData.Phase == 1)
        {
            CardAnimations.HighlightCards(GetUnownedCards(), this.id);
        }

        this.initialzed = true;
    }
Beispiel #12
0
 private void CmdFlipCard(string cardType, int locX, int locY)
 {
     CardAnimations.FlipCard(cardType, locX, locY);
 }     // CmdFlipCard()