Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # [RGSS] Mana Shield
- # Version : 1.1
- # Author : LowlingLife
- #==============================================================================
- # Membuat state yang membuat damage di-deal ke SP, bukan ke HP.
- #==============================================================================
- # CHANGELOG :
- # V. 1.0 | Initial Release
- # V. 1.1 | Add Half Damage State
- #==============================================================================
- module ManaShield
- # ID dari State yang akan mengalihkan damage ke SP secara Full.
- FULL_STATE = [17, 18, 19]
- # ID dari State dimana separuh damage dialihkan ke SP dan separuh lagi
- # dialihkan ke HP.
- HALF_STATE = [20, 21, 22]
- # ID dari State dimana hanya separuh damage yang dialihkan ke SP tapi
- # separuhnya tidak dialihkan ke HP.
- HALF_DAMAGE_STATE = [23, 24, 25]
- # Set ke true jika ingin memakai fitur Overflow. Jika Damage yang di-deal
- # lebih besar daripada SP, sisanya akan di deal ke HP.
- OVERFLOW = false
- # Set ke true jika ingin Mana Shield State otomatis di-remove setelah
- # mendapat damage yang lebih besar dari pada SP.
- # Note : Uncheck Release at the end of battle jika menggunakan opsi ini.
- AUTO_REMOVE = true
- # Set ke true jika ingin agar Mana Shield tetap men-deal damage yang
- # disebabkan Skill ke SP.
- SKILL_PROTECTION = true
- # Set ke true jika ingin agar Mana Shield tetap men-deal damage yang
- # disebakan Slip Damage ke SP.
- SLIP_DAMAGE_PROTECTION = true
- end
- #==============================================================================
- # EDITING BEYOND THIS LINE CAN CAUSE DAMAGE TO YOUR GAME. THEREFORE, EDIT
- # WITH YOUR OWN RISK!
- #==============================================================================
- class Game_Battler
- include ManaShield
- attr_accessor :overflow
- attr_accessor :sp_damage
- attr_accessor :hp_damage
- #----------------------------------------------------------------------------
- # INITIALIZE
- #----------------------------------------------------------------------------
- alias mana_shield_initialize initialize unless $@
- def initialize
- # Run the old method
- mana_shield_initialize
- @overflow = 0
- @sp_damage = 0
- @hp_damage = 0
- end
- #----------------------------------------------------------------------------
- # CHECK MANA SHIELD
- #----------------------------------------------------------------------------
- def check_mana_shield
- if FULL_STATE.any?{|s| @states.include?(s)}
- @sp_damage = self.damage
- self.sp -= @sp_damage
- if @sp_damage > self.sp
- # Jika memakai opsi OVERFLOW
- if OVERFLOW
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- self.hp -= @overflow
- # Jika tidak.
- else
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- end
- for s in FULL_STATE
- @states.delete(s) if AUTO_REMOVE
- @states_turn.delete(s) if AUTO_REMOVE
- end
- end
- elsif HALF_STATE.any?{|s| @states.include?(s)}
- @sp_damage = self.damage - (self.damage / 2)
- @hp_damage = self.damage - (self.damage / 2)
- self.sp -= @sp_damage
- self.hp -= @hp_damage
- if @sp_damage > self.sp
- # Jika memakai opsi OVERFLOW
- if OVERFLOW
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- self.hp -= @overflow
- # Jika tidak.
- else
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- end
- for s in HALF_STATE
- @states.delete(s) if AUTO_REMOVE
- @states_turn.delete(s) if AUTO_REMOVE
- end
- end
- elsif HALF_DAMAGE_STATE.any?{|s| @states.include?(s)}
- @sp_damage = self.damage - (self.damage / 2)
- self.sp -= @sp_damage
- if @sp_damage > self.sp
- # Jika memakai opsi OVERFLOW
- if OVERFLOW
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- self.hp -= @overflow
- # Jika tidak.
- else
- @overflow = @sp_damage - self.sp
- self.sp -= @sp_damage - @overflow
- end
- for s in HALF_STATE
- @states.delete(s) if AUTO_REMOVE
- @states_turn.delete(s) if AUTO_REMOVE
- end
- end
- else
- self.hp -= self.damage
- end
- end
- #----------------------------------------------------------------------------
- # ATTACK EFFECT
- #----------------------------------------------------------------------------
- def attack_effect(attacker)
- # Clear critical flag
- self.critical = false
- # First hit detection
- hit_result = (rand(100) < attacker.hit)
- # If hit occurs
- if hit_result == true
- # Calculate basic damage
- atk = [attacker.atk - self.pdef / 2, 0].max
- self.damage = atk * (20 + attacker.str) / 20
- # Element correction
- self.damage *= elements_correct(attacker.element_set)
- self.damage /= 100
- # If damage value is strictly positive
- if self.damage > 0
- # Critical correction
- if rand(100) < 4 * attacker.dex / self.agi
- self.damage *= 2
- self.critical = true
- end
- # Guard correction
- if self.guarding?
- self.damage /= 2
- end
- end
- # Dispersion
- if self.damage.abs > 0
- asp = [self.damage.abs * 15 / 100, 1].max
- self.damage += rand(asp+1) + rand(asp+1) - asp
- end
- # Second hit detection
- eva = 8 * self.agi / attacker.dex + self.eva
- hit = self.damage < 0 ? 100 : 100 - eva
- hit = self.cant_evade? ? 100 : hit
- hit_result = (rand(100) < hit)
- end
- # If hit occurs
- if hit_result == true
- # State Removed by Shock
- remove_states_shock
- # Substract damage from HP
- check_mana_shield
- # State change
- @state_changed = false
- states_plus(attacker.plus_state_set)
- states_minus(attacker.minus_state_set)
- # When missing
- else
- # Set damage to "Miss"
- self.damage = "Miss"
- # Clear critical flag
- self.critical = false
- end
- # End Method
- return true
- end
- #----------------------------------------------------------------------------
- # SKILL EFFECT
- #----------------------------------------------------------------------------
- def skill_effect(user, skill)
- # Clear critical flag
- self.critical = false
- # If skill scope is for ally with 1 or more HP, and your own HP = 0,
- # or skill scope is for ally with 0, and your own HP = 1 or more
- if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
- ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
- # End Method
- return false
- end
- # Clear effective flag
- effective = false
- # Set effective flag if common ID is effective
- effective |= skill.common_event_id > 0
- # First hit detection
- hit = skill.hit
- if skill.atk_f > 0
- hit *= user.hit / 100
- end
- hit_result = (rand(100) < hit)
- # Set effective flag if skill is uncertain
- effective |= hit < 100
- # If hit occurs
- if hit_result == true
- # Calculate power
- power = skill.power + user.atk * skill.atk_f / 100
- if power > 0
- power -= self.pdef * skill.pdef_f / 200
- power -= self.mdef * skill.mdef_f / 200
- power = [power, 0].max
- end
- # Calculate rate
- rate = 20
- rate += (user.str * skill.str_f / 100)
- rate += (user.dex * skill.dex_f / 100)
- rate += (user.agi * skill.agi_f / 100)
- rate += (user.int * skill.int_f / 100)
- # Calculate basic damage
- self.damage = power * rate / 20
- # Element correction
- self.damage *= elements_correct(skill.element_set)
- self.damage /= 100
- # If damage value is strictly positive
- if self.damage > 0
- # Guard correction
- if self.guarding?
- self.damage /= 2
- end
- end
- # Dispersion
- if skill.variance > 0 and self.damage.abs > 0
- amp = [self.damage.abs * skill.variance / 100, 1].max
- self.damage += rand(amp+1) + rand(amp+1) - amp
- end
- # Second hit detection
- eva = 8 * self.agi / user.dex + self.eva
- hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
- hit = self.cant_evade? ? 100 : hit
- hit_result = (rand(100) < hit)
- # Set effective flag if skill is uncertain
- effective |= hit < 100
- end
- # If hit occurs
- if hit_result == true
- # If physical attack has power other than 0
- if skill.power != 0 and skill.atk_f > 0
- # State Removed by Shock
- remove_states_shock
- # Set to effective flag
- effective = true
- end
- # Substract damage from HP
- last_hp = self.hp
- check_mana_shield if SKILL_PROTECTION
- effective |= self.hp != last_hp
- # State change
- @state_changed = false
- effective |= states_plus(skill.plus_state_set)
- effective |= states_minus(skill.minus_state_set)
- # If power is 0
- if skill.power == 0
- # Set damage to an empty string
- self.damage = ""
- # If state is unchanged
- unless @state_changed
- # Set damage to "Miss"
- self.damage = "Miss"
- end
- end
- # If miss occurs
- else
- # Set damage to "Miss"
- self.damage = "Miss"
- end
- # If not in battle
- unless $game_temp.in_battle
- # Set damage to nil
- self.damage = nil
- end
- # End Method
- return effective
- end
- #--------------------------------------------------------------------------
- # SLIP DAMAGE EFFECT
- #--------------------------------------------------------------------------
- def slip_damage_effect
- # Set damage
- self.damage = self.maxhp / 10
- # Dispersion
- if self.damage.abs > 0
- amp = [self.damage.abs * 15 / 100, 1].max
- self.damage += rand(amp+1) + rand(amp+1) - amp
- end
- # Subtract damage from HP
- check_mana_shield if SLIP_DAMAGE_PROTECTION
- # End Method
- return true
- end
- #============================================================================
- # END OF SCRIPT
- #============================================================================
- end
Advertisement
Add Comment
Please, Sign In to add comment