Project1

标题: (新人)求教如何弄装备上限等级 [打印本页]

作者: 古藤游戏    时间: 2015-2-2 17:41
标题: (新人)求教如何弄装备上限等级
比如:10级才能装备布衣
作者: RyanBern    时间: 2015-2-2 20:15
顺手写了一个,未测试。
插入到Main前,此脚本可能造成脚本冲突。
用法为在需要等级限制的装备的说明处,写上%lvl[最低等级],例如,如果想让布衣的最低装备等级为10,则再布衣的说明处写%lvl[10](位置任意)
注意,当使用事件指令【变更装备】时,具有等级限制的装备仍然可以强制被装备到角色身上。
RUBY 代码复制
  1. module RPG
  2.   class Weapon
  3.     Regex_Lvl_Need = /%lvl\[(\d+)\]/
  4.     unless method_defined? :rb_description_20150202
  5.       alias rb_description_20150202 description
  6.       def description
  7.         return rb_description_20150202.gsub(Regex_Lvl_Need, "")
  8.       end
  9.     end
  10.     def level_need
  11.       Regex_Lvl_Need =~ @description
  12.       return $1.to_i
  13.     end
  14.   end
  15.   class Armor
  16.     Regex_Lvl_Need = /%lvl\[(\d+)\]/
  17.     unless method_defined? :rb_description_20150202
  18.       alias rb_description_20150202 description
  19.       def description
  20.         return rb_description_20150202.gsub(Regex_Lvl_Need, "")
  21.       end
  22.     end
  23.     def level_need
  24.       Regex_Lvl_Need =~ @description
  25.       return $1.to_i
  26.     end
  27.   end
  28. end
  29.  
  30. class Game_Actor < Game_Battler
  31.   def can_equip?(equipment)
  32.     return true if equipment.nil?
  33.     return self.level >= equipment.level_need
  34.   end
  35. end
  36.  
  37. class Window_EquipItem < Window_Selectable
  38.   def draw_item(index)
  39.     item = @data[index]
  40.     x = 4 + index % 2 * (288 + 32)
  41.     y = index / 2 * 32
  42.     case item
  43.     when RPG::Weapon
  44.       number = $game_party.weapon_number(item.id)
  45.     when RPG::Armor
  46.       number = $game_party.armor_number(item.id)
  47.     end
  48.     bitmap = RPG::Cache.icon(item.icon_name)
  49.     opacity = @actor.can_equip?(item) ? 255 : 128
  50.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  51.     self.contents.font.color = @actor.can_equip?(item) ? normal_color : disabled_color
  52.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  53.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  54.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  55.   end
  56.   def update_help
  57.     text = @actor.can_equip?(self.item) ? "" : sprintf("(角色需要达到LV%d)", self.item.level_need)
  58.     @help_window.set_text(self.item == nil ? "" : self.item.description + text)
  59.   end
  60. end
  61.  
  62. class Scene_Equip
  63.   def update_item
  64.     # 按下 B 键的情况下
  65.     if Input.trigger?(Input::B)
  66.       # 演奏取消 SE
  67.       $game_system.se_play($data_system.cancel_se)
  68.       # 激活右侧窗口
  69.       @right_window.active = true
  70.       @item_window.active = false
  71.       @item_window.index = -1
  72.       return
  73.     end
  74.     # 按下 C 键的情况下
  75.     if Input.trigger?(Input::C)
  76.       # 获取物品窗口现在选择的装备数据
  77.       item = @item_window.item
  78.       unless @actor.can_equip?(item)
  79.         $game_system.se_play($data_system.buzzer_se)
  80.         return
  81.       end
  82.       # 演奏装备 SE
  83.       $game_system.se_play($data_system.equip_se)
  84.       # 变更装备
  85.       @actor.equip(@right_window.index, item == nil ? 0 : item.id)
  86.       # 激活右侧窗口
  87.       @right_window.active = true
  88.       @item_window.active = false
  89.       @item_window.index = -1
  90.       # 再生成右侧窗口、物品窗口的内容
  91.       @right_window.refresh
  92.       @item_window.refresh
  93.       return
  94.     end
  95.   end
  96. end






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