On peut ajouter une condition à notre arbre d'action (uniquement une condition sur le bouclier pour le moment) - Modification de la classe Condition pour gérer les conditions sur les robots ennemis - On peut désormais ajouter une condition uniquement sur les actions qui acceptent les liens avec d'autres actions

master
clmaisonha 5 years ago
parent d451659c97
commit 8169ee92ae

@ -1,24 +1,32 @@
class AddNode extends Phaser.Scene {
constructor(game, selected) {
constructor(father, game, selected) {
super('AddNode');
this.game = game;
this.father = father;
this.gameR = game;
this.selected = selected;
this.lCategory = [];
}
create() {
create(son) {
let height = HEIGHT_WINDOW / (4 / 3);
this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5);
this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5);
this.createButtonCancel();
this.createButtonAdd();
console.log(son);
this.createButtonAdd(son);
}
addButton(x, y, width, height, texture, category = new Category()) {
addButton(x, y, width, height, texture, category = new Category(), value) {
let btn = this.createButton(x, y, width, height, texture);
btn.on('pointerdown', () => this.click(btn, category, value));
return btn;
}
createButton(x, y, width, height, texture) {
let btn = this.add.image(x, y, texture).setOrigin(0.5, 0.5).setInteractive();
btn.on('pointerover', () => btn.setFrame(1));
btn.on('pointerout', () => btn.setFrame(0));
btn.on('pointerdown', () => this.click(btn, category));
btn.displayHeight = height;
if (width === null) {
@ -29,12 +37,18 @@ class AddNode extends Phaser.Scene {
return btn;
}
click(btn, category) {
click(btn, category, value) {
if (btn.isTinted) {
category.remove(btn);
} else {
category.add(btn);
category.add(btn, value);
}
}
newCategory(name, single, obligatory) {
let c = new Category(name, single, obligatory);
this.lCategory.push(c);
return c;
}
addTitle(x, y, title) {
@ -44,22 +58,27 @@ class AddNode extends Phaser.Scene {
}
createButtonCancel() {
this.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'cancel')
this.createButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'cancel')
.on('pointerdown', () => this.cancel());
}
createButtonAdd() {
this.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add')
.on('pointerdown', () => this.add());
createButtonAdd(son) {
this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add')
.on('pointerdown', () => son.addNode());
}
add() {
verifyCategory() {
for (let i = 0; i < this.lCategory.length; i++) {
if (!this.lCategory[i].validate()) {
return false;
}
}
return true;
}
cancel() {
this.scene.resume('Game');
this.scene.stop('AddNode');
this.game.scene.remove('AddNode');
this.father.scene.remove('AddNode');
}
}

File diff suppressed because one or more lines are too long

@ -1,12 +1,11 @@
class AddAttack extends AddNode {
constructor(game, selected) {
super(game, selected);
this.game = game;
constructor(father, game, selected) {
super(father, game, selected);
}
create() {
console.log("ATTACK");
super.create();
super.create(this);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : ATTACK", "AJOUTER ACTION : ATTAQUE"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot');

@ -1,19 +1,30 @@
class AddCondition extends AddNode {
constructor(game, selected) {
super(game, selected);
this.game = game;
this.selected = selected;
constructor(father, game, selected) {
super(father, game, selected);
}
create() {
super.create();
super.create(this);
console.log("CONDITION");
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : CONDITION", "AJOUTER ACTION : CONDITION"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
let c1 = new Category('target', true);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', c1);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'myself', c1);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 7), selectWord("TARGET FILTERS (OPTIONAL)", "FILTRES CIBLES (FACULTATIF)"));
let c1 = super.newCategory('target', true, true);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', c1, false);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'myself', c1, true);
let c2 = super.newCategory('shield', true, true);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shield0', c2, 0);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shield33', c2, 1 / 3);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'shield66', c2, 2 / 3);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'shield100', c2, 1);
}
addNode() {
if (super.verifyCategory()) {
console.log(this.lCategory[0].getValue());
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0));
super.cancel();
}
}
}

@ -1,12 +1,11 @@
class AddMove extends AddNode {
constructor(game, selected) {
super(game, selected);
this.game = game;
constructor(father, game, selected) {
super(father, game, selected);
}
create() {
console.log("MOVE");
super.create();
super.create(this);
let c1 = new Category('direction', true);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : MOVE", "AJOUTER ACTION : DEPLACEMENT"));
super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?"));

@ -1,22 +1,39 @@
class Category {
constructor(name = 'undefined', single = true) {
constructor(name = 'undefined', single = true, obligatory = true) {
this.name = name;
this.single = single;
this.lBtn = [];
this.lValue = [];
this.obligatory = obligatory;
}
add(btn) {
add(btn, value) {
if (this.lBtn.length !== 0 && this.single) {
this.lBtn[0].clearTint();
this.lValue = [];
this.lBtn = [];
}
this.lValue.push(value);
this.lBtn.push(btn);
btn.tint = 0xEFD807;
}
getValue() {
if (this.single) {
return this.lValue[0];
}
return this.lValue;
}
validate() {
return !(this.lBtn.length === 0 && this.obligatory);
}
remove(btn) {
if (this.lBtn.indexOf(btn) !== -1) {
this.lBtn.splice(this.lBtn.indexOf(btn), 1);
let id = this.lBtn.indexOf(btn);
if (id !== -1) {
this.lBtn.splice(id, 1);
this.lValue.splice(id, 1);
}
btn.clearTint();
}

@ -1,10 +1,10 @@
class Condition {
constructor(target, shieldFilter = false, rangeFilter = false, shield, range) { //shieldFilter : true/false - rangeFilter : true/false
constructor(myself, shieldFilter = false, rangeFilter = false, shield, range) { //shieldFilter : true/false - rangeFilter : true/false
this.shieldFilter = shieldFilter;
this.rangeFilter = rangeFilter;
this.shield = shield;
this.range = range;
this.target = target;
this.myself = myself; //true = myself / false = enemyBot;
this.lNode = [];
}
@ -26,7 +26,7 @@ class Condition {
doCondition(robot) {
if (this.shieldFilter) {
if (this.shieldCondition()) {
if (this.shieldCondition(robot)) {
if (this.rangeFilter) {
return this.rangeCondition(robot);
}
@ -39,14 +39,23 @@ class Condition {
}
rangeCondition(robot) {
return robot.calcDistance(this.target) <= this.range;
if (this.myself) {
return true;
}
return robot.calcDistance(robot.target) <= this.range;
}
shieldCondition() {
if (this.target.shield.value / this.target.shield.valueMax <= this.shield) {
return true;
shieldCondition(robot) {
if (this.myself) {
return this.verifyShield(robot);
} else {
return this.verifyShield(robot.target);
}
return false;
}
verifyShield(target) {
return target.shield.value / target.shield.valueMax <= this.shield;
}
clearNodes() {

@ -24,7 +24,7 @@ class Game extends Phaser.Scene {
let robot = new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, 'myself');
let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', robot, true, false, 1 / 3, 0);
let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', true, true, false, 1 / 3, 0);
condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 600, this, 'move', false));
condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack'))
this.tree.addRect(condition);
@ -157,7 +157,7 @@ class Game extends Phaser.Scene {
clickPlus() {
console.log("PLUS");
this.father.scene.add('PlusNode', new PlusNode(this.father, this.selected));
this.father.scene.add('PlusNode', new PlusNode(this.father, this, this.selected));
this.scene.launch('PlusNode');

@ -1,8 +1,11 @@
class PlusNode extends Phaser.Scene {
constructor(game, selected) {
constructor(father, game, selected) {
super('PlusNode');
this.game = game;
this.father = father;
this.gameR = game;
this.selected = selected;
console.log(this.gameR);
}
create() {
@ -46,18 +49,18 @@ class PlusNode extends Phaser.Scene {
click(action) {
switch (action.toString()) {
case 'attack':
this.game.scene.add('AddNode', new AddAttack(this.game, this.selected))
this.father.scene.add('AddNode', new AddAttack(this.father, this.gameR, this.selected))
break;
case 'move':
this.game.scene.add('AddNode', new AddMove(this.game, this.selected))
this.father.scene.add('AddNode', new AddMove(this.father, this.gameR, this.selected))
break;
case 'condition':
this.game.scene.add('AddNode', new AddCondition(this.game, this.selected))
this.father.scene.add('AddNode', new AddCondition(this.father, this.gameR, this.selected))
break;
}
this.scene.launch('AddNode');
this.scene.stop('PlusNode');
this.game.scene.remove('PlusNode');
this.father.scene.remove('PlusNode');
}
createButton() {
@ -74,6 +77,6 @@ class PlusNode extends Phaser.Scene {
cancel() {
this.scene.resume('Game');
this.scene.stop('PlusNode');
this.game.scene.remove('PlusNode');
this.father.scene.remove('PlusNode');
}
}

@ -26,7 +26,7 @@ class RectangleNode {
this.scene = scene;
this.line = scene.add.graphics();
let line;
if (option[0].name.toString().toLowerCase() === 'myself') {
if (option[0]) {
line = 0;
} else {
line = 1;
@ -93,6 +93,10 @@ class RectangleNode {
return this.rect.x;
}
getY() {
return this.rect.y;
}
addRect(node) {
if (this.canAddNode === true) {
this.lRect.push(node);

@ -20,7 +20,7 @@ class Robot {
this.lNode = [];
let condition = new Condition(this, true, false, 0.5, 0);
let condition = new Condition(true, true, false, 0.5, 0);
condition.addNode(new Move(false));
this.addNode(condition);
this.addNode(new Attack());

Loading…
Cancel
Save