注册会员 登录
Project1 返回首页

喵呜喵5的树洞 https://rpg.blue/?291206 [收藏] [复制] [分享] [RSS]

日志

【脚本】分解道具

热度 8已有 2435 次阅读2016-1-25 09:04 |个人分类:脚本| 道具

这个脚本需要搭配我的基础脚本共同使用:http://rm.66rpg.com/home.php?mod=space&uid=291206&do=blog&id=13513

=begin
===============================================================================
  分解道具 By喵呜喵5
===============================================================================

【说明】

  将主角背包里面的武器,防具,道具分解成其他若干道具。
  分解之后,原物品消失,分解后的物品会放入主角的背包中。

  在对应物品的备注栏输入:

    <分解所得 [1,3]>

  则分解该物品可以随机获得 1~3 个的 1 号道具

  在备注栏输入:

    <分解所得 [1,3]>
    <分解所得 [2,4]>

  则分解该物品可以随机获得 1~3 个的 1 号道具 和 1~4 个的 2 号道具

  在事件指令的脚本中输入

    M5DI20160122.call

  来打开分解界面

=end
$m5script ||= {}; raise("需要喵呜喵5基础脚本的支持") unless $m5script[:M5Base]
$m5script[:M5DI20160122] = 20160122; M5script.version(20151221)
module M5DI20160122
#==============================================================================
# 设定部分
#==============================================================================

  GOLD = 500

  # 单次分解所需的金钱

  RATE = 0.1

  # 分解获得更多数量道具的几率 + 10%

  SE = 'Bell2'

  # 分解成功时播放的音效,不需要的话填写 nil

  VOCAB = {

    ITEM:   "分解道具",
    WEAPON: "分解武器",
    ARMOR:  "分解防具",

    HINT_HEAD:  "分解成功后将获得",
    HINT_FOOT:  "确定分解吗?",
    HINT_ERROR: "金钱不足",
    HINT_SEP:   "-",
    HINT_UNIT:  "个",
    HINT_SUCCESS: "分解成功,获得了以下道具:",

    OK:     "分解",
    CNACEL: "放弃"

  }

  # 用语设定

#==============================================================================
# 设定结束
#==============================================================================

class << self
  def enough_money?; $game_party.gold >= GOLD; end
  def call; SceneManager.call(Scene); end
end

Gold = Class.new(Window_Gold)

class Category < Window_ItemCategory
  def initialize(width)
    @gold_width = width
    super()
  end
  def window_width; Graphics.width - @gold_width; end
  def col_max; return 3; end
  def make_command_list
    add_command(VOCAB[:ITEM], :item)
    add_command(VOCAB[:WEAPON], :weapon)
    add_command(VOCAB[:ARMOR], :armor)
  end
end

class Confirm < Window_HorzCommand
  def initialize(x,y)
    super
    self.openness = 0
    self.z = 300
    self.back_opacity = 230
  end
  def window_width; Graphics.width; end
  def col_max; 2; end
  def make_command_list
    add_command(VOCAB[:OK], :ok, M5DI20160122.enough_money?)
    add_command(VOCAB[:CNACEL], :cancel)
  end
end

class Result < Window_Base
  def initialize(height)
    super *position(height)
    self.openness = 0
    self.z = 300
    self.back_opacity = 230
  end
  def position(height)
    return [0, 0, Graphics.width, height]
  end
  def line_height; super; end
  def draw_line(line, type, data)
    y = line * line_height
    case type
    when 0 then draw_text_ex(0, y, data)
    when 1
      padding = draw_item_padding
      width = contents.width - padding * 2
      draw_item_name(data[0], padding, y, true, width)
      num = draw_item_number(data[1])
      draw_text(padding, y, width, line_height, num + VOCAB[:HINT_UNIT], 2)
    end
    line += 1
  end
  def draw_item_padding
    15
  end
  def draw_item_number(value)
    value == 1 ? "1 " : "1 #{VOCAB[:HINT_SEP]} #{value} "
  end
  def refresh(data)
    contents.clear
    line = 0
    line = draw_line(line, 0, VOCAB[:HINT_HEAD])
    line = draw_line(line, 0, "")
    data.each {|item| line = draw_line(line, 1, item) }
    line = draw_line(line, 0, "")
    line = draw_line(line, 0,
      M5DI20160122.enough_money? ? VOCAB[:HINT_FOOT] : VOCAB[:HINT_ERROR])
  end
end

class Success < Result
  def position(height)
    w, h = Graphics.width / 2, Graphics.height / 2
    return [(Graphics.width - w) / 2, (Graphics.height - h) * 2 / 3, w, h]
  end
  def draw_item_padding
    5
  end
  def draw_item_number(value)
    return "#{value} "
  end
  def refresh(data)
    contents.clear
    line = 0
    line = draw_line(line, 0, VOCAB[:HINT_SUCCESS])
    line = draw_line(line, 0, "")
    data.each {|item| line = draw_line(line, 1, item) }
  end
end
class SuccessCommand < Window_Command
  def window_width; 0; end
  def make_command_list
    add_command('close success window', :ok)
  end
end

class List < Window_ItemList
  def include?(item)
    return item.is_a?(RPG::Item) if @category == :item
    super(item)
  end
  def enable?(item); item; end
  def category=(category)
    return if @category == category
    @m5_data = nil
    super(category)
  end
  def make_item_list
    super
    @m5_data = {} unless @m5_data
    @data.reject! do |item|
      next false if @m5_data[item.id]
      result = item.m5_20160122_decompose_result
      next true unless result
      @m5_data[item.id] = result
      false
    end
    @index = [@index, @data.size - 1].min
  end
  def item_decompose_data
    return [] unless item
    @m5_data[item.id].collect{|id, num| [$data_items[id], num] }
  end
end

class Scene < Scene_MenuBase
  def start
    super
    create_help_window
    create_gold_window
    create_category_window
    create_list_window
    create_confirm_window
    create_result_window
    create_success_window
  end
  def create_category_window
    @category_window = Category.new(@gold_window.width)
    @category_window.help_window = @help_window
    @category_window.y = @help_window.height
    @category_window.set_handler(:ok, method(:on_category_ok))
    @category_window.set_handler(:cancel, method(:return_scene))
  end
  def create_gold_window
    @gold_window = Gold.new
    @gold_window.x = Graphics.width - @gold_window.width
    @gold_window.y = @help_window.height
  end
  def create_list_window
    wy = @category_window.y + @category_window.height
    wh = Graphics.height - wy
    @item_window = List.new(0, wy, Graphics.width, wh)
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @category_window.item_window = @item_window
  end
  def create_confirm_window
    @confirm_window = Confirm.new(0, 0)
    @confirm_window.y = Graphics.height - @confirm_window.height
    @confirm_window.set_handler(:ok,     method(:on_confirm_ok))
    @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  end
  def create_result_window
    @result_window = Result.new(Graphics.height - @confirm_window.height)
  end
  def create_success_window
    @success_window = Success.new(0)
    @success_window_command = SuccessCommand.new(0,0)
    @success_window_command.set_handler(:ok, method(:on_confirm_cancel))
    @success_window_command.set_handler(:cancel, method(:on_confirm_cancel))
  end
  def on_category_ok
    @item_window.activate.select(0)
  end
  def on_item_ok
    @result_window.refresh(@item_window.item_decompose_data)
    @result_window.open
    @confirm_window.refresh
    @confirm_window.open.activate.select(0)
  end
  def on_item_cancel
    @item_window.unselect
    @category_window.activate
  end
  def on_confirm_ok
    result = []
    $game_party.lose_item(@item_window.item, 1)
    @item_window.item_decompose_data.each do |i, n|
      num = n * (rand + RATE)
      num = [[num.round, 1].max, n].min
      $game_party.gain_item(i, num)
      result << [i, num]
    end
    $game_party.lose_gold(GOLD)
    Audio.se_play("Audio/SE/#{SE}") if SE
    @gold_window.refresh
    @item_window.refresh
    @success_window.refresh(result)
    @success_window.open
    @success_window_command.activate.select(0)
  end
  def on_confirm_cancel
    @result_window.close
    @confirm_window.close
    @success_window.close
    @item_window.activate
  end
end

end # module M5DI20160122

class RPG::BaseItem
  def m5_20160122_decompose_result
    value = []
    m5note("分解所得",nil,true,true) do |result|
      value << eval(result.gsub(/,/){','})
    end
    value.empty? ? nil : value
  end
end

5

鸡蛋

鲜花

刚表态过的朋友 (5 人)

发表评论 评论 (5 个评论)

回复 雪域圣痕 2016-5-6 21:06
不同物品不同的分解价格,不知道可不是设置呢,以作为备注的方式呢?
回复 喵呜喵5 2016-5-6 21:16
雪域圣痕: 不同物品不同的分解价格,不知道可不是设置呢,以作为备注的方式呢?
脚本暂时没有提供该功能,如果之后有追加时会回复你
回复 neko001 2017-4-3 22:47
如果你分解完一个道具,背包里却没有其他可以分解的道具,游戏界面就像看起来卡住了一样,很僵啊。。按一下ESC才感觉活起来了。。而且希望可以设置可以分解的类型,例如只能分解武器?
另外 希望那个得到分解出来的道具窗口可以自动关闭~不要手动确认啦
回复 造小梦 2020-4-30 11:17
喵呜喵5: 脚本暂时没有提供该功能,如果之后有追加时会回复你
大佬你基础脚本的网址打不开了,能把脚本私发给我吗?
回复 喵呜喵5 2020-4-30 12:44
造小梦: 大佬你基础脚本的网址打不开了,能把脚本私发给我吗?
https://rpg.blue/home.php?mod=space&uid=291206&do=blog&id=13513

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 20:18

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部