package to.oa.qha98.ballisticCalculator;

import static java.lang.Math.*;

import org.bukkit.util.Vector;

public class FireballBallisticCalculator extends BallisticCalculator {
	private static final double F=0.95d;
	
	private final Vector acc;
	private final Vector k;
	
	public FireballBallisticCalculator(Vector v1, Vector v2){
		acc=v2.clone().multiply(1/F).subtract(v1);
		k=acc.clone().multiply(F/(1-F));
	}
	@Override
	public Vector getVelocityAfter(int tick, Vector initialVelocity) {
		return initialVelocity.clone().subtract(k).multiply(pow(F, tick)).add(k);
	}

	@Override
	public Vector getDisplacementAfter(int tick, Vector initialVelocity) {
		return initialVelocity.clone().subtract(k).multiply((1-pow(F, tick))/(1-F)).add(k.clone().multiply(tick));
	}
	@Override
	public Vector getInitialVelocityToTargetByAirTick(int airtime,Vector displacement) {
		if(airtime<=0)
			return FAILED;
		else
			return displacement.clone().subtract(k.clone().multiply(airtime)).multiply((F-1)/(pow(F,airtime)-1)).add(k);
	}
}
