Project1

标题: [脚本]纵向行走图战斗 - 显示敌人状态和技能动画 [打印本页]

作者: swbsl    时间: 2024-10-21 15:17
标题: [脚本]纵向行走图战斗 - 显示敌人状态和技能动画
原生纵版战斗的功能扩展,添加了更换装备的指令,显示玩家角色行走图,显示双方的状态图标和技能动画。(整理队伍功能需其它脚本插件支持)
RUBY 代码复制
  1. module Vocab
  2.   BattleParty = "队伍"
  3. end
  4.  
  5. class Scene_Equip < Scene_Base
  6.   #--------------------------------------------------------------------------
  7.   # * 战斗时更换装备,返回战斗场景
  8.   #--------------------------------------------------------------------------
  9.   def return_scene
  10.     if $game_temp.in_battle
  11.       $scene = Scene_Battle.new
  12.     else
  13.       $scene = Scene_Menu.new(2)
  14.     end
  15.   end
  16. end  
  17.  
  18. class Window_BattleMessage < Window_Message
  19. #  设置战斗信息显示的最大行数
  20.   MAX_LINE = 4
  21.   #--------------------------------------------------------------------------
  22.   # * 战斗信息窗口 初始化
  23.   #--------------------------------------------------------------------------
  24.   def initialize
  25.     super
  26.     self.openness = 255    # 设置窗口可见性
  27.     self.back_opacity = 0  # 设置窗口不透明度
  28.     @lines = []
  29.     self.x = -10
  30.     self.y = 112
  31.     self.width = 566
  32.     self.height =400
  33.     refresh
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # * 绘制战斗信息     index : Line number
  37.   #--------------------------------------------------------------------------
  38.   def draw_line(index)
  39.     rect = Rect.new(4, index * WLH, contents.width - 4, WLH)
  40.     self.contents.font.color = normal_color
  41.     self.contents.draw_text(rect, @lines[index])
  42.   end
  43.   #--------------------------------------------------------------------------
  44.   # * 刷新信息显示
  45.   #--------------------------------------------------------------------------
  46.   def refresh
  47.     self.contents.clear
  48.     for i in 0...@lines.size
  49.       draw_line(i)
  50.     end
  51.   end
  52. end
  53.  
  54. class Window_TargetEnemy < Window_Base
  55.   #--------------------------------------------------------------------------
  56.   # * 初始化 敌人选择光标窗口
  57.   #--------------------------------------------------------------------------
  58.   def initialize
  59.     super(0, 0, 80, 80)
  60.     self.back_opacity = 75  # 设置窗口不透明度
  61.     self.opacity = 255       # 设置窗口内容不透明
  62.     @alive_enemies = get_alive_enemies
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * 获取活着的敌人实例
  66.   #--------------------------------------------------------------------------
  67.   def get_alive_enemies
  68.     alive_enemies = []
  69.     $game_troop.members.each do |enemy|
  70.       alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
  71.     end
  72.     alive_enemies
  73.   end   
  74.   #--------------------------------------------------------------------------  
  75.   # * 获取并绘制敌人的状态图标
  76.   #--------------------------------------------------------------------------
  77.   def draw_enemy_state(ememy_index)
  78.     self.contents.clear
  79.     count = 0
  80.     x = 0
  81.     y = 0
  82.     for state in @alive_enemies[ememy_index].states
  83.       draw_icon(state.icon_index, x, y)
  84.       count +=1
  85.       if count == 2
  86.         x = 0
  87.         y += 24
  88.         count = 0
  89.       else
  90.         x += 24
  91.       end  
  92.     end
  93.   end
  94. end
  95.  
  96. class Window_TurnCount < Window_Command   # 自定义类,用于实现战斗回合的显示 #
  97.   #--------------------------------------------------------------------------
  98.   # * 回合显示窗口 初始化
  99.   #--------------------------------------------------------------------------
  100.   def initialize
  101.     s1 = $game_troop.turn_count + 1
  102.     s2 = "回合"
  103.     super(128,[s1, s2], 2, 1)
  104.     draw_item(0, true)
  105.     draw_item(1, true)
  106.   end
  107. end
  108.  
  109. class Window_BattleStatus < Window_Selectable
  110.   #--------------------------------------------------------------------------
  111.   # * 角色状态窗口 初始化
  112.   #--------------------------------------------------------------------------
  113.   def initialize
  114.     super(126, -10, 420, 128, spacing = 0)
  115.     refresh
  116.     self.active = false
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * 绘制角色状态窗口的项目
  120.   #--------------------------------------------------------------------------
  121.   def draw_item(index)
  122.     rect = item_rect(index)
  123.     rect.x += 4
  124.     rect.width -= 8
  125.     self.contents.clear_rect(rect)
  126.     self.contents.font.color = normal_color
  127.     actor = $game_party.members[index]
  128.     draw_actor_name(actor, 4, rect.y)
  129.     draw_actor_state(actor, 80, rect.y, 120)
  130.     draw_actor_hp(actor, 210, rect.y, 90)
  131.     draw_actor_mp(actor, 310, rect.y, 70)
  132.   end
  133. end
  134.  
  135. class Window_ActorCommand < Window_Command
  136.   #--------------------------------------------------------------------------
  137.   # * 角色指令菜单窗口 初始化
  138.   #--------------------------------------------------------------------------
  139.   def initialize
  140.     super(128, [], 2, 2)
  141.     self.active = false
  142.   end
  143. end
  144.  
  145. class Window_PartyCommand < Window_Command
  146.   #--------------------------------------------------------------------------
  147.   # * 战斗初始指令窗口 初始化 (只有第一回合可管理队伍)
  148.   #--------------------------------------------------------------------------
  149.   def initialize
  150.     s1 = Vocab::fight
  151.     s2 = Vocab::equip
  152.     s3 = Vocab::BattleParty
  153.     s4 = Vocab::escape
  154.     super(128, [s1, s2, s3, s4], 2, 2)
  155.     draw_item(0, true)
  156.     draw_item(1, true)
  157.     if $game_troop.turn_count == 0
  158.       draw_item(2, true)
  159.     else
  160.       draw_item(2, false)
  161.     end  
  162.     draw_item(3, $game_troop.can_escape)
  163.     self.active = false
  164.   end
  165. end
  166.  
  167. class Scene_Battle < Scene_Base
  168. # 定义实例变量用于全局调用  
  169.   attr_accessor :draw_count
  170.   #--------------------------------------------------------------------------
  171.   # * 战斗场景开始处理
  172.   #--------------------------------------------------------------------------
  173.   def start
  174.     super
  175.     @draw_count = 0  # 绘制行走图的切换开关  
  176.     $game_temp.in_battle = true
  177.     @spriteset = Spriteset_Battle.new
  178.     @message_window = Window_BattleMessage.new
  179.     @action_battlers = []
  180.     create_info_viewport
  181.   end  
  182.   #--------------------------------------------------------------------------
  183.   # * 更新
  184.   #--------------------------------------------------------------------------
  185.   def update
  186.     super
  187.     update_basic(true)
  188.     update_info_viewport                  # 更新信息视窗
  189.     @turnCount_window.visible = true
  190.     if $game_message.visible
  191.       @info_viewport.visible = false
  192.       @status_window.visible = true
  193.       @status_window.refresh
  194.       @message_window.visible = true
  195.     end
  196.     unless $game_message.visible          # 消息显示的情况之外
  197.     draw_actor_character                  # 绘制行走图
  198.     @draw_count += 1
  199.       return if judge_win_loss            # 确定输赢结果
  200.       update_scene_change
  201.       if @target_enemy_window != nil
  202.         update_target_enemy_selection     # 选择目标敌人
  203.       elsif @target_actor_window != nil
  204.         update_target_actor_selection     # 选择目标角色
  205.       elsif @skill_window != nil      
  206.         update_skill_selection            # 选择技能
  207.       elsif @item_window != nil      
  208.         update_item_selection             # 选择道具
  209.       elsif @party_command_window.active
  210.         update_party_command_selection    # 战斗初始指令窗口
  211.       elsif @status_window.active     
  212.         update_actor_selection            # 角色更换装备需要进行角色选择
  213.       elsif @actor_command_window.active     
  214.         update_actor_command_selection    # 选择角色窗口
  215.       else
  216.         process_battle_event              # 战斗事件处理
  217.         process_action                    # 战斗动作
  218.         @status_window.refresh            # 刷新角色状态信息
  219.         process_battle_event              # 战斗事件处理
  220.       end
  221.     end
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * 创建信息显示视窗
  225.   #--------------------------------------------------------------------------
  226.   def create_info_viewport
  227.     @info_viewport = Viewport.new(0, 0, 544, 128)  # 0,288, 544, 128
  228.     @info_viewport.z = 100
  229.     @status_window = Window_BattleStatus.new  
  230.     @party_command_window = Window_PartyCommand.new
  231.     @party_command_window.x = 0
  232.     @party_command_window.y = 38
  233.     @actor_command_window = Window_ActorCommand.new
  234.     @actor_command_window.x = 0
  235.     @actor_command_window.y = 38
  236.     @turnCount_window = Window_TurnCount.new
  237.     @turnCount_window.x = 0
  238.     @turnCount_window.y = -10
  239.     @actor_character_window = Window_Base.new(-10, -10, 566, 600)
  240.     @actor_character_window.back_opacity = 0
  241.     @actor_character_window.visible = true
  242.     draw_character_1
  243.     @actor_command_window.visible = false
  244.     @party_command_window.visible = false
  245.     @turnCount_window.visible = false
  246.     @status_window.visible = false
  247.     @info_viewport.visible = false
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # * 绘制玩家角色行走图
  251.   #--------------------------------------------------------------------------
  252.   def draw_actor_character
  253.     if @draw_count == 20
  254.       draw_character_1
  255.       @actor_character_window.update
  256.     elsif @draw_count == 40
  257.       draw_character_2
  258.       @draw_count = 0
  259.       @actor_character_window.update
  260.     else
  261.       @actor_character_window.update
  262.     end
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * 行走图 - 动作1
  266.   #--------------------------------------------------------------------------
  267.   def draw_character_1
  268.     @actor_character_window.contents.clear   
  269.     x_coordinate = 120
  270.     for actor in $game_party.members
  271.       @actor_character_window.draw_character_turnU(actor.character_name, actor.character_index, x_coordinate, 380) if $game_party.members.size == 4
  272.       @actor_character_window.draw_character_turnU(actor.character_name, actor.character_index, x_coordinate + 50, 380) if $game_party.members.size == 3
  273.       @actor_character_window.draw_character_turnU(actor.character_name, actor.character_index, x_coordinate + 90, 380) if $game_party.members.size == 2
  274.       @actor_character_window.draw_character_turnU(actor.character_name, actor.character_index, x_coordinate + 150, 380) if $game_party.members.size == 1
  275.       x_coordinate += 100
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * 行走图 - 动作2
  280.   #--------------------------------------------------------------------------
  281.   def draw_character_2
  282.     @actor_character_window.contents.clear
  283.     x_coordinate = 120
  284.     for actor in $game_party.members
  285.       @actor_character_window.draw_character_turnU2(actor.character_name, actor.character_index, x_coordinate, 380) if $game_party.members.size == 4
  286.       @actor_character_window.draw_character_turnU2(actor.character_name, actor.character_index, x_coordinate + 50, 380) if $game_party.members.size == 3
  287.       @actor_character_window.draw_character_turnU2(actor.character_name, actor.character_index, x_coordinate + 90, 380) if $game_party.members.size == 2
  288.       @actor_character_window.draw_character_turnU2(actor.character_name, actor.character_index, x_coordinate + 150, 380) if $game_party.members.size == 1
  289.       x_coordinate += 100
  290.     end
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # * 逃跑动作1
  294.   #--------------------------------------------------------------------------
  295.   def draw_runaway_1
  296.     @actor_character_window.contents.clear
  297.     x_coordinate = 120
  298.     for actor in $game_party.members
  299.       @actor_character_window.draw_character_turnD(actor.character_name, actor.character_index, x_coordinate, 380) if $game_party.members.size == 4
  300.       @actor_character_window.draw_character_turnD(actor.character_name, actor.character_index, x_coordinate + 50, 380) if $game_party.members.size == 3
  301.       @actor_character_window.draw_character_turnD(actor.character_name, actor.character_index, x_coordinate + 90, 380) if $game_party.members.size == 2
  302.       @actor_character_window.draw_character_turnD(actor.character_name, actor.character_index, x_coordinate + 150, 380) if $game_party.members.size == 1
  303.       x_coordinate += 100
  304.     end
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * 逃跑动作2
  308.   #--------------------------------------------------------------------------
  309.   def draw_runaway_2
  310.     @actor_character_window.contents.clear   
  311.     x_coordinate = 120
  312.     for actor in $game_party.members
  313.       @actor_character_window.draw_character_turnD2(actor.character_name, actor.character_index, x_coordinate, 380) if $game_party.members.size == 4
  314.       @actor_character_window.draw_character_turnD2(actor.character_name, actor.character_index, x_coordinate + 50, 380) if $game_party.members.size == 3
  315.       @actor_character_window.draw_character_turnD2(actor.character_name, actor.character_index, x_coordinate + 90, 380) if $game_party.members.size == 2
  316.       @actor_character_window.draw_character_turnD2(actor.character_name, actor.character_index, x_coordinate + 150, 380) if $game_party.members.size == 1
  317.       x_coordinate += 100
  318.     end
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # * 执行角色逃跑动作 (搁置)
  322.   #--------------------------------------------------------------------------
  323.   def set_runaway
  324.     count = 0
  325.     if  #  判断条件
  326.       loop do
  327.         if count == 0
  328.           draw_runaway_1
  329.           @actor_character_window.update
  330.         elsif count == 10
  331.           draw_runaway_2
  332.           count = 0
  333.           @actor_character_window.update
  334.         else
  335.           @actor_character_window.update
  336.         end
  337.         count += 1
  338.       end
  339.     end
  340.   end  
  341.   #--------------------------------------------------------------------------
  342.   # *处置(关闭)信息显示视口
  343.   #--------------------------------------------------------------------------
  344.   def dispose_info_viewport
  345.     @status_window.dispose
  346.     @party_command_window.dispose
  347.     @actor_command_window.dispose
  348.     @info_viewport.dispose
  349.     @turnCount_window.dispose
  350.     @actor_character_window.dispose
  351.   end  
  352.   #--------------------------------------------------------------------------
  353.   # *更新信息显示视口
  354.   #--------------------------------------------------------------------------
  355.   def update_info_viewport
  356.     @turnCount_window.active = false
  357.     draw_actor_character                  # 绘制行走图
  358.     @draw_count += 1
  359.     @actor_command_window.update
  360.     @status_window.update
  361.     @turnCount_window.update
  362.     @party_command_window.update  
  363.     if @party_command_window.active   
  364.       @party_command_window.visible = true
  365.       @status_window.visible = true
  366.       @actor_command_window.visible = false
  367.     elsif @actor_command_window.active
  368.       @actor_command_window.visible = true
  369.       @party_command_window.visible = false
  370.     end
  371.   end  
  372.   #--------------------------------------------------------------------------
  373.   # * 开始窗口列表選擇指令
  374.   #--------------------------------------------------------------------------
  375.   def start_party_command_selection
  376.     if $game_temp.in_battle
  377.       @status_window.refresh
  378.       @status_window.index = @actor_index = -1
  379.       @active_battler = nil
  380.       @info_viewport.visible = true
  381.       @message_window.visible = false
  382.       @party_command_window.active = true
  383.       @party_command_window.index = 0
  384.       @actor_command_window.active = false
  385.       $game_party.clear_actions
  386.       if $game_troop.surprise or not $game_party.inputable?
  387.         start_main
  388.       end
  389.     end
  390.   end  
  391.   #--------------------------------------------------------------------------
  392.   # * 更新战斗初始選擇指令 (只有第一回合可管理队伍)
  393.   #--------------------------------------------------------------------------
  394.   def update_party_command_selection
  395.     if $game_troop.turn_count == 0
  396.       new_party_command_selection
  397.     else
  398.       old_party_command_selection
  399.     end
  400.   end
  401.   #--------------------------------------------------------------------------
  402.   # * 战斗初始選擇指令 - 不能管理队伍
  403.   #--------------------------------------------------------------------------
  404.   def old_party_command_selection
  405.     if Input.trigger?(Input::B)
  406.       Sound.play_cancel
  407.       end_actor_selection
  408.     elsif Input.trigger?(Input::C)
  409.       case @party_command_window.index
  410.       when 0
  411.         Sound.play_decision
  412.         @status_window.index = @actor_index = -1
  413.         next_actor
  414.       when 1
  415.         start_actor_selection
  416.       when 2
  417.         Sound.play_buzzer
  418.         return
  419.       when 3
  420.         if $game_troop.can_escape == false
  421.           Sound.play_buzzer
  422.           return
  423.         end
  424.         Sound.play_decision
  425.         process_escape
  426.       end
  427.     end
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # * 战斗初始選擇指令 - 可以管理队伍
  431.   #--------------------------------------------------------------------------
  432.   def new_party_command_selection
  433.     if Input.trigger?(Input::B)
  434.       Sound.play_cancel
  435.       end_actor_selection
  436.     elsif Input.trigger?(Input::C)
  437.       case @party_command_window.index
  438.       when 0
  439.         Sound.play_decision
  440.         @status_window.index = @actor_index = -1
  441.         next_actor
  442.       when 1
  443.         start_actor_selection
  444.       when 2
  445.         party_manage
  446.       when 3
  447.         if $game_troop.can_escape == false
  448.           Sound.play_buzzer
  449.           return
  450.         end
  451.         Sound.play_decision
  452.         process_escape
  453.       end
  454.     end
  455.   end  
  456.   #--------------------------------------------------------------------------
  457.   # * 更改装备 - 开始选择角色
  458.   #--------------------------------------------------------------------------
  459.   def start_actor_selection
  460.     @party_command_window.active = false
  461.     @status_window.active = true
  462.     if $game_party.last_actor_index < @status_window.item_max
  463.       @status_window.index = $game_party.last_actor_index
  464.     else
  465.       @status_window.index = 0
  466.     end
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # * 更改装备 - 角色选择结束
  470.   #--------------------------------------------------------------------------
  471.   def end_actor_selection
  472.     @party_command_window.active = true
  473.     @status_window.active = false
  474.     @status_window.index = -1
  475.   end
  476.   #--------------------------------------------------------------------------
  477.   # * 更改装备 - 更新角色选择指令
  478.   #--------------------------------------------------------------------------
  479.   def update_actor_selection
  480.     if Input.trigger?(Input::B)
  481.       Sound.play_cancel
  482.       end_actor_selection
  483.     elsif Input.trigger?(Input::C)
  484.       $game_party.last_actor_index = @status_window.index
  485.       Sound.play_decision
  486.       $scene = Scene_Equip.new(@status_window.index)
  487.     end
  488.   end
  489.   #--------------------------------------------------------------------------
  490.   # * 开始道具选择 (创建道具窗口和帮助窗口)
  491.   #--------------------------------------------------------------------------
  492.   def start_item_selection
  493.     @help_window = Window_Help.new
  494.     @help_window.y = 238
  495.     @help_window.back_opacity = 180
  496.     @item_window = Window_Item.new(0, 288, 544, 130)
  497.     @item_window.back_opacity = 180
  498.     @item_window.help_window = @help_window
  499.     @actor_command_window.active = false
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # * 开始技能选择 (创建技能窗口和帮助窗口)
  503.   #--------------------------------------------------------------------------
  504.   def start_skill_selection
  505.     @help_window = Window_Help.new
  506.     @help_window.y = 238
  507.     @help_window.back_opacity = 180
  508.     @skill_window = Window_Skill.new(0, 288, 544, 130, @active_battler)
  509.     @skill_window.back_opacity = 180
  510.     @skill_window.help_window = @help_window
  511.     @actor_command_window.active = false
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # * 调整队伍 (调用PartyRoster类的方法)
  515.   #--------------------------------------------------------------------------
  516.   def party_manage
  517.  
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # * 开始目标角色选择 (使用道具或技能时,选择玩家角色的窗口)
  521.   #--------------------------------------------------------------------------
  522.   def start_target_actor_selection
  523.     @target_actor_window =  Window_BattleStatus.new
  524.     @info_viewport.rect.x += @target_actor_window.width
  525.     @info_viewport.ox += @target_actor_window.width
  526.     @actor_command_window.active = false
  527.     @target_actor_window.active = true
  528.     if $game_party.last_actor_index < @target_actor_window.item_max
  529.       @target_actor_window.index = $game_party.last_actor_index
  530.     else
  531.       @target_actor_window.index = 0
  532.     end   
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # *更新目标角色选择
  536.   #--------------------------------------------------------------------------
  537.   def update_target_actor_selection
  538.     @target_actor_window.update
  539.     if Input.trigger?(Input::B)
  540.       Sound.play_cancel
  541.       end_target_actor_selection
  542.     elsif Input.trigger?(Input::C)
  543.       Sound.play_decision
  544.       @active_battler.action.target_index = @target_actor_window.index
  545.       end_target_actor_selection
  546.       end_skill_selection
  547.       end_item_selection
  548.       next_actor
  549.     end
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * 结束目标角色选择
  553.   #--------------------------------------------------------------------------
  554.   def end_target_actor_selection
  555.     @info_viewport.rect.x -= @target_actor_window.width
  556.     @info_viewport.ox -= @target_actor_window.width
  557.     @target_actor_window.dispose
  558.     @target_actor_window = nil
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # * 开始目标敌人选择 - 创建选择敌人指令光标
  562.   #--------------------------------------------------------------------------
  563.   def start_target_enemy_selection
  564.     @target_enemy_window = Window_TargetEnemy.new
  565.     @target_enemy_index = 0                  # 初始化选择的敌人索引
  566.     @info_viewport.rect.x += @target_enemy_window.width
  567.     @info_viewport.ox += @target_enemy_window.width
  568.     @actor_command_window.active = false   
  569.     @target_enemies = get_alive_enemies # 获取活着的敌人
  570.     update_enemy_cursor   # 更新光标位置
  571.   end
  572.   #--------------------------------------------------------------------------
  573.   # * 获取活着的敌人实例
  574.   #--------------------------------------------------------------------------
  575.   def get_alive_enemies
  576.     alive_enemies = []
  577.     $game_troop.members.each do |enemy|
  578.       alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
  579.     end
  580.     alive_enemies
  581.   end   
  582.   #--------------------------------------------------------------------------
  583.   # * 更新目标敌人选择
  584.   #--------------------------------------------------------------------------
  585.   def update_target_enemy_selection
  586.     if Input.trigger?(Input::B)
  587.       Sound.play_cancel
  588.        @enemy_name.visible = false
  589.       end_target_enemy_selection
  590.     elsif Input.trigger?(Input::C)
  591.       Sound.play_decision
  592.       select_enemy(@target_enemies[@target_enemy_index]) if @target_enemies
  593.  
  594.       end_target_enemy_selection
  595.       end_skill_selection
  596.       end_item_selection
  597.       next_actor
  598.     elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
  599.       @target_enemy_index = (@target_enemy_index + 1) % @target_enemies.size if @target_enemies
  600.       @enemy_name.visible = false
  601.       update_enemy_cursor
  602.     elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
  603.       @target_enemy_index = (@target_enemy_index - 1 + @target_enemies.size) % @target_enemies.size if @target_enemies
  604.       @enemy_name.visible = false
  605.       update_enemy_cursor
  606.     end
  607.   end
  608.   #--------------------------------------------------------------------------
  609.   # * 更新敌人光标的位置和名称窗口
  610.   #--------------------------------------------------------------------------
  611.   def update_enemy_cursor
  612.     return unless @target_enemies && @target_enemies[@target_enemy_index] # 确保数组存在且有元素
  613.     enemy = @target_enemies[@target_enemy_index]  # 获取当前选中的敌人
  614.     @target_enemy_window.x = enemy.screen_x - 37 # 更新光标位置到敌人的坐标
  615.     @target_enemy_window.y = enemy.screen_y - 70
  616.     ememy = get_alive_enemies
  617.     @target_enemy_window.draw_enemy_state(@target_enemy_index) # 在光标窗口内部显示敌人状态图标
  618.     @target_enemy_window.visible = true # 确保光标窗口可见
  619.   # 创建敌人名称显示窗口
  620.     @enemy_name = Window_Base.new(@target_enemy_window.x - 40, @target_enemy_window.y + 78, 160, 50)
  621.     @enemy_name.back_opacity = 255
  622.     @enemy_name.opacity = 255
  623.     @enemy_name.contents.clear
  624.     @enemy_name.contents.draw_text(0, 0, enemy.name.length * 22, 22, enemy.name)   
  625.     @enemy_name.visible = true  # 确保敌人名称可见
  626.   end
  627.   #--------------------------------------------------------------------------
  628.   # * 光标选定敌人
  629.   #--------------------------------------------------------------------------
  630.   def select_enemy(enemy)
  631.     @active_battler.action.target_index = enemy.index if enemy
  632.   end  
  633.   #--------------------------------------------------------------------------
  634.   # * 结束目标敌人选择
  635.   #--------------------------------------------------------------------------
  636.   def end_target_enemy_selection
  637.     @info_viewport.rect.x -= @target_enemy_window.width
  638.     @info_viewport.ox -= @target_enemy_window.width
  639.     @target_enemy_window.dispose
  640.     @target_enemy_window = nil
  641.     @enemy_name.dispose
  642.     @enemy_name = nil
  643.     @actor_command_window.active = true if @actor_command_window.index == 0
  644.   end
  645.   #--------------------------------------------------------------------------
  646.   # * 回合结束    重新创建回合显示窗口和作战指令窗口
  647.   #--------------------------------------------------------------------------
  648.   def turn_end
  649.     $game_troop.turn_ending = true
  650.     $game_party.slip_damage_effect
  651.     $game_troop.slip_damage_effect
  652.     $game_party.do_auto_recovery
  653.     $game_troop.preemptive = false
  654.     $game_troop.surprise = false
  655.     process_battle_event
  656.     $game_troop.turn_ending = false
  657.     @turnCount_window.dispose
  658.     @turnCount_window = Window_TurnCount.new
  659.     @turnCount_window.x = 0
  660.     @turnCount_window.y = -10
  661.     @party_command_window.dispose
  662.     @party_command_window = Window_PartyCommand.new
  663.     @party_command_window.x = 0
  664.     @party_command_window.y = 38
  665.     start_party_command_selection
  666.     draw_actor_character                  # 绘制行走图
  667.     @draw_count += 1
  668.   end
  669.   #--------------------------------------------------------------------------
  670.   # * 开始逃跑       添加“逃跑成功”字样显示
  671.   #--------------------------------------------------------------------------
  672.   def process_escape
  673. #    set_runaway    # 执行角色逃跑动作
  674.     @info_viewport.visible = false
  675.     @message_window.visible = true
  676.     text = sprintf(Vocab::EscapeStart, $game_party.name)
  677.     $game_message.texts.push(text)
  678.     if $game_troop.preemptive
  679.       success = true
  680.     else
  681.       success = (rand(100) < @escape_ratio)
  682.     end
  683.     Sound.play_escape
  684.     if success
  685.       wait_for_message
  686.       $game_message.texts.push("成功的逃脱了。")
  687.       wait_for_message
  688.       battle_end(1)
  689.     else
  690.       @escape_ratio += 10
  691.       $game_message.texts.push('\.' + Vocab::EscapeFailure)
  692.       wait_for_message
  693.       $game_party.clear_actions
  694.       start_main
  695.     end
  696.   end
  697.   #--------------------------------------------------------------------------
  698.   # * 战斗事件处理
  699.   #--------------------------------------------------------------------------
  700.   def process_battle_event
  701.     loop do
  702.       draw_actor_character  # 绘制角色行走图
  703.       @draw_count += 1
  704.       @status_window.refresh            # 刷新角色状态信息
  705.       return if judge_win_loss
  706.       return if $game_temp.next_scene != nil
  707.       $game_troop.interpreter.update
  708.       $game_troop.setup_battle_event
  709.       wait_for_message
  710.       process_action if $game_troop.forcing_battler != nil
  711.       return unless $game_troop.interpreter.running?
  712.       update_basic
  713.     end
  714.   end
  715.   #--------------------------------------------------------------------------
  716.   # * 顯示動畫
  717.   #     targets      : 顯示位置(目标对象实例)
  718.   #     animation_id : 動畫編號(如果為-1則播放普通攻擊動畫)
  719.   #--------------------------------------------------------------------------
  720.   def display_animation(targets, animation_id)
  721.     if animation_id < 0
  722.       display_attack_animation(targets)
  723.     else
  724.       display_normal_animation(targets, animation_id)
  725.     end
  726.     wait(20)
  727.     wait_for_animation
  728.   end
  729.   #--------------------------------------------------------------------------
  730.   # * 顯示攻擊動畫
  731.   #     targets : 顯示位置(目标对象实例)
  732.   #    如果是敵人,只播放[敵人攻擊]聲效,然後等待一陣子。
  733.   #    如果是主角則同時考慮到貳刀流主角的情況(左手動畫水準翻轉顯示)
  734.   #--------------------------------------------------------------------------
  735.   def display_attack_animation(targets)
  736.     if @active_battler.is_a?(Game_Enemy)
  737.       Sound.play_enemy_attack
  738.       display_normal_animation(targets, 1, false)   
  739.       wait(15, true)
  740.     else
  741.       aid1 = @active_battler.atk_animation_id
  742.       aid2 = @active_battler.atk_animation_id2
  743.       display_normal_animation(targets, aid1, false)
  744.       display_normal_animation(targets, aid2, true)
  745.     end
  746.     wait_for_animation
  747.   end
  748.   #--------------------------------------------------------------------------
  749.   # * 顯示普通動畫
  750.   #     targets      : 顯示位置(目标对象实例)
  751.   #     animation_id : 動畫編號
  752.   #     mirror       : 水準翻轉
  753.   #--------------------------------------------------------------------------
  754.   def display_normal_animation(targets, animation_id, mirror = false)
  755.     animation = $data_animations[animation_id]
  756.     if animation != nil
  757.       to_screen = (animation.position == 2)       # (0:头部,1:中心,2:脚部,3:全屏)
  758.       for target in targets.uniq
  759.         target.animation_id = animation_id
  760.         target.animation_mirror = mirror
  761.         wait(20, true) unless to_screen           # 如果是單體動畫,等待
  762.       end
  763.       wait(20, true) if to_screen                 # 如果是全體動畫,等待
  764.     end
  765.   end
  766. end
  767.  
  768. #==============================================================================
  769. #                 在窗口中绘制不同身体朝向的角色行走图
  770. # 调用方法·例: @xxxx_window.draw_character(character_name, character_index, x, y)
  771. #==============================================================================
  772. class Window_Base < Window
  773. # 定义原有方法绘制行走图朝向的常量 (0-下,1-左,2-右,3-上)
  774.   TURN = 0  
  775.   #--------------------------------------------------------------------------
  776.   # * 绘制角色图像   (原有方法,绘制的行走图身体朝下)
  777.   #     character_name  : 角色图像文件名
  778.   #     character_index : 角色图像索引
  779.   #     x     : 绘制点 x-坐标
  780.   #     y     : 绘制点 y-坐标
  781.   #--------------------------------------------------------------------------
  782.   def draw_character(character_name, character_index, x, y)
  783.     if character_name == nil          # 检测角色位图是否为空
  784.       character_name = "!Coffin"
  785.       character_index = 0
  786.     end  
  787.     bitmap = Cache.character(character_name)  # 从游戏的缓存中获取角色的位图
  788.     sign = character_name[/^[\!\$]./]# 使用正则表达式来匹配角色名称的第一个字符,如果匹配成功,sign 变量将存储该字符。   
  789.     if sign != nil and sign.include?('$') # 检查 sign 变量是否不为 nil 并且包含字符 $。
  790.       cw = bitmap.width / 3   # 半身头像位图的宽度
  791.       ch = bitmap.height / 4  # 半身头像位图的高度
  792.     else
  793.       cw = bitmap.width / 12  # 行走图宽度
  794.       ch = bitmap.height / 8  # 行走图高度
  795.     end
  796.     n = character_index       # 存储角色位图索引
  797. # x 坐标是根据图像索引和每行的图像数量(对于全身图像通常是 4 个)计算的,y 坐标是根据图像索引除以每行的图像数量计算的。cw 和 ch 是源区域的宽度和高度。
  798.     src_rect = Rect.new((n%4*3+1)*cw, (n/4*4+TURN)*ch, cw, ch)   #  通过Rect定义位图绘制区域
  799. # blt 是 Bitmap 类的方法,将源位图(bitmap)中的一个区域(由 src_rect 定义)绘制到窗口内容位图(self.contents)上的指定位置(由 x 和 y 坐标定义)
  800. # x - cw / 2 和 y - ch 是目标位置的坐标,它们确保角色图像居中绘制在指定的 x 和 y 坐标上。
  801.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) # 执行实际的绘制操作
  802.   end
  803.   #--------------------------------------------------------------------------
  804.   # * 绘制角色行走图 - 朝下-动作1
  805.   #--------------------------------------------------------------------------  
  806.   def draw_character_turnD(character_name, character_index, x, y)
  807.     if character_name == nil
  808.       character_name = "!Coffin"
  809.       character_index = 0
  810.     end  
  811.     bitmap = Cache.character(character_name)
  812.     sign = character_name[/^[\!\$]./]
  813.     if sign != nil
  814.       cw = bitmap.width / 12
  815.       ch = bitmap.height / 8
  816.     end
  817.     n = character_index
  818.     src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  819.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  820.   end   
  821.   #--------------------------------------------------------------------------
  822.   # * 绘制角色行走图 - 朝下-动作2
  823.   #--------------------------------------------------------------------------  
  824.   def draw_character_turnD2(character_name, character_index, x, y)
  825.     if character_name == nil
  826.       character_name = "!Coffin"
  827.       character_index = 0
  828.     end  
  829.     bitmap = Cache.character(character_name)
  830.     sign = character_name[/^[\!\$]./]
  831.     if sign != nil
  832.       cw = bitmap.width / 12
  833.       ch = bitmap.height / 8
  834.     end
  835.     n = character_index
  836.     src_rect = Rect.new((n%4*3+2)*cw, (n/4*4)*ch, cw, ch)
  837.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  838.   end   
  839.   #--------------------------------------------------------------------------
  840.   # * 绘制角色行走图 - 朝上-动作1
  841.   #--------------------------------------------------------------------------  
  842.   def draw_character_turnU(character_name, character_index, x, y)
  843.     if character_name == nil
  844.       character_name = "!Coffin"
  845.       character_index = 0
  846.     else
  847.       bitmap = Cache.character(character_name)
  848.       sign = character_name[/^[\!\$]./]
  849.       if sign != nil
  850.         cw = bitmap.width / 12
  851.         ch = bitmap.height / 8
  852.       end
  853.       n = character_index
  854.       src_rect = Rect.new((n%4*3+1)*cw, (n/4*4+3)*ch, cw, ch)
  855.       self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  856.     end  
  857.   end
  858.   #--------------------------------------------------------------------------
  859.   # * 绘制角色行走图 - 朝上-动作2
  860.   #--------------------------------------------------------------------------  
  861.   def draw_character_turnU2(character_name, character_index, x, y)
  862.     if character_name == nil
  863.       character_name = "!Coffin"
  864.       character_index = 0
  865.     else
  866.       bitmap = Cache.character(character_name)
  867.       sign = character_name[/^[\!\$]./]
  868.       if sign != nil
  869.         cw = bitmap.width / 12
  870.         ch = bitmap.height / 8
  871.       end
  872.       n = character_index
  873.       src_rect = Rect.new((n%4*3+2)*cw, (n/4*4+3)*ch, cw, ch)
  874.       self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  875.     end
  876.   end
  877. end  
  878. #------------------人物死亡时改变角色的行走图-----------------------------#
  879. #                                                                         #
  880. #       行走图文件路径:[游戏目录]\Graphics\Characters\!Coffin.png        #
  881. #-------------------------------------------------------------------------#
  882. class Game_Interpreter
  883. #--------------------------------------------------------------------------
  884. # * 角色状态变更   @params[2]:状态编号。
  885. #                  @params[0]:角色 ID,如果是 0,则表示对所有角色执行此命令。
  886. #                  @params[1]:状态 ID,如果是 0,则表示添加状态,如果是 1,则表示移除状态。            
  887. #--------------------------------------------------------------------------
  888.   def command_313
  889.     iterate_actor_id(@params[0]) do |actor|  # 遍历指定的角色,并执行给定的代码块
  890.       if @params[1] == 0                     # 如果 @params[1] 是 0,
  891.         actor.add_state(@params[2])          # 那么它将调用 add_state 方法来添加状态
  892.         actor.set_death_graphic if @params[2] == 1  #  如果添加的角色状态是1(死亡),调用game_actor的方法变更死亡行走图
  893.         actor.perform_collapse
  894.       else                                 #  如果是 1,
  895.         actor.remove_state(@params[2])     # 移除角色状态
  896.         actor.set_normal_graphic if @params[2] == 1  # 如果移除的角色状态是1(死亡),调用game_actor的方法变更正常行走图
  897.       end
  898.     end
  899.     return true
  900.   end
  901. #--------------------------------------------------------------------------
  902. # * 全部恢复   
  903. #--------------------------------------------------------------------------
  904.   def command_314
  905.     iterate_actor_id(@params[0]) do |actor|
  906.       actor.recover_all
  907.       actor.set_normal_graphic              # 调用game_actor的方法变更正常行走图
  908.     end
  909.     return true
  910.   end
  911. end
  912. #--------------------------------------------------------------------------
  913. class Game_Actor < Game_Battler
  914.   #--------------------------------------------------------------------------
  915.   # * 角色死亡状态的行走图
  916.   #--------------------------------------------------------------------------  
  917.   def set_death_graphic
  918.     @character_name = "!Coffin"  # 死亡行走图的文件名
  919.     @character_index = 0        # 设置 索引为 0 (行走图左上角)
  920.     $game_player.refresh           # 刷新队伍首位角色的行走图
  921.   end
  922.   #--------------------------------------------------------------------------
  923.   # * 角色正常状态的行走图
  924.   #--------------------------------------------------------------------------  
  925.   def set_normal_graphic
  926.       if @actor_id == 1 && $game_switches[1145] == true # 主角设置“宫廷守卫装”时
  927.         @character_name = "!Aldain"
  928.         @character_index = 1
  929.       elsif @actor_id == 1 && $game_switches[1146] == true # 主角设置“忍者装”时
  930.         @character_name = "!Aldain"
  931.         @character_index = 0
  932.       else
  933.         @character_name = actor.character_name
  934.         @character_index = actor.character_index
  935.       end
  936.       $game_player.refresh     # 刷新队伍首位角色的行走图
  937.   end
  938.   #--------------------------------------------------------------------------
  939.   # * 重构父类的hp=(hp)方法
  940.   #--------------------------------------------------------------------------   
  941.   def hp=(hp)
  942.     super  #  继承父类的方法用于判断角色生命值和状态。
  943.     if @hp <= 0 && state?(1)
  944.       set_death_graphic
  945.     else
  946.       set_normal_graphic
  947.     end
  948.   end
  949.   #--------------------------------------------------------------------------
  950.   # * 定义队伍 X坐标
  951.   #--------------------------------------------------------------------------
  952.   def screen_x
  953.     if self.index != nil
  954.       case index
  955.         when 3
  956.       return 420 if $game_party.members.size == 4
  957.         when 2
  958.       return 315 if $game_party.members.size == 4
  959.       return 380 if $game_party.members.size == 3     
  960.         when 1
  961.       return 215 if $game_party.members.size == 4
  962.       return 260 if $game_party.members.size == 3
  963.       return 320 if $game_party.members.size == 2      
  964.         when 0
  965.       return 120 if $game_party.members.size == 4
  966.       return 160 if $game_party.members.size == 3
  967.       return 200 if $game_party.members.size == 2  
  968.       return 260 if $game_party.members.size == 1      
  969.       end  
  970.     else
  971.       return 0
  972.     end
  973.   end
  974.  
  975.   #--------------------------------------------------------------------------
  976.   # * 定义队伍 Y坐标
  977.   #--------------------------------------------------------------------------
  978.   def screen_y
  979.     return 380
  980.   end  
  981.   #--------------------------------------------------------------------------
  982.   # * 定义队伍 Z坐标
  983.   #--------------------------------------------------------------------------
  984.   def screen_z
  985.      if self.index != nil
  986.       return 4 - self.index
  987.     else
  988.       return 0
  989.     end
  990.   end
  991.   #--------------------------------------------------------------------------
  992.   # * 角色精灵开关
  993.   #--------------------------------------------------------------------------
  994.   def use_sprite?
  995.     return true
  996.   end  
  997. end
  998.  
  999. class Spriteset_Battle
  1000.   #--------------------------------------------------------------------------
  1001.   # * 創建參戰主角精靈物設
  1002.   #    預設情況下不顯示主角參戰圖,不過如果需要的話,
  1003.   #    會建立一個虛擬的精靈物設並用相同的方式處理敵人隊伍和我方隊伍。
  1004.   #--------------------------------------------------------------------------
  1005.   def create_actors
  1006.    @actor_sprites = []
  1007.     for actor in $game_party.members.reverse
  1008.       @actor_sprites.push(Sprite_Battler.new(@viewport1, actor))
  1009.     end
  1010.   end
  1011.   #--------------------------------------------------------------------------
  1012.   # * 更新參戰主角之精靈物設的顯示資訊
  1013.   #--------------------------------------------------------------------------
  1014.   def update_actors
  1015.     for sprite in @actor_sprites
  1016.       sprite.update
  1017.     end
  1018.   end
  1019. end

局部截取_20241021_145927.png (216.94 KB, 下载次数: 7)

局部截取_20241021_145927.png

局部截取_20241021_150251.png (206.49 KB, 下载次数: 7)

局部截取_20241021_150251.png

局部截取_20241021_150323.png (204.04 KB, 下载次数: 6)

局部截取_20241021_150323.png

局部截取_20241021_150453.png (236.21 KB, 下载次数: 6)

局部截取_20241021_150453.png

局部截取_20241021_150534.png (217.66 KB, 下载次数: 6)

局部截取_20241021_150534.png

局部截取_20241021_150636.png (200.87 KB, 下载次数: 6)

局部截取_20241021_150636.png





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1