Beispiel #1
0
    private void Factory_OnUnitSpawned(UnitFactory arg1, GameObject arg2)
    {
        Unit unit = arg2.GetComponent <Unit>();

        unit.OnKill += Unit_OnKill;
        OnUnitSpawned?.Invoke(this, arg1, unit);
    }
    private void Spawn()
    {
        Vector3    pos = GetLocalRandomSpawnPosition() + transform.position;
        GameObject go  = _team.Instantiate(UnitPrefab, pos, transform.rotation);

        go.BroadcastMessage("SetWaypoint", _nearestWaypoint);
        OnUnitSpawned?.Invoke(this, go);
    }
Beispiel #3
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;
            }
        }
    private GameObject Spawn()
    {
        Vector3    basePos = SpawnRelativeToRoot ? _root.position : transform.position;
        Quaternion baseRot = SpawnRelativeToRoot ? _root.rotation : transform.rotation;
        Vector3    pos     = GetLocalRandomSpawnPosition() + basePos;
        GameObject go      = _team.Instantiate(SelectUnitPrefab(), pos, baseRot);

        OnUnitSpawned?.Invoke(this, go);
        return(go);
    }
        /// <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;
            }
        }
Beispiel #6
0
    public void SpawnEnemy(Graph graph, GameObject enemy, int xIndex, int yIndex, string name)
    {
        Node       node     = graph.GetNodeAt(xIndex, yIndex);
        Unit       newUnit  = new Unit(xIndex, yIndex, node, UnitType.enemy, name);
        GameObject instance = Instantiate(enemy, node.position, Quaternion.identity, this.transform);

        SetUnitWeapons(newUnit);
        enemyUnitView.Init(newUnit);
        OnUnitSpawned?.Invoke(this, new OnUnitSpawnedEventArgs {
            newUnit = newUnit, instance = instance, node = node
        });
    }
Beispiel #7
0
    public void SpawnPlayer(Graph graph, GameObject player, int xIndex, int yIndex, string name)
    {
        ItemDatabase itemDatabase = FindObjectOfType <ItemDatabase>();

        itemDatabase.BuildDatabase();
        Node       node     = graph.GetNodeAt(xIndex, yIndex);
        Unit       newUnit  = new Unit(xIndex, yIndex, node, UnitType.player, name);
        GameObject instance = Instantiate(player, node.position, Quaternion.identity, this.transform);

        SetUnitWeapons(newUnit);
        playerUnitView.Init(newUnit);
        OnUnitSpawned?.Invoke(this, new OnUnitSpawnedEventArgs {
            newUnit = newUnit, instance = instance, node = node
        });
    }
        /// <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;
            }
        }
Beispiel #9
0
    protected void Update()
    {
        if (spawnQueue.Count > 0 || objectToSpawn != null)
        {
            if (objectToSpawn == null)
            {
                currentSpawnQueueItem = spawnQueue.Dequeue();
                objectToSpawn         = currentSpawnQueueItem.thingToSpawn;
                UICoolDownImage       = currentSpawnQueueItem.UICooldownImage;
                UICoolDownImage.color = new Color(1, 0, 0, (float)122 / 255);
                hasPlayedAudio        = false;
                queueLength           = currentSpawnQueueItem.queueLength;
                currentSpawnQueueItem.Dequeue();
                if (FactoryDoor != null)
                {
                    FactoryDoor.TurnOnLights();
                }
            }
            spawntimerCurr += Time.deltaTime;

            if (spawntimerCurr > spawntimerMax)
            {
                spawntimerCurr = spawntimerMax;
                if (!manuallyPlaced)
                {
                    spawntimerCurr = 0;
                    UICoolDownImage.rectTransform.sizeDelta = new Vector2(UICoolDownImage.rectTransform.sizeDelta.x, 0);

                    MyObject tmp = Instantiate(objectToSpawn, spawnPoint.position, Quaternion.identity);
                    tmp.Activate();
                    OnUnitSpawned?.Invoke(tmp);
                    objectToSpawn         = null;
                    currentSpawnQueueItem = null;
                    tmp.team = GetComponent <MyObject>().team;
                    tmp.GetComponent <UnityEngine.AI.NavMeshAgent>().destination = waypointLocation.position;

                    if (FactoryDoor != null)
                    {
                        FactoryDoor.OpenDoor();
                    }
                }
                else
                {
                    if (!hasPlayedAudio)
                    {
                        hasPlayedAudio        = true;
                        UICoolDownImage.color = new Color(0, 1, 0, (float)122 / 255);
                        constructionComplete.Play();
                        //UICoolDownImage.transform.parent.SetAsLastSibling();
                        iTween.PunchScale(UICoolDownImage.transform.parent.gameObject, new Vector3(2f, 2f, 2f), 1f);
                    }
                }
            }

            float spriteSizeFrac = (spawntimerCurr / spawntimerMax);
            UICoolDownImage.rectTransform.sizeDelta = new Vector2(UICoolDownImage.rectTransform.sizeDelta.x, spriteMaxSize * spriteSizeFrac);
        }
        else
        {
            spawntimerCurr = 0;
        }
    }