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

Project1

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

[已经解决] 请教显示群体技能攻击每次使用时造成伤害之和的方法

[复制链接]

Lv4.逐梦者

梦石
0
星屑
9128
在线时间
463 小时
注册时间
2015-5-8
帖子
865
跳转到指定楼层
1
发表于 2019-11-24 05:39:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
咱想搞一个战斗解说系统,假设第666号公共变量是用来计算技能攻击造成伤害之和的方法的,
每次行动结束后会出现一句话概述这次行动,比如:“第1号角色对敌方造成了$game_variables[666]点伤害”

如果是单体攻击技能咱知道怎么弄,直接在skill_effect 里面加一句$game_variables[666] = self.damage就行了,
那要是群体攻击技能该怎么弄呢?

Lv3.寻梦者

梦石
0
星屑
2089
在线时间
80 小时
注册时间
2018-6-29
帖子
19

R考场第七期纪念奖

2
发表于 2019-11-24 15:24:22 | 只看该作者
应该可以这么写吧?这是我计算群体伤害之和的方法,其他大佬的方法应该会更好吧?
Game_Battler 3:
RUBY 代码复制
  1. def skill_effect(user, skill)
  2.     # 清除会心一击标志
  3.     self.critical = false
  4.     # 特技的效果范围是 HP 1 以上的己方、自己的 HP 为 0、
  5.     # 或者特技的效果范围是 HP 0 的己方、自己的 HP 为 1 以上的情况下
  6.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  7.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  8.       # 过程结束
  9.       return false
  10.     end
  11.     # 清除有效标志
  12.     effective = false
  13.     # 公共事件 ID 是有效的情况下,设置为有效标志
  14.     effective |= skill.common_event_id > 0
  15.     # 第一命中判定
  16.     hit = skill.hit
  17.     if skill.atk_f > 0
  18.       hit *= user.hit / 100
  19.     end
  20.     hit_result = (rand(100) < hit)
  21.     # 不确定的特技的情况下设置为有效标志
  22.     effective |= hit < 100
  23.     # 命中的情况下
  24.     if hit_result == true
  25.       # 计算威力
  26.       power = skill.power + user.atk * skill.atk_f / 100
  27.       if power > 0
  28.         power -= self.pdef * skill.pdef_f / 200
  29.         power -= self.mdef * skill.mdef_f / 200
  30.         power = [power, 0].max
  31.       end
  32.       # 计算倍率
  33.       rate = 20
  34.       rate += (user.str * skill.str_f / 100)
  35.       rate += (user.dex * skill.dex_f / 100)
  36.       rate += (user.agi * skill.agi_f / 100)
  37.       rate += (user.int * skill.int_f / 100)
  38.       # 计算基本伤害
  39.       self.damage = power * rate / 20
  40.       # 属性修正
  41.       self.damage *= elements_correct(skill.element_set)
  42.       self.damage /= 100
  43.       # 伤害符号正确的情况下
  44.       if self.damage > 0
  45.         # 防御修正
  46.         if self.guarding?
  47.           self.damage /= 2
  48.         end
  49.       end
  50.       # 分散
  51.       if skill.variance > 0 and self.damage.abs > 0
  52.         amp = [self.damage.abs * skill.variance / 100, 1].max
  53.         self.damage += rand(amp+1) + rand(amp+1) - amp
  54.       end
  55.       # 第二命中判定
  56.       eva = 8 * self.agi / user.dex + self.eva
  57.       hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  58.       hit = self.cant_evade? ? 100 : hit
  59.       hit_result = (rand(100) < hit)
  60.       # 不确定的特技的情况下设置为有效标志
  61.       effective |= hit < 100
  62.     end
  63.     # 命中的情况下
  64.     if hit_result == true
  65.       # 威力 0 以外的物理攻击的情况下
  66.       if skill.power != 0 and skill.atk_f > 0
  67.         # 状态冲击解除
  68.         remove_states_shock
  69.         # 设置有效标志
  70.         effective = true
  71.       end
  72.       # HP 的伤害减法运算
  73.       last_hp = self.hp
  74.       self.hp -= self.damage
  75.       effective |= self.hp != last_hp
  76.       # 状态变化
  77.       @state_changed = false
  78.       effective |= states_plus(skill.plus_state_set)
  79.       effective |= states_minus(skill.minus_state_set)
  80.       # 威力为 0 的场合
  81.       if skill.power == 0
  82.         # 伤害设置为空的字串
  83.         self.damage = ""
  84.         # 状态没有变化的情况下
  85.         unless @state_changed
  86.           # 伤害设置为 "Miss"
  87.           self.damage = "Miss"
  88.         end
  89.       end
  90.     # Miss 的情况下
  91.     else
  92.       # 伤害设置为 "Miss"
  93.       self.damage = "Miss"
  94.     end
  95.     # 不在战斗中的情况下
  96.     unless $game_temp.in_battle
  97.       # 伤害设置为 nil
  98.       self.damage = nil
  99.     end
  100.     # 过程结束
  101.     if hit_result == true #必需命中,否则不计算。#宝箱君
  102.     unless skill.power == 0 #威力为0不计算 #宝箱君
  103.     if $群体 == 2 #判定是否为全体技能,否则不计算。(只计算我方)#宝箱君
  104.      $game_variables[666] += self.damage
  105.      p $game_variables[666]
  106.    else
  107.      $game_variables[666] = 0
  108.      p $game_variables[666]
  109.    end
  110. end
  111. end
  112.     return effective
  113.   end


Scene_Battle 4:
RUBY 代码复制
  1. def set_target_battlers(scope)
  2.     # 行动方的战斗者是敌人的情况下
  3.       $game_variables[666] = 0 #初始化伤害 #宝箱君
  4.       $群体 = 0#判定是否为全体技能,由于是敌人,不计算。 #宝箱君
  5.     if @active_battler.is_a?(Game_Enemy)
  6.       # 效果范围分支
  7.       case scope
  8.       when 1  # 敌单体
  9.         index = @active_battler.current_action.target_index
  10.         @target_battlers.push($game_party.smooth_target_actor(index))
  11.       when 2  # 敌全体
  12.         for actor in $game_party.actors
  13.           if actor.exist?
  14.             @target_battlers.push(actor)
  15.           end
  16.         end
  17.       when 3  # 我方单体
  18.         index = @active_battler.current_action.target_index
  19.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  20.       when 4  # 我方全体
  21.         for enemy in $game_troop.enemies
  22.           if enemy.exist?
  23.             @target_battlers.push(enemy)
  24.           end
  25.         end
  26.       when 5  # 我方单体 (HP 0)
  27.         index = @active_battler.current_action.target_index
  28.         enemy = $game_troop.enemies[index]
  29.         if enemy != nil and enemy.hp0?
  30.           @target_battlers.push(enemy)
  31.         end
  32.       when 6  # 我方全体 (HP 0)
  33.         for enemy in $game_troop.enemies
  34.           if enemy != nil and enemy.hp0?
  35.             @target_battlers.push(enemy)
  36.           end
  37.         end
  38.       when 7  # 使用者
  39.         @target_battlers.push(@active_battler)
  40.       end
  41.     end
  42.     # 行动方的战斗者是角色的情况下
  43.     if @active_battler.is_a?(Game_Actor)
  44.       # 效果范围分支
  45.       $game_variables[666] = 0#初始化伤害 #宝箱君
  46.       $群体 = scope#判定是否为全体技能 #宝箱君
  47.       case scope
  48.       when 1  # 敌单体
  49.         index = @active_battler.current_action.target_index
  50.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  51.       when 2  # 敌全体
  52.         for enemy in $game_troop.enemies
  53.           if enemy.exist?
  54.             @target_battlers.push(enemy)
  55.           end
  56.         end
  57.       when 3  # 我方单体
  58.         index = @active_battler.current_action.target_index
  59.         @target_battlers.push($game_party.smooth_target_actor(index))
  60.       when 4  # 我方全体
  61.         for actor in $game_party.actors
  62.           if actor.exist?
  63.             @target_battlers.push(actor)
  64.           end
  65.         end
  66.       when 5  # 我方单体 (HP 0)
  67.         index = @active_battler.current_action.target_index
  68.         actor = $game_party.actors[index]
  69.         if actor != nil and actor.hp0?
  70.           @target_battlers.push(actor)
  71.         end
  72.       when 6  # 我方全体 (HP 0)
  73.         for actor in $game_party.actors
  74.           if actor != nil and actor.hp0?
  75.             @target_battlers.push(actor)
  76.           end
  77.         end
  78.       when 7  # 使用者
  79.         @target_battlers.push(@active_battler)
  80.       end
  81.     end
  82.   end

点评

666!  发表于 2019-11-27 06:52

评分

参与人数 2星屑 +80 +2 收起 理由
RyanBern + 80 + 1 认可答案
taeckle + 1 多谢了!

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-26 12:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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