#==============================================================================
# System_Reputation
# Created by: AvilaMn
# Version: 1.1
#------------------------------------------------------------------------------
# Description:
# This system add the possibility to have different reputations that can be
# increased by events, including a window to check de reputation progress and
# the posibility to create custom shops that change their items values based
# on the reputations levels
#------------------------------------------------------------------------------
# Instructions:
#
# To call the Reputation Menu use this line in a Script call or in you script:
# $scene = Scene_Reputations.new
#
# To Add exp to a certain Reputation use this line in a Script Call:
# add_rep_exp(ID, VALUE) : ID is the Reputation ID and VALUE is the ammount
# of exp you want to add
#
# To Remove exp to a certain Reputation use this line in a Script Call:
# remove_rep_exp(ID, VALUE) : ID is the Reputation ID and VALUE is the ammount
# of exp you want to remove
#
# To check if the player can access a certain Custom Shop use this line in a
# Script section of the Event Conditional:
# can_shop?(ID) : ID is the Shop ID
#
# To call a Custom Shop use this line in a Script Call:
# call_custom_shop(ID) : ID is the Shop ID
#
# The IDs you need to make the diferent calls are in the CONFIGURATION below
#==============================================================================
module REP_CONFIG
#============================================================================
# CONFIGURATION :
# To add a new data just add new lines following the syntax commented in each
# data Hash, and don't forget to put the , at the end
#============================================================================
Reputations = {
# ID => [NAME, LEVEL, EXP, ACTIVE, ICON]
0 => ["KINGDOM", 5, 99999, true, "Reputation-01"],
1 => ["ALIANCE", 1, 0, false, "Reputation-02"],
2 => ["HORDE", 1, 0, false, "Reputation-03"],
}
Levels = {
# ID => [NAME, EXP_TO_LVL, %_REDUCED_VALUE]
0 => ["HATED", -1, -100],
1 => ["UNKNOWN", 0, 0],
2 => ["NEUTRAL", 10, 0],
3 => ["FRIENDLY", 100, 0],
4 => ["HONORED", 1000, 10],
5 => ["REVERED", 10000, 25],
6 => ["EXALTED", 100000, 50],
}
Shops = {
# ID => [REP_ID, LEVEL_ID, ITEMSET_ID, WEAPONSET_ID, ARMORSET_ID]
0 => [0, 3, 0, 0, 0],
1 => [2, 2, 0, 0, 0],
2 => [1, 4, 0, 0, 0],
}
ItemSets = {
# ID => [ITEMS_IDs]
0 => [1, 2, 3, 4],
}
WeaponSets = {
# ID => [WEAPONS_IDs]
0 => [2, 5, 8],
}
ArmorSets = {
# ID => [ARMOR_IDs]
0 => [1, 10, 23],
}
end
#============================================================================
# GAME PARTY - DON'T TOUCH
#============================================================================
class Game_Party
# Variables
attr_accessor :reputations
attr_accessor :rep_levels
attr_accessor :rep_shops
attr_accessor :rep_itemsets
attr_accessor :rep_weaponsets
attr_accessor :rep_armorsets
# Aliasing
alias rep_initialize initialize
#Initialize Game_Party
def initialize
# Para acceder o modificar la variable
#$game_party.reputations[rep_id][index] = value
@reputations = REP_CONFIG::Reputations
@rep_levels = REP_CONFIG::Levels
@rep_shops = REP_CONFIG::Shops
@rep_itemsets = REP_CONFIG::ItemSets
@rep_weaponsets = REP_CONFIG::WeaponSets
@rep_armorsets = REP_CONFIG::ArmorSets
# Initialize old Game_Party
rep_initialize
end
end
#============================================================================
# WINDOW BASE - DON'T TOUCH
#============================================================================
class Window_Base
def hated_color
return Color.new(255, 36, 36, 255)
end
def neutral_color
return Color.new(250, 250, 36, 255)
end
def friendly_color
return Color.new(36, 255, 36, 255)
end
end
#============================================================================
# SYSTEM REPUTATION - DON'T TOUCH
#============================================================================
class System_Reputation
#============================================================================
# GET :
#============================================================================
# Reputation Name
def name(rep_id)
name = $game_party.reputations[rep_id][0]
end
# Reputation Level
def lvl(rep_id)
lvl = $game_party.reputations[rep_id][1]
end
# Reputation EXP
def exp(rep_id)
exp = $game_party.reputations[rep_id][2]
end
# Reputation active
def active?(rep_id)
active = $game_party.reputations[rep_id][3]
end
# Reputation Icon
def icon(rep_id)
icon = $game_party.reputations[rep_id][4]
end
#----------------------------------------------------------------------------
# Level Name
def lvl_name(lvl_id)
lvl_name = $game_party.rep_levels[lvl_id][0]
end
# Level Base Exp
def lvl_base_exp(lvl_id)
base_exp = $game_party.rep_levels[lvl_id][1]
end
# Level Reduce Price Value Percentage
def reduced_value(lvl_id)
percentage = $game_party.rep_levels[lvl_id][2]
end
#----------------------------------------------------------------------------
# Shop Reputation
def shop_rep(shop_id)
rep = $game_party.rep_shops[shop_id][0]
end
# Shop Level Needed
def shop_lvl_needed(shop_id)
lvl = $game_party.rep_shops[shop_id][1]
end
# Shop Item Set (Array)
def shop_itemset(shop_id)
id = $game_party.rep_shops[shop_id][2]
itemset = $game_party.rep_itemsets[id]
end
# Shop Weapon Set (Array)
def shop_weaponset(shop_id)
id = $game_party.rep_shops[shop_id][3]
weaponset = $game_party.rep_weaponsets[id]
return weaponset
end
# Shop Armor Set (Array)
def shop_armorset(shop_id)
id = $game_party.rep_shops[shop_id][4]
armorset = $game_party.rep_armorsets[id]
end
#============================================================================
# CHECKS :
#============================================================================
def rep_id?(string)
rep_ids = $game_party.reputations.keys
id = nil
for i in rep_ids
if exist?(i)
rep_name = name(i)
if rep_name == string
return i
end
end
end
end
# Reputation exists
def exist?(rep_id)
exist = $game_party.reputations.include?(rep_id)
end
# EXP to Level UP
def to_lvl?(rep_id)
if exist?(rep_id)
current_exp = exp(rep_id)
current_lvl = lvl(rep_id)
max_lvl = max_lvl?
if current_lvl >= max_lvl
next_lvl = current_lvl
else
next_lvl = current_lvl + 1
end
needed_exp = lvl_base_exp(next_lvl)
to_lvl = needed_exp - current_exp
return to_lvl
else
return nil
end
end
# Max Level
def max_lvl?
levels = $game_party.rep_levels.keys
temp = 0
for i in levels
if temp < i
temp = i
end
end
max_lvl = temp
end
# Is Max Level
def is_max_lvl?(rep_id)
if exist?(rep_id)
lvl = lvl(rep_id)
max_lvl = max_lvl?
if lvl == max_lvl
return true
else
return false
end
else
return false
end
end
# Can Shop
def can_shop?(shop_id)
rep_id = shop_rep(shop_id)
shop_lvl = shop_lvl_needed(shop_id)
rep_lvl = lvl(rep_id)
if rep_lvl >= shop_lvl
return true
end
return false
end
# Positive or Negative
def pos_or_neg(value)
if value > 0
return true
else
return false
end
end
#============================================================================
# SET :
#============================================================================
# Level Manager
def lvl_manager(rep_id)
if exist?(rep_id)
levels = $game_party.rep_levels.keys
levels = levels.sort
current_exp = exp(rep_id)
max_lvl = max_lvl?
max_exp = lvl_base_exp(max_lvl)
lvl = 0
if current_exp == max_exp
lvl = max_lvl
else
for i in levels
lvl_exp = lvl_base_exp(i)
if current_exp >= lvl_exp
lvl = i
end
end
end
$game_party.reputations[rep_id][1] = lvl
end
end
# Set Shop Goods
def shop_goods(shop_id)
shop_goods = []
itemset = shop_itemset(shop_id)
weaponset = shop_weaponset(shop_id)
armorset = shop_armorset(shop_id)
array = []
for id in itemset
array = [0, id]
shop_goods.push(array)
end
for id in weaponset
array = [1, id]
shop_goods.push(array)
end
for id in armorset
array = [2, id]
shop_goods.push(array)
end
return shop_goods
end
# Recalculates de Item Price
def recalculate_price(shop_id, price)
rep_id = shop_rep(shop_id)
min_lvl = shop_lvl_needed(shop_id)
rep_lvl = lvl(rep_id)
percentage = reduced_value(rep_lvl)
if rep_lvl >= min_lvl
value = (percentage * price) / 100
price -= value
return price
end
return price
end
end
#============================================================================
# WINDOW REP TITLE : Add
#============================================================================
class Window_Rep_Title < Window_Base
def initialize
super(40, 40, 560, 60)
@title = "REPUTATIONS"
draw_rep_title(@title, 180, 0)
end
def draw_rep_title(title, x, y)
if title == nil
return
end
bitmap = RPG::Cache.icon("Reputation-00")
self.contents = Bitmap.new(self.width - 32, self.height - 32)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
self.contents.draw_text(x + 28, y, 212, 32, title)
end
end
#============================================================================
# WINDOW REP DESCRIPTION : Add
#============================================================================
class Window_Rep_Description < Window_Base
def initialize
super(40, 380, 560, 60)
draw_lvl_description(rep_array = nil)
end
def draw_lvl_description(rep_array)
x = 0
y = 0
rep_id = 0
lvl = 1
exp = 0
to_lvl = 0
max_lvl = 1
lvl_name = "ERROR"
if rep_array != nil
reputation = System_Reputation.new
rep_id = rep_array[0]
lvl = reputation.lvl(rep_id)
exp = reputation.exp(rep_id)
to_lvl = reputation.to_lvl?(rep_id)
lvl_name = reputation.lvl_name(lvl)
max_lvl = reputation.max_lvl?
end
self.contents = Bitmap.new(self.width - 32, self.height - 32)
case lvl
when 0
self.contents.font.color = hated_color
when 1
self.contents.font.color = neutral_color
when 2
self.contents.font.color = neutral_color
end
if lvl > 2
self.contents.font.color = friendly_color
end
self.contents.draw_text(x, y, 140, 32, lvl_name)
self.contents.font.color = normal_color
self.contents.draw_text(x + 144, y, 140, 32, "EXP : " + exp.to_s)
if lvl == max_lvl
self.contents.draw_text(x + 284, y, 212, 32, "MAX LEVEL")
else
self.contents.draw_text(x + 284, y, 212, 32, "TO NEXT LEVEL: " + to_lvl.to_s)
end
end
end
#============================================================================
# WINDOW REP LIST : Add
#============================================================================
class Window_Rep_List < Window_Selectable
def initialize
super(40, 100, 560, 280)
@column_max = 2
refresh
self.index = 0
end
def rep
return @data[self.index]
end
def refresh
sys_rep = System_Reputation.new
if self.contents != nil
self.contents.dispose
self.contents = nil
end
# Add reputations to data
@data = []
temp = []
reputations = $game_party.reputations
for i in 0...reputations.keys.size
reputation = reputations[i]
if reputation != nil && sys_rep.active?(i)
temp = [i, reputation]
@data.push(temp)
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_rep_name(i)
end
end
end
def draw_rep_name(index)
sys_rep = System_Reputation.new
rep = @data[index]
rep_id = rep[0]
rep_name = sys_rep.name(rep_id)
lvl = sys_rep.lvl(rep_id)
if @data.empty? == true
rep_name = "Don't have reputations"
end
x = 4 + index % 2 * (248 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(sys_rep.icon(rep_id))
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), 255)
case lvl
when 0
self.contents.font.color = hated_color
when 1
self.contents.font.color = neutral_color
when 2
self.contents.font.color = neutral_color
end
if lvl > 2
self.contents.font.color = friendly_color
end
self.contents.draw_text(x + 28, y, 212, 32, rep_name, 0)
end
def update_help
@help_window.draw_lvl_description(self.rep == nil ? nil : self.rep)
end
end
#============================================================================
# SCENE REPUTATIONS :
#============================================================================
class Scene_Reputations
def start
@spriteset = Spriteset_Map.new
@window_rep_title = Window_Rep_Title.new
@window_rep_list = Window_Rep_List.new
@window_rep_description = Window_Rep_Description.new
@window_rep_list.help_window = @window_rep_description
end
def main
start
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@spriteset.dispose
@window_rep_title.dispose
@window_rep_list.dispose
@window_rep_description.dispose
end
def update
@window_rep_list.update
@window_rep_description.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
end
end
#============================================================================
# INTERPRETER : Adds to the class
#============================================================================
class Interpreter
# Reputation Gain EXP
def add_rep_exp(rep_id, value=0)
sys_rep = System_Reputation.new
if sys_rep.exist?(rep_id)
current_exp = sys_rep.exp(rep_id)
if sys_rep.pos_or_neg(value)
new_exp = current_exp + value
max_lvl = sys_rep.max_lvl?
max_exp = sys_rep.lvl_base_exp(max_lvl)
if new_exp > max_exp
$game_party.reputations[rep_id][2] = max_exp
sys_rep.lvl_manager(rep_id)
else
$game_party.reputations[rep_id][2] = new_exp
sys_rep.lvl_manager(rep_id)
end
if sys_rep.active?(rep_id) == false
$game_party.reputations[rep_id][3] = true
end
end
end
end
# Reputation Reduce EXP
def remove_rep_exp(rep_id, value=0)
sys_rep = System_Reputation.new
if sys_rep.exist?(rep_id)
current_exp = sys_rep.exp(rep_id)
if sys_rep.pos_or_neg(value)
new_exp = current_exp - value
$game_party.reputations[rep_id][2] = new_exp
sys_rep.lvl_manager(rep_id)
if sys_rep.active?(rep_id) == false
$game_party.reputations[rep_id][3] = true
end
end
end
end
# Can Shop
def can_shop?(shop_id)
sys_rep = System_Reputation.new
rep_id = sys_rep.shop_rep(shop_id)
shop_lvl = sys_rep.shop_lvl_needed(shop_id)
rep_lvl = sys_rep.lvl(rep_id)
if rep_lvl >= shop_lvl
return true
end
return false
end
# Call Custom Shop (shop_id)
def call_custom_shop(shop_id)
sys_rep = System_Reputation.new
$game_temp.shop_goods = sys_rep.shop_goods(shop_id)
$scene = Scene_Shop.new(shop_id)
end
end
#============================================================================
# SCENE SHOP : Edit
#============================================================================
class Scene_Shop
def initialize(shop_id = nil)
@shop_id = shop_id
end
alias rep_main main
def main
@help_window = Window_Help.new
@command_window = Window_ShopCommand.new
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 64
@dummy_window = Window_Base.new(0, 128, 640, 352)
@buy_window = Window_ShopBuy.new($game_temp.shop_goods, @shop_id)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
@sell_window = Window_ShopSell.new
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
@number_window = Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
@status_window = Window_ShopStatus.new
@status_window.visible = false
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@sell_window.dispose
@number_window.dispose
@status_window.dispose
end
alias rep_update_buy update_buy
def update_buy
@status_window.item = @buy_window.item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
if @shop_id != nil
sys_rep = System_Reputation.new
new_price = sys_rep.recalculate_price(@shop_id, @item.price)
if @item == nil or new_price > $game_party.gold
$game_system.se_play($data_system.buzzer_se)
return
end
else
if @item == nil or @item.price > $game_party.gold
$game_system.se_play($data_system.buzzer_se)
return
end
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @shop_id != nil
max = new_price == 0 ? 99 : $game_party.gold / new_price
max = [max, 99 - number].min
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, new_price)
else
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number].min
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, @item.price)
end
@number_window.active = true
@number_window.visible = true
end
end
end
#============================================================================
# WINDOW SHOPBUY : Edit
#============================================================================
class Window_ShopBuy
alias rep_initialize initialize
def initialize(shop_goods, shop_id = nil)
rep_initialize(shop_goods)
@shop_id = shop_id
end
alias rep_draw_item draw_item
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if @shop_id != nil
sys_rep = System_Reputation.new
new_price = sys_rep.recalculate_price(@shop_id, item.price)
if new_price <= $game_party.gold && number < 99
if new_price != item.price
self.contents.font.color = friendly_color
else
self.contents.font.color = normal_color
end
else
self.contents.font.color = disabled_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
if new_price != item.price
opacity = self.contents.font.color == friendly_color ? 255 : 128
else
opacity = self.contents.font.color == normal_color ? 255 : 128
end
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 88, 32, new_price.to_s, 2)
else
if item.price <= $game_party.gold && number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
end
end
end