Exemplo n.º 1
0
    private IEnumerator SpawnTicTacsFromSpawnModels()
    {
        SpawnModel spawnModel = spawnModels.Dequeue();

        if (!baseScriptDictionary.ContainsKey(spawnModel.pathLetter))
        {
            Debug.LogWarning("Base with path letter " + spawnModel.pathLetter + " doesn't exist.");
            yield return(null);
        }
        else if (spawnModel.spawnAmount <= 0)
        {
            Debug.LogWarning("Shouldn't be spawning " + spawnModel.spawnAmount + " tic tacs.");
            yield return(null);
        }
        else if (spawnModel.spawnTime < 0)
        {
            Debug.LogWarning("Spawn time of " + spawnModel.spawnTime + " is invalid.");
            yield return(null);
        }

        yield return(new WaitForSeconds(spawnModel.spawnTime));

        baseScriptDictionary[spawnModel.pathLetter].SpawnEnemies(spawnModel.flavor, spawnModel.spawnAmount);

        if (spawnModels.Count == 0)
        {
            yield return(null);
        }
        else
        {
            yield return(StartCoroutine(SpawnTicTacsFromSpawnModels()));
        }
    }
Exemplo n.º 2
0
 private void ParametersToSpawn(SpawnModel spawnModel)
 {
     FieldHighlight(_fieldMatereal, _gameManager.None);
     _toSupport.Clear();
     ChipSpawn(spawnModel.Chip, _gameManager.ChipsParent, spawnModel.IsBlack, spawnModel.Position, spawnModel.ChipParent);
     CheckFields(spawnModel.None, spawnModel.Current, spawnModel.PosX, spawnModel.PosZ);
     Helper(spawnModel.Next, spawnModel.Current);
 }
