Multiplayer: initial PowerUps support
parent
aa6a37f80e
commit
e248088006
|
@ -102,6 +102,11 @@ public class AMazeIng extends Game {
|
|||
new PowerUps();
|
||||
}
|
||||
|
||||
public void requestChangeToMap(int[][] todraw) {
|
||||
if(server.isRunning()) server.gameManager.requestChangeToMap(todraw);
|
||||
else if(!client.isRunning()) server.gameManager.requestChangeToMap(todraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
|
|
|
@ -43,9 +43,10 @@ public class GameManager {
|
|||
|
||||
public ArrayList<MazePlayer> players = new ArrayList<MazePlayer>();
|
||||
public ArrayList<PowerUp> powerups = new ArrayList<PowerUp>();
|
||||
ArrayList<MazePlayer> toDelete = new ArrayList<MazePlayer>();
|
||||
protected ArrayList<MazePlayer> toDeletePlayer = new ArrayList<MazePlayer>();
|
||||
protected ArrayList<PowerUp> toDeletePowerUps = new ArrayList<PowerUp>();
|
||||
|
||||
PowerUp pup;
|
||||
protected PowerUp pup;
|
||||
|
||||
TextButton pauseBtn;
|
||||
Dialog pauseDlg;
|
||||
|
@ -75,18 +76,18 @@ public class GameManager {
|
|||
if (pl != null) {
|
||||
for (MazePlayer p : players)
|
||||
if (!pl.contains(p))
|
||||
toDelete.add(p);
|
||||
toDeletePlayer.add(p);
|
||||
|
||||
// Check if new players have to be added
|
||||
for (MazePlayer p : pl)
|
||||
if (!players.contains(p))
|
||||
players.add(p);
|
||||
|
||||
for (MazePlayer p : toDelete) {
|
||||
for (MazePlayer p : toDeletePlayer) {
|
||||
p.dispose();
|
||||
players.remove(p);
|
||||
}
|
||||
toDelete.clear();
|
||||
toDeletePlayer.clear();
|
||||
}
|
||||
} else {
|
||||
for (MazePlayer p : players)
|
||||
|
@ -165,12 +166,12 @@ public class GameManager {
|
|||
stage.addActor(pauseBtn);
|
||||
}
|
||||
|
||||
|
||||
float cw, ch, d, labScale, buttonDim;
|
||||
|
||||
public void hudUpdate() {
|
||||
resetCamera();
|
||||
setCamera(new Vector3((MazeSettings.MAZEX + 1) / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.48f,
|
||||
MazeSettings.MAZEZ / 2 - 1), new Vector3(0, -90, 0));
|
||||
MazeSettings.MAZEZ / 2 - 1.75f), new Vector3(0, -90, 0));
|
||||
|
||||
cw = Gdx.graphics.getWidth();
|
||||
ch = Gdx.graphics.getHeight();
|
||||
|
@ -179,13 +180,13 @@ public class GameManager {
|
|||
buttonDim = d * 0.04f;
|
||||
pauseBtn.setSize(buttonDim, buttonDim);
|
||||
pauseBtn.setPosition((cw - pauseBtn.getWidth()) / 2, ch - pauseBtn.getHeight());
|
||||
pauseBtn.getLabel().setFontScale(labScale*0.9f);
|
||||
pauseBtn.getLabel().setFontScale(labScale * 0.9f);
|
||||
|
||||
pauseDlg.setSize(cw*0.2f, ch*0.15f);
|
||||
pauseDlg.setPosition((cw-pauseDlg.getWidth())/2, (ch-pauseDlg.getHeight())/2);
|
||||
pauseDlgResumeBtn.getLabel().setFontScale(labScale*0.9f);
|
||||
pauseDlgQuitBtn.getLabel().setFontScale(labScale*0.9f);
|
||||
pauseDlgText.setFontScale(labScale*0.9f);
|
||||
pauseDlg.setSize(cw * 0.2f, ch * 0.15f);
|
||||
pauseDlg.setPosition((cw - pauseDlg.getWidth()) / 2, (ch - pauseDlg.getHeight()) / 2);
|
||||
pauseDlgResumeBtn.getLabel().setFontScale(labScale * 0.9f);
|
||||
pauseDlgQuitBtn.getLabel().setFontScale(labScale * 0.9f);
|
||||
pauseDlgText.setFontScale(labScale * 0.9f);
|
||||
|
||||
stage.act();
|
||||
stage.draw();
|
||||
|
@ -210,6 +211,13 @@ public class GameManager {
|
|||
updatePlayer(p);
|
||||
}
|
||||
|
||||
public void updatePowerUps() {
|
||||
for (PowerUp p : toDeletePowerUps) {
|
||||
powerups.remove(p);
|
||||
}
|
||||
toDeletePowerUps.clear();
|
||||
}
|
||||
|
||||
public void renderPlayer(MazePlayer p) {
|
||||
if (getShowGame())
|
||||
p.render(main.world.modelBatch, main.world.environment);
|
||||
|
@ -224,24 +232,36 @@ public class GameManager {
|
|||
}
|
||||
|
||||
public void assignPowerUps() {
|
||||
if (players != null && !players.isEmpty())
|
||||
for (MazePlayer p : players)
|
||||
assignPowerUp(p);
|
||||
}
|
||||
|
||||
public PowerUp assignPowerUp(MazePlayer p) {
|
||||
PowerUp pup = null;
|
||||
for (PowerUp p1 : powerups) {
|
||||
if (checkPowerUp(p, p1)) {
|
||||
pup = p1;
|
||||
p.currentPowerUp = pup;
|
||||
break;
|
||||
if (players != null && !players.isEmpty()) {
|
||||
for (MazePlayer p : players) {
|
||||
for (PowerUp p1 : powerups) {
|
||||
if (checkPowerUp(p, p1)) {
|
||||
assignPowerUp(p, p1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pup != null)
|
||||
powerups.remove(pup);
|
||||
}
|
||||
|
||||
return pup;
|
||||
public void revokePowerUp(MazePlayer p) {
|
||||
p.disablePowerUp();
|
||||
}
|
||||
|
||||
public void assignPowerUp(MazePlayer p, PowerUp p1, boolean immediateUse) {
|
||||
if (p.currentPowerUp == null) {
|
||||
toDeletePowerUps.add(p1);
|
||||
p.currentPowerUp = p1;
|
||||
if (immediateUse)
|
||||
p.usePowerUp();
|
||||
}
|
||||
}
|
||||
|
||||
public void assignPowerUp(MazePlayer p, PowerUp p1) {
|
||||
this.assignPowerUp(p, p1, false);
|
||||
}
|
||||
|
||||
public void usePowerUp(MazePlayer p) {
|
||||
p.usePowerUp();
|
||||
}
|
||||
|
||||
public void checkWin() {
|
||||
|
@ -290,6 +310,7 @@ public class GameManager {
|
|||
public void inGameUpdate() {
|
||||
if (players != null) {
|
||||
updatePlayers();
|
||||
updatePowerUps();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -306,12 +327,20 @@ public class GameManager {
|
|||
}
|
||||
|
||||
public void spawnPowerUps() {
|
||||
for (int i = 0; i < MazeSettings.START_POWERUPS; i++) {
|
||||
int x = 1, z = 1;
|
||||
do {
|
||||
x = (Math.abs(rand.nextInt() - 1) % (mazeGen.w));
|
||||
z = (Math.abs(rand.nextInt() - 1) % (mazeGen.h));
|
||||
} while (thereIsPlayerInPos(x, z) || mazeGen.occupiedSpot(x, z));
|
||||
for (int i = 0; i < MazeSettings.START_POWERUPS; i++)
|
||||
spawnRandomPowerUp();
|
||||
}
|
||||
|
||||
public void spawnRandomPowerUp() {
|
||||
int x = 1, z = 1, tries = 0;
|
||||
int maxtries = MazeSettings.MAZEX * MazeSettings.MAZEZ + 2;
|
||||
do {
|
||||
x = (Math.abs(rand.nextInt() - 1) % (mazeGen.w));
|
||||
z = (Math.abs(rand.nextInt() - 1) % (mazeGen.h));
|
||||
tries++;
|
||||
} while ((thereIsPlayerInPos(x, z) || mazeGen.occupiedSpot(x, z) || thereIsPowerUpInPos(x, z))
|
||||
&& tries < maxtries);
|
||||
if (tries < maxtries) {
|
||||
System.out.println("Spawning power-up in " + x + ", " + z);
|
||||
spawnPowerUp(x + .5f, z + .5f);
|
||||
}
|
||||
|
@ -323,16 +352,22 @@ public class GameManager {
|
|||
powerups.add(p);
|
||||
}
|
||||
|
||||
public void spawnPowerUpByName(String name, float x, float z) {
|
||||
PowerUp p = PowerUps.pickByName(name);
|
||||
p.setPosition(x, 1.25f, z);
|
||||
powerups.add(p);
|
||||
}
|
||||
|
||||
public void clearPowerUps() {
|
||||
for (PowerUp p : powerups)
|
||||
if (p != null)
|
||||
p.dispose();
|
||||
powerups.clear();
|
||||
toDeletePowerUps.clear();
|
||||
}
|
||||
|
||||
public void removePowerUp(PowerUp p) {
|
||||
if (p != null)
|
||||
powerups.remove(p);
|
||||
toDeletePowerUps.add(p);
|
||||
}
|
||||
|
||||
public String getPowerUpNameByPos(int x, int z) {
|
||||
|
@ -404,7 +439,8 @@ public class GameManager {
|
|||
}
|
||||
|
||||
public void requestChangeToMap(int[][] todraw) {
|
||||
mazeGen.show(todraw);
|
||||
if (gameStarted)
|
||||
mazeGen.show(todraw);
|
||||
}
|
||||
|
||||
public void resetCamera() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.emamaker.amazeing.AMazeIng;
|
|||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.emamaker.amazeing.ui.screens.PreGameScreen;
|
||||
|
||||
public class GameManagerClient extends GameManager {
|
||||
|
@ -55,14 +56,29 @@ public class GameManagerClient extends GameManager {
|
|||
}
|
||||
}
|
||||
|
||||
// Protecting against myself since this feature doesn't exist yet
|
||||
@Override
|
||||
public void usePowerUp(MazePlayer p) {
|
||||
// System.out.println("using powerup for " + p + " " + p.currentPowerUp);
|
||||
main.client.requestUsePowerUp(p);
|
||||
}
|
||||
|
||||
// These features don't exist in clients
|
||||
@Override
|
||||
public void assignPowerUps() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkWin() {
|
||||
public void assignPowerUp(MazePlayer p, PowerUp p1) {
|
||||
}
|
||||
@Override
|
||||
public void assignPowerUp(MazePlayer p, PowerUp p1, boolean b) {
|
||||
}
|
||||
@Override
|
||||
public void requestChangeToMap(int[][] todraw) {
|
||||
}
|
||||
@Override
|
||||
public void revokePowerUp(MazePlayer p) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void quitGameByBtn() {
|
||||
|
@ -73,4 +89,3 @@ public class GameManagerClient extends GameManager {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,13 @@ import java.util.Set;
|
|||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
|
||||
public class GameManagerLocal extends GameManager {
|
||||
|
||||
long lastPowerUpTime = 0;
|
||||
|
||||
public GameManagerLocal() {
|
||||
super(AMazeIng.getMain(), GameType.LOCAL);
|
||||
setupHud();
|
||||
|
@ -33,6 +36,12 @@ public class GameManagerLocal extends GameManager {
|
|||
@Override
|
||||
public void inGameUpdate() {
|
||||
super.inGameUpdate();
|
||||
|
||||
if(System.currentTimeMillis() - lastPowerUpTime > MazeSettings.POWERUP_SPAWN_FREQUENCY) {
|
||||
lastPowerUpTime = System.currentTimeMillis();
|
||||
spawnRandomPowerUp();
|
||||
}
|
||||
|
||||
assignPowerUps();
|
||||
|
||||
renderWorld();
|
||||
|
|
|
@ -5,10 +5,14 @@ import java.util.Set;
|
|||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
import com.emamaker.amazeing.manager.GameType;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
|
||||
public class GameManagerServer extends GameManager {
|
||||
|
||||
long lastPowerUpTime = 0;
|
||||
|
||||
public GameManagerServer() {
|
||||
super(AMazeIng.getMain(), GameType.SERVER);
|
||||
}
|
||||
|
@ -24,22 +28,32 @@ public class GameManagerServer extends GameManager {
|
|||
|
||||
if (todraw != null)
|
||||
mazeGen.show(todraw);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inGameUpdate() {
|
||||
super.inGameUpdate();
|
||||
|
||||
if(System.currentTimeMillis() - lastPowerUpTime > MazeSettings.POWERUP_SPAWN_FREQUENCY) {
|
||||
lastPowerUpTime = System.currentTimeMillis();
|
||||
spawnRandomPowerUp();
|
||||
}
|
||||
|
||||
assignPowerUps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignPowerUps() {
|
||||
// if (players != null && !players.isEmpty())
|
||||
// for (MazePlayer p : players) {
|
||||
// main.server.removePowerUp(assignPowerUp(p));
|
||||
// }
|
||||
public void assignPowerUp(MazePlayer p, PowerUp p1, boolean immediateUse) {
|
||||
if (p.currentPowerUp == null) {
|
||||
toDeletePowerUps.add(p1);
|
||||
p.currentPowerUp = p1;
|
||||
main.server.assignPowerUpRequest(p, p1, immediateUse);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revokePowerUp(MazePlayer p) {
|
||||
main.server.revokePowerUpRequest(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ import com.emamaker.amazeing.manager.network.action.actions.client.login.NACRemo
|
|||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdateOtherPlayerPos;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdatePlayerPosForced;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.player.NACUpdatePlayersPos;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.powerup.NACPowerUpAssignRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.powerup.NACPowerUpRevokeRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.powerup.NACPowerUpUseRequest;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.client.powerup.NACUpdatePowerUps;
|
||||
import com.emamaker.amazeing.maze.settings.MazeSettings;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.MazePlayerLocal;
|
||||
|
@ -69,9 +73,13 @@ public class GameClient extends NetworkHandler {
|
|||
actions.add(new NACRemovePlayer(this));
|
||||
actions.add(new NACGameStatusUpdate(this));
|
||||
actions.add(new NACUpdateMap(this));
|
||||
actions.add(new NACUpdatePowerUps(this));
|
||||
actions.add(new NACUpdatePlayerPosForced(this));
|
||||
actions.add(new NACUpdatePlayersPos(this));
|
||||
actions.add(new NACUpdateOtherPlayerPos(this));
|
||||
actions.add(new NACPowerUpRevokeRequestOk(this));
|
||||
actions.add(new NACPowerUpAssignRequestOk(this));
|
||||
actions.add(new NACPowerUpUseRequest(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,12 +92,13 @@ public class GameClient extends NetworkHandler {
|
|||
super.update();
|
||||
|
||||
if (isRunning()) {
|
||||
//Check if the server disconnected or it's timing out
|
||||
if(!client.isConnected() || ((NACGameStatusUpdate.gotMessage && System.currentTimeMillis() - NACGameStatusUpdate.lastMsgTime > Constants.COMMUNICATION_TIMEOUT_MILLIS))) {
|
||||
// Check if the server disconnected or it's timing out
|
||||
if (!client.isConnected() || ((NACGameStatusUpdate.gotMessage && System.currentTimeMillis()
|
||||
- NACGameStatusUpdate.lastMsgTime > Constants.COMMUNICATION_TIMEOUT_MILLIS))) {
|
||||
stop(true);
|
||||
main.uiManager.srvJoinScreen.showErrorDlg(1);
|
||||
}
|
||||
//Normal client update
|
||||
// Normal client update
|
||||
if (gameManager != null) {
|
||||
if (gameManager.gameStarted) {
|
||||
} else {
|
||||
|
@ -126,7 +135,6 @@ public class GameClient extends NetworkHandler {
|
|||
p.dispose();
|
||||
players.clear();
|
||||
|
||||
|
||||
if (!fromserver) {
|
||||
for (NetworkAction n : pendingActions)
|
||||
n.onParentClosing();
|
||||
|
@ -210,4 +218,10 @@ public class GameClient extends NetworkHandler {
|
|||
updateMobilePlayers = true;
|
||||
}
|
||||
|
||||
public void requestUsePowerUp(MazePlayer p) {
|
||||
if (p.currentPowerUp != null)
|
||||
((NACPowerUpUseRequest) getActionByClass(NACPowerUpUseRequest.class)).startAction(null, null, p.uuid,
|
||||
p.currentPowerUp.name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,12 @@ import com.emamaker.amazeing.manager.network.action.actions.server.login.NASLogi
|
|||
import com.emamaker.amazeing.manager.network.action.actions.server.login.NASRemovePlayer;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.player.NASUpdatePlayerPos;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.player.NASUpdatePlayerPosForced;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.powerup.NASPowerUpAssignRequest;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.powerup.NASPowerUpRevokeRequest;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.powerup.NASPowerUpUseRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.action.actions.server.powerup.NASUpdatePowerUps;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.emamaker.amazeing.utils.MathUtils.Constants;
|
||||
import com.esotericsoftware.kryonet.Server;
|
||||
|
||||
|
@ -58,13 +63,18 @@ public class GameServer extends NetworkHandler {
|
|||
actions.add(new NASRemovePlayer(this));
|
||||
actions.add(new NASGameStatusUpdate(this));
|
||||
actions.add(new NASUpdateMap(this));
|
||||
actions.add(new NASUpdatePowerUps(this));
|
||||
actions.add(new NASUpdatePlayerPosForced(this));
|
||||
actions.add(new NASUpdatePlayerPos(this));
|
||||
actions.add(new NASUpdatePlayerPos(this));;
|
||||
actions.add(new NASPowerUpAssignRequest(this));
|
||||
actions.add(new NASPowerUpRevokeRequest(this));
|
||||
actions.add(new NASPowerUpUseRequestOk(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDefaultActions() {
|
||||
getActionByClass(NASGameStatusUpdate.class).startAction(null, null);
|
||||
getActionByClass(NASUpdatePowerUps.class).startAction(null, null);
|
||||
// getActionByClass(NAServerUpdatePlayers.class).startAction(null, null);
|
||||
}
|
||||
|
||||
|
@ -72,10 +82,11 @@ public class GameServer extends NetworkHandler {
|
|||
public void update() {
|
||||
super.update();
|
||||
|
||||
if(isRunning()) {
|
||||
//Check if there's some player not responding that needs to be removed
|
||||
for(String s: players.keySet()) {
|
||||
if(System.currentTimeMillis() - players.get(s).LAST_NETWORK_TIME > Constants.COMMUNICATION_TIMEOUT_MILLIS) {
|
||||
if (isRunning()) {
|
||||
// Check if there's some player not responding that needs to be removed
|
||||
for (String s : players.keySet()) {
|
||||
if (System.currentTimeMillis()
|
||||
- players.get(s).LAST_NETWORK_TIME > Constants.COMMUNICATION_TIMEOUT_MILLIS) {
|
||||
players.get(s).dispose();
|
||||
players.remove(s);
|
||||
}
|
||||
|
@ -136,4 +147,13 @@ public class GameServer extends NetworkHandler {
|
|||
positionUpdate.put(uuid, b);
|
||||
}
|
||||
|
||||
public void assignPowerUpRequest(MazePlayer p, PowerUp p1, boolean immediateUse) {
|
||||
((NASPowerUpAssignRequest) getActionByClass(NASPowerUpAssignRequest.class)).startAction(null, null, p.uuid,
|
||||
p1.name, immediateUse);
|
||||
}
|
||||
public void revokePowerUpRequest(MazePlayer p) {
|
||||
System.out.println("Revoking powerup to " + p);
|
||||
((NASPowerUpRevokeRequest) getActionByClass(NASPowerUpRevokeRequest.class)).startAction(null, null, p.uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,18 @@ public class NetworkCommon {
|
|||
kryo.register(RemovePlayer.class);
|
||||
kryo.register(PlayerRemoved.class);
|
||||
|
||||
kryo.register(GameStatusUpdate.class);
|
||||
kryo.register(String[].class);
|
||||
kryo.register(GameStatusUpdate.class);
|
||||
kryo.register(UpdateMap.class);
|
||||
|
||||
kryo.register(PowerUpUpdate.class);
|
||||
kryo.register(PowerUpAssignRequest.class);
|
||||
kryo.register(PowerUpAssignRequestOk.class);
|
||||
kryo.register(PowerUpUseRequest.class);
|
||||
kryo.register(PowerUpUseRequestOk.class);
|
||||
kryo.register(PowerUpRevokeRequest.class);
|
||||
kryo.register(PowerUpRevokeRequestOk.class);
|
||||
|
||||
kryo.register(UpdatePlayerPosition.class);
|
||||
kryo.register(UpdateForcedPlayerPosition.class);
|
||||
kryo.register(UpdateForcedPlayerPositionOk.class);
|
||||
|
@ -27,21 +35,21 @@ public class NetworkCommon {
|
|||
kryo.register(ServerClosed.class);
|
||||
}
|
||||
|
||||
|
||||
/** PLAYER PACKETS **/
|
||||
/*LOGIN*/
|
||||
public static class ClientLoginAO {
|
||||
}
|
||||
|
||||
public static class ServerLoginUUID {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class ClientLoginAO2 {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
public static class ServerLoginAO2 {
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
/*REMOVAL*/
|
||||
public static class RemovePlayer{
|
||||
public String uuid;
|
||||
}
|
||||
|
@ -49,20 +57,7 @@ public class NetworkCommon {
|
|||
public static class PlayerRemoved{
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
//Game Status is used to broadcast to clients infos about the game and players
|
||||
public static class GameStatusUpdate{
|
||||
public boolean gameStarted;
|
||||
public boolean anyoneWon;
|
||||
public String[] playersUUIDs;
|
||||
}
|
||||
|
||||
//Run-lenght encoding of the map
|
||||
public static class UpdateMap{
|
||||
public String map;
|
||||
}
|
||||
|
||||
|
||||
/*PLAYER POSITION UPDATE*/
|
||||
public static class UpdatePlayerPosition{
|
||||
public String uuid;
|
||||
public float px, py, pz;
|
||||
|
@ -77,7 +72,47 @@ public class NetworkCommon {
|
|||
public String uuid;
|
||||
}
|
||||
|
||||
/** SERVER TO CLIENT UPDATES **/
|
||||
//Game Status is used to broadcast to clients infos about the game and players
|
||||
public static class GameStatusUpdate{
|
||||
public boolean gameStarted;
|
||||
public boolean anyoneWon;
|
||||
public String[] playersUUIDs;
|
||||
}
|
||||
|
||||
//Run-lenght encoding of the map
|
||||
public static class UpdateMap{
|
||||
public String map;
|
||||
}
|
||||
|
||||
/** POWER UPS **/
|
||||
public static class PowerUpUpdate {
|
||||
public String[] powerups;
|
||||
}
|
||||
public static class PowerUpAssignRequest{
|
||||
public String uuid, pupname;
|
||||
public boolean immediateUse;
|
||||
}
|
||||
public static class PowerUpAssignRequestOk{
|
||||
public String uuid;
|
||||
}
|
||||
public static class PowerUpUseRequest{
|
||||
public String uuid, pupname;
|
||||
}
|
||||
public static class PowerUpUseRequestOk{
|
||||
public String uuid;
|
||||
public boolean canuse;
|
||||
}
|
||||
public static class PowerUpRevokeRequest{
|
||||
public String uuid;
|
||||
}
|
||||
public static class PowerUpRevokeRequestOk{
|
||||
public String uuid;
|
||||
}
|
||||
|
||||
/** MISC **/
|
||||
public static class ServerClosed{ }
|
||||
|
||||
}
|
||||
|
||||
class ConnectionPlayer extends Connection {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.emamaker.amazeing.manager.network;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.GameManager;
|
||||
|
@ -8,10 +11,6 @@ import com.emamaker.amazeing.manager.network.NetworkCommon.UpdatePlayerPosition;
|
|||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public abstract class NetworkHandler {
|
||||
|
||||
public ConcurrentHashMap<String, MazePlayer> players = new ConcurrentHashMap<String, MazePlayer>();
|
||||
|
|
|
@ -23,9 +23,8 @@ public class NACRemovePlayer extends NetworkAction {
|
|||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another and to remove the alreadyPending
|
||||
* limitation. Here we need to be able to call multiple instances of this at the
|
||||
* same time
|
||||
* passed from one instance to another. This also removes the alreadyPending statement instead of setting
|
||||
* the oneAtTheTie flag.
|
||||
*/
|
||||
public void startAction(String s_) {
|
||||
this.startAction(incomingConnection, incomingMsg, s_);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpAssignRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpAssignRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUps;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACPowerUpAssignRequestOk extends NetworkAction {
|
||||
|
||||
protected NACPowerUpAssignRequestOk(NetworkHandler parent, Connection c, Object incomingMsg_,
|
||||
Object responsePacket_, Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
setOneAtTheTime(false);
|
||||
}
|
||||
|
||||
public NACPowerUpAssignRequestOk(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.PowerUpAssignRequest(), new NetworkCommon.PowerUpAssignRequestOk(), null,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
((PowerUpAssignRequestOk) responsePacket).uuid = ((PowerUpAssignRequest) incomingMsg).uuid;
|
||||
if (parent.players.containsKey(((PowerUpAssignRequest) incomingMsg).uuid)) {
|
||||
parent.players.get(((PowerUpAssignRequest) incomingMsg).uuid).currentPowerUp = PowerUps.pickByName(((PowerUpAssignRequest) incomingMsg).pupname);
|
||||
System.out.println("Assigning powerup to " + ((PowerUpAssignRequest) incomingMsg).uuid);
|
||||
if(((PowerUpAssignRequest) incomingMsg).immediateUse) client().requestUsePowerUp(parent.players.get(((PowerUpAssignRequest) incomingMsg).uuid));
|
||||
}
|
||||
|
||||
|
||||
client().client.sendUDP(responsePacket);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACPowerUpAssignRequestOk(client(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpRevokeRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpRevokeRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACPowerUpRevokeRequestOk extends NetworkAction {
|
||||
|
||||
protected NACPowerUpRevokeRequestOk(NetworkHandler parent, Connection c, Object incomingMsg_,
|
||||
Object responsePacket_, Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
setOneAtTheTime(false);
|
||||
}
|
||||
|
||||
public NACPowerUpRevokeRequestOk(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.PowerUpRevokeRequest(), new NetworkCommon.PowerUpRevokeRequestOk(), null,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
((PowerUpRevokeRequestOk) responsePacket).uuid = ((PowerUpRevokeRequest) incomingMsg).uuid;
|
||||
if (parent.players.containsKey(((PowerUpRevokeRequest) incomingMsg).uuid)) {
|
||||
parent.players.get(((PowerUpRevokeRequest) incomingMsg).uuid).disablePowerUp();
|
||||
System.out.println("client: Revoked powerup for "
|
||||
+ parent.players.get(((PowerUpRevokeRequest) incomingMsg).uuid).uuid);
|
||||
}
|
||||
client().client.sendUDP(responsePacket);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACPowerUpRevokeRequestOk(client(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUseRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUseRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACPowerUpUseRequest extends NetworkAction {
|
||||
|
||||
String uuid, pupname;
|
||||
|
||||
protected NACPowerUpUseRequest(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime, String uuid_, String pupname_) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
this.uuid = uuid_;
|
||||
this.pupname = pupname_;
|
||||
}
|
||||
|
||||
public NACPowerUpUseRequest(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.PowerUpUseRequest(), new NetworkCommon.PowerUpUseRequestOk(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another. This also removes the alreadyPending statement instead of setting
|
||||
* the oneAtTheTie flag.
|
||||
*/
|
||||
public void startAction(String u_, String p_) {
|
||||
this.startAction(incomingConnection, incomingMsg, u_, p_);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg, String uuid_, String pupname_) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
this.uuid = uuid_;
|
||||
this.pupname = pupname_;
|
||||
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
((PowerUpUseRequest) responsePacket).uuid = uuid;
|
||||
((PowerUpUseRequest) responsePacket).pupname = pupname;
|
||||
client().client.sendUDP(responsePacket);
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to override the responseReceived package, because this action
|
||||
* has to finish only if the correct uuid has been received
|
||||
*/
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
if ( endMsg == null || ((PowerUpUseRequestOk) endMsg).uuid.equals(uuid)) {
|
||||
if (endMsg != null && ((PowerUpUseRequestOk) endMsg).canuse) {
|
||||
parent.players.get(uuid).usePowerUp();
|
||||
System.out.println("using powerup " + pupname + " on " + uuid);
|
||||
}
|
||||
detachFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACPowerUpUseRequest(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime, uuid, pupname);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.client.powerup;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUpdate;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NACUpdatePowerUps extends NetworkAction {
|
||||
|
||||
String[] a;
|
||||
String name;
|
||||
float x, y, z;
|
||||
boolean found = true;
|
||||
|
||||
static String[] oldList = new String[0];
|
||||
|
||||
protected NACUpdatePowerUps(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
}
|
||||
|
||||
public NACUpdatePowerUps(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.PowerUpUpdate(), null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
// This part works exactly the same way as remote player adding and removal
|
||||
// works
|
||||
|
||||
if (!Arrays.equals(((PowerUpUpdate) incomingMsg).powerups, oldList)) {
|
||||
|
||||
//now check if the currently used powerups are in the list received from the server, if not they have to be removed because they are not present anymore in the game
|
||||
for(PowerUp p : client().gameManager.powerups) {
|
||||
found = false;
|
||||
|
||||
//This could result quite computationally expensive and could be optimized in some way, but now we just need the thing working
|
||||
for (String s : ((PowerUpUpdate) incomingMsg).powerups) {
|
||||
a = s.split("-");
|
||||
name = a[0];
|
||||
x = Float.valueOf(a[1]);
|
||||
y = Float.valueOf(a[2]);
|
||||
z = Float.valueOf(a[3]);
|
||||
|
||||
found = p.getPosition().x == x && p.getPosition().z == z && p.name.equals(name);
|
||||
if(found) break;
|
||||
}
|
||||
if(!found) client().gameManager.removePowerUp(p);
|
||||
}
|
||||
|
||||
//check if there are new powerups to be added
|
||||
for (String s : ((PowerUpUpdate) incomingMsg).powerups) {
|
||||
a = s.split("-");
|
||||
name = a[0];
|
||||
x = Float.valueOf(a[1]);
|
||||
y = Float.valueOf(a[2]);
|
||||
z = Float.valueOf(a[3]);
|
||||
if (!client().gameManager.thereIsPowerUpInPos((int) x, (int) z)) {
|
||||
client().gameManager.spawnPowerUpByName(name, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
oldList = ((PowerUpUpdate) incomingMsg).powerups;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NACUpdatePowerUps(client(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@ import com.esotericsoftware.kryonet.Connection;
|
|||
|
||||
public class NASUpdateMap extends NetworkAction {
|
||||
|
||||
static String map = "", oldMap = "";
|
||||
|
||||
protected NASUpdateMap(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
|
@ -20,8 +22,12 @@ public class NASUpdateMap extends NetworkAction {
|
|||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
((UpdateMap) responsePacket).map = server().gameManager.mazeGen.runLenghtEncode();
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
map = server().gameManager.mazeGen.runLenghtEncode();
|
||||
if (!map.equals(oldMap)) {
|
||||
((UpdateMap)responsePacket).map = map;
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
oldMap = map;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpAssignRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpAssignRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASPowerUpAssignRequest extends NetworkAction {
|
||||
|
||||
String uuid, pupname;
|
||||
boolean immediateUse;
|
||||
|
||||
protected NASPowerUpAssignRequest(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime, String uuid_, String pupname_, boolean immediateUse_) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
this.uuid = uuid_;
|
||||
this.pupname = pupname_;
|
||||
this.immediateUse = immediateUse_;
|
||||
}
|
||||
|
||||
public NASPowerUpAssignRequest(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.PowerUpAssignRequest(), new NetworkCommon.PowerUpAssignRequestOk(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another. This also removes the alreadyPending
|
||||
* statement instead of setting the oneAtTheTie flag.
|
||||
*/
|
||||
public void startAction(String u_, String p_, boolean immediateUse_) {
|
||||
this.startAction(incomingConnection, incomingMsg, u_, p_, immediateUse_);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg, String uuid_, String pupname_, boolean immediateUse_) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
this.uuid = uuid_;
|
||||
this.pupname = pupname_;
|
||||
this.immediateUse = immediateUse_;
|
||||
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
((PowerUpAssignRequest) responsePacket).uuid = uuid;
|
||||
((PowerUpAssignRequest) responsePacket).pupname = pupname;
|
||||
((PowerUpAssignRequest) responsePacket).immediateUse = immediateUse;
|
||||
System.out.println("requesting to assign powerup " + pupname + " to " + uuid);
|
||||
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to override the responseReceived package, because this action
|
||||
* has to finish only if the correct uuid has been received
|
||||
*/
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
if (endMsg == null || ((PowerUpAssignRequestOk) endMsg).uuid.equals(uuid))
|
||||
detachFromParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASPowerUpAssignRequest(server(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime, uuid, pupname, immediateUse);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpRevokeRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpRevokeRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASPowerUpRevokeRequest extends NetworkAction {
|
||||
|
||||
String uuid;
|
||||
|
||||
protected NASPowerUpRevokeRequest(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime, String uuid_) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
this.uuid = uuid_;
|
||||
}
|
||||
|
||||
public NASPowerUpRevokeRequest(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.PowerUpRevokeRequest(), new NetworkCommon.PowerUpRevokeRequestOk(),
|
||||
false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here startAction needs to be overrided to allow for the uuid argument to be
|
||||
* passed from one instance to another. This also removes the alreadyPending
|
||||
* statement instead of setting the oneAtTheTie flag.
|
||||
*/
|
||||
public void startAction(String u_) {
|
||||
this.startAction(incomingConnection, incomingMsg, u_);
|
||||
}
|
||||
|
||||
public void startAction(Connection conn, Object msg, String uuid_) {
|
||||
this.incomingConnection = conn;
|
||||
this.incomingMsg = msg;
|
||||
this.uuid = uuid_;
|
||||
|
||||
parent.addToPending(newInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
((PowerUpRevokeRequest) responsePacket).uuid = uuid;
|
||||
System.out.println("server: Revoking powerup for " + uuid);
|
||||
parent.players.get(uuid).disablePowerUp();
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to override the responseReceived package, because this action
|
||||
* has to finish only if the correct uuid has been received
|
||||
*/
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
this.endConnection = conn;
|
||||
this.endMsg = msg;
|
||||
if (endMsg == null || ((PowerUpRevokeRequestOk) endMsg).uuid.equals(uuid)) {
|
||||
detachFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASPowerUpRevokeRequest(server(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime, uuid);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.powerup;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUseRequest;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUseRequestOk;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASPowerUpUseRequestOk extends NetworkAction {
|
||||
|
||||
protected NASPowerUpUseRequestOk(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
setOneAtTheTime(false);
|
||||
}
|
||||
|
||||
public NASPowerUpUseRequestOk(NetworkHandler parent_) {
|
||||
super(parent_, new NetworkCommon.PowerUpUseRequest(), new NetworkCommon.PowerUpUseRequestOk(), null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
((PowerUpUseRequestOk) responsePacket).uuid = ((PowerUpUseRequest) incomingMsg).uuid;
|
||||
((PowerUpUseRequestOk) responsePacket).canuse = !parent.players
|
||||
.containsKey(((PowerUpUseRequest) incomingMsg).uuid)
|
||||
|| parent.players.get(((PowerUpUseRequest) incomingMsg).uuid).currentPowerUp == null ? false
|
||||
: parent.players.get(((PowerUpUseRequest) incomingMsg).uuid).currentPowerUp.name
|
||||
.equals(((PowerUpUseRequest) incomingMsg).pupname);
|
||||
|
||||
if (((PowerUpUseRequestOk) responsePacket).canuse) {
|
||||
parent.players.get(((PowerUpUseRequest) incomingMsg).uuid).usePowerUp();
|
||||
} else {
|
||||
server().revokePowerUpRequest(parent.players.get(((PowerUpUseRequest) incomingMsg).uuid));
|
||||
}
|
||||
incomingConnection.sendUDP(responsePacket);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASPowerUpUseRequestOk(server(), incomingConnection, incomingMsg, responsePacket, endPacket,
|
||||
oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.emamaker.amazeing.manager.network.action.actions.server.powerup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon;
|
||||
import com.emamaker.amazeing.manager.network.NetworkCommon.PowerUpUpdate;
|
||||
import com.emamaker.amazeing.manager.network.NetworkHandler;
|
||||
import com.emamaker.amazeing.manager.network.action.NetworkAction;
|
||||
import com.emamaker.amazeing.player.powerups.PowerUp;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
public class NASUpdatePowerUps extends NetworkAction {
|
||||
|
||||
ArrayList<String> powerups = new ArrayList<String>();
|
||||
|
||||
protected NASUpdatePowerUps(NetworkHandler parent, Connection c, Object incomingMsg_, Object responsePacket_,
|
||||
Object endPacket_, boolean oneTime) {
|
||||
super(parent, c, incomingMsg_, responsePacket_, endPacket_, oneTime);
|
||||
enableTimeout(false);
|
||||
}
|
||||
|
||||
public NASUpdatePowerUps(NetworkHandler parent_) {
|
||||
super(parent_, null, new NetworkCommon.PowerUpUpdate(), null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAction() {
|
||||
super.resolveAction();
|
||||
|
||||
try {
|
||||
powerups.clear();
|
||||
|
||||
if (server().gameManager.powerups != null && !server().gameManager.powerups.isEmpty()) {
|
||||
for (PowerUp p : server().gameManager.powerups) {
|
||||
powerups.add(p.name + "-" + p.getPosition().x + "-" + p.getPosition().y + "-" + p.getPosition().z);
|
||||
}
|
||||
|
||||
((PowerUpUpdate) responsePacket).powerups = powerups.toArray(new String[powerups.size()]);
|
||||
server().server.sendToAllUDP(responsePacket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseReceived(Connection conn, Object msg) {
|
||||
super.responseReceived(conn, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkAction newInstance() {
|
||||
return new NASUpdatePowerUps(server(), incomingConnection, incomingMsg, responsePacket, endPacket, oneTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -264,6 +264,7 @@ public class MazeGenerator {
|
|||
|
||||
public int[][] changeMap(int[][] tmp, int x, int z, int type) {
|
||||
if (x > 0 && x < w - 1 && z > 0 && z < h - 1 && todraw[x][z] != 2) {
|
||||
System.out.println("changing " + x + ", " + z + " to " + type);
|
||||
tmp[x][z] = type;
|
||||
}
|
||||
return tmp;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.emamaker.amazeing.maze.settings;
|
||||
|
||||
import com.emamaker.amazeing.ui.UIManager;
|
||||
|
||||
public class MazeSettingPowerUpSpawnFreq extends MazeSetting{
|
||||
|
||||
/* Game max. number of players settings*/
|
||||
|
||||
public MazeSettingPowerUpSpawnFreq(String name_, String[] options_, UIManager uiManager_) {
|
||||
super(name_, options_, uiManager_);
|
||||
}
|
||||
public MazeSettingPowerUpSpawnFreq(String name_, String[] options_, int defaultOption, UIManager uiManager_) {
|
||||
super(name_, options_, defaultOption, uiManager_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseOptionString(String opt) {
|
||||
if(opt.equals("Off")) {
|
||||
MazeSettings.POWERUP_SPAWN_FREQUENCY = Integer.MAX_VALUE;
|
||||
}else {
|
||||
MazeSettings.POWERUP_SPAWN_FREQUENCY = Integer.valueOf(opt)*1000;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ public class MazeSettings {
|
|||
public static int MAXPLAYERS_MOBILE = 1;
|
||||
public static int EPDIST = 5;
|
||||
public static int START_POWERUPS = 0;
|
||||
public static int POWERUP_SPAWN_FREQUENCY = 0;
|
||||
|
||||
public static ArrayList<MazeSetting> settings = new ArrayList<MazeSetting>();
|
||||
public static MazeSetting setDim;
|
||||
|
@ -21,6 +22,7 @@ public class MazeSettings {
|
|||
public static MazeSetting setPlayers_Mobile;
|
||||
public static MazeSetting setEpDist;
|
||||
public static MazeSetting setStartPowerups;
|
||||
public static MazeSetting setPowerUpSpawnFreq;
|
||||
|
||||
public static String[] maxPlayersDesktop = new String[] { "2", "4", "6", "8", "10", "15", "20" };
|
||||
public static String[] maxPlayersMobile = new String[] { "1", "2", "3", "4" };
|
||||
|
@ -35,16 +37,20 @@ public class MazeSettings {
|
|||
setPlayers_Mobile = new MazeSettingMaxPlayersMobile("PLAYERS JOINING FROM THIS DEVICE: ", maxPlayersMobile, 0,
|
||||
AMazeIng.getMain().uiManager);
|
||||
|
||||
setStartPowerups = new MazeSettingStartPowerUps("POWERUPS AT START : ",
|
||||
new String[] { "1", "2", "3", "4", "5", "8", "10", "15" }, 3, AMazeIng.getMain().uiManager);
|
||||
setStartPowerups = new MazeSettingStartPowerUps("POWERUPS AT START: ",
|
||||
new String[] { "1", "2", "3", "4", "5", "8", "10", "15" }, 7, AMazeIng.getMain().uiManager);
|
||||
|
||||
setEpDist = new MazeSettingEPDIST("END POINT DISTANCE:", new String[] { "1", "2", "5", "10", "20" }, 2,
|
||||
AMazeIng.getMain().uiManager);
|
||||
|
||||
setPowerUpSpawnFreq = new MazeSettingPowerUpSpawnFreq("POWERUP SPAWN FREQUENCY:",
|
||||
new String[] { "Off", "1", "2", "5", "10", "20", "30" }, 4, AMazeIng.getMain().uiManager);
|
||||
|
||||
settings.add(setDim);
|
||||
settings.add(setPlayers);
|
||||
settings.add(setEpDist);
|
||||
settings.add(setStartPowerups);
|
||||
settings.add(setPowerUpSpawnFreq);
|
||||
}
|
||||
|
||||
public static void saveStates() {
|
||||
|
|
|
@ -159,8 +159,7 @@ public abstract class MazePlayer implements Disposable {
|
|||
|
||||
public void usePowerUp() {
|
||||
if (currentPowerUp != null)
|
||||
if (currentPowerUp.usePowerUp(this))
|
||||
disablePowerUp();
|
||||
currentPowerUp.usePowerUp(this);
|
||||
}
|
||||
|
||||
public void disablePowerUp() {
|
||||
|
|
|
@ -240,7 +240,7 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(kpup))
|
||||
usePowerUp();
|
||||
main.currentGameManager.usePowerUp(this);
|
||||
}
|
||||
|
||||
public void inputTouchscreen() {
|
||||
|
@ -302,6 +302,9 @@ public class MazePlayerLocal extends MazePlayer {
|
|||
@Override
|
||||
public void setTransform(float x, float y, float z, float i, float j, float k, float l) {
|
||||
if (!isDisposed() && initedPhysics) {
|
||||
//Just a little hack to avoid players disappearing in the void due to some strange things happening with physics when updating map and remote players
|
||||
if(y < 1) y = 1.25f;
|
||||
|
||||
characterTransform.set(x, y, z, i, j, k, l);
|
||||
ghostObject.setWorldTransform(characterTransform);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
|||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.emamaker.amazeing.AMazeIng;
|
||||
import com.emamaker.amazeing.manager.managers.GameManagerServer;
|
||||
import com.emamaker.amazeing.player.MazePlayer;
|
||||
import com.emamaker.amazeing.utils.MathUtils;
|
||||
|
||||
|
@ -121,15 +122,16 @@ public class PowerUp implements Disposable {
|
|||
|
||||
// Return true if the effect has been resolved
|
||||
public boolean usePowerUp(MazePlayer player) {
|
||||
System.out.println(this.name + " ! ");
|
||||
System.out.println(AMazeIng.getMain().currentGameManager + " " + this.name + " ! ");
|
||||
|
||||
if (effect != null) {
|
||||
if (effect != null && !(AMazeIng.getMain().currentGameManager instanceof GameManagerServer)) {
|
||||
PooledEffect e = effectPool.obtain();
|
||||
Vector3 pos = MathUtils.toScreenCoords(player.getPos());
|
||||
e.setPosition(pos.x, pos.y);
|
||||
|
||||
AMazeIng.getMain().effects.add(e);
|
||||
}
|
||||
AMazeIng.getMain().currentGameManager.revokePowerUp(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -165,8 +167,10 @@ class PowerUpTemporized extends PowerUp {
|
|||
startTime = System.currentTimeMillis();
|
||||
used = true;
|
||||
|
||||
e = effectPool.obtain();
|
||||
AMazeIng.getMain().effects.add(e);
|
||||
if (!(AMazeIng.getMain().currentGameManager instanceof GameManagerServer)) {
|
||||
e = effectPool.obtain();
|
||||
AMazeIng.getMain().effects.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - startTime <= time) {
|
||||
|
@ -175,16 +179,19 @@ class PowerUpTemporized extends PowerUp {
|
|||
return false;
|
||||
} else {
|
||||
used = false;
|
||||
// System.out.println("finishing " + name);
|
||||
e = null;
|
||||
temporizedEffectExpired(player);
|
||||
AMazeIng.getMain().currentGameManager.revokePowerUp(player);
|
||||
System.out.println("finishing " + name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void temporizedEffect(MazePlayer player) {
|
||||
Vector3 p = MathUtils.toScreenCoords(player.getPos());
|
||||
e.setPosition(p.x, p.y);
|
||||
if (e != null && !(AMazeIng.getMain().currentGameManager instanceof GameManagerServer)) {
|
||||
Vector3 p = MathUtils.toScreenCoords(player.getPos());
|
||||
e.setPosition(p.x, p.y);
|
||||
}
|
||||
|
||||
beingUsed = true;
|
||||
}
|
||||
|
@ -219,8 +226,8 @@ class PowerUpGiver extends PowerUp {
|
|||
if (AMazeIng.getMain().currentGameManager.players.size() > 1) {
|
||||
while (p == player || p == null)
|
||||
p = AMazeIng.getMain().currentGameManager.getRandomPlayer();
|
||||
p.currentPowerUp = powerup;
|
||||
p.usePowerUp();
|
||||
AMazeIng.getMain().currentGameManager.assignPowerUp(p, powerup, true);
|
||||
AMazeIng.getMain().currentGameManager.revokePowerUp(player);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.emamaker.amazeing.utils.TextureLoader;
|
|||
public class PowerUpBallAndChain extends PowerUpTemporized {
|
||||
|
||||
public PowerUpBallAndChain() {
|
||||
super("BALL AND CHAIN", TextureLoader.textureBallAndChain, true, 10, 1f, 1f,
|
||||
super("BALL_AND_CHAIN", TextureLoader.textureBallAndChain, true, 10, 1f, 1f,
|
||||
Gdx.files.internal("data/particles/ball_and_chain.particle"), Gdx.files.internal("data/powerups"));
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class PowerUpBallAndChain extends PowerUpTemporized {
|
|||
class PowerUpGiveBallAndChain extends PowerUpGiver {
|
||||
|
||||
public PowerUpGiveBallAndChain() {
|
||||
super(new PowerUpBallAndChain(), "BALL AND CHAIN GIVER", TextureLoader.textureBallAndChain, false, null, null);
|
||||
super(new PowerUpBallAndChain(), "BALL_AND_CHAIN_GIVER", TextureLoader.textureBallAndChain, false, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.emamaker.amazeing.utils.TextureLoader;
|
|||
|
||||
public class PowerUpBomb extends PowerUp {
|
||||
|
||||
int radius = 1;
|
||||
int radius = 2;
|
||||
|
||||
AMazeIng main = AMazeIng.getMain();
|
||||
|
||||
|
@ -36,13 +36,13 @@ public class PowerUpBomb extends PowerUp {
|
|||
for (int k = 0; k < main.currentGameManager.mazeGen.h; k++)
|
||||
tmptodraw[i][k] = main.currentGameManager.mazeGen.todraw[i][k];
|
||||
|
||||
for (int i = px - radius; i < px + radius + 1; i++) {
|
||||
for (int k = pz - radius; k < pz + radius + 1; k++) {
|
||||
tmptodraw = main.currentGameManager.mazeGen.changeMap(tmptodraw, i, k, 0);
|
||||
for (int i = px - radius - 1; i < px + radius + 2; i++) {
|
||||
for (int k = pz - radius - 1; k < pz + radius + 2; k++) {
|
||||
if(player.getPos().dst(i, 1, k) <= radius) tmptodraw = main.currentGameManager.mazeGen.changeMap(tmptodraw, i, k, 0);
|
||||
}
|
||||
}
|
||||
|
||||
AMazeIng.getMain().currentGameManager.requestChangeToMap(tmptodraw);
|
||||
AMazeIng.getMain().requestChangeToMap(tmptodraw);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class PowerUpBigBomb extends PowerUpBomb{
|
|||
|
||||
public PowerUpBigBomb() {
|
||||
super("BIG BOMB", TextureLoader.textureBomb, false, 1.5f, 1.5f, Gdx.files.internal("data/particles/explosion.particle"), Gdx.files.internal("data/particles"));
|
||||
radius = 2;
|
||||
radius = 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PowerUpSlug extends PowerUpTemporized {
|
|||
class PowerUpGiveSlug extends PowerUpGiver {
|
||||
|
||||
public PowerUpGiveSlug() {
|
||||
super(new PowerUpSlug(), "SLUG GIVER", TextureLoader.textureSlug, false, 1f, 1f, null, null);
|
||||
super(new PowerUpSlug(), "SLUG_GIVER", TextureLoader.textureSlug, false, 1f, 1f, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ public class PowerUps {
|
|||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,6 @@ public class MathUtils extends net.dermetfan.gdx.math.MathUtils {
|
|||
float hue = value*maxHue + (1-value)*minHue;
|
||||
Color c = new Color(java.awt.Color.HSBtoRGB(hue, 1, 1f));
|
||||
|
||||
System.out.println(r + ", " + g + ", " + b);
|
||||
|
||||
return new Color(c);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue