Guest User

Untitled

a guest
Jan 21st, 2015
294
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # XAS - Blood Effects
  3. #===============================================================================
  4. # by Mr_Wiggles
  5. # Version 2.3
  6. # 4/28/11
  7. #===============================================================================
  8. module Blood
  9. #-------------------------------------------------------------------------------
  10. # Blood splatter effects
  11. #-------------------------------------------------------------------------------
  12. # Number of seconds blood is shown for
  13. BLOOD_EARASE_TIME = 10
  14. # Make the blood slightly see through? (0 - 255)
  15. BLOOD_OPACITY = 180
  16. #-------------------------------------------------------------------------------
  17. # Monster blood colors. when A; return B ("A" monster ID, "B" hue [0 - 350] )
  18. # Hue colors: 0 = red; 40 = yellow; 120 = green; 190 = sky blue;
  19. # 220 = navy blue; 260 = purple; 310 = pink; 350 = red
  20. # (same for actors but id's are negative, so actor 4 is id -4)
  21.   def blood_hues(id)
  22.     case id
  23.     # when (enemy id) then return (Hue value)
  24.     when 2 then return 180
  25.     when 5 then return 40
  26.     else # this will return the default blood color
  27.       return 0
  28.     end
  29.   end
  30. #-------------------------------------------------------------------------------
  31. # Monster blood character set.
  32.   def blood_name(id)
  33.     case id
  34.     # when (enemy id) then return (IMG name)
  35.     when 1 then return "Blood" #Ciructs
  36.     else # Default IMG name
  37.       return "Blood"
  38.     end
  39.   end
  40. end
  41. #-------------------------------------------------------------------------------
  42. # Tool id's that dont cause bleeding.
  43. NO_BLOOD_TOOL  = []
  44. # Enemies that dont cause bleeding. (actor id's are negative)
  45. NO_BLOOD_ENEMY = []
  46. #-------------------------------------------------------------------------------
  47. # Blood screen effects
  48. #-------------------------------------------------------------------------------
  49. # Use screen blood effects
  50. USE_BLOODY_SCREEN = true
  51. # Number of seconds before blood fades off of screen
  52. BLOOD_DURATION = 10
  53. # Opacity of blood splatters on screen
  54. BLOOD_SCREEN_OPACITY = 200
  55. # Name of picture used for blood splaters
  56. BLOOD_SHEET = "Blood_Sheet"
  57.  
  58. #===============================================================================
  59. # XRXS Battler Attachment
  60. #===============================================================================
  61. module XRXS_BattlerAttachment
  62.   alias :be_action_effect :action_effect
  63.   def self.action_effect(bullet, action_id)
  64.     eff = be_action_effect(bullet, action_id)
  65.     user     = bullet.action.user
  66.     skill    = $data_skills[action_id]
  67.     return if user.nil? or skill.nil?
  68.     make_be  = true
  69.     if self.battler.is_a?(Game_Enemy) and
  70.         (XAS_BA_ENEMY::ENEMY_OBJECT.include?(self.id) or
  71.          XAS_BA_ENEMY::ITEM_ENEMY.include?(self.id))
  72.       make_be = false
  73.     end
  74.     if make_be and !NO_BLOOD_TOOL.include?(skill.id)
  75.       be_make_effect(user, skill)
  76.     end
  77.     return eff
  78.   end
  79.  
  80.   alias :be_attack_effect :attack_effect
  81.   def attack_effect(attacker)
  82.     eff = be_attack_effect(attacker)
  83.     make_be = true
  84.     if self.battler.is_a?(Game_Enemy) and                  
  85.         (XAS_BA_ENEMY::ENEMY_OBJECT.include?(self.id) or
  86.          XAS_BA_ENEMY::ITEM_ENEMY.include?(self.id))
  87.       make_be = false
  88.     end
  89.     if make_be and !NO_BLOOD_ENEMY.include?(attacker.id)
  90.       be_make_effect(attacker)
  91.     end
  92.     return eff
  93.   end
  94. end
  95.  
  96. #===============================================================================
  97. # Game Character
  98. #===============================================================================
  99. class Game_Player < Game_Character
  100.   def be_make_effect(user, skill = nil)
  101.     @be_old_hp = 0 if @be_old_hp.nil?
  102.     self_id = self.battler.id
  103.     self_id *= -1 if self.battler.is_a?(Game_Actor)
  104.     user_id = user.battler.id.to_i
  105.     self_id *= -1 if user.battler.is_a?(Game_Actor)
  106.     if @be_old_hp != self.battler.hp and (@be_old_hp - self.battler.hp > 0)
  107.       SceneManager.scene.make_blood_effect(@real_x, @real_y, self_id)
  108.     end
  109.     @be_old_hp = self.battler.hp
  110.   end
  111. end
  112. #===============================================================================
  113. # Blood Screen
  114. #===============================================================================
  115. class Bloody_Window < Window_Base
  116.   def initialize
  117.     super(-20, -20, 700, 600)
  118.     self.contents = Bitmap.new(width - 32, height - 32)
  119.     self.opacity = 0
  120.     self.z = 900
  121.     @blood_graphics = []
  122.     @blood_sheet = Cache.picture("blood_sheet")
  123.     @wt = @blood_sheet.width / 4
  124.     @ht = @blood_sheet.height / 4
  125.     update
  126.   end
  127.  
  128.   def refresh
  129.     self.contents.clear
  130.     for blood in @blood_graphics
  131.       rect = Rect.new(@wt * blood[2][0], blood[2][1] * @ht, @wt, @ht)
  132.       self.contents.blt(blood[0], blood[1], @blood_sheet, rect, blood[4])
  133.     end
  134.   end
  135.  
  136.   def make_random_blood
  137.     loop do
  138.       stop_loop = true
  139.       x = (rand(50) * 10) + 20
  140.       y = (rand(40) * 10) + 20
  141.       n = [rand(2)+rand(2), rand(2)+rand(2)]
  142.       @blood_graphics.each {|b| stop_loop = false if b[2] == n}
  143.       if stop_loop
  144.         @blood_graphics.push([x, y, n, BLOOD_DURATION * 8, BLOOD_SCREEN_OPACITY])
  145.         break
  146.       end
  147.     end
  148.   end
  149.  
  150. def update
  151.     @actor = $game_party.members[0]
  152.     @old_player_hp = @actor.hp if @old_player_hp.nil?
  153.     if @old_player_hp != @actor.hp
  154.       make_random_blood if (@old_player_hp - @actor.hp > 0)
  155.       @old_player_hp = @actor.hp
  156.     end
  157.     return if @blood_graphics.empty?
  158.     @blood_graphics.each {|blood| update_blood(blood)}
  159.     refresh
  160.   end
  161.  
  162.  
  163.   def update_blood(blood)
  164.     if blood[4] == 0
  165.       @blood_graphics.delete(blood)
  166.       return
  167.     end
  168.     blood[3] -= 5 if blood[3] > 0
  169.     blood[4] -= 5 if blood[4] > 0 and blood[3] <= BLOOD_SCREEN_OPACITY
  170.   end
  171. end
  172.  
  173. #==============================================================================
  174. # Scene Map
  175. #==============================================================================
  176. class Scene_Map
  177.   alias blood_window_main main
  178.   def main
  179.     if USE_BLOODY_SCREEN
  180.       @blood_window = Bloody_Window.new
  181.       @blood_update_pause = 5
  182.     end
  183.     blood_window_main
  184.     @blood_window.dispose if USE_BLOODY_SCREEN
  185.   end
  186.  
  187.   alias blood_window_update update
  188.   def update
  189.     blood_window_update
  190.     return if @blood_update_pause.nil?
  191.     @blood_update_pause -= 1 if @blood_update_pause > 0
  192.     return if @blood_update_pause > 0
  193.     @blood_window.update; @blood_update_pause = 5
  194.   end
  195.  
  196.   def make_blood_effect(*args)
  197.     @spriteset.make_blood_effect(*args)
  198.   end
  199. end
  200.  
  201. #==============================================================================
  202. # Spriteset Map
  203. #==============================================================================
  204. class Spriteset_Map  
  205.   alias :blood_effects_init :initialize
  206.   def initialize
  207.     @blood = []
  208.     blood_effects_init
  209.   end
  210.  
  211.   def make_blood_effect(x, y, id)
  212.     @blood.push(Sprite_Blood.new(@viewport1, x, y, id))
  213.   end
  214.  
  215.   alias :blood_effects_up :update
  216.   def update
  217.     blood_effects_up
  218.     @blood.each{|blood| blood.update if !blood.disposed?}
  219.   end
  220.  
  221.   alias :blood_effects_dis :dispose
  222.   def dispose
  223.     blood_effects_dis
  224.     @blood.each{|blood| blood.dispose if !blood.disposed?}
  225.   end
  226. end
  227.  
  228. #==============================================================================
  229. # Sprite Blood
  230. #==============================================================================
  231. class Sprite_Blood < Sprite_Base
  232.   include Blood
  233.  
  234.   def initialize(viewport, x, y, id)
  235.     super(viewport)
  236.     @x, @y, @id = x, y, id
  237.     @duration = (BLOOD_EARASE_TIME * 40) + BLOOD_OPACITY
  238.     set = blood_name(@id)
  239.     bit = Cache.character(set, blood_hues(@id)) rescue nil
  240.     if bit.nil?
  241.       $blood_fails = [] if $blood_fails.nil?
  242.       unless $blood_fails.include?(set)
  243.         $blood_fails.push(set)
  244.         print("Blood effect character set \"#{set}\" was not found!")
  245.       end
  246.       self.dispose
  247.       return
  248.     end
  249.     self.bitmap = bit
  250.     @cw, @ch = bitmap.width  / 4, bitmap.height / 4
  251.     sx, sy = rand(4) * @cw, rand(4) * @ch
  252.     self.src_rect.set(sx, sy, @cw, @ch)
  253.     self.opacity = BLOOD_OPACITY
  254.     self.x = screen_x
  255.     self.y = screen_y
  256.     self.z = 1
  257.     update
  258.   end
  259.  
  260.   def screen_x
  261.     return (@x - $game_map.display_x) / 4
  262.   end
  263.  
  264.   def screen_y
  265.     return (@y - $game_map.display_y) / 4
  266.   end
  267.  
  268.   def update
  269.     self.x = screen_x
  270.     self.y = screen_y
  271.     @duration -= 1
  272.     self.opacity -= 1 if BLOOD_OPACITY <= @duration
  273.     self.dispose if @duration == 0
  274.   end
  275. end
RAW Paste Data