Advertisement
kura2yamato

Step Puzzle

May 20th, 2024
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 7.30 KB | Source Code | 0 0
  1. //---------------------------------------------------------
  2. // GB_stepPuzzle.js
  3. // Copyright (c) 2024 GBison. All rights reserved.
  4. // Released under the MIT license.
  5. // http://opensource.org/licenses/mit-license.php
  6. //=========================================================
  7. /*:
  8.  * @plugindesc Combo System By Checking the Switch.
  9.  * @author Gbison
  10.  * @version 1
  11.  *
  12.  * @param Plugin Version
  13.  * @desc Version for the Plugins
  14.  *
  15.  * @param Version
  16.  * @type number
  17.  * @default 0
  18.  * @parent Plugin Version
  19.  *
  20.  * @param Position
  21.  * @desc Variable To position
  22.  *
  23.  * @param Last Player Stand X
  24.  * @desc Last Chara Position
  25.  * @type variable
  26.  * @default 11
  27.  * @parent Position
  28.  *
  29.  * @param Last Player Stand Y
  30.  * @desc Last Chara Position
  31.  * @type variable
  32.  * @default 12
  33.  * @parent Position
  34.  *
  35.  * @param Default Parameter
  36.  * @desc Parameter To Use
  37.  *
  38.  * @param Max Step
  39.  * @desc Max Step Player can Move
  40.  * @type Number
  41.  * @default 6
  42.  * @parent Default Parameter
  43.  *
  44.  * @param Switch Parameter
  45.  * @desc Switch for Puzzle
  46.  *
  47.  * @param Warning Switch
  48.  * @desc must turn OFF. Turn On if the step is more than Max Step
  49.  * @type Switch
  50.  * @default 11
  51.  * @parent Switch Parameter
  52.  *
  53.  * @help
  54.  * Copyright (c) 2024 GBison. All rights reserved.
  55.  * Released under the MIT license.
  56.  * ===================================================================
  57.  * The Idea from JoeBumpster
  58.  * https://forums.rpgmakerweb.com/index.php?threads/no-idea-why-this-switch-wont-flip.168634/
  59.  * To use this, just run plugin
  60.  *     GB_stepPuzzle Example : to run example
  61.  *     GB_stepPuzzle LastPosition : save player last position
  62.  *     GB_stepPuzzle StepPuzzle 6 : to run the Step. If the step more than 6!! The switch
  63.  *       will ON. turn Off using event
  64. */
  65.  
  66. (function() {
  67.     // parameters
  68.     var _thisPluginName = 'GB_stepPuzzle'; //change with your filename.
  69.     var parameters = PluginManager.parameters(_thisPluginName);
  70.  
  71.     var _ver_gb = {
  72.         "switch": Number(parameters['Plugin Version'] || 10),
  73.         "variable": Number(parameters['Version'] || 10)
  74.     };
  75.     var _maxStep =  Number(parameters['Max Step'] || 6);
  76.     var _lastPosX =  Number(parameters['Last Player Stand X'] || 11);
  77.     var _lastPosY =  Number(parameters['Last Player Stand Y'] || 12);
  78.     var _warningSwitch =  Number(parameters['Warning Switch'] || 11);
  79.  
  80.     var _playerBefore = {
  81.         "x": 0,
  82.         "y": 0,
  83.         "dir":0
  84.     }
  85.     var _playerLast = {
  86.         "x": 0,
  87.         "y": 0,
  88.         "dir":0
  89.     }
  90.     var cek=0;
  91.     var isMoveVertical = [2, 8];
  92.     var isMoveHorizontal = [4, 6];
  93.  
  94.     var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  95.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  96.         _Game_Interpreter_pluginCommand.call(this, command, args);
  97.         runPlugins = false;
  98.         if (command === 'GB_stepPuzzle') {
  99.             switch (args[0]) {
  100.                 case 'Example':
  101.                     $gameSystem.GB_example();
  102.                     runPlugins = [command, args];
  103.                     break;
  104.                 case 'LastPosition':                    
  105.                     player = $gamePlayer;
  106.                     console.log('last pos');
  107.                     $gameVariables.setValue( _lastPosX, player._x );
  108.                     $gameVariables.setValue( _lastPosY, player._y );
  109.                     $gameSystem.GB_saveBeforePosition( player._x, player._y, 0 );
  110.                     console.log('GB_saveLastPosition');
  111.                     $gameSystem.GB_saveLastPosition( player._x, player._y, 0 );
  112.                     runPlugins = [command, args];
  113.                    
  114.                     break;
  115.                 case 'StepPuzzle':
  116.                     player = $gamePlayer;
  117.                     $gameSystem.GB_StepPuzzle( args[1] );
  118.                     runPlugins = [command, args];
  119.                     $gameSystem.GB_saveBeforePosition( player._x, player._y, player._direction );
  120.                     $gameSystem.GB_debug(runPlugins, true);
  121.                     break;
  122.             }
  123.  
  124.         }
  125.         //$gameSystem.GB_debug( runPlugins );
  126.  
  127.     };
  128.  
  129.     Game_System.prototype.GB_StepPuzzle = function( step=0 ) {
  130.         if( step > 0 ){
  131.             _maxStep = step;
  132.             $gameSystem.GB_debug( ['step', _maxStep ]);
  133.         }
  134.         if( _playerLast.dir != 0){
  135.            
  136.             if( _playerLast.x != player._x && _playerLast.y != player._y){
  137.                 //new position
  138.                 player = $gamePlayer;
  139.                 $gameSystem.GB_debug( 'newPos1');
  140.                 $gameSystem.GB_saveLastPosition( player._x, player._y, player._direction );            
  141.                 $gameSystem.GB_debug( 'newPos2');
  142.             }
  143.             else{
  144.                 var posNow = 0;
  145.                 var posLast = 0;
  146.                 var updatePosition = false;
  147.                 player = $gamePlayer;
  148.  
  149.                 if( isMoveVertical.includes( player._direction ) ){  
  150.                     posNow = player._y;
  151.                     posLast = $gameVariables.value( _lastPosY);
  152.                     $gameSystem.GB_debug('ver');
  153.                     updatePosition =  player._x != $gameVariables.value( _lastPosX );
  154.                 }
  155.                 else if( isMoveHorizontal.includes( player._direction ) ){    
  156.                     posNow = player._x;
  157.                     posLast = $gameVariables.value( _lastPosX );
  158.                     $gameSystem.GB_debug('hor');
  159.                     updatePosition =  player._y != $gameVariables.value( _lastPosY );
  160.                 }else{
  161.                     $gameSystem.GB_debug( ['else', isMoveHorizontal, isMoveVertical, _playerLast.dir] );
  162.                 }
  163.                 if( !updatePosition ){
  164.                     $gameSystem.GB_debug('beda dir ' +  _playerLast.dir);
  165.                     updatePosition = _playerLast.dir != player._direction;
  166.                 }
  167.                 if( updatePosition ){
  168.                     $gameSystem.GB_debug('update pos');
  169.                     $gameSystem.GB_saveLastPosition( _playerBefore.x, _playerBefore.y, _playerBefore.direction );
  170.                 }
  171.                
  172.                 distance = Math.abs( posNow - posLast );
  173.                 if( distance >= _maxStep ){
  174.                     $gameSwitches.setValue(_warningSwitch, true);
  175.                 }
  176.                    
  177.                 $gameSystem.GB_debug( ['update' ,posNow, posLast, distance, _maxStep ]);
  178.             }  
  179.            
  180.         }else{
  181.             _playerLast.dir  = player._direction;
  182.             //console.log('save', player);
  183.            
  184.         }
  185.  
  186.     };
  187.    
  188.     Game_System.prototype.GB_saveBeforePosition = function( x=0, y=0, dir=0 ) {
  189.         _playerBefore = {
  190.             "x": x,
  191.             "y": y,
  192.             "dir": dir
  193.         };
  194.         $gameSystem.GB_debug(['before',_playerBefore]);
  195.     };
  196.     Game_System.prototype.GB_saveLastPosition = function( x=0, y=0, dir=0 ) {
  197.         $gameVariables.setValue( _lastPosX, x );
  198.         $gameVariables.setValue( _lastPosY, y );
  199.         _playerLast.dir = dir;
  200.         $gameSystem.GB_debug('saveLastPosition');
  201.         $gameSystem.GB_debug(['save', x, y, dir]);
  202.     };
  203.    
  204.     Game_System.prototype.GB_example = function() {
  205.         let ev = $gameMap;
  206.         let actor = $gameActors;
  207.         let party = $gameParty;
  208.         let player = $gamePlayer;
  209.         //console.log('event', _thisPluginName, ev);
  210.         //console.log('actor', actor, party, player);
  211.        
  212.         if( _playerLast.x != player._x || _playerLast.y != player._y){
  213.             console.log(player._x, player._y, player._direction, cek);
  214.             _playerLast.x = player._x;
  215.             _playerLast.y = player._y;
  216.             _playerLast.dir = player._direction;
  217.             //down:2; up:8; left:4; right:6;
  218.            
  219.         }
  220.        
  221.     };
  222. //$gameSystem.GB_debug();
  223.     Game_System.prototype.GB_debug = function( status="-", save=false ) {
  224.         let player = $gamePlayer;
  225.         if( _playerLast.x != player._x || _playerLast.y != player._y){
  226.             let savePos =[ posLast = $gameVariables.value( _lastPosX ), posLast = $gameVariables.value( _lastPosY ) ];
  227.             console.log([status, player, _playerLast, savePos, cek]);
  228.             cek ++;
  229.             if( save || _playerLast.x == 0 || _playerLast.y == 0 ){
  230.                 _playerLast.x = player._x;
  231.                 _playerLast.y = player._y;
  232.                 console.log(_playerLast, player);
  233.             }
  234.         }
  235.     }
  236.  
  237. })();
  238.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement