//-----------------------------------------------------------------------------
// Game_Followers
//
// The wrapper class for a follower array.
/**
* The wrapper class for a follower array.
*
* @class
*/
function Game_Followers() {
this.initialize(...arguments);
}
/**
* Initialize followers settings
*/
Game_Followers.prototype.initialize = function() {
this._visible = $dataSystem.optFollowers;
this._gathering = false;
this._data = [];
this.setup();
};
/**
* Set up the followers
*/
Game_Followers.prototype.setup = function() {
this._data = [];
for (let i = 1; i < $gameParty.maxBattleMembers(); i++) {
this._data.push(new Game_Follower(i));
}
};
/**
* Check if followers are visible
*
* @return {boolean} True if visible
*/
Game_Followers.prototype.isVisible = function() {
return this._visible;
};
/**
* Show the followers
*/
Game_Followers.prototype.show = function() {
this._visible = true;
};
/**
* Hide the followers
*/
Game_Followers.prototype.hide = function() {
this._visible = false;
};
/**
* Returns a clone of the follower array
*
* @return {Array} Clone of the follower data array
*/
Game_Followers.prototype.data = function() {
return this._data.clone();
};
/**
* Returns a reversed clone of the follower array
*
* @return {Array} Reversed clone of the follower data array
*/
Game_Followers.prototype.reverseData = function() {
return this._data.clone().reverse();
};
/**
* Get the follower at a given index
*
* @param {number} index - The index of the follower
* @return {Game_Follower} Follower object at the given index
*/
Game_Followers.prototype.follower = function(index) {
return this._data[index];
};
/**
* Refresh followers
*/
Game_Followers.prototype.refresh = function() {
for (const follower of this._data) {
follower.refresh();
}
};
/**
* Update followers
*/
Game_Followers.prototype.update = function() {
if (this.areGathering()) {
if (!this.areMoving()) {
this.updateMove();
}
if (this.areGathered()) {
this._gathering = false;
}
}
for (const follower of this._data) {
follower.update();
}
};
/**
* Update follower movement
*/
Game_Followers.prototype.updateMove = function() {
for (let i = this._data.length - 1; i >= 0; i--) {
const precedingCharacter = i > 0 ? this._data[i - 1] : $gamePlayer;
this._data[i].chaseCharacter(precedingCharacter);
}
};
/**
* Jump all followers (for use when player jumps)
*/
Game_Followers.prototype.jumpAll = function() {
if ($gamePlayer.isJumping()) {
for (const follower of this._data) {
const sx = $gamePlayer.deltaXFrom(follower.x);
const sy = $gamePlayer.deltaYFrom(follower.y);
follower.jump(sx, sy);
}
}
};
/**
* Sync the followers
*
* @param {number} x - The x coordinate to synchronize at
* @param {number} y - The y coordinate to synchronize at
* @param {number} d - The direction to face
*/
Game_Followers.prototype.synchronize = function(x, y, d) {
for (const follower of this._data) {
follower.locate(x, y);
follower.setDirection(d);
}
};
/**
* Gathers the followers
*/
Game_Followers.prototype.gather = function() {
this._gathering = true;
};
/**
* Check if followers are gathering
*
* @return {boolean} True if gathering
*/
Game_Followers.prototype.areGathering = function() {
return this._gathering;
};
/**
* Get visible followers
*
* @return {Game_Follower[]} Followers that are visible
*/
Game_Followers.prototype.visibleFollowers = function() {
return this._data.filter(follower => follower.isVisible());
};
/**
* Check if any follower is moving
*
* @return {boolean} True if moving
*/
Game_Followers.prototype.areMoving = function() {
return this.visibleFollowers().some(follower => follower.isMoving());
};
/**
* Check if followers are gathered
*
* @return {boolean} True if gathered
*/
Game_Followers.prototype.areGathered = function() {
return this.visibleFollowers().every(follower => follower.isGathered());
};
/**
* Check follower collision at the given coordinates
*
* @param {number} x - The x coordinate to check
* @param {number} y - The y coordinate to check
* @return {boolean} True if collided
*/
Game_Followers.prototype.isSomeoneCollided = function(x, y) {
return this.visibleFollowers().some(follower => follower.pos(x, y));
};