package mapped;

import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.TileObject;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSGameObject;
import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSRenderable;

@ObfuscatedName("le")
public final class GameObject implements RSGameObject, TileObject {
   @ObfuscatedName("aj")
   static String[] field3091;
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = 2078922457
   )
   int plane;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = -415100769
   )
   int z;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = -2117082253
   )
   int centerX;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = 1222462707
   )
   int centerY;
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Lkt;"
   )
   public Renderable renderable;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = 1248145487
   )
   int orientation;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = -1925243401
   )
   int startX;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = -471526341
   )
   int endX;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = -294435209
   )
   int startY;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = -822585263
   )
   int endY;
   @ObfuscatedName("ap")
   @ObfuscatedGetter(
      intValue = 1812635965
   )
   int field3093;
   @ObfuscatedName("av")
   @ObfuscatedGetter(
      intValue = 1902942925
   )
   int lastDrawn;
   @ObfuscatedName("ax")
   @ObfuscatedGetter(
      longValue = 5918743696151912835L
   )
   public long tag;
   @ObfuscatedName("as")
   @ObfuscatedGetter(
      intValue = -2091094119
   )
   int flags;
   public int gameObjectPlane;

   GameObject() {
      this.tag = 0L;
      this.flags = 0;
   }

   public Point getCanvasLocation(int var1) {
      return Perspective.localToCanvas(SpriteMask.client, this.getLocalLocation(), this.getPlane(), var1);
   }

   public RSModel getModel() {
      RSRenderable var1 = this.getRenderable();
      return var1 == null?null:(var1 instanceof RSModel?(RSModel)var1:var1.getModel());
   }

   public int getStartX() {
      return this.startX;
   }

   public int getEndX() {
      return this.endX;
   }

   public int getEndY() {
      return this.endY;
   }

   public RSRenderable getRenderable() {
      return this.renderable;
   }

   public int getModelOrientation() {
      return this.orientation;
   }

   public long getHash() {
      return this.tag;
   }

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

   public int getId() {
      long var1 = this.getHash();
      return (int)(var1 >>> 17 & 4294967295L);
   }

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

   public int getConfig() {
      return this.flags;
   }

   public int getStartY() {
      return this.startY;
   }

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

   public int getPlane() {
      return this.gameObjectPlane;
   }

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

   public void setPlane(int var1) {
      this.gameObjectPlane = var1;
   }

   public Point getSceneMinLocation() {
      return new Point(this.getStartX(), this.getStartY());
   }

   public Point getSceneMaxLocation() {
      return new Point(this.getEndX(), this.getEndY());
   }

   public Shape getClickbox() {
      return Perspective.getClickbox(SpriteMask.client, this.getModel(), this.getModelOrientation(), this.getX(), this.getY(), this.getZ());
   }

   public Shape getConvexHull() {
      RSModel var1 = this.getModel();
      if(var1 == null) {
         return null;
      } else {
         int var2 = Perspective.getTileHeight(SpriteMask.client, new LocalPoint(this.getX(), this.getY()), SpriteMask.client.getPlane());
         return var1.getConvexHull(this.getX(), this.getY(), this.getModelOrientation(), var2);
      }
   }

   public int getOrientation() {
      int var1 = this.getModelOrientation();
      int var2 = this.getConfig() >> 6 & 3;
      return var1 + var2 * 512;
   }

   public int sizeX() {
      return this.getEndX() - this.getStartX() + 1;
   }

   public int sizeY() {
      return this.getEndY() - this.getStartY() + 1;
   }

   public String getName() {
      return SpriteMask.client.getObjectDefinition(this.getId()).getName();
   }

   public String[] getActions() {
      return SpriteMask.client.getObjectDefinition(this.getId()).getActions();
   }

   public WorldPoint getWorldLocation() {
      if(this instanceof RSGameObject) {
         RSGameObject var1 = (RSGameObject)this;
         int var2 = var1.getStartX();
         int var3 = var1.getStartY();
         int var4 = var1.getEndX() - var2;
         int var5 = var1.getEndY() - var3;
         return WorldPoint.fromScene(SpriteMask.client, var4 / 2 + var2, var5 / 2 + var3, this.getPlane());
      } else {
         return WorldPoint.fromLocal(SpriteMask.client, this.getX(), this.getY(), this.getPlane());
      }
   }

   public Point getCanvasLocation() {
      return this.getCanvasLocation(0);
   }

   public Polygon getCanvasTilePoly() {
      int var1 = 1;
      int var2 = 1;
      if(this instanceof RSGameObject) {
         var1 = ((RSGameObject)this).sizeX();
         var2 = ((RSGameObject)this).sizeY();
      }

      return Perspective.getCanvasTileAreaPoly(SpriteMask.client, this.getLocalLocation(), var1, var2, this.getPlane(), 0);
   }

   public Point getCanvasTextLocation(Graphics2D var1, String var2, int var3) {
      return Perspective.getCanvasTextLocation(SpriteMask.client, var1, this.getLocalLocation(), var2, var3);
   }

   public Point getMinimapLocation() {
      return Perspective.localToMinimap(SpriteMask.client, this.getLocalLocation());
   }
}
