/// <summary> /// Prevents given card from being played. /// Returns it to user's hand. /// </summary> private void CancelPlay(MatchMessageCardCanceled message) { CardGrabber grabber = _cardsInHand[message.CardSlotIndex]; grabber.OnDragStarted += StartCardDrag; grabber.OnCardReturned += ReturnCard; grabber.OnCardPlayed += PlayCard; grabber.CancelPlay(); }
/// <summary> /// Reads match messages sent by other players, and fires locally events basing on opCode. /// </summary> /// <param name="opCode"></param> /// <param name="messageJson"></param> public void ReceiveMatchStateHandle(long opCode, string messageJson) { //Choosing which event should be invoked basing on opCode, then parsing json to MatchMessage class and firing event switch ((MatchMessageType)opCode) { //UNITS case MatchMessageType.UnitSpawned: MatchMessageUnitSpawned matchMessageUnitSpawned = MatchMessageUnitSpawned.Parse(messageJson); OnUnitSpawned?.Invoke(matchMessageUnitSpawned); break; case MatchMessageType.UnitMoved: MatchMessageUnitMoved matchMessageUnitMoved = MatchMessageUnitMoved.Parse(messageJson); OnUnitMoved?.Invoke(matchMessageUnitMoved); break; case MatchMessageType.UnitAttacked: MatchMessageUnitAttacked matchMessageUnitAttacked = MatchMessageUnitAttacked.Parse(messageJson); OnUnitAttacked?.Invoke(matchMessageUnitAttacked); break; //SPELLS case MatchMessageType.SpellActivated: MatchMessageSpellActivated matchMessageSpellActivated = MatchMessageSpellActivated.Parse(messageJson); OnSpellActivated?.Invoke(matchMessageSpellActivated); break; //CARDS case MatchMessageType.CardPlayRequest: if (_connection.BattleConnection.HostId == _connection.Account.User.Id) { MatchMessageCardPlayRequest matchMessageCardPlayRequest = MatchMessageCardPlayRequest.Parse(messageJson); OnCardRequested?.Invoke(matchMessageCardPlayRequest); } break; case MatchMessageType.CardPlayed: MatchMessageCardPlayed matchMessageCardPlayed = MatchMessageCardPlayed.Parse(messageJson); OnCardPlayed?.Invoke(matchMessageCardPlayed); break; case MatchMessageType.CardCanceled: MatchMessageCardCanceled matchMessageCardCancelled = MatchMessageCardCanceled.Parse(messageJson); OnCardCancelled?.Invoke(matchMessageCardCancelled); break; case MatchMessageType.StartingHand: MatchMessageStartingHand matchMessageStartingHand = MatchMessageStartingHand.Parse(messageJson); OnStartingHandReceived?.Invoke(matchMessageStartingHand); break; } }
/// <summary> /// Cancels played card and returns it to its owner's hand. /// </summary> private void SendCardCanceledMessage(MatchMessageCardPlayRequest message) { MatchMessageCardCanceled cardCanceled = new MatchMessageCardCanceled(message.PlayerId, message.CardSlotIndex); if (message.PlayerId == _connection.Session.UserId) { _stateManager.SendMatchStateMessageSelf(MatchMessageType.CardCanceled, cardCanceled); } else { _stateManager.SendMatchStateMessage(MatchMessageType.CardCanceled, cardCanceled); } }