package com.veil.adl.action;

import adl_2daa.IAction;
import adl_2daa.SequenceInterpreter;

import com.badlogic.gdx.math.Vector2;
import com.veil.adl.ItpData;
import com.veil.adl.literal.Position;
import com.veil.game.element.DynamicEntity;

public class RunTo implements IAction{

	@Override
	public boolean invoke(SequenceInterpreter itp, Object... param) {
		ItpData itpData = (ItpData)itp.getAdditionalData();
		Position pos = Position.parse(param[0]);
		float spd = ((Number)param[1]).floatValue();
		DynamicEntity dyn = itpData.thisAgent;
		
		Vector2 vec = new Vector2(pos.getX()-dyn.getWorldCenteredPosition().x,
				pos.getY()-dyn.getWorldCenteredPosition().y);
		boolean shouldEndAction = vec.len() <= spd;
		if(!shouldEndAction)
			vec = vec.nor().scl(spd);
		dyn.addVx(vec.x);
		dyn.addVy(vec.y);
		
		itpData.distance += spd;
		
		return shouldEndAction;
	}

	@Override
	public boolean isSpanAction() {
		// TODO Auto-generated method stub
		return true;
	}

}

@@ -542,16 +542,413 @@
 ent;%0A%09%09%0A
+%09%09boolean shouldEndAction = false;%0A%09%09if(itp.getSpannedActionInfo().containsKey(%22RunTo%22))%7B%0A%09%09%09Vector2 previousPos = (Vector2)itp.getSpannedActionInfo().get(%22RunTo%22);%0A%09%09%09if(dyn.getWorldCenteredPosition().dst(previousPos) %3C= 2)%7B%0A%09%09%09%09//If no movement between 2 update -- end action%0A%09%09%09%09shouldEndAction = true;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%7D%0A%09%09itp.getSpannedActionInfo().put(%22RunTo%22, dyn.getWorldCenteredPosition());%0A%09%09%0A
 %09%09Vector
@@ -1064,24 +1064,93 @@
 ).y);%0A%09%09
-boolean 
+if(vec.len() %3C= spd)%7B%0A%09%09%09//If getting close to target point -- end action%0A%09%09%09
 shouldEn
@@ -1163,25 +1163,17 @@
 n = 
-vec.len() %3C= spd;
+true;%0A%09%09%7D
 %0A%09%09i

Fix RunTo