Commit 56ab0184 authored by Louis Cohen's avatar Louis Cohen
Browse files

debug of BossEntity (with ringeade)

parent 6b8db97a
......@@ -199,25 +199,46 @@ public abstract class AbstractEntity extends Thread {
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
int distance_to_shoot = 32; // distance of tolerance of alignment
if(abs(Delta_x)<distance_to_shoot){
if(Delta_x<0){
this.relayer.move(Direction.RIGHT);
this.relayer.tryToCastAbility(1);
int distance_to_shoot = 24; // distance of tolerance of alignment
if(abs(Delta_x)<distance_to_shoot){ //we are well enough aligned to shoot
if(Delta_y<0){ // choose side to shoot
if(relayer.getCharacter().getDirection()==Direction.RIGHT){ //right side, we shoot
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.RIGHT); //wrong side, we turn
}
}
else{
this.relayer.move(Direction.LEFT);
this.relayer.tryToCastAbility(1);
if(relayer.getCharacter().getDirection()==Direction.LEFT){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
else if(abs(Delta_y)<distance_to_shoot){
if(Delta_y<0){
this.relayer.move(Direction.DOWN);
this.relayer.tryToCastAbility(1);
if(Delta_x<0){
if(relayer.getCharacter().getDirection()==Direction.DOWN){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.DOWN);
}
}
else{
this.relayer.move(Direction.UP);
this.relayer.tryToCastAbility(1);
if(relayer.getCharacter().getDirection()==Direction.UP){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.UP);
}
}
}
else{ // we have to move to be align
......
......@@ -39,8 +39,8 @@ public class BossEntity extends AbstractEntity {
Entity victim = this.gameState.getAllEntities().get(victim_i);
/* d_min minimum distance to not run away
* dmax maximum distance to not get closer*/
double d_min = 32*1; // tiles of length 32 : so 3 and 7 tiles
double d_max = 32*15;
double d_min = 32*3; // tiles of length 32 : so 3 and 7 tiles
double d_max = 32*14;
double d = Distance_to_victim(victim);
if(d<d_min){
this.run_from_victim(victim);
......@@ -68,6 +68,5 @@ public class BossEntity extends AbstractEntity {
}
// attack
this.relayer.tryToCastAbility(1);
}
}
}
......@@ -9,10 +9,12 @@ import core.relayer.*;
import artificial_intelligence.AIControler;
import artificial_intelligence.AIEntities.EnumBehaviourType;
import java.io.InterruptedIOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Semaphore;
/**
......@@ -31,6 +33,7 @@ public class GameContent implements Serializable{
private GameState gameState;
private ArrayList<Character> players;
private ArrayList<Entity> triggerEntities=new ArrayList<>();
private Semaphore sem = new Semaphore(1);
public GameContent(Map map,int playersNumber) throws InterruptedException {
this.map=Objects.requireNonNull(map);
......@@ -41,7 +44,7 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......@@ -103,18 +106,26 @@ public class GameContent implements Serializable{
}
public void applyTrigger(NetworkConnection networkConnection) throws InterruptedException {
sem.acquire();
for(Entity e:triggerEntities){
e.checkTrigger(this,networkConnection);
}
sem.release();
}
public void addTriggerToCheck(Entity e) {
public void addTriggerToCheck(Entity e) throws InterruptedException
{
sem.acquire();
triggerEntities.add(e);
sem.release();
}
public void removeTriggerToCheck(Entity e) {
public void removeTriggerToCheck(Entity e) throws InterruptedException
{
sem.acquire();
triggerEntities.remove(e);
sem.release();
}
public boolean checkStrairs(Map newMap,NetworkConnection networkConnection) throws InterruptedException {
......@@ -132,6 +143,9 @@ public class GameContent implements Serializable{
this.map=Objects.requireNonNull(map);
this.gameState=new GameState();
AIControler.killAll();
sem.acquire();
triggerEntities.clear();
sem.release();
if(!server)
Relayers.resetRelayers();
if(map.getEntities()!=null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment