jeneeus

ChangeGraphic

Oct 27th, 2015
3,570
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==============================================================================
  2. // ** Change Graphic
  3. // by: Jeneeus Guruman
  4. //------------------------------------------------------------------------------
  5.  
  6. var Imported = Imported || {};
  7. var Jene = Jene || {};
  8.  
  9. /*:
  10.  * @plugindesc Change Graphic v1.2.2
  11.  * @author Jeneeus Guruman
  12.  *
  13.  * @param changeDefaultGraphic
  14.  * @desc Enable changes of default graphics if changed using "Change Actor Graphic" command.
  15.  * @default true
  16.  *
  17.  * @param changeDefaultGraphicSwitch
  18.  * @desc Switch to activate default graphic changes. 0 value makes it always enabled.
  19.  * @default 0
  20.  *
  21.  * @param priorityEquip
  22.  * @desc The order of the equipment to be applied on changes,
  23.  * separated by spaces and arranged by "Equipment Types".
  24.  * @default 1 5 4 3 2
  25.  *
  26.  * @help
  27.  *
  28.  *     This plugin allows to change sprite and face graphics depending on
  29.  *   the state, armor, weapon, and class.
  30.  *  
  31.  *   How to use:
  32.  *
  33.  *     To use this, you need to put the following notetags:
  34.  *
  35.  *       To change sprites:
  36.  *
  37.  *       <ge: actor_id, sprite_name, sprite_index>
  38.  *
  39.  *       actor_id: The ID of the actor to be change graphics.
  40.  *       sprite_name: The filename of the sprite graphic to be placed.
  41.  *       sprite_index: The index of the sprite graphic to be placed.
  42.  *
  43.  *       To change face:
  44.  *
  45.  *       <fe: actor_id, face_name, face_index>
  46.  *
  47.  *       actor_id: The ID of the actor to be change face.
  48.  *       face_name: The filename of the face graphic to be placed.
  49.  *       face_index: The index of the face graphic to be placed.
  50.  *
  51.  *       To change sideview sprites:
  52.  *
  53.  *       <sve: [-]battler_id, sideview_name>
  54.  *
  55.  *       battler_id: The ID of the actor to be change sideview graphics.
  56.  *       Placing a negative sign will call the enemy instead.
  57.  *       sideview_name: The filename of the sideview graphic to be placed.
  58.  *
  59.  *       To change weapon animations:
  60.  *
  61.  *       <ae: battler_id, animationId, weaponSlot>
  62.  *
  63.  *       battler_id: The ID of the battler to be change sideview graphics.
  64.  *       Putting 0 instead will affect all actors inflicted.
  65.  *       animationId: The ID of the animation.
  66.  *       weaponSlot: The slot in the weapon to be changed the animation.
  67.  *
  68.  *       Notes:
  69.  *       * If you use a single-sprite file (files with $ at the beginning),
  70.  *       you may also add it but the index must be 0.
  71.  *       * If the notetag is not fit in a single line, shorten the filename
  72.  *       or use the other method below.
  73.  *       * You may put many notetags for the different actors at the
  74.  *       same equipment.
  75.  *       * The priority on the changes in graphics starting from the highest
  76.  *       priority are states, equipment, and classes.
  77.  *       * The priority in "priorityEquip" is arranged from the highest
  78.  *       priority to the lowest.
  79.  *       * "ae" tag only works on states.
  80.  *       * The actor sideview battler image to be changed must be in
  81.  *       "sv_actors" folder while the enemy must be in "sv_enemies".
  82.  *
  83.  *   Changelog:
  84.  *
  85.  *     * v1.2.2: Now compatible with Yanfly Item Core.
  86.  *     * v1.2.1: Will now load all possible sideview battler changes at the
  87.  *     start of the battle to remove the blinking bug.
  88.  *     * v1.2.0: Now enemies can be change their battler images.
  89.  *     * v1.1.0: Added "ae" tag to also change weapon animations depending on
  90.  *     the actor's state.
  91.  */
  92.  
  93. parameters = PluginManager.parameters('ChangeGraphic');
  94.  
  95. Jene.changeDefaultGraphic = Boolean(parameters['changeDefaultGraphic']);
  96. Jene.changeDefaultGraphicSwitch = Number(parameters['changeDefaultGraphicSwitch']);
  97. Jene.priorityEquip = String(parameters['priorityEquip']);
  98.  
  99. if (Imported.YEP_ItemCore) {
  100.  
  101. Jene.YEPItemManagerSetNewINdependentItem = ItemManager.setNewIndependentItem;
  102.  
  103. ItemManager.setNewIndependentItem = function(baseItem, newItem) {
  104.     Jene.YEPItemManagerSetNewINdependentItem.call(this, baseItem, newItem);
  105.     newItem.note = baseItem.note;
  106. };
  107.  
  108. }
  109.  
  110. Game_Actor.prototype.getAnimationChange = function(item, slotId) {
  111.     var re = /<ae[:]?\s*(\d+)\s*[,]?\s*(\d+)?\s*[,]?\s*(\d+)?\s*>/gi;
  112.     do {
  113.         var match = re.exec(item.note);
  114.         if (match && (match[1] == this._actorId || match[1] == 0) && match[3] == slotId) {
  115.           return match[2];
  116.         }
  117.     } while (match);
  118.     return 0;
  119. };
  120.  
  121. Jene.gameActorsAttackAnimationId1 = Game_Actor.prototype.attackAnimationId1;
  122.  
  123. Game_Actor.prototype.attackAnimationId1 = function() {
  124.     var weapons = this.weapons();
  125.     var states = this.states();
  126.     for (var i = 0; i < states.length; i++) {
  127.       var animationId = this.getAnimationChange(states[i], 1);
  128.       if (animationId) {
  129.         return animationId;
  130.       }
  131.     }
  132.     return Jene.gameActorsAttackAnimationId1.call(this);
  133. };
  134.  
  135. Jene.gameActorsAttackAnimationId2 = Game_Actor.prototype.attackAnimationId2;
  136.  
  137. Game_Actor.prototype.attackAnimationId2 = function() {
  138.     var weapons = this.weapons();
  139.     var states = this.states();
  140.     states.reverse();
  141.     for (var i = 0; i < states.length; i++) {
  142.       var animationId = this.getAnimationChange(states[i], 2);
  143.       if (animationId) {
  144.         return animationId;
  145.       }
  146.     }
  147.     return Jene.gameActorsAttackAnimationId2.call(this);
  148. };
  149.  
  150. Jene.gameActorInitMembers = Game_Actor.prototype.initMembers;
  151.  
  152. Game_Actor.prototype.initMembers = function() {
  153.   Jene.gameActorInitMembers.call(this);
  154.   this._defaultCharacterName = '';
  155.   this._defaultCharacterIndex = 0
  156.   this._defaultFaceName = '';
  157.   this._defaultFaceIndex = 0;
  158.   this._defaultBattlerName = '';
  159. };
  160.  
  161. Jene.gameActorInitImages = Game_Actor.prototype.initImages;
  162.  
  163. Game_Actor.prototype.initImages = function() {
  164.     Jene.gameActorInitImages.call(this);
  165.     var actor = this.actor();
  166.     this._defaultCharacterName = actor.characterName;
  167.     this._defaultCharacterIndex = actor.characterIndex;
  168.     this._defaultFaceName = actor.faceName;
  169.     this._defaultFaceIndex = actor.faceIndex;
  170.     this._defaultBattlerName = actor.battlerName;
  171. };
  172.  
  173. Jene.gameActorChangeEquip = Game_Actor.prototype.changeEquip;
  174.  
  175. Game_Actor.prototype.changeEquip = function(slotId, item) {
  176.     Jene.gameActorChangeEquip.call(this, slotId, item);
  177.     this.refreshGraphicEquip();
  178.     $gamePlayer.refresh();
  179. };
  180.  
  181. Jene.gameActorChangeClass = Game_Actor.prototype.changeClass;
  182.  
  183. Game_Actor.prototype.changeClass = function(classId, keepExp) {
  184.     Jene.gameActorChangeClass.call(this, classId, keepExp);
  185.     this.refreshGraphicEquip();
  186.     $gamePlayer.refresh();
  187. };
  188.  
  189. Jene.gameActorAddNewState = Game_Actor.prototype.addNewState;
  190.  
  191. Game_Actor.prototype.addNewState = function(stateId) {
  192.     Jene.gameActorAddNewState.call(this, stateId);
  193.     this.refreshGraphicEquip();
  194.     $gamePlayer.refresh();
  195. };
  196.  
  197. Jene.gameActorEraseState = Game_Actor.prototype.eraseState;
  198.  
  199. Game_Actor.prototype.eraseState = function(stateId) {
  200.     Jene.gameActorEraseState.call(this, stateId);
  201.     this.refreshGraphicEquip();
  202.     $gamePlayer.refresh();
  203. };
  204.  
  205. Jene.gameActorClearStates = Game_Actor.prototype.clearStates;
  206.  
  207. Game_Actor.prototype.clearStates = function() {
  208.     Jene.gameActorClearStates.call(this);
  209.     this.refreshGraphicEquip();
  210.     $gamePlayer.refresh();
  211. };
  212.  
  213. Game_Actor.prototype.setDefaultCharacterImage = function(characterName, characterIndex) {
  214.     this._defaultCharacterName = characterName;
  215.     this._defaultCharacterIndex = characterIndex;
  216. };
  217.  
  218. Game_Actor.prototype.setDefaultFaceImage = function(faceName, faceIndex) {
  219.     this._defaultFaceName = faceName;
  220.     this._defaultFaceIndex = faceIndex;
  221. };
  222.  
  223. Game_Actor.prototype.setDefaultBattlerImage = function(battlerName) {
  224.     this._defaultBattlerName = battlerName;
  225. };
  226.  
  227. Game_Actor.prototype.getCharacterChange = function(item) {
  228.     var re = /<ge[:]?\s*(\d+)\s*[,]?\s*([$]*\w+)?\s*[,]?\s*(\d+)\s*>/gi;
  229.     do {
  230.         var match = re.exec(item.note);
  231.         if (match && match[1] == this._actorId) {
  232.           return {name: match[2], index: match[3]};
  233.         }
  234.     } while (match);
  235.     return;
  236. };
  237.  
  238. Game_Actor.prototype.getFaceChange = function(item) {
  239.     var re = /<fe[:]?\s*(\d+)\s*[,]?\s*([$]*\w+)?\s*[,]?\s*(\d+)\s*>/gi;
  240.     do {
  241.         var match = re.exec(item.note);
  242.         if (match && match[1] == this._actorId) {
  243.           return {name: match[2], index: match[3]};
  244.         }
  245.     } while (match);
  246.     return;
  247. };
  248.  
  249. Game_Actor.prototype.getBattlerChange = function(item) {
  250.     var re = /<sve[:]?\s*(\d+)\s*[,]?\s*([$]*\w+)?\s*>/gi;
  251.     do {
  252.         var match = re.exec(item.note);
  253.         if (match && match[1] == this._actorId) {
  254.           return match[2];
  255.         }
  256.     } while (match);
  257.     return;
  258. };
  259.  
  260. Game_Actor.prototype.graphicEquip = function(item) {
  261.     if (this.getCharacterChange(item)) {
  262.       this.setCharacterImage(this.getCharacterChange(item).name, this.getCharacterChange(item).index);
  263.     }
  264. };
  265.  
  266. Game_Actor.prototype.faceEquip = function(item) {
  267.     if (this.getFaceChange(item)) {
  268.       this.setFaceImage(this.getFaceChange(item).name, this.getFaceChange(item).index);
  269.     }
  270. };
  271.  
  272. Game_Actor.prototype.graphicSideviewEquip = function(item) {
  273.     if (this.getBattlerChange(item)) {
  274.       this.setBattlerImage(this.getBattlerChange(item));
  275.     }
  276. };
  277.  
  278. Game_Actor.prototype.refreshGraphicEquip = function() {
  279.     if (!(this.currentClass() && this.equips() && this.states())) {
  280.       return;
  281.     }
  282.     this.setCharacterImage(this._defaultCharacterName, this._defaultCharacterIndex);
  283.     this.setFaceImage(this._defaultFaceName, this._defaultFaceIndex);
  284.     this.setBattlerImage(this._defaultBattlerName);
  285.     if (this.currentClass().meta.ge !== undefined) {
  286.       this.graphicEquip(this.currentClass());
  287.     }
  288.     if (this.currentClass().meta.fe !== undefined) {
  289.       this.faceEquip(this.currentClass());
  290.     }
  291.     if (this.currentClass().meta.sve !== undefined) {
  292.       this.graphicSideviewEquip(this.currentClass());
  293.     }
  294.     var equipsSort = Jene.priorityEquip.split(" ");
  295.     for (var i = 0; i < equipsSort.length; i++) {
  296.       equipsSort[i] = parseInt(equipsSort[i]);
  297.     }
  298.     var equips = this.equips().filter(function (equip) {
  299.       return equip;
  300.     });
  301.     equips.sort(function (a, b) {
  302.       return equipsSort.indexOf(b.etypeId) - equipsSort.indexOf(a.etypeId);
  303.     });
  304.     for (var i = 0; i < equips.length; i++) {
  305.       if (equips[i].meta.ge !== undefined) {
  306.         this.graphicEquip(equips[i]);
  307.       }
  308.       if (equips[i].meta.fe !== undefined) {
  309.         this.faceEquip(equips[i]);
  310.       }
  311.       if (equips[i].meta.sve !== undefined) {
  312.         this.graphicSideviewEquip(equips[i]);
  313.       }
  314.     }
  315.     var states = this.states();
  316.     states.reverse();
  317.     for (var i = 0; i < states.length; i++) {
  318.       if (states[i].meta.ge !== undefined) {
  319.         this.graphicEquip(states[i]);
  320.       }
  321.       if (states[i].meta.fe !== undefined) {
  322.         this.faceEquip(states[i]);
  323.       }
  324.       if (states[i].meta.sve !== undefined) {
  325.         this.graphicSideviewEquip(states[i]);
  326.       }
  327.     }
  328. };
  329.  
  330. Jene.gameEnemyBattlername = Game_Enemy.prototype.battlerName;
  331.  
  332. Game_Enemy.prototype.battlerName = function() {
  333.     var states = this.states();
  334.     var name = "";
  335.     for (var i = 0; i < states.length; i++) {
  336.       var re = /<sve[:]?\s*[-](\d+)\s*[,]?\s*([$]*\w+)?\s*>/gi;
  337.       do {
  338.         var match = re.exec(states[i].note);
  339.         if (match && match[1] == this._enemyId) {
  340.           name = match[2];
  341.         }
  342.       } while (match);
  343.     }
  344.     if (name === "") {
  345.       name = Jene.gameEnemyBattlername.call(this);
  346.     }
  347.     return name;
  348. };
  349.  
  350. Jene.gamePartySetupStartingMembers = Game_Party.prototype.setupStartingMembers;
  351.  
  352. Game_Party.prototype.setupStartingMembers = function() {
  353.     Jene.gamePartySetupStartingMembers.call(this);
  354.     this.refreshGraphic();
  355. };
  356.  
  357. Game_Party.prototype.refreshGraphic = function() {
  358.     for (var i = 0; i < this.members().length; i++) {
  359.       this.members()[i].refreshGraphicEquip();
  360.     }
  361. };
  362.  
  363. Jene.gameInterpreterCommand322 = Game_Interpreter.prototype.command322;
  364.  
  365. Game_Interpreter.prototype.command322 = function() {
  366.     var actor = $gameActors.actor(this._params[0]);
  367.     if (actor && Jene.changeDefaultGraphic && ($gameSwitches.value(Jene.changeDefaultGraphicSwitch) || Jene.changeDefaultGraphicSwitch === 0)) {
  368.         actor.setCharacterImage(this._params[1], this._params[2]);
  369.         actor.setFaceImage(this._params[3], this._params[4]);
  370.         actor.setBattlerImage(this._params[5]);
  371.     }
  372.     $gamePlayer.refresh();
  373.     return Jene.gameInterpreterCommand322.call(this);
  374. };
  375.  
  376. Jene.spriteBattlerInitialize = Sprite_Battler.prototype.initialize;
  377.  
  378. Sprite_Battler.prototype.initialize = function(battler) {
  379.   $dataStates.forEach(function(state) {
  380.       if (!state || !state.meta.sve) { return; }
  381.         var re = /<sve[:]?\s*([-]?\d+)\s*[,]?\s*([$]*\w+)?\s*>/gi;
  382.         do {
  383.             var match = re.exec(state.note);
  384.             if (match && match[1] > 0) {
  385.               ImageManager.loadSvActor(match[2]);
  386.             }
  387.             else if (match && -match[1] < 0) {
  388.               ImageManager.loadSvEnemy(match[2]);
  389.             }
  390.         } while (match);
  391.     }, this);
  392.   Jene.spriteBattlerInitialize.call(this, battler);
  393. };
RAW Paste Data