Skip to content

질문/답변

////////////////////////////////////////////////////////////////////////////////
//
// d2jsp-townmove.d2l town movement functions library
//
// Thanks to scavenger for the original code
// Many thanks go to Syadasti for his Dijsktra pathfinding. d2jsp-townmove uses a
// modified version of Syadasti's pathfinding.
//
// Core scripters team : Xizeta, Muellsammler, Vebev, Killkeeper, PSI_Orion
// Version 2.1
// Updated on 2005/04/20
//
// Legal stuff :
// This program is free software; You can redistribute freely as long as this
// header and contents stays intact. Modifications for redistribution can only
// be done by submitting to the core scripters team for approval. If you don't
// want to submit the modifications and wanted to redistribute this script, you
// must rename it by remplacing d2jsp with your own name to avoid conflicts.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
//
////////////////////////////////////////////////////////////////////////////////
var DTM_Version = "2.1";
if ( !isIncluded("common/d2jsp-common.d2l") ) { include("common/d2jsp-common.d2l"); }
if ( !isIncluded("common/d2jsp-move.d2l") ) { include("common/d2jsp-move.d2l"); }

////////////////////////////////////////////////////////////////////////////////
// History of d2jsp-townmove.d2j (previously called TownMove.d2l)
//==============================================================================
// 2.1  - Reverted the changes and redid to it works properly for the act 1 map init.
//      - copied the DM_MoveTo() function and simplified it for our sole purpose in CreateAct1.
// 2.0  - Changed the act 1 map init so it use getPresetUnit() instead of the getUnit().
// 1.9 - Re-added d2jsp-move include to allow successful act 1 initialization (by PSI_Orion)
// 1.8  - Adjusted a error message so it display the act and coordinates for DTM_TownFindPath()
//      - Added a 3rd call to DTM_CreateDjikstra() with a maxsep+10 to be sure a path is found
// 1.7  - Changed a call to me.move() for a clickMap() to remove the legacy code.
//      - Changed the dijkstra pathing not found exception to a debug call.
// 1.6  - Fixed index bug in FindTownPoint and improved Act1 Exit finding
// NOTE for Act 1 SOUTH Exit.  The exit townspot is at the START of the bridge.
// Use the following in your own script to get accross the bridge and out of town
//  if(me.act == 1 && _DTM_Act1Exit == _DTM_Act1SouthExit) {
//  DM_MoveTo(me.x + 50,me.y);
// }
//
// 1.5  - Ammended Act 1 coordinates for portalspot (by PSI_Orion)
// 1.4  - Ammended Act 3 coordinates for Cain (by PSI_Orion)
// 1.3  - Added check for death during movement loop (by PSI_Orion)
// 1.2  - Added Warriv act 2, Atma and Meshif act 3 townspots (thx PSI_Orion for coords)
// 1.1  - Added Warriv townspot
// 1.0  - Converted to the d2jsp common libs nomenclature and trimmed functions
// 0.57 - Fixed bot stopping moving after going to malah
// 0.56 - Removed old pathing (drunken pathing that sometimes actually worked)
//      - Removed setting "use_dijkstra"
//      - Converted to d2jsp version 0.29
//      - Added drognan coordinate (oops)
// 0.53 - Fixed a script line error
// 0.52 - Added callback function for debugging.
//      - Fixed crash when going to stash after visiting a npc
//      - Added debug messages in a few functions. More will be added soon
// 0.51 - Fixed connection interrupted problems
//      - Fixed RealmDown somehow :)
// 0.5: - Some extra movepoints added
//      - Fixed (very) stupid script errors (thanx to SwedishPower)
//      - Randomized the movement timing to prevent RD
// 0.4: - Functions renamed, they now all start with Sc_
//      - Added Dijkstra pathfinding
//      - Improved movement function, less chance to get stuck and now returns
//        false when it fails to follow the town path, ater a few tries
//      - All movepoints re-created
//      - Fixed name of npc, changed ashera to asheara
//      - Added new townspots
//      - Added all acts town exit detection
// 0.3: - Fixed name of npc qual-kehk
//      - Fixed cant find waypoint bug in act1
// 0.2: - Added extra movepoints for act 1 for townportal spot
//      - Improved pathfinding (removed walking back-forward)
// 0.1: - First release
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Spots to use in DTM_TownMove
//==============================================================================
//     A1            A2            A3            A4            A5
//------------------------------------------------------------------------------
// "waypoint"    "waypoint"    "waypoint"    "waypoint"    "waypoint"
// "portalspot"  "portalspot"  "portalspot"  "portalspot"  "portalspot"
// "exit"        "exit"        "exit"        "exit"        "exit"
// "stash"       "stash"       "stash"       "stash"       "stash"
// "gheed"       "fara"        "cain"        "cain"        "larzuk"
// "charsi"      "cain"        "alkor"       "halbu"       "malah"
// "akara"       "lysander"    "asheara"     "tyrael"      "cain"
// "kashya"      "greiz"       "ormus"       "jamella"     "qual-kehk"
// "cain"        "elzix"       "hratli"                    "anya"
// "warriv"      "palace"      "meshif"                    "portal"
//               "sewers"                                  "nihlathak"
//               "meshif"
//               "drognan"
//               "warriv"
//               "atma"
////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Exit flags for Act 1
//////////////////////////////////////////////////////////////////////

var _DTM_Act1SouthExit = 0;
var _DTM_Act1NorthExit = 1;
var _DTM_Act1WestExit = 2;
var _DTM_Act1EastExit = 3;
var _DTM_Act1Exit;

//////////////////////////////////////////////////////////////////////
// List of coordinates for town movement
//////////////////////////////////////////////////////////////////////

// array with movepoints for every act

var _movepoints = new Array(5);
var _DM_UseTeleport = true;  // Use Teleport skill    <<<< 추가한 구문

// act 1 needs to be calculated (Generate_movepoints())
_movepoints[0] = new Array();

// act 2
_movepoints[1] = new Array();
_movepoints[1][0] = new coord();
_movepoints[1][1] = new coord();
_movepoints[1][2] = new coord(5021,5067);
_movepoints[1][3] = new coord(5033,5063);
_movepoints[1][4] = new coord(5033,5052);
_movepoints[1][5] = new coord(5046,5054);
_movepoints[1][6] = new coord(5043,5064);
_movepoints[1][7] = new coord(5057,5061);
_movepoints[1][8] = new coord(5070,5060);
_movepoints[1][9] = new coord(5084,5060);
_movepoints[1][10] = new coord(5096,5060);
_movepoints[1][11] = new coord(5098,5048);
_movepoints[1][12] = new coord(5098,5035);
_movepoints[1][13] = new coord(5097,5073);
_movepoints[1][14] = new coord(5096,5087);
_movepoints[1][15] = new coord(5082,5085);
_movepoints[1][16] = new coord(5070,5081);
_movepoints[1][17] = new coord(5070,5071);
_movepoints[1][18] = new coord(5068,5093);
_movepoints[1][19] = new coord(5055,5093);
_movepoints[1][20] = new coord(5041,5091);
_movepoints[1][21] = new coord(5036,5080);
_movepoints[1][22] = new coord(5036,5069);
_movepoints[1][23] = new coord(5034,5098);
_movepoints[1][24] = new coord(5095,5100);
_movepoints[1][25] = new coord(5104,5094);
_movepoints[1][26] = new coord(5115,5096);
_movepoints[1][27] = new coord(5120,5105);
_movepoints[1][28] = new coord(5125,5117);
_movepoints[1][29] = new coord(5115,5086);
_movepoints[1][30] = new coord(5122,5082);
_movepoints[1][31] = new coord(5126,5070);
_movepoints[1][32] = new coord(5117,5060);
_movepoints[1][33] = new coord(5104,5059);
_movepoints[1][34] = new coord(5130,5061);
_movepoints[1][35] = new coord(5144,5060);
_movepoints[1][36] = new coord(5158,5060);
_movepoints[1][37] = new coord(5171,5060);
_movepoints[1][38] = new coord(5185,5059);
_movepoints[1][39] = new coord(5198,5059);
_movepoints[1][40] = new coord(5207,5050);
_movepoints[1][41] = new coord(5207,5064);
_movepoints[1][42] = new coord(5207,5077);
_movepoints[1][43] = new coord(5208,5091);
_movepoints[1][44] = new coord(5208,5103);
_movepoints[1][45] = new coord(5207,5117);
_movepoints[1][46] = new coord(5208,5131);
_movepoints[1][47] = new coord(5208,5145);
_movepoints[1][48] = new coord(5213,5153);
_movepoints[1][49] = new coord(5217,5166);
_movepoints[1][50] = new coord(5221,5179);
_movepoints[1][51] = new coord(5196,5152);
_movepoints[1][52] = new coord(5185,5144);
_movepoints[1][53] = new coord(5176,5133);
_movepoints[1][54] = new coord(5182,5125);
_movepoints[1][55] = new coord(5164,5126);
_movepoints[1][56] = new coord(5150,5126);
_movepoints[1][57] = new coord(5134,5126);
_movepoints[1][58] = new coord(5124,5129);
_movepoints[1][59] = new coord(5125,5142);
_movepoints[1][60] = new coord(5126,5156);
_movepoints[1][61] = new coord(5126,5170);
_movepoints[1][62] = new coord(5129,5183);
_movepoints[1][63] = new coord(5141,5189);
_movepoints[1][64] = new coord(5151,5199);
_movepoints[1][65] = new coord(5114,5155);
_movepoints[1][66] = new coord(5101,5155);
_movepoints[1][67] = new coord(5088,5155);
_movepoints[1][68] = new coord(5075,5150);
_movepoints[1][69] = new coord(5062,5144);
_movepoints[1][70] = new coord(5100,5143);
_movepoints[1][71] = new coord(5099,5130);
_movepoints[1][72] = new coord(5097,5118);
_movepoints[1][73] = new coord(5106,5124);
_movepoints[1][74] = new coord(5117,5126);
_movepoints[1][75] = new coord(5097,5104);
_movepoints[1][76] = new coord(5086,5126);
_movepoints[1][77] = new coord(5074,5125);
_movepoints[1][78] = new coord(5060,5124);
_movepoints[1][79] = new coord(5047,5118);
_movepoints[1][80] = new coord(5037,5109);
_movepoints[1][81] = new coord(5186,5112);
_movepoints[1][82] = new coord(5185,5099);
_movepoints[1][83] = new coord(5185,5085);
_movepoints[1][84] = new coord(5185,5073);
_movepoints[1][85] = new coord(5097,5023);

// act 3
_movepoints[2] = new Array();
_movepoints[2][0] = new coord();
_movepoints[2][1] = new coord();
_movepoints[2][2] = new coord(5120,5168);
_movepoints[2][3] = new coord(5132,5162);
_movepoints[2][4] = new coord(5133,5148);
_movepoints[2][5] = new coord(5133,5136);
_movepoints[2][6] = new coord(5133,5124);
_movepoints[2][7] = new coord(5133,5113);
_movepoints[2][8] = new coord(5133,5103);
_movepoints[2][9] = new coord(5132,5092);
_movepoints[2][10] = new coord(5144,5092);
_movepoints[2][11] = new coord(5155,5087);
_movepoints[2][12] = new coord(5147,5078);
_movepoints[2][13] = new coord(5149,5064);
_movepoints[2][14] = new coord(5156,5056);
_movepoints[2][15] = new coord(5145,5051);
_movepoints[2][16] = new coord(5132,5048);
_movepoints[2][17] = new coord(5118,5047);
_movepoints[2][18] = new coord(5106,5048);
_movepoints[2][19] = new coord(5093,5046);
_movepoints[2][20] = new coord(5092,5034);
_movepoints[2][21] = new coord(5083,5029);
_movepoints[2][22] = new coord(5085,5016);
_movepoints[2][23] = new coord(5072,5032);
_movepoints[2][24] = new coord(5072,5046);
_movepoints[2][25] = new coord(5083,5054);
_movepoints[2][26] = new coord(5083,5068);
_movepoints[2][27] = new coord(5083,5082);
_movepoints[2][28] = new coord(5082,5093);
_movepoints[2][29] = new coord(5068,5092);
_movepoints[2][30] = new coord(5055,5092);
_movepoints[2][31] = new coord(5042,5093);
_movepoints[2][32] = new coord(5095,5092);
_movepoints[2][33] = new coord(5108,5092);
_movepoints[2][34] = new coord(5121,5092);
_movepoints[2][35] = new coord(5169,5087);
_movepoints[2][36] = new coord(5181,5087);
_movepoints[2][37] = new coord(5194,5087);
_movepoints[2][38] = new coord(5206,5087);
_movepoints[2][39] = new coord(5218,5080);
_movepoints[2][40] = new coord(5223,5068);
_movepoints[2][41] = new coord(5223,5058);
_movepoints[2][42] = new coord(5156,5062);
_movepoints[2][43] = new coord(5156,5074);

// act 4
_movepoints[3] = new Array();
_movepoints[3][0] = new coord();
_movepoints[3][1] = new coord();
_movepoints[3][2] = new coord(5044,5027);
_movepoints[3][3] = new coord(5034,5032);
_movepoints[3][4] = new coord(5046,5037);
_movepoints[3][5] = new coord(5059,5039);
_movepoints[3][6] = new coord(5072,5041);
_movepoints[3][7] = new coord(5082,5044);
_movepoints[3][8] = new coord(5087,5054);
_movepoints[3][9] = new coord(5087,5032);
_movepoints[3][10] = new coord(5094,5044);
_movepoints[3][11] = new coord(5108,5047);
_movepoints[3][12] = new coord(5118,5052);
_movepoints[3][13] = new coord(5128,5060);
_movepoints[3][14] = new coord(5133,5070);
_movepoints[3][15] = new coord(5141,5079);
_movepoints[3][16] = new coord(5151,5084);
_movepoints[3][17] = new coord(5158,5087);
_movepoints[3][18] = new coord(5024,5025);
_movepoints[3][19] = new coord(5024,5037);

// act5
_movepoints[4] = new Array();
_movepoints[4][0] = new coord();
_movepoints[4][1] = new coord();
_movepoints[4][2] = new coord(5105,5043);
_movepoints[4][3] = new coord(5104,5030);
_movepoints[4][4] = new coord(5093,5022);
_movepoints[4][5] = new coord(5087,5032);
_movepoints[4][6] = new coord(5073,5032);
_movepoints[4][7] = new coord(5072,5045);
_movepoints[4][8] = new coord(5107,5055);
_movepoints[4][9] = new coord(5117,5064);
_movepoints[4][10] = new coord(5119,5077);
_movepoints[4][11] = new coord(5122,5089);
_movepoints[4][12] = new coord(5130,5101);
_movepoints[4][13] = new coord(5131,5087);
_movepoints[4][14] = new coord(5134,5073);
_movepoints[4][15] = new coord(5133,5063);
_movepoints[4][16] = new coord(5145,5057);
_movepoints[4][17] = new coord(5135,5052);
_movepoints[4][18] = new coord(5131,5042);
_movepoints[4][19] = new coord(5116,5040);
_movepoints[4][20] = new coord(5112,5087);
_movepoints[4][21] = new coord(5099,5086);
_movepoints[4][22] = new coord(5085,5087);
_movepoints[4][23] = new coord(5083,5074);
_movepoints[4][24] = new coord(5082,5064);
_movepoints[4][25] = new coord(5078,5053);
_movepoints[4][26] = new coord(5074,5079);
_movepoints[4][27] = new coord(5064,5080);
_movepoints[4][28] = new coord(5066,5094);
_movepoints[4][29] = new coord(5078,5097);
_movepoints[4][30] = new coord(5086,5099);
_movepoints[4][31] = new coord(5088,5111);
_movepoints[4][32] = new coord(5097,5120);
_movepoints[4][33] = new coord(5110,5120);
_movepoints[4][34] = new coord(5123,5118);
_movepoints[4][35] = new coord(5133,5108);
_movepoints[4][36] = new coord(5133,5106);
_movepoints[4][37] = new coord(5081,5122);
_movepoints[4][38] = new coord(5069,5114);
_movepoints[4][39] = new coord(5056,5098);
_movepoints[4][40] = new coord(5063,5107);
_movepoints[4][41] = new coord(5042,5097);
_movepoints[4][42] = new coord(5030,5096);
_movepoints[4][43] = new coord(5126,5061);

// array for town points of interest
var _townpoints = new Array();

// act 1
_townpoints[0] = new Object();
_townpoints[0]["gheed"]   = new coord();
_townpoints[0]["charsi"]   = new coord();
_townpoints[0]["akara"]   = new coord();
_townpoints[0]["kashya"]   = new coord();
_townpoints[0]["cain"]    = new coord();
_townpoints[0]["stash"]   = new coord();
_townpoints[0]["portalspot"]  = new coord();
_townpoints[0]["waypoint"]  = new coord();
_townpoints[0]["exit"]   = new coord();
_townpoints[0]["Warriv"]  = new coord();

// act 2
_townpoints[1] = new Object();
_townpoints[1]["portalspot"]  = new coord(5168,5055);
_townpoints[1]["stash"]   = new coord(5124,5082);
_townpoints[1]["fara"]    = new coord(5124,5082);
_townpoints[1]["cain"]    = new coord(5124,5082);
_townpoints[1]["lysander"]   = new coord(5118,5104);
_townpoints[1]["waypoint"]   = new coord(5070,5083);
_townpoints[1]["greiz"]   = new coord(5033,5053);
_townpoints[1]["exit"]    = new coord();
_townpoints[1]["elzix"]   = new coord(5032,5102);
_townpoints[1]["palace"]   = new coord(5055,5142);
_townpoints[1]["sewers"]   = new coord(5221,5181);
_townpoints[1]["meshif"]   = new coord(5205,5058);
_townpoints[1]["drognan"]   = new coord(5097,5035);
_townpoints[1]["atma"]    = new coord(5140,5055);
_townpoints[1]["warriv"]   = new coord(5152,5201);

// act 3
_townpoints[2] = new Object();
_townpoints[2]["cain"]    = new coord(5148,5066);
_townpoints[2]["waypoint"]   = new coord(5158,5050);
_townpoints[2]["exit"]    = new coord(5145,5044);
_townpoints[2]["alkor"]   = new coord(5083,5016);
_townpoints[2]["asheara"]   = new coord(5043,5093);
_townpoints[2]["ormus"]   = new coord(5129,5093);
_townpoints[2]["hratli"]   = new coord(5223,5048);
_townpoints[2]["stash"]   = new coord(5144,5059);
_townpoints[2]["portalspot"]   = new coord(5156,5063);
_townpoints[2]["meshif"]   = new coord(5118,5168);

// act 4
_townpoints[3] = new Object();
_townpoints[3]["waypoint"]   = new coord(5043,5018);
_townpoints[3]["cain"]    = new coord(5027,5027);
_townpoints[3]["halbu"]   = new coord(5089,5031);
_townpoints[3]["tyrael"]   = new coord(5027,5027);
_townpoints[3]["jamella"]   = new coord(5088,5054);
_townpoints[3]["stash"]   = new coord(5022,5040);
_townpoints[3]["exit"]    = new coord(5158,5086);
_townpoints[3]["portalspot"]  = new coord(5049,5038);

// act 5
_townpoints[4] = new Object();
_townpoints[4]["portalspot"]   = new coord(5097,5024);
_townpoints[4]["exit"]    = new coord(5028,5095);
_townpoints[4]["stash"]   = new coord(5129,5061);
_townpoints[4]["larzuk"]   = new coord(5141,5045);
_townpoints[4]["malah"]   = new coord(5078,5029);
_townpoints[4]["cain"]    = new coord(5119,5061);
_townpoints[4]["qual-kehk"]   = new coord(5066,5083);
_townpoints[4]["anya"]    = new coord(5112,5120);
_townpoints[4]["portal"]   = new coord(5118,5120);
_townpoints[4]["waypoint"]   = new coord(5113,5068);
_townpoints[4]["nihlathak"]   = new coord(5071,5111);


//////////////////////////////////////////////////////////////////////
// Public functions
//////////////////////////////////////////////////////////////////////

function DTM_TownMove(act, spot) {

 DC_DPrint("DTM_TownMove : Function called (" + act + "," + spot + ")");

 if (arguments.length == 1 || !spot) {

  spot = act;
  DC_DPrint("DTM_TownMove : No act specified, lets find it");
  act = _DTM_FindSpotAct(spot);
  DC_DPrint("DTM_TownMove : Act returned: "+act);

  if (!act) {

   DC_ThrowException("d2jsp-townmove","Failed to find the act for spot: " + spot);
   return false;
  }
 }

 if (act < 1 || act > 5) {

  DC_ThrowException("d2jsp-townmove","DTM_TownMove: Invalid act: " + act);
  return false;
 }
 
 if (act != me.act) {

  DC_ThrowException("d2jsp-townmove","DTM_TownMove: You are in the wrong act (entered:" + act + " current:" + me.act + ")");
  return false;
 }

 spot = spot.toLowerCase(); 
 if (act == 1) {

  if (!_DTM_CreateAct1()) { return false; }
 }

 act -= 1;

 DC_DPrint("DTM_TownMove : Checking spot");

 var pos = _townpoints[act][spot];
 if (pos.x === 0 && pos.y === 0) {

  DC_DPrint("DTM_TownMove : No spot specified, looking up spot");

  pos = _DTM_TownFindSpot(act, spot);
  if (pos && pos.x === 0 && pos.y === 0) {

   DC_ThrowException("d2jsp-townmove","Failed to find spot " + spot.toLowerCase());
   return false;
  }
 }

 DC_DPrint("DTM_TownMove : Going to find the path");

 if (pos && pos.x !== 0 && pos.y !== 0) {

  var p = DTM_FindTownPath(act, pos.x, pos.y, 15);
  if (!p || !p.length) {

   DC_ThrowException("d2jsp-townmove","Failed to find path to "+spot);
   return false;
  }

  DC_DPrint("DTM_TownMove : Path found, going to follow the path");
  return DTM_FollowTownPath(p);
 }
 else {
  DC_ThrowException("d2jsp-townmove","spot not found: " + spot.toLowerCase());
  return false;
 }
 
 return false;
}


