Home > RGSS Script Reference > Game_Troop
Game_Troop
Inherits from: None
Description: This class contains information about the monster group currently being fought, and has methods for settings up the monster group and determining a random target for a monster.
class Game_Troop
# ------------------------------------
def initialize
@enemies = []
end
# ------------------------------------
def enemies
return @enemies
end
# ------------------------------------
def setup(troop_id)
@enemies = []
for i in 0...$data_troops[troop_id].members.size
@enemies.push(Game_Enemy.new(troop_id, i))
end
end
# ------------------------------------
def random_target_enemy(hp0 = false)
roulette = []
for enemy in @enemies
if (not hp0 and enemy.exist?) or (hp0 and enemy.hp0?)
roulette.push(enemy)
end
end
if roulette.size == 0
return nil
end
return roulette[rand(roulette.size)]
end
# ------------------------------------
def random_target_enemy_hp0
return random_target_enemy(true)
end
# ------------------------------------
def smooth_target_enemy(enemy_index)
enemy = @enemies[enemy_index]
if enemy != nil and enemy.exist?
return enemy
end
for enemy in @enemies
if enemy.exist?
return enemy
end
end
end
end
|
Enemies: An array containing Game_Enemy objects representing the enemies in the monster group.
Initialize
Arguments: None
Local Variables: None
How it Works: Sets @enemies to an empty array representing an empty monster group.
Enemies
Arguments: None
Local Variables: None
How it Works: Returns the @enemies array.
Setup
Arguments:
Troop_ID: The ID of the monster group to set up.
Local Variables: None
How it Works: Set @enemies to an empty array, then accesses the monster group with the appropriate ID from the data declared in the database. For each enemy in the monster group, a Game_Enemy object is pushed into the array.
Random_Target_Enemy
Arguments:
HP0: A flag that determines whether the enemy chosen should be one with 0 HP. false by default.
Local Variables:
Roulette: An array containing the subset of enemies that are valid targets.
How it Works: Decides a random target in the monster group, either with at least 1 HP or 0 HP, depending on the value of the hp0 value passed to the method. First, the value of roulette is set to an empty array. For each enemy in the monster group that has 1 or more HP (if hp0 is false) or 0 (if hp0 is true), The monster is pushed into the roulette array. The random target chosen is the enemy in the array index chosen by the return roulette[rand(roulette.size)] statement.
Random_Target_Enemy_HP0
Arguments: None
Local Variables: None
How it Works: Calls the Random_Target_Enemy method (see above) with the hp0 flag set to true.
Smooth_Target_Enemy
Arguments:
Enemy_Index: The relative position in the monster group of the enemy to check.
Local Variables: None
How it Works: Ensures the enemy in the relative position passed to it is alive and not hidden. If the enemy is alive and not hidden, the enemy's ID is returned. If not, the loop at the end of the method iterates through the enemies in the monster group and returns the first one it finds that is alive and not hidden.
|
|