Jump to content
Shiggy

(Recettear-Like) Haggling

Recommended Posts

Introduction:
I played a lot of Recettear lately ( which means yesterday, I play 12 hours yesterday ... ) and it's a very fun game.
So it made me want to  make a script that reproduces the haggling system in this game (it doesn't seem to exist yet).
I tried to make the script work through events so that you can add the dialog and images you want during the haggling 

I try to make it as configurable and simple as possible but doing both isn't easy. I would appreciate your feedback on the matter.

I would advise to look at a Recettear let's play or play the game yourself to see what i was trying to emulate.
 
Script:

Here is the script although it is not very useful if you don't know how to configre a haggling event , I will advise to take a look at the demo

 

module Shiggy
	module Haggle
		RESERVED_VARIABLE = 100
	end
end

class Haggle_Data
	attr_reader :result
	def initialize(base_price, player_buying, limit)
		@base_price = base_price
		@accept_limit = base_price
		@run_limit = base_price
		@limit = limit
		@player_buying = player_buying
	end

	def analyse_string(str, num)
		value = str.to_i
		arr = str.each_char.to_a
		if (arr.last == '%')
			value = @base_price * value / 100
		end
		if (arr.first == '-')
			num -= value
		else
			num += value
		end
		return (num)
	end

	def update_limits(accept, run)
		if accept.is_a?(String)
			@accept_limit = analyse_string(accept, @accept_limit)
		else
			@accept_limit = accept
		end
		if run.is_a?(String)
			@run_limit = analyse_string(run, @run_limit)
		else
			@run_limit = run
		end
	end

	def compare(price)
		if (@player_buying)
			if (price <= @run_limit)
				@result = 0
			elsif (price < @accept_limit)
				@result = 1
			else
				@result = 2
			end
		else
			if (price >= @run_limit)
				@result = 0
			elsif (price > @accept_limit)
				@result = 1
			else
				@result = 2
			end
		end
		@limit -= 1
		if (@limit == 0)
			@result = 0
		end
	end


end

class Game_Interpreter
	def start_haggle(base_price, player_buying, limit = 0)
		@haggle_data = Haggle_Data.new(base_price, player_buying, limit)
	end

	def haggle_update(accept, run)
		@haggle_data.update_limits(accept, run)
	end

	def get_price
		wait_for_message
		setup_num_input([Shiggy::Haggle::RESERVED_VARIABLE, 8])
		Fiber.yield while $game_message.num_input?
	end

	def continue_haggling
		get_price
		number = $game_variables[Shiggy::Haggle::RESERVED_VARIABLE]
		@haggle_data.compare(number)
		return (@haggle_data.result)
	end

	def haggle_continues?
		return (@haggle_data.result == 1)
	end

	def haggle_succeeds?
		return (@haggle_data.result == 2)
	end

	def haggle_fails?
		return (@haggle_data.result == 0)
	end

	def haggle_end
		@haggle_data = nil
	end
end

 



 Demo:

https://www.dropbox.com/s/gx6ztbztfehs60y/haggling_demo.tar.gz?dl=0

(This is a compressed folder)

Take a look at the events to see how it works (there are explanations in the event of the right). Then try to modify it yourself

I didn't add or remove items / gold from the inventory in my example but the commands for this already exist in RPG Maker. (For the gold, add or substract from the game variable that contains the proposed price). 

 

Conclusion:

Technically all this script does can be done with events, it simply streamlines the process a bit, helping (I hope) to keep track of what happens.
I hope this will help some people. I think it can be a fun mechanic if used wisely.

Don't forget you can haggle other things than items, like a master teaching you skill or buying a ride to some place.

Have fun and keep making games

Edited by Shiggy
  • Like 1

Share this post


Link to post
Share on other sites

Capitalism ho!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted