查看: 1458|回复: 0

[VIPArcher] 【队伍负重】图书馆脚本改进版

[复制链接]

无限の剣制

梦石
0
星屑
10460
在线时间
5019 小时
注册时间
2013-2-28
回帖
4942

开拓者贵宾

发表于 2014-9-18 12:27:08 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 VIPArcher 于 2014-12-10 11:52 编辑

技术区原帖
  1. #==============================================================================
  2. # +++ VX移植 - VA负重系统改进版 +++
  3. #==============================================================================
  4. # VX版 原作者 By 雪流星
  5. # 蓝本 杂兵天下的VA移植版
  6. # 改进 By:VIPArcher
  7. #  -- 本脚本来自 https://rpg.blue 使用或转载请保留以上信息。
  8. #
  9. #==============================================================================
  10. # 就是在物品画面的右上角放了一个显示负重的窗口
  11. # 更新了代码,取消的原来的计算每个队员的负重然后累加的模式 2014-12-10
  12. # 增加了商店界面的负重显示     2014-9-3
  13. #==============================================================================
  14. #
  15. # 物品备注<load N> 则该物品占用 N 点负重
  16. # load也可以写成「负重」或「負重」#注:没有“「」”
  17. # 不写的话默认为 Default_Load
  18. # 更改当前负重 current_load(x[,assign])
  19. # 其中 x 为数值可以为负数,assign 为 true 时当前负重直接赋值为x(可省略)
  20. # 例如:current_load(10,true) 当前负重直接赋值为10
  21. # 默认给物品增加一行说明.说明内容是物品的重量.
  22. # 但默认帮助窗口一共只能显示2行内容.
  23. # 因此你在数据库设置武器、护甲说明的时候.
  24. # 如果设置了2行内容.那么这新增加的第3行将无法显示出来.
  25. #
  26. #==============================================================================
  27. $VIPArcherScript ||= {};$VIPArcherScript[:load] = 20140919
  28. #==============================================================================
  29. # ★ 设定部分 ★
  30. #==============================================================================
  31. module  VIPArcher;end
  32. module  VIPArcher::Load
  33.   Default_Load = 1    #物品的默认负重
  34.   Width = 150         #负重信息窗口宽度
  35.   Load_Name = "负重:" #负重前显示的文字
  36.   Load_Var = 1        #作为队伍负重上限的变量ID
  37.   # 事件中调用增减道具/武器/防具时,如果会导致超过负重上限,是否执行中断事件处理
  38.   # 推荐不使用,因为新加的功能就有一个是当超过负重时限制角色移动,开启这个
  39.   # 的话这个限制移动就无效了的说·3·
  40.   Stop_SW = false       #true 使用 / false 不使用
  41.   
  42.   # 满负重时降低移动速度(不使用时禁止移动连事件都无法启动,只能丢弃/使用物品)
  43.   Movable =  true       #true 使用 / false 不使用
  44.   
  45.   # 满负重时的移动速度
  46.   Move_Speed = 2
  47.   
  48.   # 负重超过上限时的提示内容
  49.   Message = "\\i[4]负重超过可承受的范围,\n移动将变得\\c[10]十分艰难!\\c[0]
  50. 丢些没用的东西掉吧。"

  51.   # 按X键(A键)是否可以丢弃道具
  52.   # 如果你另外使用了丢弃道具的脚本请关闭
  53.   Lose_SW = true       #true 使用 / false 不使用
  54.   
  55.   # 是否在帮助窗口内自动添加负重信息
  56.   Help_SW = true       #true 使用 / false 不使用
  57.   
  58.   # 装备在身上的装备是否算入负重
  59.   Equip_SW = true      #true 计算 / false 不计算
  60.   #         "★★★★★★ 注意 ★★★★★★"
  61.   # 如果你的角色初始装备有占负重并且开启上面的功能,那么你必须
  62.   # 在游戏一开始时为当前负重赋值(自己算到底有多少负重·3·)
  63.   # 当有新队员加入队伍并且也带有负重的装备那么你也需要为当前负重加上对应的重量,
  64.   # 例如:事件脚本运行 current_load(10) 就是加上10的当前负重
  65. end
  66. #-------------------------------------------------------------------------------
  67. class RPG::BaseItem
  68.   include VIPArcher::Load
  69.   #--------------------------------------------------------------------------
  70.   # ● 获取道具的重量
  71.   #--------------------------------------------------------------------------
  72.   def load
  73.     return if self.is_a?(RPG::Skill)
  74.     return $1.to_i if @note =~ /<(?:load|负重|負重)\s*(\d+)>/
  75.     return Default_Load
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 新增负重帮助内容
  79.   #--------------------------------------------------------------------------
  80.   def description
  81.     if Help_SW && !self.is_a?(RPG::Skill)
  82.       return @description + "\n\\}"  + "重量:#{load}"
  83.     else
  84.       return @description
  85.     end
  86.   end unless $VIPArcherScript[:help_ex]
  87. end
  88. #==============================================================================
  89. #  显示当前负重信息的窗口
  90. #==============================================================================
  91. class Window_Load < Window_Base
  92.   include VIPArcher::Load
  93.   #--------------------------------------------------------------------------
  94.   # ● 初始化对象
  95.   #--------------------------------------------------------------------------
  96.   def initialize
  97.     super(Graphics.width - window_width, 72, window_width, fitting_height(1))
  98.     refresh
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● 获取窗口的宽度
  102.   #--------------------------------------------------------------------------
  103.   def window_width
  104.     Width
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● 刷新
  108.   #--------------------------------------------------------------------------
  109.   def refresh
  110.     contents.clear
  111.     contents.font.size - 4
  112.     draw_text(0, 0, window_width - 64, 24,load_name,0)
  113.     draw_text(0, 0, window_width - 24, 24, weight,2)
  114.     @temp_load = $game_party.current_load
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● 获取当前负重信息
  118.   #--------------------------------------------------------------------------
  119.   def weight
  120.     "#{$game_party.current_load}/#{$game_party.total_load}"
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # ● 获取负重前显示文字
  124.   #--------------------------------------------------------------------------
  125.   def load_name
  126.     Load_Name
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 更新画面
  130.   #--------------------------------------------------------------------------
  131.   def update
  132.     super
  133.     refresh if @temp_load != $game_party.current_load
  134.   end
  135. end
  136. #-------------------------------------------------------------------------------
  137. class Window_ItemCategory < Window_HorzCommand
  138.   include VIPArcher::Load
  139.   #--------------------------------------------------------------------------
  140.   # ● 获取窗口的宽度
  141.   #--------------------------------------------------------------------------
  142.   def window_width
  143.     scene_item_is? ? Graphics.width - Width : Graphics.width
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 获取列数
  147.   #--------------------------------------------------------------------------
  148.   def col_max
  149.     return scene_item_is? ? 3 : 4
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # ● 判断是否为物品栏场景
  153.   #--------------------------------------------------------------------------
  154.   def scene_item_is?
  155.     return SceneManager.scene_is?(Scene_Item)
  156.   end
  157. end
  158. #==============================================================================
  159. # ■ 物品界面显示负重栏
  160. #==============================================================================
  161. class Scene_Item < Scene_ItemBase
  162.   include VIPArcher::Load
  163.   #--------------------------------------------------------------------------
  164.   # ● 开始处理
  165.   #--------------------------------------------------------------------------
  166.   alias load_start start
  167.   def start
  168.     load_start
  169.     @load_window = Window_Load.new
  170.     @load_window.viewport = @viewport
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # ● 结束处理
  174.   #--------------------------------------------------------------------------
  175.   alias load_terminate terminate
  176.   def terminate
  177.     load_terminate
  178.     @load_window.dispose
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # ● 更新画面
  182.   #--------------------------------------------------------------------------
  183.   alias load_update update
  184.   def update
  185.     #--------------------------------------------------------------------------
  186.     # ★ 按X键(A键)丢弃道具 - 贵重物品无法丢弃 ★修改:VIPArcher
  187.     #--------------------------------------------------------------------------
  188.     if Input.trigger?(Input::X) && Lose_SW
  189.       item = @item_window.item
  190.       if item.is_a?(RPG::Item) && item.key_item?
  191.         Sound.play_buzzer
  192.       else
  193.         Sound.play_cancel
  194.         $game_party.lose_item(item, 1)
  195.         @item_window.refresh
  196.       end unless item == nil
  197.     end
  198.     @load_window.update
  199.     load_update
  200.   end
  201. end
  202. #-------------------------------------------------------------------------------
  203. class Window_ShopNumber < Window_Selectable
  204.   include VIPArcher::Load
  205.   attr_accessor :buy_or_sell                    #买入的标志
  206.   #--------------------------------------------------------------------------
  207.   # ● 刷新
  208.   #--------------------------------------------------------------------------
  209.   alias vip_shopnumber_refresh refresh
  210.   def refresh
  211.     vip_shopnumber_refresh
  212.     draw_current_weight(@item)
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ○ 买卖时重量变化的描绘
  216.   #--------------------------------------------------------------------------
  217.   def draw_current_weight(item)
  218.     current = $game_party.current_load
  219.     weight = current + item.load * @number * (@buy_or_sell ? 1 : -1)
  220.     width = contents_width - 8
  221.     cx = text_size(@currency_unit).width
  222.     change_color(system_color)
  223.     draw_text(4, y + 60, width, line_height, "#{Load_Name}")
  224.     change_color(normal_color)
  225.     wt = "#{weight} / #{$game_party.total_load}"
  226.     draw_text(4, y + 60, width, line_height, wt, 2)
  227.   end
  228. end
  229. #-------------------------------------------------------------------------------
  230. class Window_ShopStatus < Window_Base
  231.   include VIPArcher::Load
  232.   #--------------------------------------------------------------------------
  233.   # ● 刷新
  234.   #--------------------------------------------------------------------------
  235.   alias vip_shopstatus_refresh refresh
  236.   def refresh
  237.     vip_shopstatus_refresh
  238.     draw_weight_occupy(4, 24)
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ● 绘制持负重信息
  242.   #--------------------------------------------------------------------------
  243.   def draw_weight_occupy(x, y)
  244.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  245.     change_color(system_color)
  246.     draw_text(rect, "#{Load_Name}", 3)
  247.     change_color(normal_color)
  248.     weight = "#{$game_party.current_load}/#{$game_party.total_load}"
  249.     draw_text(rect, weight, 2)
  250.     @temp_load = $game_party.current_load
  251.   end
  252. end
  253. #==============================================================================
  254. # ■ 获取队伍最大负重
  255. #==============================================================================
  256. class Game_Party < Game_Unit
  257.   include VIPArcher::Load
  258.   #--------------------------------------------------------------------------
  259.   # ● 定义实例变量
  260.   #--------------------------------------------------------------------------
  261.   attr_accessor :current_load, :load_trade_item        #负重
  262.   #--------------------------------------------------------------------------
  263.   # ● 初始化对象
  264.   #--------------------------------------------------------------------------
  265.   alias load_initialize initialize
  266.   def initialize
  267.     load_initialize
  268.     total_load
  269.     @current_load = 0
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # ● 获取队伍最大负重
  273.   #--------------------------------------------------------------------------
  274.   def total_load
  275.     $game_variables[Load_Var]
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # ● 判断负重是否已满
  279.   #--------------------------------------------------------------------------
  280.   def load_max?
  281.     @current_load >= total_load
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # ● 增加/减少物品时计算负重
  285.   #--------------------------------------------------------------------------
  286.   alias load_gain_item gain_item
  287.   def gain_item(item, n, include_equip = false)
  288.     return if item.nil?
  289.     load_gain_item(item, n, include_equip)
  290.     @current_load += item.load * n if !@load_trade_item
  291.   end
  292. end
  293. #-------------------------------------------------------------------------------
  294. class Game_Actor < Game_Battler
  295.   include VIPArcher::Load
  296.   #--------------------------------------------------------------------------
  297.   # ● 装备时不计算负重的增减 * 方法覆盖
  298.   #     new_item : 取出的物品
  299.   #     old_item : 放入的物品
  300.   #--------------------------------------------------------------------------
  301.   def trade_item_with_party(new_item, old_item)
  302.     return false if new_item && !$game_party.has_item?(new_item)
  303.     $game_party.load_trade_item = true if Equip_SW == true
  304.     $game_party.gain_item(old_item, 1)
  305.     $game_party.lose_item(new_item, 1)
  306.     $game_party.load_trade_item = false if Equip_SW == true
  307.     return true
  308.   end
  309. end
  310. #==============================================================================
  311. # ■ 增减物品时判断负重
  312. #==============================================================================
  313. class Game_Interpreter
  314.   include VIPArcher::Load
  315.   #--------------------------------------------------------------------------
  316.   # ● 增减道具
  317.   #--------------------------------------------------------------------------
  318.   alias load_command_126 command_126
  319.   def command_126
  320.     n = operate_value(@params[1], @params[2], @params[3])
  321.     return command_115 if check_load(@params[0], 0, n) && Stop_SW
  322.     load_command_126
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # ● 增減武器
  326.   #--------------------------------------------------------------------------
  327.   alias load_command_127 command_127
  328.   def command_127
  329.     n = operate_value(@params[1], @params[2], @params[3])
  330.     return command_115 if check_load(@params[0], 1, n) &&  Stop_SW
  331.     load_command_127
  332.   end
  333.   #--------------------------------------------------------------------------
  334.   # ● 增減防具
  335.   #--------------------------------------------------------------------------
  336.   alias load_command_128 command_128
  337.   def command_128
  338.     n = operate_value(@params[1], @params[2], @params[3])
  339.     return command_115 if check_load(@params[0], 2, n) && Stop_SW
  340.     load_command_128
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # ● 增减物品超重时提示
  344.   #--------------------------------------------------------------------------
  345.   def check_load(item_id, type, n)
  346.     case type
  347.     when 0; item = $data_items[item_id]
  348.     when 1; item = $data_weapons[item_id]
  349.     when 2; item = $data_armors[item_id]
  350.     end
  351.     if (((item.load * n) + $game_party.current_load) > $game_party.total_load)
  352.       $game_message.texts.push("#{Message}") if $game_message.visible != true
  353.       $game_message.visible = true
  354.     end
  355.     return (((item.load * n) + $game_party.current_load) > $game_party.total_load)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # ● 更改负重
  359.   #--------------------------------------------------------------------------
  360.   def current_load(current_load,assign = false)
  361.     if assign
  362.       $game_party.current_load = current_load
  363.     else
  364.       $game_party.current_load += current_load
  365.     end
  366.   end
  367. end
  368. #==============================================================================
  369. # ★ 满负重时限制行动 ★
  370. #==============================================================================
  371. class Game_Player < Game_Character
  372.   include VIPArcher::Load
  373.   #--------------------------------------------------------------------------
  374.   # ● 判定是否可以移动
  375.   #--------------------------------------------------------------------------
  376.   alias load_movable? movable?
  377.   def movable?
  378.     return false if $game_party.load_max? && !Movable
  379.     load_movable?
  380.   end
  381. end
  382. #==============================================================================
  383. # ★ 满负重时降低移动速度 ★
  384. #==============================================================================
  385. class Game_CharacterBase
  386.   include VIPArcher::Load
  387.   #--------------------------------------------------------------------------
  388.   # ● 获取移动速度(判断是否跑步)
  389.   #--------------------------------------------------------------------------
  390.   alias load_real_move_speed real_move_speed
  391.   def real_move_speed
  392.     return Move_Speed if $game_party.load_max? && Movable
  393.     load_real_move_speed
  394.   end
  395. end
  396. #==============================================================================
  397. # ★ 满负重时限制购买 ★
  398. #==============================================================================
  399. class Window_ShopBuy < Window_Selectable
  400.   #--------------------------------------------------------------------------
  401.   # ● 查询商品是否可买
  402.   #--------------------------------------------------------------------------
  403.   alias load_enable? enable?
  404.   def enable?(item)
  405.     load_enable?(item) && !$game_party.load_max?
  406.   end
  407. end
  408. #==============================================================================
  409. # ★ 根据负重设定可购买的物品数量 ★
  410. #==============================================================================
  411. class Scene_Shop < Scene_MenuBase
  412.   #--------------------------------------------------------------------------
  413.   # ● 指令“买入”
  414.   #--------------------------------------------------------------------------
  415.   alias vip_load_command_buy command_buy
  416.   def command_buy
  417.     vip_load_command_buy
  418.     @number_window.buy_or_sell = true
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # ● 指令“卖出”
  422.   #--------------------------------------------------------------------------
  423.   alias vip_load_command_sell command_sell
  424.   def command_sell
  425.     vip_load_command_sell
  426.     @number_window.buy_or_sell = false
  427.   end
  428.   #--------------------------------------------------------------------------
  429.   # ● 获取可以买入的最大值
  430.   #--------------------------------------------------------------------------
  431.   alias load_max_buy max_buy
  432.   def max_buy
  433.     vip = @item.load == 0 ? load_max_buy : ($game_party.total_load -
  434.     $game_party.current_load) / @item.load
  435.     [load_max_buy,vip].min
  436.   end
  437. end
复制代码
  

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本发帖返回顶部