- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
public static int[] GetRandomComStats(int level)
{
int[] stats = new int[3] { -1, -1, -1 };
int summ = (int)(1.2f * level);
int minStat = level / 3f - (level+ 1) / 10 < 0 ? 0 : (int)(level / 3f - (level + 1) / 10);
int maxStat = (int)(level / 3f + (level + 1) / 10);
Debug.Log("level: " + level + " min stat: " + minStat + " max stat: " + maxStat + " summ: " + summ);
int fr = Random.Range(0, 2);
int f2 = Random.Range(0, 3);
int f1 = 0;
stats[f2] = Random.Range(minStat, maxStat + 1);
for (int i = 0; i < 3; i++)
{
if (fr == 1 && stats[i] == -1)
{
if (summ - stats[f2] > maxStat) stats[i] = Random.Range(minStat, maxStat + 1);
else if (summ - stats[f2] < 0) stats[i] = 0;
else stats[i] = Random.Range(minStat, summ - stats[f2] + 1);
f1 = i;
goto label;
}
fr = 1;
}
label:
for (int i = 0; i < 3; i++)
{
if (stats[i] == -1)
{
if (summ < stats[f1] + stats[f2]) stats[i] = 0;
else if (summ - stats[f1] - stats[f2] > maxStat) stats[i] = maxStat;
else stats[i] = summ - stats[f1] - stats[f2];
Debug.Log(f1 + ": " + stats[f1]+ " " + f2 + ": " + stats[f2] + " " + i + ": " + stats[i]);
}
}
return stats;
}
Генерация рандомных стат персонажей в зависимости от уровня.
betking1 21.07.2017 15:29 # 0