Home > RGSS Script Reference > Game_Enemy
Game_Enemy
Inherits from: Game_Battler
Description: This class defines an enemy, containing its stats, actions, treasure drops, and resistances. It also contains the code for deciding which action the monster should take.
class Game_Enemy < Game_Battler
# ------------------------------------
def initialize(troop_id, member_index)
super()
@troop_id = troop_id
@member_index = member_index
troop = $data_troops[@troop_id]
@enemy_id = troop.members[@member_index].enemy_id
enemy = $data_enemies[@enemy_id]
@battler_name = enemy.battler_name
@battler_hue = enemy.battler_hue
@hp = maxhp
@sp = maxsp
@hidden = troop.members[@member_index].hidden
@immortal = troop.members[@member_index].immortal
end
# ------------------------------------
def id
return @enemy_id
end
# ------------------------------------
def index
return @member_index
end
# ------------------------------------
def name
return $data_enemies[@enemy_id].name
end
# ------------------------------------
def base_maxhp
return $data_enemies[@enemy_id].maxhp
end
# ------------------------------------
def base_maxsp
return $data_enemies[@enemy_id].maxsp
end
# ------------------------------------
def base_str
return $data_enemies[@enemy_id].str
end
# ------------------------------------
def base_dex
return $data_enemies[@enemy_id].dex
end
# ------------------------------------
def base_agi
return $data_enemies[@enemy_id].agi
end
# ------------------------------------
def base_int
return $data_enemies[@enemy_id].int
end
# ------------------------------------
def base_atk
return $data_enemies[@enemy_id].atk
end
# ------------------------------------
def base_pdef
return $data_enemies[@enemy_id].pdef
end
# ------------------------------------
def base_mdef
return $data_enemies[@enemy_id].mdef
end
# ------------------------------------
def base_eva
return $data_enemies[@enemy_id].eva
end
# ------------------------------------
def animation1_id
return $data_enemies[@enemy_id].animation1_id
end
# ------------------------------------
def animation2_id
return $data_enemies[@enemy_id].animation2_id
end
# ------------------------------------
def element_rate(element_id)
table = [0,200,150,100,50,0,-100]
result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
f = false
for i in @states
f |= $data_states[i].guard_element_set.include?(element_id)
end
if f
result /= 2
end
return result
end
# ------------------------------------
def state_ranks
return $data_enemies[@enemy_id].state_ranks
end
# ------------------------------------
def state_guard?(state_id)
return false
end
# ------------------------------------
def element_set
return []
end
# ------------------------------------
def plus_state_set
return []
end
# ------------------------------------
def minus_state_set
return []
end
# ------------------------------------
def actions
return $data_enemies[@enemy_id].actions
end
# ------------------------------------
def exp
return $data_enemies[@enemy_id].exp
end
# ------------------------------------
def gold
return $data_enemies[@enemy_id].gold
end
# ------------------------------------
def item_id
return $data_enemies[@enemy_id].item_id
end
# ------------------------------------
def weapon_id
return $data_enemies[@enemy_id].weapon_id
end
# ------------------------------------
def armor_id
return $data_enemies[@enemy_id].armor_id
end
# ------------------------------------
def treasure_prob
return $data_enemies[@enemy_id].treasure_prob
end
# ------------------------------------
def screen_x
return $data_troops[@troop_id].members[@member_index].x
end
# ------------------------------------
def screen_y
return $data_troops[@troop_id].members[@member_index].y
end
# ------------------------------------
def screen_z
return screen_y
end
# ------------------------------------
def escape
@hidden = true
self.current_action.clear
end
# ------------------------------------
def transform(enemy_id)
@enemy_id = enemy_id
@battler_name = $data_enemies[@enemy_id].battler_name
@battler_hue = $data_enemies[@enemy_id].battler_hue
make_action
end
# ------------------------------------
def make_action
self.current_action.clear
unless self.movable?
return
end
available_actions = []
rating_max = 0
for action in self.actions
n = $game_temp.battle_turn
a = action.condition_turn_a
b = action.condition_turn_b
if (b == 0 and n != a) or
(b > 0 and (n < 1 or n < a or n % b != a % b))
next
end
if self.hp * 100.0 / self.maxhp > action.condition_hp
next
end
if $game_party.max_level < action.condition_level
next
end
switch_id = action.condition_switch_id
if switch_id > 0 and $game_switches[switch_id] == false
next
end
available_actions.push(action)
if action.rating > rating_max
rating_max = action.rating
end
end
ratings_total = 0
for action in available_actions
if action.rating > rating_max - 3
ratings_total += action.rating - (rating_max - 3)
end
end
if ratings_total > 0
value = rand(ratings_total)
for action in available_actions
if action.rating > rating_max - 3
if value < action.rating - (rating_max - 3)
self.current_action.kind = action.kind
self.current_action.basic = action.basic
self.current_action.skill_id = action.skill_id
self.current_action.decide_random_target_for_enemy
return
else
value -= action.rating - (rating_max - 3)
end
end
end
end
end
end
|
Troop_ID: The ID of the monster group currenty being battled.
Member_Index: The relative position of the enemy within the monster group, from 0-7.
Enemy_ID: The monster ID of the enemy.
Battler_Name: The name of the file from which the monster is drawn.
Battler_Hue: The hue modification of the enemy's battle image. This can be changed in the "monster" section of the database by clicking on the battle graphic and using the slider at the bottom of the window.
Initialize
Arguments:
Troop_ID: The ID of the monster group currently being battled.
Member_Index: The relative position of the monster within the monster group.
Local Variables: None
How it Works: Sets up the monster's default state by reading data from $data_troops and $data_enemies.
ID
Arguments: None
Local Variables: None
How it Works: Returns the enemy ID of the monster as defined in the "monster" section of the database.
Index
Arguments: None
Local Variables: None
How it Works: Returns the monster's relative position within the monster group. If the monster isn't in the group, this method returns 0.
Name
Arguments: None
Local Variables: None
How it Works: Returns the name of the monster declared in the database.
Base_MaxHP
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Maximum HP. The return value of this method does not include the effects of any status effects.
Base_MaxSP
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Maximum SP. The return value of this method does not include the effects of any status effects.
Base_Str
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Strength. The return value of this method does not include the effects of any status effects.
Base_Dex
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Dexterity. The return value of this method does not include the effects of any status effects.
Base_Agi
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Agility. The return value of this method does not include the effects of any status effects.
Base_Int
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Intelligence. The return value of this method does not include the effects of any status effects.
Base_atk
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Attack Power. The return value of this method does not include the effects of any status effects.
Base_pdef
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Physical Defense. The return value of this method does not include the effects of any status effects.
Base_mdef
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Magical Defense. The return value of this method does not include the effects of any status effects.
Base_eva
Arguments: None
Local Variables: None
How it Works: Returns the monster's base Evasion. The return value of this method does not include the effects of any status effects.
Animation1_ID
Arguments: None
Local Variables: None
How it Works: Returns the ID of the monster's attacker animation.
Animation2_ID
Arguments: None
Local Variables: None
How it Works: Returns the ID of the monster's target animation.
Element_Rate
Arguments:
Element_ID: The element ID of the element for which the resistance is being checked.
Local Variables:
Table: An array of the six elemental damage multipliers from A-F. By default, this array contains the values [0,200,150,100,50,0,-100]. The first 0 is a buffer value.
Result: The elemental damage multiplier that is returned to the caller.
f: A boolean value that is true if any of the monster's status effects grant defense to that element. If f is true, the damage multiplier is divided by 2.
How it Works: This method returns the current damage multiplier for this monster with regard to the element passed to it.
State_Ranks
Arguments: None
Local Variables: None
How it Works: Returns the array of status resistance values for the monster.
State_Guard
Arguments:
State_ID: The ID of the status ailment to check for defense.
Local Variables: None
How it Works: Monsters can't equip items, so this method simply returns false.
Element_Set
Arguments: None
Local Variables: None
How it Works: A monster's normal attack can't have an element by default, so this method returns an empty array.
Plus_State_Set
Arguments: None
Local Variables: None
How it Works: A monster's normal attack can't inflict status ailments by default, so this method returns an empty array.
Minus_State_Set
Arguments: None
Local Variables: None
How it Works: A monster's normal attack can't remove status ailments by default, so this method returns an empty array.
Actions
Arguments: None
Local Variables: None
How it Works: Returns the monster's set of actions as defined in the database.
EXP
Arguments: None
Local Variables: None
How it Works: Returns the amount of experience points the party gets for defeating this monster as defined in the database.
Gold
Arguments: None
Local Variables: None
How it Works: Returns the amount of money the party gets for defeating this monster as defined in the database.
Item_ID
Arguments: None
Local Variables: None
How it Works: Returns the item the party may get for defeating this monster as defined in the database.
Weapon_ID
Arguments: None
Local Variables: None
How it Works: Returns the weapon the party may get for defeating this monster as defined in the database.
Armor_ID
Arguments: None
Local Variables: None
How it Works: Returns the defense item the party may get for defeating this monster as defined in the database.
Treasure_Prob
Arguments: None
Local Variables: None
How it Works: Returns the probability that the enemy will drop an item when defeated, as defined in the database.
Screen_X
Arguments: None
Local Variables: None
How it Works: Returns the X coordinate of the monster as defined in the Monster Groups section of the database.
Screen_Y
Arguments: None
Local Variables: None
How it Works: Returns the Y coordinate of the monster as defined in the Monster Groups section of the database.
Screen_Z
Arguments: None
Local Variables: None
How it Works: Returns the Z-index of the monster, which is equal to its Y coordinate. Therefore, if you want to overlap two or more monsters, you should place the monsters you want to appear "nearer" to the player closer to the bottom of the battle window.
Escape
Arguments: None
Local Variables: None
How it Works: This is the definition for the basic monster action "escape". The monster's @hidden flag is set, and its current action is cleared.
Transform
Arguments:
Enemy_ID: The ID of the monster into which the monster will transform.
Local Variables: None
How it Works: This method resolves the effect of the event command "Transform Monster". First, the method sets the monster's @enemy_id variable to the ID of the new monster. Its @battler_name and @battler_hue values are then set to those of the new monster, which redraws the monster on the screen. Finally, a call to make_action is made, which causes the monster to determine a new action in accordance with its new identity.
Make_Action
Arguments: None
Local Variables:
Available_Actions: An array containing the subset of actions which meet all of their preconditions for execution.
Rating_Max: The rating of the highest-rated action in the array of available actions.
Ratings_Total: The total value of the adjusted ratings of the available actions (see method description for details on the adjustment process).
How it Works: This method determines which action the monster will take next. First, if the monster already has an action set, it is cleared. Then, the method checks to see if self.movable? is true (that is, the monster isn't paralyzed by a status ailment). If it can't move, the method returns without giving the monster an action. The set of if statements that follows the movability check determine which subset of the monster's possible actions meet their preconditions as defined in the database. The first if statement checks to see if the current battle turn matches up with any turn requirement for the action. condition_turn_a is the absolute turn value specified, and condition_turn_b is the turn multiple specified. If the turn requirement is met, the method then checks the HP percentage precondition. Next, the method checks to see if the highest-level member of the party meets any necessary minimum level condition that was declared. The final check is to see if any switch that is required to be on for the action to take place is in fact on. If the action passes all of these tests, then it is added to the available_actions array. The next part of the method determines each action's relative chance of executing by adjusting their ratings based on the highest rating in the array of available actions. If an action's unadjusted rating is 3 or more points below the rating of the highest-rated action in the array of available actions, that action will never be chosen. For any action that is 0-2 rating points below the highest-rated action, the ratings_total += action.rating - (rating_max - 3) statement assigns the action an adjusted rating; 1 for actions 2 rating points below the highest rating, 2 for actions 1 rating point below the highest rating, and 3 for actions with a rating equal to the highest-rated action. The adjusted ratings are then summed up to get the total adjusted rating. Of the actions that are within 0-2 rating points of the highest-rated action, the probability that any one action will be chosen is (adjusted rating / sum of adjusted ratings). The final for loop makes the determination of which action to execute, and once it finds the action, sets the action's parameters and decides the action's target.
|
|