function DTM_TownMoveXY(act, x, y) {

 if (act < 1 || act > 5) {

  DC_ThrowException("d2jsp-townmove","DTM_TownMoveXY : Invalid act: " + act);
  return false;
 }

 if (arguments.length == 2) {

  y = x;
  x = act;
  act = me.act;
 }

 if (act == 1) { _DTM_CreateAct1(); }

 act -= 1;

 var p = DTM_FindTownPath(act, x, y, 15);

 if (!p) { return false; }

 return DTM_FollowTownPath(p);
}

function DTM_FindTownPath(act, x, y, maxsep) {

 DC_DPrint("DTM_FindTownPath : Going to find town path to " + x + "," + y + " using dijkstra pathing");

 // Find a path using maxsep entered in parameter
 var path =  _DTM_CreateDijkstra(act, x, y, maxsep);

 if (path && path.length) {

  DC_DPrint("DTM_FindTownPath : Path created");
  return path;
 }

 // Increase maxsep by 5 (should never be needed)
 DC_DPrint("DTM_FindTownPath : Need to increase maxsep for dijkstra");

 path =  _DTM_CreateDijkstra(act, x, y, maxsep + 5);
 if (path && path.length) {

  DC_DPrint("DTM_FindTownPath : maxsep+5 created a path");
  return path;
 }

 // Increase maxsep by 10 (should never be needed)
 DC_DPrint("DTM_FindTownPath : Need to increase maxsep again for dijkstra");

 path =  _DTM_CreateDijkstra(act, x, y, maxsep + 10);
 if (path && path.length) {

  DC_DPrint("DTM_FindTownPath : maxsep+10 created a path");
  return path;
 }

 DC_ThrowException("d2jsp-townmove","DTM_FindTownPath : No path found (act:" + act+1 + " ,x:" + x + " ,y:" + y + "!");

 return null;
}

function DTM_FollowTownPath(p) {

 DC_DPrint("DTM_FollowTownPath : Function called, pathlength: " + p.length);
 
 var fail = 0;
 for (var i = 0; i < p.length; i+=1) {

  DC_DPrint("DTM_FollowTownPath : Moving to Pathnode " + i + ": " + p[i]);

  if (!_DTM_TownMoveTo(p[i])) { fail+=1; }

  if (fail > 1) {

   DC_ThrowException("d2jsp-townmove","DTM_FollowTownPath : Failed to follow townpath");
   return false;
  }
 }

 DC_DPrint("DTM_FollowTownPath : Function done");
 
 return true;
}


//////////////////////////////////////////////////////////////////////
// Private functions
//////////////////////////////////////////////////////////////////////

function _DTM_FindSpotAct(spot) {

 spot = spot.toLowerCase();
 
 if (_townpoints[me.act-1][spot]) { return me.act; }

 if (_townpoints[0][spot]) { return 1; }
 if (_townpoints[1][spot]) { return 2; }
 if (_townpoints[2][spot]) { return 3; }
 if (_townpoints[3][spot]) { return 4; }
 if (_townpoints[4][spot]) { return 5; }
  
 return 0; 
}

function _DTM_CreateAct1() { 

 // If the array has move points created, return true because the map is already initialized
 if (_movepoints[0].length) { return true; }

 // Grab the fire preset object
 var _fireobject = getPresetUnits( me.area, 2, 39, null );

 // If there is no fire object returned, throw a exception
 if (!_fireobject) {

  DC_ThrowException("d2jsp-pathing","_DP_InitAct1() -> Can't build act1 map, fireplace object not found");
  return false;
 }

 // Get the x/y coords of the fire object for the calculation purpose
 else {
  _fire = new coord( _fireobject[0].roomx * 5 + _fireobject[0].x, _fireobject[0].roomy * 5 + _fireobject[0].y );
 }

 _townpoints[0]["gheed"]  = new coord(_fire.x - 34, _fire.y + 36);
 _townpoints[0]["charsi"]  = new coord(_fire.x - 39, _fire.y - 25);
 _townpoints[0]["akara"]  = new coord(_fire.x + 56, _fire.y - 30);
 _townpoints[0]["kashya"]  = new coord(_fire.x + 14, _fire.y - 4);
 _townpoints[0]["cain"]   = new coord(_fire.x + 6, _fire.y - 5);
 _townpoints[0]["warriv"] = new coord(_fire.x - 5, _fire.y - 2);
 _townpoints[0]["stash"]  = new coord(_fire.x - 7, _fire.y - 12);
 _townpoints[0]["portalspot"] = new coord(_fire.x + 10, _fire.y + 18);
 _townpoints[0]["waypoint"] = new coord();
 _townpoints[0]["exit"]  = new coord();

 var wp = getUnit(2, "Waypoint");
 delay(10);

 if (wp) { _townpoints[0]["waypoint"].set(wp.x, wp.y); }

 else {

  // Get the WP preset unit
  _wpobject = getPresetUnits( me.area, 2, 119, null );

  // If no object is found, move closer and retry to get the unit
  if ( !_wpobject ) {

   // I'm too far from the WP so go closer (usually when we are trying to build the path from the TP spot)
   // Only call if the getPresetUnit call failed to get the object (should not happen at all)
   _DTM_WalkTo(me.x,me.y-5);

   // Retry 5 times to get the wp object
   for (_loop = 0; _loop < 5; _loop+=1) {

    wp = getUnit(2, "Waypoint");
    delay(100);
   }

   if (wp) { _townpoints[0]["waypoint"].set(wp.x, wp.y); }
   else {
    DC_ThrowException("d2jsp-townmove","Cannot find the WP of act1!");
    return false;
   }
  }

  // Found the preset object so get the coords
  else {
   _townpoints[0]["waypoint"].set( _wpobject[0].roomx * 5 + _wpobject[0].x, _wpobject[0].roomy * 5 + _wpobject[0].y );
  }
 }

 _movepoints[0][0] = new coord();
 _movepoints[0][1] = new coord();
 _movepoints[0][2] = new coord(-4,-11);
 _movepoints[0][3] = new coord(-6,-22);
 _movepoints[0][4] = new coord(-16,-30);
 _movepoints[0][5] = new coord(-26,-26);
 _movepoints[0][6] = new coord(-34,-21);
 _movepoints[0][7] = new coord(-31,-11);
 _movepoints[0][8] = new coord(-21,-4);
 _movepoints[0][9] = new coord(-9,-6);
 _movepoints[0][10] = new coord(0,-17);
 _movepoints[0][11] = new coord(11,-15);
 _movepoints[0][12] = new coord(23,-13);
 _movepoints[0][13] = new coord(33,-16);
 _movepoints[0][14] = new coord(37,-27);
 _movepoints[0][15] = new coord(27,-31);
 _movepoints[0][16] = new coord(51,-28);
 _movepoints[0][17] = new coord(8,-5);
 _movepoints[0][18] = new coord(15,4);
 _movepoints[0][19] = new coord(15,15);
 _movepoints[0][20] = new coord(18,24);
 _movepoints[0][21] = new coord(27,32);
 _movepoints[0][22] = new coord(29,23);
 _movepoints[0][23] = new coord(28,9);
 _movepoints[0][24] = new coord(16,34);
 _movepoints[0][25] = new coord(5,35);
 _movepoints[0][26] = new coord(-1,22);
 _movepoints[0][27] = new coord(7,17);
 _movepoints[0][28] = new coord(-7,10);
 _movepoints[0][29] = new coord(-14,0);
 _movepoints[0][30] = new coord(-20,7);
 _movepoints[0][31] = new coord(-27,15);
 _movepoints[0][32] = new coord(-34,23);
 _movepoints[0][33] = new coord(-31,33);
 
 for (var i = 2; i < _movepoints[0].length; i+=1) {

  _movepoints[0][i].x += _fire.x;
  _movepoints[0][i].y += _fire.y;
 }
 
 return true;
}

function _DTM_WalkTo( pX, pY ) {

 // If the char has running disabled, toggle to enable it
 if ( me.runwalk === 0 ) { me.runwalk=1; }

 // Click on the current coords set to go there
 clickMap(0, 0, pX, pY);
 delay(rnd(10,50) + DC_ClickDel);
 clickMap(2, 0, pX, pY);
}

function _DTM_TownMoveTo(c) {

 if (_DTM_MoveTo(c)) { return true; }
 
 var oldpos = new coord(me);
 var pos = new coord(me);
 var dir = pos.dir(c);
 dir.rotate(90);
 pos.move(dir, 5);

 if (_DTM_MoveTo(pos)) {

  if (_DTM_MoveTo(c)) { return true; }

  _DTM_MoveTo(oldpos);
 }

 dir.rotate(180);
 pos.set(oldpos);
 pos.move(dir, 5);
 _DTM_MoveTo(pos);
 _DTM_MoveTo(c);
}

function _DTM_MoveTo(c) {

 var timer = 2000;

 do {
  if (me.mode != 2 || me.mode != 3 || me.mode != 6) {

   DC_DoClick(0, 0, c.x, c.y);
  }

  delay(50);
  timer -= 50;
  if (me.mode == 17) { return true; }

 } while(c.dist(me) > 1 && timer > 0);
 
 if (timer <= 0) { return false; }

 return true;
}

function _DTM_TownFindSpot(act,  spot) {

 if (act === 0) {

  if (spot == "waypoint") {

   var wp = getUnit(2, "Waypoint");

   if (wp) {

    _townpoints[0]["waypoint"].set(wp);
    return _townpoints[0]["waypoint"];
   }

   if (!DTM_TownMove(1, "stash")) { return null; }

   wp = getUnit(2, "Waypoint");

   if (wp) {

    _townpoints[0]["waypoint"].set(wp);
    return _townpoints[0]["waypoint"];
   }   
  }

  else if (spot == "exit") {

   if (!DTM_TownMove("cain")) { return null; }

   var fire = getUnit(2, "fire");

   if (!fire) {

    DC_ThrowException("d2jsp-townmove","_DTM_TownFindSpot : Failed to find fire, can't detect town exit");
    return null;
   }

   var _roomAct1Town = getRoom(1);
   var _roomAct1BloodMoor = getRoom(2);
   if(_roomAct1Town && _roomAct1BloodMoor) {
    var x = _roomAct1Town.getStat(4) - _roomAct1BloodMoor.getStat(4);
    var y = _roomAct1Town.getStat(5) - _roomAct1BloodMoor.getStat(5);

    index = _movepoints[0].length - 1;

    // South Exit
    if (x < 0 && y < 0) {
     _DTM_Act1Exit = _DTM_Act1SouthExit;
     _townpoints[0]["exit"].set(fire.x+78, fire.y+1);
     _movepoints[0][index+=1] = new coord(fire.x+62, fire.y-28);
     _movepoints[0][index+=1] = new coord(fire.x+70, fire.y-20);
     _movepoints[0][index+=1] = new coord(fire.x+69, fire.y-9);
     return _townpoints[0]["exit"];
    }
    // North Exit
    else if (x > 0 && y < 0) {
     _DTM_Act1Exit = _DTM_Act1NorthExit;
     _townpoints[0]["exit"].set(fire.x-75, fire.y+4);
     _movepoints[0][index+=1] = new coord(fire.x-30, fire.y-6);
     _movepoints[0][index+=1] = new coord(fire.x-41, fire.y-5);
     _movepoints[0][index+=1] = new coord(fire.x-52, fire.y-8);
     _movepoints[0][index+=1] = new coord(fire.x-61, fire.y+1);
     return _townpoints[0]["exit"];
    }
    // West Exit
    else if (x === 0 && y < 0) {
     _DTM_Act1Exit = _DTM_Act1WestExit;
     _townpoints[0]["exit"].set(fire.x+15, fire.y+70);
     _movepoints[0][index+=1] = new coord(fire.x+27, fire.y+41);
     _movepoints[0][index+=1] = new coord(fire.x+26, fire.y+52);
     _movepoints[0][index+=1] = new coord(fire.x+19, fire.y+56);
     return _townpoints[0]["exit"];
    }
    // East Exit
    else if (x === 0 && y > 0) {
     _DTM_Act1Exit = _DTM_Act1EastExit;
     _townpoints[0]["exit"].set(fire.x+15, fire.y-55);
     _movepoints[0][index+=1] = new coord(fire.x+25, fire.y-40);
     _movepoints[0][index+=1] = new coord(fire.x+6, fire.y-43);
     _movepoints[0][index+=1] = new coord(fire.x-1, fire.y-37);
     _movepoints[0][index+=1] = new coord(fire.x+2, fire.y-26);
     return _townpoints[0]["exit"];
    }
   }
  }
 }

 else if (act == 1) {

  if (spot == "exit") {

   if (!DTM_TownMoveXY(2, 5098, 5053)) { return null; }

   var found = false;   
   var obj = getUnit(2, "Dummy");
   do {
    if (obj && obj.x == 5107 && obj.y == 5052) {

     _townpoints[1]["exit"].set(5096,5009);
     // exit direction (0, -1)
     found = true;
    }
   } while(obj && obj.getNext());
   
   if (!found) {

    _townpoints[1]["exit"].set(5011,5066);
    // exit direction (-1, 0)
   }
   
   return _townpoints[1]["exit"];
  }
 }

 return null;
}


//////////////////////////////////////////////////////////////////////
// Dijkstra pathfinding. Modified version of Syadasti's Pathfinding
//////////////////////////////////////////////////////////////////////

function _DTM_CreateDijkstra(act, targetx, targety, maxsep) {

 DC_DPrint("_DTM_CreateDijkstra : function called");
 var v = new Array;

 for (var i = 0; i < _movepoints[act].length; i+=1) {

  v[i] = new _DTM_Vertex();
 }
  
 DC_DPrint("Vertex array created");
 
 _movepoints[act][0] = new coord(me);
 _movepoints[act][1] = new coord(targetx, targety);
 
 for (i = 0; i < _movepoints[act].length; i+=1) {

  for (var j = 0; j < _movepoints[act].length; j+=1) {

   if (i != j) {

    var d = _movepoints[act][i].dist(_movepoints[act][j]);

    if (d <= maxsep) {

     v[i].push(j, d);
    }
   }
  }
 }
 
 DC_DPrint("_DTM_CreateDijkstra : Vertex array initialized, starting Dijkstra algo");
 _DTM_Dijkstra(v, _movepoints[act].length);
 DC_DPrint("_DTM_CreateDijkstra : Dijkstra algo done");
 
 var path = new Array();
 if (!_DTM_CreateDijkstraPath(v, 0, 1, _movepoints[act], path)) {

  DC_DPrint("_DTM_CreateDijkstra : No path found, returning null");
  return null;
 }

 DC_DPrint("_DTM_CreateDijkstra : Path found, _DTM_Dijkstra done");
 return path;
}

function _DTM_Vertex() {

 this.NumAdjacencies = 0;
 this.Adjacent = new Array;
 this.AdjacencyWeight = new Array;
 this.Previous = 0;
 this.Cost = 0;
 this.push = _DTM_PushMethod;
}

function _DTM_PushMethod(neighbor, Cost) {

 this.Adjacent[this.NumAdjacencies] = neighbor;
 this.AdjacencyWeight[this.NumAdjacencies] = Cost;
 this.NumAdjacencies+=1;
}

function _DTM_Dijkstra(v, size) {

 var _INFINITY = 32767;
 var Cost = new Array;
 var done = new Array;
 var to_do = size;

 for (var i = 0; i < size; i+=1) {

  v[i].Cost = Cost[i] = _INFINITY;
  v[i].Previous = -1;
  done[i] = 0;
 }

 Cost[0] = 0;
 while (to_do) {

  for (i = 0; i < size; i+=1) {

   if (!done[i]) {

    iMin=i;
    break;
   }
  }

  for (i = iMin + 1; i < size; i+=1) {

   if (!done[i] && Cost[i] < Cost[iMin]) {

    iMin = i;
   }
  }

  done[iMin] = 1;
  to_do-=1;
  for (i = 0; i < v[iMin].NumAdjacencies; i+=1) {

   if (Cost[iMin] + v[iMin].AdjacencyWeight[i] < Cost[v[iMin].Adjacent[i]]) {

    v[v[iMin].Adjacent[i]].Previous = iMin;
    v[v[iMin].Adjacent[i]].Cost = Cost[v[iMin].Adjacent[i]] =
     Cost[iMin] + v[iMin].AdjacencyWeight[i];
   }
  }
 }
}

function _DTM_CreateDijkstraPath(v, source, dest, points, path) {

 if (source == dest) {

  index = path.length;
  path[index] = new coord(points[dest]);
  path[index].data = points[dest].data;
 }

 else {
  if (v[dest].Previous != -1) {

   _DTM_CreateDijkstraPath(v, source, v[dest].Previous, points, path);
   index = path.length;
   path[index] = new coord(points[dest]);
   path[index].data = points[dest].data;
  }

  else {
   DC_DPrint("_DTM_CreateDijkstraPath() : Unable to build Dijkstra path");
   return false;
  }
 }

 return true;
}

여기저기 찾다가 드디어 찾았네요 아주 오랫동안 안했더랬는데....
역시나 세월이 지나도 디아2 만한 게임이 없는듯 하네요 ㅎㅎ

질문/답변

댓글을 추천하시면 답변으로 채택됩니다.

댓글을 추천하면 글 작성자와 댓글 작성자 둘 다 경험치를 획득합니다.

자세한 내용은 업데이트 공지를 참고해주시기 바랍니다.

번호 분류 제목 글쓴이 날짜 조회
공지   게시판 푸시 알림 / 통합 앱 서비스 36 file 트디개발자 2023.09.20 965.8k
공지   댓글이 도움되었다면 댓글을 추천 해주세요. 28 트디개발자 2021.04.16 86.4k
공지   [주의사항] 원격제어를 받으시면 시디키가 유출됩니다. 131 [버스&인첸방] 2017.04.17 97.7k
공지   정확한 답변을 받으려면 본문에 캡쳐를 첨부해주세요. 45 우녕자 2014.12.16 98.6k
공지   맨땅 초보자 가이드 621 file 뮤리아 2020.10.16 1018.9k
공지   카카오톡 1:1 채팅방 만드는 법 108 트디개발자 2018.05.20 431.4k
10655   매니저 실행시 질문 있습니다 ㅜㅜ 4 한희사랑 2018.12.30 142
10654   크래프트 이니는어디잇나요?? 한가지의삶 2018.12.30 102
10653   명령키가 이상하게 동작할경우 어떻게 해야할까요? 노력중이요 2018.12.30 137
10652   시디키 중복관련 도와주세요. 1 문어머리 2018.12.30 187
10651   질문)캐릭터이니 수정해도 적용이 안되는 문제? 2 쿠쿠쿠두 2018.12.29 210
10650   d2nt 소서리스 1 따귀마왕 2018.12.29 387
10649   26시디키 설치판 다운 받아는데요 1 사이버킹콩 2018.12.29 128
10648   팔라딘 방패 이니 질문 4 명미 2018.12.29 719
10647   반자동버스 실행시,,,헬까지 가려는데요,,구멍케릭,,,,,질문좀요,, 하늘강아지 2018.12.29 103
10646   glide3 질문 다비리드 2018.12.29 165
10645   시디키 26자리 변환이 안되네요... 로빵 2018.12.29 872
10644   오늘 설치하고 작동 잘되다가 갑자기 에러가 뜨네요. 2 바람꾸러기 2018.12.29 127
10643   네크 봇 설정 문의 낙망 2018.12.28 173
10642   BH인젝터 컨피그 파일에 색상 영어 어떤것들 되는지 아시는분... free_at 2018.12.28 146
10641   윈도우 10인데 맵핵이 호환이 안되는건지 실행을 할수없다네요 ㅠㅠ 저금통 2018.12.28 108
10640   크래프트만드는거요 knox 2018.12.28 125
10639   다운로드 에서 설치 파일 다운 받아는데여 사이버킹콩 2018.12.28 261
10638   안녕하세요 혹시 룬을 바닥에 빠르게 떨구는 프로그램이 있나요? 2 L안개 2018.12.28 147
>   d2jsp 마을에서 텔포 질문~~ 구문입혔는데 반응이 없네요 고수님들 의견 부탁드립니다. 인천 2018.12.28 229
10636   혹시 캐릭따 걸리면 전방에 들어갓따가 나오는거 못하나요??? 1 한지민내꺼 2018.12.28 350