Exemple #1
0
    public Wave GenerateWave(int waveNum, int rscCount)
    {
        //~ if(creepList.Count==0){
        //~ return null;
        //~ }

        Wave thisWave = new Wave();

        thisWave.resourceGain = new int[rscCount];
        for (int i = 0; i < thisWave.resourceGain.Length; i++)
        {
            thisWave.resourceGain[i] = (int)(rscGain[i] + waveNum * rscInc[i] + (Random.Range(-rscDev[i], rscDev[i])));
        }

        int   countThisWave = (int)(unitCount + ((waveNum - 1) * countIncrement));
        float randMod       = 1f + Random.Range(-countDevMod, countDevMod);

        countThisWave = (int)((float)countThisWave * (randMod));
        int currentCount = 0;

        float HPQuota = startHPSum + (int)(HPIncrement * waveNum);
        //~ float spdQuota=moveSpeed+(int)(spdIncrement*currentWave);

        float maxSBC = subWaveCount + (waveNum) * subWaveCountInc;      //Debug.Log(Random.Range(10, 1)+"   "+max);

        maxSBC = Mathf.Min(maxSBC, maxSubWaveCount);
        //~ int subWaveCount=Random.Range(1, (int)max);     //Debug.Log(subWaveCount+"   "+max);
        thisWave.subWaves = new SubWave[Random.Range(1, (int)maxSBC)];
        //~ thisWave.subWaves=new SubWave[allPath.Count];

        List <int> pathAsgList = PathAssignment(thisWave.subWaves.Length);

        List <UnitParameter> list = GenerateCreepListForWave(waveNum);

        for (int i = 0; i < thisWave.subWaves.Length; i++)
        {
            thisWave.subWaves[i] = new SubWave();
            //~ thisWave.subWaves[i].path=allPath[Random.Range(0, allPath.Count)];
            thisWave.subWaves[i].path = allPath[pathAsgList[i]];

            int           ID = Random.Range(0, list.Count);
            UnitParameter up = list[ID];
            thisWave.subWaves[i].unit = list[ID].unit;
            thisWave.subWaves[i].SetUnitComponent();


            float unitHP = up.startHP + up.HPIncrement * waveNum + Random.Range(-up.HPDeviation, up.HPDeviation);
            thisWave.subWaves[i].overrideHP = Mathf.Max(up.minHP, unitHP);

            float unitSpd = up.startSpd + up.spdIncrement * waveNum + Random.Range(-up.spdDeviation, up.spdDeviation);
            thisWave.subWaves[i].overrideMoveSpd = Mathf.Max(up.minSpd, unitSpd);

            float unitShd = 0;
            if (up.minShd > 0)
            {
                unitShd = up.startShd + up.shdIncrement * waveNum + Random.Range(-up.shdDeviation, up.shdDeviation);
                thisWave.subWaves[i].overrideShield = Mathf.Max(up.minShd, unitShd);
            }

            thisWave.subWaves[i].interval = Random.Range(list[ID].minInterval, list[ID].maxInterval);

            if (i == 0)
            {
                thisWave.subWaves[i].delay = Random.Range(list[ID].minDelay, list[ID].maxDelay);
            }
            else
            {
                thisWave.subWaves[i].delay = 0;
            }

            countThisWave += thisWave.subWaves[i].count;
        }


        int swID = 0;

        while (currentCount < countThisWave)
        {
            int num = (int)Random.Range(countThisWave * 0.2f, countThisWave * 0.3f);
            num = Mathf.Min(num, countThisWave - currentCount);
            thisWave.subWaves[swID].count += num;
            currentCount += num;
            swID         += 1;        if (swID == thisWave.subWaves.Length)
            {
                swID = 0;
            }
        }


        float currentHPSum = 0;

        for (int i = 0; i < thisWave.subWaves.Length; i++)
        {
            currentHPSum += thisWave.subWaves[i].count * thisWave.subWaves[i].GetUnitComponent().GetFullHP();
        }
        if (currentHPSum < HPQuota)
        {
            float   delta     = HPQuota - currentHPSum;
            float[] partition = new float[thisWave.subWaves.Length];
            float   sum       = 0;
            for (int i = 0; i < partition.Length - 1; i++)
            {
                float rand = Random.Range(0f, 1.0f - sum);
                sum         += rand;
                partition[i] = rand;
            }
            for (int i = 0; i < partition.Length - 1; i++)
            {
                partition[i] = partition[i] * delta / thisWave.subWaves[i].count;
                //Debug.Log("hp adjustment: "+partition[i]);
                float HPValue = thisWave.subWaves[i].GetUnitComponent().GetFullHP() + partition[i];
                thisWave.subWaves[i].overrideHP = Mathf.Max(thisWave.subWaves[i].overrideHP, HPValue);
            }
        }

        thisWave.waveInterval = thisWave.CalculateSpawnDuration() + waveCD + Random.Range(-waveCDDev, waveCDDev);
        //Debug.Log(currentCount+"  "+countThisWave+"  "+unitCount);

        return(thisWave);
    }