XenonCreations

Smithing System (RGSS3)

Feb 10th, 2015
290
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # Smithing System v1.0.0
  3. #------------------------------------------------------------------------------
  4. # This module defines list of craftable weapons
  5. #==============================================================================
  6. # Terms of Use:
  7. #------------------------------------------------------------------------------
  8. # Can be used in free games with credit, for a commercial license message
  9. # XenonCreations and you can negotiate on a price.
  10. #==============================================================================
  11. # Credits:
  12. #------------------------------------------------------------------------------
  13. # Zarby - For Scripting
  14. # XenonCreations - Ideas and Demo
  15. #==============================================================================
  16. # How to Use:
  17. #------------------------------------------------------------------------------
  18. # Call script in event... "SceneManager.goto(Scene_Blacksmith)"
  19. #==============================================================================
  20. # ** Craft
  21. #------------------------------------------------------------------------------
  22. module Craft
  23. #Bar start at 130 if difficulty is 1 bar reduce by 12 everytime, if 10 by 30 everytime
  24. #up to 5 time then after 4 time it remain 10 pixel of greenbar
  25. #Difficulty 1-10, bar reduce (Difficulty * 2) + 10
  26. #[Weapon, [[Material,Quantity], Difficulty]
  27. Weapons_Recipes = [
  28. [1,[[20,3],[21,3],[1,3],[2,3],[3,3]],2],
  29. [13,[[20,4],[21,2]],2],
  30. [19,[[20,2],[21,4]],1],
  31. [20,[[20,2],[21,4]],10],
  32. [21,[[20,2],[21,4]],5]
  33. #Add more weapon here
  34. ]
  35.  
  36. def self.Weapon_Recipes
  37. return Weapons_Recipes
  38. end
  39.  
  40.  
  41. end
  42.  
  43. #==============================================================================
  44. # ** Window_BlacksmithList
  45. #------------------------------------------------------------------------------
  46. # This window displays all craftable weapons
  47. #==============================================================================
  48. class Window_BlacksmithList < Window_Command
  49. #--------------------------------------------------------------------------
  50. # * Set Window Width
  51. #--------------------------------------------------------------------------
  52. def window_width
  53. return 160
  54. end
  55. #--------------------------------------------------------------------------
  56. # * Set Window Height
  57. #--------------------------------------------------------------------------
  58. def window_height
  59. return 292
  60. end
  61. #--------------------------------------------------------------------------
  62. # * Set Number of items visible
  63. #--------------------------------------------------------------------------
  64. def visible_line_number
  65. item_max
  66. end
  67. #--------------------------------------------------------------------------
  68. # * Set the choices of window to the list of weapons
  69. #--------------------------------------------------------------------------
  70. def make_command_list
  71. for ind in 0..Craft.Weapon_Recipes.size-1
  72. mats = false
  73. for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
  74. nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
  75. nbrr = Craft.Weapon_Recipes[ind][1][i][1]
  76.  
  77. if (nbr >= nbrr)
  78. mats = true
  79. else
  80. mats = false
  81. break
  82. end
  83.  
  84. end
  85. add_command($data_weapons[Craft.Weapon_Recipes[ind][0]].name, :weapon,mats)
  86.  
  87. end
  88. end
  89.  
  90.  
  91.  
  92. end
  93.  
  94. #==============================================================================
  95. # ** Scene_Blacksmith
  96. #------------------------------------------------------------------------------
  97. # This class performs the craft of weapons
  98. #==============================================================================
  99. class Scene_Blacksmith < Scene_MenuBase
  100. #--------------------------------------------------------------------------
  101. # * Start Processing
  102. #--------------------------------------------------------------------------
  103. def start
  104. super
  105. create_background
  106. create_windows
  107. @minigame = false
  108. @minigame_open = false
  109. @succes = 0
  110. @greenbar = 130
  111. @minigame_started = false
  112. @minigame_timer = 0
  113. @minigame_freeze = false
  114. @minigame_cursor_direction = false
  115. @speed = 4
  116. @done = false
  117. @last_index = -1
  118. end
  119. #--------------------------------------------------------------------------
  120. # * Update Processing
  121. #--------------------------------------------------------------------------
  122. def update
  123. super
  124. ind = @selectable_window.index
  125. for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
  126. nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
  127. nbrr = Craft.Weapon_Recipes[ind][1][i][1]
  128.  
  129. end
  130.  
  131. if (@minigame == true)
  132. forge_minigame
  133. if (@minigame_open == false)
  134. draw_minigame
  135. @minigame_open = true
  136. end
  137. end
  138.  
  139. if (Input.trigger?(:B))
  140. if (@minigame == false)
  141. if @selectable_window.active == false
  142. cancel_selected_weapon
  143. else
  144. SceneManager.goto(Scene_Map)
  145. end
  146. elsif (@minigame_started == false)
  147. @minigame = false
  148. @minigame_open = false
  149. @minigame_sprite.visible = false
  150. @minigame_cursor_sprite.visible = false
  151. @description_window.visible = true
  152. end
  153. end
  154.  
  155. if (@last_index != @selectable_window.index)
  156. draw_description
  157. @last_index = @selectable_window.index
  158. end
  159.  
  160. if (@done == true)
  161. if (@minigame_timer >= 10)
  162. terminate
  163. SceneManager.goto(Scene_Map)
  164. end
  165. end
  166.  
  167. end
  168.  
  169. #--------------------------------------------------------------------------
  170. # * Weapon Command : When we select a weapons
  171. #--------------------------------------------------------------------------
  172. def command_weapon
  173. @selectable_window.active = false
  174. @minigame = true
  175. @help_window.set_text("Choose a weapon to craft \n Are you sure ?")
  176. end
  177. #--------------------------------------------------------------------------
  178. # * Weapon Cancel Command : When we cancel selection of weapon
  179. #--------------------------------------------------------------------------
  180. def cancel_selected_weapon
  181. @selectable_window.active = true
  182. @description_window.visible = true
  183. @help_window.set_text("Choose a weapon to craft")
  184. @selectable_window.active = true
  185. draw_description
  186. end
  187. #--------------------------------------------------------------------------
  188. # * Draw Description of the weapon selected
  189. #--------------------------------------------------------------------------
  190. def draw_description
  191. @description_window.contents.clear
  192. ind = @selectable_window.index
  193. @description_window.visible = true
  194. w = $data_weapons[Craft.Weapon_Recipes[ind][0]]
  195. @description_window.draw_icon(w.icon_index, 0, 0)
  196. @description_window.contents.font.color = Color.new(100,160,50)
  197. @description_window.draw_text(32,0,320,24,w.name,0)
  198. desc = w.description.split("\n")
  199.  
  200. @description_window.contents.font.size = 16
  201. @description_window.contents.font.color = Color.new(200,230,180)
  202. @description_window.draw_text(0,24,420,24,desc[0],0)
  203. @description_window.draw_text(0,38,420,24,desc[1],0)
  204. @description_window.contents.font.size = 20
  205. @description_window.contents.font.color = Color.new(255,255,255)
  206. @description_window.draw_text(0,70,320,24,"Weapon Type : "+$data_system.weapon_types[w.wtype_id],0)
  207. @description_window.contents.fill_rect(0,60,320,4,Color.new(0,0,0))
  208. @description_window.contents.fill_rect(1,61,294,2,Color.new(255,255,255))
  209. statsy = 90
  210. for i in 0..3
  211. @description_window.draw_text(0,statsy + (20 * i),320,24,Vocab.param(i)+" : "+w.params[i].to_s,0)
  212. @description_window.draw_text(160,statsy + (20 * i),320,24,Vocab.param(i+3)+" : "+w.params[i].to_s,0)
  213. end
  214. @description_window.contents.fill_rect(0,180,320,4,Color.new(0,0,0))
  215. @description_window.contents.fill_rect(1,181,294,2,Color.new(255,255,255))
  216. @description_window.contents.font.size = 24
  217. @description_window.contents.font.color = Color.new(200,230,180)
  218. @description_window.draw_text(0,190,320,24,"Materials Owned/Required",0)
  219. @description_window.contents.font.color = Color.new(255,255,255)
  220. @description_window.contents.font.size = 20
  221.  
  222.  
  223.  
  224. ind = @selectable_window.index
  225. for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
  226. nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
  227. nbrr = Craft.Weapon_Recipes[ind][1][i][1]
  228. if (nbr >= nbrr)
  229. @description_window.contents.font.color = Color.new(160,230,30)
  230. else
  231. @description_window.contents.font.color = Color.new(150,10,10)
  232. end
  233.  
  234. @description_window.draw_text(0,216 + (i * 20),320,24,$data_items[Craft.Weapon_Recipes[ind][1][i][0]].name,0)
  235. @description_window.draw_text(240,216 + (i * 20),70,24,nbr.to_s + "/" + nbrr.to_s ,1)
  236. end
  237.  
  238. end
  239.  
  240. #--------------------------------------------------------------------------
  241. # * Forge Minigame processing everything about minigame is here
  242. #--------------------------------------------------------------------------
  243. def forge_minigame
  244. if (@minigame_started == false)
  245. if (Input.trigger?(:C))
  246. @minigame_started = true
  247. @minigame_timer = 0
  248. end
  249. end
  250.  
  251. if (@minigame_started == true)
  252.  
  253. @minigame_timer += 1
  254. #If we can repress :
  255. if (@minigame_timer >= 15)
  256. @minigame_timer = 15
  257. if (@minigame_freeze == false)
  258. if (Input.trigger?(:C))
  259. if (centerbar == true)
  260.  
  261. @succes +=20
  262. @minigame_timer = 0
  263. Sound.play_ok
  264. @greenbar -= (Craft.Weapon_Recipes[@selectable_window.index][2]*2)+10
  265. @speed +=1
  266. draw_minigame
  267. if (@succes >= 100)
  268. w = $data_weapons[Craft.Weapon_Recipes[@selectable_window.index][0]]
  269. $game_party.gain_item(w, 1)
  270. $game_message.add("Congrats you created a " +(w.name)+" !")
  271. for i in 0..(Craft.Weapon_Recipes[ @selectable_window.index][1].size)-1
  272. it = $data_items[Craft.Weapon_Recipes[@selectable_window.index][1][i][0]]
  273. q = Craft.Weapon_Recipes[@selectable_window.index][1][i][1]
  274. $game_party.gain_item(it, -q)
  275. end
  276. @done = true
  277. end
  278.  
  279. r = rand(10)
  280. if (r >= 6)
  281. @minigame_cursor_direction = true
  282. else
  283. @minigame_cursor_direction = false
  284. end
  285. @minigame_freeze = true
  286.  
  287. else
  288. Sound.play_buzzer
  289. @minigame_freeze = true
  290. @minigame_timer = 0
  291. w = $data_weapons[Craft.Weapon_Recipes[@selectable_window.index][0]]
  292. $game_message.add("You failed creation of " +(w.name)+" !\nYou lose your materials")
  293. for i in 0..(Craft.Weapon_Recipes[ @selectable_window.index][1].size)-1
  294. it = $data_items[Craft.Weapon_Recipes[@selectable_window.index][1][i][0]]
  295. q = Craft.Weapon_Recipes[@selectable_window.index][1][i][1]
  296. $game_party.gain_item(it, -q)
  297. end
  298. @done = true
  299. draw_minigame
  300.  
  301. end
  302.  
  303. end
  304. end
  305.  
  306. end
  307.  
  308. if (@minigame_freeze == false)
  309. if (@minigame_cursor_direction == false)
  310. @minigame_cursor_sprite.x +=@speed
  311. if (@minigame_cursor_sprite.x >= 498)
  312. @minigame_cursor_direction = true
  313. end
  314. else
  315. @minigame_cursor_sprite.x -=@speed
  316. if (@minigame_cursor_sprite.x <= 202)
  317. @minigame_cursor_direction = false
  318. end
  319. end
  320. else
  321. if (@minigame_timer >= 15)
  322. @minigame_freeze = false
  323. @minigame_timer = 0
  324. end
  325. end
  326.  
  327.  
  328.  
  329. end
  330. end
  331. #--------------------------------------------------------------------------
  332. # * Center bar : check if the bar is in the green
  333. #--------------------------------------------------------------------------
  334. def centerbar
  335. if (@minigame_cursor_sprite.x >= 202 + (150 - @greenbar/2))
  336. if (@minigame_cursor_sprite.x <= 498 - (150 - @greenbar/2))
  337. return true
  338. end
  339. end
  340. return false
  341. end
  342.  
  343. #--------------------------------------------------------------------------
  344. # * Draw Icon, allow to draw icon
  345. #--------------------------------------------------------------------------
  346. def draw_icon(icon_index, x, y, contents)
  347. bitmap = Cache.system("Iconset")
  348. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  349. contents.blt(x, y, bitmap, rect, 255)
  350. end
  351.  
  352. #--------------------------------------------------------------------------
  353. # * Draw Minigame, draw everything used for the minigame
  354. #--------------------------------------------------------------------------
  355. def draw_minigame
  356. @help_window.set_text("Get Ready \nTry to stop the bar in center green")
  357. @description_window.visible = false
  358. @minigame_sprite.visible = true
  359. @minigame_cursor_sprite.visible = true
  360. @minigame_sprite.bitmap = Bitmap.new(320,240)
  361. @minigame_sprite.x = 192
  362. @minigame_sprite.y = 120
  363.  
  364.  
  365. @minigame_sprite.bitmap.fill_rect(0,0,320,240,Color.new(0,0,0))
  366. @minigame_sprite.bitmap.fill_rect(1,1,318,238,Color.new(255,255,255))
  367. @minigame_sprite.bitmap.fill_rect(3,3,314,234,Color.new(0,0,0))
  368. @minigame_sprite.bitmap.clear_rect(4,4,312,232)
  369. @minigame_sprite.bitmap.fill_rect(4,4,312,232,Color.new(0,0,0,180))
  370. @minigame_sprite.bitmap.draw_text(10,180,120,24,"Succes :",0)
  371. @minigame_sprite.bitmap.draw_text(10,10,200,24,"Difficulty : ",0)
  372. for i in 1..((Craft.Weapon_Recipes[@selectable_window.index][2]))
  373. draw_icon(126, 10 + ((i-1)*30), 34, @minigame_sprite.bitmap)
  374. end
  375. @minigame_sprite.bitmap.fill_rect(9,202,302,24,Color.new(0,0,0))
  376. @minigame_sprite.bitmap.fill_rect(10,203,(@succes*3),22,Color.new(0,255,0))
  377.  
  378. @minigame_sprite.bitmap.fill_rect(9,109,302,18,Color.new(0,0,0))
  379. @minigame_sprite.bitmap.fill_rect(10,110,300,16,Color.new(150,10,10))
  380. @minigame_sprite.bitmap.fill_rect(160 - (@greenbar/2),110,@greenbar,16,Color.new(160,230,30))
  381. @minigame_cursor_sprite.bitmap = Bitmap.new(4,48)
  382. @minigame_cursor_sprite.bitmap.fill_rect(0,0,4,18,Color.new(0,0,0))
  383. @minigame_cursor_sprite.bitmap.fill_rect(1,1,2,16,Color.new(255,255,255))
  384. @minigame_cursor_sprite.bitmap.fill_rect(0,30,4,18,Color.new(0,0,0))
  385. @minigame_cursor_sprite.bitmap.fill_rect(1,31,2,16,Color.new(255,255,255))
  386.  
  387.  
  388. end
  389. #--------------------------------------------------------------------------
  390. # * Create Windows
  391. #--------------------------------------------------------------------------
  392. def create_windows
  393. @selectable_window = Window_BlacksmithList.new(0,120)
  394. @craftlist_window = Window_Base.new(0,72,160,48)
  395. @help_window = Window_Help.new()
  396. @help_window.set_text("Choose a weapon to craft")
  397. @craftlist_window.draw_text(0,0,140,24,"Craft List",1)
  398. @selectable_window.set_handler(:weapon,method(:command_weapon))
  399. @description_window = Window_Base.new(160,72,320,340)
  400. @description_window.visible = true
  401. @minigame_sprite = Sprite.new()
  402. @minigame_sprite.visible = false
  403. @minigame_cursor_sprite = Sprite.new()
  404. @minigame_cursor_sprite.x = (352)
  405. @minigame_cursor_sprite.y = (240-26)
  406. @minigame_cursor_sprite.visible = false
  407. end
  408.  
  409. #--------------------------------------------------------------------------
  410. # * Terminate processing
  411. #--------------------------------------------------------------------------
  412. def terminate
  413. super
  414. dispose_background
  415. @selectable_window.dispose
  416. @craftlist_window.dispose
  417. @help_window.dispose
  418. @description_window.dispose
  419. @minigame_sprite.dispose
  420. @minigame_cursor_sprite.dispose
  421. end
  422.  
  423. end
RAW Paste Data