Files
bl/logic/service/fight/targeting.go

35 lines
936 B
Go
Raw Normal View History

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
}