Search in sources :

Example 1 with WeaponProjectile

use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile in project MechanicsMain by WeaponMechanics.

the class AirStrike method trigger.

public void trigger(Location flareLocation, LivingEntity shooter, WeaponProjectile projectile) {
    if (mechanics != null)
        mechanics.use(new CastData(shooter, projectile.getWeaponTitle(), projectile.getWeaponStack()));
    new BukkitRunnable() {

        int count = 0;

        @Override
        public void run() {
            int bombs = NumberUtil.random(min, max);
            int checks = bombs * bombs;
            // Used to make sure we don't spawn bombs too close to
            // each other. Uses distanceBetweenSquared
            List<Vector2d> spawnLocations = new ArrayList<>(bombs);
            locationFinder: for (int i = 0; i < checks && spawnLocations.size() < bombs; i++) {
                double x = flareLocation.getX() + NumberUtil.random(-radius, radius);
                double z = flareLocation.getZ() + NumberUtil.random(-radius, radius);
                Vector2d vector = new Vector2d(x, z);
                for (Vector2d spawnLocation : spawnLocations) {
                    if (vector.distanceSquared(spawnLocation) < distanceBetweenSquared) {
                        continue locationFinder;
                    }
                }
                spawnLocations.add(vector);
                double y = flareLocation.getY() + height + NumberUtil.random(-yVariation, yVariation);
                Location location = new Location(flareLocation.getWorld(), x, y, z);
                // Either use the projectile settings from the "parent" projectile,
                // or use the projectile settings for this airstrike
                Projectile projectileHandler = getProjectile() != null ? getProjectile() : getConfigurations().getObject(projectile.getWeaponTitle() + ".Projectile", Projectile.class);
                if (projectileHandler != null) {
                    WeaponProjectile newProjectile = getProjectile() != null ? projectileHandler.create(shooter, location, new Vector(0, 0, 0), projectile.getWeaponStack(), projectile.getWeaponTitle()) : projectile.clone(location, new Vector(0, 0, 0));
                    newProjectile.setIntTag("airstrike-bomb", 1);
                    projectileHandler.shoot(newProjectile, location);
                }
            }
            if (++count >= loops) {
                cancel();
            }
        }
    }.runTaskTimerAsynchronously(WeaponMechanics.getPlugin(), 0, delay);
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ArrayList(java.util.ArrayList) List(java.util.List) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile)

Example 2 with WeaponProjectile

use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile in project MechanicsMain by WeaponMechanics.

the class ShootHandler method shoot.

/**
 * Shoots using weapon.
 * Does not use ammo nor check for it.
 * Does not apply recoil nor anything that would require EntityWrapper.
 */
public void shoot(LivingEntity livingEntity, String weaponTitle, Vector normalizedDirection) {
    Configuration config = getConfigurations();
    Mechanics shootMechanics = config.getObject(weaponTitle + ".Shoot.Mechanics", Mechanics.class);
    if (shootMechanics != null)
        shootMechanics.use(new CastData(livingEntity, weaponTitle, null));
    Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class);
    if (projectile == null)
        return;
    Location shootLocation = getShootLocation(livingEntity, false, true);
    double projectileSpeed = config.getDouble(weaponTitle + ".Shoot.Projectile_Speed");
    for (int i = 0; i < config.getInt(weaponTitle + ".Shoot.Projectiles_Per_Shot"); ++i) {
        // Only create bullet first if WeaponShootEvent changes
        WeaponProjectile bullet = projectile.create(livingEntity, shootLocation, normalizedDirection.clone().multiply(projectileSpeed), null, weaponTitle);
        WeaponShootEvent shootEvent = new WeaponShootEvent(bullet);
        Bukkit.getPluginManager().callEvent(shootEvent);
        bullet = shootEvent.getProjectile();
        // Shoot the given bullet
        projectile.shoot(bullet, shootLocation);
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) Configuration(me.deecaad.core.file.Configuration) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) WeaponShootEvent(me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Location(org.bukkit.Location)

Example 3 with WeaponProjectile

use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile in project MechanicsMain by WeaponMechanics.

the class ClusterBomb method trigger.

public void trigger(WeaponProjectile projectile, LivingEntity shooter, Location splitLocation) {
    int currentDepth = projectile.getIntTag("cluster-split-level");
    // Checking to see if we have split the proper number of times
    if (currentDepth >= splits) {
        return;
    }
    debug.debug("Splitting cluster bomb");
    if (mechanics != null)
        mechanics.use(new CastData(shooter, projectile.getWeaponTitle(), projectile.getWeaponStack()));
    for (int i = 0; i < bombs; i++) {
        Vector vector = VectorUtil.random(speed);
        vector.setY(Math.abs(vector.getY()));
        // Either use the projectile settings from the "parent" projectile,
        // or use the projectile settings for this cluster bomb
        Projectile projectileHandler = getProjectile() != null ? getProjectile() : getConfigurations().getObject(projectile.getWeaponTitle() + ".Projectile", Projectile.class);
        if (projectileHandler != null) {
            WeaponProjectile newProjectile = getProjectile() != null ? projectileHandler.create(shooter, splitLocation, vector, projectile.getWeaponStack(), projectile.getWeaponTitle()) : projectile.clone(splitLocation, vector);
            newProjectile.setIntTag("cluster-split-level", currentDepth + 1);
            projectileHandler.shoot(newProjectile, splitLocation);
        }
    }
    // Remove the parent split
    projectile.remove();
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Vector(org.bukkit.util.Vector) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile)

Example 4 with WeaponProjectile

use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile in project MechanicsMain by WeaponMechanics.

the class ShootHandler method shoot.

/**
 * Shoots using weapon.
 * Does not use ammo nor check for it.
 */
public void shoot(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, Location shootLocation, boolean mainHand, boolean updateSpreadChange, boolean isMelee) {
    Configuration config = getConfigurations();
    LivingEntity livingEntity = entityWrapper.getEntity();
    if (!isMelee) {
        HandData handData = mainHand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
        handData.setLastShotTime(System.currentTimeMillis());
        if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Delay_Between_Shots") && entityWrapper.getEntity().getType() == EntityType.PLAYER) {
            CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entityWrapper, weaponStack.getType(), config.getInt(weaponTitle + ".Shoot.Delay_Between_Shots") / 50);
        }
    }
    Mechanics shootMechanics = config.getObject(weaponTitle + ".Shoot.Mechanics", Mechanics.class);
    if (shootMechanics != null)
        shootMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
    if (entityWrapper instanceof PlayerWrapper) {
        WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
        if (weaponInfoDisplay != null)
            weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND);
    }
    Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class);
    if (projectile == null || isMelee) {
        // No projectile defined or was melee trigger
        return;
    }
    Spread spread = config.getObject(weaponTitle + ".Shoot.Spread", Spread.class);
    Recoil recoil = config.getObject(weaponTitle + ".Shoot.Recoil", Recoil.class);
    double projectileSpeed = config.getDouble(weaponTitle + ".Shoot.Projectile_Speed");
    for (int i = 0; i < config.getInt(weaponTitle + ".Shoot.Projectiles_Per_Shot"); ++i) {
        // i == 0
        // -> Only allow spread changing on first shot
        Vector motion = spread != null ? spread.getNormalizedSpreadDirection(entityWrapper, mainHand, i == 0 && updateSpreadChange).multiply(projectileSpeed) : livingEntity.getLocation().getDirection().multiply(projectileSpeed);
        if (recoil != null && i == 0 && livingEntity instanceof Player) {
            recoil.start((Player) livingEntity, mainHand);
        }
        // Only create bullet first if WeaponShootEvent changes
        WeaponProjectile bullet = projectile.create(livingEntity, shootLocation, motion, weaponStack, weaponTitle);
        WeaponShootEvent shootEvent = new WeaponShootEvent(bullet);
        Bukkit.getPluginManager().callEvent(shootEvent);
        bullet = shootEvent.getProjectile();
        // Shoot the given bullet
        projectile.shoot(bullet, shootLocation);
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) Player(org.bukkit.entity.Player) Configuration(me.deecaad.core.file.Configuration) WeaponShootEvent(me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent) Recoil(me.deecaad.weaponmechanics.weapon.shoot.recoil.Recoil) PlayerWrapper(me.deecaad.weaponmechanics.wrappers.PlayerWrapper) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) LivingEntity(org.bukkit.entity.LivingEntity) Spread(me.deecaad.weaponmechanics.weapon.shoot.spread.Spread) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) WeaponInfoDisplay(me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay) Vector(org.bukkit.util.Vector) HandData(me.deecaad.weaponmechanics.wrappers.HandData)

Aggregations

CastData (me.deecaad.weaponmechanics.mechanics.CastData)4 Projectile (me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile)4 WeaponProjectile (me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile)4 Vector (org.bukkit.util.Vector)3 Configuration (me.deecaad.core.file.Configuration)2 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)2 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)2 WeaponShootEvent (me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent)2 Location (org.bukkit.Location)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)1 Recoil (me.deecaad.weaponmechanics.weapon.shoot.recoil.Recoil)1 Spread (me.deecaad.weaponmechanics.weapon.shoot.spread.Spread)1 HandData (me.deecaad.weaponmechanics.wrappers.HandData)1 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1