IceDragon200

[VX2A]SkillInteraction By FenixFyreX

Apr 6th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.38 KB | None | 0 0
  1. # // Skill Interaction By FenixFyreX
  2. # // Ported to RMVXA By IceDragon
  3. # // Date Ported  : 04/06/2012
  4. # // Port Version : 1.0
  5. # // To use:
  6. # //  put:
  7. # //    <interact id>
  8. # //    <interact id, id, id...>
  9. # //  in an event comment.
  10. # //  EG1. <interact 51>
  11. # //  EG2. <interact 51, 65, 98, 129>
  12. module Interaction
  13.   BUTTONS = [:X, :Y, :A, :F5]
  14.   # Do you want to use the HUD?
  15.   USE_HUD = true
  16.   # What icon shows on unassigned buttons?
  17.   NA_ICONINDEX = 359
  18.   # What button opens the Interaction HUD?
  19.   OPEN_HUD_BUTTON = Input::F6
  20. end
  21. class Game_Player < Game_Character
  22.   alias stop_c_button_interact check_event_trigger_there
  23.   def check_event_trigger_there(*args,&block)
  24.     return false if($game_map.interpreter.running?)
  25.     result = false
  26.     front_x = $game_map.x_with_direction(@x, @direction)
  27.     front_y = $game_map.y_with_direction(@y, @direction)
  28.     for event in $game_map.events_xy(front_x, front_y)
  29.       return false if(event.custom_skill_interact?)
  30.     end
  31.     stop_c_button_interact(*args,&block)
  32.   end
  33.   def update_nonmoving(last_moving)
  34.     return if($game_map.interpreter.running?)
  35.     return if(moving?)
  36.     return if(check_touch_event) if(last_moving)
  37.     return if(update_interaction)
  38.     update_encounter if(last_moving)
  39.   end
  40.   def update_interaction
  41.     return if($game_message.busy? || $game_message.visible)
  42.     if Input.trigger?(:C)
  43.       return true if(get_on_off_vehicle)
  44.       return true if(check_action_event)
  45.     end
  46.     Interaction::BUTTONS.each do |button|
  47.       check_event_trigger_interaction(button) if(Input.trigger?(button))
  48.     end
  49.   end
  50.   def can_start_event_interact(event,button)
  51.     return false unless(event.custom_skill_interact?())
  52.     return(event.interact_comment?(true).include?($game_party.equipped_skills[button]))
  53.   end
  54.   def check_event_trigger_interaction(button)
  55.     return false if($game_map.interpreter.running?)
  56.     result = false
  57.     front_x = $game_map.x_with_direction(@x, @direction)
  58.     front_y = $game_map.y_with_direction(@y, @direction)
  59.     for event in $game_map.events_xy(front_x, front_y)
  60.       if can_start_event_interact(event,button)
  61.         event.start
  62.         result = true
  63.       end
  64.     end
  65.     if(!result and $game_map.counter?(front_x, front_y))
  66.       front_x = $game_map.x_with_direction(front_x, @direction)
  67.       front_y = $game_map.y_with_direction(front_y, @direction)
  68.       for event in $game_map.events_xy(front_x, front_y)
  69.         if triggers.include?(event.trigger) and event.priority_type == 1
  70.           event.start
  71.           result = true
  72.         end
  73.       end
  74.     end
  75.     return result
  76.   end    
  77. end
  78. class Game_Event < Game_Character
  79.   alias eqkls_setup_page setup_page
  80.   def setup_page(*args,&block)
  81.     eqkls_setup_page(*args,&block)
  82.     @interact_comment = nil
  83.     interact_comment?(true)
  84.   end  
  85.   def custom_skill_interact?()
  86.     return interact_comment?(false)
  87.   end
  88.   def interact_comment?(return_data=false)
  89.     if(@interact_comment.nil?)
  90.       @interact_comment = false if(@interact_comment.nil?())
  91.       if(@list)
  92.         comment_a = [108,408]
  93.         for item in @list
  94.           next unless(comment_a.include?(item.code))
  95.           case(item.parameters.join(""))
  96.           when /<interact[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  97.             id_int = $1.to_s.scan(/(\d+)/i).collect{|i|i.join("").to_i}
  98.             @interact_comment = id_int
  99.           end
  100.         end
  101.       end  
  102.     end  
  103.     return return_data ? @interact_comment : !!@interact_comment
  104.   end
  105. end
  106. class Game_Party < Game_Unit
  107.   attr_accessor :equipped_skills
  108.   alias initialize_equip_skills initialize
  109.   def initialize(*args,&block)
  110.     initialize_equip_skills(*args,&block)
  111.     @equipped_skills = {}
  112.   end
  113.   def party_skills
  114.     return members.inject([]){|r,m|r+m.skills.collect{|s|s ? s.id : 0}}.uniq
  115.   end
  116.   def equip_skill(button, id)
  117.     return if @equipped_skills[button] == id
  118.     return unless party_skills.include? id
  119.     return if max_skill_equip(button, id)
  120.     @equipped_skills[button] = id
  121.   end
  122.   def max_skill_equip(button, id)
  123.     if(@equipped_skills.keys.size >= Interaction::BUTTONS.size)
  124.       return true if(!@equipped_skills.keys.include?(button))
  125.     end
  126.     return false
  127.   end
  128.   alias remove_actor_quip_skills remove_actor
  129.   def remove_actor(*args,&block)
  130.     remove_actor_quip_skills(*args,&block)
  131.     skls = party_skills
  132.     @equipped_skills.each_pair { |key,value|
  133.       @equipped_skills[key] = nil unless(skls.include?(value))
  134.     }
  135.   end
  136. end
  137. class Scene_Skill
  138.   def equip_skill(button)
  139.     item = @item_window.item
  140.     $game_party.equip_skill(button, item ? item.id : 0)
  141.     if($game_party.equipped_skills.keys.include?(button))
  142.       Sound.play_ok
  143.       show_equipped_message(button, item)
  144.     else
  145.       Sound.play_buzzer
  146.     end
  147.   end
  148.   def show_equipped_message(button, item)
  149.     @item_window.deactivate
  150.     name = item ? item.name : ""
  151.     butn = button.to_s
  152.     txt = sprintf('%s was equipped to %s.', name, butn)
  153.     @help_window.set_text(txt)
  154.     40.times { update_basic }
  155.     @item_window.activate
  156.   end
  157.   alias skleq_update update
  158.   def update()
  159.     skleq_update()
  160.     update_skill_equip() if(@item_window.active)
  161.   end  
  162.   def update_skill_equip
  163.     Interaction::BUTTONS.each{|button|equip_skill(button) if(Input.trigger?(button))}
  164.   end
  165. end
  166. if Interaction::USE_HUD
  167. class Interact_HUD < Window_Base
  168.   def initialize
  169.     super(0,Graphics.height,Graphics.width,64)
  170.     @buttons = nil
  171.     refresh
  172.   end
  173.   def refresh
  174.     self.contents.clear
  175.     @buttons = $game_party.equipped_skills
  176.     @item_max = Interaction::BUTTONS.size
  177.     for i in 0..@item_max-1
  178.       draw_item(i)
  179.     end
  180.   end
  181.   def item_rect(index)
  182.     rect = Rect.new(0,0,0,0)
  183.     rect.width = Graphics.width / @item_max
  184.     rect.height = 32
  185.     rect.x = index*(Graphics.width/@item_max)
  186.     rect.y = 0
  187.     return rect
  188.   end
  189.   def draw_item(index)
  190.     rect = item_rect(index)
  191.     button = Interaction::BUTTONS[index]
  192.     butn = button.to_s
  193.     draw_text(rect, butn, 0)
  194.     indx = $game_party.equipped_skills[button]
  195.     skl  = indx ? $data_skills[indx] : nil
  196.     cw = self.contents.text_size(butn).width+8
  197.     if(skl)
  198.       draw_item_name(skl,rect.x+cw,rect.y+4)
  199.     else
  200.       draw_icon(Interaction::NA_ICONINDEX,rect.x+cw,rect.y+4)
  201.     end  
  202.   end
  203.   def update()
  204.     super()
  205.     refresh if(@buttons != $game_party.equipped_skills)
  206.   end
  207. end
  208. class Scene_Map
  209.   alias initialize_interaction start
  210.   def start
  211.     initialize_interaction
  212.     @inter_win = Interact_HUD.new
  213.   end
  214.   alias update_interact_hud update
  215.   def update
  216.     update_interact_hud
  217.     update_inter_win_input
  218.     @inter_win.update if(@inter_win)
  219.   end
  220.   def update_inter_win_input
  221.     return if $game_map.interpreter.running?
  222.     return if @message_window.openness > 0
  223.     if Input.press?(Interaction::OPEN_HUD_BUTTON)
  224.       @inter_win.y -= 4 unless @inter_win.y <= (Graphics.height-@inter_win.height)
  225.     else
  226.       @inter_win.y += 4 unless @inter_win.y >= Graphics.height
  227.     end
  228.   end
  229.   alias terminate_interwin pre_terminate
  230.   def terminate
  231.     @inter_win.dispose if(@inter_win)
  232.     terminate_interwin
  233.   end
  234. end
  235. end # // USE_HUD
  236. #=■==========================================================================■=#
  237. #                           // ● End of File ● //                              #
  238. #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment