Commit 0174f3e8 authored by Theodore Lopez's avatar Theodore Lopez

Lot of correction about RelayerEntity

Now Relayer extends RelayerEntity
parent 51158618
......@@ -7,6 +7,7 @@ import core.gamestate.*;
import core.gamestate.Character;
import core.relayer.Relayer;
import core.relayer.RelayerEntity;
import core.relayer.Relayers;
import core.zone.Direction;
import core.zone.Translation;
import core.zone.Zone;
......@@ -101,15 +102,13 @@ public class EffectBuilder implements Serializable{
entity.setOwned_character(casterCharacterID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
RelayerEntity relayer = Relayers.addNewRelayer(entity);
if(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection() != Direction.NONE) {
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
}
else{
relayer.move(charac.getDirection());
}
relayer.start();
}
};
}
......@@ -138,15 +137,13 @@ public class EffectBuilder implements Serializable{
entity.setOwned_character(casterCharacterID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
RelayerEntity relayer = Relayers.addNewRelayer(entity);
if(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection() != Direction.NONE) {
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
}
else{
relayer.move(charac.getDirection());
}
relayer.start();
}
};
}
......@@ -175,15 +172,13 @@ public class EffectBuilder implements Serializable{
entity.setOwned_character(casterCharacterID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
RelayerEntity relayer = Relayers.addNewRelayer(entity);
if(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection() != Direction.NONE) {
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
}
else{
relayer.move(charac.getDirection());
}
relayer.start();
}
};
}
......@@ -247,9 +242,6 @@ public class EffectBuilder implements Serializable{
private static final long serialVersionUID = 1L;
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) throws InterruptedException {
try {
if(gameContent.getGameState().getEntity(casterCharacterID).getRelayer() != null){
gameContent.getGameState().getEntity(casterCharacterID).getRelayer().kill();
}
gameContent.removeTriggerToCheck(gameContent.getGameState().getEntity(casterCharacterID));
gameContent.getGameState().removeEntity(gameContent.getGameState().getEntity(casterCharacterID));
} catch (EntityNotFoundExeption entityNotFoundExeption) {
......
......@@ -2,9 +2,6 @@ package core.event;
import core.gamestate.*;
import core.gamestate.Character;
import core.relayer.RelayerEntity;
import core.zone.Direction;
import gameloop.DummyLocalGameLoop;
/**
* Created by hilaire on 06/01/16.
......
......@@ -8,7 +8,6 @@ import java.util.Objects;
import core.abilities.Ability;
import core.abilities.effects.Effect;
import core.event.TriggerEvent;
import core.relayer.RelayerEntity;
import core.zone.Direction;
import core.zone.Point;
import core.zone.Translation;
......@@ -91,10 +90,6 @@ public class Entity implements Serializable{
* The id of the possible entity's owner (character)
*/
private int owned_character = -1;
/**
* A possible pointer to the relayer of this entity.
*/
transient private RelayerEntity relayer;
//The following 3 fields are used by the method getEntityDisplayer
private EntityDisplayerType entityDisplayerType;
......@@ -470,21 +465,6 @@ public class Entity implements Serializable{
return abilityList;
}
/**
* Getters
* @return
*/
public RelayerEntity getRelayer(){
return relayer;
}
/**
* Setters
* @param relayer
*/
public void setRelayer(RelayerEntity relayer){
this.relayer = relayer;
}
/**
* Getters
......
......@@ -46,13 +46,15 @@ public class GameContent implements Serializable{
if(map.getEntities()!=null) {
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
String name = dmr.getCharacter().getSpeciesName();
if(name.equals("Ronflex")){
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
else{
AIControler.add(this,dmr, EnumBehaviourType.Straight);
if(e instanceof Character){
Relayer dmr = Relayers.addNewRelayer((Character) e);
String name = dmr.getCharacter().getSpeciesName();
if(name.equals("Ronflex")){
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
else{
AIControler.add(this,dmr, EnumBehaviourType.Straight);
}
}
}
}
......@@ -179,8 +181,10 @@ public class GameContent implements Serializable{
if(map.getEntities()!=null) {
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
if(e instanceof Character){
Relayer dmr = Relayers.addNewRelayer((Character) e);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
}
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......
......@@ -5,7 +5,6 @@ import core.event.Event;
import core.event.MoveEvent;
import core.gamestate.Action;
import core.gamestate.Character;
import core.gamestate.Entity;
import core.zone.Direction;
import core.zone.Translation;
import gameloop.DummyLocalGameLoop;
......@@ -20,12 +19,11 @@ import java.util.Objects;
*
*/
public class Relayer extends Thread{
public class Relayer extends RelayerEntity{
/**
* the relayer's id
*/
private final int ID;
/**
* the character for which the relayer create event
*/
......@@ -33,11 +31,9 @@ public class Relayer extends Thread{
/**
* kill the relayer if true
*/
private boolean end=false;
/**
* the direction the relayer should move the character to
*/
private Direction direction=Direction.NONE;
/**
*
*/
......@@ -53,11 +49,9 @@ public class Relayer extends Thread{
* @param entity the entity the relayer is using
* @param gameContent the gameContent the entity is on.
*/
public Relayer(int ID,Entity entity){
public Relayer(int ID,Character character){
this.ID=ID;
if(!(entity instanceof Character))
throw new IllegalStateException("Relayer only accepts character.");
this.character=(Character)Objects.requireNonNull(entity);
this.character=(Character)Objects.requireNonNull(character);
}
/**
......@@ -114,7 +108,7 @@ public class Relayer extends Thread{
public void run(){
while(!end && !character.isDead()){
applyMove();
if(hasTriedToCastAbility)
if(hasTriedToCastAbility && !character.isDead())
applyAbility();
long ctime= System.currentTimeMillis();
try{
......
......@@ -13,24 +13,26 @@ import gameloop.ServerLoop;
import java.util.Objects;
/**
* A simplier version of the powerfull Relayer made in order to match the entity instead of character
* -It allow entity to move, smoothly at each refresh og the gamestate.
* A simpler version of the powerful Relayer made in order to match the entity instead of character
* -It allow entity to move, smoothly at each refresh of the gamestate.
*/
public class RelayerEntity extends Thread{
private final int ID;
private Entity character;
private GameContent gameContent;
private boolean end=false;
private Direction direction=Direction.NONE;
protected int ID;
protected Entity character;
protected boolean end=false;
protected Direction direction=Direction.NONE;
public RelayerEntity(int ID, Entity entity, GameContent gameContent){
public RelayerEntity(){
}
public RelayerEntity(int ID, Entity entity){
this.ID=ID;
this.character=Objects.requireNonNull(entity);
this.gameContent = gameContent;
}
public final int getID(){
public int getID(){
return ID;
}
......@@ -52,10 +54,6 @@ public class RelayerEntity extends Thread{
return character;
}
public GameContent getGameContent() {
return gameContent;
}
@Override
public void run(){
while(!end){
......
package core.relayer;
import java.util.ArrayList;
import core.gamestate.Character;
import core.gamestate.Entity;
......@@ -10,7 +11,7 @@ import core.gamestate.Entity;
* @author Toussain Etienne
*/
public class Relayers{
private static ArrayList<Relayer> relayers=new ArrayList<>();
private static ArrayList<RelayerEntity> relayers=new ArrayList<>();
private static int ID=0;
private static Relayer followedRelayer;
......@@ -19,8 +20,22 @@ public class Relayers{
* @param entity the entity of the new relayer
* @return a new relayer
*/
public static Relayer addNewRelayer(Entity entity){
Relayer relayer=new Relayer(ID++,entity);
public static Relayer addNewRelayer(Character character){
Relayer relayer=new Relayer(ID++,character);
relayers.add(relayer);
relayer.start();
return relayer;
}
public static RelayerEntity addNewRelayer(Entity entity){
RelayerEntity relayer=new RelayerEntity(ID++,entity);
relayers.add(relayer);
relayer.start();
return relayer;
}
public static RelayerEntity addnewRelayer(Entity entity){
RelayerEntity relayer=new RelayerEntity(ID++,entity);
relayers.add(relayer);
relayer.start();
return relayer;
......@@ -30,7 +45,7 @@ public class Relayers{
* kill all relayer
*/
public static void killAll(){
for(Relayer relayer:relayers)
for(RelayerEntity relayer:relayers)
relayer.kill();
relayers.clear();
}
......@@ -44,8 +59,8 @@ public class Relayers{
}
}
public static Relayer addFollowedRelayer(Entity entity) {
Relayer relayer = addNewRelayer(entity);
public static Relayer addFollowedRelayer(Character character) {
Relayer relayer = addNewRelayer(character);
if(followedRelayer!=null){
followedRelayer.kill();
followedRelayer=relayer;
......
......@@ -4,6 +4,8 @@ import core.event.Event;
import core.event.MapChangeEvent;
import core.event.MapInit;
import core.event.ToClientDeathEvent;
import core.gamestate.Entity;
import core.gamestate.Character;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.relayer.Relayers;
......@@ -146,7 +148,11 @@ public class DummyLocalGameLoop extends Thread{
}
if (eventToReceive instanceof MapInit) {
GameContent gc = DummyLocalGameLoop.getInstance().getContent();
Relayer firstEntityRelayer = Relayers.addFollowedRelayer(((MapInit) eventToReceive).getFollowedDummyEntity());
Entity e = ((MapInit) eventToReceive).getFollowedDummyEntity();
if(!(e instanceof Character)){
throw new RuntimeException("Player isn't a Character");
}
Relayer firstEntityRelayer = Relayers.addFollowedRelayer((Character) e);
setFollowedRelayer(firstEntityRelayer);
relayerSemaphore.release();
}
......
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