Masouf

Anti-lag_XAS

Jul 29th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.22 KB | None | 0 0
  1. #==============================================================================
  2. # ■ +++ MOG - XAS ANTI LAG (V1.0) +++
  3. #==============================================================================
  4. # By Moghunter
  5. # http://www.atelier-rgss.com
  6. #==============================================================================
  7. # Ativa o sistema de Antilag no XAS.
  8. #==============================================================================
  9. # Para desativar ou ativar o sistema de antilag use o comando abaixo
  10. #
  11. # $game_system.anti_lag = true
  12. #
  13. #==============================================================================
  14. # Na caixa de notas da habilidade coloque a tag abaixo para fazer a
  15. # habilidade ser atualizada fora da tela.
  16. #
  17. # <Update Out Screen>
  18. #
  19. #==============================================================================
  20. module XAS_ANTI_LAG
  21.   #Area que será atualizada fora da tela.
  22.   UPDATE_OUT_SCREEN_RANGE = 3
  23. end
  24.  
  25. #==============================================================================
  26. # ■ Game_System
  27. #==============================================================================
  28. class Game_System
  29.   attr_accessor :anti_lag
  30.  
  31.  #--------------------------------------------------------------------------
  32.  # ● Initialize
  33.  #--------------------------------------------------------------------------  
  34.   alias mog_antilag_initialize initialize
  35.   def initialize
  36.       @anti_lag = true
  37.       mog_antilag_initialize
  38.   end  
  39. end
  40.  
  41. #==============================================================================
  42. # ■ Game_Character
  43. #==============================================================================
  44. class Game_Character < Game_CharacterBase
  45.  
  46.  #--------------------------------------------------------------------------
  47.  # ● Check Event on Screen
  48.  #--------------------------------------------------------------------------
  49.  def update_anti_lag
  50.      unless $game_system.anti_lag
  51.          @can_update = true
  52.          return
  53.      end  
  54.      anti_lag_event_on_screen
  55.  end
  56.    
  57.  #--------------------------------------------------------------------------
  58.  # ● Event On Screen
  59.  #--------------------------------------------------------------------------
  60.  def anti_lag_event_on_screen
  61.      @can_update = false
  62.      if anti_lag_need_update_out_screen?
  63.         @can_update = true
  64.         return
  65.      end  
  66.      out_screen = XAS_ANTI_LAG::UPDATE_OUT_SCREEN_RANGE
  67.      px = ($game_map.display_x).truncate
  68.      py = ($game_map.display_y).truncate
  69.      distance_x = @x - px
  70.      distance_y = @y - py
  71.      if distance_x.between?(0 - out_screen, 16 + out_screen) and
  72.         distance_y.between?(0 - out_screen, 12 + out_screen)
  73.         @can_update = true
  74.      end  
  75.  end      
  76.  
  77.  #--------------------------------------------------------------------------
  78.  # ● Event On Screen
  79.  #--------------------------------------------------------------------------
  80.  def anti_lag_need_update_out_screen?    
  81.      return true if self.force_update
  82.      return false
  83.  end
  84.  
  85.  #--------------------------------------------------------------------------
  86.  # ● Event Effects Out Screen
  87.  #--------------------------------------------------------------------------  
  88.  def execute_effects_out_screen
  89.      return if erased
  90.      if self.battler != nil
  91.         self.erase if self.battler.dead?
  92.      end
  93.      if self.tool_id > 0
  94.         self.action.duration = 1
  95.         $game_system.tools_on_map.delete(self.tool_id)
  96.         self.erase
  97.      end  
  98.  end
  99.  
  100.  #--------------------------------------------------------------------------
  101.  # ● Update
  102.  #--------------------------------------------------------------------------    
  103.   alias mog_anti_lag_update update
  104.   def update
  105.       unless self.is_a?(Game_Player)
  106.           update_anti_lag
  107.           unless @can_update
  108.               execute_effects_out_screen
  109.               return
  110.           end    
  111.       end
  112.       mog_anti_lag_update
  113.   end
  114. end
  115.  
  116. #==============================================================================
  117. # ■ Sprite Character
  118. #==============================================================================
  119. class Sprite_Character < Sprite_Base
  120.  
  121.  #--------------------------------------------------------------------------
  122.  # ● Check Can Update Sprite
  123.  #--------------------------------------------------------------------------      
  124.   def check_can_update_sprite
  125.       if self.visible and @character.can_update == false
  126.          reset_sprite_effects
  127.       end        
  128.       self.visible = @character.can_update          
  129.   end
  130.  
  131.  #--------------------------------------------------------------------------
  132.  # ● Reset Sprite Effects
  133.  #--------------------------------------------------------------------------        
  134.   def reset_sprite_effects
  135.       dispose_animation
  136.   end
  137.  
  138.  #--------------------------------------------------------------------------
  139.  # ● Update
  140.  #--------------------------------------------------------------------------          
  141.   alias mog_anti_lag_update update
  142.   def update
  143.       if $game_system.anti_lag
  144.          check_can_update_sprite
  145.          return unless self.visible
  146.       end  
  147.       mog_anti_lag_update
  148.   end
  149.  
  150. end  
  151.  
  152. $mog_rgss3_xas_anti_lag = true
Advertisement
Add Comment
Please, Sign In to add comment