#------------------------------------------------------------------------------#
# Name: Achievements #
# By: SojaBird #
# Version: 2.2 (+lesser mods by Leongon) #
# i #
# Date: 21-08-09 #
#------------------------------------------------------------------------------#
$imported = {} if $imported == nil
$imported["SojaBird_Achievements"] = true
#---------------------#----------------#
# Condition List : comparison # (all can serve as conditional branch)
#---------------------#----------------#
# - completed : >=, <=, ==, != # ('get_completed' in conditional branch)
# - completed(list) : true, false # ('get_completed' in conditional branch)
# - item(item_id) : >=, <=, ==, != #
# - weapon(weapon_id) : >=, <=, ==, != #
# - armor(armor_id) : >=, <=, ==, != #
# - var(variable_id) : >=, <=, ==, != #
# - switch(switch_id) : true, false #
# - gold : >=, <=, ==, != #
# - lvl(actor_id) : >=, <=, ==, != # (if actor_id == -1, highest of members)
# - exp(actor_id) : >=, <=, ==, != # (if actor_id == -1, highest of members)
# - points : >=, <=, ==, != # ('get_points' in conditional branch)
#---------------------#----------------#
# (true/false in combo with == or !=) #
#--------------------------------------#
#------------------------------#----------#
# Reward List : *default #
#------------------------------#----------#
# - item(item_id, *amount) : 1 #
# - weapon(weapon_id, *amount) : 1 #
# - armor(armor_id, *amount) : 1 #
# - var(variable_id, *amount) : 1 #
# - switch(switch_id, *value) : toggle #
# - gold(amount) : #
# - lvl(actor_id, amount) : # (if actor_id == -1, all members)
# - exp(actor_id, amount) : # (if actor_id == -1, all members)
#------------------------------#----------#
#----------------------------------#--------------------#
# Scene Calls : *default #
#----------------------------------#--------------------#
# - Achief.call(*return_map) : false #
# - Achief.call_shop(*reveal_cost) : Common_Reveal_Cost #
#----------------------------------#--------------------#
#----------------------#
# Configuration module #
#----------------------#
module SojaBird_Achievements
#-------#
# Menu: #
#-------#
Menu_Location = 4
Menu_Title = "Achievements"
Menu_Counting = true
#---------------------#
# Achievements scene: #
#---------------------#
Scroll_Speed = 5
Border_Size = 5
#----------------------Simple mods by Leongon--------------------#
# - Setup - #
Border_R = 0 #Leongon, set list frame color R.
Border_G = 0 #Leongon, set list frame color G.
Border_B = 0 #Leongon, set list frame color B.
Border_A = 255 #Leongon, set list frame color Opacity.
Fill_R = 0 #Leongon, set list fill color R.
Fill_G = 200 #Leongon, set list fill color G.
Fill_B = 255 #Leongon, set list fill color B.
Fill_A = 100 #Leongon, set list fill color Opacity.
Title_Sizef = 20 #Leongon, set list title size.
Description_Sizef = 14 #Leongon, set list description size.
#----------------------------------------------------------------#
Auto_Scroll = true
Auto_Scroll_Speed = 0.1
Time_Span = 4
Status_Text = "Completed: %s"
#----------------------#
# Hidden achievements: #
#----------------------#
Hidden_Title = "???"
Hidden_Description = "Secrets beyond..."
Hidden_Icon = 152
#----------------------#
# Achievements alerts: #
#----------------------#
module SE_Found
Name = "Bell"
Volume = 50
Pitch = 0
end
module SE_Complete
Name = "Applause"
Volume = 50
Pitch = 0
end
# normal/up/down
alert_Display = "up"
alert_Opacity = 200
# left/center/right
alert_Position = "center"
alert_Width = 300
alert_Reward_Width = 544
alert_Font_Size = 16
Complete_Text = "Achievement '%s' was completed!"
Reward_Text = "You've gained %s!"
Find_Text = "Achievement '%s' was found!"
Hidden_Found = "You found a hidden achievement!"
# for normal display
Time_Span_Text = 4
Display_StartUps = true
Reward_Prototype = true
#--------------------#
# Message points-tag #
#--------------------#
Message_Tag = "AP"
#--------------#
# Point system #
#--------------#
Use_Point_System = true
Point_Name = "point"
Point_Font_Size = 12
Shop_Buy = "Buy"
Shop_Reveal = "Reveal"
Common_Reveal_Cost = 5
#-----------#
# Start-up: #
#-----------#
Start_Achievements = [
#[Name, Description, Icon, Hidden, Hide_Icon, Completed]
]
Start_Buyables = [
#[Price, Name, Description, Icon]
]
Start_Conditions = [
#[Name, Condition]
]
Start_Rewards = [
#[Name, Reward]
]
Start_Points = [
#[Name, Points]
]
end
#-------------#
# Module: End #
#-------------#
#--------------------#
# Call-script module #
#--------------------#
module Achief
#--------------------------------------------------------------------------#
# Achief.new(name, description, *icon, *hidden, *hide_icon, *completed) #
# - name: Name of the achievement (string) #
# - description: Descripition of the achievement (string) #
# - icon: Icon-id of icon for the achievement (number) #
# - hidden: Hide the whole achievement? (boolean) #
# - hide_icon: Hide the icon? (boolean) #
# - completed: Check the achievement to be completed (boolean) #
#--------------------------------------------------------------------------#
def self.new(name,
description,
icon = 0,
hidden = false,
hide_icon = hidden,
completed = false)
name.gsub!(/\n/) {""}
description.gsub!(/\n/) {""}
if completed
hidden = false
hide_icon = false
end
return if !self.achievement(name).nil?
for index in 0..999
if $game_system.achievements[index].nil?
break $game_system.achievements[index] = Achievement.new(
name, description, icon, hidden, hide_icon, completed)
end
end
end
#--------------------------------------------------------------------------#
# Achief.new_buyable(price, name, description, *icon) #
# - price: Price to buy the achievement (number) #
# - name: Name of the achievement (string) #
# - description: Descripition of the achievement (string) #
# - icon: Icon-id of icon for the achievement (number) #
#--------------------------------------------------------------------------#
def self.new_buyable(price, name, description, icon = 0)
name.gsub!(/\n/) {""}
description.gsub!(/\n/) {""}
return if !self.achievement_buyable(name).nil?
for index in 0..999
if $game_system.achief_buyables[index].nil?
break $game_system.achief_buyables[index] = Achievement_Buyable.new(
price, name, description, icon)
end
end
end
#--------------------------------------------------------------------------#
# Achief.del(name) #
# - name: Name of the achievement (string) #
#--------------------------------------------------------------------------#
def self.del(name)
name.gsub!(/\n/) {""}
return if self.achievement(name).nil?
$game_system.achievements.delete(self.achievement(name, true))
end
#--------------------------------------------------------------------------#
# Achief.hidden(name, *value) #
# - name: Name of the achievement (string) #
# - value: New value of the parameter (boolean) #
#--------------------------------------------------------------------------#
def self.hidden(name, value = false)
name.gsub!(/\n/) {""}
achief = self.achievement(name)
return if achief.nil?
achief.hidden = value
end
#--------------------------------------------------------------------------#
# Achief.hide_icon(name, *value) #
# - name: Name of the achievement (string) #
# - value: New value of the parameter (boolean) #
#--------------------------------------------------------------------------#
def self.hide_icon(name, value = false)
name.gsub!(/\n/) {""}
achief = self.achievement(name)
return if achief.nil?
achief.hide_icon = value
end
#--------------------------------------------------------------------------#
# Achief.completed(name, *value) #
# - name: Name of the achievement (string) #
# - value: New value of the parameter (boolean) #
#--------------------------------------------------------------------------#
def self.completed(name, value = true)
name.gsub!(/\n/) {""}
achief = self.achievement(name)
return if achief.nil?
achief.completed = value
if value
self.hidden(name, false)
self.hide_icon(name, false)
self.gain_reward(name) if !achief.rewarded
self.gain_points(name) if !achief.points_gained and
SojaBird_Achievements::Use_Point_System
end
end
#--------------------------------------------------------------------------#
# Achief.condition(name, condition) #
# - name: Name of the achievement (string) #
# - condition: Set the condition when to complete a achievement (string) #
#--------------------------------------------------------------------------#
def self.condition(name, condition)
name.gsub!(/\n/) {""}
achief = self.achievement(name)
achief = self.achievement_buyable(name) if achief.nil?
return if achief.nil?
condition.gsub!(/\n/) {""}
listener = Completion_Listener.new(condition)
achief.completion_listener = listener
end
#--------------------------------------------------------------------------#
# Achief.reward(name, reward) #
# - name: Name of the achievement (string) #
# - condition: Set the reward that's gain when completed (string) #
#--------------------------------------------------------------------------#
def self.reward(name, reward)
name.gsub!(/\n/) {""}
achief = self.achievement(name)
achief = self.achievement_buyable(name) if achief.nil?
return if achief.nil?
reward.gsub!(/\n/) {""}
achief.reward = reward
end
#--------------------------------------------------------------------------#
# Achief.points(name, amount) #
# - name: Name of the achievement (string) #
# - amount: Amount of points gained when completing (number) #
#--------------------------------------------------------------------------#
def self.points(name, amount)
achief = self.achievement(name)
achief = self.achievement_buyable(name) if achief.nil?
return if achief.nil?
achief.points = amount
end
#--------------------------------------------------------------------------#
# Achief.all_achievements(param, new_value) #
# - param: Parameter to change for all achievements (string) #
# - new_value: New value of the parameters (depends on parameter) #
#--------------------------------------------------------------------------#
def self.all_achievements(param, new_value)
$game_system.achievements.each_value do |value|
next if self.achievement(value.name).nil?
eval("self.#{param}(\"#{value.name}\", #{new_value})")
end
$game_system.achief_buyables.each_value do |value|
next if self.achievement(value.name).nil?
eval("self.#{param}(\"#{value.name}\", #{new_value})")
end
end
end
#-------------#
# Module: End #
#-------------#
#---------------------------#
# Achievements ENGINE class #
#---------------------------#
class Scene_Achievements < Scene_Base
include SojaBird_Achievements
def initialize(return_map = false)
@return_map = return_map
end
def start
super
create_menu_background
create_achievements
new_open_time
scroll_dir
end
def create_achievements
@achievements = Window_Achievements.new
if Use_Point_System
x, y, width = 0, Graphics.height - 56, Graphics.width
@point_system = Window_Point_Currency.new(0, y, width)
end
end
def new_open_time
@open_time = Graphics.frame_count
end
def scroll_dir
@dir = "down"
end
def terminate
super
dispose_menu_background
dispose_achievements
end
def dispose_achievements
@achievements.dispose
@point_system.dispose if Use_Point_System
end
def update
super
update_menu_background
update_achievements
end
def update_achievements
auto_scroll if Auto_Scroll
scroll_up if Input.press?(Input::UP)
scroll_down if Input.press?(Input::DOWN)
return_scene if Input.trigger?(Input::B)
new_open_time if break_time_span
end
def auto_scroll
time_span = (Graphics.frame_count - @open_time) / Graphics.frame_rate
loop_scroll if time_span >= Time_Span
end
def loop_scroll
@dir = "up" if @achievements.oy == @achievements.contents.height -
@achievements.height + 32
@dir = "down" if @achievements.oy == 0
case @dir
when "up"
until (@achievements.oy <= 0 or break_time_span)
scroll_up(Auto_Scroll_Speed)
Graphics.wait(1)
Input.update
end
if @achievements.oy >= 0
new_open_time
@dir = "down"
end
when "down"
until (@achievements.oy >= @achievements.contents.height -
@achievements.height + 32 or break_time_span)
scroll_down(Auto_Scroll_Speed)
Graphics.wait(1)
Input.update
end
if @achievements.oy <= @achievements.contents.height -
@achievements.height + 32
new_open_time
@dir = "up"
end
end
end
def break_time_span
return (Input.trigger?(Input::B) or
Input.press?(Input::UP) or
Input.press?(Input::DOWN))
end
def scroll_up(speed = Scroll_Speed)
for go in 0..speed
@achievements.oy -= 1 if @achievements.oy > 0
end
end
def scroll_down(speed = Scroll_Speed)
for go in 0..speed
@achievements.oy += 1 if @achievements.oy < @achievements.contents.height-
@achievements.height + 32
end
end
def return_scene
Sound.play_cancel
if @return_map
$game_temp.next_scene = nil
$scene = Scene_Map.new
else
begin
super(Menu_Title)
rescue
$scene = Scene_Menu.new(4)
end
end
end
end
#-------------------------#
# Scene_Achievements: End #
#-------------------------#
#-------------------------#
# Achievements shop class #
#-------------------------#
class Scene_Achievements_Shop < Scene_Base
include SojaBird_Achievements
def initialize(reveal_price = Common_Reveal_Cost)
@reveal_price = reveal_price
end
def start
super
create_menu_background
create_command_window
# Windows
@help_window = Window_Help.new
@point_window = Window_Point_Currency.new(384, 56, 160, true)
@dummy_window = Window_Base.new(0, 112, Graphics.width, 304)
@buy_window = Window_Achievements_Buy.new(0, 112)
@reveal_window = Window_Achievements_Reveal.new(@reveal_price,
0, 112, Graphics.width, 304)
# Active
@buy_window.active = false
@reveal_window.active = false
# Visible
@buy_window.visible = false
@reveal_window.visible = false
# Help-window
@buy_window.help_window = @help_window
@reveal_window.help_window = @help_window
end
def terminate
super
dispose_menu_background
dispose_command_window
@help_window.dispose
@point_window.dispose
@dummy_window.dispose
@buy_window.dispose
@reveal_window.dispose
end
def return_scene
$game_temp.next_scene = nil
$scene = Scene_Map.new
end
def update
super
update_menu_background
@help_window.update
@command_window.update
@point_window.update
@dummy_window.update
@buy_window.update
@reveal_window.update
if @command_window.active; update_command_selection
elsif @buy_window.active; update_buy_selection
elsif @reveal_window.active; update_reveal_selection
end
end
def create_command_window
s1 = Shop_Buy
s2 = Shop_Reveal
s3 = Vocab::ShopCancel
@command_window = Window_Command.new(384, [s1, s2, s3], 3)
@command_window.y = 56
end
def dispose_command_window
@command_window.dispose
end
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
Sound.play_decision
case @command_window.index
when 0 #Buy
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
when 1 #Reveal
@command_window.active = false
@dummy_window.visible = false
@reveal_window.active = true
@reveal_window.visible = true
@reveal_window.refresh
when 2; return_scene #Cancel
end
end
end
def buy_achievement(item)
$game_system.achief_points -= item.price
Achief.new(item.name, item.description, item.icon)
cl = item.completion_listener
Achief.condition(item.name, cl.condition) if !cl.nil?
Achief.reward(item.name, item.reward) if !item.reward.nil?
Achief.points(item.name, item.points) if !item.points.nil?
buyable = $game_system.achief_buyables
buyable.delete(buyable.index(item))
end
def reveal_achievement(item)
$game_system.achief_points -= @reveal_price
Achief.hidden(item.name)
Achief.hide_icon(item.name)
end
def update_buy_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
if @item == nil or @item.price > $game_system.achief_points
Sound.play_buzzer
else
Sound.play_shop
buy_achievement(@item)
@point_window.refresh
@buy_window.refresh
end
end
end
def update_reveal_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@command_window.active = true
@dummy_window.visible = true
@reveal_window.active = false
@reveal_window.visible = false
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @reveal_window.item
if @item == nil or @reveal_price > $game_system.achief_points
Sound.play_buzzer
else
Sound.play_shop
reveal_achievement(@item)
@point_window.refresh
@reveal_window.refresh
end
end
end
end
#------------------------------#
# Scene_Achievements_Shop: End #
#------------------------------#
#----------------------------#
# Achievements DISPLAY class #
#----------------------------#
class Window_Achievements < Window_Base
include SojaBird_Achievements
def initialize
height = Use_Point_System ? Graphics.height - (32 + WLH) : Graphics.height
super(0, 0, Graphics.width, height)
@font_size = self.contents.font.size
refresh
end
def refresh
self.contents.clear
@border = 16
@achievement_height = 2 * WLH + 2 * @border
@line_size = Border_Size
@line_size = 16 if @line_size > @border
@icon_difference = 48
height = $game_system.achievements.size * @achievement_height
height = 32 if height == 0
self.contents = Bitmap.new(Graphics.width - 32, height)
draw_contents
end
def draw_contents
index = 0
$game_system.achievements.keys.sort!.each do |key|
value = $game_system.achievements[key]
icon = value.hide_icon ? Hidden_Icon : value.icon
draw_achievement(index, value, icon)
index += 1
end
end
def draw_achievement(index, achief, icon)
name = achief.name
description = achief.description
completed = achief.completed
if achief.hidden
name = Hidden_Title
description = Hidden_Description
completed = false
end
color = Color.new(Border_R, Border_G, Border_B, Border_A) #Simple mods by Leongon
rect = Rect.new(0,
@achievement_height * index,
self.contents.width,
@achievement_height)
self.contents.fill_rect(rect, color)
rect.x += 1 * @line_size
rect.y += 1 * @line_size
rect.width -= 2 * @line_size
rect.height -= 1 * @line_size
rect.height -= 1 * @line_size if index == $game_system.achievements.size - 1
color = Color.new(Fill_R, Fill_G, Fill_B, Fill_A) #Simple mods by Leongon
self.contents.fill_rect(rect, color)
self.contents.font.size = Title_Sizef #Simple mods by Leongon
self.contents.font.bold = true
self.contents.font.color.alpha = completed ? 255 : 128
self.contents.draw_text(@icon_difference,
@achievement_height * index + @border,
self.contents.width - @icon_difference - @border,
WLH,
name)
self.contents.font.size = Description_Sizef #Simple mods by Leongon
self.contents.font.bold = false
self.contents.draw_text(@icon_difference,
@achievement_height * index + WLH + @border,
self.contents.width - @icon_difference - @border,
WLH,
description)
draw_icon(icon,
@border,
@achievement_height * index + 12 + @border,
completed)
if Use_Point_System and !achief.hidden
self.contents.font.size = Point_Font_Size
points = achief.points
return if points == 0
custom = "#{Point_Name}#{points.abs != 1 ? "s" : ""}"
points = sprintf("%s %s", points, custom)
self.contents.draw_text(0,
@achievement_height * index,
self.contents.width - (@border / 2),
WLH,
points,
2)
end
end
end
#--------------------------#
# Window_Achievements: End #
#--------------------------#
#-----------------------#
# alerts display-window #
#-----------------------#
class Window_Achievement_Display < Window_Base
include SojaBird_Achievements
attr_reader :disp
attr_reader :start_control
attr_reader :close_control
attr_reader :delete
def initialize(achief, type)
@achief = achief
@type = type
@type = "c" if @type == "c+r" and reward.size < 1
@disp = alert_Display
lines = 1
lines = 2 if @type == "c+r"
width = alert_Width
width = alert_Reward_Width if @type == "c+r"
height = WLH + (32 * lines)
case alert_Position
when "left"; x = 0
when "center"; x = (Graphics.width / 2) - (width / 2)
when "right"; x = Graphics.width - width
end
y = next_open_spot(height)
super(x, y, width, height)
self.openness = 0
self.opacity = alert_Opacity
@start_control = false
@close_control = false
@delete = false
@wait_count = (Time_Span_Text * 60)
refresh
case @type
when "f"
if SE_Found::Name != ""
Audio.se_play("Audio/SE/#{SE_Found::Name}",
SE_Found::Volume,
SE_Found::Pitch)
end
else
if SE_Found::Name != ""
Audio.se_play("Audio/SE/#{SE_Complete::Name}",
SE_Complete::Volume,
SE_Complete::Pitch)
end
end
end
def next_open_spot(height)
case @disp
when "normal"
list = [0]
$game_system.achief_alerts.each do |alert|
list.push(alert.y + alert.height) if alert.disp == "normal"
end
return (list.max)
when "up"
list = [Graphics.height]
$game_system.achief_alerts.each do |alert|
list.push(alert.y + alert.height) if alert.disp == "up"
end
return (list.max)
when "down"
list = [-height]
$game_system.achief_alerts.each do |alert|
list.push(alert.y - height) if alert.disp == "down"
end
return (list.min)
end
end
def refresh
self.contents.clear
draw_achievement
end