Advertisement
ludovicodes

LudoMapConnect.js

Dec 17th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. //LudoMapConnect.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Allows you to forgo the use of events for transfering players from one map to another, especially usefull in the case that the maps have a line that "connects" them.
  7.  * @author Alessio De Santis
  8.  *
  9.  * @param Default Region
  10.  * @desc The region the plugin will check for when deciding to transfer the player.
  11.  * @default 60
  12.  *
  13.  * @help
  14.  * Use Region number 60 to indicate the transfer line, only one column of region 60 tiles will be saved in data.
  15.  * Use <targetId:id> tag in the Map Properties to indicate what map the player will transfer to.
  16.  */  
  17.  
  18.  
  19.  //-----------------------------------------------------------------------------
  20.  
  21.  $tileInfo = [
  22.  
  23.  ];
  24.  
  25.  $deReg = Number(PluginManager.parameters("LudoMapConnect")["Default Region"]) || 60;
  26.  
  27.  Scene_Map.prototype.isReady = function() {
  28.     if (!this._mapLoaded && DataManager.isMapLoaded()) {
  29.         this.onMapLoaded();
  30.         this._mapLoaded = true;
  31.         this.storage();
  32.     }
  33.     return this._mapLoaded && Scene_Base.prototype.isReady.call(this);
  34. };
  35.  
  36. Game_Player.prototype.checkRegionTransfer = function(){
  37.     x = this.x;
  38.     y = this.y;
  39.     id = this.regionId();
  40.     dir = this._direction;
  41.     id = Number($dataMap.meta.targetId);
  42.     transfer = false;
  43.     $tileInfo.forEach(
  44.         function(tile){
  45.             if(tile.x == x && tile.y == y && dir == (6 || 4) && id){
  46.                 transfer = true;
  47.             }
  48.         }
  49.     )
  50.     if(transfer){
  51.         this.reserveTransfer(id, x, y, dir, 0);
  52.     }
  53. };
  54.  
  55. Game_Player.prototype.performTransfer = function() {
  56.     if (this.isTransferring()) {
  57.         this.setDirection(this._newDirection);
  58.         if (this._newMapId !== $gameMap.mapId() || this._needsMapReload) {
  59.             $gameMap.setup(this._newMapId);
  60.  
  61.             this.searchCorresponding(this.x, this.y);
  62.            
  63.             this._needsMapReload = false;
  64.         }
  65.         this.locate(this._newX, this._newY);
  66.         this.refresh();
  67.         this.clearTransferInfo();
  68.     }
  69. };
  70.  
  71. Game_Player.prototype.searchCorresponding = function(x, y) {
  72.     var temp = $tileInfo;
  73.     var newX = this._newX;
  74.     Scene_Map.prototype.storage();
  75.     temp.some(function(elements){
  76.         ele = $tileInfo[elements.iD];
  77.         if(ele){
  78.             if(y == ele.y && x == ele.x){
  79.                 newX = ele.x;
  80.                 return true;
  81.             }
  82.         }
  83.     });
  84.     this._newX = newX;
  85. };
  86.  
  87. Scene_Map.prototype.storage = function() {
  88.     $tileInfo = [];
  89.             var i, j, k;
  90.             for(i = 0 ; i <  $gameMap.width(); i++){
  91.                 for(j = 0 ; j <  $gameMap.height(); j++){
  92.                     if($gameMap.regionId(i, j) == $deReg){
  93.                         for(k = j; k < $gameMap.height(); k++){
  94.                             if($gameMap.regionId(i, k) == $deReg){
  95.                                 $tileInfo.push({
  96.                                     iD : (k - j),
  97.                                     x : i,
  98.                                     y : k
  99.                                 });
  100.                             } else {
  101.                                 i = $gameMap.width();
  102.                                 j = $gameMap.height();
  103.                                 k = j;
  104.                             };
  105.                         }
  106.                     }
  107.                 }
  108.             }
  109.             console.log($tileInfo);
  110. };
  111.  
  112. Game_Player.prototype.moveByInput = function() {
  113.     if (!this.isMoving() && this.canMove()) {
  114.         var direction = this.getInputDirection();
  115.         if (direction > 0) {
  116.             $gameTemp.clearDestination();
  117.         } else if ($gameTemp.isDestinationValid()){
  118.             var x = $gameTemp.destinationX();
  119.             var y = $gameTemp.destinationY();
  120.             direction = this.findDirectionTo(x, y);
  121.         }
  122.         if (direction > 0) {
  123.             this.executeMove(direction);
  124.             this.checkRegionTransfer();
  125.         }
  126.     }
  127. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement