Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. Galv.DM.Game_CharacterBase_realMoveSpeed = Game_CharacterBase.prototype.realMoveSpeed;
  2. Game_CharacterBase.prototype.realMoveSpeed = function() {
  3. var spd = Galv.DM.Game_CharacterBase_realMoveSpeed.call(this);
  4. return this._diagDir ? spd * Galv.DM.diagMod : spd;
  5. };
  6.  
  7. // overwrite
  8. Game_Follower.prototype.realMoveSpeed = function() {
  9. return $gamePlayer.realMoveSpeed();
  10. };
  11.  
  12. Galv.DM.getHorzVertDirs = function(direction) {
  13. switch (direction) {
  14. case 1: return [4,2];
  15. case 3: return [6,2];
  16. case 7: return [4,8];
  17. case 9: return [6,8];
  18. default: return [0,0];
  19. };
  20. };
  21.  
  22. Galv.DM.getDir = function(horz,vert) {
  23. if (horz == 4 && vert == 2) return 1;
  24. if (horz == 6 && vert == 2) return 3;
  25. if (horz == 4 && vert == 8) return 7;
  26. if (horz == 6 && vert == 8) return 9;
  27. return 0;
  28. };
  29.  
  30. Galv.DM.diagRow = {
  31. 3: 0,
  32. 1: 1,
  33. 9: 2,
  34. 7: 3
  35. };
  36.  
  37. Galv.DM.Game_CharacterBase_moveStraight = Game_CharacterBase.prototype.moveStraight;
  38. Game_CharacterBase.prototype.moveStraight = function(d) {
  39. this._diagDir = false;
  40. Galv.DM.Game_CharacterBase_moveStraight.call(this,d);
  41. };
  42.  
  43. Galv.DM.Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
  44. Game_CharacterBase.prototype.setDirection = function(d) {
  45. if (this._diagStraigten) this._diagDir = false;
  46. Galv.DM.Game_CharacterBase_setDirection.call(this,d);
  47. };
  48.  
  49. if (Galv.DM.diagBlocked) {
  50. Game_Player.prototype.canPassDiagonally = function(x, y, horz, vert) {
  51. var x2 = $gameMap.roundXWithDirection(x, horz);
  52. var y2 = $gameMap.roundYWithDirection(y, vert);
  53. if (this.canPass(x, y, vert) && this.canPass(x, y2, horz) && this.canPass(x, y, horz) && this.canPass(x2, y, vert)) {
  54. return true;
  55. };
  56. return false;
  57. };
  58. };
  59.  
  60. Galv.DM.Game_Player_canPassDiagonally = Game_Player.prototype.canPassDiagonally;
  61. Game_Player.prototype.canPassDiagonally = function(x, y, horz, vert) {
  62. if ($gameSystem.disableVert) return false;
  63. return Galv.DM.Game_Player_canPassDiagonally.call(this,x,y,horz,vert);
  64. };
  65.  
  66. // OVERWRITE
  67. Game_CharacterBase.prototype.moveDiagonally = function(horz, vert) {
  68. var diag = this.canPassDiagonally(this._x, this._y, horz, vert);
  69. var norm = this.canPass(this._x, this._y, horz) || this.canPass(this._x, this._y, vert);
  70.  
  71. if (diag) {
  72. this._diagDir = Galv.DM.getDir(horz,vert);
  73. this._x = $gameMap.roundXWithDirection(this._x, horz);
  74. this._y = $gameMap.roundYWithDirection(this._y, vert);
  75. this._realX = $gameMap.xWithDirection(this._x, this.reverseDir(horz));
  76. this._realY = $gameMap.yWithDirection(this._y, this.reverseDir(vert));
  77. this.increaseSteps();
  78. } else if (norm) {
  79. this._diagDir = false;
  80. this.moveStraight(this.getOtherdir(horz,vert));
  81. };
  82.  
  83. this._diagStraigten = false;
  84. if (this._direction === this.reverseDir(horz)) this.setDirection(horz);
  85. if (this._direction === this.reverseDir(vert)) this.setDirection(vert);
  86. this._diagStraigten = true;
  87. };
  88.  
  89. Game_CharacterBase.prototype.getOtherdir = function(horz, vert) {
  90. return this.canPass(this._x, this._y, horz) ? horz : vert;
  91. };
  92.  
  93. // OVERWRITE
  94. Game_Player.prototype.getInputDirection = function() {
  95. return Input.dir8;
  96. };
  97.  
  98. Galv.DM.Game_Player_executeMove = Game_Player.prototype.executeMove;
  99. Game_Player.prototype.executeMove = function(direction) {
  100. if (direction % 2 == 0) {
  101. Galv.DM.Game_Player_executeMove.call(this,direction);
  102. } else if (Math.abs(direction % 2) == 1) {
  103. var dirArray = Galv.DM.getHorzVertDirs(direction);
  104. this.moveDiagonally(dirArray[0],dirArray[1]);
  105. };
  106. };
  107.  
  108.  
  109.  
  110. // If using Diaonal Charset
  111. if (Galv.DM.diagGraphic) {
  112. Galv.DM.Sprite_Character_characterPatternY = Sprite_Character.prototype.characterPatternY;
  113. Sprite_Character.prototype.characterPatternY = function() {
  114. if (!this._isBigCharacter && this._character._diagDir && this._character.characterIndex() < 4) {
  115. return Galv.DM.diagRow[this._character._diagDir];
  116. } else {
  117. return Galv.DM.Sprite_Character_characterPatternY.call(this);
  118. };
  119. };
  120.  
  121. Galv.DM.Sprite_Character_characterBlockX = Sprite_Character.prototype.characterBlockX;
  122. Sprite_Character.prototype.characterBlockX = function() {
  123. if (!this._isBigCharacter && this._character._diagDir && this._character.characterIndex() < 4) {
  124. var index = this._character.characterIndex() + 4;
  125. return index % 4 * this._character._cframes;
  126. } else {
  127. return Galv.DM.Sprite_Character_characterBlockX.call(this);
  128. };
  129.  
  130. };
  131.  
  132. Galv.DM.Sprite_Character_characterBlockY = Sprite_Character.prototype.characterBlockY;
  133. Sprite_Character.prototype.characterBlockY = function() {
  134. if (!this._isBigCharacter && this._character._diagDir && this._character.characterIndex() < 4) {
  135. var index = this._character.characterIndex() + 4;
  136. return Math.floor(index / 4) * 4;
  137. } else {
  138. return Galv.DM.Sprite_Character_characterBlockY.call(this);
  139. };
  140.  
  141. };
  142. };
  143. // end if using diagonal charset
  144.  
  145.  
  146. // turn toward character on diagonal
  147. // OVERWRITE
  148. Game_Character.prototype.turnTowardCharacter = function(character) {
  149. var sx = this.deltaXFrom(character.x);
  150. var sy = this.deltaYFrom(character.y);
  151.  
  152. var absSx = Math.abs(sx);
  153. var absSy = Math.abs(sy);
  154.  
  155. if (absSx == absSy) {
  156. if (sx < 0) {
  157. this._diagDir = sy > 0 ? 9 : 3;
  158. } else if (sx > 0) {
  159. this._diagDir = sy > 0 ? 7 : 1;
  160. }
  161. } else {
  162. this._diagDir = 0;
  163. };
  164. if (absSx > absSy) {
  165. this.setDirection(sx > 0 ? 4 : 6);
  166. } else if (sy !== 0) {
  167. this.setDirection(sy > 0 ? 8 : 2);
  168. }
  169. };
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. // If using diagonal mouse movement:
  177.  
  178. if (Galv.DM.mouseMove) {
  179. Galv.DM.Game_Character_findDirectionTo = Game_Character.prototype.findDirectionTo;
  180. // OVERWRITE
  181. Game_Character.prototype.findDirectionTo = function(goalX, goalY) {
  182. if ($gameSystem.disableVert) {
  183. return Galv.DM.Game_Character_findDirectionTo.call(this,goalX,goalY);
  184. } else {
  185. var searchLimit = this.searchLimit();
  186. var mapWidth = $gameMap.width();
  187. var nodeList = [];
  188. var openList = [];
  189. var closedList = [];
  190. var start = {};
  191. var best = start;
  192.  
  193. if (this.x === goalX && this.y === goalY) {
  194. return 0;
  195. }
  196.  
  197. start.parent = null;
  198. start.x = this.x;
  199. start.y = this.y;
  200. start.g = 0;
  201. start.f = $gameMap.distance(start.x, start.y, goalX, goalY);
  202. nodeList.push(start);
  203. openList.push(start.y * mapWidth + start.x);
  204.  
  205. while (nodeList.length > 0) {
  206. var bestIndex = 0;
  207. for (var i = 0; i < nodeList.length; i++) {
  208. if (nodeList[i].f < nodeList[bestIndex].f) {
  209. bestIndex = i;
  210. }
  211. }
  212.  
  213. var current = nodeList[bestIndex];
  214. var x1 = current.x;
  215. var y1 = current.y;
  216. var pos1 = y1 * mapWidth + x1;
  217. var g1 = current.g;
  218.  
  219. nodeList.splice(bestIndex, 1);
  220. openList.splice(openList.indexOf(pos1), 1);
  221. closedList.push(pos1);
  222.  
  223. if (current.x === goalX && current.y === goalY) {
  224. best = current;
  225. goaled = true;
  226. break;
  227. }
  228.  
  229. if (g1 >= searchLimit) {
  230. continue;
  231. }
  232.  
  233.  
  234. for (var j = 0; j < 9; j++) {
  235. var direction = 1 + j;
  236.  
  237. if (direction === 5) continue;
  238.  
  239. var diag = Math.abs(direction % 2) == 1;
  240. var dirs = Galv.DM.getHorzVertDirs(direction);
  241. var horz = dirs[0];
  242. var vert = dirs[1];
  243.  
  244. if (diag && this.canPassDiagonally(x1, y1, horz, vert) && (this.canPass(x1, y1, horz) || this.canPass(x1, y1, vert))) {
  245. // If can go diagonally and a horizontal dir isn't blocking
  246. var x2 = $gameMap.roundXWithDirection(x1, horz);
  247. var y2 = $gameMap.roundYWithDirection(y1, vert);
  248. } else if (this.canPass(x1, y1, direction)) {
  249. var x2 = $gameMap.roundXWithDirection(x1, direction);
  250. var y2 = $gameMap.roundYWithDirection(y1, direction);
  251. } else {
  252. continue;
  253. };
  254.  
  255. var pos2 = y2 * mapWidth + x2;
  256.  
  257. if (closedList.contains(pos2)) {
  258. continue;
  259. }
  260.  
  261. var g2 = g1 + 1;
  262. var index2 = openList.indexOf(pos2);
  263.  
  264. if (index2 < 0 || g2 < nodeList[index2].g) {
  265. var neighbor;
  266. if (index2 >= 0) {
  267. neighbor = nodeList[index2];
  268. } else {
  269. neighbor = {};
  270. nodeList.push(neighbor);
  271. openList.push(pos2);
  272. }
  273. neighbor.parent = current;
  274. neighbor.x = x2;
  275. neighbor.y = y2;
  276. neighbor.g = g2;
  277. neighbor.f = g2 + $gameMap.distance(x2, y2, goalX, goalY);
  278. if (!best || neighbor.f - neighbor.g < best.f - best.g) {
  279. best = neighbor;
  280. }
  281. }
  282. }
  283. }
  284.  
  285. var node = best;
  286. while (node.parent && node.parent !== start) {
  287. node = node.parent;
  288. }
  289.  
  290. var deltaX1 = $gameMap.deltaX(node.x, start.x);
  291. var deltaY1 = $gameMap.deltaY(node.y, start.y);
  292.  
  293.  
  294. if (deltaY1 > 0 && deltaX1 > 0) {
  295. return 3;
  296. } else if (deltaY1 > 0 && deltaX1 < 0) {
  297. return 1;
  298. } else if (deltaY1 < 0 && deltaX1 < 0) {
  299. return 7;
  300. } else if (deltaY1 < 0 && deltaX1 > 0) {
  301. return 9;
  302. };
  303.  
  304.  
  305. if (deltaY1 > 0) {
  306. return 2;
  307. } else if (deltaX1 < 0) {
  308. return 4;
  309. } else if (deltaX1 > 0) {
  310. return 6;
  311. } else if (deltaY1 < 0) {
  312. return 8;
  313. }
  314.  
  315. var deltaX2 = this.deltaXFrom(goalX);
  316. var deltaY2 = this.deltaYFrom(goalY);
  317.  
  318.  
  319. if (Math.abs(deltaX2) > Math.abs(deltaY2)) {
  320. return deltaX2 > 0 ? 4 : 6;
  321. } else if (deltaY2 !== 0) {
  322. return deltaY2 > 0 ? 8 : 2;
  323. }
  324.  
  325. return 0;
  326. };
  327. };
  328. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement