Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Don't remove this header!
- #-------------------------------------------------------------------------------
- # Potion Brewing System Script
- # by Black Mage (https://burningwizard.wordpress.com/)
- #
- # Version : 1.4
- #
- # This script is commisioned by Batworks Software.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Version History
- #-------------------------------------------------------------------------------
- # 1.4 - Added quickbrew menu (Trihan)
- #
- # 1.3 - Add compatibility fix for Theo Animated Battleback script.
- #
- # 1.0 - Initial design.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # All picture are located on Graphics/Menus folder.
- #
- # To call the Potion Brewing menu, simply put these on the script call:
- #
- # SceneManager.call(Scene_Brewing)
- #
- # Put <base> on an item note to tag it as base ingredients for brewing.
- #
- # Put <second> on an item note to tag it as second ingredients for brewing.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Settings.
- #-------------------------------------------------------------------------------
- module BLACK
- module BREW
- # Image for the scene background.
- Background = "potionbg"
- # Image for the cursor.
- Cursor_Name = "fingerpointer"
- # Position for help text.
- Help_Text_Pos = [0,3]
- # Help text that will be displayed.
- Help_Text = ["Select your ingredients!", # This is shown if base
- # ingredients is empty.
- "Select your ingredients!", # This is shown if second
- # ingredients is empty.
- "Time to brew!", # This is shown if both
- # ingredients already chosen.
- "Brew things you've made before!"
- ]
- # Font name array. You can have multiple font inside the array, and the
- # menu will use the first one that the game found.
- Ing_Font_Name = ["myfont Regular"]
- # Font size.
- Ing_Font_Size = 24
- # The position of base ingredients choices window.
- Main_Pos = [0, 165]
- # The transparent window size where the base ingredients choices are written.
- Main_Size = [250,250]
- # Icon position of selected base ingredient.
- Item_1_Icn = [30,110]
- # Cursor position of base ingredient square.
- Item_1_Pos = [75,160]
- # Starting cursor position of cursor inside base ingredients window.
- Item_1_Ingr = [180,20]
- # Background for base ingredients window.
- Item_1_Back = "backbrew1"
- # Background position for base ingredients window, relative to window
- # position.
- Item_1_BG_Off = [0,0]
- # The position of second ingredients choices window.
- Sec_Pos = [200, 165]
- # The transparent window size where the second ingredients choices are
- # written.
- Sec_Size = [250,250]
- # Icon position of selected second ingredient.
- Item_2_Icn = [170,110]
- # Cursor position of second ingredient square.
- Item_2_Pos = [220,160]
- # Starting cursor position of cursor inside second ingredients window.
- Item_2_Ingr = [180,20]
- # Background for second ingredients window.
- Item_2_Back = "backbrew2"
- # Background position for second ingredients window, relative to window
- # position.
- Item_2_BG_Off = [0,0]
- # Cursor position of brew button.
- Brew_But_Pos = [200,270]
- # Cursor position of back square.
- Back_Pos = [70,360]
- # Cursor position of recipe book.
- Recipe_Pos = [240,360]
- # base ingredients, second ingredients, result
- Recipe = [[41,43,174], #Holy Base
- [45,117,175], #Salted Root
- [66,114,124], #Death Potion
- [66,115,243], #Necro Potion
- [66,116,244], #Soul Potion
- [66,117,245], #Mind Potion
- [66,118,246], #Body Potion
- [66,119,47], #Fealixer
- [66,120,247], #Spirit Potion
- [66,121,248], #HEART POTION
- [66,122,126], #Purge Potion
- [66,123,127], #Death's Brew
- [66,171,172], #Shrinking Potion
- [67,114,128], #Death Elixir
- [67,115,129], #Endurance Elixir
- [67,116,130], #Bravery Elixir
- [67,117,131], #Agility Elixir
- [67,118,132], #Terror Elixir
- [67,119,133], #Fealixer X Elixir
- [67,120,125], #Stability Elixir
- [67,121,134], #Strength Elixir
- [67,122,135], #Luck Elixir
- [67,123,127], #Death's Brew
- [67,171,172], #Shrinking Potion
- [68,114,137], #Life Elixir
- [68,115,138], #Fragile Elixir
- [68,116,139], #Insecure Elixir
- [68,117,140], #Slow Elixir
- [68,118,141], #Meek Elixir
- [68,119,146], #Fealixer+
- [68,120,249], #Instability Elixir
- [68,121,142], #Weak Elixir
- [68,122,144], #Unlucky Elixir
- [68,123,127], #Death's Brew
- [68,171,172], #Shrinking Potion
- [69,114,144], #Death Potion+
- [69,115,250], #Purple Death Potion
- [69,116,251], #Green Death Potion
- [69,117,252], #Orange Death Potion
- [69,118,253], #Yellow Death Potion
- [69,119,254], #Pink Death Potion
- [69,120,255], #Spirit Potion+
- [69,121,256], #Red Death Potion
- [69,122,147], #Immortality
- [69,123,127], #Death's Brew
- [69,171,172], #Shrinking Potion
- [70,114,257], #Flesh Potion
- [70,115,258], #Bone Potion
- [70,116,259], #Ecto Potion
- [70,117,260], #Nature Potion
- [70,118,261], #Lightning Potion
- [70,119,262], #Sugar Potion
- [70,120,263], #Basic Potion
- [70,121,264], #Blood Potion
- [70,122,265], #ritical Potion
- [70,123,127], #Death's Brew
- [70,171,172], #Shrinking Potion
- [155,43,156], #Banishing Potion
- [174,175,44], #Spectralodium D
- ]
- # The ID of item that you got when you use wrong ingredients.
- Failed_Item = 136
- # This text will be showed after you complete brewing. The format will be
- #
- # left_text item_name right_text
- #
- # Ex. Suppose Text = ["You create ", "!"], then this will be showed:
- # You create item_name!
- Text = ["You brewed ", "!"]
- # Position for text that showed after completing the brew.
- Cre_Pos = [100,300]
- # Background name for text that showed after completing the brew.
- Create_BG = "brewcreated"
- # Position for background for the text that showed after completing the brew.
- Cre_BG_Pos = [0,0]
- # For the item icons that showed up inside the menu, we use another file
- # with the same format as the regular icon picture, but different in size.
- # The file must be placed on Graphics/System folder.
- Icon_Name = "IconSet2"
- # Icon width and height.
- Icon_W_H = 48
- # For the item icons that showed up inside the ingredients selection menu,
- # we use another file with the same format as the regular icon picture, but
- # different in size. The file must be placed on Graphics/System folder.
- Icon2_Name = "IconSet3"
- # Icon width and height.
- Icon2_W_H = 24
- #-------------------------------------------------------------------------------
- # There's animation that shown upon creating a new items. Below are their
- # settings
- # X and Y position of the animation.
- Anim_X_Y = [0,0]
- # ID of animation that will be played upon creating item.
- Anim_ID = 166
- #-------------------------------------------------------------------------------
- end
- end
- #-------------------------------------------------------------------------------
- # * Beyond this is the sacred land of code. You need programming qualification
- # to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
- # own risk.
- #-------------------------------------------------------------------------------
- # We define where we put the resources.
- module Cache; def self.menus(filename); load_bitmap("Graphics/Menus/", filename); end; end
- # We make custom variable for tab.
- class Game_System
- attr_accessor :brew_ing
- attr_accessor :item_created
- attr_accessor :recipe_book
- attr_accessor :quickbrewing
- alias b_brew_init initialize
- def initialize; b_brew_init; @brew_ing = [nil,nil]; @recipe_book = []; @quickbrewing = false; end
- end
- #-------------------------------------------------------------------------------
- # The brewing screen.
- #-------------------------------------------------------------------------------
- class Scene_Brewing < Scene_MenuBase
- include BLACK::BREW
- def start
- super; create_command_window; create_item_window; create_quickbrew_window; create_pics
- @create_window = Window_Create_Pot.new
- $game_system.brew_ing = [nil,nil]
- @recipe = []
- Recipe.each do |r|
- @recipe[r[0]] = [] if !@recipe[r[0]]; @recipe[r[0]][r[1]] = r[2]
- end
- @spriteset = Spriteset_Brew.new
- end
- def create_background
- @background_sprite = Sprite.new
- @background_sprite.bitmap = Cache.menus(Background)
- end
- def create_pics
- @cursor = Sprite.new; @cursor.bitmap = Cache.menus(Cursor_Name)
- @cursor.z = 200; update_cursor
- @bg3 = Sprite.new; @bg3.bitmap = Cache.menus(Create_BG); @bg3.opacity = 0
- @bg3.x = Cre_Pos[0] + Cre_BG_Pos[0]
- @bg3.y = Cre_Pos[1] + Cre_BG_Pos[1]
- end
- def update
- super; update_cursor
- if @s_pause
- @p_frame -= 1
- if @p_frame <= 0
- @s_pause = false
- @command_window.deactivate
- @item_window.refresh; @item_window_2.refresh
- @create_window.show; @bg3.opacity = 255
- end
- end
- @spriteset.update
- end
- def update_cursor
- return if @cursor.nil? || @command_window.nil?
- if @command_window.active
- case @command_window.index
- when 0; a = Item_1_Pos
- when 1; a = Item_2_Pos
- when 2; a = Brew_But_Pos
- when 3; a = Back_Pos
- when 4; a = Recipe_Pos
- end
- elsif @item_window.active; a = @item_window.i_pos
- elsif @item_window_2.active; a = @item_window_2.i_pos
- end
- return if a.nil?
- @cursor.x = a[0]; @cursor.y = a[1]
- end
- # We add more things to dispose instead of just background.
- def dispose_background
- @background_sprite.dispose
- @cursor.dispose; @cursor = nil
- @bg3.dispose; @bg3 = nil
- @spriteset.dispose
- end
- # Create brew choices.
- def create_command_window
- @command_window = Window_Brew.new
- @command_window.set_handler(:cancel, method(:return_scene))
- @command_window.set_handler(:ok, method(:on_slot_ok))
- end
- def on_slot_ok
- if @command_window.index == 0
- @item_window.show; @item_window.activate; @item_window.select(0)
- elsif @command_window.index == 1
- @item_window_2.show; @item_window_2.activate; @item_window_2.select(0)
- elsif @command_window.index == 4
- @cursor.opacity = 0; $game_system.quickbrewing = true; @quickbrew_window.show; @quickbrew_window.activate; @quickbrew_window.select(0)
- else
- a = $game_system.brew_ing
- if a[0] != nil && a[1] != nil
- $game_party.lose_item($data_items[a[0].id], 1)
- $game_party.lose_item($data_items[a[1].id], 1)
- result = @recipe[a[0].id][a[1].id]
- b = result.nil? ? Failed_Item : result
- $game_system.recipe_book = [] if $game_system.recipe_book.nil?
- $game_system.recipe_book.push([result, a[0].id, a[1].id]) if !result.nil?
- $game_system.recipe_book.uniq!
- $game_system.item_created = $data_items[b]
- $game_party.gain_item($data_items[b], 1)
- $game_system.brew_ing = [nil,nil]
- @spriteset.enemy[0].battler.animation_id = Anim_ID
- @s_pause = true; @p_frame = $data_animations[Anim_ID].frames.size
- else
- @command_window.activate
- end
- end
- end
- def activate_c_w
- Sound.play_ok; @command_window.activate; @bg3.opacity = 0
- end
- def create_item_window
- wx = Main_Pos[0]; wy = Main_Pos[1]; ww = Main_Size[0]; wh = Main_Size[1]
- @item_window = Window_Ingredients.new(wx, wy, ww, wh)
- @item_window.viewport = @viewport
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- wx = Sec_Pos[0]; wy = Sec_Pos[1]; ww = Sec_Size[0]; wh = Sec_Size[1]
- @item_window_2 = Window_Ingredients_2.new(wx, wy, ww, wh)
- @item_window_2.viewport = @viewport
- @item_window_2.set_handler(:ok, method(:on_item_ok))
- @item_window_2.set_handler(:cancel, method(:on_item_cancel))
- @item_window.hide; @item_window_2.hide
- @item_window_3 = Window_Ingredients_3.new
- @inst_window = Window_Instruction.new
- end
- def create_quickbrew_window
- @quickbrew_window = Window_RecipeBook.new(0, 43, Graphics.width, Graphics.height - 43)
- @quickbrew_window.set_handler(:ok, method(:on_quickbrew_ok))
- @quickbrew_window.set_handler(:cancel, method(:on_quickbrew_cancel))
- @quickbrew_window.hide
- end
- def on_item_ok
- @command_window.activate; @command_window.refresh
- if @command_window.index == 0
- $game_system.brew_ing[0] = @item_window.item
- @item_window.unselect; @item_window.refresh; @item_window.hide
- else
- $game_system.brew_ing[1] = @item_window_2.item
- @item_window_2.unselect; @item_window_2.refresh; @item_window_2.hide
- end
- end
- def on_item_cancel
- @command_window.activate
- @item_window.unselect; @item_window_2.unselect
- @item_window.hide; @item_window_2.hide
- end
- def on_quickbrew_ok
- @command_window.activate; @command_window.refresh; $game_system.quickbrewing = false
- potion = @quickbrew_window.item[0]
- ing1 = @quickbrew_window.item[1]
- ing2 = @quickbrew_window.item[2]
- $game_party.lose_item($data_items[ing1], 1)
- $game_party.lose_item($data_items[ing2], 1)
- result = @recipe[ing1][ing2]
- b = result.nil? ? Failed_Item : result
- $game_system.item_created = $data_items[b]
- $game_party.gain_item($data_items[b], 1)
- $game_system.brew_ing = [nil,nil]
- @quickbrew_window.unselect
- @quickbrew_window.hide
- @spriteset.enemy[0].battler.animation_id = Anim_ID
- @s_pause = true; @p_frame = $data_animations[Anim_ID].frames.size
- @cursor.opacity = 255
- end
- def on_quickbrew_cancel
- @command_window.activate
- @quickbrew_window.unselect
- @quickbrew_window.hide
- $game_system.quickbrewing = false
- @cursor.opacity = 255
- end
- end
- # The hidden choices of brewing.
- class Window_Brew < Window_Command
- def initialize
- super(0,0); self.openness = 0; open; self.opacity = 0; self.hide
- end
- def make_command_list
- add_command("ing 1", :ok)
- add_command("ing 2", :ok)
- add_command("brew", :ok)
- add_command("back", :cancel)
- add_command("recipe", :recipebook)
- end
- def cursor_right(wrap = false)
- if index < item_max - col_max || (wrap && col_max == 1)
- select((index + col_max) % item_max)
- end
- end
- def cursor_left(wrap = false)
- if index >= col_max || (wrap && col_max == 1)
- select((index - col_max + item_max) % item_max)
- end
- end
- def item_window=(item_window); @item_window = item_window; update; end
- def current_item_enabled?
- a = $game_system.brew_ing
- return true if @index != 2
- return (a[0] != nil && a[1] != nil) ? true : false
- end
- end
- class Window_Ingredients < Window_ItemList
- include BLACK::BREW
- def initialize(x, y, width, height); super; @letter_timer = 0; @letter_skip = 0; refresh; end
- def col_max; return 1; end
- def item_height; Ing_Font_Size; end
- def enable?(item); return true; end
- def select_last; end
- def include?(item)
- return true if item == nil; return item.note =~ /<base>/ ? true : false
- end
- def i_pos
- x = self.x + (@index % col_max * (item_width + spacing)) + Item_1_Ingr[0] - self.ox
- y = self.y + (@index / col_max * item_height) + Item_1_Ingr[1] - self.oy
- [x, y]
- end
- def draw_item_name(item, x, y, enabled = true, width = 172)
- return unless item
- draw_icon(item.icon_index, x, y, enabled)
- change_color(normal_color, enabled)
- contents.font.name = Ing_Font_Name; contents.font.size = Ing_Font_Size
- if @data.index(item) == self.index && text_size(item.name).width > 174
- @letter_skip = 0 if text_size(item.name.slice(@letter_skip, item.name.size)).width < 158
- text = item.name.slice(@letter_skip, item.name.size)
- else
- text = item.name.clone
- end
- if text_size(text).width > 174
- while text_size("#{text}...").width > 174
- text.slice!(-1)
- end
- if @data.index(item) != self.index
- text.concat("...")
- end
- end
- draw_text(x + Icon2_W_H, y, width, item_height, text)
- end
- def draw_icon(icon_index, x, y, enabled = true)
- a = Icon2_W_H; bitmap = Cache.system(Icon2_Name)
- rect = Rect.new(icon_index % 16 * a, icon_index / 16 * a, a, a)
- contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- end
- end
- class Window_Ingredients_2 < Window_ItemList
- include BLACK::BREW
- def initialize(x, y, width, height); super; @letter_timer = 0; @letter_skip = 0; refresh; end
- def col_max; return 1; end
- def item_height; Ing_Font_Size; end
- def enable?(item); return true; end
- def select_last; end
- def include?(item)
- return true if item == nil; return item.note =~ /<second>/ ? true : false
- end
- def i_pos
- x = self.x + (@index % col_max * (item_width + spacing)) + Item_2_Ingr[0] - self.ox
- y = self.y + (@index / col_max * item_height) + Item_2_Ingr[1] - self.oy
- [x, y]
- end
- def draw_item_name(item, x, y, enabled = true, width = 172)
- return unless item
- draw_icon(item.icon_index, x, y, enabled)
- change_color(normal_color, enabled)
- contents.font.name = Ing_Font_Name; contents.font.size = Ing_Font_Size
- if @data.index(item) == self.index && text_size(item.name).width > 174
- @letter_skip = 0 if text_size(item.name.slice(@letter_skip, item.name.size)).width < 158
- text = item.name.slice(@letter_skip, item.name.size)
- else
- text = item.name.clone
- end
- if text_size(text).width > 174
- while text_size("#{text}...").width > 174
- text.slice!(-1)
- end
- if @data.index(item) != self.index
- text.concat("...")
- end
- end
- draw_text(x + Icon2_W_H, y, width, item_height, text)
- end
- def draw_icon(icon_index, x, y, enabled = true)
- a = Icon2_W_H; bitmap = Cache.system(Icon2_Name)
- rect = Rect.new(icon_index % 16 * a, icon_index / 16 * a, a, a)
- contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- end
- end
- class Window_Create_Pot < Window_Base
- include BLACK::BREW
- def initialize
- a = 440; super(Cre_Pos[0],Cre_Pos[1],a,fitting_height(1))
- self.opacity = 0; self.hide
- end
- def update
- super;
- if Input.trigger?(:C) && self.visible
- self.hide; SceneManager.scene.activate_c_w
- end
- self.refresh
- end
- def refresh
- contents.clear
- return if $game_system.item_created.nil?
- item = $game_system.item_created
- contents.font.name = Ing_Font_Name; contents.font.size = Ing_Font_Size
- text = "\\c[0]#{Text[0]}\\i[#{item.icon_index}]\\c[22]#{item.name}\\c[0]#{Text[1]}"
- draw_text_ex(6, 0, text)
- end
- def draw_icon(icon_index, x, y, enabled = true)
- a = Icon2_W_H; bitmap = Cache.system(Icon2_Name)
- rect = Rect.new(icon_index % 16 * a, icon_index / 16 * a, a, a)
- contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- end
- end
- class Window_Ingredients_3 < Window_Base
- include BLACK::BREW
- def initialize
- super(0,0,Graphics.width,Graphics.height); self.opacity = 0
- end
- def update; super; self.refresh; end
- def refresh
- contents.clear
- item = $game_system.brew_ing
- draw_icon(item[0].icon_index, Item_1_Icn[0], Item_1_Icn[1]) if !item[0].nil?
- draw_icon(item[1].icon_index, Item_2_Icn[0], Item_2_Icn[1]) if !item[1].nil?
- end
- def draw_icon(icon_index, x, y, enabled = true)
- a = Icon_W_H; bitmap = Cache.system(Icon_Name)
- rect = Rect.new(icon_index % 16 * a, icon_index / 16 * a, a, a)
- contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- end
- end
- class Window_RecipeBook < Window_Selectable
- include BLACK::BREW
- def initialize(x, y, width, height)
- super
- @recipe = []
- Recipe.each do |r|
- @recipe[r[0]] = [] if !@recipe[r[0]]; @recipe[r[0]][r[1]] = r[2]
- end
- @data = []
- self.back_opacity = 230
- end
- def col_max
- return 1
- end
- def item_max
- @data ? @data.size : 1
- end
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- def current_item_enabled?
- enable?(@data[index])
- end
- def include?(item)
- true
- end
- def enable?(item)
- return false if item.nil?
- ing1 = $data_items[item[1]]
- ing2 = $data_items[item[2]]
- $game_party.has_item?(ing1) && $game_party.has_item?(ing2)
- end
- def make_item_list
- $game_system.recipe_book = [] if $game_system.recipe_book.nil?
- @data = $game_system.recipe_book
- end
- def draw_item(index)
- item = $data_items[@data[index][0]]
- if item
- ing1 = $data_items[@data[index][1]]
- ing2 = $data_items[@data[index][2]]
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, enable?(@data[index]))
- draw_icon(ing1.icon_index, rect.x + Graphics.width - 72, rect.y, $game_party.has_item?(ing1))
- draw_icon(ing2.icon_index, rect.x + Graphics.width - 48, rect.y, $game_party.has_item?(ing2))
- end
- end
- def draw_item_number(rect, item)
- draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
- end
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- def update; super; self.refresh; end
- end
- class Window_Instruction < Window_Base
- include BLACK::BREW
- def initialize
- super(Help_Text_Pos[0],Help_Text_Pos[1],Graphics.width,Graphics.height)
- self.opacity = 0
- end
- def update; super; self.refresh; end
- def refresh
- contents.clear
- a = $game_system.brew_ing
- if $game_system.quickbrewing; b = Help_Text[3]
- elsif a[0].nil?; b = Help_Text[0]
- elsif a[1].nil?; b = Help_Text[1]
- else b = Help_Text[2]
- end
- contents.font.name = Ing_Font_Name; contents.font.size = Ing_Font_Size
- draw_text(6,0,640,Ing_Font_Size,b)
- end
- end
- class Spriteset_Brew < Spriteset_Battle
- include BLACK::BREW
- def initialize; create_viewports; create_enemies; update; end
- def create_enemies
- a = Sprite_Brew.new(@viewport1, Game_Enemy.new(1,1))
- a.battler.screen_x = Anim_X_Y[0]; a.battler.screen_y = Anim_X_Y[1]
- @enemy_sprites = [a]
- end
- def enemy; @enemy_sprites; end
- def dispose; dispose_enemies; dispose_viewports; end
- def dispose_enemies; @enemy_sprites.each {|sprite| sprite.dispose }; end
- def update; update_enemies; update_viewports; end
- def update_enemies; @enemy_sprites.each {|sprite| sprite.update }; end
- def battler_sprites; @enemy_sprites; end
- end
- class Sprite_Brew < Sprite_Battler
- alias brew_u_e update_effect
- def update_effect; brew_u_e; self.bitmap.clear; end
- end
- # Fix for Theo Animated Battleback incompatibility.
- class Spriteset_Brew < Spriteset_Battle
- def create_animbb; @animbb = Sprite.new; end
- def dispose; dispose_enemies; dispose_viewports; @animbb.dispose; end
- end
Advertisement
Add Comment
Please, Sign In to add comment