Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region MainProducts
- float epsilon = 0.1f;
- //Check if has more then one main product
- int mainProductsAmount = CheckAmountOfMainItems(currentRecipe.Products.Items);
- if (mainProductsAmount >= 1)
- {
- byte[] indexes = GetMainProductsIndexes(currentRecipe.Products.Items);
- var chances = new Dictionary<float, byte>();
- for (int i = 0; i < indexes.Length; i++)
- {
- CRItemInfo item = currentRecipe.Products.Items[indexes[i]];
- float chance = 0;
- if (item.ChanceMaxLvl <= profInfo.ProfessionLevel)
- {
- chance = item.BasicChance;
- }
- else if (item.ChanceMinLvl > profInfo.ProfessionLevel)
- {
- continue;
- }
- else
- {
- chance = item.BasicChance * (float)((System.Math.Pow((profInfo.ProfessionLevel - item.ChanceMinLvl + 1), item.ChanceMod)) / System.Math.Pow((item.ChanceMaxLvl - item.ChanceMinLvl + 1), item.ChanceMod));
- }
- if (chance > item.BasicChance)
- {
- chance = item.BasicChance;
- }
- while (chances.ContainsKey(chance))
- {
- chance += epsilon;
- }
- Debug.Log("Szansa: " + chance + " Wylosowana: " + craftSucces + " item.BasicChance: " + item.BasicChance + " item.ChanceMod: " + item.ChanceMod + " item.ChanceMinLvl " + item.ChanceMinLvl + "profInfo.ProfessionLevel: " + profInfo.ProfessionLevel + " ChanceMaxLvl: " + item.ChanceMaxLvl);
- chances.Add(chance, indexes[i]);
- }
- //Removing keys (chances) below drawed craft chance
- List<float> keysArray = chances.Keys.ToList();
- for (int i = 0; i < keysArray.Count; i++)
- {
- if ((int)keysArray[i] > craftSucces)
- {
- keysArray.RemoveAt(i);
- }
- }
- //Debug.Log("Ilosc el w tablicy: " + keysArray.Count);
- //==============================================================
- if (keysArray.Count > 0)
- {
- keysArray.Sort();
- bool isCreated = false;
- for (int x = 0; x < keysArray.Count; x++)
- {
- if(!isCreated)
- {
- isCreated = true;
- //Debug.Log("keysArray[0] " + keysArray[0] + " craftS: " + craftSucces);
- if(keysArray[x] > craftSucces)
- {
- //Get item
- CRItemInfo item = currentRecipe.Products.Items[chances[keysArray[x]]];
- //Add item to "CreateItems" list after whole craft process
- IDsToCreate.Add(item.ItemId);
- TypesToCreate.Add(item.ItemType);
- int amount = 0;
- if (item.FixedAmount)
- {
- amount = item.MinAmount;
- }
- else
- {
- amount = Random.Range(item.MinAmount, item.MaxAmount);
- }
- characterExperience += item.CharacterExpBonus;
- craftingExperience += item.CraftingExpBonus;
- if (item.ChanceMaxLvl > craftMaxLevel)
- {
- craftMaxLevel = (byte)item.ChanceMaxLvl;
- }
- QuantityToCreate.Add(amount);
- productCreated = true;
- }
- }
- } //==============================================================
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement