Free_Game / maimai_6_0418 /js /plugins /EasyAction.js
Sageen's picture
Super-squash branch 'main' using huggingface_hub
99b0de1 verified
Raw
History Blame Contribute Delete
12.7 kB
// EasyAction.js Ver.1.1.2
// MIT License (C) 2021 あわやまたな
// http://opensource.org/licenses/mit-license.php
/*:
* @target MZ
* @plugindesc ツクールDS系列の簡単アクションを再現します。
* @author あわやまたな (Awaya_Matana)
* @url https://twitter.com/New_Awayamatana
* @help
* 【スクリプト】
* 移動ルートの設定で以下のスクリプトが使えるようになります。
* this.easySpin(引数)
* その場で一回転します。
* this.easyShake(引数)
* その場で揺れます。
*
* 引数がtrueもしくは未入力だと終わるまでウェイト。falseだとウェイトしません。
* 持続フレーム数は24フレームです。
*
* this.easyJump()
* その場でジャンプします。
* this.easyBackoff()
* その場で後退します。
* this.easyBackstep()
* 向きを変えず一歩後方にジャンプします。
* 持続フレーム数はキャラクターの移動速度によって可変します。
*
* 【プラグインコマンド(MV)】
* easySpin イベントID 真偽値
* その場で一回転します。
* easyShake イベントID 真偽値
* その場で揺れます。
*
* 真偽値がtrueもしくは未入力だと終わるまでウェイト。falseだとウェイトしません。
* 持続フレーム数は24フレームです。
*
* easyJump イベントID 真偽値
* その場でジャンプします。
* easyBackoff イベントID 真偽値
* その場で後退します。
* easyBackstep イベントID 真偽値
* 向きを変えず一歩後方にジャンプします。
*
* 真偽値がtrueもしくは未入力だと終わるまでウェイト。falseだとウェイトしません。
* 持続フレーム数はキャラクターの移動速度によって可変します。
*
* [更新履歴]
* 2021/08/07:Ver.1.0.0 公開
* 2021/08/09:Ver.1.1.0 バグ修正と機能追加。
* 2021/08/10:Ver.1.1.1 ジャンプ時にフォロワーの移動を禁止。
* 2021/08/17:Ver.1.1.2 例外処理追加。
*
* @command EasySpin
* @text 一回転
* @desc その場で一回転します。
*
* @arg eventId
* @text イベントID
* @desc イベントのIDを指定します。
* このイベント:0 主人公:-1
* @default 0
* @type number
* @min -999
*
* @arg wait
* @text 完了までウェイト
* @desc 指定した動作がすべて終了するまで待ちます。
* @default true
* @type boolean
*
* @command EasyShake
* @text 揺れる
* @desc その場で揺れます。
*
* @arg eventId
* @text イベントID
* @desc イベントのIDを指定します。
* このイベント:0 主人公:-1
* @default 0
* @type number
* @min -999
*
* @arg wait
* @text 完了までウェイト
* @desc 指定した動作がすべて終了するまで待ちます。
* @default true
* @type boolean
*
* @command EasyJump
* @text ジャンプ
* @desc その場でジャンプします。
*
* @arg eventId
* @text イベントID
* @desc イベントのIDを指定します。
* このイベント:0 主人公:-1
* @default 0
* @type number
* @min -999
*
* @arg wait
* @text 完了までウェイト
* @desc 指定した動作がすべて終了するまで待ちます。
* @default true
* @type boolean
*
* @command EasyBackoff
* @text 後ずさり
* @desc 一歩後退します。
*
* @arg eventId
* @text イベントID
* @desc イベントのIDを指定します。
* このイベント:0 主人公:-1
* @default 0
* @type number
* @min -999
*
* @arg wait
* @text 完了までウェイト
* @desc 指定した動作がすべて終了するまで待ちます。
* @default true
* @type boolean
*
* @command EasyBackstep
* @text バックステップ
* @desc 向きを変えず一歩後方にジャンプします。
*
* @arg eventId
* @text イベントID
* @desc イベントのIDを指定します。
* このイベント:0 主人公:-1
* @default 0
* @type number
* @min -999
*
* @arg wait
* @text 完了までウェイト
* @desc 指定した動作がすべて終了するまで待ちます。
* @default true
* @type boolean
*
*/
'use strict';
{
//プラグイン名取得。
const script = document.currentScript;
const pluginName = script.src.replace(/^.*\/(.*).js$/, function() {return arguments[1];});
function hasPluginCommonBase(){
for(const i in $plugins) {
if($plugins[i].name === "PluginCommonBase" && $plugins[i].status) return true;
}
return false;
};
//プラグインコマンドの定義。PluginCommonBaseの有無やMZ/MVを判別。
if(hasPluginCommonBase() && Utils.RPGMAKER_NAME === "MZ"){
PluginManagerEx.registerCommand(document.currentScript, "EasySpin", function (args) {
this.character(args.eventId).easySpin(false);
if(args.wait) this.wait(24);
});
PluginManagerEx.registerCommand(document.currentScript, "EasyShake", function (args) {
this.character(args.eventId).easyShake(false);
if(args.wait) this.wait(24);
});
PluginManagerEx.registerCommand(document.currentScript, "EasyJump", function (args) {
const character = this.character(args.eventId);
character.easyJump(false);
if(args.wait) this.wait(character._jumpCount);
});
PluginManagerEx.registerCommand(document.currentScript, "EasyBackoff", function (args) {
const character = this.character(args.eventId);
character.easyBackoff();
if(args.wait) this.wait(1/character.distancePerFrame());
});
PluginManagerEx.registerCommand(document.currentScript, "EasyBackstep", function (args) {
const character = this.character(args.eventId);
character.easyBackstep();
if(args.wait) this.wait(character._jumpCount);
});
}
else if(Utils.RPGMAKER_NAME === "MZ"){
PluginManager.registerCommand(pluginName, "EasySpin", function (args) {
const wait = args.wait==="true";
this.character(+args.eventId).easySpin();
if(wait) this.wait(24);
});
PluginManager.registerCommand(pluginName, "EasyShake", function (args) {
const wait = args.wait==="true";
this.character(+args.eventId).easyShake(false);
if(wait) this.wait(24);
});
PluginManager.registerCommand(pluginName, "EasyJump", function (args) {
const character = this.character(+args.eventId);
const wait = args.wait==="true";
character.easyJump(false);
if(wait) this.wait(character._jumpCount);
});
PluginManager.registerCommand(pluginName, "EasyBackoff", function (args) {
const character = this.character(+args.eventId);
const wait = args.wait==="true";
character.easyBackoff();
if(wait) this.wait(1/character.distancePerFrame());
});
PluginManager.registerCommand(pluginName, "EasyBackstep", function (args) {
const character = this.character(+args.eventId);
const wait = args.wait==="true";
character.easyBackstep();
if(wait) this.wait(character._jumpCount);
});
}
const commandSet = new Set(['easySpin', 'easyShake', 'easyJump', 'easyBackoff', 'easyBackstep']);
const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.apply(this, arguments);
if (commandSet.has(command)) {
const character = this.character(+args[0]);
const wait = args[1]==="true" || args[1]===undefined;
character[command](false);
if (wait) {
switch (command) {
case 'easySpin':
case 'easyShake':
this.wait(24);
break;
case 'easyJump':
case 'easyBackstep':
this.wait(character._jumpCount);
break;
case 'easyBackoff':
this.wait(1/character.distancePerFrame());
break;
}
}
}
};
//簡単アクションを管理する変数を追加。
const _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
_Game_CharacterBase_initMembers.call(this);
this._easySpin = false;
this._easySpinCount = 0;
this._easyShake = false;
this._easyShakeCount = 0;
this._easyActionX = 0;
this._easyActionAngle = 0;
this._easyActionJumping = false;
};
//キャラクターのアップデート処理に簡単アクションのアップデートを追加。
const _Game_CharacterBase_update = Game_CharacterBase.prototype.update;
Game_CharacterBase.prototype.update = function() {
_Game_CharacterBase_update.call(this);
this.updateEasySpin();
this.updateEasyShake();
};
//角度を更新する
Game_CharacterBase.prototype.updateEasySpin = function() {
if (this._easySpin) {
this._easySpinCount++;
this.easySpinSetAngle();
} else if (this._easySpinCount) {
this._easySpinCount = 0;
}
};
//振動を更新する
Game_CharacterBase.prototype.updateEasyShake = function() {
if (this._easyShake) {
this._easyShakeCount++;
this.easyShakeSetOffsets();
}
};
Game_CharacterBase.prototype.easySpinSetAngle = function() {
let angle = 15 * this._easySpinCount;
if(angle >= 360){
angle = 0
this._easySpin = false;
}
this._easyActionAngle = angle;
};
Game_CharacterBase.prototype.easyShakeSetOffsets = function() {
const angle = 37.5 * this._easyShakeCount;
const rad = angle*Math.PI/180
let offset = 4 * Math.sin(rad);
if(angle >= 900){
this._easyShake = false;
this._easyShakeCount = 0;
offset = 0;
}
this._easyActionX = offset;
};
Game_CharacterBase.prototype.easySpin = function (bool = true){
this._easySpin = true;
this._easySpinCount = 0;
if(bool) this._waitCount = 24;
};
Game_CharacterBase.prototype.easyShake = function (bool = true){
this._easyShake = true;
this._easyShakeCount = 0;
if(bool) this._waitCount = 24;
};
Game_CharacterBase.prototype.easyBackoff = function (){
this.moveBackward();
};
Game_CharacterBase.prototype.easyJump = function (){
this._easyActionJumping = true;
this.jump(0,0);
};
Game_CharacterBase.prototype.easyBackstep = function (){
this._easyActionJumping = true;
this.backstep();
};
Game_CharacterBase.prototype.backstep = function (){
const dir = this.direction();
const x = dir===6?-1:dir===4?1:0;
const y = dir===2?-1:dir===8?1:0;
const lastDirectionFix = this.isDirectionFixed();
this.setDirectionFix(true);
this.jump(x,y);
this.setDirectionFix(lastDirectionFix);
};
const _Sprite_Character_update = Sprite_Character.prototype.update;
Sprite_Character.prototype.update = function() {
_Sprite_Character_update.call(this);
this.updateAngle();
};
//EventEffects
const _Sprite_Character_updateAngle = Sprite_Character.prototype.updateAngle;
if (_Sprite_Character_updateAngle) {
Sprite_Character.prototype.updateAngle = function() {
_Sprite_Character_updateAngle.call(this);
if (this._character._easySpin) {
this.anchor.y = 0.5;
this.rotation += this._character._easyActionAngle * Math.PI / 180;
}
};
} else {
Sprite_Character.prototype.updateAngle = function() {
this.rotation = 0;
if (this._character._easySpin) {
this.anchor.y = 0.5;
this.rotation += this._character._easyActionAngle * Math.PI / 180;
} else {
this.anchor.y = 1;
}
};
}
const _Sprite_Character_updatePosition = Sprite_Character.prototype.updatePosition;
Sprite_Character.prototype.updatePosition = function() {
_Sprite_Character_updatePosition.call(this);
if (this._character._easyActionX) {
this.x += this._character._easyActionX;
}
if (this._character._easySpin) {
this.y -= this.height/2;
}
};
const _Game_CharacterBase_updateJump = Game_CharacterBase.prototype.updateJump;
Game_CharacterBase.prototype.updateJump = function() {
_Game_CharacterBase_updateJump.call(this);
if (this._jumpCount === 0) {
this._easyActionJumping = false;
}
};
const _Game_Followers_jumpAll = Game_Followers.prototype.jumpAll;
Game_Followers.prototype.jumpAll = function() {
if (!$gamePlayer._easyActionJumping) {
_Game_Followers_jumpAll.call(this);
}
};
Tilemap.prototype._compareChildOrder = function(a, b) {
if (a.z !== b.z) {
return a.z - b.z;
} else {
const c = a._character && a._character._easySpinCount? -a.height/2 : 0;
const d = b._character && b._character._easySpinCount? -b.height/2 : 0;
if (a.y - c !== b.y - d) {
return a.y - c - b.y + d;
} else {
return a.spriteId - b.spriteId;
}
}
};
}