So I'm trying to make a fairly basic combat ai for a small fantasy game, but I'm having a tad bit of difficulty in the removing of an object. It works fine if it's just the player and another ai (player vs ai,) but if you add another ai to the mix(player vs ai vs ai) if one ai(team 1) targets another ai(team 2) if team2 is removed from the game team1 will not recognize the removal, but instead remain locked on the removed object and crash. Below is the combat method used in the two ai, Enemies() is a brief method that returns a class of an enemy. The code used in the player is just a basic removeObject, if it would be helpful to have let me know. Thanks
Any help regarding this would be greatly appreciated, thanks!
public void combat(int str, int dex, int con, int intel, int wis, int cha, int type, String imageName) {
List<Living> possTargets = getObjectsInRange(700, Enemies());
if ( possTargets.size() <= 0 )
{
target = null;
}
else
{
if (possTargets.size() == 0) {
}
else {
if (target == null ) {
possTargets = getObjectsInRange(700, Enemies());
target = possTargets.get(Greenfoot.getRandomNumber(possTargets.size()));
}
int X = getX();
int Y = getY();
int tX = target.getX();
int tY = target.getY();
if (type == 0) {
//Up close and personal
if ( X > target.getX() + 50) {
setLocation(X -(2+dex/2), Y);
setImage(imageName+ "a4.png");
}
else if ( X < target.getX() - 50) {
setLocation(X + (2 + dex/2), Y);
setImage(imageName+ "a2.png");
}
else if (Y < target.getY()-50) {
setLocation(X , Y+ (2 + dex/2));
setImage(imageName+ "a1.png");
}
else if (Y > tY + 50) {
setLocation(X, Y - (2 + dex/2));
setImage(imageName+ "a3.png");
}
}
}
}
}
}
