More QA changes
This commit is contained in:
parent
445d620ab2
commit
4efb4c1493
@ -73,7 +73,7 @@ public class KitRetroSquid extends Kit
|
||||
location.add(location.getDirection());
|
||||
location.getWorld().playSound(location, Sound.FIREWORK_LAUNCH, 1, 1);
|
||||
|
||||
LineParticle lineParticle = new LineParticle(location, location.getDirection(), 0.3, 40, ParticleType.FIREWORKS_SPARK, UtilServer.getPlayers());
|
||||
LineParticle lineParticle = new LineParticle(location, location.getDirection(), 0.3, 30, ParticleType.FIREWORKS_SPARK, UtilServer.getPlayers());
|
||||
|
||||
while (!lineParticle.update())
|
||||
{
|
||||
|
@ -0,0 +1,40 @@
|
||||
package nautilus.game.arcade.game.games.tug;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class TugItem
|
||||
{
|
||||
|
||||
private final EntityType _entityType;
|
||||
private final ItemStack _itemStack;
|
||||
private final int _cost;
|
||||
|
||||
TugItem(EntityType entityType, ItemStack itemStack, int cost)
|
||||
{
|
||||
_entityType = entityType;
|
||||
_itemStack = new ItemBuilder(itemStack)
|
||||
.setTitle(C.cYellow + "Spawn a " + UtilEnt.getName(entityType) + C.mBody + " - " + C.cGold + cost + " Gold")
|
||||
.build();
|
||||
_cost = cost;
|
||||
}
|
||||
|
||||
public EntityType getEntityType()
|
||||
{
|
||||
return _entityType;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
public int getCost()
|
||||
{
|
||||
return _cost;
|
||||
}
|
||||
}
|
@ -11,10 +11,9 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
@ -23,12 +22,15 @@ import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
@ -36,9 +38,11 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.events.PlayerKitGiveEvent;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.TeamGame;
|
||||
import nautilus.game.arcade.game.games.tug.entities.TugCow;
|
||||
import nautilus.game.arcade.game.games.tug.entities.TugEntity;
|
||||
import nautilus.game.arcade.game.games.tug.entities.TugSheep;
|
||||
import nautilus.game.arcade.game.games.tug.kits.KitTugArcher;
|
||||
import nautilus.game.arcade.game.games.tug.kits.KitTugLeaper;
|
||||
@ -56,9 +60,12 @@ public class TugOfWool extends TeamGame
|
||||
};
|
||||
private static final int MAX_ANIMALS = 30;
|
||||
private static final long INCREASE_TIME = TimeUnit.MINUTES.toMillis(2);
|
||||
private static final long GAME_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
|
||||
private static final long GAME_TIMEOUT = TimeUnit.MINUTES.toMillis(8);
|
||||
private static final long PURCHASE_COOLDOWN = TimeUnit.SECONDS.toMillis(5);
|
||||
private static final int GOLD_SLOT = 8;
|
||||
|
||||
private final Set<TugTeam> _teams;
|
||||
private final Set<TugItem> _items;
|
||||
|
||||
private float _speed = 1;
|
||||
private int _animalsPerIteration = 1;
|
||||
@ -74,10 +81,12 @@ public class TugOfWool extends TeamGame
|
||||
}, DESCRIPTION);
|
||||
|
||||
_teams = new HashSet<>();
|
||||
_items = new HashSet<>();
|
||||
|
||||
DamageFall = false;
|
||||
DeathOut = false;
|
||||
DeathSpectateSecs = 5;
|
||||
DeathSpectateSecs = 10;
|
||||
HungerSet = 20;
|
||||
|
||||
registerChatStats(
|
||||
Kills,
|
||||
@ -99,6 +108,13 @@ public class TugOfWool extends TeamGame
|
||||
|
||||
_teams.add(red);
|
||||
_teams.add(blue);
|
||||
|
||||
_items.add(new TugItem(
|
||||
EntityType.COW,
|
||||
new ItemBuilder(Material.MONSTER_EGG, UtilEnt.getEntityEggData(EntityType.COW))
|
||||
.build(),
|
||||
3
|
||||
));
|
||||
}
|
||||
|
||||
private List<Location> setupCrops(String key)
|
||||
@ -151,30 +167,11 @@ public class TugOfWool extends TeamGame
|
||||
{
|
||||
CreatureAllowOverride = true;
|
||||
|
||||
boolean cow = Math.random() < 0.01;
|
||||
|
||||
if (cow)
|
||||
{
|
||||
Announce(F.main(getArcadeManager().getName(), F.name("Bob The Cow") + " has spawned for both teams!"));
|
||||
}
|
||||
|
||||
_teams.forEach(team ->
|
||||
{
|
||||
for (int i = 0; i < _animalsPerIteration && team.getEntities().size() < MAX_ANIMALS; i++)
|
||||
{
|
||||
team.getEntities().add(new TugSheep(this, spawnEntity(team, Sheep.class)));
|
||||
}
|
||||
|
||||
if (cow)
|
||||
{
|
||||
LivingEntity entity = spawnEntity(team, Cow.class);
|
||||
|
||||
entity.setMaxHealth(60);
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
entity.setCustomName(C.cYellowB + "Bob The Cow");
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.getWorld().playSound(entity.getLocation(), Sound.COW_IDLE, 2, 1);
|
||||
team.getEntities().add(new TugCow(this, entity));
|
||||
team.getEntities().add(spawnTugEntity(EntityType.SHEEP, team));
|
||||
}
|
||||
});
|
||||
|
||||
@ -190,7 +187,41 @@ public class TugOfWool extends TeamGame
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends LivingEntity> T spawnEntity(TugTeam team, Class<T> classOfEntity)
|
||||
private void spawnFor(EntityType entityType, Player player)
|
||||
{
|
||||
TugTeam team = getTugTeam(player);
|
||||
|
||||
if (team == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CreatureAllowOverride = true;
|
||||
TugEntity entity = spawnTugEntity(entityType, team);
|
||||
CreatureAllowOverride = false;
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1);
|
||||
player.sendMessage(F.main(Manager.getName(), "You spawned a " + F.name(UtilEnt.getName(entityType)) + "."));
|
||||
team.getEntities().add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private TugEntity spawnTugEntity(EntityType entityType, TugTeam team)
|
||||
{
|
||||
switch (entityType)
|
||||
{
|
||||
case SHEEP:
|
||||
return new TugSheep(this, team, getSpawn(team));
|
||||
case COW:
|
||||
return new TugCow(this, team, getSpawn(team));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Location getSpawn(TugTeam team)
|
||||
{
|
||||
Location location = UtilAlg.Random(team.getSpawns());
|
||||
|
||||
@ -200,17 +231,8 @@ public class TugOfWool extends TeamGame
|
||||
}
|
||||
|
||||
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, GetSpectatorLocation())));
|
||||
T entity = location.getWorld().spawn(location, classOfEntity);
|
||||
|
||||
UtilEnt.vegetate(entity);
|
||||
UtilEnt.setTickWhenFarAway(entity, true);
|
||||
|
||||
if (entity instanceof Sheep)
|
||||
{
|
||||
((Sheep) entity).setColor(team.getGameTeam().getDyeColor());
|
||||
}
|
||||
|
||||
return entity;
|
||||
return location;
|
||||
}
|
||||
|
||||
private void updateTargets()
|
||||
@ -218,7 +240,7 @@ public class TugOfWool extends TeamGame
|
||||
_teams.forEach(team ->
|
||||
{
|
||||
List<Location> targetCrops = team.getEnemy().getCrops();
|
||||
List<TugSheep> targetEntities = team.getEnemy().getEntities();
|
||||
List<TugEntity> targetEntities = team.getEnemy().getEntities();
|
||||
|
||||
team.getEntities().removeIf(tugEntity ->
|
||||
{
|
||||
@ -227,6 +249,8 @@ public class TugOfWool extends TeamGame
|
||||
return true;
|
||||
}
|
||||
|
||||
tugEntity.updateName();
|
||||
|
||||
LivingEntity targetEntity = tugEntity.getTargetEntity();
|
||||
|
||||
// Has a target entity
|
||||
@ -248,7 +272,7 @@ public class TugOfWool extends TeamGame
|
||||
|
||||
Location targetLocation = tugEntity.getTargetLocation();
|
||||
|
||||
for (TugSheep otherTugEntity : targetEntities)
|
||||
for (TugEntity otherTugEntity : targetEntities)
|
||||
{
|
||||
// Attempt to target entity. If successful no need to handle anything else
|
||||
if (tugEntity.attemptTarget(otherTugEntity.getEntity()))
|
||||
@ -290,6 +314,7 @@ public class TugOfWool extends TeamGame
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity damagee = event.GetDamageeEntity();
|
||||
Player damager = event.GetDamagerPlayer(true);
|
||||
|
||||
if (damager == null)
|
||||
@ -299,13 +324,20 @@ public class TugOfWool extends TeamGame
|
||||
|
||||
TugTeam team = getTugTeam(damager);
|
||||
|
||||
if (team == null || !team.isEntity(event.GetDamageeEntity()))
|
||||
if (team == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (team.isEntity(damagee))
|
||||
{
|
||||
event.SetCancelled("Own Tug Entity");
|
||||
}
|
||||
else
|
||||
{
|
||||
setGold(damager, getGold(damager) + (damagee instanceof Player ? 2 : 1));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityDeath(EntityDeathEvent event)
|
||||
@ -316,7 +348,7 @@ public class TugOfWool extends TeamGame
|
||||
}
|
||||
|
||||
event.getDrops().clear();
|
||||
_teams.forEach(team -> team.getEntities().removeIf(entity -> entity.getEntity().equals(event.getEntity())));
|
||||
_teams.forEach(team -> team.getEntities().removeIf(other -> other.getEntity().equals(event.getEntity())));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@ -355,12 +387,69 @@ public class TugOfWool extends TeamGame
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void cropTrample(PlayerInteractEvent event)
|
||||
{
|
||||
if (!IsLive() || event.getClickedBlock() == null || event.getClickedBlock().getRelative(BlockFace.DOWN).getType() != Material.SOIL)
|
||||
if (!IsLive() || event.getClickedBlock() == null || event.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.SOIL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerKitGive(PlayerKitGiveEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
int slot = 3;
|
||||
|
||||
for (TugItem item : _items)
|
||||
{
|
||||
player.getInventory().setItem(slot++, item.getItemStack());
|
||||
}
|
||||
|
||||
setGold(player, 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
|
||||
if (itemStack == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (TugItem item : _items)
|
||||
{
|
||||
if (item.getItemStack().equals(itemStack))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
int gold = getGold(player);
|
||||
|
||||
if (gold < item.getCost())
|
||||
{
|
||||
player.sendMessage(F.main(Manager.getName(), "You don't " + C.cGold + "Gold" + C.Reset + " to buy a " + F.name(UtilEnt.getName(item.getEntityType())) + ". You need " + F.count(item.getCost() - gold) + " more."));
|
||||
return;
|
||||
}
|
||||
else if (!Recharge.Instance.use(player, "Buy Animal", PURCHASE_COOLDOWN, true, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setGold(player, gold - item.getCost());
|
||||
spawnFor(item.getEntityType(), player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -453,6 +542,27 @@ public class TugOfWool extends TeamGame
|
||||
return _speed;
|
||||
}
|
||||
|
||||
public void setGold(Player player, int amount)
|
||||
{
|
||||
if (amount == 0)
|
||||
{
|
||||
player.getInventory().setItem(GOLD_SLOT, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(GOLD_SLOT, new ItemBuilder(Material.GOLD_NUGGET, Math.max(1, amount))
|
||||
.setTitle(C.cGold + amount + " Gold")
|
||||
.addLore("Collect gold by killing animals", "and players! You can then spend", "it on more animals!")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
public int getGold(Player player)
|
||||
{
|
||||
ItemStack itemStack = player.getInventory().getItem(GOLD_SLOT);
|
||||
return itemStack == null ? 0 : itemStack.getAmount();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void command(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.tug.entities.TugEntity;
|
||||
import nautilus.game.arcade.game.games.tug.entities.TugSheep;
|
||||
|
||||
public class TugTeam
|
||||
@ -14,7 +15,7 @@ public class TugTeam
|
||||
|
||||
private final GameTeam _gameTeam;
|
||||
private final List<Location> _crops, _spawns;
|
||||
private final List<TugSheep> _entities;
|
||||
private final List<TugEntity> _entities;
|
||||
|
||||
private TugTeam _enemy;
|
||||
|
||||
@ -41,14 +42,14 @@ public class TugTeam
|
||||
return _spawns;
|
||||
}
|
||||
|
||||
public List<TugSheep> getEntities()
|
||||
public List<TugEntity> getEntities()
|
||||
{
|
||||
return _entities;
|
||||
}
|
||||
|
||||
public boolean isEntity(LivingEntity entity)
|
||||
{
|
||||
for (TugSheep tugEntity : getEntities())
|
||||
for (TugEntity tugEntity : getEntities())
|
||||
{
|
||||
if (tugEntity.getEntity().equals(entity))
|
||||
{
|
||||
|
@ -1,8 +1,10 @@
|
||||
package nautilus.game.arcade.game.games.tug.entities;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
@ -10,34 +12,68 @@ import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
|
||||
import nautilus.game.arcade.game.games.tug.TugOfWool;
|
||||
import nautilus.game.arcade.game.games.tug.TugTeam;
|
||||
|
||||
public class TugCow extends TugSheep
|
||||
public class TugCow extends TugEntity<Cow>
|
||||
{
|
||||
|
||||
public TugCow(TugOfWool host, LivingEntity entity)
|
||||
public TugCow(TugOfWool host, TugTeam team, Location spawn)
|
||||
{
|
||||
super(host, entity);
|
||||
super(host, team, spawn, 3, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cow spawn(Location location)
|
||||
{
|
||||
Cow cow = location.getWorld().spawn(location, Cow.class);
|
||||
|
||||
cow.setCustomNameVisible(true);
|
||||
cow.setMaxHealth(40);
|
||||
cow.setHealth(cow.getMaxHealth());
|
||||
|
||||
return cow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(LivingEntity other)
|
||||
{
|
||||
UtilEnt.getInRadius(other.getLocation(), 3).forEach((entity, scale) ->
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attemptTarget(LivingEntity other)
|
||||
{
|
||||
if (getEntity().equals(entity))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move()
|
||||
{
|
||||
super.move();
|
||||
|
||||
if (_entity.getTicksLived() % 10 == 0)
|
||||
{
|
||||
Location location = _entity.getLocation();
|
||||
|
||||
UtilEnt.getInRadius(location, 4).forEach((entity, scale) ->
|
||||
{
|
||||
if (entity.equals(_entity) || entity instanceof Player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector velocity = UtilAlg.getTrajectory(entity, getEntity())
|
||||
.setY(0.8)
|
||||
.multiply(scale);
|
||||
|
||||
other.getWorld().playEffect(other.getLocation().add(0, 1, 0), Effect.STEP_SOUND, Material.GRASS);
|
||||
Vector velocity = UtilAlg.getTrajectory(location, entity.getLocation())
|
||||
.setY(0.6);
|
||||
|
||||
UtilAction.velocity(entity, velocity);
|
||||
location.getWorld().playSound(location, Sound.COW_IDLE, 1, (float) Math.random());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setTargetEntity(null);
|
||||
@Override
|
||||
public float getSpeed()
|
||||
{
|
||||
return super.getSpeed() * 2;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,171 @@
|
||||
package nautilus.game.arcade.game.games.tug.entities;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
|
||||
import nautilus.game.arcade.game.games.tug.TugOfWool;
|
||||
import nautilus.game.arcade.game.games.tug.TugTeam;
|
||||
|
||||
public abstract class TugEntity<T extends LivingEntity>
|
||||
{
|
||||
|
||||
private final TugOfWool _host;
|
||||
private final T _entity;
|
||||
private static final int TARGET_RANGE_SQUARED = 64;
|
||||
private static final int EAT_RANGE_SQUARED = 2;
|
||||
|
||||
protected final TugOfWool _host;
|
||||
protected final TugTeam _team;
|
||||
protected final T _entity;
|
||||
private final int _attackRangeSquared, _attackRate;
|
||||
|
||||
private Location _targetLocation;
|
||||
private LivingEntity _targetEntity;
|
||||
private long _lastAttack;
|
||||
|
||||
TugEntity(TugOfWool host, TugTeam team, Location spawn, int attackRange, int attackRate)
|
||||
{
|
||||
_host = host;
|
||||
_team = team;
|
||||
_entity = spawn(spawn);
|
||||
_attackRangeSquared = attackRange * attackRange;
|
||||
_attackRate = attackRate;
|
||||
|
||||
UtilEnt.vegetate(_entity);
|
||||
UtilEnt.setTickWhenFarAway(_entity, true);
|
||||
}
|
||||
|
||||
public abstract T spawn(Location location);
|
||||
|
||||
public abstract void attack(LivingEntity other);
|
||||
|
||||
public boolean attemptAttack(LivingEntity other)
|
||||
{
|
||||
if (!UtilTime.elapsed(_lastAttack, _attackRate) || UtilMath.offsetSquared(_entity, other) > _attackRangeSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_lastAttack = System.currentTimeMillis();
|
||||
attack(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean attemptEat()
|
||||
{
|
||||
Location entityLocation = _entity.getLocation();
|
||||
|
||||
if (_targetLocation == null || UtilMath.offsetSquared(entityLocation, _targetLocation) > EAT_RANGE_SQUARED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
eat(_targetLocation.getBlock());
|
||||
return true;
|
||||
}
|
||||
|
||||
public void eat(Block block)
|
||||
{
|
||||
Location entityLocation = _entity.getLocation();
|
||||
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HEART, entityLocation.add(0, 1, 0), 1, 1, 1, 0, 6, ViewDist.NORMAL);
|
||||
_targetLocation.getWorld().playSound(entityLocation, Sound.EAT, 1.5F, (float) Math.random());
|
||||
_targetLocation.getWorld().playEffect(_targetLocation, Effect.STEP_SOUND, block.getType());
|
||||
block.setType(Material.AIR);
|
||||
_entity.remove();
|
||||
}
|
||||
|
||||
public boolean attemptTarget(LivingEntity other)
|
||||
{
|
||||
if (UtilMath.offsetSquared(_entity, other) < TARGET_RANGE_SQUARED)
|
||||
{
|
||||
setTargetEntity(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateName()
|
||||
{
|
||||
if (!_entity.isCustomNameVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ChatColor colour = _team.getGameTeam().GetColor();
|
||||
String name = colour.toString() + (int) Math.ceil(_entity.getHealth()) + C.Reset + "/" + colour.toString() + (int) Math.ceil(_entity.getMaxHealth());
|
||||
|
||||
if (name.equals(_entity.getCustomName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_entity.setCustomName(name);
|
||||
}
|
||||
|
||||
public void move()
|
||||
{
|
||||
Location location;
|
||||
|
||||
if (_targetEntity != null)
|
||||
{
|
||||
location = _targetEntity.getLocation();
|
||||
}
|
||||
else if (_targetLocation != null)
|
||||
{
|
||||
location = _targetLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector direction = UtilAlg.getTrajectory(_entity.getLocation(), location)
|
||||
.multiply(3);
|
||||
UtilEnt.CreatureMoveFast(_entity, location.clone().add(direction), getSpeed());
|
||||
}
|
||||
|
||||
public float getSpeed()
|
||||
{
|
||||
return _host.getSpeed();
|
||||
}
|
||||
|
||||
public T getEntity()
|
||||
{
|
||||
return _entity;
|
||||
}
|
||||
|
||||
public void setTargetLocation(Location targetLocation)
|
||||
{
|
||||
_targetLocation = targetLocation;
|
||||
}
|
||||
|
||||
public Location getTargetLocation()
|
||||
{
|
||||
return _targetLocation;
|
||||
}
|
||||
|
||||
public void setTargetEntity(LivingEntity targetEntity)
|
||||
{
|
||||
_targetEntity = targetEntity;
|
||||
}
|
||||
|
||||
public LivingEntity getTargetEntity()
|
||||
{
|
||||
return _targetEntity;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
package nautilus.game.arcade.game.games.tug.entities;
|
||||
|
||||
public enum TugEntityType
|
||||
{
|
||||
|
||||
SHEEP,
|
||||
COW
|
||||
|
||||
}
|
@ -1,136 +1,31 @@
|
||||
package nautilus.game.arcade.game.games.tug.entities;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import org.bukkit.entity.Sheep;
|
||||
|
||||
import nautilus.game.arcade.game.games.tug.TugOfWool;
|
||||
import nautilus.game.arcade.game.games.tug.TugTeam;
|
||||
|
||||
public class TugSheep
|
||||
public class TugSheep extends TugEntity<Sheep>
|
||||
{
|
||||
|
||||
private static final int ATTACK_RATE = 500;
|
||||
private static final int ATTACK_RANGE_SQUARED = 9;
|
||||
private static final int TARGET_RANGE_SQUARED = 64;
|
||||
private static final int EAT_RANGE_SQUARED = 2;
|
||||
|
||||
private final TugOfWool _host;
|
||||
private final LivingEntity _entity;
|
||||
|
||||
private Location _targetLocation;
|
||||
private LivingEntity _targetEntity;
|
||||
private long _lastAttack;
|
||||
|
||||
public TugSheep(TugOfWool host, LivingEntity entity)
|
||||
public TugSheep(TugOfWool host, TugTeam team, Location spawn)
|
||||
{
|
||||
_host = host;
|
||||
_entity = entity;
|
||||
super(host, team, spawn, 3, 500);
|
||||
}
|
||||
|
||||
public boolean attemptAttack(LivingEntity other)
|
||||
@Override
|
||||
public Sheep spawn(Location location)
|
||||
{
|
||||
if (!UtilTime.elapsed(_lastAttack, ATTACK_RATE) || UtilMath.offsetSquared(_entity, other) > ATTACK_RANGE_SQUARED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_lastAttack = System.currentTimeMillis();
|
||||
attack(other);
|
||||
return true;
|
||||
Sheep sheep = location.getWorld().spawn(location, Sheep.class);
|
||||
sheep.setColor(_team.getGameTeam().getDyeColor());
|
||||
return sheep;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(LivingEntity other)
|
||||
{
|
||||
other.damage(4 + Math.random(), _entity);
|
||||
}
|
||||
|
||||
public boolean attemptTarget(LivingEntity other)
|
||||
{
|
||||
if (UtilMath.offsetSquared(_entity, other) < TARGET_RANGE_SQUARED)
|
||||
{
|
||||
setTargetEntity(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean attemptEat()
|
||||
{
|
||||
Location entityLocation = _entity.getLocation();
|
||||
|
||||
if (_targetLocation == null || UtilMath.offsetSquared(entityLocation, _targetLocation) > EAT_RANGE_SQUARED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Block block = _targetLocation.getBlock();
|
||||
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HEART, entityLocation.add(0, 1, 0), 1, 1, 1, 0, 6, ViewDist.NORMAL);
|
||||
_targetLocation.getWorld().playSound(entityLocation, Sound.EAT, 1.5F, (float) Math.random());
|
||||
_targetLocation.getWorld().playEffect(_targetLocation, Effect.STEP_SOUND, block.getType());
|
||||
block.setType(Material.AIR);
|
||||
_entity.remove();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void move()
|
||||
{
|
||||
Location location;
|
||||
|
||||
if (_targetEntity != null)
|
||||
{
|
||||
location = _targetEntity.getLocation();
|
||||
}
|
||||
else if (_targetLocation != null)
|
||||
{
|
||||
location = _targetLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector direction = UtilAlg.getTrajectory(_entity.getLocation(), location)
|
||||
.multiply(_host.getSpeed());
|
||||
UtilEnt.CreatureMoveFast(_entity, location.clone().add(direction), _host.getSpeed());
|
||||
}
|
||||
|
||||
public void setTargetLocation(Location targetLocation)
|
||||
{
|
||||
_targetLocation = targetLocation;
|
||||
}
|
||||
|
||||
public Location getTargetLocation()
|
||||
{
|
||||
return _targetLocation;
|
||||
}
|
||||
|
||||
public void setTargetEntity(LivingEntity targetEntity)
|
||||
{
|
||||
_targetEntity = targetEntity;
|
||||
}
|
||||
|
||||
public LivingEntity getTargetEntity()
|
||||
{
|
||||
return _targetEntity;
|
||||
}
|
||||
|
||||
public LivingEntity getEntity()
|
||||
{
|
||||
return _entity;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user