Advertisement
Vlue

Appraisal Shop

Mar 24th, 2014
1,999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.73 KB | None | 0 0
  1. #--# Appraisal Shop v 1.1a
  2. #
  3. # Allows you to create unidentified items that can be appraised for a cost
  4. #  in a special shop, or an option to appraise them at no cost from the
  5. #  inventory. Includes support for W/A Randomization.
  6. #
  7. # Usage: Plug and play, customize and set up note tags as needed.
  8. #
  9. #   SceneManager.call(Scene_Appraise) - calls the appraisal shop
  10. #
  11. #   Notetags determine what an unidentified item identifies into:
  12. #     <APPRAISE COST ##> where ## is the cost to appraise the item
  13. #     <APPRAISE id rarity> where id is the item id, and rarity is the chance
  14. #    Items identify into items, weapons into weapons, etc.
  15. #
  16. #------#
  17. #-- Script by: V.M of D.T
  18. #
  19. #- Questions or comments can be:
  20. #    given by email: sumptuaryspade@live.ca
  21. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  22. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  23. #
  24. #--- Free to use in any project, commercial or non-commercial, with credit given
  25. #--Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  26.  
  27. $imported = {} if $imported.nil?
  28. $imported[:Vlue_Appraisal] = true
  29.  
  30. #SE to be played upon appraisal
  31. APPRAISAL_SE = "Chime2"
  32. #Whether or not appraisal can be done in the menu
  33. APPRAISE_IN_MENU = true
  34. #Hide ingredient names? (set to :discover to reaveal names on identify)
  35. HIDE_INGREDIENT_NAMES = :discover
  36. #Whether or not to hide ingredient chance
  37. HIDE_INGREDIENT_NUMBERS = :discover
  38.  
  39. class RPG::BaseItem
  40.   def appraisal_list
  41.     appraise = {}
  42.     list = self.note.clone
  43.     while list =~ /<APPRAISE (\d+) (\d+)>/
  44.       appraise[$1.to_i] = $2.to_i
  45.       list[list.index("<APPRAISE")] = "N"
  46.     end
  47.     appraise
  48.   end
  49.   def appraise_cost
  50.     note =~ /<APPRAISE COST (\d+)>/
  51.     return 0 if !$~
  52.     return $1.to_i
  53.   end
  54. end
  55.  
  56. class Scene_Appraise < Scene_Base
  57.   def start
  58.     super
  59.     @random = Module.const_defined?(:AFFIXES)
  60.     @help_window = Window_Help.new
  61.     @gold_window = Window_Gold.new
  62.     @gold_window.width = Graphics.width/2
  63.     @gold_window.x = Graphics.width - @gold_window.width
  64.     @gold_window.y = Graphics.height - @gold_window.height
  65.     @window_command = Window_AppCommand.new
  66.     @window_command.set_handler(:on_ok, method(:command_ok))
  67.     @window_command.set_handler(:on_cancel, method(:command_cancel))
  68.     @window_command.set_handler(:cancel, method(:command_cancel))
  69.     @window_list = Window_AppList.new
  70.     @window_list.set_handler(:ok, method(:list_ok))
  71.     @window_list.set_handler(:cancel, method(:list_cancel))
  72.     @window_detail = Window_AppDetail.new
  73.     @window_popup = Window_AppPopup.new
  74.     @window_popup.set_handler(:ok, method(:popup_ok))
  75.     @window_popup.set_handler(:cancel, method(:popup_ok))
  76.     @window_confirm = Window_AppConfirm.new
  77.     @window_confirm.set_handler(:on_ok, method(:confirm_ok))
  78.     @window_confirm.set_handler(:on_cancel, method(:confirm_cancel))
  79.     @window_confirm.set_handler(:cancel, method(:confirm_cancel))
  80.     @window_command.activate
  81.   end
  82.   def update
  83.     super
  84.     if @window_list.active && !@window_list.current_item.nil?
  85.       @window_detail.item = @window_list.current_item
  86.       @help_window.set_text(@window_list.current_item.description)
  87.     end
  88.   end
  89.   def command_ok
  90.     @window_list.select(0)
  91.     @window_list.activate
  92.   end
  93.   def command_cancel
  94.     SceneManager.return
  95.   end
  96.   def list_ok
  97.     @window_confirm.activate
  98.   end
  99.   def list_cancel
  100.     @window_command.activate
  101.     @window_list.select(-1)
  102.     @window_detail.contents.clear
  103.   end
  104.   def confirm_ok
  105.     Audio.se_play("/Audio/SE/"+APPRAISAL_SE,100,100)
  106.     item = @window_list.current_item
  107.     $game_party.lose_gold(item.appraise_cost)
  108.     $game_party.lose_item(item,1)
  109.     random_pick = []
  110.     item.appraisal_list.each do |id, value|
  111.       value.times do |i|
  112.         random_pick.push(id)
  113.       end
  114.     end
  115.     if item.is_a?(RPG::Item)
  116.       nitem = $data_items[random_pick[rand(random_pick.size)]]
  117.       nitem = $game_party.add_item(nitem.id,1) if @random
  118.     elsif item.is_a?(RPG::Weapon)
  119.       nitem = $data_weapons[random_pick[rand(random_pick.size)]]
  120.       nitem = $game_party.add_weapon(nitem.id,1) if @random
  121.     elsif item.is_a?(RPG::Armor)
  122.       nitem = $data_armors[random_pick[rand(random_pick.size)]]
  123.       nitem = $game_party.add_armor(nitem.id,1) if @random
  124.     end
  125.     $game_party.gain_item(nitem,1) if !@random
  126.     @window_popup.set_text(nitem)
  127.     @gold_window.refresh
  128.     @window_list.refresh
  129.     @window_popup.activate
  130.   end
  131.   def confirm_cancel
  132.     @window_list.activate
  133.   end
  134.   def popup_ok
  135.     @window_popup.deactivate
  136.     @window_popup.close
  137.     @window_list.select(0)
  138.     @window_list.activate
  139.   end
  140. end
  141.  
  142. class Window_AppCommand < Window_HorzCommand
  143.   def initialize
  144.     super(0,72)
  145.   end
  146.   def item_width
  147.     width / 2 - padding * 2
  148.   end
  149.   def window_width
  150.     Graphics.width
  151.   end
  152.   def window_height
  153.     48
  154.   end
  155.   def make_command_list
  156.     add_command("Appraise",:on_ok)
  157.     add_command("Cancel",:on_cancel)
  158.   end
  159. end
  160.  
  161. class Window_AppList < Window_ItemList
  162.   def initialize
  163.     super(0,120,Graphics.width/2,Graphics.height-120)
  164.     @category = :item
  165.     refresh
  166.   end
  167.   def include?(item)
  168.     item && !item.appraisal_list.empty?
  169.   end
  170.   def current_item
  171.     @data[index]
  172.   end
  173.   def enable?(item)
  174.     return false if item.nil?
  175.     !item.appraisal_list.empty? && item.appraise_cost <= $game_party.gold
  176.   end
  177.   def col_max; 1; end
  178. end
  179.  
  180. class Window_AppDetail < Window_Base
  181.   def initialize
  182.     super(Graphics.width/2,120,Graphics.width/2,Graphics.height-168)
  183.   end
  184.   def item=(item)
  185.     @item = item
  186.     refresh
  187.   end
  188.   def refresh
  189.     contents.clear
  190.     change_color(system_color)
  191.     draw_text(0,0,contents.width,24,"Appraisal Cost:")
  192.     draw_text(0,line_height*2,contents.width,24,"Outcome:")
  193.     return unless @item
  194.     !@item.appraisal_list.empty? ? self.contents_opacity = 255 : self.contents_opacity = 150
  195.     draw_currency_value(@item.appraise_cost,Vocab::currency_unit,0,line_height,contents.width)
  196.     max = 0;yy = line_height*3
  197.     @item.appraisal_list.values.each do |i|
  198.       max += i
  199.     end
  200.     change_color(normal_color)
  201.     @item.appraisal_list.each do |id, value|
  202.       item = $data_items[id] if @item.is_a?(RPG::Item)
  203.       item = $data_weapons[id] if @item.is_a?(RPG::Weapon)
  204.       item = $data_armors[id] if @item.is_a?(RPG::Armor)
  205.       name = item.name
  206.       name = "????" if HIDE_INGREDIENT_NAMES == true
  207.       if HIDE_INGREDIENT_NAMES == :discover && !$game_party.item_discovered?(item)
  208.         name = "????"
  209.       end
  210.       draw_text(0,yy,contents.width,24,name)
  211.       val = (value/max.to_f*100).to_i.to_s
  212.       val = "??" if HIDE_INGREDIENT_NUMBERS == true
  213.       if HIDE_INGREDIENT_NUMBERS == :discover && !$game_party.item_discovered?(item)
  214.         val = "??"
  215.       end
  216.       draw_text(0,yy,contents.width,24,val+"%",2)
  217.       yy += line_height
  218.     end
  219.   end
  220. end
  221.  
  222. class Window_AppConfirm < Window_Command
  223.   def initialize
  224.     super(Graphics.width/2-window_width/2,Graphics.height/2-window_height/2)
  225.     self.openness = 0
  226.     deactivate
  227.   end
  228.   def window_width
  229.     120
  230.   end
  231.   def window_height
  232.     72
  233.   end
  234.   def make_command_list
  235.     add_command("Appraise",:on_ok)
  236.     add_command("Cancel",:on_cancel)
  237.   end
  238.   def activate
  239.     open
  240.     super
  241.   end
  242.   def deactivate
  243.     close
  244.     super
  245.   end
  246.   def process_ok
  247.     if current_item_enabled?
  248.       Input.update
  249.       deactivate
  250.       call_ok_handler
  251.     else
  252.       Sound.play_buzzer
  253.     end
  254.   end
  255. end
  256.  
  257. class Window_AppPopup < Window_Selectable
  258.   def initialize
  259.     super(Graphics.width/2-window_width/2,Graphics.height/2-window_height/2,120,48)
  260.     self.openness = 0
  261.     deactivate
  262.   end
  263.   def window_width; 120; end
  264.   def window_height; 49; end
  265.   def refresh; end;
  266.   def set_text(item)
  267.     contents.clear
  268.     text1, text2 = item.name, " identified!"
  269.     width = contents.text_size(text1 + text2).width
  270.     self.width = width + padding*2
  271.     self.x = Graphics.width/2-width/2
  272.     create_contents
  273.     $imported[:Vlue_WARandom] ? color = item.color : color = normal_color
  274.     change_color(color)
  275.     draw_text(24,1,contents.width,24,text1)
  276.     change_color(normal_color)
  277.     draw_text(24+contents.text_size(text1).width,1,contents.width,24,text2)
  278.     draw_icon(item.icon_index,0,0)
  279.     open
  280.   end
  281.   def process_ok
  282.     if current_item_enabled?
  283.       Input.update
  284.       deactivate
  285.       call_ok_handler
  286.     else
  287.       Sound.play_buzzer
  288.     end
  289.   end
  290. end
  291.  
  292. class Scene_ItemBase
  293.   alias app_start start
  294.   def start
  295.     app_start
  296.     @random = Module.const_defined?(:AFFIXES)
  297.     @window_popup = Window_AppPopup.new
  298.     @window_popup.set_handler(:ok, method(:popup_ok))
  299.     @window_popup.set_handler(:cancel, method(:popup_ok))
  300.     @window_confirm = Window_AppConfirm.new
  301.     @window_confirm.set_handler(:on_ok, method(:confirm_ok))
  302.     @window_confirm.set_handler(:on_cancel, method(:confirm_cancel))
  303.     @window_confirm.set_handler(:cancel, method(:confirm_cancel))
  304.     @window_popup.z = @window_confirm.z = 201
  305.   end
  306.   def popup_ok
  307.     @window_popup.deactivate
  308.     @window_popup.close
  309.     activate_item_window
  310.   end
  311.   def confirm_ok
  312.     identify_item
  313.   end
  314.   def confirm_cancel
  315.     activate_item_window
  316.   end
  317.   def determine_item
  318.     if item.for_friend?
  319.       show_sub_window(@actor_window)
  320.       @actor_window.select_for_item(item)
  321.     else
  322.       if !item.appraisal_list.empty? && APPRAISE_IN_MENU
  323.         @window_confirm.activate
  324.       else
  325.         use_item
  326.         activate_item_window
  327.       end
  328.     end
  329.   end
  330.   def identify_item
  331.     Audio.se_play("/Audio/SE/"+APPRAISAL_SE,100,100)
  332.     $game_party.lose_item(item,1)
  333.     random_pick = []
  334.     item.appraisal_list.each do |id, value|
  335.       value.times do |i|
  336.         random_pick.push(id)
  337.       end
  338.     end
  339.     if item.is_a?(RPG::Item)
  340.       sitem = $data_items[random_pick[rand(random_pick.size)]]
  341.       sitem = $game_party.add_item(sitem.id,1) if @random
  342.     elsif item.is_a?(RPG::Weapon)
  343.       sitem = $data_weapons[random_pick[rand(random_pick.size)]]
  344.       sitem = $game_party.add_weapon(sitem.id,1) if @random
  345.     elsif item.is_a?(RPG::Armor)
  346.       sitem = $data_armors[random_pick[rand(random_pick.size)]]
  347.       sitem = $game_party.add_armor(sitem.id,1) if @random
  348.     end
  349.     $game_party.gain_item(sitem,1) if !@random
  350.     @window_popup.set_text(sitem)
  351.     @window_popup.activate
  352.   end
  353.   def item_usable?
  354.     if APPRAISE_IN_MENU
  355.       if item.appraisal_list.empty?
  356.         return user.usable?(item) && item_effects_valid?
  357.       else
  358.         return true
  359.       end
  360.     else
  361.       return user.usable?(item) && item_effects_valid?
  362.     end
  363.   end
  364. end
  365.  
  366. class Game_Party
  367.   attr_accessor :appraise_discovery
  368.   alias app_init initialize
  369.   alias app_gain_item gain_item
  370.   def initialize
  371.     app_init
  372.     @app_disc_item = {}
  373.     @app_disc_weapon = {}
  374.     @app_disc_armor = {}
  375.   end
  376.   def item_discovered?(item)
  377.     array = @app_disc_item if item.is_a?(RPG::Item)
  378.     array = @app_disc_weapon if item.is_a?(RPG::Weapon)
  379.     array = @app_disc_armor if item.is_a?(RPG::Armor)
  380.     array[item.id] ? true : false
  381.   end
  382.   def gain_item(item, amount, *args)
  383.     app_gain_item(item, amount, *args)
  384.     return unless item
  385.     $imported[:Vlue_WARandom] ? id = item.original_id : id = item.id
  386.     @app_disc_item[id] = true if amount > 0 && item.is_a?(RPG::Item)
  387.     @app_disc_weapon[id] = true if amount > 0 && item.is_a?(RPG::Weapon)
  388.     @app_disc_armor[id] = true if amount > 0 && item.is_a?(RPG::Armor)
  389.   end
  390.   def usable?(item)
  391.     return false if item.nil?
  392.     return true if !item.appraisal_list.empty? && APPRAISE_IN_MENU
  393.     members.any? {|actor| actor.usable?(item) }
  394.   end
  395. end
  396.  
  397. class RPG::BaseItem
  398.   def for_friend?
  399.   end
  400. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement