Class: Squad
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Squad
- Defined in:
- app/models/squad.rb
Overview
This class describes a squad of mobs.
Instance Attribute Summary (collapse)
-
- (Object) current_point
Returns the value of attribute current_point.
-
- (Object) destination_point
Returns the value of attribute destination_point.
-
- (Object) distance_from_current_point
Returns the value of attribute distance_from_current_point.
-
- (Object) enemy_squads
Returns the value of attribute enemy_squads.
-
- (Object) entried
Returns the value of attribute entried.
-
- (Object) friend_squads
Returns the value of attribute friend_squads.
-
- (Object) intruder
Returns the value of attribute intruder.
-
- (Object) retreated_from_fortress
Returns the value of attribute retreated_from_fortress.
-
- (Object) route_path
Returns the value of attribute route_path.
-
- (Object) ss_dex
Returns the value of attribute ss_dex.
-
- (Object) target_squad
Returns the value of attribute target_squad.
Instance Method Summary (collapse)
-
- (Boolean) action_turn?
Return true if this squad can act in trial move turn.
-
- (Boolean) annihilated?
Return true if all the mobs belong to this squad are dead.
-
- (Integer) battle_range
Return battle range.
-
- (Integer) damaged_rate
Return the damaged hp ratio of all mobs.
-
- (Boolean) demoralized?
Return true if all the mobs belong to this squad are demoralized.
-
- (Integer) dex
Return dex of this squad.
-
- (Boolean) enemy_squad_in_battle_range?
Return true if the nearest enemy squad is in battle range.
-
- (Boolean) enemy_squad_sighted?
Return true if the nearest enemy squad is in sight.
-
- (String) missions_txt
Return the mission list which belongs to this squad.
-
- (Object) nearest_enemy_squad
Return the nearest enemy squad from current point.
-
- (Boolean) retreated_from_battle?
Return true if all the mobs belong to this squad are retreated from battle.
-
- (Object) set_current_point(x, y)
Set current point.
Instance Attribute Details
- (Object) current_point
Returns the value of attribute current_point
13 14 15 |
# File 'app/models/squad.rb', line 13 def current_point @current_point end |
- (Object) destination_point
Returns the value of attribute destination_point
14 15 16 |
# File 'app/models/squad.rb', line 14 def destination_point @destination_point end |
- (Object) distance_from_current_point
Returns the value of attribute distance_from_current_point
16 17 18 |
# File 'app/models/squad.rb', line 16 def distance_from_current_point @distance_from_current_point end |
- (Object) enemy_squads
Returns the value of attribute enemy_squads
18 19 20 |
# File 'app/models/squad.rb', line 18 def enemy_squads @enemy_squads end |
- (Object) entried
Returns the value of attribute entried
22 23 24 |
# File 'app/models/squad.rb', line 22 def entried @entried end |
- (Object) friend_squads
Returns the value of attribute friend_squads
19 20 21 |
# File 'app/models/squad.rb', line 19 def friend_squads @friend_squads end |
- (Object) intruder
Returns the value of attribute intruder
21 22 23 |
# File 'app/models/squad.rb', line 21 def intruder @intruder end |
- (Object) retreated_from_fortress
Returns the value of attribute retreated_from_fortress
23 24 25 |
# File 'app/models/squad.rb', line 23 def retreated_from_fortress @retreated_from_fortress end |
- (Object) route_path
Returns the value of attribute route_path
15 16 17 |
# File 'app/models/squad.rb', line 15 def route_path @route_path end |
- (Object) ss_dex
Returns the value of attribute ss_dex
17 18 19 |
# File 'app/models/squad.rb', line 17 def ss_dex @ss_dex end |
- (Object) target_squad
Returns the value of attribute target_squad
20 21 22 |
# File 'app/models/squad.rb', line 20 def target_squad @target_squad end |
Instance Method Details
- (Boolean) action_turn?
Return true if this squad can act in trial move turn.
75 76 77 78 |
# File 'app/models/squad.rb', line 75 def action_turn? return true if not annihilated? and rand(Params::MOB_STATUS_MAX) <= @ss_dex return false end |
- (Boolean) annihilated?
Return true if all the mobs belong to this squad are dead.
48 49 50 51 52 53 |
# File 'app/models/squad.rb', line 48 def annihilated? mobs.each do |mob| return false if mob.hp > 0 end return true end |
- (Integer) battle_range
Return battle range.
104 105 106 107 108 109 110 |
# File 'app/models/squad.rb', line 104 def battle_range range = 1 mobs.each do |mob| range = mob.battle_range if range < mob.battle_range - 1 and not mob.dead? end return range end |
- (Integer) damaged_rate
Return the damaged hp ratio of all mobs.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/squad.rb', line 134 def damaged_rate total_mob_max_hp = 0 total_mob_current_hp = 0 mobs.each do |mob| total_mob_max_hp += mob.max_hp total_mob_current_hp += mob.hp end total_mob_max_hp / total_mob_current_hp end |
- (Boolean) demoralized?
Return true if all the mobs belong to this squad are demoralized.
57 58 59 60 61 62 |
# File 'app/models/squad.rb', line 57 def demoralized? mobs.each do |mob| return false unless mob.demoralized? end return true end |
- (Integer) dex
minimum dex of mobs which belong to this squad.
Return dex of this squad.
123 124 125 126 127 128 129 130 |
# File 'app/models/squad.rb', line 123 def dex dex = Params::MOB_STATUS_MAX mobs.each do |mob| next if mob.dead? dex = mob.dex if dex > mob.dex end return dex end |
- (Boolean) enemy_squad_in_battle_range?
Return true if the nearest enemy squad is in battle range.
114 115 116 117 118 |
# File 'app/models/squad.rb', line 114 def enemy_squad_in_battle_range? return false if @target_squad.nil? return true if nearest_enemy_squad.distance_from_current_point <= battle_range return false end |
- (Boolean) enemy_squad_sighted?
Return true if the nearest enemy squad is in sight.
96 97 98 99 100 |
# File 'app/models/squad.rb', line 96 def enemy_squad_sighted? return false if @enemy_squads.blank? return true if nearest_enemy_squad.distance_from_current_point <= Params::ENEMY_VISIBLE_DISTANCE return false end |
- (String) missions_txt
Return the mission list which belongs to this squad.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/squad.rb', line 27 def missions_txt missions_txt = '' missions.each do |mission| if not mission.blank? missions_txt += mission.name missions_txt += ',' end end missions_txt.chop! if missions_txt.last == ',' return missions_txt end |
- (Object) nearest_enemy_squad
Return the nearest enemy squad from current point.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/squad.rb', line 82 def nearest_enemy_squad enemy_squads.each do |enemy_squad| # p current_point # p enemy_squad.current_point enemy_squad.distance_from_current_point = Tools.calc_distance(current_point, enemy_squad.current_point) end enemy_squads_sorted_by_distance = enemy_squads.sort{|a,b| a.distance_from_current_point <=> b.distance_from_current_point } return enemy_squads_sorted_by_distance.first end |
- (Boolean) retreated_from_battle?
Return true if all the mobs belong to this squad are retreated from battle.
66 67 68 69 70 71 |
# File 'app/models/squad.rb', line 66 def retreated_from_battle? mobs.each do |mob| return false if not mob.retreated_from_battle? and not mob.dead? end return true end |
- (Object) set_current_point(x, y)
Set current point.
42 43 44 |
# File 'app/models/squad.rb', line 42 def set_current_point(x, y) @current_point = Point.new(x, y) end |