All pastes #981988 Raw Edit

Something

public text v1 · immutable
·published 2008-04-12 05:34 UTC
rendered paste body
// Public D2BS constants

// Character Class
const NTC_CHAR_CLASS_AMAZON = 0;
const NTC_CHAR_CLASS_SORCERESS = 1;
const NTC_CHAR_CLASS_NECROMANCER = 2;
const NTC_CHAR_CLASS_PALADIN = 3;
const NTC_CHAR_CLASS_BARBARIAN = 4;
const NTC_CHAR_CLASS_DRUID = 5;
const NTC_CHAR_CLASS_ASSASSIN = 6;

// Act 1 NPCs
const NTC_NPC_ID_AKARA = 148;
const NTC_NPC_ID_WARRIV_ACT_1 = 155;
const NTC_NPC_ID_CHARSI = 154;
const NTC_NPC_ID_GHEED = 147;
const NTC_NPC_ID_KASHYA = 150;
const NTC_NPC_ID_CAIN_TRISTRAM = 146;
const NTC_NPC_ID_CAIN_ACT_1 = 244;

// Act 2 NPCs
const NTC_NPC_ID_FARA = 178;
const NTC_NPC_ID_LYSANDER = 202;
const NTC_NPC_ID_GREIZ = 198;
const NTC_NPC_ID_ELZIX = 199;
const NTC_NPC_ID_MESHIF_ACT_2 = 210;
const NTC_NPC_ID_DROGNAN = 177;
const NTC_NPC_ID_ATMA = 176;
const NTC_NPC_ID_WARRIV_ACT_2 = 175; 
const NTC_NPC_ID_CAIN_ACT_2 = 245;
const NTC_NPC_ID_JERHYN = 201;
const NTC_NPC_ID_TYRAEL_ACT_2 = 251;

// Act 3 NPCs
const NTC_NPC_ID_MESHIF_ACT_3 = 264;
const NTC_NPC_ID_CAIN_ACT_3 = 246;
const NTC_NPC_ID_ALKOR = 254;
const NTC_NPC_ID_ASHEARA = 252;
const NTC_NPC_ID_ORMUS = 255;
const NTC_NPC_ID_HRATLI = 253;

// Act 4 NPCs
const NTC_NPC_ID_CAIN_ACT_4 = 265;
const NTC_NPC_ID_HALBU = 257;
const NTC_NPC_ID_TYRAEL_ACT_4 = 367;
const NTC_NPC_ID_JAMELLA = 405;

// Act 5 NPCs
const NTC_NPC_ID_CAIN_ACT_5 = 520;
const NTC_NPC_ID_TYRAEL_ACT_5 = 521;
const NTC_NPC_ID_LARZUK = 511;
const NTC_NPC_ID_ANYA_FROZEN_RIVER = 527;
const NTC_NPC_ID_ANYA_TOWN = 512;
const NTC_NPC_ID_MALAH = 513;
const NTC_NPC_ID_QUALKEHK = 515;
const NTC_NPC_ID_NIHLATHAK_TOWN = 514;
const NTC_NPC_ID_NIHLATHAK_HALLS_OF_VAUGHT = 526;

// UNIT types
const NTC_UNIT_PLAYER = 0;
const NTC_UNIT_NPC = 1;
const NTC_UNIT_MERC = NTC_UNIT_NPC;
const NTC_UNIT_MONSTER = NTC_UNIT_NPC;
const NTC_UNIT_OBJECT = 2;
const NTC_UNIT_MISSILE = 3;
const NTC_UNIT_ITEM = 4;
const NTC_UNIT_TILE = 5;
const NTC_UNIT_STASH = 267;

const NTC_AREA_ID_ACT_1 = 1;
const NTC_AREA_ID_ACT_2 = 40;
const NTC_AREA_ID_ACT_3 = 75;
const NTC_AREA_ID_ACT_4 = 103;
const NTC_AREA_ID_ACT_5 = 109;

// COLOR types
const NTC_COLOR_BASE_WHITE = 0;
const NTC_COLOR_BASE_RED = 1;
const NTC_COLOR_BASE_GREEN = 2;
const NTC_COLOR_BASE_BLUE = 3;
const NTC_COLOR_BASE_GOLD = 4;
const NTC_COLOR_BASE_GRAY = 5;
const NTC_COLOR_BASE_BLACK = 6;
const NTC_COLOR_BASE_GOLD2 = 7;
const NTC_COLOR_BASE_ORANGE = 8;
const NTC_COLOR_BASE_YELLOW = 9;

const NTC_HAND_RIGHT = 0;
const NTC_HAND_LEFT = 1;

const NTC_CLICK_LDOWN = 0;
const NTC_CLICK_LHOLD = 1;
const NTC_CLICK_LUP = 2;
const NTC_CLICK_RDOWN = 3;
const NTC_CLICK_RHOLD = 4;
const NTC_CLICK_RUP = 5;

const NTC_SHIFT_NONE = 0;
const NTC_SHIFT_HOLD = 1;

const NTC_DELAY_FRAME = 40;

var NTC_ItemQualityToNameList = new Array(9);
NTC_ItemQualityToNameList[0] = "None";
NTC_ItemQualityToNameList[1] = "Low Quality";
NTC_ItemQualityToNameList[2] = "Normal";
NTC_ItemQualityToNameList[3] = "Superior";
NTC_ItemQualityToNameList[4] = "Magic";
NTC_ItemQualityToNameList[5] = "Set";
NTC_ItemQualityToNameList[6] = "Rare";
NTC_ItemQualityToNameList[7] = "Unique";
NTC_ItemQualityToNameList[8] = "Crafted";

function NTC_Include(filepath)
{
	if(isIncluded(filepath))
		return true;

	return include(filepath);
}

function NTC_IncludeConfig()
{
	var _configname;
	var _configfile;

	switch(me.classid)
	{
	case NTC_CHAR_CLASS_AMAZON:
		_configname = "NTConfig_Amazon_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_SORCERESS:
		_configname = "NTConfig_Sorceress_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_NECROMANCER:
		_configname = "NTConfig_Necromancer_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_PALADIN:
		_configname = "NTConfig_Paladin_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_BARBARIAN:
		_configname = "NTConfig_Barbarian_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_DRUID:
		_configname = "NTConfig_Druid_" + me.charname + ".dbl"
		break;

	case NTC_CHAR_CLASS_ASSASSIN:
		_configname = "NTConfig_Assassin_" + me.charname + ".dbl"
		break;
	}

	_configfile = fileOpen("libs/config/" + _configname, 0);
	if(_configfile)
		_configfile.close();
	else
		print("ÿc1Can't find " + _configname);

	NTC_Include("config/" + _configname);
}

function NTC_IncludeLibs()
{
	NTC_Include("common/NTAreas.dbl");
	NTC_Include("common/NTAttack.dbl");
	NTC_Include("common/NTMove.dbl");
	NTC_Include("common/NTPrecast.dbl");
	//NTC_Include("common/NTScreenHook.dbl");
	NTC_Include("common/NTSnagIt.dbl");
	NTC_Include("common/NTTown.dbl");
	NTC_Include("common/NTTownManager.dbl");
	NTC_Include("common/NTTownMove.dbl");
}

function NTC_DoCast(skillid, usehand, x, y)
{
	var _hand;
	var _shift;

	if(arguments.length < 1)
		return false;

	if(arguments.length == 1)
	{
		_hand = NTC_CLICK_RDOWN;
		_shift = NTC_SHIFT_NONE;
		usehand = NTC_HAND_RIGHT;
	}
	else
	{
		if(usehand == NTC_HAND_RIGHT)
		{
			_hand = NTC_CLICK_RDOWN;
			_shift = NTC_SHIFT_NONE;
		}
		else if(usehand == NTC_HAND_LEFT)
		{
			_hand = NTC_CLICK_LDOWN;
			_shift = NTC_SHIFT_NONE;
		}
		else
		{
			_hand = NTC_CLICK_LDOWN;
			_shift = NTC_SHIFT_HOLD;
			usehand = NTC_HAND_LEFT;
		}
	}

	if(NTC_PutSkill(skillid, usehand))
	{
		if(!NTC_ClearCursor())
			return false;

		for(var i = 0 ; i < 5 ; i++)
		{
			switch(arguments.length)
			{
			case 1:
			case 2:
				NTC_DoClick(_hand, _shift);
				break;

			case 3:
				if(x.type != NTC_UNIT_MONSTER)
					return false;

				NTC_DoClick(_hand,_shift, x);
				break;

			case 4:
				NTC_DoClick(_hand,_shift, x, y);
				break;
			}

			if(NTC_CheckDoCastInt())
				return NTC_WaitCastDone();
		}
	}

	return false;
}

function NTC_PutSkill(skillid, hand)
{
	var _sethand;

	if(NTC_IsPassiveSkill(skillid))
		return false;

	if(!NTC_CheckSkill(skillid))
		return false;

	if(hand == NTC_HAND_RIGHT)
		_sethand = 2;
	else
		_sethand = 3;

	if(me.getSkill(_sethand) != skillid)
	{
		for(var i = 0 ; i < 60 ; i++)
		{
			if((i % 20) == 0)
				me.setSkill(skillid, hand);

			NTC_Delay(NTC_DELAY_FRAME);

			if(me.getSkill(_sethand) == skillid)
				return true;
		}

		return false;
	}

	return true;
}

function NTC_CheckSkill(skillid)
{
	var _skill = me.getSkill(skillid, 1);

	if(_skill > 0)
		return _skill;

	return false;
}

function NTC_GetCastDelay(skillid)
{
	switch(skillid)
	{
	// Amazon
	case 15: return 500;  // "Poison Javelin"
	case 25: return 4000; // "Plague Javelin"
	case 27: return 1000; // "Immolation Arrow"

	// Sorceress
	case 51: return 1400; // "Fire Wall"
	case 56: return 1200; // "Meteor"
	case 62: return 2000; // "Hydra"
	case 59: return 1800; // "Blizzard"
	case 64: return 1000; // "Frozen Orb"

	// Paladin
	case 121: return 1000; // "Fist of the Heavens"

	// Druid
	case 225: return 600;  // "Firestorm"
	case 229: return 2000; // "Molten Boulder"
	case 234: return 2000; // "Eruption"
	case 244: return 4000; // "Volcano"
	case 249: return 6000; // "Armageddon"
	case 250: return 6000; // "Hurricane"
	case 223: return 1000; // "Werewolf"
	case 228: return 1000; // "Werebear"
	case 247: return 1000; // "Grizzly Bear"

	// Assassin
	case 275: return 1000; // "Dragon Flight"
	case 277: return 2000; // "Blade Sentinel"
	case 268: return 6000; // "Shadow Warrior"
	case 279: return 6000; // "Shadow Master"
	}

	return 0;
}

function NTC_IsLeftSkill(skillid)
{
	if(NTC_IsPassiveSkill(skillid))
		return false;

	var _leftskilllist = [0,2,4,5,6,7,10,11,12,14,15,16,19,20,21,22,24,25,26,27,30,
			31,34,35,36,38,39,41,45,47,49,53,55,64,67,73,84,93,96,97,
			101,106,107,111,112,116,121,126,132,133,139,140,143,144,
			147,151,152,225,229,230,232,233,238,239,240,242,243,245,
			248,251,254,255,256,257,259,260,265,266,269,270,274,275,280];

	for(var i = 0 ; i < _leftskilllist.length ; i++)
	{
		if(_leftskilllist[i] == skillid)
			return true;
	}

	return false;
}

function NTC_IsPassiveSkill(skillid)
{
	var _passiveskilllist = [9,13,18,23,29,33,37,61,63,65,69,79,89,127,128,
				129,134,135,136,141,145,148,153,224,252,263];

	for(var i = 0 ; i < _passiveskilllist.length ; i++)
	{
		if(_passiveskilllist[i] == skillid)
			return true;
	}

	return false;
}

