refactor(fight): 重构战斗系统
- 重构了 BattleSkillEntity 结构,改名为 SkillEntity - 优化了 Input 结构,移除了冗余的 Effect 容器 - 调整了 Effect 接口,增加了 SetInput 和 Alive 方法 - 重构了战斗逻辑中的技能使用和效果处理流程 - 优化了代码结构,提高了可读性和可维护性
This commit is contained in:
@@ -32,22 +32,23 @@ var Category = enum.New[struct {
|
||||
ALL EnumCategory //任何类型
|
||||
}]()
|
||||
|
||||
// BattleSkillEntity 战斗技能实体
|
||||
// SkillEntity 战斗技能实体
|
||||
// 实现了战斗中技能的所有属性和行为,包括PP管理、技能使用、属性获取等
|
||||
// 战斗中可以修改技能实体值,比如是否暴击,是否必中等
|
||||
type BattleSkillEntity struct {
|
||||
type SkillEntity struct {
|
||||
xmlres.Move
|
||||
Info *model.SkillInfo
|
||||
|
||||
DamageValue decimal.Decimal // 伤害值
|
||||
Rand *rand.Rand
|
||||
Pet *BattlePetEntity
|
||||
Crit uint32
|
||||
AttackTime uint32
|
||||
//MaxValue func(ahp, bhp uint32) decimal.Decimal
|
||||
Crit uint32
|
||||
AttackTime uint32
|
||||
}
|
||||
|
||||
// CreateBattleSkillWithInfinity 创建战斗技能实例(可指定是否无限PP)
|
||||
func CreateBattleSkillWithInfinity(skill *model.SkillInfo, rand *rand.Rand, pet *BattlePetEntity) *BattleSkillEntity {
|
||||
// CreateSkill 创建战斗技能实例(可指定是否无限PP)
|
||||
func CreateSkill(skill *model.SkillInfo, rand *rand.Rand, pet *BattlePetEntity) *SkillEntity {
|
||||
//如果PP是-1 ,那就是无限PP
|
||||
// ID小于10001的视为无效技能
|
||||
|
||||
@@ -55,7 +56,7 @@ func CreateBattleSkillWithInfinity(skill *model.SkillInfo, rand *rand.Rand, pet
|
||||
return nil
|
||||
}
|
||||
|
||||
var ret BattleSkillEntity
|
||||
var ret SkillEntity
|
||||
ret.Rand = rand
|
||||
ret.Pet = pet
|
||||
// 从资源仓库获取技能数据
|
||||
@@ -96,17 +97,17 @@ func strSliceToIntSlice(strs []string) ([]int, error) {
|
||||
}
|
||||
|
||||
// CanUse 检查技能是否可以使用(PP是否充足)
|
||||
func (s *BattleSkillEntity) CanUse() bool {
|
||||
func (s *SkillEntity) CanUse() bool {
|
||||
return s.Info.PP > 0
|
||||
}
|
||||
|
||||
// 获取技能类型
|
||||
func (s *BattleSkillEntity) Category() EnumCategory {
|
||||
func (s *SkillEntity) Category() EnumCategory {
|
||||
return EnumCategory(s.Move.Category)
|
||||
}
|
||||
|
||||
// 获取技能属性
|
||||
func (s *BattleSkillEntity) Type() *element.ElementCombination {
|
||||
func (s *SkillEntity) Type() *element.ElementCombination {
|
||||
ret, _ := element.NewElementCombination(s.Move.Type)
|
||||
return ret
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func (s *BattleSkillEntity) Type() *element.ElementCombination {
|
||||
// 解析副作用参数字符串为整数列表
|
||||
|
||||
// 获取技能名称,为空时使用ID
|
||||
func getSkillName(move *BattleSkillEntity) string {
|
||||
func getSkillName(move *SkillEntity) string {
|
||||
if move.Name == "" {
|
||||
return strconv.FormatInt(int64(move.ID), 10)
|
||||
}
|
||||
@@ -164,7 +165,7 @@ var DamageC = enum.New[struct {
|
||||
// }
|
||||
|
||||
// 计算是否命中
|
||||
func (s *BattleSkillEntity) AttackTimeC() {
|
||||
func (s *SkillEntity) AttackTimeC() {
|
||||
s.AttackTime = 0 //先重置上一次的
|
||||
if s.MustHit != 0 {
|
||||
s.AttackTime = 2
|
||||
@@ -175,7 +176,7 @@ func (s *BattleSkillEntity) AttackTimeC() {
|
||||
}
|
||||
|
||||
}
|
||||
func (s *BattleSkillEntity) CriticalsameTypeBonus() decimal.Decimal {
|
||||
func (s *SkillEntity) CriticalsameTypeBonus() decimal.Decimal {
|
||||
|
||||
// 6. 同系加成(属性相同则乘以同系加成倍率,否则1)
|
||||
sameTypeBonus := decimal.NewFromFloat(1.0)
|
||||
@@ -192,7 +193,7 @@ func (s *BattleSkillEntity) CriticalsameTypeBonus() decimal.Decimal {
|
||||
return sameTypeBonus
|
||||
}
|
||||
|
||||
func (s *BattleSkillEntity) criticalrandom() decimal.Decimal {
|
||||
func (s *SkillEntity) criticalrandom() decimal.Decimal {
|
||||
|
||||
randomnum := s.Rand.Int31n(39) + 217
|
||||
// 10. 随机倍率,随机值除以255
|
||||
@@ -202,7 +203,7 @@ func (s *BattleSkillEntity) criticalrandom() decimal.Decimal {
|
||||
}
|
||||
|
||||
// 计算技能威力
|
||||
func (s *BattleSkillEntity) CalculatePower(deftype *BattlePetEntity) decimal.Decimal {
|
||||
func (s *SkillEntity) CalculatePower(deftype *BattlePetEntity) decimal.Decimal {
|
||||
|
||||
// 1. 计算等级因子 (level * 0.4 + 2)
|
||||
levelFactor := decimal.NewFromInt(int64(s.Pet.Info.Level)).
|
||||
|
||||
Reference in New Issue
Block a user