Skip to content

Commit

Permalink
Fixed inputMultiplexer bug; fixed logic to create working AI
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Dec 11, 2020
1 parent 4bcd3bd commit 3f9f6e7
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 45 deletions.
2 changes: 2 additions & 0 deletions client-core/src/com/benberi/cadesim/GameContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,11 @@ public void exitMapEditor() {
*/
public void handleServersideDisconnect() {
if(getServerResponse()) {
inputMultiplexer.clear();
getServerChannel().disconnect();
System.out.println("Login error; handling response.");
}else {
inputMultiplexer.clear();
setConnected(false);
setIsInLobby(true);
getServerChannel().disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ public void createMap(int[][] tiles) {
selectedIsland = islandList.get(context.getIslandId());
}

/**
* set up the input processor for the chat and game
*/
public void setup() {

}

private void recountVessels() {
vesselsCountWithCurrentPhase = context.getEntities().countVesselsByPhase(currentPhase);
vesselsCountNonSinking = context.getEntities().countNonSinking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ public void splitRoomInfo() {
port_numbers.add(temp_room_info[j].replace("\\", ""));
}
else {

String[] print = temp_room_info[j].split(";");
server_codes.add(print[0]);
room_names.add(print[1]);
Expand Down Expand Up @@ -915,8 +916,6 @@ public void readURLServerConfig() {
if(line.isEmpty() || line.startsWith("#")) {
continue;
}
//remove spaces
line = line.replaceAll("\\s", "");
//check getdown.txt for url
if(line.startsWith("server.room_locations=")) {
room_info = line.split("=")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public ServerChannelHandler(ServerContext ctx) {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
try {
context.getPlayerManager().registerPlayer(ctx.channel());
Player p = new Player(context, ctx.channel());
context.getPlayerManager().registerPlayer(ctx.channel(), p);
} catch (Exception e) {
ServerContext.log("Channel register error: " + e.getMessage());
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ServerPacketManager(ServerContext context) {
*/
public void queuePackets() {
for (Player p : context.getPlayerManager().getPlayers()) {
p.getPackets().queueIncomingPackets();
p.getPackets().queueIncomingPackets();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.benberi.cadesim.server.model.player;

public enum NPC_Type {
TYPE1(),
TYPE2(),
TYPE3(),
TYPE4();
}
20 changes: 15 additions & 5 deletions server/src/com/benberi/cadesim/server/model/player/NPC_Type1.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.benberi.cadesim.server.model.player;

import com.benberi.cadesim.server.ServerContext;
import com.benberi.cadesim.server.model.player.move.MoveType;

import io.netty.channel.Channel;

/*
* AI Logic - moving type only (like green ships in flotilla with no cbs)
Expand All @@ -10,10 +13,12 @@ public class NPC_Type1 extends Player {
@SuppressWarnings("unused")
private ServerContext context;

public NPC_Type1(ServerContext ctx) {
this.context = ctx;
setBot(true);
set(-1, -1); // not spawned
public NPC_Type1(ServerContext ctx, Channel c) {
super(ctx,c);
context = ctx;
super.setBot(true);
super.set(-1, -1); // not spawned
super.setType(NPC_Type.TYPE1);
}

@Override
Expand All @@ -23,6 +28,11 @@ public void calculateRoute() {

@Override
public void performLogic() {

getMoves().setMove(0, MoveType.FORWARD);
}

@Override
public NPC_Type getType() {
return type;
}
}
23 changes: 14 additions & 9 deletions server/src/com/benberi/cadesim/server/model/player/NPC_Type2.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.benberi.cadesim.server.model.player;

import com.benberi.cadesim.server.ServerContext;
import com.benberi.cadesim.server.model.player.move.MoveType;

import io.netty.channel.Channel;

/*
* AI Logic - flag grabbing type (collect available flag points)
Expand All @@ -10,19 +13,21 @@ public class NPC_Type2 extends Player {
@SuppressWarnings("unused")
private ServerContext context;

public NPC_Type2(ServerContext ctx) {
this.context = ctx;
setBot(true);
set(-1, -1); // not spawned
public NPC_Type2(ServerContext ctx, Channel c) {
super(ctx,c);
context = ctx;
super.setBot(true);
super.set(-1, -1); // not spawned
super.setType(NPC_Type.TYPE2);
}

@Override
public void calculateRoute() {

public void performLogic() {
this.getMoves().setMove(0, MoveType.FORWARD);
}

@Override
public void performLogic() {
@Override
public NPC_Type getType() {
return type;
}
}
20 changes: 15 additions & 5 deletions server/src/com/benberi/cadesim/server/model/player/NPC_Type3.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.benberi.cadesim.server.model.player;

import com.benberi.cadesim.server.ServerContext;
import com.benberi.cadesim.server.model.player.move.MoveType;

import io.netty.channel.Channel;

/*
* AI Logic - moving type but engage with player in range
Expand All @@ -10,10 +13,12 @@ public class NPC_Type3 extends Player {
@SuppressWarnings("unused")
private ServerContext context;

public NPC_Type3(ServerContext ctx) {
this.context = ctx;
setBot(true);
set(-1, -1); // not spawned
public NPC_Type3(ServerContext ctx, Channel c) {
super(ctx,c);
context = ctx;
super.setBot(true);
super.set(-1, -1); // not spawned
super.setType(NPC_Type.TYPE3);
}

@Override
Expand All @@ -23,6 +28,11 @@ public void calculateRoute() {

@Override
public void performLogic() {

getMoves().setMove(0, MoveType.FORWARD);
}

@Override
public NPC_Type getType() {
return type;
}
}
22 changes: 16 additions & 6 deletions server/src/com/benberi/cadesim/server/model/player/NPC_Type4.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.benberi.cadesim.server.model.player;

import com.benberi.cadesim.server.ServerContext;
import com.benberi.cadesim.server.model.player.move.MoveType;

import io.netty.channel.Channel;

/*
* AI Logic - chaser type (goes after player)
Expand All @@ -10,19 +13,26 @@ public class NPC_Type4 extends Player {
@SuppressWarnings("unused")
private ServerContext context;

public NPC_Type4(ServerContext ctx) {
this.context = ctx;
setBot(true);
set(-1, -1); // not spawned
public NPC_Type4(ServerContext ctx, Channel c) {
super(ctx,c);
context = ctx;
super.setBot(true);
super.set(-1, -1); // not spawned
super.setType(NPC_Type.TYPE4);
}

@Override
public void calculateRoute() {

}

@Override
public void performLogic() {

getMoves().setMove(0, MoveType.FORWARD);
}

@Override
public NPC_Type getType() {
return type;
}
}
16 changes: 14 additions & 2 deletions server/src/com/benberi/cadesim/server/model/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class Player extends Position {
* The server context
*/
private ServerContext context;

protected NPC_Type type;
/**
* If the player is registered
*/
Expand Down Expand Up @@ -422,7 +422,7 @@ public void register(String name, int ship, int team, int[] customPosition, Vess
respawn(customPosition, customFace, customDamage, shouldSpawnFullCannons);
}

/**
/**
* wrapper for register
*/
public void register(String name, int ship, int team) {
Expand Down Expand Up @@ -945,4 +945,16 @@ public String getChatChannel() {
public void setTeam(Team team) {
this.team = team;
}

public void printType() {
System.out.println(name + " ,"+ type);
}

public NPC_Type getType() {
return type;
}

public void setType(NPC_Type typeValue) {
type = typeValue;
}
}
Loading

0 comments on commit 3f9f6e7

Please sign in to comment.