目前共有1篇帖子。
【腳本】物品合成系統【經過本人修正】
1樓 巨大八爪鱼 2013-11-30 20:33
#============================================================================== 
# Sample master list for crafting script
# written by Deke
#============================================================================================
# 簡介:
# 這是一個很不錯的合成物品系統,可以通過遊戲的過程,不斷學習可以合成的
# 物品方法。
#
# 使用方法:
# 1、召喚界面:使用腳本$scene = Scene_Craft.new
#
# 2、學習合成:$game_party.learn_recipe(合成項目)
#
# 3、合成定義:
# 這個合成腳本可以定義兩種合成物品。一種是預先定義好了的,就像下面這樣,
# 直接寫在這裡就可以,另一種是在學習之前現場定義。
#
# 4、舉例
#  4.1、學會recipe_list[1]定義的合成:$game_party.learn_recipe($game_temp.recipe_list[1])
#       注意,一行如果輸入不下,在(的後面或[的後面按回車換行,否則可能出錯
#
#  4.2、在遊戲中臨時定義一種合成,讓玩家學會。使用事件中的腳本如下,  
#  腳本:
#    材料 = [$game_variables[1],$game_variables[2]]  #——材料編號是變量1、2的編號
#    材料種類 = [0,0]                                #——材料是物品
#    材料數量 = [$game_variables[3],$game_variables[4]]  #——需要材料數量是變量3、4的編號
#    成品 = $game_variables[5]                       #——獲得結果編號是5
#    成品種類 = 1                                    #——成品是防具類
#    $game_party.learn_recipe(Game_Recipe.new(材料,材料種類, 材料數量,成品,成品種類))
#===========================================================================================
class Game_Temp
  attr_reader :recipe_list 
  alias crafting_temp_initialize initialize
  def initialize
    crafting_temp_initialize
    @recipe_list=[]
    get_recipe_list
  end 
  def get_recipe_list   
    ##########################################################################
    # 0 號合成物品設定 (物品小藥水×2 + 中藥水 = 大藥水)
    ##########################################################################
    材料 = [1, 2]             # 需要材料的數據庫編號
    材料種類 = [0, 0]         # 需要材料的種類,0是普通物品,1是防具,2是武器
    材料數量 = [2, 1]         # 需要材料的數量
    成品 = 3                  # 獲得物品編號
    成品種類 = 0              # 獲得物品種類,0是普通物品,1是防具,2是武器
    @recipe_list[0] = Game_Recipe.new(材料,材料種類, 材料數量,成品,成品種類)
    # 巨大八爪魚提示:
    # 這裡的序號必須連續,且從0開始
    # 否則會腳本錯誤
   
    ##########################################################################
    # 1 號合成物品設定 (武器銅劍、鐵劍、鋼劍各1 = 密切斯特劍)
    ##########################################################################
    材料 = [1, 2, 3]          # 需要材料的數據庫編號
    材料種類 = [2, 2, 2]      # 需要材料的種類,0是普通物品,1是防具,2是武器
    材料數量 = [3, 2, 1]      # 需要材料的數量
    成品 = 4                  # 獲得物品編號
    成品種類 = 2              # 獲得物品種類,0是普通物品,1是防具,2是武器
    @recipe_list[1] = Game_Recipe.new(材料,材料種類, 材料數量,成品,成品種類)
   
    ##########################################################################
    # 2 號合成物品設定 (物品力量之石×2 + 防具鋼盾×1 = 密切斯特盾)
    ##########################################################################
    材料 = [13, 3]            # 需要材料的數據庫編號
    材料種類 = [0, 1]         # 需要材料的種類,0是普通物品,1是防具,2是武器
    材料數量 = [2, 1]         # 需要材料的數量
    成品 = 4                  # 獲得物品編號
    成品種類 = 1              # 獲得物品種類,0是普通物品,1是防具,2是武器
    @recipe_list[2] = Game_Recipe.new(材料,材料種類, 材料數量,成品,成品種類)
   
  end # of get_recipe_list method
end # of updates to Game_Temp Class
#================================
# CRAFTING PROGRAM
#----------------------------------------------------------------
#-written by Deke
#-yes_no window code created by Phsylomortis
#----------------------------------------------------------------
#================================
#updates to Game_Party class
class Game_Party
 
  attr_accessor       :recipes
 
  alias crafting_party_initialize initialize
 
  def initialize
    crafting_party_initialize
    @recipes=[]
  end
 
  #----------------------------------------------------------------------
  def know?(recipe, version = 1)
    unless recipe.is_a?(Game_Recipe)
      recipe = get_recipe_from_master_list(recipe, version)
    end
    return $game_party.recipes.include?(recipe)
  end
 
#----------------------------------------------------------------------
  def learn_recipe(recipe , version = 1)
    unless recipe.is_a?(Game_Recipe)
      recipe = get_recipe_from_master_list(recipe, version)
    end
    if recipe.is_a?(Game_Recipe)
      unless know?(recipe)
        @recipes.push(recipe)
      end
    end
  end
 
#----------------------------------------------------------------------
  def forget_recipe(recipe , version = 1)
    if !recipe.is_a?(Game_Recipe)
      recipe = get_recipe_from_master_list(recipe, version)
    end
    if recipe.is_a?(Game_Recipe)
      for i in 0...@recipes.size
        if recipe == @recipes
          index = i
          break
        end
      end
      if index != nil
        @recipes.delete(@recipes[index])
      end
    end
  end
 
#----------------------------------------------------------------------
  def get_recipe_from_master_list(item, version)
    index = nil
    for i in 0...$game_temp.recipe_list.size
      if item[0] == $game_temp.recipe_list.result and item[1] ==$game_temp.recipe_list.result_type
        version -= 1
        if version == 0
          index = i
          break
        end
      end
    end
    if index.is_a?(Integer)
      return ($game_temp.recipe_list[index])
    else
      return false
    end
  end
 
end # of Game_Party updates
#================================
class Game_Recipe
  attr_reader :ingredients
  attr_reader :quantities
  attr_reader :result
  attr_reader :result_type
  attr_reader :ingredient_types
 
#----------------------------------------------------------------------
  def initialize( ingredients, ingredient_types, quantities, result, result_type)
    @ingredients = ingredients
    @ingredient_types = ingredient_types
    @quantities = quantities
    @result = result
    @result_type = result_type
  end
 
#----------------------------------------------------------------------
  def name
    case @result_type
      when 0
        name = $data_items[@result].name
      when 1
        name = $data_armors[@result].name
      when 2
        name = $data_weapons[@result].name
    end
    return name
  end
#----------------------------------------------------------------------
  def have
    for i in 0...@ingredients.size
      case @ingredient_types[i]
      when 0
        a = $game_party.item_number(@ingredients[i])
      when 1
        a = $game_party.armor_number(@ingredients[i])
      when 2
        a = $game_party.weapon_number(@ingredients[i])
      end
      return false if a<@quantities[i]
    end
    return true
  end
#----------------------------------------------------------------------
  def decrement
    for i in 0...@ingredients.size
      case @ingredient_types[i]
      when 0
        $game_party.lose_item(@ingredients[i], @quantities[i])
      when 1
        $game_party.lose_armor(@ingredients[i], @quantities[i])
      when 2
        $game_party.lose_weapon(@ingredients[i], @quantities[i])
      end
    end
  end
#----------------------------------------------------------------------
  def make
    if have
      case @result_type
      when 0
        $game_party.gain_item(@result, 1)
      when 1
        $game_party.gain_armor(@result, 1)
      when 2
        $game_party.gain_weapon(@result, 1)
      end
      decrement
    end
  end
 
#----------------------------------------------------------------------
  def == (recipe)
    if recipe.is_a?(Game_Recipe)
      equal = true
      if recipe.ingredients != self.ingredients
        equal = false
      end
      if recipe.ingredient_types != self.ingredient_types
        equal = false
      end
      if recipe.quantities != self.quantities
        equal = false
      end
      if recipe.result != self.result
        equal=false
      end
      if recipe.result_type != self.result_type
        equal = false
      end
    else
      equal = false
    end
    return equal
  end
 
end # of Game_Recipe class
#===================================
class Window_Craft < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 240, 416)
    @column_max = 1
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def recipe
    return $game_party.recipes[self.index]
  end
  ############################################################################
  def item
    case @types[self.index]
    when 0
      return $data_items[@ingredients]
    when 1
      return $data_armors[@ingredients]
    when 2
      return $data_weapons[@ingredients]
    end
  end
  ############################################################################
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
   
    $game_party.recipes = $game_temp.recipe_list if $game_party.recipes==nil
    @item_max = $game_party.recipes.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = "黑體" # = "黑體"
      self.contents.font.size = 18 # = 18
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    recipe = $game_party.recipes[index]
    self.contents.font.color = recipe.have ? normal_color : disabled_color
    x = 16
    y = index * 32
    self.contents.draw_text(x , y, self.width-32, 32, recipe.name, 0)
  end
  #--------------------------------------------------------------------------
  def update_help
    current_recipe = recipe
    if current_recipe.is_a?(Game_Recipe)
    case current_recipe.result_type
      when 0
        description = $data_items[current_recipe.result].description
      when 1
        description = $data_armors[current_recipe.result].description
      when 2
        description = $data_weapons[current_recipe.result].description
      end
    else
      description = ""
    end
    @help_window.set_text(description)
    @help_window.update
  end
 
end # of Window_Craft
#=======================================
class Window_CraftResult < Window_Base
  #--------------------------------------------------------------------------
  def initialize
    super(240, 64, 400, 184)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "黑體" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
    self.contents.font.size = 18 # = 20
    @result = nil
    @type = nil
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    case @type
      when 0
        item = $data_items[@result]
        if item.recover_hp_rate > item.recover_hp
          hp_string = "HP回復率:"
          hp_stat = item.recover_hp_rate
        else
          hp_string = "HP回復量:"
          hp_stat = item.recover_hp
        end
        if item.recover_sp_rate > item.recover_sp
          sp_string = "SP回復率:"
          sp_stat = item.recover_sp_rate
        else
          sp_string = "SP回復量:"
          sp_stat = item.recover_sp
        end
        @strings = [hp_string, sp_string, "物理防禦:" , "魔法防禦:", "命中率:", "分散度:"]
        @stats = [hp_stat, sp_stat, item. pdef_f, item.mdef_f, item.hit, item.variance,
                       $game_party.item_number(@result)]
        @bitmap = RPG::Cache.icon(item.icon_name)
      when 1
        item = $data_armors[@result]
        @strings = ["物理防禦:", "魔法防禦:", "迴避修正:", "力量增加:", "靈巧增加:",
                       "速度增加:", "先攻增加:"]
        @stats = [item.pdef, item.mdef, item.eva, item.str_plus, item.dex_plus,
                    item.agi_plus, item.int_plus, $game_party.armor_number(@result) ]
        @bitmap = RPG::Cache.icon(item.icon_name)
      when 2
        item = $data_weapons[@result]
        @strings =["攻擊力:", "物理防禦:", "魔法防禦:", "力量增加:", "靈巧增加:",
                    "速度增加:", "先攻增加:"]
        @stats = [item.atk, item.pdef, item.mdef, item.str_plus, item.dex_plus,
                    item.agi_plus, item.int_plus, $game_party.weapon_number(@result) ]
        @bitmap = RPG::Cache.icon(item.icon_name)
    end
    for i in 0...@strings.size
      x = i%2 * 184
      y = i /2 *28 +32
      self.contents.font.color = normal_color
      self.contents.draw_text(x,y,100, 28,@strings[i])
      self.contents.font.color = system_color
      self.contents.draw_text(x + 110, y, 45, 28, @stats[i].to_s)
    end
    self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, 24, 24), 255)
    self.contents.font.color= normal_color
    self.contents.draw_text(40, 0, 300, 28, "目前擁有該物品的數量: ")
    self.contents.font.color = system_color
    count = @stats[@stats.size - 1].to_s
    self.contents.draw_text(294, 0, 45, 28, count )
  end
   
#----------------------------------------------------------------------
  def set_result(result , type)
    @result = result
    @type = type
    refresh
  end
end #of Window_CraftResult
#=======================================
class Window_CraftIngredients < Window_Base
  #--------------------------------------------------------------------------
  def initialize
    super(240, 248, 400, 232)#232 - 32 + 16 - 15)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "黑體" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
    self.contents.font.size = 18 # = 20
    @ingredients = []
    @types = []
    @quantities = []
    @item = nil
    @count = 0
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
   
    self.contents.font.size=18
    self.contents.font.color = normal_color
    self.contents.font.name = "黑體"
    self.contents.draw_text(30, 0, 128, 20, "所需材料")
    self.contents.draw_text(244, 0, 64, 20, "現有")
    self.contents.draw_text(299, 0, 64, 20, "需要")
    self.contents.font.size=16
   
    for i in 0...@ingredients.size
      case @types[i]
      when 0
        @item = $data_items[@ingredients[i]]
        @count = $game_party.item_number(@ingredients[i])
      when 1
        @item = $data_armors[@ingredients[i]]
        @count = $game_party.armor_number(@ingredients[i])
      when 2
        @item = $data_weapons[@ingredients[i]]
        @count = $game_party.weapon_number(@ingredients[i])
      end
      y = (i+1) *26-2
     
      self.contents.blt(0, y, RPG::Cache.icon(@item.icon_name), Rect.new(0, 0, 24, 24), 255)
      self.contents.font.color = @count >= @quantities[i] ? normal_color : disabled_color
      self.contents.draw_text(30, y, 280, 28, @item.name)
      self.contents.draw_text(300, y, 45, 28, @quantities[i].to_s)
      self.contents.font.color = system_color
      self.contents.draw_text(245, y, 45, 28, @count.to_s )
    end
  end
  #--------------------------------------------------------------------------
  def set_ingredients(ingredients , types, quantities)
    @ingredients = ingredients
    @types = types
    @quantities = quantities
    refresh
  end
end # of Window_CraftIngredients
#======================================
class Scene_Craft
  #--------------------------------------------------------------------------
  def initialize(craft_index=0)
    @craft_index=craft_index
  end
 
  #--------------------------------------------------------------------------
  def main
    @craft_window = Window_Craft.new
    @craft_window.index=@craft_index
    @confirm_window = Window_Base.new(120, 188, 400, 64)
    @confirm_window.contents = Bitmap.new(368, 32)
    @confirm_window.contents.font.name = "黑體"
    @confirm_window.contents.font.size = 20
    @help_window = Window_Help.new
    @craft_window.help_window = @help_window
    @result_window=Window_CraftResult.new
    @ingredients_window=Window_CraftIngredients.new
    @yes_no_window = Window_Command.new(100, ["確定", "放棄"])
    @confirm_window.visible = false
    @confirm_window.z = 1500
    @yes_no_window.visible = false
    @yes_no_window.active = false
    @yes_no_window.index = 1
    @yes_no_window.x = 270
    @yes_no_window.y = 252
    @yes_no_window.z = 1500
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @craft_window.dispose
    @result_window.dispose
    @ingredients_window.dispose
    @confirm_window.dispose
    @yes_no_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @craft_window.update
    @ingredients_window.update
    if $game_party.recipes.size > 0
      @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
      @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
                                                           @craft_window.recipe.ingredient_types,
                                                           @craft_window.recipe.quantities)
    end
    if @craft_window.active
      update_craft
      return
    end
    if @yes_no_window.active
      confirm_update
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_craft
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(3)
      return
    end
    if Input.trigger?(Input::C) and $game_party.recipes.size != 0
      @recipe = @craft_window.recipe
      if @recipe.have
        @yes_no_window.active = true
        @craft_window.active = false
      else
        $game_system.se_play($data_system.buzzer_se)
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  def confirm_update
    @craft_index = @craft_window.index
    @confirm_window.visible = true
    @confirm_window.z = 1500
    @yes_no_window.visible = true
    @yes_no_window.active = true
    @yes_no_window.z = 1500
    @yes_no_window.update
    string = "合成 " + @recipe.name + "?"
    cw = @confirm_window.contents.text_size(string).width
    center = @confirm_window.contents.width/2 - cw /2
    unless @drawn
      @confirm_window.contents.draw_text(center, 0, cw, 30, string)
      @drawn = true
    end
    if Input.trigger?(Input::C)
      if @yes_no_window.index == 0
        if @recipe.have
          $game_system.se_play($data_system.decision_se)
          @recipe.make
          $game_system.se_play($data_system.save_se)
          $scene=Scene_Craft.new(@craft_index)
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      else
        $game_system.se_play($data_system.cancel_se)
        $scene=Scene_Craft.new(@craft_index)
      end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene=Scene_Craft.new(@craft_index)
    end
  end
end # of Scene_Craft
#==============================================================================
# 本腳本來自www.66RPG.com,使用和轉載請保留此信息
#==============================================================================

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
 
 
©2010-2024 Arslanbar [手機版] [桌面版]
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。