查看: 2818|回复: 2

[已经解决] 如何设置道具使用条件?

[复制链接]
梦石
0
星屑
143
在线时间
347 小时
注册时间
2010-7-7
回帖
96
发表于 2013-12-9 17:29:11 | 显示全部楼层 |阅读模式

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

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

×
比如在战斗中,将要使用复活石来复活一名队友,但是使用复活石会消耗100点TP值,如果TP值不足则无法使用该道具,请问如何实现?
梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
回帖
2257

贵宾

发表于 2013-12-9 20:39:55 | 显示全部楼层
本帖最后由 Sion 于 2013-12-9 20:41 编辑

[pre lang="ruby" line="1"]# 设置战斗物品消耗,物品备注中写:
# cost tp:100 消耗使用者 100 TP
# Cost_HP 200 消耗 200 HP
# cost_mp_100 消耗 100 MP
# 大小写和用来隔开的符号随意
# 对应值不足则无法使用,可以设置一个物品消耗多种数值
# 因为平时使用物品根本没有指定使用者,所以非战斗中使用物品时,不计算这些额外消耗。
# @actor

class Game_Actor
  alias_method :consume_item_s20131209, :consume_item
  def consume_item(item)
    pay_item_cost(item)
    consume_item_s20131209(item)
  end
  def pay_item_cost(item)
    return unless $game_party.in_battle
    note = item.note.downcase
    self.hp -= $1.to_i if note =~ /cost.hp.(\d+)/
    self.mp -= $1.to_i if note =~ /cost.mp.(\d+)/
    self.tp -= $1.to_i if note =~ /cost.tp.(\d+)/
  end
  def enough_item_cost?(item)
    note = item.note.downcase
    return false if note =~ /cost.hp.(\d+)/ && hp <= $1.to_i
    return false if note =~ /cost.mp.(\d+)/ && mp < $1.to_i
    return false if note =~ /cost.tp.(\d+)/ && tp < $1.to_i
    return true
  end
end

class Window_BattleItem
  def actor=(actor)
    return if @actor == actor
    @actor = actor
    refresh
    self.oy = 0
  end
  def enable?(item)
    super && @actor.enough_item_cost?(item)
  end
end

class Scene_Battle
  alias_method :s20131209_command_item, :command_item
  def command_item
    @item_window.actor = BattleManager.actor
    s20131209_command_item
  end
end[/pre]   
回复

使用道具 举报

梦石
0
星屑
143
在线时间
347 小时
注册时间
2010-7-7
回帖
96
 楼主| 发表于 2013-12-9 20:53:16 | 显示全部楼层
Sion 发表于 2013-12-9 20:39
# 设置战斗物品消耗,物品备注中写:
# cost tp:100 消耗使用者 100 TP
# Cost_HP 200 消耗 200 HP

十分感谢!
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部