attack enemy goal
This commit is contained in:
parent
7920f2729b
commit
2ef604aeaf
@ -35,7 +35,7 @@ public abstract class ObjectiveGoal <T extends Objective> implements Listener
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription(Player player)
|
||||
{
|
||||
return _description;
|
||||
|
@ -37,9 +37,11 @@ import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Giant;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilEnt
|
||||
@ -825,4 +827,21 @@ public class UtilEnt
|
||||
{
|
||||
return ent.getLocation().getBlock().getTypeId() == 8 || ent.getLocation().getBlock().getTypeId() == 9;
|
||||
}
|
||||
|
||||
public static void SetMetadata(Entity entity, String key, Object value)
|
||||
{
|
||||
entity.setMetadata(key, new FixedMetadataValue(UtilServer.getPlugin(), value));
|
||||
}
|
||||
|
||||
// Nicer than doing entity.getMetadata(key).get(0);
|
||||
public static Object GetMetadata(Entity entity, String key)
|
||||
{
|
||||
if (!entity.hasMetadata(key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return entity.getMetadata(key).get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -437,4 +437,20 @@ public class UtilInv
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void give(Player player, Material material)
|
||||
{
|
||||
give(player, material, 1);
|
||||
}
|
||||
|
||||
public static void give(Player player, Material material, int amount)
|
||||
{
|
||||
give(player, material, amount, (byte) 0);
|
||||
}
|
||||
|
||||
public static void give(Player shooter, Material material, int amount, byte data)
|
||||
{
|
||||
shooter.getInventory().addItem(new ItemStack(material, amount, data));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import mineplex.core.common.events.ServerShutdownEvent;
|
||||
import mineplex.core.delayedtask.DelayedTask;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.explosion.Explosion;
|
||||
import mineplex.core.fallingblock.FallingBlocks;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.give.Give;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
@ -93,6 +94,8 @@ public class Clans extends JavaPlugin
|
||||
|
||||
_donationManager = new DonationManager(this, _clientManager, webServerAddress);
|
||||
|
||||
new FallingBlocks(this);
|
||||
|
||||
new ServerConfiguration(this, _clientManager);
|
||||
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
|
||||
|
@ -262,11 +262,13 @@ public class SiegeManager extends MiniPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
public void spawnCannon(Player player, Location location)
|
||||
public Cannon spawnCannon(Player player, Location location)
|
||||
{
|
||||
Cannon cannon = new Cannon(location, _clansManager.getClan(player), this);
|
||||
|
||||
LiveSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon);
|
||||
|
||||
return cannon;
|
||||
}
|
||||
|
||||
public void dead(SiegeWeapon weapon)
|
||||
|
@ -199,21 +199,23 @@ public class OutpostManager extends MiniPlugin
|
||||
public void onClaim(PlayerClaimTerritoryEvent event)
|
||||
{
|
||||
for (Outpost outpost : _outposts.values())
|
||||
{
|
||||
if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getOwner().getName()) + "'s Outpost."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
_outposts.values()
|
||||
.stream()
|
||||
.filter(outpost -> outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.TICK : event.getType() == UpdateType.TICK)
|
||||
.forEach(Outpost::update);
|
||||
if (event.getType() == UpdateType.TICK)
|
||||
_outposts.values()
|
||||
.stream()
|
||||
.forEach(Outpost::update);
|
||||
|
||||
if (event.getType() == UpdateType.FASTER)
|
||||
if (!_removalQueue.isEmpty())
|
||||
|
@ -113,6 +113,8 @@ public abstract class SiegeWeapon implements Listener
|
||||
protected final NautHashMap<String, Entity> _entityMapping;
|
||||
|
||||
// Customizability
|
||||
private double[] _forcedVelocity;
|
||||
|
||||
protected boolean _isRideable;
|
||||
protected boolean _invertRotation;
|
||||
protected AccessRule _mountAccess;
|
||||
@ -299,12 +301,22 @@ public abstract class SiegeWeapon implements Listener
|
||||
return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null;
|
||||
}
|
||||
|
||||
public void SetForcedVelocity(double vertical, double horizontal)
|
||||
{
|
||||
_forcedVelocity = new double[] { vertical, horizontal };
|
||||
}
|
||||
|
||||
private void fire(Player player)
|
||||
{
|
||||
_lastFired = System.currentTimeMillis();
|
||||
|
||||
double[] vel = GetProjectileVelocity();
|
||||
|
||||
if (_forcedVelocity != null)
|
||||
{
|
||||
vel = _forcedVelocity;
|
||||
}
|
||||
|
||||
_inventory.clear();
|
||||
|
||||
CustomFire(_projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1]));
|
||||
|
@ -73,7 +73,9 @@ public class TutorialMapManager extends MiniPlugin
|
||||
_centerZ = minZ + ((maxZ - minZ) / 2);
|
||||
_centerX = (int) (Math.round(_centerX / 16D) * 16);
|
||||
_centerZ = (int) (Math.round(_centerZ / 16D) * 16);
|
||||
|
||||
|
||||
_scanList = new ArrayList<>();
|
||||
|
||||
_halfMapSize = (int) (Math.ceil(Math.max((maxX - minX) / 2D, (maxZ - minZ) / 2D) / 16D) * 16);
|
||||
|
||||
ArrayList<Entry<Integer, Integer>> list = new ArrayList<Entry<Integer, Integer>>();
|
||||
|
@ -122,7 +122,8 @@ public class ClansMainTutorial extends Tutorial
|
||||
ENEMY_LAND(DyeColor.RED), // Should be 16x16
|
||||
SPAWN(DyeColor.GREEN), // Spawn Platform
|
||||
FIELDS(DyeColor.PURPLE), // Boulders for ores to spawn in?
|
||||
SHOPS(DyeColor.YELLOW); // Little shop areas similar to Shops in clans map
|
||||
SHOPS(DyeColor.YELLOW), // Little shop areas similar to Shops in clans map
|
||||
ENEMY_ATTACK_AREA(DyeColor.BLACK); // W
|
||||
// Gray Wool - Cannon Location
|
||||
// Magenta Wool - Spawn
|
||||
// Lime Wool - Farming Shop
|
||||
@ -147,7 +148,8 @@ public class ClansMainTutorial extends Tutorial
|
||||
SPAWN(DyeColor.MAGENTA),
|
||||
FARMING_SHOP(DyeColor.LIME),
|
||||
PVP_SHOP(DyeColor.PURPLE),
|
||||
ENERGY_SHOP(DyeColor.SILVER);
|
||||
ENERGY_SHOP(DyeColor.SILVER),
|
||||
CANNON(DyeColor.GRAY);
|
||||
|
||||
private DyeColor _dataLocColor;
|
||||
|
||||
|
@ -1,19 +1,35 @@
|
||||
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.objective.Objective;
|
||||
import mineplex.core.common.objective.ObjectiveGoal;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.fallingblock.FallingBlocks;
|
||||
import mineplex.game.clans.clans.siege.SiegeManager;
|
||||
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
|
||||
import mineplex.game.clans.clans.siege.weapon.Cannon;
|
||||
import mineplex.game.clans.tutorial.TutorialRegion;
|
||||
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
|
||||
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial.Point;
|
||||
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
|
||||
|
||||
public class AttackEnemyGoal extends ObjectiveGoal
|
||||
public class AttackEnemyGoal extends ObjectiveGoal<ClanObjective>
|
||||
{
|
||||
public AttackEnemyGoal(Objective objective)
|
||||
private Cannon _cannon;
|
||||
|
||||
public AttackEnemyGoal(ClanObjective objective)
|
||||
{
|
||||
super(objective, "Attack Enemy", "Attack enemy clan! Blow a hole in their base with a Cannon.");
|
||||
}
|
||||
@ -21,8 +37,11 @@ public class AttackEnemyGoal extends ObjectiveGoal
|
||||
@Override
|
||||
protected void customStart(Player player)
|
||||
{
|
||||
player.getInventory().addItem(new ItemStack(Material.TNT, 20));
|
||||
finish(player);
|
||||
UtilInv.give(player, Material.TNT);
|
||||
|
||||
_cannon = SiegeManager.Instance.spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON));
|
||||
|
||||
_cannon.SetForcedVelocity(0.4, -2.45);
|
||||
}
|
||||
|
||||
// use this event for figuring out if the cannon hit the base
|
||||
@ -33,15 +52,68 @@ public class AttackEnemyGoal extends ObjectiveGoal
|
||||
|
||||
if (!contains(shooter))
|
||||
{
|
||||
if (getObjective().getPlugin().isInTutorial(shooter))
|
||||
{
|
||||
UtilPlayer.message(shooter, F.main("Clans", "No cheating! (:"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Location center = event.getProjectile().getLocation();
|
||||
int radiusOfCrater = event.getProjectile().getCraterSize();
|
||||
|
||||
// if (center.distance(enemyBase) <= radius) {
|
||||
// finish(shooter);
|
||||
// }
|
||||
TutorialRegion region = getObjective().getPlugin().getRegion(shooter);
|
||||
|
||||
if (getObjective().getPlugin().isIn(center, region, ClansMainTutorial.Bounds.ENEMY_ATTACK_AREA))
|
||||
{
|
||||
double radius = 4.2;
|
||||
|
||||
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
|
||||
int iR = (int) radius + 1;
|
||||
|
||||
for (int x = -iR; x <= iR; x++)
|
||||
{
|
||||
for (int z = -iR; z <= iR; z++)
|
||||
{
|
||||
for (int y = -iR; y <= iR; y++)
|
||||
{
|
||||
Block curBlock = center.getBlock().getRelative(x, y, z);
|
||||
|
||||
double offset = UtilMath.offset(center, curBlock.getLocation());
|
||||
|
||||
if (offset <= radius)
|
||||
{
|
||||
blockList.put(curBlock, Double.valueOf(offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blockList.forEach((block, dist) -> {
|
||||
|
||||
if (block.getType() == Material.SMOOTH_BRICK
|
||||
|| block.getType() == Material.SMOOTH_STAIRS
|
||||
|| block.getType() == Material.IRON_DOOR_BLOCK)
|
||||
|
||||
if (Math.random() < 0.2 + (dist.doubleValue() / 2.55) || dist.doubleValue() < 1.75)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
|
||||
if (block.getType() != Material.IRON_DOOR_BLOCK)
|
||||
FallingBlocks.Instance.Spawn(block.getLocation(), block.getType(), block.getData(), center);
|
||||
}
|
||||
});
|
||||
|
||||
finish(shooter);
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilPlayer.message(shooter, F.main("Clans", "You missed! Try to hit the enemies front wall, that should blow a nice big hole!"));
|
||||
UtilInv.give(shooter, Material.TNT);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,18 +5,21 @@ import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.objective.Objective;
|
||||
import mineplex.core.common.objective.ObjectiveGoal;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.game.clans.clans.event.ClanCreatedEvent;
|
||||
|
||||
public class StealEnemyPotatoesGoal extends ObjectiveGoal
|
||||
{
|
||||
public StealEnemyPotatoesGoal(Objective objective)
|
||||
{
|
||||
super(objective, "Create a Clan", "Create a Clan");
|
||||
super(objective, "Steal Enemy Potatoes", "Steal the enemies potatoes");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customStart(Player player)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Clans", "Now that you have blown a hole in the enemy's base, go and steal their potatoes."));
|
||||
finish(player);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user