Commit 8c3451a5 authored by Remy Garnier's avatar Remy Garnier
Browse files

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

parents 04f27257 d3d7651f
......@@ -17,6 +17,12 @@ build
org.scala-ide.sdt.core/META-INF/MANIFEST.MF
org.scala-ide.sdt.update-site/site.xml
# Fichiers générés par JavaCC
src/ingame_programming/ParseException.java
src/ingame_programming/Token*
src/ingame_programming/Script*.java
src/ingame_programming/SimpleCharStream.java
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
......
......@@ -7,7 +7,7 @@ PACKAGEDIRS = ${shell find . -iname '*.java' | sed 's/\.\/\|[^/]*.java//g' | sor
#TESTCLASS = ${shell find . -name *Test.java | sed 's/.\/src\/\|.java//g' | sed 's/\//./g'}
PARSER = ${shell find . -name *.jj | sed "s/\.\///"}
PARSER = src/ingame_programming/Script.jj
# Java compiler
JAVAC = javac
......@@ -70,7 +70,7 @@ buildplay: all
# Generate parser
genpars: $(PARSER)
cd `dirname $<` ;find . -name *.jj | while read i; do java -cp lib/javacc-6.1.2.jar javacc $$i; done
@cd `dirname $<` ;find . -name *.jj | while read i; do java -cp lib/javacc-6.1.2.jar javacc $$i; done
clean :
rm -rf $(BIN)
......
......@@ -47,6 +47,10 @@ public class AIControler {
case Straight:
ai = new StraightEntity(gameContent,dmr);
break;
case Boss:
ai = new BossEntity(gameContent,dmr);
break;
default:
LOGGER.severe("Trying to instanciate unrecognized type of AI.");
break;
......
......@@ -14,6 +14,7 @@ import java.util.logging.Logger;
import static java.lang.Math.abs;
import static java.lang.Math.random;
import static java.lang.Math.sqrt;
/**
......@@ -75,14 +76,16 @@ public abstract class AbstractEntity extends Thread {
* @return the index of the victim in the EntityList.
*/
public int Choose_victim(){
float dmin =0 ;
float dmax = 100000;
double dmin =0 ;
double dmax = 32*15; // tiles of length 32 : so 15 tiles
int victim = -1;
List<Entity> entityList=gameState.getAllEntities();
for (int i=0;i<entityList.size();i++) {
Entity act_entity = entityList.get(i);
if (act_entity.getFaction() == 1) { // if act_entity is a player
float d = (act_entity.getX() - this.relayer.getCharacter().getX())*(act_entity.getX() - this.relayer.getCharacter().getX()) + (act_entity.getY() - this.relayer.getCharacter().getY())*(act_entity.getY() - this.relayer.getCharacter().getY());
//euclidian distance and distance of manathan
//double d = sqrt((act_entity.getX() - this.relayer.getCharacter().getX())*(act_entity.getX() - this.relayer.getCharacter().getX()) + (act_entity.getY() - this.relayer.getCharacter().getY())*(act_entity.getY() - this.relayer.getCharacter().getY()));
double d = abs( (act_entity.getX() - this.relayer.getCharacter().getX()) )+abs(act_entity.getY() - this.relayer.getCharacter().getY());
if (d<dmax) {
if (dmin == 0) {
dmin = d;
......@@ -99,76 +102,21 @@ public abstract class AbstractEntity extends Thread {
return(victim);
}
public double Distance_to_victim(Entity victim){
//euclidian distance and distance of manathan
//double d = sqrt((victim.getX() - this.relayer.getCharacter().getX())*(victim.getX() - this.relayer.getCharacter().getX()) + (victim.getY() - this.relayer.getCharacter().getY())*(victim.getY() - this.relayer.getCharacter().getY()));
double d = abs( (victim.getX() - this.relayer.getCharacter().getX()) )+abs(victim.getY() - this.relayer.getCharacter().getY());
return(d);
}
/**
* Given a target return the next move to do.
*
* @param victim_i the pointer to the victim
*/
public void move_to_entity(Entity victim) {
// X is UP-DOWN
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();
if(abs(Delta_x)>abs(Delta_y)){
if(Delta_x>0) {
this.relayer.move(Direction.UP);
if(px == this.relayer.getCharacter().getX()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.println("pas mal");
}
}
}
else {
this.relayer.move(Direction.DOWN);
if(px == this.relayer.getCharacter().getX()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.println("pas mal");
}
}
}
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
this.relayer.move(Direction.LEFT);
if(py == this.relayer.getCharacter().getY()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.UP);
}
else{
this.relayer.move(Direction.DOWN);
}
}
}
else{
this.relayer.move(Direction.RIGHT);
if(py == this.relayer.getCharacter().getY()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.UP);
}
else{
this.relayer.move(Direction.DOWN);
}
}
}
}
}
public void move_to_victim(Entity victim_i){
List<Entity> entityList=gameState.getAllEntities();
......@@ -196,6 +144,33 @@ public abstract class AbstractEntity extends Thread {
}
public void run_from_victim(Entity victim_i){ //same then move_to_victim we just inverted the directions
List<Entity> entityList=gameState.getAllEntities();
Entity victim= (victim_i);
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
if(abs(Delta_x)>abs(Delta_y)){
if(Delta_x>0) {
this.relayer.move(Direction.DOWN);
}
else {
this.relayer.move(Direction.UP);
}
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
this.relayer.move(Direction.RIGHT);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
public void random_move(){
double r = random();
if(r<0.25){
......@@ -219,10 +194,78 @@ public abstract class AbstractEntity extends Thread {
*
* This is the only function that have to be overriden by specifics AIs.
*/
public void act() {
public void move_and_shoot(Entity victim){
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
int distance_to_shoot = 24; // distance of tolerance of alignment
if(abs(Delta_x)<distance_to_shoot){ //we are well enough aligned to shoot
if(Delta_y<0){ // choose side to shoot
if(relayer.getCharacter().getDirection()==Direction.RIGHT){ //right side, we shoot
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.RIGHT); //wrong side, we turn
}
}
else{
if(relayer.getCharacter().getDirection()==Direction.LEFT){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
else if(abs(Delta_y)<distance_to_shoot){
if(Delta_x<0){
if(relayer.getCharacter().getDirection()==Direction.DOWN){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.DOWN);
}
}
else{
if(relayer.getCharacter().getDirection()==Direction.UP){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.UP);
}
}
}
else{ // we have to move to be align
if(abs(Delta_x)<abs(Delta_y)){
if(Delta_x<0){
this.relayer.move(Direction.DOWN);
}
else{
this.relayer.move(Direction.UP);
}
}
else{
if(Delta_y<0){
this.relayer.move(Direction.RIGHT);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
}
public void act() {
}
/**
* Function called by the core/game_loop (call the function start() not run() because run is sequential) to launch the effective AI.
*/
......
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 BossEntity 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 BossEntity(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) {
Entity victim = this.gameState.getAllEntities().get(victim_i);
/* d_min minimum distance to not run away
* dmax maximum distance to not get closer*/
double d_min = 32*3; // tiles of length 32 : so 3 and 7 tiles
double d_max = 32*14;
double d = Distance_to_victim(victim);
if(d<d_min){
this.run_from_victim(victim);
}
else {
if (d > d_max) {
this.move_to_victim(victim);
}
else{
move_and_shoot(victim);
}
}
}
else{
Direction dir = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(Direction.NONE);
}
}
else{this.random_move();}
}
// attack
}
}
......@@ -8,5 +8,6 @@ public enum EnumBehaviourType {
Basic,
Defender,
Follower,
Boss,
Straight;
}
......@@ -41,6 +41,7 @@ public class StraightEntity extends AbstractEntity {
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(gameState.getAllEntities().get(this.Choose_victim()).getCollisionBox())) {
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(0); // if we are close enough we fight and don't move
}
else {
this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
......@@ -53,14 +54,15 @@ public class StraightEntity extends AbstractEntity {
else{
Direction d = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.75){
this.relayer.move(d);
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(d);
}
}
else{this.random_move();}
}
// 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
......@@ -72,7 +72,7 @@ CHATROSE
0
#abilityList
4
TEST_ATTACK_ABILITY
MENTALI_ATTACK
TEST_FIREBOLT
NULL_ABILITY
TEST_LP_FIREBOLT
......@@ -90,7 +90,7 @@ WATER
LIGHT
DARK
#baseHP
10
200
#baseDef
1
#baseMental
......
......@@ -8,5 +8,6 @@ public enum AbilityKey {
TEST_ATTACK_ABILITY,
TEST_LP_FIREBOLT,
TEST_FIREBOLT,
MENTALI_ATTACK,
TEST_SUICIDE;
}
......@@ -33,13 +33,29 @@ public class AbilityRoster {
abilityGenerator =
() -> new Ability(
1200,
100,
AbilityIconKeys.SWORD_RED_1,
Action.ATTACK,
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_ATTACK_EFFECT, new int[]{2})))
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_ATTACK_EFFECT, new int[]{1})))
);
abilityFactory.registerAbilityGenerator(AbilityKey.TEST_ATTACK_ABILITY, abilityGenerator);
abilityGenerator =
() -> new Ability(
2000,
AbilityIconKeys.MENTALI_ATTACK,
Action.ATTACK,
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.MENTALI_ATTACK_DAMAGE, new int[]{10000,32})))
);
abilityFactory.registerAbilityGenerator(AbilityKey.MENTALI_ATTACK, abilityGenerator);
abilityGenerator =
() -> new Ability(
2000,
......@@ -48,6 +64,7 @@ public class AbilityRoster {
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_FIREBOLT, new int[]{5,10})))
);
abilityFactory.registerAbilityGenerator(AbilityKey.TEST_FIREBOLT, abilityGenerator);
abilityGenerator =
() -> new Ability(
2000,
......
package core.abilities.effects;
import core.zone.Translation;
/**
* Created by dupriez on 22/12/15.
*
......@@ -28,6 +30,23 @@ public final class EffectGeneratorRoster {
};
effectFactory.registerEffectGenerator(EffectKey.TEST_ATTACK_EFFECT, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
int amountOfDamage = parameters.getNthParameter(0);
int range = parameters.getNthParameter(1);
return eb.affectZone((character -> (character.getHitbox().clone().translate(Translation.construct(character.getDirection(),range)) ) ),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.reduceHP(amountOfDamage)));
};
effectFactory.registerEffectGenerator(EffectKey.MENTALI_ATTACK_DAMAGE, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
return eb.suicide();
......
......@@ -14,7 +14,8 @@ public enum EffectKey {
TEST_SUICIDE(1),
TRAP_TRIGGER(0),
TRIGGER_DEGAT(0),
TRIGGER_DEGAT_LP(0);
TRIGGER_DEGAT_LP(0),
MENTALI_ATTACK_DAMAGE(2);
private EffectKey(int parameterNb) {
this.parameterNb = parameterNb;
......
......@@ -8,6 +8,6 @@ package core.gamestate;
public enum Action {
WALK,
ATTACK,
HIT
;
HIT,
NONE
}
......@@ -140,6 +140,9 @@ public class Being extends Entity {
* @return true if this is dead. false otherwise.
*/
public boolean takeDamage(int damage){
if(damage>0) {
addAction(Action.HIT);
}
HP=Math.min(maxHP, Math.max(HP-damage, 0));
if (HP==0){
Event event = new ToServerDeathEvent(this.getID());
......
......@@ -9,10 +9,12 @@ import core.relayer.*;
import artificial_intelligence.AIControler;
import artificial_intelligence.AIEntities.EnumBehaviourType;
import java.io.InterruptedIOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Semaphore;
/**
......@@ -31,6 +33,7 @@ public class GameContent implements Serializable{
private GameState gameState;
private ArrayList<Character> players;
private ArrayList<Entity> triggerEntities=new ArrayList<>();
private Semaphore sem = new Semaphore(1);
public GameContent(Map map,int playersNumber) throws InterruptedException {
this.map=Objects.requireNonNull(map);
......@@ -41,7 +44,7 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......@@ -103,18 +106,26 @@ public class GameContent implements Serializable{
}
public void applyTrigger(NetworkConnection networkConnection) throws InterruptedException {
sem.acquire();
for(Entity e:triggerEntities){
e.checkTrigger(this,networkConnection);
}
sem.release();
}
public void addTriggerToCheck(Entity e) {
public void addTriggerToCheck(Entity e) throws InterruptedException
{
sem.acquire();
triggerEntities.add(e);
sem.release();
}
public void removeTriggerToCheck(Entity e) {
public void removeTriggerToCheck(Entity e) throws InterruptedException
{
sem.acquire();
triggerEntities.remove(e);
sem.release();
}
public boolean checkStrairs(Map newMap,NetworkConnection networkConnection) throws InterruptedException {
......@@ -132,13 +143,16 @@ public class GameContent implements Serializable{
this.map=Objects.requireNonNull(map);
this.gameState=new GameState();
AIControler.killAll();
sem.acquire();
triggerEntities.clear();
sem.release();
if(!server)
Relayers.resetRelayers();
if(map.getEntities()!=null) {
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Basic);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......
......@@ -11,6 +11,7 @@ public enum AbilityIconKeys {
VIAL_RED_1,
FIRE_BOLT_1,
FROST_BOLT_1,
MENTALI_ATTACK,
EXPLOSION_1,
NULL_ABILITY,