class Game_Bank
attr_reader :gold # amount of gold
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@gold = 0
@items = {}
@weapons = {}
@armors = {}
end
def get_interest
i = rand(5000)
if i == 0
j = ($game_bank.gold * 0.025).to_i
$game_bank.gain_gold(j)
end
end
def item_number(item_id)
return @items.include?(item_id) ? @items[item_id] : 0
end
def weapon_number(weapon_id)
return @weapons.include?(weapon_id) ? @weapons[weapon_id] : 0
end
def armor_number(armor_id)
return @armors.include?(armor_id) ? @armors[armor_id] : 0
end
def gain_gold(n)
@gold = [[@gold + n, 0].max, 99999999].min
end
def lose_gold(n)
gain_gold(-n)
end
def gain_item(item_id, n)
if item_id > 0
@items[item_id] = [[item_number(item_id) + n, 0].max, 999].min
end
end
def gain_weapon(weapon_id, n)
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 999].min
end
end
def gain_armor(armor_id, n)
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 999].min
end
end
def lose_item(item_id, n)
gain_item(item_id, -n)
end
def lose_weapon(weapon_id, n)
gain_weapon(weapon_id, -n)
end
def lose_armor(armor_id, n)
gain_armor(armor_id, -n)
end
end
class Window_UserGold < Window_Base
def initialize
super(440, 320, 200, 96)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 158, 32, "User Gold :", 1)
self.contents.draw_text(4, 32, 158-cx-2, 32, $game_party.gold.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(162-cx, 32, cx, 32, $data_system.words.gold, 2)
end
end
class Window_BankGold < Window_Base
def initialize
super(240, 320, 200, 96)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 158, 32, "Bank Gold :", 1)
self.contents.draw_text(4, 32, 158-cx-2, 32, $game_bank.gold.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(162-cx, 32, cx, 32, $data_system.words.gold, 2)
end
end
class Window_BankNumber < Window_Base
def initialize
dummy_bitmap = Bitmap.new(32, 32)
@cursor_width = dummy_bitmap.text_size("0").width
@huh = 200 - @cursor_width
dummy_bitmap.dispose
super(0, 0, 240, 96)
self.contents = Bitmap.new(width - 32, height - 32)
end
def digits_max(gold)
@number = 0
@index = 0
case gold
when 1000000..9999999
@digits_max = 7
when 100000..999999
@digits_max = 6
when 10000..99999
@digits_max = 5
when 1000..9999
@digits_max = 4
when 100..999
@digits_max = 3
when 10..99
@digits_max = 2
when 0..9
@digits_max = 1
end
@max = gold
refresh
update_cursor_rect
end
def number
return @number
end
def update_cursor_rect
self.cursor_rect.set(193 - (@index * @cursor_width), 32, @cursor_width, 32)
end
def update
super
if self.active
if Input.repeat?(Input::RIGHT) and @index > 0
$game_system.se_play($data_system.cursor_se)
@index -= 1
refresh
end
if Input.repeat?(Input::LEFT) and @index < @digits_max - 1
$game_system.se_play($data_system.cursor_se)
@index += 1
refresh
end
if Input.repeat?(Input::UP) and @number < @max
$game_system.se_play($data_system.cursor_se)
@number = [@number + (10**(@index)), @max].min
refresh
end
if Input.repeat?(Input::DOWN) and @number > 0
$game_system.se_play($data_system.cursor_se)
@number = [@number - (10**(@index)), 0].max
refresh
end
end
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4,0,200,32,"Masukkan jumlahnya :", 1)
self.contents.draw_text(4,32,200,32,@number.to_s,2)
update_cursor_rect
end
end
class Window_ItemCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 64, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 3
@column_max = 3
@commands = ["Simpan", "Ambil", "Kembali"]
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
x = 4 + index * 215
self.contents.draw_text(x, 0, 128, 32, @commands[index])
end
end
class Window_ItemBank < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 128, 640, 352)
@column_max = 2
self.index = 0
end
def set(id)
@id = id
refresh
end
#--------------------------------------------------------------------------
# * Getting Items
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if @id == "deposit"
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
elsif @id == "collect"
if $game_bank.item_number(i) > 0
@data.push($data_items[i])
end
end
end
for i in 1...$data_weapons.size
if @id == "deposit"
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
elsif @id == "collect"
if $game_bank.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
end
for i in 1...$data_armors.size
if @id == "deposit"
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
elsif @id == "collect"
if $game_bank.armor_number(i) > 0
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bitmap and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
if @id == "deposit"
number = $game_party.item_number(item.id)
elsif @id == "collect"
number = $game_bank.item_number(item.id)
end
when RPG::Weapon
if @id == "deposit"
number = $game_party.weapon_number(item.id)
elsif @id == "collect"
number = $game_bank.weapon_number(item.id)
end
when RPG::Armor
if @id == "deposit"
number = $game_party.armor_number(item.id)
elsif @id == "collect"
number = $game_bank.armor_number(item.id)
end
end
x = 4 + index % 2 * (288 + 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(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), 255)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 232, y, 48, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
class Scene_Bank
def main
@spritesetmap = Spriteset_Map.new
@help_window = Window_Help.new
@help_window.visible = false
s1 = "Bank"
s2 = "Simpan Barang"
s3 = "Exit"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 240 - @command_window.height / 2
g1 = "Simpan"
g2 = "Ambil"
g3 = "Kembali"
@goldcommand_window = Window_Command.new(240, [g1, g2, g3])
@goldcommand_window.y = 288
@goldcommand_window.active = false
@goldcommand_window.visible = false
@itemcommand_window = Window_ItemCommand.new
@itemcommand_window.active = false
@itemcommand_window.visible = false
@itembank_window = Window_ItemBank.new
@itembank_window.visible = false
@itembank_window.active = false
@itembank_window.help_window = @help_window
@dummy_window = Window_Base.new(0, 128, 640, 352)
@dummy_window.visible = false
@usergold_window = Window_UserGold.new
@usergold_window.visible = false
@bankgold_window = Window_BankGold.new
@bankgold_window.visible = false
@number_window = Window_BankNumber.new
@number_window.active = false
@number_window.visible = false
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@spritesetmap.dispose
@help_window.dispose
@itembank_window.dispose
@dummy_window.dispose
@command_window.dispose
@itemcommand_window.dispose
@goldcommand_window.dispose
@usergold_window.dispose
@bankgold_window.dispose
@number_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@command_window.update
@itemcommand_window.update
@goldcommand_window.update
@usergold_window.update
@itembank_window.update
@dummy_window.update
@bankgold_window.update
@number_window.update
if @command_window.active
update_command
return
end
if @goldcommand_window.active
update_gold
return
end
if @itemcommand_window.active
update_item
return
end
if @number_window.active
update_number
return
end
if @itembank_window.active
update_itembank
return
end
end
def update_help(id)
case id
when 1
i = rand(3)
case i
when 0
text = "Ada biaya administrasi 10% setiap kali kamu menyimpan uang."
when 1
text = "Kamu akan mendapat bunga 2,5%, seiringnya berjalannya waktu"
when 2
text = "Bank ini adalah bank paling aman di dunia, uang kamu ga akan ilang"
end
when 2
text = "Mau nyimpen berapa duit?"
when 3
text = "Masukin jumlah yang mau di ambil."
when 4
text = "Kami bisa bantu menyimpan barang-barang kamu..."
end
@help_window.set_text(text,1)
end
def update_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0 # gold
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@command_window.visible = false
@goldcommand_window.visible = true
@goldcommand_window.active = true
@usergold_window.visible = true
@bankgold_window.visible = true
update_help(1)
@help_window.x = 0
@help_window.y = 416
@help_window.visible = true
when 1 # item
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@command_window.visible = false
@itemcommand_window.active = true
@itemcommand_window.visible = true
@dummy_window.visible = true
update_help(4)
@help_window.x = 0
@help_window.y = 0
@help_window.visible = true
when 2 # Exit
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
end
return
end
end
def update_gold
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@goldcommand_window.visible = false
@goldcommand_window.active = false
@command_window.visible = true
@command_window.active = true
@help_window.visible = false
@usergold_window.visible = false
@bankgold_window.visible = false
return
end
if Input.trigger?(Input::C)
case @goldcommand_window.index
when 0 # deposit
$game_system.se_play($data_system.decision_se)
@goldcommand_window.visible = false
@goldcommand_window.active = false
@number_window.digits_max($game_party.gold.to_i)
@number_window.visible = true
@number_window.active = true
@number_window.x = 0
@number_window.y = 320
@item_id = false
update_help(2)
when 1 #collect
$game_system.se_play($data_system.decision_se)
@goldcommand_window.visible = false
@goldcommand_window.active = false
@number_window.digits_max($game_bank.gold.to_i)
@number_window.visible = true
@number_window.active = true
@number_window.x = 0
@number_window.y = 320
@item_id = false
update_help(3)
when 2 # back
$game_system.se_play($data_system.decision_se)
@goldcommand_window.visible = false
@goldcommand_window.active = false
@command_window.visible = true
@command_window.active = true
@help_window.visible = false
@usergold_window.visible = false
@bankgold_window.visible = false
end
return
end
end
def update_number
if @item_id == true
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@itemcommand_window.active = true
@itembank_window.active = false
@itembank_window.visible = false
@number_window.visible = false
@number_window.active = false
@dummy_window.visible = true
update_help(4)
return
end
if Input.trigger?(Input::C)
case @itemcommand_window.index
when 0 # deposit
$game_system.se_play($data_system.shop_se)
@itembank_window.active = true
@itembank_window.visible = true
case @item
when RPG::Item
if $game_bank.item_number(@item.id) + @number_window.number < 999
$game_bank.gain_item(@item.id, @number_window.number)
$game_party.lose_item(@item.id, @number_window.number)
else
i = $game_bank.item_number(@item.id) + @number_window.number - 999
$game_bank.gain_item(@item.id, @number_window.number)
$game_party.lose_item(@item.id, @number_window.number)
$game_party.gain_item(@item.id, i)
end
when RPG::Weapon
if $game_bank.weapon_number(@item.id) + @number_window.number < 999
$game_bank.gain_weapon(@item.id, @number_window.number)
$game_party.lose_weapon(@item.id, @number_window.number)
else
i = $game_bank.weapon_number(@item.id) + @number_window.number - 999
$game_bank.gain_weapon(@item.id, @number_window.number)
$game_party.lose_weapon(@item.id, @number_window.number)
$game_party.gain_weapon(@item.id, i)
end
when RPG::Armor
if $game_bank.armor_number(@item.id) + @number_window.number < 999
$game_bank.gain_armor(@item.id, @number_window.number)
$game_party.lose_armor(@item.id, @number_window.number)
else
i = $game_bank.armor_number(@item.id) + @number_window.number - 999
$game_bank.gain_armor(@item.id, @number_window.number)
$game_party.lose_armor(@item.id, @number_window.number)
$game_party.gain_armor(@item.id, i)
end
end
@itembank_window.refresh
@number_window.visible = false
@number_window.active = false
update_help(4)
when 1 #collect
$game_system.se_play($data_system.shop_se)
@itembank_window.active = true
@itembank_window.visible = true
case @item
when RPG::Item
if $game_party.item_number(@item.id) + @number_window.number < 99
$game_bank.lose_item(@item.id, @number_window.number)
$game_party.gain_item(@item.id, @number_window.number)
else
i = $game_party.item_number(@item.id) + @number_window.number - 99
$game_bank.lose_item(@item.id, @number_window.number)
$game_bank.gain_item(@item.id, i)
$game_party.gain_item(@item.id, @number_window.number)
end
when RPG::Weapon
if $game_party.weapon_number(@item.id) + @number_window.number < 99
$game_bank.lose_weapon(@item.id, @number_window.number)
$game_party.gain_weapon(@item.id, @number_window.number)
else
i = $game_party.weapon_number(@item.id) + @number_window.number - 99
$game_bank.lose_weapon(@item.id, @number_window.number)
$game_bank.gain_weapon(@item.id, i)
$game_party.gain_weapon(@item.id, @number_window.number)
end
when RPG::Armor
if $game_party.armor_number(@item.id) + @number_window.number < 99
$game_bank.lose_armor(@item.id, @number_window.number)
$game_party.gain_armor(@item.id, @number_window.number)
else
i = $game_party.armor_number(@item.id) + @number_window.number - 99
$game_bank.lose_armor(@item.id, @number_window.number)
$game_bank.gain_armor(@item.id, i)
$game_party.gain_armor(@item.id, @number_window.number)
end
end
@itembank_window.refresh
@number_window.visible = false
@number_window.active = false
update_help(4)
when 2 # Exit
$game_system.se_play($data_system.decision_se)
@itemcommand_window.active = true
@itembank_window.active = false
@itembank_window.visible = false
@dummy_window.visible = true
@number_window.visible = false
@number_window.active = false
update_help(4)
end
return
end
else
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@goldcommand_window.visible = true
@goldcommand_window.active = true
@number_window.visible = false
@number_window.active = false
update_help(1)
return
end
if Input.trigger?(Input::C)
case @goldcommand_window.index
when 0 # deposit
$game_system.se_play($data_system.shop_se)
j = (@number_window.number * 0.9).to_i
@goldcommand_window.visible = true
@goldcommand_window.active = true
if $game_bank.gold + j < 99999999
$game_bank.gain_gold(j)
$game_party.lose_gold(@number_window.number)
else
i = $game_bank.gold + @number_window.number - 99999999
$game_bank.gain_gold(j)
$game_party.lose_gold(@number_window.number)
$game_party.gain_gold(i)
end
@usergold_window.refresh
@bankgold_window.refresh
@number_window.visible = false
@number_window.active = false
update_help(1)
when 1 #collect
$game_system.se_play($data_system.shop_se)
@goldcommand_window.visible = true
@goldcommand_window.active = true
if $game_party.gold + @number_window.number < 9999999
$game_bank.lose_gold(@number_window.number)
$game_party.gain_gold(@number_window.number)
else
i = $game_party.gold + @number_window.number - 9999999
$game_party.gain_gold(@number_window.number)
$game_bank.lose_gold(@number_window.number)
$game_bank.gain_gold(i)
end
@usergold_window.refresh
@bankgold_window.refresh
@number_window.visible = false
@number_window.active = false
update_help(1)
when 2 # Exit
$game_system.se_play($data_system.decision_se)
@goldcommand_window.visible = true
@goldcommand_window.active = true
@number_window.visible = false
@number_window.active = false
update_help(1)
end
return
end
end
end
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@itemcommand_window.visible = false
@itemcommand_window.active = false
@command_window.visible = true
@command_window.active = true
@help_window.visible = false
@dummy_window.visible = false
return
end
if Input.trigger?(Input::C)
case @itemcommand_window.index
when 0 # deposit
$game_system.se_play($data_system.decision_se)
@itemcommand_window.active = false
@dummy_window.visible = false
@itembank_window.visible = true
@itembank_window.set("deposit")
@itembank_window.active = true
when 1 #collect
$game_system.se_play($data_system.decision_se)
@itemcommand_window.active = false
@dummy_window.visible = false
@itembank_window.visible = true
@itembank_window.set("collect")
@itembank_window.active = true
when 2 # Exit
$game_system.se_play($data_system.decision_se)
@itemcommand_window.visible = false
@itemcommand_window.active = false
@command_window.visible = true
@command_window.active = true
@help_window.visible = false
@dummy_window.visible = false
end
end
end
def update_itembank
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@itemcommand_window.active = true
@itembank_window.active = false
@itembank_window.visible = false
@dummy_window.visible = true
update_help(4)
return
end
if Input.trigger?(Input::C)
case @itemcommand_window.index
when 0 # deposit
$game_system.se_play($data_system.decision_se)
@itembank_window.visible = false
@itembank_window.active = false
@dummy_window.visible = true
@item = @itembank_window.item
case @item
when RPG::Item
@number_window.digits_max($game_party.item_number(@item.id))
when RPG::Weapon
@number_window.digits_max($game_party.weapon_number(@item.id))
when RPG::Armor
@number_window.digits_max($game_party.armor_number(@item.id))
end
@number_window.visible = true
@number_window.x = 320 - @number_window.width / 2
@number_window.y = 240 - @number_window.height / 2
@number_window.active = true
@item_id = true
when 1 #collect
$game_system.se_play($data_system.decision_se)
@itembank_window.active = false
@itembank_window.visible = false
@dummy_window.visible = true
@item = @itembank_window.item
case @item
when RPG::Item
@number_window.digits_max($game_bank.item_number(@item.id))
when RPG::Weapon
@number_window.digits_max($game_bank.weapon_number(@item.id))
when RPG::Armor
@number_window.digits_max($game_bank.armor_number(@item.id))
end
@number_window.visible = true
@number_window.active = true
@number_window.x = 320 - @number_window.width / 2
@number_window.y = 240 - @number_window.height / 2
@item_id = true
end
end
end
end
class Scene_Title
alias origi_new_game command_new_game
def command_new_game
origi_new_game
$game_bank = Game_Bank.new
end
end
class Scene_Save < Scene_File
alias origi_write write_save_data
def write_save_data(file)
origi_write(file)
Marshal.dump($game_bank, file)
end
end
class Scene_Load < Scene_File
alias origi_read read_save_data
def read_save_data(file)
origi_read(file)
$game_bank = Marshal.load(file)
end
end
|
0 komentar:
Posting Komentar