State Slip Skills

Discussion in 'RGSS Scripts (RMXP)' started by MobiusXVI, Sep 30, 2015.

  1. MobiusXVI

    MobiusXVI Game Maker Veteran

    Messages:
    359
    Likes Received:
    84
    First Language:
    English
    Mobius's State Slip Skills 1.5

    by

    MobiusXVI


    Release Notes
    v. 1.0 Initial Release
    v. 1.5 Improved DBS Integration

    Introduction

    The purpose of the script is to allow you to set skills to replace the default slip damage formula. This allows you to create interesting poison-type skills and also easily create regen-type skills.

    Features
    - Create as many custom states as you want!
    - Use the old (and awful) slip damage formula if you really want to.
    - Create states that need the caster alive to maintain them.

    How to Use
    Copy the script into the script editor below the default scripts but above Main. Follow the instructions and configuration guidance within the script itself.


    Script

    Code:
    
    #===============================================================================
    # State Slip Skills
    # Author: Mobius XVI
    # Version: 1.5
    # Date: 05 SEP 2014
    #===============================================================================
    #
    # Introduction:
    #
    #   The purpose of this script is to allow you to set skills to replace
    #   the default slip damage formula
    #
    # Instructions:
    #
    #  - Place this script below all the default scripts but above main
    #
    #  - In the configuration section below, set up which states will call
    #    a skill in place of default slip damage. The format is very simple:
    #    'State_ID' => 'Skill_ID', (without quotes)
    #    Be sure each line ends in a comma, and make sure all of your lines
    #    are in between the two curly brackets, i.e. { and }
    #
    #  - Lastly, in the database, check the box for 'slip damage' for any
    #    state that you set up in the configuration section. If you don't,
    #    the script won't call a skill.
    #
    #  - There are also a few more options described in detail in the
    #    configuration section below, so be sure to check those out.
    #
    #  - One last thing, if you want to use the default slip damage for
    #    anything, simply check the 'slip damage' box in the database but
    #    don't configure anything below and the script will use the default
    #    formula.
    #
    # Issues/Bugs/Possible Bugs:
    #
    #   - This script heavily modifies Game_Battler, and my cause bugs in
    #     in other custom battle systems.
    #
    #  Credits/Thanks:
    #    - Mobius XVI, author
    #    - TheRiotInside, for requesting it
    #
    #  License
    #    The MIT License (MIT)
    #
    #    Copyright (c) 2015 darmes
    #
    #     Permission is hereby granted, free of charge, to any person obtaining a copy
    #     of this software and associated documentation files (the "Software"), to deal
    #     in the Software without restriction, including without limitation the rights
    #     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    #     copies of the Software, and to permit persons to whom the Software is
    #     furnished to do so, subject to the following conditions:
    #
    #     The above copyright notice and this permission notice shall be included in all
    #     copies or substantial portions of the Software.
    #
    #     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    #     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    #     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    #     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    #     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    #     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    #     SOFTWARE.
    #   
    #    Further, if you do decide to use this script in a commercial product,
    #    I'd ask that you let me know via a forum post or a PM. Thanks.
    #
    #===============================================================================
    #                             CONFIGURATION
    #===============================================================================
    
    module Mobius
      module State_Slip_Skills
       
        States_to_Skills = {
                            # The following is an example
                            # that links slip damage on state #3
                            # to call skill #57
                            3 => 57,
                            }
       
        # Setting this option to "true" causes the skill to track changes
        # to the original caster, i.e. if the caster get buffed then
        # the skill will cause more damage per turn or if the caster gets
        # debuffed the skill will cause less damage.
        # Setting this to "false" will cause the skill to take a snapshot
        # of the original caster, i.e. the skill will deal the same damage
        # each turn (with variance) regardless of what happens to the caster.
        Allow_Changes = true
       
        # >This option only works if "Allow_Changes" is set to true<
        # >This option only effects skills that are set in States_to_Skills<
        # Setting this option to "true" causes states to be removed when
        # the original caster dies.
        # Setting this option to false will allow states to remain even
        # if the original caster dies.
        End_State_on_Actor_Death = true
       
      end
    end
    #===============================================================================
    # ** State Slip Skills - EDIT BELOW THIS LINE AT OWN RISK
    #===============================================================================
    #--------------------------------------------------------------------------
    # Changes to class Game_Battler
    #--------------------------------------------------------------------------
    class Game_Battler
     
      # Alias old methods
      alias mobius_initialize           initialize
      alias mobius_add_state            add_state
      alias mobius_remove_state         remove_state
      alias mobius_attack_effect        attack_effect
      alias mobius_skill_effect         skill_effect
      alias mobius_slip_damage_effect   slip_damage_effect
     
      # New methods
     
      #--------------------------------------------------------------------------
      # * New Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader                       :animation_queue
     
      #--------------------------------------------------------------------------
      # * Initialize - adds new variables for tracking states
      #--------------------------------------------------------------------------
      def initialize
        mobius_initialize
        @attacker = nil                 # Variable for temp storing attacker
        @states_attacker = {}           # Variable for linking states to attacker
        @animation_queue = []           # Variable for queuing animations
      end
      #--------------------------------------------------------------------------
      # * Add State -  Links applied state to caster/actor that caused it
      #--------------------------------------------------------------------------
      def add_state(state_id, force = false)
        # Get result of old method (returns nil if ineffective)
        result = mobius_add_state(state_id, force = false)
        # If effective, link state_id to current attacker
        if result
           unless @attacker == nil
            if Mobius::State_Slip_Skills::Allow_Changes
              @states_attacker[state_id] = @attacker
            else
              @states_attacker[state_id] = @attacker.clone
            end
          end
        end
        # Pass result to caller
        result
      end
      #--------------------------------------------------------------------------
      # * Remove State - Removes associated caster/actor link
      #--------------------------------------------------------------------------
      def remove_state(state_id, force = false)
        # Get result of old method (returns nil if ineffective)
        result = mobius_remove_state(state_id, force = false)
        # If effective, remove state_id from @states_attacker hash
        if result
          @states_attacker.delete(state_id)
        end
        # Pass result to caller
        result
      end
      #--------------------------------------------------------------------------
      # * Attack Effect - Stores attacker in local variable for linking to state
      #--------------------------------------------------------------------------
      def attack_effect(attacker)
        # temporarily store value of attacker
        @attacker = attacker
        # call original method
        mobius_attack_effect(attacker)
        # reset value of attacker
        @attacker = nil
        # attack effect needs to return true to caller
        return true
      end
      #--------------------------------------------------------------------------
      # * Skill Effect - Stores attacker in local variable for linking to state
      #--------------------------------------------------------------------------
      def skill_effect(attacker, skill)
        # temporarily store value of attacker
        @attacker = attacker
        # skill effect return 'effective' to caller
        effective = mobius_skill_effect(attacker, skill)
        # reset value of attacker
        @attacker = nil
        # pass value of 'effectve' back to original caller
        return effective
      end
      #--------------------------------------------------------------------------
      # * Slip Damage Effect - drastically overhauled
      #    Now checks for states that are linked to skills and calls those
      #    skills up with an associated caster/actor. It will also store the
      #    results of the skill for display at a later time.
      #    If state is not set up that way, method calls original method
      #--------------------------------------------------------------------------
      def slip_damage_effect
        for state_id in @states
          # If an applied state has slip damage
          if $data_states[state_id].slip_damage
            # Check if state has associated skill
            if skill_id = Mobius::State_Slip_Skills::States_to_Skills[state_id]
              # Check if state has associated attacker
              if skill_attacker = @states_attacker[state_id]
                # Check if End_State option is true and actor is dead
                if Mobius::State_Slip_Skills::End_State_on_Actor_Death and
                   skill_attacker.dead?
                   # Remove state
                   self.remove_state(state_id)
                   # Go to next state
                   next
                end         
                # Call skill with attacker
                skill = $data_skills[skill_id]
                effective = self.skill_effect(skill_attacker, skill)
                # Set animation info
                add_animation_to_queue(skill.animation2_id,
                                       self.damage,
                                       self.critical)
                # Restore HP so it can be deducted when animation plays
                if self.damage.is_a?(Numeric)
                  self.hp += self.damage
                end
              end
            # If state not set with skill, use old slip damage effect
            else
              mobius_slip_damage_effect
            end       
          end
        end
      end
      #--------------------------------------------------------------------------
      # New methods that allow for queuing damage animations
      # Data structure - Array of arrays with sub arrays containing:
      # [animation_id, damage, critical]
      #--------------------------------------------------------------------------
      # * Add Animation to Queue - adds an animation to the queue
      #--------------------------------------------------------------------------
      def add_animation_to_queue(id, dam, crit)
        arr = [id, dam, crit]
        @animation_queue.push(arr)
      end
     
      #--------------------------------------------------------------------------
      # * Set Up Animation - Sets up new queued animation data
      #--------------------------------------------------------------------------
      def set_up_queued_animation
        # Get animation data
        arr = @animation_queue[0]
        # Ensure it's not nil
        if arr
          # Set all parameters
          self.animation_id = arr[0]
          self.damage = arr[1]
          self.animation_hit = (self.damage != "Miss")
        end
      end
      #--------------------------------------------------------------------------
      # * Unqueue Animation - Removes queued animation and plays damage pop
      #--------------------------------------------------------------------------
      def unqueue_animation
        # Get animation data
        arr = @animation_queue.shift
        # Ensure it's not nil
        if arr
          # Set all parameters
          self.damage = arr[1]
          self.critical = arr[2]
          self.damage_pop = true
          # If damage is a number, i.e. not "Miss"
          if self.damage.is_a?(Numeric)
            # Deal the damage here, so that the timing is right
            self.hp -= self.damage
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Animation Queued? - returns whether there are animations waiting
      #--------------------------------------------------------------------------
      def animation_queued?
        return ( not (@animation_queue.empty?) )   
      end
    
    end # class Game_Battler end
    
    #--------------------------------------------------------------------------
    # Changes to class Scene_Battle
    #--------------------------------------------------------------------------
    class Scene_Battle
     
      # alias old methods
      alias mobius_update_phase4_step1     update_phase4_step1
     
      #--------------------------------------------------------------------------
      # * Update Phase 4 - Method branches phase 4 to different steps
      #    Added steps 'slip1' and 'slip2'
      #--------------------------------------------------------------------------
      def update_phase4
        case @phase4_step
        when 1
          update_phase4_step1
        when 2
          update_phase4_step2
        when 3
          update_phase4_step3
        when 4
          update_phase4_step4
        when 5
          update_phase4_step5
        when 6
          update_phase4_step6
        when "slip1"
          update_phase4_slip1
        when "slip2"
          update_phase4_slip2
        end
      end
      #--------------------------------------------------------------------------
      # * Update Phase 4 Slip 1 - Plays state animation on target
      #--------------------------------------------------------------------------
      def update_phase4_slip1
        # Animation for target
        @active_battler.set_up_queued_animation
        # Animation has at least 8 frames, regardless of its length
        @wait_count = 8
        # Shift to step slip2
        @phase4_step = "slip2"
      end
      #--------------------------------------------------------------------------
      # * Update Phase 4 Slip 2 - Plays damage pop on target
      #--------------------------------------------------------------------------
      def update_phase4_slip2   
        # Display damage
        @active_battler.unqueue_animation
        # Refresh status window
        @status_window.refresh
        # Check if additional animations to show
        if @active_battler.animation_queued?
          # Shift to step slip1
          @phase4_step = "slip1"
        else
          # Shift to step 2
          @phase4_step = 2
        end
      end
      #--------------------------------------------------------------------------
      # * Update Phase 4 Step 1 - After old method runs, checks if there are
      #    animations to play and if there are, then it unsets the damage pop
      #-------------------------------------------------------------------------- 
      def update_phase4_step1
        # Call old method
        result = mobius_update_phase4_step1
        # Check that the active battler is valid and animations are waiting
        if result and @active_battler.animation_queued?
            # Set damage pop to false
            @active_battler.damage_pop = false
            # Shift to slip phase
            @phase4_step = "slip1"
        end
      end
    
    end # class Scene_Battle end


    FAQ
    Q. Can this do _______?
    A. Maybe! Leave a post on the forum, and I might just add the feature if it can't already do it.

    Credits and Thanks
    - MobiusXVI, author
    - TheRiotInside, for requesting it

    License
    This script is licensed under the MIT license, so you can use it for both commercial and non-commercial games!


    See the full license in the script header for notice requirements.
     
    Last edited: Mar 1, 2017
    #1
  2. XPKobold

    XPKobold Veteran Veteran

    Messages:
    235
    Likes Received:
    79
    First Language:
    English
    I was wondering if you have a demo of this script for some reason when i try to copy the script here it's seems to mess up most likely due to the forum changes sorry for bring this up but have noticed this several times.
     
    #2
  3. MobiusXVI

    MobiusXVI Game Maker Veteran

    Messages:
    359
    Likes Received:
    84
    First Language:
    English
    I edited the post and re-copied my script. Hopefully that fixes the issue, but let me know if it doesn't.
     
    #3

Share This Page