ページ 11

<解決済み>既存のスキル習得システムの機能追加リクエストです。

Posted: 2020年3月05日(木) 16:59
by ツクヨ
RGSS3 スキル習得システムの機能追加リクエストです。
ひきも記は閉鎖しました。様のスキル習得システムを使いたいのですが
https://hikimoki.sakura.ne.jp/rgss3/tmsklearn.rb
スキル習得の代価が経験値orお金の2つで私は他にスキルUP専用アイテムを使いたいと思っています。
アイテムの<n番目のアイテム><m個必要>のような感じです
どうかよろしくお願いします。

Re: 既存のスキル習得システムの機能追加リクエストです。

Posted: 2020年3月05日(木) 19:19
by TOMO
とりあえず作ってみました

コード: 全て選択

#==============================================================================
# ★ RGSS3_スキル習得システム Ver1.0
#==============================================================================
=begin

作者:tomoaky
webサイト:ひきも記 (http://hikimoki.sakura.ne.jp/)

経験値やお金を消費してスキルを習得するシステムを追加します。

職業の習得スキルのメモ欄に以下のタグを書き込んで設定します。
  <習得 E 50>
  経験値を50消費して習得することができる
 
  <習得 G 100>
  お金を100消費して習得することができる

  タグを書き込んだスキルは通常のレベルアップによる習得ができなくなります。
  習得コストは経験値とお金のどちらか一方しか設定できません。
 
 
2011.12.19 Ver1.0
  公開

=end

#==============================================================================
# □ 設定項目
#==============================================================================
module TMSKLEARN
  COMMAND_SKLEARN = "スキル習得"         # メニューに表示するコマンド名
end

#==============================================================================
# ■ RPG::Class
#==============================================================================
class RPG::Class
  #--------------------------------------------------------------------------
  # ○ 習得するスキルを返す(スキル習得システム用のものを除外)
  #--------------------------------------------------------------------------
  def learnings
    result = []
    @learnings.each do |learning|
      result.push(learning) unless /<習得\s+([EGIWA])\s+(.+)>/ =~ learning.note
    end
    result
  end
  #--------------------------------------------------------------------------
  # ○ 習得するスキルを返す(スキル習得システム用のもののみ)
  #--------------------------------------------------------------------------
  def learnings_ex
    @learnings - self.learnings
  end
end

#==============================================================================
# ■ Window_MenuCommand
#==============================================================================
class Window_MenuCommand
  #--------------------------------------------------------------------------
  # ● 主要コマンドをリストに追加
  #--------------------------------------------------------------------------
  alias tmsklearn_window_menucommand_add_main_commands add_main_commands
  def add_main_commands
    tmsklearn_window_menucommand_add_main_commands
    add_command(TMSKLEARN::COMMAND_SKLEARN, :skill_learn, main_commands_enabled)
  end
end

#==============================================================================
# □ Window_SkillLearn
#==============================================================================
class Window_SkillLearn < Window_SkillList
  #--------------------------------------------------------------------------
  # ● 桁数の取得
  #--------------------------------------------------------------------------
  def col_max
    return 1
  end
  #--------------------------------------------------------------------------
  # ● 選択項目の有効状態を取得
  #--------------------------------------------------------------------------
  def current_item_enabled?
    enable?(@data[index])
  end
  #--------------------------------------------------------------------------
  # ● スキルを許可状態で表示するかどうか
  #--------------------------------------------------------------------------
  def enable?(item)
    @actor && !@actor.skill_learn?(item) && cost_ok?(item)
  end
  #--------------------------------------------------------------------------
  # ○ スキル習得のコスト条件を満たしているかどうか
  #--------------------------------------------------------------------------
  def cost_ok?(item)
    if item
      @actor.class.learnings_ex.each do |learning|
        if learning.skill_id == item.id
          /<習得\s+([EGIWA])\s+(.+)>/ =~ learning.note
          case $1
          when "E"; return true if $2.to_i <= @actor.exp
          when "G"; return true if $2.to_i <= $game_party.gold
          when "I"
            ary = $2.split(/\s+/)
            item = $data_items[ary[0].to_i]
            return true if ary[1].to_i <= $game_party.item_number(item)
          when "W"
            ary = $2.split(/\s+/)
            item = $data_weapons[ary[0].to_i]
            return true if ary[1].to_i <= $game_party.item_number(item)
          when "A"
            ary = $2.split(/\s+/)
            item = $data_armors[ary[0].to_i]
            return true if ary[1].to_i <= $game_party.item_number(item)
          end
        end
      end
    end
    false
  end
  #--------------------------------------------------------------------------
  # ● スキルリストの作成
  #--------------------------------------------------------------------------
  def make_item_list
    @data = []
    if @actor
      @actor.class.learnings_ex.each do |learning|
        skill = $data_skills[learning.skill_id]
        @data.push(skill) if include?(skill)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 項目の描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if skill
      rect = item_rect(index)
      rect.width -= 4
      if @actor.skill_learn?(skill)
        self.contents.font.out_color.set(128, 0, 0)
        draw_item_name(skill, rect.x, rect.y, true)
      else
        self.contents.font.out_color.set(0, 0, 0)
        draw_item_name(skill, rect.x, rect.y, enable?(skill))
      end
      draw_skill_cost(rect, skill)
    end
  end
  #--------------------------------------------------------------------------
  # ● スキルの使用コストを描画
  #--------------------------------------------------------------------------
  def draw_skill_cost(rect, skill)
    @actor.class.learnings_ex.each do |learning|
      if learning.skill_id == skill.id
        /<習得\s+([EGIWA])\s+(.+)>/ =~ learning.note
        case $1
        when "E"
          text = sprintf("%s / %d %s", $2, @actor.exp, "EXP")
        when "G"
          text = sprintf("%s / %d %s", $2, $game_party.gold,
            Vocab::currency_unit)
        when "I"
          ary = $2.split(/\s+/)
          item = $data_items[ary[0].to_i]
          text = sprintf("%s / %d", ary[1], $game_party.item_number(item))
          ix = rect.x + rect.width - text_size(text).width - 36
          draw_icon(item.icon_index, ix, rect.y,
            enable?(skill) || @actor.skill_learn?(skill))
        when "W"
          ary = $2.split(/\s+/)
          item = $data_weapons[ary[0].to_i]
          text = sprintf("%s / %d", ary[1], $game_party.item_number(item))
          ix = rect.x + rect.width - text_size(text).width - 36
          draw_icon(item.icon_index, ix, rect.y,
            enable?(skill) || @actor.skill_learn?(skill))
        when "A"
          ary = $2.split(/\s+/)
          item = $data_armors[ary[0].to_i]
          text = sprintf("%s / %d", ary[1], $game_party.item_number(item))
          ix = rect.x + rect.width - text_size(text).width - 36
          draw_icon(item.icon_index, ix, rect.y,
            enable?(skill) || @actor.skill_learn?(skill))
        end
        change_color(normal_color, enable?(skill) || @actor.skill_learn?(skill))
        draw_text(rect, text, 2)
        break
      end
    end
  end
end

#==============================================================================
# ■ Scene_Menu
#==============================================================================
class Scene_Menu
  #--------------------------------------------------------------------------
  # ● コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias tmsklearn_scene_menu_create_command_window create_command_window
  def create_command_window
    tmsklearn_scene_menu_create_command_window
    @command_window.set_handler(:skill_learn, method(:command_personal))
  end
  #--------------------------------------------------------------------------
  # ● 個人コマンド[決定]
  #--------------------------------------------------------------------------
  alias tmsklearn_scene_menu_on_personal_ok on_personal_ok
  def on_personal_ok
    if @command_window.current_symbol == :skill_learn
      SceneManager.call(Scene_SkillLearn)
    else
      tmsklearn_scene_menu_on_personal_ok
    end
  end
end

#==============================================================================
# □ Scene_SkillLearn
#==============================================================================
class Scene_SkillLearn < Scene_Skill
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_window
    wx = 0
    wy = @status_window.y + @status_window.height
    ww = Graphics.width
    wh = Graphics.height - wy
    @item_window = Window_SkillLearn.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
  #--------------------------------------------------------------------------
  # ● アイテム[決定]
  #--------------------------------------------------------------------------
  def on_item_ok
    Sound.play_use_skill
    @actor.learn_skill(item.id)
    @actor.class.learnings_ex.each do |learning|
      if learning.skill_id == item.id
        /<習得\s+([EGIWA])\s+(.+)>/ =~ learning.note
        case $1
        when "E"; @actor.change_exp(@actor.exp - $2.to_i, false)
        when "G"; $game_party.lose_gold($2.to_i)
        when "I"
          ary = $2.split(/\s+/)
          item = $data_items[ary[0].to_i]
          $game_party.lose_item(item, ary[1].to_i)
        when "W"
          ary = $2.split(/\s+/)
          item = $data_weapons[ary[0].to_i]
          $game_party.lose_item(item, ary[1].to_i)
        when "A"
          ary = $2.split(/\s+/)
          item = $data_armors[ary[0].to_i]
          $game_party.lose_item(item, ary[1].to_i)
        end
      end
    end
    @status_window.refresh
    @item_window.refresh
    @item_window.activate
  end
end

アイテムは<習得 I n m>、武器は<習得 W n m>、
防具は<習得 A n m>といった感じになります
(n番目のアイテム、m個必要)

Re: 既存のスキル習得システムの機能追加リクエストです。

Posted: 2020年3月05日(木) 19:51
by ツクヨ
ありがとう御座います!その上要望に無かった武器防具も追加してくれて創作の幅が広がりました!