rmxp团队吧 关注:805贴子:10,012
  • 5回复贴,共1

脚本:在战斗中添加跟换武器选项

只看楼主收藏回复

class Scene_Battle
def main
# 初始化战斗用的各种暂时数据
$game_temp.in_battle = true
$game_temp.battle_turn = 0
$game_temp.battle_event_flags.clear
$game_temp.battle_abort = false
$game_temp.battle_main_phase = false
$game_temp.battleback_name = $game_map.battleback_name
$game_temp.forcing_battler = nil
# 初始化战斗用事件解释器
$game_system.battle_interpreter.setup(nil, 0)
# 准备队伍
@troop_id = $game_temp.battle_troop_id
$game_troop.setup(@troop_id)
# 生成角色命令窗口
s1 = $data_system.words.attack
s2 = $data_system.words.skill
s3 = $data_system.words.guard
s4 = $data_system.words.item
#kk开始
s5 = "变更武器"
@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4 , s5])
@actor_command_window.y = 128
#kk结束
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false
# 生成其它窗口
@party_command_window = Window_PartyCommand.new
@help_window = Window_Help.new
@help_window.back_opacity = 160
@help_window.visible = false
@status_window = Window_BattleStatus.new
@message_window = Window_Message.new
# 生成活动块
@spriteset = Spriteset_Battle.new
# 初始化等待计数
@wait_count = 0
# 执行过渡
if $data_system.battle_transition == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$data_system.battle_transition)
end
# 开始自由战斗回合
start_phase1
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面切换的话就中断循环
if $scene != self
break
end
end
# 刷新地图
$game_map.refresh
# 准备过渡
Graphics.freeze
# 释放窗口
@actor_command_window.dispose
@party_command_window.dispose
@help_window.dispose
@status_window.dispose
@message_window.dispose
if @skill_window != nil
@skill_window.dispose
end
if @item_window != nil
@item_window.dispose
end
if @result_window != nil
@result_window.dispose
end
# 释放活动块
@spriteset.dispose
# 标题画面切换中的情况
if $scene.is_a?(Scene_Title)
# 淡入淡出画面
Graphics.transition
Graphics.freeze
end
# 战斗测试或者游戏结束以外的画面切换中的情况
if $BTEST and not $scene.is_a?(Scene_Gameover)
$scene = nil
end
end
def update_phase3_basic_command
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)



