Falmc

Mana stones 1,6 debug

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