查看: 2944|回复: 6

[已经解决] Ace怎样在人物升级时获得技能点学习技能

[复制链接]
梦石
0
星屑
100
在线时间
84 小时
注册时间
2010-10-16
回帖
110
发表于 2014-6-8 20:59:29 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
最近遇到这个麻烦了,希望大神解决
具体问题:想在人物升级后获得若干技能点,这个技能点不能提升人物能力只能学习技能。也就是说想做出战斗后如果人物升级获得若干技能点,打开一个窗口分配技能点学习各种技能的效果。
类似勇者斗恶龙9升级加点系统。谢谢了!
[img]http://rpg.blue/static/image/smiley/default/victory.
回归中........

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-6-8 21:00:59 | 显示全部楼层
论坛搜索“技能树”,也许可以找到你想要的
回复

使用道具 举报

梦石
0
星屑
100
在线时间
84 小时
注册时间
2010-10-16
回帖
110
 楼主| 发表于 2014-6-8 21:03:12 | 显示全部楼层
taroxd 发表于 2014-6-8 21:00
论坛搜索“技能树”,也许可以找到你想要的

首先先谢谢版主!但是目前ace有技能树系统吗?貌似没看到哎。。本人脚本盲。。
[img]http://rpg.blue/static/image/smiley/default/victory.
回归中........
回复

使用道具 举报

运否天赋

梦石
10
星屑
5246
在线时间
3568 小时
注册时间
2014-5-15
回帖
1441

开拓者

发表于 2014-6-8 21:27:34 | 显示全部楼层
脚本版:传送门 这个需要再设个变量判断升级后所加的技能点
事件版:传送门  虽然是XP版的,但是可以参照这个用事件做
土猫三国开发完成
回复

使用道具 举报

梦石
0
星屑
100
在线时间
84 小时
注册时间
2010-10-16
回帖
110
 楼主| 发表于 2014-6-8 22:32:17 | 显示全部楼层
喵kano 发表于 2014-6-8 21:27
脚本版:传送门 这个需要再设个变量判断升级后所加的技能点
事件版:传送门  虽然是XP版的,但是可以参照这 ...

这个是比较接近了。可是技能升级是将原有的技能升级成新的吧?从无到有怎么搞呢?

点评

或者最低级技能不可使用  发表于 2014-6-9 07:41
建议参考下第二个用事件做的  发表于 2014-6-8 22:33
[img]http://rpg.blue/static/image/smiley/default/victory.
回归中........
回复

使用道具 举报

梦石
0
星屑
240
在线时间
341 小时
注册时间
2010-9-5
回帖
66
发表于 2014-6-9 09:46:38 | 显示全部楼层
绝命崖 发表于 2014-6-8 22:32
这个是比较接近了。可是技能升级是将原有的技能升级成新的吧?从无到有怎么搞呢? ...

从无到有可以利用这个技能学习系统,一共三个脚本,给你
[pre lang="ruby" line="1"]#==============================================================================
#
# ▼ Yanfly Engine Ace - Ace Skill Menu v1.01
# -- Last Updated: 2012.01.08
# -- Level: Normal, Hard
# -- Requires: n/a
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-SkillMenu"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.08 - Compatibility Update: Learn Skill Engine
# 2012.01.02 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This is a menu reordering script for the Skill Menu for RPG Maker VX Ace. The
# script lets you add, remove, and rearrange skill menu additions added by
# other scripts. This script will update periodically to provide better updated
# compatibility with those other scripts.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# Adjust the module's settings to adjust the skill command window.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
#==============================================================================

module YEA
  module SKILL_MENU
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Command Window Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # Adjust the command window that appears in the skill command window. Add,
    # remove, or rearrange the commands as you see fit. If you would like to
    # add in custom commands, please refer to the custom hash. Here's a list of
    # what does what:
    #
    # -------------------------------------------------------------------------
    # :command         Description
    # -------------------------------------------------------------------------
    # :stype_list      Displays all of the actor's usable skill types.
    #
    # :tp_mode         Requires YEA - TP Manager
    # :learn_skill     Requires YEA - Learn Skill Engine
    #
    # :grathnode       Requires Kread-EX - Grathnode Install
    # :sslots          Requires YSA - Slots Battle
    #
    # And that's all of the currently available commands. This list will be
    # updated as more scripts become available.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    COMMANDS =[
      :stype_list,   # Displays all of the actor's usable skill types.
      :learn_skill,  # Requires YEA - Learn Skill Engine
      :tp_mode,      # Requires YEA - TP Manager
      :grathnode,    # Requires Kread-EX - Grathnode Install
      :sslots,       # Requires YSA - Slots Battle.
    # :custom1,      # Custom Skill Command 1
    # :custom2,      # Custom Skill Command 2
    ] # Do not remove this.
   
    #--------------------------------------------------------------------------
    # - Skill Custom Commands -
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # For those who use scripts to that may produce unique effects for
    # equipping, use this hash to manage the custom commands for the Skill
    # Command Window. You can disable certain commands or prevent them from
    # appearing by using switches. If you don't wish to bind them to a switch,
    # set the proper switch to 0 for it to have no impact.
    #--------------------------------------------------------------------------
    CUSTOM_SKILL_COMMANDS ={
    # :command => ["Display Name", EnableSwitch, ShowSwitch, Handler Method],
      :grathnode => ["Grathnodes",            0,          0, :command_grath],
      :sslots  => [  "Pick Slots",            0,          0, :command_sslot],
      :custom1 => [ "Custom Name",            0,          0, :command_name1],
      :custom2 => [ "Custom Text",           13,          0, :command_name2],
    } # Do not remove this.
   
  end # SKILL_MENU
end # YEA

#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

#==============================================================================
# ■ Game_Temp
#==============================================================================

class Game_Temp
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :scene_skill_index
  attr_accessor :scene_skill_oy
  
end # Game_Temp

#==============================================================================
# ■ Window_SkillCommand
#==============================================================================

class Window_SkillCommand < Window_Command
  
  #--------------------------------------------------------------------------
  # alias method: make_command_list
  #--------------------------------------------------------------------------
  alias window_skillcommand_make_command_list_asm make_command_list
  def make_command_list
    unless SceneManager.scene_is?(Scene_Skill)
      window_skillcommand_make_command_list_asm
      return
    end
    return unless @actor
    for command in YEA::SKILL_MENU::COMMANDS
      case command
      #--- Imported YEA ---
      when :stype_list
        add_skill_types
      #--- Imported YEA ---
      when :tp_mode
        next unless $imported["YEA-TPManager"]
        add_tp_modes
      when :learn_skill
        next unless $imported["YEA-LearnSkillEngine"]
        add_learn_skill_command
      #--- Imported Other ---
      when :grathnode
        next unless $imported["KRX-GrathnodeInstall"]
        process_custom_command(command)
      when :sslots
        next unless $imported["YSA-SlotBattle"]
        process_custom_command(command)
      #--- Custom Commands ---
      else
        process_custom_command(command)
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: add_skill_types
  #--------------------------------------------------------------------------
  def add_skill_types
    @actor.added_skill_types.each do |stype_id|
      name = $data_system.skill_types[stype_id]
      add_command(name, :skill, true, stype_id)
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: process_custom_command
  #--------------------------------------------------------------------------
  def process_custom_command(command)
    return unless YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS.include?(command)
    show = YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS[command][2]
    continue = show <= 0 ? true : $game_switches[show]
    return unless continue
    text = YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS[command][0]
    switch = YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS[command][1]
    enabled = switch <= 0 ? true : $game_switches[switch]
    add_command(text, command, enabled, @actor.added_skill_types[0])
  end
  
  #--------------------------------------------------------------------------
  # new method: process_ok
  #--------------------------------------------------------------------------
  def process_ok
    if SceneManager.scene_is?(Scene_Skill)
      $game_temp.scene_skill_index = index
      $game_temp.scene_skill_oy = self.oy
    end
    super
  end
  
end # Window_SkillCommand

#==============================================================================
# ■ Scene_Skill
#==============================================================================

class Scene_Skill < Scene_ItemBase
  
  #--------------------------------------------------------------------------
  # alias method: create_command_window
  #--------------------------------------------------------------------------
  alias scene_skill_create_command_window_asm create_command_window
  def create_command_window
    scene_skill_create_command_window_asm
    if !$game_temp.scene_skill_index.nil? && SceneManager.scene_is?(Scene_Skill)
      @command_window.select($game_temp.scene_skill_index)
      @command_window.oy = $game_temp.scene_skill_oy
    end
    $game_temp.scene_skill_index = nil
    $game_temp.scene_skill_oy = nil
    process_custom_skill_commands
  end
  
  #--------------------------------------------------------------------------
  # new method: process_custom_skill_commands
  #--------------------------------------------------------------------------
  def process_custom_skill_commands
    for command in YEA::SKILL_MENU::COMMANDS
      next unless YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS.include?(command)
      called_method = YEA::SKILL_MENU::CUSTOM_SKILL_COMMANDS[command][3]
      @command_window.set_handler(command, method(called_method))
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: command_grath
  #--------------------------------------------------------------------------
  def command_grath
    SceneManager.call(Scene_Grathnode)
  end
  
  #--------------------------------------------------------------------------
  # new method: command_sslot
  #--------------------------------------------------------------------------
  def command_sslot
    SceneManager.call(Scene_PickSlots)
  end
  
  #--------------------------------------------------------------------------
  # new method: command_name1
  #--------------------------------------------------------------------------
  def command_name1
    # Do nothing.
  end
  
  #--------------------------------------------------------------------------
  # new method: command_name2
  #--------------------------------------------------------------------------
  def command_name2
    # Do nothing.
  end
  
end # Scene_Skill

