diff --git a/src/ingame_programming/FollowerBehaviour.java b/src/ingame_programming/FollowerBehaviour.java index f3b2e698647e4ab236166ad57d424fc96083ecb3..ec75abfaa37e6ab0307c6333488d475671cadf33 100644 --- a/src/ingame_programming/FollowerBehaviour.java +++ b/src/ingame_programming/FollowerBehaviour.java @@ -259,21 +259,24 @@ public class FollowerBehaviour { /** Give the current Character to target, and adapt "ruletoconsider" to this result * @param list Is the list of all visible character */ - public Character FindTarget(List list) { + public List FindTarget(List list) { ruletoconsider = -1; int k = 0; while(k result = findCharacter(list,targets.get(k)); + ArrayList copyk = new ArrayList(); + copyk.addAll(targets.get(k)); + List result = findCharacter(list,copyk); if (! result.isEmpty()) { ruletoconsider = k; - return result.get(0); + return result; } else { k = k+1; } } - return list.get(0); + ArrayList emptyList = new ArrayList(); + return emptyList; } /** A debug fonction that allows to Print the Instructions according to the FollowerBehaviour */ diff --git a/src/ingame_programming/IGPEntity.java b/src/ingame_programming/IGPEntity.java index 8e0217a78c232d7784dd018a64b1bbfa1e6e08c7..851104077220291d4ecb990f31491e3a71fe14b6 100644 --- a/src/ingame_programming/IGPEntity.java +++ b/src/ingame_programming/IGPEntity.java @@ -21,6 +21,69 @@ public class IGPEntity extends AbstractEntity { super(gameContent,relayer); } + private void move_and_attack(Character victim) { + double r = random(); + if (r<0.9) { + if (relayer.getCharacter().getCollisionBox().intersect(victim.getCollisionBox())) { + this.relayer.move(Direction.NONE); + this.relayer.tryToCastAbility(0); + } + else { + this.move_to_victim(victim); + } + } + else{ + this.random_move(); + } + } + + private void follow(Character victim) { + double r = random(); + if (r<0.9) { + if (relayer.getCharacter().getCollisionBox().intersect(victim.getCollisionBox())) { + this.relayer.move(Direction.NONE); + } + else { + this.move_to_victim(victim); + } + } + else{ + this.random_move(); + } + } + + private Character nearest(List entityList , Character victim , int faction) { + int dX = victim.getX(); + int dY = victim.getY(); + double dmin =0 ; + double dmax = 32*15; // tiles of length 32 : so 15 tiles + int newvictim = -1; + for (int i=0;i victimlist = fb.FindTarget(chlist); + ArrayList me = new ArrayList(); + me.add(relayer.getCharacter()); + victimlist.removeAll(me); String action = fb.getAction(); + Character victim = null; + if (victimlist.isEmpty()) { + action = "nothing"; + } + else { + victim = nearest(victimlist, relayer.getCharacter(), 2); + if (victim == null) { + return; + } + } switch (action) { case "attaquer": + // 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(); - } + move_and_attack(victim); + /* Second possible use with A* int dX = victim.getX(); int dY = victim.getY(); @@ -63,82 +128,41 @@ public class IGPEntity extends AbstractEntity { this.relayer.move(dir); } this.relayer.tryToCastAbility(0); */ + break; + case "proteger": + /* Find the nearest ennemy from the character we have to protect and try to attack him */ - int dX2 = victim.getX(); - int dY2 = victim.getY(); - int sX2 = relayer.getCharacter().getX(); - int sY2 = relayer.getCharacter().getY(); - double dmin =0 ; - double dmax = 32*15; // tiles of length 32 : so 15 tiles - int newvictim = -1; - List entityList=gameState.getAllEntities(); - for (int i=0;i