//-----------------------------------------------------------------------------
// Spriteset_Battle
//
// The set of sprites on the battle screen.
/**
* The set of sprites on the battle screen.
*
* @class
* @extends Spriteset_Base
*/
function Spriteset_Battle() {
this.initialize(...arguments);
}
Spriteset_Battle.prototype = Object.create(Spriteset_Base.prototype);
Spriteset_Battle.prototype.constructor = Spriteset_Battle;
Spriteset_Battle.prototype.initialize = function() {
Spriteset_Base.prototype.initialize.call(this);
this._battlebackLocated = false;
};
Spriteset_Battle.prototype.loadSystemImages = function() {
Spriteset_Base.prototype.loadSystemImages.call(this);
ImageManager.loadSystem("Shadow2");
ImageManager.loadSystem("Weapons1");
ImageManager.loadSystem("Weapons2");
ImageManager.loadSystem("Weapons3");
};
Spriteset_Battle.prototype.createLowerLayer = function() {
Spriteset_Base.prototype.createLowerLayer.call(this);
this.createBackground();
this.createBattleback();
this.createBattleField();
this.createEnemies();
this.createActors();
};
/**
* Creates the sprites that make up the background
*/
Spriteset_Battle.prototype.createBackground = function() {
this._backgroundFilter = new PIXI.filters.BlurFilter();
this._backgroundSprite = new Sprite();
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this._backgroundSprite.filters = [this._backgroundFilter];
this._baseSprite.addChild(this._backgroundSprite);
};
/**
* Creates the battleback sprites
*/
Spriteset_Battle.prototype.createBattleback = function() {
this._back1Sprite = new Sprite_Battleback(0);
this._back2Sprite = new Sprite_Battleback(1);
this._baseSprite.addChild(this._back1Sprite);
this._baseSprite.addChild(this._back2Sprite);
};
/**
* Creates the battlefield sprite
*/
Spriteset_Battle.prototype.createBattleField = function() {
const width = Graphics.boxWidth;
const height = Graphics.boxHeight;
const x = (Graphics.width - width) / 2;
const y = (Graphics.height - height) / 2;
this._battleField = new Sprite();
this._battleField.setFrame(0, 0, width, height);
this._battleField.x = x;
this._battleField.y = y - this.battleFieldOffsetY();
this._baseSprite.addChild(this._battleField);
this._effectsContainer = this._battleField;
};
/**
* Get the offset for the Y coordinate of the battlefield
*
* @return {number} The offset
*/
Spriteset_Battle.prototype.battleFieldOffsetY = function() {
return 24;
};
Spriteset_Battle.prototype.update = function() {
Spriteset_Base.prototype.update.call(this);
this.updateActors();
this.updateBattleback();
this.updateAnimations();
};
/**
* Updates the battleback sprites
*/
Spriteset_Battle.prototype.updateBattleback = function() {
if (!this._battlebackLocated) {
this._back1Sprite.adjustPosition();
this._back2Sprite.adjustPosition();
this._battlebackLocated = true;
}
};
/**
* Creates the enemy sprites
*/
Spriteset_Battle.prototype.createEnemies = function() {
const enemies = $gameTroop.members();
const sprites = [];
for (const enemy of enemies) {
sprites.push(new Sprite_Enemy(enemy));
}
sprites.sort(this.compareEnemySprite.bind(this));
for (const sprite of sprites) {
this._battleField.addChild(sprite);
}
this._enemySprites = sprites;
};
/**
* Compare two enemy sprites for sorting purposes
*
* @param {Sprite_Enemy} a - The first sprite to compare
* @param {Sprite_Enemy} b - The second sprite to compare
* @return {number} The comparison result
*/
Spriteset_Battle.prototype.compareEnemySprite = function(a, b) {
if (a.y !== b.y) {
return a.y - b.y;
} else {
return b.spriteId - a.spriteId;
}
};
/**
* Creates the actor sprites
*/
Spriteset_Battle.prototype.createActors = function() {
this._actorSprites = [];
if ($gameSystem.isSideView()) {
for (let i = 0; i < $gameParty.maxBattleMembers(); i++) {
const sprite = new Sprite_Actor();
this._actorSprites.push(sprite);
this._battleField.addChild(sprite);
}
}
};
/**
* Updates the actor sprites
*/
Spriteset_Battle.prototype.updateActors = function() {
const members = $gameParty.battleMembers();
for (let i = 0; i < this._actorSprites.length; i++) {
this._actorSprites[i].setBattler(members[i]);
}
};
/**
* Finds a target sprite by battler
*
* @param {Game_Battler} target - The battler to check against
* @return {Sprite_Battler} The sprite that matched the battler
*/
Spriteset_Battle.prototype.findTargetSprite = function(target) {
return this.battlerSprites().find(sprite => sprite.checkBattler(target));
};
/**
* Get all of the battler sprites, enemy + actor
*
* @return {Array} All battler sprites
*/
Spriteset_Battle.prototype.battlerSprites = function() {
return this._enemySprites.concat(this._actorSprites);
};
/**
* Check if any battler sprites are effecting
*
* @return {boolean} True if any battler sprites are effecting
*/
Spriteset_Battle.prototype.isEffecting = function() {
return this.battlerSprites().some(sprite => sprite.isEffecting());
};
/**
* Check if any battler sprites are moving
*
* @return {boolean} True if any battler sprites are moving
*/
Spriteset_Battle.prototype.isAnyoneMoving = function() {
return this.battlerSprites().some(sprite => sprite.isMoving());
};
/**
* Check if the spriteset is busy
*
* @return {boolean} True if anyone is moving or an animation is playing
*/
Spriteset_Battle.prototype.isBusy = function() {
return this.isAnimationPlaying() || this.isAnyoneMoving();
};