#==============================================================================
#
# ▼ End of File
#
#==============================================================================[/pre]
[pre lang="ruby" line="1"]#==============================================================================
#
# ▼ Yanfly Engine Ace - Learn Skill Engine v1.00
# -- Last Updated: 2012.01.08
# -- Level: Normal, Hard
# -- Requires: n/a
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-LearnSkillEngine"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.08 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# For those who want an alternative for actors to learn skills outside of
# leveling, this script allows actors to learn skills through a learn skill
# menu. The actor can use acquired JP, EXP, or Gold to learn skills. Skills can
# also be hidden until certain requirements are met.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Class Notetags - These notetags go in the class notebox in the database.
# -----------------------------------------------------------------------------
# <learn skills: x>
# <learn skills: x, x>
# Sets the class to be able to learn skills x through the Learn Skills menu.
# Insert multiple of these tags to increase the number of skills learned.
#
# -----------------------------------------------------------------------------
# Skill Notetags - These notetags go in the skill notebox in the database.
# -----------------------------------------------------------------------------
# <learn cost: x jp>
# <learn cost: x exp>
# <learn cost: x gold>
# Sets the learn for cost the skill to require x amounts of JP, x amounts of
# exp, or x amounts of gold. Only one type of cost can be used at a time. For
# JP costs, the Yanfly Engine Ace - JP Manager script must be installed.
#
# <learn require level: x>
# Sets the skill to require the actor's current level to be x before the skill
# will show up in the skill learning window.
#
# <learn require skill: x>
# <learn require skill: x, x>
# Sets the skill to require learning skill x (through any means) before the
# skill becomes visible in the skill learning window. Insert multiples of these
# tags to require more skills to be learned in order for the skill to show.
#
# <learn require switch: x>
# <learn require switch: x, x>
# Sets the skill to require switch x to be ON in order for it to show in the
# skill learning window. Insert multiple switches to to increase the number of
# switches needed to be ON before the skill is shown.
#
# <learn require eval>
#  string
#  string
# </learn require eval>
# For the more advanced users, replace string with lines of code to check for
# whether or not the skill will be shown in skill learning window. If multiple
# lines are used, they are all considered part of the same line.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
# This script is compatible with Yanfly Engine Ace - JP Manager v1.00+. The
# placement of this script relative to the JP Manager script doesn't matter.
#
#==============================================================================

module YEA
  module LEARN_SKILL
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - General Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # Adjust the general settings here for your game. These adjust how the
    # command name appears, a switch to show the Learn Command
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    COMMAND_NAME = "学习技能"    # Name used for Learn Skill command.
   
    # This switch will hide the "Learn" command from view if the switch is OFF.
    # The "Learn" command will be shown if the switch is ON. Set this switch to
    # 0 to not use this effect and to always have the Learn command be shown.
    SHOW_SWITCH   = 0
   
    # This adjusts the order the Skill Types appear in for the command window.
    # Any Skill Types unlisted will not be shown.
    STYPE_ORDER = [41..999, 1..40]
   
    # For those who installed Yanfly Engine - Skill Restrictions, you can
    # choose to display warmups or cooldowns inside of the menu here.
    DRAW_WARMUP   = true        # Draw warmups for skills?
    DRAW_COOLDOWN = true        # Draw cooldowns for skills?
   
    #-------------------------------------------------------------------------
    # - Default Cost -
    #-------------------------------------------------------------------------
    # This sets the default costs for all skills. If the JP script isn't
    # installed, the type will become :exp instead.
    #
    # Cost Type       Description
    #  :jp            - Requires YEA - JP Manager.
    #  :exp           - Makes skill cost EXP.
    #  :gold          - Makes skill cost gold.
    #-------------------------------------------------------------------------
    DEFAULT_COST = 100          # Sets the default cost of a skill.
    DEFAULT_TYPE = :jp          # Sets the default cost type.
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Learn Window Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # These settings adjust the Learn Window's visual appearance. Adjust the
    # way empty text appears, EXP cost suffixes appear, Learned text appears,
    # font sizes, and cost colours here.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    EMPTY_TEXT     = "-"        # Text if no restricts used for the skill.
    EXP_TEXT       = "EXP"      # Text used for EXP costs.
    LEARNED_TEXT   = "领悟"  # Text to indicate skill has been learned.
    LEARNED_SIZE   = 20         # Font size used for learned skill text.
    COLOUR_JP      = 24         # Text colour used for JP Cost.
    COLOUR_EXP     =  5         # Text colour used for EXP Cost.
    COLOUR_GOLD    = 21         # Text colour used for Gold Cost.
    COST_SIZE      = 20         # Font size used for skill costs.
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Cost Window Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # When a skill is selected to be learned, the cost window appears. Adjust
    # the settings here to choose how your game's cost window looks. Change the
    # maximum number of rows, the gold icon used for gold costs, the gold text,
    # the learn skill text, the cancel text, and the cancel icon here.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    MAXIMUM_ROWS      = 8               # Maximum number of rows displayed.
    GOLD_ICON         = 361             # Icon used for gold costs.
    GOLD_TEXT         = "金币"     # Text used for gold costs.
    LEARN_SKILL_TEXT  = "学习 %s?"     # Text used to learn skill.
    LEARN_CANCEL_TEXT = "放弃"        # Text used for do not learn.
    CANCEL_ICON       = 187             # Icon used for cancel.
   
  end # LEARN_SKILL
end # YEA

#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

module YEA
  module LEARN_SKILL
    module_function
    #--------------------------------------------------------------------------
    # convert_integer_array
    #--------------------------------------------------------------------------
    def convert_integer_array(array)
      result = []
      array.each { |i|
        case i
        when Range; result |= i.to_a
        when Integer; result |=
        end }
      return result
    end
    #--------------------------------------------------------------------------
    # converted_contants
    #--------------------------------------------------------------------------
    STYPE_ORDER = convert_integer_array(STYPE_ORDER)
  end # LEARN_SKILL
  module REGEXP
  module CLASS
   
    LEARN_SKILLS = /<(?:LEARN_SKILLS|learn skills):[ ](\d+(?:\s*,\s*\d+)*)>/i
   
  end # CLASS
  module SKILL
   
    LEARN_COST = /<(?:LEARN_COST|learn cost):[ ](.*)>/i
    LEARN_REQUIRE_LEVEL =
      /<(?:LEARN_REQUIRE_LEVEL|learn require level):[ ](\d+)>/i
    LEARN_REQUIRE_SKILL =
      /<(?:LEARN_REQUIRE_SKILL|learn require skill):[ ](\d+(?:\s*,\s*\d+)*)>/i
    LEARN_REQUIRE_SWITCH =
      /<(?:LEARN_REQUIRE_SWITCH|learn require switch):[ ](\d+(?:\s*,\s*\d+)*)>/i
    LEARN_REQUIRE_EVAL_ON  = /<(?:LEARN_REQUIRE_EVAL|learn require eval)>/i
    LEARN_REQUIRE_EVAL_OFF = /<\/(?:LEARN_REQUIRE_EVAL|learn require eval)>/i
   
  end # SKILL
  end # REGEXP
end # YEA

#==============================================================================
# ■ Numeric
#==============================================================================

class Numeric
  
  #--------------------------------------------------------------------------
  # new method: group_digits
  #--------------------------------------------------------------------------
  unless $imported["YEA-CoreEngine"]
  def group; return self.to_s; end
  end # $imported["YEA-CoreEngine"]
   
end # Numeric

#==============================================================================
# ■ Icon
#==============================================================================

module Icon
  
  #--------------------------------------------------------------------------
  # self.cancel
  #--------------------------------------------------------------------------
  def self.cancel
    return YEA::LEARN_SKILL::CANCEL_ICON
  end
  
  #--------------------------------------------------------------------------
  # self.learn_skill_gold
  #--------------------------------------------------------------------------
  def self.learn_skill_gold
    return YEA::LEARN_SKILL::GOLD_ICON
  end
  
end # Icon

#==============================================================================
# ■ Switch
#==============================================================================

module Switch
  
  #--------------------------------------------------------------------------
  # self.show_learn_skill
  #--------------------------------------------------------------------------
  def self.show_learn_skill
    return true if YEA::LEARN_SKILL::SHOW_SWITCH <= 0
    return $game_switches[YEA::LEARN_SKILL::SHOW_SWITCH]
  end
  
end # Switch

#==============================================================================
# ■ DataManager
#==============================================================================

module DataManager
  
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  class <<self; alias load_database_lse load_database; end
  def self.load_database
    load_database_lse
    load_notetags_lse
  end
  
  #--------------------------------------------------------------------------
  # new method: load_notetags_lse
  #--------------------------------------------------------------------------
  def self.load_notetags_lse
    groups = [$data_classes, $data_skills]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_lse
      end
    end
  end
  
end # DataManager

#==============================================================================
# ■ RPG::Class
#==============================================================================

class RPG::Class < RPG::BaseItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :learn_skills
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_lse
  #--------------------------------------------------------------------------
  def load_notetags_lse
    @learn_skills = []
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEA::REGEXP::CLASS::LEARN_SKILLS
        $1.scan(/\d+/).each { |num|
        @learn_skills.push(num.to_i) if num.to_i > 0 }
      end
    } # self.note.split
    #---
  end
  
end # RPG::Class

#==============================================================================
# ■ RPG::Skill
#==============================================================================

class RPG::Skill < RPG::UsableItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :learn_cost
  attr_accessor :learn_require_level
  attr_accessor :learn_require_skill
  attr_accessor :learn_require_switch
  attr_accessor :learn_require_eval
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_lse
  #--------------------------------------------------------------------------
  def load_notetags_lse
    @learn_cost = [YEA::LEARN_SKILL::DEFAULT_COST]
    @learn_cost.push(YEA::LEARN_SKILL::DEFAULT_TYPE)
    @learn_require_level = 0
    @learn_require_skill = []
    @learn_require_switch = []
    @learn_require_eval_on = false
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEA::REGEXP::SKILL::LEARN_COST
        case $1.upcase
        when /(\d+)[ ]JP/i
          next unless $imported["YEA-JPManager"]
          @learn_cost = [$1.to_i, :jp]
        when /(\d+)[ ]EXP/i
          @learn_cost = [$1.to_i, :exp]
        when /(\d+)[ ]GOLD/i
          @learn_cost = [$1.to_i, :gold]
        end
      #---
      when YEA::REGEXP::SKILL::LEARN_REQUIRE_LEVEL
        @learn_require_level = $1.to_i
      when YEA::REGEXP::SKILL::LEARN_REQUIRE_SKILL
        $1.scan(/\d+/).each { |num|
        @learn_require_skill.push(num.to_i) if num.to_i > 0 }
      when YEA::REGEXP::SKILL::LEARN_REQUIRE_SWITCH
        $1.scan(/\d+/).each { |num|
        @learn_require_switch.push(num.to_i) if num.to_i > 0 }
      #---
      when YEA::REGEXP::SKILL::LEARN_REQUIRE_EVAL_ON
        @learn_require_eval_on = true
      when YEA::REGEXP::SKILL::LEARN_REQUIRE_EVAL_OFF
        @learn_require_eval_on = false
      else
        next unless @learn_require_eval_on
        @learn_require_eval = "" if @learn_require_eval.nil?
        @learn_require_eval += line.to_s
      #---
      end
    } # self.note.split
    #---
    if !$imported["YEA-JPManager"] && @learn_cost[1] == :jp
      @learn_cost[1] = :exp
    end
  end
  
end # RPG::Skill

#==============================================================================
# ■ Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  
  #--------------------------------------------------------------------------
  # alias method: skills
  #--------------------------------------------------------------------------
  alias game_actor_skills_lse skills
  def skills
    btest_add_learn_skills
    game_actor_skills_lse
  end
  
  #--------------------------------------------------------------------------
  # new method: btest_add_learn_skills
  #--------------------------------------------------------------------------
  def btest_add_learn_skills
    return unless $BTEST
    for skill_id in self.class.learn_skills; learn_skill(skill_id); end
  end
  
  #--------------------------------------------------------------------------
  # new method: exp_class
  #--------------------------------------------------------------------------
  def exp_class(class_id)
    @exp[class_id] = 0 if @exp[class_id].nil?
    return @exp[class_id]
  end
  
  #--------------------------------------------------------------------------
  # lose_exp_class
  #--------------------------------------------------------------------------
  def lose_exp_class(value, class_id)
    exp = exp_class(class_id) - value
    change_exp_class(exp, class_id)
  end
  
  #--------------------------------------------------------------------------
  # change_exp_class
  #--------------------------------------------------------------------------
  def change_exp_class(exp, class_id)
    return change_exp(exp, false) if class_id == @class_id
    @exp[class_id] = [exp, 0].max
  end
  
end # Game_Actor

#==============================================================================
# ■ Window_SkillCommand
#==============================================================================

class Window_SkillCommand < Window_Command
  
  #--------------------------------------------------------------------------
  # alias method: make_command_list
  #--------------------------------------------------------------------------
  alias window_skillcommand_make_command_list_lse make_command_list
  def make_command_list
    window_skillcommand_make_command_list_lse
    return if @actor.nil?
    add_learn_skill_command unless $imported["YEA-SkillMenu"]
  end
  
  #--------------------------------------------------------------------------
  # new method: add_learn_skill_command
  #--------------------------------------------------------------------------
  def add_learn_skill_command
    return unless Switch.show_learn_skill
    name = YEA::LEARN_SKILL::COMMAND_NAME
    add_command(name, :learn_skill, true, @actor.added_skill_types[0])
  end
  
end # Window_SkillCommand

#==============================================================================
# ■ Window_LearnSkillCommand
#==============================================================================

class Window_LearnSkillCommand < Window_Command
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_reader   :skill_window
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(dx, dy)
    super(dx, dy)
    @actor = nil
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width; return 160; end
  
  #--------------------------------------------------------------------------
  # visible_line_number
  #--------------------------------------------------------------------------
  def visible_line_number; return 4; end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(actor)
    return if @actor == actor
    @actor = actor
    refresh
    select(item_max - 1) if index >= item_max
  end
  
  #--------------------------------------------------------------------------
  # make_command_list
  #--------------------------------------------------------------------------
  def make_command_list
    return if @actor.nil?
    make_unlocked_class_skill_types
    correct_unlocked_class_learned_skills
    for stype_id in YEA::LEARN_SKILL::STYPE_ORDER
      next unless include?(stype_id)
      name = $data_system.skill_types[stype_id]
      add_command(name, :skill, true, stype_id)
    end
  end
  
  #--------------------------------------------------------------------------
  # make_unlocked_class_skill_types
  #--------------------------------------------------------------------------
  def make_unlocked_class_skill_types
    return unless $imported["YEA-ClassSystem"]
    @unlocked_types = []
    unlocked_classes = @actor.unlocked_classes.clone
    unlocked_classes |= YEA::CLASS_SYSTEM::DEFAULT_UNLOCKS
    for class_id in unlocked_classes
      next if $data_classes[class_id].nil?
      for feature in $data_classes[class_id].features
        next unless feature.code == 41
        @unlocked_types.push(feature.data_id)
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # correct_unlocked_class_learned_skills
  #--------------------------------------------------------------------------
  def correct_unlocked_class_learned_skills
    return unless $imported["YEA-ClassSystem"]
    unlocked_classes = @actor.unlocked_classes.clone
    unlocked_classes |= YEA::CLASS_SYSTEM::DEFAULT_UNLOCKS
    for class_id in unlocked_classes
      @actor.learn_class_skills(class_id)
    end
  end
  
  #--------------------------------------------------------------------------
  # include?
  #--------------------------------------------------------------------------
  def include?(stype_id)
    return true if @actor.added_skill_types.include?(stype_id)
    if $imported["YEA-ClassSystem"]
      return true if @unlocked_types.include?(stype_id)
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    super
    @skill_window.stype_id = current_ext if @skill_window
  end
  
  #--------------------------------------------------------------------------
  # skill_window=
  #--------------------------------------------------------------------------
  def skill_window=(skill_window)
    @skill_window = skill_window
    update
  end
  
end # Window_LearnSkillCommand

#==============================================================================
# ■ Window_LearnSkillList
#==============================================================================

class Window_LearnSkillList < Window_SkillList
  
  #--------------------------------------------------------------------------
  # col_max
  #--------------------------------------------------------------------------
  def col_max; return 1; end
  
  #--------------------------------------------------------------------------
  # select_last
  #--------------------------------------------------------------------------
  def select_last; select(0); end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(actor)
    return if @actor == actor
    super(actor)
    make_learn_skills_list
  end
  
  #--------------------------------------------------------------------------
  # make_learn_skills_list
  #--------------------------------------------------------------------------
  def make_learn_skills_list
    @learn_skills = []
    @skill_classes = {}
    return if @actor.nil?
    for skill_id in @actor.class.learn_skills
      next if $data_skills[skill_id].nil?
      next if @learn_skills.include?($data_skills[skill_id])
      skill = $data_skills[skill_id]
      @learn_skills.push(skill)
      @skill_classes[skill] = [] if @skill_classes[skill].nil?
      @skill_classes[skill].push(@actor.class.id)
    end
    make_unlocked_class_skills
  end
  
  #--------------------------------------------------------------------------
  # make_unlocked_class_skills
  #--------------------------------------------------------------------------
  def make_unlocked_class_skills
    return unless $imported["YEA-ClassSystem"]
    @unlocked_types = []
    unlocked_classes = @actor.unlocked_classes.clone
    unlocked_classes |= YEA::CLASS_SYSTEM::DEFAULT_UNLOCKS
    for class_id in unlocked_classes
      next if $data_classes[class_id].nil?
      for skill_id in $data_classes[class_id].learn_skills
        next if $data_skills[skill_id].nil?
        skill = $data_skills[skill_id]
        @learn_skills.push(skill) unless @learn_skills.include?(skill)
        @skill_classes[skill] = [] if @skill_classes[skill].nil?
        @skill_classes[skill] |= [class_id]
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # skill_classes
  #--------------------------------------------------------------------------
  def skill_classes(skill)
    return @skill_classes[skill]
  end
  
  #--------------------------------------------------------------------------
  # make_item_list
  #--------------------------------------------------------------------------
  def make_item_list
    return if @learn_skills.nil?
    @data = @learn_skills.select {|skill| include?(skill) }
  end
  
  #--------------------------------------------------------------------------
  # include?
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item.nil?
    return false unless meet_requirements?(item)
    return item.stype_id == @stype_id
  end
  
  #--------------------------------------------------------------------------
  # meet_requirements?
  #--------------------------------------------------------------------------
  def meet_requirements?(item)
    return false if @actor.nil?
    return false unless meet_level_requirements?(item)
    return false unless meet_skill_requirements?(item)
    return false unless meet_switch_requirements?(item)
    return false unless meet_eval_requirements?(item)
    return true
  end
  
  #--------------------------------------------------------------------------
  # meet_level_requirements?
  #--------------------------------------------------------------------------
  def meet_level_requirements?(item)
    return @actor.level >= item.learn_require_level
  end
  
  #--------------------------------------------------------------------------
  # meet_skill_requirements?
  #--------------------------------------------------------------------------
  def meet_skill_requirements?(item)
    for skill_id in item.learn_require_skill
      next if $data_skills[skill_id].nil?
      return false unless @actor.skill_learn?($data_skills[skill_id])
    end
    return true
  end
  
  #--------------------------------------------------------------------------
  # meet_switch_requirements?
  #--------------------------------------------------------------------------
  def meet_switch_requirements?(item)
    for switch_id in item.learn_require_switch
      return false unless $game_switches[switch_id]
    end
    return true
  end
  
  #--------------------------------------------------------------------------
  # meet_eval_requirements?
  #--------------------------------------------------------------------------
  def meet_eval_requirements?(item)
    return true if item.learn_require_eval.nil?
    return eval(item.learn_require_eval)
  end
  
  #--------------------------------------------------------------------------
  # enable?
  #--------------------------------------------------------------------------
  def enable?(skill)
    return false if skill.nil?
    return false unless enabled_jp?(skill)
    return false unless enabled_exp?(skill)
    return false unless enabled_gold?(skill)
    return !@actor.skill_learn?(skill)
  end
  
  #--------------------------------------------------------------------------
  # enabled_jp?
  #--------------------------------------------------------------------------
  def enabled_jp?(skill)
    return true if skill.learn_cost[1] != :jp
    cost = skill.learn_cost[0]
    for class_id in @skill_classes[skill]
      return true if @actor.jp(class_id) >= cost
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # enabled_exp?
  #--------------------------------------------------------------------------
  def enabled_exp?(skill)
    return true if skill.learn_cost[1] != :exp
    cost = skill.learn_cost[0]
    for class_id in @skill_classes[skill]
      return true if @actor.exp_class(class_id) >= cost
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # enabled_gold?
  #--------------------------------------------------------------------------
  def enabled_gold?(skill)
    return true if skill.learn_cost[1] != :gold
    cost = skill.learn_cost[0]
    return $game_party.gold >= cost
  end
  
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    return if skill.nil?
    rect = item_rect(index)
    rect.width = (contents.width - spacing) / 2 - 4
    draw_item_name(skill, rect.x, rect.y, enable?(skill), rect.width - 24)
    draw_skill_cost(rect, skill)
    draw_restriction_info(skill, index)
    draw_learn_cost(skill, index)
  end
  
  #--------------------------------------------------------------------------
  # skill_restriction?
  #--------------------------------------------------------------------------
  def skill_restriction?(index)
    return false
  end
  
  #--------------------------------------------------------------------------
  # draw_restriction_info
  #--------------------------------------------------------------------------
  def draw_restriction_info(skill, index)
    return unless $imported["YEA-SkillRestrictions"]
    rect = item_rect(index)
    rect.x = contents.width / 2
    rect.width /= 2
    rect.width /= 3
    rect.width -= 8
    draw_skill_warmup(skill, rect)
    rect.x += rect.width + 4
    draw_skill_cooldown(skill, rect)
  end
  
  #--------------------------------------------------------------------------
  # draw_skill_warmup
  #--------------------------------------------------------------------------
  def draw_skill_warmup(skill, rect)
    return unless YEA::LEARN_SKILL::DRAW_WARMUP
    enabled = enable?(skill)
    enabled = false if skill.warmup <= 0
    change_color(warmup_colour, enabled)
    icon = Icon.warmup
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    contents.font.size = YEA::SKILL_RESTRICT::WARMUP_SIZE
    value = skill.warmup > 0 ? skill.warmup.group : empty_text
    text = sprintf(YEA::SKILL_RESTRICT::WARMUP_SUFFIX, value)
    draw_text(rect, text, 2)
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # draw_skill_cooldown
  #--------------------------------------------------------------------------
  def draw_skill_cooldown(skill, rect)
    return unless YEA::LEARN_SKILL::DRAW_COOLDOWN
    enabled = enable?(skill)
    enabled = false if skill.cooldown <= 0
    change_color(cooldown_colour, enabled)
    icon = Icon.cooldown
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    contents.font.size = YEA::SKILL_RESTRICT::COOLDOWN_SIZE
    value = skill.cooldown > 0 ? skill.cooldown.group : empty_text
    text = sprintf(YEA::SKILL_RESTRICT::COOLDOWN_SUFFIX, value)
    draw_text(rect, text, 2)
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # empty_text
  #--------------------------------------------------------------------------
  def empty_text
    return YEA::LEARN_SKILL::EMPTY_TEXT
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_cost
  #--------------------------------------------------------------------------
  def draw_learn_cost(skill, index)
    rect = item_rect(index)
    rect.width -= 4
    if @actor.skill_learn?(skill)
      draw_learned_skill(rect)
    else
      draw_learn_skill_cost(skill, rect)
    end
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # draw_learned_skill
  #--------------------------------------------------------------------------
  def draw_learned_skill(rect)
    contents.font.size = YEA::LEARN_SKILL::LEARNED_SIZE
    change_color(normal_color)
    draw_text(rect, YEA::LEARN_SKILL::LEARNED_TEXT, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_skill_cost
  #--------------------------------------------------------------------------
  def draw_learn_skill_cost(skill, rect)
    case skill.learn_cost[1]
    when :jp
      return unless $imported["YEA-JPManager"]
      draw_jp_cost(skill, rect)
    when :exp
      draw_exp_cost(skill, rect)
    when :gold
      draw_gold_cost(skill, rect)
    else; return
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_jp_cost
  #--------------------------------------------------------------------------
  def draw_jp_cost(skill, rect)
    enabled = enabled_jp?(skill)
    if Icon.jp > 0
      draw_icon(Icon.jp, rect.x + rect.width - 24, rect.y, enabled)
      rect.width -= 24
    end
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::jp, 2)
    rect.width -= text_size(Vocab::jp).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_JP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_exp_cost
  #--------------------------------------------------------------------------
  def draw_exp_cost(skill, rect)
    enabled = enabled_exp?(skill)
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, YEA::LEARN_SKILL::EXP_TEXT, 2)
    rect.width -= text_size(YEA::LEARN_SKILL::EXP_TEXT).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_EXP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_cost
  #--------------------------------------------------------------------------
  def draw_gold_cost(skill, rect)
    enabled = enabled_jp?(skill)
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::currency_unit, 2)
    rect.width -= text_size(Vocab::currency_unit).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_GOLD), enabled)
    draw_text(rect, text, 2)
  end
  
end # Window_LearnSkillList

#==============================================================================
# ■ Window_LearnSkillCostBack
#==============================================================================

class Window_LearnSkillCostBack < Window_Base
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(item_window)
    dw = Graphics.width * 3 / 4
    dx = (Graphics.width - dw) / 2
    super(dx, 0, dw, fitting_height(2))
    self.openness = 0
    self.back_opacity = 255
    @front_window = nil
    @item_window = item_window
    @skill = nil
  end
  
  #--------------------------------------------------------------------------
  # reveal
  #--------------------------------------------------------------------------
  def reveal(skill, skill_classes)
    @skill = skill
    return if @skill.nil?
    case @skill.learn_cost[1]
    when :gold
      self.height = fitting_height(3)
    else
      maximum = [skill_classes.size, YEA::LEARN_SKILL::MAXIMUM_ROWS].min
      self.height = fitting_height(maximum + 2)
    end
    create_contents
    self.y = (Graphics.height - self.height) / 2
    refresh
    open
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    reset_font_settings
    draw_learn_skill_text
    rect = Rect.new(0, 0, contents.width - 4, line_height)
    draw_learn_skill_cost(@skill, rect)
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_skill_text
  #--------------------------------------------------------------------------
  def draw_learn_skill_text
    name = sprintf("\eI[%d]%s", @skill.icon_index, @skill.name)
    fmt = YEA::LEARN_SKILL::LEARN_SKILL_TEXT
    text = sprintf(fmt, name)
    draw_text_ex(4, 0, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_skill_cost
  #--------------------------------------------------------------------------
  def draw_learn_skill_cost(skill, rect)
    case skill.learn_cost[1]
    when :jp
      return unless $imported["YEA-JPManager"]
      draw_jp_cost(skill, rect)
    when :exp
      draw_exp_cost(skill, rect)
    when :gold
      draw_gold_cost(skill, rect)
    else; return
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_jp_cost
  #--------------------------------------------------------------------------
  def draw_jp_cost(skill, rect)
    enabled = true
    if Icon.jp > 0
      draw_icon(Icon.jp, rect.x + rect.width - 24, rect.y, enabled)
      rect.width -= 24
    end
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::jp, 2)
    rect.width -= text_size(Vocab::jp).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_JP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_exp_cost
  #--------------------------------------------------------------------------
  def draw_exp_cost(skill, rect)
    enabled = true
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, YEA::LEARN_SKILL::EXP_TEXT, 2)
    rect.width -= text_size(YEA::LEARN_SKILL::EXP_TEXT).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_EXP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_cost
  #--------------------------------------------------------------------------
  def draw_gold_cost(skill, rect)
    enabled = true
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::currency_unit, 2)
    rect.width -= text_size(Vocab::currency_unit).width
    cost = skill.learn_cost[0]
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_GOLD), enabled)
    draw_text(rect, text, 2)
  end
  
end # Window_LearnSkillCostBack

#==============================================================================
# ■ Window_LearnSkillCostFront
#==============================================================================

