use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile in project MechanicsMain by WeaponMechanics.
the class AirStrike method serialize.
@Override
@Nonnull
public AirStrike serialize(SerializeData data) throws SerializerException {
int min = data.of("Minimum_Bombs").assertExists().assertPositive().getInt();
int max = data.of("Maximum_Bombs").assertExists().assertPositive().getInt();
Projectile projectile = data.of("Dropped_Projectile").assertExists().serialize(Projectile.class);
double yOffset = data.of("Height").assertPositive().getDouble(60.0);
double yNoise = data.of("Vertical_Randomness").assertPositive().getDouble(5.0);
double separation = data.of("Distance_Between_Bombs").assertPositive().getDouble(3.0);
double range = data.of("Maximum_Distance_From_Center").assertPositive().getDouble(25.0);
int layers = data.of("Layers").assertPositive().getInt(1);
int interval = data.of("Delay_Between_Layers").assertPositive().getInt(40);
Detonation detonation = data.of("Detonation").serialize(Detonation.class);
Mechanics mechanics = data.of("Mechanics").serialize(Mechanics.class);
return new AirStrike(projectile, min, max, yOffset, yNoise, separation, range, layers, interval, detonation, mechanics);
}
use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile 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);
}
use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile 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);
}
}
use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile in project MechanicsMain by WeaponMechanics.
the class ClusterBomb method serialize.
@Override
@Nonnull
public ClusterBomb serialize(SerializeData data) throws SerializerException {
int bombs = data.of("Number_Of_Bombs").assertExists().assertPositive().getInt();
Projectile projectileSettings = data.of("Split_Projectile").serialize(Projectile.class);
double speed = data.of("Projectile_Speed").assertPositive().getDouble(30.0) / 20.0;
int splits = data.of("Number_Of_Splits").assertPositive().getInt(1);
Detonation detonation = data.of("Detonation").serialize(Detonation.class);
Mechanics mechanics = data.of("Mechanics").serialize(Mechanics.class);
return new ClusterBomb(projectileSettings, speed, splits, bombs, detonation, mechanics);
}
use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile 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();
}
Aggregations