package gameEngine.actors.behaviors;

import gameAuthoring.scenes.pathBuilding.pathComponents.routeToPointTranslation.BackendRoute;
import gameEngine.actors.BaseActor;
import gameEngine.actors.BaseProjectile;
import gameEngine.actors.RealActor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.geometry.Point2D;

public abstract class RangeAttack extends BaseAttack{

    public RangeAttack (double attackSpeed) {
        super(attackSpeed);
    }
    
    protected void shootActorFromActor(BaseActor target, BaseActor actor){
        RealActor shooter=(RealActor) actor;
        Point2D shooterLoc = new Point2D(shooter.getX(), shooter.getY());
        Point2D targetLoc = new Point2D(target.getX(),target.getY());
        BackendRoute route=new BackendRoute(shooterLoc, targetLoc); 
        BaseProjectile projectile=new BaseProjectile(shooter.getProjectile().copy());
        projectile.getInfo().getMove().setRoute(route);
        shooter.spawnProjectile(projectile);
        double heading = getOrientation(shooterLoc,targetLoc);
        shooter.getNode().setRotate(-heading);
        projectile.getNode().setRotate(-heading);
        myCooldown=(int)myAttackSpeed;
    }

    private double getOrientation (Point2D shooter, Point2D target) {
        Point2D dif = shooter.subtract(target).normalize();
        return Math.toDegrees(Math.atan2(dif.getX(), dif.getY())) + 180;
    }
}

@@ -31,16 +31,85 @@
 viors;%0A%0A
+import gameAuthoring.scenes.pathBuilding.buildingPanes.BuildingPane;%0A
 import g
@@ -416,16 +416,17 @@
 int2D;%0A%0A
+%0A
 public a
@@ -473,11 +473,123 @@
 tack
+ 
 %7B%0A%0A
+    private static final int IMAGE_ANGLE_OFFSET = 270;%0A    private static final double DISTANCE_FACTOR = 2.0;%0A%0A
     
@@ -664,20 +664,16 @@
 ;%0A    %7D%0A
-    
 %0A    pro
@@ -703,16 +703,17 @@
 romActor
+ 
 (BaseAct
@@ -739,16 +739,17 @@
 r actor)
+ 
 %7B%0A      
@@ -767,17 +767,19 @@
  shooter
-=
+ = 
 (RealAct
@@ -917,16 +917,17 @@
 .getX(),
+ 
 target.g
@@ -926,32 +926,158 @@
 target.getY());%0A
+        Point2D unitVector = targetLoc.subtract(shooterLoc).normalize();%0A        double heading = getOrientation(unitVector);%0A
         BackendR
@@ -1086,17 +1086,19 @@
 te route
-=
+ = 
 new Back
@@ -1122,20 +1122,95 @@
 oc, 
-targetLoc
+shooterLoc.add(unitVector.multiply(BuildingPane.DRAW_SCREEN_WIDTH * DISTANCE_FACTOR))
 );
- 
 %0A   
@@ -1239,17 +1239,19 @@
 ojectile
-=
+ = 
 new Base
@@ -1399,71 +1399,8 @@
 e);%0A
-        double heading = getOrientation(shooterLoc,targetLoc);%0A
     
@@ -1423,33 +1423,32 @@
 ode().setRotate(
--
 heading);%0A      
@@ -1484,9 +1484,8 @@
 ate(
--
 head
@@ -1512,14 +1512,17 @@
 down
-=
+ = 
 (int)
+ 
 myAt
@@ -1586,94 +1586,14 @@
 t2D 
-shooter, Point2D target) %7B%0A        Point2D dif = shooter.subtract(target).normalize();
+dif) %7B
 %0A   
@@ -1633,25 +1633,25 @@
 tan2(dif.get
-X
+Y
 (), dif.getY
@@ -1653,19 +1653,34 @@
 .get
-Y
+X
 ())) + 
-180
+IMAGE_ANGLE_OFFSET
 ;%0A  

allow projectiles to travel farther