Class: Game_Action
- Inherits:
-
Object
- Object
- Game_Action
- Defined in:
- lib/rgss3_default_scripts/Game_Action.rb
Overview
** Game_Action
This class handles battle actions. This class is used within the
Game_Battler class.
Instance Attribute Summary collapse
-
#forcing ⇒ Object
readonly
forcing flag for battle action.
-
#item ⇒ Object
readonly
————————————————————————– * Get Item Object ————————————————————————–.
-
#subject ⇒ Object
readonly
————————————————————————– * Public Instance Variables ————————————————————————–.
-
#target_index ⇒ Object
target index.
-
#value ⇒ Object
readonly
evaluation value for auto battle.
Instance Method Summary collapse
-
#attack? ⇒ Boolean
————————————————————————– * Normal Attack Determination ————————————————————————–.
-
#clear ⇒ Object
————————————————————————– * Clear ————————————————————————–.
-
#confusion_target ⇒ Object
————————————————————————– * Target When Confused ————————————————————————–.
-
#decide_random_target ⇒ Object
————————————————————————– * Random Target ————————————————————————–.
-
#evaluate ⇒ Object
————————————————————————– * Evaluate Value of Action (for Auto Battle) @value and @target_index are automatically set.
-
#evaluate_item ⇒ Object
————————————————————————– * Evaluate Skill/Item ————————————————————————–.
-
#evaluate_item_with_target(target) ⇒ Object
————————————————————————– * Evaluate Skill/Item (Target Specification) ————————————————————————–.
-
#friends_unit ⇒ Object
————————————————————————– * Get Allied Units ————————————————————————–.
-
#initialize(subject, forcing = false) ⇒ Game_Action
constructor
————————————————————————– * Object Initialization ————————————————————————–.
-
#item_target_candidates ⇒ Object
————————————————————————– * Get Use Target Candidates for Skills/Items ————————————————————————–.
-
#make_targets ⇒ Object
————————————————————————– * Create Target Array ————————————————————————–.
-
#opponents_unit ⇒ Object
————————————————————————– * Get Enemy Units ————————————————————————–.
-
#prepare ⇒ Object
————————————————————————– * Action Preparation ————————————————————————–.
-
#set_attack ⇒ Object
————————————————————————– * Set Normal Attack ————————————————————————–.
-
#set_confusion ⇒ Object
————————————————————————– * Set Confusion Action ————————————————————————–.
-
#set_enemy_action(action) ⇒ Object
————————————————————————– * Set Battle Action of Enemy Character action : RPG::Enemy::Action ————————————————————————–.
-
#set_guard ⇒ Object
————————————————————————– * Set Guard ————————————————————————–.
-
#set_item(item_id) ⇒ Object
————————————————————————– * Set Item ————————————————————————–.
-
#set_skill(skill_id) ⇒ Object
————————————————————————– * Set Skill ————————————————————————–.
-
#speed ⇒ Object
————————————————————————– * Calculate Action Speed ————————————————————————–.
-
#targets_for_friends ⇒ Object
————————————————————————– * Targets for Allies ————————————————————————–.
-
#targets_for_opponents ⇒ Object
————————————————————————– * Targets for Opponents ————————————————————————–.
-
#valid? ⇒ Boolean
————————————————————————– * 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.
Constructor Details
#initialize(subject, forcing = false) ⇒ Game_Action
-
Object Initialization
20 21 22 23 24 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 20 def initialize(subject, forcing = false) @subject = subject @forcing = forcing clear end |
Instance Attribute Details
#forcing ⇒ Object (readonly)
forcing flag for battle action
13 14 15 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 13 def forcing @forcing end |
#item ⇒ Object (readonly)
-
Get Item Object
14 15 16 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 14 def item @item end |
#subject ⇒ Object (readonly)
-
Public Instance Variables
12 13 14 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 12 def subject @subject end |
#target_index ⇒ Object
target index
15 16 17 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 15 def target_index @target_index end |
#value ⇒ Object (readonly)
evaluation value for auto battle
16 17 18 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 16 def value @value end |
Instance Method Details
#attack? ⇒ Boolean
-
Normal Attack Determination
93 94 95 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 93 def attack? item == $data_skills[subject.attack_skill_id] end |
#clear ⇒ Object
-
Clear
28 29 30 31 32 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 28 def clear @item = Game_BaseItem.new @target_index = -1 @value = 0 end |
#confusion_target ⇒ Object
-
Target When Confused
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/rgss3_default_scripts/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 |
#decide_random_target ⇒ Object
-
Random Target
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rgss3_default_scripts/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 |
#evaluate ⇒ Object
-
Evaluate Value of Action (for Auto Battle)
@value and @target_index are automatically set.
215 216 217 218 219 220 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 215 def evaluate @value = 0 evaluate_item if valid? @value += rand if @value > 0 self end |
#evaluate_item ⇒ Object
-
Evaluate Skill/Item
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rgss3_default_scripts/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 |
#evaluate_item_with_target(target) ⇒ Object
-
Evaluate Skill/Item (Target Specification)
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/rgss3_default_scripts/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 |
#friends_unit ⇒ Object
-
Get Allied Units
36 37 38 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 36 def friends_unit subject.friends_unit end |
#item_target_candidates ⇒ Object
-
Get Use Target Candidates for Skills/Items
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/rgss3_default_scripts/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 |
#make_targets ⇒ Object
-
Create Target Array
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rgss3_default_scripts/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 |
#opponents_unit ⇒ Object
-
Get Enemy Units
42 43 44 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 42 def opponents_unit subject.opponents_unit end |
#prepare ⇒ Object
-
Action Preparation
122 123 124 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 122 def prepare set_confusion if subject.confusion? && !forcing end |
#set_attack ⇒ Object
-
Set Normal Attack
59 60 61 62 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 59 def set_attack set_skill(subject.attack_skill_id) self end |
#set_confusion ⇒ Object
-
Set Confusion Action
116 117 118 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 116 def set_confusion set_attack end |
#set_enemy_action(action) ⇒ Object
-
Set Battle Action of Enemy Character
action : RPG::Enemy::Action
49 50 51 52 53 54 55 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 49 def set_enemy_action(action) if action set_skill(action.skill_id) else clear end end |
#set_guard ⇒ Object
-
Set Guard
66 67 68 69 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 66 def set_guard set_skill(subject.guard_skill_id) self end |
#set_item(item_id) ⇒ Object
-
Set Item
80 81 82 83 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 80 def set_item(item_id) @item.object = $data_items[item_id] self end |
#set_skill(skill_id) ⇒ Object
-
Set Skill
73 74 75 76 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 73 def set_skill(skill_id) @item.object = $data_skills[skill_id] self end |
#speed ⇒ Object
-
Calculate Action Speed
137 138 139 140 141 142 |
# File 'lib/rgss3_default_scripts/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 |
#targets_for_friends ⇒ Object
-
Targets for Allies
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/rgss3_default_scripts/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 |
#targets_for_opponents ⇒ Object
-
Targets for Opponents
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rgss3_default_scripts/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 |
#valid? ⇒ Boolean
-
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.
131 132 133 |
# File 'lib/rgss3_default_scripts/Game_Action.rb', line 131 def valid? (forcing && item) || subject.usable?(item) end |