Advertisement
mrbubble

Blue Magic

Jul 29th, 2012
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.57 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Blue Magic ++                                              v1.0 (7/29/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. #--------------------------------------------------------------------------
  7. # This script is based off the concept of "Blue Magic" from the Final Fantasy
  8. # series. Blue Magic is the ability to use skills originally cast by enemies.
  9. # Those who have the talent to cast Blue Magic are called Blue Mages.
  10. #
  11. # This script is meant to serve a base script for future scripts also based
  12. # off the concept of Blue Magic/Blue Mages.
  13. #--------------------------------------------------------------------------
  14. #   ++ Changelog ++
  15. #--------------------------------------------------------------------------
  16. # v1.0 : Initial release. (7/29/2012)
  17. #--------------------------------------------------------------------------
  18. #   ++ Installation ++
  19. #--------------------------------------------------------------------------
  20. # Install this script in the Materials section in your project's
  21. # script editor.
  22. #==============================================================================
  23. #   ++ Blue Magic Notetags ++
  24. #==============================================================================
  25. # Note: Some tags are given shorter tags for typing convenience. You only
  26. #       need to use one <tag> from a given group for a notebox.
  27. #       Use common sense.
  28. #
  29. # The following Notetag is for Skills only:
  30. #
  31. # <blue magic>
  32. #   This tag flags the skill as Blue Magic. Actors capable of learning
  33. #   Blue Magic will learn the skill when directly hit by it.
  34. #
  35. # The following Notetag is for Actors, Classes, Weapons, Armors, and States:
  36. #
  37. # <blue magic: learning>
  38. #   This tag allows an Actor to learn Blue Magic skills when hit by them.
  39. #   If a Class has this tag, then an Actor must be that class to learn
  40. #   Blue Magic. If a Weapon or Armor has this tag, an Actor must equip
  41. #   it to take effect. If a State has this tag then an Actor must be
  42. #   inflicted by that state. Any Blue Magic learning notifications in
  43. #   battle are shown after an action is complete.
  44. #
  45. #--------------------------------------------------------------------------
  46. #   ++ Compatibility ++
  47. #--------------------------------------------------------------------------
  48. # This script aliases the following default VXA methods:
  49. #
  50. #     DataManager#load_database
  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. # Requests for compatibility with other scripts are welcome.
  59. #--------------------------------------------------------------------------
  60. #   ++ Terms and Conditions ++
  61. #--------------------------------------------------------------------------
  62. # Please do not repost this script elsewhere without permission.
  63. # Free for non-commercial use. For commercial use, contact me first.
  64. #
  65. # Newest versions of this script can be found at
  66. #                                           http://mrbubblewand.wordpress.com/
  67. #==============================================================================
  68.  
  69. $imported ||= {}
  70. $imported["BubsBlueMagic"] = true
  71.  
  72. #==========================================================================
  73. # ++ START OF USER CUSTOMIZATION MODULE ++
  74. #==========================================================================
  75. module Bubs
  76.   #==========================================================================
  77.   # ++ Blue Magic Settings
  78.   #==========================================================================
  79.   module BlueMagic
  80.   #--------------------------------------------------------------------------
  81.   #   Alternative Blue Magic Learning Methods
  82.   #--------------------------------------------------------------------------
  83.   # Be default, actors capable of learning Blue Magic will learn new spells
  84.   # by being directly hit by Blue Magic spells cast by enemies. These
  85.   # settings determine the alternative methods in which actors can learn
  86.   # Blue Magic.
  87.   #
  88.   # true  : Actors can learn Blue Magic regardless of who it hits.
  89.   # false : Actors must be hit directly with Blue Magic to learn.
  90.   LEARN_BY_SIGHT = false
  91.   # true  : Actors can learn Blue Magic cast by other actors.
  92.   # false : Actors can only learn Blue Magic from enemies.
  93.   LEARN_BY_ALLIES = false
  94.  
  95.   #--------------------------------------------------------------------------
  96.   #   Blue Magic Learned Battle Message
  97.   #--------------------------------------------------------------------------
  98.   # This defines the message displayed in battle when an actor learns a
  99.   # Blue Magic skill.
  100.   #
  101.   # The first %s is automatically replaced by the actor's name.
  102.   # The second %2 is automatically replaced by the skill's name.
  103.   BLUE_MAGIC_LEARNED_MESSAGE = "%s learned %s."
  104.  
  105.   #--------------------------------------------------------------------------
  106.   #   Blue Magic Learned Sound Effect
  107.   #--------------------------------------------------------------------------
  108.   # Sound effect played when the Blue Magic learned message is displayed.
  109.   # Filename is a sound effect found in the Audio/SE/ folder.
  110.   #
  111.   #                        "filename", volume, pitch
  112.   BLUE_MAGIC_LEARNED_SE = [  "Chime2",     80,   100]
  113.  
  114.   #--------------------------------------------------------------------------
  115.   #   Blue Magic Message Wait
  116.   #--------------------------------------------------------------------------
  117.   # This setting determines how long the Blue Magic learned message is
  118.   # displayed in battle. Higher values increase the wait time.
  119.   BLUE_MAGIC_LEARNED_MESSAGE_WAIT = 3
  120.  
  121.   end # module BlueMagic
  122. end # module Bubs
  123.  
  124. #==========================================================================
  125. # ++ END OF USER CUSTOMIZATION MODULE ++
  126. #==========================================================================
  127.  
  128.  
  129.  
  130.  
  131. #==============================================================================
  132. # ++ Sound
  133. #==============================================================================
  134. module Sound
  135.   #--------------------------------------------------------------------------
  136.   # new method : play_blue_magic_learned
  137.   #--------------------------------------------------------------------------
  138.   def self.play_blue_magic_learned
  139.     filename = Bubs::BlueMagic::BLUE_MAGIC_LEARNED_SE[0]
  140.     volume = Bubs::BlueMagic::BLUE_MAGIC_LEARNED_SE[1]
  141.     pitch = Bubs::BlueMagic::BLUE_MAGIC_LEARNED_SE[2]
  142.     Audio.se_play("/Audio/SE/" + filename, volume, pitch)
  143.   end
  144.  
  145. end # module Sound
  146.  
  147.  
  148. #==========================================================================
  149. # ++ DataManager
  150. #==========================================================================
  151. module DataManager
  152.   #--------------------------------------------------------------------------
  153.   # alias : load_database
  154.   #--------------------------------------------------------------------------
  155.   class << self; alias load_database_bubs_bluemagic load_database; end
  156.   def self.load_database
  157.     load_database_bubs_bluemagic # alias
  158.     load_notetags_bubs_bluemagic
  159.   end
  160.  
  161.   #--------------------------------------------------------------------------
  162.   # new method : load_notetags_bubs_bluemagic
  163.   #--------------------------------------------------------------------------
  164.   def self.load_notetags_bubs_bluemagic
  165.     groups = [$data_skills, $data_weapons, $data_armors, $data_actors,
  166.               $data_states, $data_classes, $data_enemies, $data_items]
  167.     for group in groups
  168.       for obj in group
  169.         next if obj.nil?
  170.         obj.load_notetags_bubs_bluemagic
  171.       end # for obj
  172.     end # for group
  173.   end # def
  174.  
  175. end # module DataManager
  176.  
  177.  
  178. #==========================================================================
  179. # ++ Bubs::Regexp
  180. #==========================================================================
  181. module Bubs
  182.   module Regexp
  183.     BLUE_MAGIC_SKILL_TAG = /<BLUE[_\s]?MAGIC>/i
  184.     BLUE_MAGIC_LEARNING_TAG = /<BLUE[_\s]?MAGIC:\s*LEARNING>/i
  185.    
  186.   end # module Regexp
  187. end # module Bubs
  188.  
  189.  
  190. #==========================================================================
  191. # ++ RPG::BaseItem
  192. #==========================================================================
  193. class RPG::BaseItem
  194.   #--------------------------------------------------------------------------
  195.   # public instance variables
  196.   #--------------------------------------------------------------------------
  197.   attr_accessor :blue_magic
  198.   attr_accessor :blue_magic_learning
  199.   #--------------------------------------------------------------------------
  200.   # common cache : load_notetags_bubs_bluemagic
  201.   #--------------------------------------------------------------------------
  202.   def load_notetags_bubs_bluemagic
  203.     @blue_magic = false if self.is_a?(RPG::UsableItem)
  204.     @blue_magic_learning = false unless self.is_a?(RPG::UsableItem)
  205.  
  206.     self.note.split(/[\r\n]+/).each { |line|
  207.       case line
  208.       when Bubs::Regexp::BLUE_MAGIC_SKILL_TAG
  209.         next unless self.is_a?(RPG::Skill)
  210.         @blue_magic = true
  211.        
  212.       when Bubs::Regexp::BLUE_MAGIC_LEARNING_TAG
  213.         next if self.is_a?(RPG::UsableItem)
  214.         @blue_magic_learning = true
  215.        
  216.       end # case
  217.     } # self.note.split
  218.   end # def load_notetags_bubs_bluemagic
  219. end # class RPG::BaseItem
  220.  
  221.  
  222. #==============================================================================
  223. # ++ Window_BattleLog
  224. #==============================================================================
  225. class Window_BattleLog < Window_Selectable
  226.   #--------------------------------------------------------------------------
  227.   # new method : display_learned_blue_magic
  228.   #--------------------------------------------------------------------------
  229.   def display_learned_blue_magic(actor)
  230.     id = actor.result.blue_magic_skill_to_learn
  231.     fmt = Bubs::BlueMagic::BLUE_MAGIC_LEARNED_MESSAGE
  232.     add_text( sprintf(fmt, actor.name, $data_skills[id].name) )
  233.     Sound.play_blue_magic_learned
  234.    
  235.     Bubs::BlueMagic::BLUE_MAGIC_LEARNED_MESSAGE_WAIT.times do wait end
  236.     wait_for_effect
  237.   end
  238. end
  239.  
  240.  
  241. #==============================================================================
  242. # ++ Game_ActionResult
  243. #==============================================================================
  244. class Game_ActionResult
  245.   #--------------------------------------------------------------------------
  246.   # public instance variables
  247.   #--------------------------------------------------------------------------
  248.   attr_accessor :blue_magic_skill_to_learn
  249.   #--------------------------------------------------------------------------
  250.   # alias : clear
  251.   #--------------------------------------------------------------------------
  252.   alias clear_bubs_bluemagic clear
  253.   def clear
  254.     clear_bubs_bluemagic # alias
  255.    
  256.     @blue_magic_skill_to_learn = 0
  257.   end
  258. end
  259.  
  260.  
  261. #==============================================================================
  262. # ++ Game_Battler
  263. #==============================================================================
  264. class Game_Battler < Game_BattlerBase
  265.   #--------------------------------------------------------------------------
  266.   # alias : item_apply
  267.   #--------------------------------------------------------------------------
  268.   alias item_apply_bubs_bluemagic item_apply
  269.   def item_apply(user, item)
  270.     item_apply_bubs_bluemagic(user, item) # alias
  271.    
  272.     if blue_magic_learning_ok?(user, item)
  273.       @result.blue_magic_skill_to_learn = item.id
  274.     end
  275.   end
  276.  
  277.   #--------------------------------------------------------------------------
  278.   # new method : blue_magic_learning_ok?
  279.   #--------------------------------------------------------------------------
  280.   def blue_magic_learning_ok?(user, item)
  281.     item.blue_magic && blue_magic_learning? && @result.hit? &&
  282.     blue_magic_learn_by_allies?(user)
  283.   end
  284.  
  285.   #--------------------------------------------------------------------------
  286.   # new method : blue_magic_learning?
  287.   #--------------------------------------------------------------------------
  288.   def blue_magic_learning?
  289.     if actor?
  290.       return true if self.actor.blue_magic_learning
  291.       return true if self.class.blue_magic_learning
  292.       for equip in equips
  293.         next if equip.nil?
  294.         return true if equip.blue_magic_learning
  295.       end
  296.       for state in states
  297.         next if state.nil?
  298.         return true if state.blue_magic_learning
  299.       end
  300.     end
  301.     return false
  302.   end # def blue_magic_learning?
  303.  
  304.   #--------------------------------------------------------------------------
  305.   # new method : blue_magic_learn_by_allies?
  306.   #--------------------------------------------------------------------------
  307.   def blue_magic_learn_by_allies?(user)
  308.     if user.actor?
  309.       return Bubs::BlueMagic::LEARN_BY_ALLIES
  310.     else
  311.       return true
  312.     end
  313.   end # def
  314.  
  315. end # class Game_Battler
  316.  
  317.  
  318. #==============================================================================
  319. # ++ Game_Actor
  320. #==============================================================================
  321. class Game_Actor < Game_Battler
  322.   #--------------------------------------------------------------------------
  323.   # new method : new_blue_magic_skill_learned?
  324.   #--------------------------------------------------------------------------
  325.   def new_blue_magic_skill_learned?
  326.     skill_id = @result.blue_magic_skill_to_learn
  327.     return false unless blue_magic_learning?
  328.     return false unless skill_id > 0
  329.     return false if skill_learn?($data_skills[skill_id])
  330.     learn_skill(skill_id)
  331.     return true
  332.   end
  333.  
  334.   #--------------------------------------------------------------------------
  335.   # new method : blue_magic_skills
  336.   #--------------------------------------------------------------------------
  337.   # returns an array of Blue Magic skill ids learned by the battler
  338.   def blue_magic_skills
  339.     @skills.select { |id| $data_skills[id].blue_magic }
  340.   end
  341.  
  342.   #--------------------------------------------------------------------------
  343.   # new method : learnable_blue_magic_from_target
  344.   #--------------------------------------------------------------------------
  345.   def learnable_blue_magic_from_target(target)
  346.     target.blue_magic_skills.select { |id| !@skills.include?(id) }
  347.   end
  348.  
  349. end # class Game_Actor
  350.  
  351.  
  352. #==============================================================================
  353. # ++ Game_Enemy
  354. #==============================================================================
  355. class Game_Enemy < Game_Battler
  356.   #--------------------------------------------------------------------------
  357.   # new method : blue_magic_skills
  358.   #--------------------------------------------------------------------------
  359.   # returns an array of Blue Magic skill ids learned by the battler
  360.   def blue_magic_skills
  361.     skill_ids = enemy.actions.collect { |action| action.skill_id }
  362.     skill_ids.uniq!.select! { |id| $data_skills[id].blue_magic }
  363.   end
  364.  
  365. end # class Game_Enemy
  366.  
  367.  
  368. #==============================================================================
  369. # ++ Scene_Battle
  370. #==============================================================================
  371. class Scene_Battle < Scene_Base
  372.   #--------------------------------------------------------------------------
  373.   # alias : process_action_end
  374.   #--------------------------------------------------------------------------
  375.   # Checks all Blue Magic learn flags and displays message if found
  376.   alias process_action_end_bubs_bluemagic process_action_end
  377.   def process_action_end
  378.     $game_party.members.each do |actor|
  379.       if actor.new_blue_magic_skill_learned?
  380.         @log_window.display_learned_blue_magic(actor)
  381.         @log_window.clear
  382.       end
  383.     end
  384.     process_action_end_bubs_bluemagic # alias
  385.   end
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # alias : use_item
  389.   #--------------------------------------------------------------------------
  390.   alias use_item_bubs_bluemagic use_item
  391.   def use_item
  392.     use_item_bubs_bluemagic # alias
  393.        
  394.     item = @subject.current_action.item
  395.     determine_blue_magic_learn_by_sight(@subject, item)
  396.   end # def
  397.  
  398.   #--------------------------------------------------------------------------
  399.   # new method : determine_blue_magic_learn_by_sight
  400.   #--------------------------------------------------------------------------
  401.   def determine_blue_magic_learn_by_sight(subject, item)
  402.     return unless Bubs::BlueMagic::LEARN_BY_SIGHT
  403.     return unless item.blue_magic && subject
  404.     return unless blue_magic_learn_by_allies?(subject)
  405.     all_battle_members.each do |member|
  406.       if member.result.hit?
  407.         set_blue_magic_skill_to_learn_flags(item)
  408.         break
  409.       end # if
  410.     end # do
  411.   end # def
  412.    
  413.   #--------------------------------------------------------------------------
  414.   # new method : set_blue_magic_skill_to_learn_flags
  415.   #--------------------------------------------------------------------------
  416.   def set_blue_magic_skill_to_learn_flags(item)
  417.     $game_party.members.each do |actor|
  418.       if actor.blue_magic_learning?
  419.         actor.result.blue_magic_skill_to_learn = item.id
  420.       end # if
  421.     end # do
  422.   end # def
  423.    
  424.   #--------------------------------------------------------------------------
  425.   # new method : blue_magic_learn_by_allies?
  426.   #--------------------------------------------------------------------------
  427.   def blue_magic_learn_by_allies?(subject)
  428.     if subject.actor?
  429.       return Bubs::BlueMagic::LEARN_BY_ALLIES
  430.     else
  431.       return true
  432.     end
  433.   end # def
  434.  
  435. end # class Scene_Battle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement