#--------------------------------------------------------------------
# ● require Taroxd基础设置
# 制作消耗物品的技能
#--------------------------------------------------------------------
#
# 使用方法:
# 技能备注 <itemcost item_id number>
# item_id 为消耗的物品 id,number 为消耗的物品个数。
# number 可不填,默认为 1(即 <itemcost item_id>)。
# 技能备注 <itemneed item_id number>
# item_id 为需要的物品 id(不消耗),number 为消耗的物品个数。
# number 可不填,默认为 1
#
#--------------------------------------------------------------------
Taroxd::ItemCost = Struct.new(:item, :number, :cost) do
MP_ICON = 188
TP_ICON = 189
RE = /<item\s*(cost|need)\s+(\d+)(\s+\d+)?>/i
def self.parse_note(note)
note.scan(RE).map do |cost, item_id, number|
new($data_items[item_id.to_i],
(number ? number.to_i : 1),
cost == 'cost')
end
end
def meet?
$game_party.item_number(item) >= number
end
def pay
$game_party.lose_item(item, number) if cost
end
end
class RPG::Skill < RPG::UsableItem
def item_costs
@item_costs ||= Taroxd::ItemCost.parse_note(@note)
end
end
class Game_BattlerBase
def_and :skill_cost_payable? do |skill|
skill.item_costs.all?(&:meet?)
end
def_after :pay_skill_cost do |skill|
skill.item_costs.each(&:pay)
end
end
class Window_SkillList < Window_Selectable
def draw_skill_cost(rect, skill)
contents.font.size -= 6
change_color(tp_cost_color, enable?(skill))
draw_skill_cost_icon(rect, skill,
@actor.skill_tp_cost(skill), Taroxd::ItemCost::TP_ICON)
change_color(mp_cost_color, enable?(skill))
draw_skill_cost_icon(rect, skill,
@actor.skill_mp_cost(skill), Taroxd::ItemCost::MP_ICON)
skill.item_costs.each do |item_cost|
draw_skill_cost_icon(rect, skill,
item_cost.number, item_cost.item.icon_index)
end
contents.font.size += 6
end
def draw_skill_cost_icon(rect, skill, cost, icon_index)
return if cost == 0
x = rect.x + rect.width - 24
draw_icon(icon_index, x, rect.y, enable?(skill))
draw_text(x, rect.y + 8, 24, 16, cost, 2) unless cost == 1
rect.width -= 24
end
end
#-------------------------------------------
# ● require Taroxd基础设置
# 额外战斗行动
#-------------------------------------------
#
# 在战斗公式或事件指令-脚本中输入
# battler.extra_skill(skill_id, target_index)
# 即可产生一次额外的行动(对应 skill_id 的技能)。
# target_index 省略时,目标默认为 battler 上次的目标。
#
# battler.extra_item(item_id, target_index)
# 与 extra_skill 相同。行动内容为对应 item_id 的物品。
#
# battler.extra_action(skill_id, target_index)
# 与 extra_skill 相同。
#
# 注意,额外的行动也是有消耗的(包括 MP、物品等)
# 当消耗不满足,或者因为其他原因无法行动时,额外行动无效。
#
#-------------------------------------------
class Taroxd::ExtraAction < Game_Action
# 默认目标。-2: 上次目标, -1: 随机
DEFAULT_TARGET_INDEX = -2
class << self
def new(_, _)
super.tap { |action| @actions.push action }
end
# 获取最后生成的 action 对象并移除这个对象。
# 如果没有 action,返回 nil。
def current!
@actions.pop
end
def clear
@actions = []
end
end
def initialize(subject, target_index)
super(subject)
@target_index = target_index
end
def make_targets
@target_index = @subject.last_target_index if @target_index == -2
super
end
end
class Game_Battler < Game_BattlerBase
ExtraAction = Taroxd::ExtraAction
def extra_skill(id, target_index = ExtraAction::DEFAULT_TARGET_INDEX)
ExtraAction.new(self, target_index).set_skill(id)
end
alias_method :extra_action, :extra_skill
def extra_item(id, target_index = ExtraAction::DEFAULT_TARGET_INDEX)
ExtraAction.new(self, target_index).set_item(id)
end
end
class Scene_Battle < Scene_Base
def_before :battle_start, Taroxd::ExtraAction.method(:clear)
def_before :process_forced_action do
action = Taroxd::ExtraAction.current!
return unless action
last_subject = @subject
@subject = action.subject
@subject.actions.unshift(action)
process_action
@subject = last_subject
end
end
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |