package mapped;

import java.util.Comparator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSUserComparator4;

@ObfuscatedName("en")
public class UserComparator4 implements Comparator, RSUserComparator4 {
   @ObfuscatedName("at")
   final boolean reversed;

   public UserComparator4(boolean var1) {
      this.reversed = var1;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Lrh;Lrh;B)I",
      garbageValue = "26"
   )
   int method2941(Buddy var1, Buddy var2) {
      return this.reversed?var1.int2 - var2.int2:var2.int2 - var1.int2;
   }

   public int compare(Object var1, Object var2) {
      return this.method2941((Buddy)var1, (Buddy)var2);
   }

   public boolean equals(Object var1) {
      return super.equals(var1);
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)I",
      garbageValue = "1918308972"
   )
   public static int method2943_base(int var0) {
      var0 = (var0 & 1431655765) + (var0 >>> 1 & 1431655765);
      var0 = (var0 >>> 2 & 858993459) + (var0 & 858993459);
      var0 = var0 + (var0 >>> 4) & 252645135;
      var0 += var0 >>> 8;
      var0 += var0 >>> 16;
      return var0 & 255;
   }

   @ObfuscatedName("mb")
   @ObfuscatedSignature(
      descriptor = "(Lnn;II)I",
      garbageValue = "1187363281"
   )
   static final int method2942(Widget var0, int var1) {
      if(var0.cs1Instructions != null && var1 < var0.cs1Instructions.length) {
         try {
            int[] var2 = var0.cs1Instructions[var1];
            int var3 = 0;
            int var4 = 0;
            byte var5 = 0;

            while(true) {
               int var6 = var2[var4++];
               int var7 = 0;
               byte var8 = 0;
               if(var6 == 0) {
                  int var10000 = var3;
                  return var10000;
               }

               if(var6 == 1) {
                  var7 = Client.currentLevels[var2[var4++]];
               }

               if(var6 == 2) {
                  var7 = Client.levels[var2[var4++]];
               }

               if(var6 == 3) {
                  var7 = Client.experience[var2[var4++]];
               }

               int var9;
               Widget var10;
               int var11;
               int var12;
               if(var6 == 4) {
                  var9 = var2[var4++] << 16;
                  var9 += var2[var4++];
                  var10 = HealthBarDefinition.widgetDefinition.method6287(var9);
                  var11 = var2[var4++];
                  if(var11 != -1 && (!class214.method4226(var11).isMembersOnly || Client.isMembersWorld)) {
                     for(var12 = 0; var12 < var10.itemIds.length; ++var12) {
                        if(var11 + 1 == var10.itemIds[var12]) {
                           var7 += var10.itemQuantities[var12];
                        }
                     }
                  }
               }

               if(var6 == 5) {
                  var7 = Varps.Varps_main[var2[var4++]];
               }

               if(var6 == 6) {
                  var7 = Skills.Skills_experienceTable[Client.levels[var2[var4++]] - 1];
               }

               if(var6 == 7) {
                  var7 = Varps.Varps_main[var2[var4++]] * 100 / 46875;
               }

               if(var6 == 8) {
                  var7 = class229.localPlayer.combatLevel;
               }

               if(var6 == 9) {
                  for(var9 = 0; var9 < 25; ++var9) {
                     if(Skills.Skills_enabled[var9]) {
                        var7 += Client.levels[var9];
                     }
                  }
               }

               if(var6 == 10) {
                  var9 = var2[var4++] << 16;
                  var9 += var2[var4++];
                  var10 = HealthBarDefinition.widgetDefinition.method6287(var9);
                  var11 = var2[var4++];
                  if(var11 != -1 && (!class214.method4226(var11).isMembersOnly || Client.isMembersWorld)) {
                     for(var12 = 0; var12 < var10.itemIds.length; ++var12) {
                        if(var11 + 1 == var10.itemIds[var12]) {
                           var7 = 999999999;
                           break;
                        }
                     }
                  }
               }

               if(var6 == 11) {
                  var7 = Client.runEnergy;
               }

               if(var6 == 12) {
                  var7 = Client.weight;
               }

               if(var6 == 13) {
                  var9 = Varps.Varps_main[var2[var4++]];
                  int var13 = var2[var4++];
                  var7 = (var9 & 1 << var13) != 0?1:0;
               }

               if(var6 == 14) {
                  var9 = var2[var4++];
                  var7 = HealthBar.getVarbit_base(var9);
               }

               if(var6 == 15) {
                  var8 = 1;
               }

               if(var6 == 16) {
                  var8 = 2;
               }

               if(var6 == 17) {
                  var8 = 3;
               }

               if(var6 == 18) {
                  var7 = (class229.localPlayer.x >> 7) + NpcOverrides.baseX;
               }

               if(var6 == 19) {
                  var7 = (class229.localPlayer.y >> 7) + class101.baseY;
               }

               if(var6 == 20) {
                  var7 = var2[var4++];
               }

               if(var8 == 0) {
                  if(var5 == 0) {
                     var3 += var7;
                  }

                  if(var5 == 1) {
                     var3 -= var7;
                  }

                  if(var5 == 2 && var7 != 0) {
                     var3 /= var7;
                  }

                  if(var5 == 3) {
                     var3 *= var7;
                  }

                  var5 = 0;
               } else {
                  var5 = var8;
               }
            }
         } catch (Exception var14) {
            return -1;
         }
      } else {
         return -2;
      }
   }

   @ObfuscatedName("nf")
   @ObfuscatedSignature(
      descriptor = "(IIB)V",
      garbageValue = "52"
   )
   static final void method2936_base(int var0, int var1) {
      if(Client.currentClanChannels[var0] != null) {
         if(var1 >= 0 && var1 < Client.currentClanChannels[var0].method3479_base()) {
            ClanChannelMember var2 = (ClanChannelMember)Client.currentClanChannels[var0].members.get(var1);
            if(var2.rank == -1) {
               PacketBufferNode var3 = class113.method2919(ClientPacket.AFFINEDCLANSETTINGS_ADDBANNED_FROMCHANNEL, Client.packetWriter.isaacCipher);
               var3.packetBuffer.writeByte_base(3 + ClanChannel.stringCp1252NullTerminatedByteSize_base(var2.username.getName_base()));
               var3.packetBuffer.writeByte_base(var0);
               var3.packetBuffer.writeShort_base(var1);
               var3.packetBuffer.writeStringCp1252NullTerminated_base(var2.username.getName_base());
               Client.packetWriter.method2867(var3);
            }
         }
      }
   }

   @ObfuscatedName("om")
   @ObfuscatedSignature(
      descriptor = "(II)Lte;",
      garbageValue = "-125616841"
   )
   static DbTable method2937(int var0) {
      DbTable var1 = (DbTable)Client.archive11.get((long)var0);
      if(var1 == null) {
         var1 = new DbTable(class267.field2778, var0);
      }

      return var1;
   }
}
