Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The main class for abilities.
- # It is used inside Game_Actor.
- class Game_Abilities
- # data is a hash of arrays: [level, exp, aptitude, active]
- attr_accessor :data
- attr_reader :actor
- def initialize(actor)
- @data = {}
- @actor = actor
- $data_actors[actor.id].note.split(/[\r\n]+/).each { |line|
- p line
- if line =~ /<Ability (\w*) (\d*) (\d*)>/
- @data[$1] = [$2.to_i, actor.exp_for_level($2.to_i), $3.to_i, ($2.to_i>0 ? 1 : 0)]
- end
- }
- end
- def gain_exp(value)
- sum = 0
- for i in @data do
- sum += i[3] # 1 if active, 2 if focused
- end
- for i in @data do
- i[1] += value * i[2] * i[3] / sum
- i[0]+=1 if i[1] >= @actor.exp_for_level(i[0]+1)
- end
- end
- end
- # class Game_Actor
- class Game_Actor < Game_Battler
- attr_accessor :abils
- alias abilities_initialize initialize
- def initialize(actor_id)
- abilities_initialize(actor_id)
- @abils = Game_Abilities.new(self)
- end
- alias abilities_gain_exp gain_exp
- def gain_exp(exp)
- abilities_gain_exp(exp)
- @abils.gain_exp(exp)
- end
- end
- # new window: abilities list and activating-disactivating
- class Window_Ability < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(actor)
- super(0, fitting_height(2), Graphics.width, Graphics.height - fitting_height(2))
- @data = []
- @actor = actor
- refresh
- @index = 0 if @index < 0
- activate
- end
- #--------------------------------------------------------------------------
- # * Set Actor
- #--------------------------------------------------------------------------
- def actor=(actor)
- return if @actor == actor
- @actor = actor
- refresh
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- def make_item_list
- @data.clear
- @actor.abils.data.each_pair { |name, value|
- @data.push([name,value].flatten)
- #now it is: [name, level, exp, aptitude, active]
- }
- end
- def draw_ability_name(name, x, y, enabled)
- case enabled
- when 0
- change_color(normal_color, false)
- str = "- "
- when 1
- change_color(normal_color)
- str = "+ "
- when 2
- change_color(normal_color)
- str = "* "
- end
- draw_text(x, y, Graphics.width / 2, line_height, str + name)
- end
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 48
- draw_ability_name(item[0], rect.x, rect.y, item[4])
- draw_ability_level(rect, item)
- end
- end
- def draw_ability_level(rect, item)
- change_color(system_color)
- draw_text(rect, sprintf("%2d", item[1]), 2)
- rect.width += 48
- change_color(mp_cost_color)
- draw_text(rect, sprintf("%2d", item[3]), 2)
- end
- end
- # new scene: abilities activating-disactivating
- class Scene_Ability < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_help_window
- @status_window = Window_Ability.new(@actor)
- @status_window.set_handler(:cancel, method(:return_scene))
- @status_window.set_handler(:pagedown, method(:next_actor))
- @status_window.set_handler(:pageup, method(:prev_actor))
- @status_window.set_handler(:ok, method(:change))
- @help_window.set_text(@actor.name)
- end
- #--------------------------------------------------------------------------
- # * Change Actors
- #--------------------------------------------------------------------------
- def on_actor_change
- @status_window.actor = @actor
- @help_window.set_text(@actor.name)
- @status_window.activate
- end
- def change
- item = @status_window.item
- return if item.nil?
- @actor.abils.data[item[0]][3] = (@actor.abils.data[item[0]][3] + 1) % 3
- @status_window.refresh
- end
- end
- #==============================================================================
- # ** Window_MenuCommand
- #------------------------------------------------------------------------------
- # This command window appears on the menu screen.
- #==============================================================================
- class Window_MenuCommand < Window_Command
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- alias ability_make_command_list make_command_list
- def make_command_list
- ability_make_command_list
- add_command("Способности", :ability)
- end
- end
- #==============================================================================
- # ** Scene_Menu
- #------------------------------------------------------------------------------
- # This class performs the menu screen processing.
- #==============================================================================
- class Scene_Menu < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- alias ability_create_command_window create_command_window
- def create_command_window
- ability_create_command_window
- @command_window.set_handler(:ability, method(:command_ability))
- end
- def command_ability
- SceneManager.call(Scene_Ability)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment