Advertisement
dsiver144

DSI Dungeon Rental System

Mar 9th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.28 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Dungeon Rental System
  3. # -- Last Updated: 2017.03.9
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #==============================================================================
  8.  
  9. $imported = {} if $imported.nil?
  10. $imported["DSI-DungeonRentalSystem"] = true
  11.  
  12. #==============================================================================
  13. # + Updates
  14. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. # 2017.02.21 - Finish first version.
  16. # 2017.02.21 - Fixing bugs.
  17. # - Add notetag for purchase price.
  18. # 2017.03.09 - Edit for 6 slots.
  19. #==============================================================================
  20. # + Instructions
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # To install this script, open up your script editor and copy/paste this script
  23. # to an open slot below ?? Materials/?f?? but above ?? Main. Remember to save.
  24. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  25. # + WEAPONS NOTETAGS:
  26. # <rental_tool> : Define a tool
  27. # <rental_price: x> : Set rent price for tool
  28. # <purchase_price: x> : Set purchase price for tool
  29. # + Script Call:
  30. # SceneManager.call(Scene_DungeonRental) -> Open the rental shop scene
  31. #==============================================================================
  32. # + Compatibility
  33. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  34. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  35. # it will run with RPG Maker VX without adjusting.
  36. #==============================================================================
  37. module DSIVER144
  38. module RENTAL_SYSTEM
  39. # New here!
  40. RENTAL_TOOL_ID = [13,14,15,16,17,18] # ID of tool in database
  41. # Need 6 id for this array.
  42. # It will automatically
  43. # remove the last one if
  44. # there are more than 6 object
  45. RENTAL_TEXTS = {
  46. :title => "Dungeon Rental System",
  47. :purchased => "Purchased!",
  48. :rented => "Rent!",
  49. :rent_price => "Rent price: ",
  50. :buy_price => "Buy price: ",
  51. }
  52. PURCHASED_COLOR = Color.new(0,255,102) # Red, Green, Blue
  53. RENT_COLOR = Color.new(255,102,0) # Red, Green, Blue
  54. #-------------------------------------------------------------------------
  55. # Don't touch this please
  56. #-------------------------------------------------------------------------
  57. TOOL_REGEXP = /<rental_tool>/i
  58. PRICE_REGEXP = /<rental_price:\s*(\w+)>/i
  59. PURCHASE_REGEXP = /<purchase_price:\s*(\w+)>/i
  60. end # RENTAL_SYSTEM
  61. end # DSIVER144
  62.  
  63. if !$imported["DSI-Bitmap"]
  64. msgbox_p("Please put DSI-Bitmap script on top of this script!")
  65. exit
  66. end
  67.  
  68. include DSIVER144::RENTAL_SYSTEM
  69. #==============================================================================
  70. # DataManager
  71. #==============================================================================
  72. module DataManager
  73. #--------------------------------------------------------------------------
  74. # alias method: load_database
  75. #--------------------------------------------------------------------------
  76. class <<self; alias load_database_rental_tool load_database; end
  77. def self.load_database
  78. load_database_rental_tool
  79. load_notetags_rental_tools
  80. end
  81. #--------------------------------------------------------------------------
  82. # Load Notetag Rental Weapons
  83. #--------------------------------------------------------------------------
  84. def self.load_notetags_rental_tools
  85. for weapon in $data_weapons
  86. next if weapon.nil?
  87. weapon.load_notetags_rental_tool
  88. end
  89. end
  90. end # DataManager
  91.  
  92. #==============================================================================
  93. # ?? RPG::Weapon
  94. #==============================================================================
  95. class RPG::Weapon
  96. #--------------------------------------------------------------------------
  97. # public instance variables
  98. #--------------------------------------------------------------------------
  99. attr_accessor :rental_tool
  100. attr_accessor :rental_price
  101. attr_accessor :purchase_price
  102. #--------------------------------------------------------------------------
  103. # common cache: load_notetags_sani
  104. #--------------------------------------------------------------------------
  105. def load_notetags_rental_tool
  106. @rental_tool = false
  107. @rental_price = 0
  108. @purchase_price = self.price
  109. self.note.split(/[\r\n]+/).each do |line|
  110. if line =~ TOOL_REGEXP
  111. @rental_tool = true
  112. end
  113. if line =~ PRICE_REGEXP
  114. @rental_price = $1.to_i
  115. end
  116. if line =~ PURCHASE_REGEXP
  117. @purchase_price = $1.to_i
  118. end
  119. end
  120. end
  121. end # RPG::Weapon
  122.  
  123. class Game_System
  124. attr_accessor :rental_list
  125. attr_accessor :rental_tool
  126. attr_accessor :bought_tools
  127. alias_method(:dsiver144_rental_system_init, :initialize)
  128. #--------------------------------------------------------------------------
  129. # alias method: initialize
  130. #--------------------------------------------------------------------------
  131. def initialize
  132. @rental_list = []
  133. @rental_tool = 0
  134. @bought_tools = []
  135. dsiver144_rental_system_init
  136. end
  137. end # Game_System
  138.  
  139. class Window_RentalTitle < Window_Base
  140. #--------------------------------------------------------------------------
  141. # new method: draw_title
  142. #--------------------------------------------------------------------------
  143. def draw_title
  144. contents.clear
  145. draw_text(0,0,contents_width,contents_height,RENTAL_TEXTS[:title],1)
  146. end
  147. end # Window_RentalTitle
  148.  
  149. class Window_RentalList < Window_HorzCommand
  150. #--------------------------------------------------------------------------
  151. # * Get Window Width
  152. #--------------------------------------------------------------------------
  153. def window_width
  154. return 360
  155. end
  156. #--------------------------------------------------------------------------
  157. # * Get Activation State of OK Processing
  158. #--------------------------------------------------------------------------
  159. def ok_enabled?
  160. return false
  161. end
  162. #--------------------------------------------------------------------------
  163. # new method: current_rent_state
  164. #--------------------------------------------------------------------------
  165. def current_rent_state
  166. if current_data
  167. return current_data[:name].split("-")[1].to_i
  168. end
  169. end
  170. #--------------------------------------------------------------------------
  171. # new method: current_price_state
  172. #--------------------------------------------------------------------------
  173. def current_price_state
  174. if current_data
  175. return current_data[:name].split("-")[3].to_i
  176. end
  177. end
  178. #--------------------------------------------------------------------------
  179. # new method: current_bought_state
  180. #--------------------------------------------------------------------------
  181. def current_bought_state
  182. if current_data
  183. return current_data[:name].split("-")[2].to_i
  184. end
  185. end
  186. #--------------------------------------------------------------------------
  187. # new method: current_tool
  188. #--------------------------------------------------------------------------
  189. def current_tool
  190. current_data ? $data_weapons[current_data[:name].split("-")[0].to_i] : nil
  191. end
  192. #--------------------------------------------------------------------------
  193. # overwritten method: make_command_list
  194. #--------------------------------------------------------------------------
  195. def make_command_list
  196. tool_array = RENTAL_TOOL_ID[0..6]
  197. tool_array.each do |id|
  198. status = $game_system.rental_tool != id
  199. status2 = !$game_system.bought_tools.include?(id)
  200. status3 = $game_party.gold >= $data_weapons[id].rental_price
  201. check = status ? 1 : 0
  202. check2 = status2 ? 1 : 0
  203. check3 = status3 ? 1 : 0
  204. add_command("#{id}-#{check}-#{check2}-#{check3}", :ok, status && status2)
  205. end
  206. end
  207. #--------------------------------------------------------------------------
  208. # * Draw Item
  209. #--------------------------------------------------------------------------
  210. def draw_item(index)
  211. rect = item_rect_for_text(index)
  212. tool_id = @list[index][:name].split("-")[0].to_i
  213. icon_index = $data_weapons[tool_id].icon_index
  214. draw_icon(icon_index,rect.x,rect.y + 3,command_enabled?(index))
  215. #draw_text(item_rect_for_text(index), command_name(index), alignment)
  216. end
  217. #--------------------------------------------------------------------------
  218. # * Get Window Height
  219. #--------------------------------------------------------------------------
  220. def window_height
  221. fitting_height(visible_line_number) + 12
  222. end
  223. #--------------------------------------------------------------------------
  224. # * Get Digit Count
  225. #--------------------------------------------------------------------------
  226. def col_max
  227. return 7
  228. end
  229. #--------------------------------------------------------------------------
  230. # * Get Item Width
  231. #--------------------------------------------------------------------------
  232. def item_height
  233. return 32
  234. end
  235. #--------------------------------------------------------------------------
  236. # * Get Item Width
  237. #--------------------------------------------------------------------------
  238. def item_width
  239. return 32
  240. end
  241. #--------------------------------------------------------------------------
  242. # * Get Spacing for Items Arranged Side by Side
  243. #--------------------------------------------------------------------------
  244. def spacing
  245. return 16
  246. end
  247. end # Window_RentalList
  248.  
  249. class Window_RentalAction < Window_Command
  250. attr_accessor :rental_window
  251. def initialize(x,y,rental_window)
  252. @rental_window = rental_window
  253. super(x,y)
  254. end
  255. #--------------------------------------------------------------------------
  256. # * Processing When OK Button Is Pressed
  257. #--------------------------------------------------------------------------
  258. def process_ok
  259. if current_item_enabled?
  260. #Sound.play_ok
  261. Input.update
  262. deactivate
  263. call_ok_handler
  264. else
  265. Sound.play_buzzer
  266. end
  267. end
  268. #--------------------------------------------------------------------------
  269. # overwrite method: dispose
  270. #--------------------------------------------------------------------------
  271. def dispose
  272. super
  273. @rental_window = nil
  274. end
  275. #--------------------------------------------------------------------------
  276. # overwrite method: make_command_list
  277. #--------------------------------------------------------------------------
  278. def make_command_list
  279. if @rental_window
  280. if @rental_window.current_bought_state == 1
  281. if @rental_window.current_rent_state == 1
  282. if $game_system.rental_tool > 0 && @rental_window.current_tool.id != $game_system.rental_tool
  283. add_command("Rent Tool", :rent, false)
  284. add_command("Buy Tool", :buy, true)
  285. else
  286. add_command("Rent Tool", :rent, true)
  287. add_command("Buy Tool", :buy, true)
  288. end
  289. else
  290. add_command("Return Tool", :return, true)
  291. add_command("Buy Tool", :buy, false)
  292. end
  293. else
  294. add_command("Rent Tool", :rent, false)
  295. add_command("Buy Tool", :buy, false)
  296. end
  297. end
  298. add_command("Cancel", :cancel, true)
  299. end
  300. #--------------------------------------------------------------------------
  301. # overwrite method: window_width
  302. #--------------------------------------------------------------------------
  303. def window_width
  304. return 160
  305. end
  306.  
  307. end # Window_RentalAction
  308.  
  309. class Window_RentalBackgroud < Window_Base
  310. #--------------------------------------------------------------------------
  311. # new method: fill_info_panel
  312. #--------------------------------------------------------------------------
  313. def fill_info_panel
  314. color = Color.new(255,255,255,150)
  315. contents.fill_rect(8,70,contents_width - 8*2,contents_height-80,color)
  316. end
  317. #--------------------------------------------------------------------------
  318. # * Draw Text with Control Characters
  319. #--------------------------------------------------------------------------
  320. def draw_text_ex2(x, y, text, width)
  321. #reset_font_settings
  322. text = convert_escape_characters(text)
  323. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  324. process_character2(text.slice!(0, 1), text, pos, width) until text.empty?
  325. end
  326.  
  327. def process_character2(c, text, pos, width)
  328. c = ' ' if @convert_newlines && c == "\n"
  329. if @wordwrap && c =~ /[ \t]/
  330. c = '' if @collapse_whitespace && @lastc =~ /[\s\n\f]/
  331. if pos[:x] + get_next_word_size(c, text) > width - @right_margin
  332. process_new_line(text, pos)
  333. else
  334. process_normal_character(c, pos)
  335. end
  336. @lastc = c
  337. else
  338. @lastc = c
  339. #process_character2(c, text, pos, width)
  340. end
  341. end
  342. #--------------------------------------------------------------------------
  343. # new method: draw_item_info
  344. #--------------------------------------------------------------------------
  345. def draw_item_info(item)
  346. contents.clear
  347. fill_info_panel
  348. x = 15
  349. y = 60
  350. contents.font.size = 20
  351. width = contents_width - 8*2
  352. height = contents_height-80
  353. change_color(Color.new(253,213,14))
  354. draw_text(x,y,width,fitting_height(1),item.name)
  355. y += 20
  356. change_color(normal_color)
  357. contents.font.size = 18
  358. text = RENTAL_TEXTS[:rent_price]
  359. draw_text(x,y,width,fitting_height(1),text+"#{item.rental_price}")
  360.  
  361. if $game_system.bought_tools.include?(item.id)
  362. contents.font.size = 22
  363. change_color(PURCHASED_COLOR)
  364. text = RENTAL_TEXTS[:purchased]
  365. draw_text(x+230,y,width,fitting_height(1),text)
  366. change_color(normal_color)
  367. contents.font.size = 18
  368. end
  369. if $game_system.rental_tool == item.id
  370. contents.font.size = 22
  371. change_color(RENT_COLOR)
  372. text = RENTAL_TEXTS[:rented]
  373. draw_text(x+250,y,width,fitting_height(1),text)
  374. change_color(normal_color)
  375. contents.font.size = 18
  376. end
  377. y += 20
  378. text = RENTAL_TEXTS[:buy_price]
  379. draw_text(x,y,width,fitting_height(1),text + "#{item.purchase_price}")
  380. contents.font.size = 20
  381. draw_text(x,y + 28,width - 32,fitting_height(1)," Description", 1)
  382. contents.font.size = 18
  383. y += 85
  384. x += 12
  385. color = Color.new(0,0,0,200)
  386. contents.fill_rect(20,180,contents_width - 20*2,140,color)
  387. @right_margin = 200
  388. des_bitmap = Bitmap.new(312,128)
  389. des_bitmap.font = contents.font
  390. des_bitmap.turn_on_wordwraping
  391. des_bitmap.draw_text_ex(0,0,item.description)
  392. contents.blt(x,y, des_bitmap, des_bitmap.rect)
  393. end
  394. #--------------------------------------------------------------------------
  395. # new method: refresh
  396. #--------------------------------------------------------------------------
  397. def refresh
  398. contents.clear
  399. fill_info_panel
  400. end
  401. end # Window_RentalBackgroud
  402.  
  403. class Scene_DungeonRental < Scene_Base
  404. #--------------------------------------------------------------------------
  405. # method: start
  406. #--------------------------------------------------------------------------
  407. def start
  408. super
  409. create_main_windows
  410. end
  411. #--------------------------------------------------------------------------
  412. # new method: create_main_windows
  413. #--------------------------------------------------------------------------
  414. def create_main_windows
  415. @title_window = Window_RentalTitle.new(0,0,Graphics.width,48)
  416. @title_window.draw_title
  417. bg_y = @title_window.height
  418. bg_height = Graphics.height - @title_window.height
  419. bg_width = Graphics.width - 160
  420. @background_window = Window_RentalBackgroud.new(0,bg_y,bg_width,bg_height)
  421. @background_window.refresh
  422. act_x = @background_window.x + @background_window.width
  423. act_y = bg_y
  424. act_height = @background_window.fitting_height(1)
  425. act_width = Graphics.width - @background_window.width
  426. @action_name_window = Window_Base.new(act_x,act_y,act_width,act_height)
  427. ct_w = @action_name_window.contents_width
  428. ct_h = @action_name_window.contents_height
  429. @action_name_window.draw_text(0,0,ct_w,ct_h,"Actions",1)
  430.  
  431. @gold_window = Window_Gold.new
  432. @gold_window.x = act_x
  433. @gold_window.y = Graphics.height - @gold_window.height
  434.  
  435. @rental_window = Window_RentalList.new(16,bg_y+16)
  436. @rental_window.opacity = 0
  437. new_x = 0.5*(@background_window.width - (32+16)*6) - 5
  438. @rental_window.back_opacity = 0
  439. @rental_window.x = new_x
  440. @last_index = @rental_window.index
  441. @background_window.draw_item_info(@rental_window.current_tool)
  442.  
  443. @rental_act_window = Window_RentalAction.new(act_x,act_height+act_y,@rental_window)
  444. @rental_act_window.refresh
  445. @rental_act_window.set_handler(:rent, method(:command_rent))
  446. @rental_act_window.set_handler(:buy, method(:command_buy))
  447. @rental_act_window.set_handler(:return, method(:command_return))
  448. @rental_act_window.set_handler(:cancel, method(:return_scene))
  449. end
  450. #--------------------------------------------------------------------------
  451. # new method: return_scene
  452. #--------------------------------------------------------------------------
  453. def return_scene
  454. super
  455. Sound.play_cancel
  456. end
  457. #--------------------------------------------------------------------------
  458. # new method: command_rent
  459. #--------------------------------------------------------------------------
  460. def command_rent
  461. if $game_party.gold >= @rental_window.current_tool.rental_price
  462. $game_system.rental_tool = @rental_window.current_tool.id
  463. $game_party.lose_gold(@rental_window.current_tool.rental_price)
  464. $game_party.gain_item(@rental_window.current_tool,1)
  465. Sound.play_ok
  466. else
  467. Sound.play_buzzer
  468. end
  469. refresh_windows
  470. @rental_act_window.activate
  471. end
  472. #--------------------------------------------------------------------------
  473. # new method: command_return
  474. #--------------------------------------------------------------------------
  475. def command_return
  476. if $game_system.rental_tool > 0
  477. tool = $data_weapons[$game_system.rental_tool]
  478. #~ $game_party.gain_gold(tool.rental_price)
  479. $game_party.lose_item(tool,1,true)
  480. $game_system.rental_tool = 0
  481. Sound.play_ok
  482. end
  483. refresh_windows
  484. @rental_act_window.activate
  485. end
  486. #--------------------------------------------------------------------------
  487. # new method: command_buy
  488. #--------------------------------------------------------------------------
  489. def command_buy
  490. if $game_party.gold >= @rental_window.current_tool.purchase_price
  491. $game_system.bought_tools.push(@rental_window.current_tool.id)
  492. $game_party.lose_gold(@rental_window.current_tool.purchase_price)
  493. $game_party.gain_item(@rental_window.current_tool,1)
  494. Sound.play_ok
  495. else
  496. Sound.play_buzzer
  497. end
  498. refresh_windows
  499. @rental_act_window.activate
  500. end
  501. #--------------------------------------------------------------------------
  502. # new method: refresh_windows
  503. #--------------------------------------------------------------------------
  504. def refresh_windows
  505. @rental_window.refresh
  506. @rental_act_window.refresh
  507. @background_window.draw_item_info(@rental_window.current_tool)
  508. @gold_window.refresh
  509. end
  510. #--------------------------------------------------------------------------
  511. # new method: update
  512. #--------------------------------------------------------------------------
  513. def update
  514. super
  515. if @last_index != @rental_window.index
  516. @last_index = @rental_window.index
  517. @rental_window.current_rent_state
  518. @background_window.draw_item_info(@rental_window.current_tool)
  519. @rental_act_window.refresh
  520. end
  521. end
  522. end # Scene_DungeonRental
  523.  
  524. class Window_ShopSell < Window_ItemList
  525. alias_method(:dsiver144_shop_enable_tool, :enable?)
  526. def enable?(item)
  527. dsiver144_shop_enable_tool(item) && !item.rental_tool
  528. end
  529. end # Window_ShopSell
  530.  
  531. #===============================================================================
  532. # * END OF FILE
  533. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement