=begin
====================================================================
GENERAL INFORMATION
--------------------------------------------------------------------
Title: Item Refund System
Author: Adiktuzmiko
Version: 1.20
Requirements: None
This script allows you to use notetags to have a chance of refunding
the cost of an item when you use it.
====================================================================
====================================================================
FEATURES
--------------------------------------------------------------------
Refund item cost when used
Customizable
- Set the percent chance of the refund to happen
- Set what percentage of the cost to refund
- Use either fixed values or a method
- Three different stacking modes for multiple notetags
-> Additive, Highest value, Individual refunds
- Set a maximum chance for the additive mode and maximum cost
percentage for all modes
====================================================================
====================================================================
INSTRUCTIONS
--------------------------------------------------------------------
After importing this script to your project, go to the config part
below (after TERMS AND CONDITIONS) and edit to suit your needs.
Instructions on the notetag usage also in the config part.
Notetags are usable for Actors, Class, Equipment, Items, States
====================================================================
====================================================================
TERMS AND CONDITIONS
--------------------------------------------------------------------
View it here: http://lescripts.wordpress.com/terms-and-conditions/
====================================================================
=end
module ADIK
module REFUND_ITEM
#For simple, fixed value usage
#Refund Chance, Refund Percentage
TAG = /<refund:(.*):(.*)>/i
#For more advanced usage
#Takes method_name
#Methods must be created inside Class Game_Battler
#Methods must take parameters (user,item)
#Methods must return array [Chance,Percentage]
#See sample method named sample in the class Game_Battler below
TAG_M = /<refund_method:(.*)>/i
#Text shown on the battle log
#Usable text codes
#<item> => item name
#<value> => refund value
#<user> => name of user
TEXT = "<user> has been refunded <value>!"
#:additive, :highest, :individual
#if :additive, adds all chances and refund percentages of user
#then evaluates it as a single chance and refund line
#if :highest, evaluates each refund notetag of user and returns the
#successful evaluation with the highest value
#if :individual, evaluates each refund notetag of user and returns the
#total value of all successful evaluation
MODE = :individual
#Max Chance (for additive mode)
def self.max_chance
return 100
end
#Max Refund (for all modes)
def self.max_refund
return 100
end
end
end
# DO NOT EDIT BELOW THIS LINE
# DO NOT EDIT BELOW THIS LINE
# DO NOT EDIT BELOW THIS LINE
class Game_Actor
def note
return $data_actors[@actor_id].note
end
end
class Game_Enemy
def note
return $data_enemies[@enemy_id].note
end
end
class Scene_Battle
def log_window
return @log_window
end
end
class Game_Battler
def sample(user,item)
return [50,30]
end
def process_refund_text(user,item,value)
text = ADIK::REFUND_ITEM::TEXT
text = text.gsub(/<user>/) {user.name}
text = text.gsub(/<value>/) {value.to_s}
text = text.gsub(/<item>/) {item.name}
return text
end
def refund(user,item,value)
value *= item.price
value = value.to_i
$game_party.gain_gold(value)
return unless SceneManager.scene_is?(Scene_Battle)
return if value <= 0
text = process_refund_text(user,item,value)
SceneManager.scene.log_window.add_text(text)
end
def process_refund_add(user,item)
chance = 0
percentage = 0
if item.note =~ ADIK::REFUND_ITEM::TAG
chance += $1.to_i
percentage += $2.to_i
end
if item.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
chance += result[0]
percentage += result[1]
end
user.feature_objects.each do |obj|
next if obj.nil?
if obj.note =~ ADIK::REFUND_ITEM::TAG
chance += $1.to_i
percentage += $2.to_i
end
if obj.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
chance += result[0]
percentage += result[1]
end
end
chance = [chance,ADIK::REFUND_ITEM.max_chance].min
if rand(100) < chance
return percentage
end
end
def process_refund_high(user,item)
percentage = []
if item.note =~ ADIK::REFUND_ITEM::TAG
percentage.push($2.to_i) if rand(100) <= $1.to_i
end
if item.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
percentage.push(result[1].to_i) if rand(100) <= result[0].to_i
end
user.feature_objects.each do |obj|
next if obj.nil?
if obj.note =~ ADIK::REFUND_ITEM::TAG
percentage.push($2.to_i) if rand(100) <= $1.to_i
end
if obj.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
percentage.push(result[1].to_i) if rand(100) <= result[0].to_i
end
end
return percentage.max
end
def process_refund_indi(user,item)
percentage = 0
if item.note =~ ADIK::REFUND_ITEM::TAG
percentage += $2.to_i if rand(100) <= $1.to_i
end
if item.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
percentage += result[1].to_i if rand(100) <= result[0].to_i
end
user.feature_objects.each do |obj|
next if obj.nil?
if obj.note =~ ADIK::REFUND_ITEM::TAG
percentage += $2.to_i if rand(100) <= $1.to_i
end
if obj.note =~ ADIK::REFUND_ITEM::TAG_M
result = self.method($1.to_sym).call(user,item)
percentage += result[1].to_i if rand(100) <= result[0].to_i
end
end
return percentage
end
def process_refund(user,item)
refund_value = 0
case ADIK::REFUND_ITEM::MODE
when :additive
refund_value = process_refund_add(user,item)
when :highest
refund_value = process_refund_high(user,item)
when :individual
refund_value = process_refund_indi(user,item)
end
refund_value = 0 if refund_value.nil?
refund_value = [refund_value,ADIK::REFUND_ITEM.max_refund].min
refund(user,item,refund_value.to_f/100)
end
alias use_item_refund use_item
def use_item(item)
use_item_refund(item)
process_refund(self,item) if (item.is_a?(RPG::Item) && item.consumable)
end
end
Comments
0 B
|👍
/👎
0 B
|👍
/👎