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 { class AddNode extends Phaser.Scene {
constructor(game, selected) { constructor(father, game, selected) {
super('AddNode'); super('AddNode');
this.game = game; this.father = father;
this.gameR = game;
this.selected = selected; this.selected = selected;
this.lCategory = [];
} }
create() { create(son) {
let height = HEIGHT_WINDOW / (4 / 3); 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, 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.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5);
this.createButtonCancel(); 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(); let btn = this.add.image(x, y, texture).setOrigin(0.5, 0.5).setInteractive();
btn.on('pointerover', () => btn.setFrame(1)); btn.on('pointerover', () => btn.setFrame(1));
btn.on('pointerout', () => btn.setFrame(0)); btn.on('pointerout', () => btn.setFrame(0));
btn.on('pointerdown', () => this.click(btn, category));
btn.displayHeight = height; btn.displayHeight = height;
if (width === null) { if (width === null) {
@ -29,14 +37,20 @@ class AddNode extends Phaser.Scene {
return btn; return btn;
} }
click(btn, category) { click(btn, category, value) {
if (btn.isTinted) { if (btn.isTinted) {
category.remove(btn); category.remove(btn);
} else { } 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) { addTitle(x, y, title) {
let sizeText = HEIGHT_WINDOW / 12; let sizeText = HEIGHT_WINDOW / 12;
let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"};
@ -44,22 +58,27 @@ class AddNode extends Phaser.Scene {
} }
createButtonCancel() { 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()); .on('pointerdown', () => this.cancel());
} }
createButtonAdd() { createButtonAdd(son) {
this.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add') this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add')
.on('pointerdown', () => this.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() { cancel() {
this.scene.resume('Game'); this.scene.resume('Game');
this.scene.stop('AddNode'); 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 { class AddAttack extends AddNode {
constructor(game, selected) { constructor(father, game, selected) {
super(game, selected); super(father, game, selected);
this.game = game;
} }
create() { create() {
console.log("ATTACK"); 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, selectWord("ADD NODE : ATTACK", "AJOUTER ACTION : ATTAQUE"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?")); 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'); super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot');

@ -1,19 +1,30 @@
class AddCondition extends AddNode { class AddCondition extends AddNode {
constructor(game, selected) { constructor(father, game, selected) {
super(game, selected); super(father, game, selected);
this.game = game;
this.selected = selected;
} }
create() { create() {
super.create(); super.create(this);
console.log("CONDITION"); 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, selectWord("ADD NODE : CONDITION", "AJOUTER ACTION : CONDITION"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?")); super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
let c1 = new Category('target', true); super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 7), selectWord("TARGET FILTERS (OPTIONAL)", "FILTRES CIBLES (FACULTATIF)"));
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', c1); let c1 = super.newCategory('target', true, true);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'myself', c1); 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 { class AddMove extends AddNode {
constructor(game, selected) { constructor(father, game, selected) {
super(game, selected); super(father, game, selected);
this.game = game;
} }
create() { create() {
console.log("MOVE"); console.log("MOVE");
super.create(); super.create(this);
let c1 = new Category('direction', true); 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 / 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 ?")); super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?"));

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

@ -1,10 +1,10 @@
class Condition { 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.shieldFilter = shieldFilter;
this.rangeFilter = rangeFilter; this.rangeFilter = rangeFilter;
this.shield = shield; this.shield = shield;
this.range = range; this.range = range;
this.target = target; this.myself = myself; //true = myself / false = enemyBot;
this.lNode = []; this.lNode = [];
} }
@ -26,7 +26,7 @@ class Condition {
doCondition(robot) { doCondition(robot) {
if (this.shieldFilter) { if (this.shieldFilter) {
if (this.shieldCondition()) { if (this.shieldCondition(robot)) {
if (this.rangeFilter) { if (this.rangeFilter) {
return this.rangeCondition(robot); return this.rangeCondition(robot);
} }
@ -39,14 +39,23 @@ class Condition {
} }
rangeCondition(robot) { rangeCondition(robot) {
return robot.calcDistance(this.target) <= this.range; if (this.myself) {
return true;
}
return robot.calcDistance(robot.target) <= this.range;
} }
shieldCondition() { shieldCondition(robot) {
if (this.target.shield.value / this.target.shield.valueMax <= this.shield) { if (this.myself) {
return true; return this.verifyShield(robot);
} else {
return this.verifyShield(robot.target);
} }
return false; }
verifyShield(target) {
return target.shield.value / target.shield.valueMax <= this.shield;
} }
clearNodes() { 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 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.2, 600, this, 'move', false));
condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack')) condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack'))
this.tree.addRect(condition); this.tree.addRect(condition);
@ -157,7 +157,7 @@ class Game extends Phaser.Scene {
clickPlus() { clickPlus() {
console.log("PLUS"); 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'); this.scene.launch('PlusNode');

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

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

@ -20,7 +20,7 @@ class Robot {
this.lNode = []; 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)); condition.addNode(new Move(false));
this.addNode(condition); this.addNode(condition);
this.addNode(new Attack()); this.addNode(new Attack());

Loading…
Cancel
Save