Création d'un cube déplaçable - Création des nodes : Les actions se font de manière dynamique sur le robot - si la première action n'aboutit pas, la deuxième action est effectuée - Création des conditions - Pour le moment, si le robot passe en dessous de la condition de bouclier, il effectue les action qui lui sont liés (Ex : reculer)
parent
f0ea863610
commit
9ba17166a7
File diff suppressed because one or more lines are too long
@ -0,0 +1,12 @@
|
||||
class Attack {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
do(robot) {
|
||||
if (robot.haveTarget() && robot.isTargetInRange()) {
|
||||
return robot.attackTarget();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
class Condition {
|
||||
constructor(target, 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.lNode = [];
|
||||
}
|
||||
|
||||
addNode(node) {
|
||||
this.lNode.push(node);
|
||||
}
|
||||
|
||||
do(robot) {
|
||||
if (this.doCondition(robot)) {
|
||||
for (let i = 0; i < this.lNode.length; i++) {
|
||||
if (this.lNode[i].do(robot)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
doCondition(robot) {
|
||||
if (this.shieldFilter) {
|
||||
if (this.shieldCondition()) {
|
||||
if (this.rangeFilter) {
|
||||
return this.rangeCondition(robot);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (this.rangeFilter) {
|
||||
return this.rangeCondition(robot);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
rangeCondition(robot) {
|
||||
return robot.calcDistance(this.target) <= this.range;
|
||||
}
|
||||
|
||||
shieldCondition() {
|
||||
if (this.target.shield.value / this.target.shield.valueMax <= this.shield) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
moveToward(robot) {
|
||||
return robot.advanceToTarget();
|
||||
}
|
||||
|
||||
fleeFrom(robot) {
|
||||
return robot.fleeFromTarget();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
class Move {
|
||||
constructor(toward) { //true = move toward / false = flee from
|
||||
this.toward = toward;
|
||||
}
|
||||
|
||||
do(robot) {
|
||||
if (robot.haveTarget()) {
|
||||
if (this.toward === true) {
|
||||
return this.moveToward(robot);
|
||||
} else {
|
||||
return this.fleeFrom(robot);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
moveToward(robot) {
|
||||
return robot.advanceToTarget();
|
||||
}
|
||||
|
||||
fleeFrom(robot) {
|
||||
return robot.fleeFromTarget();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue