Class: Game_Unit

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

Overview

** Game_Unit


This class handles units. It's used as a superclass of the Game_Party and

and Game_Troop classes.

Direct Known Subclasses

Game_Party, Game_Troop

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Game_Unit) initialize


  • Object Initialization




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

def initialize
  @in_battle = false
end

Instance Attribute Details

- (Object) in_battle (readonly)


  • Public Instance Variables




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

def in_battle
  @in_battle
end

Instance Method Details

- (Object) agi


  • Calculate Average Value of Agility




52
53
54
55
# File 'Game_Unit.rb', line 52

def agi
  return 1 if members.size == 0
  members.inject(0) {|r, member| r += member.agi } / members.size
end

- (Object) alive_members


  • Get Array of Living Members




28
29
30
# File 'Game_Unit.rb', line 28

def alive_members
  members.select {|member| member.alive? }
end

- (Boolean) all_dead?


  • Determine Everyone is Dead


Returns:

  • (Boolean)


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

def all_dead?
  alive_members.empty?
end

- (Object) clear_actions


  • Clear all Members' Battle Actions




46
47
48
# File 'Game_Unit.rb', line 46

def clear_actions
  members.each {|member| member.clear_actions }
end

- (Object) clear_results


  • Clear Action Results




96
97
98
# File 'Game_Unit.rb', line 96

def clear_results
  members.select {|member| member.result.clear }
end

- (Object) dead_members


  • Get Array of Incapacitated Members




34
35
36
# File 'Game_Unit.rb', line 34

def dead_members
  members.select {|member| member.dead? }
end

- (Object) make_actions


  • Create Battle Action




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

def make_actions
  members.each {|member| member.make_actions }
end

- (Object) members


  • Get Members




22
23
24
# File 'Game_Unit.rb', line 22

def members
  return []
end

- (Object) movable_members


  • Get Array of Movable Members




40
41
42
# File 'Game_Unit.rb', line 40

def movable_members
  members.select {|member| member.movable? }
end

- (Object) on_battle_end


  • Processing at End of Battle




109
110
111
112
# File 'Game_Unit.rb', line 109

def on_battle_end
  @in_battle = false
  members.each {|member| member.on_battle_end }
end

- (Object) on_battle_start


  • Processing at Start of Battle




102
103
104
105
# File 'Game_Unit.rb', line 102

def on_battle_start
  members.each {|member| member.on_battle_start }
  @in_battle = true
end

- (Object) random_dead_target


  • Randomly Determine Target (K.O.)




76
77
78
# File 'Game_Unit.rb', line 76

def random_dead_target
  dead_members.empty? ? nil : dead_members[rand(dead_members.size)]
end

- (Object) random_target


  • Random Selection of Target




65
66
67
68
69
70
71
72
# File 'Game_Unit.rb', line 65

def random_target
  tgr_rand = rand * tgr_sum
  alive_members.each do |member|
    tgr_rand -= member.tgr
    return member if tgr_rand < 0
  end
  alive_members[0]
end

- (Object) smooth_dead_target(index)


  • Smooth Selection of Target (K.O.)




89
90
91
92
# File 'Game_Unit.rb', line 89

def smooth_dead_target(index)
  member = members[index]
  (member && member.dead?) ? member : dead_members[0]
end

- (Object) smooth_target(index)


  • Smooth Selection of Target




82
83
84
85
# File 'Game_Unit.rb', line 82

def smooth_target(index)
  member = members[index]
  (member && member.alive?) ? member : alive_members[0]
end

- (Object) substitute_battler


  • Get Substitute Battler




128
129
130
# File 'Game_Unit.rb', line 128

def substitute_battler
  members.find {|member| member.substitute? }
end

- (Object) tgr_sum


  • Calculate Total Target Rate




59
60
61
# File 'Game_Unit.rb', line 59

def tgr_sum
  alive_members.inject(0) {|r, member| r + member.tgr }
end