// spectype : 0x00 = Normal Monster, 0x01 = Super Unique, 0x02 = Champion, 0x04 = Boss, 0x08 = Minion
function NTC_FindMonster(classid, spectype)
{
	var _monster;

	if(arguments.length < 1)
		return false;

	if(arguments.length < 2)
		spectype = 0;

	_monster = NTC_GetUnit(NTC_UNIT_MONSTER, classid);

	if(_monster)
	{
		if(spectype)
		{
			do
			{
				if(_monster.type == NTC_UNIT_MONSTER && (_monster.spectype & spectype))
					return copyUnit(_monster);
			} while(_monster.getNext());
		}
		else
			return _monster;
	}

	return false;
}

function NTC_DoWeaponSwitch(switchto)
{
	if(arguments.length < 1)
		switchto = (me.weaponswitch == 0) ? 1 : 0;
	else if(me.weaponswitch == switchto)
		return true;

	if(!NTC_WaitCastDone())
		return false;

	for(var i = 0 ; i < 75 ; i++)
	{
		if((i % 25) == 0)
			weaponSwitch(0);

		NTC_Delay(NTC_DELAY_FRAME);

		if(me.weaponswitch == switchto)
			return true;
	}

	return false;
}

function NTC_DoClick(button, shift, x, y)
{
	if(button != NTC_CLICK_LDOWN)
		button = NTC_CLICK_RDOWN;

	if(!NTC_WaitCastDone())
		return false;

	switch(arguments.length)
	{
	case 2:
		clickMap(button, shift, me.x, me.y);
		NTC_Delay(100, NTC_DELAY_FRAME);
		clickMap(button+2, shift, me.x, me.y);

		return true;

	case 3:
		clickMap(button, shift, x);
		NTC_Delay(100, NTC_DELAY_FRAME);
		clickMap(button+2, shift, x);

		return true;

	case 4:
		clickMap(button, shift, x, y);
		NTC_Delay(100, NTC_DELAY_FRAME);
		clickMap(button+2, shift, x, y);

		return true;
	}

	return false;
}

function NTC_MyGold()
{
	return me.getStat(14) + me.getStat(15);
}

function NTC_MyGoldCarry()
{
	return me.getStat(14);
}

function NTC_StashGoldFull()
{
	var _maxgold;
	var _level = me.getStat(12);

	if(_level < 30)
		_maxgold = Math.floor((_level+10)/10) * 50000;
	else
		_maxgold = 800000 + Math.floor((_level-30)/2) * 50000;

	return (_maxgold == me.getStat(15));
}

function NTC_CharGoldFull()
{
	return (me.getStat(14) >= (me.getStat(12)*10000));
}

function NTC_CheckOwner(object, ownername)
{
	var _owner;

	if(!object)
		return false;

	_owner = object.getParent();
	if(!_owner)
		return false;

	if(arguments.length < 2)
	{
		if(_owner == me.name || _owner.name == me.name)
			return true;
	}
	else
	{
		if(_owner == ownername || _owner.name == ownername)
			return true;
	}

	return false;
}

function NTC_ItemToCursor(item)
{
	if(me.itemoncursor)
		return true;

	for(var i = 0 ; i < 30 ; i++)
	{
		if((i % 10) == 0)
			clickItem(0, item);

		NTC_Delay(100);

		if(me.itemoncursor)
		{
			NTC_PingDelay(500);

			return true;
		}
	}

	return false;
}

function NTC_ClearCursor()
{
	if(!me.itemoncursor)
		return true;

	for(var i = 0 ; i < 60 ; i++)
	{
		if((i % 20) == 0)
			NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE);

		NTC_Delay(NTC_DELAY_FRAME);

		if(!me.itemoncursor)
			return true;
	}

	return false;
}

