//=============================================================================
// Zeros_RidingSystem.js
//=============================================================================
/*:
* @plugindesc
* @author 零殇
*
* @param v
* @desc 版本
* @default 1.0
*
* @help
*
* 上坐骑图片叫做Vehicle.png,放在img/characters下面,目前只适配角色大小和坐骑图大小一样的(标准)图片,否则会出现问题
* 坐骑图片编号:图片第一行0 1 2 3,第二行4 5 6 7
*
* 使用方法:
* 事件.setRidingCharacter('Vehicle',坐骑图片编号,玩家x偏移,玩家y偏移,玩家在坐骑上的高度);
*
* setRidingCharacterFront('Vehicle') //设置坐骑前景(如果有的话可以设置这张覆盖在角色上面的图片)
*
* 比如:
* 上坐骑
* $gamePlayer.setRidingCharacter('Vehicle',0,5,5,20);
* 设置坐骑前景
* $gamePlayer.setRidingCharacterFront('VehicleFrontz')
* 下坐骑
* $gamePlayer.clearRidingCharacter()
*
* 初代版本,可能有bug,欢迎反馈
* 觉得好用可以支持下零殇的游戏,Steam搜索《魔塔地牢》
*/
(function () {
Game_CharacterBase.prototype.setRidingCharacter = function (characterName, idx, charaHeight, charadx, charady) {
this.clearRidingCharacter();
this._ridingCharacterName = characterName;
this._ridingCharacterIndex = idx | 0;
this._charadx = charadx | 0;
this._charady = charady | 0;
this._charaHeight = charaHeight | 0;
this._ridingHeightDelta = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
SceneManager.goto(Scene_Map)
};
Game_CharacterBase.prototype.setRidingCharacterFront = function (characterName) {
this._ridingCharacterNameFront = characterName;
}
// 设置3*4帧的高度波动
Game_CharacterBase.prototype.setRidingHeightDelta = function (arr) {
this._ridingHeightDelta = arr || [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
// 检查角色是否骑坐骑
Game_CharacterBase.prototype.isRiding = function () {
return !!this._ridingCharacterName;
};
// 清除角色的坐骑行走图
Game_CharacterBase.prototype.clearRidingCharacter = function () {
this._ridingCharacterName = '';
this._ridingCharacterNameFront = '';
this._ridingCharacterIndex = 0;
SceneManager.goto(Scene_Map)
};
// 覆盖Sprite_Character的_updateBitmap方法
const _Sprite_Character_updateBitmap = Sprite_Character.prototype.updateBitmap;
Sprite_Character.prototype.updateBitmap = function () {
_Sprite_Character_updateBitmap.call(this);
// 检查角色是否骑坐骑,如果是,则拼接角色和坐骑的行走图
if (this._character.isRiding()) {
const characterName = this._character.characterName();
const ridingCharacterName = this._character._ridingCharacterName;
const ridingCharacterNameFront = this._character._ridingCharacterNameFront;
var characterIndex = this._character.characterIndex();
const index = this._character._ridingCharacterIndex;
const characterBitmap = ImageManager.loadCharacter(characterName);
const ridingCharacterBitmap = ImageManager.loadCharacter(ridingCharacterName);
var bitmapSizeX = parseInt(ridingCharacterBitmap.width / 12);
var bitmapSizeY = parseInt(ridingCharacterBitmap.height / 8);
var chaBitmapSize = 48;
let chax = this._character._charadx;
let chay = this._character._charady;
let drx = 0;
let dry = 0;
if (ridingCharacterName.contains("$")) {
bitmapSizeX = ridingCharacterBitmap.width / 3;
bitmapSizeY = ridingCharacterBitmap.height / 4;
drx = (this.characterPatternX() * bitmapSizeX)
dry = ((this._character.direction() - 2) / 2 * bitmapSizeY)
} else {
drx = (index % 4 * bitmapSizeX * 3 + this.characterPatternX() * bitmapSizeX)
dry = (Math.floor(index / 4) * bitmapSizeY * 4 + (this._character.direction() - 2) / 2 * bitmapSizeY)
}
if (characterName.contains("$")) {
chaBitmapSize = characterBitmap.width / 3;
characterIndex = 0;
}
let dx = (characterIndex % 4 * chaBitmapSize * 3)
let dy = (Math.floor(characterIndex / 4) * chaBitmapSize * 4 + (this._character.direction() - 2) / 2 * chaBitmapSize)
let dirX = (this._character.direction() == 4 ? chax : 0) + (this._character.direction() == 6 ? -chax : 0);
let dirY = (this._character.direction() == 8 ? chay : 0) + (this._character.direction() == 2 ? -chay : 0);
let heightDelta = this._character._ridingHeightDelta[this.characterPatternX() + this.characterPatternY() * 3];
let posX = parseInt((bitmapSizeX - chaBitmapSize) / 2 + dirX + chax);
let posY = parseInt(-heightDelta + (bitmapSizeY - chaBitmapSize) / 2 + dirY + bitmapSizeY - this._character._charaHeight - 8);
console.log("pos", posX, posY)
const combinedBitmap = new Bitmap(bitmapSizeX + chax * 2, bitmapSizeY * 2);
console.log("combinedBitmap", combinedBitmap.width, combinedBitmap.height)
combinedBitmap.blt(ridingCharacterBitmap, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
combinedBitmap.blt(characterBitmap, dx, dy, chaBitmapSize, chaBitmapSize, posX, posY);
if (ridingCharacterNameFront) {
const ridingCharacterBitmapFront = ImageManager.loadCharacter(ridingCharacterNameFront);
combinedBitmap.blt(ridingCharacterBitmapFront, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
}
this.bitmap = combinedBitmap;
}
};
Sprite_Character.prototype.updateCharacterFrame = function () {
const pw = this.patternWidth();
const ph = this.patternHeight();
const sx = (this.characterBlockX() + this.characterPatternX()) * pw;
const sy = (this.characterBlockY() + this.characterPatternY()) * ph;
if (this._character.isRiding()) return;
else this.setFrame(sx, sy, pw, ph);
};
})();