Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # page 4 of 12
- # Shopoholic v 2.0
- # code by cmpsr2000
- # available exclusively @ rpgrevolution.com/forums
- # Released June 25, 2008
- #
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # This class implements shopkeeper inventories and provides access to true price
- # calculations. The instance of this class is $game_shopping
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- #
- # IMPORTANT CUSOMIZATION INFORMATION:
- # There are 2 ways to call the shopping interface. Both are demonstrated
- # in the attached demo game.
- #
- # Method #1: Built-in Shop Proccessing (easiest for non-scripters)
- #
- # METHOD #1 ONLY WORKS FOR BASIC SHOPS!
- #
- # In order to use the preexisting shop interface call from an event, you
- # must first provide values to the following fields:
- #
- # $game_shopping.currentShopID:
- # Integer representing the ID number of the shop (starts at 0)
- #
- # $game_shopping.currentDiscountRate
- # Float point representing the discount on used items. (e.g.if the shop
- # sells used items at 80% of cost, the value is 0.8 )
- #
- # $game_shopping.currentSellRate
- # Float point representing the percentage of the value the shopkeeper pays
- # the player for items. (e.g. If the shopkeeper pays 50% of the item's
- # worth, the value is 0.5)
- #
- # $game_shopping.currentMarkupRate
- # Float point representing the shopkeeper's markup (or markdown) of the
- # selling prices. For example, If the shopkeeper is greedy and wants to
- # markup his items 20% (120% of the item's price in the DB) then the value
- # is 1.2. If he is generous and sells his items 10% under cost (90% of the
- # item's price in the DB) then the value is 0.9
- #
- # $game_shopping.currentTaxRate
- # Float point representing the tax rate of the shop. (e.g. if the shop has
- # a 3% tax rate, the value is 0.03)
- #
- # $game_shopping.currentInflationRate
- # Float point representing the price increase given to items in high demand.
- # (e.g. if the shop keeper marks up items 20% when the stock runs low, the
- # value is 0.2)
- #
- # After you have set these variables, you can then use the shop processing
- # button from the event wizard.
- #
- # Method #2: Calling the shopping scene manually (easiest for scripters)
- #
- # METHOD #2 IS REQUIRED FOR ADVANCED SHOPS!
- #
- # You can call the shopping scene manually by passing all the above values
- # in the constructor. You MUST first define the values of the items in the
- # shop before making the shop call!
- #
- # The format for the shop_goods are:
- # $game_temp.shop_goods = [ [ITEM_TYPE1, ITEM_ID1, ITEM_LIMIT1],
- # [ITEM_TYPE2, ITEM_ID2, ITEM_LIMIT2],
- # etc...]
- # ITEM_TYPE: 0 for RPG::Item
- # 1 for RPG::Weapon
- # 2 for RPG::Armor
- # 3 for RPG::Skill <----advanced shops only
- # 4 for RPG::Class <----advanced shops only
- # 5 for RPG::Actor <----advanced shops only
- # ITEM_ID: The ID number of the item in the DB
- # ITEM_LIMIT: The max the shop can sell to the player. Set to -1 for no
- # limit.
- #
- # The format for the scene call is:
- # $scene = Scene_Shop.new(shopID, discountRate, sellRate,
- # markupRate, taxRate, InflationRate,
- # restockRate, continuousRestock)
- #
- # (all the type rules from method #1 apply to this constuctor as well!)
- #
- # restockRate: How long, in minutes, to wait before the store
- # "restocks" its items. (e.g. a value of 90 is 1 hour
- # and 30 minutes of playtime) Set to 0 to disable
- # restocking completely!
- #
- # continuousRestock: Boolean (true/false) that determines whether the shop
- # restocks continuously. Setting this to true causes a
- # shop to restock at the restockRate regardless of the
- # player's actions. Setting this to false causes the
- # shop to "call" for a restock after the player visits
- # a fully stocked store.
- #
- # If your restockRate is 30 minutes and
- # continuousRestock is true:
- # When the player visits the shop for the first time
- # the timer will start. If the player visits again in
- # 45 minutes, The store will be restocked. If the
- # player comes back 15 minutes after that, the store
- # will be restocked again.
- #
- # But, if your restockRate is 30 minutes and
- # continuousRestock is false:
- # When the player visits the shop for the first time
- # the timer will start. If the player visits again in
- # 45 minutes, the store will be restocked, but the
- # timer will reset to 30 minutes! If the player comes
- # back 15 minutes later, there will still be 15
- # minutes left on the restock timer! This is akin to
- # the shopkeeper calling in an order for more stock
- # when the player shows up to shop.
- #
- #-------------------------------------------------------------------------------
- class Game_Shopping
- attr_accessor :shopUsedItems
- attr_accessor :shopLimitedItems
- attr_accessor :shopRestockTimers
- attr_accessor :currentShopID
- attr_accessor :currentDiscountRate
- attr_accessor :currentSellRate
- attr_accessor :currentMarkupRate
- attr_accessor :currentTaxRate
- attr_accessor :currentInflationRate
- attr_reader :allowRestockWhileShopping
- attr_reader :shopsAcceptDebit
- attr_reader :allowTax
- attr_reader :exhaustableSkills
- attr_reader :skillPrices
- attr_reader :classPrices
- attr_reader :actorPrices
- attr_reader :demandAmount
- #-----------------------------------------------------------------------------
- # Creates the $game_shopping object
- #-----------------------------------------------------------------------------
- def initialize
- #---------------------------------------------------------------------------
- # Set this to true if you would like the shops to restock themselves while
- # the player is currently shopping (this will throw up a message to the
- # player to notify him of the restock)
- #---------------------------------------------------------------------------
- @allowRestockWhileShopping = true
- #---------------------------------------------------------------------------
- # If you want to be able to restock skills, set this to true. For example,
- # if you are building a game where a skill can only be used a certain number
- # of times before being replenished(e.g. Final Fantasy VIII), set this to
- # true.
- #---------------------------------------------------------------------------
- @exhaustableSkills = false
- #---------------------------------------------------------------------------
- # Set this to false if you do not wish to use tax. Make sure to set your
- # tax rates to 0!
- #---------------------------------------------------------------------------
- @allowTax = true
- #---------------------------------------------------------------------------
- # Set this to false if you do not want shops to accept credit (IE, checks,
- # Debit Card or whatever item is linked to checking accounts)
- #---------------------------------------------------------------------------
- @shopsAcceptDebit = true
- #---------------------------------------------------------------------------
- # Set this to the item ID of the item required to enable debit purchases.
- #---------------------------------------------------------------------------
- @debitItemID = 21
- #---------------------------------------------------------------------------
- # If you want a single icon for all classes or actors, you can set that
- # here. If you want to assign icons on a per-class or per-actor basis, set
- # the universal to nil, and define the individual ones below.
- #---------------------------------------------------------------------------
- @universalClassIcon = nil
- @universalActorIcon = 1903
- #---------------------------------------------------------------------------
- # Shopkeepers will start raising their prices on new items when they have
- # this number or LESS in their inventory (for limited items)
- #---------------------------------------------------------------------------
- @demandAmount = 10
- initShopkeepers
- initPrices
- initDiscovery
- initIcons
- initDescriptions
- end
- #-----------------------------------------------------------------------------
- # Sets price data for advanced shop objects.
- #
- # PLEASE NOTE: Skills, classes and actors cannot be sold, only bought!
- #-----------------------------------------------------------------------------
- def initPrices
- #---------------------------------------------------------------------------
- # Set prices for skills here. Start at position 1. Each number corresponds
- # to the ID number of the skill in the database. If you don't wish to sell
- # a skill, use 'nil' in its place. These skills will be discovered the
- # usual way instead of being unlocked from purchasing.
- #---------------------------------------------------------------------------
- @skillPrices = [ #DON'T TOUCH THIS ONE!
- nil,
- #Skills 1-10
- 100, 200, 300, nil, nil, nil, nil, nil, nil, nil,
- #Skills 11-20
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 21-30
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 31-40
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 41-50
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 51-60
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 61-70
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 71-80
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- #Skills 81-82
- nil, nil
- ]
- #---------------------------------------------------------------------------
- # Set prices for classes here. Start at position 1. Each number corresponds
- # to the ID number of the class in the database. If you don't wish to sell
- # a class, use 'nil' in its place. These classes will be discovered the
- # usual way instead of being unlocked from purchasing.
- #---------------------------------------------------------------------------
- @classPrices = [ #DON'T TOUCH THIS ONE!
- nil,
- #Classes 1-8
- nil, 2000, 3000, 4000, 5000, 6000, 7000, 8000
- ]
- #---------------------------------------------------------------------------
- # Set prices for actors here. Start at position 1. Each number corresponds
- # to the ID number of the actor in the database. If you don't wish to sell
- # an actor, use 'nil' in its place. These actors will be discovered the
- # usual way instead of being unlocked from purchasing.
- #---------------------------------------------------------------------------
- @actorPrices = [ #DON'T TOUCH THIS ONE!
- nil,
- #Actors 1-8
- nil, 2000, 3000, 4000, 5000, 6000, 7000, 8000
- ]
- end
- #-----------------------------------------------------------------------------
- # Initializes the icons being used for classes and actors.
- #-----------------------------------------------------------------------------
- def initIcons
- if @universalClassIcon != nil
- classIcons = []
- for x in @classPrices
- classIcons.push(@universalClassIcon)
- end
- else
- #-------------------------------------------------------------------------
- # If you have individual icons for each class, define them here!
- #-------------------------------------------------------------------------
- classIcons = [ #DON'T TOUCH THIS ONE!
- nil,
- #Classes 1-8
- 1154, 1897, 1682, 1899, 549, 547, 1898, 1630
- ]
- end
- if @universalActorIcon != nil
- actorIcons = []
- for x in @actorPrices
- actorIcons.push(@universalActorIcon)
- end
- else
- #-------------------------------------------------------------------------
- # If you have individual icons for each actor, define them here!
- #-------------------------------------------------------------------------
- actorIcons = [ #DON'T TOUCH THIS ONE!
- nil,
- #Actors 1-8
- 1, 2, 3, 4, 5, 6, 7, 8
- ]
- end
- for x in 1..$data_classes.length - 1
- $data_classes[x].icon_index = classIcons[x]
- end
- for x in 1..$data_actors.length - 1
- $data_actors[x].icon_index = actorIcons[x]
- end
- end
- #-----------------------------------------------------------------------------
- # Initializes help text for classes and actors
- #-----------------------------------------------------------------------------
- def initDescriptions
- #---------------------------------------------------------------------------
- # Define the text that will appear in the shop help window for classes here:
- #---------------------------------------------------------------------------
- classDescriptions = [ #DON'T TOUCH THIS ONE!
- nil,
- #Class 1 (Paladin)
- "Stout defender and holy warrior.",
- #Class 2 (Warrior)
- "Me hit things hard!",
- #Class 3 (Priest)
- "Has anyone seen my alterboy?",
- #Class 4 (Magician)
- "Poof! You're a spider!",
- #Class 5 (Knight)
- "Yea, I smiteth mine enemies.",
- #Class 6 (Dark Knight)
- "None shall pass!",
- #Class 7 (Grappler)
- "My chi is bigger than yours.",
- #Class 8 (Thief)
- "I can haz ur gold?"
- ]
- #---------------------------------------------------------------------------
- # Define the text that will appear in the shop help window for actors here:
- #---------------------------------------------------------------------------
- actorDescriptions = [ #DON'T TOUCH THIS ONE!
- nil,
- #Actor 1
- "Actor info goes here!",
- #Actor 2
- "Actor info goes here!",
- #Actor 3
- "Actor info goes here!",
- #Actor 4
- "Actor info goes here!",
- #Actor 5
- "Actor info goes here!",
- #Actor 6
- "Actor info goes here!",
- #Actor 7
- "Actor info goes here!",
- #Actor 8
- "Actor info goes here!",
- ]
- for x in 1..$data_classes.length - 1
- $data_classes[x].description = classDescriptions[x]
- end
- for x in 1..$data_actors.length - 1
- $data_actors[x].description = actorDescriptions[x]
- end
- end
- #-----------------------------------------------------------------------------
- # Creates the shopkeeper inventories and sets up the timers for restocking
- #-----------------------------------------------------------------------------
- def initShopkeepers
- #---------------------------------------------------------------------------
- # IMPORTANT:
- # You will get an error when buying or selling used items if you try to
- # pass a shopID that is higher than the number of @totalShopkeepers - 1.
- # Set this to the number of shops in your game, or HIGHER! Setting higher
- # will waste memory, but you can always count up the number of shops you
- # have before shipping your finished game and change it back to the
- # correct number!
- #---------------------------------------------------------------------------
- @totalShopkeepers = 5
- @shopUsedItems = []
- @shopLimitedItems = []
- @shopRestockTimers = []
- for x in 0..@totalShopkeepers - 1
- @shopUsedItems [x] = {}
- @shopLimitedItems [x] = {}
- @shopRestockTimers[x] = 0
- end
- end
- #-----------------------------------------------------------------------------
- # Initilizes discovery for available skills, classes and actors
- #-----------------------------------------------------------------------------
- def initDiscovery
- for x in 1..$data_skills.length - 1
- if @skillPrices[x] == nil
- $data_skills[x].discover
- else
- $data_skills[x].hide
- end
- end
- for x in 1..$data_classes.length - 1
- if @classPrices[x] == nil
- $data_classes[x].discover
- else
- $data_classes[x].hide
- end
- end
- for x in 1..$data_actors.length - 1
- if @actorPrices[x] == nil
- $data_actors[x].discover
- else
- $data_actors[x].hide
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Calculates the item's selling price based on the current shop's rates.
- # item: The item whose price is being requested
- # rates: A shop rates array: [discountRate, sellRate, markupRate,
- # taxRate, inflationRate]
- # RETURNS Integer (Fixnum)
- #-----------------------------------------------------------------------------
- def sellItemPrice(item, rates)
- sellRate = rates[1]
- shopMarkup = rates[2]
- price = item.price * sellRate * shopMarkup
- return price.ceil
- end
- #-----------------------------------------------------------------------------
- # Calculates the item's purchase price based on the current shop's rates.
- # item: The item whose price is being requested
- # rates: A shop rates array: [discountRate, sellRate, markupRate,
- # taxRate, inflationRate]
- # includeTax: Boolean indicating whether or not the calculation should
- # include tax
- # used: Boolean indicating if the item is used
- # inflated: Boolean indicating if the shop is running low on the item
- # RETURNS Integer (Fixnum)
- #-----------------------------------------------------------------------------
- def shopPrice(item, rates, includeTax = false, used = false, inflated = false)
- discount = rates[0]
- shopMarkup = rates[2]
- shopTax = rates[3]
- shopInflation = rates[4]
- if used
- price = item.price * shopMarkup * discount
- elsif inflated
- price = (item.price * shopMarkup) + (item.price * shopInflation)
- else
- price = item.price * shopMarkup
- end
- price = includeTax ? price.ceil + (price * shopTax).ceil : price.ceil
- return price
- end
- #-----------------------------------------------------------------------------
- # resets the restock timer for a particular shop
- # shopID: The ID of the shop
- # restockRate: The shop's rate of restocking, in minutes
- # continuousRestock: Whether the shop restocks continuously
- #-----------------------------------------------------------------------------
- def resetTimer(shopID, restockRate, continuousRestock)
- if restockRate == 0
- @shopRestockTimers[shopID] = 1
- else
- now = Graphics.frame_count / Graphics.frame_rate
- lastRestockTime = @shopRestockTimers[shopID]
- while lastRestockTime < now - (restockRate * 60)
- lastRestockTime += restockRate * 60
- end
- @shopRestockTimers[shopID] = continuousRestock ? lastRestockTime : now
- end
- end
- #-----------------------------------------------------------------------------
- # Returns the item needed to allow purchases from checking Accounts.
- # RETURNS: RPG::UsableItem
- #-----------------------------------------------------------------------------
- def debitItem
- return $data_items[@debitItemID]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement