Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=======================================================================================================================================
- // * DSI-Busts.js
- // -- Last updated: 2/17/18
- // -- Author: dsiver144
- // -- Commission by: Dark Horseman
- //=======================================================================================================================================
- // Change log:
- // + 2/17/18: Finish the plugin!
- // + 2/18/18: Update the script. Fix Change Bust issue. Remake Collapse Special Code. Add centerL, centerR position for pos.
- //=======================================================================================================================================
- /*:
- * @plugindesc Provide an ability for display busts on messages with lots of features similiar to Fire Emblem series. <DSI-Busts>
- * @author dsiver144
- * @help
- * -- Plugin Commands --
- * Create_Bust <FileName> <BustIndex> <Pos> <flipped?> <Active?> <effect>
- * example: Create_Bust Create_Bust Listener 1 left false true fadeIn
- * Create_Bust Create_Bust Custom 1 right true false none
- * Create_Bust Create_Bust Custom 1 centerL true false none
- * Create_Bust Create_Bust Custom 1 centerR true false none
- * NOTE: "centerL" mean position is center but the direction of the bust is left. Same logic for "centerR".
- * -- New Plugin Commands --
- * Set_Collapse_SE <bust_id> <SE Name> <Volume> <Pitch> <Pan> : Set collapse se for bust.
- * Set_Damage_SE <bust_id> <SE Name> <Volume> <Pitch> <Pan> : Set damage se for bust when shaking.
- * Clear_All_Busts : Remember to put this in when end an conversation.
- * -- Message Special Text Codes --
- * \FadeInB[bust_id] : Perform Fade in effect for the bust with specific #bust_id.
- * \FadeOutB[bust_id] : Perform Fade out effect for the bust with specific #bust_id.
- * \ActB[bust_id] : Active bust for talking. Remove Dim Bust effect.
- * \DeactB[bust_id] : Deactive bust. Add Dim Bust effect.
- * \ChB[bust_id,bust_index,delayFrame] : Change bust image. * See demo for more details.
- * \SldB[bust_id,slideX,slideY] : Slide bust. * See demo for more details.
- * \ShkB[bust_id, power] : Shake a bust.
- * \CollapseB[bust_id, duration] : Pefrom collapse effect on bust with duration.
- */
- //=======================================================================================================================================
- (function(){
- 'use strict';
- var DSIVER144 = DSIVER144 || {};
- var params = $plugins.filter(function(p) {return p.description.contains('<DSI-Busts>')})[0].parameters;
- var windowMessageStartMessageAlias = Window_Message.prototype.startMessage;
- Window_Message.prototype.startMessage = function() {
- windowMessageStartMessageAlias.call(this);
- //SceneManager._scene._spriteset.createBusts();
- };
- var SpriteSet_Base_createUpperLayer_alias = Spriteset_Base.prototype.createUpperLayer;
- Spriteset_Base.prototype.createUpperLayer = function() {
- SpriteSet_Base_createUpperLayer_alias.call(this);
- this._bust_sprites = [];
- };
- var alias_convertEscapeCharacters_dsiBust = Window_Base.prototype.convertExtraEscapeCharacters;
- Window_Base.prototype.convertExtraEscapeCharacters = function(text) {
- var new_text = alias_convertEscapeCharacters_dsiBust.call(this, text);
- new_text = new_text.replace(/\x1bFadeInB/gi, '\x1bBFI');
- new_text = new_text.replace(/\x1bFadeOutB/gi, '\x1bBFO');
- new_text = new_text.replace(/\x1bCollapseB/gi, '\x1bBCL');
- new_text = new_text.replace(/\x1bActB/gi, '\x1bBAT');
- new_text = new_text.replace(/\x1bDeactB/gi, '\x1bBDAT');
- new_text = new_text.replace(/\x1bChB/gi, '\x1bCAB');
- new_text = new_text.replace(/\x1bSldB/gi, '\x1bSLB');
- new_text = new_text.replace(/\x1bShkB/gi, '\x1bSHKB');
- return new_text;
- };
- var alias_processEscapeCharacter_dsiBust = Window_Message.prototype.processEscapeCharacter;
- Window_Message.prototype.processEscapeCharacter = function(code, textState) {
- switch (code) {
- case 'BFI':
- var bust_id = this.obtainEscapeParam(textState);
- console.log('Here');
- $gameSystem._bustSettings[bust_id - 1].phase = 'fadeIn';
- break;
- case 'BFO':
- var bust_id = this.obtainEscapeParam(textState);
- $gameSystem._bustSettings[bust_id - 1].phase = 'fadeOut';
- break;
- case 'BCL':
- this.obtainSpecialParamCollapse(textState);
- break;
- case 'BAT':
- var bust_id = this.obtainEscapeParam(textState);
- $gameSystem._bustSettings[bust_id - 1].IsActive = true;
- break;
- case 'BDAT':
- var bust_id = this.obtainEscapeParam(textState);
- $gameSystem._bustSettings[bust_id - 1].IsActive = false;
- break;
- case 'CAB':
- this.obtainSpecialParamChangeBust(textState);
- break;
- case 'SLB':
- this.obtainSpecialParamSliding(textState);
- break;
- case 'SHKB':
- this.obtainSpecialParamShake(textState);
- break;
- }
- alias_processEscapeCharacter_dsiBust.call(this, code, textState);
- };
- Window_Message.prototype.obtainSpecialParamChangeBust = function(textState) {
- var arr = /^\[(\d+),\s*(\d+)\,\s*(\d+)\]/.exec(textState.text.slice(textState.index));
- if (arr) {
- textState.index += arr[0].length;
- var txt = arr[0].slice(1).slice(0, - 1);
- var array = txt.split(",");
- var bust_id = Number(array[0]);
- var new_name = $gameSystem._bustSettings[bust_id - 1].originalName + '_' + array[1];
- $gameSystem._bustSettings[bust_id - 1].filename = new_name;
- $gameSystem._bustSettings[bust_id - 1].changeBust = true;
- $gameSystem._bustSettings[bust_id - 1].changeBustDelay = Number(array[2]);
- } else {
- return '';
- }
- };
- Window_Message.prototype.obtainSpecialParamSliding = function(textState) {
- var arr = /^\[(\d+),(\-*\d+),(\-*\d+)\]/.exec(textState.text.slice(textState.index));
- if (arr) {
- textState.index += arr[0].length;
- var txt = arr[0].slice(1).slice(0, - 1);
- var array = txt.split(",");
- var bust_id = Number(array[0]);
- $gameSystem._bustSettings[bust_id - 1].phase = 'sliding';
- $gameSystem._bustSettings[bust_id - 1].slideX = Number(array[1]);
- $gameSystem._bustSettings[bust_id - 1].slideY = Number(array[2]);
- } else {
- return '';
- }
- };
- Window_Message.prototype.obtainSpecialParamCollapse = function(textState) {
- var arr = /^\[(\d+),(\d+)\]/.exec(textState.text.slice(textState.index));
- if (arr) {
- textState.index += arr[0].length;
- var txt = arr[0].slice(1).slice(0, - 1);
- var array = txt.split(",");
- var bust_id = Number(array[0]);
- $gameSystem._bustSettings[bust_id - 1].phase = 'collapse';
- $gameSystem._bustSettings[bust_id - 1].collapse_duration = Number(array[1]);
- if ($gameSystem._bustSettings[bust_id - 1].collapse_se) {
- AudioManager.playStaticSe($gameSystem._bustSettings[bust_id - 1].collapse_se)
- } else {
- SoundManager.playEnemyCollapse();
- }
- } else {
- return '';
- }
- };
- Window_Message.prototype.obtainSpecialParamShake = function(textState) {
- var arr = /^\[(\d+),(\-*\d+)\]/.exec(textState.text.slice(textState.index));
- if (arr) {
- textState.index += arr[0].length;
- var txt = arr[0].slice(1).slice(0, - 1);
- var array = txt.split(",");
- var bust_id = Number(array[0]);
- $gameSystem._bustSettings[bust_id - 1].phase = 'shake';
- $gameSystem._bustSettings[bust_id - 1].shakeRadius = Number(array[1]);
- if ($gameSystem._bustSettings[bust_id - 1].damage_se) {
- AudioManager.playStaticSe($gameSystem._bustSettings[bust_id - 1].damage_se)
- } else {
- SoundManager.playEnemyDamage();
- }
- } else {
- return '';
- }
- };
- function Sprite_DSIBust() {
- this.initialize.apply(this, arguments);
- };
- var dsiPluginCommandAliasBustSystem = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- if (command === 'Create_Bust') {
- var bust = {};
- bust.originalName = args[0];
- bust.filename = args[0] + '_' + args[1];
- bust.pos = args[2];
- bust.IsFlipped = (args[3] === "true") ? true : false;
- bust.IsActive = (args[4] === "true") ? true : false;
- bust.phase = args[5];
- bust.hide = false;
- bust.slideSpeed = 2;
- bust.hasSprite = false;
- bust.changeBust = true;
- bust.changeBustDelay = 0;
- bust.slideX = 0;
- bust.newX = null;
- bust.newY = null;
- $gameSystem._bustSettings.push(bust);
- SceneManager._scene._spriteset.createBusts();
- //console.log($gameSystem._bustSettings);
- }
- if (command === 'Slide_Bust') {
- var bust_id = parseInt(args[0]);
- $gameSystem._bustSettings[bust_id - 1].slideX = parseInt(args[1]);
- $gameSystem._bustSettings[bust_id - 1].phase = 'sliding';
- }
- if (command === 'Shake_Bust') {
- var bust_id = parseInt(args[0]);
- $gameSystem._bustSettings[bust_id - 1].shakeRadius = parseInt(args[1]);
- $gameSystem._bustSettings[bust_id - 1].phase = 'shake';
- SoundManager.playEnemyDamage();
- }
- if (command === 'Set_Collapse_SE') {
- var bust_id = parseInt(args[0]);
- var se = {
- name : args[1],
- volume : parseInt(args[2]),
- pitch : parseInt(args[3]),
- pan : parseInt(args[4])
- }
- $gameSystem._bustSettings[bust_id - 1].collapse_se = se;
- }
- if (command === 'Set_Damage_SE') {
- var bust_id = parseInt(args[0]);
- var se = {
- name : args[1],
- volume : parseInt(args[2]),
- pitch : parseInt(args[3]),
- pan : parseInt(args[4])
- }
- $gameSystem._bustSettings[bust_id - 1].damage_se = se;
- }
- if (command === 'Clear_All_Busts') {
- $gameSystem._bustSettings.forEach(function(bust){
- bust.phase = 'fadeOut';
- bust.delete = true;
- });
- $gameSystem._bustSettings.splice(0, $gameSystem._bustSettings.length); // Clear Bust Settings Array
- }
- dsiPluginCommandAliasBustSystem.call(this, command, args);
- }
- Spriteset_Base.prototype.createBusts = function() {
- for (var i = 0; i < $gameSystem._bustSettings.length; i++) {
- var bust = $gameSystem._bustSettings[i];
- if (bust.hasSprite) continue;
- var new_sprite = new Sprite_DSIBust(bust);
- bust.hasSprite = true;
- this._bust_sprites.push(new_sprite);
- this.addChild(new_sprite);
- }
- }
- var dsiGameSystemInitializeBustInfo = Game_System.prototype.initialize;
- Game_System.prototype.initialize = function() {
- dsiGameSystemInitializeBustInfo.call(this);
- this._bustSettings = [];
- };
- Sprite_DSIBust.prototype = Object.create(Sprite.prototype);
- Sprite_DSIBust.prototype.constructor = Sprite_DSIBust;
- Sprite_DSIBust.prototype.initialize = function(bust) {
- Sprite.prototype.initialize.call(this);
- this._bust = bust;
- if (bust.IsFlipped) {
- this.anchor.x = 1;
- this.scale.x *= -1;
- }
- this.moveX = 0;
- this.opacity = 0;
- this.update();
- this.hideFlag = false;
- this.targetX = null;
- this.targetY = null;
- };
- Sprite_DSIBust.prototype.loadBustBitmap = function() {
- var name = this._bust.filename;
- var img = ImageManager.loadPicture(name);
- if (img.isReady()) {
- this.y = Graphics._height - SceneManager._scene._messageWindow.windowHeight() - img.height;
- if (this._bust.newY) this.y = this._bust.newY;
- if (this._bust.pos === 'left') {
- this.x = 10;
- if (this._bust.newX) this.x = this._bust.newX;
- }
- if (this._bust.pos === 'right') {
- this.x = Graphics._width - img.width - 10;
- if (this._bust.newX) this.x = this._bust.newX;
- }
- if (this._bust.pos === 'centerL') {
- this.x = (Graphics._width - img.width) * 0.5;
- if (this._bust.newX) this.x = this._bust.newX;
- }
- if (this._bust.pos === 'centerR') {
- this.x = (Graphics._width - img.width) * 0.5;
- if (this._bust.newX) this.x = this._bust.newX;
- }
- this.bitmap = img;
- this._bust.changeBust = false;
- }
- };
- Sprite_DSIBust.prototype.update = function() {
- Sprite.prototype.update.call(this);
- this.update_bust();
- };
- Sprite_DSIBust.prototype.update_bust = function() {
- if (this.hideFlag) {
- return;
- }
- if (this._bust.changeBust) {
- if (this._bust.changeBustDelay > 0) this._bust.changeBustDelay--;
- if (this._bust.changeBustDelay === 0) this.loadBustBitmap();
- }
- if (!this._bust.IsActive) {
- this.setColorTone([-90,-90,-90,60]);
- } else {
- this.setColorTone([0,0,0,0]);
- }
- // Fade In
- if (this._bust.phase === 'fadeIn') {
- if (this.opacity < 255) {
- this.opacity += 10;
- }
- if (this.moveX < 30) {
- this.x += (this._bust.pos === 'left' || this._bust.pos === 'centerR') ? 1 : -1;
- this.moveX += this._bust.slideSpeed;
- }
- if (this.moveX >= 30 && this.opacity === 255) {
- this.moveX = 0;
- this._bust.newY = this.y;
- this._bust.newX = this.x;
- this._bust.phase = 'none';
- }
- }
- // Fade Out
- if (this._bust.phase === 'fadeOut') {
- if (this.opacity > 0) {
- this.opacity -= 10;
- }
- if (this.moveX <= 30) {
- this.x += (this._bust.pos === 'left' || this._bust.pos === 'centerR') ? -1 : 1;
- this.moveX += this._bust.slideSpeed;
- }
- if (this.moveX >= 30 && this.opacity === 0) {
- this.moveX = 0;
- this._bust.newY = this.y;
- this._bust.newX = this.x;
- this._bust.phase = 'none';
- if (this._bust.delete) {
- this.hideFlag = true;
- }
- }
- }
- // Collapse
- if (this._bust.phase === 'collapse') {
- this.blendMode = Graphics.BLEND_ADD;
- console.log('Colappse');
- this.setBlendColor([255, 128, 128, 128]);
- if (this.opacity > 0) {
- this.opacity -= 255 / this._bust.collapse_duration;
- }
- if (this.opacity === 0) {
- this._bust.phase = 'none';
- this.hideFlag = true;
- }
- }
- // Sliding
- if (this._bust.phase === 'sliding') {
- if (!this.targetX) {
- this.targetX = this.x + this._bust.slideX * ((this._bust.pos === 'left' || this._bust.pos === 'centerR') ? 1 : -1);
- this._bust.newX = this.targetX;
- }
- if (!this.targetY) {
- this.targetY = this.y + this._bust.slideY
- this._bust.newY = this.targetY;
- }
- this.x += (this.targetX - this.x) / 10;
- this.y += (this.targetY - this.y) / 10;
- if (Math.abs(this.x - this.targetX) <= 0.01 && Math.abs(this.y - this.targetY) <= 0.01) {
- this._bust.newY = this.y;
- this._bust.newX = this.x;
- this._bust.phase = 'none';
- this._bust.slideY = 0;
- this.targetY = null;
- this._bust.slideX = 0;
- this.targetX = null;
- return;
- }
- }
- // Damage Shake
- if (this._bust.phase === 'shake') {
- if (this._bust.shakeRadius > 0) {
- if (!this._bust.originX) {
- this._bust.originX = this.x;
- }
- this.x = this._bust.originX + Math.cos(Graphics.frameCount) * this._bust.shakeRadius;
- this._bust.shakeRadius -= 0.5
- if (this._bust.shakeRadius <= 0) {
- this._bust.phase = 'none';
- this.x = this._bust.originX;
- this._bust.originX = null;
- }
- }
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement