Distance - JohnDoeAntler/LF2-AI-Abstraction GitHub Wiki

A class that assists the calculation of distance and range determintion.

Constructor

The recommended method to instantiate Position object: click here.

Distance (Position@ pivot, Position@ target);

Properties

No property available.

Methods

predict

specify the weight of prediction, the weight is 0 by default.

// definition
Distance@ predict(double weight);

// examples
distance.predict(0);
distance.predict(5); // predict the distance after 5 game ticks.

getX

it will return the predicted x-axis distance between pivot and specified target.

// definition
double getX();

// examples
distance.getX();

getY

it will return the predicted y-axis distance between pivot and specified target.

// definition
double getY();

// examples
distance.getY();

getZ

it will return the predicted z-axis distance between pivot and specified target.

// definition
double getZ();

// examples
distance.getZ();

inX

it will check whether the x-axis distance between pivot and specified target is less than or equal to a given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ inX(int val);

// examples
distance.inX(50);

inY

it will check whether the y-axis distance between pivot and specified target is less than or equal to a given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ inY(int val);

// examples
distance.inY(40);

inZ

it will check whether the z-axis distance between pivot and specified target is less than or equal to a given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ inZ(int val);

// examples
distance.inZ(14);

inProjectileRange

it will check whether the specified target is in the given tangent scope of pivot, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ inProjectileRange(int x, int z);
Distance@ inProjectileRange(int x, int z, int zwidth, int offset);

// examples

// mocking henry normal arrow range
// 428 = max arrow attack range of x-axis
// 45 = max arrow attack range of z-axis
if (
  distance
    .inProjectileRange(428, 45)
    .toBoolean()
) {
  A();
}

// mocking henry normal arrow range
// 373 = max arrow attack range of x-axis
// 45 = max arrow attack range of z-axis
// 14 = zwidth of arrow itr
// 55 = the x-axis offset of the arrow spawning position
if (
  distance
    .inProjectileRange(373, 45, 14, 55)
    .toBoolean()
) {
  A();
}

outX

it will check whether the x-axis distance between pivot and specified target is greater than the given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ outX(int val);

// examples
distance.outX(20);

outY

it will check whether the y-axis distance between pivot and specified target is greater than the given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ outY(int val);

// examples
distance.outY(20);

outZ

it will check whether the z-axis distance between pivot and specified target is greater than the given value, the calculated value could be retrieved via toBoolean function.

// definition
Distance@ outZ(int val);

// examples
distance.outZ(20);

total

it will return the total length of the distance, the default distance calculation formula is x + y + z * 3.

// definition
double total();
double total(int x, int y, int z);

// examples
distance.total(); // using the default formula
distance.total(1,1,1); // using custom formula: x + y + z

toBoolean

this function is the core function of this entire class, it will return the boolean value result of previous calculation.

// definition
bool toBoolean();

// examples
if (
  distance
    .predict(3) // predict the distance after 3 game tick
    .inX(428) // the x-axis distance should be less than or equal to 428
    .inY(80) // the y-axis distance should be less than or equal to 80
    .inZ(45) // the z-axis distance should be less than or equal to 45
    .outX(30) // the x-axis distance should be greater than 30
    .inProjectileRange(
      373,
      45,
      14,
      55
    ) // check is in the tangent scope of henry arrow
    .toBoolean() // stop method chaining, get the result of the calculation
) {
    A(); // happy spamming arrow ;D
}

toString

return a nicely-formatted string.

toString();

// examples
distance.toString();

Snippets

No snippets available.

⚠️ **GitHub.com Fallback** ⚠️