private void _handleIngredientCardDrop(CustomerCardView customerView) { Debug.Log("PlayField Received drop of: " + customerView.cardData.titleKey); if (_draggedIngredient == null) { return; } CustomerCardState customerState = customerView.cardState; IngredientCardData ingredientData = _draggedIngredient.cardData as IngredientCardData; if (!customerState.CanAcceptCard(ingredientData)) { return; } MoveRequest move = MoveRequest.Create( activePlayer.index, _draggedIngredient.handIndex, customerState.slotIndex); Assert.IsNotNull(onPlayOnCustomer); _draggedIngredient.isDropSuccessfull = onPlayOnCustomer(move); if (_draggedIngredient.isDropSuccessfull) { _droppedCustomer = customerView; } }
public static BaseCardData CreateFromJson(JToken cardToken) { string type = cardToken.Value <string>("cardType"); string id = cardToken.Value <string>("id"); string titleKey = cardToken.Value <string>("titleKey"); string iconName = cardToken.Value <string>("iconName"); if (type == CardType.CUSTOMER) { CustomerCardData cData = new CustomerCardData(); cData.cardType = type; cData.id = id; cData.titleKey = titleKey; cData.iconName = iconName; cData.baseReward = cardToken.Value <int>("baseReward"); cData.meatRequirement = cardToken.Value <int>("meatRequirement"); cData.veggieRequirement = cardToken.Value <int>("veggieRequirement"); cData.toppingRequirement = cardToken.Value <int>("toppingRequirement"); string modifier = cardToken.Value <string>("modifier"); cData.modifier = (modifier == null) ? "" : modifier; return(cData); } else { IngredientCardData iData = new IngredientCardData(); iData.cardType = type; iData.id = id; iData.titleKey = titleKey; iData.iconName = iconName; iData.foodValue = cardToken.Value <int>("foodValue"); return(iData); } }
public bool PlayCardOnCustomer(MoveRequest move) { if (isGameOver) { Debug.LogError("Game is over!"); return(false); } if (!activeCustomerSet.IsSlotActive(move.customerSlot)) { return(false); } PlayerState playerState = playerGroup.GetPlayerByIndex(move.playerIndex); IngredientCardData ingredientData = playerState.hand.GetCard(move.handSlot); CustomerCardState customerState = activeCustomerSet.GetCustomerByIndex(move.customerSlot); if (playerState.cardsPlayed >= PlayerState.kMaxCardsPerTurn) { return(false); } if (!customerState.CanAcceptCard(ingredientData)) { return(false); } _playCard(move, playerState, customerState, ingredientData); _playCardEvent(); return(true); }
public IngredientCardData PopCard(int index) { _boundsCheck(index); IngredientCardData tmpCard = _cards[index]; _cards[index] = null; return(tmpCard); }
public IngredientCardData ReplaceCard(int index, IngredientCardData newCard) { _boundsCheck(index); IngredientCardData oldCard = _cards[index]; _cards[index] = newCard; return(oldCard); }
private void _setupIngredientView(int handSlot, IngredientCardData cardData) { PlayFieldViewUtils.SetupIngredientView( _playerHandView, handSlot, cardData, _handleIngredientCardBeginDrag, _handleEndDrag); }
private void _setupHandViewFromPlayer(int playerIndex) { PlayerState player = _matchState.playerGroup.GetPlayerByIndex(playerIndex); for (int i = 0; i < PlayerState.kHandSize; ++i) { IngredientCardData ingredientCard = player.hand.GetCard(i); _setupIngredientView(i, ingredientCard); } }
private void _setIngredientCard(IngredientCardData ingredientData) { CardResourceBank cardBank = Singleton.instance.cardResourceBank; _backgroundImg.sprite = cardBank.GetIngredientBG(ingredientData.cardType); _cardTypeIcon.sprite = cardBank.GetIngredientTypeIcon(ingredientData.cardType); _foodValueLbl.text = string.Format("{0}", ingredientData.foodValue); _foodValueLbl.color = (ingredientData.foodValue > 0) ? Color.white : Color.red; _cardIcon.sprite = cardBank.GetMainIcon(ingredientData.iconName); }
public static void AnimateOtherPlayerMoves(List <MoveResult> moveList, GameMatchState state, ActiveCustomersView customersView, Transform parent, Action <Vector3> slamCallback, TweenCallback callback) { Assert.IsNotNull(moveList); //Assert.IsTrue(moveList.Count > 0); Sequence allPlayedCards = DOTween.Sequence(); //MoveResult[] moveResults = new MoveResult[PlayerGroup.kMaxPlayerCount]; int count = moveList.Count; for (int i = 0; i < count; ++i) { MoveRequest request = moveList[i].request; MoveResult result = moveList[i]; CustomerCardView customerView = customersView.GetCardByIndex(request.customerSlot); IngredientCardData cardData = state.GetCardById(result.usedIngredient) as IngredientCardData; if (cardData == null) { Debug.LogError("Card data is null! cant animate other player card"); continue; } IngredientCardView ingredientView = Singleton.instance.cardResourceBank.CreateCardView( cardData, parent) as IngredientCardView; ingredientView.transform.position = parent.transform.position; Vector3 delta = (Camera.main.transform.position - customerView.transform.position).normalized; Vector3 targetPos = customerView.transform.position + delta; Tween moveTo = ingredientView.transform.DOMove(targetPos, 0.75f); moveTo.SetEase(Ease.OutQuad); ViewFactory vf = Singleton.instance.gui.viewFactory; Tween zoomSlam = ZoomSlamTween(ingredientView, customerView, false, () => { vf.RemoveView(ingredientView); if (slamCallback != null) { slamCallback(ingredientView.transform.position); } }, null); Sequence cardTween = DOTween.Sequence(); cardTween.Append(moveTo); cardTween.Insert(moveTo.Duration(false) * 0.75f, zoomSlam); allPlayedCards.Insert(i * (cardTween.Duration() * 0.95f), cardTween); } allPlayedCards.OnComplete(callback); allPlayedCards.Play(); }
public bool AddIngredient(IngredientCardData card, int playerIndex) { if (!CanAcceptCard(card)) { return(false); } _ingredientList.Add(card); lastPlayerIndex = playerIndex; return(true); }
public void Undo() { int count = _savedCards.Count; for (int i = count - 1; i >= 0; --i) // done in reverse to maintain the proper deck order { int index = _savedIndices[i]; IngredientCardData savedCard = _savedCards[i]; IngredientCardData oldCard = _hand.ReplaceCard(index, savedCard); Assert.IsNotNull(oldCard); _ingredientDeck.Push(oldCard); } }
private void _playCard( MoveRequest moveRequest, PlayerState playerState, CustomerCardState customer, IngredientCardData ingredient) { ICommand command = PlayCardCommand.Create( moveRequest, playerState, customer, ingredient); _commandFactory.Execute(command); }
public static PlayCardCommand Create( MoveRequest moveRequest, PlayerState playerState, CustomerCardState customer, IngredientCardData ingredient) { PlayCardCommand command = new PlayCardCommand(); command._customer = customer; command._ingredient = ingredient; command._playerState = playerState; command._moveRequest = moveRequest; return(command); }
private void _setupPlayerHands(List <PlayerState> playerList, CardDeck ingredientDeck) { PlayerGroup group = PlayerGroup.Create(playerList); for (int i = 0; i < group.playerCount; ++i) { for (int j = 0; j < PlayerState.kHandSize; ++j) { IngredientCardData cardData = ingredientDeck.Pop() as IngredientCardData; PlayerState playerState = group.GetPlayerByIndex(i); playerState.hand.SetCard(j, cardData); } } playerGroup = group; }
private void _handleIngredientCardHover(CustomerCardView customerView) { if (_draggedIngredient == null) { return; } if (!_draggedIngredient.isDragging) { return; } CustomerCardState customerState = customerView.cardState; IngredientCardData ingredientData = _draggedIngredient.cardData as IngredientCardData; if (customerState.CanAcceptCard(ingredientData)) { _activeHoverFX(customerView.transform.position); } }
public void Execute() { _savedCards.Clear(); _savedIndices.Clear(); int count = PlayerHand.kDefaultHandSize; for (int i = 0; i < count; ++i) { IngredientCardData cardData = _hand.GetCard(i); if (cardData == null) { IngredientCardData newCard = _ingredientDeck.Pop() as IngredientCardData; IngredientCardData oldData = _hand.ReplaceCard(i, newCard); _savedCards.Add(oldData); _savedIndices.Add(i); } } }
public static void SetupIngredientView( PlayerHandView handView, int handSlot, IngredientCardData cardData, Action <IngredientCardView> onBeginDrag, Action onEndDrag) { if (cardData == null) { Debug.LogWarning("Card Data is null!"); handView.RemoveCardByIndex(handSlot); // TODO: Do this On card slam instead of after the fact return; } IngredientCardView view = handView.GetCardAtIndex(handSlot); if (view == null) { view = Singleton.instance.cardResourceBank.CreateCardView( cardData, handView.cardSlotList[handSlot]) as IngredientCardView; } view.cardData = cardData; view.eventTrigger.triggers.Clear(); EventTrigger.Entry OnBeginDrag = new EventTrigger.Entry(); OnBeginDrag.eventID = EventTriggerType.BeginDrag; OnBeginDrag.callback.AddListener((e) => onBeginDrag(view)); view.eventTrigger.triggers.Add(OnBeginDrag); EventTrigger.Entry OnEndDrag = new EventTrigger.Entry(); OnEndDrag.eventID = EventTriggerType.EndDrag; OnEndDrag.callback.AddListener((e) => onEndDrag()); view.eventTrigger.triggers.Add(OnEndDrag); handView.SetCardAtIndex(handSlot, view); }
private void _handleIngredientCardDrop(CustomerCardView customerView) { Debug.Log("LocalPlayer: " + localPlayer.index + ", Active Player: " + activePlayer.index); if (localPlayer != activePlayer) { return; } if (_draggedIngredient == null) { return; } CustomerCardState customerState = customerView.cardState; IngredientCardData ingredientData = _draggedIngredient.cardData as IngredientCardData; if (!customerState.CanAcceptCard(ingredientData)) { return; } MoveRequest move = MoveRequest.Create( localPlayer.index, _draggedIngredient.handIndex, customerState.slotIndex); Assert.IsNotNull(onPlayOnCustomer); _draggedIngredient.isDropSuccessfull = onPlayOnCustomer(move); if (_draggedIngredient.isDropSuccessfull) { _isAnimating = true; _droppedCustomer = customerView; _moveRequests.Add(move); } }
public void SetCard(int index, IngredientCardData card) { _boundsCheck(index); _cards[index] = card; }
public void RemoveIngredient(IngredientCardData card, int playerIndex) { _ingredientList.Remove(card); lastPlayerIndex = playerIndex; }
public bool CanAcceptCard(IngredientCardData card) { return(GetIngredientReqLeft(card.cardType) > 0); }