查看: 3630|回复: 1

[已经解决] 关于YEP_SmartJump

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

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

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

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


[pre lang="javascript"]//=============================================================================
// Yanfly Engine Plugins - Smart Jump
// YEP_SmartJump.js
//=============================================================================

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

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

//=============================================================================
/*:
* @plugindesc v1.00 Adds a plugin command that enables smart jumping
* where the player cannot jump into illegal areas.
* @author Yanfly Engine Plugins
*
* @param Illegal Regions
* @desc These are the region ID's the player cannot jump on
* or past. Separate each region with a space.
* @default 0
*
* @help
* ============================================================================
* Introduction
* ============================================================================
*
* For those that may have made their own Jump system before with events, you
* may have come across the problem of being able to jump off the map, into
* places you're not supposed to go, or even on top of events that shouldn't be
* allowed to go on top of. This plugin helps faciliate eventing a Jump system
* for your RPG Maker game by introducing Smart Jumps.
*
* Smart Jumps will allow you to jump over areas, but will limit you from
* jumping on top of places you can't go, on top of normal priority events, and
* set up boundaries (such as walls) that you normally cannot jump past.
*
* ============================================================================
* Instructions - Setting Up Smart Jumps
* ============================================================================
*
* Use the Plugin Command 'SmartJump' to make the player character perform a
* Smart Jump.
*
* Inside the plugin parameters, mark the Illegal Regions your player cannot
* jump past or on and then draw them on the map. Alternatively, you can mark
* certain tile types within the Database > Tileset tab and use Terrain Tags to
* restrict where the player cannot jump.
*
* ============================================================================
* Notetags
* ============================================================================
*
* You can use these notetags to set up what Terrain Tags that the player can't
* jump on or past.
*
* Tileset Notetags:
*
*   <Illegal Jump: x>
*   <Illegal Jump: x, x, x>
*   <Illegal Jump: x to y>
*   Replace x with the terrain tags you want to forbid the player from going
*   past or landing on while doing Smart Jumps.
*
* Event Notetag:
*
*   <Illegal Jump>
*   This will prevent the player from being able to jump on or over this
*   event while doing Smart Jumps. If the event is set to Through mode, then
*   the player can jump through or onto the event.
*/
//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

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

Yanfly.Param.JumpIllegalRegion = String(Yanfly.Parameters['Illegal Regions']);
Yanfly.Param.JumpIllegalRegion = Yanfly.Param.JumpIllegalRegion.split(' ');
if (Yanfly.Param.JumpIllegalRegion === '') Yanfly.Param.JumpIllegalRegion = [];
Yanfly.max = Yanfly.Param.JumpIllegalRegion.length;
for (Yanfly.i = 0; Yanfly.i < Yanfly.max; ++Yanfly.i) {
  Yanfly.Param.JumpIllegalRegion[Yanfly.i] =
    parseInt(Yanfly.Param.JumpIllegalRegion[Yanfly.i]);
};

//=============================================================================
// DataManager
//=============================================================================

Yanfly.Jump.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
    if (!Yanfly.Jump.DataManager_isDatabaseLoaded.call(this)) return false;
    this.processJumpNotetags1($dataTilesets);
    return true;
};

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

    obj.illegalJumpTag = [];

    for (var i = 0; i < notedata.length; i++) {
      var line = notedata;
      if (line.match(note1a)) {
        var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
        obj.illegalJumpTag = obj.illegalJumpTag.concat(array);
      } else if (line.match(note1b)) {
        var range = Yanfly.Util.getRange(parseInt(RegExp.$1),
          parseInt(RegExp.$2));
        obj.illegalJumpTag = obj.illegalJumpTag.concat(range);
      }
    }
  }
};

DataManager.processJumpNotetags2 = function(obj) {
  var notedata = obj.note.split(/[\r\n]+/);
  obj.illegalJump = false;
  for (var i = 0; i < notedata.length; i++) {
    var line = notedata;
    if (line.match(/<(?:ILLEGAL JUMP)>/i)) {
      obj.illegalJump = true;
    }
  }
};

//=============================================================================
// Game_CharacterBase
//=============================================================================

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

Game_CharacterBase.prototype.setupSmartJump = function(distance) {
    if (this._direction === 2) {
      this.jump(0, distance);
    } else if (this._direction === 4) {
      this.jump(-distance, 0);
    } else if (this._direction === 6) {
      this.jump(distance, 0);
    } else if (this._direction === 8) {
      this.jump(0, -distance);
    }
};

Game_CharacterBase.prototype.getSmartJumpDistance = function(distance) {
    if (this._direction === 2) {
      for (var i = 0; i < distance; ++i) {
        if (this.isSmartJumpIllegalRegion(this.x, this.y + i + 1)) {
          distance = i;
          break;
        }
      }
    } else if (this._direction === 4) {
      for (var i = 0; i < distance; ++i) {
        if (this.isSmartJumpIllegalRegion(this.x - i - 1, this.y)) {
          distance = i;
          break;
        }
      }
    } else if (this._direction === 6) {
      for (var i = 0; i < distance; ++i) {
        if (this.isSmartJumpIllegalRegion(this.x + i + 1, this.y)) {
          distance = i;
          break;
        }
      }
    } else if (this._direction === 8) {
      for (var i = 0; i < distance; ++i) {
        if (this.isSmartJumpIllegalRegion(this.x, this.y - i - 1)) {
          distance = i;
          break;
        }
      }
    }
    return this.calcSmartJumpDistance(distance);
};

Game_CharacterBase.prototype.isSmartJumpIllegalRegion = function(x, y) {
    if (x < 0 || y < 0) return true;
    if (x > $gameMap.width() - 1 || y > $gameMap.height() - 1) return true;
    if (this.isThrough()) return false;
    var regionId = $gameMap.regionId(x, y);
    if (regionId > 0 && Yanfly.Param.JumpIllegalRegion.contains(regionId)) {
      return true;
    }
    var tileset = $gameMap.tileset();
    if (tileset && tileset.illegalJumpTag.contains($gameMap.terrainTag(x, y))) {
      return true;
    }
    var events = $gameMap.eventsXy(x, y);
    var length = events.length;
    for (var i = 0; i < length; ++i) {
      var ev = events;
      if (!ev) continue;
      if (ev.isThrough()) continue;
      if (ev.isSmartJumpBlocked()) return true;
    }
    return false;
};

Game_CharacterBase.prototype.calcSmartJumpDistance = function(distance) {
    var max = distance;
    var value = 0;
    if (this._direction === 2) {
      for (var i = 0; i < max; ++i) {
        if (this.isSmartJumpValid(this.x, this.y + max - i)) {
          value = max - i;
          break;
        }
      }
    } else if (this._direction === 4) {
      for (var i = 0; i < max; ++i) {
        if (this.isSmartJumpValid(this.x - max + i, this.y)) {
          value = max - i;
          break;
        }
      }
    } else if (this._direction === 6) {
      for (var i = 0; i < max; ++i) {
        if (this.isSmartJumpValid(this.x + max - i, this.y)) {
          value = max - i;
          break;
        }
      }
    } else if (this._direction === 8) {
      for (var i = 0; i < max; ++i) {
        if (this.isSmartJumpValid(this.x, this.y - max + i)) {
          value = max - i;
          break;
        }
      }
    }
    return value;
};

Game_CharacterBase.prototype.isSmartJumpValid = function(x, y) {
    if (this.isThrough()) return true;
    var events = $gameMap.eventsXyNt(x, y);
    var length = events.length;
    for (var i = 0; i < length; ++i) {
      var ev = events;
      if (!ev) continue;
      if (ev.isThrough()) continue;
      if (ev.isNormalPriority()) return false;
      if (ev.isSmartJumpBlocked()) return false;
    }
    return $gameMap.isPassable(x, y, this._direction);
};

//=============================================================================
// Game_Event
//=============================================================================

Yanfly.Jump.Game_Event_setupPageSettings =
    Game_Event.prototype.setupPageSettings;
Game_Event.prototype.setupPageSettings = function() {
    Yanfly.Jump.Game_Event_setupPageSettings.call(this);
    DataManager.processJumpNotetags2(this.event());
};

Game_Event.prototype.isSmartJumpBlocked = function() {
    if (this.event().illegalJump === undefined) {
      DataManager.processJumpNotetags2(this.event());
    }
    return this.event().illegalJump;
};

//=============================================================================
// Game_Interpreter
//=============================================================================

Yanfly.Jump.Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
  Yanfly.Jump.Game_Interpreter_pluginCommand.call(this, command, args);
  if (command === 'SmartJump') {
    $gamePlayer.smartJump(parseInt(args[0]));
  }
};

//=============================================================================
// Utilities
//=============================================================================

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

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

//=============================================================================
// End of File
//=============================================================================
[/pre]

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.

在本版发帖返回顶部