Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # ╔══════════════════════════════════╗
- # ║ ▼ Dark's 2nd Crafting System ║
- # ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
- # ║ ▼ Release Date: March 14th 2016 ║
- # ║ ▼ Forum: TaoTroChoi.com ║
- # ╚══════════════════════════════════╝
- #-------------------------------------------------------------------------------
- # Version 1.0: Release!
- # Version 2.0: Update for script!
- #-------------------------------------------------------------------------------
- # Writen for mr.rpg.700.
- #-------------------------------------------------------------------------------
- # Yêu cầu: Instance Items
- # Dark's Bitmap
- #-------------------------------------------------------------------------------
- # Script call:
- # open_crafting_scene -> Mở scene
- # $game_system.crafting_tier -> Lấy ra Tier hiện tại. (Conditional Branches)
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["DRKS-Crafting2"] = true
- if !$imported["TH_InstanceItems"]
- msgbox_p("TH_InstanceItems not found! Exiting...")
- exit
- end
- if !$imported["DRKS-Bitmap"]
- msgbox_p("DRKS-Bitmap not found! Exiting...")
- exit
- end
- module DarkCrafting2
- Craft_SE = "Item Harvest"
- Recipe = {}
- Recipe[1] = {}
- Recipe[1][:name] = "Sharp Stone"
- Recipe[1][:require_items] = ["i259x2"]
- Recipe[1][:get_item] = ["i262x1"]
- Recipe[2] = {}
- Recipe[2][:name] = "Improvised Axe"
- Recipe[2][:require_items] = ["i259x1","i255x1","w1x1"]
- Recipe[2][:get_item] = ["w4x1"]
- Recipe[3] = {}
- Recipe[3][:name] = "Basic fishing rod"
- Recipe[3][:require_items] = ["i256x1","i255x1","w1x1"]
- Recipe[3][:get_item] = ["w3x1"]
- Recipe[4] = {}
- Recipe[4][:name] = "Spear"
- Recipe[4][:require_items] = ["i262x1","i255x1","w1x1"]
- Recipe[4][:get_item] = ["w5x1"]
- Recipe[5] = {}
- Recipe[5][:name] = "Sharp Stone"
- Recipe[5][:require_items] = ["i3x2"]
- Recipe[5][:get_item] = ["i4x1"]
- Recipe[6] = {}
- Recipe[6][:name] = "Campfire"
- Recipe[6][:require_items] = ["i13x5"]
- Recipe[6][:get_item] = ["i1x1"]
- Recipe[7] = {}
- Recipe[7][:name] = "Test New Update!"
- Recipe[7][:require_items] = ["i12x5"]
- Recipe[7][:get_item] = ["i1x2","a2x2","w3x2"]
- #----------------------------------------------------------------------
- # Get Recive Items
- #----------------------------------------------------------------------
- def self.get_recive_items(id)
- a = Recipe[id][:get_item]
- b = []
- a.each do |obj|
- c = obj.split("x")
- item_id = c[0][/(\d+)/].to_i
- item_num = c[1].to_i
- if c[0].include?("i")
- d = $data_items[item_id] if $data_items
- end
- if c[0].include?("a")
- d = $data_armors[item_id] if $data_armors
- end
- if c[0].include?("w")
- d = $data_weapons[item_id] if $data_weapons
- end
- b.push([d,item_num])
- end
- return b
- end
- #----------------------------------------------------------------------
- # Get Recipe Name
- #----------------------------------------------------------------------
- def self.get_recipe_name(id)
- a = Recipe[id][:name]
- return a
- end
- #----------------------------------------------------------------------
- # Get Item
- #----------------------------------------------------------------------
- def self.get_item(id)
- a = Recipe[id][:get_item]
- b = a.split(":")
- if a.include?("w")
- c = $data_weapons[b[1].to_i]
- end
- if a.include?("i")
- c = $data_items[b[1].to_i]
- end
- if a.include?("a")
- c = $data_armors[b[1].to_i]
- end
- return c
- end
- #----------------------------------------------------------------------
- # Convert Require Item to Array.
- #----------------------------------------------------------------------
- def self.convert_req_item(id)
- a = Recipe[id][:require_items]
- c = []
- a.each do |p|
- b = p.split("x")
- b[1].to_i.times do
- c.push(b[0])
- end
- end
- return c.sort!
- end
- #----------------------------------------------------------------------
- # Convert Selected Item to Array.
- #----------------------------------------------------------------------
- def self.convert_selected(pack)
- a = pack
- b = []
- a.each do |item|
- citem = InstanceManager.get_template(item)
- if citem.is_a?(RPG::Weapon)
- b.push("w#{citem.id}")
- end
- if citem.is_a?(RPG::Item)
- b.push("i#{citem.id}")
- end
- if citem.is_a?(RPG::Armor)
- b.push("a#{citem.id}")
- end
- end
- return b
- end
- #----------------------------------------------------------------------
- # Convert Selected Item to Array.
- #----------------------------------------------------------------------
- def self.convert_selected_item2(item_pack)
- a = item_pack
- b = a.uniq
- c = {}
- d = []
- b.each do |item|
- c[item] ||= 0
- end
- a.each do |item|
- c[item] += 1
- end
- c.each_pair do |key,value|
- d.push([key,value])
- end
- return d
- end
- end
- class Scene_DarkCrafting2 < Scene_ItemBase
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_window_layout
- create_help_window
- $selected_pack = []
- @check = false
- @recive = nil
- create_item_window
- create_sprites
- end
- #--------------------------------------------------------------------------
- # * Create Help Window
- #--------------------------------------------------------------------------
- def create_help_window
- @help_window = Window_CraftingHelp.new(5,55,252,125)
- @help_window.viewport = @viewport
- end
- #--------------------------------------------------------------------------
- # * Check Sprites
- #--------------------------------------------------------------------------
- def create_sprites
- @sprites[:found_item] = Sprite.new
- @sprites[:found_item].bitmap = DarkBitmap.new(544,416)
- @sprites[:found_item].viewport = @viewport
- @sprites[:found_item].z = 100
- @sprites[:craft_key] = Sprite.new
- @sprites[:craft_key].bitmap = Cache.system("craft_key")
- @sprites[:craft_key].viewport = @viewport
- @sprites[:craft_key].z = 120
- @sprites[:craft_key].x = 544 - @sprites[:craft_key].bitmap.width
- @sprites[:craft_key].bitmap.font.size = 24
- @sprites[:craft_key].bitmap.font.bold = false
- @sprites[:craft_key].bitmap.font.outline = false
- @sprites[:craft_key].bitmap.font.color = Color.new(255,255,255)
- @sprites[:craft_key].bitmap.draw_text(30,0,130,32," to craft this!")
- @sprites[:craft_key].visible = false
- @sprites[:des_plus] = Sprite.new
- @sprites[:des_plus].bitmap = DarkBitmap.new(544,416)
- @sprites[:des_plus].viewport = @viewport
- @sprites[:des_plus].z = 100
- @sprites[:tier] = Sprite.new
- @sprites[:tier].bitmap = DarkBitmap.new(544,416)
- @sprites[:tier].viewport = @viewport
- @sprites[:tier].z = 100
- @sprites[:tier].bitmap.font.size = 24
- @sprites[:tier].bitmap.font.bold = true
- @sprites[:tier].bitmap.font.outline = false
- @sprites[:tier].bitmap.font.color = Color.new(0,0,0)
- @sprites[:tier].bitmap.draw_text(272,65,130,32,"Crafting Tier")
- @sprites[:tier].bitmap.font.size = 40
- @sprites[:tier].bitmap.font.color = Color.new(255,111,0)
- @sprites[:tier].bitmap.draw_text(311,115,130,32,$game_system.crafting_tier)
- end
- #--------------------------------------------------------------------------
- # * Create Window Layout
- #--------------------------------------------------------------------------
- def create_window_layout
- @sprites = {}
- @sprites[:layout] = Sprite.new
- @sprites[:layout].bitmap = Cache.system("Craft_Layout")
- @sprites[:layout].viewport = @viewport
- @sprites[:layout].z = 0
- end
- #--------------------------------------------------------------------------
- # * Create Item Window
- #--------------------------------------------------------------------------
- def create_item_window
- wy = 243
- wh = 170
- @item_window = Window_CraftingList.new(0, wy, Graphics.width, wh)
- @item_window.viewport = @viewport
- @item_window.opacity = 0
- @item_window.back_opacity = 0
- @item_window.refresh
- @item_window.select(0)
- @item_window.activate
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- end
- #--------------------------------------------------------------------------
- # * Category [OK]
- #--------------------------------------------------------------------------
- def on_category_ok
- @item_window.activate
- @item_window.select_last
- end
- #--------------------------------------------------------------------------
- # * Item [OK]
- #--------------------------------------------------------------------------
- def on_item_ok
- $game_party.last_item.object = item
- if !$selected_pack.include?(item)
- $selected_pack.push(item)
- else
- $selected_pack.delete(item)
- end
- check_for_recipe
- @item_window.activate
- @item_window.refresh
- end
- #--------------------------------------------------------------------------
- # * Item [Cancel]
- #--------------------------------------------------------------------------
- def on_item_cancel
- return_scene
- end
- #--------------------------------------------------------------------------
- # * Check for Recipe
- #--------------------------------------------------------------------------
- def check_for_recipe
- converted = DarkCrafting2.convert_selected($selected_pack)
- DarkCrafting2::Recipe.each_key do |key|
- if converted.sort == DarkCrafting2.convert_req_item(key).sort
- @sprites[:found_item].bitmap.clear
- @recive_name = DarkCrafting2.get_recipe_name(key)
- @recive = DarkCrafting2.get_recive_items(key)
- @check = true
- break
- else
- @check = false
- @recive = nil
- @recive_name = ""
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Craft Found
- #--------------------------------------------------------------------------
- def update_craft
- if Input.trigger?(:R)
- $selected_pack.each do |item|
- $game_party.lose_item(item,1)
- end
- @recive.each do |item|
- $game_party.gain_item(item[0],item[1])
- end
- @recive = nil
- @check = false
- @sprites[:craft_key].visible = false
- @item_window.refresh
- $selected_pack = []
- @sprites[:found_item].bitmap.clear
- begin
- se = RPG::SE.new(DarkCrafting2::Craft_SE)
- se.play
- rescue
- se = RPG::SE.new("Decision2")#Không tìm thấy file sẽ chạy file SE này!
- se.play
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Description +
- #--------------------------------------------------------------------------
- def update_des_plus
- if @check == true
- @sprites[:found_item].bitmap.clear
- @sprites[:craft_key].visible = true
- @sprites[:craft_key].y = 416 - @sprites[:craft_key].bitmap.height - 15
- @sprites[:found_item].bitmap.draw_text(276,199,300,32,"Craft: " + @recive_name)
- else
- @sprites[:craft_key].visible = false
- @sprites[:found_item].bitmap.clear
- end
- if item
- x = 392
- y = 52
- @sprites[:des_plus].bitmap.clear
- @sprites[:des_plus].bitmap.font.size = 18
- @sprites[:des_plus].bitmap.font.bold = false
- @sprites[:des_plus].bitmap.font.outline = false
- @sprites[:des_plus].bitmap.font.color = Color.new(0,0,0)
- @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"Price: #{item.price}G")
- if !item.is_a?(RPG::Item)
- y += 15
- @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"Performance: #{item.performance}")
- y += 15
- for i in 2..7 do
- @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"#{$data_system.terms.params[i]}: #{item.params[i]}")
- y += 15
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- update_des_plus
- update_craft if @check == true
- @item_window.update_help
- end
- #--------------------------------------------------------------------------
- # * Play SE When Using Item
- #--------------------------------------------------------------------------
- def play_se_for_item
- Sound.play_use_item
- end
- def terminate
- super
- @sprites.values.each do |sprite|
- sprite.bitmap.dispose
- sprite.dispose
- end
- end
- #--------------------------------------------------------------------------
- # * Use Item
- #--------------------------------------------------------------------------
- def use_item
- super
- @item_window.redraw_current_item
- end
- end
- class Window_CraftingList < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super
- self.windowskin = Cache.system("Window_Crafting")
- @data = []
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- return true
- end
- #--------------------------------------------------------------------------
- # * Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- true
- end
- #--------------------------------------------------------------------------
- # * Create Item List
- #--------------------------------------------------------------------------
- def make_item_list
- @data = $game_party.all_items.select {|item| include?(item) }
- @data.push(nil) if include?(nil)
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select(@data.index($game_party.last_item.object) || 0)
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- if item
- color_1 = Color.new(255,162,0)
- color_2 = Color.new(255,255,255,0)
- rect = item_rect(index)
- rect.width -= 4
- if $selected_pack.include?(item)
- contents.gradient_fill_rect(rect.x,rect.y+2,rect.width,rect.height-4,color_1,color_2)
- end
- draw_item_name(item, rect.x, rect.y, enable?(item))
- end
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- end
- class Window_CraftingHelp < Window_Base
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(x,y,width,height)
- super(x,y,width,height)
- @current_item = nil
- self.opacity = 0
- self.back_opacity = 0
- end
- #--------------------------------------------------------------------------
- # * Create Window Contents
- #--------------------------------------------------------------------------
- def create_contents
- contents.dispose
- if contents_width > 0 && contents_height > 0
- self.contents = DarkBitmap.new(contents_width, contents_height)
- else
- self.contents = DarkBitmap.new(1, 1)
- end
- end
- #--------------------------------------------------------------------------
- # * Set Item
- #--------------------------------------------------------------------------
- def set_item(item)
- @current_item = item if item
- refresh
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- if @current_item
- contents.font.size = 25
- contents.font.bold = true
- contents.font.outline = false
- contents.font.color = Color.new(0,0,0)
- draw_text(0,0,200,32,@current_item.name)
- draw_text(0,0,200,32,@current_item.name)
- contents.font.size = 17
- contents.font.bold = false
- contents.font.color = Color.new(0,0,0,200)
- contents.draw_text_ex(0,32,@current_item.description,false)
- else
- contents.font.size = 25
- contents.font.bold = true
- contents.font.outline = false
- contents.font.color = Color.new(0,0,0)
- draw_text(0,0,200,32,"None")
- end
- @current_item = nil
- end
- end
- class Game_System
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :crafting_tier
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias darkcrafting2gamesysteminit initialize
- def initialize
- darkcrafting2gamesysteminit
- @crafting_tier = "C"
- end
- end
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Set Crafting Tier
- #--------------------------------------------------------------------------
- def set_crafting_tier(tier)
- $game_system.crafting_tier = tier.to_s if tier
- end
- #--------------------------------------------------------------------------
- # * Open Crafting Scene
- #--------------------------------------------------------------------------
- def open_crafting_scene
- SceneManager.call(Scene_DarkCrafting2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment