//=============================================================================
// VIPArcher_Dir8.js
//=============================================================================
/*:
* @plugindesc 真 · 八方向移动
* @author VIPArcher
*
* @param Dir8_flag
* @desc 使用八方向素材的标志
* @default %
*
* @param Dir8_Affix
* @desc 八方向素材文件后缀
* @default _8D
*
* @help 使用八方向的行走图素材文件名前面添加一个标志,
* 与之对应的8方向的素材与其同名并在后面添加后缀以区别。
* 例如默认的设置就是使用八方向的素材命名为:
* !$%VIPArcher.png
*
* 那么与之对应的八方向的素材就应命名为:
* !$%VIPArcher_8D.png
*
*/
// merge the two plugins
//=============================================================================
// More Character Frames
// by Shaz
// Last Updated: 2015.09.21
//=============================================================================
/*:
* @plugindesc Allows more than 3 Frames
* @author Shaz
*
* @help This plugin does not provide plugin commands.
*
* Add [D L R U] to your character sheet name (with $ prefix) to specify haw
* many frames in each direction (Down, Left, Right, Up).
* Spritesheets with this added to the file name will use a looping frame
* animation rather than the back-and-forth default animation.
*
* The first frame should be the idle/still pose.
*
* eg. $Ralph [8 8 8 8].png
* is a character sheet consisting of 4 rows with 8 frames per row.
* Animation will go from frame 1 to 8 then start at 1 again.
*
* !!! For merging with idle action plugin, do not put $ in file name. Simply define the frame.
* 这里不要用插件默认的$前缀文件,为了和其他插件兼容我们要保持MV默认的4*2划分行走图方式
* 只需要在文件名后面加上[a b c d],分别定义4个方向的帧数
*/
(function() {
var parameters = PluginManager.parameters('VIPArcher_Dir8');
var dir8_flag = String(parameters['Dir8_flag'] || '%');
var dir8_affix = String(parameters['Dir8_Affix'] || '_8D');
ImageManager.isDir8Character = function(filename) {
var reg = new RegExp("^\[\\!\\$\\" + dir8_flag + "]+")
var sign = filename.match(reg);
return sign && sign[0].contains(dir8_flag);
};
//multiframe parameters 插入的多帧脚本内容,没有修改
ImageManager.isMultiFrameCharacter = function(filename) {
var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
return frames && frames.length === 5;
};
ImageManager.getCharacterFrameCount = function(filename) {
var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
if (!frames) {
return [3, 3, 3, 3];
} else {
return frames.splice(1, 4);
}
};
//multiframe parameters end 插入结束
Game_Player.prototype.moveByInput = function() {
if (!this.isMoving() && this.canMove()) {
var direction = Input.dir8
if (direction > 0) {
$gameTemp.clearDestination();
} else if ($gameTemp.isDestinationValid()){
var x = $gameTemp.destinationX();
var y = $gameTemp.destinationY();
direction = this.findDirectionTo(x, y);
}
if (direction > 0) {
if (direction % 2 == 0){
this.moveStraight(direction);
return;
}
if (direction < 5){
this.moveDiagonally(direction + 3 , 2);
} else{
this.moveDiagonally(direction - 3 , 8);
}
}
}
};
var dir8_move_diagonal = Game_Player.prototype.moveDiagonally;
Game_Player.prototype.moveDiagonally = function(horz, vert) {
if (!this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
this.setMovementSuccess(false);
return;
}
if (this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
this.moveStraight(horz);
return;
}
if (this.canPass(this._x, this._y, vert) && !this.canPass(this._x, this._y, horz)){
this.moveStraight(vert);
return;
}
if (!this.canPassDiagonally(this._x, this._y, horz, vert)) {
if (Math.random() > 0.5){
this.setDirection(vert); this.moveStraight(vert)
} else {
this.setDirection(horz); this.moveStraight(horz)
}
return;
}
dir8_move_diagonal.call(this, horz, vert);
if (horz > 5) {
vert > 5 ? this.setDirection(9) : this.setDirection(7);
}
else {
vert > 5 ? this.setDirection(3) : this.setDirection(1);
};
};
Sprite_Character.prototype.characterPatternY = function() {
if (this._character.direction() % 2 == 0){
if (this.dir8_bitmap){ this.bitmap = this.dir4_bitmap; }
return (this._character.direction() - 2) / 2;
} else {
if (this.dir8_bitmap){ this.bitmap = this.dir8_bitmap; }
return parseInt((this._character.direction() + 1) / 3);
}
};
var dir8_set_CharacterBitmap = Sprite_Character.prototype.setCharacterBitmap
Sprite_Character.prototype.setCharacterBitmap = function() {
dir8_set_CharacterBitmap.call(this);
this._isDir8Character = ImageManager.isDir8Character(this._characterName);
if (this._isDir8Character) {
this.dir4_bitmap = this.bitmap;
this.dir8_bitmap = ImageManager.loadCharacter(this._characterName + dir8_affix);
};
};
// multiframe code===============插入的多帧代码部分
var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.initMembers = function() {
_Game_CharacterBase_initMembers.call(this);
this._isMultiFrame = false;
this._frames = [3, 3, 3, 3];
};
var _Game_CharacterBase_maxPattern = Game_CharacterBase.prototype.maxPattern;
Game_CharacterBase.prototype.maxPattern = function() {
if (!this._isMultiFrame) {
return _Game_CharacterBase_maxPattern.call(this);
} else {
//consider diaganol directions 重写定义 考虑八向脚本兼容
return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] : this._frames[(parseInt((this._direction + 1)/ 3))];
}
};
var _Game_CharacterBase_pattern = Game_CharacterBase.prototype.pattern;
Game_CharacterBase.prototype.pattern = function() {
if (!this._isMultiFrame) {
return _Game_CharacterBase_pattern.call(this);
} else {
// return this._pattern < this._frames[this._direction / 2 - 1] ? this._pattern : 0;
// 为了简单暂时只用了第一行的帧数作为上限,稍微改一下应该就好了,懒,而且应该不太会用到不同方向不同帧数
return this._pattern < this._frames[0] ? this._pattern : 0;
}
};
var _Game_CharacterBase_isOriginalPattern = Game_CharacterBase.prototype.isOriginalPattern;
Game_CharacterBase.prototype.isOriginalPattern = function() {
if (!this._isMultiFrame) {
return _Game_CharacterBase_isOriginalPattern.call(this);
} else {
return this.pattern() === 0;
}
};
var _Game_CharacterBase_resetPattern = Game_CharacterBase.prototype.resetPattern;
Game_CharacterBase.prototype.resetPattern = function() {
if (!this._isMultiFrame) {
_Game_CharacterBase_resetPattern.call(this);
} else {
this.setPattern(0);
}
};
var _Game_CharacterBase_setImage = Game_CharacterBase.prototype.setImage;
Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
_Game_CharacterBase_setImage.call(this, characterName, characterIndex);
this._isMultiFrame = ImageManager.isMultiFrameCharacter(characterName);
this._frames = ImageManager.getCharacterFrameCount(characterName);
};
var _Game_CharacterBase_setTileImage = Game_CharacterBase.prototype.setTileImage;
Game_CharacterBase.prototype.setTileImage = function(tileId) {
_Game_CharacterBase_setTileImage.call(this, tileId);
this._isMultiFrame = false;
this._frames = [3, 3, 3, 3];
};
Game_CharacterBase.prototype.isMultiFrame = function() {
return this._isMultiFrame;
};
Game_CharacterBase.prototype.getDirectionFrames = function() {
// return this._frames[this._direction / 2 - 1]; 重新定义帧数 兼容八方向
return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] : this._frames[(parseInt((this._direction + 1)/ 3))];
};
var _Game_Event_initMembers = Game_Event.prototype.initMembers;
Game_Event.prototype.initMembers = function() {
_Game_Event_initMembers.call(this);
if (this._isMultiFrame) {
this._originalPattern = 0;
}
};
var _Sprite_Character_patternWidth = Sprite_Character.prototype.patternWidth;
Sprite_Character.prototype.patternWidth = function() {
if (!this._character.isMultiFrame()) {
return _Sprite_Character_patternWidth.call(this);
} else {
// 除4以还原默认的4*2划分方式
return this.bitmap.width / (4*this._character.getDirectionFrames());
}
};
//doranikofu edit redefine block 原始插件没有重定义的部分,需要按照新定义的行走图动画的帧数去修改index的读取位点,默认是3帧
Sprite_Character.prototype.characterBlockX = function() {
if (this._isBigCharacter) {
return 0;
} else {
var index = this._character.characterIndex();
return (index % 4) * (this._character.getDirectionFrames());
}
};
//==========
})();