Commit b74c7a79 authored by Myriam Begel's avatar Myriam Begel

Begin of Death implementation

parent 40f19650
package artificial_intelligence;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
import artificial_intelligence.AIEntities.*;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import logging.Logging;
/**
* @author Guerquin Arnaud && Ramusat Yann
......@@ -15,6 +18,8 @@ import core.relayer.Relayer;
*/
public class AIControler {
private static ArrayList<AbstractEntity> list=new ArrayList<>();
private static HashMap<Integer,AbstractEntity> hashMap = new HashMap<>();
static Logger LOGGER = new Logging().getLogger();
/**
* Create a new AI of indicated type given as context a gameContent and a relayer to contact.
......@@ -35,10 +40,11 @@ public class AIControler {
ai = new DefenderEntity(gameContent,dmr);
break;
default:
System.out.println("Trying to instanciate unrecognized type of AI.");
LOGGER.warning("Trying to instanciate unrecognized type of AI.");
break;
}
list.add(ai);
hashMap.put(dmr.getCharacter().getID(),ai);
}
/**
......@@ -57,6 +63,7 @@ public class AIControler {
return list.size();
}
/**
* To use for example at the end of a map.
*/
......@@ -65,6 +72,23 @@ public class AIControler {
ai.setEndThread(false);
}
list.clear();
hashMap.clear();
}
/**
* To use when one specific monster die.
* @param entityID ID of the entity that should die
*/
public static boolean killOne(int entityID){
AbstractEntity ai = hashMap.get(entityID);
if (ai!=null) {
ai.setEndThread(false);
list.remove(ai);
hashMap.remove(entityID);
return true;
} else {
return false;
}
}
/**
......
package core.event;
import artificial_intelligence.AIControler;
import core.gamestate.Entity;
import core.gamestate.GameContent;
/**
......@@ -7,12 +9,20 @@ import core.gamestate.GameContent;
* @author Guerquin Arnaud
*
*/
public class DeathEvent implements ClientEvent {
public class ToServerDeathEvent implements ClientEvent {
private int entityID;
public ToServerDeathEvent(int entityID){
this.entityID = entityID;
}
private static final long serialVersionUID = 1L;
@Override
public boolean execute(GameContent gameContent) {
// TODO Auto-generated method stub
LOGGER.info(entityID+" is dead");
if (AIControler.killOne(entityID);
Entity entity = gameContent.getGameState().getEntity(entityID);
gameContent.getGameState().removeEntity(entity);
return false;
}
......
......@@ -79,7 +79,7 @@ public class GameState implements Serializable{
* @param id the entity to remove.
* @return true if it was successfully removed. false otherwise.
*/
boolean removeEntity(int id){
public boolean removeEntity(int id){
if(beings.removeIf(x->x.getID()==id))
return true;
if(characters.removeIf(x->x.getID()==id))
......
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