Last active
May 18, 2021 14:28
-
-
Save elleonard/44634ed10aba328ffaff5bf89c5b1cc0 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
(function () { | |
'use strict'; | |
/** | |
* 装飾品の装備タイプID | |
*/ | |
const EQUIP_TYPE_ACCESSORY = 5; | |
/** | |
* 防御力のパラメータID | |
*/ | |
const PARAM_ID_DEF = 3; | |
/** | |
* ダメージ無効の発動率 | |
*/ | |
const DISABLE_DAMAGE_RATE = 5; | |
const _Game_Action_executeDamage = Game_Action.prototype.executeDamage; | |
Game_Action.prototype.executeDamage = function (target, value) { | |
const result = target.result(); | |
result.disableDamageByEquip = value > 0 && this.isHpEffect() && Math.randomInt(100) < target.disableDamageByEquipRate(value); | |
if (result.disableDamageByEquip) { | |
value = 0; | |
/** | |
* ここに装飾品差し替えコード | |
*/ | |
} | |
_Game_Action_executeDamage.call(this, target, value); | |
}; | |
const _Game_ActionResult_clear = Game_ActionResult.prototype.clear; | |
Game_ActionResult.prototype.clear = function () { | |
_Game_ActionResult_clear.call(this); | |
this.disableDamageByEquip = false; | |
}; | |
/** | |
* ダメージ無効の発動率 | |
* @return {number} | |
*/ | |
Game_Battler.prototype.disableDamageByEquipRate = function () { | |
return 0; | |
}; | |
Game_Actor.prototype.disableDamageByEquipRate = function (damageValue) { | |
if (this.accessoryDef() < damageValue) { | |
return 0; | |
} | |
return DISABLE_DAMAGE_RATE; | |
}; | |
/** | |
* 装備している装飾品の防御力の合計 | |
* @return {number} | |
*/ | |
Game_Actor.prototype.accessoryDef = function () { | |
return this.equips() | |
.filter(equip => equip && equip.etypeId === EQUIP_TYPE_ACCESSORY) | |
.reduce((result, equip) => equip.params[PARAM_ID_DEF] + result, 0); | |
}; | |
const _Window_BattleLog_displayHpDamage = Window_BattleLog.prototype.displayHpDamage; | |
Window_BattleLog.prototype.displayHpDamage = function (target) { | |
if (target.result().disableDamageByEquip) { | |
this.addText(`装飾品が壊れて別の装備に変わった!`); | |
} else { | |
_Window_BattleLog_displayHpDamage.call(this, target); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment