incremental claimblock prices

This commit is contained in:
destro174 2022-02-18 11:05:31 +01:00
parent b784eea500
commit bf1c4c38a2

View File

@ -69,6 +69,7 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
@ -1868,7 +1869,7 @@ public class GriefPrevention extends JavaPlugin
//if the player can't afford his purchase, send error message
double balance = economy.getBalance(player);
double totalCost = blockCount * GriefPrevention.instance.config_economy_claimBlocksPurchaseCost;
double totalCost = claimBlockCost(playerData.getBonusClaimBlocks()+playerData.getAccruedClaimBlocks() , blockCount);
if (totalCost > balance)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.InsufficientFunds, String.valueOf(totalCost), String.valueOf(balance));
@ -3897,14 +3898,49 @@ public class GriefPrevention extends JavaPlugin
portalReturnTaskMap.put(player.getUniqueId(), task);
}
private double claimBlockCost(int currentClaimBlocks, int blockCount) {
private static final double[] xMult = { 0, 500, 10000, 50000, 300000, 1000000};
private static final double[] yMultBuy = { 0.25, 0.5, 0.75, 1, 2, 5};
private double claimBlockCost(int oldPoints, int transPts) {
if (Config.claimBlockPrices.isEmpty())
return blockCount * GriefPrevention.instance.config_economy_claimBlocksPurchaseCost;
return transPts * GriefPrevention.instance.config_economy_claimBlocksPurchaseCost;
double totalBlocks = currentClaimBlocks + blockCount;
double cost = 0;
// TODO finish me
return cost;
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++;
}
for (int i = segment; i < xMult.length && high > xMult[i - 1]; i++)
finalPrice += getPricePerInterval(oldPoints, high, i);
return finalPrice;
}
private double getPricePerInterval(int start_points, int end_points, int segment) {
double bottom = xMult[segment - 1];
double top = xMult[segment];
double priceMult = yMultBuy[segment - 1];
double pricePerPoint = 1;
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;
}
}