Advertisement
dsiver144

DSI Daily Reward v1.01

Jun 26th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.80 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Daily Reward v1.01
  3. # -- Last Updated: 2017.06.25
  4. # -- Author: dsiver144
  5. # -- Level: Hard
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-DailyReward"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2017.06.25 - Finish first version of the script!
  14. # 2017.06.25 - Fix an issue that you can recieve items.
  15. #==============================================================================
  16. # + Instructions
  17. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. # To install this script, open up your script editor and copy/paste this script
  19. # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
  20. # - Script Call example:
  21. # ----------------------------------------------------------------------------
  22. # open_reward_scene - Open Reward Scene
  23. # ----------------------------------------------------------------------------
  24. # Note: "i for item, g for gold, a for armor, w for weapon"
  25. # ----------------------------------------------------------------------------
  26. # day1 = [["i1",1],["g",500],["a4",2],["w8",2]] # Reward for day 1 in cycle
  27. # day2 = [["i2",1],["g",800],["a5",1]] # Reward for day 2 in cycle
  28. # day3 = [["i1",2],["g",1000],["a5",3],["w9",1]] # Reward for day 3 in cycle
  29. # set_daily_reward(day0,day1,day2)
  30. # ----------------------------------------------------------------------------
  31. # ex: Change day 1 reward
  32. # new_day1 = [["i1",1],["g",700]]
  33. # change_reward(1,new_day1)
  34. # ex: Change day 2 reward
  35. # new_day2 = [["g",100],["a10",2]] # [100G, Armor #10 x 2]
  36. # change_reward(2,new_day2)
  37. #==============================================================================
  38. module DSIVER144
  39. module DAILY_REWARDS # DSIVER144::DAILY_REWARDS::TEXT_CONFIG[0]
  40. TEXT_CONFIG = {}
  41. TEXT_CONFIG[0] = "Redeem"
  42. TEXT_CONFIG[1] = "Cancel"
  43. TEXT_CONFIG[2] = "There is no daily reward!"
  44. TEXT_CONFIG[3] = "Daily Reward"
  45. TEXT_CONFIG[4] = "Next reward: "
  46. TEXT_CONFIG[5] = "Reward Available!"
  47. #------------------------------------------------------------------------
  48. # * new method: convert_str_to_items
  49. #------------------------------------------------------------------------
  50. def self.convert_str_to_items(str_array)
  51. items = []
  52. str_array.each do |str|
  53. if str[0] =~ /i(\d+)/i
  54. items << [$data_items[$1.to_i],str[1]]
  55. end
  56. if str[0] =~ /w(\d+)/i
  57. items << [$data_weapons[$1.to_i],str[1]]
  58. end
  59. if str[0] =~ /a(\d+)/i
  60. items << [$data_armors[$1.to_i],str[1]]
  61. end
  62. if str[0] =~ /g/i
  63. items << ["Gold",str[1]]
  64. end
  65. end
  66. items.each do |it|
  67. if it[0].is_a?(String)
  68. p "GOLD = #{it[1]}"
  69. else
  70. p "#{it[0].name} : #{it[1]}"
  71. end
  72. end
  73. return items
  74. end # convert_str_to_items
  75.  
  76. end # DAILY_REWARDS
  77.  
  78. end # DSIVER144
  79.  
  80. class Scene_DailyReward < Scene_Base
  81. include DSIVER144::DAILY_REWARDS
  82. #--------------------------------------------------------------------------
  83. # * new method: start
  84. #--------------------------------------------------------------------------
  85. def start
  86. super
  87. create_background
  88. create_main_windows
  89. end
  90. #--------------------------------------------------------------------------
  91. # * new method: create_cursor_sprite
  92. #--------------------------------------------------------------------------
  93. def create_cursor_sprite
  94. @cursor_sprite = Sprite.new
  95. @bitmap1 = Bitmap.new(34,34)
  96. color = Color.new(255,255,255)
  97. @bitmap1.fill_rect(0,0,34,2,color)
  98. @bitmap1.fill_rect(0,0,2,34,color)
  99. @bitmap1.fill_rect(32,0,2,34,color)
  100. @bitmap1.fill_rect(0,32,34,2,color)
  101. @bitmap2 = Bitmap.new(96,32)
  102. @bitmap2.fill_rect(0,0,96,2,color)
  103. @bitmap2.fill_rect(0,0,2,32,color)
  104. @bitmap2.fill_rect(94,0,2,32,color)
  105. @bitmap2.fill_rect(0,30,96,2,color)
  106. @cursor_sprite.bitmap = @bitmap2
  107. end
  108. #--------------------------------------------------------------------------
  109. # * new method: create_main_windows
  110. #--------------------------------------------------------------------------
  111. def create_main_windows
  112. @cursor_index = 0
  113. @cursor_index_max = $game_system.dsi_rewards ? $game_system.dsi_rewards.items[$game_system.dsi_rewards.day].size - 1 : 1
  114. @main_window = Window_DSI_Reward.new(0,0,400,180)
  115. @main_window.x = 0.5*(Graphics.width - @main_window.width)
  116. @main_window.y = 0.5*(Graphics.height - @main_window.height)
  117. @main_window.refresh(@cursor_index)
  118. @counter_window = Window_Base.new(0,0,400,180)
  119. @counter_window.opacity = 0
  120. @counter_window.back_opacity = 0
  121. @counter_window.x = @main_window.x
  122. @counter_window.y = @main_window.y
  123. @confirm_window = Window_Base.new(0,0,400,180)
  124. @confirm_window.opacity = 0
  125. @confirm_window.back_opacity = 0
  126. @confirm_window.x = @main_window.x
  127. @confirm_window.y = @main_window.y
  128. update_counter
  129. draw_confirm_text
  130. create_cursor_sprite
  131. @cursor_mode = $game_system.dsi_rewards ? :top : :bot
  132. correct_sprite_position
  133. @cursor_sprite.z = 120 if @cursor_sprite
  134. end
  135. #--------------------------------------------------------------------------
  136. # * new method: draw_confirm_text
  137. #--------------------------------------------------------------------------
  138. def draw_confirm_text
  139. cw = @confirm_window.contents_width
  140. @confirm_window.contents.clear
  141. @confirm_window.change_color(@confirm_window.normal_color,true)
  142. @confirm_window.draw_text(cw/2,124,cw/2,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[1],1)
  143. if $game_system.dsi_rewards && !$game_system.dsi_rewards.available?
  144. @confirm_window.change_color(@confirm_window.normal_color,false)
  145. end
  146. @confirm_window.draw_text(0,124,cw/2,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[0],1)
  147. end
  148. #--------------------------------------------------------------------------
  149. # * new method: update_counter
  150. #--------------------------------------------------------------------------
  151. def update_counter
  152. if $game_system.dsi_rewards
  153. $game_system.dsi_rewards.update_time
  154. current_time = Time.now
  155. display_time = ($game_system.dsi_rewards.next_time - current_time).to_i
  156. time_text = "#{display_time / (60*60)}:#{(display_time / (60)) % 60}:#{display_time % 60}"
  157. cw = @counter_window.contents_width
  158. @counter_window.contents.clear
  159. @main_window.refresh(@cursor_index)
  160. if !$game_system.dsi_rewards.available?
  161. @counter_window.change_color(@counter_window.normal_color)
  162. @counter_window.draw_text(0,0,cw,24,TEXT_CONFIG[4] + "#{time_text}",2)
  163. draw_confirm_text
  164. else
  165. @counter_window.change_color(@counter_window.text_color(29))
  166. @counter_window.draw_text(0,0,cw,24,TEXT_CONFIG[5],2)
  167. draw_confirm_text
  168. end
  169. end
  170. end
  171. #--------------------------------------------------------------------------
  172. # * new method: correct_sprite_position
  173. #--------------------------------------------------------------------------
  174. def correct_sprite_position
  175. if @cursor_mode == :top
  176. @cursor_sprite.bitmap = @bitmap1
  177. @cursor_sprite.x = @main_window.x + @main_window.standard_padding + @cursor_index*(32 + 12)
  178. @cursor_sprite.y = @main_window.y + @main_window.standard_padding + 32
  179. else
  180. @cursor_sprite.bitmap = @bitmap2
  181. @cursor_sprite.x = @main_window.x + @main_window.standard_padding + 45 + @cursor_index*(32 + 12 + 145)
  182. @cursor_sprite.y = @main_window.y + @main_window.standard_padding + 120
  183. end
  184. end
  185. #--------------------------------------------------------------------------
  186. # * new method: update_cursor
  187. #--------------------------------------------------------------------------
  188. def update_cursor
  189. if Input.repeat?(:RIGHT)
  190. @cursor_index += 1
  191. if @cursor_mode == :top
  192. if @cursor_index > @cursor_index_max
  193. @cursor_index = 0
  194. end
  195. else
  196. if @cursor_index > 1
  197. @cursor_index = 0
  198. end
  199. end
  200. @main_window.refresh(@cursor_index) if @cursor_mode == :top
  201. correct_sprite_position
  202. Sound.play_cursor
  203. end
  204. if Input.repeat?(:LEFT)
  205. @cursor_index -= 1
  206. if @cursor_mode == :top
  207. if @cursor_index < 0
  208. @cursor_index = @cursor_index_max
  209. end
  210. else
  211. if @cursor_index < 0
  212. @cursor_index = 1
  213. end
  214. end
  215. @main_window.refresh(@cursor_index) if @cursor_mode == :top
  216. correct_sprite_position
  217. Sound.play_cursor
  218. end
  219. if Input.trigger?(:DOWN)
  220. if @cursor_mode == :top
  221. @cursor_mode = :bot
  222. @cursor_index = 0
  223. else
  224. @cursor_mode = :top
  225. @cursor_index = 0
  226. @main_window.refresh(@cursor_index)
  227. end
  228. Sound.play_cursor
  229. correct_sprite_position
  230. end
  231. if Input.trigger?(:UP)
  232. if @cursor_mode == :bot
  233. @cursor_mode = :top
  234. @cursor_index = 0
  235. @main_window.refresh(@cursor_index)
  236. else
  237. @cursor_mode = :bot
  238. @cursor_index = 0
  239. end
  240. Sound.play_cursor
  241. correct_sprite_position
  242. end
  243. if Input.trigger?(:C)
  244. if @cursor_mode == :bot
  245. if @cursor_index == 0
  246. if $game_system.dsi_rewards && $game_system.dsi_rewards.available?
  247. p "Successful!"
  248. $game_system.dsi_rewards.get_reward!
  249. @cursor_mode = :top
  250. @cursor_index = 0
  251. @cursor_index_max = $game_system.dsi_rewards ? $game_system.dsi_rewards.items[$game_system.dsi_rewards.day].size - 1 : 0
  252. correct_sprite_position
  253. @main_window.refresh(@cursor_index)
  254. draw_confirm_text
  255. Sound.play_ok
  256. else
  257. Sound.play_buzzer
  258. end
  259. else
  260. return_scene
  261. end
  262. end
  263. end
  264. end
  265. #--------------------------------------------------------------------------
  266. # * Create Background
  267. #--------------------------------------------------------------------------
  268. def create_background
  269. @background_sprite = Sprite.new
  270. @background_sprite.bitmap = SceneManager.background_bitmap
  271. @background_sprite.color.set(16, 16, 16, 128)
  272. end
  273. #--------------------------------------------------------------------------
  274. # * Free Background
  275. #--------------------------------------------------------------------------
  276. def dispose_background
  277. @background_sprite.dispose
  278. end
  279. #--------------------------------------------------------------------------
  280. # * new method: update
  281. #--------------------------------------------------------------------------
  282. def terminate
  283. super
  284. @cursor_sprite.dispose
  285. @bitmap1.dispose
  286. @bitmap2.dispose
  287. dispose_background
  288. end
  289. #--------------------------------------------------------------------------
  290. # * new method: update
  291. #--------------------------------------------------------------------------
  292. def update
  293. super
  294. update_cursor
  295. update_counter if Graphics.frame_count % 60 == 0
  296. if Input.trigger?(:B)
  297. return_scene
  298. end
  299. end
  300.  
  301. end
  302.  
  303. class Window_DSI_Reward < Window_Base
  304. #--------------------------------------------------------------------------
  305. # * new method: refresh
  306. #--------------------------------------------------------------------------
  307. def refresh(cursor_index)
  308. contents.clear
  309. x = 0; y = 0; cw = contents_width()
  310. ch = contents_height()
  311. contents.font.bold = true
  312. draw_text(x,y,cw,24,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[3])
  313. contents.font.bold = false
  314. draw_horz_line(x,y + 24,cw,2)
  315. y += 32
  316. if $game_system.dsi_rewards
  317. black_color = Color.new(0,0,0,95)
  318. current_day = $game_system.dsi_rewards.day
  319. current_item_array = $game_system.dsi_rewards.items[current_day]
  320. current_item_array.each do |item_data,number|
  321. if !item_data.is_a?(String)
  322. contents.fill_rect(x,y,32,32,black_color)
  323. draw_icon(item_data.icon_index,x + 4, y + 4)
  324. x += 32 + 12
  325. else
  326. contents.fill_rect(x,y,32,32,black_color)
  327. draw_icon(361,x + 4, y + 4)
  328. x += 32 + 12
  329. end
  330. end
  331. y += 40; x = 0
  332. color = Color.new(255,255,255)
  333. contents.fill_rect(x,y,cw,32,black_color)
  334. contents.fill_rect(x,y,cw,1,color)
  335. contents.fill_rect(x,y+31,cw,1,color)
  336. contents.fill_rect(x,y,1,32,color)
  337. contents.fill_rect(x+cw-1,y,1,32,color)
  338. 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
  339. draw_text(x + 6,y + 4,cw - 4,24,item_name)
  340. else
  341. draw_text(x,y,cw,ch - 60,DSIVER144::DAILY_REWARDS::TEXT_CONFIG[2],1)
  342. end
  343. end
  344. #--------------------------------------------------------------------------
  345. # * new method: draw_horz_line
  346. #--------------------------------------------------------------------------
  347. def draw_horz_line(x,y,width,height)
  348. color = Color.new(255,255,255,200)
  349. contents.fill_rect(x,y,width,height,color)
  350. end
  351. end
  352.  
  353. class Game_Interpreter
  354. #--------------------------------------------------------------------------
  355. # * new method: open_reward_scene
  356. #--------------------------------------------------------------------------
  357. def open_reward_scene
  358. SceneManager.call(Scene_DailyReward)
  359. end
  360. #--------------------------------------------------------------------------
  361. # * new method: set_daily_reward
  362. #--------------------------------------------------------------------------
  363. def set_daily_reward(*str_arrays)
  364. reward = DSI_Reward.new
  365. str_arrays.each_with_index do |str_array,index|
  366. reward.set_reward(index,str_array)
  367. end
  368. $game_system.dsi_rewards = reward
  369. end
  370. #--------------------------------------------------------------------------
  371. # * new method: change_reward
  372. #--------------------------------------------------------------------------
  373. def change_reward(day,str_array)
  374. $game_system.dsi_rewards.update_time
  375. $game_system.dsi_rewards.set_reward(day-1,str_array)
  376. end
  377. #--------------------------------------------------------------------------
  378. # * new method: clear_reward
  379. #--------------------------------------------------------------------------
  380. def clear_reward(day)
  381. $game_system.dsi_rewards.update_time
  382. $game_system.dsi_rewards.clear_reward(day-1)
  383. end
  384. #--------------------------------------------------------------------------
  385. # * new method: get_reward
  386. #--------------------------------------------------------------------------
  387. def get_reward
  388. $game_system.dsi_rewards.update_time
  389. $game_system.dsi_rewards.get_reward!
  390. end
  391.  
  392. end
  393.  
  394. class DSI_Reward
  395.  
  396. attr_accessor :last_time
  397. attr_accessor :next_time
  398. attr_accessor :can_get
  399. attr_accessor :items
  400. attr_accessor :day
  401. attr_accessor :cycle
  402. attr_accessor :key
  403. #--------------------------------------------------------------------------
  404. # * new method: initialize
  405. #--------------------------------------------------------------------------
  406. def initialize
  407. @last_time = Time.now
  408. @next_time = Time.now + 86400
  409. @can_get = false
  410. @day = 0
  411. @items = {}
  412. end
  413. #--------------------------------------------------------------------------
  414. # * new method: set_reward
  415. #--------------------------------------------------------------------------
  416. def set_reward(day,str_array)
  417. @items[day] = DSIVER144::DAILY_REWARDS.convert_str_to_items(str_array)
  418. end
  419. #--------------------------------------------------------------------------
  420. # * new method: clear_reward
  421. #--------------------------------------------------------------------------
  422. def clear_reward(day)
  423. @items.delete(day)
  424. end
  425. #--------------------------------------------------------------------------
  426. # * new method: get_reward!
  427. #--------------------------------------------------------------------------
  428. def get_reward!
  429. return unless available?
  430. p "Get Rewards of day #{@day}!"
  431. @items[day].each do |item|
  432. if item[0].is_a?(String)
  433. $game_party.gain_gold(item[1])
  434. else
  435. $game_party.gain_item(item[0],item[1])
  436. end
  437. end
  438. @can_get = false
  439. @last_time = Time.now
  440. @next_time = Time.now + 86400
  441. @day += 1
  442. if @day > @items.size - 1
  443. @day = 0
  444. end
  445. end
  446. #--------------------------------------------------------------------------
  447. # * new method: update_time
  448. #--------------------------------------------------------------------------
  449. def update_time
  450. if Time.now >= @next_time
  451. @can_get = true
  452. end
  453. if Time.now >= @next_time + 86400
  454. @can_get = false
  455. @last_time = @next_time + 86400
  456. @next_time = @next_time + 86400*2
  457. @day = 0
  458. return true
  459. end
  460. end
  461. #--------------------------------------------------------------------------
  462. # * new method: available?
  463. #--------------------------------------------------------------------------
  464. def available?
  465. return @can_get
  466. end
  467.  
  468. end
  469.  
  470. class Game_System
  471.  
  472. attr_accessor :dsi_rewards
  473.  
  474. alias_method(:dsi_daily_rewards_init, :initialize)
  475. #--------------------------------------------------------------------------
  476. # * new method: get_reward
  477. #--------------------------------------------------------------------------
  478. def initialize
  479. @dsi_rewards = nil
  480. dsi_daily_rewards_init # Call original method
  481. end
  482.  
  483. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement