Search in sources :

Example 6 with HighScoreService

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

the class WildernessWorldWrapper method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> block : transactions) {
        BlockSnapshot original = block.getOriginal();
        Optional<Location<World>> optLoc = original.getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Integer> optLevel = getLevel(optLoc.get());
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        Location<World> loc = optLoc.get();
        BlockState state = original.getState();
        BlockType type = state.getType();
        // Prevent item dupe glitch by removing the position before subsequent breaks
        markedOrePoints.remove(loc);
        if (config.getDropAmplificationConfig().amplifies(state) && !original.getCreator().isPresent()) {
            markedOrePoints.add(loc);
            if (srcEnt instanceof Player) {
                Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
                optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEnt, ScoreTypes.WILDERNESS_ORES_MINED, 1));
            }
        }
        if (srcEnt instanceof Player && type.equals(BlockTypes.STONE) && Probability.getChance(Math.max(12, 250 - level))) {
            Vector3d max = loc.getPosition().add(1, 1, 1);
            Vector3d min = loc.getPosition().sub(1, 1, 1);
            Extent world = loc.getExtent();
            if (Probability.getChance(3)) {
                Entity entity = world.createEntity(EntityTypes.SILVERFISH, loc.getPosition().add(.5, 0, .5));
                world.spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
            }
            // Do this one tick later to guarantee no collision with transaction data
            Task.builder().delayTicks(1).execute(() -> {
                for (int x = min.getFloorX(); x <= max.getFloorX(); ++x) {
                    for (int z = min.getFloorZ(); z <= max.getFloorZ(); ++z) {
                        for (int y = min.getFloorY(); y <= max.getFloorY(); ++y) {
                            if (!world.containsBlock(x, y, z)) {
                                continue;
                            }
                            if (world.getBlockType(x, y, z) == BlockTypes.STONE) {
                                world.setBlockType(x, y, z, BlockTypes.MONSTER_EGG, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                            }
                        }
                    }
                }
            }).submit(SkreePlugin.inst());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Extent(org.spongepowered.api.world.extent.Extent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) HighScoreService(com.skelril.skree.service.HighScoreService) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 7 with HighScoreService

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

the class CatacombsInstance method spawnWave.

public void spawnWave() {
    wave += getSpeed();
    if (wave % 5 == 0) {
        spawnBossWave();
    } else {
        spawnNormalWave();
    }
    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_CATACOMB_WAVE, wave);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) HighScoreService(com.skelril.skree.service.HighScoreService)

Example 8 with HighScoreService

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

the class TempleOfFateInstance method rewardPlayer.

public void rewardPlayer(Player player) {
    boolean participated = participants.containsKey(player);
    long startTime = participants.get(player);
    remove(player);
    if (!participated) {
        return;
    }
    int seconds = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
    Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
    optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.FASTEST_TEMPLE_OF_FATE_RUN, seconds));
    for (ItemStack stack : dropTable.getDrops(Probability.getRandom(3))) {
        player.getInventory().offer(stack);
    }
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) 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