Exemplo n.º 3
0
    void DetectPercentageChange()
    {
        if (SpawnedModel.Length <= 0)
        {
            return;
        }

        _CurrentPercentageTotal = 0;

        int becomeGreaterIndex = -1;

        // calculate total percentage and detect the increasing ones
        for (int i = 0; i < SpawnedModel.Length; i++)
        {
            SpawnModel currentModel = SpawnedModel [i];
            // detect change greater
            if (currentModel.Percentage > currentModel.GetPrevPercentage())
            {
                becomeGreaterIndex = i;
            }
            _CurrentPercentageTotal += currentModel.Percentage;
            currentModel.SetPrevPercentage(currentModel.Percentage);
        }

        // decrease from other
        float RemainingPercentage = 100 - _CurrentPercentageTotal;

        if (RemainingPercentage < 0)
        {
            if (SpawnedModel.Length > 1)
            {
                for (int i = 0; i < SpawnedModel.Length; i++)
                {
                    SpawnModel currentModel = SpawnedModel [i];

                    //don't decrease from currently increasing model
                    if (i != becomeGreaterIndex)
                    {
                        int decreasingValue = (int)Mathf.Ceil((-RemainingPercentage) / (SpawnedModel.Length - 1));

                        if (currentModel.Percentage - decreasingValue > 0)
                        {
                            currentModel.Percentage -= decreasingValue;
                        }
                        else
                        {
                            // clamp to 0
                            currentModel.Percentage = 0;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
    private void SetPercentageRange()
    {
        // set the percentage range
        int startRange = 0;
        int endRange   = 0;

        for (int i = 0; i < SpawnedModel.Length; i++)
        {
            SpawnModel currentModel = SpawnedModel [i];

            startRange = endRange + (i > 0?1:0);
            endRange   = startRange + currentModel.Percentage - 1;

            currentModel.SetPercentageRange(startRange, endRange);
        }
    }
Exemplo n.º 5
0
    // Load SpawnModel using its probability range
    protected SpawnModel GetDesiredRange(SpawnModel[] targetArray, int value)
    {
        int i = 0;

        while (i < SpawnedModel.Length)
        {
            SpawnModel currentModel = SpawnedModel [i];
            if (currentModel.IsInRange(value))
            {
                return(currentModel);
            }
            else
            {
                i++;
            }
        }

        return(null);
    }
Exemplo n.º 6
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = _camera.ScreenPointToRay(Input.mousePosition);
         RaycastHit raycastHit;
         if (!Physics.Raycast(ray, out raycastHit))
         {
             return;
         }
         GameObject parent = raycastHit.collider.gameObject.transform.parent.gameObject;
         if (parent.layer != LayerMask.NameToLayer(_gameManager.CanSpawn))
         {
             return;
         }
         Vector3    hitPosition    = raycastHit.collider.gameObject.transform.position;
         Vector3    position       = new Vector3(hitPosition.x, ChipPosY, hitPosition.z);
         int        posX           = Mathf.FloorToInt(hitPosition.x) + 3;
         int        posZ           = (Mathf.FloorToInt(hitPosition.z) - 2) * -1;
         SpawnModel spawnChipModel = new SpawnModel(parent, position, posX, posZ, _gameManager.None);
         if (_gameManager.IsBlackTurn)
         {
             spawnChipModel.Chip    = _blackChip;
             spawnChipModel.IsBlack = false;
             spawnChipModel.Current = _gameManager.Player1;
             spawnChipModel.Next    = _gameManager.Player2;
             _gameManager.NumOfBlack++;
             _gameManager.CurrentPlayerColor = Chip.Currcolor2;
         }
         else
         {
             spawnChipModel.Chip    = _whiteChip;
             spawnChipModel.IsBlack = true;
             spawnChipModel.Current = _gameManager.Player2;
             spawnChipModel.Next    = _gameManager.Player1;
             _gameManager.NumOfWhite++;
             _gameManager.CurrentPlayerColor = Chip.Currcolor1;
         }
         ParametersToSpawn(spawnChipModel);
         _gameManager.PlayersScore();
     }
 }
Exemplo n.º 7
0
    public Entity SpawnBoss()
    {
        int randomNum = Random.Range(0, BossSpawnedModel.Length);

        SpawnModel model = BossSpawnedModel[randomNum];

        if (model != null)
        {
            string     poolName      = model.PoolName;
            GameObject spawnedEntity = PoolManager.Instance.GetPool(poolName).Get();

            if (spawnedEntity != null)
            {
                Entity e = spawnedEntity.GetComponent <Entity> ();

                if (e != null)
                {
                    // get random position
                    int randomPosIndex = Random.Range(0, Positions.Length - 1);

                    Vector3 randomPosition = Positions [randomPosIndex].position;
                    Vector3 endPosition    = new Vector3(
                        randomPosition.x + Random.Range(MinOffset.x, MaxOffset.x),
                        randomPosition.y + Random.Range(MinOffset.y, MaxOffset.y),
                        randomPosition.z + Random.Range(MinOffset.z, MaxOffset.z));
                    e.transform.position = randomPosition;
                    e.gameObject.SetActive(true);

                    OnEntitySpawned(e);

                    e.Init();

                    SpawnCount++;

                    _BossCount++;
                    return(e);
                }
            }
        }
        return(null);
    }
Exemplo n.º 8
0
    // spawn NON BOSS enemy
    public override Entity Spawn()
    {
        int randomNum = Random.Range(0, 101);

        SpawnModel model = GetDesiredRange(SpawnedModel, randomNum);

        if (model != null)
        {
            string poolName = model.PoolName;

            GameObject spawnedEntity = PoolManager.Instance.GetPool(poolName).Get();
            if (spawnedEntity != null)
            {
                Entity e = spawnedEntity.GetComponent <Entity> ();

                EnemyPatternSpawnerController ePatternSpawner = spawnedEntity.GetComponent <EnemyPatternSpawnerController> ();

                // prevent spawn boss
                if (ePatternSpawner != null)
                {
                    if (ePatternSpawner.IsBossPatternSpawner)
                    {
                        return(null);
                    }
                }

                EnemyController eController = spawnedEntity.GetComponent <EnemyController> ();

                // prevent spawn boss
                if (eController.EnemyType == EnemyController.AircraftType.BOSS)
                {
                    return(null);
                }


                // prevent boss on first try
                if (!_FirstNonBossSpawned)
                {
                    // check boss inside pattern spawner
                    if (ePatternSpawner != null)
                    {
                        if (ePatternSpawner.IsBossPatternSpawner)
                        {
                            return(null);
                        }
                    }
                    else if (eController != null)
                    {
                        if (eController.EnemyType == EnemyController.AircraftType.BOSS)
                        {
                            return(null);
                        }
                    }
                }


                if (e != null)
                {
                    // get random position
                    int randomPosIndex = Random.Range(0, Positions.Length - 1);

                    Vector3 randomPosition = Positions [randomPosIndex].position;
                    Vector3 endPosition    = new Vector3(
                        randomPosition.x + Random.Range(MinOffset.x, MaxOffset.x),
                        randomPosition.y + Random.Range(MinOffset.y, MaxOffset.y),
                        randomPosition.z + Random.Range(MinOffset.z, MaxOffset.z));
                    e.transform.position = randomPosition;
                    e.gameObject.SetActive(true);

                    OnEntitySpawned(e);

                    e.Init();
                    SpawnCount++;

                    if (!_FirstNonBossSpawned)
                    {
                        _FirstNonBossSpawned = true;
                    }

                    return(e);
                }
            }
        }
        return(null);
    }
Exemplo n.º 9
0
 private void Awake()
 {
     _townModel  = TownModel.Instance;
     _spawnModel = SpawnModel.Instance;
 }