# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: TP Control system. ║ Version: 1.00 ║
# ║ Author: Roninator2 ║ ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function: ║ Date Created ║
# ║ ╠════════════════════╣
# ║ Control TP damage ║ 06 Oct 2024 ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description: ║
# ║ Aloow control over TP for actors and enemies ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions: ║
# ║ Place note tag on skill <physical> or <magical> ║
# ║ physical will cause damage to PD first then HP ║
# ║ magical will cause damage to MD first then HP ║
# ║ If a skill has both note tags then PD is used first then MD ║
# ║ ║
# ║ Note tag a skill with <tp damage> to cause TP loss ║
# ║ The skill must be configured for mp damage ║
# ║ ║
# ║ Note tag a skill with <tp drain> to grab TP from the enemy ║
# ║ The skill must be configured for mp drain ║
# ║ ║
# ║ Note tag a skill with <tp recover> to gain TP ║
# ║ The skill must be configured with a feature for mp recovery ║
# ║ or mp recovery for the damage type ║
# ║ The amount of TP recovered will be the amount in the feature ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates: ║
# ║ 1.00 - 01 Aug 2024 - Script finished ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks: ║
# ║ Roninator2 ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use: ║
# ║ Follow the original Authors terms of use where applicable ║
# ║ - When not made by me (Roninator2) ║
# ║ Free for all uses in RPG Maker except nudity ║
# ║ Anyone using this script in their project before these terms ║
# ║ were changed are allowed to use this script even if it conflicts ║
# ║ with these new terms. New terms effective 03 Apr 2024 ║
# ║ No part of this code can be used with AI programs or tools ║
# ║ Credit must be given ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ End of editable region ║
# ╚════════════════════════════════════════════════════════════════════╝
#==============================================================================
# ■ Module
#==============================================================================
module R2_Skill_PD_MD
PHYSICAL = /<physical>/i
MAGICAL = /<magical>/i
TP_DRAIN = /<tp drain>/i
TP_DAMAGE = /<tp damage>/i
TP_RECOVER = /<tp recover>/i
end
# type
# The type of damage.
# 0: None
# 1: HP damage
# 2: MP damage
# 3: HP recovery
# 4: MP recovery
# 5: HP drain
# 6: MP drain
# 7: TP drain
# 8: TP recovery
# 9: TP damage
class RPG::UsableItem::Damage
def to_tp?
[7,8,9].include?(@type)
end
def drain?
[5,6,7].include?(@type)
end
def recover?
[3,4,8].include?(@type)
end
end
#==============================================================================
# ■ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_r2_skill_type load_database; end
def self.load_database
load_database_r2_skill_type
load_notetags_r2_skill_pdmd
load_notetags_r2_item_pdmd
end
#--------------------------------------------------------------------------
# new method: load_notetags_lse
#--------------------------------------------------------------------------
def self.load_notetags_r2_skill_pdmd
for r2skpdmd in $data_skills
next if r2skpdmd.nil?
r2skpdmd.load_notetags_r2_skill_pdmd
end
end
#--------------------------------------------------------------------------
# new method: load_notetags_lse
#--------------------------------------------------------------------------
def self.load_notetags_r2_item_pdmd
for r2skpdmd in $data_items
next if r2skpdmd.nil?
r2skpdmd.load_notetags_r2_item_pdmd
end
end
end # DataManager
#==============================================================================
# ■ RPG::Skill
#==============================================================================
class RPG::Skill < RPG::UsableItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :sk_pd, :sk_md
#--------------------------------------------------------------------------
# common cache: load_notetags_lse
#--------------------------------------------------------------------------
def load_notetags_r2_skill_pdmd
@sk_pd = false
@sk_md = false
self.note.split(/[\r\n]+/).each { |line|
case line
when R2_Skill_PD_MD::PHYSICAL
@sk_pd = true
when R2_Skill_PD_MD::MAGICAL
@sk_md = true
when R2_Skill_PD_MD::TP_DRAIN
self.damage.type = 7 if self.damage.type == 6
when R2_Skill_PD_MD::TP_DAMAGE
self.damage.type = 9 if self.damage.type == 2
when R2_Skill_PD_MD::TP_RECOVER
self.damage.type = 8 if self.damage.type == 4
self.effects.each do |ef|
ef.code = 14 if ef.code == 12
end
end
}
end
end
#==============================================================================
# ■ RPG::Skill
#==============================================================================
class RPG::Item < RPG::UsableItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :sk_pd, :sk_md
#--------------------------------------------------------------------------
# common cache: load_notetags_lse
#--------------------------------------------------------------------------
def load_notetags_r2_item_pdmd
@sk_pd = false
@sk_md = false
self.note.split(/[\r\n]+/).each { |line|
case line
when R2_Skill_PD_MD::PHYSICAL
@sk_pd = true
when R2_Skill_PD_MD::MAGICAL
@sk_md = true
when R2_Skill_PD_MD::TP_DRAIN
self.damage.type = 7 if self.damage.type == 6
when R2_Skill_PD_MD::TP_DAMAGE
self.damage.type = 9 if self.damage.type == 2
when R2_Skill_PD_MD::TP_RECOVER
self.damage.type = 8 if self.damage.type == 4
self.effects.each do |ef|
ef.code = 14 if ef.code == 12
end
end
}
end
end
#==============================================================================
# ** Game_ActionResult
#------------------------------------------------------------------------------
# This class handles the results of battle actions. It is used internally for
# the Game_Battler class.
#==============================================================================
class Game_ActionResult
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :tp_drain # TP drain
#--------------------------------------------------------------------------
# * Clear Damage Values
#--------------------------------------------------------------------------
def clear_damage_values
@hp_damage = 0
@mp_damage = 0
@tp_damage = 0
@hp_drain = 0
@mp_drain = 0
@tp_drain = 0
end
end
#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
EFFECT_RECOVER_TP = 14 # MP Recovery
#--------------------------------------------------------------------------
# * Test Effect
#--------------------------------------------------------------------------
def item_effect_test(user, item, effect)
case effect.code
when EFFECT_RECOVER_HP
hp < mhp || effect.value1 < 0 || effect.value2 < 0
when EFFECT_RECOVER_MP
mp < mmp || effect.value1 < 0 || effect.value2 < 0
when EFFECT_RECOVER_TP
tp < mtp || effect.value1 < 0 || effect.value2 < 0
when EFFECT_ADD_STATE
!state?(effect.data_id)
when EFFECT_REMOVE_STATE
state?(effect.data_id)
when EFFECT_ADD_BUFF
!buff_max?(effect.data_id)
when EFFECT_ADD_DEBUFF
!debuff_max?(effect.data_id)
when EFFECT_REMOVE_BUFF
buff?(effect.data_id)
when EFFECT_REMOVE_DEBUFF
debuff?(effect.data_id)
when EFFECT_LEARN_SKILL
actor? && !skills.include?($data_skills[effect.data_id])
else
true
end
end
#--------------------------------------------------------------------------
# * Initialize TP
#--------------------------------------------------------------------------
def init_tp
self.tp = (rand * 25).to_i
end
#--------------------------------------------------------------------------
# * Effect of Skill/Item on Using Side
#--------------------------------------------------------------------------
def item_user_effect(user, item)
user.tp += (item.tp_gain * user.tcr).to_i
end
#--------------------------------------------------------------------------
# * Charge TP by Damage Suffered
#--------------------------------------------------------------------------
def charge_tp_by_damage(damage_rate)
self.tp += (50 * damage_rate * tcr).to_i
end
#--------------------------------------------------------------------------
# * Damage Processing
# @result.hp_damage @result.mp_damage @result.hp_drain
# @result.mp_drain must be set before call.
#--------------------------------------------------------------------------
def execute_damage(user)
on_damage(@result.hp_damage) if @result.hp_damage > 0
self.hp -= @result.hp_damage.to_i
self.mp -= @result.mp_damage.to_i
self.tp -= @result.tp_damage.to_i
user.hp += @result.hp_drain.to_i
user.mp += @result.mp_drain.to_i
user.tp += @result.tp_drain.to_i
end
#--------------------------------------------------------------------------
# * Calculate Damage
#--------------------------------------------------------------------------
def make_damage_value(user, item)
value = item.damage.eval(user, self, $game_variables)
value *= item_element_rate(user, item)
type = 0
type = 1 if item.sk_pd
type = 2 if item.sk_md
type = 3 if item.sk_md && item.sk_pd
value *= rec if item.damage.recover?
value = apply_critical(value) if @result.critical
value = apply_variance(value, item.damage.variance)
value = apply_guard(value)
@result.make_damage(value.to_i, item, type)
end
#--------------------------------------------------------------------------
# * [TP Recovery] Effect
#--------------------------------------------------------------------------
def item_effect_recover_tp(user, item, effect)
value = (mtp * effect.value1 + effect.value2) * rec
value *= user.pha if item.is_a?(RPG::Item)
value = value.to_i
@result.tp_damage -= value
@result.success = true if value != 0
self.tp += value
end
#--------------------------------------------------------------------------
# * Apply Effect
#--------------------------------------------------------------------------
def item_effect_apply(user, item, effect)
method_table = {
EFFECT_RECOVER_HP => :item_effect_recover_hp,
EFFECT_RECOVER_MP => :item_effect_recover_mp,
EFFECT_RECOVER_TP => :item_effect_recover_tp,
EFFECT_GAIN_TP => :item_effect_gain_tp,
EFFECT_ADD_STATE => :item_effect_add_state,
EFFECT_REMOVE_STATE => :item_effect_remove_state,
EFFECT_ADD_BUFF => :item_effect_add_buff,
EFFECT_ADD_DEBUFF => :item_effect_add_debuff,
EFFECT_REMOVE_BUFF => :item_effect_remove_buff,
EFFECT_REMOVE_DEBUFF => :item_effect_remove_debuff,
EFFECT_SPECIAL => :item_effect_special,
EFFECT_GROW => :item_effect_grow,
EFFECT_LEARN_SKILL => :item_effect_learn_skill,
EFFECT_COMMON_EVENT => :item_effect_common_event,
}
method_name = method_table[effect.code]
send(method_name, user, item, effect) if method_name
end
#--------------------------------------------------------------------------
# * Processing at End of Battle
#--------------------------------------------------------------------------
def on_battle_end
@result.clear
remove_battle_states
remove_all_buffs
clear_actions
appear
end
#--------------------------------------------------------------------------
# * Test Skill/Item Application
# Used to determine, for example, if a character is already fully healed
# and so cannot recover anymore.
#--------------------------------------------------------------------------
def item_test(user, item)
return false if item.for_dead_friend? != dead?
return true if $game_party.in_battle
return true if item.for_opponent?
return true if item.damage.recover? && item.damage.to_hp? && hp < mhp
return true if item.damage.recover? && item.damage.to_mp? && mp < mmp
return true if item.damage.recover? && item.damage.to_tp? && tp < mtp
return true if item_has_any_valid_effects?(user, item)
return false
end
end
class Game_ActionResult
#--------------------------------------------------------------------------
# * Create Damage
#--------------------------------------------------------------------------
def make_damage(value, item, type = 0)
@critical = false if value == 0
@mp_damage = @tp_damage = 0
case type
when 1
@mp_damage = value
@mp_damage = [@battler.mp, @mp_damage].min
value = value - @mp_damage
when 2
@tp_damage = value
@tp_damage = [@battler.tp, @tp_damage].min
value = value - @tp_damage
when 3
@mp_damage = value
@mp_damage = [@battler.mp, @mp_damage].min
value = value - @mp_damage
@tp_damage = value
@tp_damage = [@battler.tp, @tp_damage].min
value = value - @tp_damage
else
@hp_damage = value if item.damage.to_hp?
@mp_damage = value if item.damage.to_mp?
@mp_damage = [@battler.mp, @mp_damage].min
@tp_damage = value if item.damage.to_tp?
@tp_damage = [@battler.tp, @tp_damage].min
end
@hp_damage = value if item.damage.to_hp?
@hp_drain = @hp_damage if item.damage.drain?
@mp_drain = @mp_damage if item.damage.drain?
@tp_drain = @tp_damage if item.damage.drain?
@hp_drain = [@battler.hp, @hp_drain].min
@success = true if item.damage.to_hp? || @mp_damage != 0 || @tp_damage != 0
end
end