Files
bl/logic/service/fight/info/BattlePetEntity.go
昔念 d360a85963 ```
refactor(fight): 优化战斗系统中的数值计算和逻辑处理

- 将GetProp方法返回类型从int改为alpacadecimal.Decimal,
避免精度丢失问题
- 修改战斗中速度比较逻辑,使用Decimal的Cmp方法进行比较
- 修正BattlePetEntity中属性计算公式,将乘法改为除法
- 调整伤害累加逻辑,修复SumDamage叠加问题
- 更新攻击力和防御力计算,直接使用Decimal数值
- 移除Effect178、Effect501等未使用的技能效果
- 重构回合处理逻辑,调整死亡判断时机和流程
- 添加TrueFirst字段用于正确跟踪实际先手方
```
2026-03-09 20:55:04 +08:00

99 lines
2.6 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 info
import (
element "blazing/common/data/Element"
"blazing/common/data/xmlres"
"blazing/modules/player/model"
"math/rand"
"github.com/alpacahq/alpacadecimal"
)
// 战斗属性类型
type EnumAttrType int
type BattlePetEntity struct {
xmlres.PetInfo
Info model.PetInfo //通过偏移赋值
//*input.Input
//PType int
Skills []*SkillEntity // 技能槽最多4个技能
//Status StatusDict //精灵的状态
//能力提升属性
//Prop PropDict
NotAlive bool `struc:"skip"`
//DamageZone map[EnumCategory]map[EnumsZoneType]map[EnumsZoneType][]float64 // 三维map 伤害类型-》增还是减-》加还是乘-》值
}
// 创建精灵实例
func CreateBattlePetEntity(info model.PetInfo, rand *rand.Rand) *BattlePetEntity {
ret := &BattlePetEntity{}
ret.PetInfo = xmlres.PetMAP[int(info.ID)] //注入精灵信息
ret.Info = info
ret.Skills = make([]*SkillEntity, 0)
for i := 0; i < len(info.SkillList); i++ {
//todo 技能信息应该每回合进行深拷贝,保证每次的技能效果都是不一样的
// ret.Skills[info.SkillList[i].ID] = CreateSkill(&info.SkillList[i], rand, ret)
ret.Skills = append(ret.Skills, CreateSkill(&info.SkillList[i], rand, ret))
}
return ret
}
// calculateRealValue 计算实际属性值根据状态变化计算实际值
// value 基础属性值
// stat 状态变化值(可正可负)
// 返回// 返回计算后的实际属性值确保结果至少为1
func CalculateRealValue(value alpacadecimal.Decimal, stat1 int8) alpacadecimal.Decimal {
if stat1 == 0 {
return value
}
if !value.IsPositive() {
value = alpacadecimal.NewFromInt(1)
}
two := alpacadecimal.NewFromInt(2)
stat := alpacadecimal.NewFromInt(int64(stat1))
if stat.IsPositive() {
r := value.Mul(stat.Add(two).Div(two))
// println(value.IntPart(), r.IntPart(), "强化后数值")
return r
} else {
r := two.Sub(stat)
return value.Mul(two.Div(r))
}
}
func (u *BattlePetEntity) GetHP() alpacadecimal.Decimal {
return alpacadecimal.NewFromInt(int64(u.Info.Hp))
}
func (u *BattlePetEntity) GetMaxHP() alpacadecimal.Decimal {
return alpacadecimal.NewFromInt(int64(u.Info.MaxHp))
}
func (u *BattlePetEntity) GetType() *element.ElementCombination {
// 1. 遍历宠物配置查找对应元素类型ID
// 3. 从预加载的组合池中获取实例(无需创建,直接读取)
combo, err := element.Calculator.GetCombination(u.PetInfo.Type)
if err != nil {
// 极端情况typeID无效强制使用默认普通属性
// (从池中获取默认值,确保实例一致性)
combo, _ = element.Calculator.GetCombination(8)
}
return combo
}