查看: 1257|回复: 2

[有事请教] 请问如何实现背包里面道具只能一个人使用,详情如下

[复制链接]
梦石
0
星屑
579
在线时间
83 小时
注册时间
2021-3-17
回帖
40
发表于 2025-7-3 16:18:58 | 显示全部楼层 |阅读模式

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

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

×
打个比方,有一个道具投石车,只有一个,使用后对全部i敌人造成伤害,可以无限使用,我想实现,当角色A选择使用此道具时,角色B便无法选择使用(毕竟道具只有一个嘛),
有大佬能给个思路吗?
梦石
0
星屑
579
在线时间
83 小时
注册时间
2021-3-17
回帖
40
 楼主| 发表于 2025-7-3 16:20:28 | 显示全部楼层
扩展一下,相当于有几个道具,就只有几个人能选择使用,
回复

使用道具 举报

梦石
0
星屑
6375
在线时间
1473 小时
注册时间
2015-7-25
回帖
609

极短25参与开拓者

发表于 2025-7-3 21:26:22 | 显示全部楼层
提供一个思路。
1.设置一个属性,随便取个名字,比如:单人使用
2.把需要单人使用的道具找出来,将此属性勾选上
3.编写核心算法
[pre lang="ruby"]module RPG
  class Item
    attr_accessor :single_use
    alias mf250703initialize initialize
    def initialize
      @single_use = nil
      mf250703initialize
    end
    def is_single_use?
      @element_set.include? 17 #单人使用的属性ID
    end
  end
end
class Game_Party
  def item_single_using?(item_id)
    $data_items[item_id].is_single_use? && $data_items[item_id].single_use
  end
  def clear_item_single_use(*item)
    item.each {|i| i.single_use = nil}
  end
  alias mf250703item_can_use? item_can_use?
  def item_can_use?(item_id)
    return if item_single_using?(item_id)
    mf250703item_can_use?(item_id)
  end
end[/pre]
4.进行调用,这里拿默认战斗系统举例,在任何其他战斗系统中也可以自行调用
先在Scene_Battle中设置一个值为空数组的类变量,@@item_single_use = []
@@item_single_use,内部存储已设置使用状态的item
实现条件1:当某个角色选择使用拥有单人使用属性的物品时,设置其single_use属性并进行记录
实现条件2:当角色指令返回时,检测并取消之前的设置
实现条件3:行动回合开始时,清除@@item_single_use中记录的数据并恢复所有item的single_use属性
class Scene_Battle
  @@item_single_use = []
  def update_phase3_item_select
    # 设置物品窗口为可视状态
    @item_window.visible = true
    # 刷新物品窗口
    @item_window.update
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 选择物品结束
      end_item_select
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 获取物品窗口现在选择的物品资料
      @item = @item_window.item
      # 无法使用的情况下
      unless $game_party.item_can_use?(@item.id)
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      # 设置行动
      @active_battler.current_action.item_id = @item.id
      
      @item.single_use = @active_battler
      @@item_single_use << @item

      # 设置物品窗口为不可见状态
      @item_window.visible = false
      # 效果范围是敌单体的情况下
      if @item.scope == 1
        # 开始选择敌人
        start_enemy_select
      # 效果范围是我方单体的情况下
      elsif @item.scope == 3 or @item.scope == 5
        # 开始选择角色
        start_actor_select
      # 效果范围不是单体的情况下
      else
        # 物品选择结束
        end_item_select
        # 转到下一位角色的指令输入
        phase3_next_actor
      end
      return
    end
  end
  alias mf250703update_phase4 update_phase4
  def update_phase4
    $game_party.clear_item_single_use *@@item_single_use
    @@item_single_use = []

    mf250703update_phase4
  end
  def phase3_prior_actor
    # 循环
    begin
      # 角色的明灭效果 OFF
      if @active_battler != nil
        @active_battler.blink = false
      end
      # 最初的角色的情况下
      if @actor_index == 0
        # 开始同伴指令回合
        start_phase2
        return
      end
      # 返回角色索引
      @actor_index -= 1
      @active_battler = $game_party.actors[@actor_index]
      @active_battler.blink = true
      
      item = $data_items[@active_battler.current_action.item_id]
      if @@item_single_use.include? item
        item.single_use = nil
        @@item_single_use.delete item
      end

    # 如果角色是在无法接受指令的状态就再试
    end until @active_battler.inputable?
    # 设置角色的命令窗口
    phase3_setup_command_window
  end
end
笨肉包的游戏讨论群932812135 (实时更新) 喜欢的话欢迎加入~
目前的坑
??? #像素风OC游戏 准备中 短篇-约5小时
花城梦之心 #像素风OC游戏 系统开发+素材绘制中
【不可思议的迷宫】幽灵契约外传:歌莉娅 v0.4 游戏文件已更新
同时更新中~ (沉迷摸鱼中~更新速度较慢请见谅w)
这是属于笨肉包一个人的旅行~(这只肉包又在摸鱼!
旅途的最终目标~ ???(保密~
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部