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

Development #50

Merged
merged 4 commits into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
905 changes: 905 additions & 0 deletions d2bs/kolbot/libs/bots/GeneticAlgorithmAttack.js

Large diffs are not rendered by default.

94 changes: 57 additions & 37 deletions d2bs/kolbot/libs/common/Prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ String.prototype.trim = function () {
};

// Check if unit is idle
Unit.prototype.__defineGetter__("idle",
function () {
Object.defineProperty(Unit.prototype, "idle", {
get: function () {
if (this.type > 0) {
throw new Error("Unit.idle: Must be used with player units.");
}

return (this.mode === 1 || this.mode === 5 || this.mode === 17); // Dead is pretty idle too
});
},
enumerable: true
});

Unit.prototype.__defineGetter__("gold",
function () {
Object.defineProperty(Unit.prototype, "gold", {
get: function () {
return this.getStat(14) + this.getStat(15);
});
},
enumerable: true
});

// Death check
Unit.prototype.__defineGetter__("dead",
function () {
Object.defineProperty(Unit.prototype, "dead", {
get: function () {
switch (this.type) {
case 0: // Player
return this.mode === 0 || this.mode === 17;
Expand All @@ -58,32 +62,40 @@ Unit.prototype.__defineGetter__("dead",
default:
return false;
}
});
},
enumerable: true
});

// Check if unit is in town
Unit.prototype.__defineGetter__("inTown",
function () {
Object.defineProperty(Unit.prototype, "inTown", {
get: function () {
if (this.type > 0) {
throw new Error("Unit.inTown: Must be used with player units.");
}

return [1, 40, 75, 103, 109].indexOf(this.area) > -1;
});
},
enumerable: true
});

// Check if party unit is in town
Party.prototype.__defineGetter__("inTown",
function () {
Object.defineProperty(Party.prototype, "inTown", {
get: function () {
return [1, 40, 75, 103, 109].indexOf(this.area) > -1;
});
},
enumerable: true
});

Unit.prototype.__defineGetter__("attacking",
function () {
Object.defineProperty(Unit.prototype, "attacking", {
get: function () {
if (this.type > 0) {
throw new Error("Unit.attacking: Must be used with player units.");
}

return [7, 8, 10, 11, 12, 13, 14, 15, 16, 18].indexOf(this.mode) > -1;
});
},
enumerable: true
});

// Open NPC menu
Unit.prototype.openMenu = function (addDelay) {
Expand Down Expand Up @@ -228,8 +240,8 @@ Unit.prototype.buy = function (shiftBuy, gamble) {
};

// Item owner name
Unit.prototype.__defineGetter__("parentName",
function () {
Object.defineProperty(Unit.prototype, "parentName", {
get: function () {
if (this.type !== 4) {
throw new Error("Unit.parentName: Must be used with item units.");
}
Expand All @@ -241,7 +253,9 @@ Unit.prototype.__defineGetter__("parentName",
}

return false;
});
},
enumerable: true
});

// You MUST use a delay after Unit.sell() if using custom scripts. delay(500) works best, dynamic delay is used when identifying/selling (500 - item id time)
Unit.prototype.sell = function () {
Expand Down Expand Up @@ -503,8 +517,8 @@ Unit.prototype.getSuffix = function (id) {
return false;
};

Unit.prototype.__defineGetter__("dexreq",
function () {
Object.defineProperty(Unit.prototype, "dexreq", {
get: function () {
var finalReq,
ethereal = this.getFlag(0x400000),
reqModifier = this.getStat(91),
Expand All @@ -517,10 +531,12 @@ Unit.prototype.__defineGetter__("dexreq",
}

return Math.max(finalReq, 0);
});
},
enumerable: true
});

Unit.prototype.__defineGetter__("strreq",
function () {
Object.defineProperty(Unit.prototype, "strreq", {
get: function () {
var finalReq,
ethereal = this.getFlag(0x400000),
reqModifier = this.getStat(91),
Expand All @@ -533,10 +549,12 @@ Unit.prototype.__defineGetter__("strreq",
}

return Math.max(finalReq, 0);
});
},
enumerable: true
});

Unit.prototype.__defineGetter__('itemclass',
function () {
Object.defineProperty(Unit.prototype, 'itemclass', {
get: function () {
if (getBaseStat(0, this.classid, 'code') === undefined) {
return 0;
}
Expand All @@ -550,7 +568,9 @@ Unit.prototype.__defineGetter__('itemclass',
}

return 0;
});
},
enumerable: true
});

Unit.prototype.getStatEx = function (id, subid) {
var i, temp, rval, regex;
Expand Down Expand Up @@ -1257,8 +1277,11 @@ Unit.prototype.castChargedSkill = function (...args) {
return false;
};

PresetUnit.prototype.__defineGetter__('unit', function () {
return getUnits(this.type, this.id).first();
Object.defineProperty(PresetUnit.prototype, 'unit', {
get: function () {
return getUnits(this.type, this.id).first();
},
enumerable: true
});

/**
Expand All @@ -1283,7 +1306,8 @@ function getUnits(...args) {
Object.defineProperty(Unit.prototype, 'distance', {
get: function() {
return getDistance(me,this);
}
},
enumerable: true
});


Expand Down Expand Up @@ -1334,10 +1358,6 @@ if (!Array.prototype.findIndex) {
});
}

PresetUnit.prototype.__defineGetter__('unit', function () {
return getUnits(this.type, this.id).first();
});

String.prototype.lcsGraph = function (compareToThis) {
if (!this.length || !compareToThis || !compareToThis.length) {
return null;
Expand Down
28 changes: 28 additions & 0 deletions d2bs/kolbot/libs/modules/GameData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const PRESET_SUPER_COUNT = 66;
const PRESET_PLACE_COUNT = 37;
const AREA_INDEX_COUNT = 137;
const MISSILES_COUNT = 385;
const SUPER = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 1, 0, 1, 4, 0, 2, 3, 1, 0, 1, 1, 0, 0, 0, 1, 3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 5, 1, 1, 1, 1, 3];
const AREA_LOCALE_STRING = [5389, 5055, 5054, 5053, 5052, 5051, 5050, 5049, 5048, 5047, 5046, 5045, 5044, 5043, 5042, 5041, 5040, 5039, 5038, 5037, 5036, 5035, 5034, 5033, 5032, 5031, 5030, 5029, 5028, 5027, 5026, 5025, 5024, 5023, 5022, 5021, 5020, 5019, 5018, 788, 852, 851, 850, 849, 848, 847, 846, 845, 844, 843, 842, 841, 840, 839, 838, 837, 836, 835, 834, 833, 832, 831, 830, 829, 828, 827, 826, 826, 826, 826, 826, 826, 826, 825, 824, 820, 819, 818, 817, 816, 815, 814, 813, 812, 810, 811, 809, 808, 806, 805, 807, 804, 845, 844, 803, 802, 801, 800, 799, 798, 797, 796, 795, 790, 792, 793, 794, 791, 789, 22646, 22647, 22648, 22649, 22650, 22651, 22652, 22653, 22654, 22655, 22656, 22657, 22658, 22659, 22660, 22662, 21865, 21866, 21867, 22663, 22664, 22665, 22667, 22666, 5389, 5389, 5389, 5018];
const MONSTER_KEYS = [
Expand Down Expand Up @@ -120,6 +121,10 @@
Min: getBaseStat('monstats', index, 'PartyMin'),
Max: getBaseStat('monstats', index, 'PartyMax')
}),
Velocity: getBaseStat('monstats', index, 'Velocity'),
Run: getBaseStat('monstats', index, 'Run'),
SizeX: getBaseStat('monstats', index, 'SizeX'),
SizeY: getBaseStat('monstats', index, 'SizeY'),
});
}

Expand Down Expand Up @@ -181,6 +186,28 @@

//(PresetMonsters);

/**
* MissilesData
*/

var MissilesData = Array(MISSILES_COUNT);

for (let i = 0; i < MissilesData.length; i++) {
let index = i;
MissilesData[i] = ({
Index: index,
ClassID: index,
InternalName: getBaseStat('missiles', index, 'Missile'),
Velocity: getBaseStat('missiles', index, 'Vel'),
VelocityMax: getBaseStat('missiles', index, 'MaxVel'),
Acceleration: getBaseStat('missiles', index, 'Accel'),
Range: getBaseStat('missiles', index, 'Range'),
Size: getBaseStat('missiles', index, 'Size'),
});
}

//(MissilesData);

/**
* AreaData[areaID]
* .Super = number of super uniques present in this area
Expand Down Expand Up @@ -1336,6 +1363,7 @@
};

// Export data
GameData.MissilesData = MissilesData;
GameData.AreaData = AreaData;
GameData.isEnemy = isEnemy;
GameData.isAlive = isAlive;
Expand Down
8 changes: 7 additions & 1 deletion d2bs/kolbot/libs/modules/Precast.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
me.gametype !== 0 && me.weaponswitch !== result.slot && me.switchWeapons(result.slot);

print('Precasting ' + getSkillById(result.skillId) + ' on slot ' + result.slot);
me.cast(result.skillId);
if (result.skillId === sdk.skills.Enchant) { // Cast enchant on everyone that is a party member
return getUnits(-1).filter(unit=>unit.allies && unit.getState(sdk.states.Enchant)).cast(result.skillId);
}
return me.cast(result.skillId);
});

me.switchWeapons(beforeSlot);
Expand Down Expand Up @@ -49,6 +52,9 @@
// In case no function is given, see if we have the state
return undefined;

case typeof what.skillId === sdk.skills.Enchant:
// If any monster/unit around us is in enchant-less, return true.
return !!getUnits(-1).filter(unit=>unit.allies && unit.getState(sdk.states.Enchant)).length;
case typeof what.skillId === 'number' || Array.isArray(what.skillId):
// If skillId is an array, it can, for example the frozen armor / chilling armor combo,
// we dont need to re-pre-cast it if either state is set. So cast it to an array and loop over it,
Expand Down
2 changes: 0 additions & 2 deletions d2bs/kolbot/libs/modules/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
function Socket(hostname, port) {
typeof Socket.__socketCounter === 'undefined' && (Socket.__socketCounter = 0);



const myEvents = new Events;
this.connect = () => (this.socket = buildinSock.open(hostname, port)) && this;

Expand Down
1 change: 1 addition & 0 deletions d2bs/kolbot/libs/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,7 @@ let sdk = {
NPC: 1,
Monsters: 1,
Objects: 2,
Missiles: 3,
Item: 4,
Stairs: 5, // ToDo: might be more as stairs
},
Expand Down
33 changes: 32 additions & 1 deletion d2bs/kolbot/libs/unit/Attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,37 @@
!this.getState(104) && // nodraw
!this.getState(107) && // shatter
!this.getState(118);
}
};

Object.defineProperty(Unit.prototype, 'partied', {
get: function () {
if (this.type > sdk.unittype.Monsters) return false; // Only players can be a member of a party, or pets/merc's (aka monsters)

let self = this;
if (this.type === sdk.unittype.Monsters) {
// In case this monster is owned by someone, it can be a party member
const parent = this.getParent();
if (!parent || parent.type !== sdk.unittype.Player) return false; // Doesn't have an (player) parent.

self = parent; // we want to know if we are partied with the owner of this pet/merc
}

if (self === me) return true; // we are always "partied" with ourselfs (trick for our own merc)

// get party object, and my party
const party = getParty(), myPartyId = (party || {partyid: 0}).partyid;
if (!party || myPartyId === 0xFFFF) return false; // We are not in the same party, if im not in a party

for (; party && party.getNext();) if (party.name === self.name && myPartyId === party.partyid) return true;

return false;
}
});

Object.defineProperty(Unit.prototype, 'allies', {
get: function () {
return ([sdk.unittype.Player,sdk.unittype.Monsters].indexOf(this.type)+1 && this.partied);
}
});

})(require, delay);
4 changes: 4 additions & 0 deletions d2bs/kolbot/libs/unit/Movement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
return this;
};

Unit.prototype.moveBy = function (offX, offY, clearPath, pop) {
return this.distance > 5 && Pather.moveTo(this.x + offX, this.y + offY, undefined, clearPath, pop);
};

PresetUnit.prototype.moveTo = function (offX, offY, clearPath, pop) {
Pather.moveTo(this.roomx * 5 + this.x + (offX || 0), this.roomy * 5 + this.y + (offY || 0), 4, clearPath, pop);
return this;
Expand Down
Loading