forked from SpinahVieh/Obsidio-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91bf0b9
commit 2bce840
Showing
12 changed files
with
270 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
server/src/com/benberi/cadesim/server/model/player/NPC_Type4.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...adesim/server/model/player/NPC_Type1.java → ...sim/server/model/player/ai/NPC_Type1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...adesim/server/model/player/NPC_Type2.java → ...sim/server/model/player/ai/NPC_Type2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...adesim/server/model/player/NPC_Type3.java → ...sim/server/model/player/ai/NPC_Type3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
server/src/com/benberi/cadesim/server/model/player/ai/NPC_Type4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.benberi.cadesim.server.model.player.ai; | ||
|
||
import java.util.List; | ||
|
||
import com.benberi.cadesim.server.ServerContext; | ||
import com.benberi.cadesim.server.model.player.Player; | ||
import com.benberi.cadesim.server.model.player.ai.util.AStarNode; | ||
import com.benberi.cadesim.server.model.player.ai.util.NPC_Type; | ||
import com.benberi.cadesim.server.model.player.move.MoveType; | ||
import com.benberi.cadesim.server.model.player.vessel.VesselFace; | ||
import com.benberi.cadesim.server.util.Position; | ||
|
||
import io.netty.channel.Channel; | ||
|
||
/* | ||
* AI Logic - chaser type (goes after player) | ||
* Priority - shooting, flag points | ||
*/ | ||
public class NPC_Type4 extends Player { | ||
@SuppressWarnings("unused") | ||
private ServerContext context; | ||
private List<AStarNode> path = null; | ||
|
||
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() { | ||
Position destination = new Position(3,3); // replace with cluster | ||
if(this.equals(destination)) { | ||
return; | ||
} | ||
path = context.getPlayerManager().getAlgorithm().findPath(this, destination); | ||
VesselFace face = getFace(); | ||
if(path != null) { | ||
if(path.size() > 0) { | ||
int numberOfMoves = getVessel().has3Moves() ? 3 : 4; | ||
Position currentPosition = this.copy(); | ||
for(int slot = 0; slot <= numberOfMoves; slot++) { //moves to enter | ||
int positionIndex = (path.size() - 1) - (slot); //subtract slot to allow multiple moves | ||
if(positionIndex < 0 || path.size() < slot) { // make sure it doesn't count too far | ||
return; | ||
} | ||
Position pos = path.get(positionIndex).position; | ||
Position left = MoveType.LEFT.getFinalPosition(currentPosition, face); | ||
Position right = MoveType.RIGHT.getFinalPosition(currentPosition, face); | ||
Position forward = MoveType.FORWARD.getFinalPosition(currentPosition, face); | ||
if(left.equals(pos)) { | ||
currentPosition.add(left.getX() - getX(), left.getY() - getY()); | ||
getMoves().setMove(slot, MoveType.LEFT); | ||
switch(face) { | ||
case NORTH: | ||
face = VesselFace.WEST; | ||
break; | ||
case SOUTH: | ||
face = VesselFace.EAST; | ||
break; | ||
case WEST: | ||
face = VesselFace.SOUTH; | ||
break; | ||
case EAST: | ||
face = VesselFace.NORTH; | ||
break; | ||
} | ||
}else if(right.equals(pos)) { | ||
currentPosition.add(right.getX() - getX(), right.getY() - getY()); | ||
getMoves().setMove(slot, MoveType.RIGHT); | ||
switch(face) { | ||
case NORTH: | ||
face = VesselFace.EAST; | ||
break; | ||
case SOUTH: | ||
face = VesselFace.WEST; | ||
break; | ||
case WEST: | ||
face = VesselFace.NORTH; | ||
break; | ||
case EAST: | ||
face = VesselFace.SOUTH; | ||
break; | ||
} | ||
}else if(forward.equals(pos)){ | ||
currentPosition.add(forward.getX() - getX(), forward.getY() - getY()); | ||
getMoves().setMove(slot, MoveType.FORWARD); | ||
switch(face) { | ||
case NORTH: | ||
face = VesselFace.NORTH; | ||
break; | ||
case SOUTH: | ||
face = VesselFace.SOUTH; | ||
break; | ||
case WEST: | ||
face = VesselFace.WEST; | ||
break; | ||
case EAST: | ||
face = VesselFace.EAST; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void performLogic() { | ||
calculateRoute(); | ||
} | ||
|
||
@Override | ||
public NPC_Type getType() { | ||
return type; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/com/benberi/cadesim/server/model/player/ai/util/AStarNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.benberi.cadesim.server.model.player.ai.util; | ||
|
||
import com.benberi.cadesim.server.model.player.vessel.VesselFace; | ||
import com.benberi.cadesim.server.util.Position; | ||
|
||
public class AStarNode { | ||
|
||
public Position position; | ||
public VesselFace face; | ||
public AStarNode parent; | ||
public double fCost, gCost, hCost; | ||
|
||
public AStarNode(Position position, AStarNode parent, double gCost, double hCost) { | ||
this.position = position; | ||
this.parent = parent; | ||
this.gCost = gCost; | ||
this.hCost = hCost; | ||
this.fCost = this.gCost + this.hCost; | ||
} | ||
|
||
} |
Oops, something went wrong.