Guest User

Falcao Mana Stones Enchantment 1.6

a guest
Oct 22nd, 2012
1,909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.58 KB | None | 0 0
  1. #==============================================================================#
  2. #  #*****************#                                                         #
  3. #  #*** By Falcao ***#          * Falcao Mana Stones Enchants 1.6              #
  4. #  #*****************#          This script allows you to enchants, weapons and#
  5. #                               armors in order to increase the actor stats.   #
  6. #       RMVXACE                                                                #
  7. #                               Date: October 22 2012                          #
  8. #                                                                              #
  9. # Falcao RGSS site:  http://falcaorgss.wordpress.com                           #
  10. # Falcao Forum site: http://makerpalace.com                                    #
  11. #==============================================================================#
  12. # 1.6 change log
  13. # - Fixed crash when mana stones are destroyed before the socketing process
  14. #
  15. # 1.5 change log
  16. # - Added new stand alone GUI
  17. # - Fixed bug when you set the DefaultSockets to cero and unequipp a weapon/armo
  18. # - Mana stones container expanded on more line
  19. #-------------------------------------------------------------------------------
  20. # * Installation
  21. # Copy and paste the script above main, no methods where overwritten so
  22. # compatibility is very hight.
  23. #-------------------------------------------------------------------------------
  24. # * Features
  25. # - Weapons and Armors enchantment enabled
  26. # - Weapons and armors can have as many mana stones slots you want.
  27. # - When soketing the actor stats increase according to especified mana stone
  28. # - Mana stones are created with a simple note tag
  29. # - Chance to Fail the enchantment process
  30. # - If mana stones enchants fail all socketed mana stones are destroyed.
  31. # - A user friendly GUI.
  32. #
  33. # Note: weapons and armors are concidered uniques, so if you have more than one
  34. # weapon of the same id, the mana stones apply to all of them
  35. #
  36. #-------------------------------------------------------------------------------
  37. # * Usage
  38. #
  39. # Mana stones are socketed in the equippment window scene by pressing 'A' key,
  40. # weapon / armor must be equipped in order to start enchanting
  41. #
  42. # Tag weapons and armors with
  43. # <sockets: x>      - Change x for the number of sockets you want
  44. #
  45. # Tag Items with (this items would be the mana stones)
  46. # <mana_mhp: x>
  47. # <mana_mmp: x>
  48. # <mana_atk: x>
  49. # <mana_def: x>       => Change x for the param amount to add
  50. # <mana_mat: x>
  51. # <mana_mdf: x>
  52. # <mana_agi: x>
  53. # <mana_luk: x>
  54. #
  55. # <socket_chance: x>  Change x for the socket chance, it may be a number between
  56. #                     0 and 100. if you dont especified this defaults apply.
  57. #
  58. # Note: the chance is measured from a number between 0 and 100, you cannot
  59. # put a number greater than 100. where 100 = 100% chance, when 0 = 0 %chance
  60. #-------------------------------------------------------------------------------
  61. # * License
  62. # For non-comercial games only, for comercial games contact me:
  63. # falmc99@gmail.com
  64. #-------------------------------------------------------------------------------
  65.  
  66. module FalMana
  67.  
  68.   # Deafault sockets for weapons and armors, set 0 if you dont want defaults
  69.   DefaultSockets = 1
  70.  
  71.   # Default enchantsment chance (a percent between 0 and 100)
  72.   DefaultChance = 80
  73.  
  74.   # Sound played while socketing mana stones
  75.   SoketingSe = "Heal6"
  76.  
  77.   # Sound played when success socketing
  78.   SocketSuccessSe = "Decision2"
  79.  
  80.   # Sound played when fail socketing
  81.   SocketFailSe = "Down1"
  82.  
  83.   # Sound played when clearing socket
  84.   ClearSocketSe = "Equip3"
  85.  
  86. #-------------------------------------------------------------------------------
  87.   def self.stones(actor)
  88.     @actor = actor
  89.     SceneManager.call(Scene_ManaStones)
  90.   end
  91.  
  92.   def self.actor ; @actor ; end
  93.  
  94.   def self.socket_manastone(item, index, value, actor)
  95.     item.manaslots[index] = value
  96.     actor.add_param(value.manastone_param[0], value.manastone_param[1])
  97.   end
  98.  
  99.   def self.remove_manastone(item, index, value, actor)
  100.     item.manaslots[index] = nil
  101.     actor.add_param(value.manastone_param[0], - value.manastone_param[1])
  102.   end
  103.  
  104.   def self.clear_manastones(item, actor)
  105.     item.manaslots.each {|m| actor.add_param(m.manastone_param[0],
  106.     - m.manastone_param[1]) unless m.nil?}
  107.     item.manaslots.size.times {|i| item.manaslots[i] = nil}
  108.   end
  109.  
  110.   def self.add_param(actor, item, sub=false)
  111.     return if item.nil?
  112.     return if item.manaslots.nil?
  113.      item.manaslots.each {|m| actor.add_param(m.manastone_param[0],
  114.      sub ? - m.manastone_param[1] : m.manastone_param[1]) unless m.nil?}
  115.   end
  116. end
  117.  
  118. # Game system: Register mana stones values
  119. class Game_System
  120.   attr_reader   :weapon_slots, :armor_slots
  121.   alias falcaomana_slots_ini initialize
  122.   def initialize
  123.     @weapon_slots = {}
  124.     @armor_slots = {}
  125.     dataslots_ini(@weapon_slots, $data_weapons)
  126.     dataslots_ini(@armor_slots, $data_armors)
  127.     falcaomana_slots_ini
  128.   end
  129.  
  130.   def dataslots_ini(operand, item)
  131.     for kind in item
  132.       next if kind.nil?
  133.       if kind.given_sl != nil
  134.         data = []
  135.         kind.given_sl.times {|i| data.push(nil)}
  136.         operand[kind.id] = data
  137.       end
  138.     end
  139.   end
  140. end
  141.  
  142. # Scene_Equip: main mana stones socketing system
  143. class Scene_Equip < Scene_MenuBase
  144.   def update
  145.     super
  146.     update_manacalling
  147.   end
  148.  
  149.   def update_manacalling
  150.     update_enchant_help
  151.     if Input.trigger?(:X)
  152.       FalMana.stones(@actor)
  153.       Sound.play_ok
  154.     end
  155.   end
  156.  
  157.   def update_enchant_help
  158.     @help_window.contents.font.size = Font.default_size
  159.     @help_window.refresh
  160.     @help_window.contents.font.size = 18
  161.     @help_window.draw_text(-22,22,@help_window.width,32, 'Press A to enchant',2)
  162.   end
  163. end
  164.  
  165. # RPG::EquipItem: get slots data for each weapon and armor
  166. class RPG::EquipItem < RPG::BaseItem
  167.   def given_sl
  168.     @note =~ /<sockets: (.*)>/i ? n = $1.to_i : n = nil
  169.     n = FalMana::DefaultSockets if n.nil? and FalMana::DefaultSockets > 0
  170.     return n
  171.   end
  172.  
  173.   def manaslots
  174.     self.is_a?(RPG::Weapon) ? i = $game_system.weapon_slots[self.id] :
  175.     i = $game_system.armor_slots[self.id]
  176.     return i
  177.   end
  178. end
  179.  
  180. # RPG::Item: Mana stones item definition
  181. class RPG::Item < RPG::UsableItem
  182.   def socket_chance
  183.     @note =~ /<socket_chance: (.*)>/i ? n = $1.to_i : n = FalMana::DefaultChance
  184.     return n
  185.   end
  186.  
  187.   def manastone_param
  188.     param = [0, $1.to_i] if @note =~ /<mana_mhp: (.*)>/i
  189.     param = [1, $1.to_i] if @note =~ /<mana_mmp: (.*)>/i
  190.     param = [2, $1.to_i] if @note =~ /<mana_atk: (.*)>/i
  191.     param = [3, $1.to_i] if @note =~ /<mana_def: (.*)>/i
  192.     param = [4, $1.to_i] if @note =~ /<mana_mat: (.*)>/i
  193.     param = [5, $1.to_i] if @note =~ /<mana_mdf: (.*)>/i
  194.     param = [6, $1.to_i] if @note =~ /<mana_agi: (.*)>/i
  195.     param = [7, $1.to_i] if @note =~ /<mana_luk: (.*)>/i
  196.     return param
  197.   end
  198. end
  199.  
  200. #-------------------------------------------------------------------------------
  201. # Window mana slots
  202. class Window_ItemSlots < Window_Selectable
  203.   def initialize(x=0, y=0, w=280, h=124)
  204.     super(x, y,  w, h)
  205.     unselect
  206.   end
  207.  
  208.   def item()        return @data[self.index] end
  209.   def line_height() return 24                end
  210.   def spacing()     return 6                 end
  211.   def col_max()     return 2                 end
  212.    
  213.   def refresh(object)
  214.     self.contents.clear if self.contents != nil
  215.     @data = []
  216.     return if object.manaslots.nil? rescue return
  217.     object.manaslots.each {|i| @data.push(i)}
  218.     @item_max = @data.size
  219.     if @item_max > 0
  220.       self.contents = Bitmap.new(width - 32, row_max * 26)
  221.       for i in 0...@item_max
  222.         draw_item(i)
  223.       end
  224.     end
  225.   end
  226.  
  227.   def draw_item(index)
  228.     item = @data[index]
  229.     x, y = index % col_max * (129), index / col_max  * 24
  230.     self.contents.font.size = 18
  231.     self.contents.draw_text(x + 2, y - 2, 212, 32, 's:', 0)
  232.     draw_icon(item.icon_index, x, y) rescue nil
  233.     param = Vocab.param(item.manastone_param[0]) rescue nil
  234.     value = item.manastone_param[1] rescue nil
  235.     self.contents.draw_text(x + 24,y,212,32, param + " +#{value}") rescue nil
  236.   end
  237.  
  238.   def item_max
  239.     return @item_max.nil? ? 0 : @item_max
  240.   end
  241. end
  242.  
  243. #-------------------------------------------------------------------------------
  244. # Window mana stones
  245. class Window_ManaStones < Window_Selectable
  246.   def initialize(x=0, y=124, w=280, h=148)
  247.     super(x, y,  w, h)
  248.     refresh ; unselect
  249.   end
  250.  
  251.   def item() return @data[self.index] end
  252.  
  253.   def refresh
  254.     self.contents.clear if self.contents != nil
  255.     @data = []
  256.     for it in $data_items
  257.       next if it.nil?
  258.       @data.push(it) if $game_party.has_item?(it) and !it.manastone_param.nil?
  259.     end
  260.     @item_max = @data.size
  261.     if @item_max > 0
  262.       self.contents = Bitmap.new(width - 32, row_max * 26)
  263.       for i in 0...@item_max
  264.         draw_item(i)
  265.       end
  266.     end
  267.   end
  268.  
  269.   def draw_item(index)
  270.     item = @data[index]
  271.     x, y = index % col_max * (90), index / col_max  * 24
  272.     self.contents.font.size = 18
  273.     draw_icon(item.icon_index, x, y)
  274.     param = Vocab.param(item.manastone_param[0])
  275.     value = item.manastone_param[1]
  276.     number = $game_party.item_number(item)
  277.     contents.draw_text(x + 24,y,212,32, item.name + "  #{param} +#{value}")
  278.     contents.draw_text(x -30, y, self.width, 32, ':' + number.to_s, 2)
  279.   end
  280.  
  281.   def item_max
  282.     return @item_max.nil? ? 0 : @item_max
  283.   end
  284. end
  285.  
  286. class Game_Actor < Game_Battler
  287.   alias falcaomanastones_change change_equip
  288.   def change_equip(slot_id, item)
  289.     FalMana.add_param(self, @equips[slot_id].object, true)
  290.     FalMana.add_param(self, item)
  291.     falcaomanastones_change(slot_id, item)
  292.   end
  293. end
  294.  
  295.  
  296. #-------------------------------------------------------------------------------
  297. # Window actor equipped
  298. class Window_Equippedwa < Window_Selectable
  299.   def initialize(x=0, y=124)
  300.     super(x, y,  190, 148)
  301.     refresh(FalMana.actor) ; activate ; select(0)
  302.   end
  303.  
  304.   def item() return @data[self.index] end
  305.  
  306.   def refresh(actor)
  307.     self.contents.clear if self.contents != nil
  308.     @data = []
  309.     actor.equips.each {|equips| @data.push(equips) if !equips.nil?}
  310.     @item_max = @data.size
  311.     if @item_max > 0
  312.       self.contents = Bitmap.new(width - 32, row_max * 26)
  313.       for i in 0...@item_max
  314.         draw_item(i)
  315.       end
  316.     end
  317.   end
  318.  
  319.   def draw_item(index)
  320.     item = @data[index]
  321.     x, y = index % col_max * (90), index / col_max  * 24
  322.     self.contents.font.size = 18
  323.     draw_icon(item.icon_index, x, y)
  324.     contents.draw_text(x + 24,y,212,32, item.name)
  325.   end
  326.  
  327.   def item_max
  328.     return @item_max.nil? ? 0 : @item_max
  329.   end
  330. end
  331.  
  332. # Scene mana stones
  333. class Scene_ManaStones < Scene_MenuBase
  334.   def start
  335.     super
  336.     w = Graphics.width ; h = Graphics.height ; @actor = FalMana.actor
  337.     @slot_window = Window_Equippedwa.new(w/2 - 190/2 - 137, h/2 - 148/2 - 106)
  338.     @param_window = Window_Base.new(@slot_window.x,@slot_window.y + 148,190,214)
  339.     refresh_param
  340.     @socket_window = Window_Base.new(w/2 - 280/2 + 97,h/2 - 90/2 - 136, 280, 90)
  341.     @col = [Color.new(180, 225, 245), Color.new(20, 160, 225), Color.new(0,0,0)]
  342.     @itemslots = Window_ItemSlots.new(@socket_window.x, @socket_window.y + 90)
  343.     @manastones = Window_ManaStones.new(@itemslots.x, @itemslots.y + 124)
  344.     @result = '' ; @meter = 0
  345.     update_indexes
  346.   end
  347.  
  348.   def refresh_param
  349.     @param_window.contents.clear
  350.     @param_window.contents.font.size = 18
  351.     @param_window.contents.font.color = @param_window.normal_color
  352.     @param_window.contents.fill_rect(0, 0, 190, 44, Color.new(0, 0, 0, 60))
  353.     @param_window.draw_character(@actor.character_name,
  354.     @actor.character_index, 20, 42)
  355.     @param_window.draw_text(50, -6, 190, 32, @actor.name)
  356.     @param_window.draw_text(50, 18, 190, 32, 'Equippment')
  357.     y = 0
  358.     for i in 0...8
  359.       y += 17
  360.       @param_window.contents.font.color = @param_window.normal_color
  361.       @param_window.draw_text(0, y + 28, 190, 32, Vocab.param(i))
  362.       @param_window.contents.font.color = @param_window.system_color
  363.       @param_window.draw_text(70, y + 28, 190, 32, "=> #{@actor.param(i)}")
  364.     end
  365.   end
  366.  
  367.   def refresh_socketing
  368.     @socket_window.contents.clear
  369.     @socket_window.contents.font.size = 18
  370.     if @slot_window.item.nil? || @slot_window.item.manaslots.nil?
  371.       @socket_window.draw_text(-16, 0, 280, 32, 'No sockets', 1)
  372.       return
  373.     end
  374.     @socket_window.draw_icon(@slot_window.item.icon_index, 0, 0)
  375.     @socket_window.draw_text(26, 0, @socket_window.width, 32,
  376.     @slot_window.item.name + " sockets: #{@slot_window.item.manaslots.size}")
  377.     @socket_window.draw_text(-20, 44, 280, 32, 'S = clear socket', 2)
  378.     if @meter > 0 and @meter < 100
  379.       x, y = 78, 34
  380.       @socket_window.draw_text(0, 22, 212, 32, 'Socketing:')
  381.       @socket_window.contents.fill_rect(x, y, 152, 12, @col[2])
  382.       @socket_window.contents.fill_rect(x+1, y+1, 150 *@meter / 100, 5, @col[0])
  383.       @socket_window.contents.fill_rect(x+1, y+6, 150 *@meter / 100, 5, @col[1])
  384.     elsif @meter > 100
  385.       @socket_window.draw_text(0, 22, @socket_window.width, 32, @result)
  386.     elsif @meter == 0
  387.       @itemslots.item.nil? ? @result = 'Socket ready' : @result = 'Socket busy'
  388.       @socket_window.draw_text(0, 22, @socket_window.width, 32, @result)
  389.     end
  390.   end
  391.  
  392.   def terminate
  393.     super
  394.     @itemslots.dispose
  395.     @manastones.dispose
  396.     @socket_window.dispose
  397.     @slot_window.dispose
  398.     @param_window.dispose
  399.   end
  400.  
  401.   def update
  402.     super
  403.     update_selection       if Input.trigger?(:C)
  404.     update_cancel          if Input.trigger?(:B)
  405.     update_clear_socket    if Input.trigger?(:Y)
  406.     start_socketing
  407.     update_indexes
  408.   end
  409.  
  410.   def update_indexes
  411.     if @equipp_slot != @slot_window.index
  412.       @itemslots.refresh(@slot_window.item)
  413.       refresh_socketing
  414.       @equipp_slot = @slot_window.index
  415.     elsif @slots_index != @itemslots.index and @itemslots.visible
  416.       @slots_index = @itemslots.index
  417.       refresh_socketing
  418.     end
  419.   end
  420.  
  421.   def start_socketing
  422.     return if @soketing.nil?
  423.     @meter += 1 ; refresh_socketing
  424.     if @meter == 100
  425.       r = rand(101)
  426.       r <= @manastones.item.socket_chance ? success_socketing : fail_socketing
  427.     elsif @meter == 200
  428.       @soketing = nil ; @meter = 0 ; @manastones.activate
  429.       refresh_socketing
  430.     end
  431.   end
  432.  
  433.   def update_selection
  434.     return if @meter > 0 || !@itemslots.visible
  435.     if !@itemslots.item.nil? || @slot_window.item.nil? ||
  436.       @slot_window.item.manaslots.nil?
  437.       if !@slot_window.active
  438.         Sound.play_buzzer; return
  439.       elsif @slot_window.active and @slot_window.item.nil?
  440.         Sound.play_buzzer; return
  441.       elsif @slot_window.item.manaslots.nil?
  442.         Sound.play_buzzer; return
  443.       end
  444.     end
  445.     if @slot_window.active and !@itemslots.active
  446.       @itemslots.select(0)
  447.       @itemslots.activate
  448.       @slot_window.deactivate ; Sound.play_ok
  449.     elsif @itemslots.active and !@manastones.active
  450.       @itemslots.deactivate
  451.       @manastones.activate ; @manastones.select(0)
  452.       Sound.play_ok
  453.     elsif @manastones.active and !@manastones.item.nil?
  454.       @manastones.deactivate
  455.       RPG::SE.new(FalMana::SoketingSe, 80,).play
  456.       @soketing = true
  457.     end
  458.   end
  459.  
  460.   def fail_socketing
  461.     FalMana.clear_manastones(@slot_window.item, @actor)
  462.     @itemslots.refresh(@slot_window.item)
  463.     refresh_param
  464.     @result = 'Mana stones destroyed!'
  465.     RPG::SE.new(FalMana::SocketFailSe, 80,).play
  466.     destroy_manastone
  467.   end
  468.  
  469.   def success_socketing
  470.     FalMana.socket_manastone(@slot_window.item, @itemslots.index,
  471.     @manastones.item, @actor)
  472.     @itemslots.refresh(@slot_window.item)
  473.     refresh_param
  474.     @result = 'Socketing successful!'
  475.     RPG::SE.new(FalMana::SocketSuccessSe, 80,).play
  476.     destroy_manastone
  477.   end
  478.  
  479.   def destroy_manastone
  480.     $game_party.lose_item(@manastones.item, 1)
  481.     @manastones.refresh
  482.   end
  483.  
  484.   def update_cancel
  485.     return if @meter > 0
  486.     Sound.play_cancel
  487.     if @slot_window.active
  488.       SceneManager.return
  489.     elsif @itemslots.active
  490.       @slot_window.activate
  491.       @itemslots.unselect
  492.       @itemslots.deactivate
  493.     elsif @manastones.active
  494.       @manastones.unselect ; @manastones.deactivate
  495.       @itemslots.activate
  496.     end
  497.   end
  498.  
  499.   def update_clear_socket
  500.     return if @itemslots.item.nil? || !@itemslots.active
  501.     RPG::SE.new(FalMana::ClearSocketSe, 80,).play
  502.     FalMana.remove_manastone(@slot_window.item, @itemslots.index,
  503.     @itemslots.item, @actor)
  504.     @itemslots.refresh(@slot_window.item)
  505.     refresh_param
  506.     refresh_socketing
  507.   end
  508. end
Add Comment
Please, Sign In to add comment