using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BoxController : PlayerStats
{
[SerializeField] Box[] Boxes;
[SerializeField] Text CoinsText;
[SerializeField] Text PPText;
public void OpenBox(int BoxId)
{
int CoinsAmount = 0;
int PPAmount = 0;
for(int i = 0; i < Boxes[BoxId].RandomIterations; i++)
{
float Number = Random.Range(0f, 100f);
if(Number < Boxes[BoxId].CoinsAndPPChance)
{
Number = Random.Range(0, 2);
if(Number == 0)
{
CoinsAmount += Random.Range(Boxes[BoxId].CoinsAmount.x, Boxes[BoxId].CoinsAmount.y);
}
else
{
PPAmount += Random.Range(Boxes[BoxId].PPAmount.x, Boxes[BoxId].PPAmount.y);
}
}
else
{
Number = 100 - Number;
print(Number);
print(Boxes[BoxId].MythicalBrawlerChance);
if(Number >= Boxes[BoxId].RareBrawlerChance)
{
Debug.LogWarning("Rare BRAWLER");
}
else if(Number >= Boxes[BoxId].SuperRareBrawlerChance && Number <= Boxes[BoxId].RareBrawlerChance)
{
Debug.LogWarning("Super RARE BRAWLER");
}
else if (Number >= Boxes[BoxId].EpicBrawlerChance && Number <= Boxes[BoxId].SuperRareBrawlerChance)
{
Number = Random.Range(0, 2);
if(Number == 0)
{
Debug.LogWarning("EPIC BRAWLER");
}
else
{
Debug.LogWarning("Chromatic");
}
}
else if (Number >= Boxes[BoxId].MythicalBrawlerChance && Number <= Boxes[BoxId].EpicBrawlerChance)
{
Debug.LogWarning("MYTHICAL BRAWLER");
}
else if (Number >= Boxes[BoxId].LegendaryBrawlerChance && Number <= Boxes[BoxId].MythicalBrawlerChance)
{
Debug.LogWarning("LEGA!");
}
}
Money += CoinsAmount;
PowerPoints += PPAmount;
CoinsText.text = "Монетки: " + Money;
PPText.text = "Павер поинты: " + PowerPoints;
}
}
}
using UnityEngine;
using UnityEngine.UI;
[CreateAssetMenu]
public class Box : ScriptableObject
{
public int RandomIterations;
public float CoinsAndPPChance;
public Vector2Int CoinsAmount;
public Vector2Int PPAmount;
public float RareBrawlerChance;
public float SuperRareBrawlerChance;
public float EpicBrawlerChance;
public float MythicalBrawlerChance;
public float LegendaryBrawlerChance;
public float ChromaticBrawlerChance;
public float StarPowerChance;
public float GadgetChance;
public float BonusChance;
}
/// <summary>
/// Функция получает случайный индекс массива, учитывая шанс получить этот самый индекс
/// (например из: 50, 10, 0, 20) наибольший шанс получит 0 индекс с шансом 50
/// </summary>
/// <param name="mas_chance">массив относительных значений шансов получить индекс</param>
/// <returns></returns>
public static int GetRandomChanceIndex(int[] mas_chance)
{
if (mas_chance.Length == 0)
return 0;
int sum = 0;
for (int i = 0; i < mas_chance.Length; i++)
{
sum += mas_chance[i];
}
int r = UnityEngine.Random.Range(0, sum);
sum = 0;
//int n = 0;
for (int i = 0; i < mas_chance.Length; i++)
{
sum += mas_chance[i];
if (sum > r)
return i;
}
return 0;
}