modern_algebra

VehiclePassabilityForEvents

Oct 27th, 2015
213
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. //  Vehicle Passability for Events
  3. //  Version: 1.0.0
  4. //  Date: 27 October 2015
  5. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6. /*:
  7.  * @plugindesc Set up events that are bound by the passability rules of boats, ships, or airships
  8.  * @author Modern Algebra (rmrk.net)
  9.  * @help This plugin does not have any plugin parameters. It is setup through
  10.  * comments in an event.
  11.  *
  12.  * To set vehicle passability for an event, you must set the first command for
  13.  * an event page to be a comment which includes one of the following codes:
  14.  *
  15.  *      \vehicle[boat]
  16.  *      \vehicle[ship]
  17.  *      \vehicle[airship]
  18.  *
  19.  * The vehicle type is determined on a page-by-page basis. If a vehicle event
  20.  * should update to a new page, it will need to have a new vehicle code or
  21.  * else it will revert to normal passability.
  22.  */
  23. //=============================================================================
  24.  
  25. (function() {
  26.    
  27.     var _Game_Event_initMembers =
  28.             Game_Event.prototype.initMembers;
  29.     Game_Event.prototype.initMembers = function() {
  30.         _Game_Event_initMembers.call(this);
  31.         this._maVehicleType = ''; // Initialize _maVehicleType
  32.     };
  33.  
  34.     var _Game_Event_setupPageSettings =
  35.             Game_Event.prototype.setupPageSettings;
  36.     Game_Event.prototype.setupPageSettings = function() {
  37.         _Game_Event_setupPageSettings.call(this)
  38.         var comments = this.maepoCollectCommentsAt(0);
  39.         // Match an integer in \vehicle[x]
  40.         var rpatt = /\\vehicle\s*\[\s*(boat|ship|airship)\s*\]/i;
  41.         var match = rpatt.exec(comments);
  42.         if (match) { // If there is a match (match is not null)
  43.             vtype = match[1].toLowerCase();
  44.             this._maVehicleType = vtype;
  45.         } else {
  46.             this._maVehicleType = '';    
  47.         }
  48.     };
  49.    
  50.     // Selects all comment lines at index i in the list
  51.     Game_Event.prototype.maepoCollectCommentsAt = function(i) {
  52.         var comments = '';
  53.         var list = this.list(); // List of event commands for current page
  54.         // Select only comment lines
  55.         while (i < list.length && (list[i].code === 108 || list[i].code === 408)) {
  56.             comments = comments + list[i].parameters[0];
  57.             i++;
  58.         }
  59.         return comments
  60.     };
  61.  
  62.     // For consistency, code below uses same structure as in Game_Player
  63.     var _Game_Event_isMapPassable =
  64.             Game_Event.prototype.isMapPassable;  
  65.     Game_Event.prototype.isMapPassable = function(x, y, d) {
  66.         var vehicle = this.vehicle();
  67.         if (vehicle) {
  68.             return vehicle.isMapPassable(x, y, d);
  69.         } else {
  70.             return _Game_Event_isMapPassable.call(this, x, y, d);
  71.         }
  72.     };
  73.    
  74.     Game_Event.prototype.vehicle = function() {
  75.         return $gameMap.vehicle(this._maVehicleType);
  76.     };
  77.    
  78. })();
RAW Paste Data