Advertisement
Raizen

Untitled

Jan 10th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.06 KB | None | 0 0
  1. #=======================================================
  2. # Lune Item Weight
  3. # Author : Raizen
  4. # Script Function:
  5. # The scripts adds the function of items having weight on the game,
  6. # Basically all item have weights and they can only be carried if below the limit
  7. #=======================================================
  8.  
  9.  
  10. module Lune_Weight
  11. #=============================================================================#
  12. #========================= General Settings ==============================#
  13. #=============================================================================#
  14.  
  15. # To configure a weight for an item, go to Database,
  16. # Inside the notetags after choosing an item or equipe, put the following.
  17. # <weight n> where n is the weight value,
  18. # Example an item weighting 60,
  19. # <weight 60>
  20.  
  21. # In case there are no notetags on the Item, the script will
  22. # choose a default value which is:
  23.  
  24. Default = 50
  25.  
  26. # Receive even if over weight?
  27. # To prevent from the actor receiving important itens through the game,
  28. # you can allow the player to receive itens even if they are over the
  29. # weight limit.
  30. Receive = true
  31. # If false, you need to know how to event the important itens, putting
  32. # conditions so that importat itens are not left out without being received.
  33.  
  34. # In case they are over the weight limit, you can lock the character movement.
  35. Travar = true
  36.  
  37. # Below the variables that you can use to make the event conditions:
  38.  
  39. # Choose a variable to receive the value of amount of weight carried.
  40. Var_C = 5
  41. # Choose a variable to receive the value of amount of the weight limit.
  42. Var_M = 6
  43. # With both variables you can event the conditions of receiving items or even
  44. # event conditions considering the weight carried and limit.
  45.  
  46. LimiteB = 8000 # Configure if you are using Lune Item Vault (My vault script)
  47. # to have no limite, LimiteB = ""
  48. #=============================================================================#
  49. #===================== Limit Weight Configuration ========================#
  50. #=============================================================================#
  51.  
  52. # Maximum amount of weight carried,
  53. # to configure the weight limit, you can put a variable value, a constant value
  54. # or strength value.
  55. # To put the main actor strength value => :for1
  56. # To put the sum of actors strength value => :all_for
  57. # To be the main actor level => :lvl1
  58. # To be the sum of all actors level => :all_lvl
  59. # To be a variable => :var
  60. # To be a constant => :fix
  61.  
  62.  
  63. # Exemple Carry_Limit = lvl1 will make only the strength of the
  64. # first actor to be put in the formula.
  65. Carry_Limit = :all_for
  66.  
  67. # Now you need to configure the formula of the weight limit,
  68. # Exemple, if I want to the limit be 2 times all the party members strength
  69.  
  70. # def self.weight_formula(at)
  71. # at * 2
  72. # end
  73.  
  74. # at is the value of the atribute, and the multiply by 2 to get the total limit.
  75.  
  76. # In case its a variable or a constant number, just put the
  77. # variable number, or the constant number.
  78.  
  79. # Exemple:
  80.  
  81. # def self.weight_formula(at)
  82. # 20
  83. # end
  84.  
  85. # The limit will be variable 20, ou if chosen a constant, will be 20.
  86.  
  87.  
  88. def self.weight_formula(at)
  89. at * 2 + 1000
  90. end
  91.  
  92.  
  93. #===================== Vocabulary Settings ==========================#
  94. # To Vocab, always put the text between commas '', or "".
  95. # Weight name,
  96. PS = ' Oz'
  97.  
  98. # Vocab on menu and shop
  99. # Weight:
  100. Peso = 'Weight:'
  101.  
  102. #Carrying =
  103. Carregando = 'Carrying: '
  104.  
  105. # If Lune Vault System included
  106. # Vault =
  107. Bau = 'In Vault: '
  108.  
  109. # Vocabulary on item window
  110.  
  111. # Use =
  112. Usar = 'Use'
  113. # Dispose =
  114. Descartar = 'Throw Away'
  115.  
  116. #=============================================================================#
  117. #========================== Here starts the script ===========================#
  118. #=============================================================================#
  119. #=============================================================================#
  120. #========================== Aqui começa o script =============================#
  121. #=============================================================================#
  122. def self.receive(bol = nil)
  123. @bol = bol unless bol == nil
  124. return @bol
  125. end
  126. #--------------------------------------------------------------------------
  127. # * Calculo do limite de peso
  128. #--------------------------------------------------------------------------
  129. def self.weight_limit
  130. return 10 unless $game_party.members[0]
  131. case Carry_Limit
  132. when :for1
  133. weight = weight_formula($game_party.members[0].param(2))
  134. when :all_for
  135. weight = 0
  136. for members in 0...$game_party.members.size - 1
  137. weight += weight_formula($game_party.members[members].param(2))
  138. end
  139. when :lvl1
  140. weight = weight_formula($game_party.members[0].level)
  141. when :all_lvl
  142. weight = 0
  143. for members in 0...$game_party.members.size - 1
  144. weight += weight_formula($game_party.members[members].level)
  145. end
  146. when :fix
  147. weight = weight_formula(0)
  148. when :var
  149. weight = $game_variables[weight_formula(0)]
  150. end
  151. $game_variables[Var_M] = weight
  152. weight
  153. end
  154. end
  155.  
  156. Lune_Weight.receive(Lune_Weight::Receive)
  157.  
  158. #==============================================================================
  159. # ** Game_Party
  160. #------------------------------------------------------------------------------
  161. # Esta classe gerencia o grupo. Contém informações sobre dinheiro, itens.
  162. # A instância desta classe é referenciada por $game_party.
  163. #==============================================================================
  164.  
  165. class Game_Party < Game_Unit
  166. alias :lune_weight_gain :gain_item
  167. #--------------------------------------------------------------------------
  168. # * Quantidade de itens carregados mais os itens equipados
  169. #--------------------------------------------------------------------------
  170. def carried_items
  171. @all_carried_items = 0
  172. all_items.each {|item| get_weight(item)}
  173. for i in 0...4
  174. members.each {|actor| @all_carried_items += calc_weight(actor.equips[i], 1)}
  175. end
  176. @all_carried_items += Lune_Weight::Gold * gold/100
  177. $game_variables[Lune_Weight::Var_C] = @all_carried_items
  178. @all_carried_items
  179. end
  180. #--------------------------------------------------------------------------
  181. # * Calculo do peso de um item no inventário
  182. #--------------------------------------------------------------------------
  183. def get_weight(item)
  184. if item.note =~ /<peso (.*)>/i
  185. @all_carried_items += $1.to_i * item_number(item)
  186. else
  187. @all_carried_items += Lune_Weight::Default * item_number(item)
  188. end
  189. end
  190. #--------------------------------------------------------------------------
  191. # * Calculo do peso de um item relativo a quantidade
  192. #--------------------------------------------------------------------------
  193. def calc_weight(item, amount)
  194. return 0 unless item
  195. if item.note =~ /<peso (.*)>/i
  196. carried_itens = $1.to_i * amount
  197. else
  198. carried_itens = Lune_Weight::Default * amount
  199. end
  200. carried_itens
  201. end
  202. #--------------------------------------------------------------------------
  203. # * Acrescentar item (redução)
  204. # item : item
  205. # amount : quantia alterada
  206. # include_equip : incluir itens equipados
  207. #--------------------------------------------------------------------------
  208. def gain_item(item, amount, include_equip = false)
  209. if Lune_Weight.receive
  210. lune_weight_gain(item, amount, include_equip = false)
  211. return
  212. end
  213. return if item == nil
  214. weight = calc_weight(item, amount) + carried_items
  215. while weight > Lune_Weight.weight_limit
  216. amount -= 1
  217. weight = calc_weight(item, amount) + carried_items
  218. return if amount == 0
  219. end
  220. lune_weight_gain(item, amount, include_equip = false)
  221. end
  222. end
  223.  
  224. #==============================================================================
  225. # ** Scene_Shop
  226. #------------------------------------------------------------------------------
  227. # Esta classe executa o processamento da tela de loja.
  228. #==============================================================================
  229.  
  230. class Scene_Shop < Scene_MenuBase
  231. alias :lune_max_buy :max_buy
  232. #--------------------------------------------------------------------------
  233. # * Aquisição do número máximo disponível para compra
  234. #--------------------------------------------------------------------------
  235. def max_buy
  236. max = lune_max_buy
  237. weight = $game_party.calc_weight(@item, max) + $game_party.carried_items
  238. while weight > Lune_Weight.weight_limit && max > 0
  239. max -= 1
  240. weight = $game_party.calc_weight(@item, max) + $game_party.carried_items
  241. end
  242. max
  243. end
  244. #--------------------------------------------------------------------------
  245. # * Criação da janela de ajuda.
  246. #--------------------------------------------------------------------------
  247. def create_help_window
  248. @help_window = Window_Weight_Help.new
  249. @help_window.viewport = @viewport
  250. @get_item_num = $game_party.carried_items
  251. end
  252. #--------------------------------------------------------------------------
  253. # * Atualização da janela de peso
  254. #--------------------------------------------------------------------------
  255. def update
  256. super
  257. if @get_item_num != $game_party.carried_items
  258. @help_window.refresh
  259. @get_item_num = $game_party.carried_items
  260. end
  261. end
  262. end
  263.  
  264. #==============================================================================
  265. # ** Window_ShopBuy
  266. #------------------------------------------------------------------------------
  267. # Esta janela exibe bens compráveis na tela de loja.
  268. #==============================================================================
  269.  
  270. class Window_ShopBuy < Window_Selectable
  271. alias :lune_enable_item :enable?
  272. #--------------------------------------------------------------------------
  273. # * Definição de habilitação do item
  274. # item : item
  275. #--------------------------------------------------------------------------
  276. def enable?(item)
  277. return false if $game_party.calc_weight(item, 1) + $game_party.carried_items > Lune_Weight.weight_limit
  278. lune_enable_item(item)
  279. end
  280. end
  281.  
  282.  
  283. #==============================================================================
  284. # ** Window_Help
  285. #------------------------------------------------------------------------------
  286. # Esta janela exibe explicação de habilidades e itens e outras informações.
  287. #==============================================================================
  288.  
  289. class Window_Weight_Help < Window_Base
  290. include Lune_Weight
  291. #--------------------------------------------------------------------------
  292. # * Inicialização do objeto
  293. # line_number : número de linhas
  294. #--------------------------------------------------------------------------
  295. def initialize(line_number = 2, bau = false)
  296. @bau = bau
  297. super(0, 0, Graphics.width, fitting_height(line_number))
  298. end
  299. #--------------------------------------------------------------------------
  300. # * Configuração de texto
  301. # text : texto
  302. #--------------------------------------------------------------------------
  303. def set_text(text)
  304. if text != @text
  305. @text = text
  306. refresh
  307. end
  308. end
  309. def on_bau(bau = false)
  310. @bau = bau
  311. end
  312. #--------------------------------------------------------------------------
  313. # * Limpeza
  314. #--------------------------------------------------------------------------
  315. def clear
  316. set_text("")
  317. end
  318. #--------------------------------------------------------------------------
  319. # * Definição de item
  320. # item : habilidades, itens, etc.
  321. #--------------------------------------------------------------------------
  322. def set_item(item)
  323. @item = item
  324. set_text(item ? item.description : "")
  325. end
  326. #--------------------------------------------------------------------------
  327. # * Renovação
  328. #--------------------------------------------------------------------------
  329. def refresh
  330. contents.clear
  331. draw_text_ex(4, 0, @text)
  332. if @item
  333. text = Peso + $game_party.calc_weight(@item,1).to_s + PS
  334. draw_text(4, line_height, 200, line_height, text, 0)
  335. if @bau == true
  336. LimiteB == "" ? text_lim = "????" : text_lim = LimiteB
  337. text = Bau + $game_party.items_on_vault.to_s + "/" + text_lim.to_s + PS
  338. else
  339. text = Carregando + $game_party.carried_items.to_s + "/" + Lune_Weight.weight_limit.to_s + PS
  340. end
  341. draw_text(- 20, line_height, Graphics.width, line_height, text, 2)
  342. end
  343. end
  344. end
  345.  
  346.  
  347. #==============================================================================
  348. # ** Game_Player
  349. #------------------------------------------------------------------------------
  350. # Esta classe gerencia o jogador.
  351. # A instância desta classe é referenciada por $game_player.
  352. #==============================================================================
  353.  
  354. class Game_Player < Game_Character
  355. alias :lune_move_by :move_by_input
  356. #--------------------------------------------------------------------------
  357. # * Processamento de movimento através de pressionar tecla
  358. #--------------------------------------------------------------------------
  359. def move_by_input
  360. return if Lune_Weight::Travar && $game_party.carried_items > Lune_Weight.weight_limit
  361. lune_move_by
  362. end
  363. end
  364.  
  365.  
  366. #==============================================================================
  367. # ** Scene_Item
  368. #------------------------------------------------------------------------------
  369. # Esta classe executa o processamento da tela de item.
  370. #==============================================================================
  371. class Scene_Item < Scene_ItemBase
  372. alias raizen_combine_start start
  373. def start
  374. raizen_combine_start
  375. @combine_item = Window_Item_Combine.new
  376. @combine_item.viewport = @viewport
  377. @combine_item.set_handler(:new_game, method(:command_use))
  378. @combine_item.set_handler(:continue, method(:command_combine))
  379. end
  380. def on_item_ok
  381. if item == nil
  382. @item_window.activate
  383. return
  384. end
  385. if @combine_item.close?
  386. @combine_item.open
  387. @combine_item.activate
  388. else
  389. determine_item
  390. end
  391. end
  392.  
  393. def update
  394. super
  395. if @number_window and @number_window.nitens == true
  396. @number_window.nitens = false
  397. @combine_item.close
  398. @item_window.refresh
  399. @help_window.refresh
  400. @item_window.activate
  401. end
  402. if Input.trigger?(:B) and !@combine_item.close?
  403. Sound.play_cancel
  404. if @number_window and !@number_window.close?
  405. @number_window.close
  406. @combine_item.activate
  407. else
  408. @combine_item.close
  409. @item_window.activate
  410. end
  411. end
  412. end
  413. def command_use
  414. determine_item
  415. end
  416.  
  417. def command_combine
  418. if @number_window and !@number_window.close?
  419. @combine_item.activate
  420. return
  421. end
  422. @number_window = Window_NumberInputInner.new(Window_Base.new(0,0,0,0), item, @item_window.index)
  423. @number_window.viewport = @viewport
  424. @number_window.start
  425. end
  426. def create_help_window
  427. @help_window = Window_Weight_Help.new
  428. @help_window.viewport = @viewport
  429. end
  430. end
  431.  
  432. #==============================================================================
  433. # ** Window_MenuStatus
  434. #------------------------------------------------------------------------------
  435. # Esta janela exibe os parâmetros dos membros do grupo na tela de menu.
  436. #==============================================================================
  437.  
  438. class Window_Item_Combine < Window_Command
  439. include Lune_Weight
  440. #--------------------------------------------------------------------------
  441. # * Inicialização do objeto
  442. #--------------------------------------------------------------------------
  443. def initialize
  444. super(0, 0)
  445. self.z = 9999
  446. self.x = (Graphics.width / 2) - (window_width / 2)
  447. self.y = Graphics.height / 2
  448. self.openness = 0
  449. end
  450. #--------------------------------------------------------------------------
  451. # * Aquisição da largura da janela
  452. #--------------------------------------------------------------------------
  453. def window_width
  454. return 160
  455. end
  456. #--------------------------------------------------------------------------
  457. # * Criação da lista de comandos
  458. #--------------------------------------------------------------------------
  459. def make_command_list
  460. add_main_commands
  461.  
  462. end
  463. #--------------------------------------------------------------------------
  464. # * Adição dos comandos principais
  465. #--------------------------------------------------------------------------
  466. def add_main_commands
  467. add_command(Usar, :new_game, true)
  468. add_command(Descartar, :continue, true)
  469. end
  470. end
  471.  
  472.  
  473.  
  474.  
  475. #==============================================================================
  476. # ** Scene_ItemBase
  477. #------------------------------------------------------------------------------
  478. # Esta é a superclasse das classes que executam as telas de itens e
  479. # habilidades.
  480. #==============================================================================
  481.  
  482. class Scene_Item < Scene_ItemBase
  483. def determine_item
  484. @combine_item.close if @combine_item
  485. if item.is_a?(RPG::Item) and item.for_friend?
  486. show_sub_window(@actor_window)
  487. @actor_window.select_for_item(item)
  488. else
  489. item.is_a?(RPG::Item) ? use_item : Sound.play_buzzer
  490. activate_item_window
  491. end
  492. end
  493. end
  494.  
  495. #==============================================================================
  496. # ** Window_NumberInputInner
  497. #------------------------------------------------------------------------------
  498. # Esta janela é utilizada para o comando de eventos [Armazenar Número]
  499. #==============================================================================
  500.  
  501. class Window_NumberInputInner < Window_NumberInput
  502. attr_accessor :nitens
  503. def initialize(message_window, item, index_2)
  504. @index_2 = index_2
  505. @item = item
  506. @get_lost_itens = 0
  507. super(message_window)
  508. end
  509. #--------------------------------------------------------------------------
  510. # * Inicialização do processo
  511. #--------------------------------------------------------------------------
  512. def start
  513. @digits_max = 2
  514. @number = @get_lost_itens
  515. @number = [[@number, 0].max, 10 ** @digits_max - 1].min
  516. @index = 0
  517. update_placement
  518. create_contents
  519. refresh
  520. open
  521. activate
  522. end
  523. #--------------------------------------------------------------------------
  524. # * Atualização da posição da janela
  525. #--------------------------------------------------------------------------
  526. def update_placement
  527. self.width = @digits_max * 20 + padding * 2
  528. self.height = fitting_height(1)
  529. self.x = (Graphics.width - width) / 2
  530. self.y = Graphics.height/2 - height
  531. self.z = 150
  532. end
  533.  
  534. #--------------------------------------------------------------------------
  535. # * Definição de resultado ao pressionar o botão de confirmação
  536. #--------------------------------------------------------------------------
  537. def process_ok
  538. number = $game_party.item_number(@item)
  539. if @number <= number
  540. make_icon
  541. else
  542. Sound.play_cancel
  543. end
  544. deactivate
  545. @nitens = true
  546. close
  547. end
  548. def make_icon
  549. @nitens = true
  550. if @item.note =~ /<keyitem>/
  551. Sound.play_cancel
  552. else
  553. Sound.play_ok
  554. $game_party.lose_item(@item, @number)
  555. end
  556. end
  557. end
  558.  
  559. #==============================================================================
  560. # ** Window_ItemList
  561. #------------------------------------------------------------------------------
  562. # Esta janela exibe a lista de itens possuidos na tela de itens.
  563. #==============================================================================
  564.  
  565. class Window_ItemList < Window_Selectable
  566. #--------------------------------------------------------------------------
  567. # * Definição de habilitação do item
  568. # item : item
  569. #--------------------------------------------------------------------------
  570. def enable?(item)
  571. true
  572. end
  573. end
  574.  
  575. #==============================================================================
  576. # ** Game_Actor
  577. #------------------------------------------------------------------------------
  578. # Esta classe gerencia os heróis. Ela é utilizada internamente pela classe
  579. # Game_Actors ($game_actors). A instância desta classe é referenciada
  580. # pela classe Game_Party ($game_party).
  581. #==============================================================================
  582.  
  583. class Game_Actor < Game_Battler
  584. #--------------------------------------------------------------------------
  585. # * Trocar item com membro do grupo
  586. # new_item : item removido do grupo
  587. # old_item : item devolvido ao grupo
  588. #--------------------------------------------------------------------------
  589. def trade_item_with_party(new_item, old_item)
  590. return false if new_item && !$game_party.has_item?(new_item)
  591. $game_party.lose_item(new_item, 1)
  592. $game_party.gain_item(old_item, 1)
  593. return true
  594. end
  595. end
  596.  
  597. $lune_weight_script = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement