Advertisement
dsiver144

DSI Card Crafting System

Jun 10th, 2017
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.63 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Card Crafting System
  3. # -- Last Updated: 2017.06.10
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-CardCraftingSystem"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2017.06.10 - Finish first version.
  14. #==============================================================================
  15. # + Instructions
  16. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  17. # To install this script, open up your script editor and copy/paste this script
  18. # to an open slot below ?? Materials/?f?? but above ?? Main. Remember to save.
  19. # Remember to put this script below: DSI-Bitmap.
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # Script Call: open_crafting_scene -> Open Crafting Scene
  22. # Notetags:
  23. # - Skills's Notetags:
  24. # + <craft show require: none> or <craft show require: [id_of_item_here]>
  25. # ex: <craft show require: none> : this card won't require any item to
  26. # be shown on the list
  27. # <craft show require: 12> : this card will require item 12 to be
  28. # show on the list
  29. # + <craft chance: x%>
  30. # ex: <craft chance: 60%> : Base Success rate equal to 60
  31. # + <craft materials: ([item_num]+[item_id]i),...>
  32. # ex: <craft materials: 5+12i,2+19i,4+16i>
  33. # this will translate to 5 of item 12, 2 of item 19, 4 of item 16.
  34. # - Items/Weapons/Armors Notetags
  35. # + <craft chance: x%>
  36. # ex: <craft chance: 2%> -> Increase 2% to overall success rate
  37. # ex: <craft chance: -10%> -> Decrease 10% to overall success rate
  38. #==============================================================================
  39. module DSIVER144
  40. module CARD_CRAFTING
  41.  
  42. BAR_COLOR1 = Color.new(153,0,0)
  43. BAR_COLOR2 = Color.new(255,153,51)
  44. SUCCESS_SE = "Flash2"
  45. FAIL_SE = "Buzzer1"
  46.  
  47. TESTING_MODE = true # Turn on this then you don't need to have require item
  48. # to unlock card for crafting.
  49.  
  50. SHOW_MENU_COMMAND = true
  51.  
  52. FILTER_BUTTON_TEXT = "\\i[1609]:Filter"
  53. CRAFT_BUTTON_TEXT = "\\i[1609]:Craft!"
  54. OTHER_BUTTONS_TEXT = "\\i[1602]:Cancel"
  55. OTHER_BUTTONS_MARGIN = 80
  56. #-------------------------------------------------------------------------
  57. # * new method: can_craft
  58. #-------------------------------------------------------------------------
  59. def self.can_craft(id)
  60. return false if id.nil?
  61. return false if !$data_skills[id].craft_materials
  62. $data_skills[id].craft_materials[:item].each do |item|
  63. if $game_party.item_number($data_items[item[0]]) < item[1]
  64. return false
  65. end
  66. end
  67. return true
  68. end # can_craft DSIVER144::CARD_CRAFTING.can_craft(id)
  69. #-------------------------------------------------------------------------
  70. # * new method: lose_craft_item
  71. #-------------------------------------------------------------------------
  72. def self.lose_craft_item(id)
  73. return if id.nil?
  74. return if !$data_skills[id].craft_materials
  75. $data_skills[id].craft_materials[:item].each do |item|
  76. $game_party.lose_item($data_items[item[0]],item[1])
  77. end
  78. end # lose_craft_item
  79.  
  80. end # CARD_CRAFTING
  81. end # DSIVER144
  82.  
  83. class Scene_CardCrafting < Scene_Base
  84. #-------------------------------------------------------------------------
  85. # * method: start
  86. #-------------------------------------------------------------------------
  87. def start
  88. super
  89. @card_window = Window_CardCraftingList.new(0,0)
  90. @card_filter = Window_CardFilter.new(100,100)
  91. @card_filter.z = 101
  92. @card_filter.x = 0.5*(Graphics.width - @card_filter.width)
  93. @card_filter.y = 0.5*(Graphics.height - @card_filter.height)
  94. @card_filter.set_handler(:type, method(:command_filter_1))
  95. @card_filter.set_handler(:secondary, method(:command_filter_2))
  96. @card_filter.set_handler(:cancel, method(:cancel_filter))
  97. @card_window.set_handler(:ok, method(:on_card_ok))
  98. @card_window.set_handler(:cancel, method(:return_scene))
  99. @card_filter.deactivate
  100. @card_filter.openness = 0
  101. @card_filter.z = 200
  102. @card_window.filter_window = @card_filter
  103. @help_window = Window_CardCraftingHelp.new
  104. @help_window.z = 101
  105. @card_window.y = @help_window.y - @card_window.height
  106. ww = @card_window.width; wh = Graphics.height - @card_window.height - @help_window.height
  107. @window_text1 = Window_Base.new(0,0,ww,wh)
  108. @window_text1.draw_text(0,0,@window_text1.contents_width,@window_text1.contents_height,"Craftable Card List",1)
  109. wx = @window_text1.width; wh = Graphics.height - @help_window.height
  110. ww = Graphics.width - @card_window.width
  111. @info_window = Window_CardCraftingInfo.new(wx,0,ww,wh)
  112. @old_index = @card_window.index
  113. wy = @info_window.height
  114. @slot_window = Window_CardCraftingItemSlots.new(0,0)
  115. @slot_window.init_slots
  116. @slot_window.x = -@slot_window.width
  117. @slot_window.y = @card_window.y
  118. @slot_window.set_handler(:ok, method(:on_slot_ok))
  119. @slot_window.set_handler(:cancel, method(:on_slot_cancel))
  120. @slot_window.deactivate
  121. @item_window = Window_AdditionItemList.new(0,0,400,200)
  122. @item_window.x = 0.5*(Graphics.width - @item_window.width)
  123. @item_window.y = 0.5*(Graphics.height - @item_window.height)
  124. @item_window.set_handler(:ok, method(:on_item_ok))
  125. @item_window.set_handler(:cancel, method(:on_item_cancel))
  126. @item_window.z = 150
  127. @item_window.category = :item
  128. @item_window.openness = 0
  129. @item_window.deactivate
  130. ww = @slot_window.width
  131. wh = @card_window.height - @slot_window.height
  132. @slot_help_window = Window_SlotHelpWindow.new(0,0,ww,wh)
  133. @slot_window.help_window = @slot_help_window
  134. @slot_help_window.y = @slot_window.y + @slot_window.height
  135. @slot_help_window_origin_y = @slot_help_window.y
  136. @slot_help_window.set_item(nil,@slot_window.slots)
  137. @slot_help_window.z = 100
  138. @slot_help_window.y = Graphics.height
  139. @can_craft = DSIVER144::CARD_CRAFTING.can_craft(@card_window.current_skill_id)
  140. @confrim_window = Window_CraftingConfirm.new(0,0)
  141. @confrim_window.x = 0.5*(Graphics.width - @confrim_window.width)
  142. @confrim_window.y = 0.5*(Graphics.height - @confrim_window.height)
  143. @confrim_window.set_handler(:cancel, method(:on_confirm_cancel))
  144. @confrim_window.set_handler(:ok, method(:on_confirm_ok))
  145. @confrim_window.openness = 0
  146. @confrim_window.deactivate
  147. @confrim_window.z = 300
  148. @progress_window = Window_CraftingProgess.new(0,0,400,80)
  149. @progress_window.x = 0.5*(Graphics.width - @progress_window.width)
  150. @progress_window.y = 0.5*(Graphics.height - @progress_window.height)
  151. @progress_window.z = 301
  152. @progress_window.openness = 0
  153. @progress_window.hide
  154. refresh_info_window
  155. @show_mode = 1
  156. end
  157. #-------------------------------------------------------------------------
  158. # * new method: refresh_info_window
  159. #-------------------------------------------------------------------------
  160. def refresh_info_window
  161. if @card_window.current_skill_id
  162. @slot_help_window.set_item(@slot_window.current_item,@slot_window.slots)
  163. @info_window.draw_info(@card_window.current_skill_id, @slot_window.slots)
  164. else
  165. @info_window.draw_info(nil)
  166. end
  167. end
  168. #-------------------------------------------------------------------------
  169. # * new method: on_card_ok
  170. #-------------------------------------------------------------------------
  171. def on_card_ok
  172. update_moving_sprite
  173. end
  174. #-------------------------------------------------------------------------
  175. # * new method: on_item_cancel
  176. #-------------------------------------------------------------------------
  177. def on_item_cancel
  178. @item_window.deactivate
  179. @item_window.close
  180. @slot_window.activate
  181. end
  182. #-------------------------------------------------------------------------
  183. # * new method: on_item_ok
  184. #-------------------------------------------------------------------------
  185. def on_item_ok
  186. if @slot_window.current_item
  187. $game_party.gain_item(@slot_window.current_item,1)
  188. end
  189. @item_window.deactivate
  190. @item_window.close
  191. $game_party.lose_item(@item_window.item,1)
  192. @slot_window.set_item(@item_window.item)
  193. @slot_window.activate
  194. refresh_info_window
  195. @can_craft = DSIVER144::CARD_CRAFTING.can_craft(@card_window.current_skill_id)
  196. @help_window.refresh(@can_craft,2)
  197. end
  198. #-------------------------------------------------------------------------
  199. # * new method: on_slot_ok
  200. #-------------------------------------------------------------------------
  201. def on_slot_ok
  202. @item_window.refresh
  203. @item_window.open
  204. @item_window.activate
  205. @item_window.select(0)
  206. end
  207. #-------------------------------------------------------------------------
  208. # * new method: on_slot_cancel
  209. #-------------------------------------------------------------------------
  210. def on_slot_cancel
  211. @slot_window.refund_items
  212. update_moving_sprite
  213. end
  214. #-------------------------------------------------------------------------
  215. # * new method: easeInOutQuad
  216. #-------------------------------------------------------------------------
  217. def easeInOutQuad(t, b, c, d)
  218. t = t / (d/2.0)
  219. if (t < 1)
  220. return c/2*t*t + b
  221. end
  222. t -= 1
  223. return -c/2.0 * (t*(t-2) - 1) + b
  224. end
  225. #-------------------------------------------------------------------------
  226. # * new method: update_moving_sprite
  227. #-------------------------------------------------------------------------
  228. def update_moving_sprite
  229. Sound.play_ok
  230. @moving = true
  231. if @show_mode == 1
  232. @slot_window.refresh
  233. @can_craft = DSIVER144::CARD_CRAFTING.can_craft(@card_window.current_skill_id)
  234. @help_window.refresh(@can_craft,2)
  235. @window_text1.contents.clear
  236. @window_text1.draw_text(0,0,@window_text1.contents_width,@window_text1.contents_height,"Addtion Item List",1)
  237. start_time = Graphics.frame_count
  238. start_x = @card_window.x
  239. change_x = -@card_window.width
  240. start_x2 = @slot_window.x
  241. change_x2 = 0 - start_x2
  242. start_y = @slot_help_window.y
  243. change_y = @slot_help_window_origin_y - start_y
  244. while (current_time = Graphics.frame_count - start_time) < 60
  245. @card_window.x = easeInOutQuad(current_time, start_x, change_x, 60)
  246. @slot_window.x = easeInOutQuad(current_time, start_x2, change_x2, 60)
  247. @slot_help_window.y = easeInOutQuad(current_time, start_y, change_y, 60)
  248. Graphics.update
  249. end
  250. @slot_window.activate
  251. @show_mode = 0
  252. else
  253. @help_window.refresh(true,1)
  254. @window_text1.contents.clear
  255. @window_text1.draw_text(0,0,@window_text1.contents_width,@window_text1.contents_height,"Craftable Card List",1)
  256. start_time = Graphics.frame_count
  257. start_x = @card_window.x
  258. change_x = 0 - start_x
  259. start_x2 = @slot_window.x
  260. change_x2 = -@slot_window.width - start_x2
  261. start_y = @slot_help_window.y
  262. change_y = Graphics.height - start_y
  263. while (current_time = Graphics.frame_count - start_time) < 60
  264. @card_window.x = easeInOutQuad(current_time, start_x, change_x, 60)
  265. @slot_window.x = easeInOutQuad(current_time, start_x2, change_x2, 60)
  266. @slot_help_window.y = easeInOutQuad(current_time, start_y, change_y, 60)
  267. Graphics.update
  268. end
  269. @card_window.activate
  270. @show_mode = 1
  271. @help_window.refresh(true,1)
  272. end
  273. @moving = false
  274. refresh_info_window
  275. end
  276. #-------------------------------------------------------------------------
  277. # * new method: open_filter
  278. #-------------------------------------------------------------------------
  279. def open_filter
  280. @help_window.refresh(false)
  281. @card_window.deactivate
  282. @card_filter.open
  283. @card_filter.activate
  284. end
  285. #-------------------------------------------------------------------------
  286. # * new method: cancel_filter
  287. #-------------------------------------------------------------------------
  288. def cancel_filter
  289. @help_window.refresh
  290. @card_filter.close
  291. @card_filter.deactivate
  292. @card_window.activate
  293. end
  294. #-------------------------------------------------------------------------
  295. # * new method: command_filter_1
  296. #-------------------------------------------------------------------------
  297. def command_filter_1
  298. @card_filter.increase_filter_1
  299. @card_filter.refresh
  300. @card_filter.activate
  301. @card_window.refresh
  302. @card_window.select(0)
  303. refresh_info_window
  304. end
  305. #-------------------------------------------------------------------------
  306. # * new method: command_filter_2
  307. #-------------------------------------------------------------------------
  308. def command_filter_2
  309. @card_filter.increase_filter_2
  310. @card_filter.refresh
  311. @card_filter.activate
  312. @card_window.refresh
  313. @card_window.select(0)
  314. refresh_info_window
  315. end
  316. #-------------------------------------------------------------------------
  317. # * new method: on_confirm_cancel
  318. #-------------------------------------------------------------------------
  319. def on_confirm_cancel
  320. @confrim_window.deactivate
  321. @confrim_window.close
  322. @slot_window.activate
  323. end
  324. #-------------------------------------------------------------------------
  325. # * new method: on_confirm_ok
  326. #-------------------------------------------------------------------------
  327. def on_confirm_ok
  328. @confrim_window.close
  329. while @confrim_window.openness > 0
  330. @confrim_window.update
  331. Graphics.update
  332. end
  333. @progress_window.show
  334. @progress_window.open
  335. while @progress_window.openness < 255
  336. @progress_window.update
  337. Graphics.update
  338. end
  339. ss_rate = @info_window.total_success_rate
  340. card_id = @card_window.current_skill_id
  341. @progress_window.play_progress(card_id,ss_rate)
  342. @slot_window.slots.clear
  343. refresh_info_window
  344. @slot_window.refresh
  345. while !Input.trigger?(:B) and !Input.trigger?(:C)
  346. Graphics.update
  347. Input.update
  348. end
  349. @progress_window.close
  350. while @progress_window.openness > 0
  351. @progress_window.update
  352. Graphics.update
  353. end
  354. update_moving_sprite
  355. end
  356. #-------------------------------------------------------------------------
  357. # * new method: command_filter_2
  358. #-------------------------------------------------------------------------
  359. def update
  360. super
  361. if Input.trigger?(:X)
  362. if @show_mode == 1
  363. Sound.play_ok
  364. open_filter
  365. elsif @can_craft && !@item_window.active
  366. Sound.play_ok
  367. @confrim_window.open
  368. @slot_window.deactivate
  369. @confrim_window.activate
  370. end
  371. end
  372. if @old_index != @card_window.index
  373. refresh_info_window
  374. @old_index = @card_window.index
  375. end
  376. end
  377. #-------------------------------------------------------------------------
  378. # * new method: command_filter_2
  379. #-------------------------------------------------------------------------
  380. def terminate
  381. super
  382.  
  383. end
  384.  
  385. end
  386.  
  387. class Window_AdditionItemList < Window_ItemList
  388. #--------------------------------------------------------------------------
  389. # * Display in Enabled State?
  390. #--------------------------------------------------------------------------
  391. def enable?(item)
  392. return true
  393. end
  394. #--------------------------------------------------------------------------
  395. # * Include in Item List?
  396. #--------------------------------------------------------------------------
  397. def include?(item)
  398. case @category
  399. when :item
  400. item.is_a?(RPG::Item) && !item.key_item? && item.craft_rate != 0
  401. else
  402. false
  403. end
  404. end
  405. #--------------------------------------------------------------------------
  406. # * Create Item List
  407. #--------------------------------------------------------------------------
  408. def make_item_list
  409. @data = $game_party.all_items.select {|item| include?(item) }
  410. @data.push(nil) #if include?(nil)
  411. end
  412. #--------------------------------------------------------------------------
  413. # * Draw Item
  414. #--------------------------------------------------------------------------
  415. def draw_item(index)
  416. item = @data[index]
  417. if item
  418. rect = item_rect(index)
  419. rect.width -= 4
  420. draw_item_name(item, rect.x, rect.y, enable?(item))
  421. draw_item_number(rect, item)
  422. else
  423. rect = item_rect(index)
  424. rect.width -= 4
  425. change_color(system_color)
  426. draw_text(rect, "Remove Item",1)
  427. change_color(normal_color)
  428. end
  429. end
  430. #--------------------------------------------------------------------------
  431. # * Update Help Text
  432. #--------------------------------------------------------------------------
  433. def update_help
  434. @help_window.set_item(item)
  435. end
  436. end # Window_AdditionItemList
  437.  
  438. class Window_MenuCommand < Window_Command
  439. #---------------------------------------------------------------------------
  440. # overwritten method: add_main_commands
  441. #---------------------------------------------------------------------------
  442. alias_method(:dsi_card_crafting_add_main_commands, :add_main_commands)
  443. def add_main_commands
  444. dsi_card_crafting_add_main_commands
  445. if DSIVER144::CARD_CRAFTING::SHOW_MENU_COMMAND
  446. add_command("Card Crafting", :card_crafting, main_commands_enabled)
  447. end
  448. end
  449. end # Window_MenuCommand
  450.  
  451. class Scene_Menu < Scene_MenuBase
  452. #--------------------------------------------------------------------------
  453. # Adds a handler to access the card crafting system
  454. #--------------------------------------------------------------------------
  455. alias :dsiver144_create_command_window_dsi_card_crafting :create_command_window
  456. def create_command_window
  457. dsiver144_create_command_window_dsi_card_crafting
  458. if DSIVER144::CARD_CRAFTING::SHOW_MENU_COMMAND
  459. @command_window.set_handler(:card_crafting, method(:command_card_crafting))
  460. end
  461. end
  462. #--------------------------------------------------------------------------
  463. # * new method: command_card_crafting
  464. #--------------------------------------------------------------------------
  465. def command_card_crafting
  466. SceneManager.call(Scene_CardCrafting)
  467. end
  468. end # Scene_Menu
  469.  
  470. class Window_CraftingProgess < Window_Base
  471. #-------------------------------------------------------------------------
  472. # * new method: easeInOutQuad
  473. #-------------------------------------------------------------------------
  474. def easeInOutQuad(t, b, c, d)
  475. t = t / (d/2.0)
  476. if (t < 1)
  477. return c/2*t*t + b
  478. end
  479. t -= 1
  480. return -c/2.0 * (t*(t-2) - 1) + b
  481. end
  482. #-------------------------------------------------------------------------
  483. # * new method: play_progress
  484. #-------------------------------------------------------------------------
  485. def play_progress(id, success_rate)
  486. start_time = Graphics.frame_count
  487. progress = 0
  488. start_value = 0
  489. change_value = 100
  490. color1 = DSIVER144::CARD_CRAFTING::BAR_COLOR1
  491. color2 = DSIVER144::CARD_CRAFTING::BAR_COLOR2
  492. x = 0; y = 0; cw = contents_width
  493. rate = 0
  494. change_color(normal_color)
  495. while (current_time = Graphics.frame_count - start_time) < 120
  496. cur_value = easeInOutQuad(current_time, start_value, change_value, 120)
  497. contents.clear
  498. draw_text(x,y,cw,24,"Crafting...",1)
  499. rate = (cur_value.to_f / 100.0)
  500. draw_gauge(x + 4,y + 24,cw - 8, rate, color1, color2)
  501. self.x += 1 # Just for update -.-
  502. self.x -= 1 # Just for update -.-
  503. Graphics.update
  504. end
  505. if (t = rand(100)+1) <= success_rate
  506. contents.clear
  507. RPG::SE.new(DSIVER144::CARD_CRAFTING::SUCCESS_SE).play
  508. change_color(text_color(11))
  509. draw_text(x,y,cw,24,"Successful!",1)
  510. rate = 1.0
  511. change_color(normal_color)
  512. draw_text(x,y + 24,cw,24,"You got a new: #{$data_skills[id].name}",1)
  513. interpreter = Game_Interpreter2.new
  514. interpreter.add_card_to_coll(id)
  515. else
  516. contents.clear
  517. RPG::SE.new(DSIVER144::CARD_CRAFTING::FAIL_SE).play
  518. change_color(text_color(10))
  519. draw_text(x,y,cw,24,"Failed!",1)
  520. rate = 1.0
  521. change_color(normal_color)
  522. draw_text(x,y + 24,cw,24,"Oh, good luck next time!",1)
  523. end
  524. DSIVER144::CARD_CRAFTING.lose_craft_item(id)
  525. end
  526.  
  527. end
  528.  
  529. class Window_SlotHelpWindow < Window_Base
  530. #-------------------------------------------------------------------------
  531. # * new method: set_item
  532. #-------------------------------------------------------------------------
  533. def set_item(item,all_items)
  534. contents.clear
  535. x = 0; y = 0; cw = contents_width
  536. if item
  537. draw_text(x,y,cw,24,"Item Bonus chance:")
  538. y += 24
  539. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  540. draw_text(x,y,cw,24,"#{item.craft_rate}%",2)
  541. else
  542. draw_text(x,y,cw,24,"Item Bonus chance:")
  543. y += 24
  544. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  545. draw_text(x,y,cw,24,"????%",2)
  546. end
  547. chance = 0
  548. all_items.each do |item|
  549. next unless item
  550. chance += item.craft_rate
  551. end
  552. y += 24
  553. draw_text(x,y,cw,24,"Total Item Chance:")
  554. y += 24
  555. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  556. draw_text(x,y,cw,24,"#{chance}%",2)
  557. chance = 0
  558. $game_party.menu_actor.equips.each do |equip|
  559. next if equip.nil?
  560. chance += equip.craft_rate
  561. end
  562. y += 24
  563. draw_text(x,y,cw,24,"Equipment Chance:")
  564. y += 24
  565. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  566. draw_text(x,y,cw,24,"#{chance}%",2)
  567. end
  568.  
  569. end
  570.  
  571. class Window_CraftingConfirm < Window_Command
  572. #-------------------------------------------------------------------------
  573. # * new method: make_command_list
  574. #-------------------------------------------------------------------------
  575. def make_command_list
  576. add_command("Craft this card!", :ok)
  577. add_command("No", :cancel)
  578. end
  579. #-------------------------------------------------------------------------
  580. # * new method: window_width
  581. #-------------------------------------------------------------------------
  582. def window_width
  583. return 210
  584. end
  585. #--------------------------------------------------------------------------
  586. # * Get Alignment
  587. #--------------------------------------------------------------------------
  588. def alignment
  589. return 1
  590. end
  591.  
  592. end
  593.  
  594. class Window_CardCraftingItemSlots < Window_Command
  595. attr_accessor :slots
  596. attr_accessor :help_window
  597. #-------------------------------------------------------------------------
  598. # * new method: init_slots
  599. #-------------------------------------------------------------------------
  600. def init_slots
  601. @slots = []
  602. end
  603. #-------------------------------------------------------------------------
  604. # * new method: update_help
  605. #-------------------------------------------------------------------------
  606. def update_help
  607. @help_window.set_item(current_item, @slots) if @help_window
  608. end
  609. #-------------------------------------------------------------------------
  610. # * new method: refund_items
  611. #-------------------------------------------------------------------------
  612. def refund_items
  613. @slots.each do |item|
  614. $game_party.gain_item(item, 1)
  615. end
  616. @slots.clear
  617. end
  618. #-------------------------------------------------------------------------
  619. # * new method: set_item
  620. #-------------------------------------------------------------------------
  621. def set_item(item)
  622. @slots[current_slot_id] = item
  623. refresh
  624. end
  625. #-------------------------------------------------------------------------
  626. # * new method: current_item
  627. #-------------------------------------------------------------------------
  628. def current_item
  629. @slots[current_slot_id]
  630. end
  631. #--------------------------------------------------------------------------
  632. # * Draw Item
  633. #--------------------------------------------------------------------------
  634. def draw_item(index)
  635. change_color(normal_color, command_enabled?(index))
  636. if @slots && @slots[index]
  637. rect = item_rect_for_text(index)
  638. draw_text(rect, "S#{index+1}:", alignment)
  639. rect.x += 24
  640. draw_icon(@slots[index].icon_index, rect.x, rect.y)
  641. rect.x += 25; rect.width -= 24
  642. draw_text(rect, @slots[index].name, alignment)
  643. else
  644. draw_text(item_rect_for_text(index), command_name(index), alignment)
  645. end
  646. end
  647. #-------------------------------------------------------------------------
  648. # * overwrite method: add_command
  649. #-------------------------------------------------------------------------
  650. def add_command(name, symbol, enabled = true, ext = nil, slot_id)
  651. @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :slot_id=>slot_id})
  652. end
  653. #--------------------------------------------------------------------------
  654. # * Get Symbol of Selection Item
  655. #--------------------------------------------------------------------------
  656. def current_slot_id
  657. current_data ? current_data[:slot_id] : nil
  658. end
  659. #-------------------------------------------------------------------------
  660. # * new method: set_item
  661. #-------------------------------------------------------------------------
  662. def make_command_list
  663. for i in 0..4 do
  664. add_command("S#{i+1}: Empty", "slot_#{i}".to_sym, true, nil, i)
  665. end
  666. end
  667. #-------------------------------------------------------------------------
  668. # * new method: window_width
  669. #-------------------------------------------------------------------------
  670. def window_width
  671. return 185
  672. end
  673.  
  674. end
  675.  
  676. class Window_CardCraftingInfo < Window_Base
  677. attr_accessor :total_success_rate
  678. #-------------------------------------------------------------------------
  679. # * new method: dispose
  680. #-------------------------------------------------------------------------
  681. def dispose
  682. @card_sprite.dispose if @card_sprite
  683. super
  684. end
  685. #-------------------------------------------------------------------------
  686. # * new method: card_number_deckcol
  687. #-------------------------------------------------------------------------
  688. def card_number_deckcol(id)
  689. player_cards = $game_party.menu_actor.deck + $game_party.coll
  690. card_ids = player_cards.map {|card| card.id}.select {|card_id| card_id == id}
  691. return card_ids.size
  692. end
  693. #-------------------------------------------------------------------------
  694. # * new method: draw_info
  695. #-------------------------------------------------------------------------
  696. def draw_info(id, addition_items=nil)
  697. contents.clear
  698. if id
  699. card_data = $data_skills[id]
  700. card_bitmap = Cache.picture("Card#{id}")
  701. @card_sprite ||= Sprite.new
  702. @card_sprite.bitmap = card_bitmap
  703. @card_sprite.x = 150 + self.x + 12
  704. @card_sprite.y = 48 + self.y + 12
  705. @card_sprite.z = 130
  706. card_num = card_number_deckcol(id)
  707. if card_num == 0
  708. @card_sprite.tone = Tone.new(0,0,0,220)
  709. else
  710. @card_sprite.tone = Tone.new(0,0,0,0)
  711. end
  712. x = 0
  713. width = contents.width - card_bitmap.width
  714. contents.fill_rect(x,y + 4,width,42,Color.new(0,0,0,200))
  715. x = 150
  716. contents.fill_rect(x,y + 4,card_bitmap.width,42,Color.new(0,0,0,200))
  717. draw_text(x,y,card_bitmap.width,48,card_data.name,1)
  718. y = card_bitmap.height + 5
  719. ss_chance = card_data.craft_rate
  720. $game_party.menu_actor.equips.each do |equip|
  721. next if equip.nil?
  722. ss_chance += equip.craft_rate if ss_chance
  723. end
  724. if addition_items
  725. addition_items.each do |item|
  726. next if item.nil?
  727. ss_chance += item.craft_rate if ss_chance
  728. end
  729. end
  730. ss_chance = [[0,ss_chance].max,100].min
  731. @total_success_rate = ss_chance
  732. change_color(text_color(5))
  733. y += 48
  734. contents.fill_rect(x,y - 2,card_bitmap.width,40,Color.new(0,0,0,200))
  735. draw_text(x,y+2,card_bitmap.width,24,"Success Chance: #{ss_chance}%",1)
  736. change_color(text_color(0))
  737. x = 0; y = 24
  738. width = contents.width - card_bitmap.width
  739. draw_text(x,y-24,width,48,"Materials",1)
  740. y += 24
  741. change_color(normal_color,false)
  742. 8.times do |i|
  743. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  744. draw_text(x,y,width,24,"Empty",1)
  745. y += 27
  746. end
  747. change_color(normal_color,true)
  748. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  749. draw_text(x + 3,y,width,24,"You owned:",0)
  750. draw_text(x + 3,y,width - 2,24,"#{card_num}",2)
  751. y += 28
  752. contents.fill_rect(x,y,width,50,Color.new(0,0,0,200))
  753. if DSIVER144::CARD_CRAFTING.can_craft(id)
  754. change_color(text_color(11))
  755. draw_text(x,y + 14,width,24,"Can craft!",1)
  756. else
  757. change_color(text_color(10))
  758. draw_text(x,y + 14,width,24,"Can't craft!",1)
  759. end
  760. y = 24 + 24
  761. card_data.craft_materials[:item].each do |material|
  762. name = $data_items[material[0]].name; icon_index = $data_items[material[0]].icon_index
  763. contents.clear_rect(x,y,width,24)
  764. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  765. if $game_party.item_number($data_items[material[0]]) < material[1]
  766. change_color(normal_color,false)
  767. else
  768. change_color(text_color(11))
  769. end
  770. draw_icon(icon_index,x+1,y)
  771. draw_text(x+26,y,width,24,name)
  772. draw_text(x,y,width,24,"x#{material[1]}",2)
  773. y += 27
  774. end
  775. change_color(normal_color, true)
  776. else
  777. if @card_sprite
  778. @card_sprite.dispose
  779. @card_sprite = nil
  780. end
  781. draw_text(0,0,contents_width,contents_height,"Please select a card",1)
  782. end
  783. end
  784.  
  785. end
  786.  
  787. class Window_CardCraftingHelp < Window_Base
  788. #-------------------------------------------------------------------------
  789. # * method: initialize
  790. #-------------------------------------------------------------------------
  791. def initialize
  792. super(0,Graphics.height-48,Graphics.width,48)
  793. refresh
  794. end
  795. #--------------------------------------------------------------------------
  796. # * Draw Text with Control Characters
  797. #--------------------------------------------------------------------------
  798. def draw_text_ex(x, y, text)
  799. text = convert_escape_characters(text)
  800. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  801. process_character(text.slice!(0, 1), text, pos) until text.empty?
  802. end
  803. #-------------------------------------------------------------------------
  804. # * new method: refresh
  805. #-------------------------------------------------------------------------
  806. def refresh(enable_filter=true, mode=1)
  807. contents.clear
  808. change_color(normal_color,enable_filter)
  809. if mode == 1
  810. draw_text_ex(0,0,DSIVER144::CARD_CRAFTING::FILTER_BUTTON_TEXT)
  811. else
  812. draw_text_ex(0,0,DSIVER144::CARD_CRAFTING::CRAFT_BUTTON_TEXT)
  813. end
  814. change_color(normal_color,true)
  815. draw_text_ex(contents_width - DSIVER144::CARD_CRAFTING::OTHER_BUTTONS_MARGIN,0,DSIVER144::CARD_CRAFTING::OTHER_BUTTONS_TEXT)
  816. end
  817. end # Window_CardLibraryHelp
  818.  
  819. class Window_CardCraftingList < Window_Command
  820. include DSIVER144::CARD_LIBRARY
  821. attr_accessor :list
  822. attr_accessor :card_data
  823. attr_accessor :filter_window
  824. #-------------------------------------------------------------------------
  825. # * new method: current_card_data
  826. #-------------------------------------------------------------------------
  827. def current_card_data
  828. @card_data ? @card_data[index] : nil
  829. end
  830. #-------------------------------------------------------------------------
  831. # * new method: match_filter?
  832. #-------------------------------------------------------------------------
  833. def match_filter?(card,card2)
  834. return true if !@filter_window
  835. filter_1_type = @filter_window.current_type
  836. filter_2_type = @filter_window.current_type2
  837. type1 = card ? card[:type] : 0
  838. type2 = card2.type
  839. return false unless (type1 == filter_1_type) || filter_1_type == 0
  840. return false unless (type2 == filter_2_type) || filter_2_type == 0
  841. return true
  842. end
  843. #-------------------------------------------------------------------------
  844. # * new method: no_filter?
  845. #-------------------------------------------------------------------------
  846. def no_filter?
  847. return true if !@filter_window
  848. return true if @filter_window.current_type == 0 && @filter_window.current_type2 == 0
  849. return false
  850. end
  851. #-------------------------------------------------------------------------
  852. # * method: has_card_deckcoll?
  853. #-------------------------------------------------------------------------
  854. def has_card_deckcoll?(id)
  855. for card in $game_party.coll
  856. return true if card.id == id
  857. end
  858. for actor in $game_party.members
  859. for card in actor.deck
  860. return true if card.id == id
  861. end
  862. end
  863. return false
  864. end
  865. #-------------------------------------------------------------------------
  866. # * overwrite method: add_command
  867. #-------------------------------------------------------------------------
  868. def add_command(name, symbol, enabled = true, ext = nil, skill_id)
  869. @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :skill_id=>skill_id})
  870. end
  871. #--------------------------------------------------------------------------
  872. # * Get Symbol of Selection Item
  873. #--------------------------------------------------------------------------
  874. def current_skill_id
  875. current_data ? current_data[:skill_id] : nil
  876. end
  877. #-------------------------------------------------------------------------
  878. # * new method: make_command_list
  879. #-------------------------------------------------------------------------
  880. def make_command_list
  881. @card_data ||= []
  882. @card_data.clear
  883. card_list = DSIVER144::CARD_LIBRARY.get_all_card
  884. card_list = card_list.select {|card| card.craft_show }
  885. if !DSIVER144::CARD_CRAFTING::TESTING_MODE
  886. card_list = card_list.select do |card|
  887. card.craft_show == 0 || $game_party.has_item?($data_items[card.craft_show])
  888. end
  889. end
  890. card_list.sort! {|a,b| a.card_id <=> b.card_id}
  891. card_list.each do |card|
  892. check = match_filter?(CARD_CONFIG[card.id],card)
  893. if check
  894. name = card.name
  895. add_command(name, "#{card.card_id}".to_sym, true, nil, card.id)
  896. @card_data.push(card)
  897. elsif no_filter?
  898. name = "????????????????????"
  899. add_command(name, :empty_card, false, nil, card.id)
  900. @card_data.push(nil)
  901. end
  902. end
  903. end
  904. #-------------------------------------------------------------------------
  905. # * new method: window_width
  906. #-------------------------------------------------------------------------
  907. def window_width
  908. return 185
  909. end
  910. #-------------------------------------------------------------------------
  911. # * new method: window_height
  912. #-------------------------------------------------------------------------
  913. def window_height
  914. return 320
  915. end
  916.  
  917. end # Window_CardList
  918.  
  919. class Window_CardFilter < Window_Command
  920. attr_accessor :filter_1
  921. attr_accessor :filter_2
  922. attr_accessor :card_types
  923. attr_accessor :card_2ndtypes
  924. #-------------------------------------------------------------------------
  925. # * new method: current_type
  926. #-------------------------------------------------------------------------
  927. def current_type
  928. @card_types[@filter_1] - 1
  929. end
  930. #-------------------------------------------------------------------------
  931. # * new method: current_type2
  932. #-------------------------------------------------------------------------
  933. def current_type2
  934. @card_2ndtypes[@filter_2] - 1
  935. end
  936. #-------------------------------------------------------------------------
  937. # * new method: increase_filter_1
  938. #-------------------------------------------------------------------------
  939. def increase_filter_1
  940. @filter_1 += 1
  941. if @filter_1 > @card_types.size - 1
  942. @filter_1 = 0
  943. end
  944. end
  945. #-------------------------------------------------------------------------
  946. # * new method: increase_filter_2
  947. #-------------------------------------------------------------------------
  948. def increase_filter_2
  949. @filter_2 += 1
  950. if @filter_2 > @card_2ndtypes.size - 1
  951. @filter_2 = 0
  952. end
  953. end
  954. #-------------------------------------------------------------------------
  955. # * new method: make_command_list
  956. #-------------------------------------------------------------------------
  957. def make_command_list
  958. @filter_1 ||= 0
  959. @filter_2 ||= 0
  960. @card_types ||= CARD_TYPE.keys
  961. @card_2ndtypes ||= TYPE.keys
  962. if @filter_1 == 0
  963. name = "---------------"
  964. else
  965. name = CARD_TYPE[@card_types[@filter_1]-1]
  966. end
  967. if @filter_2 == 0
  968. name2 = "---------------"
  969. else
  970. name2 = TYPE[@card_2ndtypes[@filter_2]-1]
  971. end
  972. add_command("Filter by Type: " + name, :type)
  973. add_command("Filter by 2nd Type: " + name2, :secondary)
  974. end
  975. #-------------------------------------------------------------------------
  976. # * new method: window_width
  977. #-------------------------------------------------------------------------
  978. def window_width
  979. return 300
  980. end
  981. end # Window_CardFilter
  982.  
  983. #==============================================================================
  984. # ** DataManager
  985. #==============================================================================
  986. module DataManager
  987. class << self
  988. alias crafting_system_load_database load_database
  989. alias crafting_system_init init
  990. end
  991. #----------------------------------------------------------------------------
  992. # * alias method: init
  993. #----------------------------------------------------------------------------
  994. def self.init
  995. crafting_system_init
  996. load_notetags_crafting_system
  997. end
  998. #----------------------------------------------------------------------------
  999. # * alias method: load_database
  1000. #----------------------------------------------------------------------------
  1001. def self.load_database
  1002. crafting_system_load_database
  1003. end
  1004. #----------------------------------------------------------------------------
  1005. # * new method: load_notetags_hp_shield
  1006. #----------------------------------------------------------------------------
  1007. def self.load_notetags_crafting_system
  1008. groups = [$data_skills, $data_weapons, $data_armors, $data_items]
  1009. for group in groups
  1010. for obj in group
  1011. next if obj.nil?
  1012. next if obj.name == ""
  1013. obj.load_notetags_crafting
  1014. end
  1015. end
  1016. end
  1017. end # DataManager
  1018.  
  1019. class RPG::EquipItem
  1020.  
  1021. attr_accessor :craft_rate
  1022.  
  1023. def load_notetags_crafting
  1024. @craft_rate = 0
  1025. self.note.split(/[\r\n]+/).each do |line|
  1026. if line =~ /<craft chance:\s*(.+)\%>/i
  1027. @craft_rate = $1.to_f
  1028. end
  1029. end
  1030. end
  1031.  
  1032. end # RPG::EquipItem
  1033.  
  1034. class RPG::Item
  1035.  
  1036. attr_accessor :craft_rate
  1037.  
  1038. def load_notetags_crafting
  1039. @craft_rate = 0
  1040. self.note.split(/[\r\n]+/).each do |line|
  1041. if line =~ /<craft chance:\s*(.+)\%>/i
  1042. @craft_rate = $1.to_f
  1043. end
  1044. end
  1045. end
  1046.  
  1047. end # RPG::EquipItem
  1048.  
  1049. #==============================================================================
  1050. # ** RPG::Skill
  1051. #==============================================================================
  1052. class RPG::Skill
  1053. attr_accessor :craft_show
  1054. attr_accessor :craft_materials
  1055. attr_accessor :craft_rate
  1056. #----------------------------------------------------------------------------
  1057. # * new method: load_notetags_hp_shield
  1058. #----------------------------------------------------------------------------
  1059. def load_notetags_crafting
  1060. @craft_show = nil
  1061. @craft_rate = 0
  1062. @craft_materials = nil
  1063. self.note.split(/[\r\n]+/).each do |line|
  1064. if line =~ /<craft show require:\s*(none|\d+)>/i
  1065. @craft_show = 0 if $1 == "none"
  1066. @craft_show = $1.to_i if $1 != "none"
  1067. end
  1068. if line =~ /<craft chance:\s*(.+)\%>/i
  1069. @craft_rate = $1.to_f
  1070. end
  1071. if line =~ /<craft materials:\s*(.+)>/i
  1072. @craft_materials ||= {}
  1073. @craft_materials[:item] ||= []
  1074. text = $1.clone
  1075. text.split(",").each do |item|
  1076. if item =~ /(\d+)\+(\d+)i/i
  1077. @craft_materials[:item] << [$2.to_i,$1.to_i]
  1078. end
  1079. end
  1080. end
  1081. end
  1082. p @craft_materials[:item] if @craft_materials
  1083. end
  1084. end # RPG::Skill
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement