Advertisement
Kakakadafi

SimpleLandVehicle

Jul 14th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //============================================================================
  2. // Karberus - Simple Land Vehicle
  3. // SimpleLandVehicle.js
  4. // Version 1.2
  5. // No credit required. Can be used commercially or non commercially
  6. //============================================================================
  7. //============================================================================
  8. var Imported = Imported || {};
  9. Imported.SimpleLandVehicle = true;
  10.  
  11. var Karberus = Karberus || {};
  12. Karberus.LandBoat = Karberus.LandBoat || {};
  13. //============================================================================
  14. //============================================================================
  15. /*:
  16.  * @plugindesc v1.2 Allows you to drive/ride a vehicle on land.
  17.  * @author Karberus
  18.  * @version 1.2
  19.  *
  20.  *
  21.  *
  22.  * @param Vehicle Speed
  23.  * @desc Change the movement speed of your land vehicle
  24.  * Default: 5
  25.  * @default 5
  26.  *
  27.  * @param Encounters
  28.  * @desc Whether encounters are enabled while on the land vehicle
  29.  * false = off / true = on
  30.  * @default false
  31.  *
  32.  *
  33.  * @param Touch Events
  34.  * @desc Whether touch events will be triggered while on land vehicle
  35.  * false = off / true = on
  36.  * @default false
  37.  *
  38.  *
  39.  * @param Action Button Events
  40.  * @desc Whether action button events will trigger while on land vehicle
  41.  * false = off / true = on
  42.  * @default false
  43.  *
  44.  *
  45.  * @param Forbid Region ID
  46.  * @desc Set which Region ID forbids land vehicle to pass through.
  47.  * Set to 0 if you don't wish to use this feature.
  48.  * @default 0
  49.  *
  50.  *
  51.  * @param Enter Vehicle Side
  52.  * @desc The side of the vehicle which player allowed to enter.
  53.  * left or right
  54.  * @default left
  55.  *
  56.  *
  57.  * @param Exit Vehicle Side
  58.  * @desc The side of the vehicle which player exit.
  59.  * left or right
  60.  * @default left
  61.  *
  62.  *
  63.  * @param Vehicle Door SE
  64.  * @desc Door Opening & Closing Sound Effect
  65.  * Filename, Volume, Pitch, Pan
  66.  * @default Close1, 90, 100, 0
  67.  *
  68.  *
  69.  *@help Change the boat's graphic in the database to fit a land vehicle.
  70.  *
  71.  *This plugin changes how the boat functions, and makes it into a land vehicle.
  72.  *
  73.  *
  74.  */
  75.  
  76. (function() {
  77.  
  78. //Initialize parameter values
  79. Karberus.Parameters = PluginManager.parameters("SimpleLandVehicle");
  80.  
  81. Karberus.LandBoat.Speed = Number(Karberus.Parameters["Vehicle Speed"]) ||  5;
  82. Karberus.LandBoat.Encounters = String(Karberus.Parameters["Encounters"]);
  83. Karberus.LandBoat.TouchEvents = String(Karberus.Parameters["Touch Events"]);
  84. Karberus.LandBoat.ActionEvents = String(Karberus.Parameters["Action Button Events"]);
  85. Karberus.LandBoat.ForbidRegionID = Number(Karberus.Parameters["Forbid Region ID"]);
  86. Karberus.LandBoat.EnterSide = String(Karberus.Parameters["Enter Vehicle Side"]);
  87. Karberus.LandBoat.ExitSide = String(Karberus.Parameters["Exit Vehicle Side"]);
  88. Karberus.LandBoat.DoorSE = String(Karberus.Parameters["Vehicle Door SE"]);
  89.  
  90. //=========================================================================
  91. // Passability / Overwrite
  92. //=========================================================================
  93. Game_Player.prototype.isMapPassable = function(x, y, d) {
  94.  
  95.   var vehicle = this.vehicle();
  96.     if (vehicle)
  97.     {
  98.       if(this._vehicleType !== 'boat') return vehicle.isMapPassable(x, y, d);
  99.       if(this._vehicleType === 'boat')
  100.       {
  101.         if(this.noLandVehicleRegion(x, y, d)) return false;
  102.         return Game_Character.prototype.isMapPassable.call(this, x, y, d);
  103.       }
  104.  
  105.     }
  106.     else
  107.     {
  108. return Game_Character.prototype.isMapPassable.call(this, x, y, d);
  109.     }
  110. };
  111.  
  112. //==========================================================================
  113. // Check
  114. //==========================================================================
  115.  
  116. Game_Player.prototype.noLandVehicleRegion = function(x, y, d) {
  117.     var regionId = this.checkNoLandVehicleRegionID(x, y, d);
  118.     if (regionId === 0) return false;
  119.     if (regionId === Karberus.LandBoat.ForbidRegionID) return true;
  120.     return regionId === Karberus.LandBoat.ForbidRegionID;
  121. };
  122.  
  123. //========================================================================
  124. // Get Region ID
  125. //========================================================================
  126.  
  127. Game_Player.prototype.checkNoLandVehicleRegionID = function(x, y, d) {
  128.     switch (d) {
  129.     case 1:
  130.       return $gameMap.regionId(x - 1, y + 1);
  131.       break;
  132.     case 2:
  133.       return $gameMap.regionId(x + 0, y + 1);
  134.       break;
  135.     case 3:
  136.       return $gameMap.regionId(x + 1, y + 1);
  137.       break;
  138.     case 4:
  139.       return $gameMap.regionId(x - 1, y + 0);
  140.       break;
  141.     case 5:
  142.       return $gameMap.regionId(x + 0, y + 0);
  143.       break;
  144.     case 6:
  145.       return $gameMap.regionId(x + 1, y + 0);
  146.       break;
  147.     case 7:
  148.       return $gameMap.regionId(x - 1, y - 1);
  149.       break;
  150.     case 8:
  151.       return $gameMap.regionId(x + 0, y - 1);
  152.       break;
  153.     case 9:
  154.       return $gameMap.regionId(x + 1, y - 1);
  155.       break;
  156.     }
  157.     return 0;
  158. };
  159.  
  160. //=============================================================================
  161. // Determine whether to have encounters while on the land vehicle / Overwrite
  162. //=============================================================================
  163.  
  164. Game_Player.prototype.canEncounter = function() {
  165.  
  166.     if (eval(Karberus.LandBoat.Encounters) === false) {
  167.     return (!$gameParty.hasEncounterNone() && $gameSystem.isEncounterEnabled() &&
  168.             !this.isInAirship() && !this.isInBoat() && !this.isMoveRouteForcing() && !this.isDebugThrough());
  169.           } else {
  170.             return (!$gameParty.hasEncounterNone() && $gameSystem.isEncounterEnabled() &&
  171.                     !this.isInAirship() && !this.isMoveRouteForcing() && !this.isDebugThrough());
  172.           }
  173. };
  174.  
  175. //=============================================================================
  176. // Check whether events can be triggered / Overwrite
  177. //=============================================================================
  178.  
  179.  
  180.  
  181. Game_Player.prototype.checkEventTriggerHere = function(triggers) {
  182.   if (eval(Karberus.LandBoat.TouchEvents) === false) {
  183.     if (!this.isInBoat() && this.canStartLocalEvents()) {
  184.         this.startMapEvent(this.x, this.y, triggers, false);
  185.     }
  186.   } else {  if (this.canStartLocalEvents()) {
  187.         this.startMapEvent(this.x, this.y, triggers, false);
  188.     }
  189.   }
  190. };
  191.  
  192. Game_Player.prototype.checkEventTriggerThere = function(triggers) {
  193.   if (eval(Karberus.LandBoat.ActionEvents) === false) {
  194.     if (!this.isInBoat() && this.canStartLocalEvents()) {
  195.         var direction = this.direction();
  196.         var x1 = this.x;
  197.         var y1 = this.y;
  198.         var x2 = $gameMap.roundXWithDirection(x1, direction);
  199.         var y2 = $gameMap.roundYWithDirection(y1, direction);
  200.         this.startMapEvent(x2, y2, triggers, true);
  201.         if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x2, y2)) {
  202.             var x3 = $gameMap.roundXWithDirection(x2, direction);
  203.             var y3 = $gameMap.roundYWithDirection(y2, direction);
  204.             this.startMapEvent(x3, y3, triggers, true);
  205.         }
  206.     }
  207.   } else {
  208.     if (this.canStartLocalEvents()) {
  209.         var direction = this.direction();
  210.         var x1 = this.x;
  211.         var y1 = this.y;
  212.         var x2 = $gameMap.roundXWithDirection(x1, direction);
  213.         var y2 = $gameMap.roundYWithDirection(y1, direction);
  214.         this.startMapEvent(x2, y2, triggers, true);
  215.         if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x2, y2)) {
  216.             var x3 = $gameMap.roundXWithDirection(x2, direction);
  217.             var y3 = $gameMap.roundYWithDirection(y2, direction);
  218.             this.startMapEvent(x3, y3, triggers, true);
  219.         }
  220.     }
  221.  
  222.   }
  223. };
  224.  
  225. Game_Player.prototype.playVehicleDoorSE = function() {
  226.     var data = Karberus.LandBoat.DoorSE;
  227.     var data_array = String(data).split(',');
  228.     var filename = data_array[0];
  229.     var volume = Number(data_array[1]);
  230.     var pitch = Number(data_array[2]);
  231.     var pan = Number(data_array[3]);
  232.     var SE = {
  233.         name: filename,
  234.         volume: volume,
  235.         pitch: pitch,
  236.         pan: pan
  237.     };
  238.     AudioManager.playSe(SE);
  239. };
  240.  
  241. Game_Player.prototype.getOnVehicle = function() {
  242.     var enterSide = Karberus.LandBoat.EnterSide;
  243.     var direction = this.direction();
  244.     var x1 = this.x;
  245.     var y1 = this.y;
  246.     var x2 = $gameMap.roundXWithDirection(x1, direction);
  247.     var y2 = $gameMap.roundYWithDirection(y1, direction);
  248.     if ($gameMap.airship().pos(x1, y1)) {
  249.         this._vehicleType = 'airship';
  250.     } else if ($gameMap.ship().pos(x2, y2)) {
  251.         this._vehicleType = 'ship';
  252.     } else if ($gameMap.boat().pos(x2, y2)) {
  253.         if (enterSide === "left") {
  254.             if ((($gameMap.boat().direction() === 2) && ($gamePlayer.direction() === 4)) ||
  255.                 (($gameMap.boat().direction() === 8) && ($gamePlayer.direction() === 6)) ||
  256.                 (($gameMap.boat().direction() === 4) && ($gamePlayer.direction() === 8)) ||
  257.                 (($gameMap.boat().direction() === 6) && ($gamePlayer.direction() === 2))) {
  258.                     this._vehicleType = 'boat';
  259.                     this.playVehicleDoorSE();
  260.                 }
  261.         } else if (enterSide === "right") {
  262.             if ((($gameMap.boat().direction() === 2) && ($gamePlayer.direction() === 6)) ||
  263.                 (($gameMap.boat().direction() === 8) && ($gamePlayer.direction() === 4)) ||
  264.                 (($gameMap.boat().direction() === 4) && ($gamePlayer.direction() === 2)) ||
  265.                 (($gameMap.boat().direction() === 6) && ($gamePlayer.direction() === 8))) {
  266.                     this._vehicleType = 'boat';
  267.                     this.playVehicleDoorSE();
  268.                 }
  269.         }
  270.     }
  271.     if (this.isInVehicle()) {
  272.         this._vehicleGettingOn = true;
  273.         if (!this.isInAirship()) {
  274.             this.forceMoveForward();
  275.         }
  276.         this.gatherFollowers();
  277.     }
  278.     return this._vehicleGettingOn;
  279. };
  280.  
  281. Game_Player.prototype.forceMoveTo = function(d) {
  282.     this.setThrough(true);
  283.     this.moveStraight(d);
  284.     this.setThrough(false);
  285. };
  286.  
  287. Game_Player.prototype.getOffVehicle = function() {
  288.     if (this.vehicle().isLandOk(this.x, this.y, this.direction())) {
  289.         if (this.isInAirship()) {
  290.             this.setDirection(2);
  291.         }
  292.         this._followers.synchronize(this.x, this.y, this.direction());
  293.         this.vehicle().getOff();
  294.         if (!this.isInAirship() && !this.isInBoat()) {
  295.             this.forceMoveForward();
  296.             this.setTransparent(false);
  297.         }
  298.         if (this.isInBoat()) {
  299.             var direction = this.direction();
  300.             var exitSide = Karberus.LandBoat.ExitSide;
  301.             if (exitSide === "left") {
  302.                 if ($gameMap.boat().direction() === 2) {
  303.                     direction = 6;
  304.                 } else if ($gameMap.boat().direction() === 8) {
  305.                     direction = 4;
  306.                 } else if ($gameMap.boat().direction() === 4) {
  307.                     direction = 2;
  308.                 } else if ($gameMap.boat().direction() === 6) {
  309.                     direction = 8;
  310.                 }
  311.             } else if (exitSide === "right") {
  312.                 if ($gameMap.boat().direction() === 2) {
  313.                     direction = 4;
  314.                 } else if ($gameMap.boat().direction() === 8) {
  315.                     direction = 6;
  316.                 } else if ($gameMap.boat().direction() === 4) {
  317.                     direction = 8;
  318.                 } else if ($gameMap.boat().direction() === 6) {
  319.                     direction = 2;
  320.                 }
  321.             }
  322.             this.playVehicleDoorSE();
  323.             this.forceMoveTo(direction);
  324.             this.setTransparent(false);
  325.         }
  326.         this._vehicleGettingOff = true;
  327.         this.setMoveSpeed(4);
  328.         this.setThrough(false);
  329.         this.makeEncounterCount();
  330.         this.gatherFollowers();
  331.     }
  332.     return this._vehicleGettingOff;
  333. };
  334.  
  335. //=============================================================================
  336. //=============================================================================
  337. // Change move speed when on the vehicle / Overwrite
  338. //=============================================================================
  339. Game_Vehicle.prototype.initMoveSpeed = function() {
  340.  
  341.   if (this.isBoat()) {
  342.       this.setMoveSpeed(Karberus.LandBoat.Speed);
  343.   } else if (this.isShip()) {
  344.       this.setMoveSpeed(5);
  345.   } else if (this.isAirship()) {
  346.       this.setMoveSpeed(6);
  347.   }
  348. };
  349.  
  350. Game_Vehicle.prototype.resetDirection = function() {
  351.     if (!this.isBoat()) this.setDirection(4);
  352. };
  353.  
  354. //=============================================================================
  355. //=============================================================================
  356. })();
  357. //=============================================================================
  358. //===================================END FILE==================================
  359. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement