Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Game_Party

Game_Party


Inherits from: None

Description: This class contains methods that deal with the party as a whole, rather than an individual party member. These methods include those for gaining/losing money and items, adding/removing party members, and some utility methods for battles.

Code


class Game_Party
# ------------------------------------  
  attr_reader   :actors
  attr_reader   :gold
  attr_reader   :steps
# ------------------------------------  
  def initialize
    @actors = []
    @gold = 0
    @steps = 0
    @items = {}
    @weapons = {}
    @armors = {}
  end
# ------------------------------------
  def setup_starting_members
    @actors = []
    for i in $data_system.party_members
      @actors.push($game_actors[i])
    end
  end
# ------------------------------------  
  def setup_battle_test_members
    @actors = []
    for battler in $data_system.test_battlers
      actor = $game_actors[battler.actor_id]
      actor.level = battler.level
      gain_weapon(battler.weapon_id, 1)
      gain_armor(battler.armor1_id, 1)
      gain_armor(battler.armor2_id, 1)
      gain_armor(battler.armor3_id, 1)
      gain_armor(battler.armor4_id, 1)
      actor.equip(0, battler.weapon_id)
      actor.equip(1, battler.armor1_id)
      actor.equip(2, battler.armor2_id)
      actor.equip(3, battler.armor3_id)
      actor.equip(4, battler.armor4_id)
      @actors.push(actor)
    end
    @items = {}
    for i in 1...$data_items.size
      if $data_items[i].name != ""
        occasion = $data_items[i].occasion
        if occasion == 0 or occasion == 1
          @items[i] = 99
        end
      end
    end
  end
# ------------------------------------  
  def refresh
      for i in 0...@actors.size
      @actors[i] = $game_actors[@actors[i].id]
    end
  end
# ------------------------------------  
  def max_level
    if @actors.size == 0
      return 0
    end
    level = 0
    for actor in @actors
      if level < actor.level
        level = actor.level
      end
    end
    return level
  end
# ------------------------------------  
  def add_actor(actor_id)
    actor = $game_actors[actor_id]
    if @actors.size < 4 and not @actors.include?(actor)
      @actors.push(actor)
      $game_player.refresh
    end
  end
# ------------------------------------  
  def remove_actor(actor_id)
    @actors.delete($game_actors[actor_id])
    $game_player.refresh
  end
# ------------------------------------  
  def gain_gold(n)
    @gold = [[@gold + n, 0].max, 9999999].min
  end
# ------------------------------------  
  def lose_gold(n)
    gain_gold(-n)
  end
# ------------------------------------  
  def increase_steps
    @steps = [@steps + 1, 9999999].min
  end
# ------------------------------------  
  def item_number(item_id)
    return @items.include?(item_id) ? @items[item_id] : 0
  end
# ------------------------------------  
  def weapon_number(weapon_id)
    return @weapons.include?(weapon_id) ? @weapons[weapon_id] : 0
  end
# ------------------------------------  
  def armor_number(armor_id)
    return @armors.include?(armor_id) ? @armors[armor_id] : 0
  end
# ------------------------------------  
  def gain_item(item_id, n)
    if item_id > 0
      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
    end
  end
# ------------------------------------  
  def gain_weapon(weapon_id, n)
    if weapon_id > 0
      @weapons[weapon_id] = [[weapon_number(weapon_id)
+ n, 0].max, 99].min end end # ------------------------------------ def gain_armor(armor_id, n) if armor_id > 0 @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min end end # ------------------------------------ def lose_item(item_id, n) gain_item(item_id, -n) end # ------------------------------------ def lose_weapon(weapon_id, n) gain_weapon(weapon_id, -n) end # ------------------------------------ def lose_armor(armor_id, n) gain_armor(armor_id, -n) end # ------------------------------------ def item_can_use?(item_id) if item_number(item_id) == 0 return false end occasion = $data_items[item_id].occasion if $game_temp.in_battle return (occasion == 0 or occasion == 1) end return (occasion == 0 or occasion == 2) end # ------------------------------------ def clear_actions for actor in @actors actor.current_action.clear end end # ------------------------------------ def all_dead? if $game_party.actors.size == 0 return false end for actor in @actors if actor.hp > 0 return false end end return true end # ------------------------------------ def check_map_slip_damage for actor in @actors if actor.hp > 0 and actor.slip_damage? actor.hp -= actor.maxhp / 100 if actor.hp == 0 $game_system.se_play($data_system.actor_collapse_se) end $game_screen.start_flash(Color.new(255,0,0,128), 4) end end end # ------------------------------------ def random_target_actor(hp0 = false) roulette = [] for actor in @actors if (not hp0 and actor.exist?) or (hp0 and actor.hp0?) position = $data_classes[actor.class_id].position n = 4 - position n.times do roulette.push(actor) end end end if roulette.size == 0 return nil end return roulette[rand(roulette.size)] end # ------------------------------------ def random_target_actor_hp0 return random_target_actor(true) end # ------------------------------------ def smooth_target_actor(actor_index) actor = @actors[actor_index] if actor != nil and actor.exist? return actor end for actor in @actors if actor.exist? return actor end end end end

