This commit is contained in:
William Burns 2015-12-08 10:44:24 +00:00
parent 43192317ad
commit e6d995008e
2 changed files with 326 additions and 0 deletions

View File

@ -0,0 +1,223 @@
package nautilus.game.arcade.game.games.gladiators;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
/**
* Created by William (WilliamTiger).
* 07/12/15
*/
public class Arena
{
private Gladiators _host;
private ArenaType _colour;
private Location _mid;
private ArrayList<Location> _spawns;
private Arena _parent;
private Arena[] _childs = new Arena[2];
private boolean _isUsed;
private ArrayList<Location> _doorBlocks;
private boolean _closedDoor;
public Arena(Gladiators host, Location mid, ArenaType colour)
{
_host = host;
_mid = mid;
_colour = colour;
_spawns = new ArrayList<>();
_parent = null;
_isUsed = false;
_doorBlocks = new ArrayList<>();
_closedDoor = false;
setupSpawns();
}
public Arena getParent()
{
return _parent;
}
public void setParent(Arena parent)
{
_parent = parent;
}
public Arena getChildAt(int index)
{
return _childs[index];
}
public Arena[] getChilds()
{
return _childs;
}
public int getCapacity()
{
int cap = _childs.length;
for(Arena child : _childs)
{
if(child != null)
if(child.isUsed()) cap--;
}
return cap;
}
public ArrayList<Location> getDoorBlocks()
{
return _doorBlocks;
}
public void setChild(int index, Arena child)
{
_childs[index] = child;
child.setParent(this);
}
public void getUsageMap(HashMap<Arena, Integer> used)
{
if(isUsed()) used.put(this, getCapacity());
for(Arena child : _childs)
{
if(child != null) child.getUsageMap(used);
}
}
public boolean areChildrenUsed()
{
for(Arena child : _childs)
{
if(child != null)
if(!child.isUsed()) return false;
}
return true;
}
public Arena getUnusedChild()
{
for(Arena child : _childs)
{
if(child != null)
if(!child.isUsed()) return child;
}
return null;
}
private void setupSpawns()
{
ArrayList<Location> possible = (ArrayList<Location>) _host.WorldData.GetDataLocs("BLACK").clone();
_mid.setY(UtilAlg.findClosest(_mid, possible).getY());
_spawns.add(correctFace(UtilAlg.findClosest(_mid, possible)));
possible.remove(_spawns.get(0));
_spawns.add(correctFace(UtilAlg.findClosest(_mid, possible)));
}
private Location correctFace(Location l)
{
l.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(l, _mid)));
l.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(l, _mid)));
return l;
}
public Gladiators getHost()
{
return _host;
}
public ArenaType getColour()
{
return _colour;
}
public Location getMid()
{
return _mid;
}
public ArrayList<Location> getSpawns()
{
return _spawns;
}
public ArrayList<Location> capacitySpawns()
{
ArrayList<Location> ret = new ArrayList<>();
if (getCapacity() == 0) return ret;
if (getCapacity() == 1)
{
ret.add(_spawns.get(0));
return ret;
}
if (getCapacity() == 2)
{
ret.add(_spawns.get(0));
ret.add(_spawns.get(1));
return ret;
}
return ret;
}
public ArrayList<Player> getPlayers()
{
ArrayList<Player> pls = new ArrayList<>();
for (Player p : _host.GetPlayers(true))
{
if (UtilMath.offset(p.getLocation(), _mid) <= 21)
pls.add(p);
}
return pls;
}
public int getPlayerCount()
{
ArrayList<Player> pls = new ArrayList<>();
for (Player p : _host.GetPlayers(true))
{
if (UtilMath.offset(p.getLocation(), _mid) <= 21)
pls.add(p);
}
return pls.size();
}
public boolean isUsed()
{
return _isUsed;
}
public void setIsUsed(boolean isUsed)
{
_isUsed = isUsed;
}
public boolean isClosedDoor()
{
return _closedDoor;
}
public void setClosedDoor(boolean closedDoor)
{
_closedDoor = closedDoor;
}
}

View File

@ -1,5 +1,10 @@
package nautilus.game.arcade.game.games.gladiators;
import java.util.ArrayList;
import org.bukkit.Location;
import mineplex.core.common.util.UtilAlg;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.SoloGame;
@ -12,6 +17,10 @@ import nautilus.game.arcade.kit.Kit;
*/
public class Gladiators extends SoloGame
{
private ArrayList<Arena> _allArenas;
private ArrayList<Arena> _gameArenaSet;
public Gladiators(ArcadeManager manager)
{
super(manager, GameType.Gladiators,
@ -25,4 +34,98 @@ public class Gladiators extends SoloGame
setKits(new Kit[]{new KitGladiator(manager)});
}
@Override
public void ParseData()
{
parseArenas();
}
private void parseArenas()
{
_allArenas = new ArrayList<>();
for (Location mid : WorldData.GetDataLocs("RED"))
_allArenas.add(new Arena(this, mid, ArenaType.RED));
for (Location mid : WorldData.GetDataLocs("ORANGE"))
_allArenas.add(new Arena(this, mid, ArenaType.ORANGE));
for (Location mid : WorldData.GetDataLocs("YELLOW"))
_allArenas.add(new Arena(this, mid, ArenaType.YELLOW));
for (Location mid : WorldData.GetDataLocs("GREEN"))
_allArenas.add(new Arena(this, mid, ArenaType.GREEN));
for (Arena a : _allArenas)
{
if (a.getColour().equals(ArenaType.GREEN))
continue;
// Set the children of that arena.
ArrayList<Location> possible = (ArrayList<Location>) getAllArenaMidsOfType(getPreviousColour(a.getColour())).clone();
a.setChild(0, getArenaByMid(UtilAlg.findClosest(a.getMid(), possible)));
possible.remove(a.getChildAt(0).getMid());
a.setChild(1, getArenaByMid(UtilAlg.findClosest(a.getMid(), possible)));
}
}
private void findGameArenaSet()
{
_gameArenaSet = new ArrayList<>();
}
public Arena getArenaByMid(Location mid)
{
for (Arena a : _allArenas)
if (a.getMid().equals(mid))
return a;
return null;
}
public ArrayList<Location> getAllArenaMidsOfType(ArenaType type)
{
ArrayList<Location> mids = new ArrayList<>();
for (Arena a : _allArenas)
if (a.getColour().equals(type))
mids.add(a.getMid());
return mids;
}
public ArrayList<Location> getAllArenaMids()
{
ArrayList<Location> mids = new ArrayList<>();
for (Arena a : _allArenas)
mids.add(a.getMid());
return mids;
}
public ArenaType getNextColour(ArenaType old)
{
switch (old)
{
case GREEN: return ArenaType.YELLOW;
case YELLOW: return ArenaType.ORANGE;
case ORANGE: return ArenaType.RED;
}
return null;
}
public ArenaType getPreviousColour(ArenaType old)
{
switch (old)
{
case RED: return ArenaType.ORANGE;
case ORANGE: return ArenaType.YELLOW;
case YELLOW: return ArenaType.GREEN;
}
return null;
}
}