package mapped;

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

@ObfuscatedName("jo")
public class WorldMapData_1 extends AbstractWorldMapData implements RSWorldMapData_1 {
   @ObfuscatedName("jc")
   static byte[][] regionLandArchives;
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = 1340751779
   )
   int chunkXLow;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = -191139103
   )
   int chunkYLow;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1637974201
   )
   int chunkX;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -312876519
   )
   int chunkY;

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Luj;I)V",
      garbageValue = "1464083774"
   )
   void method4770(Buffer var1) {
      int var2 = var1.readUnsignedByte_base();
      if(var2 != WorldMapID.field2607.value) {
         throw new IllegalStateException("");
      } else {
         super.minPlane = var1.readUnsignedByte_base();
         super.planes = var1.readUnsignedByte_base();
         super.regionXLow = var1.readUnsignedShort_base();
         super.regionYLow = var1.readUnsignedShort_base();
         this.chunkXLow = var1.readUnsignedByte_base();
         this.chunkYLow = var1.readUnsignedByte_base();
         super.regionX = var1.readUnsignedShort_base();
         super.regionY = var1.readUnsignedShort_base();
         this.chunkX = var1.readUnsignedByte_base();
         this.chunkY = var1.readUnsignedByte_base();
         super.groupId = var1.readNullableLargeSmart_base();
         super.fileId = var1.readNullableLargeSmart_base();
      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luj;B)V",
      garbageValue = "7"
   )
   void vmethod4896(Buffer var1) {
      super.planes = Math.min(super.planes, 4);
      super.floorUnderlayIds = new short[1][64][64];
      super.floorOverlayIds = new short[super.planes][64][64];
      super.field2560 = new byte[super.planes][64][64];
      super.field2571 = new byte[super.planes][64][64];
      super.decorations = new WorldMapDecoration[super.planes][64][64][];
      int var2 = var1.readUnsignedByte_base();
      if(var2 != class250.field2602.value) {
         throw new IllegalStateException("");
      } else {
         int var3 = var1.readUnsignedByte_base();
         int var4 = var1.readUnsignedByte_base();
         int var5 = var1.readUnsignedByte_base();
         int var6 = var1.readUnsignedByte_base();
         if(var3 == super.regionX && var4 == super.regionY && var5 == this.chunkX && var6 == this.chunkY) {
            for(int var7 = 0; var7 < 8; ++var7) {
               for(int var8 = 0; var8 < 8; ++var8) {
                  this.method4907(var7 + this.chunkX * 8, var8 + this.chunkY * 8, var1);
               }
            }

         } else {
            throw new IllegalStateException("");
         }
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "2104981166"
   )
   int getChunkXLow_base() {
      return this.chunkXLow;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "6"
   )
   int getChunkYLow_base() {
      return this.chunkYLow;
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "0"
   )
   int getChunkX_base() {
      return this.chunkX;
   }

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "98"
   )
   int getChunkY_base() {
      return this.chunkY;
   }

   public int hashCode() {
      return super.regionX | super.regionY << 8 | this.chunkX << 16 | this.chunkY << 24;
   }

   public boolean equals(Object var1) {
      if(!(var1 instanceof WorldMapData_1)) {
         return false;
      } else {
         WorldMapData_1 var2 = (WorldMapData_1)var1;
         return var2.regionX == super.regionX && var2.regionY == super.regionY?var2.chunkX == this.chunkX && var2.chunkY == this.chunkY:false;
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(III)Ldt;",
      garbageValue = "1462611314"
   )
   static Script method4789(int var0, int var1) {
      Script var2 = (Script)Script.Script_cached.get((long)(var0 << 16));
      if(var2 != null) {
         return var2;
      } else {
         String var3 = String.valueOf(var0);
         int var4 = class47.archive12.getGroupId_base(var3);
         if(var4 == -1) {
            return null;
         } else {
            byte[] var5 = class47.archive12.takeFileFlat_base(var4);
            if(var5 != null) {
               if(var5.length <= 1) {
                  return null;
               }

               var2 = NpcOverrides.method3690(var5);
               if(var2 != null) {
                  Script.Script_cached.put(var2, (long)(var0 << 16));
                  return var2;
               }
            }

            return null;
         }
      }
   }

   @ObfuscatedName("hj")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "5"
   )
   static int method4797_base() {
      if(Client.archiveLoaders != null && Client.archiveLoadersDone < Client.archiveLoaders.size()) {
         int var0 = 0;

         for(int var1 = 0; var1 <= Client.archiveLoadersDone; ++var1) {
            var0 += ((ArchiveLoader)Client.archiveLoaders.get(var1)).loadedCount;
         }

         return var0 * 10000 / Client.field645;
      } else {
         return 10000;
      }
   }
}
