} // 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; } }
private void CmdFlipCard(string cardType, int locX, int locY) { CardAnimations.FlipCard(cardType, locX, locY); } // CmdFlipCard()