Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # Synth Shop
- # By: Ixfuru
- ################################################################################
- # This script was based off the existing script SynthesisShopVX by Zylos. As
- # requested by Revival, who wanted to improve how the script handles synthesis.
- # For instance, the ability to require more than one of the specific item. And
- # also the ability to use more than two items for synthesis. This script adds
- # those features and changes a few other things. The script was written holding
- # as true to the basic layout of the Synthesis scene from Zylos' script as
- # possible. Anyone who uses this script MUST credit Zylos above all else, for his
- # script set the foundation and inspiration for this one.
- #
- # Basically, the script enables the player to a new shop scene by turning ON an
- # in game switch (which you provide the ID of) prior to calling the scene. Inside
- # the scene, the player can create weapons/armor/and now items if they have
- # the required items in their possession and by paying a synthesis fee. All these
- # things can be set up in the database via notebox tags:
- #
- # <synth item_type, item_id, item_amount>
- #
- # For each item involved (required) to make the item in question, you have to
- # have ONE of these note tags. This enables you to use several different
- # items to create a new i/w/a. Use the following in order to understand the
- # note tags better:
- #
- # item_type : 0 for item, 1 for weapon, 2 for armor; of the material
- # item_id : the database ID of the required material
- # item_amount : the required amount of the material item
- #
- # Here are a few examples of the note tags in action:
- #
- # EXAMPLE ONE:
- #
- # <synth 0, 12, 2>
- #
- # EXAMPLE TWO:
- # <synth 0, 6, 3>
- # <synth 0, 25, 2>
- #
- # EXAMPLE THREE:
- # <synth 0, 14, 2>
- # <synth 1, 8, 1>
- # <synth 2, 15, 1>
- #
- # In EXAMPLE ONE, you would require 2 database ITEMS with the ID of 12.
- #
- # In EXAMPLE TWO, you would require 3 database ITEMS with the ID of 6 and
- # 2 database ITEMS with the ID of 25.
- #
- # In EXAMPLE THREE, you would require 2 database ITEMS with the ID of 14,
- # 1 database WEAPON with the ID of 8 and
- # 1 database ARMOR with the ID of 15.
- #
- # There is no limit to the amount of synth items required. I made the required
- # window selectable so that the player could scroll through them if there is
- # more than would fit on the window's bitmap.
- #
- # If you want there to be a charge for synthesis, you need to also add the following
- # tag:
- #
- # <synth_cost gold_amount>
- #
- # gold_amount : the amount of gold to charge the player for synthesis. If
- # no amount is given, then the price will be the value you
- # set in the DEFAULT_SYNTH_PRICE below in the settings module.
- #
- ################################################################################
- module Ixfuru
- module SynthShop
- SYNTH_SHOP_SWITCH = 1 # Set this to the game switch ID of the switch which
- # calls the SynthShop.
- DEFAULT_SYNTH_PRICE = 50 # If no price is set for a synthesis item in the
- # item's notebox, this value is rendered as the price
- SYNTH_SOUND = ["Saint5", 80, 100] # SE played when a new item is created
- # [se_filename, volume, pitch]
- # Below is the strings you wish to use for the scene's, upper-right hand
- # corner status window. The first one is used to describe how much
- # gold the party has. The second one tells how many of the selected item
- # the party has in stock, and the third one tells how many of the selected
- # item the party has equipped.
- SYNTH_STATUS_STRINGS = ["Funds", "Stock", "Equipped"]
- # The next value sets what string you want to accompany the item's icon
- # and name when a new item is created.
- SYNTH_SUCCESS_STRING = " was created!" # make sure you leave a space at the
- # beginning.
- # The following setting is used to map input buttons to control of the scene.
- # The buttons you decide upon, will cause control to jump back and forth
- # from the items in the SynthShop window, to the required items in the
- # Required window. This is necessary because you can place more synth items
- # in the required window for a given item than there is room to hold them.
- # For instance, if you have an item that requires five different synth
- # materials, you will probably only see three listed. This ensures that you
- # can press a button and take control of the required window in order to
- # scroll it down and see the additional required items.
- #
- # You can either place 0 for using "Q" and "W"
- # or place 1 for using the LEFT/RIGHT arrow keys.
- SYNTH_WINDOW_CONTROL_KEYS = 0
- end
- end
- ################################################################################
- # DONT EDIT PAST THIS POINT!
- ################################################################################
- module Ixfuru
- module Regexp
- SYNTH = /<synth[\s]*(\d+),[\s]*(\d+),[\s]*(\d+)>/i
- SYNTH_COST = /<synth_cost[\s]*(\d+)>/i
- end
- end
- ################################################################################
- #*******************************************************************************
- # RPG::BaseItem
- ################################################################################
- class RPG::BaseItem
- #-----------------------------------------------------------------------------
- # Synth
- #-----------------------------------------------------------------------------
- def synth
- s = []
- self.note.split(/[\r\n]/).each { |line|
- case line
- when Ixfuru::Regexp::SYNTH
- t = $1.to_i
- i = $2.to_i
- a = $3.to_i
- s.push([t, i, a])
- end
- }
- return s
- end
- #-----------------------------------------------------------------------------
- # Synth Cost
- #-----------------------------------------------------------------------------
- def synth_cost
- return 0 if synth.empty?
- c = Ixfuru::SynthShop::DEFAULT_SYNTH_PRICE
- self.note.split(/[\r\n]/).each { |line|
- case line
- when Ixfuru::Regexp::SYNTH_COST
- c = $1.to_i
- end
- }
- return c
- end
- end
- ################################################################################
- #*******************************************************************************
- # Scene Map
- ################################################################################
- class Scene_Map < Scene_Base
- #-----------------------------------------------------------------------------
- # Call Shop (Aliased)
- #-----------------------------------------------------------------------------
- alias ixsynth_callshop call_shop unless $@
- def call_shop
- $game_temp.next_scene = nil
- if $game_switches[Ixfuru::SynthShop::SYNTH_SHOP_SWITCH]
- $scene = Scene_SynthShop.new
- else
- ixsynth_callshop
- end
- end
- end
- ################################################################################
- #*******************************************************************************
- # Window SynthShopItems
- ################################################################################
- class Window_SynthShopItems < Window_Selectable
- attr_reader :goods
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- super(0, 56, 304, 232)
- @goods = synth_shop_goods
- @item_max = @goods.size
- refresh
- self.index = 0
- end
- #-----------------------------------------------------------------------------
- # Synth Shop Goods
- #-----------------------------------------------------------------------------
- def synth_shop_goods
- synth_goods = []
- sg = $game_temp.shop_goods
- for g in sg
- case g[0]
- when 0
- i = $data_items[g[1]]
- when 1
- i = $data_weapons[g[1]]
- when 2
- i = $data_armors[g[1]]
- end
- synth_goods.push(i)
- end
- return synth_goods
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- create_contents
- unless @goods.empty?
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Item
- #-----------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- e = enabled?(index)
- draw_item_name(@goods[index], rect.x, rect.y, e)
- self.contents.font.color.alpha = e ? 255 : 128
- self.contents.draw_text(rect, @goods[index].synth_cost.to_s, 2)
- end
- #-----------------------------------------------------------------------------
- # Synth Item
- #
- # synthesis: [item_type, item_id, item_amount])
- #-----------------------------------------------------------------------------
- def synth_item(synthesis)
- case synthesis[0]
- when 0 # item
- return $data_items[synthesis[1]]
- when 1 # weapon
- return $data_weapons[synthesis[1]]
- when 2 # armor
- return $data_armors[synthesis[1]]
- end
- return nil
- end
- #-----------------------------------------------------------------------------
- # Enabled?
- #-----------------------------------------------------------------------------
- def enabled?(index)
- return false if @goods[index].nil?
- item = @goods[index]
- party = $game_party
- members = $game_party.members
- requireds = 0
- return true if item.synth.empty?
- for s in item.synth
- s_item = synth_item(s)
- next if s_item.nil? # Skip it if there is no such database material item
- if party.has_item?(s_item) && party.item_number(s_item) > s[2]
- requireds += 1
- end
- end
- return false if requireds < item.synth.size
- return true
- end
- end
- ################################################################################
- #******************************************************************************
- # Window SynthShopStatus
- ################################################################################
- class Window_SynthShopStatus < Window_Base
- attr_accessor :item
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(item)
- super(304, 56, 240, 116)
- @strings = Ixfuru::SynthShop::SYNTH_STATUS_STRINGS
- @item = item
- refresh
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- ly = 0
- self.contents.font.color = system_color
- for i in 0...@strings.size
- self.contents.draw_text(0, ly, self.width, WLH, @strings[i])
- ly += WLH
- end
- self.contents.font.color = normal_color
- self.contents.draw_text(0, 0, self.width - 32, WLH, $game_party.gold.to_s, 2)
- self.contents.draw_text(0, WLH, self.width - 32, WLH, $game_party.item_number(@item).to_s, 2)
- self.contents.draw_text(0, WLH * 2, self.width - 32, WLH, party_equipped.to_s, 2)
- end
- #-----------------------------------------------------------------------------
- # Party Equipped
- #
- # retrieved value for the amount of a selected item the party has as part of
- # their equipments.
- #-----------------------------------------------------------------------------
- def party_equipped
- e = 0
- return e if @item.is_a?(RPG::Item)
- for member in $game_party.members
- case @item
- when RPG::Weapon
- if member.weapons.include?(@item)
- e += 1
- end
- when RPG::Armor
- if member.armors.include?(@item)
- e += 1
- end
- end
- end
- return e
- end
- end
- ################################################################################
- #*******************************************************************************
- # Window SynthShopActors
- ################################################################################
- class Window_SynthShopActors < Window_Selectable
- attr_accessor :item
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(item)
- super(0, 288, 544, 128)
- @party = $game_party.members
- @item = item
- @item_max = @party.size
- @column_max = @party.size
- refresh
- self.index = -1
- self.active = false
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- create_contents
- for i in 0...@item_max
- draw_member(i)
- end
- end
- #-----------------------------------------------------------------------------
- # New Equipment Change
- #-----------------------------------------------------------------------------
- def new_equipment_change(value1, value2)
- return 0 if value1 == value2
- return value1 - value2
- end
- #-----------------------------------------------------------------------------
- # Draw Member
- #-----------------------------------------------------------------------------
- def draw_member(index)
- rect = item_rect(index)
- rect.x += 3
- rect.width -= 8
- draw_actor_face(@party[index], rect.x, rect.y, 96)
- return if @item.is_a?(RPG::Item)
- return if !@party[index].equippable?(@item)
- mimic = @party[index].clone
- if @item.is_a?(RPG::Weapon)
- mimic.change_equip(0, @item)
- change = new_equipment_change(mimic.atk, @party[index].atk)
- else
- mimic.change_equip(@item.kind, @item)
- change = new_equipment_change(mimic.def, @party[index].def)
- end
- return if change == 0
- up = change > 0 ? true : false
- self.contents.font.color = change > 0 ? power_up_color : power_down_color
- if up
- self.contents.draw_text(rect.x + 72, rect.y, self.width, WLH, "+" + change.to_s)
- else
- self.contents.draw_text(rect.x + 72, rect.y, self.width, WLH, change.to_s)
- end
- end
- #-----------------------------------------------------------------------------
- # Item Rect
- #-----------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- rect.width = (contents.width + @spacing) / @column_max - @spacing
- rect.height = 96
- rect.x = index % @column_max * (rect.width + @spacing)
- rect.y = index / @column_max * 96
- return rect
- end
- end
- ################################################################################
- #*******************************************************************************
- # Window SynthShopRequired
- ################################################################################
- class Window_SynthShopRequired < Window_Selectable
- attr_accessor :item
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(item)
- super(304, 172, 240, 116)
- @item = item
- @synth = []
- refresh
- self.active = false
- self.index = 0
- end
- #-----------------------------------------------------------------------------
- # Synth Item
- #
- # synthesis : [item_type, item_id, item_amount]
- #-----------------------------------------------------------------------------
- def synth_item(synthesis)
- case synthesis[0]
- when 0
- return $data_items[synthesis[1]]
- when 1
- return $data_weapons[synthesis[1]]
- when 2
- return $data_armors[synthesis[1]]
- end
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- if @item.nil?
- @item_max = 0
- else
- @item_max = @item.synth.size
- end
- self.index = 0
- return if @item_max == 0
- for i in 0...@item_max
- draw_material(i, @item.synth[i])
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Material
- #-----------------------------------------------------------------------------
- def draw_material(index, synthesis)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- s_item = synth_item(synthesis)
- draw_icon(s_item.icon_index, rect.x, rect.y)
- self.contents.draw_text(rect.x + 26, rect.y, self.width, WLH, s_item.name)
- self.contents.draw_text(rect.x, rect.y, self.width - 50, WLH, "x" + synthesis[2].to_s, 2)
- end
- end
- ################################################################################
- #*******************************************************************************
- # Window SynthSuccess
- ################################################################################
- class Window_SynthSuccess < Window_Base
- attr_accessor :created_item
- attr_accessor :created_amount
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- super(0, 180, 544, 56)
- @string = Ixfuru::SynthShop::SYNTH_SUCCESS_STRING
- @created_item = nil
- @created_amount = 0
- refresh
- self.visible = false
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- return if @created_item.nil?
- as = self.contents.text_size(@created_amount.to_s).width
- ts = self.contents.text_size(@created_item.name).width + 26 + as
- ss = self.contents.text_size(@string).width
- csize = ts + ss
- centered_x = ((self.width - 32) / 2) - (csize / 2)
- self.contents.draw_text(centered_x, 0, self.width, WLH, @created_amount.to_s)
- draw_icon(@created_item.icon_index, centered_x + as, 0)
- self.contents.draw_text(centered_x + as + 26, 0, self.width, WLH, @created_item.name)
- self.contents.draw_text((centered_x + as) + ts, 0, self.width, WLH, @string)
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW SYNTH NUMBER
- ################################################################################
- class Window_SynthNumber < Window_Base
- attr_accessor :number
- attr_accessor :max_number
- attr_accessor :price
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- super(154, 144, 204, 128)
- @number = 1
- @max_number = 99
- @price = 0
- refresh
- self.visible = false
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- self.contents.font.color = system_color
- self.contents.draw_text(0, 0, self.width - 32, WLH, "How many?", 1)
- self.contents.draw_text(0, WLH * 2, self.width - 32, WLH, "Total Price:", 1)
- self.contents.font.color = normal_color
- self.contents.draw_text(0, WLH, self.width - 32, WLH, "x" + @number.to_s, 1)
- self.contents.draw_text(0, WLH * 3, self.width - 32, WLH, total_synth_price.to_s, 1)
- end
- #-----------------------------------------------------------------------------
- # Total Synth Price
- #-----------------------------------------------------------------------------
- def total_synth_price
- return @number * @price
- end
- end
- ################################################################################
- #*******************************************************************************
- # Scene SynthShop
- ################################################################################
- class Scene_SynthShop < Scene_Base
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @win_shop = Window_SynthShopItems.new
- @item = @win_shop.goods[@win_shop.index]
- @win_status = Window_SynthShopStatus.new(@item)
- @win_actors = Window_SynthShopActors.new(@item)
- @win_required = Window_SynthShopRequired.new(@item)
- @win_help = Window_Help.new
- @win_number = Window_SynthNumber.new
- @win_success = Window_SynthSuccess.new
- end
- #-----------------------------------------------------------------------------
- # Frame Update
- #-----------------------------------------------------------------------------
- def update
- super
- if @win_success.visible
- update_success
- elsif @win_number.visible
- update_number
- elsif @win_required.active
- update_required
- elsif @win_shop.active
- update_shop
- end
- end
- #-----------------------------------------------------------------------------
- # Update Success
- #-----------------------------------------------------------------------------
- def update_success
- if Input.trigger?(Input::C) || Input.trigger?(Input::B)
- Sound.play_cancel
- @win_success.visible = false
- @win_shop.active = true
- end
- end
- #------------------------------------------------------------------------------
- # Window Toggle Button
- #-----------------------------------------------------------------------------
- def window_toggle_button
- case Ixfuru::SynthShop::SYNTH_WINDOW_CONTROL_KEYS
- when 0
- if @win_required.active
- return Input::L
- else
- return Input::R
- end
- when 1
- if @win_required.active
- return Input::LEFT
- else
- return Input::RIGHT
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Update Required
- #-----------------------------------------------------------------------------
- def update_required
- @win_required.update
- if Input.trigger?(window_toggle_button)
- Sound.play_decision
- @win_required.active = false
- @win_shop.active = true
- end
- end
- #-----------------------------------------------------------------------------
- # Update Shop
- #-----------------------------------------------------------------------------
- def update_shop
- @win_shop.update
- @item = @win_shop.goods[@win_shop.index]
- @win_help.set_text(@item.description, 1)
- update_item_windows
- if Input.trigger?(Input::C)
- if @win_shop.enabled?(@win_shop.index)
- Sound.play_decision
- activate_number
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- $game_switches[Ixfuru::SynthShop::SYNTH_SHOP_SWITCH] = false
- $scene = Scene_Map.new
- elsif Input.trigger?(window_toggle_button)
- Sound.play_decision
- @win_shop.active = false
- @win_required.active = true
- end
- end
- #-----------------------------------------------------------------------------
- # Activate Number
- #-----------------------------------------------------------------------------
- def activate_number
- @win_shop.active = false
- @win_number.number = 1
- @win_number.price = @item.synth_cost
- @win_number.max_number = maximum_possible_builds
- @win_number.refresh
- @win_number.visible = true
- end
- #-----------------------------------------------------------------------------
- # Synth Material
- #-----------------------------------------------------------------------------
- def synth_material(synthesis)
- case synthesis[0]
- when 0 # item
- return $data_items[synthesis[1]]
- when 1 # weapon
- return $data_weapons[synthesis[1]]
- when 2 # armor
- return $data_armors[synthesis[1]]
- end
- end
- #-----------------------------------------------------------------------------
- # Maximum Possible Builds
- #-----------------------------------------------------------------------------
- def maximum_possible_builds
- return 99 if @item.synth.empty?
- result = 0
- party = $game_party
- gold = party.gold
- for i in 1..99
- has = 0
- for s in @item.synth
- material = synth_material(s)
- a = s[2] # Amount required for each synth
- next unless party.item_number(material) >= a * i
- next unless gold >= @item.synth_cost * i
- has += 1
- end
- if has >= @item.synth.size
- result += 1
- end
- end
- return [result, 99].min
- end
- #-----------------------------------------------------------------------------
- # Update Number
- #-----------------------------------------------------------------------------
- def update_number
- if Input.trigger?(Input::C)
- if @win_number.number <= @win_number.max_number
- play_synth_success
- process_synthesis
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::UP)
- Sound.play_cursor
- @win_number.number = [@win_number.number + 1, @win_number.max_number].min
- @win_number.refresh
- elsif Input.trigger?(Input::DOWN)
- Sound.play_cursor
- @win_number.number = [@win_number.number - 1, 1].max
- @win_number.refresh
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_number.visible = false
- @win_shop.active = true
- end
- end
- #-----------------------------------------------------------------------------
- # Play Synth Success
- #-----------------------------------------------------------------------------
- def play_synth_success
- se = Ixfuru::SynthShop::SYNTH_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Process Synthesis
- #-----------------------------------------------------------------------------
- def process_synthesis
- for i in 0...@win_number.number
- for s in @item.synth
- material = synth_material(s)
- $game_party.lose_item(material, s[2])
- end
- end
- $game_party.gain_item(@item, @win_number.number)
- $game_party.lose_gold(@item.synth_cost * @win_number.number)
- @win_success.created_item = @item
- @win_success.created_amount = @win_number.number
- @win_success.refresh
- @win_status.refresh
- @win_shop.refresh
- @win_number.visible = false
- @win_success.visible = true
- end
- #-----------------------------------------------------------------------------
- # Update Item Windows
- #-----------------------------------------------------------------------------
- def update_item_windows
- windows = [@win_status, @win_actors, @win_required]
- for window in windows
- if window.item != @item
- window.item = @item
- window.refresh
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- windows = [@win_shop, @win_required, @win_status, @win_actors, @win_help,
- @win_success, @win_number]
- for window in windows
- window.dispose
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment