Skip to content

Instantly share code, notes, and snippets.

@HimeWorks
Last active January 27, 2016 03:48
Show Gist options
  • Save HimeWorks/25611427511296d906df to your computer and use it in GitHub Desktop.
Save HimeWorks/25611427511296d906df to your computer and use it in GitHub Desktop.
Hime ATB: Fill Rate Modifiers
// Version 2 of Hime ATB, with support for fill rate modifiers.
// Code example for tutorial: http://himeworks.com/2016/01/tutorial-series-hime-atb-customizing-atb-fill-rates/
var Imported = Imported || {} ;
var TH = TH || {};
Imported.TH_ActiveTimeBattle = 1;
TH.ActiveTimeBattle = TH.ActiveTimeBattle || {};
(function ($) {
var TH_GameBattler_initMembers = Game_Battler.prototype.initMembers;
Game_Battler.prototype.initMembers = function() {
TH_GameBattler_initMembers.call(this);
this._atb = 0;
};
var TH_GameBattler_onBattleStart = Game_Battler.prototype.onBattleStart
Game_Battler.prototype.onBattleStart = function() {
TH_GameBattler_onBattleStart.call(this);
this._atb = 0;
};
Game_Battler.prototype.atb = function() {
return this._atb
};
Game_Battler.prototype.atbMax = function() {
return 100;
};
Game_Battler.prototype.atbRate = function() {
return this._atb / this.atbMax();
};
Game_Battler.prototype.atbFillRate = function() {
var rate = this.baseAtbFillRate() + this.agiFillRate();
rate = this.applySlowAtbFillRateModifier(rate);
rate = this.applyHasteAtbFillRateModifier(rate);
return rate;
};
Game_Battler.prototype.baseAtbFillRate = function() {
return 1;
};
Game_Battler.prototype.agiFillRate = function() {
return this.agi / 10;
};
Game_Battler.prototype.isHastened = function() {
return this.isStateAffected(32); // assume 32 is the "slow" state
};
Game_Battler.prototype.isSlowed = function() {
return this.isStateAffected(31); // assume 31 is the "slow" state
};
Game_Battler.prototype.applySlowAtbFillRateModifier = function(rate) {
if (this.isSlowed()) {
return rate / 2;
}
else {
return rate;
}
};
Game_Battler.prototype.applyHasteAtbFillRateModifier = function(rate) {
if (this.isHastened()) {
return rate * 2;
}
else {
return rate;
}
};
Game_Battler.prototype.clearAtb = function() {
this._atb = 0;
};
var TH_GameBattler_canInput = Game_Battler.prototype.canInput;
Game_Battler.prototype.canInput = function() {
return this._atb === this.atbMax() && TH_GameBattler_canInput.call(this);
}
Game_Battler.prototype.updateAtb = function() {
this._atb = Math.min(this._atb + this.atbFillRate(), this.atbMax());
};
Game_Battler.prototype.updateFrame = function() {
this.updateAtb();
};
/***************************************************************************/
Game_Unit.prototype.updateFrame = function() {
var members = this.members();
for (var i = 0; i < members.length; i++) {
members[i].updateFrame();
}
};
/***************************************************************************/
BattleManager.actor = function() {
return this._subject;
};
BattleManager.selectNextCommand = function() {
this._phase = 'turn';
};
BattleManager.selectPreviousCommand = function() {
this._phase = 'turn';
};
BattleManager.startInput = function() {
if (this._subject) {
this._subject.makeActions();
if (this._subject.isActor() && this._subject.canInput()) {
this._subject.setActionState('inputting');
this._phase = 'input'
}
}
else {
this._phase = 'turn'
}
};
BattleManager.updateTurn = function() {
if (this._subject) {
if (this._subject.currentAction()) {
this.processTurn();
}
else {
this.endSubjectTurn();
}
}
else {
this.updateFrame();
}
};
BattleManager.updateFrame = function() {
var members = this.allBattleMembers();
for (var i = 0; i < members.length; i++) {
if (members[i].canInput()) {
this._subject = members[i];
this.startInput();
break;
}
}
if (!this._subject) {
$gameParty.updateFrame();
$gameTroop.updateFrame();
}
}
BattleManager.endSubjectTurn = function() {
this._subject.clearAtb()
this._subject = null;
};
/***************************************************************************/
Window_BattleStatus.prototype.drawActorAtb = function(actor, x, y, width) {
var color1;
var color2;
width = width || 186;
if (actor.isSlowed()) {
color1 = 'rgb(0, 128, 0)';
color2 = 'rgb(0, 224, 0)';
}
else if (actor.isHastened()) {
color1 = 'rgb(128, 0, 255)';
color2 = 'rgb(224, 0, 255)';
}
else {
color1 = this.hpGaugeColor1();
color2 = this.hpGaugeColor2();
}
this.drawGauge(x, y, width, actor.atbRate(), color1, color2);
this.changeTextColor(this.systemColor());
this.drawText("ATB", x, y, 44);
};
Window_BattleStatus.prototype.drawGaugeAreaWithTp = function(rect, actor) {
this.drawActorHp(actor, rect.x + 0, rect.y, 108);
this.drawActorMp(actor, rect.x + 123, rect.y, 96);
this.drawActorAtb(actor, rect.x + 234, rect.y, 96);
};
var TH_WindowBattleStatus_update = Window_BattleStatus.prototype.update;
Window_BattleStatus.prototype.update = function() {
TH_WindowBattleStatus_update.call(this);
this.refresh();
}
})(TH.ActiveTimeBattle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment