#=============================================================================# # # # Magic Growth Script # # Author: Duncan Sommerville # # Version: 1.0.0 # # Date: 25/02/2014 # # # # --------------------------------------------------------------------------- # # # # Updates: # # # # 27/02/2014 - v. 1.0.0 - Started script # # # # Description: Allows setting of user-defined magic schools and skill level # # progression. Usage is defined below in the CONFIG section. # # # # USAGE GUIDELINES: # # . # # Goes under: ACTOR # # # # This tag allows you to set magic schools for actors. # # # # Examples: # # # # # # . .. # # Goes under: ACTOR # # This element, combined with the ADD and SET tags, allow you to set # # up custom offsets for different elements. # # Example: # # # # # # # # # # will set the offset for thunder skills for this actor to 10 with a # # curve of 5. # # # # # # # # # # # # will add 5 AP to the default offset for fire skills on this actor, # # and subtract 2 from the levelling curve. # #=============================================================================# #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * I. CONFIG - Constant definitions and setup values. Editable unless # otherwise stated. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * DPS #============================================================================== module DPS #----------------------------------------------------------------------- # Constants for Magic Growth functionality #----------------------------------------------------------------------- module Magic_Growth #----------------------------------------------------------------------- # Experience formulas and values #----------------------------------------------------------------------- module EXP # AP gain per cast AP_PER_USE = 1 # Initial AP needed to level up a skill once BASE_AP = 3 # Curve amount CURVE_AP = 3 #----------------------------------------------------------------------- # AP forumla: (BASE * LEVEL) + (CURVE * ((LEVEL - 1) ** 2)) # 1 -> 2 : 5 + 0 = 5 ap # 2 -> 3 : 10 + 3 = 13 ap # 3 -> 4 : 15 + 12 = 27 ap # 4 -> 5 : 20 + 27 = 47 ap # 5 -> 6 : 25 + 48 = 73 ap #----------------------------------------------------------------------- # Maximum level for skills MAX_SKILL_LEVEL = 6 end #----------------------------------------------------------------------- # Damage formulas and values #----------------------------------------------------------------------- module DMG #----------------------------------------------------------------------- # Damage boost per skill level as a multiplier (1.25 = 25%) # Bonus damage formula is BASE * (SKILL_BOOST ** (LEVEL - 1)) #----------------------------------------------------------------------- SKILL_BOOST = 1.25 end end #----------------------------------------------------------------------- # Regular expressions. Tags are case insensitive. # Only edit this if you know what you're doing! #----------------------------------------------------------------------- module REGEX # Magic school. Characters may have multiple schools. SCHOOL = //i #----------------------------------------------------------------------- # Allows changing of the default learning offset for each character. # # Example: # A character with # # # will need 10 additional AP to level their Fire skills. # # To subtract, use # # You can also use to change all schools #----------------------------------------------------------------------- LEARNING_OFFSET_START = //i ADD_OFFSET = //i SET_OFFSET = //i ADD_CURVE = /<(?:ADD_CURVE|add curve):[ ]?([-]?\d+)>/i SET_CURVE = /<(?:SET_CURVE|set curve):[ ]?([-]?\d+)>/i LEARNING_OFFSET_END = /<\/OFFSET>/i end #----------------------------------------------------------------------- # Module for term definitions. #----------------------------------------------------------------------- module VOCAB LEVEL = "LV" MAX = "MAX" TO_NEXT = "Next:" end #----------------------------------------------------------------------- # Module for graphical constants. #----------------------------------------------------------------------- module GRAPHICS # These values use your windowskin colour palette to create a progress # bar gradient. 22 and 23 are the default MP bar colours. PROG_BAR_COLOR_1 = 22 PROG_BAR_COLOR_2 = 23 end end # DPS #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * II. OBJECT INITIALIZATION - Read notetags and define object definitions # for Actors and Skills. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * RPG::Actor #============================================================================== class RPG::Actor #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :schools attr_accessor :learning_offset attr_accessor :learning_curve #-------------------------------------------------------------------------- # * New method: load_magic_tags # . Initialize magic levels and load skill notetags #-------------------------------------------------------------------------- def load_magic_tags # Initialize a new array for magic schools @schools = Array.new # Give each character their own magic offset, based on the global offset @learning_offset = Hash.new(0) # Do the same for the curve @learning_curve = Hash.new(0) # Define a school to reference for the offset school = nil self.note.split(/[\r\n]+/).each { |line| case line when DPS::REGEX::SCHOOL @schools.push($1.to_s.downcase.to_sym) when DPS::REGEX::LEARNING_OFFSET_START school = $1.to_s.downcase.to_sym when DPS::REGEX::LEARNING_OFFSET_END school = nil when DPS::REGEX::ADD_OFFSET next if !school if school.eql?(:all) @learning_offset.each_value {|val| val += $1.to_i} else @learning_offset[school] += $1.to_i end when DPS::REGEX::SET_OFFSET next if !school if school.eql?(:all) @learning_offset.each_value {|val| val = $1.to_i} else @learning_offset[school] = $1.to_i end when DPS::REGEX::ADD_CURVE next if !school if school.eql?(:all) @learning_curve.each_value {|val| val += $1.to_i} else @learning_curve[school] += $1.to_i end when DPS::REGEX::SET_CURVE next if !school if school.eql?(:all) @learning_curve.each_value {|val| val = $1.to_i} else @learning_curve[school] = $1.to_i end end } end end # RPG::Actor #============================================================================== # * RPG::Skill #============================================================================== class RPG::Skill #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :school attr_accessor :level attr_accessor :ap #-------------------------------------------------------------------------- # * New method: init_magic # . Initialize magic levels #-------------------------------------------------------------------------- def init_magic # Initialize skill level as an empty hash with default 1 @level = Hash.new(1) if @level.nil? # Define an empty hash for holding ap values @ap = Hash.new(0) if @ap.nil? # Define the school this skill belongs to @school = get_school end #-------------------------------------------------------------------------- # * New Method: get_school #-------------------------------------------------------------------------- def get_school school_id = damage.element_id school = $data_system.elements[school_id].downcase.to_sym return school ? school : nil end #-------------------------------------------------------------------------- # * New Method: check_school #-------------------------------------------------------------------------- def check_school(user) has_school = user.actor.schools.include?(@school.downcase.to_sym) return has_school && @school end #-------------------------------------------------------------------------- # * New method: to_next # . Calculate AP to next skill level #-------------------------------------------------------------------------- def to_next(actor) level = @level[actor.id] return 1 if level >= DPS::Magic_Growth::EXP::MAX_SKILL_LEVEL # Get the actor's learning offsets base_offset = actor.actor.learning_offset[@school] curve_offset = actor.actor.learning_curve[@school] # Calculate necessary values base_offset = 0 if base_offset.nil? curve_offset = 0 if curve_offset.nil? base = DPS::Magic_Growth::EXP::BASE_AP + base_offset curve = DPS::Magic_Growth::EXP::CURVE_AP + curve_offset # AP forumla: (BASE * LEVEL) + (CURVE * ((LEVEL - 1) ** 2)) return (base * level) + (curve * ((level - 1) ** 2)) end end # RPG::Skill #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * III. DATA MANAGEMENT - Functions to do with saving/loading of data, # as well as calling the functions to read notetags on startup. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * DataManager #============================================================================== module DataManager #-------------------------------------------------------------------------- # * Alias method: load_magic_db # . Load magic growth notetags on startup #-------------------------------------------------------------------------- class <= DPS::Magic_Growth::EXP::MAX_SKILL_LEVEL item.ap[user.id] = 1 return end total = item.ap[user.id] += DPS::Magic_Growth::EXP::AP_PER_USE to_next = item.to_next(user) while total >= to_next break if item.level[user.id] >= DPS::Magic_Growth::EXP::MAX_SKILL_LEVEL # Level the skill up item.level[user.id] += 1 # Subtract the used AP from the total item.ap[user.id] -= to_next total -= to_next to_next = item.to_next(user) end end end # Game_Battler #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * V. WINDOWING - Functions for drawing data to the screen. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * Window_SkillList #============================================================================== class Window_SkillList < Window_Selectable #-------------------------------------------------------------------------- # * Overwrite Method: col_max #-------------------------------------------------------------------------- def col_max # Switch the skill list to one column if the Scene is the Skill menu return SceneManager.scene_is?(Scene_Skill) ? 1 : 2 end #-------------------------------------------------------------------------- # * Overwrite Method: draw_item #-------------------------------------------------------------------------- def draw_item(index) skill = @data[index] if skill rect = item_rect(index) rect.width -= 4 # Halve the width to accommodate the progress bar rect.width /= 2 if SceneManager.scene_is?(Scene_Skill) draw_item_name(skill, rect.x, rect.y, enable?(skill)) draw_skill_cost(rect, skill) # Draw the skill progress bar draw_skill_level(rect, skill) if SceneManager.scene_is?(Scene_Skill) draw_progress_bar(rect, skill) if SceneManager.scene_is?(Scene_Skill) end end #-------------------------------------------------------------------------- # * New Method: draw_skill_level #-------------------------------------------------------------------------- def draw_skill_level(rect, skill) x = rect.x + rect.width + 10 y = rect.y level = skill.level[@actor.id] change_color(system_color) draw_text(x, y, 60, line_height, DPS::VOCAB::LEVEL) change_color(normal_color) if level >= DPS::Magic_Growth::EXP::MAX_SKILL_LEVEL draw_text(x + 25, y, 50, line_height, DPS::VOCAB::MAX) else draw_text(x + 35, y, 40, line_height, level) end end #-------------------------------------------------------------------------- # * New Method: draw_progress_bar #-------------------------------------------------------------------------- def draw_progress_bar(rect, skill) x = rect.x + rect.width + 30 y = rect.y percent = skill.ap[@actor.id].to_f / skill.to_next(@actor) change_color(system_color) draw_text(x + 40, y, 60, line_height, DPS::VOCAB::TO_NEXT) gauge_color_1 = text_color(DPS::GRAPHICS::PROG_BAR_COLOR_1) gauge_color_2 = text_color(DPS::GRAPHICS::PROG_BAR_COLOR_2) draw_gauge(x + 100, y - 6, 120, percent, gauge_color_1, gauge_color_2) draw_current_and_max_values(x + 100, y, 120, skill.ap[@actor.id], skill.to_next(@actor), normal_color, normal_color) end end # Window_SkillList #============================================================================== # # * END # #==============================================================================