mcgluszak

Item Weight v1.1

Jul 21st, 2011
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.94 KB | None | 0 0
  1. #==============================================================================
  2. # ITEM WEIGHT
  3. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  4. # Autor: Andrzej 'mc' Głuszak
  5. # Wersja: 1.1
  6. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  7. # Opis: Dzięki temu skryptowi ustalisz limit wagi noszonych przez drużynę
  8. #       przedmiotów. Od teraz drużyna noszące ze sobą tysiąc czołgów nie będzie
  9. #       mogła się poruszać. UWAGA: do pozbycia się zbędnych czołgów serdecznie
  10. #       polecam skrypt mojego autorstwa 'Drop Item'.
  11. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  12. # Instrukcja: Ustaw mnożnik (służy do obliczania maksymalnego obciążenia postaci,
  13. #             wzór wygląda tak: maksymalne obciążenie = siła * mnożnik),
  14. #             jednostkę i przypisz każdemu przedmiotowi jego wagę.
  15. #
  16. #             Aby sprawdzić, czy drużyna jest przeciążona wywołaj skrypt
  17. #               $game_party.burdened?          
  18. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  19. # Kompatybilność: Nie testowany z SDK.
  20. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  21. # Licencja: CREATIVE COMMONS Uznanie autorstwa 3.0 Unported (CC BY 3.0)
  22. #           Wolno: kopiować, rozpowszechniać, odtwarzać i wykonywać utwór,
  23. #                  tworzyć utwory zależne
  24. #           Na następujących warunkach: Uznanie autorstwa —
  25. #                   należy wpisać twórcę skryptu (mcgluszak)
  26. #                   do credits (podziękowań).
  27. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  28. # Zmiany: v1.0 (18.05.11) - wydanie skryptu
  29. #         v1.1 (21.07.11) - zmiana prędkości jeśli drużyna jest przeciążona,
  30. #                            otwieranie ekwipunku jeśli drużyna jest przeciążona
  31. #==============================================================================
  32.  
  33. # KONFIGURACJA
  34. module Gluszak
  35.   module Item_Weight
  36.    
  37.     # Mnożnik - maksymalne obciążenie = mnożnik * siła
  38.     Multiplier = 1.1
  39.    
  40.     # Jednostka
  41.     Unit = 'kg'
  42.    
  43.     # Przedmioty
  44.     # id => waga, id => waga, itd.
  45.     Items =
  46.     {1 => 0.2,
  47.     2 => 0.25,
  48.     3 => 0.4}
  49.    
  50.     # Bronie
  51.     # id => waga, id => waga, itd.
  52.     Weapons =
  53.     {1 => 3,
  54.     2 => 5,
  55.     3 => 10}
  56.    
  57.     # Zbroje
  58.     # id => waga, id => waga, itd.
  59.     Armors =
  60.     {1 => 20,
  61.     2 => 15,
  62.     3 => 1.5}
  63.    
  64.     Burdened_Speed = 2 # Prędkość przeciążonej drużyny (0-6)
  65.    
  66.     Open_Equipment = true # Czy otworzyć ekwipunek jeśli drużyna jest przeciążona?
  67.    
  68.   end
  69. end
  70. # KONIEC KONFIGURACJI
  71.  
  72. $item_weight = 1.1
  73.  
  74. #==============================================================================
  75. # ** Game_Battler
  76. #==============================================================================
  77. class Game_Battler
  78.  
  79.   #--------------------------------------------------------------------------
  80.   # * Obciążenie
  81.   #--------------------------------------------------------------------------
  82.   def encumbrance
  83.     return Gluszak::Item_Weight::Multiplier * self.str
  84.   end
  85.  
  86. end
  87.  
  88. #==============================================================================
  89. # ** Game_Party
  90. #==============================================================================
  91. class Game_Party
  92.  
  93.   attr_reader :max_encumbrance
  94.   attr_reader :encumbrance
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # * Inicjalizacja
  98.   #--------------------------------------------------------------------------
  99.   alias :initialize_item_weight :initialize
  100.   def initialize
  101.     initialize_item_weight
  102.     @max_encumbrance = 0
  103.     @encumbrance = 0
  104.   end
  105.  
  106.   #--------------------------------------------------------------------------
  107.   # * Maksymalne obciążenie drużyny
  108.   #--------------------------------------------------------------------------
  109.   def max_encumbrance
  110.     me = 0
  111.     $game_party.actors.each {|actor| me += actor.encumbrance}
  112.     return me
  113.   end
  114.  
  115.   #--------------------------------------------------------------------------
  116.   # * Obciążenie drużyny
  117.   #--------------------------------------------------------------------------
  118.   def encumbrance
  119.     e = 0
  120.     for i in 1..$data_items.size
  121.       e += $game_party.item_number(i) * (Gluszak::Item_Weight::Items[i] != nil ? Gluszak::Item_Weight::Items[i] : 0)
  122.     end
  123.     for i in 1..$data_weapons.size
  124.       e += $game_party.weapon_number(i) * (Gluszak::Item_Weight::Weapons[i] != nil ? Gluszak::Item_Weight::Weapons[i] : 0)
  125.     end
  126.     for i in 1..$data_armors.size
  127.        e += $game_party.armor_number(i) * (Gluszak::Item_Weight::Armors[i] != nil ? Gluszak::Item_Weight::Armors[i] : 0)
  128.     end
  129.      
  130.     $game_party.actors.each {|actor|
  131.       e += Gluszak::Item_Weight::Weapons[actor.weapon_id] != nil ? Gluszak::Item_Weight::Weapons[actor.weapon_id] : 0
  132.       e += Gluszak::Item_Weight::Armors[actor.armor1_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor1_id] : 0
  133.       e += Gluszak::Item_Weight::Armors[actor.armor2_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor2_id] : 0
  134.       e += Gluszak::Item_Weight::Armors[actor.armor3_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor3_id] : 0
  135.       e += Gluszak::Item_Weight::Armors[actor.armor4_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor4_id] : 0
  136.     }
  137.      
  138.     return e
  139.   end
  140.  
  141.   #--------------------------------------------------------------------------
  142.   # * Drużyna przeciążona?
  143.   #--------------------------------------------------------------------------
  144.   def burdened?
  145.     return encumbrance > max_encumbrance
  146.   end
  147.  
  148. end
  149.  
  150. #==============================================================================
  151. # ** Window_Base
  152. #==============================================================================
  153. class Window_Base
  154.  
  155.   #--------------------------------------------------------------------------
  156.   # * Rysuj obciążenie drużyny
  157.   #--------------------------------------------------------------------------
  158.   def draw_encumbrance(x,y)
  159.     e = $game_party.encumbrance.to_f
  160.     em = $game_party.max_encumbrance.to_f
  161.    
  162.     if e/em < 0.85
  163.       self.contents.font.color = system_color
  164.     elsif e/em > 0.85 and e/em < 1
  165.       self.contents.font.color = crisis_color
  166.     else
  167.       self.contents.font.color = knockout_color
  168.     end
  169.    
  170.     self.contents.draw_text(x, y, 48, 32, e.to_s, 2)
  171.     self.contents.font.color = normal_color
  172.     self.contents.draw_text(x + 50, y, 8, 32, '/')
  173.     self.contents.draw_text(x + 60, y, 64, 32, em.to_s + 'kg')
  174.   end
  175.  
  176. end
  177.  
  178. #==============================================================================
  179. # ** Window_Encumbrance
  180. #==============================================================================    
  181. class Window_Encumbrance < Window_Base
  182.  
  183.   #--------------------------------------------------------------------------
  184.   # * Inicjalizacja
  185.   #--------------------------------------------------------------------------
  186.   def initialize
  187.     super(0, 0, 160, 64)
  188.     self.contents = Bitmap.new(width - 32, height - 32)
  189.     refresh
  190.   end
  191.  
  192.   #--------------------------------------------------------------------------
  193.   # * Odśwież
  194.   #--------------------------------------------------------------------------
  195.   def refresh
  196.     self.contents.clear
  197.     draw_encumbrance(0,0)
  198.   end
  199.  
  200. end
  201.  
  202. #==============================================================================
  203. # ** Scene_Item
  204. #==============================================================================
  205. class Scene_Item
  206.  
  207.   #--------------------------------------------------------------------------
  208.   # * Główny proces
  209.   #--------------------------------------------------------------------------
  210.   alias :main_item_weight :main
  211.   def main
  212.     @encumbrance_window = Window_Encumbrance.new
  213.     @encumbrance_window.x = 480
  214.     @encumbrance_window.y = 414
  215.     @encumbrance_window.z = 200
  216.     main_item_weight
  217.     @encumbrance_window.dispose
  218.   end
  219.  
  220.   #--------------------------------------------------------------------------
  221.   # * Uaktualnij
  222.   #--------------------------------------------------------------------------
  223.   alias :update_item_weight :update
  224.   def update
  225.     update_item_weight
  226.     @encumbrance_window.refresh
  227.   end
  228.  
  229. end
  230.  
  231. #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  232. # *** RPG
  233. #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  234. module RPG
  235.  
  236.   #==============================================================================
  237.   # ** RPG::Weapon
  238.   #==============================================================================
  239.   class Weapon
  240.    
  241.     #--------------------------------------------------------------------------
  242.     # * Opis
  243.     #--------------------------------------------------------------------------
  244.     def description
  245.       if Gluszak::Item_Weight::Weapons[@id] != nil
  246.         weight = 'Waga: '
  247.         unit = Gluszak::Item_Weight::Unit
  248.         weight += Gluszak::Item_Weight::Weapons[@id].to_s + unit + ', '
  249.       else
  250.         weight = ''
  251.       end
  252.       return weight + @description
  253.     end
  254.    
  255.   end
  256.  
  257.   #==============================================================================
  258.   # ** RPG::Armor
  259.   #==============================================================================
  260.   class Armor
  261.    
  262.     #--------------------------------------------------------------------------
  263.     # * Opis
  264.     #--------------------------------------------------------------------------
  265.     def description
  266.       if Gluszak::Item_Weight::Armors[@id] != nil
  267.         weight = 'Waga: '
  268.         unit = Gluszak::Item_Weight::Unit
  269.         weight += Gluszak::Item_Weight::Armors[@id].to_s + unit + ', '
  270.       else
  271.         weight = ''
  272.       end
  273.       return weight + @description
  274.     end
  275.    
  276.   end
  277.  
  278.   #==============================================================================
  279.   # ** RPG::Item
  280.   #==============================================================================
  281.   class Item
  282.    
  283.     #--------------------------------------------------------------------------
  284.     # * Opis
  285.     #--------------------------------------------------------------------------
  286.     def description
  287.       if Gluszak::Item_Weight::Items[@id] != nil
  288.         weight = 'Waga: '
  289.         unit = Gluszak::Item_Weight::Unit
  290.         weight += Gluszak::Item_Weight::Items[@id].to_s + unit + ', '
  291.       else
  292.         weight = ''
  293.       end
  294.       return weight + @description
  295.     end
  296.    
  297.   end
  298.  
  299. end
  300.  
  301. #==============================================================================
  302. # ** Game_Map
  303. #==============================================================================
  304. class Game_Map
  305.  
  306.   #--------------------------------------------------------------------------
  307.   # * Uaktualnij
  308.   #--------------------------------------------------------------------------
  309.   alias :update_item_weight :update
  310.   def update
  311.     update_item_weight
  312.     $item_weight_open_once = false if !$game_party.burdened?
  313.     if $game_party.burdened?
  314.       $game_player.move_speed = Gluszak::Item_Weight::Burdened_Speed
  315.       if Gluszak::Item_Weight::Open_Equipment and !$item_weight_open_once
  316.         $item_weight_open_once = true
  317.         $scene = Scene_Item.new
  318.       end
  319.     else
  320.       $game_player.move_speed = 4
  321.     end
  322.   end
  323.  
  324. end
  325.  
  326. #==============================================================================
  327. # ** Game_Character
  328. #==============================================================================
  329. class Game_Character
  330.   attr_accessor :move_speed
  331. end
  332.  
  333. #==============================================================================
  334. # ** Scene_Title
  335. #==============================================================================
  336. class Scene_Title
  337.  
  338.   alias :main_item_weight :main
  339.   def main
  340.     $item_weight_open_once = false
  341.     main_item_weight
  342.   end
  343.  
  344. end
Add Comment
Please, Sign In to add comment