Falmc

Falcao Mana Stones Enchantment

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