void OnGainResource(GainResourcePos grp)
    {
        Color col = new Color(0, 1, 1, 1);

        foreach (int val in grp.value)
        {
            if (val > 0)
            {
                DisplayOverlayText(val.ToString(), grp.pos, col, true);
            }
        }
    }
Beispiel #2
0
    public void Dead()
    {
        //~ if(PerkManager.rscGainCreepChance>0 && Random.Range(0f, 1f)>=PerkManager.rscGainCreepChance){
        //~ int[] val=new int[value.Length];
        //~ for(int i=0; i<value.Length; i++){
        //~ float modifier=1+PerkManager.rscGainCreepModifier[i]+PerkManager.rscGainModifier[i];
        //~ float bonus=PerkManager.rscGainCreepValue[i]+PerkManager.rscGainValue[i];
        //~ val[i]=(int)Mathf.Round((float)value[i]*modifier+bonus);
        //~ }
        //~ GameControl.GainResource(val);
        //~ }
        //~ else GameControl.GainResource(value);

        //value length is verified as soon as game start so it never exceed actual resource length
        if (PerkManager.rscGainChance > 0 || PerkManager.rscGainCreepChance > 0)
        {
            float randG = Random.Range(0f, 1f);
            float randC = Random.Range(0f, 1f);
            int[] val   = new int[value.Length];

            for (int i = 0; i < value.Length; i++)
            {
                float modifier = 1;
                float bonus    = 0;

                if (randG <= PerkManager.rscGainChance)
                {
                    modifier += PerkManager.rscGainModifier[i];
                    bonus    += PerkManager.rscGainValue[i];
                }
                if (randC <= PerkManager.rscGainTowerChance)
                {
                    modifier += PerkManager.rscGainCreepModifier[i];
                    bonus    += PerkManager.rscGainCreepValue[i];
                }

                val[i] = (int)Mathf.Round((float)value[i] * modifier + bonus);
            }
            GameControl.GainResource(val);

            if (onGainResourceE != null)
            {
                GainResourcePos grp = new GainResourcePos(thisT.position, val);
                onGainResourceE(grp);
            }
        }
        else
        {
            GameControl.GainResource(value);

            if (onGainResourceE != null)
            {
                GainResourcePos grp = new GainResourcePos(thisT.position, value);
                onGainResourceE(grp);
            }
        }


        if (deadEffect != null)
        {
            ObjectPoolManager.Spawn(deadEffect, thisT.position, Quaternion.identity);
        }
        float duration = PlayDead();

        StartCoroutine(Unspawn(duration));

        //spawn more unit if there's one assigned
        if (spawnUponDestroyed != null)
        {
            SpawnManager.AddActiveUnit(waveID, spawnNumber);

            for (int i = 0; i < spawnNumber; i++)
            {
                //generate a small offset position within the grid size so not all creep spawned on top of each other and not too far apart
                float allowance = BuildManager.GetGridSize() / 2;

                float x = Random.Range(-allowance, allowance);
                float y = Random.Range(-allowance, allowance);

                Vector3    pos = thisT.position + new Vector3(x, 0, y);
                GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed, pos, thisT.rotation);

                UnitCreep unit = obj.GetComponent <UnitCreep>();
                unit.Init(path, SpawnManager.NewUnitID(), waveID);
                //resume the path currently followed by this unit

                unit.StartCoroutine(unit.ResumeParentPath(wpMode, wp, wpCounter, currentPS, subPath, currentPathID, subWPCounter));
            }
        }
    }