# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: Shop Bargain ║ Version: 1.02 ║
# ║ Author: Roninator2 ║ ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function: ║ Date Created ║
# ║ ╠════════════════════╣
# ║ Set bargaining for shop items ║ 12 Jun 2024 ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description: ║
# ║ Haggle with the shop owner for paying a lower price ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions: ║
# ║ Detail notes in Module settings below ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates: ║
# ║ 1.00 - 12 Jun 2024 - Script finished ║
# ║ 1.01 - 13 Jun 2024 - Fixed bug and added shop keep face ║
# ║ 1.02 - 13 Jun 2024 - Fixed bug and added shop text in module ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks: ║
# ║ Roninator2 ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use: ║
# ║ Follow the original Authors terms of use where applicable ║
# ║ - When not made by me (Roninator2) ║
# ║ Free for all uses in RPG Maker except nudity ║
# ║ Anyone using this script in their project before these terms ║
# ║ were changed are allowed to use this script even if it conflicts ║
# ║ with these new terms. New terms effective 03 Apr 2024 ║
# ║ No part of this code can be used with AI programs or tools ║
# ║ Credit must be given ║
# ╚════════════════════════════════════════════════════════════════════╝
#==============================================================================
# ** R2_Bargain_Shop
#==============================================================================
module R2_Bargain_shop
SHOP_VARIABLE = 10 # variable used to control which shop keeper
# mood config to use.
BARGAIN_SWITCH = 10 # switch used to run bargain scene. turn on when
# you want to enter the bargain shop.
BARGAIN_TITLE = "Bargain with the Shopkeep"
# Do not touch
BARGAIN_ITEM = /<bargain:[ ]*(\d+)>/i # do not touch
# pass is for when the purchase is successful
# the mood will increase for the shopkeeper
PASS = 5 # will increase by multiples of amounts below
FAIL = 10 # will decrease by this amount
MORE = 5 # will decrease by this amount when offer is not favorable (random)
LOW = 1 # PASS times LOW when offer is higher than the minimum
MID = 2 # PASS times MID when the offer is higher than the low + item bargain
FULL = 3 # PASS times FULL when the offer is higher than the original cost
# minimum is calculated by Full price - item variance - mood adjustment
# mid is calculated by low plus mood variance
# full is the item listed price
#
# Variance is calculated by the item bargain price times item number
# <Bargain: 10> and buying 2 potions, means 10 * 2 = 20
# if item has no note tag, variance is 0.05 * item price * item number
#
# Mood is calculated by variance * mood value / 100
# 20 * 50 / 100 = 10
#
# Bargain Digits
DIGITS = 6 # 6 is for numbers as high as 999,999
# Shop keeper image filename
SHOPKEEP_IMAGE = "Actor5"
# shop keep images are configured on lines 480 -520
# using the offer conditions to change the image
# they can be changed the in code so you don't have to change the image file.
#
# Price text shown after selecting how many items to buy
PRICE_TEXT = "Asking Price"
# text for what you are gong to offer
OFFER = "Offer"
# Message when offer is good
GOOD_DEAL = "That's a good deal"
# message when negotiating
BETTER_OFFER = "I think you can do better"
# message when not enough money
NO_MONEY = "Invalid Funds"
# message when offer is too low
BAD_DEAL = "I don't like your offer"
end
# ╔════════════════════════════════════════════════════════════════════╗
# ║ End of editable region ║
# ╚════════════════════════════════════════════════════════════════════╝
$imported = {} if $imported.nil?
$imported[:r2_bargain_shop] = 1.02
#==============================================================================
# ** DataManager Load Notetag
#==============================================================================
module DataManager
class <<self; alias load_database_r2_bargain_load_database load_database; end
def self.load_database
load_database_r2_bargain_load_database
load_notetags_bargain_items
end
def self.load_notetags_bargain_items
groups = [$data_items, $data_weapons, $data_armors]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_bargain_items
end
end
end
end
#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Item < RPG::UsableItem
attr_accessor :bargain
def load_notetags_bargain_items
@bargain = 0
self.note.split(/[\r\n]+/).each { |line|
case line
when R2_Bargain_shop::BARGAIN_ITEM
@bargain = $1.to_i
end
}
end
end
#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Weapon < RPG::EquipItem
attr_accessor :bargain
def load_notetags_bargain_items
@bargain = 0
self.note.split(/[\r\n]+/).each { |line|
case line
when R2_Bargain_shop::BARGAIN_ITEM
@bargain = $1.to_i
end
}
end
end
#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Armor < RPG::EquipItem
attr_accessor :bargain
def load_notetags_bargain_items
@bargain = 0
self.note.split(/[\r\n]+/).each { |line|
case line
when R2_Bargain_shop::BARGAIN_ITEM
@bargain = $1.to_i
end
}
end
end
#--------------------------------------------------------------------------
# * Game Interpreter - Overwrite shop call method
#--------------------------------------------------------------------------
class Game_Interpreter
def command_302
return if $game_party.in_battle
goods = [@params]
while next_event_code == 605
@index += 1
goods.push(@list[@index].parameters)
end
if $game_switches[R2_Bargain_shop::BARGAIN_SWITCH]
SceneManager.call(Scene_Bargain_Shop)
SceneManager.scene.prepare(goods)
else
SceneManager.call(Scene_Shop)
SceneManager.scene.prepare(goods, @params[4])
end
Fiber.yield
end
end
#==============================================================================
# ** Game_Party
#==============================================================================
class Game_Party
attr_accessor :shop_mood
alias :r2_party_init_bargain_shop :initialize
def initialize
r2_party_init_bargain_shop
@shop_mood = []
end
end
#==============================================================================
# ** Window_Help
#------------------------------------------------------------------------------
# This window shows skill and item explanations along with actor status.
#==============================================================================
class Window_BargainHelp < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(line_number = 2)
super(0, Graphics.height - fitting_height(line_number), Graphics.width, fitting_height(line_number))
end
#--------------------------------------------------------------------------
# * Set Text
#--------------------------------------------------------------------------
def set_text(text)
if text != @text
@text = text
refresh
end
end
#--------------------------------------------------------------------------
# * Clear
#--------------------------------------------------------------------------
def clear
set_text("")
end
#--------------------------------------------------------------------------
# * Set Item
# item : Skills and items etc.
#--------------------------------------------------------------------------
def set_item(item)
set_text(item ? item.description : "")
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_text_ex(4, 0, @text)
end
end
#==============================================================================
# ** Window_Title
#==============================================================================
class Window_BargainTitle < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, fitting_height(1))
refresh
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
return Graphics.width
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_text(0, 0, Graphics.width, 24, R2_Bargain_shop::BARGAIN_TITLE, 1)
end
end
#==============================================================================
# ** Window_BargainGold
#==============================================================================
class Window_BargainGold < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, fitting_height(1))
refresh
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
return Graphics.width / 2
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
end
#--------------------------------------------------------------------------
# * Get Party Gold
#--------------------------------------------------------------------------
def value
$game_party.gold
end
#--------------------------------------------------------------------------
# Get Currency Unit
#--------------------------------------------------------------------------
def currency_unit
Vocab::currency_unit
end
#--------------------------------------------------------------------------
# * Open Window
#--------------------------------------------------------------------------
def open
refresh
super
end
end
#==============================================================================
# ** Window_ShopCommand
#------------------------------------------------------------------------------
# This window is for selecting buy/sell on the shop screen.
#==============================================================================
class Window_BargainShopCommand < Window_HorzCommand
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(window_width)
@window_width = window_width
super(0, 0)
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
@window_width
end
#--------------------------------------------------------------------------
# * Get Digit Count
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# * Create Command List
#--------------------------------------------------------------------------
def make_command_list
add_command(Vocab::ShopBuy, :buy)
add_command(Vocab::ShopCancel, :cancel)
end
end
#==============================================================================
# ** Window_BargainShopNumber
#==============================================================================
class Window_BargainShopNumber < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :number # quantity entered
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y, height)
super(x, y, window_width, height)
@item = nil
@max = 1
@price = 0
@number = 1
@currency_unit = Vocab::currency_unit
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
return 300
end
#--------------------------------------------------------------------------
# * Set Item, Max Quantity, Price, and Currency Unit
#--------------------------------------------------------------------------
def set(item, max, currency_unit = nil)
@item = item
@max = max
@currency_unit = currency_unit if currency_unit
@number = 1
refresh
end
#--------------------------------------------------------------------------
# * Set Currency Unit
#--------------------------------------------------------------------------
def currency_unit=(currency_unit)
@currency_unit = currency_unit
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_item_name(@item, 0, item_y)
draw_number
end
#--------------------------------------------------------------------------
# * Draw Quantity
#--------------------------------------------------------------------------
def draw_number
change_color(normal_color)
draw_text(cursor_x - 28, item_y, 22, line_height, "×")
draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
end
#--------------------------------------------------------------------------
# * Y Coordinate of Item Name Display Line
#--------------------------------------------------------------------------
def item_y
contents_height / 2 - line_height * 3 / 2
end
#--------------------------------------------------------------------------
# * Y Coordinate of Price Display Line
#--------------------------------------------------------------------------
def price_y
contents_height / 2 + line_height / 2
end
#--------------------------------------------------------------------------
# * Get Cursor Width
#--------------------------------------------------------------------------
def cursor_width
figures * 10 + 12
end
#--------------------------------------------------------------------------
# * Get X Coordinate of Cursor
#--------------------------------------------------------------------------
def cursor_x
contents_width - cursor_width - 4
end
#--------------------------------------------------------------------------
# * Get Maximum Number of Digits for Quantity Display
#--------------------------------------------------------------------------
def figures
return 2
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if active
last_number = @number
update_number
if @number != last_number
Sound.play_cursor
refresh
end
end
end
#--------------------------------------------------------------------------
# * Update Quantity
#--------------------------------------------------------------------------
def update_number
change_number(1) if Input.repeat?(:RIGHT)
change_number(-1) if Input.repeat?(:LEFT)
change_number(10) if Input.repeat?(:UP)
change_number(-10) if Input.repeat?(:DOWN)
end
#--------------------------------------------------------------------------
# * Change Quantity
#--------------------------------------------------------------------------
def change_number(amount)
@number = [[@number + amount, @max].min, 1].max
end
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
def update_cursor
cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
end
end
#==============================================================================
# ** Window_BargainShopNumber
#==============================================================================
class Window_BargainNumber < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super(x, y, width, height)
@number = 0
@digits_max = 1
@index = 0
@currency_unit = Vocab::currency_unit
end
#--------------------------------------------------------------------------
# * Start Input Processing
#--------------------------------------------------------------------------
def start
@digits_max = R2_Bargain_shop::DIGITS
@number = [[@number, 0].max, 10 ** @digits_max - 1].min
@index = 0
create_contents
refresh
open
activate
end
#--------------------------------------------------------------------------
# * Set Item, Max Quantity, Price, and Currency Unit
#--------------------------------------------------------------------------
def set(price, num)
@price = price
@num = num
refresh
end
#--------------------------------------------------------------------------
# * Draw Total Price
#--------------------------------------------------------------------------
def draw_total_price
width = contents_width - 8
text = R2_Bargain_shop::PRICE_TEXT
draw_text(0,0,width,24, text)
draw_currency_value(@price * @num, @currency_unit, 4, 0, width)
end
#--------------------------------------------------------------------------
# * Message
#--------------------------------------------------------------------------
def message(type)
width = contents_width - 8
mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
case type
when :pass
change_color(normal_color)
text = R2_Bargain_shop::GOOD_DEAL
draw_text(0,50,width,24, text)
draw_shopkeep(mood, 10)
when :more
change_color(tp_cost_color)
text = R2_Bargain_shop::BETTER_OFFER
draw_text(0,80,width,24, text)
draw_shopkeep(mood, 5)
when :gold
change_color(system_color)
text = R2_Bargain_shop::NO_MONEY
draw_text(0,80,width,24, text)
draw_shopkeep(mood, 0)
when :fail
change_color(crisis_color)
text = R2_Bargain_shop::BAD_DEAL
draw_text(0,80,width,24, text)
draw_shopkeep(mood, -10)
end
end
#--------------------------------------------------------------------------
# new method: draw_shopkeep
#--------------------------------------------------------------------------
def draw_shopkeep(mood, adjust=0)
name = R2_Bargain_shop::SHOPKEEP_IMAGE
if adjust > 5
index = 3
elsif adjust > 0
index = 2
elsif adjust < 0
index = 1
else
index = 0
end
draw_face(name, index, 40, 120)
end
#--------------------------------------------------------------------------
# * Move Cursor Right
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_right(wrap)
if @index < @digits_max - 1
@index = @index + 1
else
@index = 0
end
end
#--------------------------------------------------------------------------
# * Move Cursor Left
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_left(wrap)
if @index > 0
@index = @index - 1
else
@index = @digits_max - 1
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
process_digit_change
process_handling
update_cursor
end
#--------------------------------------------------------------------------
# * Cursor Movement Processing
#--------------------------------------------------------------------------
def process_cursor_move
return unless active
last_index = @index
cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
cursor_left (Input.trigger?(:LEFT)) if Input.repeat?(:LEFT)
Sound.play_cursor if @index != last_index
end
#--------------------------------------------------------------------------
# * Change Processing for Digits
#--------------------------------------------------------------------------
def process_digit_change
return unless active
if Input.repeat?(:UP) || Input.repeat?(:DOWN)
Sound.play_cursor
place = 10 ** (@digits_max - 1 - @index)
n = @number / place % 10
@number -= n * place
n = (n + 1) % 10 if Input.repeat?(:UP)
n = (n + 9) % 10 if Input.repeat?(:DOWN)
@number += n * place
refresh
end
end
#--------------------------------------------------------------------------
# * Handling Processing for OK and Cancel
#--------------------------------------------------------------------------
def process_handling
return unless active
set_number
return process_ok if Input.trigger?(:C)
return process_cancel if Input.trigger?(:B)
end
#--------------------------------------------------------------------------
# * Saving the final number
#--------------------------------------------------------------------------
def set_number
@final_price = @number
end
#--------------------------------------------------------------------------
# * returning final number
#--------------------------------------------------------------------------
def get_number
@final_price
end
#--------------------------------------------------------------------------
# * Get Rectangle for Displaying Item
#--------------------------------------------------------------------------
def item_rect(index)
Rect.new(index * 15, 0, 15, line_height)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
change_color(normal_color)
s = sprintf("%0*d", @digits_max, @number)
text = R2_Bargain_shop::OFFER
draw_text(5, 48, 50, 24,text)
@digits_max.times do |i|
rect = item_rect(i)
rect.x += 80
rect.y += 48
draw_text(rect, s[i,1], 1)
change_color(system_color) if i == @digits_max - 1
draw_text(rect.x+24, rect.y, rect.width, rect.height,@currency_unit) if i == @digits_max - 1
end
draw_total_price
mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
draw_shopkeep(mood)
end
#--------------------------------------------------------------------------
# * clear
#--------------------------------------------------------------------------
def clear
@digits_max = 0
@index = -1
contents.clear
end
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
def update_cursor
cursor_rect.set(item_rect(@index))
cursor_rect.x += 80
cursor_rect.y += 48
cursor_rect.empty if @index == -1
end
end
#==============================================================================
# ** Scene_Bargain_Shop
#==============================================================================
class Scene_Bargain_Shop < Scene_MenuBase
#--------------------------------------------------------------------------
# * Prepare
#--------------------------------------------------------------------------
def prepare(goods)
@goods = goods
@purchase_only = true
end
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
def start
super
create_help_window
create_title_window
create_gold_window
create_command_window
create_dummy_window
create_number_window
create_buy_window
create_bargain_window
end
#--------------------------------------------------------------------------
# * Create Help Window
#--------------------------------------------------------------------------
def create_help_window
@help_window = Window_BargainHelp.new
@help_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# * Create Title Window
#--------------------------------------------------------------------------
def create_title_window
@title_window = Window_BargainTitle.new
@title_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# * Create Gold Window
#--------------------------------------------------------------------------
def create_gold_window
@gold_window = Window_BargainGold.new
@gold_window.viewport = @viewport
@gold_window.x = Graphics.width - @gold_window.width
@gold_window.y = @title_window.height
end
#--------------------------------------------------------------------------
# * Create Command Window
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_BargainShopCommand.new(@gold_window.x)
@command_window.viewport = @viewport
@command_window.y = @title_window.height
@command_window.set_handler(:buy, method(:command_buy))
@command_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# * Create Dummy Window
#--------------------------------------------------------------------------
def create_dummy_window
wy = @command_window.y + @command_window.height
wh = Graphics.height - wy - @help_window.height
@dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
@dummy_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# * Create Quantity Input Window
#--------------------------------------------------------------------------
def create_number_window
wy = @dummy_window.y
wh = @dummy_window.height
@number_window = Window_BargainShopNumber.new(0, wy, wh)
@number_window.viewport = @viewport
@number_window.z = 200
@number_window.hide
@number_window.set_handler(:ok, method(:on_number_ok))
@number_window.set_handler(:cancel, method(:on_number_cancel))
end
#--------------------------------------------------------------------------
# * Create Purchase Window
#--------------------------------------------------------------------------
def create_buy_window
wy = @dummy_window.y
wh = @dummy_window.height
@buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
@buy_window.viewport = @viewport
@buy_window.help_window = @help_window
@buy_window.status_window = @status_window
@buy_window.hide
@buy_window.set_handler(:ok, method(:on_buy_ok))
@buy_window.set_handler(:cancel, method(:on_buy_cancel))
end
#--------------------------------------------------------------------------
# * Create Status Window
#--------------------------------------------------------------------------
def create_bargain_window
wx = @buy_window.width
wy = @buy_window.y
ww = Graphics.width - wx
wh = @buy_window.height
@bargain_window = Window_BargainNumber.new(wx, wy, ww, wh)
@bargain_window.viewport = @viewport
@bargain_window.hide
@bargain_window.set_handler(:ok, method(:on_bargain_ok))
@bargain_window.set_handler(:cancel, method(:on_bargain_cancel))
end
#--------------------------------------------------------------------------
# * Activate Purchase Window
#--------------------------------------------------------------------------
def activate_buy_window
@buy_window.money = money
@buy_window.show.activate
@bargain_window.show
end
#--------------------------------------------------------------------------
# * [Buy] Command
#--------------------------------------------------------------------------
def command_buy
@dummy_window.hide
activate_buy_window
end
#--------------------------------------------------------------------------
# * Buy [OK]
#--------------------------------------------------------------------------
def on_buy_ok
@item = @buy_window.item
@number_window.set(@item, max_buy, currency_unit)
@number_window.show.activate
end
#--------------------------------------------------------------------------
# * Buy [Cancel]
#--------------------------------------------------------------------------
def on_buy_cancel
@command_window.activate
@dummy_window.show
@buy_window.hide
@bargain_window.hide
@help_window.clear
end
#--------------------------------------------------------------------------
# * Quantity Input [OK]
#--------------------------------------------------------------------------
def on_number_ok
@bargain_window.set(buying_price, @number_window.number)
@bargain_window.activate
@bargain_window.start
@number_window.hide
end
#--------------------------------------------------------------------------
# * Quantity Input [Cancel]
#--------------------------------------------------------------------------
def on_number_cancel
Sound.play_cancel
@number_window.hide
activate_buy_window
end
#--------------------------------------------------------------------------
# * Price Input [OK]
#--------------------------------------------------------------------------
def on_bargain_ok
do_buy(@bargain_window.get_number)
end
#--------------------------------------------------------------------------
# * Quantity Input [Cancel]
#--------------------------------------------------------------------------
def on_bargain_cancel
@number_window.set(@item, max_buy, currency_unit)
@number_window.show.activate
@bargain_window.clear
end
#--------------------------------------------------------------------------
# * Execute Purchase
#--------------------------------------------------------------------------
def do_buy(number)
# buy mechanic
mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
if mood == nil
mood = 50
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 50
end
# do mood calculation
full = buying_price * @number_window.number
min = (full / 2).to_i
variance = 0
if @item.bargain != 0
variance = @item.bargain * @number_window.number
else
variance = (@item.price * 0.05).to_i * @number_window.number
end
adjust = (variance * mood / 100).to_i
low = full - adjust - variance
mid = low + adjust
# check for price accepted
bonus = 0
if number >= full
bonus = 3
elsif number >= mid
bonus = 2
elsif number >= low
bonus = 1
else
bonus = -1
end
odds = 0
success = false
cost_compare = (full * 0.95).to_i
if bonus > 0
if $game_party.gold >= number
if number >= cost_compare
success = true
elsif mood >= 95
success = true
else
odds = rand(100)
end
if odds > mood
@bargain_window.message(:more)
@bargain_window.activate
else
success = true
end
if success
@bargain_window.clear
@bargain_window.message(:pass)
Sound.play_shop
$game_party.lose_gold(number)
$game_party.gain_item(@item, @number_window.number)
@bargain_window.deactivate
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::PASS
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 100 if
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] > 100
activate_buy_window
@gold_window.refresh
else
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::MORE
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 0 if
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] < 0
end
else
# not enough gold
@bargain_window.activate
@bargain_window.message(:gold)
return
end
else
# fail and return to amount
@bargain_window.activate
@bargain_window.message(:fail)
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::FAIL
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 0 if
$game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] < 0
end
end
#--------------------------------------------------------------------------
# * Exit Quantity Input
#--------------------------------------------------------------------------
def end_bargain_input
@bargain_window.clear
activate_buy_window
end
#--------------------------------------------------------------------------
# * Get Maximum Quantity Buyable
#--------------------------------------------------------------------------
def max_buy
max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
end
#--------------------------------------------------------------------------
# * Get Party Gold
#--------------------------------------------------------------------------
def money
@gold_window.value
end
#--------------------------------------------------------------------------
# Get Currency Unit
#--------------------------------------------------------------------------
def currency_unit
@gold_window.currency_unit
end
#--------------------------------------------------------------------------
# * Get Purchase Price
#--------------------------------------------------------------------------
def buying_price
@buy_window.price(@item)
end
#--------------------------------------------------------------------------
# * Return Scene
#--------------------------------------------------------------------------
alias :r2_return_bargain_shop_custom :return_scene
def return_scene
$game_switches[R2_Bargain_shop::BARGAIN_SWITCH] = false
r2_return_bargain_shop_custom
end
end