1楼2011-07-28 09:14回复
    # 转向前一个角色的指令输入
    phase3_prior_actor
    return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
    # 角色指令窗口光标位置分之
    case @actor_command_window.index
    when 0 # 攻击
    # 演奏确定 SE
    $game_system.se_play($data_system.decision_se)
    # 设置行动
    @active_battler.current_action.kind = 0
    @active_battler.current_action.basic = 0
    # 开始选择敌人
    start_enemy_select
    when 1 # 特技
    # 演奏确定 SE
    $game_system.se_play($data_system.decision_se)
    # 设置行动
    @active_battler.current_action.kind = 1
    # 开始选择特技
    start_skill_select
    when 2 # 防御
    # 演奏确定 SE
    $game_system.se_play($data_system.decision_se)
    # 设置行动
    @active_battler.current_action.kind = 0
    @active_battler.current_action.basic = 1
    # 转向下一位角色的指令输入
    phase3_next_actor
    when 3 # 物品
    # 演奏确定 SE
    $game_system.se_play($data_system.decision_se)
    # 设置行动
    @active_battler.current_action.kind = 2
    # 开始选择物品
    start_item_select
    #kk_开始
    when 4 # 变更武器
    # 演奏确定 SE
    $game_system.se_play($data_system.decision_se)
    # 设置行动
    @active_battler.current_action.kind = 3
    # 开始选择武器
    start_weapon_select
    #kk_结束
    end
    return
    end
    end
    #--------------------------------------------------------------------------
    # ● 刷新画面 (角色命令回合)
    #--------------------------------------------------------------------------
    def update_phase3
    # 敌人光标有效的情况下
    if @enemy_arrow != nil
    update_phase3_enemy_select
    # 角色光标有效的情况下
    elsif @actor_arrow != nil
    update_phase3_actor_select
    # 特技窗口有效的情况下
    elsif @skill_window != nil
    update_phase3_skill_select
    # 物品窗口有效的情况下
    elsif @item_window != nil
    update_phase3_item_select
    #kk开始
    elsif @weapon_window != nil
    update_phase3_weapon_select
    #kk结束
    # 角色指令窗口有效的情况下
    elsif @actor_command_window.active
    update_phase3_basic_command
    end
    end
    #--------------------------------------------------------------------------
    # ● 刷新画面 (角色命令回合 : 选择武器)
    #--------------------------------------------------------------------------
    def update_phase3_weapon_select
    # 设置物品窗口为可视状态
    # @weapon_window.visible = true
    # 刷新物品窗口
    @weapon_window.update
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
    # 演奏取消 SE
    $game_system.se_play($data_system.cancel_se)
    # 选择物品结束
    end_weapon_select
    return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
    # 获取物品窗口现在选择的物品资料
    @weapon = @weapon_window.item
    


    2楼2011-07-28 09:14
    回复
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      item = @weapon_window.item
      @active_battler.equip(0, item == nil ? 0 : item.id)
      @weapon_window.refresh
      @actor_window.refresh
      end
      return
      end
      #--------------------------------------------------------------------------
      # ● 开始选择武器
      #--------------------------------------------------------------------------
      def start_weapon_select
      # 生成特技窗口
      @weapon_window = Window_EquipItemk.new(@active_battler,0)
      @actor_window = Window_EquipLeftk.new(@active_battler)
      # 关联帮助窗口
      @weapon_window.help_window = @help_window
      # 无效化角色指令窗口
      @actor_command_window.active = false
      @actor_command_window.visible = false
      end
      def end_weapon_select
      # 释放物品窗口
      @weapon_window.dispose
      @weapon_window = nil
      @actor_window.dispose
      @actor_window = nil
      # 隐藏帮助窗口
      @help_window.visible = false
      # 有效化角色指令窗口
      @actor_command_window.active = true
      @actor_command_window.visible = true
      end
      end
      class Window_EquipItemk < Window_Selectable
      #--------------------------------------------------------------------------
      # ● 初始化对像
      # actor : 角色
      # equip_type : 装备部位 (0~3)
      #--------------------------------------------------------------------------
      def initialize(actor, equip_type)
      super(320, 64, 320, 256)
      @actor = actor
      @equip_type = equip_type
      @column_max = 1
      self.opacity = 160
      self.index = 0
      refresh
      end
      #--------------------------------------------------------------------------
      # ● 获取物品
      #--------------------------------------------------------------------------
      def item
      return @data[self.index]
      end
      #--------------------------------------------------------------------------
      # ● 刷新
      #--------------------------------------------------------------------------
      def refresh
      if self.contents != nil
      self.contents.dispose
      self.contents = nil
      end
      @data = []
      # 添加可以装备的武器
      if @equip_type == 0
      weapon_set = $data_classes[@actor.class_id].weapon_set
      for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
      @data.push($data_weapons[i])
      


      3楼2011-07-28 09:14
      回复
        end
        end
        end
        # 添加可以装备的防具
        if @equip_type != 0
        armor_set = $data_classes[@actor.class_id].armor_set
        for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0 and armor_set.include?(i)
        if $data_armors[i].kind == @equip_type-1
        @data.push($data_armors[i])
        end
        end
        end
        end
        # 添加空白
        @data.push(nil)
        # 生成位图、描绘全部项目
        @item_max = @data.size
        self.contents = Bitmap.new(width - 32, row_max * 32)
        for i in 0...@item_max-1
        draw_item(i)
        end
        end
        #--------------------------------------------------------------------------
        # ● 项目的描绘
        # index : 项目符号
        #--------------------------------------------------------------------------
        def draw_item(index)
        item = @data[index]
        x = 4
        y = index * 32
        case item
        when RPG::Weapon
        number = $game_party.weapon_number(item.id)
        when RPG::Armor
        number = $game_party.armor_number(item.id)
        end
        bitmap = RPG::Cache.icon(item.icon_name)
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
        self.contents.font.color = normal_color
        self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
        self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
        self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
        end
        #--------------------------------------------------------------------------
        # ● 刷新帮助文本
        #--------------------------------------------------------------------------
        def update_help
        @help_window.set_text(self.item == nil ? "" : self.item.description)
        end
        end
        class Window_EquipLeftk < Window_Base
        #--------------------------------------------------------------------------
        # ● 初始化对像
        # actor : 角色
        #--------------------------------------------------------------------------
        def initialize(actor)
        super(0, 64, 320, 256)
        self.contents = Bitmap.new(width - 32, height - 32)
        @actor = actor
        self.opacity = 160
        refresh
        end
        #--------------------------------------------------------------------------
        # ● 刷新
        #--------------------------------------------------------------------------
        def refresh
        self.contents.clear
        draw_actor_name(@actor, 4, 0)
        draw_actor_level(@actor, 4, 32)
        draw_actor_parameter(@actor, 4, 64, 0)
        draw_actor_parameter(@actor, 4, 96, 1)
        draw_actor_parameter(@actor, 4, 128, 2)
        draw_item_name($data_weapons[@actor.weapon_id], 132, 160)
        self.contents.font.color = system_color
        


        4楼2011-07-28 09:14
        回复
          self.contents.draw_text(4, 160, 128, 32, "目前武器")
          self.contents.draw_text(4, 192, 128, 32, "武器属性")
          self.contents.font.color = Color.new(0,255,0)
          element = ""
          if @actor.weapon_id == 0
          element = "无"
          else
          if $data_weapons[@actor.weapon_id].element_set[1] == nil
          element = "无"
          else
          for i in 1...$data_weapons[@actor.weapon_id].element_set.size
          element += $data_system.elements[$data_weapons[@actor.weapon_id].element_set[i]] + " "
          end
          end
          end
          self.contents.draw_text(132, 192, 128, 32, element)
          if @new_atk != nil
          self.contents.font.color = system_color
          self.contents.draw_text(160, 64, 40, 32, "→", 1)
          self.contents.font.color = normal_color
          self.contents.draw_text(200, 64, 36, 32, @new_atk.to_s, 2)
          end
          if @new_pdef != nil
          self.contents.font.color = system_color
          self.contents.draw_text(160, 96, 40, 32, "→", 1)
          self.contents.font.color = normal_color
          self.contents.draw_text(200, 96, 36, 32, @new_pdef.to_s, 2)
          end
          if @new_mdef != nil
          self.contents.font.color = system_color
          self.contents.draw_text(160, 128, 40, 32, "→", 1)
          self.contents.font.color = normal_color
          self.contents.draw_text(200, 128, 36, 32, @new_mdef.to_s, 2)
          end
          end
          #--------------------------------------------------------------------------
          # ● 变更装备后的能力值设置
          # new_atk : 变更装备后的攻击力
          # new_pdef : 变更装备后的物理防御
          # new_mdef : 变更装备后的魔法防御
          #--------------------------------------------------------------------------
          def set_new_parameters(new_atk, new_pdef, new_mdef)
          if @new_atk != new_atk or @new_pdef != new_pdef or @new_mdef != new_mdef
          @new_atk = new_atk
          @new_pdef = new_pdef
          @new_mdef = new_mdef
          refresh
          end
          end
          end
          


          5楼2011-07-28 09:14
          回复
            正在复刻新仙剑项目的程序逻辑,您的源码有非常实用的借鉴意义,谢谢!先收藏一下,遇到问题的话再回帖联系。


            IP属地:山东6楼2021-04-24 09:52
            回复