Last active
June 19, 2018 11:04
-
-
Save rghavlin/e2b1ccb643f37c4d7dda9a9c298b0953 to your computer and use it in GitHub Desktop.
This is an RPG Maker MV plugin for displaying attack animations only if the attacker scores a hit.
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
//============================================================================= | |
// attackAnimationOnHit.js | |
//============================================================================= | |
/*: | |
* @plugindesc Plays attack animation only if there is a hit. If miss, shows miss popup and plays miss sound. Applies only to physical attacks. | |
* @author robhav | |
* | |
* @help | |
* Plug and play. | |
* -------------------------------------------------------------------------------- | |
* Terms of Use: | |
* Free for commercial and non-commercial projects. | |
* -------------------------------------------------------------------------------- | |
* Version: 1.0 | |
*/ | |
(function() { | |
var animateDisplayActionResults = Window_BattleLog.prototype.displayActionResults; | |
Window_BattleLog.prototype.displayActionResults = function(subject, target) { | |
var action = BattleManager._action; | |
var item = action.item(); | |
animateDisplayActionResults.call(this, subject, target); | |
if (target.result().used) { | |
if (action.isPhysical() && target.result().isHit()) { | |
this.attackAnimationOnHit(subject, target); | |
} | |
} | |
}; | |
Window_BattleLog.prototype.attackAnimationOnHit = function(subject, target) { | |
var action = BattleManager._action; | |
var item = action.item(); | |
if (subject.isActor() || Imported.YEP_BattleEngineCore) { | |
if (!item.animationId || item.animationId < 0) { | |
if (!action.isGuard()) { | |
var animaId1 = subject.attackAnimationId1(); | |
var animaId2 = subject.attackAnimationId2(); | |
} else { | |
var animaId1 = -1; | |
var animaId2 = -1; | |
} | |
} else { | |
var animaId = item.animationId; | |
} | |
if (animaId1 && animaId1 > 0) { | |
target.startAnimation(animaId1); | |
} | |
if (animaId2 && animaId2 > 0) { | |
target.startAnimation(animaId2); | |
} | |
} else { | |
SoundManager.playEnemyAttack(); | |
} | |
}; | |
var startAction = Window_BattleLog.prototype.startAction; | |
Window_BattleLog.prototype.startAction = function(subject, action, targets) { | |
if (!Imported.YEP_BattleEngineCore) { | |
var item = action.item(); | |
this.push('performActionStart', subject, action); | |
this.push('waitForMovement'); | |
this.push('performAction', subject, action); | |
if (!action.isPhysical()) { | |
this.push('showAnimation', subject, targets.clone(), item.animationId); | |
} | |
this.displayAction(subject, item); | |
} | |
}; | |
var showNormalAnimation = Window_BattleLog.prototype.showNormalAnimation; | |
Window_BattleLog.prototype.showNormalAnimation = function(targets, animationId, mirror) { | |
var animation = $dataAnimations[animationId]; | |
var action = BattleManager._action; | |
if (!action.isPhysical()) { | |
if (animation) { | |
var delay = this.animationBaseDelay(); | |
var nextDelay = this.animationNextDelay(); | |
targets.forEach(function(target) { | |
target.startAnimation(animationId, mirror, delay); | |
delay += nextDelay; | |
}); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment