Skip to content

Commit

Permalink
Merge branch 'master' into Mercenary
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeKGilmore authored Apr 15, 2019
2 parents a5d76ff + 2ddba43 commit bd78d83
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 106 deletions.
6 changes: 5 additions & 1 deletion d2bs/kolbot/default.dbj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ function main() {
}

if (mode === 1638) { // getProfile
GameAction.init(JSON.parse(msg).Tag);
msg = JSON.parse(msg);

if (msg.Tag) {
GameAction.init(msg.Tag);
}
}
};

Expand Down
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;
}
}
8 changes: 5 additions & 3 deletions d2bs/kolbot/libs/common/Attacks/Amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ var ClassAttack = {
lightFuryTick: 0,

doAttack: function (unit, preattack) {
if (Config.MercWatch && Mercenary.needMerc()) {
Town.visitTown();
var needRepair = Town.needRepair();

if ((Config.MercWatch && Mercenary.needMerc()) || needRepair.length > 0) {
Town.visitTown(!!needRepair.length);
}

if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, Config.AttackSkill[0]) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) {
Expand Down Expand Up @@ -102,7 +104,7 @@ var ClassAttack = {
needRepair = Town.needRepair();

if (needRepair && needRepair.length > 0) { // Repair check, mainly to restock arrows
Town.visitTown();
Town.visitTown(true);
}

this.lightFuryTick = 0;
Expand Down
8 changes: 5 additions & 3 deletions d2bs/kolbot/libs/common/Attacks/Barbarian.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

var ClassAttack = {
doAttack: function (unit, preattack) {
if (Config.MercWatch && Mercenary.needMerc()) {
Town.visitTown();
var needRepair = Town.needRepair();

if ((Config.MercWatch && Mercenary.needMerc()) || needRepair.length > 0) {
Town.visitTown(!!needRepair.length);
}

if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, Attack.getSkillElement(Config.AttackSkill[0])) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) {
Expand Down Expand Up @@ -59,7 +61,7 @@ var ClassAttack = {
needRepair = Town.needRepair();

if (needRepair && needRepair.length > 0) { // Repair check
Town.visitTown();
Town.visitTown(true);
}

if (pickit) {
Expand Down
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;
}
};
};
17 changes: 6 additions & 11 deletions d2bs/kolbot/libs/common/Misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,10 +1290,7 @@ var Misc = {

var desc,
date = new Date(),
h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds(),
dateString = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "]";
dateString = "[" + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0,-5).replace(/-/g, '/').replace('T', ' ') + "]";

switch (action) {
case "Sold":
Expand Down Expand Up @@ -1359,7 +1356,7 @@ var Misc = {
return false;
}

if (!Config.LogHighGems && ["glv", "gly", "glb", "glg", "glr", "glw", "skl", "gpv", "gpy", "gpb", "gpg", "gpr", "gpw", "skz"].indexOf(unit.code) > -1) {
if (!Config.LogHighGems && ["gzv", "gly", "glb", "glg", "glr", "glw", "skl", "gpv", "gpy", "gpb", "gpg", "gpr", "gpw", "skz"].indexOf(unit.code) > -1) {
return false;
}

Expand Down Expand Up @@ -1847,23 +1844,21 @@ MainLoop:

// Report script errors to logs/ScriptErrorLog.txt
errorReport: function (error, script) {
var i, h, m, s, date, msg, oogmsg, filemsg, source, stack,
var i, date, dateString, msg, oogmsg, filemsg, source, stack,
stackLog = "";

date = new Date();
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
dateString = "[" + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0,-5).replace(/-/g, '/').replace('T', ' ') + "]";

if (typeof error === "string") {
msg = error;
oogmsg = error.replace(/ÿc[0-9!"+<:;.*]/gi, "");
filemsg = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "] <" + me.profile + "> " + error.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";
filemsg = dateString + " <" + me.profile + "> " + error.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";
} else {
source = error.fileName.substring(error.fileName.lastIndexOf("\\") + 1, error.fileName.length);
msg = "ÿc1Error in ÿc0" + script + " ÿc1(" + source + " line ÿc1" + error.lineNumber + "): ÿc1" + error.message;
oogmsg = " Error in " + script + " (" + source + " #" + error.lineNumber + ") " + error.message + " (Area: " + me.area + ", Ping:" + me.ping + ", Game: " + me.gamename + ")";
filemsg = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "] <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";
filemsg = dateString + " <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";

if (error.hasOwnProperty("stack")) {
stack = error.stack;
Expand Down
10 changes: 9 additions & 1 deletion d2bs/kolbot/libs/common/Pather.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,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
Loading

0 comments on commit bd78d83

Please sign in to comment.