Search in sources :

Example 1 with HighScoreService

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;
}
Also used : BigDecimal(java.math.BigDecimal) HighScoreService(com.skelril.skree.service.HighScoreService) PlayerStateService(com.skelril.skree.service.PlayerStateService) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) MarketService(com.skelril.skree.service.MarketService)

Example 2 with HighScoreService

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);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) HighScoreService(com.skelril.skree.service.HighScoreService)

Example 3 with HighScoreService

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));
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) HighScoreService(com.skelril.skree.service.HighScoreService) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 4 with HighScoreService

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();
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ScoreType(com.skelril.skree.service.internal.highscore.ScoreType) Clause(com.skelril.nitro.Clause) HighScoreService(com.skelril.skree.service.HighScoreService)

Example 5 with HighScoreService

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();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) HighScoreService(com.skelril.skree.service.HighScoreService)

Aggregations

HighScoreService (com.skelril.skree.service.HighScoreService)8 Player (org.spongepowered.api.entity.living.player.Player)5 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Listener (org.spongepowered.api.event.Listener)2 World (org.spongepowered.api.world.World)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Clause (com.skelril.nitro.Clause)1 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 MarketService (com.skelril.skree.service.MarketService)1 ModifierService (com.skelril.skree.service.ModifierService)1 PlayerStateService (com.skelril.skree.service.PlayerStateService)1 ScoreType (com.skelril.skree.service.internal.highscore.ScoreType)1 BigDecimal (java.math.BigDecimal)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 BlockState (org.spongepowered.api.block.BlockState)1 BlockType (org.spongepowered.api.block.BlockType)1