public void AttachCard(CardView card) { card.Open(true); card.GetComponent<RectTransform>().SetParent(transform); card.GetComponent<RectTransform>().localPosition = Vector3.zero; card.GetComponent<RectTransform>().localRotation = Quaternion.identity; card.GetComponent<RectTransform>().localScale = Vector3.one; card.GetCardData().state = CardState.Arena; }
public void AttachCard(CardView card) { card.Open(true); card.GetComponent <RectTransform>().SetParent(transform); card.GetComponent <RectTransform>().localPosition = Vector3.zero; card.GetComponent <RectTransform>().localRotation = Quaternion.identity; card.GetComponent <RectTransform>().localScale = Vector3.one; card.GetCardData().state = CardState.Arena; }
public void PickCard(CardView card) { if (card.GetCardData().state == CardState.Stacked && TurnManager.IsCardDrawn()) { return; }else{ card.GetComponent<RectTransform>().SetParent(container.transform); card.GetComponent<RectTransform>().localRotation = Quaternion.identity; card.GetComponent<RectTransform>().localScale = Vector3.one; card.GetComponent<CardView>().GetCardData().state = CardState.Handed; TurnManager.SetCardDrawn(); } }
public void PickCard(CardView card) { if (card.GetCardData().state == CardState.Stacked && TurnManager.IsCardDrawn()) { return; } else { card.GetComponent <RectTransform>().SetParent(container.transform); card.GetComponent <RectTransform>().localRotation = Quaternion.identity; card.GetComponent <RectTransform>().localScale = Vector3.one; card.GetComponent <CardView>().GetCardData().state = CardState.Handed; TurnManager.SetCardDrawn(); } }
private void DealCards(int amount) { var deck = deckCreationSystem.Deck; var j = 0; for (var i = 0; i < amount; ++i) { if (deck.Length == 0) { break; } var card = deck[0]; CardView cardView = CreateCardView(card); var cardEntity = cardView.GetComponent <GameObjectEntity>().Entity; var selectedSlotEntity = Entity.Null; var selectedSlotData = default(SlotData); var foundFreeSlot = false; while (!foundFreeSlot) { var slotEntity = gameBoard.TopRowSlots[j].GetComponent <GameObjectEntity>().Entity; var slotData = EntityManager.GetComponentData <SlotData>(slotEntity); if (slotData.Occupied == 0) { selectedSlotEntity = slotEntity; selectedSlotData = slotData; foundFreeSlot = true; } else { ++j; } } cardView.transform.position = gameBoard.TopRowSlots[j].transform.position; cardView.Slot = gameBoard.TopRowSlots[j]; EntityManager.SetComponentData(selectedSlotEntity, new SlotData { Type = selectedSlotData.Type, Occupied = 1, Entity = cardEntity }); EntityManager.AddComponentData(cardEntity, new CardSlotData { Type = SlotType.Deck }); deck.RemoveAtSwapBack(0); EntityManager.DestroyEntity(card); } applyFaith = false; deckSizeText.text = deckCreationSystem.Deck.Length.ToString(); }
public void OnPointerClick(PointerEventData eventData) { card.GetComponent <RectTransform>().SetParent(prevParent); card.transform.localPosition = Vector3.zero; card.transform.localRotation = prevRot; card.transform.localScale = Vector3.one; card.GetCardData().state = prevState; card = null; shadow.SetActive(false); }
public void Dismiss(CardView card) { cards.Remove(card.transform); card.gameObject.SetActive(false); card.transform.localScale = Vector3.one; var poolable = card.GetComponent <Poolable> (); var pooler = GetComponentInParent <BoardView> ().cardPooler; pooler.Enqueue(poolable); }
public void PreviewCard(CardView view) { shadow.SetActive(true); card = view; AudioSource.PlayClipAtPoint(audioClip, Vector3.zero); prevParent = card.transform.parent; prevState = card.GetCardData().state; card.GetCardData().state = CardState.Preview; card.GetComponent <RectTransform>().SetParent(transform); card.transform.localPosition = Vector3.zero; prevRot = card.transform.localRotation; card.transform.localRotation = Quaternion.identity; card.transform.localScale = Vector3.one; }
public void PreviewCard(CardView view) { shadow.SetActive(true); card = view; AudioSource.PlayClipAtPoint(audioClip, Vector3.zero); prevParent = card.transform.parent; prevState = card.GetCardData().state; card.GetCardData().state = CardState.Preview; card.GetComponent<RectTransform>().SetParent(transform); card.transform.localPosition = Vector3.zero; prevRot = card.transform.localRotation; card.transform.localRotation = Quaternion.identity; card.transform.localScale = Vector3.one; }
private void InstantiateStockPile(Stack <Card> stockPileCards, Vector2 suggestedCardSize, float y_padding_worldSpace) { this.stockPile_pos = tableuPositions.Last() + new Vector3(0, y_padding_worldSpace + suggestedCardSize.y, 0); Card[] stockPileCardsArr = stockPileCards.ToArray(); CardView previousCardView = null; for (int i = 0; i < stockPileCards.Count; i++) { Card stockPileCard = stockPileCardsArr[i]; GameObject stockPileGO = this.InstantiateCardGameObject(suggestedCardSize, stockPile_pos, false, stockPileCard, i); CardView stockPileCardView = stockPileGO.GetComponent <CardView>(); previousCardView = stockPileCardView; stockPileGO.name = stockPileCard.ToString() + "(Stock)"; } //Initialize Object to decect stock touches GameObject stockPileClickDetectorGO = new GameObject("stockPileClickDetectorGO"); stockPileClickDetectorGO.transform.parent = cardsContainer; var stockClickDetector = stockPileClickDetectorGO.AddComponent <StockClickDetector>(); stockClickDetector.cooldown = flipSpeed; stockPileClickDetectorGO.AddComponentCopy(previousCardView.GetComponent <BoxCollider2D>()); stockPileClickDetectorGO.transform.localScale = previousCardView.transform.localScale; stockPileClickDetectorGO.transform.position = previousCardView.transform.position; //Make sure it's above everything else so it catches the raycastings first. stockPileClickDetectorGO.transform.SetZ(-52); //Make fondo of stock object var go = InstantiateAndScale(foundationPilePrefab, suggestedCardSize, stockPile_pos); go.GetComponent <CardView>().bigSuit.enabled = false; go.transform.SetZ(1); go.name = "Stock_Fondo"; go.transform.parent = cardsContainer; }
bool IsSelected(CardView view) { return view.GetComponent<Toggle>().isOn; }
public void PlayCard(CardView card) { if (card.CanBePlayed(this)) { gameUI.endTurnButton.SetEnabled(false); var gameConfig = GameManager.Instance.config; var libraryCard = gameConfig.GetCard(card.card.cardId); var cardType = gameConfig.cardTypes.Find(x => x.id == libraryCard.cardTypeId); if (cardType.name == "Creature") { var boardCreature = Instantiate(boardCreaturePrefab); var board = GameObject.Find("PlayerBoard"); boardCreature.tag = "PlayerOwned"; boardCreature.transform.parent = board.transform; boardCreature.transform.position = new Vector2(1.9f * playerBoardCards.Count, 0); boardCreature.GetComponent <BoardCreature>().ownerPlayer = this; boardCreature.GetComponent <BoardCreature>().PopulateWithInfo(card.card); playerHandCards.Remove(card); RearrangeHand(); playerBoardCards.Add(boardCreature.GetComponent <BoardCreature>()); Destroy(card.gameObject); currentCreature = boardCreature.GetComponent <BoardCreature>(); RearrangeBottomBoard(() => { var triggeredAbilities = libraryCard.abilities.FindAll(x => x is TriggeredAbility); TriggeredAbility targetableAbility = null; foreach (var ability in triggeredAbilities) { var triggeredAbility = ability as TriggeredAbility; var trigger = triggeredAbility.trigger as OnCardEnteredZoneTrigger; if (trigger != null && trigger.zoneId == boardZone.zoneId && triggeredAbility.target is IUserTarget) { targetableAbility = triggeredAbility; break; } } // Preemptively move the card so that the effect solver can properly check the availability of targets // by also taking into account this card (that is trying to be played). playerInfo.namedZones["Hand"].RemoveCard(card.card); playerInfo.namedZones["Board"].AddCard(card.card); if (targetableAbility != null && effectSolver.AreTargetsAvailable(targetableAbility.effect, card.card, targetableAbility.target)) { var targetingArrow = Instantiate(spellTargetingArrowPrefab).GetComponent <SpellTargetingArrow>(); boardCreature.GetComponent <BoardCreature>().abilitiesTargetingArrow = targetingArrow; targetingArrow.effectTarget = targetableAbility.target; targetingArrow.targetType = targetableAbility.target.GetTarget(); targetingArrow.onTargetSelected += () => { PlayCreatureCard(card.card, targetingArrow.targetInfo); effectSolver.MoveCard(netId, card.card, "Hand", "Board", targetingArrow.targetInfo); currentCreature = null; gameUI.endTurnButton.SetEnabled(true); }; targetingArrow.Begin(boardCreature.transform.localPosition); } else { PlayCreatureCard(card.card); effectSolver.MoveCard(netId, card.card, "Hand", "Board"); currentCreature = null; gameUI.endTurnButton.SetEnabled(true); } boardCreature.GetComponent <BoardCreature>().fightTargetingArrowPrefab = fightTargetingArrowPrefab; }); } else if (cardType.name == "Spell") { var spellsPivot = GameObject.Find("PlayerSpellsPivot"); var sequence = DOTween.Sequence(); sequence.Append(card.transform.DOMove(spellsPivot.transform.position, 0.5f)); sequence.Insert(0, card.transform.DORotate(Vector3.zero, 0.2f)); sequence.Play().OnComplete(() => { card.GetComponent <SortingGroup>().sortingLayerName = "BoardCards"; card.GetComponent <SortingGroup>().sortingOrder = 1000; var boardSpell = card.gameObject.AddComponent <BoardSpell>(); var triggeredAbilities = libraryCard.abilities.FindAll(x => x is TriggeredAbility); TriggeredAbility targetableAbility = null; foreach (var ability in triggeredAbilities) { var triggeredAbility = ability as TriggeredAbility; var trigger = triggeredAbility.trigger as OnCardEnteredZoneTrigger; if (trigger != null && trigger.zoneId == boardZone.zoneId && triggeredAbility.target is IUserTarget) { targetableAbility = triggeredAbility; break; } } currentSpellCard = card; if (targetableAbility != null && effectSolver.AreTargetsAvailable(targetableAbility.effect, card.card, targetableAbility.target)) { var targetingArrow = Instantiate(spellTargetingArrowPrefab).GetComponent <SpellTargetingArrow>(); boardSpell.targetingArrow = targetingArrow; targetingArrow.effectTarget = targetableAbility.target; targetingArrow.targetType = targetableAbility.target.GetTarget(); targetingArrow.onTargetSelected += () => { PlaySpellCard(card.card, targetingArrow.targetInfo); effectSolver.MoveCard(netId, card.card, "Hand", "Board", targetingArrow.targetInfo); currentSpellCard = null; gameUI.endTurnButton.SetEnabled(true); }; targetingArrow.Begin(boardSpell.transform.localPosition); } else { PlaySpellCard(card.card); effectSolver.MoveCard(netId, card.card, "Hand", "Board"); currentSpellCard = null; gameUI.endTurnButton.SetEnabled(true); } }); } } else { card.GetComponent <HandCard>().ResetToInitialPosition(); } }
public override void OnStartLocalPlayer() { base.OnStartLocalPlayer(); gameUI = GameObject.Find("GameUI").GetComponent <GameUI>(); Assert.IsNotNull(gameUI); foreach (var entry in playerInfo.stats) { if (entry.Value.name == "Life") { lifeStat = entry.Value; } else if (entry.Value.name == "Mana") { manaStat = entry.Value; } } foreach (var entry in opponentInfo.stats) { if (entry.Value.name == "Life") { opponentLifeStat = entry.Value; } else if (entry.Value.name == "Mana") { opponentManaStat = entry.Value; } } lifeStat.onValueChanged += (oldValue, newValue) => { gameUI.SetPlayerHealth(lifeStat.effectiveValue); }; manaStat.onValueChanged += (oldValue, newValue) => { gameUI.SetPlayerMana(manaStat.effectiveValue); UpdateHandCardsHighlight(); }; opponentLifeStat.onValueChanged += (oldValue, newValue) => { gameUI.SetOpponentHealth(opponentLifeStat.effectiveValue); }; opponentManaStat.onValueChanged += (oldValue, newValue) => { gameUI.SetOpponentMana(opponentManaStat.effectiveValue); }; deckZone = playerInfo.namedZones["Deck"]; deckZone.onZoneChanged += numCards => { gameUI.SetPlayerDeckCards(numCards); }; handZone = playerInfo.namedZones["Hand"]; handZone.onZoneChanged += numCards => { gameUI.SetPlayerHandCards(numCards); }; handZone.onCardAdded += card => { AddCardToHand(card); RearrangeHand(); }; handZone.onCardRemoved += card => { var handCard = playerHandCards.Find(x => x.card == card); if (handCard != null) { playerHandCards.Remove(handCard); RearrangeHand(); } }; boardZone = playerInfo.namedZones["Board"]; boardZone.onCardRemoved += card => { var graveyardPos = GameObject.Find("GraveyardPlayer").transform.position + new Vector3(0.0f, -0.2f, 0.0f); var boardCard = playerBoardCards.Find(x => x.card == card); if (boardCard != null) { playerGraveyardCards.Add(boardCard); playerBoardCards.Remove(boardCard); boardCard.transform.DOKill(); boardCard.transform.DOMove(graveyardPos, 0.7f); boardCard.SetHighlightingEnabled(false); boardCard.StopSleepingParticles(); RearrangeBottomBoard(); boardCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards"; boardCard.GetComponent <SortingGroup>().sortingOrder = playerGraveyardCards.Count; Destroy(boardCard.GetComponent <BoxCollider2D>()); } else if (currentSpellCard != null && card == currentSpellCard.card) { currentSpellCard.SetHighlightingEnabled(false); currentSpellCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards"; currentSpellCard.GetComponent <SortingGroup>().sortingOrder = playerGraveyardCards.Count; Destroy(currentSpellCard.GetComponent <BoxCollider2D>()); currentSpellCard.transform.DOMove(graveyardPos, 0.5f); currentSpellCard.transform.DOScale(new Vector2(0.6f, 0.6f), 0.5f); currentSpellCard.GetComponent <HandCard>().enabled = false; currentSpellCard = null; } }; graveyardZone = playerInfo.namedZones["Graveyard"]; graveyardZone.onZoneChanged += numCards => { gameUI.SetPlayerGraveyardCards(numCards); }; opponentDeckZone = opponentInfo.namedZones["Deck"]; opponentDeckZone.onZoneChanged += numCards => { gameUI.SetOpponentDeckCards(numCards); }; opponentHandZone = opponentInfo.namedZones["Hand"]; opponentHandZone.onZoneChanged += numCards => { gameUI.SetOpponentHandCards(numCards); }; opponentHandZone.onCardRemoved += card => { var randomIndex = UnityEngine.Random.Range(0, opponentHandCards.Count); var randomCard = opponentHandCards[randomIndex]; opponentHandCards.Remove(randomCard); Destroy(randomCard); RearrangeOpponentHand(); }; opponentBoardZone = opponentInfo.namedZones["Board"]; opponentBoardZone.onCardRemoved += card => { var graveyardPos = GameObject.Find("GraveyardOpponent").transform.position + new Vector3(0.0f, -0.2f, 0.0f); var boardCard = opponentBoardCards.Find(x => x.card == card); if (boardCard != null) { opponentGraveyardCards.Add(boardCard); opponentBoardCards.Remove(boardCard); boardCard.transform.DOKill(); boardCard.transform.DOMove(graveyardPos, 0.7f); boardCard.SetHighlightingEnabled(false); boardCard.StopSleepingParticles(); RearrangeTopBoard(); boardCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards"; boardCard.GetComponent <SortingGroup>().sortingOrder = opponentGraveyardCards.Count; Destroy(boardCard.GetComponent <BoxCollider2D>()); } else if (currentSpellCard != null && card == currentSpellCard.card) { currentSpellCard.SetHighlightingEnabled(false); currentSpellCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards"; currentSpellCard.GetComponent <SortingGroup>().sortingOrder = opponentGraveyardCards.Count; Destroy(currentSpellCard.GetComponent <BoxCollider2D>()); var sequence = DOTween.Sequence(); sequence.PrependInterval(2.0f); sequence.Append(currentSpellCard.transform.DOMove(graveyardPos, 0.5f)); sequence.Append(currentSpellCard.transform.DOScale(new Vector2(0.6f, 0.6f), 0.5f)); sequence.OnComplete(() => { currentSpellCard = null; }); } }; opponentGraveyardZone = opponentInfo.namedZones["Graveyard"]; opponentGraveyardZone.onZoneChanged += numCards => { gameUI.SetOpponentGraveyardCards(numCards); }; }