Change scoring behavior to increase accuracy, increase power of right click throw, solve players becoming stuck in webs and border, solve ball becoming stuck outside border, perform other small gameplay tweaks

This commit is contained in:
AlexTheCoder 2016-06-22 18:25:32 -04:00
parent 4f00c72d8c
commit 56205a2505
3 changed files with 209 additions and 67 deletions

View File

@ -1,6 +1,7 @@
package nautilus.game.arcade.game.games.basketball;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import mineplex.core.common.util.C;
@ -9,7 +10,9 @@ import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
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.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
@ -27,12 +30,15 @@ import nautilus.game.arcade.game.games.basketball.data.ScoringManager;
import nautilus.game.arcade.game.games.basketball.data.ThrowData;
import nautilus.game.arcade.game.games.basketball.kit.BasketballPlayerKit;
import nautilus.game.arcade.kit.Kit;
import net.minecraft.server.v1_8_R3.BlockPosition;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
@ -41,9 +47,11 @@ import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
/**
@ -58,6 +66,7 @@ public class Basketball extends TeamGame
private static final double THREE_POINTER_DISTANCE = 27;
private boolean _frozen = false;
private long _lastDribbleAnim = 0;
private HashMap<GameTeam, Block> _hoops = new HashMap<>();
private ScoringManager _score;
@ -67,6 +76,8 @@ public class Basketball extends TeamGame
private double _maxZ = 0;
private double _minZ = 0;
private double _velocity = -7;
public Basketball(ArcadeManager manager)
{
super(manager, GameType.Basketball, new Kit[] {new BasketballPlayerKit(manager)}, new String[]
@ -78,6 +89,7 @@ public class Basketball extends TeamGame
);
this.TeamArmor = true;
this.TeamArmorHotbar = true;
this.HealthSet = 20;
this.HungerSet = 20;
this.Damage = false;
@ -87,8 +99,22 @@ public class Basketball extends TeamGame
_score = new ScoringManager(this);
}
private boolean isOutOfBounds(Location loc)
private boolean isOutOfBounds(Location loc, boolean ball)
{
if (ball)
{
if ((loc.getX() - 1) > _maxX || (loc.getX() + 1) < _minX)
{
return true;
}
if ((loc.getZ() - 1) > _maxZ || (loc.getZ() + 1) < _minZ)
{
return true;
}
return false;
}
if (loc.getX() >= _maxX || loc.getX() <= _minX)
{
return true;
@ -104,6 +130,7 @@ public class Basketball extends TeamGame
private Entity spawnBall(Location loc)
{
this.CreatureAllowOverride = true;
_velocity = -7;
Entity e = Manager.GetCreature().SpawnEntity(loc, EntityType.SLIME);
UtilEnt.Vegetate(e, true);
UtilEnt.ghost(e, true, false);
@ -131,17 +158,40 @@ public class Basketball extends TeamGame
return;
}
Vector vec = _ball.getVelocity();
if (_throwData != null)
{
for (Player player : GetTeam(_throwData.getThrower()).GetPlayers(true))
{
if (UtilMath.offset(_ball, player) <= 2.5)
{
if (Recharge.Instance.usable(player, "Catch Ball", false))
{
catchBall(player);
return;
}
}
}
}
Vector vec = _ball.getVelocity();
announceDebug(vec.toString());
//Rebound Y
if (UtilEnt.isGrounded(_ball))
{
if (vec.getY() < -0.1)
announceDebug("First");
if (vec.getY() < 0)
{
vec.setY(_ball.getVelocity().getY() * -0.65);
announceDebug("Second");
vec.setY(_ball.getVelocity().getY() * _velocity);
_velocity = Math.max(0, _velocity - .5);
}
}
if (!UtilEnt.isGrounded(_ball))
{
vec.setY(vec.getY() - 0.08);
}
//Rebound X
if ((vec.getX() > 0 && _ball.getLocation().getX() >= _maxX) || (vec.getX() < 0 && _ball.getLocation().getX() <= _minX))
{
@ -158,6 +208,7 @@ public class Basketball extends TeamGame
vec = vec.multiply(0.9);
}
announceDebug(vec);
_ball.setVelocity(vec);
}
@ -174,7 +225,7 @@ public class Basketball extends TeamGame
double power = 1.7;
if (right)
{
power = 1.52;
power = 3.1;
}
e.setVelocity(origin.getEyeLocation().getDirection().normalize().multiply(power));
@ -193,7 +244,7 @@ public class Basketball extends TeamGame
private void catchBall(Player player)
{
_dribbling = player;
for (int i = 0; i < 9; i++)
for (int i = 0; i < 8; i++)
{
_dribbling.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
}
@ -227,13 +278,14 @@ public class Basketball extends TeamGame
public void stealBall(Player to, Player from)
{
Recharge.Instance.use(to, "ThrowBall", 1500, false, false, false);
_dribbling = to;
for (int i = 0; i < 9; i++)
for (int i = 0; i < 8; i++)
{
to.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
}
UtilInv.removeAll(from, Material.SLIME_BALL, (byte)0);
Bukkit.broadcastMessage(F.main("Game", to.getName() + " has stolen the ball from " + from.getName() + "!"));
Bukkit.broadcastMessage(F.main("Game", GetTeam(to).GetColor() + to.getName() + C.cGray + " has stolen the ball from " + GetTeam(from).GetColor() + from.getName() + C.cGray + "!"));
}
private boolean checkCatching()
@ -265,67 +317,83 @@ public class Basketball extends TeamGame
_ball = null;
_throwData = null;
_frozen = true;
GameTeam other = getOtherTeam(team);
List<Player> teamP = other.GetPlayers(true);
GameTeam red = GetTeam(ChatColor.RED);
GameTeam blue = GetTeam(ChatColor.AQUA);
//Select player to get ball
Player carrier = teamP.get(new Random().nextInt(teamP.size()));
for (Player player : red.GetPlayers(true))
for (int i = 0; i < teamP.size(); i++)
{
player.teleport(red.GetSpawn());
Player player = teamP.get(i);
if (carrier.getEntityId() != player.getEntityId())
{
String key = DataLoc.BLUE_SCORE_SPAWN.getKey();
if (other.GetColor() == ChatColor.RED)
key = DataLoc.RED_SCORE_SPAWN.getKey();
i = Math.min(WorldData.GetCustomLocs(key).size() - 1, i);
player.teleport(WorldData.GetCustomLocs(key).get(i));
}
}
for (Player player : blue.GetPlayers(true))
for (Player player : team.GetPlayers(true))
{
player.teleport(blue.GetSpawn());
player.teleport(team.GetSpawn());
}
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () -> {
_frozen = false;
spawnNeutralBall();
}, 20 * 3);
Location teleport = WorldData.GetCustomLocs(DataLoc.BLUE_UNDER_HOOP.getKey()).get(0);
if (other.GetColor() == ChatColor.RED)
teleport = WorldData.GetCustomLocs(DataLoc.RED_UNDER_HOOP.getKey()).get(0);
teleport.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(teleport, WorldData.GetCustomLocs(DataLoc.CENTER_COURT.getKey()).get(0))));
teleport.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(teleport, WorldData.GetCustomLocs(DataLoc.CENTER_COURT.getKey()).get(0))));
carrier.teleport(teleport);
_dribbling = carrier;
for (int i = 0; i < 8; i++)
{
_dribbling.getInventory().setItem(i, new ItemBuilder(Material.SLIME_BALL).setTitle(C.cGold + "Basketball").build());
}
}
private void checkScoring()
{
announceDebug(1);
if (_ball == null)
{
announceDebug(1.5);
return;
}
announceDebug(2);
for (GameTeam team : _hoops.keySet())
{
if (team != null)
announceDebug(team.GetName());
else
announceDebug(2.5);
Location check = _hoops.get(team).getLocation();
if (UtilMath.offset(check, _ball.getLocation()) <= 1)
if (UtilMath.offset(check, _ball.getLocation()) <= 1.3)
{
announceDebug(3);
score(getOtherTeam(team), check);
return;
}
}
}
private void dribble(boolean animate)
private void dribble()
{
if (_dribbling == null)
{
_lastDribbleAnim = System.currentTimeMillis();
return;
}
UtilTextBottom.display(C.cRed + "You have the ball!", _dribbling);
if (animate)
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, _dribbling.getEyeLocation(), new Random().nextFloat(), new Random().nextFloat(), new Random().nextFloat(), 0, 1, ViewDist.MAX);
if (System.currentTimeMillis() - _lastDribbleAnim > 333)
{
_lastDribbleAnim = System.currentTimeMillis();
Item item = _dribbling.getWorld().dropItem(_dribbling.getLocation(), new ItemStack(Material.SLIME_BALL));
item.setPickupDelay(Integer.MAX_VALUE);
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () -> {
item.remove();
}, 20 * 1);
//TODO: Add dribbling animation
}, 7);
}
}
@ -406,6 +474,7 @@ public class Basketball extends TeamGame
}
}
}
_score.displayScores(Scoreboard, true, winner.GetColor() + winner.GetName());
SetState(GameState.End);
}
@ -433,6 +502,8 @@ public class Basketball extends TeamGame
{
if (!IsLive())
return;
if (_frozen)
return;
if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player))
{
@ -446,8 +517,8 @@ public class Basketball extends TeamGame
{
if (Recharge.Instance.usable(player, "Steal Ball", true))
{
Recharge.Instance.use(player, "Steal Ball", 1000 * 30, true, false, false);
if (new Random().nextDouble() <= .25)
Recharge.Instance.use(player, "Steal Ball", 1000 * 5, true, false, false);
if (new Random().nextDouble() <= .15)
{
stealBall(player, target);
}
@ -465,12 +536,16 @@ public class Basketball extends TeamGame
if (!IsLive())
return;
if (_dribbling != null && event.getPlayer().getEntityId() == _dribbling.getEntityId())
if (_frozen)
return;
if (_dribbling != null && event.getPlayer().getEntityId() == _dribbling.getEntityId() && Recharge.Instance.usable(_dribbling, "ThrowBall", false))
{
throwBall(event.getPlayer(), event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK);
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onUpdate(UpdateEvent event)
{
@ -483,11 +558,56 @@ public class Basketball extends TeamGame
{
return;
}
for (Player player : GetPlayers(true))
{
CraftPlayer cp = (CraftPlayer)player;
for (int x = (int)Math.floor(cp.getHandle().getBoundingBox().a + 0.001); x <= (int)Math.floor(cp.getHandle().getBoundingBox().d - 0.001); x++)
{
for (int y = (int)Math.floor(cp.getHandle().getBoundingBox().b + 0.001); y <= (int)Math.floor(cp.getHandle().getBoundingBox().e - 0.001); y++)
{
for (int z = (int)Math.floor(cp.getHandle().getBoundingBox().c + 0.001); z <= (int)Math.floor(cp.getHandle().getBoundingBox().f - 0.001); z++)
{
CraftWorld world = (CraftWorld)WorldData.World;
if (net.minecraft.server.v1_8_R3.Block.getId(world.getHandle().getType(new BlockPosition(x, y, z)).getBlock()) == Material.WEB.getId())
{
player.teleport(new Location(player.getWorld(), x, y - 2, z));
}
}
}
}
}
if (_dribbling != null && !_dribbling.isOnline())
{
_dribbling = null;
spawnBall(_dribbling.getLocation());
spawnNeutralBall();
}
if (_ball != null)
{
if (isOutOfBounds(_ball.getLocation(), true))
{
if (_ball.hasMetadata("Respawn"))
{
if (UtilTime.elapsed(_ball.getMetadata("Respawn").get(0).asLong(), 2000))
{
_ball.removeMetadata("Respawn", Manager.getPlugin());
_ball.setVelocity(UtilAlg.getTrajectory(_ball.getLocation(), WorldData.GetCustomLocs(DataLoc.CENTER_COURT.getKey()).get(0)));
}
}
else
{
_ball.setMetadata("Respawn", new FixedMetadataValue(Manager.getPlugin(), System.currentTimeMillis()));
}
}
else
{
if (_ball.hasMetadata("Respawn"))
{
_ball.removeMetadata("Respawn", Manager.getPlugin());
}
}
}
reboundBall();
if (!checkCatching())
@ -495,17 +615,12 @@ public class Basketball extends TeamGame
checkScoring();
}
dribble(false);
}
if (event.getType() == UpdateType.SEC)
{
dribble(true);
dribble();
}
if (event.getType() == UpdateType.FASTER)
{
_score.displayScores(Scoreboard);
_score.displayScores(Scoreboard, false, "");
}
}
@ -515,7 +630,7 @@ public class Basketball extends TeamGame
if (!IsLive())
return;
if (UtilPlayer.isSpectator(event.getPlayer()))
if (!IsPlaying(event.getPlayer()))
{
return;
}
@ -531,10 +646,10 @@ public class Basketball extends TeamGame
return;
}
if (isOutOfBounds(event.getTo()))
if (isOutOfBounds(event.getTo(), false))
{
event.getPlayer().teleport(event.getFrom());
Vector bounce = UtilAlg.getTrajectory(event.getTo(), event.getFrom());
Vector bounce = UtilAlg.getTrajectory(event.getTo(), WorldData.GetCustomLocs(DataLoc.CENTER_COURT.getKey()).get(0));
event.getPlayer().setVelocity(bounce.normalize());
event.getPlayer().sendMessage(F.main("Game", "You aren't allowed to go out of bounds!"));
}
@ -545,11 +660,24 @@ public class Basketball extends TeamGame
{
if (event.GetGame().equals(this) && event.GetState() == GameState.Live)
{
_frozen = true;
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () -> {
spawnNeutralBall();
_ball.setVelocity(_ball.getVelocity().add(new Vector(0, 1.5, 0)));
/*_frozen = true;
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () ->
{
_frozen = false;
spawnNeutralBall();
}, 20 * 3);
}, 20 * 3);*/
}
}
@EventHandler
public void onDebug(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().toLowerCase().contains("/setvelocity ") && event.getPlayer().isOp())
{
event.setCancelled(true);
_velocity = Double.parseDouble(event.getMessage().replace("/setvelocity ", "")) * -1;
}
}
}

