157 lines
3.7 KiB
Go
157 lines
3.7 KiB
Go
package effect
|
||
|
||
import (
|
||
"sync"
|
||
|
||
"blazing/logic/service/fight/action"
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/fight/input"
|
||
"blazing/logic/service/fight/node"
|
||
|
||
"github.com/alpacahq/alpacadecimal"
|
||
"github.com/gogf/gf/v2/util/grand"
|
||
)
|
||
|
||
type chargeRecord struct {
|
||
mu sync.Mutex
|
||
layers int
|
||
skipConsume bool
|
||
}
|
||
|
||
var chargeRegistry sync.Map // key uint32 -> *chargeRecord
|
||
|
||
func getChargeRecord(in *input.Input) *chargeRecord {
|
||
if in == nil || in.Player == nil {
|
||
return nil
|
||
}
|
||
userID := in.Player.GetInfo().UserID
|
||
value, _ := chargeRegistry.LoadOrStore(userID, &chargeRecord{})
|
||
return value.(*chargeRecord)
|
||
}
|
||
|
||
func (c *chargeRecord) getLayers() int {
|
||
if c == nil {
|
||
return 0
|
||
}
|
||
c.mu.Lock()
|
||
defer c.mu.Unlock()
|
||
return c.layers
|
||
}
|
||
|
||
func (c *chargeRecord) setSkipConsume(skip bool) {
|
||
if c == nil {
|
||
return
|
||
}
|
||
c.mu.Lock()
|
||
c.skipConsume = skip
|
||
c.mu.Unlock()
|
||
}
|
||
|
||
// Effect 1543: 当回合击败对手则不消耗蓄力层数
|
||
type Effect1543 struct{ node.EffectNode }
|
||
|
||
func (e *Effect1543) Skill_Use() bool {
|
||
if e.Ctx().Opp == nil || e.Ctx().Opp.CurPet[0] == nil || e.Ctx().Opp.CurPet[0].Info.Hp > 0 {
|
||
return true
|
||
}
|
||
if rec := getChargeRecord(e.Ctx().Our); rec != nil {
|
||
rec.setSkipConsume(true)
|
||
}
|
||
return true
|
||
}
|
||
|
||
// Effect 1544: 对手存在护盾时先制+1
|
||
type Effect1544 struct{ node.EffectNode }
|
||
|
||
func (e *Effect1544) ComparePre(fattack, sattack *action.SelectSkillAction) bool {
|
||
if e.Ctx().Opp == nil || !e.Ctx().Opp.HasShield() {
|
||
return true
|
||
}
|
||
current := actionByPlayer(fattack, sattack, e.Ctx().Our.UserID)
|
||
if current == nil || current.SkillEntity == nil {
|
||
return true
|
||
}
|
||
current.SkillEntity.XML.Priority++
|
||
return true
|
||
}
|
||
|
||
// Effect 1545: 消除对手所有护盾效果,消除成功则为自身附加等量的护盾值
|
||
type Effect1545 struct{ node.EffectNode }
|
||
|
||
func (e *Effect1545) Skill_Use() bool {
|
||
if e.Ctx().Our == nil || e.Ctx().Opp == nil {
|
||
return true
|
||
}
|
||
shield := e.Ctx().Opp.ConsumeAllShield()
|
||
if shield.Cmp(alpacadecimal.Zero) <= 0 {
|
||
return true
|
||
}
|
||
e.Ctx().Our.AddShield(shield)
|
||
return true
|
||
}
|
||
|
||
// Effect 1546: 1回合做{0}-{1}次攻击,自身每存在1层蓄力则连击上限次数额外增加{2}次
|
||
type Effect1546 struct{ node.EffectNode }
|
||
|
||
func (e *Effect1546) SkillHit() bool {
|
||
if len(e.Args()) < 3 || e.Ctx().SkillEntity == nil || e.Ctx().SkillEntity.Category() == info.Category.STATUS || e.Ctx().SkillEntity.AttackTime == 0 {
|
||
return true
|
||
}
|
||
|
||
minHits := int(e.Args()[0].IntPart())
|
||
maxHits := int(e.Args()[1].IntPart())
|
||
if minHits <= 0 {
|
||
minHits = 1
|
||
}
|
||
if maxHits < minHits {
|
||
maxHits = minHits
|
||
}
|
||
|
||
if rec := getChargeRecord(e.Ctx().Our); rec != nil {
|
||
maxHits += rec.getLayers() * int(e.Args()[2].IntPart())
|
||
}
|
||
if maxHits < minHits {
|
||
maxHits = minHits
|
||
}
|
||
|
||
hits := minHits
|
||
if maxHits > minHits {
|
||
hits += grand.Intn(maxHits - minHits + 1)
|
||
}
|
||
if hits <= 1 {
|
||
return true
|
||
}
|
||
|
||
e.Ctx().SkillEntity.AttackTime += uint32(hits - 1)
|
||
return true
|
||
}
|
||
|
||
// Effect 1547: 自身每存在3层蓄力先制额外+1
|
||
type Effect1547 struct{ node.EffectNode }
|
||
|
||
func (e *Effect1547) ComparePre(fattack, sattack *action.SelectSkillAction) bool {
|
||
current := actionByPlayer(fattack, sattack, e.Ctx().Our.UserID)
|
||
if current == nil || current.SkillEntity == nil {
|
||
return true
|
||
}
|
||
|
||
layers := 0
|
||
if rec := getChargeRecord(e.Ctx().Our); rec != nil {
|
||
layers = rec.getLayers()
|
||
}
|
||
if layers < 3 {
|
||
return true
|
||
}
|
||
|
||
current.SkillEntity.XML.Priority += layers / 3
|
||
return true
|
||
}
|
||
|
||
func init() {
|
||
input.InitEffect(input.EffectType.Skill, 1543, &Effect1543{})
|
||
input.InitEffect(input.EffectType.Skill, 1544, &Effect1544{})
|
||
input.InitEffect(input.EffectType.Skill, 1545, &Effect1545{})
|
||
input.InitEffect(input.EffectType.Skill, 1546, &Effect1546{})
|
||
input.InitEffect(input.EffectType.Skill, 1547, &Effect1547{})
|
||
}
|