molegato

Basimple BS v2

Feb 8th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.46 KB | None | 0 0
  1. #==============================================================================
  2. # BASIMPLE BATTLE SYSTEM
  3. # Author Molegato
  4. # Version 2.1
  5. #------------------------------------------------------------------------------
  6. # The formerly least customizable battle system on the universe, now it's
  7. # customizable! hooray!
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported['Molegato-Basimple Battle System'] = true
  12.  
  13. #==============================================================================
  14. # CONFIGURATION, YOU CAN TOUCH THIS
  15. #==============================================================================
  16. module MOLEGATO_BASIMPLE_BS
  17.   # Number of frames for the poses
  18.   FRAME_NUMBER = 4
  19.   # Animation Speed
  20.   FRAME_SPEED = 0.1
  21.  
  22.   # 0 -> default
  23.   # 1 -> no effect
  24.   # 2 -> all blink
  25.   DAMAGE_EFFECT = 1
  26.  
  27.   #troops with @ in their name will never auto-arrange
  28.   ARRANGE_ENEMIES = true
  29.  
  30.   #0= heroes at left, 1= heroes at right
  31.   SIDE = 0
  32.   #distance to the border of the screen (horizontally)
  33.   MARGIN = 75
  34.   #distance to the top of the lowest member of the party
  35.   VERTICAL_PARTY_POS = 325
  36.   #vertical separation between members of the party
  37.   VERTICAL_SEP = 25
  38.   #for a diagonal-ish effect, horizontal separation between members of party
  39.   DIAGONAL_POS = 30
  40.   #Distance the battler will be away of its target while meleeing
  41.   MELEE_DISTANCE = 25
  42.   #Distance the battler will move forward while casting magic
  43.   STEP_DISTANCE = 100
  44.   # screen y for battlers that are attacking everyone
  45.   CENTER_DOWN = 250
  46.   #to mirror every battler. Useful if all your battlers are facing the left and you dont want to flip'em all
  47.   GLOBAL_MIRROR = false
  48. end
  49.  
  50. #==============================================================================
  51. # TAG INSTRUCTIONS
  52. #------------------------------------------------------------------------------
  53. # For Actors/enemies:
  54. # <guard_anim: id>      Sets an animation for guarding
  55. # <enemy_size: size>
  56. # <actor_size: size>    Both control the size of the battler. 1 means normal.
  57. #
  58. # For Skills/items:
  59. # <melee>               The battler gets near the target while performing action
  60. # <cast_anim: id>       Shows an animation on battler before moving
  61. # <melee_anim: id>      Shows an animation on battler after moving.
  62. # <custom_pose: name>   Uses a custom pose animation, rather than the default
  63. #                       magical/physical/item one.
  64. #
  65. #==============================================================================
  66.  
  67. #==============================================================================
  68. # END OF CONFIGURATION. EVERYTHING UNDER HERE IS A HELLISH MESS OF DEFICIENT
  69. # AMATEUR SCRIPTING. BE AWARE THAT MESSING WITH IT CAN RESULT IN DISASTER
  70. #==============================================================================
  71.  
  72.  
  73. #==============================================================================
  74. # ■ BattleManager
  75. #==============================================================================
  76.  
  77. module BattleManager
  78.  
  79.   def self.update_pos
  80.     action_battlers = []
  81.     action_battlers += $game_party.members unless @surprise
  82.     action_battlers += $game_troop.members unless @preemptive
  83.     action_battlers.each {|battler|
  84.     battler.update_pos
  85.     battler.frame+=MOLEGATO_BASIMPLE_BS::FRAME_SPEED
  86.     if frame_string=battler.frame.round()>MOLEGATO_BASIMPLE_BS::FRAME_NUMBER-1
  87.       if battler.action=='' or battler.action=='move' or battler.action=='move_back'
  88.         battler.frame=0
  89.       else
  90.         battler.frame=MOLEGATO_BASIMPLE_BS::FRAME_NUMBER-1
  91.       end
  92.     end
  93.     }
  94.   end
  95.  
  96.   def self.init_pos
  97.     @action_battlers = []
  98.     @action_battlers += $game_party.members unless @surprise
  99.     @action_battlers += $game_troop.members unless @preemptive
  100.     @action_battlers.each {|battler|
  101.     battler.set_x=battler.screen_x
  102.     battler.set_y=battler.screen_y
  103.     battler.current_x=battler.screen_x
  104.     battler.current_y=battler.screen_y
  105.     }
  106.   end
  107.  
  108.   #--------------------------------------------------------------------------
  109.   # ● battle_start
  110.   #--------------------------------------------------------------------------
  111.   # overwritten for fun!!
  112.   #--------------------------------------------------------------------------
  113.   def self.battle_start
  114.     $game_system.battle_count += 1
  115.     $game_party.on_battle_start
  116.     $game_troop.on_battle_start
  117.     $game_troop.enemy_names.each do |name|
  118.       $game_message.add(sprintf(Vocab::Emerge, name))
  119.     end
  120.     if @preemptive
  121.       $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
  122.     elsif @surprise
  123.       $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
  124.     end
  125.     init_pos
  126.     wait_for_message
  127.   end
  128.  
  129.  
  130. end
  131.  
  132.  
  133. #==============================================================================
  134. # ■ Scene_Battle
  135. #==============================================================================
  136.  
  137. class Scene_Battle < Scene_Base
  138.   #--------------------------------------------------------------------------
  139.   # ● update_basic
  140.   #--------------------------------------------------------------------------
  141.   # there used to be an infinite loop here. Its gone now.
  142.   #--------------------------------------------------------------------------
  143.   alias basimple_update_basic update_basic
  144.   def update_basic
  145.     basimple_update_basic
  146.     BattleManager.update_pos
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # ● use_item
  150.   #--------------------------------------------------------------------------
  151.   # i spent a big time here
  152.   #--------------------------------------------------------------------------
  153.  
  154.   def use_item
  155.     item = @subject.current_action.item
  156.    
  157.     #show cast anim
  158.     if item.tag_check_multivalues(item.note,"cast_anim")
  159.       show_animation([@subject], item.tag_check_multivalues(item.note,"cast_anim")[0].to_i())
  160.     end
  161.    
  162.     @subject.action="move"
  163.     @subject.frame=0
  164.     #change pos
  165.     if item.has_tag?("melee")
  166.       if item.for_all?
  167.         @subject.set_x=Graphics.width/2
  168.         @subject.set_y=MOLEGATO_BASIMPLE_BS::CENTER_DOWN
  169.       else
  170.         @subject.set_x=@subject.current_action.make_targets.compact[0].screen_x-MOLEGATO_BASIMPLE_BS::MELEE_DISTANCE*@subject.face_direction
  171.         @subject.set_y=@subject.current_action.make_targets.compact[0].screen_y
  172.       end
  173.     end
  174.    
  175.     if not item.has_tag?("melee")
  176.       if item.for_all?
  177.         @subject.set_x=@subject.screen_x+MOLEGATO_BASIMPLE_BS::STEP_DISTANCE*@subject.face_direction
  178.         @subject.set_y=MOLEGATO_BASIMPLE_BS::CENTER_DOWN
  179.       else
  180.         @subject.set_x=@subject.screen_x+MOLEGATO_BASIMPLE_BS::STEP_DISTANCE*@subject.face_direction
  181.         @subject.set_y=@subject.current_action.make_targets.compact[0].screen_y
  182.       end
  183.     end
  184.  
  185.     #wait for the movement
  186.     abs_wait(30)
  187.        
  188.     #change graphic
  189.     custom=false
  190.     if item.tag_check_multivalues(item.note,"custom_pose")
  191.       @subject.action=item.tag_check_multivalues(item.note,"custom_pose")[0]
  192.       custom=true
  193.     end
  194.     if item.is_a?(RPG:: Skill) && item.id == @subject.attack_skill_id
  195.       if custom==false
  196.         @subject.action="attack"
  197.       end
  198.     else
  199.       if item.is_a?(RPG:: Skill) && item.id == @subject.guard_skill_id
  200.         @subject.action="stand"
  201.         #show guard anim
  202.         if @subject.actor?
  203.           if item.tag_check_multivalues(@subject.actor.note,"guard_anim")
  204.             show_animation([@subject], item.tag_check_multivalues(@subject.actor.note,"guard_anim")[0].to_i())
  205.           end
  206.         else
  207.           if item.tag_check_multivalues(@subject.enemy.note,"guard_anim")
  208.             show_animation([@subject], item.tag_check_multivalues(@subject.enemy.note,"guard_anim")[0].to_i())
  209.           end
  210.         end
  211.       else
  212.         if item.is_a?(RPG:: Skill) && item.physical?
  213.           if custom==false
  214.             @subject.action="physical"
  215.           end
  216.         end
  217.         if item.is_a?(RPG:: Skill) && item.magical?
  218.           if custom==false
  219.             @subject.action="magical"
  220.           end
  221.         end
  222.         if item.is_a?(RPG:: Item)
  223.           if custom==false
  224.             @subject.action="item"
  225.           end
  226.         end
  227.       end
  228.     end
  229.     @subject.frame=0
  230.    
  231.     #show melee anim
  232.     if item.tag_check_multivalues(item.note,"melee_anim")
  233.       show_animation([@subject], item.tag_check_multivalues(item.note,"melee_anim")[0].to_i())
  234.     else
  235.       #wait some more
  236.       abs_wait(15)
  237.     end
  238.    
  239.     @log_window.display_use_item(@subject, item)
  240.     @subject.use_item(item)
  241.     refresh_status
  242.     targets = @subject.current_action.make_targets.compact
  243.     targets.each {|target| item.repeats.times {
  244.       if item.damage.to_hp? and not item.damage.recover?
  245.         target.action="hurt"
  246.         target.frame=0
  247.       end} }
  248.     if not $imported["YEA-BattleEngine"]
  249.       if targets.size==1
  250.         show_animation(targets, item.animation_id,targets[0].animation_mirror)
  251.       else
  252.         show_animation(targets, item.animation_id)
  253.       end
  254.     end
  255.     targets.each {|target| item.repeats.times {
  256.     invoke_item(target, item)
  257.     target.action=""
  258.     } }
  259.    
  260.     #restart graphic and pos
  261.     @subject.action="move_back"
  262.     @subject.frame=0
  263.     @subject.set_x=@subject.screen_x
  264.     @subject.set_y=@subject.screen_y
  265.     abs_wait(30)
  266.     @subject.action=""
  267.     @subject.frame=0
  268.   end
  269.  
  270.   #--------------------------------------------------------------------------
  271.   # show animation
  272.   #--------------------------------------------------------------------------
  273.   # because of the mirror
  274.   #--------------------------------------------------------------------------
  275.   def show_animation(targets, animation_id, mirror = false)
  276.     if animation_id < 0
  277.       show_attack_animation(targets)
  278.     else
  279.       show_normal_animation(targets, animation_id, mirror)
  280.     end
  281.     @log_window.wait
  282.     wait_for_animation
  283.   end
  284.  
  285. end
  286.  
  287.  
  288. #==============================================================================
  289. # ■ Game_Enemy
  290. #==============================================================================
  291.  
  292. class Game_Enemy < Game_Battler
  293.   attr_accessor :current_x
  294.   attr_accessor :current_y
  295.   attr_accessor :set_x
  296.   attr_accessor :set_y
  297.   attr_accessor :action
  298.   attr_accessor :frame
  299.   attr_accessor :size
  300.   #--------------------------------------------------------------------------
  301.   # ● initialize
  302.   #--------------------------------------------------------------------------
  303.   def initialize(index, enemy_id)
  304.     super()
  305.     @index = index
  306.     @enemy_id = enemy_id
  307.     enemy = $data_enemies[@enemy_id]
  308.     @original_name = enemy.name
  309.     @letter = ""
  310.     @plural = false
  311.     @screen_x = 0
  312.     @screen_y = 0
  313.     @battler_hue = enemy.battler_hue
  314.     @hp = mhp
  315.     @mp = mmp
  316.     @current_x=0
  317.     @current_y=0
  318.     @set_x=0
  319.     @set_y=0
  320.     @action = ''
  321.     @frame=0.0
  322.     if enemy.tag_check_multivalues(enemy.note,"enemy_size")
  323.       @size=enemy.tag_check_multivalues(enemy.note,"enemy_size")[0].to_f
  324.     else
  325.       @size=1
  326.     end
  327.   end
  328.  
  329.   def battler_name
  330.     if MOLEGATO_BASIMPLE_BS::FRAME_NUMBER==1
  331.       frame_string=''
  332.     else
  333.       frame_string=@frame.round().to_s()
  334.     end
  335.    
  336.     if action==''
  337.       return enemy.battler_name+'/'+'stand'+frame_string
  338.     else
  339.       return enemy.battler_name+'/'+action+frame_string
  340.     end
  341.   end
  342.  
  343.   def update_pos
  344.     @current_x=(@current_x*9+@set_x)/10
  345.     @current_y=(@current_y*9+@set_y)/10
  346.   end
  347.  
  348.   def screen_x
  349.     if MOLEGATO_BASIMPLE_BS::ARRANGE_ENEMIES==false or $game_troop.troop.name[/@/mi]=="@"
  350.       return @screen_x
  351.     else
  352.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  353.         return Graphics.width-MOLEGATO_BASIMPLE_BS::MARGIN - MOLEGATO_BASIMPLE_BS::DIAGONAL_POS*self.index
  354.       else
  355.         return MOLEGATO_BASIMPLE_BS::MARGIN + MOLEGATO_BASIMPLE_BS::DIAGONAL_POS*self.index
  356.       end
  357.     end
  358.   end
  359.  
  360.   def screen_y
  361.     if MOLEGATO_BASIMPLE_BS::ARRANGE_ENEMIES==false or $game_troop.troop.name[/@/mi]=="@"
  362.       return @screen_y
  363.     else
  364.       return MOLEGATO_BASIMPLE_BS::VERTICAL_PARTY_POS-self.index*MOLEGATO_BASIMPLE_BS::VERTICAL_SEP
  365.     end
  366.   end
  367.  
  368.   def animation_mirror
  369.     if MOLEGATO_BASIMPLE_BS::GLOBAL_MIRROR==false
  370.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  371.         return false
  372.       else
  373.         return true
  374.       end
  375.     else
  376.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  377.         return true
  378.       else
  379.         return false
  380.       end
  381.     end
  382.   end
  383.   #--------------------------------------------------------------------------
  384.   # ● perform damage_effect
  385.   #--------------------------------------------------------------------------
  386.   # cause it was annoying.
  387.   #--------------------------------------------------------------------------
  388.   def perform_damage_effect
  389.     if MOLEGATO_BASIMPLE_BS::DAMAGE_EFFECT==0 or MOLEGATO_BASIMPLE_BS::DAMAGE_EFFECT==2
  390.       @sprite_effect_type = :blink
  391.       Sound.play_enemy_damage      
  392.     end
  393.   end
  394.  
  395.   def face_direction
  396.     if MOLEGATO_BASIMPLE_BS::SIDE==0
  397.       if actor?
  398.         return 1
  399.       else
  400.         return -1
  401.       end
  402.     else
  403.       if actor?
  404.         return -1
  405.       else
  406.         return 1
  407.       end        
  408.     end
  409.   end
  410.  
  411. end
  412.  
  413.  
  414. #==============================================================================
  415. # ■ Game_Actor
  416. #==============================================================================
  417.  
  418. class Game_Actor < Game_Battler
  419.   attr_accessor :current_x
  420.   attr_accessor :current_y
  421.   attr_accessor :set_x
  422.   attr_accessor :set_y
  423.   attr_accessor :action
  424.   attr_accessor :frame
  425.   attr_accessor :size
  426.  
  427.   #--------------------------------------------------------------------------
  428.   # ● setup
  429.   #--------------------------------------------------------------------------
  430.   def setup(actor_id)
  431.     @actor_id = actor_id
  432.     @name = actor.name
  433.     @nickname = actor.nickname
  434.     init_graphics
  435.     @class_id = actor.class_id
  436.     @level = actor.initial_level
  437.     @exp = {}
  438.     @equips = []
  439.     @battler_hue = 0
  440.     init_exp
  441.     init_skills
  442.     init_equips(actor.equips)
  443.     clear_param_plus
  444.     recover_all
  445.     @current_x=0
  446.     @current_y=0
  447.     @set_x=0
  448.     @set_y=0
  449.     @action = ''
  450.     @frame=0.0
  451.     if actor.tag_check_multivalues(actor.note,"actor_size")
  452.       @size=actor.tag_check_multivalues(actor.note,"actor_size")[0].to_f
  453.     else
  454.       @size=1
  455.     end
  456.  
  457.   end
  458.  
  459.   #--------------------------------------------------------------------------
  460.   # ● screen_whatever
  461.   #--------------------------------------------------------------------------
  462.   def screen_z
  463.     return 100
  464.   end
  465.  
  466.   def screen_x
  467.     if MOLEGATO_BASIMPLE_BS::SIDE==0
  468.       return MOLEGATO_BASIMPLE_BS::MARGIN + MOLEGATO_BASIMPLE_BS::DIAGONAL_POS*self.index
  469.     else
  470.       return Graphics.width-MOLEGATO_BASIMPLE_BS::MARGIN - MOLEGATO_BASIMPLE_BS::DIAGONAL_POS*self.index
  471.     end
  472.   end
  473.  
  474.   def screen_y
  475.     return MOLEGATO_BASIMPLE_BS::VERTICAL_PARTY_POS-self.index*MOLEGATO_BASIMPLE_BS::VERTICAL_SEP
  476.   end
  477.    
  478.   def battler_name
  479.     if MOLEGATO_BASIMPLE_BS::FRAME_NUMBER==1
  480.       frame_string=''
  481.     else
  482.       frame_string=@frame.round().to_s()
  483.     end
  484.    
  485.     if action==''
  486.       return face_name+"/"+'stand'+frame_string
  487.     else
  488.       return face_name+"/"+action+frame_string
  489.     end
  490.   end
  491.  
  492.   def update_pos
  493.     @current_x=(@current_x*9+@set_x)/10
  494.     @current_y=(@current_y*9+@set_y)/10
  495.   end
  496.  
  497.   #--------------------------------------------------------------------------
  498.   # ● use sprite
  499.   #--------------------------------------------------------------------------
  500.   def use_sprite?
  501.     return true
  502.   end
  503.  
  504.   def animation_mirror
  505.     if MOLEGATO_BASIMPLE_BS::GLOBAL_MIRROR==false
  506.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  507.         return true
  508.       else
  509.         return false
  510.       end
  511.     else
  512.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  513.         return false
  514.       else
  515.         return true
  516.       end
  517.     end
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # ● perform damage effect
  521.   #--------------------------------------------------------------------------
  522.   # edited cause it annoyed me
  523.   #--------------------------------------------------------------------------
  524.   def perform_damage_effect
  525.     if MOLEGATO_BASIMPLE_BS::DAMAGE_EFFECT==0
  526.       $game_troop.screen.start_shake(5, 5, 10)
  527.       @sprite_effect_type = :blink
  528.       Sound.play_actor_damage
  529.     end
  530.     if MOLEGATO_BASIMPLE_BS::DAMAGE_EFFECT==2
  531.       @sprite_effect_type = :blink
  532.       Sound.play_actor_damage      
  533.     end
  534.   end
  535.  
  536.   def face_direction
  537.     if MOLEGATO_BASIMPLE_BS::SIDE==0
  538.       if actor?
  539.         return 1
  540.       else
  541.         return -1
  542.       end
  543.     else
  544.       if actor?
  545.         return -1
  546.       else
  547.         return 1
  548.       end        
  549.     end
  550.   end
  551.  
  552. end
  553.  
  554.  
  555. #==============================================================================
  556. # ■ Sprite_Battler
  557. #==============================================================================
  558.  
  559. class Sprite_Battler < Sprite_Base
  560.      
  561.   alias basimple_update update
  562.   def update
  563.     basimple_update
  564.     update_size
  565.     if MOLEGATO_BASIMPLE_BS::GLOBAL_MIRROR==false
  566.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  567.         self.mirror=@battler.enemy?
  568.       else
  569.         self.mirror=@battler.actor?
  570.       end
  571.     else
  572.       if MOLEGATO_BASIMPLE_BS::SIDE==0
  573.         self.mirror=@battler.actor?
  574.       else
  575.         self.mirror=@battler.enemy?
  576.       end
  577.     end
  578.   end
  579.  
  580.   def update_size
  581.     if @battler and @battler.size!=get_size
  582.       @size=@battler.size
  583.     end
  584.     if get_size!=1
  585.       source = self.bitmap
  586.       self.bitmap = Bitmap.new(source.width*@size, source.height*@size)
  587.       self.bitmap.stretch_blt(self.bitmap.rect, source, source.rect)
  588.       self.ox*=get_size
  589.       self.oy*=get_size
  590.     end
  591.   end
  592.  
  593.   #--------------------------------------------------------------------------
  594.   # ● 位置の更新
  595.   #--------------------------------------------------------------------------
  596.   def update_position
  597.     self.x = @battler.current_x
  598.     self.y = @battler.current_y
  599.     self.z = self.y*2
  600.   end
  601.  
  602.   def set_size(new_size)
  603.     @size=new_size
  604.   end
  605.  
  606.   def get_size
  607.     if !@size
  608.       @size=1
  609.     end
  610.     return @size
  611.   end
  612. end
  613.  
  614. class Game_Battler < Game_BattlerBase
  615.   def face_direction
  616.     if MOLEGATO_BASIMPLE_BS::SIDE==0
  617.       if actor?
  618.         return 1
  619.       else
  620.         return -1
  621.       end
  622.     else
  623.       if actor?
  624.         return -1
  625.       else
  626.         return 1
  627.       end        
  628.     end
  629.   end
  630. end
  631. #==============================================================================
  632. # ■ Spriteset_Battle
  633. #==============================================================================
  634.  
  635. class Spriteset_Battle
  636.   #--------------------------------------------------------------------------
  637.   # create_actors
  638.   #--------------------------------------------------------------------------
  639.   # cause they needed to be visible
  640.   #--------------------------------------------------------------------------
  641.   def create_actors
  642.     @actor_sprites = $game_party.members.reverse.collect do |actor|
  643.       Sprite_Battler.new(@viewport1, actor)
  644.     end
  645.   end
  646.  
  647.   #--------------------------------------------------------------------------
  648.   # update_actors
  649.   #--------------------------------------------------------------------------
  650.   def update_actors
  651.       @actor_sprites.each {|sprite| sprite.update }
  652.   end
  653.    
  654. end
Advertisement
Add Comment
Please, Sign In to add comment