Advertisement
AngryPacman

PAC Party Management

Jul 29th, 2011
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.42 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Party Management System
  4. # 19/6/2011
  5. # Type: Scene
  6. # Installation: Script calls.
  7. # Level: Average
  8. #
  9. #===============================================================================
  10. #
  11. # Description:
  12. # VX limits your party to having 4 members. Isn't that terrible? This script
  13. # won't give you more members in your party, rather be able to change them
  14. # throughout the game at the player's call. Read the instructions to find out
  15. # more.
  16. #
  17. #===============================================================================
  18. #
  19. # Instructions:
  20. # INSTALLATION
  21. # Paste above main, below materials, in the script editor (F11). Make sure you
  22. # save upon exiting.
  23. # SCRIPT CALLS
  24. # $data_actors[ID].found = true/false
  25. # Where ID is the ID of an actor in the database. This places an actor in the
  26. # reserves party, ready for selection by the player if true, and takes them
  27. # out if false.
  28. # $data_actors[ID].unavailable = true/false
  29. # Makes actor with the specified ID unavailable to the player in the reserves
  30. # party if true. If false, makes them available.
  31. # $data_actors[ID].required = true/false
  32. # Locks actor with specified ID to the actual party, ergo mandatory to the
  33. # player, if true. Unlocks the character if false.
  34. # For each of these calls you can use, instead of $data_actors[ID],
  35. # $game_party.members[position].actor.found/unavailable/required to perform
  36. # the action for the actor in that position in the party, starting with 0 as
  37. # the party leader.
  38. # $game_party.party_menu_disabled = true/false
  39. # This will change the access of the command if PAC Main Menu is being used.
  40. # $scene = Scene_Party.new
  41. # Simply calls the Party Management scene. By default, there is no menu option
  42. # for the party scene, but it is simple to add if you are using PAC Main Menu,
  43. # and still quite easy if you are using the default menu system.
  44. #
  45. #===============================================================================
  46. #
  47. # This script requires no editing. Do not edit anything in this script
  48. # unless you are a compenent scripter. Should you edit without any scripting
  49. # education, it may result in me tutting at you for getting it wrong.
  50. #
  51. #===============================================================================
  52.  
  53. $imported = {} if $imported == nil
  54. $imported["PAC_Party"] = true
  55.  
  56. module PAC::MENU
  57.   PARTY_SWITCH = Input::X # Button which will switch between equip and status
  58.   # display in the party scene.
  59. end
  60.  
  61. #==============================================================================
  62. # ** RPG::Actor
  63. #------------------------------------------------------------------------------
  64. #  Data class for actors.
  65. #==============================================================================
  66.  
  67. class RPG::Actor  
  68.   #--------------------------------------------------------------------------
  69.   # Public Instance Variables
  70.   #--------------------------------------------------------------------------
  71.   attr_accessor :found
  72.   attr_accessor :unavailable
  73.   attr_accessor :required
  74.   #--------------------------------------------------------------------------
  75.   # * Setup
  76.   #--------------------------------------------------------------------------
  77.   def setup
  78.     @found = false
  79.     @unavailable = false
  80.     @required = false
  81.   end
  82. end
  83.  
  84. #==============================================================================
  85. # ** Game_Party
  86. #------------------------------------------------------------------------------
  87. #  This class handles the party. It includes information on amount of gold
  88. # and items. The instance of this class is referenced by $game_party.
  89. #==============================================================================
  90.  
  91. class Game_Party
  92.   #--------------------------------------------------------------------------
  93.   # Public Instance Variables
  94.   #--------------------------------------------------------------------------
  95.   attr_accessor :party_menu_disabled
  96.   #--------------------------------------------------------------------------
  97.   # alias listing
  98.   #--------------------------------------------------------------------------
  99.   alias pac_party_initialize initialize
  100.   #--------------------------------------------------------------------------
  101.   # * Object Initialization
  102.   #--------------------------------------------------------------------------
  103.   def initialize
  104.     pac_party_initialize
  105.     @party_menu_disabled = false
  106.   end
  107. end
  108.  
  109. #==============================================================================
  110. # ** Game_Actors
  111. #------------------------------------------------------------------------------
  112. #  This class handles the actor array. The instance of this class is
  113. # referenced by $game_actors.
  114. #==============================================================================
  115.  
  116. class Game_Actors
  117.   #--------------------------------------------------------------------------
  118.   # Public Instance Variables
  119.   #--------------------------------------------------------------------------
  120.   attr_reader :data
  121.   #--------------------------------------------------------------------------
  122.   # alias listing
  123.   #--------------------------------------------------------------------------
  124.   alias pac_pms_act_initialize initialize
  125.   #--------------------------------------------------------------------------
  126.   # * Object Initialization
  127.   #--------------------------------------------------------------------------
  128.   def initialize
  129.     pac_pms_act_initialize
  130.     $data_actors.each do |actor|
  131.       actor.setup if actor
  132.       @data[actor.id] = Game_Actor.new(actor.id) if actor
  133.     end
  134.   end
  135. end
  136.  
  137. #==============================================================================
  138. # ** Window_CurrentMember
  139. #------------------------------------------------------------------------------
  140. #  This window displays the current party member in the party scene.
  141. #==============================================================================
  142.  
  143. class Window_CurrentMember < Window_Base
  144.   #--------------------------------------------------------------------------
  145.   # Public Instance Variables
  146.   #--------------------------------------------------------------------------
  147.   attr_reader :mode
  148.   #--------------------------------------------------------------------------
  149.   # * Object Initialization
  150.   #--------------------------------------------------------------------------
  151.   def initialize(member = nil, mode = 0)
  152.     super(304, 80, 192, 256)
  153.     create_contents
  154.     @member = member
  155.     @mode = 0
  156.     refresh
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Get member
  160.   #--------------------------------------------------------------------------
  161.   def member
  162.     return @member
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Set Member
  166.   #--------------------------------------------------------------------------
  167.   def set_member(member)
  168.     old_member = @member
  169.     @member = member
  170.     refresh if old_member != @member
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # * Set modes
  174.   #--------------------------------------------------------------------------
  175.   def set_mode(mode)
  176.     @mode = mode if [0, 1].include?(mode)
  177.     refresh
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # * Refresh
  181.   #--------------------------------------------------------------------------
  182.   def refresh
  183.     self.contents.clear
  184.     return unless @member
  185.     x, y = 0, 0
  186.     self.draw_actor_face(@member, x, y, 48)
  187.     self.draw_actor_name(@member, x + 52, y)
  188.     self.draw_actor_class(@member, x + 52, y + WLH)
  189.     self.draw_actor_level(@member, x, y + WLH*2)
  190.     case @mode
  191.     when 0
  192.       self.draw_icon(142, self.contents.width - 24, y + WLH*2)
  193.       self.contents.draw_text(x, y + WLH*2, self.contents.width - 12, WLH,
  194.        'Equip', 2)
  195.       self.draw_actor_hp(@member, x, y + WLH*3, 160)
  196.       self.draw_actor_mp(@member, x, y + WLH*4, 160)
  197.       self.draw_actor_parameter(@member, x, y + WLH*5, 0)
  198.       self.draw_actor_parameter(@member, x, y + WLH*6, 1)
  199.       self.draw_actor_parameter(@member, x, y + WLH*7, 2)
  200.       self.draw_actor_parameter(@member, x, y + WLH*8, 3)
  201.     when 1
  202.       self.draw_icon(143, self.contents.width - 24, y + WLH*2)
  203.       self.contents.draw_text(x, y + WLH*2, self.contents.width - 12, WLH,
  204.        'Stat', 2)
  205.       for i in 0...@member.equips.size
  206.         item = @member.equips[i]
  207.         self.draw_item_name(item, x, y + WLH*(3+i), true)
  208.       end
  209.     end
  210.   end
  211. end
  212.  
  213. #==============================================================================
  214. # ** Window_CurrentParty
  215. #------------------------------------------------------------------------------
  216. #  This window displays the current party selected in the party scene.
  217. #==============================================================================
  218.  
  219. class Window_CurrentParty < Window_Selectable
  220.   #--------------------------------------------------------------------------
  221.   # * Object Initialization
  222.   #--------------------------------------------------------------------------
  223.   def initialize
  224.     super(48, 80, 256, 64)
  225.     @item_max = 4
  226.     @column_max = @item_max
  227.     create_contents
  228.     self.index = 0
  229.     refresh
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # * Get member
  233.   #--------------------------------------------------------------------------
  234.   def member
  235.     return $game_party.members[self.index]
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Refresh window
  239.   #--------------------------------------------------------------------------
  240.   def refresh
  241.     for i in 0...@item_max
  242.       rect = item_rect(i)
  243.       self.contents.clear_rect(rect)
  244.     end
  245.     for i in 0...$game_party.members.size
  246.       rect = item_rect(i)
  247.       bitmap = Cache.character($game_party.members[i].character_name)
  248.       sign = $game_party.members[i].character_name[/^[\!\$]./]
  249.       if sign != nil and sign.include?('$')
  250.         cw = bitmap.width / 3
  251.         ch = bitmap.height / 4
  252.       else
  253.         cw = bitmap.width / 12
  254.         ch = bitmap.height / 8
  255.       end
  256.       n = $game_party.members[i].character_index
  257.       src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  258.       if $game_party.members[i].actor.unavailable
  259.         self.contents.blt(rect.x, rect.y, bitmap, src_rect, 128)
  260.       else
  261.         self.contents.blt(rect.x, rect.y, bitmap, src_rect, 255)
  262.       end
  263.       if $game_party.members[i].actor.required
  264.         lock_bitmap = Cache.system("Locked")
  265.         self.contents.blt(rect.x + rect.width - lock_bitmap.width,
  266.         rect.y + rect.height - lock_bitmap.height,lock_bitmap,lock_bitmap.rect)
  267.       end
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Get rectangle for displaying items
  272.   #     index : item number
  273.   #--------------------------------------------------------------------------
  274.   def item_rect(index)
  275.     rect = Rect.new(0, 0, 0, 0)
  276.     rect.width = (contents.width + @spacing) / @column_max - @spacing
  277.     rect.height = 32
  278.     rect.x = index % @column_max * (rect.width + @spacing)
  279.     rect.y = index / @column_max * 32
  280.     return rect
  281.   end
  282. end
  283.  
  284. #==============================================================================
  285. # ** Window_SelectMember
  286. #------------------------------------------------------------------------------
  287. #  This window displays the currently selected member in the party scene.
  288. #==============================================================================
  289.  
  290. class Window_SelectMember < Window_Selectable
  291.   #--------------------------------------------------------------------------
  292.   # * Object Initialization
  293.   #--------------------------------------------------------------------------
  294.   def initialize
  295.     super(48, 144, 256, 192)
  296.     calculate_actors
  297.     @item_max = @actors.size + 1
  298.     @column_max = 4
  299.     self.index = -1
  300.     self.active = false
  301.     refresh
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * Calculate Actors
  305.   #--------------------------------------------------------------------------
  306.   def calculate_actors
  307.     @actors = []
  308.     for a in $game_actors.data
  309.       if a != nil and a.actor.found and !$game_party.members.include?(a)
  310.         @actors << a
  311.       end
  312.     end
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # * Get member
  316.   #--------------------------------------------------------------------------
  317.   def member
  318.     return @actors[self.index]
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # * Refresh Window
  322.   #--------------------------------------------------------------------------
  323.   def refresh
  324.     self.contents.clear
  325.     calculate_actors
  326.     @item_max = @actors.size + 1
  327.     for i in 0...@actors.size
  328.       rect = item_rect(i)
  329.       bitmap = Cache.character(@actors[i].character_name)
  330.       sign = @actors[i].character_name[/^[\!\$]./]
  331.       if sign != nil and sign.include?('$')
  332.         cw = bitmap.width / 3
  333.         ch = bitmap.height / 4
  334.       else
  335.         cw = bitmap.width / 12
  336.         ch = bitmap.height / 8
  337.       end
  338.       n = @actors[i].character_index
  339.       src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  340.       if @actors[i].actor.unavailable
  341.         self.contents.blt(rect.x, rect.y, bitmap, src_rect, 128)
  342.       else
  343.         self.contents.blt(rect.x, rect.y, bitmap, src_rect, 255)
  344.       end
  345.       if @actors[i].actor.required
  346.         lock_bitmap = Cache.system("Locked")
  347.         self.contents.blt(rect.x + rect.width - lock_bitmap.width,
  348.         rect.y + rect.height - lock_bitmap.height,lock_bitmap,lock_bitmap.rect)
  349.       end
  350.     end
  351.   end
  352.   #--------------------------------------------------------------------------
  353.   # * Get rectangle for displaying items
  354.   #     index : item number
  355.   #--------------------------------------------------------------------------  
  356.   def item_rect(index)
  357.     rect = Rect.new(0, 0, 0, 0)
  358.     rect.width = (contents.width + @spacing) / @column_max - @spacing
  359.     rect.height = 32
  360.     rect.x = index % @column_max * (rect.width + @spacing)
  361.     rect.y = index / @column_max * 32
  362.     return rect
  363.   end
  364. end
  365.  
  366. #==============================================================================
  367. # ** Scene_File
  368. #------------------------------------------------------------------------------
  369. #  This class performs the save and load screen processing.
  370. #==============================================================================
  371.  
  372. class Scene_File < Scene_Base
  373.   #--------------------------------------------------------------------------
  374.   # alias listing
  375.   #--------------------------------------------------------------------------
  376.   alias pac_pms_file_write_save_data write_save_data
  377.   alias pac_pms_file_read_save_data read_save_data
  378.   #--------------------------------------------------------------------------
  379.   # * Write Save Data
  380.   #     file : write file object (opened)
  381.   #--------------------------------------------------------------------------
  382.   def write_save_data(file)
  383.     pac_pms_file_write_save_data(file)
  384.     Marshal.dump($data_actors, file)
  385.   end
  386.   #--------------------------------------------------------------------------
  387.   # * Read Save Data
  388.   #     file : file object for reading (opened)
  389.   #--------------------------------------------------------------------------
  390.   def read_save_data(file)
  391.     pac_pms_file_read_save_data(file)
  392.     $data_actors = Marshal.load(file)
  393.   end
  394. end
  395.  
  396. #==============================================================================
  397. # ** Scene_Title
  398. #------------------------------------------------------------------------------
  399. #  This class performs the title screen processing.
  400. #==============================================================================
  401.  
  402. class Scene_Title < Scene_Base
  403.   #--------------------------------------------------------------------------
  404.   # alias listing
  405.   #--------------------------------------------------------------------------
  406.   alias pac_pms_ttl_command_new_game command_new_game
  407.   #--------------------------------------------------------------------------
  408.   # * Command: New Game
  409.   #--------------------------------------------------------------------------
  410.   def command_new_game
  411.     pac_pms_ttl_command_new_game
  412.     $game_party.members.each {|s| s.actor.found = true if s}
  413.   end
  414. end
  415.  
  416. #==============================================================================
  417. # ** Scene_Party
  418. #------------------------------------------------------------------------------
  419. #  This class performs the party screen processing.
  420. #==============================================================================
  421.  
  422. class Scene_Party < Scene_Base
  423.   include PAC::MENU
  424.   #--------------------------------------------------------------------------
  425.   # * Object Initialization
  426.   #--------------------------------------------------------------------------
  427.   def initialize(from_map = true, from_menu = false)
  428.     @from_map = from_map
  429.     @from_menu = from_menu
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # * Start processing
  433.   #--------------------------------------------------------------------------
  434.   def start
  435.     super
  436.     create_menu_background
  437.     create_windows
  438.   end
  439.   #--------------------------------------------------------------------------
  440.   # * Create windows
  441.   #--------------------------------------------------------------------------
  442.   def create_windows
  443.     @member_window = Window_CurrentMember.new
  444.     @party_window = Window_CurrentParty.new
  445.     @party_window.active = true
  446.     @selectable_window = Window_SelectMember.new
  447.   end
  448.   #--------------------------------------------------------------------------
  449.   # * Window update
  450.   #--------------------------------------------------------------------------
  451.   def update_windows
  452.     @member_window.update
  453.     @party_window.update
  454.     @selectable_window.update
  455.     if @party_window.active
  456.       @member_window.set_member(@party_window.member)
  457.     elsif @selectable_window.active
  458.       @member_window.set_member(@selectable_window.member)
  459.     end
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # * Termination Processing
  463.   #--------------------------------------------------------------------------
  464.   def terminate
  465.     super
  466.     @member_window.dispose
  467.     @party_window.dispose
  468.     @selectable_window.dispose
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # * Frame Update
  472.   #--------------------------------------------------------------------------
  473.   def update
  474.     super
  475.     update_windows
  476.     update_input
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Update Command Input
  480.   #--------------------------------------------------------------------------
  481.   def update_input
  482.     if Input.trigger?(PARTY_SWITCH) # If the button is being pressed...
  483.       if @member_window.mode == 1 # If equip mode is on,
  484.         @member_window.set_mode(0)  # Activate stats mode.
  485.       elsif @member_window.mode == 0  # If stats mode is on,
  486.         @member_window.set_mode(1)  # Activate equip mode.
  487.       end
  488.     end
  489.     if @party_window.active # If the party member is active
  490.       if Input.trigger?(Input::B) # If you want to leave,
  491.         if $game_party.members.size == 0  # If party is empty,
  492.           Sound.play_buzzer # Bee-bow.
  493.           return  # No soup for you
  494.         else
  495.           Sound.play_cancel # Bloop.
  496.           if @from_map
  497.             $scene = Scene_Map.new
  498.           elsif @from_menu
  499.             if $imported["PAC_Menu 1.7"]              
  500.               $scene = Scene_Menu.new
  501.             else
  502.               $scene = Scene_Menu.new(4)
  503.             end
  504.           end
  505.         end
  506.       elsif Input.trigger?(Input::C)  # If you want to do something,
  507.         member = @party_window.member # do stuff.
  508.         if member != nil
  509.           if member.actor.unavailable or member.actor.required
  510.             Sound.play_buzzer
  511.             return
  512.           end
  513.         end
  514.         Sound.play_decision
  515.         @party_window.active = false
  516.         @selectable_window.active = true
  517.         @selectable_window.index = 0
  518.       end
  519.     elsif @selectable_window.active
  520.       if Input.trigger?(Input::B)
  521.         Sound.play_cancel
  522.         @selectable_window.index = -1
  523.         @selectable_window.active = false
  524.         @party_window.active = true
  525.       elsif Input.trigger?(Input::C)
  526.         member = @selectable_window.member
  527.         if member != nil
  528.           if member.actor.unavailable
  529.             Sound.play_buzzer
  530.             return
  531.           end
  532.         end
  533.         Sound.play_decision
  534.         if @party_window.member != nil
  535.           $game_party.remove_actor(@party_window.member.id)
  536.         end
  537.         if @selectable_window.member != nil
  538.           $game_party.add_actor(@selectable_window.member.id)
  539.         end
  540.         @selectable_window.refresh
  541.         @party_window.refresh
  542.         @selectable_window.index = -1
  543.         @selectable_window.active = false
  544.         @party_window.active = true
  545.       end
  546.     end
  547.   end
  548. end
  549.  
  550. #===============================================================================
  551. #
  552. # END OF SCRIPT
  553. #
  554. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement