Commit 18e5990f authored by Ghyselen's avatar Ghyselen

Changing movement in the IGPEntity

parent 4a2fd459
...@@ -8,6 +8,8 @@ import core.relayer.Relayer; ...@@ -8,6 +8,8 @@ import core.relayer.Relayer;
import core.zone.Direction; import core.zone.Direction;
import core.gamestate.Character; import core.gamestate.Character;
import java.util.*; import java.util.*;
import static java.lang.Math.random;
import static java.lang.Math.abs;
/** The AbstractEntity generated for the IA implied by the FollowerBehaviour in BehaviourHolder /** The AbstractEntity generated for the IA implied by the FollowerBehaviour in BehaviourHolder
* @author Alexis Ghyselen * @author Alexis Ghyselen
...@@ -35,6 +37,21 @@ public class IGPEntity extends AbstractEntity { ...@@ -35,6 +37,21 @@ public class IGPEntity extends AbstractEntity {
switch (action) { switch (action) {
case "attaquer": case "attaquer":
// Goto the victim and try to attack it // Goto the victim and try to attack it
double r = random();
if(r<0.9){
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(victim.getCollisionBox())) {
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(0); // if we are close enough we fight and don't move
}
else {
this.move_to_victim(victim);
}
}
else{
this.random_move();
}
/* Second possible use with A*
int dX = victim.getX(); int dX = victim.getX();
int dY = victim.getY(); int dY = victim.getY();
int sX = relayer.getCharacter().getX(); int sX = relayer.getCharacter().getX();
...@@ -45,7 +62,7 @@ public class IGPEntity extends AbstractEntity { ...@@ -45,7 +62,7 @@ public class IGPEntity extends AbstractEntity {
} else { } else {
this.relayer.move(dir); this.relayer.move(dir);
} }
this.relayer.tryToCastAbility(0); this.relayer.tryToCastAbility(0); */
break; break;
case "proteger": case "proteger":
/* Find the nearest ennemy from the character we have to protect and try to attack him */ /* Find the nearest ennemy from the character we have to protect and try to attack him */
...@@ -53,24 +70,48 @@ public class IGPEntity extends AbstractEntity { ...@@ -53,24 +70,48 @@ public class IGPEntity extends AbstractEntity {
int dY2 = victim.getY(); int dY2 = victim.getY();
int sX2 = relayer.getCharacter().getX(); int sX2 = relayer.getCharacter().getX();
int sY2 = relayer.getCharacter().getY(); int sY2 = relayer.getCharacter().getY();
float dmin =0 ; double dmin =0 ;
double dmax = 32*15; // tiles of length 32 : so 15 tiles
int newvictim = -1; int newvictim = -1;
List<Entity> entityList=gameState.getAllEntities(); List<Entity> entityList=gameState.getAllEntities();
for (int i=0;i<entityList.size();i++) { for (int i=0;i<entityList.size();i++) {
Entity act_entity = entityList.get(i); Entity act_entity = entityList.get(i);
if (act_entity.getFaction() != victim.getFaction()) { // if act_entity is an ennemy of the character we have to protect if (act_entity.getFaction() != victim.getFaction()) { // if act_entity is in another faction that victim
float d = (act_entity.getX() - dX2) ^ 2 + (act_entity.getY() - dY2) ^ 2; double d = abs(act_entity.getX() - dX2)+abs(act_entity.getY() - dY2);
if (dmin == 0) { if (d<dmax) {
dmin = d; if (dmin == 0) {
newvictim = i;
} else {
if (d != 0 && dmin < d) {
dmin = d; dmin = d;
newvictim = i; newvictim = i;
} else {
if (d != 0 && dmin < d) {
dmin = d;
newvictim = i;
}
} }
} }
} }
} }
if (newvictim!=-1) {
double r2 = random();
if(r2<0.9){
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(gameState.getAllEntities().get(newvictim).getCollisionBox())) {
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(0); // if we are close enough we fight and don't move
}
else {
this.move_to_victim(gameState.getAllEntities().get(newvictim));
}
}
else{
this.random_move();
}
}
else{
this.waiting_move();
}
/* Other instruction using A*
if (newvictim != -1) { if (newvictim != -1) {
int tardX = entityList.get(newvictim).getX(); int tardX = entityList.get(newvictim).getX();
int tardY = entityList.get(newvictim).getY(); int tardY = entityList.get(newvictim).getY();
...@@ -81,11 +122,24 @@ public class IGPEntity extends AbstractEntity { ...@@ -81,11 +122,24 @@ public class IGPEntity extends AbstractEntity {
this.relayer.move(dir2); this.relayer.move(dir2);
} }
this.relayer.tryToCastAbility(0); this.relayer.tryToCastAbility(0);
} } */
break; break;
case "soigner" : case "soigner" :
// This case is not implemented in the game, so "soigner" will be considered as "follow" by the IA // This case is not implemented in the game, so "soigner" will be considered as "follow" by the IA
System.out.println("Je suis" + victim.getName()); double r3 = random();
if(r3<0.9){
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(victim.getCollisionBox())) {
this.relayer.move(Direction.NONE);
}
else {
this.move_to_victim(victim);
}
}
else{
this.random_move();
}
/* Other way using A*
int dX4 = victim.getX(); int dX4 = victim.getX();
int dY4 = victim.getY(); int dY4 = victim.getY();
int sX4 = relayer.getCharacter().getX(); int sX4 = relayer.getCharacter().getX();
...@@ -95,16 +149,30 @@ public class IGPEntity extends AbstractEntity { ...@@ -95,16 +149,30 @@ public class IGPEntity extends AbstractEntity {
this.relayer.move(Direction.NONE); this.relayer.move(Direction.NONE);
} else { } else {
this.relayer.move(dir4); this.relayer.move(dir4);
} } */
break; break;
default: default:
// In the default case, so the aciton "nothing", the Follower will just follow his owner // In the default case, so the aciton "nothing", the Follower will just follow his owner
Entity owner =null; Entity owner =null;
try { try {
owner = gameState.getEntity(relayer.getCharacter().getOwner()); owner = gameState.getEntity(relayer.getCharacter().getOwner());
}catch(Exception e){ }catch(Exception e){
return; return;
} }
double r4 = random();
if(r4<0.9){
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(owner.getCollisionBox())) {
this.relayer.move(Direction.NONE);
}
else {
this.move_to_victim(owner);
}
}
else{
this.random_move();
}
/* other way using A*
int dX3 = owner.getX(); int dX3 = owner.getX();
int dY3 = owner.getY(); int dY3 = owner.getY();
int sX3 = relayer.getCharacter().getX(); int sX3 = relayer.getCharacter().getX();
...@@ -114,7 +182,7 @@ public class IGPEntity extends AbstractEntity { ...@@ -114,7 +182,7 @@ public class IGPEntity extends AbstractEntity {
this.relayer.move(Direction.NONE); this.relayer.move(Direction.NONE);
} else { } else {
this.relayer.move(dir3); this.relayer.move(dir3);
} } */
} }
} }
} }
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