public static void OnDraggedCardUpdate(Vector2 mousePos, CardRoot draggedCardRoot, bool inTableZone) { foreach (var obs in _observers) { obs.OnDraggedCardUpdate(mousePos, draggedCardRoot, inTableZone); } }
/// <summary> /// Called by InputManager whenever i drop card on table /// </summary> public override void OnCardDroppedOnTableByMe(CardRoot heldCard) { StopAnimationGlowingCardsOnTable(); if (State != RoomState.Playing) { return; } if (AllPassed || (AllButDefenderPassed && AllCardsCovered)) { return; } //if i am defending. if (MeDefending) { var closestCardOnTable = GetClosestCardOnTableTo(Input.mousePosition); // check if action is correct if (CanCoverThisCardWith(closestCardOnTable, heldCard)) { CoverThisCardWith(closestCardOnTable, heldCard); } } else if (IcanAddCards && CanAddThisCard(heldCard)) //if i am attacking and can add this card { MeAddCardToTable(heldCard); } // else if i am not attacking nor defenfing and cant add cards // then wait till attacker passes priority }
private void AddCardToHand(CardRoot cardRootScript) { CardsInHand.Add(cardRootScript); //disable interaction cardRootScript.InteractionDisable(); cardsN++; }
//Methods that have an implementation and used by RoomLogic #region Protected methods /// <summary> /// Do table contains card of same value with held card? /// </summary> protected bool CanAddThisCard(CardRoot heldCard) { // You always can add to an empty table if (TableIsEmpty) { return(true); } // check If trying to drop wrong card // get card value from the held card int heldCardValue = heldCard.GetCardValue(); // find at least one card on table with same value if (!GetAllCardsOnTable().Any(card => card.Value == heldCardValue)) //bug: can add carn not on your turn { // say 'Cant add this card to table' GameplayMessageManager.Instance.ShowFullScreenText("Эту карту нельзя подкинуть"); return(false); } // if table is not full (5 cards on first turn, 6 on any other) // and player defending has cards if (TableIsFull || !DefenderHasCardsToDefend) { // say 'Too much cards on table' GameplayMessageManager.Instance.ShowFullScreenText("Перебор"); return(false); } return(true); }
/// <summary> /// Covers card on table with dropped card. Adds to covered cards list /// </summary> protected override void AnimateCoverCardBy(CardRoot cardOnTable, CardRoot heldCard) { //Disable interactions cardOnTable.InteractionDisable(); //Animate heldCard.AnimateMoveToTransform(cardOnTable.CoveredCardContainer); cardOnTable.CoveredCardContainer.SetAsLastSibling(); }
public void DraggedCardDrop(Vector2 mousePos, CardRoot cardRoot) { //if it was dropped insude table rect if (RectTransformUtility.RectangleContainsScreenPoint(TableDropZone, mousePos)) { FoolObservable.OnCardDroppedOnTableByMe(cardRoot); } }
public void PickUpCard(CardRoot cardRoot) { CardsInHand.Add(cardRoot); //Enable interactions cardRoot.InteractionEnable(); cardRoot.AnimateMoveToTransform(HandContainer); }
public static void OnCardDroppedOnTableByMe(CardRoot cardRoot) { StaticRoomData.MyPlayer.TakeCards(-1); foreach (var obs in _observers) { obs.OnCardDroppedOnTableByMe(cardRoot); } }
protected override CardRoot AnimateEnemyCoversCard(int slotN, CardRoot cardOnTable, string cardCodeHeld) { var heldCard = _playersInfosManager.AnimateEnemySpawnCard(slotN, cardCodeHeld); AnimateCoverCardBy(cardOnTable, heldCard); return(heldCard); }
/// <summary> /// Called on each frame when i drag card /// </summary> public void DraggedCardUpdate(Vector2 mousePos, CardRoot cardRoot) { //if it was dragged insude table rect if (RectTransformUtility.RectangleContainsScreenPoint(TableDropZone, mousePos)) { FoolObservable.OnDraggedCardUpdate(mousePos, cardRoot, true); } else { FoolObservable.OnDraggedCardUpdate(mousePos, cardRoot, false); } }
//todo show discarded card backs /// <summary> /// Animates moving card to discardpile (отбой) /// </summary> public void AnimateRemoveCardToDiscardPile(CardRoot cardRoot, float delay = 0f) { if (cardRoot == null) { return; } //bug null reference if other player leaves float duration = 1f; cardRoot.AnimateMoveToPosition(transform.position, duration, delay); cardRoot.DestroyCard(delay + duration); }
/// <summary> /// Animate taking cards from talon one by one with slight delay between every card /// </summary> private IEnumerator AnimateCardsFromTalon(int cardsN) { for (int i = 0; i < cardsN; i++) { //Spawn card as child of this trahsform. CardRoot cardRootScript = SpawnCardInHand(); cardRootScript.transform.SetParent(_talonTransform, false); //Init animation cardRootScript.AnimateMoveToTransform(HandContainer); yield return(new WaitForSeconds(0.1f)); //StaticParameters.TalonAnimationDelay); } //UpdateCardsInHand(); }
/// <summary> /// If me dropped card on table while defending then check if action is possible /// </summary> protected bool CanCoverThisCardWith(CardRoot cardOnTable, CardRoot heldCard) { //if table is empty if (TableIsEmpty || AllCardsCovered) { // say 'you are defending' GameplayMessageManager.Instance.ShowFullScreenText("На вас ходят"); return(false); } //if i passed if (DefenderPassedPriority) { // say 'you passed' GameplayMessageManager.Instance.ShowFullScreenText("Вы решили брать"); return(false); } bool cardOnTableIsTrump = cardOnTable.IsTrump(); bool droppedCardIsTrump = heldCard.IsTrump(); if (!cardOnTableIsTrump && droppedCardIsTrump) { return(true); } if (cardOnTableIsTrump && droppedCardIsTrump && cardOnTable.Value < heldCard.Value) { return(true); } if (!cardOnTableIsTrump && !droppedCardIsTrump && cardOnTable.Suit == heldCard.Suit && cardOnTable.Value < heldCard.Value) { return(true); } // else { // say 'you can not defend with this card' GameplayMessageManager.Instance.ShowFullScreenText("Вы не можете побиться этой картой"); return(false); } }
/// <summary> /// Animates covering card on table with held card /// </summary> protected void CoverThisCardWith(CardRoot cardOnTable, CardRoot heldCard) { //TODO save action in buffer for in case if server will say no so we can ctrl+z this action // Beat it AnimateCoverCardBy(cardOnTable, heldCard); heldCard.InteractionDisable(); // add to list cardsOnTableCovering.Add(heldCard); //Set cards parameters cardOnTable.IsCoveredByACard = true; cardOnTable.CoveredByCard = heldCard; // Send to server ClientSendPackets.Send_CoverCardOnTable(cardOnTable.CardCode, heldCard.CardCode); TableUpdated(); }
/// <summary> /// Called on each frame by InputManger when i drag card /// Animates cards that can be covered when you are defending /// </summary> public override void OnDraggedCardUpdate(Vector2 mousePos, CardRoot heldCardRoot, bool inTableZone) { //Am i defending or attacking? if (!MeDefending) { return; } //if dragged above a table if (inTableZone) { //Choose cards that can be covered with grabbed card var cardsCanBeTargeted = GetCardsCanBeTargetedBy(heldCardRoot); if (cardsCanBeTargeted.Count == 0) { return; } //Chose closest beatable card var closestCard = GetClosestCardOnTableTo(mousePos); //Animate them foreach (var cardCanBeTargeted in cardsCanBeTargeted) { if (cardCanBeTargeted == closestCard) { cardCanBeTargeted.AnimateTargetedGlow(); } else { cardCanBeTargeted.AnimateCanBeTargetedGlow(); } } } else { //if not in table: idle animation StopAnimationGlowingCardsOnTable(); } }
/// <summary> /// Other player covered some card on table /// </summary> public override void OnOtherPlayerCoversCard(long coveredPlayerId, int slotN, string cardOnTableCode, string cardDroppedCode) { //find card on table CardRoot cardOnTable = cardsOnTable.Find(c => !c.IsCoveredByACard && c.CardCode == cardOnTableCode); if (cardOnTable == null) { Debug.LogWarning("Trying to cover non existing card: " + cardOnTableCode + " by " + cardDroppedCode, this); return; } var droppedCardRoot = AnimateEnemyCoversCard(slotN, cardOnTable, cardDroppedCode); //set state cardOnTable.IsCoveredByACard = true; cardsOnTableCovering.Add(droppedCardRoot); TableUpdated(); }
/// <summary> /// Adds card to table from my hand and animates it /// </summary> protected void MeAddCardToTable(CardRoot heldCard) { //disable interactions heldCard.InteractionDisable(); //ADD CARD cardsOnTable.Add(heldCard); //init animation AnimateAddCardOnTableFromMyHand(heldCard); //TODO save action in buffer for in case if server will say no so we can ctrl+z this action //Send to server ClientSendPackets.Send_DropCardOnTable(heldCard.CardCode); // if my hand is empty then count as pass if (StaticRoomData.MyPlayer.CardsNumber == 0 && MeLeadAttack) { AttackerPassedPriority = true; } TableUpdated(); }
/// <summary> /// Returns physically closest card to mousePos /// </summary> protected CardRoot GetClosestCardOnTableTo(Vector2 mousePos) { CardRoot closest = null; float minDistance = float.MaxValue; foreach (var cardOnTable in cardsOnTable) { if (cardOnTable.IsCoveredByACard) { continue; } float dist = Vector2.Distance(cardOnTable.transform.position, mousePos); if (dist < minDistance) { minDistance = dist; closest = cardOnTable; } } return(closest); }
/// <summary> /// Find cards which can be targeted (has lower value and same suit) /// </summary> protected List <CardRoot> GetCardsCanBeTargetedBy(CardRoot heldCard) { //find cards that wasn't covered already var cardsCanBeTargeted = cardsOnTable.Where(card => !card.IsCoveredByACard); //held card is a trump? if (heldCard.IsTrump()) { //find cards that ... return(cardsCanBeTargeted.Where( card => !card.IsTrump() || //.. are not trump (card.IsTrump() && card.Value < heldCard.Value)) //.. or cheaper trump .ToList()); // return as list } else //held card is not a trump { //find cards that ... return(cardsCanBeTargeted.Where( card => card.Value < heldCard.Value && //.. cheaper than held card card.Suit == heldCard.Suit) //.. and has same suit .ToList()); // return as list } }
public void RemoveCardFromHand(CardRoot cardRoot) { CardsInHand.Remove(cardRoot); }
protected abstract CardRoot AnimateEnemyCoversCard(int slotN, CardRoot cardOnTable, string cardCodeHeld);
protected abstract void AnimateCoverCardBy(CardRoot cardOnTable, CardRoot heldCard);
protected abstract void AnimateAddCardOnTableFromMyHand(CardRoot cardRoot);
protected override void AnimateAddCardOnTableFromMyHand(CardRoot cardRoot) { _myPlayerInfoDisplay.RemoveCardFromHand(cardRoot); _tableDisplay.AnimateDropCardOnTable(cardRoot); }
/// <summary> /// Animates drop card on table /// </summary> public void AnimateDropCardOnTable(CardRoot cardRoot) { cardRoot.AnimateMoveToTransform(this.transform); LayoutRebuilder.ForceRebuildLayoutImmediate(this.transform as RectTransform); }
/// <summary> /// Animates cover existing card on table /// </summary> public void AnimateCoverCardOnTable(CardRoot cardOnTable, CardRoot cardHeld) { cardHeld.AnimateMoveToTransform(cardOnTable.transform); LayoutRebuilder.ForceRebuildLayoutImmediate(this.transform as RectTransform); }
/// <summary> /// Sent by InputManager when i drag card arund the screen /// </summary> public virtual void OnDraggedCardUpdate(Vector2 mousePos, CardRoot heldCardRoot, bool inTableZone) { }
/// <summary> /// Sent by InputManager when i release card from hand /// </summary> public virtual void OnCardDroppedOnTableByMe(CardRoot heldCard) { }