1.5
This commit is contained in:
parent
b9e029cbe3
commit
c21d1e4848
19 changed files with 51 additions and 39 deletions
|
|
@ -26,21 +26,7 @@ public class Info {
|
|||
|
||||
player.sendMessage("Total item count: " + Shared.formatNumber(totalItemCount));
|
||||
|
||||
double totalValue = 0.0;
|
||||
|
||||
// OPTIMIZATION: Iterating over entrySet() prevents redundant .get() lookups on every loop cycle
|
||||
for (Map.Entry<String, Long> entry : market.items.entrySet()) {
|
||||
Material material = Material.matchMaterial(entry.getKey());
|
||||
|
||||
if (material != null) {
|
||||
long amount = entry.getValue();
|
||||
Double price = MarketBaseValues.marketBaseValues.get(material);
|
||||
|
||||
// Cleaned up double casting syntax with a modern fallback assignment
|
||||
double unitPrice = (price != null) ? price : 0.25;
|
||||
totalValue += amount * unitPrice;
|
||||
}
|
||||
}
|
||||
double totalValue = Math.pow(market.NegMarketSaturation, 4);
|
||||
|
||||
player.sendMessage("Total value: " + Shared.formatNumber(totalValue));
|
||||
player.sendMessage("Unique item count: " + market.items.size());
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class Market {
|
||||
public double NegMarketSaturation = 0.0F;
|
||||
public final Map<String, Long> items = new HashMap();
|
||||
public double NegMarketSaturation = 0.0;
|
||||
public final Map<String, Long> items = new HashMap<>();
|
||||
public final Map<String, Long> enchantments = new HashMap<>();
|
||||
|
||||
public Market() {
|
||||
}
|
||||
|
|
@ -32,18 +33,22 @@ public class Market {
|
|||
|
||||
public double sell(ItemStack itemStack, Player player) {
|
||||
if (!player.getInventory().contains(itemStack)) {
|
||||
return 0.0F;
|
||||
return 0.0;
|
||||
} else {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
this.items.putIfAbsent(itemStack.getType().getKey().getKey(), 0L);
|
||||
long initialAmount = this.items.get(itemStack.getType().getKey().getKey());
|
||||
double sold = 0.0F;
|
||||
double sold = 0.0;
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); ++i) {
|
||||
sold += this.getISPriceWithAmount(itemStack.getType(), itemStack.getEnchantments(), initialAmount + i);
|
||||
}
|
||||
|
||||
this.items.put(itemStack.getType().getKey().getKey(), initialAmount + (long) itemStack.getAmount());
|
||||
for (Enchantment enchantment : itemStack.getEnchantments().keySet()){
|
||||
this.enchantments.putIfAbsent(enchantment.getName(), 0L);
|
||||
this.enchantments.compute(enchantment.getName(), (k, initialEnchantmentAmount) -> initialEnchantmentAmount + (long) itemStack.getAmount());
|
||||
}
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) + sold);
|
||||
player.getInventory().removeItem(itemStack);
|
||||
return sold;
|
||||
|
|
@ -53,24 +58,28 @@ public class Market {
|
|||
public void unsafeSell(ItemStack itemStack, Player player) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
this.items.putIfAbsent(itemStack.getType().getKey().getKey(), 0L);
|
||||
double sold = 0.0F;
|
||||
double sold = 0.0;
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); ++i) {
|
||||
sold += this.getISPrice(itemStack.getType(), itemStack.getEnchantments());
|
||||
}
|
||||
|
||||
this.items.put(itemStack.getType().getKey().getKey(), this.items.get(itemStack.getType().getKey().getKey()) + (long) itemStack.getAmount());
|
||||
for (Enchantment enchantment : itemStack.getEnchantments().keySet()){
|
||||
this.enchantments.putIfAbsent(enchantment.getName(), 0L);
|
||||
this.enchantments.compute(enchantment.getName(), (k, initialEnchantmentAmount) -> initialEnchantmentAmount + (long) itemStack.getAmount());
|
||||
}
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) + sold);
|
||||
}
|
||||
|
||||
public Data<Double, Integer> sellAll(Material item, Player player) {
|
||||
if (!player.getInventory().contains(item)) {
|
||||
return Data.of((double) 0.0F, 0);
|
||||
return Data.of(0.0, 0);
|
||||
} else {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
this.items.putIfAbsent(item.getKey().getKey(), 0L);
|
||||
long initialAmount = this.items.get(item.getKey().getKey());
|
||||
Double sold = (double) 0.0F;
|
||||
Double sold = 0.0;
|
||||
int amount = player.getInventory().all(item).values().stream().mapToInt(ItemStack::getAmount).sum();
|
||||
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
|
|
@ -86,9 +95,9 @@ public class Market {
|
|||
|
||||
public double buy(Material item, int amount, Player player) {
|
||||
if (this.items.get(item.getKey().getKey()) == null) {
|
||||
return 0.0F;
|
||||
return 0.0;
|
||||
} else if ((long) amount > this.items.get(item.getKey().getKey())) {
|
||||
return 0.0F;
|
||||
return 0.0;
|
||||
} else {
|
||||
long initialAmount = this.items.get(item.getKey().getKey());
|
||||
|
||||
|
|
@ -115,8 +124,8 @@ public class Market {
|
|||
}
|
||||
}
|
||||
|
||||
public double reCalcNegMarketSaturation() {
|
||||
double totalValue = 0.0F;
|
||||
public void reCalcNegMarketSaturation() {
|
||||
double totalValue = 0.0;
|
||||
|
||||
for (String string : this.items.keySet()) {
|
||||
Material material = Material.matchMaterial(string);
|
||||
|
|
@ -126,18 +135,30 @@ public class Market {
|
|||
if (price != null) {
|
||||
totalValue += (double) amount * price;
|
||||
} else {
|
||||
totalValue += (double) amount * (double) 0.25F;
|
||||
totalValue += (double) amount * 0.25;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String string : this.enchantments.keySet()){
|
||||
Enchantment enchantment = Enchantment.getByName(string);
|
||||
if(enchantment != null){
|
||||
long amount = this.enchantments.get(string);
|
||||
Double price = EnchantBaseValues.enchantBaseValues.get(enchantment) / 10;
|
||||
if(price != null){
|
||||
totalValue += (double) amount * price;
|
||||
}else{
|
||||
totalValue += (double) amount * 0.25;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.NegMarketSaturation = Math.floor(Math.sqrt(Math.sqrt(totalValue)));
|
||||
return this.NegMarketSaturation;
|
||||
}
|
||||
|
||||
public double getPrice(Material item) {
|
||||
if (this.items.get(item.getKey().getKey()) == null) {
|
||||
return 0.0F;
|
||||
return 0.0;
|
||||
} else {
|
||||
return this.getPriceWithAmount(item, this.items.get(item.getKey().getKey()));
|
||||
}
|
||||
|
|
@ -159,10 +180,10 @@ public class Market {
|
|||
double rt = this.getPrice(item);
|
||||
|
||||
for (Enchantment e : enchantments.keySet()) {
|
||||
Double enchantValue = EnchantBaseValues.enchantBaseValues.get(e);
|
||||
if (enchantValue != null) {
|
||||
rt += enchantValue * Math.sqrt(enchantments.get(e));
|
||||
}
|
||||
Long enchantmentAmount = this.enchantments.get(e.getName());
|
||||
double enchantValue = EnchantBaseValues.enchantBaseValues.get(e) - (Math.sqrt((enchantmentAmount != null ? enchantmentAmount : 0L) * 300) * 10) + this.NegMarketSaturation*10;
|
||||
double minValue = Math.sqrt(EnchantBaseValues.enchantBaseValues.get(e)) * Math.sqrt(NegMarketSaturation);
|
||||
rt += Math.max(enchantValue,minValue) * enchantments.get(e);
|
||||
}
|
||||
|
||||
return rt;
|
||||
|
|
@ -172,8 +193,13 @@ public class Market {
|
|||
double rt = this.getPriceWithAmount(item, amount);
|
||||
|
||||
for (Enchantment e : enchantments.keySet()) {
|
||||
Double enchantValue = EnchantBaseValues.enchantBaseValues.get(e);
|
||||
if (enchantValue != null) {
|
||||
Long enchantmentAmount = this.enchantments.get(e.getName());
|
||||
Double baseEnchantValue = EnchantBaseValues.enchantBaseValues.get(e);
|
||||
if (baseEnchantValue != null) {
|
||||
double enchantValue = baseEnchantValue - (Math.sqrt((enchantmentAmount != null ? enchantmentAmount : 0L) * 300) * 10) + this.NegMarketSaturation*10;
|
||||
if(enchantValue < 0){
|
||||
enchantValue = this.NegMarketSaturation;
|
||||
}
|
||||
rt += enchantValue * Math.sqrt(enchantments.get(e));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import org.gsdistance.grimmsServer.Stats.PlayerTitles;
|
|||
import java.util.Map;
|
||||
|
||||
public class JobTitlesBaseValues {
|
||||
public static final Map<String, JobTitle> jobTitleBaseValues = Map.ofEntries(Map.entry("dictator", new JobTitle("Dictator", "Dictator of a dictatorship. Requires title 'Dictator'", 95, 50000.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Dictator"))), Map.entry("executioner", new JobTitle("Executioner", "Executioner, self explanatory. Requires title 'Executioner'", 65, 8500.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Executioner"))), Map.entry("", new JobTitle("None", "No Job", -1, 0.0F, (player) -> true)), Map.entry("miner", new JobTitle("Miner", "Minin' for a quick buck, requires title 'Miner'", -1, 750.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Miner"))), Map.entry("farmer", new JobTitle("Farmer", "Farming, but inefficiently.", 60, 650.0F, (player) -> true)), Map.entry("hitman", new JobTitle("Hitman", "Killing as a job? Right away! Requires title 'Hitman'", 75, 17500.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Hitman"))), Map.entry("ceo", new JobTitle("CEO", "Makin money while laying back, the best life! Requires title 'Millionaire'", 80, 11500.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Millionaire"))));
|
||||
public static final Map<String, JobTitle> jobTitleBaseValues = Map.ofEntries(Map.entry("dictator", new JobTitle("Dictator", "Dictator of a dictatorship. Requires title 'Dictator'", 95, 50000.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Dictator"))), Map.entry("executioner", new JobTitle("Executioner", "Executioner, self explanatory. Requires title 'Executioner'", 65, 8500.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Executioner"))), Map.entry("", new JobTitle("None", "No Job", -1, 0.0F, (player) -> true)), Map.entry("miner", new JobTitle("Miner", "Minin' for a quick buck, requires title 'Miner'", -1, 750.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Miner"))), Map.entry("farmer", new JobTitle("Farmer", "Farming, but inefficiently.", 60, 650.0F, (player) -> true)), Map.entry("hitman", new JobTitle("Hitman", "Killing as a job? Right away! Requires title 'Hitman'", 75, 5750.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Hitman"))), Map.entry("ceo", new JobTitle("CEO", "Makin' money while laying back, the best life! Requires title 'Millionaire'", 80, 4150.0F, (player) -> PlayerTitles.getPlayerTitles(player).hasTitle("Millionaire"))));
|
||||
|
||||
public JobTitlesBaseValues() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.gsdistance.grimmsServer.GrimmsServer;
|
|||
import java.util.*;
|
||||
|
||||
public class PlayerStats {
|
||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable();
|
||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||
public static final Dictionary<String, String> StatNames;
|
||||
public static final List<String> StatOrder;
|
||||
public static final Map<String, ?> StatDefaultValues;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue