设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3079|回复: 0
打印 上一主题 下一主题

[转载] 改过的简单物品分类脚本

[复制链接]

Lv2.观梦者

梦石
0
星屑
635
在线时间
244 小时
注册时间
2010-9-9
帖子
472
跳转到指定楼层
1
发表于 2010-10-21 22:53:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 EngShun 于 2010-11-5 17:13 编辑

我看过两种版本的简单物品分类,
一个是通过‘可能使用的时候’分类的,
一个是通过‘分散度’分类的,
但分散度会影响物品的效果,
所以我改了一下这个脚本,
是通过属性分类的。
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================

  4. module RPG
  5.   # 物品分类
  6.   class Item
  7.     def name
  8.       name = @name.split(/,/)[0]
  9.       return name != nil ? name : ""
  10.     end
  11.     def occasion
  12.       occasion = @name.split(/,/)[1]
  13.       return occasion != nil ? 4 : @occasion
  14.     end
  15.   end
  16. end
  17. #==============================================================================
  18. # ■ Harts_Window_ItemTitle
  19. #------------------------------------------------------------------------------
  20. #  アイテム画面で、タイトルを表示するウィンドウ。
  21. #==============================================================================

  22. class Harts_Window_ItemTitle < Window_Base
  23.   #--------------------------------------------------------------------------
  24.   # ● オブジェクト初期化
  25.   #--------------------------------------------------------------------------
  26.   def initialize
  27.     super(10, 10, 150, 59)
  28.     self.contents = Bitmap.new(width - 32, height - 32)
  29.     self.contents.clear
  30.     self.contents.font.color = normal_color
  31.     self.contents.draw_text(0, 0, 100, 32, $data_system.words.item, 1)
  32.   end
  33. end

  34. #==============================================================================
  35. # ■ Harts_Window_ItemCommand
  36. #------------------------------------------------------------------------------
  37. #  アイテムの種別選択を行うウィンドウです。
  38. #==============================================================================

  39. class Harts_Window_ItemCommand < Window_Selectable
  40.   #--------------------------------------------------------------------------
  41.   # ● オブジェクト初期化
  42.   #--------------------------------------------------------------------------
  43.   def initialize
  44.     super(10, 79, 150, 321)
  45.     self.contents = Bitmap.new(width - 32, height - 32)
  46.     @item_max = 9
  47.     @commands = ["全部","医药", "能力", "战斗", "秘籍", "证书", "武器", "防具", "特殊"]
  48.     refresh
  49.     self.index = 0
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● リフレッシュ
  53.   #--------------------------------------------------------------------------
  54.   def refresh
  55.     self.contents.clear
  56.     for i in 0...@item_max
  57.     draw_item(i, normal_color)
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 項目の描画
  62.   # index : 項目番号
  63.   # color : 文字色
  64.   #--------------------------------------------------------------------------
  65.   def draw_item(index, color)
  66.     self.contents.font.color = color
  67.     y = index * 32
  68.     self.contents.draw_text(4, y, 128, 32, @commands[index])
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● ヘルプテキスト更新
  72.   #--------------------------------------------------------------------------
  73.   def update_help
  74.     case self.index
  75.     when 0
  76.       @text = "所有拥有的物品。"
  77.     when 1
  78.       @text = "药用物品。"
  79.     when 2
  80.       @text = "改变能力值的物品。"
  81.     when 3
  82.       @text = "战斗用的物品。"
  83.     when 4
  84.       @text = "一些什么武林秘籍,还是什么某某物的使用技巧。"
  85.     when 5
  86.       @text = "一些看似有用,却没有用的证书。"
  87.     when 6
  88.       @text = "一些武器"
  89.     when 7
  90.       @text = "一些防具"
  91.     when 8
  92.       @text = "可能是一些剧情物品,也可能是一些摆美物。"
  93.     end
  94.     @help_window.set_text(@text)
  95.   end
  96. end

  97. #==============================================================================
  98. # ■ Window_Item
  99. #------------------------------------------------------------------------------
  100. #  アイテム画面で、所持アイテムの一覧を表示するウィンドウです。
  101. #==============================================================================

  102. class Harts_Window_ItemList < Window_Selectable
  103.   #--------------------------------------------------------------------------
  104.   # ● オブジェクト初期化
  105.   #--------------------------------------------------------------------------
  106.   def initialize
  107.     super(170, 10, 460, 390)
  108.     refresh
  109.     self.index = 0
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● アイテムの取得
  113.   #--------------------------------------------------------------------------
  114.   def item
  115.     return @data[self.index]
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # ● リフレッシュ
  119.   #--------------------------------------------------------------------------
  120.   def refresh
  121.     if self.contents != nil
  122.       self.contents.dispose
  123.       self.contents = nil
  124.     end
  125.     @data = []
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● アイテム一覧設定
  129.   # command : 選択中のコマンド
  130.   #--------------------------------------------------------------------------
  131.   def set_item(command)
  132.     refresh
  133.     case command
  134.     when 0
  135.       for i in 1...$data_items.size
  136.         if $game_party.item_number(i) > 0
  137.           @data.push($data_items[i])
  138.         end
  139.       end
  140.     when 1
  141.       for i in 1...$data_items.size
  142.         if $data_items[i].element_set.include?($data_system.elements.index("医药")) and $game_party.item_number(i) > 0
  143.           @data.push($data_items[i])
  144.         end
  145.       end
  146.     when 2
  147.       for i in 1...$data_items.size
  148.         if ($data_items[i].element_set.include?($data_system.elements.index("能力")) and $game_party.item_number(i) > 0)
  149.           @data.push($data_items[i])
  150.         end
  151.       end
  152.     when 3
  153.       for i in 1...$data_items.size
  154.         if ($data_items[i].element_set.include?($data_system.elements.index("战斗")) and $game_party.item_number(i) > 0)
  155.           @data.push($data_items[i])
  156.         end
  157.       end
  158.     when 4
  159.       for i in 1...$data_items.size
  160.         if ($data_items[i].element_set.include?($data_system.elements.index("秘籍")) and $game_party.item_number(i) > 0)
  161.           @data.push($data_items[i])
  162.         end
  163.       end
  164.     when 5
  165.       for i in 1...$data_items.size
  166.         if ($data_items[i].element_set.include?($data_system.elements.index("证书")) and $game_party.item_number(i) > 0)
  167.           @data.push($data_items[i])
  168.         end
  169.       end
  170.     when 6
  171.       for i in 1...$data_weapons.size
  172.         if $game_party.weapon_number(i) > 0
  173.           @data.push($data_weapons[i])
  174.         end
  175.       end
  176.     when 7
  177.       for i in 1...$data_armors.size
  178.         if $game_party.armor_number(i) > 0
  179.           @data.push($data_armors[i])
  180.         end
  181.       end
  182.     when 8
  183.       for i in 1...$data_items.size
  184.         if ($data_items[i].element_set.include?($data_system.elements.index("特殊")) and $game_party.item_number(i) > 0)
  185.           @data.push($data_items[i])
  186.         end
  187.       end
  188.     end
  189.     # 項目数が 0 でなければビットマップを作成し、全項目を描画
  190.     @item_max = @data.size
  191.     if @item_max > 0
  192.       self.contents = Bitmap.new(width - 32, row_max * 32)
  193.       self.contents.clear
  194.       for i in 0...@item_max
  195.         draw_item(i)
  196.       end
  197.     end
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # ● 種類別アイテム数の取得
  201.   #--------------------------------------------------------------------------
  202.   def item_number
  203.     return @item_max
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 項目の描画
  207.   # index : 項目番号
  208.   #--------------------------------------------------------------------------
  209.   def draw_item(index)
  210.     item = @data[index]
  211.     case item
  212.     when RPG::Item
  213.       number = $game_party.item_number(item.id)
  214.     when RPG::Weapon
  215.       number = $game_party.weapon_number(item.id)
  216.     when RPG::Armor
  217.       number = $game_party.armor_number(item.id)
  218.     end
  219.     if item.is_a?(RPG::Item) and
  220.       $game_party.item_can_use?(item.id)
  221.       self.contents.font.color = normal_color
  222.     else
  223.       self.contents.font.color = disabled_color
  224.     end
  225.     x = 4
  226.     y = index * 32
  227.     bitmap = RPG::Cache.icon(item.icon_name)
  228.     opacity = self.contents.font.color == normal_color ? 255 : 128
  229.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  230.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  231.     self.contents.draw_text(x + 350, y, 16, 32, ":", 1)
  232.     self.contents.draw_text(x + 366, y, 24, 32, number.to_s, 2)
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● ヘルプテキスト更新
  236.   #--------------------------------------------------------------------------
  237.   def update_help
  238.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  239.   end
  240. end

  241. #==============================================================================
  242. # ■ Harts_Scene_Item
  243. #------------------------------------------------------------------------------
  244. #  アイテム画面の処理を行うクラスです。再定義
  245. #==============================================================================

  246. class Scene_Item
  247.   #--------------------------------------------------------------------------
  248.   # ● メイン処理
  249.   #--------------------------------------------------------------------------
  250.   def main
  251.     @spriteset = Spriteset_Map.new
  252.     # タイトルウィンドウを作成
  253.     @itemtitle_window = Harts_Window_ItemTitle.new
  254.     #コマンドウィンドウを作成
  255.     @itemcommand_window = Harts_Window_ItemCommand.new
  256.     @command_index = @itemcommand_window.index
  257.     #アイテムウィンドウを作成
  258.     @itemlist_window = Harts_Window_ItemList.new
  259.     @itemlist_window.active = false
  260.     #ヘルプウィンドウを作成
  261.     @help_window = Window_Help.new
  262.     @help_window.x = 0
  263.     @help_window.y = 410
  264.     # ヘルプウィンドウを関連付け
  265.     @itemcommand_window.help_window = @help_window
  266.     @itemlist_window.help_window = @help_window
  267.     # ターゲットウィンドウを作成 (不可視?非アクティブに設定)
  268.     @target_window = Window_Target.new
  269.     @target_window.visible = false
  270.     @target_window.active = false
  271.     # アイテムウィンドウ内容表示
  272.     @itemlist_window.set_item(@command_index)
  273.     # トランジション実行
  274.     Graphics.transition
  275.     # メインループ
  276.     loop do
  277.       # ゲーム画面を更新
  278.       Graphics.update
  279.       # 入力情報を更新
  280.       Input.update
  281.       # フレーム更新
  282.       update
  283.       # 画面が切り替わったらループを中断
  284.       if $scene != self
  285.         break
  286.       end
  287.     end
  288.     # トランジション準備
  289.     Graphics.freeze
  290.     # ウィンドウを解放
  291.     @spriteset.dispose
  292.     @itemtitle_window.dispose
  293.     @itemcommand_window.dispose
  294.     @itemlist_window.dispose
  295.     @help_window.dispose
  296.     @target_window.dispose
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # ● フレーム更新
  300.   #--------------------------------------------------------------------------
  301.   def update
  302.     # ウィンドウを更新
  303.     @itemtitle_window.update
  304.     @itemcommand_window.update
  305.     @itemlist_window.update
  306.     @help_window.update
  307.     @target_window.update
  308.     if @command_index != @itemcommand_window.index
  309.       @command_index = @itemcommand_window.index
  310.       @itemlist_window.set_item(@command_index)
  311.     end
  312.     # コマンドウィンドウがアクティブの場合: update_itemcommand を呼ぶ
  313.     if @itemcommand_window.active
  314.       update_itemcommand
  315.       return
  316.     end
  317.     # アイテムウィンドウがアクティブの場合: update_itemlist を呼ぶ
  318.     if @itemlist_window.active
  319.       update_itemlist
  320.       return
  321.     end
  322.     # ターゲットウィンドウがアクティブの場合: update_target を呼ぶ
  323.     if @target_window.active
  324.       update_target
  325.       return
  326.     end
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # ● フレーム更新 (コマンドウィンドウがアクティブの場合)
  330.   #--------------------------------------------------------------------------
  331.   def update_itemcommand
  332.   # B ボタンが押された場合
  333.   if Input.trigger?(Input::B)
  334.   # キャンセル SE を演奏
  335.   $game_system.se_play($data_system.cancel_se)
  336.   # メニュー画面に切り替え
  337.   $scene = Scene_Menu.new(0)
  338.   return
  339.   end
  340.   # C ボタンが押された場合
  341.   if Input.trigger?(Input::C)
  342.   # 選択中のコマンドのアイテムがない場合
  343.   if @itemlist_window.item_number == 0
  344.   # ブザー SE を演奏
  345.   $game_system.se_play($data_system.buzzer_se)
  346.   return
  347.   end
  348.   # 決定 SE を演奏
  349.   $game_system.se_play($data_system.decision_se)
  350.   # アイテムウィンドウをアクティブにする
  351.   @itemcommand_window.active = false
  352.   @itemlist_window.active = true
  353.   @itemlist_window.index = 0
  354.   return
  355.   end
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # ● フレーム更新 (アイテムウィンドウがアクティブの場合)
  359.   #--------------------------------------------------------------------------
  360.   def update_itemlist
  361.     # B ボタンが押された場合
  362.     if Input.trigger?(Input::B)
  363.       # キャンセル SE を演奏
  364.       $game_system.se_play($data_system.cancel_se)
  365.       # アイテムウィンドウをアクティブにする
  366.       @itemcommand_window.active = true
  367.       @itemlist_window.active = false
  368.       @itemlist_window.index = 0
  369.       @itemcommand_window.index = @command_index
  370.       return
  371.     end
  372.     # C ボタンが押された場合
  373.     if Input.trigger?(Input::C)
  374.       # アイテムウィンドウで現在選択されているデータを取得
  375.       @item = @itemlist_window.item
  376.       # 使用アイテムではない場合
  377.       unless @item.is_a?(RPG::Item)
  378.         # ブザー SE を演奏
  379.         $game_system.se_play($data_system.buzzer_se)
  380.         return
  381.       end
  382.       # 使用できない場合
  383.       unless $game_party.item_can_use?(@item.id)
  384.         # ブザー SE を演奏
  385.         $game_system.se_play($data_system.buzzer_se)
  386.         return
  387.       end
  388.       # 決定 SE を演奏
  389.       $game_system.se_play($data_system.decision_se)
  390.       # 効果範囲が味方の場合
  391.       if @item.scope >= 3
  392.         # ターゲットウィンドウをアクティブ化
  393.         @itemlist_window.active = false
  394.         @target_window.x = 304
  395.         @target_window.visible = true
  396.         @target_window.active = true
  397.         # 効果範囲 (単体/全体) に応じてカーソル位置を設定
  398.         if @item.scope == 4 || @item.scope == 6
  399.           @target_window.index = -1
  400.         else
  401.           @target_window.index = 0
  402.         end
  403.         # 効果範囲が味方以外の場合
  404.       else
  405.         # コモンイベント ID が有効の場合
  406.         if @item.common_event_id > 0
  407.           # コモンイベント呼び出し予約
  408.           $game_temp.common_event_id = @item.common_event_id
  409.           # アイテムの使用時 SE を演奏
  410.           $game_system.se_play(@item.menu_se)
  411.           # 消耗品の場合
  412.             if @item.consumable
  413.               # 使用したアイテムを 1 減らす
  414.               $game_party.lose_item(@item.id, 1)
  415.               # アイテムウィンドウの項目を再描画
  416.               @itemlist_window.draw_item(@itemlist_window.index)
  417.             end
  418.           # マップ画面に切り替え
  419.           $scene = Scene_Map.new
  420.           return
  421.         end
  422.       end
  423.       return
  424.     end
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # ● フレーム更新 (ターゲットウィンドウがアクティブの場合)
  428.   #--------------------------------------------------------------------------
  429.   def update_target
  430.     # B ボタンが押された場合
  431.     if Input.trigger?(Input::B)
  432.       # キャンセル SE を演奏
  433.       $game_system.se_play($data_system.cancel_se)
  434.       # アイテム切れなどで使用できなくなった場合
  435.       unless $game_party.item_can_use?(@item.id)
  436.         # アイテムウィンドウの内容を再作成
  437.         @itemlist_window.refresh
  438.       end
  439.       # ターゲットウィンドウを消去
  440.       @itemlist_window.active = true
  441.       @target_window.visible = false
  442.       @target_window.active = false
  443.       @itemlist_window.set_item(@command_index)
  444.       return
  445.     end
  446.     # C ボタンが押された場合
  447.     if Input.trigger?(Input::C)
  448.       # アイテムを使い切った場合
  449.       if $game_party.item_number(@item.id) == 0
  450.         # ブザー SE を演奏
  451.         $game_system.se_play($data_system.buzzer_se)
  452.         return
  453.       end
  454.       # ターゲットが全体の場合
  455.       if @target_window.index == -1
  456.         # パーティ全体にアイテムの使用効果を適用
  457.         used = false
  458.         for i in $game_party.actors
  459.           used |= i.item_effect(@item)
  460.         end
  461.       end
  462.       # ターゲットが単体の場合
  463.       if @target_window.index >= 0
  464.         # ターゲットのアクターにアイテムの使用効果を適用
  465.         target = $game_party.actors[@target_window.index]
  466.         used = target.item_effect(@item)
  467.       end
  468.       # アイテムを使った場合
  469.       if used
  470.         # アイテムの使用時 SE を演奏
  471.         $game_system.se_play(@item.menu_se)
  472.         # 消耗品の場合
  473.         if @item.consumable
  474.           # 使用したアイテムを 1 減らす
  475.           $game_party.lose_item(@item.id, 1)
  476.           # アイテムウィンドウの項目を再描画
  477.           @itemlist_window.draw_item(@itemlist_window.index)
  478.           @itemlist_window.set_item(@command_index)
  479.         end
  480.         # ターゲットウィンドウの内容を再作成
  481.         @target_window.refresh
  482.         # 全滅の場合
  483.         if $game_party.all_dead?
  484.           # ゲームオーバー画面に切り替え
  485.           $scene = Scene_Gameover.new
  486.           return
  487.         end
  488.         # コモンイベント ID が有効の場合
  489.         if @item.common_event_id > 0
  490.           # コモンイベント呼び出し予約
  491.           $game_temp.common_event_id = @item.common_event_id
  492.           # マップ画面に切り替え
  493.           $scene = Scene_Map.new
  494.           return
  495.         end
  496.       end
  497.       # アイテムを使わなかった場合
  498.       unless used
  499.         # ブザー SE を演奏
  500.         $game_system.se_play($data_system.buzzer_se)
  501.       end
  502.     return
  503.     end
  504.   end
  505. end


  506. #==============================================================================
  507. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  508. #==============================================================================
复制代码
注意:与半透明菜单有冲突
解决方法:将此脚本内的@spriteset = Spriteset_Map.new和@spriteset.dispose

这是原网站

由于不知要将此贴放什么分类,
所以放了转载。

评分

参与人数 1星屑 +100 收起 理由
无双sxa + 100 很实用啊。

查看全部评分

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-29 05:56

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表