Commit f566545c authored by Ghyselen's avatar Ghyselen

Adding link beetween a parsed propriety and entities in the game states that...

Adding link beetween a parsed propriety and entities in the game states that satisfying this propriety
parent 47a1b81d
package ingame_programming;
import java.io.InputStream;
import java.util.*;
import core.gamestate.GameState;
import core.gamestate.Character;
/**
* This class is used to register data from IGPpanel.
* @author William Babonnaud
*/
public class FollowerBehaviour {
/** Number of rules to consider */
private int numberOfRules;
/** Array for store instructions as InputStream */
private InputStream[] instructions;
/** Number of rules to consider */
private int numberOfRules;
/** Array for store targets as ArrayListString */
private ArrayList<ArrayList<String>> targets;
/** Constructor */
public FollowerBehaviour(int nRules) {
numberOfRules = nRules;
instructions = new InputStream[numberOfRules];
}
private InputStream[] actions;
/** Constructor */
public FollowerBehaviour(int nRules) {
numberOfRules = nRules;
targets = new ArrayList<ArrayList<String>>(nRules);
actions = new InputStream[nRules];
}
/**
* Set instruction value, given its position in the rules array.
* @param the InputStream value to set
* @param an integer strictly lesser than numberOfRules
*/
public void setNthInstruction(InputStream instr, int n) {
instructions[n] = instr;
}
/**
* Set instruction value, given its position in the rules array.
* @param the InputStream value to set
* @param an integer strictly lesser than numberOfRules
*/
public void setNthInstruction(ArrayList<String> target,InputStream action, int n) {
targets.set(n,target);
actions[n] = action;
}
private List<Character> findCharacter(List<Character> list, ArrayList<String> target) {
switch (target.get(0)) {
case "ET":
int count1 = 1;
target.remove(0);
target.remove(0);
ArrayList<String> target1 = new ArrayList<String>();
while (count1 > 0) {
String s = target.get(0);
switch (s) {
case "(":
target.remove(0);
count1 = count1 + 1;
target1.add(s);
break;
case ")":
target.remove(0);
count1 = count1 - 1;
if (count1 > 0) {
target1.add(s);
}
break;
default :
target1.add(s);
target.remove(0);
}
}
target1.add("EOF");
return findCharacter(findCharacter(list,target1),target);
case "OU":
int count2 = 1;
target.remove(0);
target.remove(0);
ArrayList<String> target2 = new ArrayList<String>();
while (count2 > 0) {
String s = target.get(0);
switch (s) {
case "(":
target.remove(0);
count2 = count2 + 1;
target2.add(s);
break;
case ")":
target.remove(0);
count2 = count2 - 1;
if (count2 > 0) {
target2.add(s);
}
break;
default :
target2.add(s);
target.remove(0);
}
}
target2.add("EOF");
List<Character> l1 = findCharacter(list,target2);
List<Character> l2 = findCharacter(list,target);
l1.addAll(l2);
return l1;
case "NO":
target.remove(0);
List<Character> l3 = findCharacter(list,target);
list.removeAll(l3);
return list;
case "CTR":
target.remove(0);
String s = target.get(0);
target.remove(0);
switch(s) {
case "humain" :
/* TODO, je ne sais pas ce qu'est un "humain" pour l'instant" */
break;
case "allie" :
/* Je n'ai pas encore trouvé l'information, mais je pense que la faction allié est la 1, et la faction ennemie est la 0 */
List<Character> l4 = new ArrayList<Character>();
for (Character ch : list) {
if (ch.getFaction() == 1) {
l4.add(ch);
}
}
return findCharacter(l4,target);
case "ennemi" :
/* Je n'ai pas encore trouvé l'information, mais je pense que la faction allié est la 1, et la faction ennemie est la 0 */
List<Character> l5 = new ArrayList<Character>();
for (Character ch : list) {
if (ch.getFaction() == 0) {
l5.add(ch);
}
}
return findCharacter(l5,target);
default :
return findCharacter(list,target);
}
return findCharacter(list,target);
case "CLASS" :
switch (target.get(1)) {
case "guerrier" :
case "mage" :
case "rogue" :
/* TODO, je ne sais pas encore comment trouvé la classe d'un character */
break;
}
return list;
case "AVEC" :
List<Character> l6 = new ArrayList<Character>();
for (Character ch : list) {
int stat = 0;
switch (target.get(1)) {
case "PV" :
stat = ch.getHP();
break;
case "ATK" :
stat = ch.getAtk();
break;
case "DEF" :
stat = ch.getDef();
break;
case "MANA" :
/* TODO : pour l'instant le mana n'est pas implémenté dans le jeu ? */
break;
case "INT" :
stat = ch.getIntel();
break;
case "MEN" :
stat = ch.getMental();
break;
default :
stat = 0;
}
int limit = 0;
switch (target.get(3)) {
case "%" :
limit = ((ch.getMaxHP())*(Integer.parseInt(target.get(4))))/100;
break;
default :
limit = Integer.parseInt(target.get(3));
}
switch (target.get(2)) {
case "=":
if (stat == limit) {
l6.add(ch);
}
break;
case ">":
if (stat > limit) {
l6.add(ch);
}
break;
case "<":
if (stat < limit) {
l6.add(ch);
}
break;
case ">=":
if (stat >= limit) {
l6.add(ch);
}
break;
case "<=":
if (stat <= limit) {
l6.add(ch);
}
break;
default :
}
}
return l6;
case "POSSEDANT" :
/* TODO, je ne sais pas encore comment les objets sont gérés */
return list;
case "NOMME" :
List<Character> l7 = new ArrayList<Character>();
for (Character ch : list) {
if (target.get(1) == ch.getName()) {
l7.add(ch);
}
}
return l7;
default :
return list;
}
}
}
......@@ -9,6 +9,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.util.*;
/** First iteration of the panel for ingame programming
Created by Alexis Ghyselen **/
......@@ -202,7 +203,10 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
public FollowerBehaviour generateFollower() {
FollowerBehaviour fob = new FollowerBehaviour(nbf);
for(int i = 0; i < nbf; i++) {
fob.setNthInstruction(stringToStream(prflabel[i].getText()), i);
/* fob.setNthInstruction(stringToStream(prflabel[i].getText()), i); */
/* TODO : Transform prflabel[i] into a simplified ArrayList<String> and an InputStream representing only the action */
ArrayList<String> list = new ArrayList<String>();
fob.setNthInstruction(list,stringToStream(prflabel[i].getText()),i);
}
return fob;
}
......
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