package org.runite.client;
import java.util.Objects;
import java.util.Random;

final class TextureOperation38 extends TextureOperation {

   private int anInt3444 = 0;
   
   static int[] spritePalette;
   private int anInt3447 = 2000;
   static long[] aLongArray3448 = new long[1000];
   private int anInt3450 = 4096;
   private int anInt3451 = 16;
   static short[] aShortArray3453 = new short[256];
   private int anInt3454 = 0;
   static short[] aShortArray3455;
   static int[] anIntArray3456 = new int[4096];

   final void postDecode() {
      try {
         Class8.method844((byte)-9);
      } catch (RuntimeException var3) {
         throw ClientErrorException.clientError(var3, "vc.P(" + ')');
      }
   }

   final void decode(int var1, DataBuffer var2) {
      try {
         if(var1 == 0) {
            this.anInt3454 = var2.readUnsignedByte();
         } else if(var1 == 1) {
            this.anInt3447 = var2.readUnsignedShort();
         } else if(var1 == 2) {
            this.anInt3451 = var2.readUnsignedByte();
         } else if (3 == var1) {
             this.anInt3444 = var2.readUnsignedShort();
         } else if (var1 == 4) {
             this.anInt3450 = var2.readUnsignedShort();
         }

      } catch (RuntimeException var5) {
         throw ClientErrorException.clientError(var5, "vc.A(" + var1 + ',' + (var2 != null?"{...}":"null") + ',' + true + ')');
      }
   }

   public TextureOperation38() {
      super(0, true);
   }

   final int[] method154(int var1, byte var2) {
      try {
         int[] var3 = this.aClass114_2382.method1709(var1);
         if(this.aClass114_2382.aBoolean1580) {
            int var5 = this.anInt3450 >> 1;
            int[][] var6 = this.aClass114_2382.method1710((byte)93);
            Random var7 = new Random(this.anInt3454);

            for(int var8 = 0; this.anInt3447 > var8; ++var8) {
               int var9 = this.anInt3450 > 0?this.anInt3444 + -var5 + TextureOperation.method1603((byte)-99, this.anInt3450, var7):this.anInt3444;
               int var10 = TextureOperation.method1603((byte)-96, Class113.anInt1559, var7);
               var9 = (var9 & 4088) >> 4;
               int var11 = TextureOperation.method1603((byte)62, Class101.anInt1427, var7);
               int var12 = var10 - -(this.anInt3451 * Class75_Sub2.anIntArray2639[var9] >> 12);
               int var13 = var11 + (TextureOperation23.anIntArray3212[var9] * this.anInt3451 >> 12);
               int var15 = var12 - var10;
               int var14 = -var11 + var13;
               if(var15 != 0 || var14 != 0) {
                  if(var15 < 0) {
                     var15 = -var15;
                  }

                  if(var14 < 0) {
                     var14 = -var14;
                  }

                  boolean var16 = var14 > var15;
                  int var17;
                  int var18;
                  if(var16) {
                     var17 = var10;
                     var18 = var12;
                     var12 = var13;
                     var13 = var18;
                     var10 = var11;
                     var11 = var17;
                  }

                  if(var12 < var10) {
                     var17 = var10;
                     var18 = var11;
                     var10 = var12;
                     var11 = var13;
                     var13 = var18;
                     var12 = var17;
                  }

                  var18 = -var10 + var12;
                  int var19 = var13 + -var11;
                  var17 = var11;
                  if(var19 < 0) {
                     var19 = -var19;
                  }

                  int var20 = -var18 / 2;
                  int var22 = -(TextureOperation.method1603((byte)-18, 4096, var7) >> 2) + 1024;
                  int var23 = var11 >= var13 ?-1:1;
                  int var21 = 2048 / var18;

                  for(int var24 = var10; var12 > var24; ++var24) {
                     var20 += var19;
                     int var25 = var21 * (-var10 + var24) + var22 + 1024;
                     int var27 = var17 & Class3_Sub20.anInt2487;
                     if(0 < var20) {
                        var20 += -var18;
                        var17 += var23;
                     }

                     int var26 = RenderAnimationDefinition.anInt396 & var24;
                     if(var16) {
                        Objects.requireNonNull(var6)[var27][var26] = var25;
                     } else {
                        Objects.requireNonNull(var6)[var26][var27] = var25;
                     }
                  }
               }
            }
         }

         return var3;
      } catch (RuntimeException var28) {
         throw ClientErrorException.clientError(var28, "vc.D(" + var1 + ',' + var2 + ')');
      }
   }

}
