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

Project1

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

[已经解决] 如何制作通过吸收魔法攻击来格挡物理攻击的技能

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2013-3-31
帖子
50
跳转到指定楼层
1
发表于 2013-8-5 11:02:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
原先那个帖子我就设置成过期了,因为很重要所以换个方法再问一遍。最初的设想是做一个技能给自己附加一个状态,然后处在这个状态下的角色在被对方的魔法攻击时会将伤害值转化为能量值,然后在有能量值的情况下对方的物理技能和普通攻击造成的伤害会减少50%,并扣除等额的能量值。能量值不足时只抵挡剩余能量数额的伤害。同时技能存在吸收上限,超出人物等级*100的攻击无法吸收,但是伤害会减少人物当前等级*100的数值。具体设想是在Game_Battler脚本里先加上attr_accessor :energy之后再在Game_Battler3的应用通常攻击效果和应用特技效果里的HP的伤害计算部分分别加上下面两段脚本
  1.       # HP 的伤害计算
  2.       # 检测对象是否拥有无光之盾状态
  3.       if self.states.include?(18)
  4.         #判断剩余的能量是否足以抵挡此次攻击
  5.         if self.damage <= self.energy * 2
  6.         self.hp -= self.damage / 2
  7.         self.energy -= self.damage / 2
  8.         #不足的情况,只抵挡剩余能量的伤害,同时能量值清零
  9.         else self.damage -= self.energy
  10.         self.hp -= self.damage
  11.         self.energy = 0
  12.         end
  13.       else; self.hp -= self.damage
  14.       end
复制代码
  1.       # HP 的伤害减法运算
  2.       if self.is_a?(Game_Actor)
  3.       # 检测对象是否拥有无光之盾状态
  4.       if self.states.include?(18)
  5.         #判断对手使用的是否是魔法攻击
  6.         if skill.atk_f == 0
  7.           if self.damage > self.level * 100      #无光之盾的能量上限
  8.             self.damage -= self.level * 100
  9.             last_hp = self.hp
  10.             self.hp -= self.damage
  11.             effective |= self.hp != last_hp
  12.           elsif self.damage + self.energy > self.level * 100
  13.             self.energy = self.level * 100
  14.           else; self.energy += self.damage
  15.           end
  16.         #判断剩余的能量是否足以抵挡此次攻击
  17.         elsif self.damage <= self.energy * 2
  18.           last_hp = self.hp
  19.           self.hp -= self.damage / 2
  20.           effective |= self.hp != last_hp
  21.           self.energy -= self.damage / 2
  22.         #不足的情况,只抵挡剩余能量的伤害,同时能量值清零
  23.         else; self.damage -= self.energy
  24.           last_hp = self.hp
  25.           self.hp -= self.damage
  26.           effective |= self.hp != last_hp
  27.           self.energy = 0
  28.         end
  29.         end
  30.       last_hp = self.hp
  31.       self.hp -= self.damage
  32.       effective |= self.hp != last_hp
  33.       end
复制代码
但是加上以上两段脚本之后使用技能攻击怪物就只显示伤害却无法致死,一直不明白问题出在哪里,求指点

点评

分号不是判断句,只是表示结束语句,俺不推荐用分号意思是容易让人看漏了,最好还是换行写。  发表于 2013-8-5 15:13

Lv2.观梦者 (暗夜天使)

万兽

梦石
0
星屑
597
在线时间
2271 小时
注册时间
2006-11-4
帖子
4868

贵宾

2
发表于 2013-8-5 11:44:57 | 只看该作者
本帖最后由 弗雷德 于 2013-8-5 13:43 编辑

你把 effective |= self.hp != last_hp 写进if self.is_a?(Game_Actor)的判断当中,那么如果对象不是角色,就不会执行效果,移出去试试。
另外强烈抗议使用的分号的判断语句,看得很晕,这跟一大堆三目似的……

俺是的意思是将effective |= self.hp != last_hp 这句写出判断外,当执行完判断之后,再统一应用效果
比如你现在是这样写的。
  1.       # HP 的伤害减法运算
  2.       if self.is_a?(Game_Actor)
  3.       # 检测对象是否拥有无光之盾状态
  4.       if self.states.include?(18)
  5.         #判断对手使用的是否是魔法攻击
  6.         if skill.atk_f == 0
  7.           if self.damage > self.level * 100      #无光之盾的能量上限
  8.             self.damage -= self.level * 100
  9.             last_hp = self.hp
  10.             self.hp -= self.damage
  11.             effective |= self.hp != last_hp
  12.           elsif self.damage + self.energy > self.level * 100
  13.             self.energy = self.level * 100
  14.           else; self.energy += self.damage
  15.           end
  16.         #判断剩余的能量是否足以抵挡此次攻击
  17.         elsif self.damage <= self.energy * 2
  18.           last_hp = self.hp
  19.           self.hp -= self.damage / 2
  20.           effective |= self.hp != last_hp
  21.           self.energy -= self.damage / 2
  22.         #不足的情况,只抵挡剩余能量的伤害,同时能量值清零
  23.         else; self.damage -= self.energy
  24.           last_hp = self.hp
  25.           self.hp -= self.damage
  26.           effective |= self.hp != last_hp
  27.           self.energy = 0
  28.         end
  29.         end
  30.       last_hp = self.hp
  31.       self.hp -= self.damage
  32.       effective |= self.hp != last_hp
  33.       end
复制代码
改成:
  1. # HP 的伤害减法运算
  2. if self.is_a?(Game_Actor)
  3. # 检测对象是否拥有无光之盾状态
  4. if self.states.include?(18)
  5. #判断对手使用的是否是魔法攻击
  6. if skill.atk_f == 0
  7. if self.damage > self.level * 100 #无光之盾的能量上限
  8. self.damage -= self.level * 100
  9. last_hp = self.hp
  10. self.hp -= self.damage
  11. effective |= self.hp != last_hp
  12. elsif self.damage + self.energy > self.level * 100
  13. self.energy = self.level * 100
  14. else; self.energy += self.damage
  15. end
  16. #判断剩余的能量是否足以抵挡此次攻击
  17. elsif self.damage <= self.energy * 2
  18. last_hp = self.hp
  19. self.hp -= self.damage / 2
  20. effective |= self.hp != last_hp
  21. self.energy -= self.damage / 2
  22. #不足的情况,只抵挡剩余能量的伤害,同时能量值清零
  23. else; self.damage -= self.energy
  24. last_hp = self.hp
  25. self.hp -= self.damage
  26. effective |= self.hp != last_hp
  27. self.energy = 0
  28. end
  29. end
  30. last_hp = self.hp
  31. self.hp -= self.damage
  32. end
  33. ##########################################写出这个判断外。因为你之前的代码导致只有当对象为角色的时候才执行effective |= self.hp != last_hp
  34. effective |= self.hp != last_hp

复制代码
@qqyxzyb  

点评

那个,虽然是无关紧要的话但是我还是想问一下,有关分号的判断句的内容在哪里?因为之前也有人叫我加分号试试……  发表于 2013-8-5 15:09
我试过了,思路是对的,但是要同时将“last_hp = self.hp”“self.hp -= self.damage”“effective |= self.hp != last_hp”同时移出来才可以,谢谢了。  发表于 2013-8-5 15:08
不好意思我不会使用分号的判断句,能告诉我哪里有相关的内容吗?另外,那个判断是每一个effective |= self.hp != last_hp都要写吗?  发表于 2013-8-5 13:26

评分

参与人数 1星屑 +111 收起 理由
︶ㄣ牛排ぶ + 111 认可答案,给你三光棍

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-21 05:36

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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