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