package mapped;

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

@ObfuscatedName("ld")
public class PacketBufferNode extends Node implements RSPacketBufferNode {
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "[Lld;"
   )
   static PacketBufferNode[] PacketBufferNode_packetBufferNodes;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = -1591179597
   )
   static int PacketBufferNode_packetBufferNodeCount;
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Llq;"
   )
   ClientPacket clientPacket;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = 1596400087
   )
   int clientPacketLength;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Luo;"
   )
   public PacketBuffer packetBuffer;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -1934564091
   )
   public int index;

   static {
      PacketBufferNode_packetBufferNodes = new PacketBufferNode[300];
      PacketBufferNode_packetBufferNodeCount = 0;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1380070255"
   )
   public void release_base() {
      if(PacketBufferNode_packetBufferNodeCount < PacketBufferNode_packetBufferNodes.length) {
         PacketBufferNode_packetBufferNodes[++PacketBufferNode_packetBufferNodeCount - 1] = this;
      }
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(III)I",
      garbageValue = "-1877979689"
   )
   public static int method5929_base(int var0, int var1) {
      return (int)Math.round(Math.atan2((double)var0, (double)var1) * 2607.5945876176133D) & 16383;
   }

   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "(ZI)V",
      garbageValue = "1854762565"
   )
   static void method5917_base(boolean var0) {
      if(var0) {
         SecureRandomCallable.method2326_base();
      } else {
         for(int var1 = 0; var1 < class316.musicSongs.size(); ++var1) {
            MusicSong var2 = (MusicSong)class316.musicSongs.get(var1);
            if(var2 == null) {
               class316.musicSongs.remove(var1);
               --var1;
            } else if(var2.field3526) {
               if(var2.midiPcmStream.field3455 > 0) {
                  --var2.midiPcmStream.field3455;
               }

               var2.midiPcmStream.clear_base();
               var2.midiPcmStream.method6011_base();
               var2.midiPcmStream.setPcmStreamVolume_base(0);
               class316.musicSongs.remove(var1);
               --var1;
            } else {
               var2.field3526 = true;
            }
         }
      }

   }

   @ObfuscatedName("lc")
   @ObfuscatedSignature(
      descriptor = "(IIIIS)V",
      garbageValue = "-9846"
   )
   static final void addSceneMenuOptions_base(int var0, int var1, int var2, int var3) {
      if(Client.isItemSelected == 0 && !Client.isSpellSelected) {
         WorldMapSectionType.insertMenuItemNoShift_base("Walk here", "", 23, 0, var0 - var2, var1 - var3);
      }

      long var4 = -1L;
      long var6 = -1L;

      int var8;
      for(var8 = 0; var8 < class93.method2450_base(); ++var8) {
         long var9 = ViewportMouse.ViewportMouse_entityTags[var8];
         if(var9 != var6) {
            var6 = var9;
            long var15 = ViewportMouse.ViewportMouse_entityTags[var8];
            int var14 = (int)(var15 >>> 0 & 127L);
            var14 = var14;
            int var27 = GrandExchangeOfferAgeComparator.method7113_base(var8);
            int var16 = class128.method3081_base(var8);
            int var17 = class232.Entity_unpackID_base(ViewportMouse.ViewportMouse_entityTags[var8]);
            int var18 = var17;
            int var22;
            if(var16 == 2 && class36.scene.getObjectFlags_base(ItemLayer.Client_plane, var14, var27, var9) >= 0) {
               ObjectComposition var19 = WorldMapSection2.method4515(var17);
               if(var19.transforms != null) {
                  var19 = var19.method3907();
               }

               if(var19 == null) {
                  continue;
               }

               PendingSpawn var28 = null;

               for(PendingSpawn var21 = (PendingSpawn)Client.pendingSpawns.method7265(); var21 != null; var21 = (PendingSpawn)Client.pendingSpawns.method7235()) {
                  if(var21.plane == ItemLayer.Client_plane && var14 == var21.x && var27 == var21.y && var18 == var21.field1162) {
                     var28 = var21;
                     break;
                  }
               }

               if(Client.isItemSelected == 1) {
                  WorldMapSectionType.insertMenuItemNoShift_base("Use", Client.field767 + " " + "->" + " " + class167.colorStartTag_base(65535) + var19.name, 1, var18, var14, var27);
               } else if(Client.isSpellSelected) {
                  if((UrlRequest.selectedSpellFlags & 4) == 4) {
                     WorldMapSectionType.insertMenuItemNoShift_base(Client.selectedSpellActionName, Client.selectedSpellName + " " + "->" + " " + class167.colorStartTag_base(65535) + var19.name, 2, var18, var14, var27);
                  }
               } else {
                  String[] var34 = var19.actions;
                  if(var34 != null) {
                     for(var22 = 4; var22 >= 0; --var22) {
                        if((var28 == null || var28.method2455_base(var22)) && var34[var22] != null) {
                           short var30 = 0;
                           if(var22 == 0) {
                              var30 = 3;
                           }

                           if(var22 == 1) {
                              var30 = 4;
                           }

                           if(var22 == 2) {
                              var30 = 5;
                           }

                           if(var22 == 3) {
                              var30 = 6;
                           }

                           if(var22 == 4) {
                              var30 = 1001;
                           }

                           WorldMapSectionType.insertMenuItemNoShift_base(var34[var22], class167.colorStartTag_base(65535) + var19.name, var30, var18, var14, var27);
                        }
                     }
                  }

                  WorldMapSectionType.insertMenuItemNoShift_base("Examine", class167.colorStartTag_base(65535) + var19.name, 1002, var19.id, var14, var27);
               }
            }

            int var20;
            Player var23;
            NPC var35;
            int[] var36;
            if(var16 == 1) {
               NPC var31 = Client.npcs[var18];
               if(var31 == null) {
                  continue;
               }

               if(var31.definition.size == 1 && (var31.x & 127) == 64 && (var31.y & 127) == 64) {
                  for(var20 = 0; var20 < Client.npcCount; ++var20) {
                     var35 = Client.npcs[Client.npcIndices[var20]];
                     if(var35 != null && var35 != var31 && var35.definition.size == 1 && var35.x == var31.x && var35.y == var31.y) {
                        WorldMapLabelSize.method4485(var35, Client.npcIndices[var20], var14, var27);
                     }
                  }

                  var20 = Players.Players_count;
                  var36 = Players.Players_indices;

                  for(var22 = 0; var22 < var20; ++var22) {
                     var23 = Client.players[var36[var22]];
                     if(var23 != null && var23.x == var31.x && var23.y == var31.y) {
                        ArchiveDiskAction.method6888(var23, var36[var22], var14, var27);
                     }
                  }
               }

               WorldMapLabelSize.method4485(var31, var18, var14, var27);
            }

            if(var16 == 0) {
               Player var32 = Client.players[var18];
               if(var32 == null) {
                  continue;
               }

               if((var32.x & 127) == 64 && (var32.y & 127) == 64) {
                  for(var20 = 0; var20 < Client.npcCount; ++var20) {
                     var35 = Client.npcs[Client.npcIndices[var20]];
                     if(var35 != null && var35.definition.size == 1 && var32.x == var35.x && var32.y == var35.y) {
                        WorldMapLabelSize.method4485(var35, Client.npcIndices[var20], var14, var27);
                     }
                  }

                  var20 = Players.Players_count;
                  var36 = Players.Players_indices;

                  for(var22 = 0; var22 < var20; ++var22) {
                     var23 = Client.players[var36[var22]];
                     if(var23 != null && var32 != var23 && var32.x == var23.x && var23.y == var32.y) {
                        ArchiveDiskAction.method6888(var23, var36[var22], var14, var27);
                     }
                  }
               }

               if(var18 != Client.combatTargetPlayerIndex) {
                  ArchiveDiskAction.method6888(var32, var18, var14, var27);
               } else {
                  var4 = var9;
               }
            }

            if(var16 == 3) {
               NodeDeque var33 = Client.groundItems[ItemLayer.Client_plane][var14][var27];
               if(var33 != null) {
                  for(TileItem var38 = (TileItem)var33.method7258(); var38 != null; var38 = (TileItem)var33.method7236()) {
                     ItemComposition var37 = class214.method4226(var38.id);
                     if(Client.isItemSelected == 1) {
                        WorldMapSectionType.insertMenuItemNoShift_base("Use", Client.field767 + " " + "->" + " " + class167.colorStartTag_base(16748608) + var37.name, 16, var38.id, var14, var27);
                     } else if(Client.isSpellSelected) {
                        if((UrlRequest.selectedSpellFlags & 1) == 1) {
                           WorldMapSectionType.insertMenuItemNoShift_base(Client.selectedSpellActionName, Client.selectedSpellName + " " + "->" + " " + class167.colorStartTag_base(16748608) + var37.name, 17, var38.id, var14, var27);
                        }
                     } else {
                        String[] var29 = var37.groundActions;

                        for(int var39 = 4; var39 >= 0; --var39) {
                           if(var38.method2755_base(var39)) {
                              if(var29 != null && var29[var39] != null) {
                                 byte var24 = 0;
                                 if(var39 == 0) {
                                    var24 = 18;
                                 }

                                 if(var39 == 1) {
                                    var24 = 19;
                                 }

                                 if(var39 == 2) {
                                    var24 = 20;
                                 }

                                 if(var39 == 3) {
                                    var24 = 21;
                                 }

                                 if(var39 == 4) {
                                    var24 = 22;
                                 }

                                 WorldMapSectionType.insertMenuItemNoShift_base(var29[var39], class167.colorStartTag_base(16748608) + var37.name, var24, var38.id, var14, var27);
                              } else if(var39 == 2) {
                                 WorldMapSectionType.insertMenuItemNoShift_base("Take", class167.colorStartTag_base(16748608) + var37.name, 20, var38.id, var14, var27);
                              }
                           }
                        }

                        WorldMapSectionType.insertMenuItemNoShift_base("Examine", class167.colorStartTag_base(16748608) + var37.name, 1004, var38.id, var14, var27);
                     }
                  }
               }
            }
         }
      }

      if(-1L != var4) {
         var8 = (int)(var4 >>> 0 & 127L);
         int var10 = (int)(var4 >>> 7 & 127L);
         Player var12 = Client.players[Client.combatTargetPlayerIndex];
         ArchiveDiskAction.method6888(var12, Client.combatTargetPlayerIndex, var8, var10);
      }

   }

   @ObfuscatedName("oo")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "-1716534762"
   )
   public static boolean method5925_base() {
      return Client.clickedWidget != null;
   }
}
