Advertisement
TheoAllen

Theo x richter_h -- Smithing simply upgrade your weapon

Aug 15th, 2013
2,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.92 KB | None | 0 0
  1. # =============================================================================
  2. # Smithing -- Simply Upgrade Your Weapon
  3. # By : TheoAllen feat richter_h
  4. # -----------------------------------------------------------------------------
  5. # Version : 1.1b
  6. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  7. # (English Documentation)
  8. # =============================================================================
  9. ($imported ||= {})[:Theo_Smithing] = true
  10. # =============================================================================
  11. # CHANGE LOGS:
  12. # -----------------------------------------------------------------------------
  13. # 2013.09.08 - Bugfix at attack animation
  14. # 2013.08.18 - Raise compatibility among various script
  15. # 2013.08.16 - Finished script
  16. # 2013.08.15 - Started script
  17. # =============================================================================
  18. =begin
  19.   # --------------------------------------------------------------------------
  20.   Prelude :
  21.   I heard you guys are really obsessed with richter_h's upgrade weapon script
  22.   for RMVX / RGSS2. One of you are desperately bumping the thread request in a
  23.   countless time. Well, I hope with this script may solve your life problems :P
  24.  
  25.   # --------------------------------------------------------------------------
  26.   Introduction :
  27.   This script allow you to upgrade your equipped weapon just like suikoden.
  28.   Well, at least my friend, richter_h said so. I never played suikoden actually
  29.  
  30.   # --------------------------------------------------------------------------
  31.   What are inside this script?
  32.   - Add basic parameter for every weapon in each level. You may change ATK,
  33.     DEF, or even MHP.
  34.   - Change your weapon's name from a simple "Short sword" into "Shorter Sword",
  35.     "Bodycleaver", "Excalibur", or even "Super Awesome Sword"? your choice.
  36.   - Different name means that it also need a different icon and description,
  37.     isn't it? Who knows if a wooden sword suddenly turned into a great hammer
  38.     after upgrade it?
  39.   - Highly customizable vocab. You may change every quotes to your language
  40.   - Customizable color composition.
  41.   - Customizable price formula
  42.  
  43.   # --------------------------------------------------------------------------
  44.   How to use?
  45.   Put this script below material but above main
  46.   To call the smithing menu, write down this following line to script call
  47.   SceneManager.call(Scene_Smith)
  48.  
  49.   Don't forget to edit the extra configurations.
  50.  
  51.   # --------------------------------------------------------------------------
  52.   Terms of use :
  53.   Credit me, TheoAllen. Because rewrite this script for RGSS3 is not that
  54.   simple if you know. And don't forget to credit richter_h as well. He provides
  55.   the basic workflows, so I can rewrite this script for RGSS3.
  56.  
  57.   # --------------------------------------------------------------------------
  58.   Questions :
  59.   Q : Can I add some features for the next upgraded weapon?
  60.   A : No, you can't. I just have no idea how to make user-friendly
  61.       configuration for that feature
  62.   Q : Where's the socket?
  63.   A : After my friend's, richter_h made them for his RGSS2 script, I'll also
  64.       update my script as well.
  65.   Q : Where's the SEs configuration?
  66.   A : Personally, I don't like those SEs when the upgrading is in progress. So
  67.       I remove them. Add by yourself if you dare :v
  68.  
  69. =end
  70. # =============================================================================
  71. # Extra Configurations. Brace yourself, there're a lot of works to do
  72. # =============================================================================
  73. module THEO
  74.   module Smith
  75.   # =========================================================================
  76.   # General settings
  77.   # -------------------------------------------------------------------------
  78.     MenuActor_Size    = 125   # Menu actor width
  79.     GoldWindow_Size   = 125   # Gold window width
  80.     Confirm_Width     = 80    # Yes/No confirmation width
  81.     NotifShowDuration = 200   # Duration for showing notification
  82.   # =========================================================================
  83.    
  84.   # =========================================================================
  85.   # Price Settings
  86.   # -------------------------------------------------------------------------
  87.   # These settings are for price. You may use your custom formula to optimize
  88.   # your upgraded weapon price.
  89.   #
  90.   # The price formula divided by two.
  91.   # - PriceUpgrade = The cost requirement for upgrading the weapon
  92.   # - PriceTrade = The cost formula for shop processing
  93.   #
  94.   # These are provided variables
  95.   # - item_price = the original item price in database
  96.   # - base_price = same as PriceBase
  97.   # - level = The upgraded weapon level
  98.   #
  99.   # Beware, the false formula may causes an error
  100.   # -------------------------------------------------------------------------
  101.     PriceBase     = 10
  102.     PriceUpgrade  = "item_price/2 + (base_price * level)"
  103.     PriceTrade    = "item_price + ((item_price/2) * level)"
  104.   # =========================================================================
  105.  
  106.   # =========================================================================
  107.   # Color Settings :
  108.   # These are for color setting. The color code is same as \C[n] in message
  109.   # -------------------------------------------------------------------------
  110.     module Colour
  111.       Level       = 6   # Level color
  112.       Maxout      = 21  # Maxout color
  113.       Upgradable  = 24  # Upgradable color
  114.     end
  115.   # =========================================================================
  116.   # Smithing Vocabs list :
  117.   # Wanna translate to your languange? Do not hesitate to change these
  118.   # settings.
  119.   # -------------------------------------------------------------------------
  120.     module SVocab
  121.       Cost        = "Cost: "
  122.       Level       = "Lv.%d"
  123.       Upgradable  = "Upgradable"
  124.       Maxout      = "Maxed Out"
  125.       Yes_Confirm = "Yes"
  126.       No_Confirm  = "No"
  127.      
  128.       Select_Weapon   = "Whose weapon will be upgraded?"
  129.       Decide_Weapon   = "Upgrade this weapon?"
  130.       Upgraded_Quote  = "Upgrade complete"
  131.      
  132.       NotifNameChange = "Weapon changed to %s"
  133.       NotifNormal     = "Weapon Improved"
  134.     end
  135.   # ==========================================================================
  136.   # Weapon Upgrade Table (Main Configuration)
  137.   # This is the main course for this script. You may called this an
  138.   # "Upgrade Tree" or "Weapon tree".
  139.   #
  140.   # You must follow the instruction to make sure the script will work.
  141.   # --------------------------------------------------------------------------
  142.    
  143.     W_Upgrade_Table = { # <-- Do not touch this at all cost!
  144.    
  145.     # ------------------------------------------------------------------------
  146.     # Upgrade tree format.
  147.     # ------------------------------------------------------------------------
  148.     # ID => [ <-- opening
  149.     #
  150.     #       [{:symbol => num}, icon_index, name, description],  # Level 2
  151.     #       [{:symbol => num}, icon_index, name, description],  # Level 3
  152.     #       [ <add more here for the next level> ],             # Level 4
  153.     #
  154.     #       ], <-- ending (do not forget to add comma!)
  155.     # ------------------------------------------------------------------------
  156.     # Just a quick guide won't kill yourself :)
  157.     # ------------------------------------------------------------------------
  158.     # ID                = Weapon ID in database.
  159.     #
  160.     # {:symbol => num } = Once you've upgrade your weapon, the parameter will
  161.     #                     change whether it's up or down. Use the symbol to
  162.     #                     represent the status. Here's the list:
  163.     #                     ---------------------------------------------------
  164.     #                     :atk = attack     || :def = defense
  165.     #                     :mat = magic atk  || :mdf = magic defense
  166.     #                     :agi = agility    || :luk = luck
  167.     #                     :mhp = Max HP     || :mmp = Max MP
  168.     #                     ---------------------------------------------------
  169.     #                     And "num" is a number represent to parameter change
  170.     #
  171.     # icon_index        = Represent as icon index. You may look the icon
  172.     #                     index when you open the icon window dialog box and
  173.     #                     see to the bottom left of that window. Use -1 if you
  174.     #                     don't want to change weapon's icon once upgraded.
  175.     #
  176.     # name              = The new name of upgraded weapon. Leave it blank ("")
  177.     #                     if you wanna keep the original name
  178.     #
  179.     # description       = The new description of upgraded weapon. Leave it
  180.     #                     blank ("") if you wanna keep the original description
  181.     #
  182.     # Here's the example :
  183.     # ------------------------------------------------------------------------
  184.       1  => [
  185.             [{:atk => 2,:luk => 2},-1,"",""], # dont forget comma
  186.             [{:atk => 2},-1,"Iron Ax","Upgrade version of Hand ax"],
  187.             [{:atk => 2},-1,"Silver Ax",""],
  188.             ], # dont forget comma
  189.            
  190.      13  => [
  191.             [{:atk => 4, :def => 1 },-1,"Fine Spear","Upgrade version of spear"],
  192.             [{:atk => 10, :def => 10 },-1,"Awesome Spear","It's super awesome"],
  193.             ],
  194.            
  195.      19  => [
  196.             [{:atk => 1, :agi => 3},-1,"Shorter Sword","The shorter version of short sword"],
  197.             [{:atk => 2, :agi => 10},150,"Dagger",""],
  198.             ],
  199.            
  200.     # add more here if it's necessary
  201.    
  202.     # ------------------------------------------------------------------------
  203.     } # <-- Do not touch this at all cost!
  204. # ============================================================================
  205. # Do not ever touch anything pass this line or the risk is yours
  206. # ============================================================================
  207.     Key = {
  208.       :mhp => 0,
  209.       :mmp => 1,
  210.       :atk => 2,
  211.       :def => 3,
  212.       :mat => 4,
  213.       :mdf => 5,
  214.       :agi => 6,
  215.       :luk => 7,
  216.     }
  217.   end
  218. end
  219.  
  220. class RPG::Weapon < RPG::EquipItem
  221.   attr_accessor :level
  222.  
  223.   alias theo_smith_upgrade_init initialize
  224.   def initialize
  225.     theo_smith_upgrade_init
  226.     @level = 1
  227.   end
  228.  
  229.   def clone_data
  230.     original = self
  231.     cloned = RPG::UpgradedWeapon.new
  232.     self.instance_variables.each do |varsym|
  233.       ivar_name = varsym.to_s.gsub(/@/) {""}
  234.       eval("
  235.      if cloned.respond_to?(\"#{ivar_name}\")
  236.        begin
  237.          cloned.#{ivar_name} = original.#{ivar_name}.clone
  238.        rescue
  239.          cloned.#{ivar_name} = original.#{ivar_name}
  240.        end
  241.      end")
  242.     end
  243.     return cloned
  244.   end
  245.  
  246.   def next_weapon
  247.     next_weapon_exist? ? $upgraded_weapons[upgrade_key] : nil
  248.   end
  249.  
  250.   def next_weapon_exist?
  251.     !$upgraded_weapons[upgrade_key].nil?
  252.   end
  253.  
  254.  
  255.   def upgrade_key
  256.     self.id * 100 + (level+1)
  257.   end
  258.  
  259.   def level
  260.     @level ||= 1
  261.   end
  262.  
  263. end
  264.  
  265. class RPG::UpgradedWeapon < RPG::Weapon
  266.   attr_accessor :ori_id
  267.   attr_accessor :upgrade_price
  268.  
  269.   def upgrade_key
  270.     self.ori_id * 100 + (level+1)
  271.   end
  272.  
  273.   def make_price
  274.     item_price = @price
  275.     base_price = THEO::Smith::PriceBase
  276.     @upgrade_price = eval(THEO::Smith::PriceUpgrade)
  277.     @price = eval(THEO::Smith::PriceTrade)
  278.   end
  279.  
  280. end
  281.  
  282. class << DataManager
  283.  
  284.   alias theo_upgrade_smith_game_obj create_game_objects
  285.   def create_game_objects
  286.     theo_upgrade_smith_game_obj
  287.     init_upgraded_weapons
  288.   end
  289.  
  290.   def init_upgraded_weapons
  291.     $upgraded_weapons = {}
  292.     THEO::Smith::W_Upgrade_Table.each do |id, table|
  293.       table.each_with_index do |data,level|
  294.         gen_id = (id*100) + (level+1) # Generated ID
  295.         weapon_check = $upgraded_weapons[gen_id]
  296.         result = nil
  297.         if (level + 1) != 1 && !weapon_check.nil?
  298.           result = weapon_check.clone_data
  299.         else
  300.           result = $data_weapons[id].clone_data
  301.         end
  302.         result.level = level+2
  303.         data[0].each do |param,value|
  304.           param_id = THEO::Smith::Key[param]
  305.           result.params[param_id] += value
  306.         end
  307.         if data[1] > -1
  308.           result.icon_index = data[1]
  309.         end
  310.         result.name = data[2].empty? ? result.name : data[2]
  311.         result.description = data[3].empty? ? result.description : data[3]
  312.         result.ori_id = id
  313.         result.make_price
  314.         gen_id = (id*100) + (level+2)
  315.         result.id = gen_id # Generated ID
  316.         $upgraded_weapons[gen_id] = result
  317.       end
  318.     end
  319.   end
  320.  
  321. end
  322.  
  323. class Game_BaseItem
  324.  
  325.   def upgraded_weapon?
  326.     @class == RPG::UpgradedWeapon
  327.   end
  328.  
  329.   alias theo_smt_upgrade_object object
  330.   def object
  331.     return $upgraded_weapons[@item_id] if upgraded_weapon?
  332.     return theo_smt_upgrade_object
  333.   end
  334.  
  335. end
  336.  
  337. class Game_Party < Game_Unit
  338.  
  339.   alias theo_smith_init_item init_all_items
  340.   def init_all_items
  341.     theo_smith_init_item
  342.     @upgraded_weapons = {}
  343.   end
  344.  
  345.   alias theo_smith_item_container item_container
  346.   def item_container(item_class)
  347.     return @upgraded_weapons if item_class == RPG::UpgradedWeapon
  348.     return theo_smith_item_container(item_class)
  349.   end
  350.  
  351.   alias theo_smith_weapon weapons
  352.   def weapons
  353.     theo_smith_weapon + upgraded_weapons
  354.   end
  355.  
  356.   def upgraded_weapons
  357.     @upgraded_weapons.keys.sort.collect {|id| $upgraded_weapons[id]}
  358.   end
  359.  
  360. end
  361.  
  362. class Window_Base < Window
  363.   SText_Format = "\\C[16]%s\\C[0] : %d → \\C[24]%d\\C[0]"
  364.   def obtain_params_change
  365.     result = []
  366.     @weapon.params.each_with_index do |param,id|
  367.       next_param = @weapon.next_weapon.params[id]
  368.       next if param == next_param
  369.       text = sprintf(SText_Format,Vocab.param(id),param,next_param)
  370.       result.push(text)
  371.     end if @weapon
  372.     return result
  373.   end
  374. end
  375.  
  376. class Window_SmithGold < Window_Gold
  377.   def window_width
  378.     return THEO::Smith::GoldWindow_Size
  379.   end
  380. end
  381.  
  382. class Window_SmithMenu < Window_Selectable
  383.  
  384.   def initialize(x,y)
  385.     super(x,y,window_width,window_height)
  386.     refresh
  387.   end
  388.  
  389.   def window_width
  390.     THEO::Smith::MenuActor_Size
  391.   end
  392.  
  393.   def window_height
  394.     fitting_height(item_max)
  395.   end
  396.  
  397.   def item_max
  398.     $game_party.members.size
  399.   end
  400.  
  401.   def draw_item(index)
  402.     actor = $game_party.members[index]
  403.     color = normal_color
  404.     color.alpha = enable?(index) ? 255 : translucent_alpha
  405.     change_color(color)
  406.     draw_text(item_rect(index),actor.name,alignment)
  407.   end
  408.  
  409.   def alignment
  410.     return 0
  411.   end
  412.  
  413.   def weapon
  414.     $game_party.members[index].equips[0]
  415.   end
  416.  
  417.   def update_help
  418.     @help_window.refresh(weapon)
  419.   end
  420.  
  421.   def enable?(index)
  422.     actor = $game_party.members[index]
  423.     return false if actor.equips[0].nil?
  424.     return actor.equips[0].next_weapon_exist? &&
  425.       $game_party.gold >= actor.equips[0].next_weapon.upgrade_price
  426.   end
  427.  
  428.   def current_item_enabled?
  429.     enable?(index)
  430.   end
  431.  
  432. end
  433.  
  434. class Window_SmithResult < Window_Base
  435.   include THEO::Smith
  436.  
  437.   def next_weapon
  438.     @weapon.next_weapon
  439.   end
  440.  
  441.   def refresh(weapon)
  442.     contents.clear
  443.     @weapon = weapon
  444.     return unless @weapon
  445.     reset_font_settings
  446.     draw_weapon_name
  447.     if @weapon.next_weapon_exist?
  448.       draw_next_weapon
  449.     else
  450.       draw_maxed_out
  451.     end
  452.   end
  453.  
  454.   def draw_weapon_name
  455.     draw_item_name(@weapon,0,0)
  456.     level = sprintf(SVocab::Level,@weapon.level)
  457.     change_color(text_color(Colour::Level))
  458.     draw_text(0,0,contents.width,line_height,level,2)
  459.     contents.fill_rect(0,24,contents.width,2,Color.new(255,255,255,128))
  460.   end
  461.  
  462.   def draw_next_weapon
  463.     ypos = 28
  464.     rect = Rect.new(0,ypos,contents.width,line_height)
  465.     contents.font.size -= 4
  466.     change_color(text_color(Colour::Upgradable))
  467.     draw_text(rect,SVocab::Upgradable,2)
  468.     change_color(system_color)
  469.     draw_text(rect,SVocab::Cost)
  470.     rect.x += text_size(SVocab::Cost).width
  471.     change_color(normal_color)
  472.     draw_text(rect,@weapon.next_weapon.upgrade_price)
  473.     texts = obtain_params_change
  474.     ypos += line_height
  475.     texts.each do |txt|
  476.       draw_text_ex(0,ypos,txt)
  477.       ypos += line_height
  478.     end
  479.   end
  480.  
  481.   def draw_maxed_out
  482.     ypos = 28
  483.     rect = Rect.new(0,ypos,contents.width,line_height)
  484.     contents.font.size -= 4
  485.     change_color(text_color(Colour::Maxout))
  486.     draw_text(rect,SVocab::Maxout,2)
  487.   end
  488.  
  489. end
  490.  
  491. class Window_SmithNotif < Window_Base
  492.  
  493.   def initialize(width,menu_actor,help_window)
  494.     super(0,0,width,0)
  495.     self.openness = 0
  496.     update_placement
  497.     @show_count = -1
  498.     @menu_actor = menu_actor
  499.     @help_window = help_window
  500.   end
  501.  
  502.   def update_placement
  503.     self.x = Graphics.width/2 - self.width/2
  504.     self.y = Graphics.height/2 - self.height/2
  505.   end
  506.  
  507.   def height=(height)
  508.     super
  509.     update_placement
  510.     create_contents
  511.   end
  512.  
  513.   def show_weapon(weapon)
  514.     @weapon = weapon
  515.     @texts = obtain_params_change
  516.     update_height
  517.     refresh
  518.     @show_count = THEO::Smith::NotifShowDuration
  519.   end
  520.  
  521.   def update_height
  522.     self.height = fitting_height(@texts.size + 1)
  523.   end
  524.  
  525.   def refresh
  526.     contents.clear
  527.     rect = Rect.new(0,0,contents.width,line_height)
  528.     next_name = @weapon.next_weapon.name
  529.     if next_name != @weapon.name
  530.       text = sprintf(THEO::Smith::SVocab::NotifNameChange,next_name)
  531.       draw_text(rect,text)
  532.     else
  533.       text = THEO::Smith::SVocab::NotifNormal
  534.       draw_text(rect,text)
  535.     end
  536.     ypos = line_height
  537.     contents.fill_rect(0,ypos-1,contents.width,2,Color.new(255,255,255,128))
  538.     @texts.each do |txt|
  539.       draw_text_ex(0,ypos,txt)
  540.       ypos += line_height
  541.     end
  542.   end
  543.  
  544.   def update
  545.     super
  546.     update_close_input
  547.     if @show_count > 0
  548.       open
  549.     elsif @show_count == 0
  550.       close
  551.     end
  552.   end
  553.  
  554.   def update_close_input
  555.     @show_count -= 1
  556.     @show_count = 0 if Input.trigger?(:C)
  557.   end
  558.  
  559.   def open
  560.     super
  561.     @menu_actor.deactivate
  562.     @help_window.set_text(THEO::Smith::SVocab::Upgraded_Quote)
  563.   end
  564.  
  565.   def close
  566.     super
  567.     @menu_actor.activate
  568.     @help_window.set_text(THEO::Smith::SVocab::Select_Weapon)
  569.   end
  570.  
  571. end
  572.  
  573. class Window_SmithConfirm < Window_Command
  574.  
  575.   def initialize
  576.     super(0,0)
  577.     self.openness = 0
  578.   end
  579.  
  580.   def make_command_list
  581.     vocab = THEO::Smith::SVocab
  582.     add_command(vocab::Yes_Confirm, :yes)
  583.     add_command(vocab::No_Confirm, :no)
  584.   end
  585.  
  586.   def window_width
  587.     return THEO::Smith::Confirm_Width
  588.   end
  589.  
  590. end
  591.  
  592. class Scene_Smith < Scene_MenuBase
  593.   include THEO::Smith::SVocab
  594.  
  595.   def start
  596.     super
  597.     create_help_window
  598.     create_actor_menu
  599.     create_gold_window
  600.     create_smith_result
  601.     create_notif_smith
  602.     create_confirm_window
  603.   end
  604.  
  605.   def create_help_window
  606.     @help_window = Window_Help.new(1)
  607.     @help_window.set_text(Select_Weapon)
  608.   end
  609.  
  610.   def create_actor_menu
  611.     y = @help_window.height
  612.     @menu_actor = Window_SmithMenu.new(0,y)
  613.     @menu_actor.set_handler(:cancel, method(:return_scene))
  614.     @menu_actor.set_handler(:ok, method(:on_actor_ok))
  615.     @menu_actor.activate
  616.     @menu_actor.select(0)
  617.   end
  618.  
  619.   def create_smith_result
  620.     x = @menu_actor.width
  621.     y = @help_window.height
  622.     w = Graphics.width - @menu_actor.width - @gold_window.width
  623.     h = 24 * 9 + 4
  624.     @smith_result = Window_SmithResult.new(x,y,w,h)
  625.     @menu_actor.help_window = @smith_result
  626.   end
  627.  
  628.   def create_gold_window
  629.     @gold_window = Window_SmithGold.new
  630.     @gold_window.x = Graphics.width - @gold_window.width
  631.     @gold_window.y = @help_window.height
  632.   end
  633.  
  634.   def create_notif_smith
  635.     @notif_smith = Window_SmithNotif.new(300,@menu_actor,@help_window)
  636.   end
  637.  
  638.   def create_confirm_window
  639.     @confirm =  Window_SmithConfirm.new
  640.     @confirm.set_handler(:yes, method(:craft_weapon))
  641.     @confirm.set_handler(:no, method(:confirm_no))
  642.     @confirm.set_handler(:cancel, method(:confirm_no))
  643.     @confirm.x = @smith_result.x + @smith_result.width - @confirm.width
  644.     @confirm.y = @smith_result.y + @smith_result.height - @confirm.height
  645.   end
  646.  
  647.   def on_actor_ok
  648.     @confirm.open
  649.     @confirm.activate
  650.     @help_window.set_text(Decide_Weapon)
  651.   end
  652.  
  653.   def confirm_no
  654.     @confirm.close
  655.     @menu_actor.activate
  656.     @help_window.set_text(Select_Weapon)
  657.   end
  658.  
  659.   def craft_weapon
  660.     @confirm.close
  661.     @confirm.deactivate
  662.     $game_party.gain_item(next_weapon,1)
  663.     $game_party.lose_gold(next_weapon.upgrade_price)
  664.     last_equip = item_to_lose
  665.     @notif_smith.show_weapon(last_equip)
  666.     actor.change_equip(0,next_weapon)
  667.     $game_party.lose_item(last_equip,1)
  668.     @menu_actor.update_help
  669.     @menu_actor.activate
  670.     @menu_actor.refresh
  671.     @gold_window.refresh
  672.   end
  673.  
  674.   def next_weapon
  675.     @smith_result.next_weapon
  676.   end
  677.  
  678.   def actor
  679.     $game_party.members[@menu_actor.index]
  680.   end
  681.  
  682.   def item_to_lose
  683.     actor.equips[0]
  684.   end
  685.  
  686. end
  687.  
  688. class Game_Actor < Game_Battler
  689.   def weapons
  690.     @equips.select {|item| item.is_weapon? ||
  691.     item.upgraded_weapon? }.collect {|item| item.object }
  692.   end
  693. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement