package mapped;

import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.GraphicsObjectCreated;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSGraphicsObject;
import net.runelite.rs.api.RSRuneLiteObject;
import net.runelite.rs.api.RSSequenceDefinition;

@ObfuscatedName("cu")
public class GraphicsObject extends Renderable implements RSGraphicsObject {
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = -760217247
   )
   int id;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = -1322973095
   )
   int cycleStart;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1889541897
   )
   int plane;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = 1464920783
   )
   int x;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = -1449357735
   )
   int y;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = -609987307
   )
   int z;
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lhx;"
   )
   SequenceDefinition sequenceDefinition;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = -202407843
   )
   int frame;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = 1223932003
   )
   int frameCycle;
   @ObfuscatedName("az")
   boolean isFinished;

   public GraphicsObject() {
      this.rl$$init();
   }

   GraphicsObject(int var1, int var2, int var3, int var4, int var5, int var6, int var7) {
      this.frame = 0;
      this.frameCycle = 0;
      this.isFinished = false;
      this.id = var1;
      this.plane = var2;
      this.x = var3;
      this.y = var4;
      this.z = var5;
      this.cycleStart = var7 + var6;
      int var8 = Canvas.method324(this.id).sequence;
      if(var8 != -1) {
         this.isFinished = false;
         this.sequenceDefinition = DynamicObject.method2245(var8);
      } else {
         this.isFinished = true;
      }

      this.rl$$init();
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(IB)V",
      garbageValue = "-19"
   )
   final void advance_base(int var1) {
      this.copy$advance(var1, (byte)-19);
      if(this instanceof net.runelite.api.RuneLiteObject) {
         ((RSRuneLiteObject)this).advanceRL(var1);
      }

   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(B)Lka;",
      garbageValue = "1"
   )
   protected final Model vmethod5504() {
      return this instanceof net.runelite.api.RuneLiteObject?(Model)((RSRuneLiteObject)this).getModelRl():(Model)this.copy$getModel((byte)1);
   }

   public int getX() {
      return this.x;
   }

   @ObfuscatedSignature(
      descriptor = "(IB)V",
      garbageValue = "-19"
   )
   public final void copy$advance(int var1, byte var2) {
      if(!this.isFinished) {
         this.frameCycle += var1;
         if(!this.sequenceDefinition.isCachedModelIdSet_base()) {
            while(this.frameCycle > this.sequenceDefinition.frameLengths[this.frame]) {
               this.frameCycle -= this.sequenceDefinition.frameLengths[this.frame];
               ++this.frame;
               if(this.frame >= this.sequenceDefinition.frameIds.length) {
                  this.isFinished = true;
                  break;
               }
            }
         } else {
            this.frame += var1;
            if(this.frame >= this.sequenceDefinition.method4064_base()) {
               this.isFinished = true;
            }
         }

      }
   }

   public void setFrame(int var1) {
      this.frame = var1;
   }

   public RSSequenceDefinition getSequenceDefinition() {
      return this.sequenceDefinition;
   }

   public void setX(int var1) {
      this.x = var1;
   }

   @ObfuscatedSignature(
      descriptor = "(B)Lka;",
      garbageValue = "1"
   )
   public final Model copy$getModel(byte var1) {
      SpotAnimationDefinition var2 = Canvas.method324(this.id);
      Model var3;
      if(!this.isFinished) {
         var3 = var2.method3762(this.frame);
      } else {
         var3 = var2.method3762(-1);
      }

      return var3 == null?null:var3;
   }

   public int getY() {
      return this.y;
   }

   public void setFrameCycle(int var1) {
      this.frameCycle = var1;
   }

   private void rl$$init() {
      GraphicsObjectCreated var1 = new GraphicsObjectCreated(this);
      SpriteMask.client.getCallbacks().post(var1);
   }

   public void setY(int var1) {
      this.y = var1;
   }

   public void setSequenceDefinition(RSSequenceDefinition var1) {
      this.sequenceDefinition = (SequenceDefinition)var1;
   }

   public void setLevel(int var1) {
      this.plane = var1;
   }

   public boolean finished() {
      return this.isFinished;
   }

   public int getFrame() {
      return this.frame;
   }

   public void setFinished(boolean var1) {
      this.isFinished = var1;
   }

   public void setZ(int var1) {
      this.z = var1;
   }

   public LocalPoint getLocation() {
      return new LocalPoint(this.getX(), this.getY());
   }

   public int getId() {
      return this.id;
   }

   public void setId(int var1) {
      this.id = var1;
   }

   public int getStartCycle() {
      return this.cycleStart;
   }

   public int getLevel() {
      return this.plane;
   }

   public int getZ() {
      return this.z;
   }

   public int getFrameCycle() {
      return this.frameCycle;
   }

   public void advance(int var1) {
      this.advance_base(var1);
   }

   public RSSequenceDefinition getAnimation() {
      return this.sequenceDefinition;
   }

   public int getAnimationFrame() {
      return this.frame;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(IIB)Z",
      garbageValue = "-39"
   )
   public static boolean method2128_base(int var0, int var1) {
      return (var0 >> var1 + 1 & 1) != 0;
   }
}
