sacred-ritual-academy/Scripts/_RGSS3_Ver1_01.rb
2025-03-18 19:45:34 -05:00

181 lines
No EOL
6.4 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#==============================================================================
# ■ RGSS3 アイテム/スキル使用時スイッチ/変数変更 Ver1.01 by 星潟
#------------------------------------------------------------------------------
# 使用時にスイッチ/変数を変更するアイテム/スキルの作成が可能になります。
# コモンイベントと異なり、アイテム/スキル画面で使用しても
# 毎回マップ画面に切り替わるという事はなくなります。
#------------------------------------------------------------------------------
# ★設定例(アイテム/スキルのメモ欄に指定)
#------------------------------------------------------------------------------
# <スイッチ変更:1,true>
# 使用後、スイッチID1がONになります。
#------------------------------------------------------------------------------
# <スイッチ変更:1,false>
# 使用後、スイッチID1がOFFになります。
#------------------------------------------------------------------------------
# <変数変更:2,=,0>
# 変数2の値を0にします。
#------------------------------------------------------------------------------
# <変数変更:2,+,1>
# 変数2の値を1加算します。
#------------------------------------------------------------------------------
# <変数変更:2,-,2>
# 変数2の値を2減算します。
#------------------------------------------------------------------------------
# <変数変更:2,*,3>
# 変数2の値を3で乗算します。
#------------------------------------------------------------------------------
# <変数変更:2,/,4>
# 変数2の値を4で除算します。
#------------------------------------------------------------------------------
# <変数変更:2,%,5>
# 変数2の値を5の剰余とします。
#------------------------------------------------------------------------------
# ★条件付きでの変更(スクリプトにある程度の理解がある方向け)
#------------------------------------------------------------------------------
# <スイッチ変更:11,true,$game_switches[20]>
# 使用後、スイッチID20がONの場合に限り、スイッチID11がONになります。
#------------------------------------------------------------------------------
# <変数変更:12,+,1,rand(2)==0>
# 使用後、1/2の確率で変数12の値を1加算します。
#==============================================================================
module USE_ITEM_SVC
#スイッチ変更用のキーワードを指定。
WORD1 = "スイッチ変更"
#変数変更用のキーワードを指定。
WORD2 = "変数変更"
end
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# スキル/アイテムの使用
#--------------------------------------------------------------------------
alias use_item_switches_variables use_item
def use_item(item)
#本来の処理を実行。
use_item_switches_variables(item)
#アイテム使用時のスイッチ変更を実行。
item.use_switches_change
#アイテム使用時の変数変更を実行。
item.use_variables_change
end
end
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# アイテム使用時のスイッチ変更
#--------------------------------------------------------------------------
def use_switches_change
return if switches_change.empty?
switches_change.each {|s| $game_switches[s[0]] = eval(s[1]) if eval(s[2])}
end
#--------------------------------------------------------------------------
# アイテム使用時の変数変更
#--------------------------------------------------------------------------
def use_variables_change
return if variables_change.empty?
variables_change.each {|s|
next unless eval(s[3])
case s[1]
when "="
$game_variables[s[0]] = eval(s[2])
when "+"
$game_variables[s[0]] += eval(s[2])
when "-"
$game_variables[s[0]] -= eval(s[2])
when "*"
$game_variables[s[0]] *= eval(s[2])
when "/"
$game_variables[s[0]] /= eval(s[2])
when "%"
$game_variables[s[0]] %= eval(s[2])
end
}
end
#--------------------------------------------------------------------------
# スイッチ変更用データ
#--------------------------------------------------------------------------
def switches_change
#キャッシュが存在する場合はキャッシュを返す。
@switches_change ||= create_switches_change
end
#--------------------------------------------------------------------------
# スイッチ変更用データ作成
#--------------------------------------------------------------------------
def create_switches_change
#スイッチの配列を作成。
a1 = []
#メモ欄の各行からデータを取得。
self.note.each_line {|l|
if /<#{USE_ITEM_SVC::WORD1}[:](\S+)>/ =~ l
a2 = $1.to_s.split(/\s*,\s*/).inject([]) {|r,i| r.push(i)}
if a2.size > 1
a2[0] = a2[0].to_i
a2.push("true") if a2.size == 2
a1.push(a2)
end
end
}
#データを返す。
a1
end
#--------------------------------------------------------------------------
# 変数変更用データ
#--------------------------------------------------------------------------
def variables_change
#キャッシュが存在する場合はキャッシュを返す。
@variables_change ||= create_variables_change
end
#--------------------------------------------------------------------------
# 変数変更用データ作成
#--------------------------------------------------------------------------
def create_variables_change
a1 = []
#メモ欄の各行からデータを取得。
self.note.each_line {|l|
if /<#{USE_ITEM_SVC::WORD2}[:](\S+)>/ =~ l
a2 = $1.to_s.split(/\s*,\s*/).inject([]) {|r,i| r.push(i)}
if a2.size > 2
a2[0] = a2[0].to_i
a2.push("true") if a2.size == 3
a1.push(a2)
end
end
}
#データを返す。
a1
end
end