Project1

标题: 求救,这个我瞎写的脚本有办法缩短吗 [打印本页]

作者: yang1zhi    时间: 2014-11-3 17:14
标题: 求救,这个我瞎写的脚本有办法缩短吗
太可怕了。状态少的时候还好。状态多起来要给每种排列都设定。


RUBY 代码复制
  1. def slip_damage_effect
  2.   xxxx = self.maxhp / 30
  3.   yyyy = self.hp / 20
  4.   zzzz = self.maxsp / 20
  5.   qqqq = self.maxhp / 10
  6.   if self.state?(24) and self.state?(3) and self.state?(32)  and self.state?(45)  
  7.     #默认的回血毒烧伤回SP效果
  8.     self.damage["slip"] = (xxxx + yyyy - qqqq)
  9.     self.damage_sp["slip"] = zzzz
  10.     self.hp -= self.damage["slip"]
  11.     self.sp += self.damage_sp["slip"]
  12.     return true
  13.   end
  14.   if self.state?(24) and self.state?(3) and self.state?(32)#默认的毒烧伤回血效果
  15.     self.damage["slip"] = (xxxx + yyyy - qqqq)  
  16.     self.hp -= self.damage["slip"]
  17.     return true
  18.   end
  19.   if self.state?(3) and self.state?(32)#默认的毒烧伤效果
  20.     self.damage["slip"] = (xxxx + yyyy)  
  21.     self.hp -= self.damage["slip"]
  22.     return true
  23.   end
  24.   if  self.state?(24) and self.state?(32)  and self.state?(45)  #默认的烧伤回SP回血效果
  25.     self.damage["slip"] = (yyyy - qqqq)
  26.     self.damage_sp["slip"] = zzzz
  27.     self.hp -= self.damage["slip"]
  28.     self.sp += self.damage_sp["slip"]
  29.     return true
  30.   if  self.state?(32)  and self.state?(45)  #默认的烧伤回SP效果
  31.     self.damage["slip"] = yyyy
  32.     self.damage_sp["slip"] = zzzz
  33.     self.hp -= self.damage["slip"]
  34.     self.sp += self.damage_sp["slip"]
  35.     return true
  36.   end
  37.   if self.state?(24) and self.state?(3) and self.state?(45)  #默认的毒回SP回血效果
  38.     self.damage["slip"] = (xxxx - qqqq)
  39.     self.damage_sp["slip"] = zzzz
  40.     self.hp -= self.damage["slip"]
  41.     self.sp += self.damage_sp["slip"]
  42.     return true
  43.   end
  44.   if self.state?(3) and self.state?(45)  #默认的毒回SP效果
  45.     self.damage["slip"] = xxxx
  46.     self.damage_sp["slip"] = zzzz
  47.     self.hp -= self.damage["slip"]
  48.     self.sp += self.damage_sp["slip"]
  49.     return true
  50.   end
  51.   if self.state?(24) and self.state?(3) #默认的毒回血效果
  52.     self.damage["slip"] = (xxxx - qqqq)
  53.     self.hp -= self.damage["slip"]
  54.     return true
  55.   end
  56.   if self.state?(3) #默认的毒效果
  57.     self.damage["slip"] = xxxx
  58.     self.hp -= self.damage["slip"]
  59.     return true
  60.   end
  61.   if self.state?(24) and self.state?(32) #烧伤回血
  62.     self.damage["slip"] = (yyyy - qqqq)
  63.     self.hp -= self.damage["slip"]
  64.     return true
  65.   end
  66.   if self.state?(32) #烧伤
  67.     self.damage["slip"] = yyyy
  68.     self.hp -= self.damage["slip"]
  69.     return true
  70.   end
  71.   if self.state?(24) and self.state?(45)  #回SP回血效果
  72.     self.damage["slip"] = qqqq
  73.     self.hp += self.damage["slip"]
  74.     self.damage_sp["slip"] = zzzz
  75.     self.sp += self.damage_sp["slip"]
  76.     return true
  77.   end
  78.   if self.state?(45)  #回SP效果
  79.     self.damage_sp["slip"] = zzzz
  80.     self.sp += self.damage_sp["slip"]
  81.     return true
  82.   end
  83.   if self.state?(24)  #回血
  84.     self.damage["slip"] = qqqq  
  85.     self.hp += self.damage["slip"]
  86.     return true
  87.   end
  88.   # 过程结束
  89.   return true
  90. end
  91. end

作者: yang1zhi    时间: 2014-11-3 17:33
最后添加得太多了报错了{:2_264:}
作者: RyanBern    时间: 2014-11-3 19:25
4个状态共要考虑16种情况……
self.damage被黑掉了?
即兴写下面的脚本,未测试
RUBY 代码复制
  1. # 3=>毒
  2. # 24=>回血
  3. # 32=>烧伤
  4. # 45=>回蓝
  5. def slip_damage_effect
  6.   hp_v = {3 => self.maxhp / 30, 24 => -self.hp / 20, 32 => self.maxhp / 10}
  7.   sp_v = {45 => -self.maxsp / 20}
  8.   hp_damage = 0
  9.   sp_damage = 0
  10.   hp_v.keys.each do |id|
  11.     hp_damage += hp_v[id] if self.state?(id)
  12.   end
  13.   sp_v.keys.each do |id|
  14.     sp_damage += sp_v[id] if self.state?(id)
  15.   end
  16.   self.damage["slip"] = hp_damage if hp_damage != 0
  17.   self.hp -= hp_damage
  18.   self.damage_sp["slip"] = sp_damage if sp_damage != 0
  19.   self.sp -= sp_damage
  20. end

作者: chd114    时间: 2014-11-5 21:58
你这是用在哪里的脚本···




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1