示例#1
0
        /// <summary>
        /// This method is used by host to invoke locally event connected with match message which is sent to other players.
        /// Should be always runned on host client after sending any message, otherwise some of the game logic would not be runned on host game instance.
        /// Don't use this method when client is not a host!
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="opCode"></param>
        /// <param name="message"></param>
        public void SendMatchStateMessageSelf <T>(MatchMessageType opCode, T message)
            where T : MatchMessage <T>
        {
            //Choosing which event should be invoked basing on opCode and firing event
            switch (opCode)
            {
            //GAME
            case MatchMessageType.MatchEnded:
                OnGameEnded?.Invoke(message as MatchMessageGameEnded);
                break;

            //UNITS
            case MatchMessageType.UnitSpawned:
                OnUnitSpawned?.Invoke(message as MatchMessageUnitSpawned);
                break;

            case MatchMessageType.UnitMoved:
                OnUnitMoved?.Invoke(message as MatchMessageUnitMoved);
                break;

            case MatchMessageType.UnitAttacked:
                OnUnitAttacked?.Invoke(message as MatchMessageUnitAttacked);
                break;

            //SPELLS
            case MatchMessageType.SpellActivated:
                OnSpellActivated?.Invoke(message as MatchMessageSpellActivated);
                break;

            //CARDS
            case MatchMessageType.CardPlayRequest:
                OnCardRequested?.Invoke(message as MatchMessageCardPlayRequest);
                break;

            case MatchMessageType.CardPlayed:
                OnCardPlayed?.Invoke(message as MatchMessageCardPlayed);
                break;

            case MatchMessageType.CardCanceled:
                OnCardCancelled?.Invoke(message as MatchMessageCardCanceled);
                break;

            case MatchMessageType.StartingHand:
                OnStartingHandReceived?.Invoke(message as MatchMessageStartingHand);
                break;

            default:
                break;
            }
        }
示例#2
0
    public IEnumerator FollowPath(List <Node> path, Unit unit, GameObject unitView, bool isEnemySelected)
    {
        Cursor.visible = false;
        Node startNode = path[0];

        foreach (Node node in path)
        {
            yield return(new WaitForSeconds(moveDelay));

            if (node != startNode)
            {
                Graph graph = FindObjectOfType <Graph>();
                m_graph = graph;
                float distanceBetweenNodes = m_graph.GetNodeDistance(node.previous, node);
                unit.actionPoints -= distanceBetweenNodes;
            }

            if (isEnemySelected)
            {
                UpdateUnitPosData(unit, unitView, node);
            }

            if (!isEnemySelected)
            {
                UpdateUnitPosData(unit, unitView, node);
            }
        }
        Unit currentUnit = unit;
        Node currentNode = unit.currentNode;

        unit.hasMoved = true;
        if (unit.actionPoints < 1)
        {
            unit.isWaiting = true;
        }
        OnUnitMoved?.Invoke(this, new OnUnitMovedEventArgs {
            startNode = startNode, currentUnit = currentUnit, endNode = currentNode
        });
        m_playerManager.DeselectUnit(unit);
        Cursor.visible = true;
    }
示例#3
0
        private void PerformAction(Action action, Unit unit, bool alreadyPerfomedType)
        {
            switch (action.Type)
            {
            case ActionType.Move:
                if (CanMove(unit, action.Direction))
                {
                    unit.Move(action.Direction, alreadyPerfomedType);
                    OnUnitMoved?.Invoke(this, new MoveEventArgs {
                        Unit = unit
                    });
                }
                break;

            case ActionType.Attack:
                Unit target = GetTarget(unit, action);
                if (target != null)
                {
                    unit.Attack(target);
                    if (target.Health <= 0)
                    {
                        OnUnitDied?.Invoke(this, new DeathEventArgs {
                            Unit = target
                        });
                        if (GameConfig.BloodLust)
                        {
                            unit.Power += 2;
                        }
                    }
                }
                OnUnitAttacked?.Invoke(this, new AttackEventArgs {
                    Unit = unit, Target = target
                });
                break;
            }
        }
        /// <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)
        {
            if (GameStarted == false)
            {
                _incommingMessages.Enqueue(new IncommingMessageState(opCode, messageJson));
                return;
            }

            //Choosing which event should be invoked basing on opCode, then parsing json to MatchMessage class and firing event
            switch ((MatchMessageType)opCode)
            {
            //GAME
            case MatchMessageType.MatchEnded:
                MatchMessageGameEnded matchMessageGameEnded = MatchMessageGameEnded.Parse(messageJson);
                OnGameEnded?.Invoke(matchMessageGameEnded);
                break;

            //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 (IsHost == true)
                {
                    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;
            }
        }