VanCoolz

[RGSS] Mana Shield State

May 16th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.44 KB | None | 0 0
  1. #==============================================================================
  2. # [RGSS] Mana Shield
  3. # Version : 1.1
  4. # Author : LowlingLife
  5. #==============================================================================
  6. # Membuat state yang membuat damage di-deal ke SP, bukan ke HP.
  7. #==============================================================================
  8. # CHANGELOG :
  9. # V. 1.0 | Initial Release
  10. # V. 1.1 | Add Half Damage State
  11. #==============================================================================
  12. module ManaShield
  13.   # ID dari State yang akan mengalihkan damage ke SP secara Full.
  14.   FULL_STATE = [17, 18, 19]
  15.  
  16.   # ID dari State dimana separuh damage dialihkan ke SP dan separuh lagi
  17.   # dialihkan ke HP.
  18.   HALF_STATE = [20, 21, 22]
  19.  
  20.   # ID dari State dimana hanya separuh damage yang dialihkan ke SP tapi
  21.   # separuhnya tidak dialihkan ke HP.
  22.   HALF_DAMAGE_STATE = [23, 24, 25]
  23.  
  24.   # Set ke true jika ingin memakai fitur Overflow. Jika Damage yang di-deal
  25.   # lebih besar daripada SP, sisanya akan di deal ke HP.
  26.   OVERFLOW = false
  27.  
  28.   # Set ke true jika ingin Mana Shield State otomatis di-remove setelah
  29.   # mendapat damage yang lebih besar dari pada SP.
  30.   # Note : Uncheck Release at the end of battle jika menggunakan opsi ini.
  31.   AUTO_REMOVE = true
  32.  
  33.   # Set ke true jika ingin agar Mana Shield tetap men-deal damage yang
  34.   # disebabkan Skill ke SP.
  35.   SKILL_PROTECTION = true
  36.  
  37.   # Set ke true jika ingin agar Mana Shield tetap men-deal damage yang
  38.   # disebakan Slip Damage ke SP.
  39.   SLIP_DAMAGE_PROTECTION = true
  40. end
  41. #==============================================================================
  42. # EDITING BEYOND THIS LINE CAN CAUSE DAMAGE TO YOUR GAME. THEREFORE, EDIT
  43. # WITH YOUR OWN RISK!
  44. #==============================================================================
  45. class Game_Battler
  46.   include ManaShield
  47.  
  48.   attr_accessor :overflow
  49.   attr_accessor :sp_damage
  50.   attr_accessor :hp_damage
  51.  
  52.   #----------------------------------------------------------------------------
  53.   # INITIALIZE
  54.   #----------------------------------------------------------------------------
  55.   alias mana_shield_initialize initialize unless $@
  56.   def initialize
  57.     # Run the old method
  58.     mana_shield_initialize
  59.     @overflow = 0
  60.     @sp_damage = 0
  61.     @hp_damage = 0
  62.   end
  63.  
  64.   #----------------------------------------------------------------------------
  65.   # CHECK MANA SHIELD
  66.   #----------------------------------------------------------------------------
  67.   def check_mana_shield
  68.     if FULL_STATE.any?{|s| @states.include?(s)}
  69.       @sp_damage = self.damage
  70.       self.sp -= @sp_damage
  71.      
  72.       if @sp_damage > self.sp
  73.         # Jika memakai opsi OVERFLOW
  74.         if OVERFLOW
  75.           @overflow = @sp_damage - self.sp
  76.           self.sp -= @sp_damage - @overflow
  77.           self.hp -= @overflow
  78.         # Jika tidak.
  79.         else
  80.           @overflow = @sp_damage - self.sp
  81.           self.sp -= @sp_damage - @overflow
  82.         end
  83.         for s in FULL_STATE
  84.           @states.delete(s) if AUTO_REMOVE
  85.           @states_turn.delete(s) if AUTO_REMOVE
  86.         end
  87.       end
  88.      
  89.     elsif HALF_STATE.any?{|s| @states.include?(s)}
  90.       @sp_damage = self.damage - (self.damage / 2)
  91.       @hp_damage = self.damage - (self.damage / 2)
  92.       self.sp -= @sp_damage
  93.       self.hp -= @hp_damage
  94.      
  95.       if @sp_damage > self.sp
  96.         # Jika memakai opsi OVERFLOW
  97.         if OVERFLOW
  98.           @overflow = @sp_damage - self.sp
  99.           self.sp -= @sp_damage - @overflow
  100.           self.hp -= @overflow
  101.         # Jika tidak.
  102.         else
  103.           @overflow = @sp_damage - self.sp
  104.           self.sp -= @sp_damage - @overflow
  105.         end
  106.         for s in HALF_STATE
  107.           @states.delete(s) if AUTO_REMOVE
  108.           @states_turn.delete(s) if AUTO_REMOVE
  109.         end
  110.       end
  111.      
  112.     elsif HALF_DAMAGE_STATE.any?{|s| @states.include?(s)}
  113.       @sp_damage = self.damage - (self.damage / 2)
  114.       self.sp -= @sp_damage
  115.      
  116.       if @sp_damage > self.sp
  117.         # Jika memakai opsi OVERFLOW
  118.         if OVERFLOW
  119.           @overflow = @sp_damage - self.sp
  120.           self.sp -= @sp_damage - @overflow
  121.           self.hp -= @overflow
  122.         # Jika tidak.
  123.         else
  124.           @overflow = @sp_damage - self.sp
  125.           self.sp -= @sp_damage - @overflow
  126.         end
  127.         for s in HALF_STATE
  128.           @states.delete(s) if AUTO_REMOVE
  129.           @states_turn.delete(s) if AUTO_REMOVE
  130.         end
  131.       end
  132.      
  133.     else
  134.       self.hp -= self.damage
  135.     end
  136.   end
  137.  
  138.   #----------------------------------------------------------------------------
  139.   # ATTACK EFFECT
  140.   #----------------------------------------------------------------------------
  141.   def attack_effect(attacker)
  142.     # Clear critical flag
  143.     self.critical = false
  144.     # First hit detection
  145.     hit_result = (rand(100) < attacker.hit)
  146.     # If hit occurs
  147.     if hit_result == true
  148.       # Calculate basic damage
  149.       atk = [attacker.atk - self.pdef / 2, 0].max
  150.       self.damage = atk * (20 + attacker.str) / 20
  151.       # Element correction
  152.       self.damage *= elements_correct(attacker.element_set)
  153.       self.damage /= 100
  154.       # If damage value is strictly positive
  155.       if self.damage > 0
  156.         # Critical correction
  157.         if rand(100) < 4 * attacker.dex / self.agi
  158.           self.damage *= 2
  159.           self.critical = true
  160.         end
  161.         # Guard correction
  162.         if self.guarding?
  163.           self.damage /= 2
  164.         end
  165.       end
  166.       # Dispersion
  167.       if self.damage.abs > 0
  168.         asp = [self.damage.abs * 15 / 100, 1].max
  169.         self.damage += rand(asp+1) + rand(asp+1) - asp
  170.       end
  171.       # Second hit detection
  172.       eva = 8 * self.agi / attacker.dex + self.eva
  173.       hit = self.damage < 0 ? 100 : 100 - eva
  174.       hit = self.cant_evade? ? 100 : hit
  175.       hit_result = (rand(100) < hit)
  176.     end
  177.     # If hit occurs
  178.     if hit_result == true
  179.       # State Removed by Shock
  180.       remove_states_shock
  181.       # Substract damage from HP
  182.       check_mana_shield
  183.       # State change
  184.       @state_changed = false
  185.       states_plus(attacker.plus_state_set)
  186.       states_minus(attacker.minus_state_set)
  187.     # When missing
  188.     else
  189.       # Set damage to "Miss"
  190.       self.damage = "Miss"
  191.       # Clear critical flag
  192.       self.critical = false
  193.     end
  194.     # End Method
  195.     return true
  196.   end
  197.  
  198.   #----------------------------------------------------------------------------
  199.   # SKILL EFFECT
  200.   #----------------------------------------------------------------------------
  201.   def skill_effect(user, skill)
  202.     # Clear critical flag
  203.     self.critical = false
  204.     # If skill scope is for ally with 1 or more HP, and your own HP = 0,
  205.     # or skill scope is for ally with 0, and your own HP = 1 or more
  206.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  207.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  208.       # End Method
  209.       return false
  210.     end
  211.     # Clear effective flag
  212.     effective = false
  213.     # Set effective flag if common ID is effective
  214.     effective |= skill.common_event_id > 0
  215.     # First hit detection
  216.     hit = skill.hit
  217.     if skill.atk_f > 0
  218.       hit *= user.hit / 100
  219.     end
  220.     hit_result = (rand(100) < hit)
  221.     # Set effective flag if skill is uncertain
  222.     effective |= hit < 100
  223.     # If hit occurs
  224.     if hit_result == true
  225.       # Calculate power
  226.       power = skill.power + user.atk * skill.atk_f / 100
  227.       if power > 0
  228.         power -= self.pdef * skill.pdef_f / 200
  229.         power -= self.mdef * skill.mdef_f / 200
  230.         power = [power, 0].max
  231.       end
  232.       # Calculate rate
  233.       rate = 20
  234.       rate += (user.str * skill.str_f / 100)
  235.       rate += (user.dex * skill.dex_f / 100)
  236.       rate += (user.agi * skill.agi_f / 100)
  237.       rate += (user.int * skill.int_f / 100)
  238.       # Calculate basic damage
  239.       self.damage = power * rate / 20
  240.       # Element correction
  241.       self.damage *= elements_correct(skill.element_set)
  242.       self.damage /= 100
  243.       # If damage value is strictly positive
  244.       if self.damage > 0
  245.         # Guard correction
  246.         if self.guarding?
  247.           self.damage /= 2
  248.         end
  249.       end
  250.       # Dispersion
  251.       if skill.variance > 0 and self.damage.abs > 0
  252.         amp = [self.damage.abs * skill.variance / 100, 1].max
  253.         self.damage += rand(amp+1) + rand(amp+1) - amp
  254.       end
  255.       # Second hit detection
  256.       eva = 8 * self.agi / user.dex + self.eva
  257.       hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  258.       hit = self.cant_evade? ? 100 : hit
  259.       hit_result = (rand(100) < hit)
  260.       # Set effective flag if skill is uncertain
  261.       effective |= hit < 100
  262.     end
  263.     # If hit occurs
  264.     if hit_result == true
  265.       # If physical attack has power other than 0
  266.       if skill.power != 0 and skill.atk_f > 0
  267.         # State Removed by Shock
  268.         remove_states_shock
  269.         # Set to effective flag
  270.         effective = true
  271.       end
  272.       # Substract damage from HP
  273.       last_hp = self.hp
  274.       check_mana_shield if SKILL_PROTECTION
  275.       effective |= self.hp != last_hp
  276.       # State change
  277.       @state_changed = false
  278.       effective |= states_plus(skill.plus_state_set)
  279.       effective |= states_minus(skill.minus_state_set)
  280.       # If power is 0
  281.       if skill.power == 0
  282.         # Set damage to an empty string
  283.         self.damage = ""
  284.         # If state is unchanged
  285.         unless @state_changed
  286.           # Set damage to "Miss"
  287.           self.damage = "Miss"
  288.         end
  289.       end
  290.     # If miss occurs
  291.     else
  292.       # Set damage to "Miss"
  293.       self.damage = "Miss"
  294.     end
  295.     # If not in battle
  296.     unless $game_temp.in_battle
  297.       # Set damage to nil
  298.       self.damage = nil
  299.     end
  300.     # End Method
  301.     return effective
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # SLIP DAMAGE EFFECT
  305.   #--------------------------------------------------------------------------
  306.   def slip_damage_effect
  307.     # Set damage
  308.     self.damage = self.maxhp / 10
  309.     # Dispersion
  310.     if self.damage.abs > 0
  311.       amp = [self.damage.abs * 15 / 100, 1].max
  312.       self.damage += rand(amp+1) + rand(amp+1) - amp
  313.     end
  314.     # Subtract damage from HP
  315.     check_mana_shield if SLIP_DAMAGE_PROTECTION
  316.     # End Method
  317.     return true
  318.   end
  319.   #============================================================================
  320.   # END OF SCRIPT
  321.   #============================================================================
  322. end
Advertisement
Add Comment
Please, Sign In to add comment