Capture point fix

This commit is contained in:
Sam 2017-05-04 20:20:48 +01:00
parent 8f01015df9
commit 3210843395
3 changed files with 148 additions and 22 deletions

View File

@ -1,11 +1,18 @@
package nautilus.game.arcade.game.games.moba;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.moba.kit.KitPlayer;
import nautilus.game.arcade.game.games.moba.structure.point.CapturePoint;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import java.util.*;
public class Moba extends TeamGame
{
@ -14,12 +21,16 @@ public class Moba extends TeamGame
"MORE CAPTURE POINTS"
};
private final List<CapturePoint> _capturePoints = new ArrayList<>(3);
public Moba(ArcadeManager manager)
{
super(manager, GameType.MOBA, new Kit[] { new KitPlayer(manager) }, DESCRIPTION);
DeathOut = false;
DeathSpectateSecs = 8;
HungerSet = 20;
DontAllowOverfill = false;
new CompassModule()
.setGiveCompass(true)
@ -31,6 +42,82 @@ public class Moba extends TeamGame
@Override
public void ParseData()
{
Collection<Location> capturePoints = getLocationStartsWith("POINT").values();
for (Location location : capturePoints)
{
_capturePoints.add(new CapturePoint(this, location));
}
}
@Override
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
GameState state = GetState();
switch (state)
{
case Prepare:
writePrepare();
break;
case Live:
writeLive();
break;
case End:
writeEnd();
break;
}
Scoreboard.draw();
}
private void writePrepare()
{
}
private void writeLive()
{
}
private void writeEnd()
{
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
for (CapturePoint point : _capturePoints)
{
point.update();
}
}
private Map<String, Location> getLocationStartsWith(String s)
{
Map<String, Location> map = new HashMap<>();
for (String key : WorldData.GetAllCustomLocs().keySet())
{
if (key.startsWith(s))
{
map.put(key, WorldData.GetCustomLocs(key).get(0));
}
}
return map;
}
}

View File

@ -0,0 +1,30 @@
package nautilus.game.arcade.game.games.moba.kit;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.moba.Moba;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class KitSelection implements Listener
{
private final
public KitSelection(Moba moba)
{
UtilServer.RegisterEvents(this);
}
@EventHandler
public void live(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
{
return;
}
UtilServer.Unregister(this);
}
}

View File

@ -1,15 +1,10 @@
package nautilus.game.arcade.game.games.moba.structure.point;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.*;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.moba.Moba;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@ -66,7 +61,7 @@ public class CapturePoint
_captureDist = highestDist * (double) MAX_RADIUS;
}
public boolean update()
public void update()
{
// Store the number of players in a team in this map
Map<GameTeam, Integer> playersOnPoint = new HashMap<>();
@ -112,7 +107,7 @@ public class CapturePoint
// This means there are 2 teams on the point
else
{
return false;
return;
}
}
}
@ -120,17 +115,16 @@ public class CapturePoint
// No one at all is on the point
if (highest == null)
{
return false;
return;
}
// If it has just reached the maximum progress, set the owner.
if (_owner != null && _owner.equals(highest) && _progress == MAX_PROGRESS)
if (_owner != null && _owner.equals(highest) && _progress >= MAX_PROGRESS)
{
return false;
return;
}
capture(highest);
return true;
}
private void capture(GameTeam team)
@ -144,15 +138,15 @@ public class CapturePoint
// If it is the same team
if (_side.equals(team))
{
// Captured
if (_progress == MAX_PROGRESS)
{
setOwner(team);
}
// Increase progress
_progress++;
display(team, true);
// Captured
if (_progress >= MAX_PROGRESS)
{
setOwner(team);
}
}
// Other team
else
@ -160,6 +154,7 @@ public class CapturePoint
// Point back to a neutral state
if (_progress == 0)
{
setBeaconColour(null);
_side = team;
// Recursively call this method now that the first (same team) condition will be true
capture(team);
@ -175,6 +170,9 @@ public class CapturePoint
{
_owner = team;
setBeaconColour(team);
UtilFirework.playFirework(_center, Type.BURST, team.GetColorBase(), false, false);
UtilServer.CallEvent(new CapturePointCaptureEvent(this));
}
@ -182,7 +180,7 @@ public class CapturePoint
{
Bukkit.broadcastMessage("progress=" + _progress + " forward=" + forward);
double toChange = Math.ceil(_wool.size() / MAX_PROGRESS);
double toChange = Math.ceil(_wool.size() / MAX_PROGRESS) + 1;
int changed = 0;
for (Block block : _wool)
{
@ -203,6 +201,7 @@ public class CapturePoint
block.setData(team.GetColorData());
glass.setData(team.GetColorData());
changed++;
_changed.add(block);
}
else
{
@ -214,10 +213,20 @@ public class CapturePoint
block.setData((byte) 0);
glass.setData((byte) 0);
changed++;
_changed.remove(block);
}
glass.getWorld().playEffect(glass.getLocation().add(0.5, 0.5, 0.5), Effect.STEP_SOUND, block.getType(), team.GetColorData());
}
}
private void setBeaconColour(GameTeam team)
{
byte colour = team == null ? 0 : team.GetColorData();
_center.getBlock().getRelative(BlockFace.DOWN).setData(colour);
}
public GameTeam getOwner()
{
return _owner;