Advertisement
LeonMMS

AnimOverhaul+IdleAnim

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