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