Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.49 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Skill Crack
  4. # Last Date Updated: 2010.05.27
  5. # Level: Normal
  6. #
  7. # Allow actors to learn skills by killing enemies that possess crackable skills.
  8. #===============================================================================
  9. # Instructions
  10. # -----------------------------------------------------------------------------
  11. # To install this script, open up your script editor and copy/paste this script
  12. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  13. #
  14. # <skill crack: x>
  15. # <skill crack: x, x, x>
  16. # This causes actor x to learn the skill when an enemy who knows the skill is
  17. # killed. Place this inside of the skill's notebox. Use 0 to affect all actors.
  18. #===============================================================================
  19.  
  20. $imported = {} if $imported == nil
  21. $imported["SkillCrack"] = true
  22.  
  23. module SSS
  24.   # This is the message displayed when a skill has learned by killing an enemy.
  25.   SKILL_CRACK_MESSAGE = "%s has learned %s!"
  26. end
  27.  
  28. #==============================================================================
  29. # RPG::Skill
  30. #==============================================================================
  31.  
  32. class RPG::Skill < RPG::UsableItem
  33.   #--------------------------------------------------------------------------
  34.   # # Skill Crack
  35.   #--------------------------------------------------------------------------
  36.   def skill_crack
  37.     return @skill_crack if @skill_crack != nil
  38.     @skill_crack = []
  39.     self.note.split(/[\r\n]+/).each { |line|
  40.       case line
  41.       when /<(?:SKILL_CRACK|skill crack):[ ](\d+(?:\s*,\s*\d+)*)>/i
  42.         $1.scan(/\d+/).each { |num| @skill_crack.push(num.to_i) }
  43.       end
  44.     }
  45.     return @skill_crack
  46.   end
  47. end
  48.  
  49. #==============================================================================
  50. # ** Game_Actor
  51. #==============================================================================
  52.  
  53. class Game_Actor < Game_Battler
  54.   #--------------------------------------------------------------------------
  55.   # * Apply Skill Crack
  56.   #--------------------------------------------------------------------------
  57.   def apply_skill_crack(skill)
  58.     return if skill.nil?
  59.     return unless skill.skill_crack.include?(0) or
  60.     skill.skill_crack.include?(@actor_id)
  61.     return if skill_learn?(skill)
  62.     learn_skill(skill.id)
  63.     return if $scene.message_window.nil?
  64.     text = sprintf(SSS::SKILL_CRACK_MESSAGE, @name, skill.name)
  65.     $scene.message_window.add_instant_text(text)
  66.   end
  67. end
  68.  
  69. #==============================================================================
  70. # ** Game_Enemy
  71. #==============================================================================
  72.  
  73. class Game_Enemy < Game_Battler
  74.   #--------------------------------------------------------------------------
  75.   # * Total Skills
  76.   #--------------------------------------------------------------------------
  77.   unless method_defined?(:total_skills)
  78.   def total_skills
  79.     result = []
  80.     for action in enemy.actions
  81.       next unless action.kind == 1
  82.       skill = $data_skills[action.skill_id]
  83.       result.push(skill) unless result.include?(skill)
  84.     end
  85.     result.sort! { |a,b| a.id <=> b.id }
  86.     return result.uniq
  87.   end
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Perform Collapse
  91.   #--------------------------------------------------------------------------
  92.   alias perform_collapse_sss_skill_crack perform_collapse unless $@
  93.   def perform_collapse
  94.     perform_collapse_sss_skill_crack
  95.     return unless $scene.is_a?(Scene_Battle) and dead?
  96.     return if $scene.active_battler.nil?
  97.     return unless $scene.active_battler.actor?
  98.     for skill in total_skills
  99.       $scene.active_battler.apply_skill_crack(skill)
  100.     end
  101.   end
  102. end
  103.  
  104. #==============================================================================
  105. # ** Scene_Battle
  106. #==============================================================================
  107.  
  108. class Scene_Battle < Scene_Base
  109.   #--------------------------------------------------------------------------
  110.   # * Public Instance Variables
  111.   #--------------------------------------------------------------------------
  112.   attr_accessor :active_battler
  113.   attr_accessor :message_window
  114. end
  115.  
  116. #===============================================================================
  117. #
  118. # END OF FILE
  119. #
  120. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement