dsiver144

DSI Card Crafting System

Jun 9th, 2017
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.30 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. # * Update Help Text
  396. #--------------------------------------------------------------------------
  397. def update_help
  398. @help_window.set_item(item)
  399. end
  400. end # Window_AdditionItemList
  401.  
  402. class Window_MenuCommand < Window_Command
  403. #---------------------------------------------------------------------------
  404. # overwritten method: add_main_commands
  405. #---------------------------------------------------------------------------
  406. alias_method(:dsi_card_crafting_add_main_commands, :add_main_commands)
  407. def add_main_commands
  408. dsi_card_crafting_add_main_commands
  409. if DSIVER144::CARD_CRAFTING::SHOW_MENU_COMMAND
  410. add_command("Card Crafting", :card_crafting, main_commands_enabled)
  411. end
  412. end
  413. end # Window_MenuCommand
  414.  
  415. class Scene_Menu < Scene_MenuBase
  416. #--------------------------------------------------------------------------
  417. # Adds a handler to access the card crafting system
  418. #--------------------------------------------------------------------------
  419. alias :dsiver144_create_command_window_dsi_card_crafting :create_command_window
  420. def create_command_window
  421. dsiver144_create_command_window_dsi_card_crafting
  422. if DSIVER144::CARD_CRAFTING::SHOW_MENU_COMMAND
  423. @command_window.set_handler(:card_crafting, method(:command_card_crafting))
  424. end
  425. end
  426. #--------------------------------------------------------------------------
  427. # * new method: command_card_crafting
  428. #--------------------------------------------------------------------------
  429. def command_card_crafting
  430. SceneManager.call(Scene_CardCrafting)
  431. end
  432. end # Scene_Menu
  433.  
  434. class Window_CraftingProgess < Window_Base
  435. #-------------------------------------------------------------------------
  436. # * new method: easeInOutQuad
  437. #-------------------------------------------------------------------------
  438. def easeInOutQuad(t, b, c, d)
  439. t = t / (d/2.0)
  440. if (t < 1)
  441. return c/2*t*t + b
  442. end
  443. t -= 1
  444. return -c/2.0 * (t*(t-2) - 1) + b
  445. end
  446. #-------------------------------------------------------------------------
  447. # * new method: play_progress
  448. #-------------------------------------------------------------------------
  449. def play_progress(id, success_rate)
  450. start_time = Graphics.frame_count
  451. progress = 0
  452. start_value = 0
  453. change_value = 100
  454. color1 = DSIVER144::CARD_CRAFTING::BAR_COLOR1
  455. color2 = DSIVER144::CARD_CRAFTING::BAR_COLOR2
  456. x = 0; y = 0; cw = contents_width
  457. rate = 0
  458. change_color(normal_color)
  459. while (current_time = Graphics.frame_count - start_time) < 120
  460. cur_value = easeInOutQuad(current_time, start_value, change_value, 120)
  461. contents.clear
  462. draw_text(x,y,cw,24,"Crafting...",1)
  463. rate = (cur_value.to_f / 100.0)
  464. draw_gauge(x + 4,y + 24,cw - 8, rate, color1, color2)
  465. self.x += 1 # Just for update -.-
  466. self.x -= 1 # Just for update -.-
  467. Graphics.update
  468. end
  469. if (t = rand(100)+1) <= success_rate
  470. contents.clear
  471. RPG::SE.new(DSIVER144::CARD_CRAFTING::SUCCESS_SE).play
  472. change_color(text_color(11))
  473. draw_text(x,y,cw,24,"Successful!",1)
  474. rate = 1.0
  475. change_color(normal_color)
  476. draw_text(x,y + 24,cw,24,"You got a new: #{$data_skills[id].name}",1)
  477. interpreter = Game_Interpreter2.new
  478. interpreter.add_card_to_coll(id)
  479. else
  480. contents.clear
  481. RPG::SE.new(DSIVER144::CARD_CRAFTING::FAIL_SE).play
  482. change_color(text_color(10))
  483. draw_text(x,y,cw,24,"Failed!",1)
  484. rate = 1.0
  485. change_color(normal_color)
  486. draw_text(x,y + 24,cw,24,"Oh, good luck next time!",1)
  487. end
  488. DSIVER144::CARD_CRAFTING.lose_craft_item(id)
  489. end
  490.  
  491. end
  492.  
  493. class Window_SlotHelpWindow < Window_Base
  494. #-------------------------------------------------------------------------
  495. # * new method: set_item
  496. #-------------------------------------------------------------------------
  497. def set_item(item,all_items)
  498. contents.clear
  499. x = 0; y = 0; cw = contents_width
  500. if item
  501. draw_text(x,y,cw,24,"Item Bonus chance:")
  502. y += 24
  503. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  504. draw_text(x,y,cw,24,"#{item.craft_rate}%",2)
  505. else
  506. draw_text(x,y,cw,24,"Total Item chance:")
  507. y += 24
  508. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  509. draw_text(x,y,cw,24,"????%",2)
  510. end
  511. chance = 0
  512. all_items.each do |item|
  513. next unless item
  514. chance += item.craft_rate
  515. end
  516. y += 24
  517. draw_text(x,y,cw,24,"Total Item Chance:")
  518. y += 24
  519. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  520. draw_text(x,y,cw,24,"#{chance}%",2)
  521. chance = 0
  522. $game_party.menu_actor.equips.each do |equip|
  523. next if equip.nil?
  524. chance += equip.craft_rate
  525. end
  526. y += 24
  527. draw_text(x,y,cw,24,"Equipment Chance:")
  528. y += 24
  529. contents.fill_rect(x,y,cw,24,Color.new(0,0,0,200))
  530. draw_text(x,y,cw,24,"#{chance}%",2)
  531. end
  532.  
  533. end
  534.  
  535. class Window_CraftingConfirm < Window_Command
  536. #-------------------------------------------------------------------------
  537. # * new method: make_command_list
  538. #-------------------------------------------------------------------------
  539. def make_command_list
  540. add_command("Craft this card!", :ok)
  541. add_command("No", :cancel)
  542. end
  543. #-------------------------------------------------------------------------
  544. # * new method: window_width
  545. #-------------------------------------------------------------------------
  546. def window_width
  547. return 210
  548. end
  549. #--------------------------------------------------------------------------
  550. # * Get Alignment
  551. #--------------------------------------------------------------------------
  552. def alignment
  553. return 1
  554. end
  555.  
  556. end
  557.  
  558. class Window_CardCraftingItemSlots < Window_Command
  559. attr_accessor :slots
  560. attr_accessor :help_window
  561. #-------------------------------------------------------------------------
  562. # * new method: init_slots
  563. #-------------------------------------------------------------------------
  564. def init_slots
  565. @slots = []
  566. end
  567. #-------------------------------------------------------------------------
  568. # * new method: update_help
  569. #-------------------------------------------------------------------------
  570. def update_help
  571. @help_window.set_item(current_item, @slots) if @help_window
  572. end
  573. #-------------------------------------------------------------------------
  574. # * new method: refund_items
  575. #-------------------------------------------------------------------------
  576. def refund_items
  577. @slots.each do |item|
  578. $game_party.gain_item(item, 1)
  579. end
  580. @slots.clear
  581. end
  582. #-------------------------------------------------------------------------
  583. # * new method: set_item
  584. #-------------------------------------------------------------------------
  585. def set_item(item)
  586. @slots[current_slot_id] = item
  587. refresh
  588. end
  589. #-------------------------------------------------------------------------
  590. # * new method: current_item
  591. #-------------------------------------------------------------------------
  592. def current_item
  593. @slots[current_slot_id]
  594. end
  595. #--------------------------------------------------------------------------
  596. # * Draw Item
  597. #--------------------------------------------------------------------------
  598. def draw_item(index)
  599. change_color(normal_color, command_enabled?(index))
  600. if @slots && @slots[index]
  601. rect = item_rect_for_text(index)
  602. draw_text(rect, "S#{index+1}:", alignment)
  603. rect.x += 24
  604. draw_icon(@slots[index].icon_index, rect.x, rect.y)
  605. rect.x += 25; rect.width -= 24
  606. draw_text(rect, @slots[index].name, alignment)
  607. else
  608. draw_text(item_rect_for_text(index), command_name(index), alignment)
  609. end
  610. end
  611. #-------------------------------------------------------------------------
  612. # * overwrite method: add_command
  613. #-------------------------------------------------------------------------
  614. def add_command(name, symbol, enabled = true, ext = nil, slot_id)
  615. @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :slot_id=>slot_id})
  616. end
  617. #--------------------------------------------------------------------------
  618. # * Get Symbol of Selection Item
  619. #--------------------------------------------------------------------------
  620. def current_slot_id
  621. current_data ? current_data[:slot_id] : nil
  622. end
  623. #-------------------------------------------------------------------------
  624. # * new method: set_item
  625. #-------------------------------------------------------------------------
  626. def make_command_list
  627. for i in 0..4 do
  628. add_command("S#{i+1}: Empty", "slot_#{i}".to_sym, true, nil, i)
  629. end
  630. end
  631. #-------------------------------------------------------------------------
  632. # * new method: window_width
  633. #-------------------------------------------------------------------------
  634. def window_width
  635. return 185
  636. end
  637.  
  638. end
  639.  
  640. class Window_CardCraftingInfo < Window_Base
  641. attr_accessor :total_success_rate
  642. #-------------------------------------------------------------------------
  643. # * new method: dispose
  644. #-------------------------------------------------------------------------
  645. def dispose
  646. @card_sprite.dispose if @card_sprite
  647. super
  648. end
  649. #-------------------------------------------------------------------------
  650. # * new method: card_number_deckcol
  651. #-------------------------------------------------------------------------
  652. def card_number_deckcol(id)
  653. player_cards = $game_party.menu_actor.deck + $game_party.coll
  654. card_ids = player_cards.map {|card| card.id}.select {|card_id| card_id == id}
  655. return card_ids.size
  656. end
  657. #-------------------------------------------------------------------------
  658. # * new method: draw_info
  659. #-------------------------------------------------------------------------
  660. def draw_info(id, addition_items=nil)
  661. contents.clear
  662. if id
  663. card_data = $data_skills[id]
  664. card_bitmap = Cache.picture("Card#{id}")
  665. @card_sprite ||= Sprite.new
  666. @card_sprite.bitmap = card_bitmap
  667. @card_sprite.x = 150 + self.x + 12
  668. @card_sprite.y = 48 + self.y + 12
  669. @card_sprite.z = 130
  670. card_num = card_number_deckcol(id)
  671. if card_num == 0
  672. @card_sprite.tone = Tone.new(0,0,0,220)
  673. else
  674. @card_sprite.tone = Tone.new(0,0,0,0)
  675. end
  676. x = 0
  677. width = contents.width - card_bitmap.width
  678. contents.fill_rect(x,y + 4,width,42,Color.new(0,0,0,200))
  679. x = 150
  680. contents.fill_rect(x,y + 4,card_bitmap.width,42,Color.new(0,0,0,200))
  681. draw_text(x,y,card_bitmap.width,48,card_data.name,1)
  682. y = card_bitmap.height + 5
  683. ss_chance = card_data.craft_rate
  684. $game_party.menu_actor.equips.each do |equip|
  685. next if equip.nil?
  686. ss_chance += equip.craft_rate if ss_chance
  687. end
  688. if addition_items
  689. addition_items.each do |item|
  690. next if item.nil?
  691. ss_chance += item.craft_rate if ss_chance
  692. end
  693. end
  694. ss_chance = [[0,ss_chance].max,100].min
  695. @total_success_rate = ss_chance
  696. change_color(text_color(5))
  697. y += 48
  698. contents.fill_rect(x,y - 2,card_bitmap.width,40,Color.new(0,0,0,200))
  699. draw_text(x,y+2,card_bitmap.width,24,"Success Chance: #{ss_chance}%",1)
  700. change_color(text_color(0))
  701. x = 0; y = 24
  702. width = contents.width - card_bitmap.width
  703. draw_text(x,y-24,width,48,"Materials",1)
  704. y += 24
  705. change_color(normal_color,false)
  706. 8.times do |i|
  707. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  708. draw_text(x,y,width,24,"Empty",1)
  709. y += 27
  710. end
  711. change_color(normal_color,true)
  712. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  713. draw_text(x + 3,y,width,24,"You owned: #{card_num}",0)
  714. y += 28
  715. contents.fill_rect(x,y,width,50,Color.new(0,0,0,200))
  716. if DSIVER144::CARD_CRAFTING.can_craft(id)
  717. change_color(text_color(11))
  718. draw_text(x,y + 14,width,24,"Can craft!",1)
  719. else
  720. change_color(text_color(10))
  721. draw_text(x,y + 14,width,24,"Can't craft!",1)
  722. end
  723. y = 24 + 24
  724. card_data.craft_materials[:item].each do |material|
  725. name = $data_items[material[0]].name; icon_index = $data_items[material[0]].icon_index
  726. contents.clear_rect(x,y,width,24)
  727. contents.fill_rect(x,y,width,24,Color.new(0,0,0,200))
  728. if $game_party.item_number($data_items[material[0]]) < material[1]
  729. change_color(normal_color,false)
  730. else
  731. change_color(text_color(11))
  732. end
  733. draw_icon(icon_index,x+1,y)
  734. draw_text(x+26,y,width,24,name)
  735. draw_text(x,y,width,24,"x#{material[1]}",2)
  736. y += 27
  737. end
  738. change_color(normal_color, true)
  739. else
  740. if @card_sprite
  741. @card_sprite.dispose
  742. @card_sprite = nil
  743. end
  744. draw_text(0,0,contents_width,contents_height,"Please select a card",1)
  745. end
  746. end
  747.  
  748. end
  749.  
  750. class Window_CardCraftingHelp < Window_Base
  751. #-------------------------------------------------------------------------
  752. # * method: initialize
  753. #-------------------------------------------------------------------------
  754. def initialize
  755. super(0,Graphics.height-48,Graphics.width,48)
  756. refresh
  757. end
  758. #--------------------------------------------------------------------------
  759. # * Draw Text with Control Characters
  760. #--------------------------------------------------------------------------
  761. def draw_text_ex(x, y, text)
  762. text = convert_escape_characters(text)
  763. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  764. process_character(text.slice!(0, 1), text, pos) until text.empty?
  765. end
  766. #-------------------------------------------------------------------------
  767. # * new method: refresh
  768. #-------------------------------------------------------------------------
  769. def refresh(enable_filter=true, mode=1)
  770. contents.clear
  771. change_color(normal_color,enable_filter)
  772. if mode == 1
  773. draw_text_ex(0,0,DSIVER144::CARD_CRAFTING::FILTER_BUTTON_TEXT)
  774. else
  775. draw_text_ex(0,0,DSIVER144::CARD_CRAFTING::CRAFT_BUTTON_TEXT)
  776. end
  777. change_color(normal_color,true)
  778. draw_text_ex(contents_width - DSIVER144::CARD_CRAFTING::OTHER_BUTTONS_MARGIN,0,DSIVER144::CARD_CRAFTING::OTHER_BUTTONS_TEXT)
  779. end
  780. end # Window_CardLibraryHelp
  781.  
  782. class Window_CardCraftingList < Window_Command
  783. include DSIVER144::CARD_LIBRARY
  784. attr_accessor :list
  785. attr_accessor :card_data
  786. attr_accessor :filter_window
  787. #-------------------------------------------------------------------------
  788. # * new method: current_card_data
  789. #-------------------------------------------------------------------------
  790. def current_card_data
  791. @card_data ? @card_data[index] : nil
  792. end
  793. #-------------------------------------------------------------------------
  794. # * new method: match_filter?
  795. #-------------------------------------------------------------------------
  796. def match_filter?(card,card2)
  797. return true if !@filter_window
  798. filter_1_type = @filter_window.current_type
  799. filter_2_type = @filter_window.current_type2
  800. type1 = card ? card[:type] : 0
  801. type2 = card2.type
  802. return false unless (type1 == filter_1_type) || filter_1_type == 0
  803. return false unless (type2 == filter_2_type) || filter_2_type == 0
  804. return true
  805. end
  806. #-------------------------------------------------------------------------
  807. # * new method: no_filter?
  808. #-------------------------------------------------------------------------
  809. def no_filter?
  810. return true if !@filter_window
  811. return true if @filter_window.current_type == 0 && @filter_window.current_type2 == 0
  812. return false
  813. end
  814. #-------------------------------------------------------------------------
  815. # * method: has_card_deckcoll?
  816. #-------------------------------------------------------------------------
  817. def has_card_deckcoll?(id)
  818. for card in $game_party.coll
  819. return true if card.id == id
  820. end
  821. for actor in $game_party.members
  822. for card in actor.deck
  823. return true if card.id == id
  824. end
  825. end
  826. return false
  827. end
  828. #-------------------------------------------------------------------------
  829. # * overwrite method: add_command
  830. #-------------------------------------------------------------------------
  831. def add_command(name, symbol, enabled = true, ext = nil, skill_id)
  832. @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :skill_id=>skill_id})
  833. end
  834. #--------------------------------------------------------------------------
  835. # * Get Symbol of Selection Item
  836. #--------------------------------------------------------------------------
  837. def current_skill_id
  838. current_data ? current_data[:skill_id] : nil
  839. end
  840. #-------------------------------------------------------------------------
  841. # * new method: make_command_list
  842. #-------------------------------------------------------------------------
  843. def make_command_list
  844. @card_data ||= []
  845. @card_data.clear
  846. card_list = DSIVER144::CARD_LIBRARY.get_all_card
  847. card_list = card_list.select {|card| card.craft_show }
  848. if !DSIVER144::CARD_CRAFTING::TESTING_MODE
  849. card_list = card_list.select do |card|
  850. card.craft_show == 0 || $game_party.has_item?($data_items[card.craft_show])
  851. end
  852. end
  853. card_list.sort! {|a,b| a.card_id <=> b.card_id}
  854. card_list.each do |card|
  855. check = match_filter?(CARD_CONFIG[card.id],card)
  856. if check
  857. name = card.name
  858. add_command(name, "#{card.card_id}".to_sym, true, nil, card.id)
  859. @card_data.push(card)
  860. elsif no_filter?
  861. name = "????????????????????"
  862. add_command(name, :empty_card, false, nil, card.id)
  863. @card_data.push(nil)
  864. end
  865. end
  866. end
  867. #-------------------------------------------------------------------------
  868. # * new method: window_width
  869. #-------------------------------------------------------------------------
  870. def window_width
  871. return 185
  872. end
  873. #-------------------------------------------------------------------------
  874. # * new method: window_height
  875. #-------------------------------------------------------------------------
  876. def window_height
  877. return 320
  878. end
  879.  
  880. end # Window_CardList
  881.  
  882. class Window_CardFilter < Window_Command
  883. attr_accessor :filter_1
  884. attr_accessor :filter_2
  885. attr_accessor :card_types
  886. attr_accessor :card_2ndtypes
  887. #-------------------------------------------------------------------------
  888. # * new method: current_type
  889. #-------------------------------------------------------------------------
  890. def current_type
  891. @card_types[@filter_1] - 1
  892. end
  893. #-------------------------------------------------------------------------
  894. # * new method: current_type2
  895. #-------------------------------------------------------------------------
  896. def current_type2
  897. @card_2ndtypes[@filter_2] - 1
  898. end
  899. #-------------------------------------------------------------------------
  900. # * new method: increase_filter_1
  901. #-------------------------------------------------------------------------
  902. def increase_filter_1
  903. @filter_1 += 1
  904. if @filter_1 > @card_types.size - 1
  905. @filter_1 = 0
  906. end
  907. end
  908. #-------------------------------------------------------------------------
  909. # * new method: increase_filter_2
  910. #-------------------------------------------------------------------------
  911. def increase_filter_2
  912. @filter_2 += 1
  913. if @filter_2 > @card_2ndtypes.size - 1
  914. @filter_2 = 0
  915. end
  916. end
  917. #-------------------------------------------------------------------------
  918. # * new method: make_command_list
  919. #-------------------------------------------------------------------------
  920. def make_command_list
  921. @filter_1 ||= 0
  922. @filter_2 ||= 0
  923. @card_types ||= CARD_TYPE.keys
  924. @card_2ndtypes ||= TYPE.keys
  925. if @filter_1 == 0
  926. name = "---------------"
  927. else
  928. name = CARD_TYPE[@card_types[@filter_1]-1]
  929. end
  930. if @filter_2 == 0
  931. name2 = "---------------"
  932. else
  933. name2 = TYPE[@card_2ndtypes[@filter_2]-1]
  934. end
  935. add_command("Filter by Type: " + name, :type)
  936. add_command("Filter by 2nd Type: " + name2, :secondary)
  937. end
  938. #-------------------------------------------------------------------------
  939. # * new method: window_width
  940. #-------------------------------------------------------------------------
  941. def window_width
  942. return 300
  943. end
  944. end # Window_CardFilter
  945.  
  946. #==============================================================================
  947. # ** DataManager
  948. #==============================================================================
  949. module DataManager
  950. class << self
  951. alias crafting_system_load_database load_database
  952. alias crafting_system_init init
  953. end
  954. #----------------------------------------------------------------------------
  955. # * alias method: init
  956. #----------------------------------------------------------------------------
  957. def self.init
  958. crafting_system_init
  959. load_notetags_crafting_system
  960. end
  961. #----------------------------------------------------------------------------
  962. # * alias method: load_database
  963. #----------------------------------------------------------------------------
  964. def self.load_database
  965. crafting_system_load_database
  966. end
  967. #----------------------------------------------------------------------------
  968. # * new method: load_notetags_hp_shield
  969. #----------------------------------------------------------------------------
  970. def self.load_notetags_crafting_system
  971. groups = [$data_skills, $data_weapons, $data_armors, $data_items]
  972. for group in groups
  973. for obj in group
  974. next if obj.nil?
  975. next if obj.name == ""
  976. obj.load_notetags_crafting
  977. end
  978. end
  979. end
  980. end # DataManager
  981.  
  982. class RPG::EquipItem
  983.  
  984. attr_accessor :craft_rate
  985.  
  986. def load_notetags_crafting
  987. @craft_rate = 0
  988. self.note.split(/[\r\n]+/).each do |line|
  989. if line =~ /<craft chance:\s*(.+)\%>/i
  990. @craft_rate = $1.to_f
  991. end
  992. end
  993. end
  994.  
  995. end # RPG::EquipItem
  996.  
  997. class RPG::Item
  998.  
  999. attr_accessor :craft_rate
  1000.  
  1001. def load_notetags_crafting
  1002. @craft_rate = 0
  1003. self.note.split(/[\r\n]+/).each do |line|
  1004. if line =~ /<craft chance:\s*(.+)\%>/i
  1005. @craft_rate = $1.to_f
  1006. end
  1007. end
  1008. end
  1009.  
  1010. end # RPG::EquipItem
  1011.  
  1012. #==============================================================================
  1013. # ** RPG::Skill
  1014. #==============================================================================
  1015. class RPG::Skill
  1016. attr_accessor :craft_show
  1017. attr_accessor :craft_materials
  1018. attr_accessor :craft_rate
  1019. #----------------------------------------------------------------------------
  1020. # * new method: load_notetags_hp_shield
  1021. #----------------------------------------------------------------------------
  1022. def load_notetags_crafting
  1023. @craft_show = nil
  1024. @craft_rate = 0
  1025. @craft_materials = nil
  1026. self.note.split(/[\r\n]+/).each do |line|
  1027. if line =~ /<craft show require:\s*(none|\d+)>/i
  1028. @craft_show = 0 if $1 == "none"
  1029. @craft_show = $1.to_i if $1 != "none"
  1030. end
  1031. if line =~ /<craft chance:\s*(.+)\%>/i
  1032. @craft_rate = $1.to_f
  1033. end
  1034. if line =~ /<craft materials:\s*(.+)>/i
  1035. @craft_materials ||= {}
  1036. @craft_materials[:item] ||= []
  1037. text = $1.clone
  1038. text.split(",").each do |item|
  1039. if item =~ /(\d+)\+(\d+)i/i
  1040. @craft_materials[:item] << [$2.to_i,$1.to_i]
  1041. end
  1042. end
  1043. end
  1044. end
  1045. p @craft_materials[:item] if @craft_materials
  1046. end
  1047. end # RPG::Skill
Advertisement
Add Comment
Please, Sign In to add comment