package mapped;

import java.security.SecureRandom;
import net.runelite.api.events.PostHealthBar;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSBuffer;
import net.runelite.rs.api.RSHealthBarDefinition;
import net.runelite.rs.api.RSSpritePixels;

@ObfuscatedName("gh")
public class HealthBarDefinition extends DualNode implements RSHealthBarDefinition {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive HealthBarDefinition_archive;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable HealthBarDefinition_cached;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable HealthBarDefinition_cachedSprites;
   @ObfuscatedName("eb")
   @ObfuscatedSignature(
      descriptor = "Lmr;"
   )
   static WidgetDefinition widgetDefinition;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = 1659826943
   )
   public int field1870;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = -1405285573
   )
   public int int1;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = 318693701
   )
   public int int2;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = -583737083
   )
   public int int3;
   @ObfuscatedName("ap")
   @ObfuscatedGetter(
      intValue = -1271315221
   )
   public int field1874;
   @ObfuscatedName("av")
   @ObfuscatedGetter(
      intValue = -1099648425
   )
   public int int5;
   @ObfuscatedName("ax")
   @ObfuscatedGetter(
      intValue = -2045655285
   )
   int frontSpriteID;
   @ObfuscatedName("as")
   @ObfuscatedGetter(
      intValue = -1279527771
   )
   int backSpriteID;
   @ObfuscatedName("ay")
   @ObfuscatedGetter(
      intValue = -1392965729
   )
   public int width;
   @ObfuscatedName("ak")
   @ObfuscatedGetter(
      intValue = 186493939
   )
   public int widthPadding;

   static {
      HealthBarDefinition_cached = new EvictingDualNodeHashTable(64);
      HealthBarDefinition_cachedSprites = new EvictingDualNodeHashTable(64);
   }

   HealthBarDefinition() {
      this.int1 = 255;
      this.int2 = 255;
      this.int3 = -1;
      this.field1874 = 1;
      this.int5 = 70;
      this.frontSpriteID = -1;
      this.backSpriteID = -1;
      this.width = 30;
      this.widthPadding = 0;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luj;I)V",
      garbageValue = "-1942652761"
   )
   void method3641(Buffer var1) {
      while(true) {
         int var2 = var1.readUnsignedByte_base();
         if(var2 == 0) {
            this.onRead(var1);
            return;
         }

         this.method3633(var1, var2);
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Luj;II)V",
      garbageValue = "88568767"
   )
   void method3633(Buffer var1, int var2) {
      if(var2 == 1) {
         var1.readUnsignedShort_base();
      } else if(var2 == 2) {
         this.int1 = var1.readUnsignedByte_base();
      } else if(var2 == 3) {
         this.int2 = var1.readUnsignedByte_base();
      } else if(var2 == 4) {
         this.int3 = 0;
      } else if(var2 == 5) {
         this.int5 = var1.readUnsignedShort_base();
      } else if(var2 == 6) {
         var1.readUnsignedByte_base();
      } else if(var2 == 7) {
         this.frontSpriteID = var1.readNullableLargeSmart_base();
      } else if(var2 == 8) {
         this.backSpriteID = var1.readNullableLargeSmart_base();
      } else if(var2 == 11) {
         this.int3 = var1.readUnsignedShort_base();
      } else if(var2 == 14) {
         this.width = var1.readUnsignedByte_base();
      } else if(var2 == 15) {
         this.widthPadding = var1.readUnsignedByte_base();
      }

   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(I)Luz;",
      garbageValue = "-309117701"
   )
   public SpritePixels method3634() {
      if(this.frontSpriteID < 0) {
         return null;
      } else {
         SpritePixels var1 = (SpritePixels)HealthBarDefinition_cachedSprites.get((long)this.frontSpriteID);
         if(var1 != null) {
            return var1;
         } else {
            var1 = IgnoreList.method8066(SecureRandomCallable.field1014, this.frontSpriteID, 0);
            if(var1 != null) {
               HealthBarDefinition_cachedSprites.put(var1, (long)this.frontSpriteID);
            }

            return var1;
         }
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(B)Luz;",
      garbageValue = "54"
   )
   public SpritePixels method3635() {
      if(this.backSpriteID < 0) {
         return null;
      } else {
         SpritePixels var1 = (SpritePixels)HealthBarDefinition_cachedSprites.get((long)this.backSpriteID);
         if(var1 != null) {
            return var1;
         } else {
            var1 = IgnoreList.method8066(SecureRandomCallable.field1014, this.backSpriteID, 0);
            if(var1 != null) {
               HealthBarDefinition_cachedSprites.put(var1, (long)this.backSpriteID);
            }

            return var1;
         }
      }
   }

   public void onRead(RSBuffer var1) {
      PostHealthBar var2 = new PostHealthBar();
      var2.setHealthBar(this);
      SpriteMask.client.getCallbacks().post(var2);
   }

   public int getHealthBarFrontSpriteId() {
      return this.frontSpriteID;
   }

   public int getHealthScale() {
      return this.width;
   }

   public void setPadding(int var1) {
      this.widthPadding = var1;
   }

   public RSSpritePixels getHealthBarFrontSprite() {
      return this.method3634();
   }

   public RSSpritePixels getHealthBarBackSprite() {
      return this.method3635();
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(I)Ljava/security/SecureRandom;",
      garbageValue = "1872253772"
   )
   static SecureRandom method3639_base() {
      SecureRandom var0 = new SecureRandom();
      var0.nextInt();
      return var0;
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-876386223"
   )
   public static void method3654_base() {
      try {
         JagexCache.JagexCache_dat2File.close_base();

         for(int var0 = 0; var0 < UserComparator6.field1464; ++var0) {
            KeyHandler.JagexCache_idxFiles[var0].close_base();
         }

         JagexCache.JagexCache_idx255File.close_base();
         JagexCache.JagexCache_randomDat.close_base();
      } catch (Exception var2) {
         ;
      }

   }
}
