查看: 3297|回复: 2

[已经过期] 萌新求解

[复制链接]
梦石
0
星屑
1461
在线时间
815 小时
注册时间
2013-8-3
回帖
355
发表于 2019-6-7 10:39:03 | 显示全部楼层 |阅读模式

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

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

×
限制物品使用次数
[pre lang="ruby"]#--------------------------------------------------------------------------
  # ● 技能/物品的应用测试and
  #    如果使用目标的 HP 或者 MP 全满时,禁止使用恢复道具。
  #--------------------------------------------------------------------------
  def item_test(user, item)
    if item.is_a?(RPG::Item) and [13,14,15,16,17,18,19,20].include?(item.id) and item.is_a?(RPG::Item)
    $使用次数 = [] if $使用次数 == nil
    $使用次数[self.id] = 0 if $使用次数[self.id] == nil
    return false if $使用次数[self.id] >99
  end[/pre]
[pre lang="ruby"] #--------------------------------------------------------------------------
  # ● 应用技能/物品的效果
  #--------------------------------------------------------------------------
  def item_apply(user, item)
    $使用次数[self.id] += 1  if self.actor?  and  $使用次数[self.id] <= 100
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end[/pre]

这项会报错  $使用次数[self.id] += 1   if self.actor? and $使用次数[self.id] <= 100

【同人游戏】勇者斗恶龙TG
欢迎加入游戏测试群333599798
如有需私聊请加QQ:516425000

老鹰

梦石
40
星屑
37812
在线时间
7091 小时
注册时间
2012-5-26
回帖
3297

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2019-6-7 10:53:04 | 显示全部楼层
self.id 是什么鬼
记录的到底是啥??物品的应用目标的使用次数??

推荐使用 hash类型
  1. $使用次数 = {}
复制代码


然后key用item来表示,value为被使用的次数
报错是因为那个test不一定会在之前运行,所以加上空值判定
  1. $使用次数[item] ||= 0
  2. $使用次数[item] += 1  if self.actor?  and  $使用次数[item] <= 100
复制代码

点评

还是搞不懂,可不可以帮我改改  发表于 2019-6-14 22:27
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部