⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbm_mlmap.d2l

📁 转载其他网站的资料与大家分享
💻 D2L
📖 第 1 页 / 共 5 页
字号:
		// Hmm, could also do bucket array o_o
//		print("Checking " + p2s({x:x,y:y}) + " collision");

//		var room.getRoom();
		var room = getRoom();
		var vx, vy;
		var init = false;
		var cnt = 0;
		if (room) do {
//			cnt++;
			if (x >= room.x*5 && y >= room.y*5) {
				if (!room.getStat(11)) { init = true; room.init(); }
				if ((x - room.x*5) <= room.getStat(11) && (y - room.y*5) <= room.getStat(12)) {
//					var v = room.getCollision(vx, vy);
//					print("found " + p2s({x:x,y:y}) + " in room " + cnt + ", value " + v + " , dimensions: " + room.getStat(11) + "x" + room.getStat(12));
//					delay(400);
					return room.getCollision(x - room.x*5, y - room.y*5);
				}
				if (init) { init = false; room.release(); } 
			}
		} while (room.getNext());
		
		return undefined;
	}

	function _loadpos(x, y) {
		
		var room, q, r;
		var init = false;
		var list, area;
		
		for (var r = 0; r < this.RoomList.length; r++) {

//			delay(500);
			
			if (this.RoomList[r].loaded == false && x >= this.RoomList[r].x && y >= this.RoomList[r].y && x <= this.RoomList[r].xmax && y <= this.RoomList[r].ymax) {
//				print("Check room " + r + " list length: " + this.RoomList.length);
				room = getRoom();
				if (room) do {
//					if (room.number == this.RoomList[r].number) {
					if (room.x == this.RoomList[r].orgx && room.y == this.RoomList[r].orgy) {
						// Load the room
//						print("Loading room " + room.number);
						q = room.y*5 - this.miny;
						p = room.x*5 - this.minx;

						if (!room.getStat(12)) { init = true; room.init(); } 
						for(var yy = 0; yy < room.getStat(12); yy++) {
							for(var xx = 0; xx < room.getStat(11); xx++) {
//								print("Setting point " + (q + yy) + "," + (r + xx));
//								delay(20);
								this.Area[q + yy][p + xx] = (0 | room.getCollision(xx,yy));
							}
						}
						if (init) { room.release(); init = false;}
						this.RoomList[r].loaded = true;
					}
				} while (room.getNext());
			}
		}
	}

	//////////////////////////////////////////////////////////////////////
	// oMap.DumpMap(_filename, _type, _bit)
	// -------------------------------------------------------------------
	// Used to dump the map to a file
	// _type 0 == Hex dump
	// _type 1 == text character dump
	//////////////////////////////////////////////////////////////////////
	function oMap_dumpmap(_filename, _type, _bit) {
		var line = "";
		var bit = 0x1 << _bit;

		hFile = fileOpen("output/" + _filename, 1);
		if(!_type) {
			for (var y = 0; y < this.sizey; y++) {
				for (var x = 0; x < this.sizex; x++) {
					if(this.Area[y][x] != undefined)
						line += "0x" + this.Area[y][x].toString(16) + " ";
					else line += "0xFFFF ";
				}
				hFile.writeLine(line);
				line = "";
			}
		}
		else if(_type ==1) {
			for (var y = 0; y < this.sizey; y++) {
				for (var x = 0; x < this.sizex; x++) {

					if(this.Area[y][x] & bit)
						line += "X";
					else if(this.Area[y][x] & 0x10000)
						line += "1";
					else if(this.Area[y][x] & 0x20000)
						line += "2";
					else if(this.Area[y][x] & 0x40000)
						line += "3";
					else if(this.Area[y][x] & 0x80000)
						line += "4";
					//else if(this.Area[y][x] & 0x100000)
					//	line += "+";
					//else if(this.Area[y][x] & 0x200000)
					//	line += "-";
					else
						line += ".";

				}
				hFile.writeLine(line);
				line = "";
			}
		}

		hFile.close();
	}
}

//////////////////////////////////////////////////////////////////////
// mlwalkto(x, y, walkcallflag)
// -------------------------------------------------------------------
// walks to the given coordinates
// returns: true on success, false on failure
// requires mlMapInitializeMap: NO
//////////////////////////////////////////////////////////////////////
function mlwalkto(x, y, walkcallflag, currentpoint) //currentpoint is for internal use only
{
	var startX = me.x;
	var startY = me.y;
	var currDestX = x;
	var currDestY = y;

	if (Math.abs(me.x - x) <= 1 && Math.abs(me.y - y) <= 1) return 1;

	var trys = 0;
	var ntrys=12;
	var thrash = 0;
	var nthrash=3;
	var startX = me.x;
	var startY = me.y;
	var currDestX = x;
	var currDestY = y;
	var door;
	mlprint("Walking to (lib)[" + x + ", " + y + "]");

	//if (Math.sqrt(Dist2(x, y, mdx[3], mdx[3])) > Math.sqrt(Dist2(me.x, me.y, mdx[3], mdx[3])) && midi != 3)
	//	continue;
	directionalmove=0;

	while ((Math.abs(me.x - x) > 2 || Math.abs(me.y - y) > 2) && trys <= ntrys)
	{
		me.move(currDestX, currDestY);
		//call optional function if true
		if (walkcallflag)
		{
			var retvalin = walkcalls(x,y, currentpoint, walkcallflag);
			if (retvalin == mlSTEPBACK)
				me.move(currDestX, currDestY);
			if (retvalin > 1 && retvalin != mlSTEPBACK && retvalin != mlSTEPAHEAD)
				return retvalin;
			//Now move back where we were so we can so we can continue on
			//me.move(currDestX, currDestY);
			if (Math.abs(me.x - x) <= 2 && Math.abs(me.y - y) <= 2)
				return 1;
		}
		delay(walkdel);
		trys++;
		if ((Math.abs(me.x - startX) < 3 && Math.abs(me.y - startY) < 3))
		{
			if (thrash >= nthrash)
			{
				var direction = Math.abs(Math.floor((Math.atan2(x-me.x , y-me.y)) * 180 / 3.1415) - 180);
				if (direction > 0 && direction < 45){
					currDestX = me.x+5;
					currDesty = me.y+1;
				}
				else if(direction > 45 && direction < 90) {
					currDestX = me.x-1;
					currDestY = me.y-5;
				}
				else if (direction > 90 && direction < 135){
					currDestX = me.x-1;
					currDestY = me.y+5;
				}
				else if(direction > 135 && direction < 180) {
					currDestX = me.x+5;
					currDestY = me.y-1;
				}
				else if (direction > 180 && direction < 225){
					currDestX = me.x-5;
					cuurDestY = me.y-1;
				}
				else if(direction > 225 && direction < 270) {
					currDestX = me.x+1;
					cuurDestY = me.y+5;
				}
				else if (direction > 270 && direction < 315){
					currDestX = me.x+1;
					currDestY = me.y-5;
				}
				else if(direction > 315 && direction < 360) {
					currDestX = me.x-5;
					currDestY = me.y+1;
				}
				else
				{
					//make a randome move
					var dx = currDestX - startX;
					var dy = currDestY - startY;
					var a = Math.atan2(dx, dy);
					a = Math.floor(a * 100) + 157;  // + pi/2;
					var direction = rnd(a, a+314)/100;  // + pi
					currDestX = Math.floor(Math.sin(direction)*20) + me.x;
					currDestY = Math.floor(Math.cos(direction)*20) + me.y;
				}
				directionalmove = 0;

				//########################################
				thrash=0;
				directionalmove++;
				while (me.mode !=1)
					delay(50);
			} else thrash++;
		}
		else
		{
			startX = me.x;
			startY = me.y;
			currDestX = x;
			currDestY = y;
		}

	}
	if (Math.abs(me.x - x) > 4 || Math.abs(me.y - y) > 4)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

//////////////////////////////////////////////////////////////////////
// mlteleportto(x, y, walkcallflag)
// -------------------------------------------------------------------
// teleports to the given coordinates
// returns: true on success, false on failure
// requires mlMapInitializeMap: NO
//////////////////////////////////////////////////////////////////////
function mlteleportto(x, y, walkcallflag, currentpoint) //current point is used internally
{
	var DestX = x;
	var DestY = y;

		if (walkcallflag)
		{
			var retvalin = walkcalls(x,y, currentpoint, walkcallflag);
			if(currentpoint)
			{
				if (retvalin == mlSTEPBACK)
					mlCast("Teleport",0,DestX,DestY);
				if (retvalin > 1 && retvalin != mlSTEPBACK && retvalin != mlSTEPAHEAD)
					return retvalin;
			}
		}

		for (var rv = 0; rv < 3; rv++)
		{
			mlCast("Teleport",0,x,y);

			// Check to see see if we have arrived at our destination
			if ((Math.abs(me.x - x) < 6) && (Math.abs(me.y - y) < 6))
			{
				mlprint("Teleported to [" + me.x + ", " + me.y + "]");
				break;
			}
		}

	if ((Math.abs(me.x - DestX) < 6) && (Math.abs(me.y - DestY) < 6))
		return 1;
	else
		return 0;

}

//#################
//Utility Functions
//#################
function mlinitdebuglog()
{
	var debugfile = fileOpen(mldebuglog, 1);
	debugfile.writeLine("Debug Initialized");
	debugfile.close();
}

function mlprint(string)
{
	if (mldebuglevel > 0)
	{
		var debugfile = fileOpen(mldebuglog, 2);
		debugfile.writeLine(string);
		debugfile.close();
	}
	if (mldebuglevel > 1)
	{
		print(string);
		delay(mldebugdelay);
	}
}

function mlCast(which,usehand,x,y)
{
	if(!usehand) usehand = 0;

	me.setSkill(which,usehand);
	var count=0;
	while(1) {
		if(me.getSkill(usehand) == which) break;
		delay(20);
		count++;
		if(count>50) {
			print("Could not set skill");
			return false;
		}
	}

	switch(arguments.length)
	{
		case 0: break;
		case 2: me.useSkill(usehand); break;
		case 3:	x.useSkill(usehand);
			break;
		case 4: me.useSkillAt(x,y,usehand); break;
	}
	mcheck=mlModeWait();
	while (me.mode==mcheck)
	{
		if(x)
		{
			if (x.hp <= 0) return true;
		}
		delay(10);
	}
	return true;
}

function mlModeWait()
{
	for (qw = 1; qw <= 20; qw++)
	{
		var mymode = me.mode;
		if (mymode==7 || mymode==8 || (mymode>9 && mymode<19)) return mymode;
		delay(20);
	}
	return 10;
}

function mlgetClosestObject(x, y, r, n, s) {
	if (arguments.length < 4)
	{
		n = null;
		s = null;
	}
	closest_dist = r; obj_id = 0;
	obj = getUnit(2, n, s);
	if (obj) do {
			p = obj.getParent();
			if (!p || p.name != me.name) {
				dist = mlDist(obj.x, obj.y, x, y);
				if (dist <= closest_dist) {
					closest_dist = dist;
					obj_id = obj.id
				}
			}
	}while(obj && obj.getNext(n));
	// - skip this if no objs found
	if (obj_id)
	{
		obj = getUnit(2, n, s);
		if (obj) do {
				p = obj.getParent();
				if (!p || p.name != me.name) {
					if (obj.id == obj_id) {
						return obj;
					}
				}
		}while(obj && obj.getNext());
		print("Close object not on 2nd detect");
	}
	return false;
}

function mlDist(x1, y1, x2, y2) {
	return Math.floor(Math.sqrt(mlDist2(x1, y1, x2, y2))); }

function mlDist2(x1, y1, x2, y2) {
	return Math.floor((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

function mlInTown(unit) {
	switch(unit.area) {
		case 1: case 40: case 75: case 103: case 109: return true;
		default: return false;
	}
}



function getAngle(x1, y1, x2, y2) {
	return Math.floor((Math.atan2(y2-y1 , x2-x1)) * 180 / 3.1415);
}

var the_id = 0;
function NextId() {
	return the_id++;
}

function oNode(_x, _y, _o, _c, _p, _g, _h){
	this.x = _x;
	this.y = _y;
	this.open = _o;
	this.closed = _c;
	this.parent = _p;
	this.g = _g;	//cost to dest, will be either euclidean or manhattan, latter being the quicker
	this.h = _h;	//total cost
	this.f;	//cost so far
	this.id = NextId(); // hacky shacky
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -