Falmc

Falcao Mana Stones Enchantment

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