Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.97 KB | None | 0 0
  1.     public void sendDropRates_new(int npcId) {
  2.  
  3.         Drop[] drops = NPCDrops.getDrops(npcId);
  4.         if (drops == null) {
  5.             player.sendMessage("This NPC has no Drops");
  6.             return;
  7.         }
  8.         int NPCID = npcId;
  9.         Drop[] possibleDrops = new Drop[drops.length];
  10.         int possibleDropsCount = 0;
  11.         int[] Rollvars = { 10, 25, 40, 50 };
  12.         int Count_of_100s = 0;
  13.         for (int i = 0; i < drops.length; i++) {
  14.             if (drops[i].getRate() == 100) {
  15.                 Count_of_100s++;
  16.             }
  17.  
  18.         }
  19.         int[] Drops = new int[drops.length - Count_of_100s];
  20.         if (Drops.length >= 1 && Drops.length <= 15) {
  21.             int[] DropsMinAmount = new int[drops.length - Count_of_100s];
  22.             int[] DropsMaxAmount = new int[drops.length - Count_of_100s];
  23.             int[] GuaranteedDrops = new int[Count_of_100s];
  24.             int[] GuaranteedDropsMinAmount = new int[Count_of_100s];
  25.             int[] GuaranteedDropsMaxAmount = new int[Count_of_100s];
  26.             double[] Chances = new double[Drops.length];
  27.             double[] TrueChances = new double[Drops.length];
  28.             double[] RealTrueChances = new double[Drops.length];
  29.             double KillerDropRate = player.getEquipment().getDropRate();
  30.             int I = 0;
  31.             for (int i = 0; i < drops.length; i++) {
  32.                 if (drops[i].getRate() != 100) {
  33.                     Drops[i - I] = drops[i].getItemId();
  34.                     Chances[i - I] = drops[i].getRate();
  35.                     DropsMinAmount[i - I] = drops[i].getMinAmount();
  36.                     DropsMaxAmount[i - I] = drops[i].getMaxAmount();
  37.                 } else {
  38.                     GuaranteedDrops[I] = drops[i].getItemId();
  39.                     GuaranteedDropsMinAmount[I] = drops[i].getMinAmount();
  40.                     GuaranteedDropsMaxAmount[I] = drops[i].getMaxAmount();
  41.                     I++;
  42.                 }
  43.             }
  44.  
  45.             for (int i = 0; i < Drops.length; i++) {
  46.                 if (Chances[i] > 1.0 && Chances[i] < 100) {
  47.                     TrueChances[i] = (Chances[i] + 4 + KillerDropRate) / (99) > 1 ? 1
  48.                             : (Chances[i] + 4 + KillerDropRate) / (99);
  49.                 } else if (Chances[i] > 0.5 && Chances[i] <= 1.0) {
  50.                     TrueChances[i] = (Chances[i] + 4 + KillerDropRate) / (Rollvars[0] * 99);
  51.                 } else if (Chances[i] >= 0.3 && Chances[i] <= 0.5) {
  52.                     TrueChances[i] = (Chances[i] + 4 + KillerDropRate) / (Rollvars[1] * 99);
  53.                 } else if (Chances[i] == 0.2) {
  54.                     TrueChances[i] = (Chances[i] + 4 + KillerDropRate) / (Rollvars[2] * 99);
  55.                 } else if (Chances[i] == 0.1) {
  56.                     TrueChances[i] = (Chances[i] + 4 + KillerDropRate) / (Rollvars[3] * 99);
  57.                 }
  58.             }
  59.  
  60.             double[] Multipliers;
  61.             int n = Drops.length;
  62.             int len = (int) Math.pow(2, n);
  63.             String[][] BinaryNumbers = new String[len][];
  64.             int[] DummyArray = new int[n];
  65.             int[][] BinaryNumbersInt = new int[len][];
  66.             for (int count = 0; count < len; count++) {
  67.                 BinaryNumbers[count] = String.format("%" + n + "s", Integer.toBinaryString(count)).replace((" "), ("0"))
  68.                         .split("");
  69.                 for (int i = 0; i < n; i++) {
  70.                     DummyArray[i] = Integer.parseInt(BinaryNumbers[count][i]);
  71.                 }
  72.                 BinaryNumbersInt[count] = Arrays.copyOf(DummyArray, DummyArray.length);
  73.             }
  74.  
  75.             int NumberArray[];
  76.             int CountArray[];
  77.             int AmountOfZeros = 0;
  78.             double Product = 1;
  79.             for (int i = 0; i < len; i++) {
  80.                 AmountOfZeros = 0;
  81.                 Multipliers = Arrays.copyOf(TrueChances, TrueChances.length);
  82.                 NumberArray = BinaryNumbersInt[i];
  83.                 // System.out.println(NumberArray.length);
  84.                 Product = 1;
  85.                 for (int IDK = 0; IDK < n; IDK++) {
  86.                     // System.out.println(NumberArray[IDK] + " num");
  87.                     if (NumberArray[IDK] == 0) {
  88.                         AmountOfZeros++;
  89.                     }
  90.                 }
  91.                 if (AmountOfZeros != 0) {
  92.                     Product *= 1.0 / AmountOfZeros;
  93.                     for (int Integer = 0; Integer < NumberArray.length; Integer++) {
  94.                         Product *= Math.abs(NumberArray[Integer] - Multipliers[Integer]);
  95.                         // System.out.println(Product);
  96.                     }
  97.  
  98.                     for (int JK = 0; JK < NumberArray.length; JK++) {
  99.                         RealTrueChances[JK] += (NumberArray[JK] * -1 + 1) * Product;
  100.                         // System.out.println(TrueChances[JK] + " Goes to " + RealTrueChances[JK]);
  101.                     }
  102.                 }
  103.             }
  104.  
  105.             /*
  106.              *
  107.              *
  108.              * player.getPackets().sendItemOnIComponent(inter, 24 + i, drops[i].getItemId(),
  109.              * 1); player.getPackets().sendIComponentText(inter, 49 + i,
  110.              * itemDefs.getName()); player.getPackets().sendIComponentText(inter, 64 + i, ""
  111.              * + drops[i].getRate() + "%");
  112.              *
  113.              *
  114.              */
  115.  
  116.             /*
  117.              * for (int j = 0; j < Drops.length; j++) { ItemDefinitions itemDefs =
  118.              * ItemDefinitions.getItemDefinitions(drops[j].getItemId()); double doubleValue
  119.              * = BigDecimal.valueOf((RealTrueChances[j] * 100)).setScale(3,
  120.              * RoundingMode.HALF_UP) .doubleValue(); player.sm(itemDefs.getName() + "-" +
  121.              * doubleValue + "%");
  122.              *
  123.              *
  124.              *
  125.              * }
  126.              */
  127.  
  128.             player.getInterfaceManager().sendInterface(1265);
  129.  
  130.             NPCDefinitions defs = NPCDefinitions.getNPCDefinitions(npcId);
  131.  
  132.             if (drops == null) {
  133.                 player.sendMessage("This NPC has no Drops");
  134.                 return;
  135.             }
  136.  
  137.             player.getPackets().sendIComponentText(1265, 48, "Drops from : " + defs.name);
  138.  
  139.             for (int i = 0; i < Drops.length; i++) {
  140.  
  141.                 ItemDefinitions itemDefs = ItemDefinitions.getItemDefinitions(drops[i].getItemId());
  142.  
  143.                 String amount = "";
  144.                 if (itemDefs.isStackable()) {
  145.                     amount = drops[i].getMinAmount() + "-" + drops[i].getMaxAmount();
  146.                 } else {
  147.                     amount = "1";
  148.                 }
  149.  
  150.                 player.getPackets().sendItemOnIComponent(1265, 24 + i, drops[i].getItemId(), 1);
  151.                 player.getPackets().sendIComponentText(1265, 49 + i, itemDefs.getName());
  152.  
  153.                 player.getPackets().sendIComponentText(1265, 64 + i + Count_of_100s,
  154.                         BigDecimal.valueOf((RealTrueChances[i] * 100)).setScale(3, RoundingMode.HALF_UP).doubleValue()
  155.                                 + "%");
  156.                 player.getPackets().sendIComponentText(1265, 79 + i, "" + amount);
  157.             }
  158.  
  159.             for (int i = Drops.length; i < 15; i++) {
  160.                 player.getPackets().sendItemOnIComponent(1265, 24 + i, -2, 1);
  161.                 player.getPackets().sendIComponentText(1265, 49 + i, "");
  162.                 player.getPackets().sendIComponentText(1265, 64 + i + Count_of_100s, "");
  163.                 player.getPackets().sendIComponentText(1265, 79 + i, "");
  164.             }
  165.  
  166.         }
  167.  
  168.         else {
  169.  
  170.             player.sm("Error opening drops,please resport to the Developer");
  171.  
  172.         }
  173.  
  174.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement