#=============================================================================== # ** Ability System Script (based on common event shop) ** # # Author: eugene222 (Evgenij) # Version: 1.0 # Date: 24.05.2014 # Required: Tsukihimes(Himes) Shop Manager # http://www.himeworks.com/2013/02/22/shop-manager/ # # Credit: Tsukihime, Andar and Me # # Notes: This Script Belongs To Andar. He Is Free To Do What He Wants With # This Script. # # Idea, Translation, Demo and Tutorial by: Andar # # # Commercial Use: # # - I Took Some Code From Himes Shop Manager And Changed It To Make This Script # Compatible With It. # So You Need To Ask Tsukihime For Commercial Use (http://www.himeworks.com/). # From My Side Feel Free To Use It How You Like. # # - I Have Made A Shop Manager Independent Version, PM Me If You Want It. # For That Version You Don't Need To Ask Hime, If You Want To Use It # Commercially, But That Version Is Incompatible With The Shop Manager. # # - Eugene222 # #------------------------------------------------------------------------------- # # I'm placing this script (and the demo/tutorial for it) publically # # For commercial use, credit me with the idea for this script and a link to either # my profile or my user-blog on www.rpgmakerweb.com # # - Andar # #=============================================================================== module E222 #----------------------------------------------------------------------------- # Instructions for the shop/learning-scene call: # (see tutorial for full instructions) # # Before the shop processing command, execute this script call: # @shop_type = "Item_Learn" # # In the shop processing command, use the ability items like a normal shop. # This shop data will automatically be transferred to the learning scene. # # These ability items will be paid for by AP (ability points) from the selected # actor. All the ability items are required to have a feature "common event", # and that event will be executed upon purchase. # The actor purchasing the ability will be stored in a variable set in the # scrip options farther below. The common event may or may not use that actor # ID, for example to learn a skill on that actor, or it could simply add a game # mechanic/switch instead. # # For better explanations, check the tutorial or the demo project. # #----------------------------------------------------------------------------- # Notetag overview: #----------------------------------------------------------------------------- # # Actor notetags # All notetags are optional - if missing the defaults will be used. # # This number will be the number of ability points # available at actor initialisation (usually lvl 1) # Default is zero. # # This level will determine the first level when the # actor will gain AP by leveling. The higher this # number, the longer the player has to wait for # level-points. # Default is 2, which means that the actor gains # AP on first leveling (set it to 100 if he should # never gain abilities from leveling, as the max # level is 99). # # This number will determine how many levels should be # between gaining ability points by leveling. # Default is 1, which means ability points every # level. # If you set it to 3, the actor would gain abilities # only on levels 2, 5, 8, ... # # How many ability points should the actor gain # whenever the engine distributes AP's? # Default is 10, but this should be set according # to your Ability costs as well as your actor's # intended learning speed (which can be different # for each actor). # ATTENTION: This AP-Setting depends on the selected gain mode # and may be ignored according to script settings # #-------------------------------------------------------------------------------- # # Enemy notetags # This notetag is only functional with KILL_MODE = :enemy # # This setting will tell the engine how many AP's to give # to the actors when this enemy is killed. # ATTENTION: This AP-Setting depends on the selected gain mode # and may be ignored according to script settings # #-------------------------------------------------------------------------------- # # Item notetags # If an item has no notetags, it can be learned in any training shop by any actor. # To create ability trees or ability tiers, you'll have to use notetags. # # In addition to the shop processing, there is # also a training scene available in the menu. # All ability items that have this tag are avail- # able in this menu scene (in addition to any # availability on training shops). # # Required Ability Items: The actor needs to have # gained all the abilities from the listed item # ID's before this ability can be gained. # Example: you need the ability light armor before # the actor can learn medium armor # # Blocking Ability items: If the actor has already # learned one of the abilities from the listed # item ID's, then this ability can no longer be # learned. # Example: if the actor already has necromancy, # he can no longer learn healing spells # # Required Class: This ability can only be learned # if the actor has the listed class (ID) # #----------------------------------------------------------------------------- # # Scriptcalls: # The scriptcalls can be used to affect the ability system by eventing, or to # handle things without the learning shop/scene (not recommended) # #----------------------------------------------------------------------------- # Scriptcalls: # # The following two script calls allow gaining and reducing AP by events, for # example quest rewards or story sequences. # - $game_actors[id].add_ability_points(n) # increases the actor's AP by n # - $game_actors[id].reduce_ability_points(n) # reduces the actor's AP by n # # The following script call is intended to allow for checking if the actor # has learned a specific ability or not - either for access something or # for use in non-training_scene-use of ability items. # The function returns true if the actor has learned the ability from item_id: # - $game_actors[id].ce_item_learned?(item_id) # # The following script call forces the actor to learn an ability while ignoring # all conditions set on that ability item's notetags. # It can be used to give a new actor initial abilities upon joining, or to # allow for manual handling of the abilities. # This command should be used after the check above if you learn abilities # outside the Training scene. # - ap_force_learn(actor_id, item_id) # #---------------------------------------------------------------------------------------- # # The following script call is for advanced users, as it can cause problems # if used in a wrong way. It causes the given actor to un-train the given # ability. # However, it actually does only two things: # 1) removing the ability from the actor's learned list, allowing the actor # to learn it again later. # 2) checking if there is an common event set to be executed on remove for # this ability, and then execute that common event. # Without the removal event, nothing is actually removed from the actor # - ap_remove_item(actor_id, item_id) # # The removal event has to be configured for each ability item in the list # that is placed farther below. # #-------------------------------------------------------------------------------------- # # English/German compatibility lines, to make messages use the same line numbers # in both versions of the script (German version needed more comment lines) #------------------------------------------------------------------------------------- module AP_Config #---------------------------------------------------------------------------------- # Editable Region: Script Configuration # The following part of the script contains the settings on how the ability # system should work in your project. # Be carefull with editing those options #---------------------------------------------------------------------------------- #-------------------------------------------------------------------------- # The GET_MODE decides how an actor can automatically gain ability points. # - :level : Gain points for level-ups as defined in the actor # - :kill : Gain points for defeated enemies (after battle is won) #-------------------------------------------------------------------------- GET_MODE = :level #-------------------------------------------------------------------------- # The KILL_MODE decides where the script looks for the number of ability # points gained for defeated enemies. It is only functional when the # GET_MODE is set to :kill and ignored when set to :level # # - :actor : Each actor gains the number of AP set in its notetags with # . This allows for different gains on each actor. # # - :enemy : Each actor gains the number of AP set in the enemy notetag by # . This gives each actor the same number, but the # number is determined by the enemy. This allows for ability points # only gained from boss enemies or an EXP-alternative for AP. # # In both cases a missing notetags results in the points gained being defined # by the setting DEFAULT_POINTS (on the line below KILL_MODE) #-------------------------------------------------------------------------- KILL_MODE = :actor DEFAULT_POINTS = 10 #-------------------------------------------------------------------------- # The following number defines the variable ID where the actor ID is stored # upon purchasing an ability in the training scenes/shops. # This setting is vital for the common events and the variable should be # named accordingly to prevent a double use. #-------------------------------------------------------------------------- ACTOR_VARIABLE = 1 #-------------------------------------------------------------------------- # The following number defines the variable ID where the item ID is stored # upon purchasing an ability in the training scenes/shops. # This setting is vital for the common events and the variable should be # named accordingly to prevent a double use. # #-------------------------------------------------------------------------- ITEM_VARIABLE = 2 #--------------------------------------------------------------------------- # The following table (empty by default) lists which common event should # be executed to remove an ability, if that ability is removed by script # command. # Removing abilities should be done very carefull, because not all abilities # are easy to remove # If no common event is defined, nothing will be removed from the actor - # but the ability can be learned again (perhaps gaining a parameter bonus # a second time) # #--------------------------------------------------------------------------- ON_REMOVE = { #------------------------------------------------------------------------- # item_id => common_event_id, # Example: 17 => 5, # if ability from item 17 is removed, execute the # Common Event with the ID #5 #------------------------------------------------------------------------- #------------------------------------------------------------------------- } #--------------------------------------------------------------------------- # Font Color For Block Abilities # This is the color used when the actor doesn't have the blocking ability # and may still learn the listed ability. # For requirements and already blocked abilities the colors for power up and # power down as defined in the system are used. # Power Up Color if requirement is met # Power Down Color if requirement is not met or if blocking ability is learned # # Attention: Depending on the choosen menu background it might be neccessary # to change this color for readability #--------------------------------------------------------------------------- BLOCK_COLOR = Color.new(80, 80, 80, 255) end #--------------------------------------------------------------------------- # End of Editable Region: Script Configuration #--------------------------------------------------------------------------- #---------------------------------------------------------------------------- # Vocab #---------------------------------------------------------------------------- module Vocab #---------------------------------------------------------------------------------- # Editable Region: VOCABs # The following part of the script contains the settings for the Vocabs # You can edit them to change the language or the display texts #---------------------------------------------------------------------------------- #------------------------------------------------------------------------- # Menu Names # The following two names are added to the main menu for general training # and to display the learned abilities #-------------------------------------------------------------------------- TRAIN_SCENE = "Training" VIEW_SCENE = "Abilities" #-------------------------------------------------------------------------- # Vocab for abilities that are already learned #-------------------------------------------------------------------------- LEARNED = "Learned!" #-------------------------------------------------------------------------- # Vocab if no other ability is required #-------------------------------------------------------------------------- NO_ITEMS = "---" #-------------------------------------------------------------------------- # Vocab if no class is required #-------------------------------------------------------------------------- NO_CLASS = "All" #-------------------------------------------------------------------------- # Vocab for window title for requirements #-------------------------------------------------------------------------- REQUIREMENT = "Required" #-------------------------------------------------------------------------- # Vocab for displaying required class (actor) #-------------------------------------------------------------------------- CLASS = "Class:" #-------------------------------------------------------------------------- # Vocab for title of ability window #-------------------------------------------------------------------------- ABILITIES = "Abilities:" #-------------------------------------------------------------------------- # title vocab for available abilities #-------------------------------------------------------------------------- AVAILABLE = "Available:" #-------------------------------------------------------------------------- # Vocab for the displayed name for ability points (short) #-------------------------------------------------------------------------- AP = "AP" #-------------------------------------------------------------------------- # short vocab for displaying required abilities and blocked abilities # %s will be replaced with the item name from database # REQ_ABIL is for required, BLK_ABIL for blocking abilities #-------------------------------------------------------------------------- REQ_ABIL = "req. %s" BLK_ABIL = "blo. %s" #-------------------------------------------------------------------------- # Vocab for Message "ability points gained" # %s will be replaced by (in order): # - Actor Name # - Number of points gained # - Vocab of the name for ability points (see above) #-------------------------------------------------------------------------- GET_AP = "%s has gained %s %s!" #---------------------------------------------------------------------------------- # End of Editable Region: VOCABs #---------------------------------------------------------------------------------- #-------------------------------------------------------------------------- end #---------------------------------------------------------------------------- end class << DataManager alias :evg_dm_ld_as :load_database def load_database evg_dm_ld_as $data_actors.compact.each(&:load_custom_data_evg_as) $data_enemies.compact.each(&:load_custom_data_evg_as) $data_items.compact.each(&:load_custom_data_evg_as) end end #============================================================================== # RPG Actor #============================================================================== class RPG::Actor attr_reader :initial_ability_points attr_reader :ability_points_value attr_reader :first_ap_level attr_reader :ap_level_difference #-------------------------------------------------------------------------- # Initialize Custom Data #-------------------------------------------------------------------------- def load_custom_data_evg_as load_initial_ap_evg load_ap_value_evg load_first_ap_level_evg load_ap_level_difference_evg end #-------------------------------------------------------------------------- # Initialize Intial AP Points #-------------------------------------------------------------------------- def load_initial_ap_evg @initial_ability_points = 0 info = /\d+)\s*>/.match(@note) return unless info @initial_ability_points = info[:ap].to_i end #-------------------------------------------------------------------------- # Initialize AP Value #-------------------------------------------------------------------------- def load_ap_value_evg @ability_points_value = false info = /\d+)\s*>/.match(@note) return unless info @ability_points_value = info[:ap].to_i end #-------------------------------------------------------------------------- # Initialize First Ap Level #-------------------------------------------------------------------------- def load_first_ap_level_evg @first_ap_level = 2 info = /\d+)\s*>/.match(@note) return unless info @first_ap_level = info[:level] end #-------------------------------------------------------------------------- # Initialize AP Level Difference #-------------------------------------------------------------------------- def load_ap_level_difference_evg @ap_level_difference = 1 info = /\d+)\s*>/.match(@note) return unless info @ap_level_difference = info[:dif] end #-------------------------------------------------------------------------- end #============================================================================== # RPG Enemy #============================================================================== class RPG::Enemy attr_reader :ability_points_value #-------------------------------------------------------------------------- # Load Custom Data #-------------------------------------------------------------------------- def load_custom_data_evg_as load_ap_value_evg end #-------------------------------------------------------------------------- # Initialize AP Value #-------------------------------------------------------------------------- def load_ap_value_evg @ability_points_value = false info = /\d+)\s*>/.match(@note) return unless info return @ability_points_value = info[:ap].to_i end #-------------------------------------------------------------------------- end #============================================================================== # RPG Item #============================================================================== class RPG::Item attr_reader :required_class_id attr_reader :required_ability_ids attr_reader :blocked_ability_ids #-------------------------------------------------------------------------- # Load Custom Data #-------------------------------------------------------------------------- def load_custom_data_evg_as load_required_class_as load_required_ability_ids_as load_blocked_ability_ids_as load_general_ability_as end #-------------------------------------------------------------------------- # Initialize Required Class #-------------------------------------------------------------------------- def load_required_class_as @required_class_ids = nil info = /\d+)\s*>/i.match(@note) return unless info @required_class = info[:id].to_i end #-------------------------------------------------------------------------- # Initialize Required Ability IDs #-------------------------------------------------------------------------- def load_required_ability_ids_as @required_ability_ids = nil info = /.+)>/i.match(@note) return unless info @required_ability_ids = info[:ids].split(",").map(&:to_i) end #-------------------------------------------------------------------------- # Initialize Blocked Ability IDs #-------------------------------------------------------------------------- def load_blocked_ability_ids_as @blocked_ability_ids = nil info = /.+)>/i.match(@note) return unless info @blocked_ability_ids = info[:ids].split(",").map(&:to_i) end #-------------------------------------------------------------------------- # Initialize General Ability #-------------------------------------------------------------------------- def load_general_ability_as @general_ability = @note.include?("") end #-------------------------------------------------------------------------- # Return If self is a general ability #-------------------------------------------------------------------------- def general_ability? return @general_ability end end #============================================================================== # Game Interpreter #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # Load AP Item Shop #-------------------------------------------------------------------------- def load_ap_item_shop return if $game_party.in_battle goods = load_ap_item_general_goods shop = ShopManager.setup_shop(shop_map_id, shop_event_id, goods, true, "Abil_Learn") setup_shop(shop) ShopManager.call_scene(shop) end #-------------------------------------------------------------------------- # Load General Goods #-------------------------------------------------------------------------- def load_ap_item_general_goods good_id = 1 goods = [] $data_items.each do |item| if item && item.general_ability? good = make_good([0, item.id, 0, 0], good_id) goods.push(good) good_id +=1 end end return goods end #-------------------------------------------------------------------------- # Force AP Ability Learn #-------------------------------------------------------------------------- def ap_force_learn(actor_id, ability_id) $game_variables[E222::AP_Config::ACTOR_VARIABLE] = actor_id $game_variables[E222::AP_Config::ITEM_VARIABLE] = ability_id effects = $data_items[ability_id].effects.select {|eff|eff.code == 44} effects.each do |eff| common_event = $data_common_events[eff.data_id] if common_event child = Game_Interpreter.new(@depth + 1) child.setup(common_event.list, same_map? ? @event_id : 0) child.run end end $game_actors[actor_id].learn_ability(ability_id) end #-------------------------------------------------------------------------- # Remove AP Ability From Actor #-------------------------------------------------------------------------- def ap_remove_item(actor_id, ability_id) return unless $game_actors[actor_id].ability_learned?(ability_id) $game_variables[E222::AP_Config::ACTOR_VARIABLE] = actor_id $game_variables[E222::AP_Config::ITEM_VARIABLE] = ability_id $game_actors[actor_id].remove_ability(ability_id) return unless E222::AP_Config::ON_REMOVE[ability_id] common_event = $data_common_events[E222::AP_Config::ON_REMOVE[ability_id]] if common_event child = Game_Interpreter.new(@depth + 1) child.setup(common_event.list, same_map? ? @event_id : 0) child.run end end #-------------------------------------------------------------------------- end #============================================================================== # Game Actor - Ability Logic #============================================================================== class Game_Actor #-------------------------------------------------------------------------- attr_reader :ability_points attr_reader :learned_ability_ids #-------------------------------------------------------------------------- # Alias: Setup #-------------------------------------------------------------------------- alias :e222_ga_setup_ap :setup #-------------------------------------------------------------------------- def setup(actor_id) @ability_points = $data_actors[actor_id].initial_ability_points @learned_ability_ids = [] e222_ga_setup_ap(actor_id) end #-------------------------------------------------------------------------- # Learn Ability #-------------------------------------------------------------------------- def learn_ability(id) return if ability_learned?(id) @learned_ability_ids.push(id) end #-------------------------------------------------------------------------- # Remove Ability #-------------------------------------------------------------------------- def remove_ability(id) return unless ability_learned?(id) @learned_ability_ids.delete(id) end #-------------------------------------------------------------------------- # Add ability Points #-------------------------------------------------------------------------- def add_ability_points(number) @ability_points += number end #-------------------------------------------------------------------------- # Reduce Ability Points #-------------------------------------------------------------------------- def reduce_ability_points(number) @ability_points -= number @ability_points = [@ability_points, 0].max end #-------------------------------------------------------------------------- # Ability Learned? #-------------------------------------------------------------------------- def ability_learned?(id) @learned_ability_ids.include?(id) end #-------------------------------------------------------------------------- # AP Number #-------------------------------------------------------------------------- def ability_point_value return actor.ability_points_value || E222::AP_Config::DEFAULT_POINTS end #-------------------------------------------------------------------------- # Display AP Gain Number Message #-------------------------------------------------------------------------- def display_gain_ap_message(number) $game_message.add(sprintf(E222::Vocab::GET_AP, @name, number, E222::Vocab::AP)) end end #=============================================================================== # GET_MODE == :level , KILL_MODE will be ignored #=============================================================================== if E222::AP_Config::GET_MODE == :level class Game_Actor #-------------------------------------------------------------------------- # * Level Up #-------------------------------------------------------------------------- alias :e222_ga_levelup_ap :level_up def level_up e222_ga_levelup_ap return unless receive_ability_points? @tmp_ap ||= 0 @tmp_ap += ability_point_value @ability_points += ability_point_value end #-------------------------------------------------------------------------- # * Show Level Up Message # new_skills : Array of newly learned skills #-------------------------------------------------------------------------- alias :e222_ga_displaylvlup_ap :display_level_up def display_level_up(new_skills) e222_ga_displaylvlup_ap(skills) msg = sprintf(E222::Vocab::GET_AP, @name, @tmp_ap, E222::Vocab::AP) $game_message.add(msg) @tmp_ap = 0 end #-------------------------------------------------------------------------- # Determine if AP should be gained this level up or not #-------------------------------------------------------------------------- def receive_ability_points? return (@level - actor.first_ap_level) % actor.ap_level_difference == 0 end #-------------------------------------------------------------------------- end end #=============================================================================== # GET_MODE == :kill , KILL_MODE == :enemy #=============================================================================== if E222::AP_Config::GET_MODE == :kill && E222::AP_Config::KILL_MODE == :enemy class Game_Actor #-------------------------------------------------------------------------- # * Get EXP (Account for Experience Rate) #-------------------------------------------------------------------------- alias :e222_ga_gainexp_ap :gain_exp def gain_exp(exp) e222_ga_gainexp_ap(exp) @ability_points += $game_troop.total_ap display_gain_ap_message($game_troop.total_ap) end #-------------------------------------------------------------------------- end class Game_Troop #-------------------------------------------------------------------------- # * Calculate Total Experience #-------------------------------------------------------------------------- def total_ap dead_members.inject(0) {|r, enemy| r += ap_number(enemy) } end #-------------------------------------------------------------------------- # AP Number #-------------------------------------------------------------------------- def ap_number(enemy) p enemy.enemy.ability_points_value return enemy.enemy.ability_points_value || E222::AP_Config::DEFAULT_POINTS end #-------------------------------------------------------------------------- end end #=============================================================================== # GET_MODE == :kill , KILL_MODE == :actor #=============================================================================== if E222::AP_Config::GET_MODE == :kill && E222::AP_Config::KILL_MODE == :actor #============================================================================== # Battle Manager #============================================================================== module BattleManager class << self alias :e222_bm_gainexp_ap :gain_exp end #-------------------------------------------------------------------------- # * EXP Acquisition and Level Up Display #-------------------------------------------------------------------------- def self.gain_exp $game_party.all_members.each(&:gain_self_ap) e222_bm_gainexp_ap end #-------------------------------------------------------------------------- end class Game_Actor #-------------------------------------------------------------------------- # Gain AP #-------------------------------------------------------------------------- def gain_self_ap @ability_points += ability_point_value display_gain_ap_message(ability_point_value) end #-------------------------------------------------------------------------- end end #=============================================================================== # GET_MODE END #=============================================================================== #============================================================================== # Actor Info Window #============================================================================== class Window_APActorInfo < Window_Base #-------------------------------------------------------------------------- # Initialize #-------------------------------------------------------------------------- def initialize super(0, fitting_height(2), 304, fitting_height(2)) end #-------------------------------------------------------------------------- # Set Actor #-------------------------------------------------------------------------- def actor=(actor) @actor = actor refresh end #-------------------------------------------------------------------------- # Refresh #-------------------------------------------------------------------------- def refresh contents.clear draw_actor_name(@actor, 0, 0, contents.width / 3) draw_actor_level(@actor, contents.width / 3, 0) draw_actor_class(@actor, 0, line_height , contents.width / 2) draw_actor_hp(@actor, contents.width - 124, 0) draw_actor_mp(@actor, contents.width - 124, line_height) end #-------------------------------------------------------------------------- end #============================================================================== # Actor Status For Learned Items Scene #============================================================================== class Window_APActorInfo2 < Window_SkillStatus #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width Graphics.width end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh contents.clear return unless @actor draw_actor_face(@actor, 0, 0) draw_actor_simple_status(@actor, 108, line_height / 2) ap_text = sprintf("%s %s", @actor.ability_points, E222::Vocab::AP) draw_text(360, line_height / 2, contents.width - 360, line_height, ap_text, 2) end end #============================================================================== # Actor Window - TODO: redo scrolling #============================================================================== class Window_APActors < Window_Selectable #-------------------------------------------------------------------------- attr_accessor :buy_window attr_accessor :info_window #-------------------------------------------------------------------------- # * Initialize #-------------------------------------------------------------------------- def initialize(x, y, width, height) super(x, y, width, height) refresh select(0) activate end #-------------------------------------------------------------------------- # * Contents Width #-------------------------------------------------------------------------- def contents_width if (item_width + spacing) * item_max >= self.width - 24 return (item_width + spacing) * item_max else return super end end #-------------------------------------------------------------------------- # * Get Digit Count #-------------------------------------------------------------------------- def col_max contents.width > 306 ? contents.width / (item_width + spacing) : 4 end #-------------------------------------------------------------------------- # * Row Max #-------------------------------------------------------------------------- def row_max return 1 end #-------------------------------------------------------------------------- # * Spacing #-------------------------------------------------------------------------- def spacing 6 end #-------------------------------------------------------------------------- # * Get Number of Items #-------------------------------------------------------------------------- def item_max return $game_party.all_members.size end #-------------------------------------------------------------------------- # * Get Item Height #-------------------------------------------------------------------------- def item_height return 48 end #-------------------------------------------------------------------------- # * Get Item Width #-------------------------------------------------------------------------- def item_width return 48 end #-------------------------------------------------------------------------- # * Get The Selected Actor #-------------------------------------------------------------------------- def selected_actor return $game_party.all_members[index] end #----------------------------------------------------------------------------- # * top_col= #----------------------------------------------------------------------------- def top_col=(col) col = 0 if col < 0 col = col_max - 1 if col > col_max - 1 self.ox = (index / col_max).ceil * (item_width + spacing) * col_max end #----------------------------------------------------------------------------- # * ensure_cursor_visible #----------------------------------------------------------------------------- def ensure_cursor_visible self.top_col = ((index + 1) / col_max).floor * col_max end #-------------------------------------------------------------------------- # * Get Rectangle for Drawing Items #-------------------------------------------------------------------------- def item_rect(index) rect = Rect.new rect.width = item_width rect.height = item_height rect.x = index * (item_width + spacing) rect.y = 0 rect end #-------------------------------------------------------------------------- # * Move Cursor Down #-------------------------------------------------------------------------- def cursor_down(wrap = false) end #-------------------------------------------------------------------------- # * Move Cursor Up #-------------------------------------------------------------------------- def cursor_up(wrap = false) end #-------------------------------------------------------------------------- # * Move Cursor One Page Down #-------------------------------------------------------------------------- def cursor_pagedown end #-------------------------------------------------------------------------- # * Move Cursor One Page Up #-------------------------------------------------------------------------- def cursor_pageup end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item(index) x = (item_width + spacing) * index draw_actor_graphic($game_party.all_members[index], x + 24, 40) end #-------------------------------------------------------------------------- # Set Buy Window #-------------------------------------------------------------------------- def buy_window=(window) @buy_window = window update_buy end #-------------------------------------------------------------------------- # Set Info Window #-------------------------------------------------------------------------- def info_window=(window) @info_window = window update_info end #-------------------------------------------------------------------------- # * Call Help Window Update Method #-------------------------------------------------------------------------- def call_update_help update_help if active && @help_window update_buy if active && @buy_window update_info if active && @info_window end #-------------------------------------------------------------------------- # * Update Buy Window #-------------------------------------------------------------------------- def update_buy @buy_window.actor = selected_actor @buy_window.status_window.actor = selected_actor end #-------------------------------------------------------------------------- # Update Info Window #-------------------------------------------------------------------------- def update_info @info_window.actor = selected_actor end #-------------------------------------------------------------------------- end #============================================================================== # Item Window #============================================================================== class Window_APBuy < Window_ShopBuy #-------------------------------------------------------------------------- attr_accessor :status_window #-------------------------------------------------------------------------- # Initialize #-------------------------------------------------------------------------- def initialize(x, y, height, goods) super select(0) activate end #-------------------------------------------------------------------------- # Set Status Window #-------------------------------------------------------------------------- def status_window=(window) @status_window = window update_help end #-------------------------------------------------------------------------- # Set Actor #-------------------------------------------------------------------------- def actor=(actor) @actor = actor refresh end #-------------------------------------------------------------------------- # Enable Item? #-------------------------------------------------------------------------- def enable?(ability) return false unless @actor return false unless @goods[ability].enable? return false unless price(ability) <= @actor.ability_points return false if ability_learned?(ability) return false unless correct_class?(ability) return false unless required_abilities_learned?(ability) return false if blocked_abilities_learned?(ability) return true end #-------------------------------------------------------------------------- # Item Already Learned? #-------------------------------------------------------------------------- def ability_learned?(ability) return @actor && @actor.ability_learned?(ability.id) end #-------------------------------------------------------------------------- # Have Actor Correct Class For Learning? #-------------------------------------------------------------------------- def correct_class?(ability) return true unless ability.required_class_id return @actor.class_id == ability.required_class_id end #-------------------------------------------------------------------------- # Have Actor All Required Abilities Learned? #-------------------------------------------------------------------------- def required_abilities_learned?(ability) return true unless ability.required_ability_ids return ability.required_ability_ids.all? {|id| @actor.ability_learned?(id)} end #-------------------------------------------------------------------------- # Have Actor Any Blocked Abilities Learned? #-------------------------------------------------------------------------- def blocked_abilities_learned?(ability) return false unless ability.blocked_ability_ids return ability.blocked_ability_ids.any? {|id| @actor.ability_learned?(id)} end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item(index) ability = @data[index] rect = item_rect(index) draw_ability_name(ability, rect.x, rect.y, enable?(ability)) rect.width -= 4 draw_text(rect, price_vocab(ability), 2) end #-------------------------------------------------------------------------- # * Draw Ability Name # enabled : Enabled flag. When false, draw semi-transparently. #-------------------------------------------------------------------------- def draw_ability_name(ability, x, y, enabled = true, width = 172) return unless ability draw_icon(ability.icon_index, x, y, enabled) change_color(ability_color(ability), enabled) draw_text(x + 24, y, width, line_height, ability.name) end #-------------------------------------------------------------------------- # * Update Help Text #-------------------------------------------------------------------------- def update_help @help_window.set_item(item) if @help_window @status_window.item = item if @status_window @status_window.actor = @actor if @status_window end #-------------------------------------------------------------------------- # Price Vocabular #-------------------------------------------------------------------------- def price_vocab(ability) return ability_learned?(ability) ? E222::Vocab::LEARNED : price(ability) end #-------------------------------------------------------------------------- # Ability Color #-------------------------------------------------------------------------- def ability_color(ability) return (ability_learned?(ability) ? text_color(3) : normal_color) end #-------------------------------------------------------------------------- end #============================================================================== # ability Point Window #============================================================================== class Window_APPoints < Window_Base #-------------------------------------------------------------------------- # Initialize #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, Graphics.width - 304, fitting_height(1)) end #-------------------------------------------------------------------------- # Refresh #-------------------------------------------------------------------------- def refresh(actor, item_id) return unless actor contents.clear draw_ability_points(actor, item_id) end #-------------------------------------------------------------------------- # Draw ability Points #-------------------------------------------------------------------------- def draw_ability_points(actor, item_id) ap = actor.ability_points draw_text(0, 0, contents.width, line_height, E222::Vocab::AVAILABLE) draw_text(0, 0, contents.width, line_height, "#{ap} #{E222::Vocab::AP}", 2) end #-------------------------------------------------------------------------- end #============================================================================== # Learned Item List Window - TODO: add categories for abilites maybe? #============================================================================== class Window_APItemList < Window_Selectable #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(actor) super(0, fitting_height(7), Graphics.width, Graphics.height - fitting_height(7)) @data = [] @actor = actor select(0) refresh self.activate end #-------------------------------------------------------------------------- # * Get Digit Count #-------------------------------------------------------------------------- def col_max return 2 end #-------------------------------------------------------------------------- # * Set Actor #-------------------------------------------------------------------------- def actor=(actor) @actor = actor refresh end #-------------------------------------------------------------------------- # Get Actor #-------------------------------------------------------------------------- def actor return @actor end #-------------------------------------------------------------------------- # * Get Number of Items #-------------------------------------------------------------------------- def item_max @data ? @data.size : 1 end #-------------------------------------------------------------------------- # * Get Item #-------------------------------------------------------------------------- def item @data && index >= 0 ? @data[index] : nil end #-------------------------------------------------------------------------- # * Create Item List #-------------------------------------------------------------------------- def make_item_list return unless @actor @data = actor.learned_ability_ids.sort.collect {|id| $data_items[id]} end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] if item rect = item_rect(index) rect.width -= 4 draw_item_name(item, rect.x, rect.y) end end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh make_item_list create_contents draw_all_items end #-------------------------------------------------------------------------- # * Update Help Text #-------------------------------------------------------------------------- def update_help @help_window.set_item(item) end #-------------------------------------------------------------------------- end #============================================================================== # Status Window #============================================================================== class Window_APStatus < Window_Base #-------------------------------------------------------------------------- attr_accessor :point_window #-------------------------------------------------------------------------- # Initialize #-------------------------------------------------------------------------- def initialize(x, y, width, height) super refresh end #-------------------------------------------------------------------------- # Refresh #-------------------------------------------------------------------------- def refresh return unless @actor return unless @item contents.clear draw_vocab draw_horz_line(line_height) draw_required_class draw_abilities(0, line_height * 3) end #-------------------------------------------------------------------------- # Draw Vocab #-------------------------------------------------------------------------- def draw_vocab change_color(system_color) draw_text(0,0, contents.width, line_height, E222::Vocab::REQUIREMENT, 1) draw_text(0, line_height * 2, contents.width, line_height, E222::Vocab::CLASS) draw_text(0, line_height * 3, contents.width, line_height, E222::Vocab::ABILITIES) change_color(normal_color) end #-------------------------------------------------------------------------- # Draw Required Class #-------------------------------------------------------------------------- def draw_required_class change_color(class_color) draw_text(0, line_height * 2, contents.width, line_height, class_text, 2) change_color(normal_color) end #-------------------------------------------------------------------------- # Draw Abilities #-------------------------------------------------------------------------- def draw_abilities(x, y) if !@item.required_ability_ids && !@item.blocked_ability_ids draw_text(x, y, contents.width, line_height, E222::Vocab::NO_ITEMS, 2) else draw_required_abilities(x, y) draw_blocked_abilities(x, y) end end #-------------------------------------------------------------------------- # Draw Required Abilities #-------------------------------------------------------------------------- def draw_required_abilities(x, y) return unless @item.required_ability_ids @item.required_ability_ids.each_with_index do |id, i| text = sprintf(E222::Vocab::REQ_ABIL, $data_items[id].name) change_color(req_color(id)) draw_text(x, y + line_height * (i+1), contents.width, line_height, text) end end #-------------------------------------------------------------------------- # Draw Blocked Abilities #-------------------------------------------------------------------------- def draw_blocked_abilities(x, y) return unless @item.blocked_ability_ids @item.blocked_ability_ids.each_with_index do |id, i| text = sprintf(E222::Vocab::BLK_ABIL, $data_items[id].name) size = @item.required_ability_ids.size || 0 n_y = y + line_height * (i+1) + size * line_height change_color(blk_color(id)) draw_text(x, n_y, contents.width, line_height, text) end end #-------------------------------------------------------------------------- # * Draw Horizontal Line #-------------------------------------------------------------------------- def draw_horz_line(y) line_y = y + line_height / 2 - 1 contents.fill_rect(0, line_y, contents_width, 2, line_color) end #-------------------------------------------------------------------------- # Set Point Window #-------------------------------------------------------------------------- def point_window=(window) @point_window = window end #-------------------------------------------------------------------------- # Set Item #-------------------------------------------------------------------------- def item=(item) @item = item refresh end #-------------------------------------------------------------------------- # Set Actor #-------------------------------------------------------------------------- def actor=(actor) @actor = actor @point_window.refresh(actor, @item.id) if @point_window && @item refresh end #-------------------------------------------------------------------------- # Correct Class ? #-------------------------------------------------------------------------- def correct_class? return true unless @item.required_class_id return @actor.class_id == @item.required_class_id end #-------------------------------------------------------------------------- # Class Text #-------------------------------------------------------------------------- def class_text if !@item.required_class_id return E222::Vocab::NO_CLASS else return $data_classes[@item.required_class_id].name end end #-------------------------------------------------------------------------- # Class Color #-------------------------------------------------------------------------- def class_color if !@item.required_class_id || correct_class? return power_up_color else return power_down_color end end #-------------------------------------------------------------------------- # Color For Required Abilities #-------------------------------------------------------------------------- def req_color(id) if @actor.ability_learned?(id) return power_up_color else return power_down_color end end #-------------------------------------------------------------------------- # Color For Blocked Abilities #-------------------------------------------------------------------------- def blk_color(id) if !@actor.ability_learned?(id) return E222::AP_Config::BLOCK_COLOR else return power_down_color end end #-------------------------------------------------------------------------- # * Get Color of Horizontal Line #-------------------------------------------------------------------------- def line_color color = normal_color color.alpha = 48 color end #-------------------------------------------------------------------------- end #============================================================================== # Item Learn Scene #============================================================================== class Scene_Item_Learn < Scene_Shop #-------------------------------------------------------------------------- # Start #-------------------------------------------------------------------------- def start super create_actor_info_window create_actor_window create_interpreter create_message_window end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_gold_window return end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_dummy_window return end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_command_window return end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_number_window return end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_category_window return end #-------------------------------------------------------------------------- # Remove Un-Needed Method #-------------------------------------------------------------------------- def create_sell_window return end #-------------------------------------------------------------------------- # Create Interpreter #-------------------------------------------------------------------------- def create_interpreter @interpreter = Game_Interpreter.new end #-------------------------------------------------------------------------- # Create Help Window #-------------------------------------------------------------------------- def create_help_window @help_window = Window_Help.new end #-------------------------------------------------------------------------- # Create Status Window #-------------------------------------------------------------------------- def create_status_window height = Graphics.height - 144 - 48 @status_window = Window_APStatus.new(304, 144, Graphics.width - 304, height) @points_window = Window_APPoints.new(304, height + 144) @status_window.point_window = @points_window end #-------------------------------------------------------------------------- # Create Buy Window #-------------------------------------------------------------------------- def create_buy_window height = Graphics.height - 144 @buy_window = Window_APBuy.new(0, 144, height, @goods) @buy_window.help_window = @help_window @buy_window.status_window = @status_window @buy_window.set_handler(:ok, method(:on_buy_ok)) end #-------------------------------------------------------------------------- # Create Actor Info Window #-------------------------------------------------------------------------- def create_actor_info_window @actor_info_window = Window_APActorInfo.new end #-------------------------------------------------------------------------- # Create Actor Window #-------------------------------------------------------------------------- def create_actor_window @actor_window = Window_APActors.new(304, 72, Graphics.width - 304, 72) @actor_window.buy_window = @buy_window @actor_window.set_handler(:cancel, method(:return_scene)) @actor_window.info_window = @actor_info_window end #-------------------------------------------------------------------------- # Create Message Window #-------------------------------------------------------------------------- def create_message_window @message_window = Window_Message.new end #-------------------------------------------------------------------------- # Return Selected Item #-------------------------------------------------------------------------- def ability return @buy_window.item end #-------------------------------------------------------------------------- # Return Selected Actor #-------------------------------------------------------------------------- def actor return @actor_window.selected_actor end #-------------------------------------------------------------------------- # Return Selected Actor ID #-------------------------------------------------------------------------- def actor_id return actor.actor.id end #-------------------------------------------------------------------------- # Return Item Price #-------------------------------------------------------------------------- def price return @buy_window.price(ability) end #-------------------------------------------------------------------------- # On Buy Ok #-------------------------------------------------------------------------- def on_buy_ok @buy_window.deactivate @actor_window.deactivate do_buy process_common_event refresh_all_windows @actor_window.activate @buy_window.activate end #-------------------------------------------------------------------------- # Refresh All Windows #-------------------------------------------------------------------------- def refresh_all_windows @actor_info_window.refresh @points_window.refresh(actor, ability.id) @status_window.refresh @buy_window.refresh end #-------------------------------------------------------------------------- # Do Buy #-------------------------------------------------------------------------- def do_buy actor.learn_ability(ability.id) actor.reduce_ability_points(price) end #-------------------------------------------------------------------------- # Process Common Event #-------------------------------------------------------------------------- def process_common_event prepare_variables effects = ability.effects.select {|eff|eff.code == 44} effects.each {|eff| run_common_event(eff.data_id)} end #-------------------------------------------------------------------------- # Prepare Variables For Common Event #-------------------------------------------------------------------------- def prepare_variables $game_variables[E222::AP_Config::ACTOR_VARIABLE] = actor_id $game_variables[E222::AP_Config::ITEM_VARIABLE] = ability.id end #-------------------------------------------------------------------------- # Run Common Event #-------------------------------------------------------------------------- def run_common_event(event_id) $game_temp.reserve_common_event(event_id) @interpreter.setup_reserved_common_event update_interpreter while @interpreter.running? end #-------------------------------------------------------------------------- # Update Interpreter #-------------------------------------------------------------------------- def update_interpreter update_basic @interpreter.update end #-------------------------------------------------------------------------- # * Update Frame (Basic) #-------------------------------------------------------------------------- def update_basic Graphics.update Input.update @message_window.update update_all_windows unless $game_message.busy? end #-------------------------------------------------------------------------- end #============================================================================== # Item Learned Scene #============================================================================== class Scene_Learned_Items < Scene_MenuBase #-------------------------------------------------------------------------- # * Start #-------------------------------------------------------------------------- def start super create_help_window create_status_window create_item_window end #-------------------------------------------------------------------------- # * Create Item Window #-------------------------------------------------------------------------- def create_item_window @item_window = Window_APItemList.new(@actor) @item_window.help_window = @help_window @item_window.set_handler(:cancel, method(:return_scene)) @item_window.set_handler(:pagedown, method(:next_actor)) @item_window.set_handler(:pageup, method(:prev_actor)) end #-------------------------------------------------------------------------- # * Create Status Window #-------------------------------------------------------------------------- def create_status_window y = @help_window.height @status_window = Window_APActorInfo2.new(0, y) @status_window.actor = @actor end #-------------------------------------------------------------------------- # * On Actor Change #-------------------------------------------------------------------------- def on_actor_change @item_window.actor = @actor @status_window.actor = @actor @item_window.activate end #-------------------------------------------------------------------------- end #=============================================================================== # Game Item Learn #=============================================================================== class Game_Item_Learn < Game_Shop end #============================================================================== # Add new Scenes To Command Window #============================================================================== class Window_MenuCommand #-------------------------------------------------------------------------- # Add Main Commands #-------------------------------------------------------------------------- alias :e222_wmc_addmain_ap :add_main_commands #-------------------------------------------------------------------------- def add_main_commands e222_wmc_addmain_ap add_command(E222::Vocab::TRAIN_SCENE, :e222_ap_train, main_commands_enabled) add_command(E222::Vocab::VIEW_SCENE, :e222_ap_view, main_commands_enabled) end #-------------------------------------------------------------------------- end #============================================================================== # Add Handlers For New Scenes #============================================================================== class Scene_Menu #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- alias :e222_sm_start_ap :start #-------------------------------------------------------------------------- def start super e222_sm_start_ap add_new_handlers_e222 end #-------------------------------------------------------------------------- # * Add New Handlers #-------------------------------------------------------------------------- def add_new_handlers_e222 @command_window.set_handler(:e222_ap_train, method(:command_train_e222)) @command_window.set_handler(:e222_ap_view, method(:command_personal)) end #-------------------------------------------------------------------------- # * On Personal Ok #-------------------------------------------------------------------------- alias :e222_sm_onpersonalok_ap :on_personal_ok def on_personal_ok e222_sm_onpersonalok_ap case @command_window.current_symbol when :e222_ap_view SceneManager.call(Scene_Learned_Items) end end #-------------------------------------------------------------------------- # * Command Train #-------------------------------------------------------------------------- def command_train_e222 interpreter = Game_Interpreter.new interpreter.load_ap_item_shop end #-------------------------------------------------------------------------- end #============================================================================== # Script END #==============================================================================