Advertisement
Vlue

Field Effects

Jul 9th, 2014
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.62 KB | None | 0 0
  1. #Field Effects v1.1
  2. #----------#
  3. #Features: Allows you to set skills and items that change the background of the
  4. #           battle, as well as apply states to both enemies and allies.
  5. #
  6. #Usage:    Plug and play, Customize as needed
  7. #            Skill/Item Notetag:
  8. #             <FIELD id>   - where id is the field ID to apply
  9. #----------#
  10. #-- Script by: V.M of D.T
  11. #
  12. #- Questions or comments can be:
  13. #    given by email: sumptuaryspade@live.ca
  14. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  15. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  16. #
  17. #--- Free to use in any project, commercial or non-commercial, with credit given
  18. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  19.  
  20. #FIELD SETUP:
  21. # ID => {
  22. #   :name => "field name",              - Arbitrary, isn't even used.
  23. #   :background1 => "background1",      - Background 1 to use
  24. #   :background1 => "background1",      - Background 2 to use
  25. #   :fade => :fadestyle,                - Fade effect- :none, :white, :black
  26. #   :duration => int,                   - Where int is number of turns to last
  27. #   :enemy_state => id,                 - State id to be applied to all enemies
  28. #   :actor_state => id, },              - State id to be applied to all actors
  29. #
  30. # Setting duration, enemy_state, or actor_state to 0 will ignore that portion.
  31.  
  32. $imported = {} if $imported.nil?
  33. $imported[:VlueFieldEffects] = true
  34.  
  35. FIELD_EFFECTS = {
  36.   0 => { },
  37.   1 => {
  38.     :name => "Swamp",
  39.     :background1 => "PoisonSwamp",
  40.     :background2 => "PoisonSwamp",
  41.     :fade => :black,
  42.     :duration => 3,
  43.     :enemy_state => 2,
  44.     :actor_state => 0, },
  45.   2 => {
  46.     :name => "Sanctuary",
  47.     :background1 => "GrassMaze",
  48.     :background2 => "Forest1",
  49.     :fade => :white,
  50.     :duration => 3,
  51.     :enemy_state => 0,
  52.     :actor_state => 14, },
  53. }
  54.  
  55. #Fade effect when field effect is over
  56. RESET_FIELD_FADE = :black
  57.    
  58. class Scene_Battle
  59.   alias field_effects_start start
  60.   alias field_effects_apply_item_effects apply_item_effects
  61.   alias field_effects_turn_end turn_end
  62.   alias field_effects_turn_start turn_start
  63.   def start(*args)
  64.     field_effects_start(*args)
  65.     @field_effect = 0
  66.     @field_duration = 0
  67.   end
  68.   def turn_end(*args)
  69.     field_effects_turn_end
  70.     if @field_duration > 0
  71.       @field_duration -= 1
  72.       if @field_duration == 0
  73.         @spriteset.change_field(0)
  74.         remove_field_effects
  75.         @field_effect = 0
  76.       end
  77.     end
  78.   end
  79.   def turn_start(*args)
  80.     field_effects_turn_start(*args)
  81.     apply_field_effects
  82.   end
  83.   def apply_field(id)
  84.     return unless id
  85.     return if @field_effect == id
  86.     remove_field_effects
  87.     @field_effect = id
  88.     @spriteset.change_field(id)
  89.     @field_duration = field[:duration]
  90.     apply_field_effects
  91.   end
  92.   def field
  93.     FIELD_EFFECTS[@field_effect]
  94.   end
  95.   def apply_item_effects(target, item)
  96.     field_effects_apply_item_effects(target, item)
  97.     apply_field(item.field_effect?)
  98.   end
  99.   def apply_field_effects
  100.     return unless @field_effect > 0
  101.     if field[:actor_state] > 0
  102.       $game_party.battle_members.each do |actor|
  103.         actor.add_state(field[:actor_state])
  104.       end
  105.     end
  106.     if field[:enemy_state] > 0
  107.       $game_troop.members.each do |enemy|
  108.         enemy.add_state(field[:enemy_state])
  109.       end
  110.     end
  111.   end
  112.   def remove_field_effects
  113.     return unless @field_effect > 0
  114.     if field[:actor_state] > 0
  115.       $game_party.battle_members.each do |actor|
  116.         actor.remove_state(field[:actor_state])
  117.       end
  118.     end
  119.     if field[:enemy_state] > 0
  120.       $game_troop.members.each do |enemy|
  121.         enemy.remove_state(field[:enemy_state])
  122.       end
  123.     end
  124.   end
  125. end
  126.  
  127. class Spriteset_Battle
  128.   #@back2_sprite
  129.   def change_field(id)
  130.     field = FIELD_EFFECTS[id]
  131.     field = {:fade => RESET_FIELD_FADE } if id == 0
  132.     case field[:fade]
  133.     when :none
  134.       create_battleback_custom(field)
  135.     when :white
  136.       fade_white_battleback
  137.       create_battleback_custom(field)
  138.       unfade_battleback
  139.     when :black
  140.       fade_black_battleback
  141.       create_battleback_custom(field)
  142.       unfade_battleback
  143.     end
  144.   end
  145.   def fade_white_battleback
  146.     duration = 0
  147.     while @back1_sprite.color.red != 255
  148.       @back1_sprite.color = Color.new(duration,duration,duration,duration)
  149.       @back2_sprite.color = Color.new(duration,duration,duration,duration)
  150.       duration += 5
  151.       SceneManager.scene.update_basic
  152.     end
  153.   end
  154.   def fade_black_battleback
  155.     duration = 0
  156.     while @back1_sprite.color.alpha != 255
  157.       @back1_sprite.color = Color.new(0,0,0,duration)
  158.       @back2_sprite.color = Color.new(0,0,0,duration)
  159.       duration += 5
  160.       SceneManager.scene.update_basic
  161.     end
  162.   end
  163.   def unfade_battleback
  164.     duration = 255
  165.     while @back1_sprite.color.alpha != 0
  166.       @back1_sprite.color.red == 0 ? color_value = 0 : color_value = duration
  167.       @back1_sprite.color = Color.new(color_value,color_value,color_value,duration)
  168.       @back2_sprite.color = Color.new(color_value,color_value,color_value,duration)
  169.       duration -= 5
  170.       SceneManager.scene.update_basic
  171.     end
  172.   end
  173.   def create_battleback_custom(field)
  174.     if field[:background1]
  175.       @back1_sprite.bitmap = Cache.battleback1(field[:background1])
  176.       @back2_sprite.bitmap = Cache.battleback2(field[:background2])
  177.     else
  178.       @back1_sprite.bitmap = battleback1_bitmap
  179.       @back2_sprite.bitmap = battleback2_bitmap
  180.     end
  181.   end
  182. end
  183.  
  184. class RPG::UsableItem
  185.   def field_effect?
  186.     self.note =~ /<FIELD (\d+)>/ ? $1.to_i : nil
  187.   end
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement