Commit a77cd37a authored by Arnaud Guerquin's avatar Arnaud Guerquin
Browse files

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

parents bf243270 175d7172
No preview for this file type
......@@ -43,6 +43,10 @@ public class AIControler {
break;
case Follower:
ai = new IGPEntity(gameContent,dmr);
break;
case Straight:
ai = new StraightEntity(gameContent,dmr);
break;
default:
LOGGER.severe("Trying to instanciate unrecognized type of AI.");
break;
......
......@@ -76,7 +76,7 @@ public abstract class AbstractEntity extends Thread {
*/
public int Choose_victim(){
float dmin =0 ;
float dmax = 10000000;
float dmax = 100000;
int victim = -1;
List<Entity> entityList=gameState.getAllEntities();
for (int i=0;i<entityList.size();i++) {
......@@ -106,8 +106,8 @@ public abstract class AbstractEntity extends Thread {
*/
public void move_to_entity(Entity victim) {
// X is UP-DOWN
int px = this.relayer.getCharacter().getX();
int py = this.relayer.getCharacter().getY();
int px = this.relayer.getCharacter().getX();
int py = this.relayer.getCharacter().getY();
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
......@@ -118,11 +118,11 @@ public abstract class AbstractEntity extends Thread {
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.print("pas mal");
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.print("pas mal");
System.out.println("pas mal");
}
}
}
......@@ -132,11 +132,11 @@ public abstract class AbstractEntity extends Thread {
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.print("pas mal");
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.print("pas mal");
System.out.println("pas mal");
}
}
}
......@@ -196,6 +196,23 @@ public abstract class AbstractEntity extends Thread {
}
public void random_move(){
double r = random();
if(r<0.25){
this.relayer.move(Direction.RIGHT);
}
else {
if (r < 0.5) {
this.relayer.move(Direction.UP);
} else {
if (r < 0.75) {
this.relayer.move(Direction.DOWN);
} else {
this.relayer.move(Direction.LEFT);
}
}
}
}
/**
* This is the function sequentially called by run.
* The behaviour of the AI is implemented here.
......
......@@ -9,6 +9,8 @@ import logging.Logging;
import java.util.List;
import static java.lang.Math.random;
/**
* Created by Yann RAMUSAT on 30/12/15.
*/
......@@ -33,12 +35,12 @@ public class BasicEntity extends AbstractEntity {
public void act() {
// basic targeting and pathfinding
int victim_i = this.Choose_victim();
/*if (victim_i!=-1) {
this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
}*/
// A*
// A*
List<Entity> entityList=gameState.getAllEntities();
int dX = entityList.get(this.Choose_victim()).getX();
int dY = entityList.get(this.Choose_victim()).getY();
......
......@@ -7,5 +7,6 @@ public enum EnumBehaviourType {
Agressive,
Basic,
Defender,
Follower;
Follower,
Straight;
}
package artificial_intelligence.AIEntities;
import artificial_intelligence.AlphaStar.AI;
import core.gamestate.Entity;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.zone.Direction;
import logging.Logging;
import java.util.List;
import static java.lang.Math.random;
/**
* Created by Yann RAMUSAT on 30/12/15.
*/
public class StraightEntity extends AbstractEntity {
/**
* Instanciate a basic AI given as context a GameContent and a Relayer to contact.
*
* This use the classes used by the network.
*
* @param gameContent the actual content of the game. Map + Entities.
* @param relayer the relayer to contact.
*/
public StraightEntity(GameContent gameContent, Relayer relayer) {
super(gameContent, relayer);
}
/**
* This is the function sequentially called by run.
* The behaviour of the basic AI is implemented here.
*/
@Override
public void act() {
// basic targeting and pathfinding
int victim_i = this.Choose_victim();
if (victim_i!=-1) {
double r = random();
if(r<0.9){
this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
}
else{
this.random_move();
}
}
// A*
/*List<Entity> entityList=gameState.getAllEntities();
int dX = entityList.get(this.Choose_victim()).getX();
int dY = entityList.get(this.Choose_victim()).getY();
int sX = relayer.getCharacter().getX();
int sY = relayer.getCharacter().getY();
Direction dir = AI.alpha_star(sX, sY, dX, dY,map.getWidth(),map.getHeight());
//Logging.getInstance().getLogger().info(dir.toString());
this.relayer.move(dir);*/
// attack
this.relayer.tryToCastAbility(0);
}
}
src/assets/firebolt.png

2.65 KB | W: | H:

src/assets/firebolt.png

2.65 KB | W: | H:

src/assets/firebolt.png
src/assets/firebolt.png
src/assets/firebolt.png
src/assets/firebolt.png
  • 2-up
  • Swipe
  • Onion skin
number of patterns : 4
number of monsters : 3
Ronflex
Ponyta
Diagla
id : 1
nom : fullMonster1
1
0
0
id : 2
nom : fullMonster2
0
1
0
id : 3
nom : fullMonster3
0
0
1
id : 4
nom : equilibria
1
1
1
\ No newline at end of file
......@@ -23,7 +23,7 @@ public abstract class Effect implements Serializable{
* @param targetCharacterIDList a List of the IDs of the Characters to apply this effect on
* @param gameContent the gameContent in which the target characters lives
* @param casterCharacterID the ID of the Character that casted the Ability containing this Effect
* @throws InterruptedException
* @throws InterruptedException
*/
abstract public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) throws InterruptedException;
}
......@@ -30,16 +30,16 @@ public class AbilityEvent implements ClientEvent,ServerEvent {
this.potentialCasterCharacterID = potentialCasterCharacterID;
this.abilityNb = abilityNb;
}
@Override
public boolean execute(GameContent gameContent) throws InterruptedException {
Entity potentialCaster = null;
try {
potentialCaster = gameContent.getGameState().getEntity(potentialCasterCharacterID);
Ability abilityPotentiallyCasted = potentialCaster.getAbilityList().get(abilityNb);
List<EffectDescriptor> effectDescriptorList = abilityPotentiallyCasted.cast();
if (effectDescriptorList != null) {
//Ability successfully cast
//TODO: Remove later in the game the Action we add in the following line
......
......@@ -9,7 +9,7 @@ public class AddedTriggerEvent implements ClientEvent{
private static final long serialVersionUID = 1L;
int targetID;
Trigger trigger;
@Override
public boolean execute(GameContent gameContent) throws InterruptedException {
Entity e= null;
......
package core.event;
import core.gamestate.GameContent;
import network.innershell.NetworkObject;
/**
* This interface is used to define the message transmitted between the Relayer,
* the GameState and the GameLoop.
* @author Guerquin Arnaud
*
*/
public interface Event extends NetworkObject{
static final long serialVersionUID = 1L;
public static final int infinity = -1;
boolean execute(GameContent gameContent) throws InterruptedException;
Event resolve(GameContent gameContent);
/**
* Applies the event on the given gameContent.
* @param gameContent the gameContent on which the event will be applied.
* @return If modification to the gameState occured, it returns an Event whose apply method will perform the same modification
* @throws InterruptedException
*/
default public Event apply(GameContent gameContent) throws InterruptedException{
if(execute(gameContent))
return resolve(gameContent);
return FailedEvent.failed;
}
}
package core.event;
import core.gamestate.GameContent;
import network.innershell.NetworkObject;
/**
* This interface is used to define the message transmitted between the Relayer,
* the GameState and the GameLoop.
* @author Guerquin Arnaud
*
*/
public interface Event extends NetworkObject{
static final long serialVersionUID = 1L;
public static final int infinity = -1;
boolean execute(GameContent gameContent) throws InterruptedException;
Event resolve(GameContent gameContent);
/**
* Applies the event on the given gameContent.
* @param gameContent the gameContent on which the event will be applied.
* @return If modification to the gameState occured, it returns an Event whose apply method will perform the same modification
* @throws InterruptedException
*/
default public Event apply(GameContent gameContent) throws InterruptedException{
if(execute(gameContent))
return resolve(gameContent);
return FailedEvent.failed;
}
}
......@@ -5,11 +5,11 @@ import map_generation.map.Map;
public class MapChangeEvent implements Event {
/**
*
*
*/
private static final long serialVersionUID = 1L;
Map map;
public MapChangeEvent(Map newMap) {
map=newMap;
}
......
......@@ -8,7 +8,7 @@ public class RemovedTriggerEvent implements ClientEvent{
private static final long serialVersionUID = 1L;
int targetID;
int triggerID;
@Override
public boolean execute(GameContent gameContent) throws InterruptedException {
Entity e= null;
......
......@@ -12,7 +12,7 @@ import core.gamestate.Trigger;
public class TriggerEvent implements ClientEvent {
/**
*
*
*/
private static final long serialVersionUID = 1L;
transient private Trigger trigger;
......
package core.gamestate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
import core.abilities.Ability;
import core.event.Event;
import core.event.ToServerDeathEvent;
import core.zone.Zone;
import gameloop.DummyLocalGameLoop;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayerType;
import logging.Logging;
import map_generation.tiles.TilePropertyVector;
import network.innershell.NetworkConnection;
/**
* This class represents an Entity able to be hit and die.
* @author Guerquin Arnaud
*
*/
public class Being extends Entity {
private static final long serialVersionUID = 1L;
/**
* The Being's current HP. Can't be negative.
*/
private int HP;
/**
* The Being's max HP. maxHP must always be greater or equal than HP.
*/
private int maxHP;
/**
* The character's defense value. Used to protect against physical damage. Must be positive.
*/
private int def;
/**
* The character's mental value. Used to protect against magical damage. Must be positive.
*/
private int mental;
/**
* The Being's Hitbox.
*/
private Zone hitbox;
private DamageTypeVector dtv;
/**
* Being's constructor
* @param name the Being's name.
* @param speciesName the name of the species of the Being.
* @param posX the Being's center X position. Must be in Point Coordinate.
* @param posY the Being's center Y position. Must be in Point Coordinate.
* @param ID the Being's ID.
* @param owner the Being's Relayer ID.
* @param collisionBox the being's collisionBox
* @param tpv the being's tilePropertyVector
* @param visibility the being's visibility
* @param type the being's sprite
* @param triggers the list of all triggers of the being.
* @param HP the being's HP
* @param def the being's def
* @param mental the being's mental
* @param dtv the being's damagePropertyVector
* @param hitbox the being's hitbox.
*/
public Being(String name,String speciesName,int posX,int posY,int ID,int owner,Zone collisionBox,TilePropertyVector tpv,Zone visibility,EntityDisplayerType type,List<TriggerDescriptor> triggers,
int HP,int def,int mental,DamageTypeVector dtv,Zone hitbox,ArrayList<Ability> abilityList) {
super(name,speciesName,posX, posY, ID,owner, collisionBox, tpv, visibility, type,triggers,abilityList);
this.HP= HP;
this.maxHP=HP;
this.def=def;
this.mental=mental;
this.dtv=Objects.requireNonNull(dtv).clone();
this.hitbox=Objects.requireNonNull(hitbox).clone(getCenter());
}
/**
* Returns the Being's current HP
* @return the Being's current HP
*/
public int getHP(){
return HP;
}
/**
* Returns the Being's maxHP
* @return Returns the Being's maxHP
*/
public int getMaxHP() {return maxHP;}
/**
* Returns the character's defense value.
* @return the character's defense value.
*/
public int getDef() {
return def;
}
/**
* Returns the character's mental value.
* @return the character's mental value.
*/
public int getMental() {
return mental;
}
/**
* Returns the Being's current Exp
* @return the Being's current Exp
*/
//TODO : implement exp
public int getExp() {
return 50;
}
/**
* Returns the Being's maxExp
* @return Returns the Being's maxExp
*/
//TODO : implement maxExp
public int getMaxExp() {
return 100;
}
/**
* The being's hitbox.
* @return the beings hitbox
*/
public Zone getHitbox() {
return hitbox.clone();
}
/**
* Applies the given damage to the Being. Return a boolean meaning if this is dead or not.
* @param damage the damage to apply. A negative number will heal.
* @return true if this is dead. false otherwise.
*/
public boolean takeDamage(int damage){
HP=Math.min(maxHP, Math.max(HP-damage, 0));
if (HP==0){
Event event = new ToServerDeathEvent(this.getID());
Logger LOGGER = Logging.getInstance().getLogger();
NetworkConnection network = DummyLocalGameLoop.getInstance().getNetworkConnection();
if (network==null){
LOGGER.severe("NetworkConnection null, Being"+this.getID()+" can't die");
} else {
LOGGER.info("Death of "+this.getID()+" is send");
network.sendEvent(event);
}
}
return isDead();
}
/**
* Return true is the being is sensible to the given damage
* @param damage the damageType used to check sensibility
* @return true if the being is sensible
*/
public boolean isSensible(DamageType damage){
return dtv.hasType(damage);
}
/**
* Tells if the current being is dead.
* @return true if this is dead. false otherwise.
*/
public boolean isDead(){
return HP==0;
}
@Override
boolean hackGamestate(GameState gameState) throws InterruptedException {
return gameState.addEntity(this);
}
package core.gamestate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
import core.abilities.Ability;
import core.event.Event;
import core.event.ToServerDeathEvent;
import core.zone.Zone;
import gameloop.DummyLocalGameLoop;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayerType;
import logging.Logging;
import map_generation.tiles.TilePropertyVector;
import network.innershell.NetworkConnection;
/**
* This class represents an Entity able to be hit and die.
* @author Guerquin Arnaud
*
*/
public class Being extends Entity {
private static final long serialVersionUID = 1L;
/**
* The Being's current HP. Can't be negative.
*/
private int HP;
/**
* The Being's max HP. maxHP must always be greater or equal than HP.
*/
private int maxHP;
/**
* The character's defense value. Used to protect against physical damage. Must be positive.
*/
private int def;
/**
* The character's mental value. Used to protect against magical damage. Must be positive.
*/
private int mental;
/**
* The Being's Hitbox.
*/
private Zone hitbox;
private DamageTypeVector dtv;
/**
* Being's constructor
* @param name the Being's name.
* @param speciesName the name of the species of the Being.
* @param posX the Being's center X position. Must be in Point Coordinate.
* @param posY the Being's center Y position. Must be in Point Coordinate.
* @param ID the Being's ID.
* @param owner the Being's Relayer ID.
* @param collisionBox the being's collisionBox
* @param tpv the being's tilePropertyVector
* @param visibility the being's visibility
* @param type the being's sprite
* @param triggers the list of all triggers of the being.
* @param HP the being's HP
* @param def the being's def
* @param mental the being's mental
* @param dtv the being's damagePropertyVector
* @param hitbox the being's hitbox.
*/
public Being(String name,String speciesName,int posX,int posY,int ID,int owner,Zone collisionBox