Advertisement
AngryPacman

PAC Units

Jul 29th, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.76 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Units
  4. # 6/7/2011
  5. # Type: System
  6. # Installation: Script calls, plug-n-play.
  7. # Level: Average
  8. #
  9. #===============================================================================
  10. #
  11. # Description:
  12. # So, for whatever reason you've decided to make a tedious puzzle which requires
  13. # multiple parties, or you want a more diverse story that can be played at any
  14. # which when time, or you just want some cool gimmick to give your game that
  15. # memorable touch. Look no further (because MA has a similar script), this
  16. # script is here to fulfill your insane needs.
  17. #
  18. #===============================================================================
  19. #
  20. # Instructions:
  21. # INSTALLATION
  22. # Paste above main, below materials, in the script editor (F11). Remember to
  23. # save upon exiting.
  24. # SCRIPT CALLS
  25. # $game_units[id]       - accesses (creates if does not exist) the party located
  26. #                         in that ID.
  27. # $game_units[id] = x   - Sets the party to x. X must be a Game_Party object.
  28. # $game_units.merge_units(id1, id2, id3)
  29. #                       - Merges units id1, id2 and id3 (may be omitted).
  30. # $game_units.merge_and_delete(id1, id2, id3)
  31. #                       - Merges id1, id2 and id3 (may be omitted) and deletes
  32. #                         id2 and id3 if included.
  33. # $game_units.delete_unit(id, id2)
  34. #                       - Deletes the specified ids. Id2 may be omitted.
  35. #
  36. # To change the actve party, use the following:
  37. # $game_party = $game_units[id] - Where id is the party you want to access.
  38. # $game_player.refresh
  39. #
  40. # By default, $game_units[0] holds the default, original party. Work with 1, 2,
  41. # 3 etc. to avoid messing with crucial game data. Don't use 0.
  42. #
  43. #===============================================================================
  44.  
  45. #==============================================================================
  46. # ** Game_Party
  47. #------------------------------------------------------------------------------
  48. #  This class handles the party. It includes information on amount of gold
  49. # and items. The instance of this class is referenced by $game_party.
  50. #==============================================================================
  51.  
  52. class Game_Party < Game_Unit
  53.   #--------------------------------------------------------------------------
  54.   # * Multiple Step Add
  55.   #--------------------------------------------------------------------------
  56.   def add_multiple_steps(amount)
  57.     @steps += amount
  58.   end
  59. end
  60.  
  61. class Game_Units
  62.   #--------------------------------------------------------------------------
  63.   # * Object Initialization
  64.   #--------------------------------------------------------------------------
  65.   def initialize
  66.     @data = {0 => $game_party}
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # * Retrieve Unit
  70.   #   id : ID of the unit
  71.   #--------------------------------------------------------------------------
  72.   def [](id)
  73.     @data[id] = Game_Party.new if @data[id] == nil
  74.     return @data[id]
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * Set Unit
  78.   #--------------------------------------------------------------------------
  79.   def []= (id, unit)
  80.     return unless unit.class == Game_Party  # Do nothing if not Game_Party.
  81.     @data[id] = unit
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # * Merge Processing
  85.   #   id1 : ID of the first party, where the merge is stored.
  86.   #   id2 : ID of the second party.
  87.   #   id3 : ID of the third party. May be omitted.
  88.   #--------------------------------------------------------------------------
  89.   def merge_units(id1, id2, id3=nil)
  90.     new_unit = Game_Party.new # Set new unit
  91.     u1 = self[id1] # Get old units.
  92.     u2 = self[id2]
  93.     u3 = self[id3]
  94.     if id3 != nil  # If id3 is used
  95.       new_unit.gain_gold(u1.gold + u2.gold + u3.gold) # Gold
  96.       (u1.members + u2.members + u3.members).each { |actor| # Actors
  97.       new_unit.add_actor(actor.id) }
  98.       (u1.items + u2.items + u3.items).uniq.each { |item| # Items
  99.       new_unit.gain_item(item,u1.item_number(item) +  u2.item_number(item) +
  100.        u3.item_number(item))}
  101.       new_unit.add_multiple_steps(u1.steps + u2.steps + u3.steps) # Steps
  102.     else  # If id3 is not used
  103.       new_unit.gain_gold(u1.gold + u2.gold) # Gold
  104.       (u1.members + u2.members).each { |actor| new_unit.add_actor (actor.id) }
  105.       (u1.items + u2.items).uniq.each { |item|  # Items
  106.       new_unit.gain_item (item, u1.item_number(item) +  u2.item_number(item)) }
  107.       new_unit.add_multiple_steps(u1.steps + u2.steps)  # Steps
  108.     end
  109.     new_unit.last_item_id = u1.last_item_id # Aesthetic stuff.
  110.     new_unit.last_actor_index = u1.last_actor_index
  111.     new_unit.last_target_index = u1.last_target_index
  112.     return new_unit # Get new unit.
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Merge and Delete Processing
  116.   #   id1 : ID of the first party, which will hold the merged data.
  117.   #   id2 : ID of the second party, which will be deleted.
  118.   #   id3 : ID of the third party. May be omitted; will be deleted.
  119.   #--------------------------------------------------------------------------
  120.   def merge_and_delete(id1, id2, id3=nil)
  121.     if id3 != nil # If 3 is used
  122.       @data[id1] = merge_units(id1, id2, id3) # Merge the 3.
  123.       delete_unit(id2, id3) # Delete 2 and 3.
  124.     else  # If 3 is not used.
  125.       @data[id1] = merge_units(id1, id2)  # Merge the 2.
  126.       delete_unit(id2)  # Delete 2.
  127.     end
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # * Delete Processing
  131.   #   id1 : ID of the first party, which will be deleted.
  132.   #   id2 : ID of the second party, which may be omitted. It will be deleted.
  133.   #--------------------------------------------------------------------------
  134.   def delete_unit(id1, id2=nil)
  135.     @data[id1] = nil  # Null data.
  136.     if id1 == @data.size - 1  # If this was the last in the array
  137.       id1 -= 1  # Delete any nil objects between this ID and the next.
  138.       while @data[id1] == nil
  139.         @data.delete(id1)
  140.         id1 -= 1
  141.       end
  142.     end
  143.     if id2 != nil # Delete id2?
  144.       @data[id2] = nil  # Do the same.
  145.       if id2 == @data.size - 1
  146.         while @data[id2] == nil
  147.           @data.delete(id2)
  148.           id2 -= 1
  149.         end
  150.       end
  151.     end
  152.   end
  153. end
  154.  
  155. #==============================================================================
  156. # ** Scene_Title
  157. #------------------------------------------------------------------------------
  158. #  This class performs the title screen processing.
  159. #==============================================================================
  160.  
  161. class Scene_Title < Scene_Base
  162.   #--------------------------------------------------------------------------
  163.   # alias listing
  164.   #--------------------------------------------------------------------------
  165.   alias pac_mulprt_create_game_objects create_game_objects
  166.   #--------------------------------------------------------------------------
  167.   # * Create Game Objects
  168.   #--------------------------------------------------------------------------
  169.   def create_game_objects
  170.     pac_mulprt_create_game_objects
  171.     $game_units = Game_Units.new
  172.   end
  173. end
  174.  
  175. #==============================================================================
  176. # ** Scene_File
  177. #------------------------------------------------------------------------------
  178. #  This class performs the save and load screen processing.
  179. #==============================================================================
  180.  
  181. class Scene_File
  182.   #--------------------------------------------------------------------------
  183.   # alias listing
  184.   #--------------------------------------------------------------------------
  185.   alias pac_mulun_write_save_data write_save_data
  186.   alias pac_mulun_read_save_data read_save_data
  187.   #--------------------------------------------------------------------------
  188.   # * Write Save Data
  189.   #     file : write file object (opened)
  190.   #--------------------------------------------------------------------------
  191.   def write_save_data(file)
  192.     pac_mulun_write_save_data(file)
  193.     Marshal.dump($game_units, file)
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Read Save Data
  197.   #     file : file object for reading (opened)
  198.   #--------------------------------------------------------------------------
  199.   def read_save_data(file)
  200.     pac_mulun_read_save_data(file)
  201.     $game_units = Marshal.load(file)
  202.   end
  203. end
  204.  
  205. #===============================================================================
  206. #
  207. # END OF SCRIPT
  208. #
  209. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement