=begin #============================================================================== ** Auto Removal Author: Hime Date: Nov 10, 2012 ------------------------------------------------------------------------------ ** Change log Nov 10 - updated to allow note-tag in states Nov 9, 2012 - initial release ------------------------------------------------------------------------------ ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Preserve this header ------------------------------------------------------------------------------ This script extends the "auto remove timing" for database objects. The default remove types are 1: end of action: when the battler has finished its turn 2: end of turn: when all battlers have finished their turns I define additional remove types 3: end of skill: immediately after first skill is used Supports weapons, armors, and states. To specify a remove type, tag it with Where x is one of the integers above To specify the remove time, tag it with Where x and y are integers indicating the min and max removal times #============================================================================== =end $imported = {} if $imported.nil? $imported["Tsuki_AutoRemoval"] = true #============================================================================== # ** Configuration #============================================================================= module Tsuki module Auto_Removal # not used just for reference Auto_Remove_Table = { 0 => :none, 1 => :end_of_action, 2 => :end_of_turn, # custom auto remove timings 3 => :end_of_skill } Remove_Regex = //i Timing_Regex = //i end end #============================================================================== # ** Rest of the script #============================================================================= module RPG class BaseItem def remove_min_turns return @remove_min_turns unless @remove_min_turns.nil? load_notetag_auto_removal return @remove_min_turns end def remove_max_turns return @remove_max_turns unless @remove_max_turns.nil? load_notetag_auto_removal return @remove_max_turns end def auto_removal_timing return @auto_removal_timing unless @auto_removal_timing.nil? res = self.note.match(Tsuki::Auto_Removal::Remove_Regex) return @auto_removal_timing = res ? res[1].to_i : 0 end def load_notetag_auto_removal res = self.note.match(Tsuki::Auto_Removal::Timing_Regex) if res @remove_min_turns = res[1].to_i @remove_max_turns = res[1].to_i p @remove_min_turns, @remove_max_turns else @remove_min_turns = 0 @remove_max_turns = 0 end end end class State def auto_removal_timing return @auto_removal_timing if @checked_auto_removal_timing res = self.note.match(Tsuki::Auto_Removal::Remove_Regex) @checked_auto_removal_timing = true return @auto_removal_timing = res ? res[1].to_i : 0 end end end class Game_Battler < Game_BattlerBase alias :th_auto_removal_reset_counts :reset_state_counts def reset_state_counts(state_id) th_auto_removal_reset_counts(state_id) state = $data_states[state_id] variance = 1 + [state.remove_max_turns - state.remove_min_turns, 0].max @state_turns[state_id] = state.min_turns + rand(variance) end def remove_states_auto(timing) states.each do |state| if @state_turns[state.id] == 0 && state.auto_removal_timing == timing remove_state(state.id) end end end def update_auto_removal_skill remove_states_auto(3) end def update_equip_remove_turns end def remove_equips_auto(timing) end # Update skill state turns at the end of the skill application alias :th_auto_removal_item_apply :item_apply def item_apply(user, item) th_auto_removal_item_apply(user, item) user.update_auto_removal_skill end alias :th_auto_removal_action_end :on_action_end def on_action_end th_auto_removal_action_end remove_equips_auto(1) end alias :th_auto_removal_turn_end :on_turn_end def on_turn_end th_auto_removal_turn_end update_equip_remove_turns remove_equips_auto(2) end end class Game_Actor alias :th_auto_removal_setup :setup def setup(actor_id) th_auto_removal_setup(actor_id) init_equip_timing end def init_equip_timing @equip_timing = [] end alias :th_auto_removal_change_equip :change_equip def change_equip(slot_id, item) th_auto_removal_change_equip(slot_id, item) set_equip_removal_timing(slot_id, item) end def update_auto_removal_skill super remove_equips_auto(3) end def update_equip_remove_turns @equip_timing.size.times {|i| @equip_timing[i] -= 1 if @equip_timing[i] > 0 } end def set_equip_removal_timing(slot_id, item) variance = [item.remove_max_turns - item.remove_min_turns, 0].max @equip_timing[slot_id] = item.remove_min_turns + rand(variance).to_i end def remove_equips_auto(timing) @equip_timing.each_with_index { |count, i| # remove it next unless @equips[i].object if count <= 0 && @equips[i].object.auto_removal_timing == timing force_change_equip(i, nil) end } end end