Search in sources :

Example 1 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class SkyWarsInstance method add.

@Override
public Clause<Player, ZoneStatus> add(Player player) {
    if (state != SkyWarsState.LOBBY) {
        return new Clause<>(player, ZoneStatus.NO_REJOIN);
    }
    player.setLocation(startingLocation);
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        try {
            service.storeInventory(player);
            service.releaseInventory(player);
            giveTeamHoods(player);
        } catch (InventoryStorageStateException e) {
            e.printStackTrace();
            return new Clause<>(player, ZoneStatus.ERROR);
        }
    }
    playerDataMapping.put(player, new SkyWarsPlayerData());
    return new Clause<>(player, ZoneStatus.ADDED);
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService) InventoryStorageStateException(com.skelril.skree.service.internal.playerstate.InventoryStorageStateException) Clause(com.skelril.nitro.Clause)

Example 2 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class GoldRushInstance method tryToStart.

public void tryToStart() {
    BigDecimal coffersNeeded = getCoffersNeeded();
    if (coffersNeeded.compareTo(BigDecimal.ZERO) >= 0) {
        MessageChannel channel = getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
        channel.send(Text.of(TextColors.RED, "Your party doesn't have a high enough coffer risk!"));
        channel.send(Text.of(TextColors.RED, "At least ", coffersNeeded, " more coffers must be risked."));
        return;
    }
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
        if (optService.isPresent()) {
            PlayerStateService service = optService.get();
            try {
                service.storeInventory(player);
                service.releaseInventory(player);
                player.getInventory().clear();
            } catch (InventoryStorageStateException e) {
                e.printStackTrace();
                player.sendMessage(Text.of(TextColors.RED, "An error occurred while saving your inventory, contact an admin!"));
                return;
            }
        } else {
            if (player.getInventory().query(PlayerInventory.class, EquipmentInventory.class).size() > 0) {
                getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.RED, "All players inventories must be empty."));
                return;
            }
        }
    }
    readyPlayers();
    calculateLootSplit();
    // Reset tryToStart clock
    startTime = System.currentTimeMillis();
    // Add content
    populateChest();
    runLavaChance();
    setFloodStartTime();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerStateService(com.skelril.skree.service.PlayerStateService) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) InventoryStorageStateException(com.skelril.skree.service.internal.playerstate.InventoryStorageStateException) BigDecimal(java.math.BigDecimal)

Example 3 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService 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;
    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.length; ++i) {
        net.minecraft.item.ItemStack is = itemStacks[i];
        if (is == null || 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[i] = null;
    }
    // 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());
    remove(player);
    return true;
}
Also used : BigDecimal(java.math.BigDecimal) 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 4 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class GoldRushInstance method tryInventoryRestore.

public void tryInventoryRestore(Player player) {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        service.loadInventoryIfStored(player);
    }
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService)

Example 5 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class TempleOfFateInstance method add.

@Override
public Clause<Player, ZoneStatus> add(Player player) {
    player.setLocation(startingPoint);
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        try {
            service.storeInventory(player);
            service.releaseInventory(player);
            player.offer(Keys.POTION_EFFECTS, new ArrayList<>());
            player.getInventory().clear();
        } catch (InventoryStorageStateException e) {
            e.printStackTrace();
            return new Clause<>(player, ZoneStatus.ERROR);
        }
    }
    participants.add(player);
    return new Clause<>(player, ZoneStatus.ADDED);
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService) InventoryStorageStateException(com.skelril.skree.service.internal.playerstate.InventoryStorageStateException) Clause(com.skelril.nitro.Clause)

Aggregations

PlayerStateService (com.skelril.skree.service.PlayerStateService)12 InventoryStorageStateException (com.skelril.skree.service.internal.playerstate.InventoryStorageStateException)5 Clause (com.skelril.nitro.Clause)3 BigDecimal (java.math.BigDecimal)2 Player (org.spongepowered.api.entity.living.player.Player)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 MarketService (com.skelril.skree.service.MarketService)1 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 MessageChannel (org.spongepowered.api.text.channel.MessageChannel)1