Class: Game_Action

Inherits:
Object
  • Object
show all
Defined in:
Game_Action.rb

Overview

** Game_Action


This class handles battle actions. This class is used within the

Game_Battler class.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Game_Action) initialize(subject, forcing = false)


  • Object Initialization




20
21
22
23
24
# File 'Game_Action.rb', line 20

def initialize(subject, forcing = false)
  @subject = subject
  @forcing = forcing
  clear
end

Instance Attribute Details

- (Object) forcing (readonly)

forcing flag for battle action



13
14
15
# File 'Game_Action.rb', line 13

def forcing
  @forcing
end

- (Object) item (readonly)


  • Get Item Object




14
15
16
# File 'Game_Action.rb', line 14

def item
  @item
end

- (Object) subject (readonly)


  • Public Instance Variables




12
13
14
# File 'Game_Action.rb', line 12

def subject
  @subject
end

- (Object) target_index

target index



15
16
17
# File 'Game_Action.rb', line 15

def target_index
  @target_index
end

- (Object) value (readonly)

evaluation value for auto battle



16
17
18
# File 'Game_Action.rb', line 16

def value
  @value
end

Instance Method Details

- (Boolean) attack?


  • Normal Attack Determination


Returns:

  • (Boolean)


93
94
95
# File 'Game_Action.rb', line 93

def attack?
  item == $data_skills[subject.attack_skill_id]
end

- (Object) clear


  • Clear




28
29
30
31
32
# File 'Game_Action.rb', line 28

def clear
  @item = Game_BaseItem.new
  @target_index = -1
  @value = 0
end

- (Object) confusion_target


  • Target When Confused




160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'Game_Action.rb', line 160

def confusion_target
  case subject.confusion_level
  when 1
    opponents_unit.random_target
  when 2
    if rand(2) == 0
      opponents_unit.random_target
    else
      friends_unit.random_target
    end
  else
    friends_unit.random_target
  end
end

- (Object) decide_random_target


  • Random Target




99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'Game_Action.rb', line 99

def decide_random_target
  if item.for_dead_friend?
    target = friends_unit.random_dead_target
  elsif item.for_friend?
    target = friends_unit.random_target
  else
    target = opponents_unit.random_target
  end
  if target
    @target_index = target.index
  else
    clear
  end
end

- (Object) evaluate


  • Evaluate Value of Action (for Auto Battle)

    @value and @target_index are automatically set.



215
216
217
218
219
220
# File 'Game_Action.rb', line 215

def evaluate
  @value = 0
  evaluate_item if valid?
  @value += rand if @value > 0
  self
end

- (Object) evaluate_item


  • Evaluate Skill/Item




224
225
226
227
228
229
230
231
232
233
234
# File 'Game_Action.rb', line 224

def evaluate_item
  item_target_candidates.each do |target|
    value = evaluate_item_with_target(target)
    if item.for_all?
      @value += value
    elsif value > @value
      @value = value
      @target_index = target.index
    end
  end
end

- (Object) evaluate_item_with_target(target)


  • Evaluate Skill/Item (Target Specification)




252
253
254
255
256
257
258
259
260
261
# File 'Game_Action.rb', line 252

def evaluate_item_with_target(target)
  target.result.clear
  target.make_damage_value(subject, item)
  if item.for_opponent?
    return target.result.hp_damage.to_f / [target.hp, 1].max
  else
    recovery = [-target.result.hp_damage, target.mhp - target.hp].min
    return recovery.to_f / target.mhp
  end
end

- (Object) friends_unit


  • Get Allied Units




36
37
38
# File 'Game_Action.rb', line 36

def friends_unit
  subject.friends_unit
end

- (Object) item_target_candidates


  • Get Use Target Candidates for Skills/Items




238
239
240
241
242
243
244
245
246
247
248
# File 'Game_Action.rb', line 238

def item_target_candidates
  if item.for_opponent?
    opponents_unit.alive_members
  elsif item.for_user?
    [subject]
  elsif item.for_dead_friend?
    friends_unit.dead_members
  else
    friends_unit.alive_members
  end
end

- (Object) make_targets


  • Create Target Array




146
147
148
149
150
151
152
153
154
155
156
# File 'Game_Action.rb', line 146

def make_targets
  if !forcing && subject.confusion?
    [confusion_target]
  elsif item.for_opponent?
    targets_for_opponents
  elsif item.for_friend?
    targets_for_friends
  else
    []
  end
end

- (Object) opponents_unit


  • Get Enemy Units




42
43
44
# File 'Game_Action.rb', line 42

def opponents_unit
  subject.opponents_unit
end

- (Object) prepare


  • Action Preparation




122
123
124
# File 'Game_Action.rb', line 122

def prepare
  set_confusion if subject.confusion? && !forcing
end

- (Object) set_attack


  • Set Normal Attack




59
60
61
62
# File 'Game_Action.rb', line 59

def set_attack
  set_skill(subject.attack_skill_id)
  self
end

- (Object) set_confusion


  • Set Confusion Action




116
117
118
# File 'Game_Action.rb', line 116

def set_confusion
  set_attack
end

- (Object) set_enemy_action(action)


  • Set Battle Action of Enemy Character

    action : RPG::Enemy::Action



49
50
51
52
53
54
55
# File 'Game_Action.rb', line 49

def set_enemy_action(action)
  if action
    set_skill(action.skill_id)
  else
    clear
  end
end

- (Object) set_guard


  • Set Guard




66
67
68
69
# File 'Game_Action.rb', line 66

def set_guard
  set_skill(subject.guard_skill_id)
  self
end

- (Object) set_item(item_id)


  • Set Item




80
81
82
83
# File 'Game_Action.rb', line 80

def set_item(item_id)
  @item.object = $data_items[item_id]
  self
end

- (Object) set_skill(skill_id)


  • Set Skill




73
74
75
76
# File 'Game_Action.rb', line 73

def set_skill(skill_id)
  @item.object = $data_skills[skill_id]
  self
end

- (Object) speed


  • Calculate Action Speed




137
138
139
140
141
142
# File 'Game_Action.rb', line 137

def speed
  speed = subject.agi + rand(5 + subject.agi / 4)
  speed += item.speed if item
  speed += subject.atk_speed if attack?
  speed
end

- (Object) targets_for_friends


  • Targets for Allies




194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'Game_Action.rb', line 194

def targets_for_friends
  if item.for_user?
    [subject]
  elsif item.for_dead_friend?
    if item.for_one?
      [friends_unit.smooth_dead_target(@target_index)]
    else
      friends_unit.dead_members
    end
  elsif item.for_friend?
    if item.for_one?
      [friends_unit.smooth_target(@target_index)]
    else
      friends_unit.alive_members
    end
  end
end

- (Object) targets_for_opponents


  • Targets for Opponents




177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'Game_Action.rb', line 177

def targets_for_opponents
  if item.for_random?
    Array.new(item.number_of_targets) { opponents_unit.random_target }
  elsif item.for_one?
    num = 1 + (attack? ? subject.atk_times_add.to_i : 0)
    if @target_index < 0
      [opponents_unit.random_target] * num
    else
      [opponents_unit.smooth_target(@target_index)] * num
    end
  else
    opponents_unit.alive_members
  end
end

- (Boolean) valid?


  • Determination if Action is Valid or Not

    Assuming that an event command does not cause [Force Battle Action],
    if state limitations or lack of items, etc. make the planned action
    impossible, return false.

Returns:

  • (Boolean)


131
132
133
# File 'Game_Action.rb', line 131

def valid?
  (forcing && item) || subject.usable?(item)
end