package mapped;

import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.Reflection;
import net.runelite.rs.api.RSBuffer;
import net.runelite.rs.api.RSFloorOverlayDefinition;

@ObfuscatedName("hd")
public class FloorOverlayDefinition extends DualNode implements RSFloorOverlayDefinition {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive FloorOverlayDefinition_archive;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable FloorOverlayDefinition_cached;
   @ObfuscatedName("ve")
   @ObfuscatedGetter(
      intValue = 57709805
   )
   static int field2194;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = -35615287
   )
   public int primaryRgb;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -2118857867
   )
   public int texture;
   @ObfuscatedName("ab")
   public boolean hideUnderlay;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = -1500626921
   )
   public int secondaryRgb;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = -1648808253
   )
   public int hue;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = 1001398063
   )
   public int saturation;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = -2112714123
   )
   public int lightness;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = -447286151
   )
   public int secondaryHue;
   @ObfuscatedName("ap")
   @ObfuscatedGetter(
      intValue = -1458718483
   )
   public int secondarySaturation;
   @ObfuscatedName("av")
   @ObfuscatedGetter(
      intValue = -729708453
   )
   public int secondaryLightness;

   static {
      FloorOverlayDefinition_cached = new EvictingDualNodeHashTable(64);
   }

   FloorOverlayDefinition() {
      this.primaryRgb = 0;
      this.texture = -1;
      this.hideUnderlay = true;
      this.secondaryRgb = -1;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "563834011"
   )
   void postDecode_base() {
      if(this.secondaryRgb != -1) {
         this.setHsl_base(this.secondaryRgb);
         this.secondaryHue = this.hue;
         this.secondarySaturation = this.saturation;
         this.secondaryLightness = this.lightness;
      }

      this.setHsl_base(this.primaryRgb);
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Luj;II)V",
      garbageValue = "1543407873"
   )
   void method4018(Buffer var1, int var2) {
      while(true) {
         int var3 = var1.readUnsignedByte_base();
         if(var3 == 0) {
            return;
         }

         this.method4027(var1, var3, var2);
      }
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Luj;IIB)V",
      garbageValue = "2"
   )
   void method4027(Buffer var1, int var2, int var3) {
      if(var2 == 1) {
         this.primaryRgb = var1.readUnsignedMedium_base();
      } else if(var2 == 2) {
         this.texture = var1.readUnsignedByte_base();
      } else if(var2 == 5) {
         this.hideUnderlay = false;
      } else if(var2 == 7) {
         this.secondaryRgb = var1.readUnsignedMedium_base();
      } else if(var2 == 8) {
         ;
      }

   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(II)V",
      garbageValue = "-1030496121"
   )
   void setHsl_base(int var1) {
      double var2 = (double)(var1 >> 16 & 255) / 256.0D;
      double var4 = (double)(var1 >> 8 & 255) / 256.0D;
      double var6 = (double)(var1 & 255) / 256.0D;
      double var8 = var2;
      if(var4 < var2) {
         var8 = var4;
      }

      if(var6 < var8) {
         var8 = var6;
      }

      double var10 = var2;
      if(var4 > var2) {
         var10 = var4;
      }

      if(var6 > var10) {
         var10 = var6;
      }

      double var12 = 0.0D;
      double var14 = 0.0D;
      double var16 = (var10 + var8) / 2.0D;
      if(var8 != var10) {
         if(var16 < 0.5D) {
            var14 = (var10 - var8) / (var10 + var8);
         }

         if(var16 >= 0.5D) {
            var14 = (var10 - var8) / (2.0D - var10 - var8);
         }

         if(var2 == var10) {
            var12 = (var4 - var6) / (var10 - var8);
         } else if(var10 == var4) {
            var12 = (var6 - var2) / (var10 - var8) + 2.0D;
         } else if(var10 == var6) {
            var12 = (var2 - var4) / (var10 - var8) + 4.0D;
         }
      }

      var12 /= 6.0D;
      this.hue = (int)(256.0D * var12);
      this.saturation = (int)(256.0D * var14);
      this.lightness = (int)(256.0D * var16);
      if(this.saturation < 0) {
         this.saturation = 0;
      } else if(this.saturation > 255) {
         this.saturation = 255;
      }

      if(this.lightness < 0) {
         this.lightness = 0;
      } else if(this.lightness > 255) {
         this.lightness = 255;
      }

   }

   public int getPrimaryRgb() {
      return this.primaryRgb;
   }

   public int getTexture() {
      return this.texture;
   }

   public void postDecode() {
      this.postDecode_base();
   }

   public void decode(RSBuffer var1, int var2) {
      this.method4018((Buffer)var1, var2);
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Lgv;",
      garbageValue = "-1578338318"
   )
   public static VarpDefinition method4037(int var0) {
      VarpDefinition var1 = (VarpDefinition)VarpDefinition.VarpDefinition_cached.get((long)var0);
      if(var1 != null) {
         return var1;
      } else {
         byte[] var2 = VarpDefinition.VarpDefinition_archive.takeFile_base(16, var0);
         var1 = new VarpDefinition();
         if(var2 != null) {
            var1.method3555(new Buffer(var2));
         }

         VarpDefinition.VarpDefinition_cached.put(var1, (long)var0);
         return var1;
      }
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;I)Ljava/lang/Class;",
      garbageValue = "92814810"
   )
   static Class loadClassFromDescriptor_base(String var0) throws ClassNotFoundException {
      return var0.equals("B")?Byte.TYPE:(var0.equals("I")?Integer.TYPE:(var0.equals("S")?Short.TYPE:(var0.equals("J")?Long.TYPE:(var0.equals("Z")?Boolean.TYPE:(var0.equals("F")?Float.TYPE:(var0.equals("D")?Double.TYPE:(var0.equals("C")?Character.TYPE:(var0.equals("void")?Void.TYPE:Reflection.findClass(var0)))))))));
   }

   @ObfuscatedName("an")
   @ObfuscatedSignature(
      descriptor = "(ILdt;ZB)I",
      garbageValue = "-19"
   )
   static int method4035(int var0, Script var1, boolean var2) {
      Widget var3;
      if(var0 == 2700) {
         var3 = HealthBarDefinition.widgetDefinition.method6287(Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize]);
         Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = var3.itemId;
         return 1;
      } else if(var0 == 2701) {
         var3 = HealthBarDefinition.widgetDefinition.method6287(Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize]);
         if(var3.itemId != -1) {
            Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = var3.itemQuantity;
         } else {
            Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = 0;
         }

         return 1;
      } else if(var0 == 2702) {
         int var5 = Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize];
         InterfaceParent var4 = (InterfaceParent)Client.interfaceParents.get((long)var5);
         if(var4 != null) {
            Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = 1;
         } else {
            Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = 0;
         }

         return 1;
      } else if(var0 == 2706) {
         Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = Client.rootInterface;
         return 1;
      } else if(var0 == 2707) {
         var3 = HealthBarDefinition.widgetDefinition.method6287(Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize]);
         Interpreter.Interpreter_intStack[++DbTableType.Interpreter_intStackSize - 1] = var3.method6682_base()?1:0;
         return 1;
      } else if(var0 == 2708) {
         var3 = HealthBarDefinition.widgetDefinition.method6287(Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize]);
         return class310.method5940(var3);
      } else if(var0 == 2709) {
         var3 = HealthBarDefinition.widgetDefinition.method6287(Interpreter.Interpreter_intStack[--DbTableType.Interpreter_intStackSize]);
         return GrandExchangeOfferTotalQuantityComparator.method7082(var3);
      } else {
         return 2;
      }
   }

   @ObfuscatedName("lw")
   @ObfuscatedSignature(
      descriptor = "(IIIILjava/lang/String;B)V",
      garbageValue = "8"
   )
   static void widgetDefaultMenuAction_base(int var0, int var1, int var2, int var3, String var4) {
      Widget var5 = HealthBarDefinition.widgetDefinition.method6281(var1, var2);
      if(var5 != null) {
         if(var5.onOp != null) {
            ScriptEvent var6 = new ScriptEvent();
            var6.widget = var5;
            var6.opIndex = var0;
            var6.targetName = var4;
            var6.args = var5.onOp;
            class157.method3403(var6);
         }

         boolean var8 = true;
         if(var5.contentType > 0) {
            var8 = class101.method2724(var5);
         }

         if(var8) {
            if(GraphicsObject.method2128_base(class361.method6871(var5), var0 - 1)) {
               PacketBufferNode var7;
               if(var0 == 1) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON1, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 2) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON2, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 3) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON3, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 4) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON4, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 5) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON5, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 6) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON6, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 7) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON7, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 8) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON8, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 9) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON9, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

               if(var0 == 10) {
                  var7 = class113.method2919(ClientPacket.IF_BUTTON10, Client.packetWriter.isaacCipher);
                  var7.packetBuffer.writeInt_base(var1);
                  var7.packetBuffer.writeShort_base(var2);
                  var7.packetBuffer.writeShort_base(var3);
                  Client.packetWriter.method2867(var7);
               }

            }
         }
      }
   }
}
