Last active
June 18, 2022 06:37
-
-
Save elleonard/6694f6e87bfcaeb37c0288c42a9abc8c to your computer and use it in GitHub Desktop.
倉庫番サンプルプラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
'use strict'; | |
const pluginName = document.currentScript.src.replace(/^.*\/(.*).js$/, function () { | |
return arguments[1]; | |
}); | |
const BOXY_BOY_MODE_SWITCH = 41; | |
/** | |
* @param {Game_Temp.prototype} gameTemp | |
*/ | |
function Game_Temp_BoxyBoyMixIn(gameTemp) { | |
/** | |
* @return {boolean} | |
*/ | |
gameTemp.isBoxyBoyMode = function () { | |
return $gameSwitches.value(BOXY_BOY_MODE_SWITCH); | |
}; | |
} | |
Game_Temp_BoxyBoyMixIn(Game_Temp.prototype); | |
/** | |
* @param {Game_CharacterBase.prototype} gameCharacterBase | |
*/ | |
function Game_CharacterBase_BoxyBoyMixIn(gameCharacterBase) { | |
/** | |
* @return {boolean} | |
*/ | |
gameCharacterBase.canMoveBox = function () { | |
return false; | |
}; | |
const _isCollidedWithEvents = gameCharacterBase.isCollidedWithEvents; | |
gameCharacterBase.isCollidedWithEvents = function (x, y) { | |
/** | |
* 倉庫番モードの際、箱はイベントとしてではなく箱として扱う | |
*/ | |
return _isCollidedWithEvents.call(this, x, y) && !this.isCollidedWithBox(x, y); | |
}; | |
/** | |
* @param {number} x | |
* @param {number} y | |
* @return {boolean} | |
*/ | |
gameCharacterBase.isCollidedWithBox = function (x, y) { | |
return !!this.collidedBox(x, y); | |
}; | |
/** | |
* 指定座標にいる自身以外の箱をひとつ返す | |
* 複数イベントが重なっているケースは考慮していない | |
* @param {number} x | |
* @param {number} y | |
* @return {Game_Event|null} | |
*/ | |
gameCharacterBase.collidedBox = function (x, y) { | |
return $gameTemp.isBoxyBoyMode() ? $gameMap.eventsXyNt(x, y) | |
.find(event => event !== this && event.isNormalPriority() && event.isBox()) : null; | |
}; | |
const _canPass = gameCharacterBase.canPass; | |
gameCharacterBase.canPass = function (x, y, d) { | |
const canPass = _canPass.call(this, x, y, d); | |
const x2 = $gameMap.roundXWithDirection(x, d); | |
const y2 = $gameMap.roundYWithDirection(y, d); | |
const collidedBox = this.collidedBox(x2, y2); | |
if (collidedBox && this.canMoveBox()) { | |
/** | |
* 押そうとしている箱が動かせるか | |
*/ | |
return collidedBox.canPass(x2, y2, d); | |
} | |
return canPass; | |
}; | |
const _moveStraight = gameCharacterBase.moveStraight; | |
gameCharacterBase.moveStraight = function (d) { | |
_moveStraight.call(this, d); | |
/** | |
* 直進した際、押した箱も直進する | |
*/ | |
const collidedBox = this.collidedBox(this.x, this.y); | |
if (this.isMovementSucceeded() && collidedBox) { | |
collidedBox.moveStraight(d); | |
} | |
}; | |
} | |
Game_CharacterBase_BoxyBoyMixIn(Game_CharacterBase.prototype); | |
/** | |
* @param {Game_Player.prototype} gamePlayer | |
*/ | |
function Game_Player_BoxyBoyMixIn(gamePlayer) { | |
/** | |
* @return {boolean} | |
*/ | |
gamePlayer.canMoveBox = function () { | |
return true; | |
}; | |
} | |
Game_Player_BoxyBoyMixIn(Game_Player.prototype); | |
/** | |
* @param {Game_Event.prototype} gameEvent | |
*/ | |
function Game_Event_BoxyBoyMixIn(gameEvent) { | |
/** | |
* @return {boolean} | |
*/ | |
gameEvent.canMoveBox = function () { | |
return this.isBox(); | |
}; | |
/** | |
* @return {boolean} | |
*/ | |
gameEvent.isBox = function () { | |
return this.event() && this.event().meta && this.event().meta.box; | |
}; | |
} | |
Game_Event_BoxyBoyMixIn(Game_Event.prototype); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment