Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. #region MainProducts
  2.  
  3. float epsilon = 0.1f;
  4.  
  5. //Check if has more then one main product
  6. int mainProductsAmount = CheckAmountOfMainItems(currentRecipe.Products.Items);
  7. if (mainProductsAmount >= 1)
  8. {
  9. byte[] indexes = GetMainProductsIndexes(currentRecipe.Products.Items);
  10. var chances = new Dictionary<float, byte>();
  11.  
  12. for (int i = 0; i < indexes.Length; i++)
  13. {
  14. CRItemInfo item = currentRecipe.Products.Items[indexes[i]];
  15. float chance = 0;
  16. if (item.ChanceMaxLvl <= profInfo.ProfessionLevel)
  17. {
  18. chance = item.BasicChance;
  19. }
  20. else if (item.ChanceMinLvl > profInfo.ProfessionLevel)
  21. {
  22. continue;
  23. }
  24. else
  25. {
  26. chance = item.BasicChance * (float)((System.Math.Pow((profInfo.ProfessionLevel - item.ChanceMinLvl + 1), item.ChanceMod)) / System.Math.Pow((item.ChanceMaxLvl - item.ChanceMinLvl + 1), item.ChanceMod));
  27. }
  28.  
  29. if (chance > item.BasicChance)
  30. {
  31. chance = item.BasicChance;
  32. }
  33. while (chances.ContainsKey(chance))
  34. {
  35. chance += epsilon;
  36. }
  37. 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);
  38.  
  39. chances.Add(chance, indexes[i]);
  40. }
  41.  
  42. //Removing keys (chances) below drawed craft chance
  43. List<float> keysArray = chances.Keys.ToList();
  44. for (int i = 0; i < keysArray.Count; i++)
  45. {
  46. if ((int)keysArray[i] > craftSucces)
  47. {
  48. keysArray.RemoveAt(i);
  49. }
  50. }
  51. //Debug.Log("Ilosc el w tablicy: " + keysArray.Count);
  52. //==============================================================
  53. if (keysArray.Count > 0)
  54. {
  55. keysArray.Sort();
  56. bool isCreated = false;
  57. for (int x = 0; x < keysArray.Count; x++)
  58. {
  59. if(!isCreated)
  60. {
  61. isCreated = true;
  62. //Debug.Log("keysArray[0] " + keysArray[0] + " craftS: " + craftSucces);
  63. if(keysArray[x] > craftSucces)
  64. {
  65. //Get item
  66. CRItemInfo item = currentRecipe.Products.Items[chances[keysArray[x]]];
  67.  
  68. //Add item to "CreateItems" list after whole craft process
  69. IDsToCreate.Add(item.ItemId);
  70. TypesToCreate.Add(item.ItemType);
  71.  
  72. int amount = 0;
  73. if (item.FixedAmount)
  74. {
  75. amount = item.MinAmount;
  76. }
  77. else
  78. {
  79. amount = Random.Range(item.MinAmount, item.MaxAmount);
  80. }
  81.  
  82. characterExperience += item.CharacterExpBonus;
  83. craftingExperience += item.CraftingExpBonus;
  84.  
  85. if (item.ChanceMaxLvl > craftMaxLevel)
  86. {
  87. craftMaxLevel = (byte)item.ChanceMaxLvl;
  88. }
  89. QuantityToCreate.Add(amount);
  90. productCreated = true;
  91. }
  92. }
  93. } //==============================================================
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement