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

Project1

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

得失物品提示

[复制链接]

…あたしは天使なんかじゃないわ

梦石
0
星屑
2208
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

跳转到指定楼层
1
发表于 2014-5-21 16:08:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 taroxd 于 2015-1-23 21:26 编辑

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2. # ● require Taroxd基础设置
  3. #    得失物品提示
  4. #--------------------------------------------------------------------------
  5.  
  6. module Taroxd::GainMessage
  7.  
  8.   # 常数设置
  9.  
  10.   # 信息格式
  11.  
  12.   # 转义符:
  13.   # \name    代表物品名称 / 金钱单位
  14.   # \value   代表获得 / 失去的物品 / 金钱数量
  15.   # \icon    绘制物品 / 金钱的图标
  16.   # \action  代表“获得”或者“失去”。可在下面修改。
  17.   # 支持“显示文字”中的所有转义符。
  18.   ITEM_FORMAT  = '\action了 \name * \value'
  19.   GOLD_FORMAT  = '\action了 \value \name'
  20.   ACTION_GAIN  = '获得'
  21.   ACTION_LOSE  = '失去'
  22.   GOLD_ICON_INDEX = 361           # 金钱图标的索引
  23.  
  24.   BACKGROUND   = 1                # 窗口背景(0/1/2)
  25.   POSITION     = 1                # 显示位置(0/1/2)
  26.  
  27.   # 音效(不需要的话可以直接删去对应的行)
  28.   GAIN_GOLD_SE = 'Shop'           # 获得金钱
  29.   LOSE_GOLD_SE = 'Blow2'          # 失去金钱
  30.   GAIN_ITEM_SE = 'Item1'          # 获得物品
  31.   LOSE_ITEM_SE = LOSE_GOLD_SE     # 失去物品
  32.  
  33.   # 设置功能是否启用。
  34.   # true:启用。
  35.   # false:不启用。
  36.   # $game_switches[开关ID]: 对应开关打开时。
  37.   def self.enabled?
  38.     true
  39.   end
  40.  
  41.   # --- 设置结束 ---
  42.  
  43.   # 显示提示信息。获得金钱时将 item 设为 nil。
  44.   def self.show(value, item)
  45.     @item = item
  46.     @value = value
  47.     $game_message.background = BACKGROUND
  48.     $game_message.position = POSITION
  49.     $game_message.add(message)
  50.     play_se
  51.   end
  52.  
  53.   private
  54.  
  55.   # 获取提示的消息
  56.   def self.message
  57.     if @item
  58.       format = ITEM_FORMAT
  59.       icon_index = @item.icon_index
  60.       name = @item.name
  61.     else
  62.       format = GOLD_FORMAT
  63.       icon_index = GOLD_ICON_INDEX
  64.       name = Vocab.currency_unit
  65.     end
  66.  
  67.     # gsub: 以替换前的字符串为键,替换后内容为值的 hash。可以自由设置。
  68.     gsub = {
  69.       '\action' => @value > 0 ? ACTION_GAIN : ACTION_LOSE,
  70.       '\value'  => @value.abs,
  71.       '\icon'   => "\\I[#{icon_index}]",
  72.       '\name'   => name
  73.     }
  74.  
  75.     format.gsub(Regexp.union(gsub.keys), gsub)
  76.   end
  77.  
  78.   def self.play_se
  79.     const = :"#{@value > 0 ? 'GAIN' : 'LOSE'}_#{@item ? 'ITEM' : 'GOLD'}_SE"
  80.     se = const_defined?(const) && const_get(const)
  81.     Audio.se_play('Audio/SE/' + se) if se
  82.   end
  83. end
  84.  
  85. class Game_Party < Game_Unit
  86.   # 获取道具总数(包括装备)
  87.   def item_number_with_equip(item)
  88.     members.inject(item_number(item)) { |a, e| a + e.equips.count(item) }
  89.   end
  90. end
  91.  
  92. class Game_Interpreter
  93.  
  94.   GainMessage = Taroxd::GainMessage
  95.  
  96.   # 显示提示窗口
  97.   def show_gain_message(value, item = nil)
  98.     return if value.zero?
  99.     GainMessage.show(value, item)
  100.     wait_for_message
  101.   end
  102.  
  103.   # 增减金钱
  104.   def_chain :command_125 do |old|
  105.     return old.call unless GainMessage.enabled?
  106.     last_gold = $game_party.gold
  107.     old.call
  108.     show_gain_message($game_party.gold - last_gold)
  109.   end
  110.  
  111.   # 增减物品
  112.   def_chain :command_126 do |old|
  113.     return old.call unless GainMessage.enabled?
  114.     item = $data_items[@params[0]]
  115.     last_num = $game_party.item_number(item)
  116.     old.call
  117.     show_gain_message($game_party.item_number(item) - last_num, item)
  118.   end
  119.  
  120.   # 增减武器
  121.   def_chain :command_127 do |old|
  122.     return old.call unless GainMessage.enabled?
  123.     item = $data_weapons[@params[0]]
  124.     last_num = $game_party.item_number_with_equip(item)
  125.     old.call
  126.     value = $game_party.item_number_with_equip(item) - last_num
  127.     show_gain_message(value, item)
  128.   end
  129.  
  130.   # 增减护甲
  131.   def_chain :command_128 do |old|
  132.     return old.call unless GainMessage.enabled?
  133.     item = $data_armors[@params[0]]
  134.     last_num = $game_party.item_number_with_equip(item)
  135.     old.call
  136.     value = $game_party.item_number_with_equip(item) - last_num
  137.     show_gain_message(value, item)
  138.   end
  139. end
  140.  
  141. # 整合事件转译器
  142. if Taroxd.const_defined?(:Translator)
  143.   125.upto(128, &Taroxd::Translator.method(:delegate_command))
  144. end
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2024-5-22 01:04

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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