Properties


Actors: An array containing Game_Actor objects representing the actors currently in the party.

Gold: The amount of money possessed by the party.

Steps: The number of steps the party has taken.

Items: A hash table. The keys are item IDs, and the values are the number of that item possessed by the party.

Weapons: A hash table. The keys are item IDs, and the values are the number of that item possessed by the party.

Armors: A hash table. The keys are item IDs, and the values are the number of that item possessed by the party.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: Initializes the party variables to null values, representing an empty party with no money or items.

Setup_Starting_Members

Arguments: None
Local Variables: None

How it Works: This method adds the starting party members defined in the "System" section of the database to the party.

Setup_Battle_Test_Members

Arguments: None
Local Variables:
Occasion: The Usability of the item being evaluated.

How it Works: This method sets up the party members for a test battle. For each party member declared in the "Test Battle" dialog, the method adds and equips the selected weapons and armor. Finally, the method gives the party 99 of each non-weapon, non-armor item that can be used in battle.

Refresh

Arguments: None
Local Variables: None

How it Works: This method refreshes the party members. It is used immediately after loading a saved game to reconstitute the party.

Max_Level

Arguments: None
Local Variables:
Level: The highest level found so far.

How it Works: Finds the highest level of the actors in the party. If there are no actors currently in the party, this method returns 0. Otherwise, the method iterates through each actor and compares the value of level with the actor's level. If the actor's level is lower, the value of level is set to that actor's level.

Add_Actor

Arguments:
Actor: The ID of the actor to add.
Local Variables: None

How it Works: Adds an actor to the party. If the size of the party is less than 4 and the actor is not already in the party, the actor is added to the @actors array and the party is refreshed.

Remove_Actor

Arguments:
Actor: The ID of the actor to remove.
Local Variables: None

How it Works: Removes an actor from the party. If the actor is in the party, the actor is removed from the @actors array and the party is refreshed.

Gain_Gold

Arguments:
n: The amount of money to gain.
Local Variables: None

How it Works: Adds an amount of money equal to n to the party's funds. It is then bounds-checked. If the amount of money is below 0, it becomes 0. If it is higher than 9999999, it is reduced to 9999999.

Lose_Gold

Arguments:
n: The amount of money to lose.
Local Variables: None

How it Works: Removes an amount of money equal to n from the party's funds. It is then bounds-checked. If the amount of money is below 0, it becomes 0. If it is higher than 9999999, it is reduced to 9999999.

Increase_Steps

Arguments: None
Local Variables: None

How it Works: Increments the number of steps the party has taken. The number of steps can't increase above 9999999.

Item_Number

Arguments:
Item_ID: The item ID for which to search.
Local Variables: None

How it Works: Searches the @items hash table for the item with the specified ID. If the method finds the appropriate key in the hash table, it returns the value associated with that key. Otherwise, it returns 0.

Weapon_Number

Arguments:
Weapon_ID: The item ID for which to search.
Local Variables: None

How it Works: Searches the @weapons hash table for the item with the specified ID. If the method finds the appropriate key in the hash table, it returns the value associated with that key. Otherwise, it returns 0.

Armor_Number

Arguments:
Armor_ID: The item ID for which to search.
Local Variables: None

How it Works: Searches the @armors hash table for the item with the specified ID. If the method finds the appropriate key in the hash table, it returns the value associated with that key. Otherwise, it returns 0.

Gain_Item

Arguments:
Item_ID: The item ID of the item to gain.
n: The number of that item to gain.
Local Variables: None

How it Works: Adds n to the value of the hash table value associated with the key for Item_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Gain_Weapon

Arguments:
Weapon_ID: The item ID of the item to gain.
n: The number of that item to gain.
Local Variables: None

How it Works: Adds n to the value of the hash table value associated with the key for Weapon_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Gain_Armor

Arguments:
Armor_ID: The item ID of the item to gain.
n: The number of that item to gain.
Local Variables: None

How it Works: Adds n to the value of the hash table value associated with the key for Armor_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Lose_Item

Arguments:
Item_ID: The item ID of the item to lose.
n: The number of that item to lose.
Local Variables: None

How it Works: Subtracts n from the value of the hash table value associated with the key for Item_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Lose_Weapon

Arguments:
Weapon_ID: The item ID of the item to lose.
n: The number of that item to lose.
Local Variables: None

How it Works: Subtracts n from the value of the hash table value associated with the key for Weapon_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Lose_Armor

Arguments:
Armor_ID: The item ID of the item to lose.
n: The number of that item to lose.
Local Variables: None

How it Works: Subtracts n from the value of the hash table value associated with the key for Armor_ID. This value is then bounds-checked. If the value is less than 0, it becomes 0. If the value is above 99, it becomes 99.

Item_Can_Use?

Arguments:
Item_ID: The item ID of the item to check.
Local Variables:
Occasion: The Usability value of the item to check.

How it Works: This method checks to see if an item is usable at the present time based on its Usability value. If the item ID of the item to check is 0, the method returns false. Otherwise, the value of occasion is set to the Usability code of the item from $data_items (0 = Battle and Menu, 1 = Battle Only, 2 = Menu Only, 3 = Unusable). If the party is in battle, the method returns true if the Usability code is 0 or 1. If the party isn't in battle, the method returns true if the Usability code is 0 or 2.

Clear_Actions

Arguments: None
Local Variables: None

How it Works: This method iterates through the array of actors in the party and resets each actor's Game_BattleAction object to null values, clearing its action.

All_Dead?

Arguments: None
Local Variables: None

How it Works: Determines if every member of the party is dead. If there are no actors in the party, the method returns false. Otherwise, the method iterates through the array of actors in the party and checks to see if any one of them has HP greater than 0. If one does, the method returns false. Otherwise, the method returns true.

Check_Map_Slip_Damage

Arguments: None
Local Variables: None

How it Works: This method handles damage from poison and the like that persists even after battle. The method iterates through each actor and uses the Game_Battler#Slip_Damage? method to check if the actor is afflicted with one or more status ailments that has the "Slip Damage' property. For each living actor it finds, the actor loses 1% of it's maximum HP. If the actor HP is reduced to 0, the "collpase" SE defined in the "System" section of the database plays. If the method found any actors to damage, the screen flashes red for 4 frames.

Random_Target_Actor

Arguments:
HP0: A flag that determines whether the actor chosen should be one with 0 HP. false by default.
Local Variables:
Roulette: An array containing the subset of actors that are valid targets.
Position: The "Position" code of the actor's class (1 = Front, 2 = Middle, 3 = Back).
n: The number of times that the actor will be represented in the random selection. 3 for a an actor in the front, 2 for an actor in the middle, and 1 for an actor in the back.

How it Works: Decides a random target in the party, 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 actor in the party that has 1 or more HP (if hp0 is false) or 0 (if hp0 is true) the position value of the class associated with the actor determines how many times it is pushed onto the roulette array. The actor's ID is pushed into the roulette array three times if its position is "front", twice if its position is "middle", and once if its position is "back". Therefore, the actor is three times more likely to be targetted if it's in the front row than the back. If the roulette has at least one actor in it, the method chooses a random number between 0 and the roulette's size. The random target chosen is the actor in the array index chosen.

Random_Target_Actor_HP0

Arguments: None
Local Variables: None

How it Works: Calls the Random_Target_Actor method (see above) with the hp0 flag set to true.

Smooth_Target_Actor

Arguments:
Actor_Index: The relative position in the party of the actor to check.
Local Variables: None

How it Works: Ensures the actor in the relative position passed to it is alive. If the actor is alive, the actor's ID is returned. If not, the loop at the end of the method iterates through the actors in the party and returns the first one it finds that is alive. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal