Search in sources :

Example 1 with ModifierService

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

the class CursedMineListener method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause, @Named(NamedCause.NOTIFIER) Player player) {
    if (!Probability.getChance(4)) {
        return;
    }
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> loc = optLocation.get();
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    if (!inst.hasrecordForPlayerAt(player, loc)) {
        return;
    }
    List<ItemStackSnapshot> itemStacks = new ArrayList<>();
    Iterator<Entity> entityIterator = event.getEntities().iterator();
    while (entityIterator.hasNext()) {
        Entity entity = entityIterator.next();
        if (entity instanceof Item) {
            ItemStackSnapshot snapshot = ((Item) entity).item().get();
            itemStacks.add(snapshot);
            entityIterator.remove();
        }
    }
    int times = 1;
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
            times *= 2;
        }
    }
    for (ItemStackSnapshot stackSnapshot : itemStacks) {
        int quantity = Math.min(stackSnapshot.getCount() * Probability.getRangedRandom(4, 8), stackSnapshot.getType().getMaxStackQuantity());
        for (int i = 0; i < times; ++i) {
            ItemStack stack = stackSnapshot.createStack();
            stack.setQuantity(quantity);
            player.getInventory().offer(stack);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Item(org.spongepowered.api.entity.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 2 with ModifierService

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

the class WildernessWorldWrapper method getOreMod.

public int getOreMod(int dropTier) {
    int modifier = (int) Math.round(Math.max(1, dropTier * 1.5));
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.DOUBLE_WILD_ORES)) {
            modifier *= 2;
        }
    }
    return modifier;
}
Also used : ModifierService(com.skelril.skree.service.ModifierService)

Example 3 with ModifierService

use of com.skelril.skree.service.ModifierService 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);
                }
            }
        }
        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());
        }
    }
    GRAVE_STONE.createGraveFromDeath(event);
}
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) 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 ModifierService

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

the class GoldRushInstance method calculateLootSplit.

private void calculateLootSplit() {
    multiplier = BigDecimal.ONE;
    Collection<Player> cPlayers = getPlayers(PlayerClassifier.PARTICIPANT);
    for (Player next : cPlayers) {
        BigDecimal origCharge = cofferRisk.get(next.getUniqueId());
        if (origCharge == null) {
            continue;
        }
        lootSplit = lootSplit.add(origCharge.multiply(new BigDecimal(.05)));
    }
    lootSplit = lootSplit.divide(new BigDecimal(cPlayers.size()), RoundingMode.HALF_DOWN);
    if (Probability.getChance(35))
        multiplier = multiplier.multiply(BigDecimal.TEN);
    if (Probability.getChance(15))
        multiplier = multiplier.multiply(new BigDecimal(2));
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.QUAD_GOLD_RUSH))
            multiplier = multiplier.multiply(new BigDecimal(4));
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ModifierService(com.skelril.skree.service.ModifierService) BigDecimal(java.math.BigDecimal)

Example 5 with ModifierService

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

the class ModExtendCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "Modifier service not found."));
        return CommandResult.empty();
    }
    ModifierService service = optService.get();
    String modifier = args.<String>getOne("modifier").get();
    int minutes = args.<Integer>getOne("minutes").get();
    boolean wasActive = service.isActive(modifier);
    service.extend(modifier, TimeUnit.MINUTES.toMillis(minutes));
    String friendlyName = StringUtils.capitalize(modifier.replace("_", " ").toLowerCase());
    String friendlyTime = PrettyText.date(service.expiryOf(modifier));
    String change = wasActive ? " extended" : " enabled";
    String rawMessage = friendlyName + change + " till " + friendlyTime + "!";
    MessageChannel.TO_ALL.send(Text.of(TextColors.GOLD, rawMessage));
    GameChatterPlugin.inst().sendSystemMessage(rawMessage);
    return CommandResult.success();
}
Also used : ModifierService(com.skelril.skree.service.ModifierService)

Aggregations

ModifierService (com.skelril.skree.service.ModifierService)7 Listener (org.spongepowered.api.event.Listener)4 Player (org.spongepowered.api.entity.living.player.Player)3 World (org.spongepowered.api.world.World)3 ItemDropper (com.skelril.nitro.item.ItemDropper)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)1 Entity (org.spongepowered.api.entity.Entity)1 Item (org.spongepowered.api.entity.Item)1 Living (org.spongepowered.api.entity.living.Living)1 Boss (org.spongepowered.api.entity.living.monster.Boss)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1