Project1

标题: 希望帮忙修改负重脚本,负重满了仍可获得物品但无法移动 [打印本页]

作者: xyzgwx    时间: 2014-7-20 19:50
标题: 希望帮忙修改负重脚本,负重满了仍可获得物品但无法移动
这里
https://rpg.blue/thread-224133-1-1.html
的负重脚本

当最大负重满了时,无法再获得&购买物品

我希望能改成,负重满了时,仍然可以获得&购买物品,但得到后角色无法移动,除非使用或扔掉部分物品减重(扔掉物品的脚本我自己寻找)

作者: taroxd    时间: 2014-7-20 19:54
思路是修改 Game_Party#gain_item
并且在移动的时候进行判断即可。

具体实现交给楼下大触们。
作者: VIPArcher    时间: 2014-7-21 06:27
本帖最后由 VIPArcher 于 2014-7-21 07:23 编辑
  1. class RPG::BaseItem
  2.   def load
  3.     return if self.is_a?(RPG::Skill)
  4.     self.note.split(/[\r\n]+/).each { |line|
  5.       if line =~ /\[(?:load|负重|負重) (\w+)\]/
  6.         return $1.nil? ? 0 : $1.to_i
  7.       end}
  8.     return 0
  9.   end
  10. end

  11. class Scene_Item < Scene_ItemBase
  12.   alias load_start start
  13.   alias load_terminate terminate
  14.   alias load_update update
  15.   def start
  16.     load_start
  17.     @load_window = Window_Base.new(392, 0, 152, 56)
  18.     @load_window.viewport = @viewport
  19.   end
  20.   def terminate
  21.     @load_window.dispose
  22.     load_terminate
  23.   end
  24.   def update
  25.     @load_window.update
  26.     if @temp_load != $game_party.current_load
  27.       @load_window.contents.clear
  28.       @load_window.contents.draw_text(0, 0, 120, 24, "负重:#{$game_party.current_load}/#{$game_party.total_load}")
  29.       @temp_load = $game_party.current_load
  30.     end
  31.     if Input.trigger?(Input::X)
  32.       @item = @item_window.item
  33.       $game_party.lose_item(@item, 1)
  34.       @item_window.refresh
  35.     end
  36.     load_update
  37.   end
  38. end

  39. class Scene_Shop < Scene_MenuBase
  40.   alias load_start start
  41.   alias load_terminate terminate
  42.   alias load_update update
  43.   def start
  44.     load_start
  45.     @load_window = Window_Base.new(392, 0, 152, 56)
  46.     @load_window.viewport = @viewport
  47.   end
  48.   def terminate
  49.     @load_window.dispose
  50.     load_terminate
  51.   end
  52.   def update
  53.     @load_window.update
  54.     if @temp_load != $game_party.current_load
  55.       @load_window.contents.clear
  56.       @load_window.contents.draw_text(0, 0, 120, 24, "负重:#{$game_party.current_load}/#{$game_party.total_load}")
  57.       @temp_load = $game_party.current_load
  58.     end
  59.     load_update
  60.   end
  61. end

  62. class Game_Party < Game_Unit
  63.   attr_reader :current_load
  64.   alias load_initialize initialize
  65.   alias load_gain_item gain_item
  66.   def initialize
  67.     load_initialize
  68.     @current_load = 0
  69.   end
  70.   # 获取队伍最大负重
  71.   def total_load
  72.     party_load = 0
  73.     #members.size.times do |i|
  74.     for i in 0...members.size
  75.       actor = members[i]
  76.       party_load += actor.load
  77.     end
  78.     return party_load
  79.    
  80.   end

  81.   def gain_item(item, n, include_equip = false)
  82.     return if item.nil?
  83.       load_gain_item(item, n, include_equip)
  84.       @current_load += item.load * n
  85.   end
  86. end
  87. class Game_Actor < Game_Battler
  88.   # 获取队员负重
  89.   def load
  90.     return (mhp + mmp) * @level / agi
  91.   end
  92. end
  93. class Game_Interpreter
  94.   alias load_command_126 command_126
  95.   alias load_command_127 command_127
  96.   alias load_command_128 command_128
  97.   
  98.   def show_gain_window2
  99.     viparcher = Window_Base.new((640-300)/2,128 + 16,200,100 - 16)
  100.     viparcher.contents.draw_text(0, 20, 160, 30, "负重已满,无法移动", 2)
  101.   end
  102.   def command_126
  103.     n = operate_value(@params[1], @params[2], @params[3])
  104.     return command_115 if check_load(@params[0], 0, n)
  105.     load_command_126
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● 增減武器
  109.   #--------------------------------------------------------------------------
  110.   def command_127
  111.     n = operate_value(@params[1], @params[2], @params[3])
  112.     return command_115 if check_load(@params[0], 1, n)
  113.     load_command_127
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # ● 增減防具
  117.   #--------------------------------------------------------------------------
  118.   def command_128
  119.     n = operate_value(@params[1], @params[2], @params[3])
  120.     return command_115 if check_load(@params[0], 2, n)
  121.     load_command_128
  122.   end
  123.   
  124.   def check_load(item_id, type, n)
  125.     case type
  126.     when 0; item = $data_items[item_id]
  127.     when 1; item = $data_weapons[item_id]
  128.     when 2; item = $data_armors[item_id]
  129.     end
  130.     if (((item.load * n) + $game_party.current_load) > $game_party.total_load)
  131.       show_gain_window2
  132.     end
  133.     return
  134.   end
  135. end

  136. class Game_Player < Game_Character
  137.   
  138.   alias vipmovable? movable?
  139.   #--------------------------------------------------------------------------
  140.   # ● 判定是否负重已满
  141.   #--------------------------------------------------------------------------
  142.   def mfz_vip?
  143.     $game_party.total_load < $game_party.current_load
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 判定是否可以移动
  147.   #--------------------------------------------------------------------------
  148.   def movable?
  149.     return false if mfz_vip?
  150.     vipmovable?
  151.   end
  152. end
复制代码
稍微测试了一下,似乎没什么问题,自己去详细测试吧。
修改了提示窗口




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1