internal void init() { var cardCanvas = GameObject.Find(Constants.cardCanvas); canvas = GameObject.Find("Canvas").gameObject.GetComponent<Canvas>(); //set up fake card model var hoverCardModel = new CardModel() { playerId = -1, }; //init the hover card that's hidden most of the time cardService.CreateCard(hoverCardModel, cardCanvas.transform, new Vector3(10000,10000, 0)); var hoverCardGO = hoverCardModel.gameObject; hoverCardGO.name = hoverName; hoverCardGO.tag = "HoverCard"; //disable all colliders so you can't hover the hover foreach (var collider in hoverCardGO.GetComponentsInChildren<BoxCollider>()) { collider.enabled = false; } foreach (var collider in hoverCardGO.GetComponentsInChildren<MeshCollider>()) { collider.enabled = false; } hoverCardView = hoverCardGO.AddComponent<CardView>(); hoverCardView.card = hoverCardModel; hoverCardGO.SetActive(false); }
public CardModel CreateCard(CardModel cardModel, Transform parent, Vector3? spawnPosition = null) { var cardPrefab = loader.Load<GameObject>("Card"); var newCard = GameObject.Instantiate( cardPrefab, spawnPosition ?? Constants.cardSpawnPosition, Quaternion.identity ) as GameObject; if (parent != null) { newCard.transform.SetParent(parent, false); } newCard.name = "Player " + cardModel.playerId + " Card " + cardModel.id; cardModel.gameObject = newCard; cardModel.rectTransform = newCard.GetComponent<RectTransform>(); if (cardModel.cardTemplateId != 0) { UpdateCardArt(cardModel); } return cardModel; }
public void SetupGameObject(CardModel model, GameObject cardGameObject) { model.gameObject = cardGameObject; model.rectTransform = cardGameObject.GetComponent<RectTransform>(); var cardView = cardGameObject.AddComponent<CardView>(); cardView.card = model; model.cardView = cardView; UpdateCardArt(model); }
internal void onCardHovered(CardModel card) { //reset previous hovered card to active if (hoveredCard != null) { hoveredCard.cardView.displayWrapper.SetActive(true); } //then update hoveredCard = card; hoverAccumulator = 0f; }
public void UpdateCardArt(CardModel model) { //set there is art to setup var render = loader.Load<Texture>("Models/" + model.cardTemplateId + "/render"); var displayWrapper = model.gameObject.transform.FindChild("DisplayWrapper").gameObject; var art = displayWrapper.transform.FindChild("Art").gameObject; var artRenderer = art.GetComponent<MeshRenderer>(); if (render != null) { artRenderer.material.SetTexture("_MainTex", render); } else { artRenderer.material.SetTexture("_MainTex", null); } }
private void onCardHovered(CardModel card) { if (card != null) { var hoveredCardRect = card.rectTransform; var position = hoveredCardRect.anchoredPosition3D; view.showCardFromHand(card, position, possibleActions.GetSpellDamage(card.playerId)); hoveringCard = true; //debug.Log("Hovering from card"); } else { view.hideCard(); hoveringCard = false; //debug.Log("Hiding from card"); } }
private void SetCardPos(CardModel card, int c, bool isOpponent) { if (isOpponent) { card.gameObject.transform.SetParent(OpponentDeckGO.transform, false); } else { card.gameObject.transform.SetParent(DeckGO.transform, false); } var rectTransform = card.rectTransform; rectTransform.anchorMax = anchorPosition; rectTransform.anchorMin = anchorPosition; rectTransform.anchoredPosition3D = baseCardOffset + new Vector3(c * 0.3f, 0, c); rectTransform.localRotation = baseRotation; rectTransform.localScale = Vector3.one; rectTransform.pivot = anchorPosition; }
public void CopyPieceToCard(PieceModel src, CardModel dest, bool link) { var templateCard = cardDirectory.Card(src.cardTemplateId); dest.cardTemplateId = src.cardTemplateId; dest.playerId = src.playerId; dest.name = templateCard.name; dest.description = templateCard.description; dest.cost = templateCard.cost; dest.baseCost = templateCard.baseCost; dest.attack = src.attack; dest.health = src.health; dest.movement = src.movement; dest.range = src.range; dest.tags = src.tags; dest.statuses = src.statuses; dest.metCondition = false; if (link) { dest.linkedPiece = src; } }
public override void Execute() { if (!processedActions.Verify(spawnDeck.id)) return; //holding area that all cards go into to start with until the deck mediator sorts them out var DeckGO = GameObject.Find("Deck"); for (var c = 0; c < spawnDeck.cards; c++) { var cardModel = new CardModel() { playerId = spawnDeck.playerId, }; cardService.CreateCard(cardModel, DeckGO.transform); decks.Cards.Add(cardModel); } deckSpawned.Dispatch(spawnDeck); debug.Log(string.Format("Spawned deck for player {0}", spawnDeck.playerId), socketKey); }
private void onShuffleToDeck(CardModel card) { //TODO: Better animation updateDecks(); }
private void onCardDrawnShown(CardModel card) { cards.Cards.Add(card); UpdateCardsPlayableStatus(cards.Cards); view.init(PlayerCards(), OpponentCards()); }
public void OnPointerEnter(PointerEventData eventData) { if (item != null) { hovering = true; historyHoverSignal.Dispatch(true); //show main card/piece as a card if (item.triggeringCard != null) { hoveringCards[item.triggeringCard.id] = showCard(item.triggeringCard, Vector3.zero, item.spellDamage); } else if (item.triggeringPiece != null) { var pieceCard = new CardModel(); pieceService.CopyPieceToCard(item.triggeringPiece, pieceCard, true); hoveringCards[-item.triggeringPiece.id] = showCard(pieceCard, Vector3.zero, item.spellDamage); } //show all damage/heal events var xOffset = 180f; var numberSplat = loader.Load<GameObject>("NumberSplat"); var deathOverlay = loader.Load<GameObject>("DeathOverlay"); for (int i = 0; i < item.pieceChanges.Count; i++) { var pieceChange = item.pieceChanges[i]; changeCounts[pieceChange.originalPiece.id] = changeCounts.ContainsKey(pieceChange.originalPiece.id) ? changeCounts[pieceChange.originalPiece.id] + 1 : 1; var pieceChangeCount = changeCounts[pieceChange.originalPiece.id]; var totalPieceChangeCount = item.pieceChanges.Where(p => p.originalPiece.id == pieceChange.originalPiece.id).Count(); //gonna cap out the piece changes we can show so we don't end up with horribly broken UI in rare cases if (pieceChangeCount > 6) { continue; } CardView healthChangeCard = null; //if the hp change is about an existing hovered card, reuse that card instead of making a new one if (pieceChange.originalPiece != null && hoveringCards.ContainsKey(-pieceChange.originalPiece.id)) { healthChangeCard = hoveringCards[-pieceChange.originalPiece.id]; } else { var pieceCard = new CardModel(); pieceService.CopyPieceToCard(pieceChange.originalPiece, pieceCard, true); healthChangeCard = showCard(pieceCard, new Vector3(xOffset * (i + 1), 0, 0), 0); hoveringCards[-pieceChange.originalPiece.id] = healthChangeCard; } if (pieceChange.type == HistoryPieceChangeType.HealthChange) { var hpChange = (HistoryHealthChange)pieceChange; //death vs damage if (pieceChange.originalPiece.health <= 0) { var deathSplat = Instantiate(deathOverlay); deathSplat.transform.SetParent(healthChangeCard.displayWrapper.transform, false); } else { //plop down the number splat scaled up and reset to the right position var newNumberSplat = Instantiate(numberSplat, healthChangeCard.displayWrapper.transform, false) as GameObject; var yPos = totalPieceChangeCount == 1 ? 40.5f : 120 - (pieceChangeCount * 40f); newNumberSplat.transform.localPosition = new Vector3(0, yPos, -2.0f); newNumberSplat.transform.localScale = new Vector3(140, 140, 1); newNumberSplat.transform.localRotation = Quaternion.Euler(Vector3.zero); var view = newNumberSplat.GetComponent<NumberSplatView>(); view.change = hpChange.healthChange.change; view.bonus = hpChange.healthChange.bonus; view.bonusText = hpChange.healthChange.bonusMsg; view.animate = false; } } } } }
private void onCancelTarget(CardModel c) { view.setDragEnabled(true); }
internal CardView showCard(CardModel cardToShow, Vector3 positionOffset, int spellDamage) { var selfPos = transform.position; //copy over props from hovered to hover var hoverCardModel = new CardModel(); cardToShow.CopyProperties(hoverCardModel); var hoverCardView = CreateHoverCard(hoverCardModel); var hoverGo = hoverCardView.card.gameObject; hoverCardView.card.gameObject = hoverGo; hoverCardView.staticSpellDamage = spellDamage; hoverGo.name = "Hover Card for " + hoverCardView.card.id; hoverCardView.UpdateText(spellDamage); hoverCardView.UpdateBuffsDisplay(); //now for the fun positioning Vector2 viewportPos = Camera.main.WorldToViewportPoint(selfPos); Vector2 cardCanvasPos = cardCanvasHelper.ViewportToWorld(viewportPos); var hWidth = hoverCardView.rectTransform.sizeDelta; var displayPosition = new Vector3(cardCanvasPos.x + hWidth.x, cardCanvasPos.y + (hWidth.y * 0.75f), -5f); displayPosition = displayPosition + positionOffset; hoverCardView.rectTransform.SetAnchor(Vector2.zero); hoverCardView.rectTransform.anchoredPosition3D = displayPosition; return hoverCardView; }
private CardView CreateHoverCard(CardModel hoverCardModel) { var cardCanvas = GameObject.Find(Constants.cardCanvas); hoverCardModel.playerId = -1; cardService.CreateCard(hoverCardModel, cardCanvas.transform, new Vector3(10000,10000, 0)); var hoverCardGO = hoverCardModel.gameObject; //disable all colliders so you can't hover the hover foreach (var collider in hoverCardGO.GetComponentsInChildren<BoxCollider>()) { collider.enabled = false; } foreach (var collider in hoverCardGO.GetComponentsInChildren<MeshCollider>()) { collider.enabled = false; } var hoverCardView = hoverCardGO.AddComponent<CardView>(); hoverCardView.card = hoverCardModel; return hoverCardView; }
private void onTargetCancel(CardModel card) { startTargetModel = null; if (chooseModel != null) { debug.Log("Cancelling choose from target cancel"); cancelChoose.Dispatch(chooseModel); } chooseModel = null; cardSelected.Dispatch(null); }
private void onCancelSelectTarget(CardModel card) { setAttackRangeTiles(null); selectingArea = null; updateSelectHighlights(null); }
internal void showCardFromHand(CardModel cardToShow, Vector3 position, int spellDamage) { //copy over props from hovered to hover cardToShow.CopyProperties(hoverCardView.card); //but reset some key things hoverCardView.name = hoverName; hoverCardView.card.gameObject = hoverCardView.gameObject; hoverCardView.rectTransform.SetAnchor(cardAnchor); var displayPosition = new Vector3(position.x, 125f, zPos - 11f); showCard(displayPosition, spellDamage); }
private void onClick(GameObject clickedObject, Vector3 point) { if (clickedObject != null) { if (clickedObject.CompareTag("Card")) { var cardView = clickedObject.GetComponent<CardView>(); //Choose card interactions if (chooseModel != null && cardView.card.tags.Contains(Constants.chooseCardTag)) { chooseModel.chosenTemplateId = cardView.card.cardTemplateId; cardChosen.Dispatch(chooseModel); if (chooseModel.chooseFulfilled) { activateCard.Dispatch(new ActivateModel() { cardActivated = chooseModel.choosingCard, optionalTarget = null, position = chooseModel.cardDeployPosition.position, pivotPosition = null, chooseCardTemplateId = chooseModel.chosenTemplateId }); chooseModel = null; } else { var selected = chooseModel.choices.choices .FirstOrDefault(x => x.cardTemplateId == chooseModel.chosenTemplateId.Value); //if the choice isn't fulfilled yet it must mean it needs targets startTargetModel = new TargetModel() { targetingCard = chooseModel.choosingCard, cardDeployPosition = chooseModel.cardDeployPosition, targets = selected.targets, area = null // not supported yet }; Invoke("StartSelectTargets", 0.10f); return; } return; } if (cardView.card.isSpell) { var targets = possibleActions.GetActionsForCard(turns.currentPlayerId, cardView.card.id); var area = possibleActions.GetAreasForCard(turns.currentPlayerId, cardView.card.id); if (targets != null || area != null) { startTargetModel = new TargetModel() { targetingCard = cardView.card, cardDeployPosition = null, targets = targets, area = area }; Invoke("StartSelectTargets", 0.10f); return; } } draggedCard = cardView.card; pieceSelected.Dispatch(null); cardSelected.Dispatch(new CardSelectedModel() { card = draggedCard, point = point }); } } else { draggedCard = null; cardSelected.Dispatch(null); //only cancel if we're not targeting with a choose if (startTargetModel == null) { if (chooseModel != null) { cancelChoose.Dispatch(chooseModel); } chooseModel = null; } } }
private void onCancelSelectTarget(CardModel card) { view.disable(); }
private void onCancelTarget(CardModel card) { cardTarget = null; }
private void onCardDiscarded(CardModel card) { var opponentId = players.OpponentId(gameTurn.currentPlayerId); card.activated = true; if (card.playerId == opponentId) { animationQueue.Add(new CardsView.DiscardCardAnim() { card = card, destroyCard = destroyCard, isOpponentCard = true }); } else { animationQueue.Add(new CardsView.DiscardCardAnim() { card = card, destroyCard = destroyCard }); } }
private void onCardDestroyed(CardModel card) { cards.Cards.Remove(card); Destroy(card.gameObject); view.init(PlayerCards(), OpponentCards()); }
private CardModel CopyCard(CardModel src) { var dst = new CardModel(); src.CopyProperties(dst); dst.gameObject = null; //don't need the original game object here return dst; }
private void SetCardXPos(CardModel card, float x) { var rectTransform = card.rectTransform; rectTransform.anchorMax = anchorPosition; rectTransform.anchorMin = anchorPosition; rectTransform.pivot = anchorPosition; rectTransform.anchoredPosition3D = new Vector3(x, 0, 0); rectTransform.localScale = Vector3.one; }
private void onCardGiven(CardModel card) { //animate the card going to the right hand, based on who's turn it is and if it's hotseat vs net var opponentId = players.OpponentId(gameTurn.currentPlayerId); var isOpponent = card.playerId == opponentId; animationQueue.Add(new CardsView.GiveCardAnim() { card = card, isOpponentCard = isOpponent }); onCardDrawn(card); }
private void onCardHovered(CardModel card) { view.onCardHovered(card); }
private void onTargetCancel(CardModel card) { foreach (var piece in pieces.Pieces) { piece.pieceView.targetCandidate = false; } }