Esempio n. 1
0
        /// <summary>
        /// Sends information about fireball activation to other players through Nakama server.
        /// Use only on host!
        /// </summary>
        /// <param name="node"></param>
        /// <param name="impactedUnits"></param>
        /// <param name="playerId"></param>
        private void SendSpellActivatedRequest(Node node, List <Unit> impactedUnits, string playerId)
        {
            List <int> impactedUnitsIds        = impactedUnits.Select(u => u.Id).ToList();
            MatchMessageSpellActivated message = new MatchMessageSpellActivated(playerId, SpellType, node.Position.x, node.Position.y, impactedUnitsIds);

            _stateManager.SendMatchStateMessage(MatchMessageType.SpellActivated, message);
            _stateManager.SendMatchStateMessageSelf(MatchMessageType.SpellActivated, message);
        }
        /// <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>
        /// Resolves spell activation on given node
        /// </summary>
        /// <param name="message"></param>
        private void ResolveSpellActivation(MatchMessageSpellActivated message)
        {
            ISpell spell = GetNonactiveSpellOfType(message.SpellType);

            _nonactiveSpells.Remove(spell);
            _activeSpells.Add(spell);

            spell.OnHide += HideSpell;

            spell.Show(Scene02BattleController.Instance.Nodes[message.NodeX, message.NodeY]);

            List <Unit> impactedUnits = new List <Unit>();

            foreach (int unitId in message.ImpactedUnitsIds)
            {
                impactedUnits.Add(_unitsManager.GetUnit(unitId));
            }

            spell.MakeImpactOnUnits(impactedUnits);
        }