mcgluszak

Item Weight v1.0

May 18th, 2011
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.72 KB | None | 0 0
  1. #==============================================================================
  2. # ITEM WEIGHT
  3. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  4. # Autor: Andrzej 'mc' Głuszak
  5. # Wersja: 1.0
  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. # Kompatybilność: Nie testowany z SDK.
  17. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  18. # Licencja: CREATIVE COMMONS Uznanie autorstwa 3.0 Unported (CC BY 3.0)
  19. #           Wolno: kopiować, rozpowszechniać, odtwarzać i wykonywać utwór,
  20. #                  tworzyć utwory zależne
  21. #           Na następujących warunkach: Uznanie autorstwa —
  22. #                   należy wpisać twórcę skryptu (mcgluszak)
  23. #                   do credits (podziękowań).
  24. #-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-=
  25. # Zmiany: v1.0 (18.05.11) - wydanie skryptu
  26. #==============================================================================
  27.  
  28. # KONFIGURACJA
  29. module Gluszak
  30.   module Item_Weight
  31.    
  32.     # Mnożnik
  33.     Multiplier = 1.1
  34.    
  35.     # Jednostka
  36.     Unit = 'kg'
  37.    
  38.     # Przedmioty
  39.     # id => waga, id => waga, itd.
  40.     Items =
  41.     {1 => 0.2,
  42.     2 => 0.25,
  43.     3 => 0.4}
  44.    
  45.     # Bronie
  46.     # id => waga, id => waga, itd.
  47.     Weapons =
  48.     {1 => 2,
  49.     2 => 3,
  50.     3 => 10}
  51.    
  52.     # Zbroje
  53.     # id => waga, id => waga, itd.
  54.     Armors =
  55.     {1 => 20,
  56.     2 => 15,
  57.     3 => 1.5}
  58.    
  59.   end
  60. end
  61. # KONIEC KONFIGURACJI
  62.  
  63. $item_weight = 1.0
  64.  
  65. #==============================================================================
  66. # ** Game_Battler
  67. #==============================================================================
  68. class Game_Battler
  69.  
  70.   #--------------------------------------------------------------------------
  71.   # * Obciążenie
  72.   #--------------------------------------------------------------------------
  73.   def encumbrance
  74.     return Gluszak::Item_Weight::Multiplier * self.str
  75.   end
  76.  
  77. end
  78.  
  79. #==============================================================================
  80. # ** Game_Party
  81. #==============================================================================
  82. class Game_Party
  83.  
  84.   attr_reader :max_encumbrance
  85.   attr_reader :encumbrance
  86.  
  87.   #--------------------------------------------------------------------------
  88.   # * Inicjalizacja
  89.   #--------------------------------------------------------------------------
  90.   alias :initialize_item_weight :initialize
  91.   def initialize
  92.     initialize_item_weight
  93.     @max_encumbrance = 0
  94.     @encumbrance = 0
  95.   end
  96.  
  97.   #--------------------------------------------------------------------------
  98.   # * Maksymalne obciążenie drużyny
  99.   #--------------------------------------------------------------------------
  100.   def max_encumbrance
  101.     me = 0
  102.     $game_party.actors.each {|actor| me += actor.encumbrance}
  103.     return me
  104.   end
  105.  
  106.   #--------------------------------------------------------------------------
  107.   # * Obciążenie drużyny
  108.   #--------------------------------------------------------------------------
  109.   def encumbrance
  110.     e = 0
  111.     for i in 1..$data_items.size
  112.       e += $game_party.item_number(i) * (Gluszak::Item_Weight::Items[i] != nil ? Gluszak::Item_Weight::Items[i] : 0)
  113.     end
  114.     for i in 1..$data_weapons.size
  115.       e += $game_party.weapon_number(i) * (Gluszak::Item_Weight::Weapons[i] != nil ? Gluszak::Item_Weight::Weapons[i] : 0)
  116.     end
  117.     for i in 1..$data_armors.size
  118.        e += $game_party.armor_number(i) * (Gluszak::Item_Weight::Armors[i] != nil ? Gluszak::Item_Weight::Armors[i] : 0)
  119.     end
  120.      
  121.     $game_party.actors.each {|actor|
  122.       e += Gluszak::Item_Weight::Weapons[actor.weapon_id] != nil ? Gluszak::Item_Weight::Weapons[actor.weapon_id] : 0
  123.       e += Gluszak::Item_Weight::Armors[actor.armor1_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor1_id] : 0
  124.       e += Gluszak::Item_Weight::Armors[actor.armor2_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor2_id] : 0
  125.       e += Gluszak::Item_Weight::Armors[actor.armor3_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor3_id] : 0
  126.       e += Gluszak::Item_Weight::Armors[actor.armor4_id] != nil ? Gluszak::Item_Weight::Armors[actor.armor4_id] : 0
  127.     }
  128.      
  129.     return e
  130.   end
  131.  
  132. end
  133.  
  134. #==============================================================================
  135. # ** Window_Base
  136. #==============================================================================
  137. class Window_Base
  138.  
  139.   #--------------------------------------------------------------------------
  140.   # * Rysuj obciążenie drużyny
  141.   #--------------------------------------------------------------------------
  142.   def draw_encumbrance(x,y)
  143.     e = $game_party.encumbrance.to_f
  144.     em = $game_party.max_encumbrance.to_f
  145.    
  146.     if e/em < 0.85
  147.       self.contents.font.color = system_color
  148.     elsif e/em > 0.85 and e/em < 1
  149.       self.contents.font.color = crisis_color
  150.     else
  151.       self.contents.font.color = knockout_color
  152.     end
  153.    
  154.     self.contents.draw_text(x, y, 48, 32, e.to_s, 2)
  155.     self.contents.font.color = normal_color
  156.     self.contents.draw_text(x + 50, y, 8, 32, '/')
  157.     self.contents.draw_text(x + 60, y, 64, 32, em.to_s + 'kg')
  158.   end
  159.  
  160. end
  161.  
  162. #==============================================================================
  163. # ** Window_Encumbrance
  164. #==============================================================================    
  165. class Window_Encumbrance < Window_Base
  166.  
  167.   #--------------------------------------------------------------------------
  168.   # * Inicjalizacja
  169.   #--------------------------------------------------------------------------
  170.   def initialize
  171.     super(0, 0, 160, 64)
  172.     self.contents = Bitmap.new(width - 32, height - 32)
  173.     refresh
  174.   end
  175.  
  176.   #--------------------------------------------------------------------------
  177.   # * Odśwież
  178.   #--------------------------------------------------------------------------
  179.   def refresh
  180.     self.contents.clear
  181.     draw_encumbrance(0,0)
  182.   end
  183.  
  184. end
  185.  
  186. #==============================================================================
  187. # ** Scene_Item
  188. #==============================================================================
  189. class Scene_Item
  190.  
  191.   #--------------------------------------------------------------------------
  192.   # * Główny proces
  193.   #--------------------------------------------------------------------------
  194.   alias :main_item_weight :main
  195.   def main
  196.     @encumbrance_window = Window_Encumbrance.new
  197.     @encumbrance_window.x = 480
  198.     @encumbrance_window.y = 414
  199.     @encumbrance_window.z = 200
  200.     main_item_weight
  201.     @encumbrance_window.dispose
  202.   end
  203.  
  204.   #--------------------------------------------------------------------------
  205.   # * Uaktualnij
  206.   #--------------------------------------------------------------------------
  207.   alias :update_item_weight :update
  208.   def update
  209.     update_item_weight
  210.     @encumbrance_window.refresh
  211.   end
  212.  
  213. end
  214.  
  215. #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  216. # *** RPG
  217. #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  218. module RPG
  219.  
  220.   #==============================================================================
  221.   # ** RPG::Weapon
  222.   #==============================================================================
  223.   class Weapon
  224.    
  225.     #--------------------------------------------------------------------------
  226.     # * Opis
  227.     #--------------------------------------------------------------------------
  228.     def description
  229.       if Gluszak::Item_Weight::Weapons[@id] != nil
  230.         weight = 'Waga: '
  231.         unit = Gluszak::Item_Weight::Unit
  232.         weight += Gluszak::Item_Weight::Weapons[@id].to_s + unit + ', '
  233.       else
  234.         weight = ''
  235.       end
  236.       return weight + @description
  237.     end
  238.    
  239.   end
  240.  
  241.   #==============================================================================
  242.   # ** RPG::Armor
  243.   #==============================================================================
  244.   class Armor
  245.    
  246.     #--------------------------------------------------------------------------
  247.     # * Opis
  248.     #--------------------------------------------------------------------------
  249.     def description
  250.       if Gluszak::Item_Weight::Armors[@id] != nil
  251.         weight = 'Waga: '
  252.         unit = Gluszak::Item_Weight::Unit
  253.         weight += Gluszak::Item_Weight::Armors[@id].to_s + unit + ', '
  254.       else
  255.         weight = ''
  256.       end
  257.       return weight + @description
  258.     end
  259.    
  260.   end
  261.  
  262.   #==============================================================================
  263.   # ** RPG::Item
  264.   #==============================================================================
  265.   class Item
  266.    
  267.     #--------------------------------------------------------------------------
  268.     # * Opis
  269.     #--------------------------------------------------------------------------
  270.     def description
  271.       if Gluszak::Item_Weight::Items[@id] != nil
  272.         weight = 'Waga: '
  273.         unit = Gluszak::Item_Weight::Unit
  274.         weight += Gluszak::Item_Weight::Items[@id].to_s + unit + ', '
  275.       else
  276.         weight = ''
  277.       end
  278.       return weight + @description
  279.     end
  280.    
  281.   end
  282.  
  283. end
  284.  
  285. #==============================================================================
  286. # ** Game_Player
  287. #==============================================================================
  288. class Game_Player
  289.  
  290.   #--------------------------------------------------------------------------
  291.   # * Uaktualnij
  292.   #--------------------------------------------------------------------------
  293.   def update
  294.     last_moving = moving?
  295.     unless moving? or $game_system.map_interpreter.running? or
  296.            @move_route_forcing or $game_temp.message_window_showing or
  297.            $game_party.encumbrance > $game_party.max_encumbrance
  298.            # dopóki drużyna nie jest przeciążona
  299.       case Input.dir4
  300.       when 2
  301.         move_down
  302.       when 4
  303.         move_left
  304.       when 6
  305.         move_right
  306.       when 8
  307.         move_up
  308.       end
  309.     end
  310.     last_real_x = @real_x
  311.     last_real_y = @real_y
  312.     super
  313.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  314.       $game_map.scroll_down(@real_y - last_real_y)
  315.     end
  316.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  317.       $game_map.scroll_left(last_real_x - @real_x)
  318.     end
  319.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  320.       $game_map.scroll_right(@real_x - last_real_x)
  321.     end
  322.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  323.       $game_map.scroll_up(last_real_y - @real_y)
  324.     end
  325.     unless moving?
  326.       if last_moving
  327.         result = check_event_trigger_here([1,2])
  328.         if result == false
  329.           unless $DEBUG and Input.press?(Input::CTRL)
  330.             if @encounter_count > 0
  331.               @encounter_count -= 1
  332.             end
  333.           end
  334.         end
  335.       end
  336.       if Input.trigger?(Input::C)
  337.         check_event_trigger_here([0])
  338.         check_event_trigger_there([0,1,2])
  339.       end
  340.     end
  341.   end
  342.  
  343. end
Add Comment
Please, Sign In to add comment