From 2fcd80944747d41ecf37a09612228af52ac4be4a Mon Sep 17 00:00:00 2001 From: William Burns Date: Tue, 29 Mar 2016 18:03:28 +0100 Subject: [PATCH] PC-34 - Effects/Particles when you blow up enemy --- .../mineplex/core/common/util/UtilAlg.java | 10 ++++++ .../game/clans/clans/siege/weapon/Cannon.java | 36 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index 1bc7c0147..ebf5f7f8d 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.Random; import java.util.Set; import java.util.TreeSet; import java.util.stream.Stream; @@ -612,4 +613,13 @@ public class UtilAlg return new Location(location.getWorld(), x, location.getY(), z, location.getYaw(), location.getPitch()); } + + public static Location getRandomLocation(Location center, int radius) + { + Random r = new Random(); + int x = r.nextInt(radius * 2) - radius; + int y = r.nextInt(radius * 2) - radius; + int z = r.nextInt(radius * 2) - radius; + return center.clone().add(x, y, z); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index c739c1bb3..cd9c28f64 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -1,10 +1,13 @@ package mineplex.game.clans.clans.siege.weapon; +import java.util.ArrayList; +import java.util.Collection; import java.util.Map.Entry; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; @@ -20,6 +23,7 @@ import com.google.common.collect.Lists; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilCollections; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilMath; @@ -32,6 +36,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; @@ -405,5 +410,36 @@ public class Cannon extends SiegeWeapon return new double[] { yAdd, hMult }; } + + @EventHandler + public void explosionEffects(SiegeWeaponExplodeEvent event) + { + for (int i = 0; i < 8; i++) + { + // Explosion particle effects. + Location point = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 5); + UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, point, 0, 0, 0, 1, 2, ViewDist.MAX); + } + + // Block explosion. + ArrayList blocks = new ArrayList<>(); + int attempts = 0; + while (blocks.size() < 10 && (attempts < 30)) + { + Block block = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), (4 * getPowerLevel())).getBlock(); + if ((block.getType() != Material.AIR) && (!blocks.contains(block))) + { + blocks.add(block); + } + + attempts++; + } + + _siegeManager.getClansManager().getExplosion().BlockExplosion( + blocks, + event.getProjectile().getLocation(), + false + ); + } }