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; } }
private void _onCardDropFinished() { int handIndex = _draggedIngredient.handIndex; int customerIndex = _droppedCustomer.cardState.slotIndex; _draggedIngredient = null; _playerHandView.RemoveCardByIndex(handIndex); Assert.IsNotNull(onResolveScore); bool customerFinished = onResolveScore(customerIndex); if (customerFinished) { _playfieldView.SetPlayerScore(activePlayer.index, activePlayer.score); CustomerCardState newState = _matchState.activeCustomerSet.GetCustomerByIndex(customerIndex); _setupCustomerView(customerIndex, newState); } _playerHandView.blockCardDrag = false; _isAnimating = false; if (_timerEndedTurn) { _endPlayerTurn(true); _timerEndedTurn = false; } }
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 static CustomerCardState Create(CustomerCardData cardData) { CustomerCardState state = new CustomerCardState(); state.cardData = cardData; state.lastPlayerIndex = -1; return(state); }
public void SetCustomerAtIndex(int slotIndex, CustomerCardState cardState) { _boundsCheck(slotIndex); if (cardState != null) { cardState.slotIndex = slotIndex; } _activeCustomerList[slotIndex] = cardState; }
private void _setupCustomerView(int customerSlot, CustomerCardState cardState) { PlayFieldViewUtils.SetupCustomerView( _activeCustomersView, customerSlot, cardState, _handleIngredientCardDrop, _handleIngredientCardHover, _deactiveHoverFX); }
public static ResolveScoreCommand Create( PlayerState player, CustomerCardState customer) { ResolveScoreCommand command = new ResolveScoreCommand(); command._player = player; command._customer = customer; return(command); }
public void Undo() { _activePlayer.deadCustomerStack.Pop(); CustomerCardState undoState = _customerSet.GetCustomerByIndex(_slotIndex); if (undoState != null) { _customerDeck.Push(undoState.cardData); } _customerSet.SetCustomerAtIndex(_slotIndex, _savedCustomerState); }
private bool _resolveCustomerCards( CustomerCardState customer, PlayerState player) { if (customer.isComplete) { ICommand resolve = ResolveScoreCommand.Create(player, customer); _commandFactory.Execute(resolve); return(true); } return(false); }
private void _setupActiveCustomersView(Transform parent) { viewFactory.CreateAsync <ActiveCustomersView>("ActiveCustomersView", (view) => { _activeCustomersView = (ActiveCustomersView)view; for (int i = 0; i < ActiveCustomerSet.kMaxActiveCustomers; ++i) { CustomerCardState state = _matchState.activeCustomerSet.GetCustomerByIndex(i); _setupCustomerView(i, state); } }, parent ); }
private void _setupCustomerCards(CardDeck customerDeck) { ActiveCustomerSet customers = ActiveCustomerSet.Create(); // Intentionally not using commands here, as we don't want to be able to // undo the first set of customers for (int i = 0; i < ActiveCustomerSet.kMaxActiveCustomers; ++i) { CustomerCardData cardData = customerDeck.Pop() as CustomerCardData; CustomerCardState cardState = CustomerCardState.Create(cardData); customers.SetCustomerAtIndex(i, cardState); } activeCustomerSet = customers; }
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 _playCard( MoveRequest moveRequest, PlayerState playerState, CustomerCardState customer, IngredientCardData ingredient) { ICommand command = PlayCardCommand.Create( moveRequest, playerState, customer, ingredient); _commandFactory.Execute(command); }
public bool ResolveCustomerCard(int customerSlotIndex, int playerIndex) { PlayerState player = playerGroup.GetPlayerByIndex(playerIndex); Assert.IsNotNull(player); CustomerCardState customerState = activeCustomerSet.GetCustomerByIndex(customerSlotIndex); bool result = _resolveCustomerCards(customerState, player); if (result) { _createNewCustomer(customerSlotIndex); } _resolveMoveEvent(result); return(result); }
public void Execute() { _savedCustomerState = _customerSet.GetCustomerByIndex(_slotIndex); _activePlayer.deadCustomerStack.Push(_savedCustomerState.cardData); CustomerCardData card = _customerDeck.Pop() as CustomerCardData; if (card != null) { CustomerCardState newState = CustomerCardState.Create(card); _customerSet.SetCustomerAtIndex(_slotIndex, newState); } else { _customerSet.SetCustomerAtIndex(_slotIndex, null); } }
static public void SetupCustomerView( ActiveCustomersView customersView, int customerIndex, CustomerCardState cardState, Action <CustomerCardView> onCardDrop, Action <CustomerCardView> onPointerEnter, Action onPointerExit) { if (cardState == null) { Debug.LogWarning("Card State is null!"); customersView.RemoveCardByIndex(customerIndex); // TODO: Do this On card slam instead of after the fact return; } CustomerCardView view = customersView.GetCardByIndex(customerIndex); if (view == null) { view = (CustomerCardView)Singleton.instance.cardResourceBank.CreateCardView( cardState.cardData, customersView._activeSlotList[customerIndex]); } view.cardState = cardState; view.eventTrigger.triggers.Clear(); EventTrigger.Entry OnDrop = new EventTrigger.Entry(); OnDrop.eventID = EventTriggerType.Drop; OnDrop.callback.AddListener((e) => onCardDrop(view)); view.eventTrigger.triggers.Add(OnDrop); EventTrigger.Entry OnHoverBegin = new EventTrigger.Entry(); OnHoverBegin.eventID = EventTriggerType.PointerEnter; OnHoverBegin.callback.AddListener((e) => onPointerEnter(view)); view.eventTrigger.triggers.Add(OnHoverBegin); EventTrigger.Entry OnHoverEnd = new EventTrigger.Entry(); OnHoverEnd.eventID = EventTriggerType.PointerExit; OnHoverEnd.callback.AddListener((e) => onPointerExit()); view.eventTrigger.triggers.Add(OnHoverEnd); customersView.SetCardByIndex(customerIndex, view); }
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); } }
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); } }