Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buildDodgeList: function () {
- var monster = getUnit(1),
- list = [];
- if (monster) {
- do {
- if (this.checkMonster(monster)) {
- list.push(copyUnit(monster));
- }
- } while (monster.getNext());
- }
- return list;
- },
- dodge: function (unit, distance, list) {
- var i, j, coordx, coordy, monster, count,
- maxcount = 99,
- coords = [],
- goodCoords = [],
- angles = [45, 90, 135, 180, 225, 270, 305, 360];
- // step 1 - build possible dodge positions based on angles
- for (i = 0; i < angles.length; i = i + 1) {
- coordx = Math.round((Math.cos(angles[i] * Math.PI / 180)) * distance + unit.x);
- coordy = Math.round((Math.sin(angles[i] * Math.PI / 180)) * distance + unit.y);
- if (this.validSpot(coordx, coordy)) {
- coords.push([coordx, coordy]);
- }
- }
- if (coords.length === 0) { // no valid positions - don't move
- me.overhead("Can't dodge :(");
- return true;
- }
- coords.sort(this.sortRooms);
- for (i = 0; i < coords.length; i += 1) {
- count = 0;
- for (j = 0; j < list.length; j += 1) {
- if (list[j].hp > 0 && getDistance(list[j].x, list[j].y, coords[i][0], coords[i][1]) < 10) {
- count += 1;
- }
- }
- if (count < maxcount) {
- goodCoords = [coords[i][0], coords[i][1]];
- maxcount = count;
- if (count === 0) {
- break;
- }
- }
- }
- if (goodCoords.length > 0) { // just in case goodCoords is empty (shouldn't happen)
- if (getDistance(me, goodCoords[0], goodCoords[1]) < 5) { // close enough
- return true;
- }
- me.overhead("Dodge!");
- Pather.moveTo(goodCoords[0], goodCoords[1], 1);
- }
- return true;
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement