Advertisement
estriole

EST - DYNAMIC SHOP

Jan 4th, 2013
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.80 KB | None | 0 0
  1. =begin
  2.  
  3.  ** EST - DYNAMIC SHOP v1.3
  4.  
  5.  author : estriole
  6.  
  7.  requested by Adon from rpgmakerweb.com
  8.  extra credits:
  9.  Nate McCloud for pointing bugs in v 1.2
  10.  
  11.  licences:
  12.  Free to use in all project (except the one containing pornography)
  13.  as long as i credited (ESTRIOLE).
  14.  
  15.  version history
  16.  v 1.0 - 2013.01.04 => finish the script
  17.  v 1.1 - 2013.01.05 => add sell add goods to shop feature. (can be based on category)
  18.  v 1.2 - 2013.01.05 => add notetags for custom item/wep/armor category (to use to shop sell add goods feature)
  19.  v 1.3 - 2014.05.28 => rewritten part of the script. change the logic to make sure no duplicated items.
  20.                        also compacting the method, and changing the shop from $game_temp to $game_system
  21.                        so it can carry on save files. also create game_interpreter method
  22.                        to shorten the script calls.
  23.  
  24.  introduction:
  25.  this script can make dynamic shop. what is dynamic shop?
  26.  it's shop that the item can be added freely. example usage:
  27.  suikoden game:
  28.  you have armor shop in your castle. then after visiting certain town armor shop...
  29.  your armor shop will sell all armor that town armor shop sell too.
  30.  from v1.1 above... ds games- master of monster lair:
  31.  when you sell weapon/armor in weapon shop. you'll able to buy it in buy list.
  32.  
  33.  v1.1 : added feature to create shop that will add what party sold to buy list.
  34.         can also set the type that will be added (ex: only item, only weapon, only armor)
  35.  v1.2 : added feature for custom type (category) by adding notetags to item/weapon/armor
  36.  
  37.  feature:
  38.  - multiple "dynamic" shop. you can name them
  39.  - add and remove goods to dynamic shop freely
  40.  - can set the shop to behave this way. when the item sold. it will add item
  41.    to buy list. can also set to only add certain category ("ALL","Item","Weapon","Armor")
  42.    and also can set to use custom category assigned in notetags
  43.  
  44.  how to use:
  45.  ===============================================================================
  46.  1)to call dynamic shop. use script call:
  47.  
  48.  d_shop(shop_name,purchase_only,sell_add_goods_type)
  49.  
  50.  shop_name[required] => the name you assign for that dynamic shop
  51.  purchase only => set this to true if you want the shop to cannot sell item
  52.                   default set to false
  53.  sell_add_goods_type => "All" => will add all item/weapon/armor sold to buy list
  54.                         "Item" => will add only item sold to buy list
  55.                         "Weapon" => will add only weapon sold to buy list
  56.                         "Armor" => will add only armor sold to buy list
  57.                         not case sensitive. if left nil/blank it will not add
  58.                         anything to buy list
  59.                        
  60.                         you could also create your custom category
  61.                         by adding notetags to item/weapon/armor. example in item1
  62.                         we add notetags:
  63.                         <shop_cat: potion>
  64.                         notetags not needed to case sensitive with category.
  65.                         then when we set sell_add_goods_type to "Potion" then
  66.                         when we sell item1. it will add it to buy list. other item don't
  67.                        
  68.                         and of course we have reserved word not to use:
  69.                         all, item, weapon, armor, none
  70.                        
  71.  some example usage:
  72.  -) since only shop_name is required you can skip the other
  73.  d_shop("Castle Ugly Shop")
  74.  will call "Castle Ugly Shop" and party can sell items.
  75.  if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
  76.  
  77.  -) can set the sold item to added to buy list
  78.  d_shop("Castle Ugly Shop",false,"ALL")
  79.  will call "Castle Ugly Shop" and party can sell items.
  80.  if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
  81.  then every item/weapon/armor sold will added to buy list.
  82.  
  83.  -) can set to add only "item" sold to added to buy list. weapon and armor not
  84.  d_shop("Castle Ugly Shop",false,"Item")
  85.  will call "Castle Ugly Shop" and party can sell items.
  86.  if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
  87.  then every item (only) sold will added to buy list. weapon and armor will be ignored
  88.  
  89.  -) can use custom category you defined in notetags.
  90.  d_shop("Castle Ugly Shop",false,"Sword")
  91.  will call "Castle Ugly Shop" and party can sell items.
  92.  if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
  93.  then every item/weapon/armor that have notetags <shop_cat: sword>
  94.  sold will added to buy list.
  95.    
  96.  ===============================================================================
  97.  
  98.  2)to add goods to your dynamic shop.
  99.  
  100.  use this script call:
  101.  
  102.  d_shop_add_goods(shop_name,goods,price)
  103.  
  104.  shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
  105.  goods [required] => item you want to add for example $data_items[1], $data_weapons[1], $data_armors[1], etc.
  106.  price => if you want to set the price. if blank it will use default price set in database
  107.  
  108.  example usage:
  109.  d_shop_add_goods("Goldsmith",$data_weapons[10],1000)
  110.  will add to "Goldsmith" shop. weapon id 10 in database. with the price 1000.
  111.  
  112.  ===============================================================================
  113.  
  114.  3) to remove goods for you dynamic shop.
  115.  
  116.  use this script call:
  117.  
  118.  d_shop_rem_goods(shop_name,goods)
  119.  
  120.  shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
  121.  goods [required] => item you want to remove for example $data_items[1], $data_weapons[1], $data_armors[1], etc.
  122.  
  123.  example usage:
  124.  d_shop_rem_goods("Goldsmith",$data_weapons[10])
  125.  will remove weapon id 10 in database from "Goldsmith" shop.
  126.  
  127.  ===============================================================================
  128.  
  129.  4) profit $$$
  130.  
  131.  ===============================================================================
  132.  
  133.  i also set that whenever you add item/weapon/armor to certain dynamic shop.
  134.  it will search for that shop goods. if it contain same item/weapon/armor it will
  135.  be overwritten. so if you first add item1 for 100 gold. shop will sell it for 100 gold
  136.  later you add item1 for 10 gold. then the price will be changed to 10 gold.
  137.  
  138.  Author Note
  139.  none
  140.  
  141. =end
  142.  
  143. class Game_System
  144.   attr_accessor :dynamic_shop
  145.   alias est_dynamic_shop_game_temp_init initialize
  146.   def initialize
  147.     est_dynamic_shop_game_temp_init
  148.     @dynamic_shop = {}
  149.   end
  150. end
  151.  
  152. class Game_Interpreter
  153.   def d_shop(shop_name,purchase_only = false, sell_add_goods_type = nil)
  154.     ESTRIOLE.call_special_shop(shop_name,purchase_only, sell_add_goods_type)
  155.   end
  156.   def d_shop_add_goods(shop_name,goods,price=nil)
  157.     ESTRIOLE.shop_add_goods(shop_name,goods,price)
  158.   end
  159.   def d_shop_rem_goods(shop_name,goods)
  160.     ESTRIOLE.shop_rem_goods(shop_name,goods)
  161.   end
  162.   def d_shop_reset_all
  163.     ESTRIOLE.shop_reset_all
  164.   end
  165.   def d_shop_reset(shop_name)
  166.     ESTRIOLE.shop_reset(shop_name)
  167.   end
  168. end
  169.  
  170. module ESTRIOLE
  171.   def self.call_special_shop(shop_name,purchase_only = false, sell_add_goods_type = nil)
  172.     goods = $game_system.dynamic_shop[shop_name]
  173.     goods = [] if !goods
  174.     SceneManager.call(Scene_Shop)
  175.     SceneManager.scene.prepare(goods, purchase_only)
  176.     SceneManager.scene.sell_add_new_goods(shop_name,sell_add_goods_type) if sell_add_goods_type
  177.   end
  178.  
  179.   def self.shop_add_goods(shop_name,goods,price=nil)
  180.     id = goods.id
  181.     type = 0 if goods.is_a?(RPG::Item)
  182.     type = 1 if goods.is_a?(RPG::Weapon)
  183.     type = 2 if goods.is_a?(RPG::Armor)
  184.    
  185.     use_def_price = price.nil?? 0 : 1
  186.     specify_price = price.nil?? 0 : price
  187.     flag = false
  188.    
  189.     array = [type,id,use_def_price,specify_price,flag]
  190.    
  191.     $game_system.dynamic_shop[shop_name] = [] if !$game_system.dynamic_shop[shop_name]
  192.     old_goods = false
  193.    
  194.       $game_system.dynamic_shop[shop_name].each do |item|
  195.       item = array if item[0] == type && item[1] == id
  196.       old_goods = true if item[0] == type && item[1] == id
  197.       end
  198.     return if @old_goods
  199.     $game_system.dynamic_shop[shop_name].push(array) if !chk = old_goods rescue false
  200.   end
  201.    
  202.   def self.shop_rem_goods(shop_name,goods)
  203.     id = goods.id
  204.     type = 0 if goods.is_a?(RPG::Item)
  205.     type = 1 if goods.is_a?(RPG::Weapon)
  206.     type = 2 if goods.is_a?(RPG::Armor)
  207.     $game_system.dynamic_shop[shop_name] = [] if !$game_system.dynamic_shop[shop_name]
  208.       $game_system.dynamic_shop[shop_name].each do |item|
  209.       $game_system.dynamic_shop[shop_name].delete(item) if item[0] == type && item[1] == id
  210.       end
  211.   end
  212.      
  213.   def self.shop_reset_all
  214.   $game_system.dynamic_shop={}
  215.   end
  216.  
  217.   def self.shop_reset(shop_name)
  218.   $game_system.dynamic_shop[shop_name]=[]
  219.   end  
  220. end
  221.  
  222. class Window_ShopBuy < Window_Selectable
  223.   def data_list;return @data;end
  224.   def add_new_goods(goods)
  225.     id = goods.id
  226.     type = 0 if goods.is_a?(RPG::Item)
  227.     type = 1 if goods.is_a?(RPG::Weapon)
  228.     type = 2 if goods.is_a?(RPG::Armor)
  229.     array = [type,goods.id,0,0,false]
  230.     old_goods = false
  231.     @shop_goods.each do |item|
  232.       item = array if item[0] == type && item[1] == id
  233.       old_goods = true if item[0] == type && item[1] == id      
  234.     end
  235.     return if @old_goods
  236.     @shop_goods.push(array)
  237.   end
  238. end
  239.  
  240. class Scene_Shop < Scene_MenuBase
  241.   def sell_add_new_goods(shop_name,category = "None")
  242.     @sell_add_new_goods = shop_name
  243.     @shop_dynamic_category = category
  244.   end
  245.  
  246.   alias est_dynamic_shop_do_sell do_sell
  247.   def do_sell(number)
  248.     est_dynamic_shop_do_sell(number)
  249.     return if !@sell_add_new_goods
  250.     case @shop_dynamic_category.upcase
  251.     when "ALL"
  252.       ESTRIOLE.shop_add_goods(@sell_add_new_goods,@item)
  253.       add_new_item = true
  254.     when "ITEM"
  255.       ESTRIOLE.shop_add_goods(@sell_add_new_goods,@item) if @item.is_a?(RPG::Item)
  256.       add_new_item = true if @item.is_a?(RPG::Item)
  257.     when "WEAPON"
  258.       ESTRIOLE.shop_add_goods(@sell_add_new_goods,@item) if @item.is_a?(RPG::Weapon)
  259.       add_new_item = true if @item.is_a?(RPG::Weapon)
  260.     when "ARMOR"
  261.       ESTRIOLE.shop_add_goods(@sell_add_new_goods,@item) if @item.is_a?(RPG::Armor)
  262.       add_new_item = true if @item.is_a?(RPG::Armor)
  263.     else
  264.       ESTRIOLE.shop_add_goods(@sell_add_new_goods,@item) if @shop_dynamic_category.upcase == @item.shop_category
  265.       add_new_item = true if @shop_dynamic_category.upcase == @item.shop_category
  266.     end
  267.    
  268.     @buy_window.add_new_goods(@item) if !@buy_window.data_list.include?(@item) && add_new_item
  269.     @buy_window.refresh
  270.   end
  271. end
  272.  
  273. class RPG::BaseItem
  274.   def shop_category
  275.     if @shop_category.nil?
  276.       if @note =~ /<shop_cat: (.*)>/i
  277.         @shop_category = $1.to_s.upcase
  278.       else
  279.         @shop_category = nil
  280.       end
  281.     end
  282.     @shop_category
  283.   end  
  284. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement