Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add red portal use in Summoner + minor fix #1419

Merged
merged 8 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions d2bs/kolbot/libs/bots/Andariel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 7 additions & 5 deletions d2bs/kolbot/libs/bots/Duriel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,9 +44,11 @@ function Duriel() {

var i, unit;

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

if (!Pather.moveToExit(getRoom().correcttomb, true)) {
throw new Error("Failed to move to Tal Rasha's Tomb");
Expand Down Expand Up @@ -100,4 +102,4 @@ function Duriel() {
Pickit.pickItems();

return true;
}
}
19 changes: 18 additions & 1 deletion d2bs/kolbot/libs/bots/Summoner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,22 @@ 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");
}
}

return true;
}
}
23 changes: 21 additions & 2 deletions d2bs/kolbot/libs/common/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var global = this;

var Loader = {
scriptList: [],
scriptIndex: -1,

init: function () {
this.getScripts();
Expand Down Expand Up @@ -105,7 +106,7 @@ var Loader = {
reconfiguration = typeof Scripts[i] === 'object';

if (typeof (global[i]) === "function") {
if (i !== "Test" && i !== "Follower") {
if (i !== "Test" && i !== "Follower" && i !== "Duriel") {
townCheck = Town.goToTown();
} else {
townCheck = true;
Expand All @@ -115,6 +116,7 @@ var Loader = {
print("ÿc2Starting script: ÿc9" + i);
//scriptBroadcast(JSON.stringify({currScript: i}));
Messaging.sendToScript("tools/toolsthread.js", JSON.stringify({currScript: i}));
this.scriptIndex++;
Copy link
Collaborator

@noah- noah- Apr 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider the following refactor:

		for (s in Scripts) {
			if (Scripts[s]) {
				scriptList.push(s);
			}
		}

		for (this.scriptIndex = 0; this.scriptIndex < charScripts.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);
						}

						global[script]();

						if (reconfiguration) {
							print("ÿc2Reverting back unmodified config properties.");
							this.copy(unmodifiedConfig, Config);
						}
					}
				} catch (error) {
					Misc.errorReport(error, script);
				}
			}
		}

change existing scriptList to fileList
move charScripts from scriptName to main function, rename charScripts to scriptList
change the loader loop from what it is to for loop using new scriptList you have created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, modifications done


if (reconfiguration) {
print("ÿc2Copying Config properties from " + i + " object.");
Expand All @@ -141,5 +143,22 @@ var Loader = {
}
}
}
},

scriptName: function (offset = 0) {
let s, charScripts = [],
index = this.scriptIndex + offset;

for (s in Scripts) {
if (Scripts[s]) {
charScripts.push(s);
}
}

if (index < 0 || index >= charScripts.length) {
return undefined;
}

return charScripts[index];
}
};
};
8 changes: 7 additions & 1 deletion d2bs/kolbot/libs/common/Pather.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,20 @@ 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) {
if (me.area === 40 && npc && getDistance(me, npc) < 50) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npc isn't defined here.

if (npc && npc.openMenu()) {
Misc.useMenu(0x0D37);
}
}

Town.move("waypoint");
}

Expand Down
11 changes: 8 additions & 3 deletions d2bs/kolbot/libs/common/Town.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ var Town = {

// Do town chores
doChores: function (repair = false) {
var i,
cancelFlags = [0x01, 0x02, 0x04, 0x08, 0x14, 0x16, 0x0c, 0x0f, 0x19, 0x1a],
npc = getUnit(1, "warriv");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use NPC.Warriv variable for npc name to ensure compatibility with different locales.


if (!me.inTown) {
this.goToTown();
} else if (me.area === 40 && npc && getDistance(me, npc) < 50) {
if (npc.openMenu()) {
Misc.useMenu(0x0D37);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using warriv to travel to A1 for chores may save time in common cases, it changes behavior for bots that may expect to be on current act for other tasks. Most definitely this isn't desired behavior for bots on normal difficulty because pots are lower tiered in a1.

}

var i,
cancelFlags = [0x01, 0x02, 0x04, 0x08, 0x14, 0x16, 0x0c, 0x0f, 0x19, 0x1a];

Attack.weaponSwitch(Attack.getPrimarySlot());

this.heal();
Expand Down