function NTC_GetMerc()
{
	var _merc;

	for(var i = 0 ; i < 2 ; i++)
	{
		_merc = me.getMerc();

		if(_merc)
		{
			if(_merc.hp > 0 && _merc.mode != 12)
				return _merc;

			break;
		}

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_OpenChest(chest)
{
	if(!chest)
		return false;

	if(chest.mode > 0)
		return false;

	for(var i = 0 ; i < 20 ; i++)
	{
		if((i % 5) == 0)
			chest.interact();

		NTC_Delay(100);

		if(chest.mode > 0)
			return true;
	}

	return false;
}

function NTC_Delay(amount, random)
{
	if(arguments.length < 2)
		delay(amount);
	else
		delay(amount+rnd(0, random));
}

function NTC_PingDelay(amount)
{
	var _currentping = me.ping;

	if(_currentping > 100)
		_currentping -= 100;
	else
		_currentping = 0;

	NTC_Delay(amount+_currentping);
}

function NTC_InTown(who)
{
	var _area;

	if(arguments.length < 1)
		who = me;

	while(who.area == 0)
		NTC_Delay(NTC_DELAY_FRAME);

	_area = who.area;

	return (_area == NTC_AREA_ID_ACT_1 || _area == NTC_AREA_ID_ACT_2 || _area == NTC_AREA_ID_ACT_3 || _area == NTC_AREA_ID_ACT_4 || _area == NTC_AREA_ID_ACT_5);
}

function NTC_InMyParty(playerName)
{
	var _player;
	var _myPartyId;

	for(var i = 0 ; i < 2 ; i++)
	{
		_player = getParty();

		if(_player)
		{
			_myPartyId = _player.partyid;

			if(_myPartyId != 65535)
			{
				do
				{
					if(_player.name == playerName && _myPartyId == _player.partyid)
						return true;
				} while(_player.getNext());
			}

			break;
		}

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_GetUnit(unittype, classid)
{
	var _unit;

	for(var i = 0 ; i < 3 ; i++)
	{
		if(arguments.length < 2)
			_unit = getUnit(unittype);
		else
			_unit = getUnit(unittype, classid);

		if(_unit && _unit.type == unittype)
			return _unit;

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_GetPresetUnits(unittype, classid, area)
{
	var _unit;

	if(arguments.length < 3)
		area = me.area;

	for(var i = 0 ; i < 3 ; i++)
	{
		if(arguments.length < 2)
			_unit = getPresetUnits(area, unittype);
		else
			_unit = getPresetUnits(area, unittype, classid);

		if(_unit && _unit.length > 0 && _unit[0].type == unittype)
			return _unit;

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_GetItems(who)
{
	var _items;

	if(arguments.length < 1)
		who = me;

	for(var i = 0 ; i < 2 ; i++)
	{
		_items = who.getItems();

		if(_items)
			return _items;

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_GetBeltSize()
{
	var _items = NTC_GetItems();

	if(!_items)
		return 1;

	for(var i = 0 ; i < _items.length ; i++)
	{
		if(_items[i].mode == 1 && _items[i].bodylocation == 8)
		{
			if(_items[i].code == "lbl" || _items[i].code == "vbl")
				return 2;
			else if(_items[i].code == "mbl" || _items[i].code == "tbl")
				return 3;

			return 4;
		}
	}

	return 1;
}

function NTC_FindScript(scriptname)
{
	var _script;
	var _scriptpath;

	_script = getScript();

	if(_script)
	{
		do
		{
			_scriptpath = _script.name.toLowerCase();

			if(_scriptpath.indexOf(scriptname.toLowerCase()) != -1)
				return _script;
		} while(_script.getNext());
	}

	return false;
}

function NTC_SendMsgToScript(scriptname, msg)
{
	var _script = NTC_FindScript(scriptname);

	if(_script)
	{
		_script.send(msg);

		return true;
	}

	return false;
}

function NTC_StopScript(scriptname)
{
	var _script = NTC_FindScript(scriptname);

	if(_script)
	{
		_script.stop();

		return true;
	}

	return false;
}

function NTC_WaitCastDone()
{
	var _mode;

	for(var i = 0 ; i < 25 ; i++)
	{
		_mode = me.mode;

		if(!(_mode == 7 || _mode == 8 || (_mode >= 10 && _mode <= 16) || _mode == 18))
			return true;

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}

function NTC_SendLogToOOG(logString)
{
	return sendCopyData(null, "D2Manager 2.5", (65535<<16)|65535, me.windowtitle+";"+logString);
}

// Internal function
function NTC_CheckDoCastInt()
{
	var _mode;

	for(var i = 0 ; i < 10 ; i++)
	{
		_mode = me.mode;

		if(_mode == 7 || _mode == 8 || (_mode >= 10 && _mode <= 16) || _mode == 18)
			return true;

		NTC_Delay(NTC_DELAY_FRAME);
	}

	return false;
}