Last active
September 30, 2016 12:58
-
-
Save Vamoss/3609fe74d57c4c208560 to your computer and use it in GitHub Desktop.
CondeCombat Patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MOVE EASY | |
hero.moveRight = function() { | |
var target = { "x": hero.pos.x + 6, "y": hero.pos.y }; | |
while(hero.distanceTo(target) > 0.1) { | |
hero.move(target); | |
} | |
}; | |
hero.moveLeft = function() { | |
var target = { "x": hero.pos.x - 6, "y": hero.pos.y }; | |
while(hero.distanceTo(target) > 0.1) { | |
hero.move(target); | |
} | |
}; | |
hero.moveDown = function() { | |
var target = { "x": hero.pos.x, "y": hero.pos.y - 6 }; | |
while(hero.distanceTo(target) > 0.1) { | |
hero.move(target); | |
} | |
}; | |
hero.moveUp = function() { | |
var target = { "x": hero.pos.x, "y": hero.pos.y + 6 }; | |
while(hero.distanceTo(target) > 0.1) { | |
hero.move(target); | |
} | |
}; | |
//DRAW WITH FLOWERS | |
//simple | |
this.setFlowerColor("blue"); | |
this.toggleFlowers(true); | |
this.moveXY(63, 24); | |
var twoPi = 2 * Math.PI; | |
this.degreesToRadians = function(degrees) { | |
return (degrees/360)*twoPi; | |
}; | |
this.drawCircle = function(x, y, size) { | |
var angle = 0; | |
this.toggleFlowers(false); | |
while (angle <= Math.PI * 2) { | |
var newX = x + (size * Math.cos(angle)); | |
var newY = y + (size * Math.sin(angle)); | |
this.moveXY(newX, newY); | |
this.toggleFlowers(true); | |
angle += 0.2; | |
} | |
}; | |
this.drawSquare = function(x, y, size) { | |
this.toggleFlowers(false); | |
cornerOffset = size / 2; | |
this.moveXY(x - cornerOffset, y - cornerOffset); | |
this.toggleFlowers(true); | |
this.moveXY(x + cornerOffset, y - cornerOffset); | |
this.moveXY(x + cornerOffset, y + cornerOffset); | |
this.moveXY(x - cornerOffset, y + cornerOffset); | |
this.moveXY(x - cornerOffset, y - cornerOffset); | |
}; | |
this.drawHeart = function(x, y, size){ | |
this.toggleFlowers(false); | |
var t = 0; | |
while (t <= 6.28318530718) { | |
var xx=x+size*(16*(Math.pow(Math.sin(t),3))); | |
var yy=y+size*((13*Math.cos(t))-(5*Math.cos(2*t))-(2*Math.cos(3*t))-(Math.cos(4*t))); | |
this.moveXY(xx, yy); | |
this.toggleFlowers(true); | |
t+=0.1; | |
} | |
}; | |
this.drawPolyStars = function(center, radius, sides, skips, startAngle) { | |
this.toggleFlowers(false); | |
var angle = startAngle; | |
var x = center.x; | |
var y = center.y; | |
var hoops = skips + 1; | |
var stepAngle = hoops * (twoPi / sides); | |
if(skips !== 0 && (sides % hoops) === 0) { | |
hoops = skips; | |
} | |
var endAngle = (twoPi * hoops) + startAngle; | |
while(angle <= endAngle) { | |
var newX = x + radius * Math.cos(angle); | |
var newY = y + radius * Math.sin(angle); | |
this.moveXY(newX, newY); | |
this.toggleFlowers(true); | |
angle += stepAngle; | |
} | |
}; | |
this.drawStar = function(center, radius, sides, skips, startAngle) { | |
var skipsPlusOne = skips + 1; | |
if ((sides/skipsPlusOne) != 1 && (sides%skipsPlusOne) === 0) { | |
var index = skips; | |
while(index >= 0) { | |
var angle = startAngle + index * (twoPi / sides); | |
this.drawPolyStars(center, radius, sides, skips, angle); | |
index -= 1; | |
} | |
} else { | |
this.drawPolyStars(center, radius, sides, skips, startAngle); | |
} | |
}; | |
this.drawPolygon = function(center, radius, sides, startAngle) { | |
this.drawPolyStars(center, radius, sides, 0, startAngle); | |
}; | |
this.drawSpokes = function(center, radius, sides, startAngle) { | |
var x = center.x; | |
var y = center.y; | |
var endAngle = twoPi + startAngle; | |
var stepAngle = twoPi / sides; | |
var angle = startAngle; | |
while(angle < endAngle) { | |
var newX = x + radius * Math.cos(angle); | |
var newY = y + radius * Math.sin(angle); | |
if((this.pos.x|0) == (x|0) && (this.pos.y|0) == (y|0)) { | |
this.toggleFlowers(true); | |
this.moveXY(newX, newY); | |
} else { | |
this.toggleFlowers(false); | |
this.moveXY(newX, newY); | |
this.toggleFlowers(true); | |
this.moveXY(x, y); | |
} | |
this.toggleFlowers(false); | |
angle += stepAngle; | |
} | |
}; | |
this.drawSpiral = function(center, size, loopNum, startAngle) { | |
var newX, x = center.x; | |
var newY, y = center.y; | |
this.toggleFlowers(false); | |
this.moveXY(x, y); | |
this.toggleFlowers(true); | |
var steps = size * 2; | |
var direction = Math.sign(loopNum); | |
var stepAngle = twoPi / steps / direction; | |
var loops = direction * loopNum; | |
var stepSize = size / steps / loops; | |
var curSize = 0; | |
var angle = startAngle; | |
var endAngle = (twoPi * loopNum) + startAngle; | |
while(loopNum<0 ? (angle>=endAngle) : (angle<=endAngle)) { | |
newX = x + curSize * Math.cos(angle); | |
newY = y + curSize * Math.sin(angle); | |
this.moveXY(newX, newY); | |
angle += stepAngle; | |
curSize += stepSize; | |
} | |
newX = x + size * Math.cos(endAngle); | |
newY = y + size * Math.sin(endAngle); | |
this.moveXY(newX, newY); | |
}; | |
var redX = {x: 28, y: 36}; | |
var whiteX = {x: 44, y: 36}; | |
//3d cube | |
this.setFlowerColor("white"); | |
var startAngle = this.degreesToRadians(30); | |
this.drawPolygon(redX, 10, 6, startAngle); | |
this.drawSpokes(redX, 10, 3, startAngle); | |
//bib | |
startAngle = this.degreesToRadians(-90/8); | |
this.setFlowerColor("yellow"); | |
this.drawStar(whiteX, 6, 7, 9, startAngle); | |
this.setFlowerColor("purple"); | |
this.drawSpiral({x:whiteX.x, y:42}, 15, 1, -Math.PI/2); | |
this.setFlowerColor("purple"); | |
this.drawSpiral({x:whiteX.x, y:42}, 15, -1, -Math.PI/2); | |
//circle | |
this.setFlowerColor("red"); | |
this.drawCircle(redX.x, redX.y, 10); | |
//square | |
this.setFlowerColor("blue"); | |
this.drawSquare(whiteX.x, whiteX.y, 10); | |
//hearts | |
this.setFlowerColor("pink"); | |
this.drawHeart(84, 71, 1); | |
this.setFlowerColor("red"); | |
this.drawHeart(84, 71, 2); | |
this.setFlowerColor("blue"); | |
this.drawHeart(84, 71, 3); | |
//PICKUP NEAREST COIN | |
var minDistanceToAttack = 50; | |
var friendType = "soldier"; | |
var sommunedSolders = 0; | |
this.pickUpNearestCoin = function() { | |
var value = 0; | |
var distance = 9999; | |
var items = this.findItems(); | |
var item = items[0]; | |
var index = 0; | |
if(items.length>0){ | |
while(index < items.length){ | |
var tempDistance = this.distanceTo(items[index]); | |
var tempValue = items[index].value; | |
if(tempDistance<distance && tempValue>=value) { | |
item = items[index]; | |
distance = tempDistance; | |
value = tempValue; | |
} | |
index++; | |
} | |
this.move(item.pos); | |
} | |
}; | |
//SUMMON SOLDIER | |
this.summonSoldier = function() { | |
if (this.gold > this.costOf(friendType)) { | |
this.summon(friendType); | |
sommunedSolders++; | |
} | |
}; | |
//SOLDIER COMMAND(ATTACK TOGETHER) | |
this.commandSoldiers = function() { | |
var friends = this.findFriends(); | |
var strongest; | |
var enemyIndex = 0; | |
var enemies = this.findEnemies(); | |
var mostPower = 0; | |
var closestArcher = null; | |
var closestDistance = 999; | |
while (enemyIndex<enemies.length) { | |
var tempEnemy = enemies[enemyIndex]; | |
if(tempEnemy.maxHealth>mostPower && this.distanceTo(tempEnemy)<minDistanceToAttack && tempEnemy.team=="ogres"){ | |
mostPower=tempEnemy.maxHealth; | |
strongest = tempEnemy; | |
} | |
if(tempEnemy.type=="thrower" && this.distanceTo(tempEnemy)<closestDistance){ | |
closestDistance = this.distanceTo(tempEnemy); | |
closestArcher = tempEnemy; | |
} | |
enemyIndex++; | |
} | |
var enemy = strongest; | |
if(!closestArcher) closestArcher = enemy; | |
for(var i=0; i < friends.length; i++) { | |
if(enemy) { | |
if(i<friends.length*0.7){ | |
this.command(friends[i],"attack", enemy); | |
}else{ | |
this.command(friends[i],"attack", closestArcher); | |
} | |
} | |
} | |
}; | |
//SOLDIER COMMAND(ATTACK INDIVIDUALLY OR GO TO POSITION) | |
this.commandSoldier = function() { | |
var friends = this.findFriends(); | |
var strongest; | |
var enemyIndex = 0; | |
var enemies = this.findEnemies(); | |
for(var i=0; i < friends.length; i++) { | |
if(friends[i].type == "soldier" || friends[i].type == "archer"){ | |
var mostPower = 0; | |
var closestArcher = null; | |
var closestDistance = 999; | |
while (enemyIndex<enemies.length) { | |
var tempEnemy = enemies[enemyIndex]; | |
if(tempEnemy.maxHealth>mostPower && friends[i].distanceTo(tempEnemy)<minDistanceToAttack && tempEnemy.team=="ogres"){ | |
mostPower=tempEnemy.maxHealth; | |
strongest = tempEnemy; | |
} | |
if(tempEnemy.type=="thrower" && this.distanceTo(tempEnemy)<closestDistance){ | |
closestDistance = this.distanceTo(tempEnemy); | |
closestArcher = tempEnemy; | |
} | |
enemyIndex++; | |
} | |
var enemy = strongest; | |
if(!closestArcher) closestArcher = enemy; | |
if(enemy) { | |
//if(i<friends.length*0.7){ | |
this.command(friends[i],"attack", enemy); | |
//} | |
}else{ | |
var pos = {x:20, y:24}; | |
if(i%2) pos.y = 68; | |
this.command(friends[i],"move", pos); | |
} | |
} | |
} | |
}; | |
//ATTACK | |
this.brutality = function(){ | |
var strongest = null; | |
var enemyIndex = 0; | |
var enemies = this.findEnemies(); | |
var mostPower = 0; | |
var closestArcher = null; | |
var closestDistance = 999; | |
while (enemyIndex<enemies.length) { | |
var tempEnemy = enemies[enemyIndex]; | |
if(tempEnemy.maxHealth>mostPower && this.distanceTo(tempEnemy)<minDistanceToAttack && tempEnemy.team=="ogres"){ | |
mostPower=tempEnemy.maxHealth; | |
strongest = tempEnemy; | |
} | |
/* | |
if(tempEnemy.type=="thrower" && this.distanceTo(tempEnemy)<closestDistance){ | |
closestDistance = this.distanceTo(tempEnemy); | |
closestArcher = tempEnemy; | |
} | |
*/ | |
enemyIndex++; | |
} | |
var enemy; | |
if(closestArcher) { | |
enemy = closestArcher; | |
}else{ | |
enemy = strongest; | |
} | |
var closeEnemies = 0; | |
for(var i=0; i<enemies.length;i++){ | |
distance = this.distanceTo(enemies[i]); | |
if(distance<10) closeEnemies++; | |
} | |
if(this.isReady("cleave") && closeEnemies>3){ | |
this.cleave(enemy); | |
}else if(enemy){ | |
this.attack(enemy); | |
} | |
}; | |
loop { | |
if(sommunedSolders<12){ | |
this.pickUpNearestCoin(); | |
this.summonSoldier(); | |
}else{ | |
this.brutality(); | |
} | |
this.commandSoldiers(); | |
} | |
//COLLECT MOST VALUABLE & SUMMON & ATTACK STRONGEST & POSITION SPECIFIC POINT | |
var points = []; | |
points[0] = {x: 33, y: 42}; | |
points[1] = {x: 47, y: 42}; | |
points[2] = {x: 33, y: 26}; | |
points[3] = {x: 47, y: 26}; | |
var minDistanceToAttack = 50; | |
var friendType = "soldier"; | |
var soldiers; | |
var soldierIndex; | |
var soldier; | |
loop { | |
var value = 0; | |
var distance = 9999; | |
var items = this.findItems(); | |
var item = items[0]; | |
var index = 0; | |
if(items.length>0){ | |
while(index < items.length){ | |
var tempDistance = this.distanceTo(items[index]); | |
var tempValue = items[index].value; | |
if(tempDistance<distance && tempValue>=value) { | |
item = items[index]; | |
distance = tempDistance; | |
value = tempValue; | |
} | |
index++; | |
} | |
this.move(item.pos); | |
} | |
if (this.gold > this.costOf(friendType)) { | |
this.summon(friendType); | |
} | |
var enemies = this.findEnemies(); | |
var enemyIndex = 0; | |
var mostPower = 0; | |
var strongest; | |
while (enemyIndex<enemies.length) { | |
if(enemies[enemyIndex].maxHealth>mostPower && this.distanceTo(enemies[enemyIndex])<minDistanceToAttack && enemies[enemyIndex].team=="ogres"){ | |
mostPower=enemies[enemyIndex].maxHealth; | |
strongest = enemies[enemyIndex]; | |
} | |
enemyIndex++; | |
} | |
var enemy = strongest; | |
var friends = this.findFriends(); | |
for(var friendIndex = 0; friendIndex < friends.length; friendIndex++) { | |
var friend = friends[friendIndex]; | |
if(friend.type == friendType) { | |
if(enemy){ | |
this.command(friend, "attack", enemy); | |
}else { | |
this.command(friend, "move",points[friendIndex%4]); | |
} | |
} | |
} | |
if(enemy){ | |
var closeEnemies = 0; | |
for(var i=0; i<enemies.length;i++){ | |
distance = this.distanceTo(enemies[i]); | |
if(distance<10) closeEnemies++; | |
} | |
if(this.isReady("cleave") && closeEnemies>3){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
} | |
} | |
//COLLECT MOST VALUABLE & SUMMON & ATTACK STRONGEST & MOVE | |
var minDistanceToAttack = 30; | |
var friendType = "artillery"; | |
var soldiers; | |
var soldierIndex; | |
var soldier; | |
loop { | |
var value = 0; | |
var distance = 9999; | |
var items = this.findItems(); | |
var item = items[0]; | |
var index = 0; | |
if(items.length>0){ | |
while(index < items.length){ | |
var tempDistance = this.distanceTo(items[index]); | |
var tempValue = items[index].value; | |
if(tempDistance<distance && tempValue>=value) { | |
item = items[index]; | |
distance = tempDistance; | |
value = tempValue; | |
} | |
index++; | |
} | |
this.move(item.pos); | |
} | |
if (this.gold > this.costOf(friendType)) { | |
this.summon(friendType); | |
} | |
var enemies = this.findEnemies(); | |
var enemyIndex = 0; | |
var mostPower = 0; | |
var strongest; | |
while (enemyIndex<enemies.length) { | |
if(enemies[enemyIndex].maxHealth>mostPower && this.distanceTo(enemies[enemyIndex])<minDistanceToAttack && enemies[enemyIndex].type!="sand-yak"){ | |
mostPower=enemies[enemyIndex].maxHealth; | |
strongest = enemies[enemyIndex]; | |
} | |
enemyIndex++; | |
} | |
var enemy = strongest; | |
if(this.canCast("goldstorm", this)) this.cast("goldstorm", this); | |
var friends = this.findFriends(); | |
for(var friendIndex = 0; friendIndex < friends.length; friendIndex++) { | |
var friend = friends[friendIndex]; | |
if(friend.type == friendType) { | |
if(enemy){ | |
this.command(friend, "attack", enemy); | |
}else { | |
this.command(friend, "move", {x:39, y:39}); | |
} | |
} | |
} | |
} | |
//SUMMON SOLDIERS & MOVE TO FLAG & ATTACK THE STRONGEST & COLLECT | |
var minDistanceToAttack = 30; | |
var soldiers; | |
var soldierIndex; | |
var soldier; | |
loop { | |
if (this.gold > this.costOf("soldier")) { | |
this.summon("soldier"); | |
} | |
var flag = this.findFlag("green"); | |
if (flag) { | |
soldiers = this.findFriends(); | |
soldierIndex = 0; | |
while(soldierIndex<soldiers.length){ | |
soldier = soldiers[soldierIndex]; | |
this.command(soldier, "move", {x:flag.pos.x+Math.random()*10-5, y:flag.pos.y+Math.random()*10-5}); | |
soldierIndex++; | |
} | |
this.move(flag.pos); | |
this.pickUpFlag(flag); | |
} | |
else { | |
var enemies = this.findEnemies(); | |
var enemyIndex = 0; | |
var mostPower = 0; | |
var strongest; | |
while (enemyIndex<enemies.length) { | |
if(enemies[enemyIndex].maxHealth>mostPower && this.distanceTo(enemies[enemyIndex])<minDistanceToAttack && enemies[enemyIndex].type!="sand-yak"){ | |
mostPower=enemies[enemyIndex].maxHealth; | |
strongest = enemies[enemyIndex]; | |
} | |
enemyIndex++; | |
} | |
var enemy = strongest; | |
var attacked = false; | |
if(enemy){ | |
var closeEnemies = 0; | |
for(var i=0; i<enemies.length;i++){ | |
var distance = this.distanceTo(enemies[i]); | |
if(distance<10) closeEnemies++; | |
} | |
if(this.distanceTo(enemy)<minDistanceToAttack){ | |
attacked = true; | |
soldiers = this.findFriends(); | |
soldierIndex = 0; | |
while(soldierIndex<soldiers.length){ | |
soldier = soldiers[soldierIndex]; | |
this.command(soldier, "attack", enemy); | |
soldierIndex++; | |
} | |
if(this.isReady("cleave") && closeEnemies>3){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
} | |
} | |
if(!attacked){ | |
var items = this.findItems(); | |
if (items.length && items[0]) { | |
var itemPos = items[0].pos; | |
var itemX = itemPos.x; | |
var itemY = itemPos.y; | |
this.moveXY(itemX, itemY); | |
soldiers = this.findFriends(); | |
soldierIndex = 0; | |
while(soldierIndex<soldiers.length){ | |
soldier = soldiers[soldierIndex]; | |
this.command(soldier, "move", {x: itemX, y:itemY}); | |
soldierIndex++; | |
} | |
} | |
} | |
} | |
} | |
//COLLECT THE MOST VALUEBLE AND CLOSEST COIN && SUMMON SOLDIERS && ATTACK | |
loop { | |
if (this.gold > this.costOf("soldier")) { | |
this.summon("soldier"); | |
} | |
var enemy = this.findNearest(this.findEnemies()); | |
if (enemy) { | |
var soldiers = this.findFriends(); | |
var soldierIndex = 0; | |
while(soldierIndex<soldiers.length){ | |
var soldier = soldiers[soldierIndex]; | |
this.command(soldier, "attack", enemy); | |
soldierIndex++; | |
} | |
} | |
var value = 0; | |
var distance = 9999; | |
var items = this.findItems(); | |
var item = items[0]; | |
var index = 0; | |
if(items.length>0 && this.now()<20){ | |
while(index < items.length){ | |
var tempDistance = this.distanceTo(items[index]); | |
var tempValue = items[index].value; | |
if(tempDistance<distance && tempValue>=value) { | |
item = items[index]; | |
distance = tempDistance; | |
value = tempValue; | |
} | |
index++; | |
} | |
this.move(item.pos); | |
}else if(enemy){ | |
this.attack(enemy); | |
} | |
} | |
//COLLECT THE MOST VALUEBLE AND CLOSEST COIN | |
loop { | |
var value = 0; | |
var distance = 9999; | |
var items = this.findItems(); | |
var item = items[0]; | |
var index = 0; | |
while(index < items.length){ | |
var tempDistance = this.distanceTo(items[index]); | |
var tempValue = items[index].value; | |
if(tempDistance<distance && tempValue>=value) { | |
item = items[index]; | |
distance = tempDistance; | |
value = tempValue; | |
} | |
index++; | |
} | |
this.move(item.pos); | |
} | |
//FLAG & ATTACK STRONGEST & PICK | |
//exclude type and distance | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.buildXY("fire-trap", flag.pos.x, flag.pos.y); | |
this.pickUpFlag(flag); | |
} | |
else { | |
var enemies = this.findEnemies(); | |
if(enemies.length){ | |
var enemyIndex = 0; | |
var mostPower = 0; | |
var strongest; | |
while (enemyIndex<enemies.length) { | |
if(enemies[enemyIndex].maxHealth>mostPower && this.distanceTo(enemies[enemyIndex])<30 && enemies[enemyIndex].type!="sand-yak"){ | |
mostPower=enemies[enemyIndex].maxHealth; | |
strongest = enemies[enemyIndex]; | |
} | |
enemyIndex++; | |
} | |
this.attack(strongest); | |
}else{ | |
var item = this.findNearest(this.findItems()); | |
if (item) { | |
var itemPos = item.pos; | |
var itemX = itemPos.x; | |
var itemY = itemPos.y; | |
this.moveXY(itemX, itemY); | |
} | |
} | |
} | |
} | |
//ATTACK & PROTECT | |
loop { | |
var enemy = this.findNearestEnemy(); | |
var distance = this.distanceTo(enemy); | |
if (distance < 10) { | |
if(this.isReady("cleave")){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
}else{ | |
this.moveXY(40, 32); | |
} | |
} | |
//ATTACK | |
loop { | |
var enemy = this.findNearestEnemy(); | |
if(enemy){ | |
var distance = this.distanceTo(enemy); | |
if(this.isReady("cleave") && distance<8){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
} | |
} | |
//ATTACK EXCLUDING TYPE | |
// Use while loops to pick out the ogre | |
loop { | |
var enemies = this.findEnemies(); | |
var enemyIndex = 0; | |
while(enemyIndex<enemies.length){ | |
var enemy = enemies[enemyIndex]; | |
if (enemy.type != "sand-yak") { | |
while(enemy.health>0){ | |
this.attack(enemy); | |
} | |
} | |
enemyIndex++; | |
} | |
} | |
//FLAG & PICK | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.pickUpFlag(flag); | |
}else{ | |
var item = this.findNearestItem(); | |
if (item) { | |
var position = item.pos; | |
var x = position.x; | |
var y = position.y; | |
this.moveXY(x, y); | |
} | |
} | |
} | |
//FLAG & ATTACK | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.pickUpFlag(flag); | |
}else{ | |
var enemy = this.findNearestEnemy(); | |
if(enemy){ | |
var distance = this.distanceTo(enemy); | |
if(this.isReady("cleave") && distance<7){ | |
this.cleave(enemy); | |
}else if(distance<20){ | |
this.attack(enemy); | |
} | |
} | |
} | |
} | |
// Put flags where you want to build traps. | |
// When you're not building traps, pick up coins! | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.buildXY("fire-trap", flag.pos.x, flag.pos.y); | |
this.pickUpFlag(flag); | |
} | |
else { | |
var item = this.findNearestItem(); | |
if (item) { | |
var itemPos = item.pos; | |
var itemX = itemPos.x; | |
var itemY = itemPos.y; | |
this.moveXY(itemX, itemY); | |
} | |
} | |
} | |
//FLAG & ATTACK & COLLECT | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.buildXY("fire-trap", flag.pos.x, flag.pos.y); | |
this.pickUpFlag(flag); | |
} | |
else { | |
var enemy = this.findNearestEnemy(); | |
if(enemy){ | |
var distance = this.distanceTo(enemy); | |
if(this.isReady("cleave") && distance<7){ | |
this.cleave(enemy); | |
}else if(distance<20){ | |
this.attack(enemy); | |
} | |
}else{ | |
var item = this.findNearestItem(); | |
if (item) { | |
var itemPos = item.pos; | |
var itemX = itemPos.x; | |
var itemY = itemPos.y; | |
this.moveXY(itemX, itemY); | |
} | |
} | |
} | |
} | |
//FLAG & ATTACK & COLLECT | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.moveXY(flag.pos.x, flag.pos.y); | |
this.pickUpFlag(flag); | |
} | |
else { | |
var enemy = this.findNearestEnemy(); | |
var attacked = false; | |
if(enemy){ | |
var distance = this.distanceTo(enemy); | |
if(this.isReady("cleave") && distance<7){ | |
this.cleave(enemy); | |
attacked = true; | |
}else if(distance<20){ | |
this.attack(enemy); | |
attacked = true; | |
} | |
} | |
if(!attacked){ | |
var items = this.findItems(); | |
if (items.length && items[0]) { | |
var itemPos = items[0].pos; | |
var itemX = itemPos.x; | |
var itemY = itemPos.y; | |
this.moveXY(itemX, itemY); | |
} | |
} | |
} | |
} | |
//MODES & ATTACK & RUN | |
loop { | |
var flag = this.findFlag("green"); | |
if (flag) { | |
this.pickUpFlag(flag); | |
loop{ | |
flag = this.findFlag("black"); | |
if(flag){ | |
this.pickUpFlag(flag); | |
return; | |
}else{ | |
var enemy = this.findNearestEnemy(); | |
if(enemy){ | |
var distance = this.distanceTo(enemy); | |
if(this.isReady("cleave") && distance<7){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
} | |
} | |
} | |
} | |
flag = this.findFlag("violet"); | |
if(flag){ | |
this.moveXY(flag.pos.x, flag.pos.y); | |
this.pickUpFlag(flag); | |
} | |
} | |
//DODGE & RUN | |
// Let yaks get close, then move 10m right to dodge. | |
// Dodge 4 yaks to complete the level. | |
var minDist = 5; | |
var skip = 10; | |
var maxWidth = 70; | |
loop { | |
this.say(this.pos.x); | |
if(this.pos.x<10) this.moveXY(10, this.pos.y); | |
if(this.pos.x>maxWidth) this.moveXY(maxWidth-10, this.pos.y); | |
var item = this.findNearestEnemy(); | |
if (item) { | |
var distX = this.pos.x - item.pos.x; | |
var distY = this.pos.y - item.pos.y; | |
if(distY<20 && distY>-20) { | |
if(distX>=0&&distX<minDist){ | |
this.moveXY(this.pos.x+skip, this.pos.y); | |
}else if(distX<0&&distX>-minDist){ | |
this.moveXY(this.pos.x-skip, this.pos.y); | |
} | |
} | |
} | |
} | |
//AVOID HIT & RUN | |
var minDist = 5; | |
var skip = 10; | |
var maxWidth = 70; | |
loop { | |
this.say(this.pos.x); | |
var item = this.findNearestEnemy(); | |
if (item) { | |
var distX = this.pos.x - item.pos.x; | |
var distY = this.pos.y - item.pos.y; | |
if(this.distanceTo(item)<10){ | |
this.moveXY(this.pos.x+distX/7, this.pos.y+distY/7); | |
}else{ | |
this.moveXY(this.pos.x+10, this.pos.y); | |
} | |
}else{ | |
this.moveXY(this.pos.x+10, this.pos.y); | |
} | |
} | |
//ATTACK OR GO | |
loop { | |
// Attack any enemies you see, or keep moving up and right. | |
x = this.pos.x + 10; | |
y = this.pos.y + 10; | |
var enemy = this.findNearestEnemy(); | |
var distance = 999; | |
if(enemy) distance = this.distanceTo(enemy); | |
if (distance < 10) { | |
if(this.isReady("cleave")){ | |
this.cleave(enemy); | |
}else{ | |
this.attack(enemy); | |
} | |
}else{ | |
this.moveXY(x, y); | |
} | |
} | |
//BLOCK & RUN | |
loop { | |
var yak = this.findNearestEnemy(); | |
if (yak && yak.pos.x>this.pos.x) { | |
// A yak is above you if its y is greater than your y. | |
// If the yak is above you, build a fence 10m below it. | |
if(yak.pos.y<this.pos.y) this.buildXY("fence", yak.pos.x, 32-3); | |
// If the yak is below you, build a fence 10m above it. | |
if(yak.pos.y>this.pos.y) this.buildXY("fence", yak.pos.x, 32+5); | |
} else { | |
// Move right 10m towards the oasis. | |
this.moveXY(this.pos.x+10, this.pos.y); | |
} | |
} | |
//GET CLOSE | |
loop { | |
// How do you find the nearest friendly unit? | |
var horse = this.findFriends()[0]; | |
if (horse) { | |
var x1 = horse.pos.x - 7; | |
var x2 = horse.pos.x + 7; | |
if (x1 >= 1) { | |
// Move to the horse's y position but use x1 for the x position. | |
horse.pos.x = x1; | |
horse.pos.y = 54; | |
this.moveXY(x1, horse.pos.y); | |
} else if (x2 <= 79) { | |
// Move to the horse's y position but use x2 for the x position. | |
this.moveXY(x2, horse.pos.y); | |
} | |
var distance = this.distanceTo(horse); | |
if (distance <= 10) { | |
this.say("Whoa"); | |
// Move to the red x to return the horse to the farm. | |
this.moveXY(27, 54); | |
// Move back out into the pasture to begin looking for the next horse. | |
this.moveXY(43, 27); | |
} | |
} | |
} | |
//BUILD FENCE, FIRE-TRAP OR MOVE | |
// Use different colored flags to perform different tasks. | |
loop { | |
flagGreen = this.findFlag("green"); | |
flagBlack = this.findFlag("black"); | |
flagViolet = this.findFlag("violet"); | |
// If there's a green flag, build a "fence". | |
if(flagGreen){ | |
this.buildXY("fence", flagGreen.pos.x, flagGreen.pos.y); | |
this.pickUpFlag(flagGreen); | |
} | |
// If there's a black flag, build a "fire-trap". | |
if(flagBlack){ | |
this.buildXY("fire-trap", flagBlack.pos.x, flagBlack.pos.y); | |
this.pickUpFlag(flagBlack); | |
} | |
// If there's a violet flag, just move to its location. | |
if(flagViolet){ | |
this.moveXY(flagViolet.pos.x, flagViolet.pos.y); | |
this.pickUpFlag(flagViolet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment