dsiver144

Dark's Pre-Skill Image v1.5

Mar 4th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.69 KB | None | 0 0
  1. #===============================================================================
  2. # ╔══════════════════════════════════╗
  3. # ║ ▼ Dark's Pre-Skill Image         ║  
  4. # ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. # ║ ▼ Release Date: March 5th 2016   ║
  6. # ╚══════════════════════════════════╝
  7. # ▼ Notetag: <pre_image: "ImageName">
  8. #  -> Ex: <pre_image: "Skill1"> : Where Skill1 is name of a picture in
  9. #                                 Graphics/Picture
  10. #  To edit the image show time please check line 14.
  11. #===============================================================================
  12. $imported = {} if $imported.nil?
  13. $imported["DRK-Pre-Skill_Image"] = true
  14.  
  15. module DarkPreSkill
  16.   Delay = 100
  17.   SE_Name = "Skill3"
  18.   REGEXP = /<pre[_*]image:\s*"(\w+)">/i
  19. end
  20.  
  21. class RPG::Skill < RPG::UsableItem
  22.   #--------------------------------------------------------------------------
  23.   # * Load Notetag for Pre Image
  24.   #--------------------------------------------------------------------------
  25.   def load_pre_image
  26.     @pre_image = nil
  27.     note.split(/[\r\n]+/).each do |line|
  28.       if line =~ DarkPreSkill::REGEXP
  29.         @pre_image = $1.to_s
  30.       end
  31.     end
  32.   end
  33.   attr_accessor :pre_image
  34. end
  35. class Game_Actor < Game_Battler
  36.   #--------------------------------------------------------------------------
  37.   # * Initialize
  38.   #--------------------------------------------------------------------------
  39.   alias :dark_pre_skill_init_game_actor :initialize
  40.   def initialize(actor_id)
  41.     dark_pre_skill_init_game_actor(actor_id)
  42.     $data_skills.each do |skill|
  43.       if skill
  44.         skill.load_pre_image
  45.       end
  46.     end
  47.   end
  48. end
  49. class Scene_Battle < Scene_Base  
  50.   #--------------------------------------------------------------------------
  51.   # * start
  52.   #--------------------------------------------------------------------------
  53.   alias :dark_pre_skill_start :start
  54.   def start
  55.     dark_pre_skill_start
  56.     @pre_wait = 0
  57.     @used_skill = false
  58.     @pre_skill_sprite = Sprite.new
  59.     @pre_skill_sprite.opacity = 0
  60.     @pre_image = ""
  61.     @play_pre_skill = false
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # * Update Pre Skill
  65.   #--------------------------------------------------------------------------
  66.   def update_pre_skill
  67.     if @pre_wait > (DarkPreSkill::Delay/2) && @play_pre_skill == true
  68.       @pre_skill_sprite.bitmap = Cache.picture(@pre_image)
  69.       @pre_skill_sprite.viewport = @viewport
  70.       @pre_skill_sprite.z = 999
  71.       @pre_skill_sprite.visible = true
  72.       @pre_skill_sprite.opacity += 10
  73.     else
  74.       if @pre_wait > 0
  75.         @pre_skill_sprite.opacity -= 5
  76.       end
  77.     end
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Frame Update
  81.   #--------------------------------------------------------------------------
  82.   def update
  83.     super
  84.     update_pre_skill
  85.     if @pre_wait > 0 && @used_skill == true
  86.       @pre_wait -= 1
  87.     end
  88.     if BattleManager.in_turn? && @used_skill == false && @pre_wait <= 0
  89.         process_event
  90.         process_action
  91.     end
  92.     if @used_skill == true && @pre_wait <= 0
  93.       @pre_skill_sprite.visible = false
  94.       execute_action
  95.       @subject.remove_current_action
  96.       process_action_end unless @subject.current_action
  97.       @used_skill = false
  98.       @play_pre_skill = false
  99.     end
  100.     BattleManager.judge_win_loss if @used_skill != true
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Battle Action Processing
  104.   #--------------------------------------------------------------------------
  105.   def process_action
  106.     return if scene_changing?
  107.     if !@subject || !@subject.current_action
  108.       @subject = BattleManager.next_subject
  109.     end
  110.     return turn_end unless @subject
  111.     if @subject.current_action
  112.       @subject.current_action.prepare
  113.       if @subject.current_action.valid?
  114.         @status_window.open
  115.         item = @subject.current_action.item
  116.         if @subject.current_action.subject.is_a?(Game_Actor)
  117.           if item.is_a?(RPG::Skill)
  118.             if item.pre_image
  119.               @pre_wait = DarkPreSkill::Delay
  120.               @play_pre_skill = true
  121.               @pre_image = item.pre_image
  122.               $game_troop.screen.start_flash(Color.new(255,255,255),60)
  123.               Audio.se_play("Audio//SE//#{DarkPreSkill::SE_Name}")
  124.             else
  125.               @play_pre_skill = false
  126.               @pre_wait = 0
  127.             end
  128.           end
  129.         end
  130.         @used_skill = true
  131.       end
  132.     end
  133.   end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment