查看: 3661|回复: 1

[已经解决] 关于YEP_SmartJump

[复制链接]
梦石
0
星屑
6963
在线时间
1557 小时
注册时间
2011-6-14
回帖
425
发表于 2016-3-16 17:06:00 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
智能跳跃脚本在插件管理设置跳跃步数进入游戏实测相差太大
我设置为1 在游戏里面却是跳了4.5步 求设置方法


  1. //=============================================================================
  2. // Yanfly Engine Plugins - Smart Jump
  3. // YEP_SmartJump.js
  4. //=============================================================================

  5. var Imported = Imported || {};
  6. Imported.YEP_SmartJump = true;

  7. var Yanfly = Yanfly || {};
  8. Yanfly.Jump = Yanfly.Jump || {};

  9. //=============================================================================
  10. /*:
  11. * @plugindesc v1.00 Adds a plugin command that enables smart jumping
  12. * where the player cannot jump into illegal areas.
  13. * @author Yanfly Engine Plugins
  14. *
  15. * @param Illegal Regions
  16. * @desc These are the region ID's the player cannot jump on
  17. * or past. Separate each region with a space.
  18. * @default 0
  19. *
  20. * @help
  21. * ============================================================================
  22. * Introduction
  23. * ============================================================================
  24. *
  25. * For those that may have made their own Jump system before with events, you
  26. * may have come across the problem of being able to jump off the map, into
  27. * places you're not supposed to go, or even on top of events that shouldn't be
  28. * allowed to go on top of. This plugin helps faciliate eventing a Jump system
  29. * for your RPG Maker game by introducing Smart Jumps.
  30. *
  31. * Smart Jumps will allow you to jump over areas, but will limit you from
  32. * jumping on top of places you can't go, on top of normal priority events, and
  33. * set up boundaries (such as walls) that you normally cannot jump past.
  34. *
  35. * ============================================================================
  36. * Instructions - Setting Up Smart Jumps
  37. * ============================================================================
  38. *
  39. * Use the Plugin Command 'SmartJump' to make the player character perform a
  40. * Smart Jump.
  41. *
  42. * Inside the plugin parameters, mark the Illegal Regions your player cannot
  43. * jump past or on and then draw them on the map. Alternatively, you can mark
  44. * certain tile types within the Database > Tileset tab and use Terrain Tags to
  45. * restrict where the player cannot jump.
  46. *
  47. * ============================================================================
  48. * Notetags
  49. * ============================================================================
  50. *
  51. * You can use these notetags to set up what Terrain Tags that the player can't
  52. * jump on or past.
  53. *
  54. * Tileset Notetags:
  55. *
  56. *   <Illegal Jump: x>
  57. *   <Illegal Jump: x, x, x>
  58. *   <Illegal Jump: x to y>
  59. *   Replace x with the terrain tags you want to forbid the player from going
  60. *   past or landing on while doing Smart Jumps.
  61. *
  62. * Event Notetag:
  63. *
  64. *   <Illegal Jump>
  65. *   This will prevent the player from being able to jump on or over this
  66. *   event while doing Smart Jumps. If the event is set to Through mode, then
  67. *   the player can jump through or onto the event.
  68. */
  69. //=============================================================================

  70. //=============================================================================
  71. // Parameter Variables
  72. //=============================================================================

  73. Yanfly.Parameters = PluginManager.parameters('YEP_SmartJump');
  74. Yanfly.Param = Yanfly.Param || {};

  75. Yanfly.Param.JumpIllegalRegion = String(Yanfly.Parameters['Illegal Regions']);
  76. Yanfly.Param.JumpIllegalRegion = Yanfly.Param.JumpIllegalRegion.split(' ');
  77. if (Yanfly.Param.JumpIllegalRegion === '') Yanfly.Param.JumpIllegalRegion = [];
  78. Yanfly.max = Yanfly.Param.JumpIllegalRegion.length;
  79. for (Yanfly.i = 0; Yanfly.i < Yanfly.max; ++Yanfly.i) {
  80.   Yanfly.Param.JumpIllegalRegion[Yanfly.i] =
  81.     parseInt(Yanfly.Param.JumpIllegalRegion[Yanfly.i]);
  82. };

  83. //=============================================================================
  84. // DataManager
  85. //=============================================================================

  86. Yanfly.Jump.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  87. DataManager.isDatabaseLoaded = function() {
  88.     if (!Yanfly.Jump.DataManager_isDatabaseLoaded.call(this)) return false;
  89.     this.processJumpNotetags1($dataTilesets);
  90.     return true;
  91. };

  92. DataManager.processJumpNotetags1 = function(group) {
  93.   var note1a = /<(?:ILLEGAL JUMP):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
  94.   var note1b = /<(?:ILLEGAL JUMP):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  95.   for (var n = 1; n < group.length; n++) {
  96.     var obj = group[n];
  97.     var notedata = obj.note.split(/[\r\n]+/);

  98.     obj.illegalJumpTag = [];

  99.     for (var i = 0; i < notedata.length; i++) {
  100.       var line = notedata[i];
  101.       if (line.match(note1a)) {
  102.         var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  103.         obj.illegalJumpTag = obj.illegalJumpTag.concat(array);
  104.       } else if (line.match(note1b)) {
  105.         var range = Yanfly.Util.getRange(parseInt(RegExp.$1),
  106.           parseInt(RegExp.$2));
  107.         obj.illegalJumpTag = obj.illegalJumpTag.concat(range);
  108.       }
  109.     }
  110.   }
  111. };

  112. DataManager.processJumpNotetags2 = function(obj) {
  113.   var notedata = obj.note.split(/[\r\n]+/);
  114.   obj.illegalJump = false;
  115.   for (var i = 0; i < notedata.length; i++) {
  116.     var line = notedata[i];
  117.     if (line.match(/<(?:ILLEGAL JUMP)>/i)) {
  118.       obj.illegalJump = true;
  119.     }
  120.   }
  121. };

  122. //=============================================================================
  123. // Game_CharacterBase
  124. //=============================================================================

  125. Game_CharacterBase.prototype.smartJump = function(distance) {
  126.     if (distance === 0) return this.jump(0, 0);
  127.     this.setupSmartJump(this.getSmartJumpDistance(distance));
  128. };

  129. Game_CharacterBase.prototype.setupSmartJump = function(distance) {
  130.     if (this._direction === 2) {
  131.       this.jump(0, distance);
  132.     } else if (this._direction === 4) {
  133.       this.jump(-distance, 0);
  134.     } else if (this._direction === 6) {
  135.       this.jump(distance, 0);
  136.     } else if (this._direction === 8) {
  137.       this.jump(0, -distance);
  138.     }
  139. };

  140. Game_CharacterBase.prototype.getSmartJumpDistance = function(distance) {
  141.     if (this._direction === 2) {
  142.       for (var i = 0; i < distance; ++i) {
  143.         if (this.isSmartJumpIllegalRegion(this.x, this.y + i + 1)) {
  144.           distance = i;
  145.           break;
  146.         }
  147.       }
  148.     } else if (this._direction === 4) {
  149.       for (var i = 0; i < distance; ++i) {
  150.         if (this.isSmartJumpIllegalRegion(this.x - i - 1, this.y)) {
  151.           distance = i;
  152.           break;
  153.         }
  154.       }
  155.     } else if (this._direction === 6) {
  156.       for (var i = 0; i < distance; ++i) {
  157.         if (this.isSmartJumpIllegalRegion(this.x + i + 1, this.y)) {
  158.           distance = i;
  159.           break;
  160.         }
  161.       }
  162.     } else if (this._direction === 8) {
  163.       for (var i = 0; i < distance; ++i) {
  164.         if (this.isSmartJumpIllegalRegion(this.x, this.y - i - 1)) {
  165.           distance = i;
  166.           break;
  167.         }
  168.       }
  169.     }
  170.     return this.calcSmartJumpDistance(distance);
  171. };

  172. Game_CharacterBase.prototype.isSmartJumpIllegalRegion = function(x, y) {
  173.     if (x < 0 || y < 0) return true;
  174.     if (x > $gameMap.width() - 1 || y > $gameMap.height() - 1) return true;
  175.     if (this.isThrough()) return false;
  176.     var regionId = $gameMap.regionId(x, y);
  177.     if (regionId > 0 && Yanfly.Param.JumpIllegalRegion.contains(regionId)) {
  178.       return true;
  179.     }
  180.     var tileset = $gameMap.tileset();
  181.     if (tileset && tileset.illegalJumpTag.contains($gameMap.terrainTag(x, y))) {
  182.       return true;
  183.     }
  184.     var events = $gameMap.eventsXy(x, y);
  185.     var length = events.length;
  186.     for (var i = 0; i < length; ++i) {
  187.       var ev = events[i];
  188.       if (!ev) continue;
  189.       if (ev.isThrough()) continue;
  190.       if (ev.isSmartJumpBlocked()) return true;
  191.     }
  192.     return false;
  193. };

  194. Game_CharacterBase.prototype.calcSmartJumpDistance = function(distance) {
  195.     var max = distance;
  196.     var value = 0;
  197.     if (this._direction === 2) {
  198.       for (var i = 0; i < max; ++i) {
  199.         if (this.isSmartJumpValid(this.x, this.y + max - i)) {
  200.           value = max - i;
  201.           break;
  202.         }
  203.       }
  204.     } else if (this._direction === 4) {
  205.       for (var i = 0; i < max; ++i) {
  206.         if (this.isSmartJumpValid(this.x - max + i, this.y)) {
  207.           value = max - i;
  208.           break;
  209.         }
  210.       }
  211.     } else if (this._direction === 6) {
  212.       for (var i = 0; i < max; ++i) {
  213.         if (this.isSmartJumpValid(this.x + max - i, this.y)) {
  214.           value = max - i;
  215.           break;
  216.         }
  217.       }
  218.     } else if (this._direction === 8) {
  219.       for (var i = 0; i < max; ++i) {
  220.         if (this.isSmartJumpValid(this.x, this.y - max + i)) {
  221.           value = max - i;
  222.           break;
  223.         }
  224.       }
  225.     }
  226.     return value;
  227. };

  228. Game_CharacterBase.prototype.isSmartJumpValid = function(x, y) {
  229.     if (this.isThrough()) return true;
  230.     var events = $gameMap.eventsXyNt(x, y);
  231.     var length = events.length;
  232.     for (var i = 0; i < length; ++i) {
  233.       var ev = events[i];
  234.       if (!ev) continue;
  235.       if (ev.isThrough()) continue;
  236.       if (ev.isNormalPriority()) return false;
  237.       if (ev.isSmartJumpBlocked()) return false;
  238.     }
  239.     return $gameMap.isPassable(x, y, this._direction);
  240. };

  241. //=============================================================================
  242. // Game_Event
  243. //=============================================================================

  244. Yanfly.Jump.Game_Event_setupPageSettings =
  245.     Game_Event.prototype.setupPageSettings;
  246. Game_Event.prototype.setupPageSettings = function() {
  247.     Yanfly.Jump.Game_Event_setupPageSettings.call(this);
  248.     DataManager.processJumpNotetags2(this.event());
  249. };

  250. Game_Event.prototype.isSmartJumpBlocked = function() {
  251.     if (this.event().illegalJump === undefined) {
  252.       DataManager.processJumpNotetags2(this.event());
  253.     }
  254.     return this.event().illegalJump;
  255. };

  256. //=============================================================================
  257. // Game_Interpreter
  258. //=============================================================================

  259. Yanfly.Jump.Game_Interpreter_pluginCommand =
  260.     Game_Interpreter.prototype.pluginCommand;
  261. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  262.   Yanfly.Jump.Game_Interpreter_pluginCommand.call(this, command, args);
  263.   if (command === 'SmartJump') {
  264.     $gamePlayer.smartJump(parseInt(args[0]));
  265.   }
  266. };

  267. //=============================================================================
  268. // Utilities
  269. //=============================================================================

  270. Yanfly.Util = Yanfly.Util || {};

  271. Yanfly.Util.getRange = function(n, m) {
  272.     var result = [];
  273.     for (var i = n; i <= m; ++i) result.push(i);
  274.     return result;
  275. };

  276. //=============================================================================
  277. // End of File
  278. //=============================================================================
复制代码

Mr.Gandum

梦石
0
星屑
226
在线时间
2070 小时
注册时间
2007-1-31
回帖
2982

贵宾

发表于 2016-3-16 17:13:36 | 显示全部楼层
本帖最后由 feizhaodan 于 2016-3-16 17:16 编辑

插件管理里面设置的数值是不可以跳上或者跳过的区域ID。。。
在呼出跳跃指令(SmartJump)的参数里面指定了跳跃距离了么?
然后看了一下脚本内容,貌似是自动寻找设置的距离之内可以着地的最远的位置进行跳跃

点评

设置了 我设置的1 但是他却是跳4.5步,我是新建的一张地图然后填充草地测试的  发表于 2016-3-16 18:12
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部