查看: 1575|回复: 1

[已经过期] 设计好了10个战斗点 只能出9个战斗不知道原因

[复制链接]
梦石
0
星屑
7296
在线时间
1244 小时
注册时间
2015-8-15
回帖
473
发表于 2017-4-3 14:37:45 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
[pre lang="ruby"]#==============================================================================
# ■ EFS
#------------------------------------------------------------------------------
#  群战系统的游戏主操控类
#   全新版本
#   作者 Raider Soap 肥皂君~
#
#==============================================================================
class EFS
  
  #--------------------------------------------------------------------------
  # ● 初始化数据
  #--------------------------------------------------------------------------
  def initialize(party1,party2)
    $Team_Fighter = []
    $Enermy_Fighter = []
    $Num_Team = 1    # player
    $Team_Fighter.push $game_player
    $Num_Enermy = 0
    #死亡计数
    $Team_Death_counter = 0
    $Enermy_Death_counter = 0
   
    $game_player.self_battler = $game_player # 正太君改
    $game_player.hp = $game_party.actors[0].hp  # 正太君改
    $game_player.maxhp = $game_party.actors[0].maxhp # 正太君改
    $game_player.mp = $game_party.actors[0].sp # 正太君改
    $game_player.maxmp = $game_party.actors[0].maxsp # 正太君改
    $game_player.skilled_level = 3
    $game_player.action_mode = 0
    $game_player.armor = 30
    $game_player.ap = 60
    $game_player.ap_range = 5
    $game_player.atk_se = "swordbasic_"
    $game_player.atk_se_num = 11
    $game_player.heavy = false
    $game_player.name = "theplayer"
    $game_player.atk_fr = 30
    $game_player.is_cav = false
    $game_player.shd = false

    #双方队伍
    @team_party = party1
    @enermy_party = party2
   
    #团队
    $team_group = []
    $enermy_group = []
    $team_group[0] = []
    for i in 1..10
      $team_group = []
      $enermy_group = []
    end
    $lisenter = 0
    #坚守的行数量
    @guarding_line_num = 1
   
    #出生点
    @group_spawn = []
    for i in 1..10#  5改为10个
      @group_spawn = []
    end
    @group_spawn_e = []
    for i in 1..10 #  5改为10个
      @group_spawn_e = []
    end
   
    @counter = 0
    @counter_for_wait = 0
    @counter_for_push = 0
   
    @c = false
   
    @spell_used = []
    #一定要把所有技能在这里过一遍
    #一定要把所有技能在这里过一遍
    #一定要把所有技能在这里过一遍
   # for i in 1..X
    @spell_used[1] = Skill_data::TIME[1] # i
   #end
  end
  
  #--------------------------------------------------------------------------
  # ● 显示图标
  #--------------------------------------------------------------------------  
  def show_icon
    if $selected_item == 0
      item_id = 33
    else
      item_id =  Item_data::ID[$selected_item]  
    end  
    if $selected_spell == 0
      spell_id = 0
    else
       spell_id =  $selected_spell
    end  
    item = $data_items[item_id]
    spell_icon = Skill_data::ICON[spell_id]
   
    # 设置变量
    $game_variables[2] = $game_party.item_number(item_id) #物品数量
    $game_variables[3] = @spell_used[$selected_spell]
   
    # 显示图
    $game_screen.pictures[5].show(item.icon_name,1,494,444, 100, 100, 255, 0)
    $game_screen.pictures[2].show(spell_icon,1,532,444, 100, 100, 255, 0)   if not $selected_spell == 0
    $game_screen.pictures[8].show("shd01",1,609,444, 100, 100, 255, 0)
    weapons = $data_weapons[$game_party.actors[0].weapon_id]
    $game_screen.pictures[9].show(weapons.icon_name,1,571,444, 100, 100, 255, 0)

  end
  #--------------------------------------------------------------------------
  # ● 寻找小队坐标点
  #--------------------------------------------------------------------------
  def group_spawn_points
    #循环全部事件
     for event in $game_map.events.values
       Graphics.update
       if event.name[0,3] == "##T"
          group = event.name[3,1].to_i
          @group_spawn[group].push event.x
          @group_spawn[group].push event.y
          @group_spawn[group].push event.name[4,1].to_i
          #[event.x,event.y,event.name[4,1].to_i]
       elsif event.name[0,3] == "##E"
          group = event.name[3,1].to_i
          @group_spawn_e[group].push event.x
          @group_spawn_e[group].push event.y
          # name[4,1]的值为 1 代表横着 2 代表竖着
          @group_spawn_e[group].push event.name[4,1].to_i      
       end  
     end
  end   
  #--------------------------------------------------------------------------
  # ● 创建士兵
  #--------------------------------------------------------------------------
  def spawn_fighters
    Drop_Item.pre_load
    for group_id in 1..10
       num_people = @team_party.number(group_id)
       next if @team_party.number(group_id) == 0
       num = even?(num_people) ? num_people/2 : (num_people-1)/2
       for i in 0..@team_party.number(group_id) - 1
       x = @group_spawn[group_id][0]  
       y = @group_spawn[group_id][1]
       new_x = @group_spawn[group_id][2] == 1 ? x - num + i : x
       new_y = @group_spawn[group_id][2] == 2 ? y - num + i : y
       Drop_Item.make_events_EFS(new_x,new_y)
       Graphics.update
        for event in $game_map.events.values
          if event.x == new_x and event.y == new_y and not event.name[0,2] == "##"
            team_fighter = @team_party.group[group_id]
            @team_party.group[group_id].set_event(event)
            $Team_Fighter.push(team_fighter)
            $team_group[0].push team_fighter
            $team_group[team_fighter.group_id].push team_fighter         
            event.self_battler = team_fighter
            
          end  
        end
       end
     end
     Drop_Item.refresh_map
  end
  def spawn_fighters_e
      Drop_Item.pre_load
    for group_id in 1..10
       num_people = @enermy_party.number(group_id)
       num = even?(num_people) ? num_people/2 : (num_people-1)/2
       for i in 0..@enermy_party.number(group_id)-1
       x = @group_spawn_e[group_id][0]  
       y = @group_spawn_e[group_id][1]
       new_x = @group_spawn_e[group_id][2] == 1 ? x - num + i : x
       new_y = @group_spawn_e[group_id][2] == 2 ? y - num + i : y
       Drop_Item.make_events_EFS(new_x,new_y)
       Graphics.update
       for event in $game_map.events.values
         if event.x == new_x and event.y == new_y and not event.name[0,2] == "##"
            team_fighter = @enermy_party.group[group_id]
            @enermy_party.group[group_id].set_event(event)
            $Enermy_Fighter.push(team_fighter)
            $enermy_group[team_fighter.group_id].push team_fighter  
            event.self_battler = team_fighter
          end  
       end
       end
     end
     Drop_Item.refresh_map
  end   
  def even?(value)
  value & 1 == 0
  end  
  #--------------------------------------------------------------------------
  # ● 分组设定
  #--------------------------------------------------------------------------
  def groups_setting
    for fighters in $Team_Fighter
      $team_group[fighters.group_id].push fighters if fighters != $game_player
      $team_group[0].push fighters if fighters != $game_player
    end
    for fighters in $Enermy_Fighter
      $enermy_group[fighters.group_id].push fighters
    end
  end  

  #--------------------------------------------------------------------------
  # ● 下达初始指令
  #--------------------------------------------------------------------------
  def command(team,group,command_id)
    #TEAM = 1 代表 玩家的队伍 2 代表 敌人的队伍
      if team = 1
        for f in $team_group[group]
         f.command_action = command_id
        end
      else
        for e in $enermy_group[group]
         e.command_action = command_id
        end
      end  
  end   

  #--------------------------------------------------------------------------
  # ● 士兵基础设置 # 正太君改
  #--------------------------------------------------------------------------
  def set_fighters
    #循环全部事件
     for event in $game_map.events.values
       if event.name[0,2] == "#T"
         team_fighter = EFS_Team.new(event,event.name[3,3].to_i)
         $Team_Fighter.push(team_fighter)
         event.self_battler = team_fighter
       elsif event.name[0,2] == "#E"
         enermy_fighter = EFS_Enermy.new(event,event.name[3,3].to_i)
         $Enermy_Fighter.push(enermy_fighter)
         event.self_battler = enermy_fighter
       end  
     end  

   end
   
   
   def update_player_data
    $game_player.hp = $game_party.actors[0].hp  # 正太君改
    $game_player.mp = $game_party.actors[0].sp # 正太君改
    $game_party.actors[0].hp = $game_party.actors[0].hp.round
    $game_party.actors[0].sp = $game_party.actors[0].sp.round
    $game_player.update_die if $game_player.dead?
    # 冷却
    $item_cd -= 1 if $item_cd > 0
    $spell_cd -= 1 if $spell_cd > 0
    $item_opacity = 255 if $item_cd <= 0 else  $item_opacity = 140

    if $selected_item == 0
      item_id = 33
    else
      item_id =  Item_data::ID[$selected_item]  
    end  
    if $selected_spell == 0
      spell_id = 0
    else
       spell_id =  $selected_spell
    end  
    item = $data_items[item_id]
    # 设置变量
    $game_variables[2] = $game_party.item_number(item_id)
    $game_variables[3] = @spell_used[$selected_spell]
    # 显示图
    $game_screen.pictures[2].move(0,0,532,444, 100, 100, 255, 0)   if not $selected_spell == 0
    $game_screen.pictures[8].move(0,0,609,444, 100, 100, 255, 0)
    $game_screen.pictures[5].move(0,0,450,432, 100, 100,$item_opacity, 0)
    weapons = $data_weapons[$game_party.actors[0].weapon_id]
    $game_screen.pictures[9].move(0,0,573,433, 100, 100,255, 0)
   
    show_icon
   
    # 是否是加速状态的更新
    $game_player.accelarting = $game_player.move_speed == 4 ? true : false
     
    end  
  
  
  
  #--------------------------------------------------------------------------
  # ● 主处理  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  
  #--------------------------------------------------------------------------
  def main
    return if $BattleOn == false
    #判断是否胜利
    if check_winning
      after_battle
      return
    end  
    $game_player.update_die if $game_player.dead?
    #######UPDATE#########
      update_player_data
    ######################
    $game_player.attack if $game_player.attack? and not $game_player.dead?  
   
    #如果敌人是推进策略
    for i in 1..10
      group_check_cor(i)
    end  
    if @enermy_party.strategy == 2
        e_push if push_wait
    end
      
    #判断输入
    if (Kboard.keyboard($R_Key_SPACE)) and not $game_player.dead?
         $game_player.attack if use_sp(90)
     elsif Kboard.keyboard($R_Key_1) and not $game_player.dead?
       Notification.post("第1队!听我的命令!")
      $lisenter = 1 #group 1
    elsif Kboard.keyboard($R_Key_2) and not $game_player.dead?
      $lisenter = 2 #group 2
         Notification.post("第2队!听我的命令!")
    elsif Kboard.keyboard($R_Key_3) and not $game_player.dead?
      $lisenter = 3 #group 3
         Notification.post("第3队!听我的命令!")
    elsif Kboard.keyboard($R_Key_4) and not $game_player.dead?
      $lisenter = 4 #group 4
         Notification.post("第4队!听我的命令!")
    elsif Kboard.keyboard($R_Key_5) and not $game_player.dead?
      $lisenter = 5 #group 5
         Notification.post("第5队!听我的命令!")
       elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
      $lisenter = 6 #group 5
         Notification.post("第6队!听我的命令!")
    elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?
      $lisenter = 7 #group 5
         Notification.post("第7队!听我的命令!")
    elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?      
      $lisenter = 8 #group 5
         Notification.post("第8队!听我的命令!")
    elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?      
      $lisenter = 9 #group 5
         Notification.post("第9队!听我的命令!")
    elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?      
      $lisenter = 10 #group 5
         Notification.post("第10队!听我的命令!")
    elsif Kboard.keyboard($R_Key_0) and not $game_player.dead?      
      
     $lisenter = 0 #group All
     Notification.post("所有人!听我的命令!")
   elsif Kboard.keyboard($R_Key_Q) and not $game_player.dead?
       Notification.post("坚守这里!")
       blocked = false
       for f in $Team_Fighter
         next if f.is_a?(Game_Player)
         blocked = true if f.check_guard_position($game_player.x,$game_player.y,$game_player.direction)
       end  
       unless blocked
          for e in $team_group[$lisenter]
           e.command_action = 1 #def
           e.set_guard_cor($game_player.x,$game_player.y,$game_player.direction,@guarding_line_num) if not @set
          end  
      @set = true
      else
        $game_system.se_play($data_system.buzzer_se)
      end
    elsif Kboard.keyboard($R_Key_W) and not $game_player.dead?
      Notification.post("跟我来!")
      for e in $team_group[$lisenter]
         e.command_action = 2 #onme
      end  
    elsif Kboard.keyboard($R_Key_E) and not $game_player.dead?
        Notification.post("冲锋")
      for e in $team_group[$lisenter]
         e.command_action = 3 #atk
       end
    elsif Kboard.keyboard($R_Key_A) and not $game_player.dead?
       $game_player.character_name = "theplayer-jump"
       if $game_player.accelarting
         $game_player.animation_id = 117
         $game_player.jump_forward(2) if use_sp(75)
       else
        $game_player.animation_id = 117
        $game_player.jump_forward(1) if use_sp(50)
       end   
    elsif Kboard.keyboard($R_Key_S) and not $game_player.dead?
        use_item
    elsif Kboard.keyboard($R_Key_D) and not $game_player.dead?
        use_spell   
    end   

      #是否按键加速
    if Kboard.keyb($R_Key_LSHIFT) and not $game_player.dead? and  not $game_player.attack?
          $game_player.character_name = "theplayer-swd-run" if not $game_player.jumping?
          $game_player.move_speed = use_sp(4) ? 4 : 3
    elsif Kboard.keyb($R_Key_Z) and not $game_player.dead? and  not $game_player.attack?
          $game_player.character_name = "theplayer-shd" if not $game_player.jumping?
          $game_player.heavy = true
          $game_player.move_speed = 2
          $game_player.shd = true     
    else
       if not $game_player.attack?
         $game_player.shd = false
         $game_player.heavy = false
         $game_player.character_name = "theplayer" if not $game_player.jumping?
         $game_party.actors[0].sp += 4
         $game_party.actors[0].sp = $game_party.actors[0].maxsp if $game_party.actors[0].sp >= $game_party.actors[0].maxsp
       end  
         $game_player.move_speed = 3
    end            
   
    if Kboard.keyboard($R_Key_SEP)
      if @guarding_line_num != 1
      @guarding_line_num -= 1
      else
      @guarding_line_num = 3
      end  
    Notification.post("排成"+@guarding_line_num.to_s+"行!")
    elsif Kboard.keyboard($R_Key_DOTT)
      if @guarding_line_num != 3
      @guarding_line_num += 1
      else
      @guarding_line_num = 1
      end  
     Notification.post("排成"+@guarding_line_num.to_s+"行!")
    end  
   
   if Kboard.keyboard($R_Key_ALT)
    @c = @c ? false : true
    $game_switches[5] = @c
    $game_switches[6] = @c
   end  
  
    #所有士兵的main
    for i in 1..$Team_Fighter.size-1
     $Team_Fighter.main
    end
    for e in $Enermy_Fighter
      e.main
    end
    @set = false
   
  end
  #--------------------------------------------------------------------------
  # ● 判断玩家的体力是否足够维持&&可以的话就扣掉相应的
  #--------------------------------------------------------------------------  
  def use_sp(sp)
    if $game_party.actors[0].sp < sp
        $game_system.se_play($data_system.buzzer_se)
        return false
    else
        $game_party.actors[0].sp -= sp if ! $game_player.attack?
        return true
    end
  end
  #--------------------------------------------------------------------------
  # ● 敌人策略分析器
  #--------------------------------------------------------------------------  
  def enermy_strategy
    case @enermy_party.strategy
    when 1
      for e in $Enermy_Fighter
        e.get_group_spawn(@group_spawn_e,@group_spawn)
        e.command_action = 1
      end
    when 2
      for e in $Enermy_Fighter
        e.get_group_spawn(@group_spawn_e,@group_spawn)
        e.command_action = 1
      end
    when 3  
      for e in $Enermy_Fighter
        e.command_action = 3
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 设置初始坚守坐标
  #--------------------------------------------------------------------------
  def set_defualt_guard_cor
      for e in $Team_Fighter
        next if e.is_a?(Game_Player)
        e.get_group_spawn(@group_spawn_e,@group_spawn)
        e.command_action = 1
      end
  end
  #--------------------------------------------------------------------------
  # ● 是否进入警戒距离
  #--------------------------------------------------------------------------   
    def group_check_cor(group_id)
      d_list = []
      e_x,e_y = enermy_avg_cor(group_id)
      for i in 1..10
        t_x,t_y = team_avg_cor(i)
        d = (t_x - e_x).abs + (t_y - e_y).abs
        d_list.push d
      end  
      if d_list.min < 10
        for e in $enermy_group[group_id]
            e.command_action = 3
        end  
      end  
  end
  #--------------------------------------------------------------------------
  # ● 小队的平均坐标
  #--------------------------------------------------------------------------   
  def team_avg_cor(group_id)
    return 0,0 if $team_group[group_id] == nil or $team_group[group_id].size == 0
    sum_x,sum_y = 0,0
    for f in $team_group[group_id]
      sum_x += f.event.x
      sum_y += f.event.y
    end  
    sum_x /= $team_group[group_id].size
    sum_y /= $team_group[group_id].size
    return sum_x,sum_y
  end
  def enermy_avg_cor(group_id)
    return 0,0 if $enermy_group[group_id] == nil or $enermy_group[group_id].size == 0
    sum_x,sum_y = 0,0
    for f in $enermy_group[group_id]
      sum_x += f.event.x
      sum_y += f.event.y
    end  
    sum_x /= $enermy_group[group_id].size
    sum_y /= $enermy_group[group_id].size
    return sum_x,sum_y
  end
  
  def team_avg_cor_all
    sum_x,sum_y = 0,0
    for f in $Team_Fighter
      sum_x += f.event.x
      sum_y += f.event.y
    end  
    sum_x /= $Team_Fighter.size
    sum_y /= $Team_Fighter.size
    return sum_x,sum_y
  end  
  def enermy_avg_cor_all
    sum_x,sum_y = 0,0
    for f in $Enermy_Fighter
      sum_x += f.event.x
      sum_y += f.event.y
    end  
    sum_x /= $Enermy_Fighter.size
    sum_y /= $Enermy_Fighter.size
    return sum_x,sum_y
  end   
  #--------------------------------------------------------------------------
  # ● 使用物品
  #--------------------------------------------------------------------------
  def use_item
    if $selected_item == 0
      item_id = 33
    else
      item_id =  Item_data::ID[$selected_item]  
    end  
    item = $data_items[item_id]
    # 如果物品用完的情况下
      if $game_party.item_number(item_id) == 0
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
    # 如果交战中
      if $game_player.attack?
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end      
    #冷却时间
    if $item_cd > 0
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
    end   
      
     target = $game_party.actors[0]
     used = target.item_effect(item)
              
    # 使用物品的情况下
      if used
        # 演奏物品使用时的 SE
        $game_system.se_play(item.menu_se)
        # 设定冷却时间
        $item_cd = Item_data::COLD_DOWN[$selected_item]
        ###设置变灰###
        $item_opacity = 140
        # 动画
        $game_player.animation_id = item.animation2_id
        # 消耗品的情况下
        if item.consumable
          # 使用的物品数减 1
          $game_party.lose_item(item.id, 1)
        end
        # 全灭的情况下
        if $game_party.all_dead?
          $scene = Scene_Gameover.new
          return
        end
        # 公共事件 ID 有效的情况下
        if item.common_event_id > 0
          # 预约调用公共事件
          $game_temp.common_event_id = item.common_event_id
          return
        end
      end
      # 无法使用物品的情况下
      unless used
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end  
  #--------------------------------------------------------------------------
  # ● 使用技能
  #--------------------------------------------------------------------------   
  def use_spell
    return if $selected_spell == 0
    # 如果技能使用次数用完
    if @spell_used[$selected_spell] <= 0
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
    end
    # 如果交战中
    if $game_player.attack?
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
    end      
    #冷却时间
    if $spell_cd > 0
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
    end   
      
    @spell_used[$selected_spell] -= 1
    $spell_cd = Skill_data::CD[$selected_spell]
    name = Skill_data::NAME[$selected_spell]
    code = Skill_data::CODE[$selected_spell]
    Notification.post("发动了技能"+name+"!")
    EFS_Spell.use_spell(code)
   
  end
  #--------------------------------------------------------------------------
  # ● 判断胜利
  #--------------------------------------------------------------------------
  def check_winning
        counter = 0
      for enermy in $Enermy_Fighter
        if enermy.dead?
         counter+=1
        end  
      end  
      return counter >= $Enermy_Fighter.size
  end
  #--------------------------------------------------------------------------
  # ● 战后处理
  #--------------------------------------------------------------------------
  def after_battle
    if Kboard.keyboard($R_Key_TAB)
      reset
      $scene.spriteset.clear_point_arrow
      $scene.spriteset.clear_arrow
      $game_temp.common_event_id = 2
      $game_player.move_speed = 4
      $BattleOn = false
      $game_switches[20] = false
      $game_temp.common_event_id = 21
      Notification.clear
      $game = nil
      back_to_map  
      $game_party.actors[0].sp = $game_party.actors[0].maxsp
      $player_party.full_ammo
      return
    end      
    $game_party.actors[0].sp += 5
    $game_party.actors[0].sp = $game_party.actors[0].maxsp if $game_party.actors[0].sp >= $game_party.actors[0].maxsp
    for e in $Enermy_Fighter        
      e.event.update_die
    end
    for i in 1..$Team_Fighter.size-1
     $Team_Fighter.event.update_die if $Team_Fighter.dead?
     next if $Team_Fighter.dead?
     $Team_Fighter.event.attack_action = false
     $Team_Fighter.action_mode = 1
     $Team_Fighter.event.character_name = $Team_Fighter.name
    end
      $game_player.attack_action = false
      $game_player.action_mode = 1
      $game_player.attack_over
      $game_player.move_speed =3
    $game_party.actors[0].hp = $game_party.actors[0].hp.round
    $game_party.actors[0].sp = $game_party.actors[0].sp.round
      for e in $Team_Fighter
        next if e.is_a?(Game_Player)
        e.remove_all_state
      end  
    end
  #--------------------------------------------------------------------------
  # ● 战斗结束的士兵处理
  #--------------------------------------------------------------------------  
  def reset
    for f in $Team_Fighter
      next if f.is_a?(Game_Player)
      $player_party.delete(f) if f.dead? and not f.wounded
    end
  end  
  #--------------------------------------------------------------------------
  # ● 战斗结束返回地图
  #--------------------------------------------------------------------------      
  def back_to_map
    # 场所移动中、信息显示中、过渡处理中的情况下
    if $game_temp.player_transferring or
       $game_temp.message_window_showing or
       $game_temp.transition_processing
      # 结束
      return false
    end
    $game_temp.player_transferring = true
      # 设置主角的移动目标
      $game_temp.player_new_map_id = @or_map_id
      $game_temp.player_new_x = @or_x
      $game_temp.player_new_y = @or_y
      $game_temp.player_new_direction = @or_d
      # 准备过渡
      Graphics.freeze
      # 设置过渡处理中标志
      $game_temp.transition_processing = true
      $game_temp.transition_name = ""
    return false
   
  end  
  def load_or_map_data
    @or_map_id = $game_map.map_id
    @or_x =  $game_player.x
    @or_y =  $game_player.y
    @or_d =  $game_player.direction
  end  
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  # ● 接近目标的方向 (面向目标)
  #--------------------------------------------------------------------------
  def get_guard_direction
    sx = @group_spawn_e[1][0] - @group_spawn[1][0]
    sy = @group_spawn_e[1][1] - @group_spawn[1][1]
    abs_sx= (sx).abs  
    abs_sy = (sy).abs
    if abs_sx == 0 and abs_sy == 0
      return
    end
    if sx.abs > sy.abs
      return sx > 0 ? 4 : 6
    else
      return sy > 0 ? 8 : 2
    end
  end  
  
  def e_push
    case get_guard_direction
    when 2
      for i in 1..5
      @group_spawn_e[1] += 4
      end
    when 4
      for i in 1..5
      @group_spawn_e[0] -= 4
      end
    when 6
      for i in 1..5
      @group_spawn_e[0] += 4
      end
    when 8
      for i in 1..5
      @group_spawn_e[1] -= 4
      end
    end  
    for e in $Enermy_Fighter
      e.get_group_spawn(@group_spawn_e,@group_spawn)
    end  
  end
  #--------------------------------------------------------------------------
  # ● Code等待
  #--------------------------------------------------------------------------
  def push_wait
      if @counter_for_push < 135
        @counter_for_push += 1
        return false
      else
        @counter_for_push = 0
        return true
      end
  end     
  #--------------------------------------------------------------------------
  # ● Code等待
  #--------------------------------------------------------------------------
  def code_wait(s)
    #不需要解释,自己写的太渣了
    if @counter_for_wait < s
      @counter_for_wait += 1
      return false
    else
      @counter_for_wait = 0
      return true
    end
  end     

  
  
  
end[/pre]
群战.jpg
群战2.jpg
梦石
0
星屑
7296
在线时间
1244 小时
注册时间
2015-8-15
回帖
473
 楼主| 发表于 2017-4-3 14:40:06 | 显示全部楼层
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 1)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_reader   :id                       # ID
  12.   attr_reader   :x                        # 地图 X 坐标 (理论坐标)
  13.   attr_reader   :y                        # 地图 Y 坐标 (理论坐标)
  14.   attr_reader   :real_x                   # 地图 X 坐标 (实际坐标 * 128)
  15.   attr_reader   :real_y                   # 地图 Y 坐标 (实际坐标 * 128)
  16.   attr_reader   :tile_id                  # 元件 ID  (0 为无效)
  17.   attr_accessor :character_name           # 角色 文件名
  18.   attr_reader   :character_hue            # 角色 色相
  19.   attr_accessor :opacity                  # 不透明度
  20.   attr_reader   :blend_type               # 合成方式
  21.   attr_reader   :direction                # 朝向
  22.   attr_reader   :pattern                  # 图案
  23.   attr_reader   :move_route_forcing       # 移动路线强制标志
  24.   attr_accessor :through                  # 穿透
  25.   attr_accessor :animation_id             # 动画 ID
  26.   attr_accessor :transparent              # 透明状态
  27.   attr_accessor :walk_anime               # 移动时动画
  28.   attr_accessor :step_anime               # 停止时动画
  29.   attr_accessor :anime_count
  30.   attr_accessor :pattern
  31.   attr_accessor :direction_fix
  32.   attr_accessor :attack_action
  33.   attr_accessor :anime_count
  34.   attr_accessor :atk_fr
  35.   attr_accessor :move_speed
  36.   #--------------------------------------------------------------------------
  37.   # ● 初始化对像
  38.   #--------------------------------------------------------------------------
  39.   def initialize
  40.     @id = 0
  41.     @x = 0
  42.     @y = 0
  43.     @real_x = 0
  44.     @real_y = 0
  45.     @tile_id = 0
  46.     @character_name = ""
  47.     @character_hue = 0
  48.     @opacity = 255
  49.     @blend_type = 0
  50.     @direction = 2
  51.     @pattern = 0
  52.     @move_route_forcing = false
  53.     @through = false
  54.     @animation_id = 0
  55.     @transparent = false
  56.     @original_direction = 2
  57.     @original_pattern = 0
  58.     @move_type = 0
  59.     @move_speed = 4
  60.     @move_frequency = 6
  61.     @move_route = nil
  62.     @move_route_index = 0
  63.     @original_move_route = nil
  64.     @original_move_route_index = 0
  65.     @walk_anime = true
  66.     @step_anime = false
  67.     @direction_fix = false
  68.     @always_on_top = false
  69.     @anime_count = 0
  70.     @stop_count = 0
  71.     @jump_count = 0
  72.     @jump_peak = 0
  73.     @wait_count = 0
  74.     @locked = false
  75.     @prelock_direction = 0
  76.     @attack_action = false
  77.     @counter = 0
  78.     @counter_for_animation = 0
  79.     @counter_for_die_animation = 0
  80.     @switchA = false
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● 移动中判定
  84.   #--------------------------------------------------------------------------
  85.   def moving?
  86.     # 如果在移动中理论坐标与实际坐标不同
  87.     return (@real_x != @x * 128 or @real_y != @y * 128)
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ● 跳跃中判定
  91.   #--------------------------------------------------------------------------
  92.   def jumping?
  93.     # 如果跳跃中跳跃点数比 0 大
  94.     return @jump_count > 0
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 矫正姿势
  98.   #--------------------------------------------------------------------------
  99.   def straighten
  100.     # 移动时动画以及停止动画为 ON 的情况下
  101.     if @walk_anime or @step_anime
  102.       # 设置图形为 0
  103.       @pattern = 0
  104.     end
  105.     # 清除动画计数
  106.     @anime_count = 0
  107.     # 清除被锁定的向前朝向
  108.     @prelock_direction = 0
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● 强制移动路线
  112.   #     move_route : 新的移动路线
  113.   #--------------------------------------------------------------------------
  114.   def force_move_route(move_route)
  115.     # 保存原来的移动路线
  116.     if @original_move_route == nil
  117.       @original_move_route = @move_route
  118.       @original_move_route_index = @move_route_index
  119.     end
  120.     # 更改移动路线
  121.     @move_route = move_route
  122.     @move_route_index = 0
  123.     # 设置强制移动路线标志
  124.     @move_route_forcing = true
  125.     # 清除被锁定的向前朝向
  126.     @prelock_direction = 0
  127.     # 清除等待计数
  128.     @wait_count = 0
  129.     # 自定义移动
  130.     move_type_custom
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ● 可以通行判定
  134.   #     x : X 坐标
  135.   #     y : Y 坐标
  136.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  137.   #--------------------------------------------------------------------------
  138.   def passable?(x, y, d)
  139.     # 求得新的坐标
  140.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  141.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  142.     # 坐标在地图以外的情况
  143.     unless $game_map.valid?(new_x, new_y)
  144.       # 不能通行
  145.       return false
  146.     end
  147.     # 穿透是 ON 的情况下
  148.     if @through
  149.       # 可以通行
  150.       return true
  151.     end
  152.     # 移动者的元件无法来到指定方向的情况下
  153.     unless $game_map.passable?(x, y, d, self)
  154.       # 通行不可
  155.       return false
  156.     end
  157.     # 从指定方向不能进入到移动处的元件的情况下
  158.     unless $game_map.passable?(new_x, new_y, 10 - d)
  159.       # 不能通行
  160.       return false
  161.     end
  162.     # 循环全部事件
  163.     for event in $game_map.events.values
  164.       # 事件坐标于移动目标坐标一致的情况下
  165.       if event.x == new_x and event.y == new_y
  166.         # 穿透为 ON
  167.         unless event.through
  168.           # 自己就是事件的情况下
  169.           if self != $game_player
  170.             # 不能通行
  171.             return false
  172.           end
  173.           # 自己是主角、对方的图形是角色的情况下
  174.           if event.character_name != ""
  175.             # 不能通行
  176.             return false
  177.           end
  178.         end
  179.       end
  180.     end
  181.     # 主角的坐标与移动目标坐标一致的情况下
  182.     if $game_player.x == new_x and $game_player.y == new_y
  183.       # 穿透为 ON
  184.       unless $game_player.through
  185.         # 自己的图形是角色的情况下
  186.         if @character_name != ""
  187.           # 不能通行
  188.           return false
  189.         end
  190.       end
  191.     end
  192.     # 可以通行
  193.     return true
  194.   end
  195.   
  196.   #--------------------------------------------------------------------------
  197.   # ● 可以通行判定 (无视事件版)
  198.   #--------------------------------------------------------------------------
  199.   def passable_no_event?(x, y, d)
  200.     # 求得新的坐标
  201.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  202.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  203.     # 坐标在地图以外的情况
  204.     unless $game_map.valid?(new_x, new_y)
  205.       # 不能通行
  206.       return false
  207.     end
  208.     # 穿透是 ON 的情况下
  209.     if @through
  210.       # 可以通行
  211.       return true
  212.     end
  213.     # 移动者的元件无法来到指定方向的情况下
  214.     unless $game_map.passable?(x, y, d, self)
  215.       # 通行不可
  216.       return false
  217.     end
  218.     # 从指定方向不能进入到移动处的元件的情况下
  219.     unless $game_map.passable?(new_x, new_y, 10 - d)
  220.       # 不能通行
  221.       return false
  222.     end
  223.     # 循环全部事件
  224.     for event in $game_map.events.values
  225.       # 事件坐标于移动目标坐标一致的情况下
  226.       if event.x == new_x and event.y == new_y
  227.         # 穿透为 ON
  228.         unless event.through
  229.           # 自己就是事件的情况下
  230.           if self != $game_player
  231.             # 能通行
  232.             return  true
  233.           end
  234.           # 自己是主角、对方的图形是角色的情况下
  235.           if event.character_name != ""
  236.             # 能通行
  237.             return false
  238.           end
  239.         end
  240.       end
  241.     end
  242.     # 主角的坐标与移动目标坐标一致的情况下
  243.     if $game_player.x == new_x and $game_player.y == new_y
  244.       # 穿透为 ON
  245.       unless $game_player.through
  246.         # 自己的图形是角色的情况下
  247.         if @character_name != ""
  248.           # 不能通行
  249.           return false
  250.         end
  251.       end
  252.     end
  253.     # 可以通行
  254.     return true
  255.   end
  256.   
  257.   #--------------------------------------------------------------------------
  258.   # ● 锁定
  259.   #--------------------------------------------------------------------------
  260.   def lock
  261.     # 如果已经被锁定的情况下
  262.     if @locked
  263.       # 过程结束
  264.       return
  265.     end
  266.     # 保存锁定前的朝向
  267.     @prelock_direction = @direction
  268.     # 保存主角的朝向
  269.     turn_toward_player
  270.     # 设置锁定中标志
  271.     @locked = true
  272.   end
  273.   #--------------------------------------------------------------------------
  274.   # ● 锁定中判定
  275.   #--------------------------------------------------------------------------
  276.   def lock?
  277.     return @locked
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # ● 解除锁定
  281.   #--------------------------------------------------------------------------
  282.   def unlock
  283.     # 没有锁定的情况下
  284.     unless @locked
  285.       # 过程结束
  286.       return
  287.     end
  288.     # 清除锁定中标志
  289.     @locked = false
  290.     # 没有固定朝向的情况下
  291.     unless @direction_fix
  292.       # 如果保存了锁定前的方向
  293.       if @prelock_direction != 0
  294.         # 还原为锁定前的方向
  295.         @direction = @prelock_direction
  296.       end
  297.     end
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # ● 移动到指定位置
  301.   #     x : X 坐标
  302.   #     y : Y 坐标
  303.   #--------------------------------------------------------------------------
  304.   def moveto(x, y)
  305.     @x = x % $game_map.width
  306.     @y = y % $game_map.height
  307.     @real_x = @x * 128
  308.     @real_y = @y * 128
  309.     @prelock_direction = 0
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # ● 获取画面 X 坐标
  313.   #--------------------------------------------------------------------------
  314.   def screen_x
  315.     # 通过实际坐标和地图的显示位置来求得画面坐标
  316.     return (@real_x - $game_map.display_x + 3) / 4 + 16
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # ● 获取画面 Y 坐标
  320.   #--------------------------------------------------------------------------
  321.   def screen_y
  322.     # 通过实际坐标和地图的显示位置来求得画面坐标
  323.     y = (@real_y - $game_map.display_y + 3) / 4 + 32
  324.     # 取跳跃计数小的 Y 坐标
  325.     if @jump_count >= @jump_peak
  326.       n = @jump_count - @jump_peak
  327.     else
  328.       n = @jump_peak - @jump_count
  329.     end
  330.     return y - (@jump_peak * @jump_peak - n * n) / 2
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # ● 获取画面 Z 坐标
  334.   #     height : 角色的高度
  335.   #--------------------------------------------------------------------------
  336.   def screen_z(height = 0)
  337.     # 在最前显示的标志为 ON 的情况下
  338.     if @always_on_top
  339.       # 无条件设置为 999
  340.       return 999
  341.     end
  342.     # 通过实际坐标和地图的显示位置来求得画面坐标
  343.     z = (@real_y - $game_map.display_y + 3) / 4 + 32
  344.     # 元件的情况下
  345.     if @tile_id > 0
  346.       # 元件的优先不足 * 32
  347.       return z + $game_map.priorities[@tile_id] * 32
  348.     # 角色的场合
  349.     else
  350.       # 如果高度超过 32 就判定为满足 31
  351.       return z + ((height > 32) ? 31 : 0)
  352.     end
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # ● 取得繁茂
  356.   #--------------------------------------------------------------------------
  357.   def bush_depth
  358.     # 是元件、并且在最前显示为 ON 的情况下
  359.     if @tile_id > 0 or @always_on_top
  360.       return 0
  361.     end
  362.     # 在跳跃以外的状态时繁茂处元件的属性为 12,除此之外为 0
  363.     if @jump_count == 0 and $game_map.bush?(@x, @y)
  364.       return 12
  365.     else
  366.       return 0
  367.     end
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ● 取得地形标记
  371.   #--------------------------------------------------------------------------
  372.   def terrain_tag
  373.     return $game_map.terrain_tag(@x, @y)
  374.   end
  375. end
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部