refactor(fight): 优化战斗效果中的属性检测逻辑 通过引入HasPropADD()和HasPropSub()方法来替代循环遍历, 简化了多处战斗效果代码,提高了可读性和性能。 - effect/200.go: 使用HasPropADD()替代循环检测 - effect/418.go: 使用HasPropADD()替代循环检测 - effect/437.go: 使用HasPropADD()替代循环检测 - effect/449.go: 使用HasPropSub()替代循环检测 - effect
This commit is contained in:
@@ -11,18 +11,15 @@ type Effect200 struct {
|
||||
}
|
||||
|
||||
func (e *Effect200) OnSkill() bool {
|
||||
if e.Ctx().Opp.HasPropADD() {
|
||||
chance := e.Args()[0].IntPart()
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型
|
||||
|
||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v > 0 {
|
||||
chance := e.Args()[0].IntPart()
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型
|
||||
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,8 @@ type Effect418 struct {
|
||||
}
|
||||
|
||||
func (e *Effect418) OnSkill() bool {
|
||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v > 0 {
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||
return true
|
||||
}
|
||||
if e.Ctx().Opp.HasPropADD() {
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||
|
||||
}
|
||||
|
||||
|
||||
32
logic/service/fight/effect/434.go
Normal file
32
logic/service/fight/effect/434.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package effect
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/fight/node"
|
||||
)
|
||||
|
||||
// 434 - 若自身处于能力强化状态,则n%几率令对手XX
|
||||
type Effect434 struct {
|
||||
node.EffectNode
|
||||
}
|
||||
|
||||
func (e *Effect434) OnSkill() bool {
|
||||
if e.Ctx().Our.CurrentPet.HasPositiveBuff() { // 自身处于能力强化状态
|
||||
chance := e.Args()[0].IntPart()
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型,比如麻痹
|
||||
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
func init() {
|
||||
input.InitEffect(input.EffectType.Skill, 434, &Effect434{})
|
||||
|
||||
}
|
||||
@@ -12,12 +12,8 @@ type Effect437 struct {
|
||||
|
||||
func (e *Effect437) OnSkill() bool {
|
||||
|
||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v > 0 {
|
||||
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||
return true
|
||||
}
|
||||
if e.Ctx().Opp.HasPropADD() {
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,20 +11,16 @@ type Effect449 struct {
|
||||
}
|
||||
|
||||
func (e *Effect449) OnSkill() bool {
|
||||
if e.Ctx().Opp.HasPropSub() {
|
||||
chance := e.Args()[0].IntPart() // N%
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型
|
||||
|
||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v < 0 {
|
||||
chance := e.Args()[0].IntPart() // N%
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型
|
||||
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,18 +14,8 @@ type Effect460 struct {
|
||||
func (e *Effect460) OnSkill() bool {
|
||||
baseChance := e.Args()[0].IntPart() // m%
|
||||
|
||||
// 检查对手是否处于能力强化状态
|
||||
extraChance := false
|
||||
|
||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v > 0 {
|
||||
extraChance = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
totalChance := baseChance
|
||||
if extraChance {
|
||||
if e.Ctx().Opp.HasPropADD() {
|
||||
totalChance += e.Args()[1].IntPart()
|
||||
}
|
||||
success, _, _ := e.Input.Player.Roll(int(totalChance), 100)
|
||||
|
||||
@@ -12,13 +12,10 @@ type Effect489 struct {
|
||||
}
|
||||
|
||||
func (e *Effect489) SkillHit_ex() bool {
|
||||
for _, v := range e.Ctx().Our.Prop[:] {
|
||||
if v > 0 {
|
||||
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
|
||||
healAmount := maxHp.Div(e.Args()[0]) // 1/m
|
||||
e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount)
|
||||
return true
|
||||
}
|
||||
if e.Ctx().Our.HasPropADD() {
|
||||
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
|
||||
healAmount := maxHp.Div(e.Args()[0]) // 1/m
|
||||
e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -461,28 +461,6 @@ func (e *Effect516) OnSkill() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// 434 - 若自身处于能力强化状态,则n%几率令对手XX
|
||||
type Effect434 struct {
|
||||
node.EffectNode
|
||||
}
|
||||
|
||||
func (e *Effect434) OnSkill() bool {
|
||||
if e.Ctx().Our.CurrentPet.HasPositiveBuff() { // 自身处于能力强化状态
|
||||
chance := e.Args()[0].IntPart()
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
effectType := int(e.Args()[1].IntPart()) // XX类型,比如麻痹
|
||||
|
||||
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||
if statusEffect != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 495 - 若对手处于XX状态,则30%几率秒杀对手
|
||||
type Effect495 struct {
|
||||
node.EffectNode
|
||||
@@ -14,17 +14,15 @@ type Effect419 struct {
|
||||
}
|
||||
|
||||
func (e *Effect419) Skill_Use() bool {
|
||||
for _, V := range e.Ctx().Opp.Prop[:] {
|
||||
if V > 0 {
|
||||
fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害
|
||||
if e.Ctx().Opp.HasPropADD() {
|
||||
fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害
|
||||
|
||||
damageZone := &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: fixedDamage,
|
||||
}
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, damageZone)
|
||||
return true
|
||||
damageZone := &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: fixedDamage,
|
||||
}
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, damageZone)
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,13 +83,7 @@ func init() {
|
||||
})
|
||||
registerStatusFunc(431, func(i, o *input.Input) bool {
|
||||
|
||||
for _, v := range o.Prop[:] {
|
||||
|
||||
if v < 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return o.HasPropSub()
|
||||
})
|
||||
initskill(609, &Effect609{})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
package input
|
||||
|
||||
func (our *Input) HasPropADD() bool {
|
||||
for _, v := range our.Prop[:] {
|
||||
if v > 0 {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (our *Input) HasPropSub() bool {
|
||||
for _, v := range our.Prop[:] {
|
||||
if v < 0 {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (target *Input) SetProp(source *Input, index, level int8) bool {
|
||||
// 前置状态结算:判断是否允许执行属性操作
|
||||
canExecute := target.Exec(func(effect Effect) bool {
|
||||
|
||||
Reference in New Issue
Block a user