Code:
# * KDefense XP * #
# Scripter : Kyonides Arkanthes
# 2024-03-05
# This scriptlet allows you to reduce a hero's or monster's PDEF or MDEF.
# If the target was inflicted with a PDEF- or MDEF- state, it will lose some
# percent of that stat every single turn till the state wears off.
# The state's PDEF Rate or MDEF Rate will be substracted from your target'script
# PDEF or MDEF as plain points. I find it incovenient to use percents there.
# You cannot remove the effect by simply removing the state.
# Use a specific item or skill to heal your hero or wait till battle is over.
# Configure the KDefense module's Constants to let the script find your new
# states, skills and items. Set any value to 0 if you don't need it.
module KDefense
module ClearDef
PDEF_ITEM = 33
MDEF_ITEM = 34
end
module PlusDef
PDEF_STATE = 17
MDEF_STATE = 18
PDEF_SKILL = 10
MDEF_SKILL = 11
end
module MinusDef
PDEF_STATE = 19
MDEF_STATE = 20
PDEF_SKILL = 10
MDEF_SKILL = 11
end
end
class Game_Battler
include KDefense
alias :kyon_defense_gm_btl_init :initialize
alias :kyon_defense_gm_btl_rcvr :recover_all
alias :kyon_defense_gm_btl_rstb :remove_states_battle
alias :kyon_defense_gm_btl_sde :slip_damage_effect
alias :kyon_defense_gm_btl_skef :skill_effect
alias :kyon_defense_gm_btl_itef :item_effect
alias :kyon_defense_gm_btl_pdef :pdef
alias :kyon_defense_gm_btl_mdef :mdef
def initialize
kyon_defense_gm_btl_init
clear_pdef_extra
clear_mdef_extra
end
def clear_pdef_extra
@pdef_extra = 0
end
def clear_mdef_extra
@mdef_extra = 0
end
def clear_def_extra
clear_pdef_extra
clear_mdef_extra
end
def change_pdef_extra(force, state_id, clear_now)
return false unless force
add_state(state_id)
clear_pdef_extra if clear_now
true
end
def change_mdef_extra(state_id, clear_now)
return false unless force
add_state(state_id)
clear_mdef_extra if clear_now
true
end
def add_pdef_plus(force=true)
change_pdef_extra(force, PlusDef::PDEF_STATE, @pdef_extra < 0)
end
def add_mdef_plus(force=true)
change_mdef_extra(force, PlusDef::MDEF_STATE, @mdef_extra < 0)
end
def add_pdef_minus(force=true)
change_pdef_extra(force, MinusDef::PDEF_STATE, @pdef_extra > 0)
end
def add_mdef_minus(force=true)
change_mdef_extra(force, MinusDef::MDEF_STATE, @mdef_extra > 0)
end
def recover_all
kyon_defense_gm_btl_rcvr
clear_pdef_extra
clear_mdef_extra
end
def remove_states_battle
kyon_defense_gm_btl_rstb
clear_pdef_extra
clear_mdef_extra
end
def slip_damage_effect
result = kyon_defense_gm_btl_sde
if state?(PlusDef::PDEF_STATE)
@pdef_extra += $data_skills[PlusDef::PDEF_STATE].pdef_rate
result |= true
elsif state?(Minus::PDEF_STATE)
@pdef_extra -= $data_skills[MinusDef::PDEF_STATE].pdef_rate
result |= true
end
if state?(PlusDef::MDEF_STATE)
@mdef_extra += $data_skills[PlusDef::MDEF_STATE].mdef_rate
result |= true
elsif state?(MinusDef::MDEF_STATE)
@mdef_extra -= $data_skills[MinusDef::MDEF_STATE].mdef_rate
result |= true
end
result
end
def skill_effect(user, skill)
result = rand(100) < skill.hit
case skill.id
when PlusDef::PDEF_SKILL
return add_pdef_plus(result)
when PlusDef::MDEF_SKILL
return add_mdef_plus(result)
when MinusDef::PDEF_SKILL
return add_pdef_minus(result)
when MinusDef::MDEF_SKILL
return add_mdef_minus(result)
end
kyon_defense_gm_btl_skef(user, skill)
end
def item_effect(item)
case item.id
when ClearDef::PDEF_ITEM
clear_pdef_extra
return true
when ClearDef::MDEF_ITEM
clear_mdef_extra
return true
end
kyon_defense_gm_btl_itef(item)
end
def pdef
[kyon_defense_gm_btl_pdef + @pdef_extra, 0].max
end
def mdef
[kyon_defense_gm_btl_mdef + @mdef_extra, 0].max
end
attr_accessor :pdef_extra, :mdef_extra
end