Advertisement
FlipelyFlip

Extended Shop Prices v1.0

Apr 27th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.92 KB | None | 0 0
  1. #===============================================================================
  2. #                           FLIPELYFLIP CREATIONS
  3. #-------------------------------------------------------------------------------
  4. #
  5. #                         Extended Shop Prices v1.0
  6. #                              by FlipelyFlip
  7. #
  8. #-------------------------------------------------------------------------------
  9. #  What does this script do?
  10. #  -------------------------
  11. #  This script allows you to define automaticly while the game is running.
  12. #  It dyes the name in the defined colors if it's more expensive or cheaper
  13. #  than the standard price.
  14. #
  15. #  How to use?
  16. #  -----------
  17. #  The script itself is plug and play. To use it without any problems,
  18. #  define with the first item in the shop selection the ID of the shop.
  19. #  This is done through the "Specify"-option. This is used to prevent
  20. #  from pushing the standard price down by entering multiple times the
  21. #  same shop.
  22. #
  23. #  Terms of Use?
  24. #  -------------
  25. #  If you use this script for your non-commercial project then only credits
  26. #  needed to give to me. FlipelyFlip is my name.
  27. #  If you want to use this script in your commercial project then please write
  28. #  me an mail to flipely@hotmail.com or write me a pm.
  29. #===============================================================================
  30.  
  31. #===============================================================================
  32. #  ** Module Flip
  33. #-------------------------------------------------------------------------------
  34. #  * Used to define needed variables and includes the main method for the script
  35. #===============================================================================
  36. module Flip
  37.   # COUNTER is used to set the countdown for the price, when it will turn to the
  38.   # standard-price. The counter will count every time one step down, if the
  39.   # item ID and price match. Else it would add it to the hash.
  40.   COUNTER = 5
  41.   # EXPENSIVE_COLOR is used to set the color for the items which are more
  42.   # expensive then the standard-price.
  43.   # Color.new(r,g,b)
  44.   EXPENSIVE_COLOR = Color.new(255,100,100)
  45.   # CHEAPER_COLOR is the same like EXPENSIVE_COLOR but it will be aplied when
  46.   # the item is cheaper than the standard-price
  47.   # Color.new(r,g,b)
  48.   CHEAPER_COLOR = Color.new(100,255,100)
  49.   # USE_LOW_RANGE: if true then it will use a different color if the prices are
  50.   # in a certain range. if false then it only will aply the colors defined above
  51.   USE_LOW_RANGE = true
  52.   # EXPENSIVE_RANGE is the range to whom the EXPENSIVE_MID_RANGE_COLOR will be
  53.   # aplied.
  54.   EXPENSIVE_RANGE = 20 # value is given as per cent
  55.   # CHEAPER_RANGE is the range to whom the CHEAPER_MID_RANGE_COLOR will be
  56.   # aplied.
  57.   CHEAPER_RANGE = 20 # value is given as per cent
  58.   # EXPENSIVE_LOW_RANGE is the range to whom the EXPENSIVE_LOW_RANGE_COLOR will
  59.   # be aplied.
  60.   EXPENSIVE_LOW_RANGE = 10 # value is given as per cent
  61.   # CHEAPER_LOW_RANGE is the range to whom the CHEAPER_LOW_RANGE_COLOR will
  62.   # be aplied.
  63.   CHEAPER_LOW_RANGE = 10 # value is given as per cent
  64.   # EXPENSIVE_MID_RANGE_COLOR is used to set the color to the defined amount if
  65.   # the price is between EXPENSIVE_LOW_RANGE and EXPENSIVE_MID_RANGE.
  66.   # Color.new(r,g,b)
  67.   EXPENSIVE_MID_RANGE_COLOR = Color.new(255,160,160)
  68.   # CHEAPER_MID_RANGE_COLOR is used to set the color to the defined amount if
  69.   # the price is between CHEAPER_LOW_RANGE and CHEAPER_MID_RANGE.
  70.   # Color.new(r,g,b)
  71.   CHEAPER_MID_RANGE_COLOR = Color.new(180,255,180)
  72.   # EXPENSIVE_LOW_RANGE_COLOR is used to set the color to the defined amount if
  73.   # the price is in the EXPENSIVE_LOW_RANGE.
  74.   # Color.new(r,g,b)
  75.   EXPENSIVE_LOW_RANGE_COLOR = Color.new(255,220,220)
  76.   # CHEAPER_LOW_RANGE_COLOR is used to set the color to the defined amount if
  77.   # the price is in the CHEAPER_LOW_RANGE.
  78.   # Color.new(r,g,b)
  79.   CHEAPER_LOW_RANGE_COLOR = Color.new(220,255,220)
  80.  
  81. ################################################################################
  82. #                                                                              #
  83. #          ONLY EDIT BELOW THIS LINE IF YOU KNOW WHAT ARE YOU DOING!!          #
  84. #                                                                              #
  85. ################################################################################
  86.  
  87.   ITEM_COSTS = {} # do not edit
  88.   ARMOR_COSTS = {} # do not edit
  89.   WEAPON_COSTS = {} # do not edit
  90.   ITEM_STANDARD_COST = {} # do not edit
  91.   ARMOR_STANDARD_COST = {} # do not edit
  92.   WEAPON_STANDARD_COST = {} # do not edit
  93.  
  94.   #-----------------------------------------------------------------------------
  95.   # * Pass the costs Away
  96.   #   goodies = shop goods
  97.   #-----------------------
  98.   #   This is used to get the standard-price and count down the counter for the
  99.   #   new prices.
  100.   #-----------------------------------------------------------------------------
  101.   def self.pass_the_costs_away(goodies)
  102.     $new_shop_id = goodies[0][3]
  103.     goodies.delete_at(0)
  104.     if $old_shop_id != $new_shop_id
  105.       for goods in goodies
  106.         case goods[0]
  107.         when 0 # Item
  108.           item = $data_items[goods[1]]
  109.           price = goods[3]
  110.           price = item.price if goods[2] == 0
  111.           if !ITEM_STANDARD_COST.include?(item.id)
  112.             ITEM_STANDARD_COST[item.id] = price
  113.           else
  114.             if price != ITEM_STANDARD_COST[item.id]
  115.               if ITEM_COSTS.include?([item.id,price])
  116.                 ITEM_COSTS[[item.id,price]] -= 1
  117.                 if ITEM_COSTS[[item.id,price]] <= 0
  118.                   ITEM_STANDARD_COST[item.id] = price
  119.                   ITEM_COSTS[[item.id,price]] = COUNTER
  120.                   ITEM_COSTS.each_key { |item_id|
  121.                   if item_id[0] == item.id
  122.                     ITEM_COSTS[item_id] = COUNTER
  123.                   end
  124.                   }
  125.                 end
  126.               else
  127.                 ITEM_COSTS[[item.id,price]] = COUNTER
  128.               end
  129.             end
  130.           end
  131.         when 1 # Weapon
  132.           item = $data_weapons[goods[1]]
  133.           price = goods[3]
  134.           price = item.price if goods[2] == 0
  135.           if !WEAPON_STANDARD_COST.include?(item.id)
  136.             WEAPON_STANDARD_COST[item.id] = price
  137.           else
  138.             if price != WEAPON_STANDARD_COST[item.id]
  139.               if WEAPON_COSTS.include?([item.id,price])
  140.                 WEAPON_COSTS[[item.id,price]] -= 1
  141.                 if WEAPON_COSTS[[item.id,price]] <= 0
  142.                   WEAPON_STANDARD_COST[item.id] = price
  143.                   WEAPON_COSTS[[item.id,price]] = COUNTER
  144.                   WEAPON_COSTS.each_key { |item_id|
  145.                   if item_id[0] == item.id
  146.                     WEAPON_COSTS[item_id] = COUNTER
  147.                   end
  148.                   }
  149.                 end
  150.               else
  151.                 WEAPON_COSTS[[item.id,price]] = COUNTER
  152.               end
  153.             end
  154.           end
  155.         when 2 # Armor
  156.           item = $data_armors[goods[1]]
  157.           price = goods[3]
  158.           price = item.price if goods[2] == 0
  159.           if !ARMOR_STANDARD_COST.include?(item.id)
  160.             ARMOR_STANDARD_COST[item.id] = price
  161.           else
  162.             if price != ARMOR_STANDARD_COST[item.id]
  163.               if ARMOR_COSTS.include?([item.id,price])
  164.                 ARMOR_COSTS[[item.id,price]] -= 1
  165.                 if ARMOR_COSTS[[item.id,price]] <= 0
  166.                   ARMOR_STANDARD_COST[item.id] = price
  167.                   ARMOR_COSTS[[item.id,price]] = COUNTER
  168.                   ARMOR_COSTS.each_key { |item_id|
  169.                   if item_id[0] == item.id
  170.                     ARMOR_COSTS[item_id] = COUNTER
  171.                   end
  172.                   }
  173.                 end
  174.               else
  175.                 ARMOR_COSTS[[item.id,price]] = COUNTER
  176.               end
  177.             end
  178.           end
  179.         end
  180.       end
  181.       $old_shop_id = $new_shop_id
  182.     end
  183.   end
  184. end
  185.  
  186. #==============================================================================
  187. # ** Window_Base
  188. #------------------------------------------------------------------------------
  189. #  This is a super class of all windows within the game.
  190. #==============================================================================
  191.  
  192. class Window_Base < Window
  193.  
  194.   def expensive_color;           Flip::EXPENSIVE_COLOR ;  end;  # Color for  more expensive Items
  195.   def cheaper_color;             Flip::CHEAPER_COLOR ;  end;  # Color for cheaper Items
  196.   def expensive_low_range_color; Flip::EXPENSIVE_LOW_RANGE_COLOR ; end; # Color for low expensive Items
  197.   def cheaper_low_range_color;   Flip::CHEAPER_LOW_RANGE_COLOR ; end; # Color for low cheaper Items
  198.   def expensive_mid_range_color; Flip::EXPENSIVE_MID_RANGE_COLOR ; end; # Color for mid expensive Items
  199.   def cheaper_mid_range_color;   Flip::CHEAPER_MID_RANGE_COLOR  ; end; # Color for mid cheaper Items
  200.  
  201.   #--------------------------------------------------------------------------
  202.   # * Draw Shop Text
  203.   #     Same as draw_text but modified for this script (:
  204.   #     rect = x,y,width,height of the text
  205.   #     text = text which would be written
  206.   #     pos  = position of the text
  207.   #     item = the Item which will be drawn for this time.
  208.   #--------------------------------------------------------------------------
  209.   def draw_shop_text(rect,text,pos,item)
  210.     pricing_color(item)
  211.     contents.draw_text(rect.x,rect.y,rect.width,rect.height,text,pos)
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * Draw Item Name
  215.   #     enabled : Enabled flag. When false, draw semi-transparently.
  216.   #--------------------------------------------------------------------------
  217.   def draw_item_buy_name(item, x, y, enabled = true, width = 172)
  218.     return unless item
  219.     draw_icon(item.icon_index, x, y, enabled)
  220.     pricing_color(item)
  221.     draw_text(x + 24, y, width, line_height, item.name)
  222.   end
  223.  
  224.   #--------------------------------------------------------------------------
  225.   # * Pricing Color
  226.   #     Checks for the right colors to use.
  227.   #--------------------------------------------------------------------------
  228.   def pricing_color(item)
  229.     if item.is_a?(RPG::Item)
  230.       costing = Flip::ITEM_STANDARD_COST[item.id]
  231.     elsif item.is_a?(RPG::Armor)
  232.       costing = Flip::ARMOR_STANDARD_COST[item.id]
  233.     elsif item.is_a?(RPG::Weapon)
  234.       costing = Flip::WEAPON_STANDARD_COST[item.id]
  235.     end
  236.     if price(item) > costing
  237.       pricey = costing * Flip::EXPENSIVE_RANGE  / 100 + costing
  238.       low_pricey = costing * Flip::EXPENSIVE_LOW_RANGE / 100 + costing
  239.       if price(item) >= pricey
  240.         change_color(expensive_color,enable?(item))
  241.       elsif Flip::USE_LOW_RANGE
  242.         if price(item) >= low_pricey && price(item) <= pricey
  243.           change_color(expensive_mid_range_color,enable?(item))
  244.         elsif price(item) <= low_pricey
  245.           change_color(expensive_low_range_color,enable?(item))
  246.         end
  247.       end
  248.     elsif price(item) < costing
  249.       pricey = costing - (costing * Flip::CHEAPER_RANGE / 100)
  250.       low_pricey = costing - (costing * Flip::CHEAPER_LOW_RANGE / 100)
  251.       if price(item) <= pricey
  252.         change_color(cheaper_color,enable?(item))
  253.       elsif Flip::USE_LOW_RANGE
  254.         if price(item) >= pricey && price(item) <= low_pricey
  255.           change_color(cheaper_mid_range_color,enable?(item))
  256.         elsif price(item) >= low_pricey
  257.           change_color(cheaper_low_range_color,enable?(item))
  258.         end
  259.       end
  260.     else
  261.       change_color(normal_color,enable?(item))
  262.     end
  263.   end
  264. end
  265.  
  266. #==============================================================================
  267. # ** Window_ShopCommand
  268. #------------------------------------------------------------------------------
  269. #  This window is for selecting buy/sell on the shop screen.
  270. #==============================================================================
  271.  
  272. class Window_ShopCommand < Window_HorzCommand
  273.   #--------------------------------------------------------------------------
  274.   # * Get Digit Count
  275.   #--------------------------------------------------------------------------
  276.   def col_max
  277.     return 3 if !@purchase_only
  278.     return 2 if @purchase_only
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * Create Command List
  282.   #--------------------------------------------------------------------------
  283.   def make_command_list
  284.     add_command(Vocab::ShopBuy,    :buy)
  285.     add_command(Vocab::ShopSell,   :sell) if !@purchase_only
  286.     add_command(Vocab::ShopCancel, :cancel)
  287.   end
  288. end
  289.  
  290. #==============================================================================
  291. # ** Window_ShopBuy
  292. #------------------------------------------------------------------------------
  293. #  This window displays a list of buyable goods on the shop screen.
  294. #==============================================================================
  295.  
  296. class Window_ShopBuy < Window_Selectable
  297.  
  298.   #--------------------------------------------------------------------------
  299.   # * Object Initialization
  300.   #--------------------------------------------------------------------------
  301.   alias flipitialize initialize
  302.   def initialize(x, y, height, shop_goods)
  303.     Flip.pass_the_costs_away(shop_goods)
  304.     flipitialize(x, y, height, shop_goods)
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Draw Item
  308.   #--------------------------------------------------------------------------
  309.   def draw_item(index)
  310.     item = @data[index]
  311.     rect = item_rect(index)
  312.     draw_item_buy_name(item, rect.x, rect.y, enable?(item))
  313.     rect.width -= 4
  314.     draw_shop_text(rect, price(item), 2, item)
  315.   end
  316. end
  317. ################################################################################
  318. #                                                                              #
  319. #                                 END OF SCRIPT                                #
  320. #                                                                              #
  321. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement