package mapped;

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

@ObfuscatedName("rh")
public class Buddy extends User implements RSBuddy {
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = -1077063835
   )
   public int world;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = -977987065
   )
   public int int2;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = -461792485
   )
   public int rank;

   Buddy() {
      this.world = -1;
   }

   @ObfuscatedName("bu")
   @ObfuscatedSignature(
      descriptor = "(IIB)V",
      garbageValue = "2"
   )
   void set_base(int var1, int var2) {
      this.world = var1;
      this.int2 = var2;
   }

   @ObfuscatedName("by")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "48"
   )
   public int getWorld_base() {
      return this.world;
   }

   @ObfuscatedName("bh")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "1781991225"
   )
   public boolean hasWorld_base() {
      return this.world > 0;
   }

   public int getRSRank() {
      return this.rank;
   }

   public int getWorld() {
      return this.getWorld_base();
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(Luo;II)Z",
      garbageValue = "1704651337"
   )
   static boolean method8273(PacketBuffer var0, int var1) {
      int var2 = var0.readBits_base(2);
      int var3;
      int var4;
      int var7;
      int var8;
      int var9;
      int var10;
      if(var2 == 0) {
         if(var0.readBits_base(1) != 0) {
            method8273(var0, var1);
         }

         var3 = var0.readBits_base(13);
         var4 = var0.readBits_base(13);
         boolean var12 = var0.readBits_base(1) == 1;
         if(var12) {
            Players.Players_pendingUpdateIndices[++Players.Players_pendingUpdateCount - 1] = var1;
         }

         if(Client.players[var1] != null) {
            throw new RuntimeException();
         } else {
            Player var10000 = Client.players[var1] = new Player();
            Client.cachedPlayersChanged(var1);
            Player var6 = var10000;
            var6.index = var1;
            if(Players.field1357[var1] != null) {
               var6.method2387(Players.field1357[var1]);
            }

            var6.orientation = Players.Players_orientations[var1];
            var6.targetIndex = Players.Players_targetIndices[var1];
            var6.interactingChanged(-1);
            var7 = Players.Players_regions[var1];
            var8 = var7 >> 28;
            var9 = var7 >> 14 & 255;
            var10 = var7 & 255;
            var6.pathTraversed[0] = Players.field1356[var1];
            var6.plane = (byte)var8;
            var6.resetPath_base((var9 << 13) + var3 - NpcOverrides.baseX, (var10 << 13) + var4 - class101.baseY);
            var6.field1122 = false;
            return true;
         }
      } else if(var2 == 1) {
         var3 = var0.readBits_base(2);
         var4 = Players.Players_regions[var1];
         Players.Players_regions[var1] = (var4 & 268435455) + (((var4 >> 28) + var3 & 3) << 28);
         return false;
      } else {
         int var5;
         int var11;
         if(var2 == 2) {
            var3 = var0.readBits_base(5);
            var4 = var3 >> 3;
            var5 = var3 & 7;
            var11 = Players.Players_regions[var1];
            var7 = (var11 >> 28) + var4 & 3;
            var8 = var11 >> 14 & 255;
            var9 = var11 & 255;
            if(var5 == 0) {
               --var8;
               --var9;
            }

            if(var5 == 1) {
               --var9;
            }

            if(var5 == 2) {
               ++var8;
               --var9;
            }

            if(var5 == 3) {
               --var8;
            }

            if(var5 == 4) {
               ++var8;
            }

            if(var5 == 5) {
               --var8;
               ++var9;
            }

            if(var5 == 6) {
               ++var9;
            }

            if(var5 == 7) {
               ++var8;
               ++var9;
            }

            Players.Players_regions[var1] = (var8 << 14) + var9 + (var7 << 28);
            return false;
         } else {
            var3 = var0.readBits_base(18);
            var4 = var3 >> 16;
            var5 = var3 >> 8 & 255;
            var11 = var3 & 255;
            var7 = Players.Players_regions[var1];
            var8 = (var7 >> 28) + var4 & 3;
            var9 = var5 + (var7 >> 14) & 255;
            var10 = var11 + var7 & 255;
            Players.Players_regions[var1] = (var9 << 14) + var10 + (var8 << 28);
            return false;
         }
      }
   }
}
