Files
bl/logic/service/fight/input/ctx.go
xinian 2eba4b7915
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat: 实现乱舞效果并完善战斗输入上下文
2026-04-04 22:39:56 +08:00

77 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package input
import "blazing/logic/service/fight/info"
type LegacySides struct {
// Our 兼容旧 effect当前执行侧历史语义里的“我方”
// 使用场景:
// 1) 旧 effect 仍通过 Ctx().Our/Ctx().Opp 取双方输入。
// 2) Source/Carrier/Target 未设置时作为默认回退。
Our *Input
// Opp 兼容旧 effect当前执行侧的对位历史语义里的“对手”
// 使用场景:
// 1) 单目标旧链路下,直接作为“对手输入”。
// 2) Source/Carrier/Target 语义未接入的旧 effect。
Opp *Input
}
type EffectBinding struct {
// Source effect 来源输入(谁施加/创建了这个 effect通常等价于 e.GetInput()。
// 该值一般在 effect 生命周期内保持不变。
// 使用场景:
// 1) 伤害归属/效果归属判定(谁是施法者)。
// 2) A 给 B 挂效果后,后续仍需要识别“来源是 A”。
Source *Input
// Carrier 当前持有效果的输入effect 实际挂载在哪个输入上)。
// 例如 A 给 B 挂 debuff 时Source=ACarrier=B。
// 使用场景:
// 1) 回合开始/结束、切换、状态结算时,按“持有者”触发。
// 2) 需要区分“是谁挂的”(Source) 与 “挂在谁身上”(Carrier)。
Carrier *Input
// Target 本次结算的实际作用目标输入(瞬时语义,可在链式/群体结算中变化)。
// 为空时通常回退到 Carrier 或 LegacySides.Our。
// 使用场景:
// 1) 链式/群体/溅射:同一个 effect 逐个作用不同目标。
// 2) 重定向/反弹:效果仍由原 Carrier 持有,但本次作用对象发生变化。
Target *Input
}
type Ctx struct {
LegacySides
EffectBinding
*info.SkillEntity //action本身
// *info.DamageZone //伤害
}
func (c *Ctx) Self() *Input {
if c == nil {
return nil
}
if c.Source != nil {
return c.Source
}
return c.Our
}
// Receiver 返回本次结算的接收方输入Target > Carrier > Our。
// 使用场景:
// 1) 写 effect 时不关心目标来源,只取“当前实际受影响者”。
// 2) 统一兼容单目标与群体/重定向结算链路。
func (c *Ctx) Receiver() *Input {
if c == nil {
return nil
}
if c.Target != nil {
return c.Target
}
if c.Carrier != nil {
return c.Carrier
}
return c.Our
}