package mapped;

import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSNPCComposition;

@ObfuscatedName("dr")
public enum class90 implements MouseWheel {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1092(0, -1),
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1084(1, 2),
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1085(2, 3),
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1091(3, 4),
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1087(4, 5),
   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "Ldr;"
   )
   field1086(5, 6);

   @ObfuscatedName("av")
   public static short[][] field1094;
   @ObfuscatedName("ae")
   static String field1088;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = 1259061193
   )
   final int field1089;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = -447285435
   )
   final int field1090;

   class90(int var3, int var4) {
      this.field1089 = var3;
      this.field1090 = var4;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "-11"
   )
   public int rsOrdinal_base() {
      return this.field1090;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(IIB)Z",
      garbageValue = "-9"
   )
   static boolean method2382_base(int var0, int var1) {
      return var0 != 4 || var1 < 8;
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(CLof;B)I",
      garbageValue = "53"
   )
   static int method2385(char var0, Language var1) {
      int var2 = var0 << 4;
      if(Character.isUpperCase(var0) || Character.isTitleCase(var0)) {
         var0 = Character.toLowerCase(var0);
         var2 = (var0 << 4) + 1;
      }

      if(var0 == 241 && var1 == Language.Language_ES) {
         var2 = 1762;
      }

      return var2;
   }

   @ObfuscatedName("ks")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "892396745"
   )
   static final void method2384_base() {
      for(PendingSpawn var0 = (PendingSpawn)Client.pendingSpawns.method7265(); var0 != null; var0 = (PendingSpawn)Client.pendingSpawns.method7235()) {
         if(var0.hitpoints == -1) {
            var0.delay = 0;
            ScriptFrame.method1212(var0);
         } else {
            var0.remove_base();
         }
      }

   }

   @ObfuscatedName("kz")
   @ObfuscatedSignature(
      descriptor = "(ZLuo;I)V",
      garbageValue = "2029902605"
   )
   static final void method2383(boolean var0, PacketBuffer var1) {
      Client.updateNpcs(var0, var1);
      Client.field617 = 0;
      Client.field637 = 0;
      class472.method8567(var1);

      int var3;
      int var9;
      int var10;
      int var12;
      int var15;
      int var16;
      NPCComposition var10001;
      while(true) {
         byte var2 = 16;
         var3 = 1 << var2;
         if(var1.bitsRemaining_base(Client.packetWriter.serverPacketLength) < var2 + 12) {
            break;
         }

         int var14 = var1.readBits_base(var2);
         if(var14 == var3 - 1) {
            break;
         }

         boolean var5 = false;
         if(Client.npcs[var14] == null) {
            Client.npcs[var14] = new NPC();
            Client.cachedNPCsChanged(var14);
            var5 = true;
         }

         NPC var17 = Client.npcs[var14];
         Client.npcIndices[++Client.npcCount - 1] = var14;
         var17.npcCycle = Client.cycle;
         var16 = var1.readBits_base(1);
         var10 = Client.defaultRotations[var1.readBits_base(3)];
         if(var5) {
            var17.orientation = var17.rotation = var10;
         }

         if(var0) {
            var15 = var1.readBits_base(8);
            if(var15 > 127) {
               var15 -= 256;
            }
         } else {
            var15 = var1.readBits_base(5);
            if(var15 > 15) {
               var15 -= 32;
            }
         }

         boolean var11 = var1.readBits_base(1) == 1;
         if(var11) {
            var1.readBits_base(32);
         }

         var12 = var1.readBits_base(1);
         if(var12 == 1) {
            Client.field549[++Client.field637 - 1] = var14;
         }

         if(var0) {
            var9 = var1.readBits_base(8);
            if(var9 > 127) {
               var9 -= 256;
            }
         } else {
            var9 = var1.readBits_base(5);
            if(var9 > 15) {
               var9 -= 32;
            }
         }

         var10001 = VerticalAlignment.method3757(var1.readBits_base(14));
         var17.onDefinitionChanged((RSNPCComposition)var10001);
         var17.definition = var10001;
         class33.method495(var17);
         if(var17.field1240 == 0) {
            var17.rotation = 0;
         }

         var17.method2702_base(class229.localPlayer.pathX[0] + var15, class229.localPlayer.pathY[0] + var9, var16 == 1);
      }

      var1.exportIndex_base();

      int var21;
      for(var21 = 0; var21 < Client.field637; ++var21) {
         var3 = Client.field549[var21];
         NPC var4 = Client.npcs[var3];
         int var22 = var1.readUnsignedByte_base();
         int var6;
         if((var22 & 16) != 0) {
            var6 = var1.readUnsignedByte_base();
            var22 += var6 << 8;
         }

         if((var22 & 256) != 0) {
            var6 = var1.readUnsignedByte_base();
            var22 += var6 << 16;
         }

         int[] var7;
         short[] var8;
         short[] var18;
         long var19;
         int var23;
         boolean var24;
         if((var22 & 4096) != 0) { // 0 - idk
            var6 = var1.readUnsignedByteAdd_base();
            if((var6 & 1) == 1) {
               var4.method2675_base();
            } else {
               var7 = null;
               if((var6 & 2) == 2) {
                  var15 = var1.readUnsignedByteNeg_base();
                  var7 = new int[var15];

                  for(var9 = 0; var9 < var15; ++var9) {
                     var10 = var1.readUnsignedShortLE_base();
                     var10 = var10 == 65535?-1:var10;
                     var7[var9] = var10;
                  }
               }

               var8 = null;
               if((var6 & 4) == 4) {
                  var9 = 0;
                  if(var4.definition.recolorTo != null) {
                     var9 = var4.definition.recolorTo.length;
                  }

                  var8 = new short[var9];

                  for(var10 = 0; var10 < var9; ++var10) {
                     var8[var10] = (short)var1.readUnsignedShortLE_base();
                  }
               }

               var18 = null;
               if((var6 & 8) == 8) {
                  var10 = 0;
                  if(var4.definition.retextureTo != null) {
                     var10 = var4.definition.retextureTo.length;
                  }

                  var18 = new short[var10];

                  for(var23 = 0; var23 < var10; ++var23) {
                     var18[var23] = (short)var1.readUnsignedShortAdd_base();
                  }
               }

               var24 = false;
               if((var6 & 16) != 0) {
                  var24 = var1.readUnsignedByteAdd_base() == 1;
               }

               var19 = (long)(++NPC.field1311 - 1);
               var4.method2673(new NpcOverrides(var19, var7, var8, var18, var24));
            }
         }

         if((var22 & 65536) != 0) { // 1 - overhead icon
            var6 = var1.readUnsignedByte_base();
            var7 = new int[8];
            var8 = new short[8];

            for(var9 = 0; var9 < 8; ++var9) {
               if((var6 & 1 << var9) != 0) {
                  var7[var9] = var1.readNullableLargeSmart_base();
                  var8[var9] = (short)var1.readShortSmartSub_base();
               } else {
                  var7[var9] = -1;
                  var8[var9] = -1;
               }
            }

            var4.method2669_base(var7, var8);
         }

         if((var22 & 262144) != 0) { // 2 - default animations
            var6 = var1.readUnsignedIntME_base();
            var4.turnLeftSequence = (var6 & 1) != 0?var1.readUnsignedShort_base():var4.definition.turnLeftSequence;
            var4.turnRightSequence = (var6 & 2) != 0?var1.readUnsignedShortAdd_base():var4.definition.turnRightSequence;
            var4.walkSequence = (var6 & 4) != 0?var1.readUnsignedShortAddLE_base():var4.definition.walkSequence;
            var4.walkBackSequence = (var6 & 8) != 0?var1.readUnsignedShortAdd_base():var4.definition.walkBackSequence;
            var4.walkLeftSequence = (var6 & 16) != 0?var1.readUnsignedShortAddLE_base():var4.definition.walkLeftSequence;
            var4.walkRightSequence = (var6 & 32) != 0?var1.readUnsignedShortAdd_base():var4.definition.walkRightSequence;
            var4.runSequence = (var6 & 64) != 0?var1.readUnsignedShortLE_base():var4.definition.field1931;
            var4.field1185 = (var6 & 128) != 0?var1.readUnsignedShortAddLE_base():var4.definition.field1937;
            var4.field1186 = (var6 & 256) != 0?var1.readUnsignedShortAdd_base():var4.definition.field1954;
            var4.field1233 = (var6 & 512) != 0?var1.readUnsignedShort_base():var4.definition.field1962;
            var4.field1188 = (var6 & 1024) != 0?var1.readUnsignedShortAdd_base():var4.definition.field1961;
            var4.field1189 = (var6 & 2048) != 0?var1.readUnsignedShort_base():var4.definition.field1941;
            var4.field1190 = (var6 & 4096) != 0?var1.readUnsignedShortAdd_base():var4.definition.field1958;
            var4.field1239 = (var6 & 8192) != 0?var1.readUnsignedShortAdd_base():var4.definition.field1945;
            var4.idleSequence = (var6 & 16384) != 0?var1.readUnsignedShortAddLE_base():var4.definition.idleSequence;
         }

         if((var22 & 1) != 0) { // 3 - animation
            var6 = var1.readUnsignedShortLE_base();
            if(var6 == 65535) {
               var6 = -1;
            }

            var16 = var1.readUnsignedByte_base();
            if(var6 == var4.sequence && var6 != -1) {
               var15 = DynamicObject.method2245(var6).restartMode;
               if(var15 == 1) {
                  var4.sequenceFrame = 0;
                  var4.sequenceFrameCycle = 0;
                  var4.sequenceDelay = var16;
                  var4.field1199 = 0;
               }

               if(var15 == 2) {
                  var4.field1199 = 0;
               }
            } else if(var6 == -1 || var4.sequence == -1 || DynamicObject.method2245(var6).field2223 >= DynamicObject.method2245(var4.sequence).field2223) {
               var4.sequence = var6;
               var4.animationChanged(-1);
               var4.sequenceFrame = 0;
               var4.sequenceFrameCycle = 0;
               var4.sequenceDelay = var16;
               var4.field1199 = 0;
               var4.field1220 = var4.pathLength;
            }
         }

         if((var22 & 1024) != 0) { // 4 - force movement
            var4.field1209 = var1.readByteAdd_base();
            var4.field1194 = var1.readByteNeg_base();
            var4.field1224 = var1.readByteAdd_base();
            var4.field1203 = var1.readByteNeg_base();
            var4.spotAnimation = var1.readUnsignedShortAddLE_base() + Client.cycle;
            var4.field1187 = var1.readUnsignedShortAddLE_base() + Client.cycle;
            var4.field1229 = var1.readUnsignedShortAddLE_base();
            var4.pathLength = 1;
            var4.field1220 = 0;
            var4.field1209 += var4.pathX[0];
            var4.field1194 += var4.pathY[0];
            var4.field1224 += var4.pathX[0];
            var4.field1203 += var4.pathY[0];
         }

         if((var22 & 8192) != 0) { // 5 - combat level
            var4.field1247 = var1.readUnsignedIntIME_base();
         }

         if((var22 & 32) != 0) { // 6 - Face Location
            var6 = var1.readUnsignedShort_base();
            var16 = var1.readUnsignedShortLE_base();
            var4.field1211 = var1.readUnsignedByteNeg_base() == 1;
            if(Client.revision >= 212) {
               var4.field1178 = var6;
               var4.field1210 = var16;
            } else {
               var15 = var4.x - (var6 - NpcOverrides.baseX - NpcOverrides.baseX) * 64;
               var9 = var4.y - (var16 - class101.baseY - class101.baseY) * 64;
               if(var15 != 0 || var9 != 0) {
                  var4.field1208 = SequenceDefinition.method4094_base(var15, var9);
               }
            }
         }

         if((var22 & 128) != 0) { // 7 - face entity
            var4.targetIndex = var1.readUnsignedShort_base();
            var4.interactingChanged(-1);
            var4.targetIndex += var1.readUnsignedByteNeg_base() << 16;
            var4.interactingChanged(-1);
            var6 = 16777215;
            if(var6 == var4.targetIndex) {
               var4.targetIndex = -1;
               var4.interactingChanged(-1);
            }
         }

         if((var22 & 2) != 0) { // 8 - hit update
            var6 = var1.readUnsignedByteAdd_base();
            if(var6 > 0) {
               for(var16 = 0; var16 < var6; ++var16) {
                  var9 = -1;
                  var10 = -1;
                  var23 = -1;
                  var15 = var1.readUShortSmart_base();
                  if(var15 == 32767) {
                     var15 = var1.readUShortSmart_base();
                     var10 = var1.readUShortSmart_base();
                     var9 = var1.readUShortSmart_base();
                     var23 = var1.readUShortSmart_base();
                  } else if(var15 != 32766) {
                     var10 = var1.readUShortSmart_base();
                  } else {
                     var15 = -1;
                  }

                  var12 = var1.readUShortSmart_base();
                  var4.addHitSplat_base(var15, var10, var9, var23, Client.cycle, var12);
               }
            }

            var16 = var1.readUnsignedByteSub_base();
            if(var16 > 0) {
               for(var15 = 0; var15 < var16; ++var15) {
                  var9 = var1.readUShortSmart_base();
                  var10 = var1.readUShortSmart_base();
                  if(var10 != 32767) {
                     var23 = var1.readUShortSmart_base();
                     var12 = var1.readUnsignedByte_base();
                     int var13 = var10 > 0?var1.readUnsignedByte_base():var12;
                     var4.addHealthBar_base(var9, Client.cycle, var10, var23, var12, var13);
                  } else {
                     var4.removeHealthBar_base(var9);
                  }
               }
            }
         }

         if((var22 & 16384) != 0) { // 9 - name
            var4.method2713_base(var1.readStringCp1252NullTerminated_base());
         }

         if((var22 & 32768) != 0) { // 10 - IDK
            var4.method2660_base(var1.readUnsignedByteNeg_base());
         }

         if((var22 & 131072) != 0) { // 11 - graphic
            var6 = var1.readUnsignedByte_base();

            for(var16 = 0; var16 < var6; ++var16) {
               var15 = var1.readUnsignedByte_base();
               var9 = var1.readUnsignedShort_base();
               var10 = var1.readUnsignedIntIME_base();
               var4.updateSpotAnimation_base(var15, var9, var10 >> 16, var10 & 65535);
            }
         }

         if((var22 & 2048) != 0) { // 12 - model recolor
            var4.field1232 = Client.cycle + var1.readUnsignedShortLE_base();
            var4.field1215 = Client.cycle + var1.readUnsignedShortAddLE_base();
            var4.field1234 = var1.readByteAdd_base();
            var4.field1235 = var1.readByteNeg_base();
            var4.field1171 = var1.readByteAdd_base();
            var4.field1237 = (byte)var1.readUnsignedByteSub_base();
         }

         if((var22 & 512) != 0) { // 13 - IDK
            var6 = var1.readUnsignedByteNeg_base();
            if((var6 & 1) == 1) {
               var4.method2674_base();
            } else {
               var7 = null;
               if((var6 & 2) == 2) {
                  var15 = var1.readUnsignedByteNeg_base();
                  var7 = new int[var15];

                  for(var9 = 0; var9 < var15; ++var9) {
                     var10 = var1.readUnsignedShort_base();
                     var10 = var10 == 65535?-1:var10;
                     var7[var9] = var10;
                  }
               }

               var8 = null;
               if((var6 & 4) == 4) {
                  var9 = 0;
                  if(var4.definition.recolorTo != null) {
                     var9 = var4.definition.recolorTo.length;
                  }

                  var8 = new short[var9];

                  for(var10 = 0; var10 < var9; ++var10) {
                     var8[var10] = (short)var1.readUnsignedShort_base();
                  }
               }

               var18 = null;
               if((var6 & 8) == 8) {
                  var10 = 0;
                  if(var4.definition.retextureTo != null) {
                     var10 = var4.definition.retextureTo.length;
                  }

                  var18 = new short[var10];

                  for(var23 = 0; var23 < var10; ++var23) {
                     var18[var23] = (short)var1.readUnsignedShortAdd_base();
                  }
               }

               var24 = false;
               if((var6 & 16) != 0) {
                  var24 = var1.readUnsignedByteAdd_base() == 1;
               }

               var19 = (long)(++NPC.field1305 - 1);
               var4.method2671(new NpcOverrides(var19, var7, var8, var18, var24));
            }
         }

         if((var22 & 8) != 0) { // 14 - transform
            var10001 = VerticalAlignment.method3757(var1.readUnsignedShortLE_base());
            var4.onDefinitionChanged((RSNPCComposition)var10001);
            var4.definition = var10001;
            class33.method495(var4);
            var4.method2670_base();
         }

         if((var22 & 4) != 0) { // 15 - force chat
            var4.overheadText = var1.readStringCp1252NullTerminated_base();
            var4.overheadTextChanged(-1);
            var4.overheadTextCyclesRemaining = 100;
         }

         if((var22 & 64) != 0) { // 16 IDK, unused
            var1.readUnsignedShortAdd_base();
            var1.readUnsignedIntME_base();
         }
      }

      for(var21 = 0; var21 < Client.field617; ++var21) {
         var3 = Client.field618[var21];
         if(Client.npcs[var3].npcCycle != Client.cycle) {
            NPC var10000 = Client.npcs[var3];
            Client.npcs[var3].onDefinitionChanged((RSNPCComposition)null);
            var10000.definition = null;
            Client.npcs[var3] = null;
            Client.cachedNPCsChanged(var3);
         }
      }

      if(var1.offset != Client.packetWriter.serverPacketLength) {
         throw new RuntimeException(var1.offset + "," + Client.packetWriter.serverPacketLength);
      } else {
         for(var21 = 0; var21 < Client.npcCount; ++var21) {
            if(Client.npcs[Client.npcIndices[var21]] == null) {
               throw new RuntimeException(var21 + "," + Client.npcCount);
            }
         }

      }
   }
}
