package mapped;

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

@ObfuscatedName("hu")
public class FloorUnderlayDefinition extends DualNode implements RSFloorUnderlayDefinition {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive FloorUnderlayDefinition_archive;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable FloorUnderlayDefinition_cached;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1132257727
   )
   int rgb;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -856680181
   )
   public int hue;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = 1806065313
   )
   public int saturation;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = -927410829
   )
   public int lightness;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = 825539727
   )
   public int hueMultiplier;

   static {
      FloorUnderlayDefinition_cached = new EvictingDualNodeHashTable(64);
   }

   FloorUnderlayDefinition() {
      this.rgb = 0;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "110"
   )
   void postDecode_base() {
      this.setHsl_base(this.rgb);
   }

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

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

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Luj;IIS)V",
      garbageValue = "29369"
   )
   void method3784(Buffer var1, int var2, int var3) {
      if(var2 == 1) {
         this.rgb = var1.readUnsignedMedium_base();
      }

   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(II)V",
      garbageValue = "511229306"
   )
   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 = (var8 + var10) / 2.0D;
      if(var8 != var10) {
         if(var16 < 0.5D) {
            var14 = (var10 - var8) / (var8 + var10);
         }

         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 = 4.0D + (var2 - var4) / (var10 - var8);
         }
      }

      var12 /= 6.0D;
      this.saturation = (int)(var14 * 256.0D);
      this.lightness = (int)(var16 * 256.0D);
      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;
      }

      if(var16 > 0.5D) {
         this.hueMultiplier = (int)(512.0D * (1.0D - var16) * var14);
      } else {
         this.hueMultiplier = (int)(512.0D * var16 * var14);
      }

      if(this.hueMultiplier < 1) {
         this.hueMultiplier = 1;
      }

      this.hue = (int)(var12 * (double)this.hueMultiplier);
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(II)Ljava/lang/String;",
      garbageValue = "1384349139"
   )
   static String method3799_base(int var0) {
      return "<img=" + var0 + ">";
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "([FIFZFZ[FI)I",
      garbageValue = "-1537766732"
   )
   public static int method3791_base(float[] var0, int var1, float var2, boolean var3, float var4, boolean var5, float[] var6) {
      float var7 = 0.0F;

      for(int var8 = 0; var8 < var1 + 1; ++var8) {
         var7 += Math.abs(var0[var8]);
      }

      float var24 = (Math.abs(var2) + Math.abs(var4)) * (float)(var1 + 1) * class127.field1484;
      if(var7 <= var24) {
         return -1;
      } else {
         float[] var9 = new float[var1 + 1];

         int var10;
         for(var10 = 0; var10 < var1 + 1; ++var10) {
            var9[var10] = var0[var10] * (1.0F / var7);
         }

         while(Math.abs(var9[var1]) < var24) {
            --var1;
         }

         var10 = 0;
         if(var1 == 0) {
            return var10;
         } else if(var1 == 1) {
            var6[0] = -var9[0] / var9[1];
            boolean var11 = var3?var2 < var6[0] + var24:var2 < var6[0] - var24;
            boolean var12 = var5?var4 > var6[0] - var24:var4 > var24 + var6[0];
            var10 = var11 && var12?1:0;
            if(var10 > 0) {
               if(var3 && var6[0] < var2) {
                  var6[0] = var2;
               } else if(var5 && var6[0] > var4) {
                  var6[0] = var4;
               }
            }

            return var10;
         } else {
            class464 var21 = new class464(var9, var1);
            float[] var22 = new float[var1 + 1];

            for(int var13 = 1; var13 <= var1; ++var13) {
               var22[var13 - 1] = (float)var13 * var9[var13];
            }

            float[] var23 = new float[var1 + 1];
            int var14 = method3791_base(var22, var1 - 1, var2, false, var4, false, var23);
            if(var14 == -1) {
               return 0;
            } else {
               boolean var15 = false;
               float var17 = 0.0F;
               float var18 = 0.0F;
               float var19 = 0.0F;

               for(int var20 = 0; var20 <= var14; ++var20) {
                  if(var10 > var1) {
                     return var10;
                  }

                  float var16;
                  if(var20 == 0) {
                     var16 = var2;
                     var18 = WorldMapID.method4936_base(var9, var1, var2);
                     if(Math.abs(var18) <= var24 && var3) {
                        var6[var10++] = var2;
                     }
                  } else {
                     var16 = var19;
                     var18 = var17;
                  }

                  if(var20 == var14) {
                     var19 = var4;
                     var15 = false;
                  } else {
                     var19 = var23[var20];
                  }

                  var17 = WorldMapID.method4936_base(var9, var1, var19);
                  if(var15) {
                     var15 = false;
                  } else if(Math.abs(var17) < var24) {
                     if(var14 != var20 || var5) {
                        var6[var10++] = var19;
                        var15 = true;
                     }
                  } else if(var18 < 0.0F && var17 > 0.0F || var18 > 0.0F && var17 < 0.0F) {
                     var6[var10++] = ClanSettings.method3387_base(var21, var16, var19, 0.0F);
                     if(var10 > 1 && var6[var10 - 2] >= var6[var10 - 1] - var24) {
                        var6[var10 - 2] = (var6[var10 - 2] + var6[var10 - 1]) * 0.5F;
                        --var10;
                     }
                  }
               }

               return var10;
            }
         }
      }
   }
}
