Skip to content

Instantly share code, notes, and snippets.

@HimeWorks
Last active January 28, 2016 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HimeWorks/004d095840983b6c18ca to your computer and use it in GitHub Desktop.
Save HimeWorks/004d095840983b6c18ca to your computer and use it in GitHub Desktop.
Hime ATB: Turn Counts
// Version 3 of Hime ATB, with support for turn counts.
// Code example for tutorial: http://himeworks.com/2016/01/tutorial-series-hime-atb-3-implementing-turn-count/
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 0
};
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();
}
};
/***************************************************************************/
var TH_BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function() {
TH_BattleManager_initMembers.call(this);
this._framesPerTurn = 100;
this._frames = 0;
}
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) {
this._frames++;
$gameParty.updateFrame();
$gameTroop.updateFrame();
this.updateTurnCount();
}
}
BattleManager.updateTurnCount = function() {
var rem = this._frames % this._framesPerTurn
if (rem === 0) {
this.startTurn();
}
else if (rem === this._framesPerTurn - 1) {
this.endTurn();
}
}
/* Overwrite for now */
BattleManager.startTurn = function() {
this._phase = 'turn';
$gameTroop.increaseTurn();
$gameParty.requestMotionRefresh();
};
/* Overwrite for now */
BattleManager.endTurn = function() {
this._phase = 'turnEnd'
var battlers = this.allBattleMembers();
for (var i = 0; i < battlers.length; i++) {
battlers[i].onTurnEnd();
this._logWindow.displayAutoAffectedStatus(battlers[i]);
this._logWindow.displayRegeneration(battlers[i]);
}
};
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