设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 58|回复: 2
打印 上一主题 下一主题

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

[复制链接]

Lv2.观梦者

梦石
0
星屑
839
在线时间
66 小时
注册时间
2021-3-17
帖子
47
跳转到指定楼层
1
发表于 昨天 16:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
打个比方,有一个道具投石车,只有一个,使用后对全部i敌人造成伤害,可以无限使用,我想实现,当角色A选择使用此道具时,角色B便无法选择使用(毕竟道具只有一个嘛),
有大佬能给个思路吗?

Lv2.观梦者

梦石
0
星屑
839
在线时间
66 小时
注册时间
2021-3-17
帖子
47
2
 楼主| 发表于 昨天 16:20 | 只看该作者
扩展一下,相当于有几个道具,就只有几个人能选择使用,
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6225
在线时间
1456 小时
注册时间
2015-7-25
帖子
617

极短25参与开拓者

3
发表于 昨天 21:26 | 只看该作者
提供一个思路。
1.设置一个属性,随便取个名字,比如:单人使用
2.把需要单人使用的道具找出来,将此属性勾选上
3.编写核心算法
RUBY 代码复制
  1. module RPG
  2.   class Item
  3.     attr_accessor :single_use
  4.     alias mf250703initialize initialize
  5.     def initialize
  6.       @single_use = nil
  7.       mf250703initialize
  8.     end
  9.     def is_single_use?
  10.       @element_set.include? 17 #单人使用的属性ID
  11.     end
  12.   end
  13. end
  14. class Game_Party
  15.   def item_single_using?(item_id)
  16.     $data_items[item_id].is_single_use? && $data_items[item_id].single_use
  17.   end
  18.   def clear_item_single_use(*item)
  19.     item.each {|i| i.single_use = nil}
  20.   end
  21.   alias mf250703item_can_use? item_can_use?
  22.   def item_can_use?(item_id)
  23.     return if item_single_using?(item_id)
  24.     mf250703item_can_use?(item_id)
  25.   end
  26. end

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.3.8.1 (游戏文件已上传更新
同时更新中~ (沉迷摸鱼中~更新速度较慢请见谅w)
这是属于笨肉包一个人的旅行~(再见了...蚊子湯,七重酱,笨肉包永远想你们!TwT
旅途的最终目标~ ???(保密~
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-7-4 20:49

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表