Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # DSI Daily Reward v1.01
- # -- Last Updated: 2017.06.25
- # -- Author: dsiver144
- # -- Level: Hard
- # -- Requires: n/a
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DSI-DailyReward"] = true
- #==============================================================================
- # + Updates
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2017.06.25 - Finish first version of the script!
- # 2017.06.25 - Fix an issue that you can recieve items.
- #==============================================================================
- # + Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
- # - Script Call example:
- # ----------------------------------------------------------------------------
- # open_reward_scene - Open Reward Scene
- # ----------------------------------------------------------------------------
- # Note: "i for item, g for gold, a for armor, w for weapon"
- # ----------------------------------------------------------------------------
- # day1 = [["i1",1],["g",500],["a4",2],["w8",2]] # Reward for day 1 in cycle
- # day2 = [["i2",1],["g",800],["a5",1]] # Reward for day 2 in cycle
- # day3 = [["i1",2],["g",1000],["a5",3],["w9",1]] # Reward for day 3 in cycle
- # set_daily_reward(day0,day1,day2)
- # ----------------------------------------------------------------------------
- # ex: Change day 1 reward
- # new_day1 = [["i1",1],["g",700]]
- # change_reward(1,new_day1)
- # ex: Change day 2 reward
- # new_day2 = [["g",100],["a10",2]] # [100G, Armor #10 x 2]
- # change_reward(2,new_day2)
- #==============================================================================
- module DSIVER144
- module DAILY_REWARDS # DSIVER144::DAILY_REWARDS::TEXT_CONFIG[0]
- TEXT_CONFIG = {}
- TEXT_CONFIG[0] = "Redeem"
- TEXT_CONFIG[1] = "Cancel"
- TEXT_CONFIG[2] = "There is no daily reward!"
- TEXT_CONFIG[3] = "Daily Reward"
- TEXT_CONFIG[4] = "Next reward: "
- TEXT_CONFIG[5] = "Reward Available!"
- #------------------------------------------------------------------------
- # * new method: convert_str_to_items
- #------------------------------------------------------------------------
- def self.convert_str_to_items(str_array)
- items = []
- str_array.each do |str|
- if str[0] =~ /i(\d+)/i
- items << [$data_items[$1.to_i],str[1]]
- end
- if str[0] =~ /w(\d+)/i
- items << [$data_weapons[$1.to_i],str[1]]
- end
- if str[0] =~ /a(\d+)/i
- items << [$data_armors[$1.to_i],str[1]]
- end
- if str[0] =~ /g/i
- items << ["Gold",str[1]]
- end
- end
- items.each do |it|
- if it[0].is_a?(String)
- p "GOLD = #{it[1]}"
- else
- p "#{it[0].name} : #{it[1]}"
- end
- end
- return items
- end # convert_str_to_items
- end # DAILY_REWARDS
- end # DSIVER144
- class Scene_DailyReward < Scene_Base
- include DSIVER144::DAILY_REWARDS
- #--------------------------------------------------------------------------
- # * new method: start
- #--------------------------------------------------------------------------
- def start
- super
- create_background
- create_main_windows
- end
- #--------------------------------------------------------------------------
- # * new method: create_cursor_sprite
- #--------------------------------------------------------------------------
- def create_cursor_sprite
- @cursor_sprite = Sprite.new
- @bitmap1 = Bitmap.new(34,34)
- color = Color.new(255,255,255)
- @bitmap1.fill_rect(0,0,34,2,color)
- @bitmap1.fill_rect(0,0,2,34,color)
- @bitmap1.fill_rect(32,0,2,34,color)
- @bitmap1.fill_rect(0,32,34,2,color)
- @bitmap2 = Bitmap.new(96,32)
- @bitmap2.fill_rect(0,0,96,2,color)
- @bitmap2.fill_rect(0,0,2,32,color)
- @bitmap2.fill_rect(94,0,2,32,color)
- @bitmap2.fill_rect(0,30,96,2,color)
- @cursor_sprite.bitmap = @bitmap2
- end
- #--------------------------------------------------------------------------
- # * new method: create_main_windows
- #--------------------------------------------------------------------------
- def create_main_windows
- @cursor_index = 0
- @cursor_index_max = $game_system.dsi_rewards ? $game_system.dsi_rewards.items[$game_system.dsi_rewards.day].size - 1 : 1
- @main_window = Window_DSI_Reward.new(0,0,400,180)
- @main_window.x = 0.5*(Graphics.width - @main_window.width)
- @main_window.y = 0.5*(Graphics.height - @main_window.height)
- @main_window.refresh(@cursor_index)
- @counter_window = Window_Base.new(0,0,400,180)
- @counter_window.opacity = 0
- @counter_window.back_opacity = 0
- @counter_window.x = @main_window.x
- @counter_window.y = @main_window.y
- @confirm_window = Window_Base.new(0,0,400,180)
- @confirm_window.opacity = 0
- @confirm_window.back_opacity = 0
- @confirm_window.x = @main_window.x
- @confirm_window.y = @main_window.y
- update_counter
- draw_confirm_text
- create_cursor_sprite
- @cursor_mode = $game_system.dsi_rewards ? :top : :bot
- correct_sprite_position
- @cursor_sprite.z = 120 if @cursor_sprite
- end
- #--------------------------------------------------------------------------
- # * new method: draw_confirm_text
- #--------------------------------------------------------------------------
- def draw_confirm_text
- cw = @confirm_window.contents_width
- @confirm_window.contents.clear
- @confirm_window.change_color(@confirm_window.normal_color,true)
- @confirm_window.draw_text(cw/2,124,cw/2,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[1],1)
- if $game_system.dsi_rewards && !$game_system.dsi_rewards.available?
- @confirm_window.change_color(@confirm_window.normal_color,false)
- end
- @confirm_window.draw_text(0,124,cw/2,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[0],1)
- end
- #--------------------------------------------------------------------------
- # * new method: update_counter
- #--------------------------------------------------------------------------
- def update_counter
- if $game_system.dsi_rewards
- $game_system.dsi_rewards.update_time
- current_time = Time.now
- display_time = ($game_system.dsi_rewards.next_time - current_time).to_i
- time_text = "#{display_time / (60*60)}:#{(display_time / (60)) % 60}:#{display_time % 60}"
- cw = @counter_window.contents_width
- @counter_window.contents.clear
- @main_window.refresh(@cursor_index)
- if !$game_system.dsi_rewards.available?
- @counter_window.change_color(@counter_window.normal_color)
- @counter_window.draw_text(0,0,cw,24,TEXT_CONFIG[4] + "#{time_text}",2)
- draw_confirm_text
- else
- @counter_window.change_color(@counter_window.text_color(29))
- @counter_window.draw_text(0,0,cw,24,TEXT_CONFIG[5],2)
- draw_confirm_text
- end
- end
- end
- #--------------------------------------------------------------------------
- # * new method: correct_sprite_position
- #--------------------------------------------------------------------------
- def correct_sprite_position
- if @cursor_mode == :top
- @cursor_sprite.bitmap = @bitmap1
- @cursor_sprite.x = @main_window.x + @main_window.standard_padding + @cursor_index*(32 + 12)
- @cursor_sprite.y = @main_window.y + @main_window.standard_padding + 32
- else
- @cursor_sprite.bitmap = @bitmap2
- @cursor_sprite.x = @main_window.x + @main_window.standard_padding + 45 + @cursor_index*(32 + 12 + 145)
- @cursor_sprite.y = @main_window.y + @main_window.standard_padding + 120
- end
- end
- #--------------------------------------------------------------------------
- # * new method: update_cursor
- #--------------------------------------------------------------------------
- def update_cursor
- if Input.repeat?(:RIGHT)
- @cursor_index += 1
- if @cursor_mode == :top
- if @cursor_index > @cursor_index_max
- @cursor_index = 0
- end
- else
- if @cursor_index > 1
- @cursor_index = 0
- end
- end
- @main_window.refresh(@cursor_index) if @cursor_mode == :top
- correct_sprite_position
- Sound.play_cursor
- end
- if Input.repeat?(:LEFT)
- @cursor_index -= 1
- if @cursor_mode == :top
- if @cursor_index < 0
- @cursor_index = @cursor_index_max
- end
- else
- if @cursor_index < 0
- @cursor_index = 1
- end
- end
- @main_window.refresh(@cursor_index) if @cursor_mode == :top
- correct_sprite_position
- Sound.play_cursor
- end
- if Input.trigger?(:DOWN)
- if @cursor_mode == :top
- @cursor_mode = :bot
- @cursor_index = 0
- else
- @cursor_mode = :top
- @cursor_index = 0
- @main_window.refresh(@cursor_index)
- end
- Sound.play_cursor
- correct_sprite_position
- end
- if Input.trigger?(:UP)
- if @cursor_mode == :bot
- @cursor_mode = :top
- @cursor_index = 0
- @main_window.refresh(@cursor_index)
- else
- @cursor_mode = :bot
- @cursor_index = 0
- end
- Sound.play_cursor
- correct_sprite_position
- end
- if Input.trigger?(:C)
- if @cursor_mode == :bot
- if @cursor_index == 0
- if $game_system.dsi_rewards && $game_system.dsi_rewards.available?
- p "Successful!"
- $game_system.dsi_rewards.get_reward!
- @cursor_mode = :top
- @cursor_index = 0
- @cursor_index_max = $game_system.dsi_rewards ? $game_system.dsi_rewards.items[$game_system.dsi_rewards.day].size - 1 : 0
- correct_sprite_position
- @main_window.refresh(@cursor_index)
- draw_confirm_text
- Sound.play_ok
- else
- Sound.play_buzzer
- end
- else
- return_scene
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Create Background
- #--------------------------------------------------------------------------
- def create_background
- @background_sprite = Sprite.new
- @background_sprite.bitmap = SceneManager.background_bitmap
- @background_sprite.color.set(16, 16, 16, 128)
- end
- #--------------------------------------------------------------------------
- # * Free Background
- #--------------------------------------------------------------------------
- def dispose_background
- @background_sprite.dispose
- end
- #--------------------------------------------------------------------------
- # * new method: update
- #--------------------------------------------------------------------------
- def terminate
- super
- @cursor_sprite.dispose
- @bitmap1.dispose
- @bitmap2.dispose
- dispose_background
- end
- #--------------------------------------------------------------------------
- # * new method: update
- #--------------------------------------------------------------------------
- def update
- super
- update_cursor
- update_counter if Graphics.frame_count % 60 == 0
- if Input.trigger?(:B)
- return_scene
- end
- end
- end
- class Window_DSI_Reward < Window_Base
- #--------------------------------------------------------------------------
- # * new method: refresh
- #--------------------------------------------------------------------------
- def refresh(cursor_index)
- contents.clear
- x = 0; y = 0; cw = contents_width()
- ch = contents_height()
- contents.font.bold = true
- draw_text(x,y,cw,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[3])
- contents.font.bold = false
- draw_horz_line(x,y + 24,cw,2)
- y += 32
- if $game_system.dsi_rewards
- black_color = Color.new(0,0,0,95)
- current_day = $game_system.dsi_rewards.day
- current_item_array = $game_system.dsi_rewards.items[current_day]
- current_item_array.each do |item_data,number|
- if !item_data.is_a?(String)
- contents.fill_rect(x,y,32,32,black_color)
- draw_icon(item_data.icon_index,x + 4, y + 4)
- x += 32 + 12
- else
- contents.fill_rect(x,y,32,32,black_color)
- draw_icon(361,x + 4, y + 4)
- x += 32 + 12
- end
- end
- y += 40; x = 0
- color = Color.new(255,255,255)
- contents.fill_rect(x,y,cw,32,black_color)
- contents.fill_rect(x,y,cw,1,color)
- contents.fill_rect(x,y+31,cw,1,color)
- contents.fill_rect(x,y,1,32,color)
- contents.fill_rect(x+cw-1,y,1,32,color)
- item_name = current_item_array[cursor_index][0].is_a?(String) ? current_item_array[cursor_index][1].to_s + "G" : current_item_array[cursor_index][0].name + " x" + current_item_array[cursor_index][1].to_s
- draw_text(x + 6,y + 4,cw - 4,24,item_name)
- else
- draw_text(x,y,cw,ch - 60,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[2],1)
- end
- end
- #--------------------------------------------------------------------------
- # * new method: draw_horz_line
- #--------------------------------------------------------------------------
- def draw_horz_line(x,y,width,height)
- color = Color.new(255,255,255,200)
- contents.fill_rect(x,y,width,height,color)
- end
- end
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * new method: open_reward_scene
- #--------------------------------------------------------------------------
- def open_reward_scene
- SceneManager.call(Scene_DailyReward)
- end
- #--------------------------------------------------------------------------
- # * new method: set_daily_reward
- #--------------------------------------------------------------------------
- def set_daily_reward(*str_arrays)
- reward = DSI_Reward.new
- str_arrays.each_with_index do |str_array,index|
- reward.set_reward(index,str_array)
- end
- $game_system.dsi_rewards = reward
- end
- #--------------------------------------------------------------------------
- # * new method: change_reward
- #--------------------------------------------------------------------------
- def change_reward(day,str_array)
- $game_system.dsi_rewards.update_time
- $game_system.dsi_rewards.set_reward(day-1,str_array)
- end
- #--------------------------------------------------------------------------
- # * new method: clear_reward
- #--------------------------------------------------------------------------
- def clear_reward(day)
- $game_system.dsi_rewards.update_time
- $game_system.dsi_rewards.clear_reward(day-1)
- end
- #--------------------------------------------------------------------------
- # * new method: get_reward
- #--------------------------------------------------------------------------
- def get_reward
- $game_system.dsi_rewards.update_time
- $game_system.dsi_rewards.get_reward!
- end
- end
- class DSI_Reward
- attr_accessor :last_time
- attr_accessor :next_time
- attr_accessor :can_get
- attr_accessor :items
- attr_accessor :day
- attr_accessor :cycle
- attr_accessor :key
- #--------------------------------------------------------------------------
- # * new method: initialize
- #--------------------------------------------------------------------------
- def initialize
- @last_time = Time.now
- @next_time = Time.now + 86400
- @can_get = false
- @day = 0
- @items = {}
- end
- #--------------------------------------------------------------------------
- # * new method: set_reward
- #--------------------------------------------------------------------------
- def set_reward(day,str_array)
- @items[day] = DSIVER144::DAILY_REWARDS.convert_str_to_items(str_array)
- end
- #--------------------------------------------------------------------------
- # * new method: clear_reward
- #--------------------------------------------------------------------------
- def clear_reward(day)
- @items.delete(day)
- end
- #--------------------------------------------------------------------------
- # * new method: get_reward!
- #--------------------------------------------------------------------------
- def get_reward!
- return unless available?
- p "Get Rewards of day #{@day}!"
- @items[day].each do |item|
- if item[0].is_a?(String)
- $game_party.gain_gold(item[1])
- else
- $game_party.gain_item(item[0],item[1])
- end
- end
- @can_get = false
- @last_time = Time.now
- @next_time = Time.now + 86400
- @day += 1
- if @day > @items.size - 1
- @day = 0
- end
- end
- #--------------------------------------------------------------------------
- # * new method: update_time
- #--------------------------------------------------------------------------
- def update_time
- if Time.now >= @next_time
- @can_get = true
- end
- if Time.now >= @next_time + 86400
- @can_get = false
- @last_time = @next_time + 86400
- @next_time = @next_time + 86400*2
- @day = 0
- return true
- end
- end
- #--------------------------------------------------------------------------
- # * new method: available?
- #--------------------------------------------------------------------------
- def available?
- return @can_get
- end
- end
- class Game_System
- attr_accessor :dsi_rewards
- alias_method(:dsi_daily_rewards_init, :initialize)
- #--------------------------------------------------------------------------
- # * new method: get_reward
- #--------------------------------------------------------------------------
- def initialize
- @dsi_rewards = nil
- dsi_daily_rewards_init # Call original method
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement