use of com.skelril.skree.service.HighScoreService in project Skree by Skelril.
the class GoldRushInstance method payPlayer.
public boolean payPlayer(Player player) {
BigDecimal fee = cofferRisk.get(player.getUniqueId());
// They didn't pay, CHEATER!!!
if (fee == null) {
return false;
}
NonNullList<net.minecraft.item.ItemStack> itemStacks = tf(player).inventory.mainInventory;
BigDecimal goldValue = BigDecimal.ZERO;
BigDecimal itemValue = BigDecimal.ZERO;
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
List<ItemStack> returned = new ArrayList<>();
for (int i = 0; i < itemStacks.size(); ++i) {
net.minecraft.item.ItemStack is = itemStacks.get(i);
if (is == net.minecraft.item.ItemStack.EMPTY || is.getItem() != CustomItemTypes.PRIZE_BOX) {
continue;
}
Optional<ItemStack> optOpened = PrizeBox.getPrizeStack(is);
if (optService.isPresent() && optOpened.isPresent()) {
MarketService service = optService.get();
ItemStack opened = optOpened.get();
Optional<BigDecimal> value = service.getPrice(opened);
if (value.isPresent()) {
BigDecimal quantity = new BigDecimal(opened.getQuantity());
if (opened.getItem() == ItemTypes.GOLD_NUGGET || opened.getItem() == ItemTypes.GOLD_INGOT || opened.getItem() == BlockTypes.GOLD_BLOCK.getItem().get()) {
goldValue = goldValue.add(value.get().multiply(quantity));
} else {
itemValue = itemValue.add(value.get().multiply(quantity));
returned.add(opened);
}
}
}
itemStacks.set(i, net.minecraft.item.ItemStack.EMPTY);
}
// Get the original grab amount (The Sum of Gold & Items)
BigDecimal originalGrabbed = goldValue.add(itemValue);
// Create a penalty value if the player was in a flood (Time Taken / Time Per Penalty) * Penalty Increment Value
// for instance (6000 milliseconds after / 3000 millisecond penality increment) * 9 coffer increment value
// would result in 18 coffers being the penalty value
BigDecimal penaltyValue = new BigDecimal(getTimeTakenAfterFlood()).divide(PENALTY_INCREMENT, 2, RoundingMode.UP).multiply(PENALTY_INCREMENT_VALUE);
// Total grabbed is the original grab amount - the penalty value
BigDecimal totalGrabbed = originalGrabbed.subtract(penaltyValue);
// The ratio they would have recieved with no time penalty
// Calculated as the multiplier * (Grab Ratio * (Value of stuff (grab amount) / Pivotal value (target amount)))
BigDecimal originalGrabRatio = multiplier.multiply(GRAB_RATIO.multiply(originalGrabbed.divide(PIVOTAL_VALUE, 2, RoundingMode.DOWN)));
// The same calculation as the original grab ratio, just using the time penalty modified grab amount
BigDecimal grabRatio = multiplier.multiply(GRAB_RATIO.multiply(totalGrabbed.divide(PIVOTAL_VALUE, 2, RoundingMode.DOWN)));
// The penalty ratio is the percentage value loss from the original grab ratio
BigDecimal penaltyRatio = originalGrabRatio.subtract(grabRatio);
// The loot split times the group modifier
BigDecimal multipliedLootSplit = multiplier.multiply(lootSplit);
// The amount of money they gain from the their boosted risk
BigDecimal splitBoost = multipliedLootSplit.multiply(grabRatio);
// The total amount of money they get, being the loot split + their boosted risk value
// minus item value
BigDecimal personalLootSplit = multipliedLootSplit.add(splitBoost);
player.sendMessage(Text.of(TextColors.YELLOW, "You obtain: "));
player.sendMessage(Text.of(TextColors.YELLOW, " - Bail: ", format(fee)));
player.sendMessage(Text.of(TextColors.YELLOW, " - Split: ", format(multipliedLootSplit), ", Multiplied by: ", format(multiplier), "x, Boosted by: ", format(grabRatio.multiply(new BigDecimal(100))), "%"));
if (penaltyRatio.compareTo(BigDecimal.ZERO) != 0) {
player.sendMessage(Text.of(TextColors.YELLOW, " - Boost time penalty: ", format(penaltyRatio.multiply(new BigDecimal(100))), "%"));
}
if (grabRatio.compareTo(BigDecimal.ZERO) != 0) {
player.sendMessage(Text.of(TextColors.YELLOW, " - Boost value: ", format(splitBoost)));
}
BigDecimal total = fee.add(personalLootSplit);
player.sendMessage(Text.of(TextColors.YELLOW, "Total: ", format(total)));
// Give the player their items
Optional<PlayerStateService> optInvService = Sponge.getServiceManager().provide(PlayerStateService.class);
if (optInvService.isPresent()) {
PlayerStateService invService = optInvService.get();
invService.loadInventoryIfStored(player);
}
returned.forEach(i -> player.getInventory().offer(i));
MarketImplUtil.setBalanceTo(player, total.add(MarketImplUtil.getMoney(player)), Cause.source(this).build());
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.GOLD_RUSH_ROBBERIES, 1));
optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.GOLD_RUSH_LOOT_VALUE, total.toBigInteger().intValue()));
remove(player);
return true;
}
use of com.skelril.skree.service.HighScoreService in project Skree by Skelril.
the class TheButcherShopInstance method spawnWave.
public void spawnWave() {
ticks = 0;
processedItems = 0;
++wave;
for (int i = 0; i < getMobsForWave(); ++i) {
spawnAnimal();
}
for (Player player : getPlayers(SPECTATOR)) {
player.sendTitle(Title.builder().title(Text.of(TextColors.RED, "Wave")).subtitle(Text.of(TextColors.RED, wave)).fadeIn(20).fadeOut(20).build());
}
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
if (optHighScores.isPresent()) {
HighScoreService highScores = optHighScores.get();
for (Player player : getPlayers(PARTICIPANT)) {
highScores.update(player, ScoreTypes.HIGHEST_BUTCHER_SHOP_WAVE, wave);
}
}
}
use of com.skelril.skree.service.HighScoreService in project Skree by Skelril.
the class WildernessWorldWrapper method onEntityDeath.
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
Entity entity = event.getTargetEntity();
Location<World> loc = entity.getLocation();
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
int level = optLevel.get();
if (entity instanceof Monster) {
DropTable dropTable;
if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
dropTable = netherMobDropTable;
} else {
dropTable = commonDropTable;
}
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
Entity srcEntity;
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
} else {
srcEntity = optDamageSource.get().getSource();
}
int dropTier = level;
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) {
Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
if (optLooting.isPresent()) {
dropTier += optLooting.get().getLevel();
}
}
dropTier = getDropTier(dropTier);
Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
times *= 2;
}
}
ItemDropper dropper = new ItemDropper(loc);
for (int i = 0; i < times; ++i) {
dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEntity, ScoreTypes.WILDERNESS_MOB_KILLS, 1));
}
}
if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
}
}
if (entity instanceof Player) {
Player player = (Player) entity;
GRAVE_STONE.createGraveFromDeath(player);
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.WILDERNESS_DEATHS, 1));
}
}
use of com.skelril.skree.service.HighScoreService in project Skree by Skelril.
the class HighScoreCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
HighScoreService service = Sponge.getServiceManager().provideUnchecked(HighScoreService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
Optional<ScoreType> optScoreType = args.getOne("score type");
if (optScoreType.isPresent()) {
ScoreType scoreType = optScoreType.get();
List<Clause<Optional<GameProfile>, Integer>> scores = service.getTop(scoreType);
List<Text> result = new ArrayList<>(scores.size());
for (int i = 0; i < scores.size(); ++i) {
result.add(createScoreLine(i + 1, scores.get(i), scoreType));
}
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, getFriendlyName(reverseChoices.get(scoreType)))).padding(Text.of(" ")).sendTo(src);
} else {
List<Text> result = choices.keySet().stream().map(this::createScoreTypeLine).sorted().collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "High Score Tables")).padding(Text.of(" ")).sendTo(src);
}
return CommandResult.success();
}
use of com.skelril.skree.service.HighScoreService in project Skree by Skelril.
the class JungleRaidInstance method forceEnd.
@Override
public void forceEnd() {
if (state == JungleRaidState.DONE) {
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
for (Player player : getPlayers(PARTICIPANT)) {
remove(player);
optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.JUNGLE_RAID_WINS, 1));
}
}
remove();
}
Aggregations