Advertisement
LeonMMS

AnimOverhaul

Feb 26th, 2022 (edited)
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.78 KB | None | 0 0
  1. # LM² - Anim Overhaul
  2. # Créditos:
  3. # - Victor Sant por criar vários dos métodos usados de base
  4. # Visitem o site dele https://victorenginescripts.wordpress.com/
  5. # - LeonM² por criar/adaptar
  6.  
  7. class Game_CharacterBase
  8.   attr_reader :frames
  9.   attr_reader :anim_max
  10.   attr_reader :multiframe
  11.  
  12.  
  13.   alias :initialize_multi_frames :initialize
  14.  
  15.   def initialize
  16.     initialize_multi_frames
  17.     @frames = 3
  18.     @anim_max = 2
  19.     @multiframe = false
  20.   end
  21.  
  22.   def set_graphic(character_name, character_index)
  23.     @tile_id = 0
  24.     @character_name = character_name
  25.     @character_index = character_index
  26.     @frames = character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  27.     @multiframe = @frames != 3
  28.     @original_pattern = @multiframe ? 0 : 1
  29.     @anim_max = character_name[/\[A(\d+)\]/i] ? $1.to_i : 2
  30.   end
  31.  
  32.   alias :update_anime_pattern_multi_frames :update_anime_pattern
  33.  
  34.   def update_anime_pattern
  35.     if @multiframe
  36.       if !@step_anime && @stop_count > 0
  37.         @pattern = @original_pattern
  38.       else
  39.         @pattern = (@pattern + 1) % @frames
  40.       end
  41.     else
  42.       update_anime_pattern_multi_frames
  43.     end
  44.   end
  45.  
  46.   alias :straighten_anime_pattern_multi_frames :straighten
  47.  
  48.   def straighten
  49.     if @multiframe
  50.       @pattern = 0 if @walk_anime || @step_anime
  51.       @anime_count = 0
  52.     else
  53.       straighten_anime_pattern_multi_frames
  54.     end
  55.   end
  56.  
  57. end
  58.  
  59. class Game_Character < Game_CharacterBase
  60.  
  61.   def animate_attack(ani_index)
  62.     return if ani_index == 255 || @ani_time < Configs::ATTACK_ANIMATION_TIME
  63.     @last_character_index = @character_index
  64.     @last_pattern = @pattern
  65.     @last_step_anime = @step_anime
  66.     @character_index = ani_index
  67.     @pattern = 0
  68.     @step_anime = true
  69.     @ani_time = 0
  70.   end
  71.  
  72.   def update_animate_attack
  73.     return if @ani_time == Configs::ATTACK_ANIMATION_TIME
  74.     @ani_time += 1
  75.     fpf = (Configs::ATTACK_ANIMATION_TIME / @frames ).to_i
  76.     @pattern = (@ani_time / fpf).to_i
  77.     if @ani_time == Configs::ATTACK_ANIMATION_TIME
  78.       @character_index = @last_character_index
  79.       @pattern = @last_pattern
  80.       @step_anime = @last_step_anime
  81.     end
  82.   end  
  83.  
  84. end
  85.  
  86. class Game_Player < Game_Character
  87.   alias :refresh_multi_frames :refresh
  88.   def refresh
  89.     refresh_multi_frames
  90.     @frames = @character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  91.     @multiframe = @frames != 3
  92.     @original_pattern = @multiframe ? 0 : 1
  93.     @anim_max = @character_name[/\[A(\d+)\]/i] ? $1.to_i : 2    
  94.     @original_pattern = @multiframe ? 0 : 1
  95.   end
  96. end
  97.  
  98. class Game_Event < Game_Character
  99.   alias :setup_page_settings_multi_frames :setup_page_settings
  100.   def setup_page_settings
  101.     setup_page_settings_multi_frames
  102.     @frames = @character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  103.     @multiframe = @frames != 3
  104.     @anim_max = @character_name[/\[A(\d+)\]/i] ? $1.to_i : 2    
  105.     if (@move_type != 0 && @walk_anime) || @step_anime
  106.       @original_pattern = @multiframe ? 0 : 1
  107.     end
  108.   end
  109. end
  110.  
  111.  
  112. class Game_NetPlayer < Game_Character
  113.  
  114.   alias :refresh_multi_frames :refresh
  115.   def refresh
  116.     refresh_multi_frames
  117.     @frames = @character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  118.     @multiframe = @frames != 3
  119.     @original_pattern = @multiframe ? 0 : 1
  120.     @anim_max = @character_name[/\[A(\d+)\]/i] ? $1.to_i : 2    
  121.     @original_pattern = @multiframe ? 0 : 1
  122.   end
  123.  
  124. end
  125.  
  126.  
  127.  
  128. class Sprite_Character < Sprite_Base
  129.   alias :init_sprites_multi_frames :init_sprites
  130.   def init_sprites
  131.     init_sprites_multi_frames
  132.     @paperdoll_cw = []
  133.     @paperdoll_ch = []
  134.     @pd_frames = []
  135.     @pd_anim = []
  136.   end
  137.  
  138.   def set_character_bitmap
  139.     self.bitmap = Cache.character(@character_name)
  140.     sign = @character_name[/^[\!\$]./]
  141.     if sign && sign.include?('$')
  142.       @cw = bitmap.width / @character.frames
  143.       @ch = bitmap.height / 4
  144.     else
  145.       @cw = bitmap.width / (@character.frames * 4)
  146.       @ch = bitmap.height / (@character.anim_max * 4)
  147.     end
  148.     self.ox = @cw / 2
  149.     self.oy = @ch
  150.   end
  151.  
  152.  def update_src_rect
  153.     if @tile_id == 0
  154.       if @character.multiframe
  155.          index = @character.character_index
  156.           sx = (index % 4 * @character.frames + @character.pattern) * @cw
  157.           sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  158.           self.src_rect.set(sx, sy, @cw, @ch)
  159.       else
  160.         index = @character.character_index
  161.         pattern = @character.pattern < 3 ? @character.pattern : 1
  162.         sx = (index % 4 * 3 + pattern) * @cw
  163.         sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  164.         self.src_rect.set(sx, sy, @cw, @ch)
  165.       end
  166.     end
  167.   end
  168.  
  169.   def update_paperdolls
  170.     order_equips.each_with_index do |slot_id, index|
  171.       if @character.actor.equips[slot_id] && @character.actor.equips[slot_id].paperdoll_name
  172.         refresh_paperdoll(slot_id) unless @last_equips[slot_id] == @character.actor.equips[slot_id] && @last_sex == @character.actor.sex
  173.         pattern = @character.pattern
  174.         paperdoll_index = @character.character_index
  175.         sx = (paperdoll_index % 4 * @pd_frames[slot_id] + pattern) * @paperdoll_cw[slot_id]
  176.         sy = (paperdoll_index / 4 * 4 + (@character.direction - 2) / 2) * @paperdoll_ch[slot_id]
  177.         @paperdoll_sprites[slot_id].src_rect.set(sx, sy, @paperdoll_cw[slot_id], @paperdoll_ch[slot_id])
  178.         @paperdoll_sprites[slot_id].x = x
  179.         @paperdoll_sprites[slot_id].y = y + index
  180.         @paperdoll_sprites[slot_id].oy = @paperdoll_oy[slot_id] + index
  181.       else
  182.         dispose_paperdoll(slot_id)
  183.       end
  184.     end
  185.     @last_sex = @character.actor.sex
  186.   end
  187.  
  188.   def refresh_paperdoll(slot_id)
  189.     @last_equips[slot_id] = @character.actor.equips[slot_id]
  190.     bitmap = Cache.paperdoll(@character.actor.equips[slot_id].paperdoll_name, @character.actor.sex)
  191.     @paperdoll_sprites[slot_id] ? @paperdoll_sprites[slot_id].bitmap.clear : create_paperdoll(slot_id, bitmap)
  192.     @paperdoll_sprites[slot_id].bitmap.blt(0, 0, bitmap, bitmap.rect)
  193.     sign = @character.actor.equips[slot_id].paperdoll_name[/^[\!\$]./]
  194.     frames = @character.actor.equips[slot_id].paperdoll_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  195.     @pd_frames[slot_id] = frames
  196.     anim_max = @character.actor.equips[slot_id].paperdoll_name[/\[A(\d+)\]/i] ? $1.to_i : 2      
  197.     @pd_anim[slot_id] = anim_max
  198.     if sign && sign.include?('$')
  199.       @paperdoll_cw[slot_id] = bitmap.width / frames
  200.       @paperdoll_ch[slot_id] = bitmap.height / 4
  201.     else
  202.       @paperdoll_cw[slot_id] = bitmap.width / (frames * 4)
  203.       @paperdoll_ch[slot_id] = bitmap.height / (anim_max * 4)
  204.     end
  205.     @paperdoll_sprites[slot_id].ox = @paperdoll_cw[slot_id] / 2
  206.     @paperdoll_sprites[slot_id].oy = @paperdoll_ch[slot_id]
  207.     @paperdoll_oy[slot_id] = @paperdoll_ch[slot_id]
  208.   end
  209. end
  210.  
  211. class Window_Base < Window
  212.  
  213.   def draw_character(character_name, character_index, x, y)
  214.     return unless character_name
  215.     bitmap = Cache.character(character_name)
  216.     sign = character_name[/^[\!\$]./]
  217.     frames = character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  218.     increase = frames == 3 ? 1 : 0
  219.     anim_max = character_name[/\[A(\d+)\]/i] ? $1.to_i : 2
  220.     if sign && sign.include?('$')
  221.       cw = bitmap.width / frames
  222.       ch = bitmap.height / 4
  223.     else
  224.       cw = bitmap.width / (frames * 4)
  225.       ch = bitmap.height / (anim_max * 4)
  226.     end
  227.     n = character_index
  228.     src_rect = Rect.new((n%4*frames+increase)*cw, (n/4*4)*ch, cw, ch)
  229.     contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  230.   end
  231.  
  232.   def draw_paperdoll(paperdoll_name, paperdoll_index, sex, x, y)
  233.     return unless paperdoll_name
  234.     bitmap = Cache.paperdoll(paperdoll_name, sex)
  235.     sign = paperdoll_name[/^[\!\$]./]
  236.     frames = paperdoll_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  237.     increase = frames == 3 ? 1 : 0
  238.     anim_max = paperdoll_name[/\[A(\d+)\]/i] ? $1.to_i : 2
  239.     if sign && sign.include?('$')
  240.       cw = bitmap.width / frames
  241.       ch = bitmap.height / 4
  242.     else
  243.       cw = bitmap.width / (frames * 4)
  244.       ch = bitmap.height / (anim_max * 4)
  245.     end
  246.     src_rect = Rect.new((paperdoll_index % 4 * frames + increase) * cw, (paperdoll_index / 4 * 4) * ch, cw, ch)
  247.     contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  248.   end
  249. end
  250.  
  251.  
  252. class Sprite_Party < Sprite2
  253.   def draw_character(index, member)
  254.     self.bitmap.blt(0, 39 * index, @bitmap, @bitmap.rect, opacity(member.id))
  255.     return unless member.actor.character_name
  256.     bitmap = Cache.character(member.actor.character_name)
  257.     sign = member.actor.character_name[/^[\!\$]./]
  258.     frames = member.actor.character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  259.     increase = frames == 3 ? 1 : 0
  260.     anim_max = member.actor.character_name[/\[A(\d+)\]/i] ? $1.to_i : 2
  261.     if sign && sign.include?('$')
  262.       cw = bitmap.width / frames
  263.       ch = bitmap.height / 4
  264.     else
  265.       cw = bitmap.width / (frames * 4)
  266.       ch = bitmap.height / (anim_max * 4)
  267.     end
  268.     src_rect = Rect.new((member.actor.character_index % 4 * frames + increase) * cw, (member.actor.character_index / 4 * 4) * ch, cw, 24)
  269.     self.bitmap.blt(10, 39 * index - 2, bitmap, src_rect, opacity(member.id))
  270.   end
  271.  
  272.   def draw_paperdoll(index, equip, sex, opacity)
  273.     return unless equip.paperdoll_name
  274.     bitmap = Cache.paperdoll(equip.paperdoll_name, sex)
  275.     sign = equip.paperdoll_name[/^[\!\$]./]
  276.     frames = equip.paperdoll_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  277.     increase = frames == 3 ? 1 : 0    
  278.     anim_max = equip.paperdoll_name[/\[A(\d+)\]/i] ? $1.to_i : 2    
  279.     if sign && sign.include?('$')
  280.       cw = bitmap.width / frames
  281.       ch = bitmap.height / 4
  282.     else
  283.       cw = bitmap.width / (frames * 4)
  284.       ch = bitmap.height / (anim_max * 4)
  285.     end
  286.     src_rect = Rect.new((equip.paperdoll_index % 4 * frames + increase) * cw, (equip.paperdoll_index / 4 * 4) * ch, cw, 24)
  287.     self.bitmap.blt(10, 39 * index - 2, bitmap, src_rect, opacity)
  288.   end
  289. end
  290.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement