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 {
|
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[:] {
|
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||||
if v > 0 {
|
if statusEffect != nil {
|
||||||
chance := e.Args()[0].IntPart()
|
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,8 @@ type Effect418 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect418) OnSkill() bool {
|
func (e *Effect418) OnSkill() bool {
|
||||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
if e.Ctx().Opp.HasPropADD() {
|
||||||
if v > 0 {
|
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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 {
|
func (e *Effect437) OnSkill() bool {
|
||||||
|
|
||||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
if e.Ctx().Opp.HasPropADD() {
|
||||||
if v > 0 {
|
e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
||||||
|
|
||||||
e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1]))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,20 +11,16 @@ type Effect449 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect449) OnSkill() bool {
|
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[:] {
|
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
|
||||||
if v < 0 {
|
if statusEffect != nil {
|
||||||
chance := e.Args()[0].IntPart() // N%
|
e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,18 +14,8 @@ type Effect460 struct {
|
|||||||
func (e *Effect460) OnSkill() bool {
|
func (e *Effect460) OnSkill() bool {
|
||||||
baseChance := e.Args()[0].IntPart() // m%
|
baseChance := e.Args()[0].IntPart() // m%
|
||||||
|
|
||||||
// 检查对手是否处于能力强化状态
|
|
||||||
extraChance := false
|
|
||||||
|
|
||||||
for _, v := range e.Ctx().Opp.Prop[:] {
|
|
||||||
if v > 0 {
|
|
||||||
extraChance = true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
totalChance := baseChance
|
totalChance := baseChance
|
||||||
if extraChance {
|
if e.Ctx().Opp.HasPropADD() {
|
||||||
totalChance += e.Args()[1].IntPart()
|
totalChance += e.Args()[1].IntPart()
|
||||||
}
|
}
|
||||||
success, _, _ := e.Input.Player.Roll(int(totalChance), 100)
|
success, _, _ := e.Input.Player.Roll(int(totalChance), 100)
|
||||||
|
|||||||
@@ -12,13 +12,10 @@ type Effect489 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect489) SkillHit_ex() bool {
|
func (e *Effect489) SkillHit_ex() bool {
|
||||||
for _, v := range e.Ctx().Our.Prop[:] {
|
if e.Ctx().Our.HasPropADD() {
|
||||||
if v > 0 {
|
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
|
||||||
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
|
healAmount := maxHp.Div(e.Args()[0]) // 1/m
|
||||||
healAmount := maxHp.Div(e.Args()[0]) // 1/m
|
e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount)
|
||||||
e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -461,28 +461,6 @@ func (e *Effect516) OnSkill() bool {
|
|||||||
return true
|
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%几率秒杀对手
|
// 495 - 若对手处于XX状态,则30%几率秒杀对手
|
||||||
type Effect495 struct {
|
type Effect495 struct {
|
||||||
node.EffectNode
|
node.EffectNode
|
||||||
@@ -14,17 +14,15 @@ type Effect419 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect419) Skill_Use() bool {
|
func (e *Effect419) Skill_Use() bool {
|
||||||
for _, V := range e.Ctx().Opp.Prop[:] {
|
if e.Ctx().Opp.HasPropADD() {
|
||||||
if V > 0 {
|
fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害
|
||||||
fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害
|
|
||||||
|
|
||||||
damageZone := &info.DamageZone{
|
damageZone := &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: fixedDamage,
|
Damage: fixedDamage,
|
||||||
}
|
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, damageZone)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
e.Ctx().Opp.Damage(e.Ctx().Our, damageZone)
|
||||||
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,13 +83,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
registerStatusFunc(431, func(i, o *input.Input) bool {
|
registerStatusFunc(431, func(i, o *input.Input) bool {
|
||||||
|
|
||||||
for _, v := range o.Prop[:] {
|
return o.HasPropSub()
|
||||||
|
|
||||||
if v < 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
initskill(609, &Effect609{})
|
initskill(609, &Effect609{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
package input
|
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 {
|
func (target *Input) SetProp(source *Input, index, level int8) bool {
|
||||||
// 前置状态结算:判断是否允许执行属性操作
|
// 前置状态结算:判断是否允许执行属性操作
|
||||||
canExecute := target.Exec(func(effect Effect) bool {
|
canExecute := target.Exec(func(effect Effect) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user