package mapped;

import java.awt.datatransfer.Clipboard;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;

@ObfuscatedName("ij")
public class class221 implements class29 {
   @ObfuscatedName("pk")
   @ObfuscatedGetter(
      intValue = -93724707
   )
   static int field2343;
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lnn;"
   )
   Widget field2340;
   @ObfuscatedName("ah")
   boolean field2341;
   @ObfuscatedName("ar")
   boolean field2342;

   public class221() {
      this.field2340 = null;
      this.field2341 = false;
      this.field2342 = false;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(IS)Z",
      garbageValue = "512"
   )
   public boolean vmethod4310_base(int var1) {
      if(this.field2340 == null) {
         return false;
      } else {
         class27 var2 = this.field2340.method6690_base();
         if(var2 == null) {
            return false;
         } else {
            if(var2.method422_base(var1)) {
               switch(var1) {
               case 81:
                  this.field2342 = true;
                  break;
               case 82:
                  this.field2341 = true;
                  break;
               default:
                  if(this.method4285_base(var1)) {
                     class159.method3423(this.field2340);
                  }
               }
            }

            return var2.method409_base(var1);
         }
      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Z",
      garbageValue = "-1146773117"
   )
   public boolean vmethod4320_base(int var1) {
      switch(var1) {
      case 81:
         this.field2342 = false;
         return false;
      case 82:
         this.field2341 = false;
         return false;
      default:
         return false;
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(CI)Z",
      garbageValue = "984376689"
   )
   public boolean vmethod4321_base(char var1) {
      if(this.field2340 == null) {
         return false;
      } else if(!DirectByteArrayCopier.method6830_base(var1)) {
         return false;
      } else {
         class341 var2 = this.field2340.method6688_base();
         if(var2 != null && var2.method6394_base()) {
            class27 var3 = this.field2340.method6690_base();
            if(var3 == null) {
               return false;
            } else {
               if(var3.method412_base(var1) && var2.method6378_base(var1)) {
                  class159.method3423(this.field2340);
               }

               return var3.method410_base(var1);
            }
         } else {
            return false;
         }
      }
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(ZB)Z",
      garbageValue = "-49"
   )
   public boolean vmethod4312_base(boolean var1) {
      return false;
   }

   @ObfuscatedName("av")
   @ObfuscatedSignature(
      descriptor = "(Lnn;I)V",
      garbageValue = "950407656"
   )
   public void method4279(Widget var1) {
      if(var1 != null) {
         if(var1 != this.field2340) {
            this.method4281_base();
            this.field2340 = var1;
         }

         class339 var2 = var1.method6767_base();
         if(var2 != null) {
            if(!var2.field3593.method6640_base() && var2.field3592 != null) {
               ScriptEvent var3 = new ScriptEvent();
               var3.method2357(var1);
               var3.setArgs_base(var2.field3592);
               FileSystem.method4225().method7233(var3);
            }

            var2.field3593.method6361_base(true);
         }
      } else {
         this.method4281_base();
      }

   }

   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "(S)Lnn;",
      garbageValue = "-15065"
   )
   public Widget method4303() {
      return this.field2340;
   }

   @ObfuscatedName("as")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-881991302"
   )
   public void method4281_base() {
      if(this.field2340 != null) {
         class339 var1 = this.field2340.method6767_base();
         Widget var2 = this.field2340;
         this.field2340 = null;
         if(var1 != null) {
            if(var1.field3593.method6640_base() && var1.field3592 != null) {
               ScriptEvent var3 = new ScriptEvent();
               var3.method2357(var2);
               var3.setArgs_base(var1.field3592);
               FileSystem.method4225().method7233(var3);
            }

            var1.field3593.method6361_base(false);
         }
      }
   }

   @ObfuscatedName("ay")
   @ObfuscatedSignature(
      descriptor = "(IB)Z",
      garbageValue = "2"
   )
   boolean method4285_base(int var1) {
      if(this.field2340 == null) {
         return false;
      } else {
         class341 var2 = this.field2340.method6688_base();
         if(var2 != null && var2.method6394_base()) {
            Clipboard var5;
            switch(var1) {
            case 13:
               this.method4281_base();
               return true;
            case 48:
               if(this.field2341) {
                  var2.method6434_base();
               }

               return true;
            case 65:
               if(this.field2341) {
                  var5 = SpriteMask.client.method498_base();
                  var2.method6403_base(var5);
               }

               return true;
            case 66:
               if(this.field2341) {
                  var5 = SpriteMask.client.method498_base();
                  var2.method6402_base(var5);
               }

               return true;
            case 67:
               if(this.field2341) {
                  var5 = SpriteMask.client.method498_base();
                  var2.method6546_base(var5);
               }

               return true;
            case 84:
               if(var2.method6423_base() == 0) {
                  var2.method6378_base(10);
               } else if(this.field2342 && var2.method6426_base()) {
                  var2.method6378_base(10);
               } else {
                  class339 var3 = this.field2340.method6767_base();
                  ScriptEvent var4 = new ScriptEvent();
                  var4.method2357(this.field2340);
                  var4.setArgs_base(var3.field3595);
                  FileSystem.method4225().method7233(var4);
                  this.method4281_base();
               }

               return true;
            case 85:
               if(this.field2341) {
                  var2.method6428_base();
               } else {
                  var2.method6368_base();
               }

               return true;
            case 96:
               if(this.field2341) {
                  var2.method6392_base(this.field2342);
               } else {
                  var2.method6390_base(this.field2342);
               }

               return true;
            case 97:
               if(this.field2341) {
                  var2.method6393_base(this.field2342);
               } else {
                  var2.method6391_base(this.field2342);
               }

               return true;
            case 98:
               if(this.field2341) {
                  var2.method6405_base();
               } else {
                  var2.method6602_base(this.field2342);
               }

               return true;
            case 99:
               if(this.field2341) {
                  var2.method6406_base();
               } else {
                  var2.method6395_base(this.field2342);
               }

               return true;
            case 101:
               if(this.field2341) {
                  var2.method6382_base();
               } else {
                  var2.method6380_base();
               }

               return true;
            case 102:
               if(this.field2341) {
                  var2.method6565_base(this.field2342);
               } else {
                  var2.method6440_base(this.field2342);
               }

               return true;
            case 103:
               if(this.field2341) {
                  var2.method6389_base(this.field2342);
               } else {
                  var2.method6387_base(this.field2342);
               }

               return true;
            case 104:
               if(this.field2341) {
                  var2.method6596_base(this.field2342);
               } else {
                  var2.method6396_base(this.field2342);
               }

               return true;
            case 105:
               if(this.field2341) {
                  var2.method6506_base(this.field2342);
               } else {
                  var2.method6397_base(this.field2342);
               }

               return true;
            default:
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(B)[Laa;",
      garbageValue = "-14"
   )
   public static class6[] method4305_base() {
      return new class6[]{class6.field16};
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Luo;I)V",
      garbageValue = "-620397215"
   )
   static final void method4304(PacketBuffer var0) {
      int var1 = 0;
      var0.importIndex_base();

      int var2;
      int var3;
      int var4;
      for(var2 = 0; var2 < Players.Players_count; ++var2) {
         var3 = Players.Players_indices[var2];
         if((Players.field1366[var3] & 1) == 0) {
            if(var1 > 0) {
               --var1;
               Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
            } else {
               var4 = var0.readBits_base(1);
               if(var4 == 0) {
                  var1 = Client.method1394(var0);
                  Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
               } else {
                  class9.method86(var0, var3);
               }
            }
         }
      }

      var0.exportIndex_base();
      if(var1 != 0) {
         throw new RuntimeException();
      } else {
         var0.importIndex_base();

         for(var2 = 0; var2 < Players.Players_count; ++var2) {
            var3 = Players.Players_indices[var2];
            if((Players.field1366[var3] & 1) != 0) {
               if(var1 > 0) {
                  --var1;
                  Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
               } else {
                  var4 = var0.readBits_base(1);
                  if(var4 == 0) {
                     var1 = Client.method1394(var0);
                     Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                  } else {
                     class9.method86(var0, var3);
                  }
               }
            }
         }

         var0.exportIndex_base();
         if(var1 != 0) {
            throw new RuntimeException();
         } else {
            var0.importIndex_base();

            for(var2 = 0; var2 < Players.Players_emptyIdxCount; ++var2) {
               var3 = Players.Players_emptyIndices[var2];
               if((Players.field1366[var3] & 1) != 0) {
                  if(var1 > 0) {
                     --var1;
                     Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                  } else {
                     var4 = var0.readBits_base(1);
                     if(var4 == 0) {
                        var1 = Client.method1394(var0);
                        Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                     } else if(Buddy.method8273(var0, var3)) {
                        Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                     }
                  }
               }
            }

            var0.exportIndex_base();
            if(var1 != 0) {
               throw new RuntimeException();
            } else {
               var0.importIndex_base();

               for(var2 = 0; var2 < Players.Players_emptyIdxCount; ++var2) {
                  var3 = Players.Players_emptyIndices[var2];
                  if((Players.field1366[var3] & 1) == 0) {
                     if(var1 > 0) {
                        --var1;
                        Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                     } else {
                        var4 = var0.readBits_base(1);
                        if(var4 == 0) {
                           var1 = Client.method1394(var0);
                           Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                        } else if(Buddy.method8273(var0, var3)) {
                           Players.field1366[var3] = (byte)(Players.field1366[var3] | 2);
                        }
                     }
                  }
               }

               var0.exportIndex_base();
               if(var1 != 0) {
                  throw new RuntimeException();
               } else {
                  Players.Players_count = 0;
                  Players.Players_emptyIdxCount = 0;

                  for(var2 = 1; var2 < 2048; ++var2) {
                     Players.field1366[var2] = (byte)(Players.field1366[var2] >> 1);
                     Player var5 = Client.players[var2];
                     if(var5 != null) {
                        Players.Players_indices[++Players.Players_count - 1] = var2;
                     } else {
                        Players.Players_emptyIndices[++Players.Players_emptyIdxCount - 1] = var2;
                     }
                  }

               }
            }
         }
      }
   }
}
