查看: 3255|回复: 6

[原创发布] 输出统计系统

[复制链接]
梦石
0
星屑
1281
在线时间
172 小时
注册时间
2010-10-11
回帖
13
发表于 2019-5-3 17:38:22 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 719783572 于 2019-5-3 19:54 编辑

DPS输出统计系统
http://rpg.blue/forum.php?mod=vi ... &fromuid=106151

这是我之前写的VX版的,这个系统主要就是用于统计单局队伍内各个成员的输出情况。
附上脚本。

  1. #==============================================================================
  2. # ■ DPS统计系统 by ZYYNOV
  3. # ■ Game_Battler
  4. #==============================================================================
  5. DPSswitch = true  #战斗结束后是否自动跳出DPS窗口
  6.                   #如果要手动呼出DPS窗口,请使用脚本SceneManager.call(Scene_DPS)
  7. class Game_Battler < Game_BattlerBase
  8.   attr_accessor :dps ##
  9.   #--------------------------------------------------------------------------
  10.   # ● 初始化对象
  11.   #--------------------------------------------------------------------------
  12.   alias zyynov_initialize initialize
  13.   def initialize
  14.     @dps = 0###
  15.     zyynov_initialize
  16.   end
  17.   #--------------------------------------------------------------------------
  18.   # ● 处理伤害(在此处将伤害计入DPS)
  19.   #--------------------------------------------------------------------------
  20.   alias zyynov_execute_damage execute_damage
  21.   def execute_damage(user)
  22.     zyynov_execute_damage(user)
  23.     user.dps += @result.hp_damage###
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 战斗开始处理(战斗开始时清空上局DPS)
  27.   #--------------------------------------------------------------------------
  28.   alias zyynov_on_battle_start on_battle_start
  29.   def on_battle_start
  30.     zyynov_on_battle_start
  31.     for i in 0 .. 3##清空队伍成员的DPS
  32.       if $game_party.members[i] != nil
  33.       $game_party.members[i].dps = 0
  34.       end
  35.     end
  36.   end
  37.   ###
  38. end

  39. #==============================================================================
  40. # ■ Window_DPS
  41. # 显示DPS的窗口
  42. #==============================================================================
  43. class Window_DPS < Window_Selectable
  44.   #--------------------------------------------------------------------------
  45.   # ● 初始化对象
  46.   #--------------------------------------------------------------------------
  47.   def initialize(actor)
  48.     super(0, 96, 544, 224)
  49.     @actor = actor
  50.     @adps = 1###
  51.     refresh
  52.     activate
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ☆ 绘制角色战斗用肖像图
  56.   #     enabled : 有效的标志。false 的时候使用半透明效果绘制
  57.   #--------------------------------------------------------------------------
  58.   def draw_face(face_name, face_index, x, y, enabled = true)
  59.     bitmap = Cache.face(face_name)
  60.     rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96 + 32, 96, 22)
  61.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  62.     bitmap.dispose
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● 刷新
  66.   #--------------------------------------------------------------------------
  67.   def refresh
  68.     ###
  69.     for i in 0 .. 3
  70.      if $game_party.members[i] != nil
  71.       @adps+=($game_party.members[i].dps).to_f
  72.      end
  73.     end
  74.     per1 = ($game_party.members[0].dps / @adps * 100).to_i
  75.     if $game_party.members[1] != nil
  76.     per2 = ($game_party.members[1].dps / @adps * 100).to_i
  77.     end
  78.     if $game_party.members[2] != nil
  79.     per3 = ($game_party.members[2].dps / @adps * 100).to_i
  80.     end
  81.     if $game_party.members[3] != nil
  82.     per4 = ($game_party.members[3].dps / @adps * 100).to_i
  83.     end
  84.     ###
  85.     contents.clear
  86.     change_color(system_color)
  87.     draw_text(x + 0, y - line_height * 4, 128, line_height, "名字")
  88.     draw_text(x + 128, y - line_height * 4, 128, line_height, "头像")
  89.     draw_text(x + 256, y - line_height * 4, 128, line_height, "输出")
  90.     draw_text(x + 384, y - line_height * 4, 128, line_height, "占比")
  91.     ###
  92.     change_color(normal_color)
  93.     if $game_party.members[0] != nil
  94.     draw_actor_face($game_party.members[0], x + 128 - 8, y - line_height * 2)
  95.     draw_text(x - 0, y - line_height * 2, 128, line_height, $game_party.members[0].name)
  96.     draw_text(x + 256, y - line_height * 2, 128, line_height, $game_party.members[0].dps)
  97.     draw_text(x + 384, y - line_height * 2, 128, line_height, per1.to_s + "%")
  98.     else
  99.     return
  100.     end
  101.     ###
  102.     if $game_party.members[1] != nil
  103.     draw_actor_face($game_party.members[1], x + 128 - 8, y - line_height * 1)
  104.     draw_text(x - 0, y - line_height * 1, 128, line_height, $game_party.members[1].name)
  105.     draw_text(x + 256, y - line_height * 1, 128, line_height, $game_party.members[1].dps)
  106.     draw_text(x + 384, y - line_height * 1, 128, line_height, per2.to_s + "%")
  107.     else
  108.     return
  109.     end
  110.     ###
  111.     if $game_party.members[2] != nil
  112.     draw_actor_face($game_party.members[2], x + 128 - 8, y - line_height * 0)
  113.     draw_text(x - 0, y - line_height * 0, 128, line_height, $game_party.members[2].name)
  114.     draw_text(x + 256, y - line_height * 0, 128, line_height, $game_party.members[2].dps)
  115.     draw_text(x + 384, y - line_height * 0, 128, line_height, per3.to_s + "%")
  116.     else
  117.     return
  118.     end
  119.     ###
  120.     if $game_party.members[3] != nil
  121.     draw_actor_face($game_party.members[3], x + 128 - 8, y + line_height * 1)
  122.     draw_text(x - 0, y + line_height * 1, 128, line_height, $game_party.members[3].name)
  123.     draw_text(x + 256, y + line_height * 1, 128, line_height, $game_party.members[3].dps)
  124.     draw_text(x + 384, y + line_height * 1, 128, line_height, per4.to_s + "%")
  125.     else
  126.     return
  127.     end
  128.     ###
  129.   end
  130. end

  131. #==============================================================================
  132. # ■ Scene_DPS
  133. # 处理DPS画面
  134. #==============================================================================

  135. class Scene_DPS < Scene_MenuBase
  136.   #--------------------------------------------------------------------------
  137.   # ● 开始处理
  138.   #--------------------------------------------------------------------------
  139.   def start
  140.     super
  141.     @dps_window = Window_DPS.new(@actor)
  142.     @dps_window.set_handler(:cancel,   method(:return_scene))
  143.   end
  144. end

  145. #==============================================================================
  146. # ■ Scene_Battle
  147. #  战斗画面
  148. #==============================================================================
  149. class Scene_Battle < Scene_Base
  150.   #--------------------------------------------------------------------------
  151.   # ● 结束处理
  152.   #--------------------------------------------------------------------------
  153.   alias zyynov_terminate terminate
  154.   def terminate
  155.     zyynov_terminate
  156.     if DPSswitch == true
  157.      SceneManager.call(Scene_DPS)
  158.     end
  159.   end
  160. end
复制代码
1.PNG

点评

道理我都懂,但占比合起来不是100%啊_(:3」∠)_  发表于 2019-5-3 20:45

评分

参与人数 1赞 +1 收起 理由
897656o + 1 塞糖

查看全部评分

梦石
10
星屑
39550
在线时间
1919 小时
注册时间
2010-11-14
回帖
3214

R考场第七期纪念奖

发表于 2019-5-3 20:41:30 | 显示全部楼层
……看到了一大堆的"for i in 0..3"和"$game_party.members[i]",还有一些重复率高达99%的语句。
这样对成员上限为4人的是没问题,但是成员上限多或少于4人的就有可能无法正常工作。

最好可以用块,直接迭代$game_party.battle_members
用头画头像,用脚写脚本
回复

使用道具 举报

梦石
0
星屑
1281
在线时间
172 小时
注册时间
2010-10-11
回帖
13
 楼主| 发表于 2019-5-3 21:39:18 | 显示全部楼层
emmm关于占比不是100这个问题,主要是因为写法是通过先用浮点数计算,然后再转换成整数输出,但是浮点数变成整数的过程是把小数点后面的数字一刀切,不会四舍五入,所以会出现一定的误差......

点评

最简单粗暴的方法就是最后一人的百分比用100减去前面人的和来得出  发表于 2019-5-3 23:41
回复

使用道具 举报

梦石
0
星屑
1281
在线时间
172 小时
注册时间
2010-10-11
回帖
13
 楼主| 发表于 2019-5-3 21:47:31 | 显示全部楼层
本帖最后由 719783572 于 2019-5-3 21:59 编辑
KB.Driver 发表于 2019-5-3 20:41
……看到了一大堆的"for i in 0..3"和"$game_party.members",还有一些重复率高达99%的语句。
这样对成员上 ...


确实没考虑五人以上战斗,毕竟不是脚本专业户,写的时候大概就是能更简单一些就按照简单的思路来实现。。。哈哈哈哈。其实还有很多功能没实现,比如辅助职业 团队增益这些都没考虑,还有抗伤控制等等。
其实最终版是打算做一个战斗评分系统的,包括控制抗伤回血团队buff等等。现在这个输出统计其实就是模仿一下DNF的DPS统计这些哈哈哈

然后队伍少于四人其实没有问题,因为各种计算都做了分歧,包括窗口的描绘,只有队伍成员不为nil才会继续运算,所以这个是不会报错的。至于五人以上的战斗系统,如果成员依旧放在$game_party中(不是一些很奇怪的宠物系统等等),我想只要
把Window_DPS扩写一下就行,再把0..3改0..X都行,方法比较笨,就是队伍有几个成员就用for in全部加起来,下次改写肯定要重写算法的

点评

可以看一下VA里each的写法,直接用$game_party.battle_members.each xxx 就能完成你写4遍的效果  发表于 2019-5-3 23:53
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部