Esempio n. 1
0
    private void MoveIfSomeoneIsTryingTo()
    {
        if (_levelController.TryingToMove() != null)
        {
            if (hit.collider.GetComponent <CellBehaviour>().entityIn == _levelController.TryingToMove() && Input.GetMouseButtonDown(0))
            {
                hit.collider.GetComponent <CellBehaviour>().entityIn.GetComponent <IdleOrder>().Idle = true; //cancelamos.
                soundManager.PlaySingle(soundManager.cancelActionSound);
            }

            //bool nodeMovementAccesible = _levelController.TryingToMove().gameObject.GetComponent<Troop>().ListPossibleMovementsContains(hit.collider.GetComponent<CellBehaviour>().PNode);
            bool nodeMovementAccesible = _levelController.TryingToMove().gameObject.GetComponent <Troop>().possibleMovements.Contains(hit.collider.GetComponent <CellBehaviour>().PNode);
            if (Input.GetMouseButtonDown(0) &&
                nodeMovementAccesible)
            {
                Debug.Log("CLICK IN A CELL TO MOVE. ");
                if (_levelController.TryingToMove().gameObject.GetComponent <Move>() != null)
                {
                    bool bloodEnough = _bloodController.GetCurrentPlayerBlood() >= _levelController.TryingToMove().gameObject.GetComponent <Attack>().bloodCost;
                    if (bloodEnough)
                    {
                        _bloodController.DecreasePlayerBloodValue(_levelController.TryingToMove().GetComponent <Move>().bloodCost);
                        soundManager.PlaySingle(soundManager.buttonPressedSound);
                        _levelController.TryingToMove().gameObject.GetComponent <Move>().OnGoingCell  = lastCellSelected;
                        _levelController.TryingToMove().gameObject.GetComponent <Move>().PathReceived = true;
                    }
                    else
                    {
                        Instantiate(Resources.Load <GameObject>("Prefabs/Popups/SimpleInfoPopup")).GetComponent <SimpleInfoPopupController>().SetPopup("PLAYER", "NOT ENOUGH\nBLOOD");
                    }
                }
            }
        }
    }
    public void SpawnEntity(CellBehaviour cell, ENTITY _entityToSpawn, Entity.Owner owner)
    {
        if (!_levelController.CheckIfCanSpawn(owner))
        {
            return;
        }

        GameObject entitySpawned    = null;
        GameObject entityToSpawn    = null;
        AudioClip  entitySpawnSound = null;

        switch (_entityToSpawn)
        {
        case ENTITY.None:
            Debug.Log("Antes debes seleccionar una tropa! ");
            FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().ShowButtons();
            soundManagerRef.PlaySingle(soundManagerRef.incorrectMovement);
            break;

        case ENTITY.Prisioner:
            lastTroopSpawned = ENTITY.Prisioner;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Prisioner.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.cageSoundSpawn;
            break;

        case ENTITY.Launcher:
            lastTroopSpawned = ENTITY.Launcher;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Launcher.ToString() + owner.ToString());
            entityToSpawn.GetComponentInChildren <ParticleSystem>().Stop();
            entitySpawnSound = soundManagerRef.launcherSoundSpawn;
            break;

        case ENTITY.Tank:
            lastTroopSpawned = ENTITY.Tank;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Tank.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.tankSoundSpawn;
            break;

        case ENTITY.Wall:
            lastTroopSpawned = ENTITY.Wall;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Wall.ToString() + owner.ToString());
            break;

        case ENTITY.Turret:
            lastTroopSpawned = ENTITY.Turret;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Turret.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.turretSoundSpawn;
            break;
        }

        if (entityToSpawn == null)
        {
            return;
        }
        int  bloodCost   = entityToSpawn.GetComponent <Entity>().bloodCost;
        bool bloodEnough = owner == Entity.Owner.Player ? bloodCost <= _bloodController.GetCurrentPlayerBlood() : bloodCost <= _bloodController.GetCurrentAIBlood();

        if (bloodEnough)
        {
            if (entityToSpawn != null)
            {
                soundManagerRef.PlaySingle(entitySpawnSound);
                entitySpawned = Instantiate(entityToSpawn, new Vector3(cell.transform.position.x, 0f, cell.transform.position.z), entityToSpawn.transform.rotation);
                entitySpawned.GetComponent <Entity>().SetEntity(owner);
                entitySpawned.GetComponent <Entity>().entityType = lastTroopSpawned;

                if (owner == Entity.Owner.Player)
                {
                    currentEntitySelected = ENTITY.None;
                }

                //Node node = _influenceMapComponent.GetNodeAtLocation(new Vector3(cell.transform.position.x, 1f, cell.transform.position.z));

                OnSpawnedTroop?.Invoke(entitySpawned.GetComponent <Entity>());

                if (owner == Entity.Owner.Player)
                {
                    _levelController.currentTroopsPlayerSpawned++;
                    _bloodController.DecreasePlayerBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }
                else if (owner == Entity.Owner.AI)
                {
                    Debug.Log("decreasing blood");
                    _levelController.currentTroopsAISpawned++;
                    _bloodController.DecreaseAIBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }

                FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().HideButtons();
                cell.GetComponent <CellBehaviour>().entityIn = entitySpawned.GetComponent <AbstractNPCBrain>();
                entitySpawned.GetComponent <Entity>().cell   = cell.GetComponent <CellBehaviour>();
            }
        }

        else
        {
            Instantiate(Resources.Load <GameObject>("Prefabs/Popups/SimpleInfoPopup")).GetComponent <SimpleInfoPopupController>().SetPopup("PLAYER", "NOT ENOUGH\nBLOOD");
        }
    }