2021-10-23 12:42:55 +00:00
|
|
|
package com.alttd.objects;
|
|
|
|
|
|
|
|
|
|
import com.alttd.util.Utilities;
|
|
|
|
|
|
2021-11-10 15:58:47 +00:00
|
|
|
public final class Price {
|
|
|
|
|
private final double price;
|
|
|
|
|
private final int points;
|
|
|
|
|
|
2021-12-31 17:44:49 +00:00
|
|
|
private static final double[] xMult = {Integer.MIN_VALUE, -4000, -2000, -500, 500, 2000, 4000, Integer.MAX_VALUE};
|
2022-01-03 00:50:37 +00:00
|
|
|
private static final double[] yMultBuy = {0.6, 0.75, 0.9, 1, 1.5, 2.5, 5};
|
|
|
|
|
private static final double[] yMultSell = {0.2, 0.4, 0.7, 1, 1.25, 1.75, 2.5};
|
2021-12-17 19:44:38 +00:00
|
|
|
|
2021-11-10 15:58:47 +00:00
|
|
|
public Price(double price) {
|
|
|
|
|
this.price = price;
|
2021-12-21 02:18:06 +00:00
|
|
|
this.points = (int) price;
|
2021-11-10 15:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-23 12:42:55 +00:00
|
|
|
public static Price addPrice(Price one, Price two) {
|
2021-11-10 15:58:47 +00:00
|
|
|
return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2)));
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getPrice(int multiplier) {
|
|
|
|
|
return (Utilities.round(price * multiplier, 2));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 17:44:49 +00:00
|
|
|
public double calculatePriceThing(int oldPoints, int transPts, boolean buying, int itemPts) {
|
|
|
|
|
double finalPrice = 0; //Initialize final price
|
|
|
|
|
int segment = 1; //Start segment at one
|
|
|
|
|
int high = oldPoints + transPts; //Will be the highest point value
|
|
|
|
|
|
|
|
|
|
if (oldPoints > high) //If high is not the highest point value, swap it with oldPoints so it is
|
|
|
|
|
{
|
|
|
|
|
int temp = oldPoints;
|
|
|
|
|
oldPoints = high;
|
|
|
|
|
high = temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (oldPoints > xMult[segment] && segment < xMult.length - 1) { //Calculate the start segment (first value smaller than lower)
|
|
|
|
|
segment++;
|
2021-12-23 22:00:59 +00:00
|
|
|
}
|
2021-12-31 17:44:49 +00:00
|
|
|
|
|
|
|
|
for (int i = segment; i < xMult.length && high > xMult[i - 1]; i++)
|
|
|
|
|
finalPrice += getPricePerInterval(oldPoints, high, i, buying, itemPts);
|
|
|
|
|
return Utilities.round(finalPrice, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double getPricePerInterval(int start_points, int end_points, int segment, boolean buying, int itemPts) {
|
|
|
|
|
double bottom = xMult[segment - 1];
|
|
|
|
|
double top = xMult[segment];
|
|
|
|
|
double priceMult = buying ? yMultBuy[segment - 1] : yMultSell[segment - 1];
|
|
|
|
|
double pricePerPoint = price / itemPts;
|
|
|
|
|
|
|
|
|
|
if (start_points <= bottom && end_points <= top)// +_---+---
|
|
|
|
|
return (end_points - bottom) * pricePerPoint * priceMult;
|
|
|
|
|
else if (start_points <= bottom && end_points >= top) // +_---_+
|
|
|
|
|
return (top - bottom) * pricePerPoint * priceMult;
|
|
|
|
|
else if (start_points >= bottom && end_points <= top) // _--+--+--_
|
|
|
|
|
return (end_points - start_points) * pricePerPoint * priceMult;
|
|
|
|
|
else if (start_points >= bottom && end_points >= top) // _--+--_+
|
|
|
|
|
return (top - start_points) * pricePerPoint * priceMult;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
2021-12-17 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-08 19:28:25 +00:00
|
|
|
public int getPoints() {
|
|
|
|
|
return (points);
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|
2021-11-10 15:58:47 +00:00
|
|
|
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|