class Window_LearnSkillCostFront < Window_Command
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(item_window, cost_window)
    super((Graphics.width - window_width) / 2, 0)
    self.openness = 0
    self.opacity = 0
    @item_window = item_window
    @cost_window = cost_window
    @skill = nil
    @actor = nil
    deactivate
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width; return Graphics.width * 3 / 4; end
  
  #--------------------------------------------------------------------------
  # skill_class
  #--------------------------------------------------------------------------
  def skill_class
    return @skill_classes.nil? ? nil : @skill_classes[index]
  end
  
  #--------------------------------------------------------------------------
  # reveal
  #--------------------------------------------------------------------------
  def reveal(skill, skill_classes, actor)
    @skill = skill
    @skill_classes = skill_classes.clone
    @actor = actor
    return if @skill.nil?
    case @skill.learn_cost[1]
    when :gold
      self.height = fitting_height(2)
    else
      maximum = [skill_classes.size, YEA::LEARN_SKILL::MAXIMUM_ROWS].min
      self.height = fitting_height(maximum + 1)
    end
    create_contents
    self.y = @cost_window.y + line_height
    refresh
    select(0)
    open
    activate
  end
  
  #--------------------------------------------------------------------------
  # make_command_list
  #--------------------------------------------------------------------------
  def make_command_list
    return if @skill_classes.nil?
    if @skill.learn_cost[1] == :gold
      add_command("GOLD", :gold, true)
      add_command(YEA::LEARN_SKILL::LEARN_CANCEL_TEXT, :cancel, true)
      return
    end
    for class_id in @skill_classes
      name = $data_classes[class_id].name
      add_command(name, :class, enabled?(class_id), class_id)
    end
    add_command(YEA::LEARN_SKILL::LEARN_CANCEL_TEXT, :cancel, true)
  end
  
  #--------------------------------------------------------------------------
  # enabled?
  #--------------------------------------------------------------------------
  def enabled?(class_id)
    cost = @skill.learn_cost[0]
    case @skill.learn_cost[1]
    when :jp
      return @actor.jp(class_id) >= cost
    when :exp
      return @actor.exp_class(class_id) >= cost
    end
    return true
  end
  
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    reset_font_settings
    rect = item_rect(index)
    rect.x += 24
    rect.width -= 28
    return draw_cancel_text(index, rect) if @list[index][:symbol] == :cancel
    draw_class_name(index, rect) if @skill.learn_cost[1] != :gold
    draw_party_gold(rect) if @skill.learn_cost[1] == :gold
    draw_learn_skill_cost(@skill, rect, index)
  end
  
  #--------------------------------------------------------------------------
  # draw_cancel_text
  #--------------------------------------------------------------------------
  def draw_cancel_text(index, rect)
    draw_icon(Icon.cancel, rect.x, rect.y)
    text = command_name(index)
    draw_text(rect.x+24, rect.y, rect.width-24, line_height, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_class_name
  #--------------------------------------------------------------------------
  def draw_class_name(index, rect)
    class_id = @list[index][:ext]
    return if $data_classes[class_id].nil?
    enabled = enabled?(class_id)
    if $imported["YEA-ClassSystem"]
      draw_icon($data_classes[class_id].icon_index, rect.x, rect.y, enabled)
    end
    rect.x += 24
    rect.width -= 24
    change_color(normal_color, enabled)
    draw_text(rect, $data_classes[class_id].name)
  end
  
  #--------------------------------------------------------------------------
  # draw_class_name
  #--------------------------------------------------------------------------
  def draw_party_gold(rect)
    enabled = true
    draw_icon(Icon.learn_skill_gold, rect.x, rect.y)
    rect.x += 24
    rect.width -= 24
    change_color(normal_color, enabled)
    draw_text(rect, YEA::LEARN_SKILL::GOLD_TEXT)
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_skill_cost
  #--------------------------------------------------------------------------
  def draw_learn_skill_cost(skill, rect, index)
    case skill.learn_cost[1]
    when :jp
      return unless $imported["YEA-JPManager"]
      draw_jp_cost(skill, rect, index)
    when :exp
      draw_exp_cost(skill, rect, index)
    when :gold
      draw_gold_cost(skill, rect)
    else; return
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_jp_cost
  #--------------------------------------------------------------------------
  def draw_jp_cost(skill, rect, index)
    enabled = enabled?(@list[index][:ext])
    if Icon.jp > 0
      draw_icon(Icon.jp, rect.x + rect.width - 24, rect.y, enabled)
      rect.width -= 24
    end
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::jp, 2)
    rect.width -= text_size(Vocab::jp).width
    cost = @actor.jp(@list[index][:ext])
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_JP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_exp_cost
  #--------------------------------------------------------------------------
  def draw_exp_cost(skill, rect, index)
    enabled = enabled?(@list[index][:ext])
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, YEA::LEARN_SKILL::EXP_TEXT, 2)
    rect.width -= text_size(YEA::LEARN_SKILL::EXP_TEXT).width
    cost = @actor.exp_class(@list[index][:ext])
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_EXP), enabled)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_cost
  #--------------------------------------------------------------------------
  def draw_gold_cost(skill, rect)
    enabled = $game_party.gold >= skill.learn_cost[0]
    contents.font.size = YEA::LEARN_SKILL::COST_SIZE
    change_color(system_color, enabled)
    draw_text(rect, Vocab::currency_unit, 2)
    rect.width -= text_size(Vocab::currency_unit).width
    cost = $game_party.gold
    text = cost.group
    change_color(text_color(YEA::LEARN_SKILL::COLOUR_GOLD), enabled)
    draw_text(rect, text, 2)
  end
  
end # Window_LearnSkillCostFront

#==============================================================================
# ■ Scene_Skill
#==============================================================================

class Scene_Skill < Scene_ItemBase
  
  #--------------------------------------------------------------------------
  # alias method: create_command_window
  #--------------------------------------------------------------------------
  alias scene_skill_create_command_window_lse create_command_window
  def create_command_window
    scene_skill_create_command_window_lse
    @command_window.set_handler(:learn_skill, method(:command_learn_skill))
  end
  
  #--------------------------------------------------------------------------
  # new method: command_learn_skill
  #--------------------------------------------------------------------------
  def command_learn_skill
    SceneManager.call(Scene_LearnSkill)
  end
  
end # Scene_Skill

#==============================================================================
# ■ Scene_LearnSkill
#==============================================================================

class Scene_LearnSkill < Scene_Skill
  
  #--------------------------------------------------------------------------
  # start
  #--------------------------------------------------------------------------
  def start
    super
    create_cost_windows
  end
  
  #--------------------------------------------------------------------------
  # create_command_window
  #--------------------------------------------------------------------------
  def create_command_window
    wy = @help_window.height
    @command_window = Window_LearnSkillCommand.new(0, wy)
    @command_window.viewport = @viewport
    @command_window.help_window = @help_window
    @command_window.actor = @actor
    @command_window.set_handler(:skill,    method(:command_skill))
    @command_window.set_handler(:cancel,   method(:return_scene))
    @command_window.set_handler(:pagedown, method(:next_actor))
    @command_window.set_handler(:pageup,   method(:prev_actor))
  end
  
  #--------------------------------------------------------------------------
  # create_item_window
  #--------------------------------------------------------------------------
  def create_item_window
    wx = 0
    wy = @status_window.y + @status_window.height
    ww = Graphics.width
    wh = Graphics.height - wy
    @item_window = Window_LearnSkillList.new(wx, wy, ww, wh)
    @item_window.actor = @actor
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @command_window.skill_window = @item_window
  end
  
  #--------------------------------------------------------------------------
  # create_cost_windows
  #--------------------------------------------------------------------------
  def create_cost_windows
    @cost_window = Window_LearnSkillCostBack.new(@item_window)
    @cost_front = Window_LearnSkillCostFront.new(@item_window, @cost_window)
    @cost_window.viewport = @viewport
    @cost_front.viewport = @viewport
    @cost_front.set_handler(:ok, method(:on_cost_ok))
    @cost_front.set_handler(:cancel, method(:on_cost_cancel))
  end
  
  #--------------------------------------------------------------------------
  # on_item_ok
  #--------------------------------------------------------------------------
  def on_item_ok
    skill = @item_window.item
    @cost_window.reveal(skill, @item_window.skill_classes(skill))
    @cost_front.reveal(skill, @item_window.skill_classes(skill), @actor)
  end
  
  #--------------------------------------------------------------------------
  # on_cost_ok
  #--------------------------------------------------------------------------
  def on_cost_ok
    Sound.play_use_skill
    skill = @item_window.item
    @actor.learn_skill(skill.id)
    cost = skill.learn_cost[0]
    case skill.learn_cost[1]
    when :jp
      @actor.lose_jp(cost, @cost_front.skill_class)
    when :exp
      @actor.lose_exp_class(cost, @cost_front.skill_class)
    when :gold
      $game_party.lose_gold(cost)
    end
    on_cost_cancel
    refresh_windows
  end
  
  #--------------------------------------------------------------------------
  # on_cost_cancel
  #--------------------------------------------------------------------------
  def on_cost_cancel
    @cost_front.close
    @cost_window.close
    @item_window.activate
  end
  
  #--------------------------------------------------------------------------
  # refresh_windows
  #--------------------------------------------------------------------------
  def refresh_windows
    @item_window.refresh
    @status_window.refresh
  end
  
end # Scene_LearnSkill

