Guest User

Untitled

a guest
Jun 23rd, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Yanfly Engine Plugins - Weapon Animation
  3. // YEP_WeaponAnimation.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.YEP_WeaponAnimation = true;
  8.  
  9. var Yanfly = Yanfly || {};
  10. Yanfly.WA = Yanfly.WA || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.02 This plugin allows you to go past the standard
  15.  * weapon images and even using custom images.
  16.  * @author Yanfly Engine Plugins
  17.  *
  18.  * @param Image Filepath
  19.  * @desc The filepath used for custom weapon images.
  20.  * @default img/weapons/
  21.  *
  22.  * @param Image Smoothing
  23.  * @desc Enable image smoothing for weapons?
  24.  * NO - false     YES - true
  25.  * @default false
  26.  *
  27.  * @param Default Motion
  28.  * @desc Default motion used for custom weapon images.
  29.  * @default swing
  30.  *
  31.  * @help
  32.  * ============================================================================
  33.  * Introduction
  34.  * ============================================================================
  35.  *
  36.  * Ever wanted to give your swords different images despite being the same
  37.  * sword type? Or how about your axes? Or any weapon? Now you can! On top of
  38.  * that, you can even use custom images to accomplish this.
  39.  *
  40.  * Note: If you are using the YEP_BattleEngineCore, YEP_X_AnimatedSVEnemies, or
  41.  * any of the Action Sequence Packs, place this plugin under those plugins in
  42.  * the plugin list within the Plugin Manager for the best compatibility.
  43.  *
  44.  * ============================================================================
  45.  * Notetags
  46.  * ============================================================================
  47.  *
  48.  * For those who would like to give their weapons a little bit of a change, you
  49.  * can make use of these notetags:
  50.  *
  51.  * Actor, Class, Enemy, Weapon, Armor, and State Notetags:
  52.  *
  53.  *   <Weapon Image: x>
  54.  *   Replace x with a number above 0 and you'll get an image from img/system's
  55.  *   weapon sheets. Each sheet contains 12 weapon images. If you wish to load a
  56.  *   weapon from the first sheet, it'll be within 1-12. If you wish to load a
  57.  *   weapon from the second sheet, it'll be within 13-24, and so on. The weapon
  58.  *   sheets increase in increments of 12, which means that if you wish to load
  59.  *   a weapon from weapon sheet 50, x will be between 589 to 600.
  60.  *
  61.  *   By default, these are the number values associated with each:
  62.  *   1 - Dagger   7 - Long Bow  13 - Mace       19 - Slingshot  25 - Book
  63.  *   2 - Sword    8 - Crossbow  14 - Rod        20 - Shotgun    26 - Custom
  64.  *   3 - Flail    9 - Gun       15 - Club       21 - Rifle      27 - Custom
  65.  *   4 - Axe     10 - Claw      16 - Chain      22 - Chainsaw   28 - Custom
  66.  *   5 - Whip    11 - Glove     17 - Sword#2    23 - Railgun    29 - Custom
  67.  *   6 - Staff   12 - Spear     18 - Iron Pipe  24 - Stun Rod   30 - Custom
  68.  *
  69.  *   <Weapon Image: filename>
  70.  *   If you have created a custom folder to place unique weapon sheets, you can
  71.  *   use this notetag to acquire them. The filename is case sensitive. Do not
  72.  *   include the file extension. If your weapon sheet is called DaggerBlue.png,
  73.  *   then the notetag you'd use would be <Weapon Image: DaggerBlue> only.
  74.  *
  75.  *   <Weapon Motion: thrust>
  76.  *   <Weapon Motion: swing>
  77.  *   <Weapon Motion: missile>
  78.  *   This will dictate the motion the battler will use when attacking if you're
  79.  *   using a custom weapon animation. If nothing is placed here, the motion
  80.  *   will default to the 'Default Motion' value in the plugin parameters. You
  81.  *   can use any of the following motions:
  82.  *   walk     wait     chant     guard     damage     evade
  83.  *   thrust   swing    missile   skill     spell      item
  84.  *   escape   victory  dying     abnormal  sleep      dead
  85.  *
  86.  *   <Weapon Hue: x>
  87.  *   For those who would like to use different hues with your weapon animation,
  88.  *   use this notetag in the same notebox as the <Weapon Image: x> notetag to
  89.  *   change the hue of the weapon animation to x.
  90.  *
  91.  *   <Weapon Animation: x>
  92.  *   If you would like to override the attack animation when using this weapon,
  93.  *   you can use x to dictate which animation will be used for regular attacks.
  94.  *
  95.  * ---
  96.  *
  97.  * If you haven't noticed yet, these notetags are made for actors, classes,
  98.  * enemies, weapons, armors, and also states. What this means is, the weapon
  99.  * animation changes will behave more like traits. Priorities will occur in the
  100.  * following order:
  101.  *
  102.  *   States
  103.  *   Weapons
  104.  *   Armors
  105.  *   Classes
  106.  *   Actors
  107.  *   Enemies
  108.  *
  109.  * This means that if a battler is affected by a state that would modify its
  110.  * weapon appearance, any other weapon animation changes that the user would
  111.  * have will be overwritten by the state's weapon animation change until the
  112.  * state wears off.
  113.  *
  114.  * ============================================================================
  115.  * Instructions - Custom Weapon Images
  116.  * ============================================================================
  117.  *
  118.  * The weapon sheet format will follow RPG Maker MV's weapon sheet format in
  119.  * individual frame dimensions. However, unlike RPG Maker MV's weapon sheet
  120.  * format. That said, these custom weapon images will need to be made a certain
  121.  * way in order to look properly with RPG Maker MV's default battlers.
  122.  *
  123.  * Here is the weapon sheet format:
  124.  *
  125.  *   Sheet Width:   288 Minimum
  126.  *   Sheet Height:  64 Minimum
  127.  *   Frame Width:   Sheet Width / 3
  128.  *   Frame Height:  Sheet Height
  129.  *
  130.  * As long as you make them in that format, the weapon sheets will work with
  131.  * RPG Maker's default battlers.
  132.  *
  133.  * ============================================================================
  134.  * Changelog
  135.  * ============================================================================
  136.  *
  137.  * Version 1.02:
  138.  * - Updated for RPG Maker MV version 1.1.0.
  139.  *
  140.  * Version 1.01:
  141.  * - Fixed a conflict with sideview enemies using no weapon animations.
  142.  *
  143.  * Version 1.00:
  144.  * - Finished Plugin!
  145.  */
  146. //=============================================================================
  147.  
  148. //=============================================================================
  149. // Parameter Variables
  150. //=============================================================================
  151.  
  152. Yanfly.Parameters = PluginManager.parameters('YEP_WeaponAnimation');
  153. Yanfly.Param = Yanfly.Param || {};
  154.  
  155. Yanfly.Param.WAFilepath = String(Yanfly.Parameters['Image Filepath']);
  156. Yanfly.Param.WASmoothing = eval(String(Yanfly.Parameters['Image Smoothing']));
  157. Yanfly.Param.WAMotion = String(Yanfly.Parameters['Default Motion']);
  158. Yanfly.Param.WAMotion = Yanfly.Param.WAMotion.toLowerCase();
  159.  
  160. //=============================================================================
  161. // DataManager
  162. //=============================================================================
  163.  
  164. Yanfly.WA.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  165. DataManager.isDatabaseLoaded = function() {
  166.   if (!Yanfly.WA.DataManager_isDatabaseLoaded.call(this)) return false;
  167.   if (!Yanfly._loaded_YEP_WeaponAnimation) {
  168.     this.processWANotetags1($dataActors);
  169.     this.processWANotetags1($dataClasses);
  170.     this.processWANotetags1($dataEnemies);
  171.     this.processWANotetags1($dataWeapons);
  172.     this.processWANotetags1($dataArmors);
  173.     this.processWANotetags1($dataStates);
  174.     Yanfly._loaded_YEP_WeaponAnimation = true;
  175.   }
  176.   return true;
  177. };
  178.  
  179. DataManager.processWANotetags1 = function(group) {
  180.   for (var n = 1; n < group.length; n++) {
  181.     var obj = group[n];
  182.     var notedata = obj.note.split(/[\r\n]+/);
  183.  
  184.     obj.weaponImageIndex = [];
  185.     obj.weaponAttackMotion = undefined;
  186.     obj.weaponAnimationId = 0;
  187.     obj.weaponHue = undefined;
  188.  
  189.     for (var i = 0; i < notedata.length; i++) {
  190.       var line = notedata[i];
  191.       if (line.match(/<(?:WEAPON IMAGE):[ ](\d+)>/i)) {
  192.         obj.weaponImageIndex.push(parseInt(RegExp.$1));
  193.         if (obj.weaponAttackMotion) continue;
  194.         var motion = $dataSystem.attackMotions[parseInt(RegExp.$1)];
  195.         if (motion) {
  196.           if (motion.type === 0) {
  197.             obj.weaponAttackMotion = 'thrust';
  198.           } else if (motion.type === 1) {
  199.             obj.weaponAttackMotion = 'swing';
  200.           } else {
  201.             obj.weaponAttackMotion = 'missile';
  202.           }
  203.         } else {
  204.           obj.weaponAttackMotion = Yanfly.Param.WAMotion;
  205.         }
  206.         if (obj.weaponHue === undefined) obj.weaponHue = 0;
  207.       } else if (line.match(/<(?:WEAPON IMAGE):[ ](.*)>/i)) {
  208.         obj.weaponImageIndex.push(String(RegExp.$1));
  209.         obj.weaponAttackMotion = Yanfly.Param.WAMotion;
  210.       } else if (line.match(/<(?:WEAPON MOTION):[ ](.*)>/i)) {
  211.         obj.weaponAttackMotion = String(RegExp.$1).toLowerCase();
  212.       } else if (line.match(/<(?:WEAPON ANIMATION):[ ](\d+)>/i)) {
  213.         obj.weaponAnimationId = parseInt(RegExp.$1);
  214.       } else if (line.match(/<(?:WEAPON HUE):[ ](\d+)>/i)) {
  215.         obj.weaponHue = parseInt(RegExp.$1);
  216.       }
  217.     }
  218.   }
  219. };
  220.  
  221. //=============================================================================
  222. // ImageManager
  223. //=============================================================================
  224.  
  225. ImageManager.loadWeapon = function(filename, hue) {
  226.     var filepath = Yanfly.Param.WAFilepath;
  227.     var smooth = Yanfly.Param.WASmoothing;
  228.     return this.loadBitmap(filepath, filename, hue, smooth);
  229. };
  230.  
  231. //=============================================================================
  232. // Game_Battler
  233. //=============================================================================
  234.  
  235. Yanfly.WA.Game_Battler_refresh = Game_Battler.prototype.refresh;
  236. Game_Battler.prototype.refresh = function() {
  237.     this._cacheWeaponImage = undefined;
  238.     this._cacheWeaponHue = undefined;
  239.     this._cacheWeaponMotion = undefined;
  240.     this._cacheWeaponAni = undefined;
  241.     Yanfly.WA.Game_Battler_refresh.call(this);
  242. };
  243.  
  244. Yanfly.WA.Game_Battler_startWeaponAnimation =
  245.     Game_Battler.prototype.startWeaponAnimation;
  246. Game_Battler.prototype.startWeaponAnimation = function(id) {
  247.     var unique = false;
  248.     if (this.getUniqWeapAniId()) {
  249.       id = this.getUniqWeapAniId();
  250.       unique = true;
  251.     }
  252.     Yanfly.WA.Game_Battler_startWeaponAnimation.call(this, id);
  253.     if (!unique) return;
  254.     if (Imported.YEP_BattleEngineCore) {
  255.       this.forceMotion(this.getUniqueWeaponMotion());
  256.     } else {
  257.       this.requestMotion(this.getUniqueWeaponMotion());
  258.     }
  259. };
  260.  
  261. Game_Battler.prototype.getUniqWeapAniId = function() {
  262.     var length = this.states().length;
  263.     for (var i = 0; i < length; ++i) {
  264.       var obj = this.states()[i];
  265.       if (obj && obj.weaponImageIndex) {
  266.         this._cacheWeaponImage = Yanfly.Util.getRandomElement(obj.weaponImageIndex);
  267.         this._cacheWeaponHue = obj.weaponHue;
  268.         return this._cacheWeaponImage;
  269.       }
  270.     }
  271.     return undefined;
  272. };
  273.  
  274. Game_Battler.prototype.getUniqueWeaponHue = function() {
  275.     if (this._cacheWeaponHue === undefined) this.getUniqWeapAniId();
  276.     return this._cacheWeaponHue ||0;
  277. };
  278.  
  279. Game_Battler.prototype.getUniqueWeaponMotion = function() {
  280.     var length = this.states().length;
  281.     for (var i = 0; i < length; ++i) {
  282.       var obj = this.states()[i];
  283.       if (obj && obj.weaponAttackMotion) {
  284.         this._cacheWeaponMotion = obj.weaponAttackMotion;
  285.         return this._cacheWeaponMotion;
  286.       }
  287.     }
  288.     return undefined;
  289. };
  290.  
  291. Game_Battler.prototype.getUniqueWeaponAni = function() {
  292.     var length = this.states().length;
  293.     for (var i = 0; i < length; ++i) {
  294.       var obj = this.states()[i];
  295.       if (obj && obj.weaponAnimationId) {
  296.         this._cacheWeaponAni = obj.weaponAnimationId;
  297.         return this._cacheWeaponAni;
  298.       }
  299.     }
  300.     return undefined;
  301. };
  302.  
  303. Game_Battler.prototype.isWeaponAnimationRequested = function() {
  304.     return this._weaponImageId !== 0;
  305. };
  306.  
  307. //=============================================================================
  308. // Game_Actor
  309. //=============================================================================
  310.  
  311. Game_Actor.prototype.getUniqWeapAniId = function() {
  312.     if (this._cacheWeaponImage !== undefined) return this._cacheWeaponImage;
  313.     var id = Game_Battler.prototype.getUniqWeapAniId.call(this);
  314.     if (id) {
  315.       this._cacheWeaponImage = id;
  316.       return this._cacheWeaponImage;
  317.     }
  318.     var length = this.equips().length;
  319.     for (var i = 0; i < length; ++i) {
  320.       var obj = this.equips()[i];
  321.       if (obj && obj.weaponImageIndex) {
  322.         this._cacheWeaponImage = Yanfly.Util.getRandomElement(obj.weaponImageIndex);
  323.         this._cacheWeaponHue = obj.weaponHue;
  324.         return this._cacheWeaponImage;
  325.       }
  326.     }
  327.     if (this.currentClass().weaponImageIndex) {
  328.       this._cacheWeaponImage = Yanfly.Util.getRandomElement(this.currentClass().weaponImageIndex);
  329.         this._cacheWeaponHue = this.currentClass().weaponHue;
  330.       return this._cacheWeaponImage;
  331.     }
  332.     if (this.actor().weaponImageIndex) {
  333.       this._cacheWeaponImage = Yanfly.Util.getRandomElement(this.actor().weaponImageIndex);
  334.         this._cacheWeaponHue = this.actor().weaponHue;
  335.       return this._cacheWeaponImage;
  336.     }
  337.     this._cacheWeaponImage = 0;
  338.     return this._cacheWeaponImage;
  339. };
  340.  
  341. Game_Actor.prototype.getUniqueWeaponMotion = function() {
  342.     if (this._cacheWeaponMotion !== undefined) return this._cacheWeaponMotion;
  343.     var motion = Game_Battler.prototype.getUniqueWeaponMotion.call(this);
  344.     if (motion) {
  345.       this._cacheWeaponMotion = motion;
  346.       return this._cacheWeaponMotion;
  347.     }
  348.     var length = this.equips().length;
  349.     for (var i = 0; i < length; ++i) {
  350.       var obj = this.equips()[i];
  351.       if (obj && obj.weaponAttackMotion) {
  352.         this._cacheWeaponMotion = obj.weaponAttackMotion;
  353.         return this._cacheWeaponMotion;
  354.       }
  355.     }
  356.     if (this.currentClass().weaponAttackMotion) {
  357.       this._cacheWeaponMotion = this.currentClass().weaponAttackMotion;
  358.       return this._cacheWeaponMotion;
  359.     }
  360.     if (this.actor().weaponAttackMotion) {
  361.       this._cacheWeaponMotion = this.actor().weaponAttackMotion;
  362.       return this._cacheWeaponMotion;
  363.     }
  364.     return 'thrust';
  365. };
  366.  
  367. Game_Actor.prototype.getUniqueWeaponAni = function() {
  368.     if (this._cacheWeaponAni !== undefined) return this._cacheWeaponAni;
  369.     var ani = Game_Battler.prototype.getUniqueWeaponAni.call(this);
  370.     if (ani) {
  371.       this._cacheWeaponAni = ani;
  372.       return this._cacheWeaponAni;
  373.     }
  374.     var length = this.equips().length;
  375.     for (var i = 0; i < length; ++i) {
  376.       var obj = this.equips()[i];
  377.       if (obj && obj.weaponAnimationId) {
  378.         this._cacheWeaponAni = obj.weaponAnimationId;
  379.         return this.weaponAnimationId;
  380.       }
  381.     }
  382.     if (this.currentClass().weaponAnimationId) {
  383.       this._cacheWeaponAni = this.currentClass().weaponAnimationId;
  384.       return this.weaponAnimationId;
  385.     }
  386.     if (this.actor().weaponAttackMotion) {
  387.       this._cacheWeaponAni = this.actor().weaponAnimationId;
  388.       return this.weaponAnimationId;
  389.     }
  390.     return 0;
  391. };
  392.  
  393. Yanfly.WA.Game_Actor_attackAnimationId1 =
  394.     Game_Actor.prototype.attackAnimationId1;
  395. Game_Actor.prototype.attackAnimationId1 = function() {
  396.     if (this.getUniqueWeaponAni()) return this.getUniqueWeaponAni();
  397.     return Yanfly.WA.Game_Actor_attackAnimationId1.call(this);
  398. };
  399.  
  400. Yanfly.WA.Game_Actor_attackAnimationId2 =
  401.     Game_Actor.prototype.attackAnimationId2;
  402. Game_Actor.prototype.attackAnimationId2 = function() {
  403.     if (this.getUniqueWeaponAni()) return this.getUniqueWeaponAni();
  404.     return Yanfly.WA.Game_Actor_attackAnimationId2.call(this);
  405. };
  406.  
  407. //=============================================================================
  408. // Game_Enemy
  409. //=============================================================================
  410.  
  411. Game_Enemy.prototype.getUniqWeapAniId = function() {
  412.     if (this._cacheWeaponImage !== undefined) return this._cacheWeaponImage;
  413.     var id = Game_Battler.prototype.getUniqWeapAniId.call(this);
  414.     if (id) {
  415.       this._cacheWeaponImage = id;
  416.       return this._cacheWeaponImage;
  417.     }
  418.     if (this.enemy().weaponImageIndex) {
  419.       this._cacheWeaponImage = Yanfly.Util.getRandomElement(this.enemy().weaponImageIndex);
  420.         this._cacheWeaponHue = this.enemy().weaponHue;
  421.       return this._cacheWeaponImage;
  422.     }
  423.     this._cacheWeaponImage = undefined;
  424.     return this._cacheWeaponImage;
  425. };
  426.  
  427. Game_Enemy.prototype.getUniqueWeaponMotion = function() {
  428.     if (this._cacheWeaponMotion !== undefined) return this._cacheWeaponMotion;
  429.     var motion = Game_Battler.prototype.getUniqueWeaponMotion.call(this);
  430.     if (motion) {
  431.       this._cacheWeaponMotion = motion;
  432.       return this._cacheWeaponMotion;
  433.     }
  434.     if (this.enemy().weaponAttackMotion) {
  435.       this._cacheWeaponMotion = this.enemy().weaponAttackMotion;
  436.       return this._cacheWeaponMotion;
  437.     }
  438.     return 'thrust';
  439. };
  440.  
  441. Game_Enemy.prototype.getUniqueWeaponAni = function() {
  442.     if (this._cacheWeaponAni !== undefined) return this._cacheWeaponAni;
  443.     var ani = Game_Battler.prototype.getUniqueWeaponAni.call(this);
  444.     if (ani) {
  445.       this._cacheWeaponAni = ani;
  446.       return this._cacheWeaponAni;
  447.     }
  448.     if (this.enemy().weaponAttackMotion) {
  449.       this._cacheWeaponAni = this.enemy().weaponAnimationId;
  450.       return this.weaponAnimationId;
  451.     }
  452.     return 0;
  453. };
  454.  
  455. Yanfly.WA.Game_Enemy_attackAnimationId = Game_Enemy.prototype.attackAnimationId;
  456. Game_Enemy.prototype.attackAnimationId = function() {
  457.     if (this.getUniqueWeaponAni()) return this.getUniqueWeaponAni();
  458.     return Yanfly.WA.Game_Enemy_attackAnimationId.call(this);
  459. };
  460.  
  461. if (Imported.YEP_X_AnimatedSVEnemies) {
  462.  
  463. Yanfly.WA.Game_Enemy_attackMotion = Game_Enemy.prototype.attackMotion;
  464. Game_Enemy.prototype.attackMotion = function() {
  465.     if (this._cacheWeaponMotion !== undefined) return this._cacheWeaponMotion;
  466.     return Yanfly.WA.Game_Enemy_attackMotion.call(this);
  467. };
  468.  
  469. Yanfly.WA.Game_Enemy_weaponImageId = Game_Enemy.prototype.weaponImageId;
  470. Game_Enemy.prototype.weaponImageId = function() {
  471.     if (this._cacheWeaponImage !== undefined) return this._cacheWeaponImage;
  472.     return Yanfly.WA.Game_Enemy_weaponImageId.call(this);
  473. };
  474.  
  475. }; // Imported.YEP_X_AnimatedSVEnemies
  476.  
  477. //=============================================================================
  478. // Sprite_Weapon
  479. //=============================================================================
  480.  
  481. Yanfly.WA.Sprite_Weapon_loadBitmap = Sprite_Weapon.prototype.loadBitmap;
  482. Sprite_Weapon.prototype.loadBitmap = function() {
  483.     if (this.isCustomGraphic()) return this.loadCustomBitmap();
  484.     Yanfly.WA.Sprite_Weapon_loadBitmap.call(this);
  485. };
  486.  
  487. Sprite_Weapon.prototype.isCustomGraphic = function() {
  488.     return typeof this._weaponImageId === 'string';
  489. };
  490.  
  491. Sprite_Weapon.prototype.loadCustomBitmap = function() {
  492.     if (this.parent && this.parent._battler) {
  493.       var hue = this.parent._battler.getUniqueWeaponHue();
  494.     } else {
  495.       var hue = 0;
  496.     }
  497.     this.bitmap = ImageManager.loadWeapon(this._weaponImageId, hue);
  498. };
  499.  
  500. Yanfly.WA.Sprite_Weapon_updateFrame = Sprite_Weapon.prototype.updateFrame;
  501. Sprite_Weapon.prototype.updateFrame = function() {
  502.     if (this.isCustomGraphic()) {
  503.       var w = Math.floor(this.bitmap.width / 3);
  504.       var h = this.bitmap.height;
  505.       var sx = this._pattern * w;
  506.       var sy = 0;
  507.       this.setFrame(sx, sy, w, h);
  508.     } else {
  509.       Yanfly.WA.Sprite_Weapon_updateFrame.call(this);
  510.     }
  511. };
  512.  
  513. Yanfly.WA.Sprite_Weapon_update = Sprite_Weapon.prototype.update;
  514. Sprite_Weapon.prototype.update = function() {
  515.     Yanfly.WA.Sprite_Weapon_update.call(this);
  516.     this.updateFrame();
  517. };
  518.  
  519. //=============================================================================
  520. // Utilities
  521. //=============================================================================
  522.  
  523. Yanfly.Util = Yanfly.Util || {};
  524.  
  525. Yanfly.Util.getRandomElement = function(array) {
  526.     var value = array[Math.floor(Math.random() * array.length)];
  527.     return value;
  528. };
  529.  
  530. //=============================================================================
  531. // End of File
  532. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment