Guest User

Untitled

a guest
Dec 22nd, 2015
555
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvUndead.js
  3. // Version: 1.00
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc v1.00 Silvers Undead Plugin. Allows heals to damage undead-characters and (optionally) vice versa. <SilverUndead>
  7.  * @author Silver
  8.  *
  9.  * @param Undead State ID
  10.  * @desc ID of the undead-state in the database. Use the value -1 to disable the undead state. This state is purely for other plugins and effects.
  11.  * @default -1
  12.  *
  13.  * @help
  14.  *
  15.  *--------------------------------------
  16.  * Notetags
  17.  *--------------------------------------
  18.  * The following notetag can be placed in the Actors, Enemies and Classes note-fields in order to mark them as undead:
  19.  * <is_undead>
  20.  *
  21.  * The following notetag can be placed in the skills and item note-fields:
  22.  * <invert_for_undead>
  23.  * Placing this notetag in that field will turn healing into damage and damage into healing (for undead). This only applies to items&skills tagged with this notetag.
  24.  *
  25.  *--------------------------------------
  26.  * Dev Notes
  27.  *--------------------------------------
  28.  * You can check if an actor/enemy is an undead either by checking for the undeadState or through: $gameActors._data[actorId].isUndead
  29.  *
  30.  *--------------------------------------
  31.  * Version History
  32.  *--------------------------------------
  33.  *
  34.  * v1.00 (21 December 2015)
  35.  * - First release
  36.  */
  37.  
  38. // Imported
  39. var Imported = Imported || {};
  40. Imported.SILV_Undead = 1.00;
  41.  
  42. // Get Plugin #Parameters
  43. var Silv = Silv || {};
  44. Silv.Undead = Silv.Undead || {};
  45. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverUndead>'); })[0].parameters;
  46. Silv.Undead.StateID = parseInt(Silv.Parameters['Undead State ID']);
  47.  
  48. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. // Utilities
  50. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. Silv.Undead.SetUndeadState = function(target)
  52. {
  53.     if (Silv.Undead.StateID != -1) { (target.isUndead) ? target.addState(Silv.Undead.StateID) : target.removeState(Silv.Undead.StateID); }
  54. };
  55.  
  56. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57. // Game Actor
  58. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. var alias_silv_undead_Game_Actor_setup = Game_Actor.prototype.setup;
  60. Game_Actor.prototype.setup = function(actorId)
  61. {
  62.     alias_silv_undead_Game_Actor_setup.apply(this, arguments);
  63.     this.setUndead();
  64. };
  65.  
  66. // This alias is required to prevent RM from clearing the undead-state after they have been set in the Actor.setup()
  67. var alias_silv_undead_Game_BattlerBase_clearStates = Game_BattlerBase.prototype.clearStates;
  68. Game_BattlerBase.prototype.clearStates = function()
  69. {
  70.     if (!this._states)
  71.     {
  72.         alias_silv_undead_Game_BattlerBase_clearStates.apply(this, arguments);
  73.     }
  74.     else
  75.     {
  76.         var addUndeadStateAgain = false;
  77.         if (this._states.indexOf(Silv.Undead.StateID) > -1) { addUndeadStateAgain = true; }
  78.         alias_silv_undead_Game_BattlerBase_clearStates.apply(this, arguments);
  79.         if (addUndeadStateAgain) { this.addState(Silv.Undead.StateID); }
  80.     }
  81. };
  82.  
  83. // This alias is required because the undead state must be added even when a character is dead,  the undead state should never be resisted, etc.
  84. var alias_silv_undead_Game_Battler_isStateAddable = Game_Battler.prototype.isStateAddable;
  85. Game_Battler.prototype.isStateAddable = function(stateId)
  86. {
  87.     return (stateId == Silv.Undead.StateID) || alias_silv_undead_Game_Battler_isStateAddable.apply(this, arguments);
  88. };
  89.  
  90. Game_Actor.prototype.setUndead = function()
  91. {
  92.     (('is_undead' in $dataActors[this._actorId].meta) || ('is_undead' in $dataClasses[this._classId].meta)) ? this.isUndead = true : this.isUndead = false;
  93.     Silv.Undead.SetUndeadState(this);
  94. };
  95.  
  96. // Re-rest the undead-state if the actor's class changes. Because the undead-state could have originated from the actor's class.
  97. var alias_test = Game_Actor.prototype.changeClass;
  98. Game_Actor.prototype.changeClass = function(classId, keepExp)
  99. {
  100.     alias_test.apply(this, arguments);
  101.     this.setUndead();
  102. };
  103.  
  104. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. // Game Enemy
  106. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  107. var alias_silv_undead_Game_Enemy_setup = Game_Enemy.prototype.setup;
  108. Game_Enemy.prototype.setup = function(enemyId, x, y)
  109. {
  110.     alias_silv_undead_Game_Enemy_setup.apply(this, arguments);
  111.     this.setUndead();
  112. };
  113.  
  114. // Note that unlike the Game_Actor.prototype.setUndead(), this method isn't required to delete the undead state if it's not an undead because enemies can't change class
  115. Game_Enemy.prototype.setUndead = function()
  116. {
  117.     ('is_undead' in $dataEnemies[this._enemyId].meta) ? this.isUndead = true : this.isUndead = false;
  118.     Silv.Undead.SetUndeadState(this);
  119. };
  120.  
  121. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. // Game Action
  123. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. var alias_silv_undead_Game_Action_executeHpDamage = Game_Action.prototype.executeHpDamage;
  125. Game_Action.prototype.executeHpDamage = function(target, value)
  126. {
  127.     if (target.isUndead && (('invert_for_undead' in this.item().meta))) { value *= -1; }
  128.     alias_silv_undead_Game_Action_executeHpDamage.call(this, target, value);
  129. };
  130.  
  131. var alias_silv_undead_Game_Action_itemEffectRecoverHp = Game_Action.prototype.itemEffectRecoverHp;
  132. Game_Action.prototype.itemEffectRecoverHp = function(target, effect)
  133. {
  134.     var newEffect = JsonEx.makeDeepCopy(effect);
  135.     if (target.isUndead && ('invert_for_undead' in this.item().meta))
  136.     {
  137.         newEffect.value1 *= -1;
  138.         newEffect.value2 *= -1;
  139.     }
  140.  
  141.     alias_silv_undead_Game_Action_itemEffectRecoverHp.call(this, target, newEffect);   
  142. };
  143.  
  144. // Make sure that tagged healing-potions and healing-skills can be used on undead-characters which have full hp
  145. var alias_silv_undead_Game_Action_hasItemAnyValidEffects = Game_Action.prototype.hasItemAnyValidEffects;
  146. Game_Action.prototype.hasItemAnyValidEffects = function(target)
  147. {
  148.     var item = this.item(); // cloning is not required because these items are new objects and are not the database itself. // var item = JsonEx.makeDeepCopy(this.item());
  149.     if (target.isUndead && ('invert_for_undead' in item.meta)) //target.isStateAffected(Silv.Undead.StateID)
  150.     {
  151.         if (item.effects.some(function (effect) { return effect.code == Game_Action.EFFECT_RECOVER_HP; } ) || item.damage.type == 3) // 3 == HP Recover
  152.         {
  153.             return true;
  154.         }
  155.     }
  156.    
  157.     return alias_silv_undead_Game_Action_hasItemAnyValidEffects.apply(this, arguments);
  158. };
  159.  
  160. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. // This is the end of this awesome script!
  162. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RAW Paste Data