#==============================================================================
#
# ▼ End of File
#
#==============================================================================[/pre]
[pre lang="ruby" line="1"]#==============================================================================
#
# ▼ Yanfly Engine Ace - Skill Cost Manager v1.02
# -- Last Updated: 2012.01.23
# -- Level: Normal, Hard, Lunatic
# -- Requires: n/a
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-SkillCostManager"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.23 - Compatibility Update: Doppelganger
# 2011.12.11 - Started Script and Finished.
#            - Added max and min notetags.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script adds more functionality towards skill costs. Skills can now cost
# HP, more MP, more TP, gold, and even have custom costs. The way the skill
# costs are drawn in the display windows are changed to deliver more effective
# and reliable information to the player. And if four skill costs aren't enough
# to satisfy you, you can even make your own custom skill costs.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Actor Notetags - These notetags go in the actors notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the actor to drop the HP cost of skills to x%.
#
# <tp cost rate: x%>
# Allows the actor to drop the TP cost of skills to x%.
#
# <gold cost rate: x%>
# Allows the actor to drop the Gold cost of skills to x%.
#
# -----------------------------------------------------------------------------
# Class Notetags - These notetags go in the class notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the class to drop the HP cost of skills to x%.
#
# <tp cost rate: x%>
# Allows the class to drop the TP cost of skills to x%.
#
# <gold cost rate: x%>
# Allows the class to drop the Gold cost of skills to x%.
#
# -----------------------------------------------------------------------------
# Skill Notetags - These notetags go in the skills notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost: x>
# Sets the skill's HP cost to x. This function did not exist by default in
# RPG Maker VX Ace.
#
# <hp cost: x%>
# Sets the HP cost to a percentage of the actor's MaxHP. If a normal HP cost is
# present on the skill, too, then this value is added to the HP cost.
#
# <hp cost max: x>
# <hp cost min: x>
# Sets the maximum and minimum range of the HP Cost of the skill. If you do not
# use this tag, there will be no maximum and/or minimum range.
#
# <mp cost: x>
# Sets the skill's MP cost to x. Allows MP cost to exceed 9999, which is RPG
# Maker VX Ace's database editor's maximum limit.
#
# <mp cost: x%>
# Sets the MP cost to a percentage of the actor's MaxMP. If a normal MP cost is
# present on the skill, too, then this value is added to the MP cost.
#
# <mp cost max: x>
# <mp cost min: x>
# Sets the maximum and minimum range of the MP Cost of the skill. If you do not
# use this tag, there will be no maximum and/or minimum range.
#
# <tp cost: x>
# Sets the skill's TP cost to x. Allows TP cost to exceed 100, which is RPG
# Maker VX Ace's database editor's maximum limit.
#
# <tp cost: x%>
# Sets the TP cost to a percentage of the actor's MaxTP. If a normal TP cost is
# present on the skill, too, then this value is added to the TP cost.
#
# <tp cost max: x>
# <tp cost min: x>
# Sets the maximum and minimum range of the TP Cost of the skill. If you do not
# use this tag, there will be no maximum and/or minimum range.
#
# <gold cost: x>
# Sets the skill's gold cost to x. Enemies with skills that cost gold do not
# use gold. If the player does not have enough gold, the skill can't be used.
#
# <gold cost: x%>
# Sets the skill's gold cost equal to a percentage of the party's total gold.
# If both a regular gold cost and a percentile gold cost is used, the total of
# both values will be the skill's gold cost.
#
# <gold cost max: x>
# <gold cost min: x>
# Sets the maximum and minimum range of the Gold Cost of the skill. If you do
# not use this tag, there will be no maximum and/or minimum range.
#
# --- Making Your Own Custom Costs ---
#
# <custom cost: string>
# If you decide to have a custom cost for your game, insert this notetag to
# change what displays in the skill menu visually.
#
# <custom cost colour: x>
# This is the "Window" skin text colour used for the custom cost. By default,
# it is text colour 0, which is the white colour.
#
# <custom cost size: x>
# This is the text font size used for the custom cost in the display windows.
# By default, it is font size 20.
#
# <custom cost icon: x>
# If you wish to use an icon for your custom cost, replace x with the icon ID
# you wish to show in display windows. By default, it is 0 (and not shown).
#
# <custom cost requirement>
#  string
#  string
# </custom cost requirement>
# Sets the custom cost requirement of the skill with an eval function using the
# strings in between. The strings are a part of one line even if in the notebox
# they are on separate lines.
#
# <custom cost perform>
#  string
#  string
# </custom cost perform>
# Sets how the custom cost payment is done with an eval function using the
# strings in between. The strings are a part of one line even if in the notebox
# they are on separate lines.
#
# -----------------------------------------------------------------------------
# Weapon Notetags - These notetags go in the weapons notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the weapon to drop the HP cost of skills to x% when worn.
#
# <tp cost rate: x%>
# Allows the weapon to drop the TP cost of skills to x% when worn.
#
# <gold cost rate: x%>
# Allows the weapon to drop the Gold cost of skills to x% when worn.
#
# -----------------------------------------------------------------------------
# Armour Notetags - These notetags go in the armours notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the armour to drop the HP cost of skills to x% when worn.
#
# <tp cost rate: x%>
# Allows the armour to drop the TP cost of skills to x% when worn.
#
# <gold cost rate: x%>
# Allows the armour to drop the TP cost of skills to x% when worn.
#
# -----------------------------------------------------------------------------
# Enemy Notetags - These notetags go in the enemies notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the enemy to drop the HP cost of skills to x%.
#
# <tp cost rate: x%>
# Allows the enemy to drop the TP cost of skills to x%.
#
# -----------------------------------------------------------------------------
# State Notetags - These notetags go in the states notebox in the database.
# -----------------------------------------------------------------------------
# <hp cost rate: x%>
# Allows the state to drop the HP cost of skills to x% when afflicted.
#
# <tp cost rate: x%>
# Allows the state to drop the TP cost of skills to x% when afflicted.
#
# <gold cost rate: x%>
# Allows the state to drop the Gold cost of skills to x% when afflicted.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
#==============================================================================

module YEA
  module SKILL_COST
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - HP Cost Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # New to this script are HP costs. HP costs require the battler to have
    # sufficient HP before being able to use the skill. The text colour that's
    # used, the suffix, or whether or not to use an icon. If you do not wish
    # to use an icon, set the icon to 0.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    HP_COST_COLOUR = 21         # Colour used from "Window" skin.
    HP_COST_SIZE   = 20         # Font size used for HP costs.
    HP_COST_SUFFIX = "%sHP"     # Suffix used for HP costs.
    HP_COST_ICON   = 0          # Icon used for HP costs. Set 0 to disable.
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - MP Cost Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # Here, you can change the settings for MP costs: the text colour that's
    # used, the suffix, or whether or not to use an icon. If you do not wish
    # to use an icon, set the icon to 0.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    MP_COST_COLOUR = 23         # Colour used from "Window" skin. Default: 23
    MP_COST_SIZE   = 20         # Font size used for MP costs. Default: 24
    MP_COST_SUFFIX = "%sMP"     # Suffix used for MP costs. No suffix default.
    MP_COST_ICON   = 0          # Icon used for MP costs. Set 0 to disable.
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - TP Cost Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # Here, you can change the settings for TP costs: the text colour that's
    # used, the suffix, or whether or not to use an icon. If you do not wish
    # to use an icon, set the icon to 0.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    TP_COST_COLOUR = 2          # Colour used from "Window" skin. Default: 29
    TP_COST_SIZE   = 20         # Font size used for TP costs. Default: 24
    TP_COST_SUFFIX = "%sTP"     # Suffix used for TP costs. No suffix default.
    TP_COST_ICON   = 0          # Icon used for TP costs. Set 0 to disable.
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Gold Cost Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # New to this script are Gold costs. Gold costs require the party to have
    # enough gold before being able to use the skill. The text colour that's
    # used, the suffix, or whether or not to use an icon. If you do not wish
    # to use an icon, set the icon to 0.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    GOLD_COST_COLOUR = 6          # Colour used from "Window" skin.
    GOLD_COST_SIZE   = 20         # Font size used for Gold costs.
    GOLD_COST_SUFFIX = "%sGold"   # Suffix used for Gold costs.
    GOLD_COST_ICON   = 0          # Icon used for Gold costs. Set 0 to disable.
   
  end # SKILL_COST
end # YEA

#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

module YEA
  module REGEXP
  module BASEITEM
   
    HP_COST_RATE = /<(?:HP_COST_RATE|hp cost rate):[ ](\d+)([%%])>/i
    TP_COST_RATE = /<(?:TP_COST_RATE|tp cost rate):[ ](\d+)([%%])>/i
    GOLD_COST_RATE = /<(?:GOLD_COST_RATE|gold cost rate):[ ](\d+)([%%])>/i
   
  end # BASEITEM
  module SKILL
   
    HP_COST_SET = /<(?:HP_COST|hp cost):[ ](\d+)>/i
    HP_COST_PER = /<(?:HP_COST|hp cost):[ ](\d+)([%%])>/i
    MP_COST_SET = /<(?:MP_COST|mp cost):[ ](\d+)>/i
    MP_COST_PER = /<(?:MP_COST|mp cost):[ ](\d+)([%%])>/i
    TP_COST_SET = /<(?:TP_COST|tp cost):[ ](\d+)>/i
    TP_COST_PER = /<(?:TP_COST|tp cost):[ ](\d+)([%%])>/i
    GOLD_COST_SET = /<(?:GOLD_COST|gold cost):[ ](\d+)>/i
    GOLD_COST_PER = /<(?:GOLD_COST|gold cost):[ ](\d+)([%%])>/i
   
    CUSTOM_COST_TEXT = /<(?:CUSTOM_COST|custom cost):[ ](.*)>/i
    CUSTOM_COST_COLOUR =
      /<(?:CUSTOM_COST_COLOUR|custom cost colour|custom cost color):[ ](\d+)>/i
    CUSTOM_COST_SIZE = /<(?:CUSTOM_COST_SIZE|custom cost size):[ ](\d+)>/i
    CUSTOM_COST_ICON = /<(?:CUSTOM_COST_ICON|custom cost icon):[ ](\d+)>/i
    CUSTOM_COST_REQUIREMENT_ON =
      /<(?:CUSTOM_COST_REQUIREMENT|custom cost requirement)>/i
    CUSTOM_COST_REQUIREMENT_OFF =
      /<\/(?:CUSTOM_COST_REQUIREMENT|custom cost requirement)>/i
    CUSTOM_COST_PERFORM_ON =
      /<(?:CUSTOM_COST_PERFORM|custom cost perform)>/i
    CUSTOM_COST_PERFORM_OFF =
      /<\/(?:CUSTOM_COST_PERFORM|custom cost perform)>/i
   
    HP_COST_MIN = /<(?:HP_COST_MIN|hp cost min):[ ](\d+)>/i
    HP_COST_MAX = /<(?:HP_COST_MIN|hp cost max):[ ](\d+)>/i
    MP_COST_MIN = /<(?:MP_COST_MIN|mp cost min):[ ](\d+)>/i
    MP_COST_MAX = /<(?:MP_COST_MIN|mp cost max):[ ](\d+)>/i
    TP_COST_MIN = /<(?:TP_COST_MIN|tp cost min):[ ](\d+)>/i
    TP_COST_MAX = /<(?:TP_COST_MIN|tp cost max):[ ](\d+)>/i
    GOLD_COST_MIN = /<(?:GOLD_COST_MIN|gold cost min):[ ](\d+)>/i
    GOLD_COST_MAX = /<(?:GOLD_COST_MIN|gold cost max):[ ](\d+)>/i
   
  end # SKILL
  end # REGEXP
end # YEA

#==============================================================================
# ■ Icon
#==============================================================================

module Icon
  
  #--------------------------------------------------------------------------
  # self.mp_cost
  #--------------------------------------------------------------------------
  def self.mp_cost; return YEA::SKILL_COST::MP_COST_ICON; end
  
  #--------------------------------------------------------------------------
  # self.tp_cost
  #--------------------------------------------------------------------------
  def self.tp_cost; return YEA::SKILL_COST::TP_COST_ICON; end
  
  #--------------------------------------------------------------------------
  # self.hp_cost
  #--------------------------------------------------------------------------
  def self.hp_cost; return YEA::SKILL_COST::HP_COST_ICON; end
  
  #--------------------------------------------------------------------------
  # self.gold_cost
  #--------------------------------------------------------------------------
  def self.gold_cost; return YEA::SKILL_COST::GOLD_COST_ICON; end
   
end # Icon

#==============================================================================
# ■ Numeric
#==============================================================================

class Numeric
  
  #--------------------------------------------------------------------------
  # new method: group_digits
  #--------------------------------------------------------------------------
  unless $imported["YEA-CoreEngine"]
  def group; return self.to_s; end
  end # $imported["YEA-CoreEngine"]
   
end # Numeric

#==============================================================================
# ■ DataManager
#==============================================================================

module DataManager
  
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  class <<self; alias load_database_scm load_database; end
  def self.load_database
    load_database_scm
    load_notetags_scm
  end
  
  #--------------------------------------------------------------------------
  # new method: load_notetags_scm
  #--------------------------------------------------------------------------
  def self.load_notetags_scm
    groups = [$data_actors, $data_classes, $data_skills, $data_weapons,
      $data_armors, $data_enemies, $data_states]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_scm
      end
    end
  end
  
end # DataManager

#==============================================================================
# ■ RPG::BaseItem
#==============================================================================

class RPG::BaseItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :tp_cost_rate
  attr_accessor :hp_cost_rate
  attr_accessor :gold_cost_rate
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_scm
  #--------------------------------------------------------------------------
  def load_notetags_scm
    @tp_cost_rate = 1.0
    @hp_cost_rate = 1.0
    @gold_cost_rate = 1.0
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEA::REGEXP::BASEITEM::TP_COST_RATE
        @tp_cost_rate = $1.to_i * 0.01
      when YEA::REGEXP::BASEITEM::HP_COST_RATE
        @hp_cost_rate = $1.to_i * 0.01
      when YEA::REGEXP::BASEITEM::GOLD_COST_RATE
        @gold_cost_rate = $1.to_i * 0.01
      #---
      end
    } # self.note.split
    #---
  end
  
end # RPG::BaseItem

#==============================================================================
# ■ RPG::Skill
#==============================================================================

class RPG::Skill < RPG::UsableItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :hp_cost
  attr_accessor :hp_cost_percent
  attr_accessor :mp_cost_percent
  attr_accessor :tp_cost_percent
  attr_accessor :gold_cost
  attr_accessor :gold_cost_percent
  
  attr_accessor :hp_cost_min
  attr_accessor :hp_cost_max
  attr_accessor :mp_cost_min
  attr_accessor :mp_cost_max
  attr_accessor :tp_cost_min
  attr_accessor :tp_cost_max
  attr_accessor :gold_cost_min
  attr_accessor :gold_cost_max
  
  attr_accessor :use_custom_cost
  attr_accessor :custom_cost_text
  attr_accessor :custom_cost_colour
  attr_accessor :custom_cost_size
  attr_accessor :custom_cost_icon
  attr_accessor :custom_cost_requirement
  attr_accessor :custom_cost_perform
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_scm
  #--------------------------------------------------------------------------
  def load_notetags_scm
    @hp_cost = 0
    @gold_cost = 0
    @hp_cost_percent = 0.0
    @mp_cost_percent = 0.0
    @tp_cost_percent = 0.0
    @gold_cost_percent = 0.0
   
    @custom_cost_text = "0"
    @custom_cost_colour = 0
    @custom_cost_size = 20
    @custom_cost_icon = 0
    @custom_cost_requirement = ""
    @custom_cost_perform = ""
   
    @use_custom_cost = false
    @custom_cost_req_on = false
    @custom_cost_per_on = false
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEA::REGEXP::SKILL::MP_COST_SET
        @mp_cost = $1.to_i
      when YEA::REGEXP::SKILL::MP_COST_PER
        @mp_cost_percent = $1.to_i * 0.01
      when YEA::REGEXP::SKILL::TP_COST_SET
        @tp_cost = $1.to_i
      when YEA::REGEXP::SKILL::TP_COST_PER
        @tp_cost_percent = $1.to_i * 0.01
      when YEA::REGEXP::SKILL::HP_COST_SET
        @hp_cost = $1.to_i
      when YEA::REGEXP::SKILL::HP_COST_PER
        @hp_cost_percent = $1.to_i * 0.01
      when YEA::REGEXP::SKILL::GOLD_COST_SET
        @gold_cost = $1.to_i
      when YEA::REGEXP::SKILL::GOLD_COST_PER
        @gold_cost_percent = $1.to_i * 0.01
      #---
      when YEA::REGEXP::SKILL::HP_COST_MIN
        @hp_cost_min = $1.to_i
      when YEA::REGEXP::SKILL::HP_COST_MAX
        @hp_cost_max = $1.to_i
      when YEA::REGEXP::SKILL::MP_COST_MIN
        @mp_cost_min = $1.to_i
      when YEA::REGEXP::SKILL::MP_COST_MAX
        @mp_cost_max = $1.to_i
      when YEA::REGEXP::SKILL::TP_COST_MIN
        @tp_cost_min = $1.to_i
      when YEA::REGEXP::SKILL::TP_COST_MAX
        @tp_cost_max = $1.to_i
      when YEA::REGEXP::SKILL::GOLD_COST_MIN
        @gold_cost_min = $1.to_i
      when YEA::REGEXP::SKILL::GOLD_COST_MAX
        @gold_cost_max = $1.to_i
      #---
      when YEA::REGEXP::SKILL::CUSTOM_COST_TEXT
        @custom_cost_text = $1.to_s
      when YEA::REGEXP::SKILL::CUSTOM_COST_COLOUR
        @custom_cost_colour = $1.to_i
      when YEA::REGEXP::SKILL::CUSTOM_COST_SIZE
        @custom_cost_size = $1.to_i
      when YEA::REGEXP::SKILL::CUSTOM_COST_ICON
        @custom_cost_icon = $1.to_i
      when YEA::REGEXP::SKILL::CUSTOM_COST_REQUIREMENT_ON
        @custom_cost_req_on = true
        @use_custom_cost = true
      when YEA::REGEXP::SKILL::CUSTOM_COST_REQUIREMENT_OFF
        @custom_cost_req_on = false
        @use_custom_cost = true
      when YEA::REGEXP::SKILL::CUSTOM_COST_PERFORM_ON
        @custom_cost_per_on = true
        @use_custom_cost = true
      when YEA::REGEXP::SKILL::CUSTOM_COST_PERFORM_OFF
        @custom_cost_per_on = false
        @use_custom_cost = true
      else
        @custom_cost_requirement += line.to_s if @custom_cost_req_on
        @custom_cost_perform += line.to_s if @custom_cost_per_on
      #---
      end
    } # self.note.split
    #---
  end
  
end # RPG::Skill

#==============================================================================
# ■ Game_BattlerBase
#==============================================================================

class Game_BattlerBase
  
  #--------------------------------------------------------------------------
  # alias method: skill_cost_payable?
  #--------------------------------------------------------------------------
  alias game_battlerbase_skill_cost_payable_scm skill_cost_payable?
  def skill_cost_payable?(skill)
    return false if hp <= skill_hp_cost(skill)
    return false unless gold_cost_met?(skill)
    return false unless custom_cost_met?(skill)
    return game_battlerbase_skill_cost_payable_scm(skill)
  end
  
  #--------------------------------------------------------------------------
  # new method: gold_cost_met?
  #--------------------------------------------------------------------------
  def gold_cost_met?(skill)
    return true unless actor?
    return $game_party.gold >= skill_gold_cost(skill)
  end
  
  #--------------------------------------------------------------------------
  # new method: custom_cost_met?
  #--------------------------------------------------------------------------
  def custom_cost_met?(skill)
    return true unless skill.use_custom_cost
    return eval(skill.custom_cost_requirement)
  end
  
  #--------------------------------------------------------------------------
  # alias method: pay_skill_cost
  #--------------------------------------------------------------------------
  alias game_battlerbase_pay_skill_cost_scm pay_skill_cost
  def pay_skill_cost(skill)
    game_battlerbase_pay_skill_cost_scm(skill)
    self.hp -= skill_hp_cost(skill)
    $game_party.lose_gold(skill_gold_cost(skill)) if actor?
    pay_custom_cost(skill)
  end
  
  #--------------------------------------------------------------------------
  # new method: pay_custom_cost
  #--------------------------------------------------------------------------
  def pay_custom_cost(skill)
    return unless skill.use_custom_cost
    eval(skill.custom_cost_perform)
  end
  
  #--------------------------------------------------------------------------
  # alias method: skill_mp_cost
  #--------------------------------------------------------------------------
  alias game_battlerbase_skill_mp_cost_scm skill_mp_cost
  def skill_mp_cost(skill)
    n = game_battlerbase_skill_mp_cost_scm(skill)
    n += skill.mp_cost_percent * mmp * mcr
    n = [n.to_i, skill.mp_cost_max].min unless skill.mp_cost_max.nil?
    n = [n.to_i, skill.mp_cost_min].max unless skill.mp_cost_min.nil?
    return n.to_i
  end
  
  #--------------------------------------------------------------------------
  # alias method: skill_tp_cost
  #--------------------------------------------------------------------------
  alias game_battlerbase_skill_tp_cost_scm skill_tp_cost
  def skill_tp_cost(skill)
    n = game_battlerbase_skill_tp_cost_scm(skill) * tcr
    n += skill.tp_cost_percent * max_tp * tcr
    n = [n.to_i, skill.tp_cost_max].min unless skill.tp_cost_max.nil?
    n = [n.to_i, skill.tp_cost_min].max unless skill.tp_cost_min.nil?
    return n.to_i
  end
  
  #--------------------------------------------------------------------------
  # new method: tcr
  #--------------------------------------------------------------------------
  def tcr
    n = 1.0
    if actor?
      n *= self.actor.tp_cost_rate
      n *= self.class.tp_cost_rate
      for equip in equips
        next if equip.nil?
        n *= equip.tp_cost_rate
      end
    else
      n *= self.enemy.tp_cost_rate
      if $imported["YEA-Doppelganger"] && !self.class.nil?
        n *= self.class.tp_cost_rate
      end
    end
    for state in states
      next if state.nil?
      n *= state.tp_cost_rate
    end
    return n
  end
  
  #--------------------------------------------------------------------------
  # new method: skill_hp_cost
  #--------------------------------------------------------------------------
  def skill_hp_cost(skill)
    n = skill.hp_cost * hcr
    n += skill.hp_cost_percent * mhp * hcr
    n = [n.to_i, skill.hp_cost_max].min unless skill.hp_cost_max.nil?
    n = [n.to_i, skill.hp_cost_min].max unless skill.hp_cost_min.nil?
    return n.to_i
  end
  
  #--------------------------------------------------------------------------
  # new method: hcr
  #--------------------------------------------------------------------------
  def hcr
    n = 1.0
    if actor?
      n *= self.actor.hp_cost_rate
      n *= self.class.hp_cost_rate
      for equip in equips
        next if equip.nil?
        n *= equip.hp_cost_rate
      end
    else
      n *= self.enemy.hp_cost_rate
      if $imported["YEA-Doppelganger"] && !self.class.nil?
        n *= self.class.hp_cost_rate
      end
    end
    for state in states
      next if state.nil?
      n *= state.hp_cost_rate
    end
    return n
  end
  
  #--------------------------------------------------------------------------
  # new method: skill_gold_cost
  #--------------------------------------------------------------------------
  def skill_gold_cost(skill)
    n = skill.gold_cost * gcr
    n += skill.gold_cost_percent * $game_party.gold * gcr
    n = [n.to_i, skill.gold_cost_max].min unless skill.gold_cost_max.nil?
    n = [n.to_i, skill.gold_cost_min].max unless skill.gold_cost_min.nil?
    return n.to_i
  end
  
  #--------------------------------------------------------------------------
  # new method: gcr
  #--------------------------------------------------------------------------
  def gcr
    n = 1.0
    n *= self.actor.gold_cost_rate
    n *= self.class.gold_cost_rate
    for equip in equips
      next if equip.nil?
      n *= equip.gold_cost_rate
    end
    for state in states
      next if state.nil?
      n *= state.gold_cost_rate
    end
    return n
  end
  
end # Game_BattlerBase
  
#==============================================================================
# ■ Window_Base
#==============================================================================

class Window_Base < Window
  
  #--------------------------------------------------------------------------
  # overwrite methods: cost_colours
  #--------------------------------------------------------------------------
  def mp_cost_color; text_color(YEA::SKILL_COST::MP_COST_COLOUR); end;
  def tp_cost_color; text_color(YEA::SKILL_COST::TP_COST_COLOUR); end;
  def hp_cost_color; text_color(YEA::SKILL_COST::HP_COST_COLOUR); end;
  def gold_cost_color; text_color(YEA::SKILL_COST::GOLD_COST_COLOUR); end;
  
end # Window_Base

#==============================================================================
# ■ Window_SkillList
#==============================================================================

class Window_SkillList < Window_Selectable
  
  #--------------------------------------------------------------------------
  # overwrite method: draw_skill_cost
  #--------------------------------------------------------------------------
  def draw_skill_cost(rect, skill)
    draw_tp_skill_cost(rect, skill) unless $imported["YEA-BattleEngine"]
    draw_mp_skill_cost(rect, skill)
    draw_tp_skill_cost(rect, skill) if $imported["YEA-BattleEngine"]
    draw_hp_skill_cost(rect, skill)
    draw_gold_skill_cost(rect, skill)
    draw_custom_skill_cost(rect, skill)
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_mp_skill_cost
  #--------------------------------------------------------------------------
  def draw_mp_skill_cost(rect, skill)
    return unless @actor.skill_mp_cost(skill) > 0
    change_color(mp_cost_color, enable?(skill))
    #---
    icon = Icon.mp_cost
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    #---
    contents.font.size = YEA::SKILL_COST::MP_COST_SIZE
    cost = @actor.skill_mp_cost(skill)
    text = sprintf(YEA::SKILL_COST::MP_COST_SUFFIX, cost.group)
    draw_text(rect, text, 2)
    cx = text_size(text).width + 4
    rect.width -= cx
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_tp_skill_cost
  #--------------------------------------------------------------------------
  def draw_tp_skill_cost(rect, skill)
    return unless @actor.skill_tp_cost(skill) > 0
    change_color(tp_cost_color, enable?(skill))
    #---
    icon = Icon.tp_cost
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    #---
    contents.font.size = YEA::SKILL_COST::TP_COST_SIZE
    cost = @actor.skill_tp_cost(skill)
    text = sprintf(YEA::SKILL_COST::TP_COST_SUFFIX, cost.group)
    draw_text(rect, text, 2)
    cx = text_size(text).width + 4
    rect.width -= cx
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_hp_skill_cost
  #--------------------------------------------------------------------------
  def draw_hp_skill_cost(rect, skill)
    return unless @actor.skill_hp_cost(skill) > 0
    change_color(hp_cost_color, enable?(skill))
    #---
    icon = Icon.hp_cost
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    #---
    contents.font.size = YEA::SKILL_COST::HP_COST_SIZE
    cost = @actor.skill_hp_cost(skill)
    text = sprintf(YEA::SKILL_COST::HP_COST_SUFFIX, cost.group)
    draw_text(rect, text, 2)
    cx = text_size(text).width + 4
    rect.width -= cx
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_gold_skill_cost
  #--------------------------------------------------------------------------
  def draw_gold_skill_cost(rect, skill)
    return unless @actor.skill_gold_cost(skill) > 0
    change_color(gold_cost_color, enable?(skill))
    #---
    icon = Icon.gold_cost
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    #---
    contents.font.size = YEA::SKILL_COST::GOLD_COST_SIZE
    cost = @actor.skill_gold_cost(skill)
    text = sprintf(YEA::SKILL_COST::GOLD_COST_SUFFIX, cost.group)
    draw_text(rect, text, 2)
    cx = text_size(text).width + 4
    rect.width -= cx
    reset_font_settings
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_custom_skill_cost
  #--------------------------------------------------------------------------
  def draw_custom_skill_cost(rect, skill)
    return unless skill.use_custom_cost
    change_color(text_color(skill.custom_cost_colour), enable?(skill))
    icon = skill.custom_cost_icon
    if icon > 0
      draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
      rect.width -= 24
    end
    contents.font.size = skill.custom_cost_size
    text = skill.custom_cost_text
    draw_text(rect, text, 2)
    cx = text_size(text).width + 4
    rect.width -= cx
    reset_font_settings
  end
  
end # Window_SkillList

#==============================================================================
#
# ▼ End of File
#
#==============================================================================[/pre]
另外,升级加技能点的话,用这个:
在Game_Actor的420行左右是判断升级的,这段代码可以改为:
[pre lang="ruby" line="1"]  def level_up
    @level += 1
    if @actor_id == 1
          $game_variables[0032]=$game_variables[0032]+2
          end
    self.class.learnings.each do |learning|
      learn_skill(learning.skill_id) if learning.level == @level
    end
  end[/pre]
这段效果就是主角升一级,32号变量增加两点,而其他人升级是不增加的,可用作技能点

评分

参与人数 1梦石 +1 收起 理由
taroxd + 1 认可答案

查看全部评分

点击即可领养:
回复

使用道具 举报

梦石
0
星屑
100
在线时间
84 小时
注册时间
2010-10-16
回帖
110
 楼主| 发表于 2014-6-10 18:45:24 | 显示全部楼层
令狐林 发表于 2014-6-9 09:46
从无到有可以利用这个技能学习系统,一共三个脚本,给你
#============================================ ...

谢谢了!
[img]http://rpg.blue/static/image/smiley/default/victory.
回归中........
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部