Skip to content

Commit

Permalink
Add red portal use in Summoner (#1419)
Browse files Browse the repository at this point in the history
* Summoner script now uses red portal to move to Duriel

* Change attack function in Andariel and Duriel for classic compatibility

* Use Warriv to move to act 1 if game starts in act 2

* always precast at duriel start

* Remove warriv use in doChores + revisions

* Loader refactoring

* scriptName now returns null instead of undefined
  • Loading branch information
5noop authored and MikeKGilmore committed Apr 14, 2019
1 parent 9365873 commit 2730a59
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 57 deletions.
6 changes: 3 additions & 3 deletions d2bs/kolbot/libs/bots/Andariel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @desc kill Andariel
*/

function Andariel() {
function Andariel () {
this.killAndariel = function () {
var i,
target = getUnit(1, 156);
Expand All @@ -19,7 +19,7 @@ function Andariel() {
}

for (i = 0; i < 300; i += 1) {
ClassAttack.doCast(target, Config.AttackSkill[1], Config.AttackSkill[2]);
ClassAttack.doAttack(target);

if (target.dead) {
return true;
Expand Down Expand Up @@ -53,4 +53,4 @@ function Andariel() {
Pickit.pickItems();

return true;
}
}
13 changes: 8 additions & 5 deletions d2bs/kolbot/libs/bots/Duriel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @desc kill Duriel
*/

function Duriel() {
function Duriel () {
this.killDuriel = function () {
var i, target;

Expand All @@ -28,7 +28,7 @@ function Duriel() {
}

for (i = 0; i < 300; i += 1) {
ClassAttack.doCast(target, Config.AttackSkill[1], Config.AttackSkill[2]);
ClassAttack.doAttack(target);

if (target.dead) {
return true;
Expand All @@ -44,8 +44,11 @@ function Duriel() {

var i, unit;

Town.doChores();
Pather.useWaypoint(46);
if (me.area !== 46) {
Town.doChores();
Pather.useWaypoint(46);
}

Precast.doPrecast(true);

if (!Pather.moveToExit(getRoom().correcttomb, true)) {
Expand Down Expand Up @@ -100,4 +103,4 @@ function Duriel() {
Pickit.pickItems();

return true;
}
}
23 changes: 21 additions & 2 deletions d2bs/kolbot/libs/bots/Summoner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @desc kill the Summoner
*/

function Summoner() {
function Summoner () {
Town.doChores();
Pather.useWaypoint(74);
Precast.doPrecast(true);
Expand All @@ -27,5 +27,24 @@ function Summoner() {

Attack.clear(15, 0, 250); // The Summoner

if (Loader.scriptName(1) === "Duriel") {
let journal = getUnit(2, 357);

if (!journal) {
throw new Error("Journal not found");
}

Pather.moveToUnit(journal);
journal.interact();
delay(500);
me.cancel();

if (!Pather.usePortal(46)) {
throw new Error("Failed to take arcane portal");
}

Loader.skipTown.push("Duriel");
}

return true;
}
}
105 changes: 59 additions & 46 deletions d2bs/kolbot/libs/common/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
var global = this;

var Loader = {
fileList: [],
scriptList: [],
scriptIndex: -1,
skipTown: ["Test", "Follower"],

init: function () {
this.getScripts();
Expand All @@ -20,7 +23,7 @@ var Loader = {

for (i = 0; i < fileList.length; i += 1) {
if (fileList[i].indexOf(".js") > -1) {
this.scriptList.push(fileList[i].substring(0, fileList[i].indexOf(".js")));
this.fileList.push(fileList[i].substring(0, fileList[i].indexOf(".js")));
}
}
},
Expand Down Expand Up @@ -81,65 +84,75 @@ var Loader = {
},

loadScripts: function () {
var i, townCheck, reconfiguration,
var reconfiguration, s, script,
unmodifiedConfig = {};

this.copy(Config, unmodifiedConfig);

if (!this.scriptList.length) {
if (!this.fileList.length) {
showConsole();

throw new Error("You don't have any valid scripts in bots folder.");
}

for (i in Scripts) {
if (Scripts.hasOwnProperty(i)) {
if (this.scriptList.indexOf(i) > -1) {
if (!!Scripts[i]) {
if (!include("bots/" + i + ".js")) {
Misc.errorReport("Failed to include script: " + i);
for (s in Scripts) {
if (Scripts.hasOwnProperty(s) && Scripts[s]) {
this.scriptList.push(s);
}
}

for (this.scriptIndex = 0; this.scriptIndex < this.scriptList.length; this.scriptIndex++) {
script = this.scriptList[this.scriptIndex];

if (this.fileList.indexOf(script) < 0) {
Misc.errorReport("ÿc1Script " + script + " doesn't exist.");
continue;
}

if (!include("bots/" + script + ".js")) {
Misc.errorReport("Failed to include script: " + script);
continue;
}

if (isIncluded("bots/" + script + ".js")) {
try {
if (typeof (global[script]) !== "function") {
throw new Error("Invalid script function name");
}

if (this.skipTown.indexOf(script) > -1 || Town.goToTown()) {
print("ÿc2Starting script: ÿc9" + script);
//scriptBroadcast(JSON.stringify({currScript: script}));
Messaging.sendToScript("tools/toolsthread.js", JSON.stringify({currScript: script}));

reconfiguration = typeof Scripts[script] === 'object';

if (reconfiguration) {
print("ÿc2Copying Config properties from " + script + " object.");
this.copy(Scripts[script], Config);
}

if (isIncluded("bots/" + i + ".js")) {
try {
reconfiguration = typeof Scripts[i] === 'object';

if (typeof (global[i]) === "function") {
if (i !== "Test" && i !== "Follower") {
townCheck = Town.goToTown();
} else {
townCheck = true;
}

if (townCheck) {
print("ÿc2Starting script: ÿc9" + i);
//scriptBroadcast(JSON.stringify({currScript: i}));
Messaging.sendToScript("tools/toolsthread.js", JSON.stringify({currScript: i}));

if (reconfiguration) {
print("ÿc2Copying Config properties from " + i + " object.");
this.copy(Scripts[i], Config);
}

global[i]();

if (reconfiguration) {
print("ÿc2Reverting back unmodified config properties.");
this.copy(unmodifiedConfig, Config);
}
}
} else {
throw new Error("Invalid script function name");
}
} catch (error) {
Misc.errorReport(error, i);
}
global[script]();

if (reconfiguration) {
print("ÿc2Reverting back unmodified config properties.");
this.copy(unmodifiedConfig, Config);
}
}
} else {
Misc.errorReport("ÿc1Script " + i + " doesn't exist.");
} catch (error) {
Misc.errorReport(error, script);
}
}
}
},

scriptName: function (offset = 0) {
let index = this.scriptIndex + offset;

if (index >= 0 && index < this.scriptList.length) {
return this.scriptList[index];
}

return null;
}
};
};
10 changes: 9 additions & 1 deletion d2bs/kolbot/libs/common/Pather.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,22 @@ ModeLoop:
break;
}

var i, tick, wp, coord, retry;
var i, tick, wp, coord, retry, npc;

for (i = 0; i < 12; i += 1) {
if (me.area === targetArea || me.dead) {
break;
}

if (me.inTown) {
npc = getUnit(1, NPC.Warriv);

if (me.area === 40 && npc && getDistance(me, npc) < 50) {
if (npc && npc.openMenu()) {
Misc.useMenu(0x0D37);
}
}

Town.move("waypoint");
}

Expand Down

0 comments on commit 2730a59

Please sign in to comment.