设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1378|回复: 0
打印 上一主题 下一主题

[已经解决] 自改的物品合成脚本使用时出现问题

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1188
在线时间
100 小时
注册时间
2022-1-14
帖子
29
跳转到指定楼层
1
发表于 2022-4-14 15:22:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
主要问题就是界面打开之后,即使金钱和素材足够,也会显示素材无法选择……
传不了图,简单po一下用法
事件脚本:
SceneManager.call(Scene_MakeItem)
SceneManager.scene.prepare(0)


代码:
RUBY 代码复制
  1. #==============================================================================
  2. # ■ Scene_MakeItem
  3. #------------------------------------------------------------------------------
  4. #  表单式合成界面
  5. #==============================================================================
  6.  
  7. #~模块
  8. module INDIX_MAKEITEM_INI
  9.   TABLE1 = [[0, 3, 50, [1,1], [2,1] ],
  10.             [0, 4, 60, [1,1], [2,2] ]
  11.             #[(0物品/1武器/2护甲), 3(id), 50(制作价格), [1(id(物品)),1(数量)],[2,1]]
  12.           ]  #一个表单里包含一套物品制作方式,使用时直接调用表单
  13.   TABLE2 = [[1,10, 50, [1,2], [2,1] ],
  14.             [2, 6, 60, [1,1], [2,1] ]
  15.           ]
  16.  
  17.   def table
  18.     return [TABLE1, TABLE2]  #实际调用时以table[1]表示第0个表单,以此类推
  19.   end
  20. end
  21.  
  22. #~列表窗口
  23. class Window_MakeItemList < Window_Selectable
  24.   include INDIX_MAKEITEM_INI
  25.  
  26.   def initialize(x, y, height, page)
  27.     super(x, y, window_width, height)
  28.     @page = page
  29.     @shop_goods = []
  30.     @shop_recipes = []
  31.     for i in 0...table[@page].size
  32.       recipe = table[@page][i]
  33.       if recipe
  34.         good = [recipe[0],recipe[1], recipe[2]]
  35.         @shop_goods.push(good)
  36.         @shop_recipes.push(recipe)
  37.       end
  38.     end
  39.     @money = 0
  40.     refresh
  41.     select(0)
  42.   end
  43.   def window_width
  44.     return 304
  45.   end
  46.  
  47.   def item_max #项目最大数
  48.     @data ? @data.size : 1
  49.   end
  50.   def item #项目获取
  51.     @data[index]
  52.   end
  53.   def money=(money) #所持金
  54.     @money = money
  55.     refresh
  56.   end
  57.  
  58.   def current_item_enabled? #选择项目的有效状态
  59.     enable?(@data[index])
  60.   end
  61.   def price(item) #价格
  62.     @price[item]
  63.   end
  64.   def enable?(item) #是否可用
  65.     @makable[item]
  66.   end
  67.   def recipe(item) #配方
  68.     @recipe[item]
  69.   end
  70.  
  71.   def have_mat?(recipe)
  72.     flag = true
  73.     if @money >= recipe[2]
  74.       for i in 3...recipe.size
  75.         id   = recipe[i][0]
  76.         num  = recipe[i][1]
  77.         item = $data_items[id]
  78.         if $game_party.item_number(item) < [num, 1].max
  79.           flag = false
  80.         end
  81.       end
  82.     else
  83.       flag = false
  84.     end
  85.     return flag
  86.   end
  87.  
  88.   def refresh #刷新
  89.     make_item_list
  90.     create_contents
  91.     draw_all_items
  92.   end
  93.  
  94.   def make_item_list #列表作成
  95.     @data = []
  96.     @price = {}
  97.     @makable = {}
  98.     @recipe = {}
  99.     for i in 0...@shop_goods.size
  100.       goods = @shop_goods[i]
  101.       recipe = @shop_recipes[i]
  102.       case goods[0]
  103.       when 0;  item = $data_items[goods[1]]
  104.       when 1;  item = $data_weapons[goods[1]]
  105.       when 2;  item = $data_armors[goods[1]]
  106.       end
  107.       if item
  108.         @data.push(item)
  109.         @price[item] = goods[2]
  110.         @makable[item] = have_mat?(recipe)
  111.         @recipe[item] = recipe
  112.       end
  113.     end
  114.   end
  115.  
  116.   def draw_item(index) #绘制项目
  117.     item = @data[index]
  118.     rect = item_rect(index)
  119.     draw_item_name(item, rect.x, rect.y, enable?(item))
  120.     rect.width -= 4
  121.     draw_text(rect, price(item), 2)
  122.   end
  123.  
  124.   def material_window=(material_window)
  125.     @material_window = material_window
  126.     call_update_help
  127.   end
  128.   def update_help
  129.     @help_window.set_item(item) if @help_window
  130.     @material_window.set(item, recipe(item)) if @material_window
  131.   end
  132.  
  133. end
  134.  
  135. #~素材窗口
  136. class Window_MakeItemMaterial < Window_Base
  137.   def initialize(x, y, width, height)
  138.     super(x, y, width, height)
  139.     @item = nil
  140.     refresh
  141.   end
  142.   def refresh
  143.     contents.clear
  144.     draw_possession(4, 0)
  145.     draw_material_info(0, line_height * 2)
  146.   end
  147.  
  148.   #设定物品
  149.   def set(item, recipe)
  150.     @item = item
  151.     @recipe = recipe
  152.     @make_number = 1
  153.     refresh
  154.   end
  155.  
  156.   #设定个数
  157.   def set_num(make_number)
  158.     @make_number = make_number
  159.     refresh
  160.   end
  161.  
  162.   #绘制所持数
  163.   def draw_possession(x, y)
  164.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  165.     change_color(system_color)
  166.     draw_text(rect, Vocab::Possession)
  167.     change_color(normal_color)
  168.     draw_text(rect, $game_party.item_number(@item), 2)
  169.   end
  170.  
  171.   #绘制素材情报
  172.   def draw_material_info(x, y)
  173.     rect = Rect.new(x, y, contents.width, line_height)
  174.     change_color(system_color)
  175.     contents.font.size = 18
  176.     draw_text(rect, "素材", 0)
  177.     if @recipe
  178.       for i in 3...@recipe.size
  179.         id   = @recipe[i][0]
  180.         num  = @recipe[i][1]
  181.         item = $data_items[id]
  182.         rect = Rect.new(x, y + line_height*i, contents.width, line_height)
  183.         enabled = true
  184.         enabled = false if [num*@make_number, 1].max  > $game_party.item_number(item)
  185.         draw_item_name(item, rect.x, rect.y, enabled)
  186.         change_color(normal_color, enabled)
  187.         if num > 0
  188.           draw_text(rect, "#{num*@make_number}/#{$game_party.item_number(item)}", 2)
  189.         end
  190.       end
  191.     end
  192.     change_color(normal_color)
  193.     contents.font.size = 24
  194.   end
  195. end
  196.  
  197. #~输入个数窗口
  198. class Window_MakeItemNumber < Window_ShopNumber
  199.   def refresh
  200.     contents.clear
  201.     draw_item_name(@item, 0, item_y)
  202.     draw_number
  203.     draw_total_price
  204.   end
  205.  
  206.   def material_window=(material_window)
  207.     @material_window = material_window
  208.     call_update_help
  209.   end
  210.  
  211.   #个数变更
  212.   def change_number(amount)
  213.     @number = [[@number + amount, @max].min, 1].max
  214.     call_update_help #追加
  215.   end
  216.  
  217.   def call_update_help
  218.     @material_window.set_num(@number) if @material_window
  219.   end
  220. end
  221.  
  222. #~合成物品场景
  223. class Scene_MakeItem < Scene_MenuBase
  224.   #准备
  225.   def prepare(page)
  226.     @page = page
  227.   end
  228.  
  229.   #开始
  230.   def start
  231.     super
  232.     create_help_window
  233.     create_number_window
  234.     create_gold_window
  235.     create_material_window
  236.     create_list_window
  237.   end
  238.  
  239.   def create_number_window
  240.     wy = @help_window.height
  241.     wh = Graphics.height - wy
  242.     @number_window = Window_MakeItemNumber.new(0, wy, wh)
  243.     @number_window.viewport = @viewport
  244.     @number_window.hide
  245.     @number_window.set_handler(:ok,     method(:on_number_ok))
  246.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  247.   end
  248.  
  249.   def create_gold_window
  250.     @gold_window = Window_Gold.new
  251.     @gold_window.viewport = @viewport
  252.     @gold_window.x = @number_window.width
  253.     @gold_window.y = @help_window.height
  254.     @gold_window.width = Graphics.width - @number_window.width
  255.   end
  256.  
  257.   def create_material_window
  258.     wx = @number_window.width
  259.     wy = @help_window.height + @gold_window.height
  260.     ww = Graphics.width - wx
  261.     wh = Graphics.height - wy
  262.     @material_window = Window_MakeItemMaterial.new(wx, wy, ww, wh)
  263.     @material_window.viewport = @viewport
  264.     @number_window.material_window = @material_window
  265.   end
  266.  
  267.   def create_list_window
  268.     wy = @help_window.height
  269.     wh = Graphics.height - wy
  270.     @list_window = Window_MakeItemList.new(0, wy, wh, @page)
  271.     @list_window.viewport = @viewport
  272.     @list_window.help_window = @help_window
  273.     @list_window.material_window = @material_window
  274.     @list_window.activate
  275.     @list_window.set_handler(:ok,     method(:on_list_ok))
  276.     @list_window.set_handler(:cancel, method(:return_scene))
  277.   end
  278.  
  279.   #启用物品列表
  280.   def activate_list_window
  281.     @list_window.money = money
  282.     @list_window.show.activate
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # ● 合成[決定]
  286.   #--------------------------------------------------------------------------
  287.   def on_list_ok
  288.     @item = @list_window.item
  289.     @list_window.hide
  290.     @number_window.set(@item, max_buy, buying_price, currency_unit)
  291.     @number_window.show.activate
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● 個数入力[決定]
  295.   #--------------------------------------------------------------------------
  296.   def on_number_ok
  297.     Sound.play_shop
  298.     do_syntetic(@number_window.number)
  299.     end_number_input
  300.     @gold_window.refresh
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● 個数入力[キャンセル]
  304.   #--------------------------------------------------------------------------
  305.   def on_number_cancel
  306.     Sound.play_cancel
  307.     end_number_input
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● 合成の実行
  311.   #--------------------------------------------------------------------------
  312.   def do_syntetic(number)
  313.     $game_party.lose_gold(number * buying_price)
  314.     $game_party.gain_item(@item, number)
  315.  
  316.       @recipe = @list_window.recipe(@item)
  317.       for i in 3...@recipe.size
  318.         id   = @recipe[i][0]
  319.         num  = @recipe[i][1]
  320.         item = $data_items[id]
  321.         $game_party.lose_item(item, num*number)
  322.       end
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # ● 個数入力の終了
  326.   #--------------------------------------------------------------------------
  327.   def end_number_input
  328.     @number_window.hide
  329.     activate_list_window
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # ● 最大購入可能個数の取得
  333.   #--------------------------------------------------------------------------
  334.   def max_buy
  335.     max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  336.  
  337.     @recipe = @list_window.recipe(@item)
  338.       for i in 3...@recipe.size
  339.         id   = @recipe[i][0]
  340.         num  = @recipe[i][1]
  341.         item = $data_items[id]
  342.  
  343.         if num > 0
  344.           max_buf = $game_party.item_number(item)/num
  345.         else
  346.           max_buf = 999
  347.         end
  348.         max = [max, max_buf].min
  349.       end
  350.  
  351.     buying_price == 0 ? max : [max, money / buying_price].min
  352.  
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # ● 所持金の取得
  356.   #--------------------------------------------------------------------------
  357.   def money
  358.     @gold_window.value
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # ● 通貨単位の取得
  362.   #--------------------------------------------------------------------------
  363.   def currency_unit
  364.     @gold_window.currency_unit
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ● 合成費用の取得
  368.   #--------------------------------------------------------------------------
  369.   def buying_price
  370.     @list_window.price(@item)
  371.   end
  372. end
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-11-27 18:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表