#============================================================================== # Crystal Engine - Use Based Stat Growth #------------------------------------------------------------------------------ # Current Version: 1.00 #============================================================================== $imported ||= {} $imported["CE-UseBasedStatGrowth"] = true =begin This script sets up a system where actor's gain stats based on the actions they take in battle. This allows characters to grow based on how they fight and adapt to how the player uses them. ------------------------------------------------------------------------------ Notetags: Skill Notes # Increase stat EXP for the user by x for the specified stat # Increase stat EXP for the user using a rank based calulation # Increase stat EXP for the target by x for the specified stat # Increase stat EXP for the target using a rank based calulation Item Notes # Increase stat EXP for the user by x for the specified stat # Increase stat EXP for the user using a rank based calulation # Increase stat EXP for the target by x for the specified stat # Increase stat EXP for the target using a rank based calulation State Notes # Increase stat EXP by x for the specified stats when applies =end module CRYSTAL module FF2 module STATS #------------------------------------------------------------------------ # * The Message Displayed for a Stat Increase #------------------------------------------------------------------------ INCREASE_MESSAGE = "%s's %s increased!" #------------------------------------------------------------------------ # * Stat EXP Needed for a Stat Increase #------------------------------------------------------------------------ STAT_EXP_NEEDED = 100 #------------------------------------------------------------------------ # * Does a Skill Need to Connect in Order to Register an Increase # This does not apply to increases you get per action #------------------------------------------------------------------------ HIT_REQUIRED = true #------------------------------------------------------------------------ # * Criteria for Regular Stat Increases #------------------------------------------------------------------------ NORMAL_STATS = { 0 => { # Max HP # The amount the stat goes up by when a character's HP increases :increase => 50, # The amount for Stat EXP you get per battle :regular_increase => 0, :hit_types => { # The hit types that increase HP upon use (increases by target's rank) :use => [], # The hit types that increase HP upon being hit by (increases by user's rank) :hit => [], }, # The formula for increase Stat EXP when taking damage (HP and MP only) :damage_formula => "@result.hp_damage / 25 + 5", # Stat EXP added for buffing the stat :buff_exp => 5, # Amount of Stat EXP you get per action :per_action => 0, }, 1 => { # Max MP :increase => 10, :regular_increase => 0, :hit_types => { :use => [], :hit => [], }, :damage_formula => "@result.mp_damage / 10 + 5", # The formula for increase Stat EXP when using MP (MP only) :use_formula => "skill_mp_cost(skill) + 5", :buff_exp => 5, :per_action => 0, }, 2 => { # Attack :increase => 5, :regular_increase => 0, :hit_types => { :use => [1], :hit => [], }, :buff_exp => 5, :per_action => 0, }, 3 => { # Defense :increase => 5, :regular_increase => 0, :hit_types => { :use => [], :hit => [1], }, :buff_exp => 5, :per_action => 0, }, 4 => { # Magic Attack :increase => 5, :regular_increase => 0, :hit_types => { :use => [2], :hit => [], }, :buff_exp => 5, :per_action => 0, }, 5 => { # Magic Defense :increase => 5, :regular_increase => 0, :hit_types => { :use => [], :hit => [2], }, :buff_exp => 5, :per_action => 0, }, 6 => { # Agility :increase => 5, :regular_increase => 5, :hit_types => { :use => [], :hit => [], }, :buff_exp => 5, :per_action => 10, }, 7 => { # Luck :increase => 5, :regular_increase => 5, :hit_types => { :use => [], :hit => [], }, :buff_exp => 5, :per_action => 10, }, } #------------------------------------------------------------------------ # * Criteria for Extra Stat Increases # Follows the same format as regular stat increases (exept for buffs) #------------------------------------------------------------------------ EXTRA_STATS = { } end end end #============================================================================== # Editing beyond this point may cause stone, zombie, mist frenzy, and/or toad, # so edit at your own risk. #============================================================================== module CRYSTAL module CHECK #-------------------------------------------------------------------------- # * Checks if you have a certain script installed #-------------------------------------------------------------------------- def self.require(self_name, script, site = "http://crystalnoel42.wordpress.com") unless $imported["CE-BasicModule"] msg = "The script '#{self_name}' requires the latest\n" msg += "version of 'Crystal Engine - Basic Module' to work properly\n" msg += "Go to http://crystalnoel42.wordpress.com/ to download this script." raise SyntaxError.new(msg) end unless $imported[script] msg = "The script '#{self_name}' requires the latest\n" msg += "version of #{scripts_list(script)} to work properly\n" msg += "Go to #{site} to download this script." raise SyntaxError.new(msg) end end require("Crystal Engine - Use Based Stat Growth", "CE-BasicModule") #-------------------------------------------------------------------------- # * Script Name Guide #-------------------------------------------------------------------------- class </i @use_increase[$1.to_i] = :rank when //i @use_increase[$1.to_i] = $2.to_i when //i @use_increase[$1.to_sym] = :rank when //i @use_increase[$1.sym] = $2.to_i end end return @use_increase end #-------------------------------------------------------------------------- # * Hit Increase #-------------------------------------------------------------------------- def hit_increase return @hit_increase if @hit_increase @hit_increase = {} @note.split(/[\r\n]+/).each do |line| case line when //i @hit_increase[$1.to_i] = :rank when //i @hit_increase[$1.to_i] = $2.to_i when //i @use_increase[$1.to_sym] = :rank when //i @use_increase[$1.sym] = $2.to_i end return @hit_increase end end end #============================================================================== # ** RPG::State #------------------------------------------------------------------------------ # The data class for state. #============================================================================== class RPG::State < RPG::BaseItem #-------------------------------------------------------------------------- # * Use Increase #-------------------------------------------------------------------------- def apply_increase return @apply_increase if @apply_increase @apply_increase = {} @note.split(/[\r\n]+/).each do |line| case line when //i @apply_increase[$1.to_i] = $2.to_i when //i @apply_increase[$1.to_sym] = $2.to_i end end return @apply_increase end end #============================================================================== # ** BattleManager #------------------------------------------------------------------------------ # This module manages battle progress. #============================================================================== module BattleManager #-------------------------------------------------------------------------- # * Display EXP Earned #-------------------------------------------------------------------------- class <= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[1] = 0 @increased_stats.push(1) end end end #============================================================================== # ** Game_Battler #------------------------------------------------------------------------------ # A battler class with methods for sprites and actions added. This class # is used as a super class of the Game_Actor class and Game_Enemy class. #============================================================================== class Game_Battler < Game_BattlerBase #-------------------------------------------------------------------------- # * Processing at Start of Battle #-------------------------------------------------------------------------- alias on_battle_start_ce_ff2_stat_growth on_battle_start def on_battle_start on_battle_start_ce_ff2_stat_growth return if enemy? return if no_advancement? for i in 0..7 next if param_base(i) == param_max(i) @stat_exp[i] += CRYSTAL::FF2::STATS::NORMAL_STATS[i][:regular_increase] if @stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[i] = 0 @increased_stats.push(i) end end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| next if eval("xstat.#{stat}") == CRYSTAL::XSTAT::STAT_MAX @stat_exp[stat] += CRYSTAL::FF2::STATS::EXTRA_STATS[stat][:regular_increase] if @stat_exp[stat] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[stat] = 0 @increased_stats.push(stat) end end end end #-------------------------------------------------------------------------- # * Use Skill/Item # Called for the acting side and applies the effect to other than the user. #-------------------------------------------------------------------------- alias use_item_ce_ff2_stat_growth use_item def use_item(item) use_item_ce_ff2_stat_growth(item) return unless SceneManager.scene_is?(Scene_Battle) return if enemy? return if no_advancement? for i in 0..7 next if param_base(i) == param_max(i) @stat_exp[i] += CRYSTAL::FF2::STATS::NORMAL_STATS[i][:per_action] if @stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[i] = 0 @increased_stats.push(i) end end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| next if eval("xstat.#{stat}") == CRYSTAL::XSTAT::STAT_MAX @stat_exp[stat] += CRYSTAL::FF2::STATS::EXTRA_STATS[stat][:per_action] if @stat_exp[stat] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[stat] = 0 @increased_stats.push(stat) end end end end #-------------------------------------------------------------------------- # * Apply Effect of Skill/Item #-------------------------------------------------------------------------- alias item_apply_ce_ff2_stat_growth item_apply def item_apply(user, item) item_apply_ce_ff2_stat_growth(user, item) return unless SceneManager.scene_is?(Scene_Battle) return if CRYSTAL::FF2::STATS::HIT_REQUIRED && !@result.hit? growth = CRYSTAL::FF2::STATS::NORMAL_STATS growth2 = CRYSTAL::FF2::STATS::EXTRA_STATS if user.actor? && !user.no_advancement? for i in 0..7 next if param_base(i) == param_max(i) if growth[i][:hit_types][:use].include?(item.hit_type) || item.use_increase[i] == :rank user.stat_exp[i] += CRYSTAL::FF2::PROCESSOR.rank_based_eval(user, self) elsif !item.use_increase[i].nil? user.stat_exp[i] += item.use_increase[i] end if user.stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED user.stat_exp[i] = 0 user.increased_stats.push(i) end end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| next if eval("xstat.#{stat}") == CRYSTAL::XSTAT::STAT_MAX if growth2[stat][:hit_types][:use].include?(item.hit_type) || item.use_increase[stat] == :rank user.stat_exp[stat] += CRYSTAL::FF2::PROCESSOR.rank_based_eval(user, self) elsif !item.use_increase[stat].nil? user.stat_exp[stat] += item.use_increase[stat] end if user.stat_exp[stat] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED user.stat_exp[stat] = 0 user.increased_stats.push(stat) end end end end if actor? && !no_advancement? for i in 0..7 next if param_base(i) == param_max(i) if growth[i][:hit_types][:use].include?(item.hit_type) || item.use_increase[i] == :rank @stat_exp[i] += CRYSTAL::FF2::PROCESSOR.rank_based_eval(self, user) elsif !item.use_increase[i].nil? user.stat_exp[i] += item.use_increase[i] end if @stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[i] = 0 @increased_stats.push(i) end end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| next if eval("xstat.#{stat}") == CRYSTAL::XSTAT::STAT_MAX if growth2[stat][:hit_types][:use].include?(item.hit_type) || item.use_increase[stat] == :rank @stat_exp[stat] += CRYSTAL::FF2::PROCESSOR.rank_based_eval(self, user) elsif !item.use_increase[stat].nil? @stat_exp[stat] += item.use_increase[stat] end if @stat_exp[stat] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[stat] = 0 @increased_stats.push(stat) end end end end end #-------------------------------------------------------------------------- # * Add Buff #-------------------------------------------------------------------------- alias add_buff_ce_ff2_stat_growth add_buff def add_buff(param_id, turns) add_buff_ce_ff2_stat_growth(param_id, turns) return unless SceneManager.scene_is?(Scene_Battle) return if enemy? return if param_base(param_id) == param_max(param_id) return if no_advancement? @stat_exp[param_id] += CRYSTAL::FF2::STATS::NORMAL_STATS[i][:buff_exp] if @stat_exp[param_id] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[param_id] = 0 @increased_stats.push(param_id) end end #-------------------------------------------------------------------------- # * Add New State #-------------------------------------------------------------------------- alias add_new_state_ce_ff2_stat_growth add_new_state def add_new_state(state_id) add_new_state_ce_ff2_stat_growth(state_id) return unless SceneManager.scene_is?(Scene_Battle) return if enemy? return if no_advancement? for i in 0..7 next if param_base(i) == param_max(i) next unless $data_states[state_id].apply_increase[i] @stat_exp[i] += $data_states[state_id].apply_increase[i] if @stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[i] = 0 @increased_stats.push(i) end end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| next if eval("xstat.#{stat}") == CRYSTAL::XSTAT::STAT_MAX @stat_exp[stat] += $data_states[state_id].apply_increase[stat] if @stat_exp[stat] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[stat] = 0 @increased_stats.push(stat) end end end end #-------------------------------------------------------------------------- # * Damage Processing # @result.hp_damage @result.mp_damage @result.hp_drain # @result.mp_drain must be set before call. #-------------------------------------------------------------------------- alias execute_damage_ce_ff2_stat_growth execute_damage def execute_damage(user) execute_damage_ce_ff2_stat_growth(user) return if enemy? return if no_advancement? for i in 0..1 case i when 0 next if @result.hp_damage = 0 when 1 next if @result.mp_damage = 0 end formula = CRYSTAL::FF2::STATS::NORMAL_STATS[i][:damage_formula] @stat_exp[i] += eval(formula) if @stat_exp[i] >= CRYSTAL::FF2::STATS::STAT_EXP_NEEDED @stat_exp[i] = 0 @increased_stats.push(i) end end end end #============================================================================== # ** Game_Actor #------------------------------------------------------------------------------ # This class handles actors. It is used within the Game_Actors class # ($game_actors) and is also referenced from the Game_Party class ($game_party). #============================================================================== class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :stat_exp attr_accessor :increased_stats #-------------------------------------------------------------------------- # * Setup #-------------------------------------------------------------------------- alias setup_ce_ff2_stat_growth setup def setup(actor_id) setup_ce_ff2_stat_growth(actor_id) return if no_advancement? @stat_exp = {} for i in 0..7 @stat_exp[i] = 0 end if $imported["CE-ExtraStats"] CRYSTAL::XSTAT::STATS.each do |stat| @stat_exp[stat] = 0 end end @increased_stats = [] end #-------------------------------------------------------------------------- # * Show Level Up Message # new_skills : Array of newly learned skills #-------------------------------------------------------------------------- alias display_level_up_ce_ff2_stat_growth display_level_up def display_level_up(new_skills) if CRYSTAL::FF2::GENERAL::DISPLAY_LEVEL && !no_advancement? if CRYSTAL::FF2::GENERAL::DISPLAY_SKILL_LEARN new_skills.each do |skill| $game_message.add(sprintf(Vocab::ObtainSkill, skill.name)) end end else display_level_up_ce_ff2_stat_growth(new_skills) end end end