查看: 2196|回复: 0

[已经过期] 关于theoallen的合成系统,怎么增加条件判定

[复制链接]
梦石
0
星屑
237
在线时间
29 小时
注册时间
2018-5-8
回帖
7
发表于 2018-9-2 14:25:12 | 显示全部楼层 |阅读模式

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

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

×
如题

例如我需要2号人物在队里的时候,才能对物品1号进行合成;
或者判断主角在地图里的坐标,只有在某个位置的时候才能进行合成……

请问一下这两个条件的脚本我需要怎么写?

求教orz

顺便附上源代码
  1. # =============================================================================
  2. # TheoAllen - (像辐射的) 合成系统
  3. # Version : 1.1
  4. # Contact : [url]www.rpgmakerid.com[/url] (or) [url]http://theolized.blogspot.com[/url]
  5. # (English documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_Crafting] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.08.25 - Bugfix disable req text isn't working
  12. # 2013.08.22 - Bugfix at amount of item crafting
  13. #            - Added show condition
  14. #            - Added custom name
  15. # 2013.08.20 - Finished script
  16. # 2013.08.19 - Started script
  17. # =============================================================================
  18. =begin

  19.   ---------------------------------------------------------------------------
  20.   介绍 :
  21.   本脚本可以根据原料合成物品
  22.   
  23.   ---------------------------------------------------------------------------
  24.   使用方法 :
  25.   ---------------------------------------------------------------------------
  26.   本脚本放在插件脚本之下,main之上
  27.   使用脚本来显示合成画面 :
  28.   
  29.   enter_crafting
  30.   
  31.   ---------------------------------------------------------------------------
  32.   物品/武器/护甲备注:
  33.   ---------------------------------------------------------------------------
  34.   -----------------------------------
  35.   简单的备注
  36.   -----------------------------------
  37.   <add item recipe: id,数量>
  38.   <add armor recipe: id,数量>
  39.   <add weapon recipe: id,数量>
  40.   ^
  41.   以上备注可以确定该物品/武器/护甲需要物品/护甲/武器作为合成原料,id为原料id,
  42.   数量为需要原料的数量
  43.   
  44.   <craft name: 文本>
  45.   ^
  46.   暂时改变物品名称的备注.例如,在你的合成列表中,回复剂会显示名称“合成回复剂”
  47.   但是当你成功合成回复剂,且得到它后,它的名称会变回初始名称。
  48.   -----------------------------------
  49.   复杂的备注
  50.   (如果你不懂,就不要尝试)
  51.   -----------------------------------
  52.   <craft require>
  53.   脚本
  54.   </craft require>
  55.   ^
  56.   设定物品的合成条件,由脚本作为判断条件。写作多行时会视为同一行。我在别处写了
  57.   可以调用的脚本指令,可是..用的是印尼语。
  58.   
  59.   错误的书写会使游戏崩溃,所以请确定书写规范.
  60.   
  61.   <craft req text>
  62.   文本
  63.   </craft req text>
  64.   ^
  65.   用于告诉玩家合成的条件。例如,如果合成某物品需要一把银色的锤子,则你可以这样写:
  66.   
  67.   <craft req text>
  68.   合成这个物品需要一把银色的锤子
  69.   </craft req text>
  70.   
  71.   <craft show eval>
  72.   脚本
  73.   </craft show eval>
  74.   ^
  75.   以上备注用来确定物品是否会出现在合成列表中。例如,合成圣灵药时,需要角色学会
  76.   高等级的炼金术,所以在角色学会特定技能前不会显示于合成列表中。
  77.   
  78.   错误的书写会使游戏崩溃,所以请确定书写规范.
  79.   
  80.   ---------------------------------------------------------------------------
  81.   使用规定 :
  82.   属名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
  83.   如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.

  84. =end
  85. # =============================================================================
  86. # 设定 :
  87. # =============================================================================
  88. module THEO
  89.   module Craft
  90.   
  91.   # --------------------------------------------------------------------------
  92.   # 通用设定 (true/false)
  93.   # --------------------------------------------------------------------------
  94.     MainMenu        = true
  95.   # 是否在菜单中显示"合成"指令
  96.   
  97.     DisplayReqText  = true
  98.   # 对于那些不想使用合成条件文本的人,你可以在这里禁用它
  99.   
  100.   # --------------------------------------------------------------------------
  101.   # 用语设置 (文本/字符串)
  102.   # --------------------------------------------------------------------------
  103.     VocabMenu      = "合成"          # 主菜单的合成指令
  104.     VocabNoReq     = "- 无 -"        # 无任何合成条件
  105.     VocabRequire   = "合成条件 :"    # 合成条件
  106.     VocabRecipes   = "原料 : "       # 原料
  107.     VocabInventory = "持有量: "      # 持有量
  108.    
  109.   # --------------------------------------------------------------------------
  110.   # 杂项 (使用数字来设定 / 0123456789)
  111.   # --------------------------------------------------------------------------
  112.     Text_Buffer_x = 12
  113.   # 文本右移距离
  114.   
  115.     AmountSize = 250
  116.   # 数量窗口的宽度
  117.   
  118.   end
  119. end
  120. # =============================================================================
  121. # 以下勿动
  122. # =============================================================================
  123. module THEO
  124.   module Craft
  125.     def self.items
  126.       items = $data_items + $data_armors + $data_weapons
  127.       items.compact!
  128.       items.select {|item| item.can_be_crafted? }
  129.     end
  130.   end
  131. end

  132. class RPG::BaseItem
  133.   attr_accessor :item_recipes
  134.   attr_accessor :armor_recipes
  135.   attr_accessor :weapon_recipes
  136.   attr_accessor :enable_cond
  137.   attr_accessor :enable_text
  138.   attr_accessor :show_cond
  139.   attr_accessor :craft_name
  140.   attr_accessor :craft_key  # For future planned feature
  141.   
  142.   def load_recipes
  143.     @item_recipes = {}
  144.     @armor_recipes = {}
  145.     @weapon_recipes = {}
  146.     @show_cond = @enable_cond = "true"
  147.     @enable_text = []
  148.     @craft_name = ""
  149.     @craft_key = ""
  150.     read_craft_cond = read_craft_txt = read_craft_show = false
  151.     self.note.split(/[\r\n]+/).each do |line|
  152.       case line
  153.       when /<(?:ADD_ITEM_RECIPE|add item recipe): (.*)>/i
  154.         str = $1.scan(/\d+/)
  155.         @item_recipes[str[0].to_i] = str[1].to_i
  156.       when /<(?:ADD_ARMOR_RECIPE|add armor recipe): (.*)>/i
  157.         str = $1.scan(/\d+/)
  158.         @armor_recipes[str[0].to_i] = str[1].to_i
  159.       when /<(?:ADD_WEAPON_RECIPE|add WEAPON recipe): (.*)>/i
  160.         str = $1.scan(/\d+/)
  161.         @weapon_recipes[str[0].to_i] = str[1].to_i
  162.       when /<(?:CRAFT_REQUIRE|craft require)>/i
  163.         read_craft_cond = true
  164.         @enable_cond = ""
  165.       when /<\/(?:CRAFT_REQUIRE|craft require)>/i
  166.         read_craft_cond = false
  167.       when /<(?:CRAFT_REQ_TEXT|craft req text)>/i
  168.         read_craft_txt = true
  169.       when /<\/(?:CRAFT_REQ_TEXT|craft req text)>/i
  170.         read_craft_txt = false
  171.       when /<(?:CRAFT_SHOW_EVAL|craft show eval)>/i
  172.         read_craft_show = true
  173.         @show_cond = ""
  174.       when /<\/(?:CRAFT_SHOW_EVAL|craft show eval)>/i
  175.         read_craft_show = false
  176.       when /<(?:CRAFT_NAME|craft name): (.*)>/i
  177.         @craft_name = $1.to_s
  178.       when /<(?:CRAFT_KEY|craft key): [ ]*(.*)>/i
  179.         @craft_key = $1.to_s
  180.       else
  181.         if read_craft_cond
  182.           @enable_cond += line
  183.         end
  184.         if read_craft_txt
  185.           @enable_text.push(line)
  186.         end
  187.         if read_craft_show
  188.           @show_cond += line
  189.         end
  190.       end
  191.     end
  192.   end
  193.   
  194.   def recipes
  195.     [@item_recipes, @armor_recipes, @weapon_recipes]
  196.   end
  197.   
  198.   # ---------------------------------------------------------------------------
  199.   # If the error is directed you to this line. It's possible that you wrote
  200.   # craft requirement formula in a wrong way. Not this script mistake
  201.   # ---------------------------------------------------------------------------
  202.   def craft_possible?
  203.     return eval(@enable_cond) && can_be_crafted?
  204.   end
  205.   
  206.   def show_possible?
  207.     return eval(@show_cond)
  208.   end
  209.   # ---------------------------------------------------------------------------
  210.   # Determine if item can be crafted
  211.   # ---------------------------------------------------------------------------
  212.   def can_be_crafted?
  213.     recipes.any? {|recipe| !recipe.empty?} && show_possible?
  214.   end
  215.   
  216. end

  217. class << DataManager
  218.   
  219.   alias theo_recipe_craft_load_db load_database
  220.   def load_database
  221.     theo_recipe_craft_load_db
  222.     load_item_recipes
  223.   end
  224.   
  225.   def load_item_recipes
  226.     ($data_items+$data_armors+$data_weapons).compact.each do |db|
  227.       db.load_recipes
  228.     end
  229.   end
  230.   
  231. end

  232. class Window_CraftList < Window_ItemList
  233.   
  234.   def initialize(x,y,w,h,key)
  235.     @key = key
  236.     super(x,y,w,h)
  237.     refresh
  238.   end
  239.   
  240.   def col_max
  241.     return 1
  242.   end
  243.   
  244.   def status_window=(window)
  245.     @status_window = window
  246.     update_help
  247.   end
  248.   
  249.   def item_number_window=(window)
  250.     @inum_window = window
  251.     update_help
  252.   end
  253.   
  254.   def update_help
  255.     super
  256.     @status_window.set_item(item) if @status_window
  257.     @inum_window.set_item(item) if @inum_window
  258.   end
  259.   
  260.   def make_item_list
  261.     @data = []
  262.     items = THEO::Craft.items
  263.     items.each do |item|
  264.       @data.push(item) if @key.empty? || item.craft_key == @key
  265.     end
  266.   end
  267.   
  268.   def enable?(item)
  269.     item.craft_possible? && has_recipes?(item) && has_free_slot?(item)
  270.   end
  271.   
  272.   def has_free_slot?(item)
  273.     $game_party.item_number(item) < $game_party.max_item_number(item)
  274.   end
  275.   
  276.   def has_recipes?(item)
  277.     result1 = check_recipe(item.recipes[0], $data_items)
  278.     result2 = check_recipe(item.recipes[1], $data_armors)
  279.     result3 = check_recipe(item.recipes[2], $data_weapons)
  280.     return result1 && result2 && result3
  281.   end
  282.   
  283.   def check_recipe(recipes, data)
  284.     return true if recipes.empty?
  285.     return recipes.all? {|recipe|
  286.       $game_party.item_number(data[recipe[0]]) >= recipe[1]}
  287.   end
  288.   
  289.   def draw_item_name(item, x, y, enabled = true, width = 172)
  290.     return unless item
  291.     draw_icon(item.icon_index, x, y, enabled)
  292.     change_color(normal_color, enabled)
  293.     name = item.craft_name.empty? ? item.name : item.craft_name
  294.     draw_text(x + 24, y, width, line_height, name)
  295.   end
  296.   
  297.   def draw_item_number(rect, item)
  298.     return unless $imported[:Theo_LimInventory]
  299.     return unless THEO::LimInv::Display_ItemSize
  300.     draw_text(rect, sprintf(":%2d", item.inv_size), 2)
  301.   end
  302.   
  303. end

  304. class Window_CraftStatus < Window_Base
  305.   
  306.   def set_item(item)
  307.     @item = item
  308.     refresh
  309.   end
  310.   
  311.   def refresh
  312.     contents.clear
  313.     return unless @item
  314.     @line_count = 0
  315.     draw_requirement
  316.     draw_recipes
  317.   end
  318.   
  319.   def draw_requirement
  320.     return unless THEO::Craft::DisplayReqText
  321.     change_color(system_color)
  322.     draw_text(line_rect(4),THEO::Craft::VocabRequire)
  323.     increase_line_count
  324.     if !@item.enable_text.empty?
  325.       change_color(normal_color, @item.craft_possible?)
  326.       @item.enable_text.each do |text|
  327.         draw_text(line_rect(buff_x),text)
  328.         increase_line_count
  329.       end
  330.       increase_line_count
  331.     else
  332.       change_color(normal_color)
  333.       draw_text(line_rect(buff_x),THEO::Craft::VocabNoReq)
  334.       2.times { increase_line_count }
  335.     end
  336.   end
  337.   
  338.   def draw_recipes
  339.     change_color(system_color)
  340.     draw_text(line_rect(4),THEO::Craft::VocabRecipes)
  341.     change_color(normal_color)
  342.     increase_line_count
  343.     draw_recipe(@item.recipes[0], $data_items)
  344.     draw_recipe(@item.recipes[1], $data_armors)
  345.     draw_recipe(@item.recipes[2], $data_weapons)
  346.   end
  347.   
  348.   def draw_recipe(hash, items)
  349.     hash.each do |id,amount|
  350.       item_num = $game_party.item_number(items[id])
  351.       enable = item_num >= amount
  352.       change_color(normal_color, enable)
  353.       rect = line_rect(buff_x + 24)
  354.       text = sprintf("%s (%d/%d)",items[id].name, item_num, amount)
  355.       draw_text(rect, text)
  356.       draw_icon(items[id].icon_index, buff_x, @line_count, enable)
  357.       increase_line_count
  358.     end
  359.   end  
  360.   
  361.   def line_rect(xpos = 0)
  362.     Rect.new(xpos,@line_count,contents.width-xpos,line_height)
  363.   end
  364.   
  365.   def increase_line_count
  366.     @line_count += line_height
  367.   end
  368.   
  369.   def buff_x
  370.     THEO::Craft::Text_Buffer_x
  371.   end
  372.   
  373. end

  374. class Window_CraftAmount < Window_Base
  375.   attr_accessor :inv_window
  376.   attr_accessor :ok_handler
  377.   attr_accessor :cancel_handler
  378.   attr_reader :amount
  379.   
  380.   def initialize
  381.     super(0,0,window_width,fitting_height(1))
  382.     self.openness = 0
  383.     to_center
  384.     @amount = 0
  385.     @max = 0
  386.     @item = nil
  387.   end
  388.   
  389.   def window_width
  390.     return THEO::Craft::AmountSize
  391.   end
  392.   
  393.   def to_center
  394.     self.x = (Graphics.width - width)/2
  395.     self.y = (Graphics.height - height)/2
  396.   end
  397.   
  398.   def set(item, max)
  399.     change_amount(0,true)
  400.     @item = item
  401.     @max = max
  402.     open
  403.     refresh
  404.   end
  405.   
  406.   def refresh
  407.     contents.clear
  408.     return unless @item
  409.     draw_item_name(@item,0,0,true,contents.width)
  410.     draw_amount
  411.   end
  412.   
  413.   def draw_amount
  414.     text = sprintf("%d/%d",@amount,@max)
  415.     draw_text(0,0,contents.width,line_height,text,2)
  416.   end
  417.   
  418.   def update
  419.     super
  420.     if open?
  421.       change_amount(1) if Input.repeat?(:RIGHT)
  422.       change_amount(-1) if Input.repeat?(:LEFT)
  423.       change_amount(10) if Input.repeat?(:UP)
  424.       change_amount(-10) if Input.repeat?(:DOWN)
  425.       call_ok if Input.trigger?(:C)
  426.       call_cancel if Input.trigger?(:B)
  427.     end
  428.   end
  429.   
  430.   def change_amount(number, instant = false)
  431.     if instant
  432.       @amount = number
  433.     else
  434.       Sound.play_cursor
  435.       @amount = [[@amount + number,0].max,@max].min
  436.     end
  437.     refresh
  438.     @inv_window.amount = @amount if @inv_window
  439.   end
  440.   
  441.   def call_ok
  442.     Sound.play_ok
  443.     ok_handler.call
  444.     change_amount(0,true)
  445.     close
  446.   end
  447.   
  448.   def call_cancel
  449.     Sound.play_cancel
  450.     cancel_handler.call
  451.     change_amount(0,true)
  452.     close
  453.   end
  454.   
  455. end

  456. class Window_CraftFooter < Window_Base
  457.   
  458.   def initialize
  459.     super(0,0,Graphics.width,fitting_height(1))
  460.     self.y = Graphics.height - height
  461.     @amount = 0
  462.     @item = nil
  463.     refresh
  464.   end
  465.   
  466.   def amount=(amount)
  467.     @amount = amount
  468.     refresh
  469.   end
  470.   
  471.   def refresh
  472.     contents.clear
  473.     change_color(system_color)
  474.     draw_text(0,0,contents.width,line_height,THEO::Craft::VocabInventory)
  475.     change_color(normal_color)
  476.     return unless @item
  477.     if $imported[:Theo_LimInventory]
  478.       draw_inv_slot(0,0)
  479.     else
  480.       draw_item_number
  481.     end
  482.   end
  483.   
  484.   def draw_inv_slot(x,y,width = contents.width,align = 2)
  485.     total = $game_party.total_inv_size + @amount*@item.inv_size
  486.     total -= calculate_lose_item
  487.     txt = sprintf("%d/%d", total, $game_party.inv_max)
  488.     color = THEO::LimInv::NearMaxed_Color
  489.     near_max = total.to_f/$game_party.inv_max >=
  490.       (100 - THEO::LimInv::NearMaxed_Percent).to_f / 100
  491.     if near_max
  492.       change_color(text_color(color))
  493.     else
  494.       change_color(normal_color)
  495.     end
  496.     draw_text(x,y,width,line_height,txt,align)
  497.     change_color(normal_color)
  498.   end
  499.   
  500.   def draw_item_number
  501.     txt = sprintf("%d/%d",@amount + $game_party.item_number(@item),
  502.       $game_party.max_item_number(@item))
  503.     draw_text(0,0,contents.width,line_height,txt,2)
  504.   end
  505.   
  506.   def set_item(item)
  507.     @item = item
  508.     refresh
  509.   end
  510.   
  511.   def calculate_lose_item
  512.     result = 0
  513.     @item.recipes[0].each do |id,amount|
  514.       data = $data_items[id]
  515.       amount *= @amount
  516.       result += amount
  517.     end
  518.     @item.recipes[1].each do |id,amount|
  519.       data = $data_armors[id]
  520.       amount *= @amount
  521.       result += amount
  522.     end
  523.     @item.recipes[2].each do |id,amount|
  524.       data = $data_weapons[id]
  525.       amount *= @amount
  526.       result += amount
  527.     end
  528.     return result
  529.   end
  530.   
  531. end

  532. class Game_Interpreter
  533.   
  534.   # ----------------------------------------------
  535.   # key is just for my future planned feature
  536.   # ----------------------------------------------
  537.   def enter_crafting(key = "")
  538.     SceneManager.call(Scene_ItemCrafting)
  539.     SceneManager.scene.prepare(key)
  540.     Fiber.yield
  541.   end
  542.   
  543. end

  544. class Window_MenuCommand < Window_Command
  545.   
  546.   alias theo_craft_ori_cmd add_original_commands
  547.   def add_original_commands
  548.     theo_craft_ori_cmd
  549.     return unless THEO::Craft::MainMenu
  550.     add_command(THEO::Craft::VocabMenu, :craft)
  551.   end
  552.   
  553. end

  554. class Scene_Menu < Scene_MenuBase
  555.   
  556.   alias theo_craft_cmnd_window create_command_window
  557.   def create_command_window
  558.     theo_craft_cmnd_window
  559.     @command_window.set_handler(:craft, method(:enter_crafting))
  560.   end
  561.   
  562.   def enter_crafting
  563.     SceneManager.call(Scene_ItemCrafting)
  564.     SceneManager.scene.prepare("")
  565.   end
  566.   
  567. end

  568. class Scene_ItemCrafting < Scene_MenuBase
  569.   
  570.   def prepare(key)
  571.     @key = key
  572.   end
  573.   
  574.   def start
  575.     super
  576.     create_help_window
  577.     create_craftfooter_window
  578.     create_craftlist_window
  579.     create_craftstatus_window
  580.     create_craftamount_window
  581.   end
  582.   
  583.   def create_craftfooter_window
  584.     @craft_footer = Window_CraftFooter.new
  585.   end
  586.   
  587.   def create_craftlist_window
  588.     wy = @help_window.height
  589.     ww = Graphics.width/2
  590.     wh = Graphics.height - wy - @craft_footer.height
  591.     @craft_list = Window_CraftList.new(0,wy,ww,wh,@key)
  592.     @craft_list.set_handler(:ok, method(:on_craft_ok))
  593.     @craft_list.set_handler(:cancel, method(:return_scene))
  594.     @craft_list.help_window = @help_window
  595.     @craft_list.item_number_window = @craft_footer
  596.     @craft_list.activate
  597.     @craft_list.select(0)
  598.   end
  599.   
  600.   def create_craftstatus_window
  601.     wx = @craft_list.width
  602.     wy = @craft_list.y
  603.     ww = @craft_list.width
  604.     wh = @craft_list.height
  605.     @craft_status = Window_CraftStatus.new(wx,wy,ww,wh)
  606.     @craft_list.status_window = @craft_status
  607.   end
  608.   
  609.   def create_craftamount_window
  610.     @craft_amount = Window_CraftAmount.new
  611.     @craft_amount.ok_handler = method(:on_amount_ok)
  612.     @craft_amount.cancel_handler = method(:on_amount_cancel)
  613.     @craft_amount.inv_window = @craft_footer
  614.   end
  615.   
  616.   def on_craft_ok
  617.     @craft_amount.set(item, item_max)
  618.   end
  619.   
  620.   def on_amount_ok
  621.     $game_party.gain_item(item, @craft_amount.amount)
  622.     lose_recipes
  623.     @craft_status.refresh
  624.     @craft_list.refresh
  625.     @craft_list.activate
  626.   end
  627.   
  628.   def on_amount_cancel
  629.     @craft_list.activate
  630.   end
  631.   
  632.   def item
  633.     @craft_list.item
  634.   end
  635.   
  636.   def item_max
  637.     ary = []
  638.     item.recipes[0].each do |id,amount|
  639.       data = $data_items[id]
  640.       ary.push($game_party.item_number(data)/amount)
  641.     end
  642.     item.recipes[1].each do |id,amount|
  643.       data = $data_armors[id]
  644.       ary.push($game_party.item_number(data)/amount)
  645.     end
  646.     item.recipes[2].each do |id,amount|
  647.       data = $data_weapons[id]
  648.       ary.push($game_party.item_number(data)/amount)
  649.     end
  650.     max_item = $game_party.max_item_number(item)
  651.     inum = $game_party.item_number(item)
  652.     return [ary.min , max_item - inum].min
  653.   end
  654.   
  655.   def lose_recipes
  656.     item.recipes[0].each do |id,amount|
  657.       data = $data_items[id]
  658.       amount *= @craft_amount.amount
  659.       $game_party.lose_item(data,amount)
  660.     end
  661.     item.recipes[1].each do |id,amount|
  662.       data = $data_armors[id]
  663.       amount *= @craft_amount.amount
  664.       $game_party.lose_item(data,amount)
  665.     end
  666.     item.recipes[2].each do |id,amount|
  667.       data = $data_weapons[id]
  668.       amount *= @craft_amount.amount
  669.       $game_party.lose_item(data,amount)
  670.     end
  671.   end
  672.   
  673. end
复制代码
01.png
02.png
03.png
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部