modern_algebra

Composite Characters / Visual Equipment v. 1.0.1

Sep 5th, 2016
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 46.64 KB | None | 0 0
  1. #==============================================================================
  2. #    Composite Graphics / Visual Equipment
  3. #    Version: 1.0.1
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: January 13, 2013
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This script allows you to "compose" face and character graphics out of
  10. #   multiple graphics. This permits you to make it so that equipment worn by
  11. #   a character can change the appearance of that actor's sprite and/or face.
  12. #
  13. #    Unlike my VX version, this script has a lot of new and improved features,
  14. #   including, but not limited to: support for faces and not just character
  15. #   sprites; a more flexible configuration scheme; the ability to set one
  16. #   equipment to draw different graphics onto different actors (useful, for
  17. #   instance, if you want an equipment to show a different graphic on males
  18. #   than it would on females).
  19. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  20. #  Instructions:
  21. #
  22. #    Paste this script into its own slot in the Script Editor (F11), above Main
  23. #   but below Materials.
  24. #
  25. #    I hope that this script is fairly straightforward to set up. The
  26. #   configuration may look daunting at first, and I have obviously gone a bit
  27. #   overboard on the volume of instructions I gave, but I trust that once you
  28. #   take a look you will find it to be quite easy and that really, all the
  29. #   codes are basically identical. I will start by going over how to setup
  30. #   actors, then move on to equipment, and then move on to events.
  31. #``````````````````````````````````````````````````````````````````````````````
  32. #  Actors:
  33. #
  34. #    The first thing to mention about actors is that the default character
  35. #   sprite is retained, so if the face or character sprite you setup there is
  36. #   sufficient, you do not have to spend much time configuring actors.
  37. #
  38. #    There are three codes you can use in an Actor's note box. Of these, \cc
  39. #   and \cf are identical as to how they are configured - the only difference
  40. #   is that \cc is setting up a character sprite while \cf is setting up a
  41. #   face. For that reason, I will go over these codes together. The general
  42. #   format for these codes are as follows (note that where there are numbers,
  43. #   such as 0 or 255, then that simply means that is the default value of that
  44. #   parameter - that is what you replace when you are setting it). It may seem
  45. #   a little daunting at first, but note that only the filename is a required
  46. #   parameter - the rest are just additional features.
  47. #
  48. #    \cc["filename", i0, h0, o255, z0, r0]
  49. #    \cf["filename", i0, h0, o255, z0, r0]
  50. #
  51. #      "filename" : this should be the name of the character or face file you
  52. #        want to load. You MUST put the quotation marks around it. Ie. if you
  53. #        wanted to load a character graphic from Actor1, you would put "Actor1"
  54. #      i0         : this is the index of the character or face you want in the
  55. #        characterset or faceset. The indices correspond to a particular
  56. #        graphic in the characterset or faceset, in the following manner:
  57. #                  0    1    2    3
  58. #                  4    5    6    7
  59. #        So if you want the third face in a faceset, you would put i2. Note
  60. #        that you can exclude the i and just put 2.
  61. #       h0        : this allows you to change the hue of a character or face
  62. #         graphic you select. It can be anything between 0 and 360. Ie. h65
  63. #         would change the hue by 65 degrees.
  64. #       o255      : this allows you to change the transparency of the character
  65. #         or face graphic selected. 255 is fully opaque, while 0 is fully
  66. #         transparent. Ie. o128 would add the face graphic but make it half
  67. #         see-through.
  68. #       z0        : this determines the order in which each of the graphics in
  69. #         a composite set are drawn. Those with lower z values are drawn before
  70. #         ones with higher z values. So, if you want to make sure that the hair
  71. #         is drawn over the skin, you need to set it so that the z value is
  72. #         higher. This can also be negative. Example: if you have four graphics
  73. #         on an actor, one with z-2, one with z2, one with z0, and one with z4,
  74. #         then the z-2 will be drawn first, then the z0, then the z2, and then
  75. #         the z4.
  76. #       r0        : The R-code is a way of setting up graphics that are
  77. #         replaced if one with a greater r-code is applied. It is useful for
  78. #         instance, if you want your actor to normally have a full head of hair,
  79. #         but want the hair to be removed if an actor is wearing a helmet. In
  80. #         that case, all you need to do is make sure they have the same r-code.
  81. #         Graphics with r-code of 0 all show up and are not replaced.
  82. #
  83. #   There are a lot of options here, but I note that you only need to fill in
  84. #  the filename and the rest of the parameters will default to the value above.
  85. #  In other words, if you want the hue to be 0, opacity to be 255, and R-code
  86. #  to to be 0, then you could exclude them all together and just specify the
  87. #  filename, index, and z value. Additionally, I should note that the default
  88. #  graphic of an actor you set through the normal way has only the filename and
  89. #  index set - the rest of the values are all default.
  90. #
  91. #    EXAMPLES:
  92. #      \cc["Actor1", 2]
  93. #        This will set it so that the third character graphic in the "Actor1"
  94. #       character set is drawn onto the character. Since no other values are
  95. #       set, they default to h0, o255, z0, r0.
  96. #      \cf["BackHair1", 3, z-1, h105, r1]
  97. #        This will set it so that the fourth face graphic in the "BackHair1"
  98. #       faceset will have its hue changed by 105 degrees and then drawn onto
  99. #       the actor's face graphic. Since it's z is -1, it will be drawn below
  100. #       anything with a higher z value, including the default face. It's r-code
  101. #       is 1, so if the actor equips anything else that has an r-code of 1,
  102. #       this graphic will not show up at all. Since the opacity is not set, it
  103. #       defaults to 255.
  104. #
  105. #    There is only one further setting you can configure in the Actor notebox,
  106. #   and it will probably make a little more sense once we look at equipment,
  107. #   but it is the following:
  108. #
  109. #      \ct[x, y, ..., z]
  110. #
  111. #    where x, y, and z are just a series of integers. What this feature does is
  112. #   set this actor's composite types, which will let you make equipments that
  113. #   draw different graphics depending on which actor is equipping the item. As
  114. #   I mentioned, this will become clearer once we look at equipment. Note that
  115. #   type 0 is automatically applied to all actors, and will be drawn on all
  116. #   actors.
  117. #
  118. #    EXAMPLES:
  119. #      \ct[2, 5]
  120. #        This actor has composite sets 2 and 5, so any equipment graphics of
  121. #       those types will be drawn on this actor.
  122. #``````````````````````````````````````````````````````````````````````````````
  123. #  Weapons & Armor:
  124. #  
  125. #    The codes for equipment are, in almost every respect, the same as that for
  126. #   actors. The only difference is that you have the option to set "type" for
  127. #   each graphic, in which case that graphic will only be drawn on an actor
  128. #   equipping this weapon or armor if that actor has the correct type. To set
  129. #   this, you use this code:
  130. #
  131. #      \cc0["filename", i0, h0, o255, z0, r0]
  132. #      \cf0["filename", i0, h0, o255, z0, r0]
  133. #
  134. #    As you can see, the stuff inside the square brackets is exactly the same
  135. #   as for actors. The difference lies in the number you place which lies
  136. #   directly before the square brackets. It is optional - if you do not place
  137. #   a number there at all (or if you put 0 there) then it will apply to every
  138. #   actor who equips the weapon or armor. However, if you put any integer above
  139. #   0, then it will only apply to actors who have that ID listed in their \ct[]
  140. #   code.
  141. #
  142. #  EXAMPLE:
  143. #    \cf["Helmet1", 2, z1, r1]
  144. #      Any actor who equips this item will have the 3rd graphic in the
  145. #     "Helmet1" faceset drawn oon their face. If that actor has as one of its
  146. #     base graphics something with an r-code of 1, then that will be erased and
  147. #     only the Helmet will show up.
  148. #    \cc4["Actor1", 5]
  149. #      The 6th character in the "Actor1" characterset will be drawn onto an
  150. #     an actor when he or she equips this item, but only if 4 is in that
  151. #     actor's \ct[] code.
  152. #``````````````````````````````````````````````````````````````````````````````
  153. #  Events:
  154. #
  155. #    You can also set up events to use composite characters, though not faces.
  156. #   To do so, you need to create a comment at the very top of a new page (must
  157. #   be the first line in the page), and in that comment you can use the exact
  158. #   same character codes as you can for actors:
  159. #
  160. #      \cc["filename", i0, h0, o255, z0, r0]
  161. #
  162. #    It is the exact same as with Actors. Additionally, you can use the
  163. #   following codes:
  164. #      \cc[a1]  - This allows you to set an event to the composite character of
  165. #        the actor with the specified ID. All you do is replace the 1 with the
  166. #        ID of the actor you want, so \cc[a5], for example, would make it so
  167. #        this event looked exactly like Actor 5, including equipment.
  168. #      \cc[p1]  - This is similar, except the index you give corresponds
  169. #        instead to the actor in that position in the party. It starts at one,
  170. #        so \cc[p1] would show the party leader, \cc[p2] the second member in
  171. #        the party, etc.
  172. #      \cc[w1]  - This will show the graphic you set for the weapon with that
  173. #        ID. So, for instance, \cc[w8] would apply the composite graphic of the
  174. #        weapon with ID 8 to the event.
  175. #      \cc[ar1] - This will show the graphic you set for the armor with that
  176. #        ID. So, for instance, \cc[ar3] would apply the composite graphic of the
  177. #        armor with ID 3 to the event.
  178. #
  179. #    Given that you can apply weapon and armor character graphics to an event,
  180. #   you can also use the \ct[] codes from Actor here if you are using that
  181. #   feature.
  182. #``````````````````````````````````````````````````````````````````````````````
  183. #  Messages:
  184. #
  185. #    This script introduces two new codes which can be used in messages to show
  186. #   actor faces, since otherwise you would be unable to show composite faces in
  187. #   messages. The codes are:
  188. #
  189. #      \af[x] - this will show the face of the actor with ID x
  190. #      \pf[x] - this will show the face of the party member in xth place. It
  191. #              starts at 1, so \pf[1] would show the face of the party leader,
  192. #              \pf[2] would show the second member's face, etc.
  193. #``````````````````````````````````````````````````````````````````````````````
  194. #  Adding & Removing Composite Graphics:
  195. #
  196. #    Firstly, I will note that the regular event command of Change Actor
  197. #   Graphic does work, but it will only change the basic sprite - it will not
  198. #   remove any of the composite graphics you set up through the notebox.
  199. #
  200. #    To add or remove composite graphics from events, you use the following
  201. #   code in a comment (NOT a script call!), wherever you want it to happen in
  202. #   the sequence of events:
  203. #
  204. #     \add_e1_cc["filename", i0, h0, o255, z0, r0]
  205. #     \remove_e1_cc["filename", i0, h0, o255, z0, r0]
  206. #
  207. #    As you can see, the arguments ("filename", etc.) are all identical to
  208. #   those with which you should now be familiar. The biggest difference is that
  209. #   you need to put remove_e1 or add_e1 before that stuff. Note, the 1 after e
  210. #   is the ID of the event. So, it can be any integer and the graphic will be
  211. #   added to or removed from the event with that ID. If you don't provide any
  212. #   ID, then it will go to the event from which it is called.
  213. #
  214. #    It is important to note that when you use a remove code, you do not need
  215. #   to specify every aspect of the code - what the script will do is simply get
  216. #   rid of every graphic that shares the parameters you do set in. So all you
  217. #   need to do is be specific enough with the arguments that you don't
  218. #   accidentally delete more than you want to delete.
  219. #      
  220. #    The codes for actors are similar:
  221. #
  222. #     \add_a1_cc["filename", i0, h0, o255, z0, r0]
  223. #     \remove_a1_cc["filename", i0, h0, o255, z0, r0]
  224. #     \add_a1_cf["filename", i0, h0, o255, z0, r0]
  225. #     \remove_a1_cf["filename", i0, h0, o255, z0, r0]
  226. #
  227. #   Again, replace the 1 after the a with the ID of the actor whose composite
  228. #   graphic you want to change.
  229. #
  230. #    Finally, you can also use the commands:
  231. #
  232. #     \add_p1_cc["filename", i0, h0, o255, z0, r0]
  233. #     \remove_p1_cc["filename", i0, h0, o255, z0, r0]
  234. #     \add_p1_cf["filename", i0, h0, o255, z0, r0]
  235. #     \remove_p1_cf["filename", i0, h0, o255, z0, r0]
  236. #
  237. #    That will change the composite graphic selected for the party member in
  238. #   that order. So, p1 would be the leader of the party, p2 the second actor
  239. #   in the party, etc...
  240. #==============================================================================
  241.  
  242. $imported = {} unless $imported
  243. $imported[:MA_CompositeGraphics] = true
  244.  
  245. #==============================================================================
  246. # *** RPG
  247. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  248. #  Summary of Changes:
  249. #    new module - MACGVE_Data_CompositeGraphic, mixed in with Actor & EquipItem
  250. #    modified class - Actor
  251. #==============================================================================
  252.  
  253. module RPG
  254.   #============================================================================
  255.   # *** MACGVE_Data_CompositeGraphic
  256.   #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  257.   #  This module holds a method to retrieve composite graphics. It is to be
  258.   # mixed in with the relevant data classes
  259.   #============================================================================
  260.  
  261.   module MACGVE_Data_CompositeGraphic
  262.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  263.     # * Composite Character and Composite Face methods - lazy instantiation
  264.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265.     [:character, :face].each { |method|
  266.       define_method(:"macgve_composite_#{method}") do |*args|
  267.         id, = *args
  268.         # Define @macgve_composite_ if undefined
  269.         if !instance_variable_defined?(:"@macgve_composite_#{method}")
  270.           instance_variable_set(:"@macgve_composite_#{method}", {})
  271.         end
  272.         if !instance_variable_get(:"@macgve_composite_#{method}")[id]
  273.           instance_variable_get(:"@macgve_composite_#{method}")[id] = []
  274.           idtos = id == 0 ? "0?" : id.to_s
  275.           note.scan(/\\C#{method.to_s[0,1] + idtos}\[(.+?)\]/im) { |str|
  276.             str[0].gsub!(/[\r\n]/, "")
  277.             cg = MACGVE_Data_CompositeGraphic.interpret_composite_graphic_string(str[0])
  278.             instance_variable_get(:"@macgve_composite_#{method}")[id] << cg
  279.           }
  280.         end
  281.         instance_variable_get(:"@macgve_composite_#{method}")[id]
  282.       end
  283.     }
  284.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  285.     # * Interpret Composite Graphic String
  286.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  287.     def self.interpret_composite_graphic_string(string, cg = MA_Composite_Graphic.new("", 0, 0, 255, 0, 0))
  288.       if cg.is_a?(Hash)
  289.         string.sub!(/["'](.+)["']/) { cg[:filename] = $1;    "" } # Filename: ""
  290.        string.sub!(/[Zz](-?\d+)/) { cg[:z] = $1.to_i;       "" } # Z:         0
  291.        string.sub!(/[Hh](\d+)/)   { cg[:hue] = $1.to_i;     "" } # Hue:       0
  292.        string.sub!(/[Oo](\d+)/)   { cg[:opacity] = $1.to_i; "" } # Opacity: 255
  293.        string.sub!(/[Rr](\d+)/)   { cg[:rcode] = $1.to_i;   "" } # R-Code:    0
  294.        string.sub!(/[Ii]?(\d+)/)  { cg[:index] = $1.to_i;   "" } # Index:     0
  295.      elsif cg.is_a?(MA_Composite_Graphic)
  296.        string.sub!(/["'](.+)["']/) { cg.filename = $1;     "" }  # Filename: ""
  297.        string.sub!(/[Zz](-?\d+)/)  { cg.z = $1.to_i;       "" }  # Z:         0
  298.        string.sub!(/[Hh](\d+)/)    { cg.hue = $1.to_i;     "" }  # Hue:       0
  299.        string.sub!(/[Oo](\d+)/)    { cg.opacity = $1.to_i; "" }  # Opacity: 255
  300.        string.sub!(/[Rr](\d+)/)    { cg.rcode = $1.to_i;   "" }  # R-Code:    0
  301.        string.sub!(/[Ii]?(\d+)/)   { cg.index = $1.to_i;   "" }  # Index:     0
  302.      end
  303.      cg
  304.    end
  305.  end
  306.  
  307.  #============================================================================
  308.  # ** Actor, EquipItem
  309.  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  310.  #  Summary of Changes:
  311.  #    MACGVE_Data_CompositeGraphic included in both classes
  312.  #    new method in Actor - macgve_composite_type
  313.  #============================================================================
  314.  
  315.  class Actor
  316.    include(MACGVE_Data_CompositeGraphic)
  317.    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  318.    # * Composite Type
  319.    #````````````````````````````````````````````````````````````````````````
  320.    #  This is a type set to an actor - mostly used to distinguish between
  321.    # visual equipment assigned to particular genders
  322.    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  323.    def macgve_composite_types
  324.      if !@macgve_composite_types
  325.        @macgve_composite_types = [0]
  326.        if note[/\\CT\[(.+)\]/i]
  327.          match = $1
  328.          match.scan(/\d+/).each { |id| @macgve_composite_types << id.to_i }
  329.        end
  330.        @macgve_composite_types.compact!
  331.      end
  332.      @macgve_composite_types
  333.    end
  334.  end
  335.  
  336.  EquipItem.send(:include, MACGVE_Data_CompositeGraphic)
  337. end
  338.  
  339. #==============================================================================
  340. # *** Cache
  341. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  342. #  Summary of Changes:
  343. #    new constant - MACGVE_PRESERVED_CHARACTERS
  344. #    new methods - self.macgve_composite_graphic_name; self.make_unique_name;
  345. #      self.macgve_create_composite_graphic; self.macgve_src_rect;
  346. #      self.macgve_get_individual_graphic; self.macgve_get_key;
  347. #      self.macgve_get_path; self.macgve_tidy_cg_array
  348. #    aliased method - clear; load_bitmap
  349. #==============================================================================
  350.  
  351. module Cache
  352.  class << self
  353.    alias macgve_clearcach_2jh5 clear
  354.    alias macgve_lodbmp_3nj6 load_bitmap
  355.  end
  356.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357.  # * Clear Cache
  358.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359.  def self.clear(*args, &block)
  360.    @macgve_name_cache ||= { face: {}, character: {} }
  361.    @macgve_name_cache.clear
  362.    @macgve_unique_name_id ||= 0
  363.    macgve_clearcach_2jh5(*args, &block)
  364.  end
  365.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  366.  # * Load Bitmap
  367.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  368.  def self.load_bitmap(folder_name, filename, *args)
  369.    path = folder_name + filename
  370.    if @cache && @cache[path] && @cache[path].disposed? && filename[0, 8] == "$macgve_"
  371.      retrieved_ary = macgve_cgary_from_name(filename)
  372.      recache_cg_from_key(*retrieved_ary) if retrieved_ary
  373.    end
  374.    macgve_lodbmp_3nj6(folder_name, filename, *args) # Call original method
  375.  end
  376.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  377.  # * Composite Graphic
  378.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  379.  def self.macgve_composite_graphic_name(type, composite_graphics)
  380.    cg_array = macgve_tidy_cg_array(composite_graphics)
  381.    return "" if cg_array.empty?
  382.    key = macgve_get_key(cg_array)
  383.    path = macgve_get_path(type)
  384.    @macgve_name_cache ||= { face: {}, character: {} }
  385.     # If no graphic for this cached
  386.    if !@macgve_name_cache[type].has_key?(key) ||
  387.        !include?(path + @macgve_name_cache[type][key])
  388.      name = macgve_make_unique_name(cg_array)
  389.      # Create new graphic and cache it
  390.      @cache[path + name] = macgve_create_composite_graphic(type, cg_array)
  391.      @macgve_name_cache[type][key] = name
  392.    end
  393.    @macgve_name_cache[type][key]    # Return cached graphic
  394.  end
  395.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  396.  # * Tidy Composite Graphic Array
  397.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  398.  def self.macgve_tidy_cg_array(cg_array)
  399.    cg_array = cg_array.select {|cg| cg.is_a?(MA_Composite_Graphic) && !cg.filename.empty? }
  400.    # Delete subordinate R-Codes - preserve latest of each type
  401.    rcodes = cg_array.collect { |cg| cg.rcode }
  402.    cg_array.delete_if { |cg| rcodes.shift != 0 && rcodes.include?(cg.rcode) }
  403.    cg_array.sort! {|a, b| a.z <=> b.z }
  404.  end
  405.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  406.  # * Get Key
  407.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  408.  def self.macgve_get_key(cg_array)
  409.    cg_array.collect {|cg| Array(cg)[0, 4] }.flatten
  410.  end
  411.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  412.  # * Get Path
  413.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414.  def self.macgve_get_path(type)
  415.    type == :character ? "Graphics/Characters/" : "Graphics/Faces/"
  416.  end
  417.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  418.  # * Make Unique Name
  419.  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  420.  def self.macgve_make_unique_name(cg_array = [])
  421.    @macgve_unique_name_id ||= 0
  422.    @macgve_unique_name_id += 1
  423.    #  Create a mostly garbage name to avoid accidental overwrite
  424.    char_ary = Array(0..9).collect {|i| i.to_s } + Array("a".."z") + Array("A".."Z")
  425.    rand_s = ""
  426.    24.times do rand_s += char_ary.sample end
  427.    result = "$macgve_#{rand_s}_#{@macgve_unique_name_id}"
  428.     result.insert(0, '!') if cg_array.any? {|cg| cg.filename[/^!/] != nil }
  429.     result
  430.   end
  431.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  432.   # * Create Composite Graphic
  433.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  434.   def self.macgve_create_composite_graphic(type, cg_array)
  435.     bmp_array = cg_array.collect {|cg| macgve_get_individual_graphic(type, cg) }
  436.     w = bmp_array.max_by { |bmp| bmp.width }.width
  437.     h = bmp_array.max_by { |bmp| bmp.height }.height
  438.     bitmap = Bitmap.new(w, h)
  439.     bmp_array.each { |bmp| bitmap.blt((bitmap.width - bmp.width) / 2,
  440.       bitmap.height - bmp.height, bmp, bmp.rect) }
  441.     bitmap # Return bitmap
  442.   end
  443.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  444.   # * Collect Individual Graphics
  445.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  446.   def self.macgve_get_individual_graphic(type, cg)
  447.     bmp = send(type, cg.filename) # Get graphic from file
  448.     src_rect = macgve_src_rect(type, bmp, cg)
  449.     bitmap = Bitmap.new(src_rect.width, src_rect.height)
  450.     bitmap.blt(0, 0, bmp, src_rect, cg.opacity)
  451.     bitmap.hue_change(cg.hue) if cg.hue != 0
  452.     bitmap
  453.   end
  454.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  455.   # * Get Source Rectangle
  456.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457.   def self.macgve_src_rect(type, bmp, cg)
  458.     if type == :face || type == :character
  459.       sign = cg.filename[/^[\!\$]./]
  460.       if sign && sign.include?('$')
  461.         w, h = bmp.width, bmp.height
  462.       else
  463.         w, h = bmp.width / 4, bmp.height / 2
  464.       end
  465.     else
  466.       w, h = bmp.width, bmp.height # Full graphic if unrecognized type
  467.     end
  468.     Rect.new((cg.index % 4) * w, (cg.index / 4) * h, w, h)
  469.   end
  470.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  471.   # * Get CG Array from Name
  472.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473.   def self.macgve_cgary_from_name(name)
  474.     @macgve_name_cache.keys.each { |key|
  475.       @macgve_name_cache[key].each_pair { |cg_key, cg_name|
  476.         return [key, name, cg_key] if cg_name == name } }
  477.     false
  478.   end
  479.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  480.   # * Recache CG from Key
  481.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  482.   def self.recache_cg_from_key(type, name, key)
  483.     return [] if !key || key.empty?
  484.     cg_array = []
  485.     for i in 0...(key.size / 4)
  486.       cg_array.push(MA_Composite_Graphic.new(*(key.slice!(0, 4) + [i, 0])))
  487.     end
  488.     @cache[macgve_get_path(type) + name] = macgve_create_composite_graphic(type, cg_array)
  489.     @macgve_name_cache ||= { face: {}, character: {} }
  490.     @macgve_name_cache[type][key] = name
  491.   end
  492. end
  493.  
  494. #==============================================================================
  495. # *** DataManager
  496. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  497. #  Summary of Changes:
  498. #    aliased method - extract_save_contents; make_save_header; load_header
  499. #==============================================================================
  500.  
  501. module DataManager
  502.   class << self
  503.     alias macgve_extractsave_2wm5 extract_save_contents
  504.     alias macgve_savehedr_2df6 make_save_header
  505.     alias macgve_ldheadr_6hk8 load_header
  506.   end
  507.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  508.   # * Extract Save Contents
  509.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  510.   def self.extract_save_contents(contents, *args, &block)
  511.     macgve_extractsave_2wm5(contents, *args, &block) # Call Original Method
  512.     # Initialize new data for actors if old save file
  513.     for i in 1...$data_actors.size
  514.       # If actor has been initialized in this save file but data not setup
  515.       if $game_actors.macgve_actor_init?(i) && !$game_actors[i].composite_equip_types
  516.         $game_actors[i].macgve_initialize_composite_graphics
  517.         $game_actors[i].macgve_extend_equips_to_refresh
  518.       end
  519.     end
  520.     $game_player.refresh
  521.   end
  522.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523.   # * Make Save Header
  524.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  525.   def self.make_save_header(*args, &block)
  526.     result = macgve_savehedr_2df6(*args, &block)
  527.     result[:cache_cgs] = []
  528.     #  Cycle through all values of the header (while :characters holds the
  529.     # characters by default, this is intended to check for the possibility
  530.     # that another script adds it under a different key - :face, for instance
  531.     result.values.flatten.each { |el|
  532.       if el.is_a?(String)
  533.         r = Cache.macgve_cgary_from_name(el)
  534.         result[:cache_cgs].push(r) if r
  535.       end
  536.     }
  537.     result
  538.   end
  539.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  540.   # * Load Header
  541.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  542.   def self.load_header(*args, &block)
  543.     result = macgve_ldheadr_6hk8(*args, &block) # Call Original Method
  544.     if result && result[:cache_cgs]
  545.       result[:cache_cgs].each { |type, name, cg_key|
  546.         cg_array = Cache.recache_cg_from_key(type, name, cg_key)
  547.       }
  548.     end
  549.     result
  550.   end
  551. end
  552.  
  553. #==============================================================================
  554. # *** MACGVE_BaseItem_Refresh
  555. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  556. #  This module is intended to be mixed in with instances of Game_BaseItem that
  557. # handle equipment, and it refreshes the player whenever equipment changes
  558. #==============================================================================
  559.  
  560. module MACGVE_BaseItem_Refresh
  561.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  562.   # * Set Object
  563.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  564.   def object=(*args, &block)
  565.     result = super(*args, &block)
  566.     $game_player.refresh
  567.     result
  568.   end
  569. end
  570.  
  571. #==============================================================================
  572. # ** Composite_Graphic
  573. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  574. #  This Struct holds data for composite graphics
  575. #==============================================================================
  576.  
  577. class MA_Composite_Graphic < Struct.new(:filename, :index, :hue, :opacity, :z, :rcode)
  578.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  579.   # * Equality?
  580.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  581.   def eql?(other)
  582.     # Don't check for z or rcode equality
  583.     other.is_a?(MA_Composite_Graphic) && @filename == other.filename &&
  584.       @index == other.index && @hue == other.hue && @opacity == other.opacity
  585.   end
  586.   alias == eql?
  587. end
  588.  
  589. #==============================================================================
  590. # ** Game Actor
  591. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  592. #  Summary of Changes:
  593. #    new public instance variables - composite_equip_types;
  594. #      base_composite_characte; base_composite_face;
  595. #    aliased methods - init_graphics; init_equips; character_name,
  596. #      character_index, face_name, face_index
  597. #    new methods - macgve_composite_character; macgve_composite_face;
  598. #      macgve_add_cg; macgve_remove_cg;
  599. #      macgve_initialize_composite_graphics
  600. #==============================================================================
  601.  
  602. class Game_Actor
  603.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  604.   # * Public Instance Variables
  605.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606.   attr_accessor :composite_equip_types
  607.   attr_accessor :base_composite_character
  608.   attr_accessor :base_composite_face
  609.   [:character, :face].each { |method|
  610.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  611.     # * Compose Character/Face
  612.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  613.     define_method(:"macgve_composite_#{method}") do |*args|
  614.       # Add all composite graphics from actor, equipments and states
  615.       basic = MA_Composite_Graphic.new(instance_variable_get(:"@#{method}_name"),
  616.         instance_variable_get("@#{method}_index"), 0, 255, 0, 0)
  617.       result = [basic] + instance_variable_get(:"@base_composite_#{method}")
  618.       equips.compact.each { |equip|
  619.         composite_equip_types.each { |t|
  620.           result += equip.send(:"macgve_composite_#{method}", t) } }
  621.       result
  622.     end
  623.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  624.     # * Character/Face Name
  625.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626.     alias_method(:"macgve_#{method}nm_2qa5", :"#{method}_name")
  627.     define_method(:"#{method}_name") do |*args|
  628.       if send(:"macgve_composite_#{method}").size > 1
  629.         Cache.macgve_composite_graphic_name(method, send(:"macgve_composite_#{method}"))
  630.       else
  631.         send(:"macgve_#{method}nm_2qa5", *args)
  632.       end
  633.     end
  634.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  635.     # * Character/Face Index
  636.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  637.     alias_method(:"macgve_#{method}ix_3fm9", :"#{method}_index")
  638.     define_method(:"#{method}_index") do |*args|
  639.       send(:"macgve_composite_#{method}").size > 1 ? 0 :
  640.         send(:"macgve_#{method}ix_3fm9", *args)
  641.     end
  642.   }
  643.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  644.   # * Initialize Graphics
  645.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  646.   alias macgve_initlzgraph_3dk4 init_graphics
  647.   def init_graphics(*args, &block)
  648.     macgve_initialize_composite_graphics
  649.     macgve_initlzgraph_3dk4(*args, &block)
  650.   end
  651.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  652.   # * Initialize Composite Graphics
  653.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  654.   def macgve_initialize_composite_graphics
  655.     @composite_equip_types = actor.macgve_composite_types
  656.     @base_composite_character = actor.macgve_composite_character
  657.     @base_composite_face = actor.macgve_composite_face
  658.   end
  659.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  660.   # * Initialize Equips
  661.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  662.   alias macgve_initequpment_2gu7 init_equips
  663.   def init_equips(*args, &block)
  664.     macgve_initequpment_2gu7(*args, &block)
  665.     macgve_extend_equips_to_refresh
  666.   end
  667.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  668.   # * Extend Equips to Refresh
  669.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  670.   def macgve_extend_equips_to_refresh
  671.     @equips.each { |eqp| eqp.send(:extend, MACGVE_BaseItem_Refresh) }
  672.   end
  673.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  674.   # * Add Composite Character/Face
  675.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  676.   def macgve_add_cg(type, arg = {})
  677.     case arg
  678.     when String then cg = RPG::MACGVE_Data_CompositeGraphic.interpret_composite_graphic_string(arg)
  679.     when Hash
  680.       cg = MA_Composite_Graphic.new("", 0, 0, 255, 0, 0)
  681.       arg.each_pair(key, value) { cg.send(:"#{key}=", value) }
  682.     when MA_Composite_Graphic then cg = arg
  683.     else
  684.       return
  685.     end
  686.     send(:"base_composite_#{type}") << cg
  687.     $game_player.refresh
  688.   end
  689.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  690.   # * Remove Composite Character/Face
  691.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  692.   def macgve_remove_cg(type, hash = {})
  693.     hash = RPG::MACGVE_Data_CompositeGraphic.interpret_composite_graphic_string(hash, {}) if hash.is_a?(String)
  694.     send(:"base_composite_#{type}").delete_if { |cg|
  695.       return_value = true
  696.       # If any element is not equal to the CG, then return false
  697.       hash.each_pair { |key, value|
  698.         unless cg.send(key) == value
  699.           return_value = false
  700.           break
  701.         end
  702.       }
  703.       return_value
  704.     }
  705.     $game_player.refresh
  706.   end
  707. end
  708.  
  709. #==============================================================================
  710. # ** Game Actors
  711. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  712. #  Summary of Changes:
  713. #    new method - macgve_actor_init?
  714. #==============================================================================
  715.  
  716. class Game_Actors
  717.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  718.   # * Actor Initialized?
  719.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  720.   def macgve_actor_init?(id)
  721.     @data[id] != nil
  722.   end
  723. end
  724.  
  725. #==============================================================================
  726. # ** Game Event
  727. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  728. #  Summary of Changes:
  729. #    aliased methods - clear_page_settings; setup_page_settings
  730. #    overwritten (super)methods - character_name; character_index
  731. #    new method - macgve_setup_composite_characters;
  732. #      interpret_composite_graphic_string
  733. #==============================================================================
  734.  
  735. class Game_Event
  736.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  737.   # * Public Instance Variables
  738.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  739.   attr_accessor :composite_equip_types
  740.   attr_accessor :base_composite_character
  741.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  742.   # * Clear Page Settings
  743.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  744.   alias macgve_clrpagesets_2rd8 clear_page_settings
  745.   def clear_page_settings(*args, &block)
  746.     @macgve_character_name = ""
  747.     macgve_clrpagesets_2rd8(*args, &block) # Call Original Method
  748.     @base_composite_characters = []
  749.   end
  750.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  751.   # * Setup Page Settings
  752.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  753.   alias macgve_setppagestngs_4qm3 setup_page_settings
  754.   def setup_page_settings(*args, &block)
  755.     macgve_setppagestngs_4qm3(*args, &block) # Call Original Method
  756.     macgve_setup_composite_characters
  757.   end
  758.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  759.   # * Setup Composite Characters
  760.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  761.   def macgve_setup_composite_characters
  762.     # Collect Comments
  763.     comment = maccve_get_first_comment
  764.     set_composite_equip_types(comment)
  765.     set_base_composite_characters(comment)
  766.     @macgve_character_name = Cache.macgve_composite_graphic_name(:character, macgve_composite_characters)
  767.     # If no original graphic
  768.     if @page.graphic.character_name.empty? && !@base_composite_characters.empty?
  769.       @pattern, @original_pattern = 1, 1
  770.       @tile_id = 0
  771.     end
  772.   end
  773.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  774.   # * Get First Comment
  775.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  776.   def maccve_get_first_comment
  777.     comment = ""
  778.     i = 0
  779.     while !@list[i].nil? && (@list[i].code == 108 || @list[i].code == 408)
  780.       comment += @list[i].parameters[0].dup
  781.       i += 1
  782.     end
  783.     comment
  784.   end
  785.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  786.   # * Set Composite Equip Types
  787.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  788.   def set_composite_equip_types(comment = "")
  789.     @composite_equip_types = [0]
  790.     unless comment[/\\CT\[(.+?)\]/i].nil?
  791.       match = $1
  792.       match.scan(/\d+/).each { |id| @composite_equip_types << id.to_i }
  793.     end
  794.     @composite_equip_types
  795.   end
  796.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  797.   # * Set Base Composite Characters
  798.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  799.   def set_base_composite_characters(comment = "")
  800.     @base_composite_characters = []
  801.     comment.scan(/\\CC\[(.+?)\]/i) { |str|
  802.       composite_equip_types.each { |id|
  803.         @base_composite_characters += interpret_composite_graphic_string(str[0], id)
  804.       }
  805.     }
  806.   end
  807.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  808.   # * Interpret Composite Graphic String
  809.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  810.   def interpret_composite_graphic_string(string, id = 0)
  811.     string.gsub!(/([APW]|AR)(\d+)/i) {
  812.       object =  case $1.upcase
  813.       when 'A'  then $game_actors[$2.to_i]            # Actor
  814.       when 'P'  then $game_party.members[$2.to_i - 1] # Party Member
  815.       when 'W'  then $data_weapons[$2.to_i]           # Weapon
  816.       when 'AR' then $data_armors[$2.to_i]            # Armor
  817.       end
  818.       return *object.macgve_composite_character(id) unless object.nil?
  819.       ""
  820.     }
  821.     [RPG::MACGVE_Data_CompositeGraphic.interpret_composite_graphic_string(string)]
  822.   end
  823.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  824.   # * Composite Characters
  825.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  826.   def macgve_composite_characters
  827.     # Add all composite graphics from actor, equipments and states
  828.     result = [MA_Composite_Graphic.new(@character_name, @character_index, 0, 255, 0, 0)]
  829.     result += @base_composite_characters if @base_composite_characters
  830.     result
  831.   end
  832.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  833.   # * Add Composite Character
  834.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  835.   def macgve_add_cc(string)
  836.     @base_composite_characters ||= []
  837.     @base_composite_characters.push(*interpret_composite_graphic_string(string))
  838.     @macgve_character_name = Cache.macgve_composite_graphic_name(:character, macgve_composite_characters)
  839.   end
  840.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  841.   # * Remove Composite Character
  842.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  843.   def macgve_remove_cc(string)
  844.     return unless @base_composite_characters
  845.     hash = RPG::MACGVE_Data_CompositeGraphic.interpret_composite_graphic_string(string, {})
  846.     @base_composite_characters.delete_if { |cg|
  847.       return_value = true
  848.       # If any element is not equal to the CG, then return false
  849.       hash.each_pair { |key, value|
  850.         unless cg.send(key) == value
  851.           return_value = false
  852.           break
  853.         end
  854.       }
  855.       return_value
  856.     }
  857.     @macgve_character_name = Cache.macgve_composite_graphic_name(:character, macgve_composite_characters)
  858.   end
  859.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  860.   # * Character Name/Index
  861.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  862.   alias macgve_crctrname_4dk8 character_name
  863.   def character_name
  864.     if !@base_composite_characters.empty? # If not just the base sprite
  865.       if @macgve_character_name.empty? || !Cache.include?("Graphics/Characters/" + @macgve_character_name)
  866.         @macgve_character_name = Cache.macgve_composite_graphic_name(:character, macgve_composite_characters)
  867.       end
  868.       @macgve_character_name
  869.     else # If no composite characters, just return the default.
  870.       macgve_crctrname_4dk8
  871.     end
  872.   end
  873.   alias macgve_charindx_2vd3 character_index
  874.   def character_index
  875.     !@base_composite_characters.empty? ? 0 : macgve_charindx_2vd3
  876.   end
  877. end
  878.  
  879. #==============================================================================
  880. # ** Game Interpreter
  881. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  882. #  Summary of Changes:
  883. #    aliased method - command_108
  884. #    new method - macgve_interpret_cg_comment
  885. #    new methods - add_actor_cc; add_actor_cf; remove_actor_cc; remove_actor_cf
  886. #==============================================================================
  887.  
  888. class Game_Interpreter
  889.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  890.   # * Collect Comment
  891.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  892.   alias macgve_commnd108comments_1xh4 command_108
  893.   def command_108(*args, &block)
  894.     macgve_commnd108comments_1xh4(*args, &block) # Call Original Method
  895.     macgve_interpret_cg_comment(@comments.join)
  896.   end
  897.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  898.   # * Interpret Composite Graphic Comment
  899.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  900.   def macgve_interpret_cg_comment(comment)
  901.     comment.scan(/\\(add|remove)_([eap])(-?\d*)_c([cf])\[(.+?)\]/i) { |oper, char, id, type, args|
  902.       case char.upcase
  903.       when 'A' then actor = $game_actors[id.empty? ? 1 : id.to_i]
  904.       when 'P' then actor = $game_party.members[id.empty? ? 0 : id.to_i - 1]
  905.       when 'E' then id.to_i < 0 ? actor = $game_player.actor : event = get_character(id.to_i)
  906.       end
  907.       type = type.upcase == 'C' ? :character : :face
  908.       actor.send(:"macgve_#{oper.downcase}_cg", type, args) unless actor.nil?
  909.       event.send(:"macgve_#{oper.downcase}_cc", args) unless event.nil?
  910.     }
  911.   end
  912. end
  913.  
  914. #==============================================================================
  915. # ** Window_Base
  916. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  917. #  Summary of Changes:
  918. #    aliased method - draw_face
  919. #==============================================================================
  920.  
  921. class Window_Base
  922.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923.   # * Draw Face
  924.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  925.   alias masff_drawfac_1wk7 draw_face
  926.   def draw_face(face_name, face_index, *args, &block)
  927.     if face_index == 0 && face_name[/^$/]
  928.       ma_draw_single_face(face_name, *args, &block) # Draw single face
  929.     else
  930.       # Call Original Method
  931.       masff_drawfac_1wk7(face_name, face_index, *args, &block)
  932.     end
  933.   end
  934.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  935.   # * Draw Single Face
  936.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  937.   unless method_defined?(:ma_draw_single_face)
  938.     def ma_draw_single_face(face_name, x, y, enabled = true)
  939.       bmp = Cache.face(face_name)
  940.       contents.blt(x, y, bmp, bmp.rect, enabled ? 255 : translucent_alpha)
  941.     end
  942.   end
  943. end
  944.  
  945. #==============================================================================
  946. # ** Window_Message
  947. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  948. #  Summary of Changes:
  949. #    aliased (super)method - new_page; process_escape_character
  950. #    new method - macgve_new_page
  951. #==============================================================================
  952.  
  953. class Window_Message
  954.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  955.   # * New Page
  956.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  957.   if instance_methods(false).include?(:new_page)
  958.     alias macgve_newpage_5di4 new_page
  959.     def new_page(text, pos, *args, &block)
  960.       result = macgve_new_page(text, pos, *args, &block)
  961.       macgve_newpage_5di4(result, pos, *args, *block) # Call Original Method
  962.     end
  963.   else
  964.     def new_page(text, pos, *args, &block)
  965.       result = macgve_new_page(text, pos, *args, &block)
  966.       super(result, pos, *args, *block) # Call Original Method
  967.     end
  968.   end
  969.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  970.   # * Check First Code for Face
  971.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  972.   def macgve_new_page(text, pos, *args, &block)
  973.     result = text.dup
  974.     # Remove AF or PF code and process it
  975.     if result[/\A\e[AP]F\[\d+\]/i] != nil
  976.       result.sub!(/\A\e([AP]F)/i, "")
  977.       process_escape_character($1, result, pos)
  978.     end
  979.     return result
  980.   end
  981.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  982.   # * Process Escape Character
  983.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  984.   alias macgve_procesccha_2gk1 process_escape_character
  985.   def process_escape_character(code, text, *args, &block)
  986.     if code.upcase[/([AP])F/] != nil
  987.       type = ($1 == 'A')
  988.       param = obtain_escape_param(text)
  989.       actor = type ? $game_actors[param] : $game_party.members[param - 1]
  990.       if actor
  991.         # Change face to that of the chosen actor
  992.         $game_message.face_name = actor.face_name
  993.         $game_message.face_index = actor.face_index
  994.       end
  995.     else
  996.       macgve_procesccha_2gk1(code, text, *args, &block) # Call Original Method
  997.     end
  998.   end
  999. end
Add Comment
Please, Sign In to add comment