# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: Recover Tech Points Options ║ Version: 1.05 ║
# ║ Author: Roninator2 ║ ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function: ║ Date Created ║
# ║ ╠════════════════════╣
# ║ Provide additional methods of recovering ║ 05 Sep 2024 ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: Victor Sant Base Module ║
# ║ Victor Ssnt Tech Points ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description: ║
# ║ Use item to recover tech points ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions: ║
# ║ Use note tags on item when the item is designed to recover ║
# ║ a specific amount of points on a specific skill ║
# ║ <TECH RECOVER> <- required ║
# ║ <RECOVER TECH POINT: X> <- X equals the points to recover ║
# ║ ║
# ║ Use the hp recover damage type and specify a formula ║
# ║ Have the item set to use on 1 ally ║
# ║ b.restore_tech_points(X) <- X equals the points to recover ║
# ║ A window to select the skill will pop up ║
# ║ Must be an item. Item is returned if no tech points given ║
# ║ ║
# ║ To recover all points for skills with an actor use formula ║
# ║ b.restore_all_techs ║
# ║ Must be an item. Item is returned if no tech points given ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates: ║
# ║ 1.00 - 05 Sep 2024 - Script finished ║
# ║ 1.01 - 05 Sep 2024 - Updated for battles ║
# ║ 1.02 - 05 Sep 2024 - Stopped item consumption if tech is full ║
# ║ 1.03 - 10 Sep 2024 - Fixed Battle usage of tech items ║
# ║ 1.04 - 10 Sep 2024 - Fixed bugs ║
# ║ 1.05 - 11 Sep 2024 - Fixed bad code ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ 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 ║
# ╚════════════════════════════════════════════════════════════════════╝
#==============================================================================
# ** RPG::UsableItem
#------------------------------------------------------------------------------
# This is the superclass for skills and items.
#==============================================================================
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# * New method: recover_tech_points
#--------------------------------------------------------------------------
def recover_tech_points
regexp = /<RECOVER TECH POINT: (\d+)>/i
note.scan(regexp).collect { {value: $1.to_i} }
end
#--------------------------------------------------------------------------
# * New method: is_tech_recover?
#--------------------------------------------------------------------------
def is_tech_recover?
note =~ /<TECH RECOVER>/i ? true : false
end
end
#==============================================================================
# ** Game_BattlerBase
#------------------------------------------------------------------------------
# This class handles battlers. It's used as a superclass of the Game_Battler
# classes.
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# * New method: draw_tech_points_cost
#--------------------------------------------------------------------------
def skill_tech_points?(skill)
return true if get_all_notes =~ /<INFINITE TECH POINTS>/i
return true if self.is_a?(Game_Enemy)
setup_tech(skill.id) if !@tech_skills[skill.id]
@tech_skills[skill.id][:now] > 0
end
#--------------------------------------------------------------------------
# new method: make_miss_popups
#--------------------------------------------------------------------------
alias r2_make_popup_block_tech_item make_miss_popups
def make_miss_popups(user, item)
if item.damage.formula.include?("restore_tech_points") ||
item.damage.formula.include?("restore_all_techs") ||
item.is_tech_recover?
return
end
r2_make_popup_block_tech_item(user, item)
end
end
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * New method: restore_tech_points
#--------------------------------------------------------------------------
def restore_tech_points(value)
imp = false
item = $game_party.last_item.object
@equip_skills.each {|id|
next if id == 0
sk = $data_skills[id]
next if !sk.is_tech_skill?
setup_tech(id) if !@tech_skills[id]
next if tech_point(id) == tech_max(id)
@tech_skills[id][:now] += value
@tech_skills[id][:now] == @tech_skills[id][:max] if @tech_skills[id][:now] > @tech_skills[id][:max]
refresh_tech(id)
imp = true
}
if imp == false
$game_party.gain_item(item, 1)
Sound.play_buzzer
end
end
#--------------------------------------------------------------------------
# * New method: restore_all_techs
#--------------------------------------------------------------------------
def restore_all_techs
imp = false
item = $game_party.last_item.object
@skills.each {|id|
next if id == 0
sk = $data_skills[id]
next if !sk.is_tech_skill?
setup_tech(id) if !@tech_skills[id]
next if tech_point(id) == tech_max(id)
@tech_skills[id][:now] = @tech_skills[id][:max]
refresh_tech(id)
imp = true
}
if imp == false
$game_party.gain_item(item, 1)
Sound.play_buzzer
end
end
end
#==============================================================================
# ¡ Window_SkillList_Item
#==============================================================================
class Window_SkillList_Item < Window_SkillList
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
self.hide
self.index = 0
select(-1)
end
#--------------------------------------------------------------------------
# col_max
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# enable?
#--------------------------------------------------------------------------
def enable?(item)
@actor
end
#--------------------------------------------------------------------------
# include?
#--------------------------------------------------------------------------
def include?(item)
item
end
#--------------------------------------------------------------------------
# make_item_list
#--------------------------------------------------------------------------
def make_item_list
super
@data = @data.select{|s| s.is_tech_skill?}
end
#--------------------------------------------------------------------------
# draw_item
#--------------------------------------------------------------------------
def draw_item(index)
draw_text(0, 0, self.width-24, 24, @actor.name, 2)
skill = @data[index]
rect = item_rect(index)
rect.width -= 4
rect.y += line_height
draw_item_name(skill, rect.x, rect.y, enable?(skill))
end
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
alias r2_cursor_pos_down update_cursor
def update_cursor
r2_cursor_pos_down
cursor_rect.y += line_height
end
#--------------------------------------------------------------------------
# * Processing When OK Button Is Pressed
#--------------------------------------------------------------------------
def process_ok
if @index < 0
select_last
return
end
call_ok_handler
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def select_last
select(0)
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def actor(act)
@actor = act
end
end
#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
# This class performs the item screen processing.
#==============================================================================
class Scene_Item < Scene_ItemBase
#--------------------------------------------------------------------------
# alias method: start
#--------------------------------------------------------------------------
alias r2_skill_equip_start start
def start
r2_skill_equip_start
create_skill_equip_window
end
#--------------------------------------------------------------------------
# new method: create_skill_equip_window
#--------------------------------------------------------------------------
def create_skill_equip_window
wx = 0
wy = 100
ww = Graphics.width / 2
wh = Graphics.height - wy
@skill_recover = Window_SkillList_Item.new(wx, wy, ww, wh)
@skill_recover.z = 1000
@skill_recover.actor = @actor
@skill_recover.set_handler(:ok, method(:on_skill_item_ok))
@skill_recover.set_handler(:cancel, method(:on_skill_item_cancel))
@skill_recover.deactivate.hide
end
#--------------------------------------------------------------------------
# new method: on_skill_equip_ok
#--------------------------------------------------------------------------
def on_skill_item_ok
return if @skill_recover.item == nil
id = @skill_recover.item.id
value = item.recover_tech_points[0][:value]
Sound.play_buzzer if @actor.tech_point(id) == @actor.tech_max(id)
return if @actor.tech_point(id) == @actor.tech_max(id)
@actor.change_tech_points(id, value)
r2_item_skill_tech_recover
if !$game_party.has_item?(item)
@skill_recover.deactivate.hide
on_actor_cancel
end
end
#--------------------------------------------------------------------------
# new method: on_skill_equip_cancel
#--------------------------------------------------------------------------
def on_skill_item_cancel
@skill_recover.deactivate.hide
@actor_window.activate
@skill_recover.actor(nil)
@skill_recover.select(-1)
end
#--------------------------------------------------------------------------
# * Use Item
#--------------------------------------------------------------------------
alias r2_item_skill_tech_recover use_item
def use_item
@actor = $game_party.members[@actor_window.index]
if item.is_tech_recover? && item.recover_tech_points[0]
$game_party.last_item.object = item
@actor_window.deactivate
@skill_recover.actor(@actor)
@skill_recover.refresh
@skill_recover.activate.show
elsif item.damage.formula.include?("restore_tech_points") ||
item.damage.formula.include?("restore_all_techs")
if !actor_tech_rec(item, @actor_window.index)
Sound.play_buzzer
@actor_window.activate
return
end
r2_item_skill_tech_recover
else
r2_item_skill_tech_recover
end
end
#--------------------------------------------------------------------------
# * Actor [OK]
#--------------------------------------------------------------------------
def actor_tech_rec(item, index)
actor = $game_party.members[index]
can_use = false
actor.equip_skills.each { |sk|
can_use = true if actor.tech_point(sk) < actor.tech_max(sk)
}
return can_use
end
end
#==============================================================================
# ** Window_BattleActor
#------------------------------------------------------------------------------
# This window is for selecting an actor's action target on the battle screen.
#==============================================================================
class Window_BattleActor < Window_BattleStatus
#--------------------------------------------------------------------------
# current_item_enabled?
#--------------------------------------------------------------------------
def current_item_enabled?
@item = BattleManager.actor.actions[0].item
if @item.is_a?(RPG::Item) && @item.is_tech_recover?
actor = $game_party.battle_members[@index]
can_use = false
actor.equip_skills.each { |sk|
can_use = true if actor.tech_point(sk) < actor.tech_max(sk)
}
return true if actor && can_use
else
super
end
end
end
#==============================================================================
# ¡ Window_BattleList_Item
#==============================================================================
class Window_BattleList_Item < Window_SkillList
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
self.hide
self.index = 0
select(-1)
end
#--------------------------------------------------------------------------
# col_max
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# enable?
#--------------------------------------------------------------------------
def enable?(item)
@actor
end
#--------------------------------------------------------------------------
# include?
#--------------------------------------------------------------------------
def include?(item)
item
end
#--------------------------------------------------------------------------
# make_item_list
#--------------------------------------------------------------------------
def make_item_list
super
@data = @data.select{|s| s.is_tech_skill?}
end
#--------------------------------------------------------------------------
# draw_item
#--------------------------------------------------------------------------
def draw_item(index)
draw_text(0, 0, self.width-24, 24, @subject.name, 0)
draw_text(0, 0, self.width-24, 24, "->", 1)
draw_text(0, 0, self.width-24, 24, @actor.name, 2)
skill = @data[index]
rect = item_rect(index)
rect.width -= 4
rect.y += line_height
draw_item_name(skill, rect.x, rect.y, enable?(skill))
end
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
alias r2_cursor_pos_down update_cursor
def update_cursor
r2_cursor_pos_down
cursor_rect.y += line_height
end
#--------------------------------------------------------------------------
# * Processing When OK Button Is Pressed
#--------------------------------------------------------------------------
def process_ok
if @index < 0
select_last
return
end
call_ok_handler
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def select_last
select(0)
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def actor(act)
@actor = act
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def subject(act)
@subject = act
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle < Scene_Base
attr_accessor :item_tech_track
#--------------------------------------------------------------------------
# * Create All Windows
#--------------------------------------------------------------------------
alias r2_skill_battle_equip_create_windows create_all_windows
def create_all_windows
r2_skill_battle_equip_create_windows
create_skill_equip_window
@item_tech_track = []
end
#--------------------------------------------------------------------------
# new method: create_skill_equip_window
#--------------------------------------------------------------------------
def create_skill_equip_window
wx = 0
wy = 100
ww = Graphics.width / 2
wh = Graphics.height - wy
@skill_recover = Window_BattleList_Item.new(wx, wy, ww, wh)
@skill_recover.z = 1000
@skill_recover.actor = @actor
@skill_recover.set_handler(:ok, method(:on_skill_item_ok))
@skill_recover.set_handler(:cancel, method(:on_skill_item_cancel))
@skill_recover.deactivate.hide
end
#--------------------------------------------------------------------------
# new method: on_skill_equip_ok
#--------------------------------------------------------------------------
def on_skill_item_ok
id = @skill_recover.item.id
item = @subject.actions[0].item
value = item.recover_tech_points[0][:value]
Sound.play_buzzer if @actor.tech_point(id) == @actor.tech_max(id)
return if @actor.tech_point(id) == @actor.tech_max(id)
@actor.change_tech_points(id, value)
@skill_recover.deactivate.hide
r2_actor_skill_recover_item
end
#--------------------------------------------------------------------------
# new method: on_skill_equip_cancel
#--------------------------------------------------------------------------
def on_skill_item_cancel
@skill_recover.deactivate.hide
end
#--------------------------------------------------------------------------
# * Actor [OK]
#--------------------------------------------------------------------------
alias r2_on_item_actor_recover_tech_ok on_actor_ok
def on_actor_ok
item = @item_window.item
skill = @skill_window.item
last = BattleManager.actor.actions[0].item
if item.is_a?(RPG::Item) && item.is_tech_recover? && item.recover_tech_points[0] &&
item.recover_tech_points[0][:value] > 0 && item == last
if !actor_tech_rec(item, @actor_window.index)
select_actor_selection
return
end
@item_tech_track.push([item, @actor_window.index])
end
if item.is_a?(RPG::Item) && item.is_tech_recover? && item.damage.formula.include?("restore_tech_points") &&
item == last
if !actor_tech_rec(item, @actor_window.index)
select_actor_selection
return
end
end
if item.is_a?(RPG::Item) && item.is_tech_recover? && item.damage.formula.include?("restore_all_techs") &&
item == last
if !actor_tech_rec(item, @actor_window.index)
select_actor_selection
return
end
end
r2_on_item_actor_recover_tech_ok
end
#--------------------------------------------------------------------------
# * Actor [OK]
#--------------------------------------------------------------------------
def actor_tech_rec(item, index)
actor = $game_party.members[index]
can_use = false
actor.equip_skills.each { |sk|
can_use = true if actor.tech_point(sk) < actor.tech_max(sk)
}
return can_use
end
#--------------------------------------------------------------------------
# * Use Skill/Item
#--------------------------------------------------------------------------
alias r2_actor_skill_recover_item use_item
def use_item
item = @subject.current_action.item
i = 0; ind = 0; @actor = nil
if item.is_tech_recover? && item.recover_tech_points[0]
@item_tech_track.each { |lit|
@actor = $game_party.members[lit[1]] if lit[0] == item
ind = i if lit[0] == item
i += 1
}
@actor_window.deactivate
@skill_recover.actor(@actor)
@skill_recover.subject(@subject)
@skill_recover.refresh
@skill_recover.activate.show
@skill_recover.select_last
update_for_wait while @skill_recover.active
elsif item.damage.formula.include?("restore_tech_points") ||
item.damage.formula.include?("restore_all_techs")
if !actor_tech_rec(item, @actor_window.index)
Sound.play_buzzer
@actor_window.activate
return
end
r2_actor_skill_recover_item
else
r2_actor_skill_recover_item
end
end
#--------------------------------------------------------------------------
# * Start Party Command Selection
#--------------------------------------------------------------------------
alias r2_party_select_reset_tech start_party_command_selection
def start_party_command_selection
@item_tech_track = []
r2_party_select_reset_tech
end
end
class Window_BattleLog < Window_Selectable
#--------------------------------------------------------------------------
# * Display HP Damage
#--------------------------------------------------------------------------
alias r2_display_hp_damage_return display_hp_damage
def display_hp_damage(target, item)
if item.damage.formula.include?("restore_tech_points") ||
item.damage.formula.include?("restore_all_techs") ||
item.is_tech_recover?
return
end
r2_display_hp_damage_return(target, item)
end
#--------------------------------------------------------------------------
# * Display Failure
#--------------------------------------------------------------------------
alias r2_display_failure_return display_failure
def display_failure(target, item)
if item.damage.formula.include?("restore_tech_points") ||
item.damage.formula.include?("restore_all_techs") ||
item.is_tech_recover?
return
end
r2_display_failure_return(target, item)
end
end