#=============================================================================# # # # Physical Skill 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 skill level progression. # # Usage is defined below in the CONFIG section. # # # #=============================================================================# #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * I. CONFIG - Constant definitions and setup values. Editable unless # otherwise stated. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * DPS #============================================================================== module DPS #----------------------------------------------------------------------- # Constants for Skill Growth functionality #----------------------------------------------------------------------- module SkillGrowth #----------------------------------------------------------------------- # Experience formulas and values #----------------------------------------------------------------------- module EXP # AP gain per skill use. Can be overridden with the tag 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)) # With a base of 5 and a curve of 3: # 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 ... etc #----------------------------------------------------------------------- # Default maximum level for skills MAX_SKILL_LEVEL = 10 # Default end #----------------------------------------------------------------------- # Damage formulas and values #----------------------------------------------------------------------- module DMG #----------------------------------------------------------------------- # Damage boost per skill level either as a flat increase or a # compounding multiple. # # Bonus damage formula is BASE + (SKILL_BOOST * (LEVEL - 1)) or # BASE * (SKILL_BOOST ** (LEVEL - 1)) #----------------------------------------------------------------------- SKILL_BOOST_FLAT = 40 # Default SKILL_BOOST_COMP = 1.25 # Default, 25% end end #----------------------------------------------------------------------- # Regular expressions. Tags are case insensitive. # Only edit this if you know what you're doing! # # All tags go under Skill Notes, and are optional, however you must # have a tag on each skill that you want to utilize this # script. #----------------------------------------------------------------------- module REGEX # Used to define a skill that will level as it's used GROWS = //i #----------------------------------------------------------------------- # Allows changing of the default learning offset for each skill. # # Example: # A skill with # # means Actor 1 will need 10 additional AP to level the skill. # # Since multiple actors can use the same skill, it makes sense to have # multiple levels and offsets for each skill. # # To subtract, use # # You can also use in a similar manner. #----------------------------------------------------------------------- GROWTH_OFFSET = /<(?:GROWTH_OFFSET|growth offset) (\d+):[ ]*([-]?\d+)>/i GROWTH_CURVE = /<(?:GROWTH_CURVE|growth curve) (\d+):[ ]*([-]?\d+)>/i #----------------------------------------------------------------------- # Allows setting a non-default damage boost value. # Boost type defaults to flat. # Usage: # # (assigning 0 uses the default SKILL_BOOST_COMP value) #----------------------------------------------------------------------- BOOST_FLAT = /<(?:BOOST_FLAT|boost flat):[ ]*(\d+)>/i BOOST_COMP = /<(?:BOOST_COMP|boost comp):[ ]*(\d+)>/i #----------------------------------------------------------------------- # Define AP per use of a given skill # Usage: #----------------------------------------------------------------------- AP_PER_USE = /<(?:AP_PER_USE|ap per use):[ ]*(\d+)>/i #----------------------------------------------------------------------- # Define max skill level # Usage: #----------------------------------------------------------------------- MAX_LEVEL = /<(?:MAX_SKILL_LEVEL|max skill level):[ ]*(\d+)>/i end end # DPS #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # * II. OBJECT INITIALIZATION - Read notetags and define object definitions # for Skills. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #============================================================================== # * RPG::Skill #============================================================================== class RPG::Skill include DPS #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :grows attr_accessor :level attr_accessor :ap attr_accessor :boost_type attr_accessor :boost attr_accessor :learning_offset attr_accessor :learning_curve attr_accessor :ap_per_use attr_accessor :max_level #-------------------------------------------------------------------------- # * New method: load_skill_growth_tags # . Initialize skill levels and load notetags #-------------------------------------------------------------------------- def load_skill_growth_tags @grows = false # 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 a hash to hold offset values, based on the global base @learning_offset = Hash.new(SkillGrowth::EXP::BASE_AP) # Do the same for the curve @learning_curve = Hash.new(SkillGrowth::EXP::CURVE_AP) # Set up the damage variables. A value of 0 uses the default in config @boost = 0 @boost_type = :flat # Set up ap per use. A value of 0 uses the default in config @ap_per_use = 0 # Set up max skill level. A value of 0 uses the default in config @max_level = 0 self.note.split(/[\r\n]+/).each { |line| case line when REGEX::GROWS @grows = true when REGEX::GROWTH_OFFSET @learning_offset[$1.to_i] = $2.to_i when REGEX::GROWTH_CURVE @learning_curve[$1.to_i] = $2.to_i when REGEX::BOOST_FLAT @boost = $1.to_i || 0 when REGEX::BOOST_COMP @boost_type = :comp @boost = $1.to_i || 0 when REGEX::AP_PER_USE @ap_per_use = $1.to_i when REGEX::MAX_LEVEL @max_level = $1.to_i end } end #-------------------------------------------------------------------------- # * New method: to_next # . Calculate AP to next skill level #-------------------------------------------------------------------------- def to_next(actor) level = @level[actor.id] max = @max_level > 0 ? @max_level : SkillGrowth::EXP::MAX_SKILL_LEVEL return 1 if level >= max # AP forumla: (BASE * LEVEL) + (CURVE * ((LEVEL - 1) ** 2)) base = @learning_offset[actor.id] curve = @learning_curve[actor.id] 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_skill_growth_db # . Load skill growth notetags on startup #-------------------------------------------------------------------------- class < 0 ? max : SkillGrowth::EXP::MAX_SKILL_LEVEL if item.level[user.id] >= max item.ap[user.id] = 1 return end ap = item.ap_per_use == 0 ? EXP::AP_PER_USE : item.ap_per_use total = item.ap[user.id] += ap to_next = item.to_next(user) while total >= to_next break if item.level[user.id] >= max # 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: draw_item #-------------------------------------------------------------------------- def draw_item(index) skill = @data[index] if skill rect = item_rect(index) rect.width -= SceneManager.scene_is?(Scene_Skill) ? 30 : 4 if rect.x >= Graphics.width/2 && SceneManager.scene_is?(Scene_Skill) rect.width -= 30 end draw_item_name(skill, rect.x, rect.y, enable?(skill)) draw_skill_cost(rect, skill) if skill.grows draw_skill_level(rect, skill) if SceneManager.scene_is?(Scene_Skill) end 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, "LV") change_color(normal_color) draw_text(x + 35, y, 40, line_height, level) end end # Window_SkillList #============================================================================== # # * END # #==============================================================================