Falmc

Falcao Mana Stones Enchantment 1.5

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