Advertisement
jesterruby

Map Slide Transfer (MV) Work in Progress

Mar 11th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MapSlideTransfer.js
  2. // Map Slide Transfer (MV) WIP by Lain
  3.  
  4. var Lain = Lain || {};
  5. Lain.mst_version = 1.0;
  6.  
  7. /*:
  8. @plugindesc v1.0 Adds a Slide Effect for transitions and includes a Map Edge Transfer System using Map Notetags.
  9. @author Lain
  10.  
  11. @param FadeType
  12. @desc 0 = Black, 1 = White, 2 = None, 3 = Slide Effect
  13. Default: 3
  14. @default 3
  15.  
  16. @param SlideSpeed
  17. @desc The speed of the Slide Effect.
  18. Default: 12
  19. @default 12
  20.  
  21. @param MouseMode
  22. @desc An alternative Map Edge Transfer mode that is compatible with mouse and touch controls. (Default: false)
  23. @default false
  24.  
  25. @help
  26. Free to use. Credit me if you feel like it. Have a nice day.
  27. [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~General Information~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]
  28.  
  29. Version History:
  30. 11.MAR.2017 -> 1.0 -> Work in Progress
  31.  
  32. Features:
  33. Slide Effect Transition (like in the topdown Zelda games) (not included, yet)
  34. Map Edge Transfer system via Map Notetags
  35.  
  36. Conflicts:
  37. I expect issues with the Slide Effect when using HUDs, Windows, Pictures and Parallax Mapping.
  38. Some incompatibilities are simple and some are almost impossible to solve.
  39.  
  40. Report bugs, please.
  41. [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Notetags~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]
  42.  
  43. Map Notetag:
  44.  
  45. <direction: mapid x y direction transition>
  46.  
  47.     direction = The cardinal direction you want automatic Map Edge Transfer to happen at
  48.         (north, east, west, south)
  49.     mapid = the ID of the map you want to transfer to
  50.         Must be a Number
  51.     x (OPTIONAL) = Forces the player to transfer to this x coordinate of the new map
  52.         Number (0 = west edge) or false (false = the script will predict it)
  53.     y (OPTIONAL) = Forces the player to transfer to this y coordinate of the new map
  54.         Number (0 = north edge) or false (false = the script will predict it)
  55.     direction (OPTIONAL) = Forces the player to face a certain direction after the transfer
  56.         (8, 6, 4, 2) or false (false = no change)
  57.     transition (OPTIONAL) = Force a transition effect
  58.         0 = Black, 1 = White, 2 = None, 3 = Slide Effect
  59.  
  60.     Examples:
  61.    
  62.     <north: 4>
  63.     Transfers the player to map 4 when hitting the northern edge.
  64.  
  65.     <west: 90 false 10>
  66.     Transfers the player to map 90 when hitting the western edge.
  67.     Forces the player to come out at the Y coordinates of 10.
  68.    
  69.     <south: 1 false false 6 2>
  70.     Transfers the player to map 1 when hitting the southern edge.
  71.     The player will face to the right after transfering.
  72.     Skips the transition effect that normally happens.
  73. */
  74.  
  75. Lain.mst_params = PluginManager.parameters('MapSlideTransfer');
  76. Lain.mst_fadetype = Number(Lain.mst_params['FadeType'] || 3);
  77. Lain.mst_slidespeed = Number(Lain.mst_params['SlideSpeed'] || 12);
  78. Lain.mst_mousemode = eval(Lain.mst_params['MouseMode'] || false);
  79. Lain.mst_through = false;
  80.  
  81. // **
  82. // * [Alias]
  83. // Game_CharacterBase.prototype.canPass : Makes it possible to move through the edge
  84. // Game_Player.prototype.update
  85. // * [New Methods]
  86. // Game_Player.prototype.mst_facepassableedge
  87. // Game_Player.prototype.mst_overedge
  88. // Game_Player.prototype.mst_autotransfer
  89.  
  90. //=============================================================================
  91. // ** Game_CharacterBase
  92. //=============================================================================
  93. var alias_Game_CharacterBase_canPass = Game_CharacterBase.prototype.canPass;
  94. Game_CharacterBase.prototype.canPass = function(x, y, d) {
  95.     if(Lain.mst_through){return true;}
  96.     return alias_Game_CharacterBase_canPass.call(this,x,y,d);
  97. };
  98.  
  99. //=============================================================================
  100. // ** Game_Player
  101. //=============================================================================
  102. var mst_gameplayer_update = Game_Player.prototype.update;
  103. Game_Player.prototype.update = function(sceneActive) {
  104.     if(this.mst_overedge() && !this.isMoving()){this.mst_autotransfer();}
  105.     mst_gameplayer_update.call(this, sceneActive);
  106. };
  107.  
  108. var mst_gameplayer_movebyinput = Game_Player.prototype.moveByInput;
  109. Game_Player.prototype.moveByInput = function() {
  110.     mst_gameplayer_movebyinput.call(this);
  111.     if(this.mst_facepassableedge() && !this.isMoving()){
  112.         if(Lain.mst_mousemode){
  113.             var direction = this.direction();
  114.         }
  115.         if(!Lain.mst_mousemode){
  116.             var direction = this.getInputDirection();
  117.             if(!direction>0){return;}
  118.         }
  119.         Lain.mst_through = true;
  120.         this.moveStraight(direction);
  121.         Lain.mst_through = false;
  122.         $gameTemp.clearDestination();
  123.     }
  124. };
  125.  
  126. Game_Player.prototype.mst_facepassableedge = function(){
  127.     if (this.direction() == 8 && this.y == 0 && $dataMap.meta.north) {
  128.         return 8;
  129.     }
  130.     if (this.direction() == 6 && this.x == $dataMap.width - 1 && $dataMap.meta.east) {
  131.         return 6;
  132.     }
  133.     if (this.direction() == 4 && this.x == 0 && $dataMap.meta.west) {
  134.         return 4;
  135.     }
  136.     if (this.direction() == 2 && this.y == $dataMap.height - 1 && $dataMap.meta.south) {
  137.         return 2;
  138.     }
  139.     return false;
  140. };
  141.  
  142. Game_Player.prototype.mst_overedge = function(){
  143.     if(this.y+1==0&&this.direction()==8){return 8;}
  144.     if(this.x==$dataMap.width&&this.direction()==6){return 6;}
  145.     if(this.x+1==0&&this.direction()==4){return 4;}
  146.     if(this.y==$dataMap.height&&this.direction()==2){return 2;}
  147.     return false;
  148. };
  149.  
  150. Game_Player.prototype.mst_autotransfer = function(){
  151.     var edgedir = this.mst_overedge();
  152.     if(edgedir==8){var mapmeta = $dataMap.meta.north;}
  153.     if(edgedir==6){var mapmeta = $dataMap.meta.east;}
  154.     if(edgedir==4){var mapmeta = $dataMap.meta.west;}
  155.     if(edgedir==2){var mapmeta = $dataMap.meta.south;}
  156.     var transinfo = mapmeta.trim().split(' ');
  157.     var newmapid = eval(transinfo[0]);
  158.     DataManager.mst_loadMapDataInfo(newmapid, function (result) {
  159.         if(eval(transinfo[1])!==false){var new_x = eval(transinfo[1])+1;}else{var new_x = false;}
  160.         if(eval(transinfo[2])!==false){var new_y = eval(transinfo[2])+1;}else{var new_y = false;}
  161.         var new_dir = eval(transinfo[3]) || this.direction();
  162.         var new_type = eval(transinfo[4])+1 || Lain.mst_fadetype+1;
  163.         new_type--;
  164.         if (edgedir == 8) {
  165.             var new_x = new_x || this.x+1;
  166.             var new_y = new_y || result.height;
  167.         }
  168.         if (edgedir == 6) {
  169.             var new_x = new_x || 1;
  170.             var new_y = new_y || this.y+1;
  171.         }
  172.         if (edgedir == 4) {
  173.             var new_x = new_x || result.width;
  174.             var new_y = new_y || this.y+1;
  175.         }
  176.         if (edgedir == 2) {
  177.             var new_x = new_x || this.x+1;
  178.             var new_y = new_y || 1;
  179.         }
  180.         new_x--;
  181.         new_y--;
  182.         this.reserveTransfer(newmapid, new_x, new_y, new_dir, new_type);
  183.     }, this);
  184. };
  185.  
  186. DataManager.mst_loadMapDataInfo = function(mapId, onload, context) {
  187.     var src = 'Map%1.json'.format(mapId.padZero(3));
  188.     var xhr = new XMLHttpRequest();
  189.     var url = 'data/' + src;
  190.     var result = null;
  191.     xhr.open('GET', url);
  192.     xhr.overrideMimeType('application/json');
  193.     xhr.onload = function() {
  194.         if (xhr.status < 400) {
  195.             result = JSON.parse(xhr.responseText);
  196.             onload.call(context, result)
  197.         }
  198.     };
  199.     xhr.onerror = function(err) {
  200.         console.log("Failed to load Map Info");
  201.     };
  202.     xhr.send();
  203. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement