=begin
#==============================================================================#
# AMN HimeWorks Battle Reactions add-on - Use Items
# Version 1.01
# Author: AMoonlessNight
# Date: 30 Jun 2020
# Latest: 30 Jun 2020
#==============================================================================#
# UPDATE LOG
#------------------------------------------------------------------------------#
# 30 Jun 2020 - created the script
#==============================================================================#
# TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Please credit Tsukihime/HimeWorks and follow their terms of use
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
# script (do not edit this script directly) and provide proper credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#
This script is an add-on for Tsukihime's Battle Reactions script:
http://himeworks.com/2013/09/battle-reactions/
It makes it so that you can set certain reactions to use an item instead of
a skill.
Set up the reaction notetags as per the original script. For reactions that you
want to use an item instead, put the Item ID instead of reaction skill ID.
Add the following notetag:
<item reaction: id1,id2, ... >
Where id1, id2, etc., are the unique IDs of the reactions that you want to use
items for instead of skills. Each reaction has a unique ID, in the order that
they are written in your notebox. The first reaction is 1, the second reaction
is 2, and so on.
This notetag works for enemies as well.
NOTE: You will need to set a condition that the party has the item, otherwise
you will use the items even if you don't have them, e.g. something like this:
<reaction condition: id1>
FORMULA && $game_party.has_item?($data_items[X])
</reaction condition>
(Obviously don't use this for enemies, because they don't have inventory).
=end
#==============================================================================
# Please do not edit below this point unless you know what you are doing.
#==============================================================================
module TH
module Battle_Reactions
Item_React_Regex = /<item[ _-]reaction:(.*?)>/i
end
end
class RPG::BaseItem
alias amn_himebr_rpgbaseitem_lnbr load_notetag_battle_reactions
def load_notetag_battle_reactions
amn_himebr_rpgbaseitem_lnbr
load_notetag_item_reactions
end
def load_notetag_item_reactions
results = self.note.scan(TH::Battle_Reactions::Item_React_Regex)
results.each do |res|
res[0].split(",").map {|id| id.to_i - 1 }.each do |id|
next unless @reactions[id]
@reactions[id].react_type = :item
end
end
end
end
class Game_Battler < Game_BattlerBase
def set_action_by_reaction_type(user, reaction, action)
case reaction.react_type
when :skill
if reaction.react_id > $data_skills.size
puts "AMN HimeWorks Battle Reactions add-on: #{reaction.react_id} is not a valid Skill ID"
return false
end
item = $data_skills[reaction.react_id]
when :item
if reaction.react_id > $data_items.size
puts "AMN HimeWorks Battle Reactions add-on: #{reaction.react_id} is not a valid Item ID"
return false
end
item = $data_items[reaction.react_id]
end
return false unless item
if item.for_opponent?
action.target_index = user.index
elsif item.for_friend?
action.target_index = self.index
end
return false unless action.respond_to?("set_#{reaction.react_type}")
action.send("set_#{reaction.react_type}", reaction.react_id)
return true
end
# Overwrite to consider react_type
def make_reaction(user, reaction)
return unless reaction.condition_met?(self, user)
return unless movable? || reaction.forced
chance = reaction.chance(self, user)
return if chance < rand
action = Game_Action.new(self, reaction.forced)
return unless set_action_by_reaction_type(user,reaction,action)
action.make_targets
@actions.push(action)
BattleManager.force_reaction(self)
end
end