dsiver144

Dark's 2nd Crafting System v2

Apr 24th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.47 KB | None | 0 0
  1. #===============================================================================
  2. # ╔══════════════════════════════════╗
  3. # ║ ▼ Dark's 2nd Crafting System ║
  4. # ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. # ║ ▼ Release Date: March 14th 2016 ║
  6. # ║ ▼ Forum: TaoTroChoi.com ║
  7. # ╚══════════════════════════════════╝
  8. #-------------------------------------------------------------------------------
  9. # Version 1.0: Release!
  10. # Version 2.0: Update for script!
  11. #-------------------------------------------------------------------------------
  12. # Writen for mr.rpg.700.
  13. #-------------------------------------------------------------------------------
  14. # Yêu cầu: Instance Items
  15. # Dark's Bitmap
  16. #-------------------------------------------------------------------------------
  17. # Script call:
  18. # open_crafting_scene -> Mở scene
  19. # $game_system.crafting_tier -> Lấy ra Tier hiện tại. (Conditional Branches)
  20. #===============================================================================
  21. $imported = {} if $imported.nil?
  22. $imported["DRKS-Crafting2"] = true
  23. if !$imported["TH_InstanceItems"]
  24. msgbox_p("TH_InstanceItems not found! Exiting...")
  25. exit
  26. end
  27. if !$imported["DRKS-Bitmap"]
  28. msgbox_p("DRKS-Bitmap not found! Exiting...")
  29. exit
  30. end
  31. module DarkCrafting2
  32. Craft_SE = "Item Harvest"
  33. Recipe = {}
  34. Recipe[1] = {}
  35. Recipe[1][:name] = "Sharp Stone"
  36. Recipe[1][:require_items] = ["i259x2"]
  37. Recipe[1][:get_item] = ["i262x1"]
  38. Recipe[2] = {}
  39. Recipe[2][:name] = "Improvised Axe"
  40. Recipe[2][:require_items] = ["i259x1","i255x1","w1x1"]
  41. Recipe[2][:get_item] = ["w4x1"]
  42. Recipe[3] = {}
  43. Recipe[3][:name] = "Basic fishing rod"
  44. Recipe[3][:require_items] = ["i256x1","i255x1","w1x1"]
  45. Recipe[3][:get_item] = ["w3x1"]
  46. Recipe[4] = {}
  47. Recipe[4][:name] = "Spear"
  48. Recipe[4][:require_items] = ["i262x1","i255x1","w1x1"]
  49. Recipe[4][:get_item] = ["w5x1"]
  50. Recipe[5] = {}
  51. Recipe[5][:name] = "Sharp Stone"
  52. Recipe[5][:require_items] = ["i3x2"]
  53. Recipe[5][:get_item] = ["i4x1"]
  54. Recipe[6] = {}
  55. Recipe[6][:name] = "Campfire"
  56. Recipe[6][:require_items] = ["i13x5"]
  57. Recipe[6][:get_item] = ["i1x1"]
  58. Recipe[7] = {}
  59. Recipe[7][:name] = "Test New Update!"
  60. Recipe[7][:require_items] = ["i12x5"]
  61. Recipe[7][:get_item] = ["i1x2","a2x2","w3x2"]
  62. #----------------------------------------------------------------------
  63. # Get Recive Items
  64. #----------------------------------------------------------------------
  65. def self.get_recive_items(id)
  66. a = Recipe[id][:get_item]
  67. b = []
  68. a.each do |obj|
  69. c = obj.split("x")
  70. item_id = c[0][/(\d+)/].to_i
  71. item_num = c[1].to_i
  72. if c[0].include?("i")
  73. d = $data_items[item_id] if $data_items
  74. end
  75. if c[0].include?("a")
  76. d = $data_armors[item_id] if $data_armors
  77. end
  78. if c[0].include?("w")
  79. d = $data_weapons[item_id] if $data_weapons
  80. end
  81. b.push([d,item_num])
  82. end
  83. return b
  84. end
  85. #----------------------------------------------------------------------
  86. # Get Recipe Name
  87. #----------------------------------------------------------------------
  88. def self.get_recipe_name(id)
  89. a = Recipe[id][:name]
  90. return a
  91. end
  92. #----------------------------------------------------------------------
  93. # Get Item
  94. #----------------------------------------------------------------------
  95. def self.get_item(id)
  96. a = Recipe[id][:get_item]
  97. b = a.split(":")
  98. if a.include?("w")
  99. c = $data_weapons[b[1].to_i]
  100. end
  101. if a.include?("i")
  102. c = $data_items[b[1].to_i]
  103. end
  104. if a.include?("a")
  105. c = $data_armors[b[1].to_i]
  106. end
  107. return c
  108. end
  109. #----------------------------------------------------------------------
  110. # Convert Require Item to Array.
  111. #----------------------------------------------------------------------
  112. def self.convert_req_item(id)
  113. a = Recipe[id][:require_items]
  114. c = []
  115. a.each do |p|
  116. b = p.split("x")
  117. b[1].to_i.times do
  118. c.push(b[0])
  119. end
  120. end
  121. return c.sort!
  122. end
  123. #----------------------------------------------------------------------
  124. # Convert Selected Item to Array.
  125. #----------------------------------------------------------------------
  126. def self.convert_selected(pack)
  127. a = pack
  128. b = []
  129. a.each do |item|
  130. citem = InstanceManager.get_template(item)
  131. if citem.is_a?(RPG::Weapon)
  132. b.push("w#{citem.id}")
  133. end
  134. if citem.is_a?(RPG::Item)
  135. b.push("i#{citem.id}")
  136. end
  137. if citem.is_a?(RPG::Armor)
  138. b.push("a#{citem.id}")
  139. end
  140. end
  141. return b
  142. end
  143. #----------------------------------------------------------------------
  144. # Convert Selected Item to Array.
  145. #----------------------------------------------------------------------
  146. def self.convert_selected_item2(item_pack)
  147. a = item_pack
  148. b = a.uniq
  149. c = {}
  150. d = []
  151. b.each do |item|
  152. c[item] ||= 0
  153. end
  154. a.each do |item|
  155. c[item] += 1
  156. end
  157. c.each_pair do |key,value|
  158. d.push([key,value])
  159. end
  160. return d
  161. end
  162. end
  163.  
  164. class Scene_DarkCrafting2 < Scene_ItemBase
  165. #--------------------------------------------------------------------------
  166. # * Start Processing
  167. #--------------------------------------------------------------------------
  168. def start
  169. super
  170. create_window_layout
  171. create_help_window
  172. $selected_pack = []
  173. @check = false
  174. @recive = nil
  175. create_item_window
  176. create_sprites
  177. end
  178. #--------------------------------------------------------------------------
  179. # * Create Help Window
  180. #--------------------------------------------------------------------------
  181. def create_help_window
  182. @help_window = Window_CraftingHelp.new(5,55,252,125)
  183. @help_window.viewport = @viewport
  184. end
  185. #--------------------------------------------------------------------------
  186. # * Check Sprites
  187. #--------------------------------------------------------------------------
  188. def create_sprites
  189. @sprites[:found_item] = Sprite.new
  190. @sprites[:found_item].bitmap = DarkBitmap.new(544,416)
  191. @sprites[:found_item].viewport = @viewport
  192. @sprites[:found_item].z = 100
  193. @sprites[:craft_key] = Sprite.new
  194. @sprites[:craft_key].bitmap = Cache.system("craft_key")
  195. @sprites[:craft_key].viewport = @viewport
  196. @sprites[:craft_key].z = 120
  197. @sprites[:craft_key].x = 544 - @sprites[:craft_key].bitmap.width
  198. @sprites[:craft_key].bitmap.font.size = 24
  199. @sprites[:craft_key].bitmap.font.bold = false
  200. @sprites[:craft_key].bitmap.font.outline = false
  201. @sprites[:craft_key].bitmap.font.color = Color.new(255,255,255)
  202. @sprites[:craft_key].bitmap.draw_text(30,0,130,32," to craft this!")
  203. @sprites[:craft_key].visible = false
  204. @sprites[:des_plus] = Sprite.new
  205. @sprites[:des_plus].bitmap = DarkBitmap.new(544,416)
  206. @sprites[:des_plus].viewport = @viewport
  207. @sprites[:des_plus].z = 100
  208. @sprites[:tier] = Sprite.new
  209. @sprites[:tier].bitmap = DarkBitmap.new(544,416)
  210. @sprites[:tier].viewport = @viewport
  211. @sprites[:tier].z = 100
  212. @sprites[:tier].bitmap.font.size = 24
  213. @sprites[:tier].bitmap.font.bold = true
  214. @sprites[:tier].bitmap.font.outline = false
  215. @sprites[:tier].bitmap.font.color = Color.new(0,0,0)
  216. @sprites[:tier].bitmap.draw_text(272,65,130,32,"Crafting Tier")
  217. @sprites[:tier].bitmap.font.size = 40
  218. @sprites[:tier].bitmap.font.color = Color.new(255,111,0)
  219. @sprites[:tier].bitmap.draw_text(311,115,130,32,$game_system.crafting_tier)
  220. end
  221. #--------------------------------------------------------------------------
  222. # * Create Window Layout
  223. #--------------------------------------------------------------------------
  224. def create_window_layout
  225. @sprites = {}
  226. @sprites[:layout] = Sprite.new
  227. @sprites[:layout].bitmap = Cache.system("Craft_Layout")
  228. @sprites[:layout].viewport = @viewport
  229. @sprites[:layout].z = 0
  230. end
  231. #--------------------------------------------------------------------------
  232. # * Create Item Window
  233. #--------------------------------------------------------------------------
  234. def create_item_window
  235. wy = 243
  236. wh = 170
  237. @item_window = Window_CraftingList.new(0, wy, Graphics.width, wh)
  238. @item_window.viewport = @viewport
  239. @item_window.opacity = 0
  240. @item_window.back_opacity = 0
  241. @item_window.refresh
  242. @item_window.select(0)
  243. @item_window.activate
  244. @item_window.help_window = @help_window
  245. @item_window.set_handler(:ok, method(:on_item_ok))
  246. @item_window.set_handler(:cancel, method(:on_item_cancel))
  247. end
  248. #--------------------------------------------------------------------------
  249. # * Category [OK]
  250. #--------------------------------------------------------------------------
  251. def on_category_ok
  252. @item_window.activate
  253. @item_window.select_last
  254. end
  255. #--------------------------------------------------------------------------
  256. # * Item [OK]
  257. #--------------------------------------------------------------------------
  258. def on_item_ok
  259. $game_party.last_item.object = item
  260. if !$selected_pack.include?(item)
  261. $selected_pack.push(item)
  262. else
  263. $selected_pack.delete(item)
  264. end
  265. check_for_recipe
  266. @item_window.activate
  267. @item_window.refresh
  268. end
  269. #--------------------------------------------------------------------------
  270. # * Item [Cancel]
  271. #--------------------------------------------------------------------------
  272. def on_item_cancel
  273. return_scene
  274. end
  275. #--------------------------------------------------------------------------
  276. # * Check for Recipe
  277. #--------------------------------------------------------------------------
  278. def check_for_recipe
  279. converted = DarkCrafting2.convert_selected($selected_pack)
  280. DarkCrafting2::Recipe.each_key do |key|
  281. if converted.sort == DarkCrafting2.convert_req_item(key).sort
  282. @sprites[:found_item].bitmap.clear
  283. @recive_name = DarkCrafting2.get_recipe_name(key)
  284. @recive = DarkCrafting2.get_recive_items(key)
  285. @check = true
  286. break
  287. else
  288. @check = false
  289. @recive = nil
  290. @recive_name = ""
  291. end
  292. end
  293. end
  294. #--------------------------------------------------------------------------
  295. # * Update Craft Found
  296. #--------------------------------------------------------------------------
  297. def update_craft
  298. if Input.trigger?(:R)
  299. $selected_pack.each do |item|
  300. $game_party.lose_item(item,1)
  301. end
  302. @recive.each do |item|
  303. $game_party.gain_item(item[0],item[1])
  304. end
  305. @recive = nil
  306. @check = false
  307. @sprites[:craft_key].visible = false
  308. @item_window.refresh
  309. $selected_pack = []
  310. @sprites[:found_item].bitmap.clear
  311. begin
  312. se = RPG::SE.new(DarkCrafting2::Craft_SE)
  313. se.play
  314. rescue
  315. se = RPG::SE.new("Decision2")#Không tìm thấy file sẽ chạy file SE này!
  316. se.play
  317. end
  318. end
  319. end
  320. #--------------------------------------------------------------------------
  321. # * Update Description +
  322. #--------------------------------------------------------------------------
  323. def update_des_plus
  324. if @check == true
  325. @sprites[:found_item].bitmap.clear
  326. @sprites[:craft_key].visible = true
  327. @sprites[:craft_key].y = 416 - @sprites[:craft_key].bitmap.height - 15
  328. @sprites[:found_item].bitmap.draw_text(276,199,300,32,"Craft: " + @recive_name)
  329. else
  330. @sprites[:craft_key].visible = false
  331. @sprites[:found_item].bitmap.clear
  332. end
  333. if item
  334. x = 392
  335. y = 52
  336. @sprites[:des_plus].bitmap.clear
  337. @sprites[:des_plus].bitmap.font.size = 18
  338. @sprites[:des_plus].bitmap.font.bold = false
  339. @sprites[:des_plus].bitmap.font.outline = false
  340. @sprites[:des_plus].bitmap.font.color = Color.new(0,0,0)
  341. @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"Price: #{item.price}G")
  342. if !item.is_a?(RPG::Item)
  343. y += 15
  344. @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"Performance: #{item.performance}")
  345. y += 15
  346. for i in 2..7 do
  347. @sprites[:des_plus].bitmap.draw_text(x,y,146,32,"#{$data_system.terms.params[i]}: #{item.params[i]}")
  348. y += 15
  349. end
  350. end
  351. end
  352. end
  353. #--------------------------------------------------------------------------
  354. # * Update
  355. #--------------------------------------------------------------------------
  356. def update
  357. super
  358. update_des_plus
  359. update_craft if @check == true
  360. @item_window.update_help
  361. end
  362. #--------------------------------------------------------------------------
  363. # * Play SE When Using Item
  364. #--------------------------------------------------------------------------
  365. def play_se_for_item
  366. Sound.play_use_item
  367. end
  368. def terminate
  369. super
  370. @sprites.values.each do |sprite|
  371. sprite.bitmap.dispose
  372. sprite.dispose
  373. end
  374. end
  375. #--------------------------------------------------------------------------
  376. # * Use Item
  377. #--------------------------------------------------------------------------
  378. def use_item
  379. super
  380. @item_window.redraw_current_item
  381. end
  382. end
  383.  
  384. class Window_CraftingList < Window_Selectable
  385. #--------------------------------------------------------------------------
  386. # * Object Initialization
  387. #--------------------------------------------------------------------------
  388. def initialize(x, y, width, height)
  389. super
  390. self.windowskin = Cache.system("Window_Crafting")
  391. @data = []
  392. end
  393. #--------------------------------------------------------------------------
  394. # * Get Digit Count
  395. #--------------------------------------------------------------------------
  396. def col_max
  397. return 2
  398. end
  399. #--------------------------------------------------------------------------
  400. # * Get Number of Items
  401. #--------------------------------------------------------------------------
  402. def item_max
  403. @data ? @data.size : 1
  404. end
  405. #--------------------------------------------------------------------------
  406. # * Get Item
  407. #--------------------------------------------------------------------------
  408. def item
  409. @data && index >= 0 ? @data[index] : nil
  410. end
  411. #--------------------------------------------------------------------------
  412. # * Get Activation State of Selection Item
  413. #--------------------------------------------------------------------------
  414. def current_item_enabled?
  415. enable?(@data[index])
  416. end
  417. #--------------------------------------------------------------------------
  418. # * Include in Item List?
  419. #--------------------------------------------------------------------------
  420. def include?(item)
  421. return true
  422. end
  423. #--------------------------------------------------------------------------
  424. # * Display in Enabled State?
  425. #--------------------------------------------------------------------------
  426. def enable?(item)
  427. true
  428. end
  429. #--------------------------------------------------------------------------
  430. # * Create Item List
  431. #--------------------------------------------------------------------------
  432. def make_item_list
  433. @data = $game_party.all_items.select {|item| include?(item) }
  434. @data.push(nil) if include?(nil)
  435. end
  436. #--------------------------------------------------------------------------
  437. # * Restore Previous Selection Position
  438. #--------------------------------------------------------------------------
  439. def select_last
  440. select(@data.index($game_party.last_item.object) || 0)
  441. end
  442. #--------------------------------------------------------------------------
  443. # * Draw Item
  444. #--------------------------------------------------------------------------
  445. def draw_item(index)
  446. item = @data[index]
  447. if item
  448. color_1 = Color.new(255,162,0)
  449. color_2 = Color.new(255,255,255,0)
  450. rect = item_rect(index)
  451. rect.width -= 4
  452. if $selected_pack.include?(item)
  453. contents.gradient_fill_rect(rect.x,rect.y+2,rect.width,rect.height-4,color_1,color_2)
  454. end
  455. draw_item_name(item, rect.x, rect.y, enable?(item))
  456. end
  457. end
  458. #--------------------------------------------------------------------------
  459. # * Update Help Text
  460. #--------------------------------------------------------------------------
  461. def update_help
  462. @help_window.set_item(item)
  463. end
  464. #--------------------------------------------------------------------------
  465. # * Refresh
  466. #--------------------------------------------------------------------------
  467. def refresh
  468. make_item_list
  469. create_contents
  470. draw_all_items
  471. end
  472. end
  473. class Window_CraftingHelp < Window_Base
  474. #--------------------------------------------------------------------------
  475. # * Initialize
  476. #--------------------------------------------------------------------------
  477. def initialize(x,y,width,height)
  478. super(x,y,width,height)
  479. @current_item = nil
  480. self.opacity = 0
  481. self.back_opacity = 0
  482. end
  483. #--------------------------------------------------------------------------
  484. # * Create Window Contents
  485. #--------------------------------------------------------------------------
  486. def create_contents
  487. contents.dispose
  488. if contents_width > 0 && contents_height > 0
  489. self.contents = DarkBitmap.new(contents_width, contents_height)
  490. else
  491. self.contents = DarkBitmap.new(1, 1)
  492. end
  493. end
  494. #--------------------------------------------------------------------------
  495. # * Set Item
  496. #--------------------------------------------------------------------------
  497. def set_item(item)
  498. @current_item = item if item
  499. refresh
  500. end
  501. #--------------------------------------------------------------------------
  502. # * Refresh
  503. #--------------------------------------------------------------------------
  504. def refresh
  505. contents.clear
  506. if @current_item
  507. contents.font.size = 25
  508. contents.font.bold = true
  509. contents.font.outline = false
  510. contents.font.color = Color.new(0,0,0)
  511. draw_text(0,0,200,32,@current_item.name)
  512. draw_text(0,0,200,32,@current_item.name)
  513. contents.font.size = 17
  514. contents.font.bold = false
  515. contents.font.color = Color.new(0,0,0,200)
  516. contents.draw_text_ex(0,32,@current_item.description,false)
  517. else
  518. contents.font.size = 25
  519. contents.font.bold = true
  520. contents.font.outline = false
  521. contents.font.color = Color.new(0,0,0)
  522. draw_text(0,0,200,32,"None")
  523. end
  524. @current_item = nil
  525. end
  526. end
  527. class Game_System
  528. #--------------------------------------------------------------------------
  529. # * Public Instance Variables
  530. #--------------------------------------------------------------------------
  531. attr_accessor :crafting_tier
  532. #--------------------------------------------------------------------------
  533. # * Object Initialization
  534. #--------------------------------------------------------------------------
  535. alias darkcrafting2gamesysteminit initialize
  536. def initialize
  537. darkcrafting2gamesysteminit
  538. @crafting_tier = "C"
  539. end
  540. end
  541.  
  542. class Game_Interpreter
  543. #--------------------------------------------------------------------------
  544. # * Set Crafting Tier
  545. #--------------------------------------------------------------------------
  546. def set_crafting_tier(tier)
  547. $game_system.crafting_tier = tier.to_s if tier
  548. end
  549. #--------------------------------------------------------------------------
  550. # * Open Crafting Scene
  551. #--------------------------------------------------------------------------
  552. def open_crafting_scene
  553. SceneManager.call(Scene_DarkCrafting2)
  554. end
  555. end
Advertisement
Add Comment
Please, Sign In to add comment