Commit 826cac06 authored by Myriam Begel's avatar Myriam Begel
parents 1844f5d6 0bfba283
# Fichier contenant l'ensemble des species du jeu.
# Nombre de species total
5
6
#Ronflex - Character
C
......@@ -26,7 +26,7 @@ RONFLEX
TEST_ATTACK_ABILITY
TEST_FIREBOLT
NULL_ABILITY
TEST_SUICIDE
TEST_LP_FIREBOLT
#hitbox
R
15
......@@ -75,7 +75,7 @@ CHATROSE
TEST_ATTACK_ABILITY
TEST_FIREBOLT
NULL_ABILITY
TEST_SUICIDE
TEST_LP_FIREBOLT
#hitbox
R
10
......@@ -213,24 +213,41 @@ R
#entityDisplayerType
DIAGLA
#triggers
0
1
USSELESS
DEFAULT_TRIGGER
USSELESS
1
TRIGGER_DEGAT
#abilityList
1
TEST_SUICIDE
#hitbox
#--------------------------------------------------------------------
#FireboltLP- Entity
E
#name
FireBoltLP
#tilePropertyVector
2
SOLID
LIQUID
#collisionBox
R
15
15
#damageTypeVector
#visilibity
R
200
200
#entityDisplayerType
DIAGLA
#triggers
1
FIRE
#baseHP
USSELESS
DEFAULT_TRIGGER
USSELESS
1
#baseDef
0
#baseMental
0
#baseAtk
0
#baseIntel
0
TRIGGER_DEGAT_LP
#abilityList
1
TEST_SUICIDE
......@@ -6,6 +6,7 @@ package core.abilities;
public enum AbilityKey {
NULL_ABILITY,
TEST_ATTACK_ABILITY,
TEST_LP_FIREBOLT,
TEST_FIREBOLT,
TEST_SUICIDE;
}
......@@ -48,13 +48,21 @@ 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,
AbilityIconKeys.FIRE_BOLT_1,
Action.ATTACK,
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_LP_FIREBOLT, new int[]{5,10})))
);
abilityFactory.registerAbilityGenerator(AbilityKey.TEST_LP_FIREBOLT, abilityGenerator);
abilityGenerator =
() -> new Ability(
2000,
AbilityIconKeys.SHIELD_1,
Action.ATTACK,
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_SUICIDE, new int[]{5})))
new ArrayList<>(Arrays.asList(new EffectDescriptor(EffectKey.TEST_SUICIDE, new int[]{})))
);
abilityFactory.registerAbilityGenerator(AbilityKey.TEST_SUICIDE, abilityGenerator);
}
......
package core.abilities.effects;
import core.gamestate.*;
import java.io.Serializable;
import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
......@@ -16,7 +19,13 @@ public class CommonCharacterIDListFilter {
* @param characterIDToIgnore
* @return A CharacterIDListFilter that only remove elements equal to characterIDToIgnore
*/
static UnaryOperator<List<Integer>> allExceptOne(int characterIDToIgnore) {
return charaIDList -> {charaIDList.removeIf(x->(x==characterIDToIgnore));return charaIDList;};
}
static UnaryOperator<List<Integer>> allExceptTwo(int characterIDToIgnore, int characterIDToIgnore2) {
return charaIDList -> {charaIDList.removeIf(x->(x==characterIDToIgnore ||x== characterIDToIgnore2 ));return charaIDList;};
}
}
package core.abilities.effects;
import core.event.AbilityEvent;
import core.event.Event;
import core.gamestate.*;
import core.gamestate.Character;
import core.relayer.Relayer;
......@@ -70,7 +71,9 @@ public class EffectBuilder implements Serializable{
Entity entity = SpeciesArray.create(charac.getX(), charac.getY(), 0, "FireBolt", "FireBolt");
entity.setOrientation(charac.getOrientation());
entity.setSpeed(speed);
entity.setOwned_character(casterCharacterID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
......@@ -84,7 +87,39 @@ public class EffectBuilder implements Serializable{
};
}
Effect suicide(int howMany) {
Effect spawnLPFireBolt(int degat,int speed) {
return new Effect() {
private static final long serialVersionUID = 1L;
@Override
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) {
Character charac = null;
try {
charac = gameContent.getGameState().getCharacter(casterCharacterID);
} catch (EntityNotFoundExeption entityNotFoundExeption) {
entityNotFoundExeption.printStackTrace();
return ;
}
Entity entity = SpeciesArray.create(charac.getX(), charac.getY(), 0, "FireBoltLP", "FireBoltLP");
entity.setOrientation(charac.getOrientation());
entity.setSpeed(speed);
entity.setOwned_character(casterCharacterID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
relayer.start();
//Direction direction = gameContent.getGameState().getCharacter(casterCharacterID).getDirection();
//Entity n_entity = new Entity()
}
};
}
Effect trigger_degat() {
return new Effect() {
private static final long serialVersionUID = 1L;
......@@ -92,23 +127,57 @@ public class EffectBuilder implements Serializable{
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) {
for (Integer targetID : targetCharacterIDList) {
try {
gameContent.getGameState().getCharacter(targetID).takeDamage(Math.max(howMany, 0));
if(gameContent.getGameState().getEntity(casterCharacterID).getOwned_character() != targetID) {
gameContent.getGameState().getCharacter(targetID).takeDamage(Math.max(1, 0));
//hit =true;
}
} catch (EntityNotFoundExeption entityNotFoundExeption) {
entityNotFoundExeption.printStackTrace();
continue;
}
}
}
};
}
Effect trigger_degat_lp() {
return new Effect() {
private static final long serialVersionUID = 1L;
@Override
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) {
boolean hit = false;
for (Integer targetID : targetCharacterIDList) {
try {
if(gameContent.getGameState().getEntity(casterCharacterID).getOwned_character() != targetID) {
gameContent.getGameState().getCharacter(targetID).takeDamage(Math.max(1, 0));
hit =true;
}
} catch (EntityNotFoundExeption entityNotFoundExeption) {
entityNotFoundExeption.printStackTrace();
}
}
if(hit){
Event event = new AbilityEvent(casterCharacterID, 0);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
}
}
};
}
Effect suicide(){
return new Effect(){
private static final long serialVersionUID = 1L;
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) {
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) {
entityNotFoundExeption.printStackTrace();
return;
}
//gameContent.getGameState().getCharacter(casterCharacterID).takeDamage(Math.max(gameContent.getGameState().getCharacter(casterCharacterID).getMaxHP(), 0));
}
}
};
}
......
......@@ -28,6 +28,14 @@ public final class EffectGeneratorRoster {
};
effectFactory.registerEffectGenerator(EffectKey.TEST_ATTACK_EFFECT, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
return eb.suicide();
};
effectFactory.registerEffectGenerator(EffectKey.TEST_SUICIDE, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
int amountOfDamage = parameters.getNthParameter(0);
......@@ -39,9 +47,37 @@ public final class EffectGeneratorRoster {
effectGenerator =
(casterCharacterID, parameters) -> {
int amountOfDamage = parameters.getNthParameter(0);
return eb.suicide(amountOfDamage);
int speed = parameters.getNthParameter(1);
return eb.spawnLPFireBolt(amountOfDamage, speed);
};
effectFactory.registerEffectGenerator(EffectKey.TEST_SUICIDE, effectGenerator);
effectFactory.registerEffectGenerator(EffectKey.TEST_LP_FIREBOLT, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
//int amountOfDamage = parameters.getNthParameter(0);
/*Effect[] arr = {eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.reduceHP(5)))
,eb.suicide()};*/
//return eb.sequence(arr);
return eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.trigger_degat()));
};
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_DEGAT, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
//int amountOfDamage = parameters.getNthParameter(0);
/*Effect[] arr = {eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.reduceHP(5)))
,eb.suicide()};*/
//return eb.sequence(arr);
return eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.trigger_degat_lp()));
};
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_DEGAT_LP, effectGenerator);
}
}
......@@ -10,7 +10,10 @@ package core.abilities.effects;
public enum EffectKey {
TEST_ATTACK_EFFECT(1),
TEST_FIREBOLT(2),
TEST_SUICIDE(1);
TEST_LP_FIREBOLT(2),
TRIGGER_DEGAT(0),
TRIGGER_DEGAT_LP(0),
TEST_SUICIDE(0);
private EffectKey(int parameterNb) {
this.parameterNb = parameterNb;
......
......@@ -35,7 +35,7 @@ public class MoveEvent implements ClientEvent,ServerEvent {
target.setCenter(p);
target.addAction(Action.WALK);
}
else if(target.getSpeciesName().equals("FireBolt")){
else if(target.getSpeciesName().equals("FireBolt") || target.getSpeciesName().equals("FireBoltLP")){
Event event = new AbilityEvent(targetID, 0);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
}
......
......@@ -15,7 +15,7 @@ public class TriggerEvent implements ClientEvent {
*
*/
private static final long serialVersionUID = 1L;
private Trigger trigger;
transient private Trigger trigger;
private int casterID;
public TriggerEvent(Trigger trigger, int casterID) {
......
......@@ -70,7 +70,8 @@ public class Being extends Entity {
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=this.maxHP=HP;
this.HP= HP;
this.maxHP=HP;
this.def=def;
this.mental=mental;
this.dtv=Objects.requireNonNull(dtv).clone();
......
......@@ -52,6 +52,8 @@ public class Entity implements Serializable{
private int speed=5;
private ActionVector actionVector=new ActionVector();
private ArrayList<Trigger> triggers=new ArrayList<>();
private int owned_character = -1;
//TODO Add a use for floors ?
//private int floor = 0;
......@@ -216,7 +218,7 @@ public class Entity implements Serializable{
* Returns the entity's Relayer's ID.
* @return the entity's Relayer's ID.
*/
int getOwner() {
public int getOwner() {
return owner;
}
......@@ -224,7 +226,7 @@ public class Entity implements Serializable{
* Changes the entity's Relayer's ID.
* @param owner the entity's new Relayer's ID.
*/
void setOwner(int owner){
public void setOwner(int owner){
this.owner=owner;
}
......@@ -370,6 +372,13 @@ public class Entity implements Serializable{
public void setRelayer(RelayerEntity relayer){
this.relayer = relayer;
}
public int getOwned_character() {
return owned_character;
}
public void setOwned_character(int owned_character) {
this.owned_character = owned_character;
}
}
\ No newline at end of file
......@@ -78,7 +78,7 @@ public class EntitySpecies{
switch (tile){
case WALL : return false;
case TORCH : return false;
case WATER : return name == "Ponyta";
case WATER : return name.equals("Ponyta");
default : return true;
}
}
......
package core.gamestate;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.function.Supplier;
......
......@@ -32,6 +32,7 @@ public class TileSpriteLinker
spriteMap.put(TileType.STAIRS , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/dungeon_set_1/stairs/stairs2.bmp").getSpriteImage()));
spriteMap.put(TileType.WATER , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Lava.png").getSpriteImage()));
spriteMap.put(TileType.TORCH , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Torch.png").getSpriteImage()));
spriteMap.put(TileType.CHEST , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/chest.png").getSpriteImage()));
}
public Displayable[][] getSpriteOfTile(TileType type, TileSprite.TileAbstractType[][] mask)
......
......@@ -55,6 +55,16 @@ public class FollowerBehaviour {
actions[n] = action;
}
public void SwitchInstructions(int i, int j) {
ArrayList<String> tar = targets.get(i);
String act = actions[i];
targets.set(i,targets.get(j));
actions[i]=actions[j];
targets.set(j,tar);
actions[j]=actions[i];
}
/** Output the list of Character satysfying all the properties in target
* @param A list of Character in which you want to keep only the one satisfying the propertie in target
* @param Target : a list of words, representing a target in an instruction in the IGP Panel
......
......@@ -6,6 +6,8 @@ import core.gamestate.Entity;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.zone.Direction;
import core.gamestate.Character;
import java.util.*;
......@@ -19,5 +21,26 @@ public class IGPEntity extends AbstractEntity {
@Override
public void act() {
FollowerBehaviour fb = behold.GetFollowerBehaviour();
List <Character> chlist = gameState.getAllCharacters();
/* TODO : ne garder que les personnages visibles ? */
Character victim = fb.FindTarget(chlist);
String action = fb.getAction();
switch (action) {
case "attaquer":
System.out.println("Je vais attaquer !");
/* TODO : attaquer victim */
break;
case "proteger":
System.out.println("Je vais te protéger !");
/* TODO : proteger victim */
break;
case "soigner" :
System.out.println("Je vais te soigner !");
/*TODO : Soigner victim */
break;
default:
System.out.println("Je ne fais rien !");
}
}
}
......@@ -172,16 +172,21 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
/**
* ActionListener to parse an instruction.
* Should be modified soon.
* Should be modified soon. Now change the color of the textfield in green if the
* instruction is correct, and in red otherwise.
* TODO We should find some more harmonious colors and add them to GUIColorAndFonts.
*/
private ActionListener parselistener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Script parser = new Script(stringToStream(((JTextField)e.getSource()).getText()));
JTextField btf = (JTextField) e.getSource();
Script parser = new Script(stringToStream(btf.getText()));
if (parser.checkInput()) {
System.out.println("L'instruction est correcte");
// System.out.println("L'instruction est correcte");
btf.setBackground(Color.green);
} else {
System.out.println("Erreur dans l'instruction");
//System.out.println("Erreur dans l'instruction");
btf.setBackground(Color.red);
}
}
};
......
This diff is collapsed.
......@@ -26,6 +26,8 @@ public class Script {
return true;
} catch(ParseException e) {
return false;
} catch(TokenMgrError e) {
return false;
}
}
}
......@@ -47,7 +49,9 @@ TOKEN :
|
< CLASS: "guerrier" | "mage" | "rogue" >
|
< STAT: "PV" | "ATK" | "DEF" | "MANA" | "INT" | "MEN" >
< STAT: "ATK" | "DEF" | "INT" | "MEN" >
|
< HP: "PV" >
|
< CMP: "=" | ">" | "<" | ">=" | "<=" >
|
......@@ -57,11 +61,13 @@ TOKEN :
|
< NOMME: "nomm" ("é" | "e") >
|
< LOGIC: "ET" | "OU" >
< LOGIC: "ET" | "et" | "OU" | "ou" >
|
< NO: "NON" >
< NO: "NON" | "non" >
|
< VAL: ( ["0"-"9"] )+ | ( "1" )? ( ["1"-"9"] )? ["0"-"9"] "%" >
< VAL: ( ["0"-"9"] )+ >
|
< VALPRCT: ( ( ["1"-"9"] )? ["0"-"9"] | "100" ) "%" >
|
< ITEM: "fl" ("è" | "e") "che" | "potion" >
// Il faudra sûrement recenser tous les objets existants.
......@@ -101,11 +107,10 @@ void Instruction() :
/* Traitements divers TODO */
ss += " tout " + t.image;
}
<SPACE> s=Option()
( <SPACE> s=Option()
{
/* Traitements divers TODO. Pour l'instant, on construit
* une simple phrase. <EOF> sera à remplacer par le caractère
* de fin de chaîne (?) */
* une simple phrase. */
ss += " " + s;
}
( <SPACE> t=<LOGIC> <SPACE> s=Option()
......@@ -113,7 +118,7 @@ void Instruction() :
ss += " " + t.image.toLowerCase() + " (" + s;
count = count + 1;
}
)* <EOF>
)* )? <EOF>
{
for (int i=0; i < count; i++) {
ss += ")";
......@@ -144,7 +149,7 @@ String Option() : /* À terme, on renverra peut-être autre chose qu'un String..
return s;
}
|
<AVEC> <SPACE> t=<STAT>
<AVEC> <SPACE> ( t=<STAT>
{
/* Traitements divers TODO */
s = "avec la stat " + t.image;
......@@ -174,6 +179,32 @@ String Option() : /* À terme, on renverra peut-être autre chose qu'un String..
s += t.image;
return s;
}
| <HP> ( <SPACE> )? t=<CMP>
{
/* Traitements divers TODO */
s = "avec la stat PV";
switch (t.image) {
case "=":
case "<":
case ">":
s += t.image;
break;
case "<=":
s += "≤";
break;
case ">=":
s += "≥";
break;
default:
throw new ParseException("Invalid comparator: " + t.image);
}
}
( <SPACE> )? ( t=<VAL> | t=<VALPRCT> ) )
{
/* Traitements divers TODO */
s += t.image;
return s;
}
|
<POSSEDANT> <SPACE> t=<ITEM>
{
......@@ -204,9 +235,9 @@ String Option() : /* À terme, on renverra peut-être autre chose qu'un String..
return ss;
}
|
<NO> s=Option()
<NO> <SPACE> s=Option()
{
s = "non" + s;
s = "non " + s;
return s;
}
}
......
......@@ -19,25 +19,29 @@ public interface ScriptConstants {
/** RegularExpression Id. */
int STAT = 7;
/** RegularExpression Id. */
int CMP = 8;
int HP = 8;
/** RegularExpression Id. */
int AVEC = 9;
int CMP = 9;
/** RegularExpression Id. */
int POSSEDANT = 10;
int AVEC = 10;
/** RegularExpression Id. */
int NOMME = 11;
int POSSEDANT = 11;
/** RegularExpression Id. */
int LOGIC = 12;
int NOMME = 12;
/** RegularExpression Id. */
int NO = 13;
int LOGIC = 13;
/** RegularExpression Id. */
int VAL = 14;
int NO = 14;
/** RegularExpression Id. */
int ITEM = 15;
int VAL = 15;
/** RegularExpression Id. */
int NAME = 16;
int VALPRCT = 16;
/** RegularExpression Id. */
int SPACE = 17;
int ITEM = 17;
/** RegularExpression Id. */
int NAME = 18;
/** RegularExpression Id. */
int SPACE = 19;
/** Lexical state. */
int DEFAULT = 0;
......@@ -52,13 +56,15 @@ public interface ScriptConstants {
"<CTR>",
"<CLASS>",
"<STAT>",
"\"PV\"",
"<CMP>",
"\"avec\"",
"<POSSEDANT>",
"<NOMME>",
"<LOGIC>",
"\"NON\"",
"<NO>",
"<VAL>",
"<VALPRCT>",
"<ITEM>",
"<NAME>",
"<SPACE>",
......
......@@ -26,7 +26,7 @@ import core.abilities.AbilityKey;
public class Test {
public static void main(String argv[]) throws ParseException {
System.out.println("Bonjour");
Script parser = new Script(stringToStream("attaque ennemi (avec PV < 50% ET (avec DEF < 50 OU possedant potion)) OU avec DEF = 50"));
Script parser = new Script(stringToStream("attaque ennemi (avec PV < 50% ET (avec DEF < 50 OU non possedant potion)) OU avec DEF = 50"));
parser.Instruction();
Zone zone = EmptyZone.getEmptyZone();
TilePropertyVector tpv = new TilePropertyVector();
......@@ -62,7 +62,7 @@ public class Test {
target2.add("MEN");
target2.add("=");
target2.add("20");
fb.setNthInstruction(target2,"pasbouh",0);
fb.setNthInstruction(target2,"proteger",0);
ArrayList<String> target = new ArrayList<String>();
target.add("CTR");
target.add("ennemi");
......@@ -85,7 +85,7 @@ public class Test {
target.add("%");
target.add("100");
target.add("EOF");
fb.setNthInstruction(target,"bouh",1);
fb.setNthInstruction(target,"attaquer",1);
BehaviourHolder bh = BehaviourHolder.getInstance();
bh.SetFollowerBehaviour(fb);
Character ch = bh.GetFollowerBehaviour().FindTarget(chlist);
......
......@@ -67,6 +67,11 @@ public final class MapBuilder implements Serializable{
RoomBuilder end=roomTree.getMostFarNode();
end.setType(RoomType.END);
}
private void generateChestRooms(){
for (RoomBuilder room : roomTree.getDeadEnds()) {
room.setType(RoomType.CHESTS);
}
}
public void setPositionPlayerAtStart(MapPoint positionPlayerAtStart) {
this.positionPlayerAtStart = positionPlayerAtStart;
}
......@@ -87,6 +92,7 @@ public final class MapBuilder implements Serializable{
* @return The map
*/
public Map build(){
generateChestRooms();
generateEndRoom();