Advertisement
adiktuzmiko

Extended Blue Magic v1.01

May 22nd, 2013
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.38 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # Extended Blue Magic v1.01
  4. # by AdiktuzMiko
  5. # --- Date Created: 05/22/2013
  6. # --- Last Date Updated: 05/23/2013
  7. # --- Level: Easy
  8. # Requires:
  9. #         "Tag Manager" - by Tsukihime
  10. #         http://himeworks.wordpress.com/2013/03/07/tag-manager/
  11. #
  12. # Based/Edited on Blue Magic Script by:
  13. #     Mr. Bubble (http://mrbubblewand.wordpress.com/rgss3/blue-magic/)
  14. #
  15. # All I did was modify his script to enable multiple kinds of "blue" magic
  16. # by utilizing the Tag Manager by Tsukihime
  17. #
  18. # For those who don't know what blue magic is, its a method of learning
  19. # abilities from monsters that was introduced by Final Fantasy.
  20. # When a monster with a blue magic hits a blue mage, he will learn that
  21. # ability.
  22. #
  23. # Now, this script allows you to have more than one kind of "blue" magic
  24. # which gives you better flexibility on your "blue" magic escapades.
  25. #
  26. # If you only need a single blue magic type for your game, I would suggest
  27. # that you use the original version by Mr. Bubble
  28. #
  29. #==============================================================================
  30. #   ++ Notetags ++
  31. #==============================================================================
  32. #
  33. # Note tags will depend on the tags that you will set on the settings below
  34. #
  35. #==============================================================================
  36. #   ++ Installation ++
  37. #==============================================================================
  38. # Install this script in the Materials section in your project's
  39. # script editor.
  40. #
  41. # This script requires:
  42. #
  43. #     "Tag Manager" - by Tsukihime
  44. #         http://himeworks.wordpress.com/2013/03/07/tag-manager/
  45. #
  46. #==============================================================================
  47. #   ++ Compatibility ++
  48. #==============================================================================
  49. # This script aliases the following default VXA methods:
  50. #
  51. #     Game_ActionResult#clear
  52. #     Game_Battler#item_apply
  53. #     Scene_Battle#process_action_end
  54. #     Scene_Battle#use_item
  55. #    
  56. # There are no default method overwrites.
  57. #
  58. # I don't know if this is compatible with the original Blue Magic script by Mr. Bubble
  59. # but I don't see why you'll have them both in your game anyway
  60. #
  61. # Also, it doesn't seem to be compatible with the Yami Engine Ace - Charge Skill
  62. # script.
  63. #
  64. #==============================================================================
  65. #   ++ Terms and Conditions ++
  66. #==============================================================================
  67. #
  68. # The terms and conditions to be used on this script will be the same
  69. # as that of the original script for the moment.
  70. #
  71. #==============================================================================
  72.  
  73. $imported ||= {}
  74. $imported["ExtendedBlueMagic"] = true
  75.  
  76. #==========================================================================
  77. # ++ START OF USER CUSTOMIZATION MODULE ++
  78. #==========================================================================
  79.  
  80. #==========================================================================
  81. # ++ Adiktuz::Regexp
  82. #==========================================================================
  83. module Adiktuz
  84.   module Regexp
  85.     #register tags here
  86.     #key => "tagname",
  87.    
  88.     #remember that since this utilizes TagManager
  89.     #the actual tags that you put in the note boxes would be
  90.     #<tag: tagname>
  91.    
  92.     #BLUE_MAGIC_SKILLS_TAG lists the tags that you will put on skills
  93.     #that are to be specified as blue magic
  94.  
  95.     #BLUE_MAGIC_LEARNING_TAG lists the tags that you will put on
  96.     #actors, classes, equipments and states that should be given the
  97.     #blue mage property
  98.    
  99.     #If an actor is tagged as a blue mage, then he can learn the blue magic
  100.     #skills of that type
  101.     #If a class is tagged as a blue mage, then any actor of that class can
  102.     #learn the blue magic skills of that type
  103.     #If an equipment is tagged as a blue mage, then any actor that equips it
  104.     #can learn the blue magic skills of that type
  105.     #If a state is tagged as a blue mage, then any actor who has that state
  106.     #can learn the blue magic skills of that type
  107.    
  108.     #Example: If a skill tagged with <tag: oversoul> hits an actor tagged
  109.     #         with <tag: oversoullearn>, then that actor will learn that
  110.     #         skill
  111.  
  112.     #Remember also that multiple of these tags can be used on a single object
  113.    
  114.     #Example: Skill 1 can be both a dragonmagic and an oversoul
  115.     #         Actor 2 can be both a blue mage and an oversoul user
  116.     #         If skill 1 is used on Actor 2, he will learn that skill
  117.     #         since it has the oversoul tag, and the actor has the oversoullearn tag
  118.     #         Now if it hits for example Actor 3 that is only tagged as a bluemage
  119.     #         then actor 3 won't learn the ability since that ability is not
  120.     #         tagged as a blue magic  
  121.  
  122.     BLUE_MAGIC_SKILLS_TAG =
  123.     {
  124.         1 => "bluemagic",
  125.         2 => "dragonmagic",
  126.         3 => "oversoul",
  127.     }
  128.     BLUE_MAGIC_LEARNING_TAG =
  129.     {
  130.         1 => "bluemagiclearn",
  131.         2 => "dragonmagiclearn",
  132.         3 => "oversoullearn",
  133.     }
  134.    
  135.   end # module Regexp
  136. end # module Adiktuz
  137.  
  138. module Adiktuz
  139.   #==========================================================================
  140.   # ++ Blue Magic Settings
  141.   #==========================================================================
  142.   #
  143.   # All of these settings are to be set per key that you have placed on the
  144.   # tags part above.
  145.   #
  146.   # Make sure that all keys have registered values, else it might throw an error
  147.   #
  148.   # Example: If I have a key (3) on any of the settings or the tags, then
  149.   #          all settings and tags must also have an entry for the key (3)
  150.   module BlueMagic
  151.   #--------------------------------------------------------------------------
  152.   #   Alternative Blue Magic Learning Methods
  153.   #--------------------------------------------------------------------------
  154.   # true  : Actors can learn Blue Magic regardless of who it hits.
  155.   # false : Actors must be hit directly with Blue Magic to learn.
  156.   LEARN_BY_SIGHT =
  157.   {
  158.       1 => true,
  159.       2 => false,
  160.       3 => false,
  161.   }
  162.   # true  : Actors can learn Blue Magic cast by other actors.
  163.   # false : Actors can only learn Blue Magic from enemies.
  164.   LEARN_BY_ALLIES =
  165.   {
  166.       1 => false,
  167.       2 => false,
  168.       3 => false,
  169.   }
  170.  
  171.   #--------------------------------------------------------------------------
  172.   #   Blue Magic Learned Battle Message
  173.   #--------------------------------------------------------------------------
  174.   # This defines the message displayed in battle when an actor learns an
  175.   # Blue Magic skill.
  176.   #
  177.   # The first %s is automatically replaced by the actor's name.
  178.   # The second %2 is automatically replaced by the skill's name.
  179.   BLUE_MAGIC_LEARNED_MESSAGE =
  180.   {
  181.      1 => "%s learned %s.",
  182.      2 => "%s assimilated the dragon's %s.",
  183.      3 => "%s learned %s.",
  184.   }
  185.  
  186.   #--------------------------------------------------------------------------
  187.   #   Blue Magic Learned Sound Effect
  188.   #--------------------------------------------------------------------------
  189.   # Sound effect played when the Blue Magic learned message is displayed.
  190.   # Filename is a sound effect found in the Audio/SE/ folder.
  191.   #
  192.   #                        "filename", volume, pitch
  193.   BLUE_MAGIC_LEARNED_SE =
  194.   {
  195.      1 => [  "Chime2",     80,   100],
  196.      2 => [  "Chime2",     80,   100],
  197.      3 => [  "Chime2",     80,   100],
  198.   }
  199.  
  200.   #--------------------------------------------------------------------------
  201.   #   Blue Magic Message Wait
  202.   #--------------------------------------------------------------------------
  203.   # This setting determines how long the Blue Magic learned message is
  204.   # displayed in battle. Higher values increase the wait time.
  205.   BLUE_MAGIC_LEARNED_MESSAGE_WAIT =
  206.   {
  207.       1 => 3,
  208.       2 => 3,
  209.       3 => 3,
  210.   }
  211.  
  212.   end # module BlueMagic
  213. end # module Adiktuz
  214.  
  215.  
  216. #==========================================================================
  217. # ++ END OF USER CUSTOMIZATION MODULE ++
  218. #==========================================================================
  219.  
  220. #==========================================================================
  221. # ++ DO NOT TOUCH ++
  222. #==========================================================================
  223.  
  224. $Which = 0
  225.  
  226. #==============================================================================
  227. # ++ Sound
  228. #==============================================================================
  229. module Sound
  230.   #--------------------------------------------------------------------------
  231.   # new method : play_blue_magic_learned
  232.   #--------------------------------------------------------------------------
  233.   def self.play_blue_magic_learned
  234.     filename = Adiktuz::BlueMagic::BLUE_MAGIC_LEARNED_SE[$Which][0]
  235.     volume = Adiktuz::BlueMagic::BLUE_MAGIC_LEARNED_SE[$Which][1]
  236.     pitch = Adiktuz::BlueMagic::BLUE_MAGIC_LEARNED_SE[$Which][2]
  237.     Audio.se_play("Audio/SE/" + filename, volume, pitch)
  238.   end
  239.  
  240. end # module Sound
  241.  
  242.  
  243. #==============================================================================
  244. # ++ Window_BattleLog
  245. #==============================================================================
  246. class Window_BattleLog < Window_Selectable
  247.   #--------------------------------------------------------------------------
  248.   # new method : display_learned_blue_magic
  249.   #--------------------------------------------------------------------------
  250.   def display_learned_blue_magic(actor)
  251.     id = actor.result.blue_magic_skill_to_learn
  252.     fmt = Adiktuz::BlueMagic::BLUE_MAGIC_LEARNED_MESSAGE[$Which]
  253.     add_text( sprintf(fmt, actor.name, $data_skills[id].name) )
  254.     Sound.play_blue_magic_learned
  255.     Adiktuz::BlueMagic::BLUE_MAGIC_LEARNED_MESSAGE_WAIT[$Which].times do wait end
  256.     wait_for_effect
  257.   end
  258. end
  259.  
  260.  
  261. #==============================================================================
  262. # ++ Game_ActionResult
  263. #==============================================================================
  264. class Game_ActionResult
  265.   #--------------------------------------------------------------------------
  266.   # public instance variables
  267.   #--------------------------------------------------------------------------
  268.   attr_accessor :blue_magic_skill_to_learn
  269.   #--------------------------------------------------------------------------
  270.   # alias : clear
  271.   #--------------------------------------------------------------------------
  272.   alias clear_Adiktuz_bluemagic clear
  273.   def clear
  274.     clear_Adiktuz_bluemagic # alias
  275.    
  276.     @blue_magic_skill_to_learn = 0
  277.   end
  278. end
  279.  
  280.  
  281. #==============================================================================
  282. # ++ Game_Battler
  283. #==============================================================================
  284. class Game_Battler < Game_BattlerBase
  285.   #--------------------------------------------------------------------------
  286.   # alias : item_apply
  287.   #--------------------------------------------------------------------------
  288.   alias item_apply_Adiktuz_bluemagic item_apply
  289.   def item_apply(user, item)
  290.     item_apply_Adiktuz_bluemagic(user, item) # alias
  291.    
  292.     if blue_magic_learning_ok?(user, item)
  293.       @result.blue_magic_skill_to_learn = item.id
  294.     end
  295.   end
  296.  
  297.   #--------------------------------------------------------------------------
  298.   # new method : blue_magic_learning_ok?
  299.   #--------------------------------------------------------------------------
  300.   #This is done so that each ability and actor can have multiple
  301.   #bluemagic types and so that it will correctly process if any of those
  302.   #combinations are present
  303.   def blue_magic_learning_ok?(user, item)
  304.     if @result.hit? then
  305.       Adiktuz::Regexp::BLUE_MAGIC_LEARNING_TAG.each_pair do |index,value|
  306.          return true if blue_magic_learning?(index,value) && item.object_tags.include?(Adiktuz::Regexp::BLUE_MAGIC_SKILLS_TAG[index]) && blue_magic_learn_by_allies?(user)
  307.       end
  308.     end
  309.     return false
  310.   end
  311.  
  312.   #--------------------------------------------------------------------------
  313.   # new method : blue_magic_learning?
  314.   #--------------------------------------------------------------------------
  315.   def blue_magic_learning?(index,value)
  316.     if actor?
  317.         $Which = index
  318.         return true if self.actor.object_tags.include?(value)
  319.         return true if self.class.object_tags.include?(value)
  320.         for equip in equips
  321.          next if equip.nil?
  322.          return true if equip.object_tags.include?(value)
  323.         end
  324.           for state in states
  325.          next if state.nil?
  326.          return true if state.object_tags.include?(value)
  327.         end
  328.     end
  329.     return false
  330.   end # def blue_magic_learning?
  331.  
  332.   #--------------------------------------------------------------------------
  333.   # new method : blue_magic_learn_by_allies?
  334.   #--------------------------------------------------------------------------
  335.   def blue_magic_learn_by_allies?(user)
  336.     if user.actor?
  337.       return Adiktuz::BlueMagic::LEARN_BY_ALLIES[$which]
  338.     else
  339.       return true
  340.     end
  341.   end # def
  342.  
  343. end # class Game_Battler
  344.  
  345.  
  346. #==============================================================================
  347. # ++ Game_Actor
  348. #==============================================================================
  349. class Game_Actor < Game_Battler
  350.  
  351.   #--------------------------------------------------------------------------
  352.   # new method : new_blue_magic_skill_learned?
  353.   #--------------------------------------------------------------------------
  354.   def new_blue_magic_skill_learned?
  355.     skill_id = @result.blue_magic_skill_to_learn
  356.     return false unless skill_id > 0
  357.     return false if skill_learn?($data_skills[skill_id])
  358.     learn_skill(skill_id)
  359.     return true
  360.   end
  361.  
  362.   #--------------------------------------------------------------------------
  363.   # new method : blue_magic_skills
  364.   #--------------------------------------------------------------------------
  365.   # returns an array of Blue Magic skill ids learned by the battler
  366.   def blue_magic_skills
  367.     Adiktuz::Regexp::BLUE_MAGIC_SKILLS_TAG.each_value do |value|
  368.         @skills.select { |id| $data_skills[id].object_tags.include?(value) }
  369.     end
  370.   end
  371.  
  372.   #--------------------------------------------------------------------------
  373.   # new method : learnable_blue_magic_from_target
  374.   #--------------------------------------------------------------------------
  375.   def learnable_blue_magic_from_target(target)
  376.     target.blue_magic_skills.select { |id| !@skills.include?(id) }
  377.   end
  378.  
  379. end # class Game_Actor
  380.  
  381.  
  382. #==============================================================================
  383. # ++ Game_Enemy
  384. #==============================================================================
  385. class Game_Enemy < Game_Battler
  386.   #--------------------------------------------------------------------------
  387.   # new method : blue_magic_skills
  388.   #--------------------------------------------------------------------------
  389.   # returns an array of Blue Magic skill ids learned by the battler
  390.   def blue_magic_skills
  391.     skill_ids = enemy.actions.collect { |action| action.skill_id }
  392.     Adiktuz::Regexp::BLUE_MAGIC_SKILLS_TAG.each_key do |index|
  393.         skill_ids.uniq!.select! { |id| $data_skills[id].object_tags.include?(Adiktuz::Regexp::BLUE_MAGIC_SKILLS_TAG[index]) }
  394.     end
  395.   end
  396.  
  397. end # class Game_Enemy
  398.  
  399.  
  400. #==============================================================================
  401. # ++ Scene_Battle
  402. #==============================================================================
  403. class Scene_Battle < Scene_Base
  404.   #--------------------------------------------------------------------------
  405.   # alias : process_action_end
  406.   #--------------------------------------------------------------------------
  407.   # Checks all Blue Magic learn flags and displays message if found
  408.   alias process_action_end_Adiktuz_bluemagic process_action_end
  409.   def process_action_end
  410.     $game_party.members.each do |actor|
  411.       if actor.new_blue_magic_skill_learned?
  412.         @log_window.display_learned_blue_magic(actor)
  413.         @log_window.clear
  414.       end
  415.     end
  416.     process_action_end_Adiktuz_bluemagic # alias
  417.   end
  418.  
  419.   #--------------------------------------------------------------------------
  420.   # alias : use_item
  421.   #--------------------------------------------------------------------------
  422.   alias use_item_Adiktuz_bluemagic use_item
  423.   def use_item
  424.     use_item_Adiktuz_bluemagic # alias
  425.        
  426.     item = @subject.current_action.item
  427.     determine_blue_magic_learn_by_sight(@subject, item)
  428.   end # def
  429.  
  430.   #--------------------------------------------------------------------------
  431.   # new method : determine_blue_magic_learn_by_sight
  432.   #--------------------------------------------------------------------------
  433.   def determine_blue_magic_learn_by_sight(subject, item)
  434.     return unless subject
  435.     all_battle_members.each do |member|
  436.       if member.result.hit?
  437.         set_blue_magic_skill_to_learn_flags(item)
  438.         break
  439.       end # if
  440.     end # do
  441.   end # def
  442.    
  443.   #--------------------------------------------------------------------------
  444.   # new method : can_actor_learn?
  445.   #--------------------------------------------------------------------------
  446.   def can_actor_learn?(actor,item)
  447.     Adiktuz::Regexp::BLUE_MAGIC_LEARNING_TAG.each_pair do |index,value|
  448.         return true if actor.blue_magic_learning?(index,value) && item.object_tags.include?(Adiktuz::Regexp::BLUE_MAGIC_SKILLS_TAG[index])
  449.     end
  450.     return false
  451.   end
  452.  
  453.   #--------------------------------------------------------------------------
  454.   # new method : set_blue_magic_skill_to_learn_flags
  455.   #--------------------------------------------------------------------------
  456.   def set_blue_magic_skill_to_learn_flags(item)
  457.     $game_party.members.each do |actor|
  458.       if can_actor_learn?(actor,item)
  459.         if Adiktuz::BlueMagic::LEARN_BY_SIGHT[$Which] && blue_magic_learn_by_allies?(subject) then
  460.             actor.result.blue_magic_skill_to_learn = item.id
  461.         end
  462.       end # if
  463.     end # do
  464.   end # def
  465.    
  466.   #--------------------------------------------------------------------------
  467.   # new method : blue_magic_learn_by_allies?
  468.   #--------------------------------------------------------------------------
  469.   def blue_magic_learn_by_allies?(subject)
  470.     if subject.actor?
  471.       return Adiktuz::BlueMagic::LEARN_BY_ALLIES[$Which]
  472.     else
  473.       return true
  474.     end
  475.   end # def
  476.  
  477. end # class Scene_Battle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement