Advertisement
Raizen

Akea Battle Input Trigger(English)

Mar 15th, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.80 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Battle Input Trigger
  3. # Author: Raizen
  4. # Comunity: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7. #=======================================================
  8. # The script allows that a key, or many keys are pressed to either
  9. # cast skills or prevent the enemy from casting skills
  10.  
  11. ($imported ||= {})[:akea_bit] = true
  12. module Akea_ITT
  13. # ============== Don't modify! ==================
  14. Input = Array.new
  15. #--------------------------------------------------------
  16. # ==================== Instructions =======================
  17. #--------------------------------------------------------
  18. # To add an Input to a skill or weapon, just add this to
  19. # the notetag on DataBase
  20. # <getinput n|id|chance>
  21.  
  22. # Where:
  23. # n is the id of the input configured below on the script
  24. # id is the skill id on database
  25. # chance is the chance to activate the input in %
  26.  
  27. # Example:
  28. # <getinput 0|55|50> on a notetag in skill or weapon would mean
  29. # the moment I attack or use the skill,
  30. # It would use Input[0] config
  31. # cast skill with id 55
  32. # and has 50% chance of actually activating the chain trigger
  33.  
  34. #--------------------------------------------------------
  35. # ================= Configurations ========================
  36. #--------------------------------------------------------
  37.  
  38. # IMPORTANT: Images MUST BE on folder Graphics/Akea of your project!!
  39.  
  40. # HUD IMAGES
  41. #Base Image
  42. Base_Hud = 'base_input_hud'
  43.  
  44. #Bar Image
  45. Bar_Hud = 'bar_input'
  46.  
  47. # All positions follow this pattern
  48. # [X Pos, Y Pos, Z Pos]
  49. # Z Pos is only necessary if a picture gets over or below the hud
  50.  
  51. # Hud Base Image(Position is according to Input button position)
  52. Base_Hud_Pos = [-20, 40, 100]
  53.  
  54. # Hud Bar Image(Position is according to Input button position)
  55. Bar_Hud_Pos = [-14, 43, 99]
  56.  
  57. # Input According to enemy position
  58. Enemy_Pos = [0, -80]
  59.  
  60. # Input according to actor position
  61. Actor_Pos = [0, -80]
  62.  
  63.  
  64. #--------------------------------------------------------
  65. # ================= Input Settings ========================
  66. #--------------------------------------------------------
  67. # RPG Maker VX Ace Input Map, just for  helping with triggers
  68. # X = Key A  ;  Y = Key S  ;  Z = Key D
  69. # L = Key Q  ;  R = Key W  ;  SHIFT
  70. # RIGHT, LEFT, UP, DOWN
  71. # ----------- Input 0 -----------------------
  72. Input[0] = {
  73. :triggers => [:X, :B, :Y, :C, :LEFT, :RIGHT, :DOWN, :UP], # Keys of this Input,
  74. :pics => ['A', 'X', 'S', 'Z', 'LEFT', 'RIGHT', 'DOWN', 'UP'], # Input Images
  75. :time => 300, #Time Limit for the Input
  76. :num_times => 6, #Times input will appear
  77. :random? => true, #Randomize? if false it will follow the triggers order
  78. :position? => 'enemy', #can be, 'actor', 'enemy', or [x, y] screen position
  79. :success_se => 'Save', #SE in case you succeed the sequence
  80. :failure_se => 'Buzzer2', #SE in case you faill the sequence
  81. }
  82.  
  83. # ----------- Input 1 -----------------------
  84. Input[1] = {
  85. :triggers => [:X], # Keys of this Input,
  86. :pics => ['A'], # Input Images
  87. :time => 30, #Time Limit for the Input
  88. :num_times => 1, #Times input will appear
  89. :random? => true, #Randomize? if false it will follow the triggers order
  90. :position? => [200, 200], #can be, 'actor', 'enemy' , or [x, y] a position
  91. :success_se => 'Save', #SE in case you succeed the sequence
  92. :failure_se => 'Buzzer2', #SE in case you faill the sequence
  93. }
  94.  
  95. # Key mapping : put all triggers you want to check if
  96. # the player gets wrong and fails the sequence
  97. Key_Map = [:X, :Y, :C, :B, :LEFT, :RIGHT, :UP, :DOWN]
  98. end
  99.  
  100. # HERE STARTS THE SCRIPT
  101. #==============================================================================
  102. # ** Scene_Battle
  103. #------------------------------------------------------------------------------
  104. #  Esta classe executa o processamento da tela de batalha.
  105. #==============================================================================
  106.  
  107. class Scene_Battle < Scene_Base
  108. alias :akea_itt_process_action :process_action
  109. alias :akea_itt_use_item :use_item
  110. alias :akea_itt_start :start
  111. alias :akea_itt_terminate :terminate
  112.   #--------------------------------------------------------------------------
  113.   # * Inicialização do processo
  114.   #--------------------------------------------------------------------------
  115.   def start
  116.     akea_itt_start
  117.     @akea_itt_pic = Sprite.new
  118.     @akea_itt_pic.z = Akea_ITT::Base_Hud_Pos[2]
  119.     @akea_itt_bar = Sprite.new
  120.     @akea_itt_bar.bitmap = Cache.akea(Akea_ITT::Bar_Hud)
  121.     @akea_itt_bar.opacity = 0
  122.     @akea_itt_bar.z = Akea_ITT::Bar_Hud_Pos[2]
  123.     @akea_itt_bar_base = Sprite.new
  124.     @akea_itt_bar_base.bitmap = Cache.akea(Akea_ITT::Base_Hud)
  125.     @akea_itt_bar_base.opacity = 0
  126.     @akea_itt_bar_base.z = Akea_ITT::Base_Hud_Pos[2]
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Uso de habilidades/itens
  130.   #--------------------------------------------------------------------------
  131.   def use_item
  132.     akea_itt_use_item
  133.     battle_notes = @subject.current_action.item.note
  134.     if @subject.current_action.item.id == 1 && @subject.actor? && @subject.equips[0]
  135.       battle_notes = @subject.equips[0].note
  136.     end
  137.     @akea_itt = []
  138.     @akea_trigger_shuffle = -1
  139.     for n in 0...battle_notes.size
  140.       if battle_notes[n..n+9] == "<getinput "
  141.         y = 0
  142.         y += 1 until battle_notes[n+10+y] == '|'
  143.         w = 0
  144.         w += 1 until battle_notes[n+11+y+w] == '|'
  145.         z = 0
  146.         z += 1 until battle_notes[n+11+y+w+z] == '>'
  147.         insert_akea_input(battle_notes[n+10..n+9+y].to_i, battle_notes[n+11+y..n+10+y+w].to_i, battle_notes[n+13+w..n+12+y+w+z].to_i)
  148.       end
  149.     end
  150.     party_id = all_battle_members.index(@subject)
  151.     start_akea_input_trigger
  152.     until @akea_itt.empty?
  153.       break unless party_id
  154.       move_akea_input_bars
  155.       self.class.superclass.instance_method(:update).bind(self).call
  156.       if @akea_input_timer <= 0 && @akea_input_success
  157.         next unless akea_input_animation
  158.         RPG::SE.new(Akea_ITT::Input[@akea_itt.first[0]][:success_se]).play
  159.         @subject.actor? ? call_akea_skill : @akea_itt = []
  160.       elsif @akea_input_timer <= 0 || check_input == 2
  161.         @akea_input_timer = 0
  162.         next unless akea_input_animation
  163.         RPG::SE.new(Akea_ITT::Input[@akea_itt.first[0]][:failure_se]).play
  164.         @subject.actor? ? @akea_itt = [] : call_akea_skill
  165.       elsif check_input == 1
  166.         Sound.play_ok
  167.         @akea_num_triggers -= 1
  168.         if @akea_num_triggers == 0
  169.           @akea_input_success = true
  170.           @akea_input_timer = 0
  171.         else
  172.           if Akea_ITT::Input[@akea_itt.first[0]][:random?]
  173.             @akea_trigger_shuffle = rand(Akea_ITT::Input[@akea_itt.first[0]][:triggers].size)
  174.           else
  175.             @akea_trigger_shuffle += 1
  176.           end
  177.           while @akea_itt_pic.opacity > 0
  178.             self.class.superclass.instance_method(:update).bind(self).call
  179.             @akea_itt_pic.opacity -= 30
  180.           end
  181.           @akea_itt_pic.bitmap.dispose
  182.           @akea_itt_pic.opacity = 255
  183.           @akea_itt_pic.bitmap = Cache.akea(Akea_ITT::Input[@akea_itt.first[0]][:pics][@akea_trigger_shuffle])
  184.         end
  185.       end
  186.       @akea_input_timer -= 1
  187.     end
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Inserir o input na array
  191.   #--------------------------------------------------------------------------
  192.   def insert_akea_input(n, id, chance)
  193.     p [n, id, chance]
  194.     @akea_itt << [n, id] if rand(100) < chance
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Animação de fade do input
  198.   #--------------------------------------------------------------------------
  199.   def akea_input_animation
  200.     @akea_itt_pic.opacity -= 30
  201.     @akea_itt_bar_base.opacity -= 30
  202.     @akea_itt_bar.opacity -= 30
  203.     return false if @akea_itt_pic.opacity > 0
  204.     return true
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Inicialização do processo de input
  208.   #--------------------------------------------------------------------------
  209.   def start_akea_input_trigger
  210.     return if @akea_itt.empty?
  211.     @akea_input_success = false
  212.     if Akea_ITT::Input[@akea_itt.first[0]][:random?]
  213.       @akea_trigger_shuffle = rand(Akea_ITT::Input[@akea_itt.first[0]][:triggers].size)
  214.     else
  215.       @akea_trigger_shuffle += 1
  216.     end
  217.     @akea_num_triggers = Akea_ITT::Input[@akea_itt.first[0]][:num_times]
  218.     if Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'actor' || (Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'enemy' && @subject.enemy?)
  219.       @akea_itt_pic.x = @subject.screen_x + Akea_ITT::Actor_Pos[0]
  220.       @akea_itt_pic.y = @subject.screen_y + Akea_ITT::Actor_Pos[1]
  221.     elsif Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'enemy'
  222.       targets = @subject.current_action.make_targets.compact
  223.       @akea_itt_pic.x = targets[0].screen_x + Akea_ITT::Enemy_Pos[0]
  224.       @akea_itt_pic.y = targets[0].screen_y + Akea_ITT::Enemy_Pos[1]
  225.     else
  226.       @akea_itt_pic.x = Akea_ITT::Input[@akea_itt.first[0]][:position?][0]
  227.       @akea_itt_pic.y = Akea_ITT::Input[@akea_itt.first[0]][:position?][1]
  228.     end
  229.     @akea_itt_bar.x = @akea_itt_pic.x + Akea_ITT::Bar_Hud_Pos[0]
  230.     @akea_itt_bar.y = @akea_itt_pic.y + Akea_ITT::Bar_Hud_Pos[1]
  231.     @akea_itt_bar_base.x = @akea_itt_pic.x + Akea_ITT::Base_Hud_Pos[0]
  232.     @akea_itt_bar_base.y = @akea_itt_pic.y + Akea_ITT::Base_Hud_Pos[1]
  233.     @akea_input_timer = Akea_ITT::Input[@akea_itt.first[0]][:time]
  234.     @akea_itt_pic.bitmap.dispose if @akea_itt_pic.bitmap
  235.     @akea_itt_pic.opacity = @akea_itt_bar.opacity = @akea_itt_bar_base.opacity = 255
  236.     @akea_itt_bar.zoom_x = 1
  237.     @akea_itt_pic.bitmap = Cache.akea(Akea_ITT::Input[@akea_itt.first[0]][:pics][@akea_trigger_shuffle])
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Movimento das barras de Input
  241.   #--------------------------------------------------------------------------
  242.   def move_akea_input_bars
  243.     @akea_itt_bar.zoom_x = @akea_input_timer.to_f/Akea_ITT::Input[@akea_itt.first[0]][:time]
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Verificador de teclas
  247.   #--------------------------------------------------------------------------
  248.   def check_input
  249.     Akea_ITT::Key_Map.each{|key|
  250.     if Input.trigger?(key)
  251.       return 2 if key != Akea_ITT::Input[@akea_itt.first[0]][:triggers][@akea_trigger_shuffle]
  252.     end
  253.     }
  254.     return 1 if Input.trigger?(Akea_ITT::Input[@akea_itt.first[0]][:triggers][@akea_trigger_shuffle])
  255.     return 0
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # * Chamada de invocação de habilidade
  259.   #--------------------------------------------------------------------------
  260.   def call_akea_skill
  261.     @akea_trigger_shuffle = -1
  262.     party_id = all_battle_members.index(@subject)
  263.     BattleManager.add_input_trigger_action(party_id)
  264.     if all_battle_members[party_id].actor?
  265.       $game_party.members[party_id].input.set_skill(@akea_itt.first[1])
  266.     else
  267.       targets = @subject.current_action.make_targets.compact
  268.       $game_troop.members[party_id - $game_party.members.size].force_action(@akea_itt.first[1], $game_party.members.index(targets[0]))
  269.     end
  270.     @akea_itt.shift
  271.     akea_itt_use_item
  272.     self.class.superclass.instance_method(:update).bind(self).call until akea_input_animation
  273.     BattleManager.remove_action_trigger
  274.     unless @akea_itt.empty?
  275.       @akea_input_success = false
  276.       start_akea_input_trigger
  277.     end
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # * Finalização do processo
  281.   #--------------------------------------------------------------------------
  282.   def terminate
  283.     @akea_itt_bar_base.bitmap.dispose
  284.     @akea_itt_bar_base.dispose
  285.     @akea_itt_bar.bitmap.dispose
  286.     @akea_itt_bar.dispose
  287.     @akea_itt_pic.bitmap.dispose if @akea_itt_pic.bitmap
  288.     @akea_itt_pic.dispose    
  289.     akea_itt_terminate
  290.   end
  291. end
  292.  
  293.  
  294. #==============================================================================
  295. # ** BattleManager
  296. #------------------------------------------------------------------------------
  297. #  Este módulo gerencia o andamento da batalha.
  298. #==============================================================================
  299.  
  300. module BattleManager
  301.   #--------------------------------------------------------------------------
  302.   # * Criação da seqüencia de ações
  303.   #--------------------------------------------------------------------------
  304.   def self.add_input_trigger_action(id)
  305.     @action_battlers = [] unless @action_battlers.is_a?(Array)
  306.     @action_battlers.unshift($game_party.members[id])
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # * Remove um actor
  310.   #--------------------------------------------------------------------------
  311.   def self.remove_action_trigger
  312.     @action_battlers.shift
  313.   end
  314. end
  315.  
  316.  
  317. #==============================================================================
  318. # ** Cache
  319. #------------------------------------------------------------------------------
  320. #  Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  321. # Para acelerar o carregamento e preservar memória, este módulo matém o
  322. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  323. # pré-existentes quando mesmo Bitmap é requerido novamente.
  324. #==============================================================================
  325.  
  326.  
  327. module Cache
  328.   #--------------------------------------------------------------------------
  329.   # * Carregamento dos gráficos de animação
  330.   #     filename : nome do arquivo
  331.   #     hue      : informações da alteração de tonalidade
  332.   #--------------------------------------------------------------------------
  333.   def self.akea(filename)
  334.     load_bitmap("Graphics/Akea/", filename)
  335.   end
  336. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement