Files
bl/logic/service/fight/targeting.go
xinian 78a68148ce
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
chore: update fight logic and effect implementations
2026-04-05 02:25:44 +08:00

35 lines
936 B
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 fight
// 技能目标关系(与前端可选目标范围对齐):
// 0: 对手enemy
// 1: 自己self
// 2: 队友ally
const (
SkillTargetOpponent uint8 = 0
SkillTargetSelf uint8 = 1
SkillTargetAlly uint8 = 2
)
// EncodeTargetIndex 对目标下标进行编码,兼容旧 UseSkillAt(actorIndex,targetIndex) 接口:
// 1) 敌方目标直接使用非负下标0,1,2...
// 2) 同侧目标(自己/队友):编码为负数 -(index+1)
func EncodeTargetIndex(targetIndex int, targetIsOpposite bool) int {
if targetIndex < 0 {
targetIndex = 0
}
if targetIsOpposite {
return targetIndex
}
return -(targetIndex + 1)
}
// DecodeTargetIndex 解析目标下标编码,返回:
// 1) 目标位下标
// 2) 是否为敌方目标
func DecodeTargetIndex(encoded int) (targetIndex int, targetIsOpposite bool) {
if encoded < 0 {
return -encoded - 1, false
}
return encoded, true
}