Search in sources :

Example 1 with ProjectileSource

use of org.spongepowered.api.entity.projectile.source.ProjectileSource in project Skree by Skelril.

the class PlayerCombatParser method parse.

default default void parse(CollideEntityEvent.Impact event) {
    Optional<Projectile> optProjectile = event.getCause().first(Projectile.class);
    if (!optProjectile.isPresent()) {
        return;
    }
    Projectile projectile = optProjectile.get();
    ProjectileSource source = optProjectile.get().getShooter();
    if (!(source instanceof Player)) {
        return;
    }
    Player attacker = (Player) source;
    for (Entity anEntity : event.getEntities()) {
        if (anEntity instanceof Player) {
            Player defender = (Player) anEntity;
            processPvP(attacker, defender);
            processPvP(attacker, defender, projectile);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Projectile(org.spongepowered.api.entity.projectile.Projectile)

Example 2 with ProjectileSource

use of org.spongepowered.api.entity.projectile.source.ProjectileSource in project Skree by Skelril.

the class ArrowFishingHandler method onProjectileTickEvent.

@Listener
public void onProjectileTickEvent(ProjectileTickEvent event) {
    Projectile projectile = event.getTargetEntity();
    if (!(projectile instanceof Arrow) || Probability.getChance(3)) {
        return;
    }
    Location<World> loc = projectile.getLocation();
    if (MultiTypeRegistry.isWater(loc.getBlockType()) && checkVelocity(projectile.getVelocity())) {
        ProjectileSource source = projectile.getShooter();
        double modifier = 1;
        if (source instanceof Living) {
            modifier = 50;
        }
        Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
        int rolls = 1;
        if (optService.isPresent() && optService.get().isActive(UBER_ARROW_FISHING)) {
            if (source instanceof Living) {
                rolls = 15;
            } else {
                rolls = 5;
            }
        }
        new ItemDropper(loc).dropStacks(dropTable.getDrops(rolls, modifier), SpawnTypes.DROPPED_ITEM);
    }
}
Also used : Arrow(org.spongepowered.api.entity.projectile.arrow.Arrow) ItemDropper(com.skelril.nitro.item.ItemDropper) Living(org.spongepowered.api.entity.living.Living) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Example 3 with ProjectileSource

use of org.spongepowered.api.entity.projectile.source.ProjectileSource in project Skree by Skelril.

the class JungleRaidEffectListener method onProjectileHit.

@Listener
public void onProjectileHit(CollideEvent.Impact event, @First Entity entity) {
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(entity);
    if (!optInst.isPresent())
        return;
    JungleRaidInstance inst = optInst.get();
    if (inst.getState() != JungleRaidState.IN_PROGRESS) {
        return;
    }
    int explosionSize = 2;
    if (entity.getType() == EntityTypes.TIPPED_ARROW) {
        if (inst.isFlagEnabled(JungleRaidFlag.TORMENT_ARROWS)) {
            ProjectileSource shooter = ((Arrow) entity).getShooter();
            CuboidContainmentPredicate predicate = new CuboidContainmentPredicate(entity.getLocation().getPosition(), 16, 16, 16);
            for (Entity e : entity.getNearbyEntities(en -> predicate.test(en.getLocation().getPosition()))) {
                if (e.equals(shooter))
                    continue;
                if (e instanceof Living && shooter instanceof Living) {
                    e.damage(1, IndirectEntityDamageSource.builder().type(DamageTypes.PROJECTILE).entity(entity).proxySource((Living) shooter).build());
                    if (Probability.getChance(5)) {
                        EntityHealthUtil.heal((Living) shooter, 1);
                    }
                }
            }
        }
        if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 4;
        } else
            return;
    }
    if (entity instanceof Snowball) {
        if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 10;
            else
                explosionSize = 6;
        } else
            return;
    }
    if (entity instanceof ThrownPotion) {
        return;
    }
    entity.getLocation().getExtent().triggerExplosion(Explosion.builder().radius(explosionSize).location(entity.getLocation()).shouldDamageEntities(true).shouldBreakBlocks(true).build(), Cause.source(SkreePlugin.container()).build());
}
Also used : Arrow(org.spongepowered.api.entity.projectile.arrow.Arrow) CuboidContainmentPredicate(com.skelril.nitro.position.CuboidContainmentPredicate) Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Living(org.spongepowered.api.entity.living.Living) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Example 4 with ProjectileSource

use of org.spongepowered.api.entity.projectile.source.ProjectileSource in project Skree by Skelril.

the class PointOfContactClusterListener method onBlockCollide.

@Listener
public void onBlockCollide(CollideEvent.Impact event, @First Projectile projectile) {
    ProjectileSource source = projectile.getShooter();
    if (!(source instanceof Living)) {
        return;
    }
    Living sourceEntity = (Living) source;
    if (!isApplicable(sourceEntity)) {
        return;
    }
    if (cooldownHandler.canUseAbility(sourceEntity)) {
        cooldownHandler.useAbility(sourceEntity);
    } else {
        return;
    }
    attackCluster.getNextAbilityToRun().run(sourceEntity, event.getImpactPoint());
}
Also used : Living(org.spongepowered.api.entity.living.Living) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Aggregations

ProjectileSource (org.spongepowered.api.entity.projectile.source.ProjectileSource)4 Living (org.spongepowered.api.entity.living.Living)3 Listener (org.spongepowered.api.event.Listener)3 Entity (org.spongepowered.api.entity.Entity)2 Projectile (org.spongepowered.api.entity.projectile.Projectile)2 Arrow (org.spongepowered.api.entity.projectile.arrow.Arrow)2 ItemDropper (com.skelril.nitro.item.ItemDropper)1 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)1 ModifierService (com.skelril.skree.service.ModifierService)1 Player (org.spongepowered.api.entity.living.player.Player)1 Snowball (org.spongepowered.api.entity.projectile.Snowball)1 ThrownPotion (org.spongepowered.api.entity.projectile.ThrownPotion)1 World (org.spongepowered.api.world.World)1