View File

@ -9,7 +9,12 @@ public enum DataLoc
BLUE_HOOP("BLUE_HOOP"),
CENTER_COURT("CENTER_COURT"),
CORNER_MIN("CORNER_MIN"),
CORNER_MAX("CORNER_MAX")
CORNER_MAX("CORNER_MAX"),
RED_SCORE_SPAWN("RED_SCORE_SP"),
RED_UNDER_HOOP("RED_UNDER"),
BLUE_SCORE_SPAWN("BLUE_SCORE_SP"),
BLUE_UNDER_HOOP("BLUE_UNDER"),
STAND("STAND_POS")
;
private String _key;

View File

@ -36,7 +36,7 @@ public class ScoringManager
* Displays the scores and time remaining on the Game Scoreboard
* @param sb The GameScoreboard of the currently running Basketball game
*/
public void displayScores(GameScoreboard sb)
public void displayScores(GameScoreboard sb, boolean end, String winTeam)
{
sb.Reset();
sb.Write(C.cRedB + "Red Score");
@ -49,24 +49,33 @@ public class ScoringManager
sb.WriteBlank();
sb.Write(C.cYellowB + "Time Remaining");
long timeLeft = (_host.GetStateTime() + UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)) - System.currentTimeMillis();
if (!_host.IsLive() && !_host.InProgress())
if (end)
{
timeLeft = 0;
}
else if (!_host.IsLive() && _host.InProgress())
{
timeLeft = UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.SECONDS);
}
if (timeLeft < 0)
{
sb.Write(C.cYellow + "Overtime");
sb.Write(C.cWhiteB + "FINAL SCORE");
sb.WriteBlank();
sb.Write(winTeam + " Wins!");
}
else
{
sb.Write(UtilTime.MakeStr(timeLeft));
sb.Write(C.cYellowB + "Time Remaining");
long timeLeft = (_host.GetStateTime() + UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)) - System.currentTimeMillis();
if (!_host.IsLive() && !_host.InProgress())
{
timeLeft = 0;
}
else if (!_host.IsLive() && _host.InProgress())
{
timeLeft = UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.SECONDS);
}
if (timeLeft < 0)
{
sb.Write(C.cYellow + "Overtime");
}
else
{
sb.Write(UtilTime.MakeStr(timeLeft));
}
}
sb.Draw();
@ -88,4 +97,4 @@ public class ScoringManager
_blueScore += points;
}
}
}
}