Progress
This commit is contained in:
parent
cdc602a435
commit
2b12016e14
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
@ -26,7 +27,6 @@ public class Arena
|
||||
private boolean _isUsed;
|
||||
|
||||
private ArrayList<Location> _doorBlocks;
|
||||
private boolean _closedDoor;
|
||||
|
||||
public Arena(Gladiators host, Location mid, ArenaType colour)
|
||||
{
|
||||
@ -37,7 +37,6 @@ public class Arena
|
||||
_parent = null;
|
||||
_isUsed = false;
|
||||
_doorBlocks = new ArrayList<>();
|
||||
_closedDoor = false;
|
||||
|
||||
setupSpawns();
|
||||
}
|
||||
@ -211,13 +210,9 @@ public class Arena
|
||||
_isUsed = isUsed;
|
||||
}
|
||||
|
||||
public boolean isClosedDoor()
|
||||
public void closeDoor()
|
||||
{
|
||||
return _closedDoor;
|
||||
}
|
||||
|
||||
public void setClosedDoor(boolean closedDoor)
|
||||
{
|
||||
_closedDoor = closedDoor;
|
||||
for (Location loc : _doorBlocks)
|
||||
loc.getBlock().setType(Material.OBSIDIAN);
|
||||
}
|
||||
}
|
@ -1,13 +1,23 @@
|
||||
package nautilus.game.arcade.game.games.gladiators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.SoloGame;
|
||||
import nautilus.game.arcade.game.games.gladiators.events.PlayerChangeArenaEvent;
|
||||
import nautilus.game.arcade.game.games.gladiators.kits.KitGladiator;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
|
||||
@ -21,24 +31,54 @@ public class Gladiators extends SoloGame
|
||||
private ArrayList<Arena> _allArenas;
|
||||
private ArrayList<Arena> _gameArenaSet;
|
||||
|
||||
private HashMap<Player, Arena> _playerArenas;
|
||||
|
||||
public Gladiators(ArcadeManager manager)
|
||||
{
|
||||
super(manager, GameType.Gladiators,
|
||||
new Kit[0],
|
||||
new String[]
|
||||
{
|
||||
"This is a 1v1 tournament!",
|
||||
"Kill and then run to the next arena!",
|
||||
"There is only one victor!"
|
||||
});
|
||||
{
|
||||
"This is a 1v1 tournament!",
|
||||
"Kill and then run to the next arena!",
|
||||
"There is only one victor!"
|
||||
});
|
||||
|
||||
Damage = true;
|
||||
DamageFall = false;
|
||||
DamagePvP = true;
|
||||
DamageSelf = true;
|
||||
DamageTeamSelf = true;
|
||||
HungerSet = 20;
|
||||
|
||||
setKits(new Kit[]{new KitGladiator(manager)});
|
||||
|
||||
_playerArenas = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseData()
|
||||
{
|
||||
parseArenas();
|
||||
parseDoors();
|
||||
}
|
||||
|
||||
private void parseDoors()
|
||||
{
|
||||
for (Location loc : WorldData.GetCustomLocs("129"))
|
||||
{
|
||||
ArrayList<Location> mids = new ArrayList<>(getAllArenaMids());
|
||||
Arena arena1 = getArenaByMid(UtilAlg.findClosest(loc, mids));
|
||||
mids.remove(UtilAlg.findClosest(loc, mids));
|
||||
Arena arena2 = getArenaByMid(UtilAlg.findClosest(loc, mids));
|
||||
|
||||
if (arena1.getColour().furtherOut(arena2.getColour()))
|
||||
arena1.getDoorBlocks().add(loc);
|
||||
else
|
||||
arena2.getDoorBlocks().add(loc);
|
||||
|
||||
loc.getBlock().setType(Material.FENCE);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseArenas()
|
||||
@ -73,6 +113,107 @@ public class Gladiators extends SoloGame
|
||||
private void findGameArenaSet()
|
||||
{
|
||||
_gameArenaSet = new ArrayList<>();
|
||||
|
||||
GetTeamList().get(0).GetSpawns().clear(); // Clear the original game spawns.
|
||||
|
||||
int neededSpawns = Math.min(GetPlayers(true).size(), 16); // Quick fix
|
||||
Arena masterNode = getArenasOfType(ArenaType.RED).get(0);
|
||||
|
||||
HashMap<Arena, Integer> spawnsPerRoom = new HashMap<>();
|
||||
|
||||
Queue<Arena> queue = new LinkedList<>();
|
||||
Queue<Arena> nextQueue = new LinkedList<>();
|
||||
queue.add(masterNode);
|
||||
|
||||
int sum;
|
||||
boolean solved = false;
|
||||
|
||||
while (!queue.isEmpty() && !solved)
|
||||
{
|
||||
sum = 0;
|
||||
ArrayList<Arena> currentNodes = new ArrayList<>();
|
||||
while (!queue.isEmpty())
|
||||
{
|
||||
currentNodes.add(queue.poll());
|
||||
}
|
||||
|
||||
for (Arena node : currentNodes)
|
||||
{
|
||||
sum += node.getCapacity();
|
||||
node.setIsUsed(true);
|
||||
}
|
||||
|
||||
if (sum >= neededSpawns)
|
||||
{
|
||||
solved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Arena node : currentNodes)
|
||||
{
|
||||
for(int i = 0; i < node.getChilds().length; i++)
|
||||
{
|
||||
System.out.println("Adding child of node: " + node.getColour() + "number of childs: " + node.getChilds().length);
|
||||
nextQueue.add(node.getChildAt(i));
|
||||
queue.add(node.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
while (!nextQueue.isEmpty())
|
||||
{
|
||||
Arena node = nextQueue.poll();
|
||||
node.setIsUsed(true);
|
||||
|
||||
System.out.println("Node: " + node.getColour());
|
||||
sum = sum + node.getCapacity() - 1;
|
||||
|
||||
/*
|
||||
if (node.getParent().areChildrenUsed())
|
||||
{
|
||||
node.getParent().setIsUsed(false);
|
||||
}
|
||||
*/
|
||||
|
||||
if (sum >= neededSpawns)
|
||||
{
|
||||
solved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (solved)
|
||||
{
|
||||
masterNode.getUsageMap(spawnsPerRoom);
|
||||
System.out.println("Solution: ");
|
||||
|
||||
for (Map.Entry<Arena, Integer> entry : spawnsPerRoom.entrySet())
|
||||
{
|
||||
System.out.println("Color: " + entry.getKey().getColour() + ", Spawns: " + entry.getValue());
|
||||
_gameArenaSet.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Arena a : _gameArenaSet)
|
||||
{
|
||||
if (a.getCapacity() <= 0)
|
||||
continue;
|
||||
|
||||
for (Location l : a.capacitySpawns())
|
||||
GetTeamList().get(0).GetSpawns().add(l);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Arena> getArenasOfType(ArenaType type)
|
||||
{
|
||||
ArrayList<Arena> arenas = new ArrayList<>();
|
||||
|
||||
for (Arena a : _allArenas)
|
||||
if (a.getColour().equals(type))
|
||||
arenas.add(a);
|
||||
|
||||
return arenas;
|
||||
}
|
||||
|
||||
public Arena getArenaByMid(Location mid)
|
||||
@ -128,4 +269,61 @@ public class Gladiators extends SoloGame
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void setups(GameStateChangeEvent e)
|
||||
{
|
||||
if (e.GetState().equals(GameState.Live))
|
||||
{
|
||||
for (Player p : GetPlayers(true))
|
||||
{
|
||||
for (Arena a : _allArenas)
|
||||
{
|
||||
if (a.getPlayers().contains(p))
|
||||
_playerArenas.put(p, a);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.GetState() != GameState.Prepare)
|
||||
return;
|
||||
|
||||
findGameArenaSet();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void arenaMoveCheck(PlayerMoveEvent e){
|
||||
if (!GetPlayers(true).contains(e.getPlayer()))
|
||||
return;
|
||||
|
||||
if (!_playerArenas.containsKey(e.getPlayer()))
|
||||
return;
|
||||
|
||||
for (Arena a : _allArenas)
|
||||
{
|
||||
if (a.getPlayers().contains(e.getPlayer()))
|
||||
{
|
||||
if (_playerArenas.get(e.getPlayer()) != a)
|
||||
{
|
||||
Manager.getPluginManager().callEvent(new PlayerChangeArenaEvent(e.getPlayer(),
|
||||
a, _playerArenas.get(e.getPlayer())));
|
||||
|
||||
_playerArenas.put(e.getPlayer(), a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void arenaChange(PlayerChangeArenaEvent e)
|
||||
{
|
||||
Player p = e.getPlayer();
|
||||
Arena old = e.getFrom();
|
||||
Arena current = e.getTo();
|
||||
|
||||
old.closeDoor();
|
||||
|
||||
p.sendMessage("§7§lDEBUG: §3You left §b" + old.getColour().toString() + " §3and entered §b" + current.getColour().toString() + "§3.");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package nautilus.game.arcade.game.games.gladiators.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import nautilus.game.arcade.game.games.gladiators.Arena;
|
||||
|
||||
/**
|
||||
* Created by William (WilliamTiger).
|
||||
* 08/12/15
|
||||
*/
|
||||
public class PlayerChangeArenaEvent extends Event
|
||||
{
|
||||
private static final HandlerList _handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private Arena to;
|
||||
private Arena from;
|
||||
|
||||
public PlayerChangeArenaEvent(Player player, Arena to, Arena from)
|
||||
{
|
||||
this.player = player;
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
public Arena getTo()
|
||||
{
|
||||
return to;
|
||||
}
|
||||
|
||||
public Arena getFrom()
|
||||
{
|
||||
return from;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return _handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return getHandlerList();
|
||||
}
|
||||
}
|
@ -87,7 +87,11 @@ public class PerkCowAngryHerd extends SmashPerk
|
||||
loc.add(UtilAlg.getLeft(dir).multiply(i*1.5));
|
||||
|
||||
Manager.GetGame().CreatureAllowOverride = true;
|
||||
Cow cow = player.getWorld().spawn(loc, isSuperActive(player) ? MushroomCow.class : Cow.class);
|
||||
Cow cow;
|
||||
if (isSuperActive(player))
|
||||
cow = player.getWorld().spawn(loc, MushroomCow.class);
|
||||
else
|
||||
cow = player.getWorld().spawn(loc, Cow.class);
|
||||
Manager.GetGame().CreatureAllowOverride = false;
|
||||
|
||||
_active.add(new DataCowCharge(player, cow));
|
||||
|
Loading…
Reference in New Issue
Block a user