Files
bl/logic/service/fight/info/BattlePetEntity.go
昔念 c42e392efe refactor(fight): 重构战斗系统
- 移除 Player 结构中的 IsFighting 字段,使用 FightID 替代
- 优化 Move 结构,重新排序字段并添加注释
- 修改 EffectNode 和相关结构,统一使用 Ctx 字段名称
- 重构 Battle 和 BattlePetEntity 结构,简化属性并优化布局
- 更新战斗逻辑,调整效果应用和回合处理机制
2025-09-03 00:37:05 +08:00

92 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 info
import (
element "blazing/common/data/Element"
"blazing/modules/blazing/model"
"context"
"sync"
"github.com/tnnmigga/enum"
)
// 战斗属性类型
type EnumAttrType int
// 精灵
const Pet_O_Ctx = "PET_O"
const Pet_T_Ctx = "PET_T"
var AttrType = enum.New[struct {
Attack EnumAttrType `enum:"1"` //`enum:"攻击"`
Defense EnumAttrType `enum:"2"` //`enum:"防御"`
SpecialAttack EnumAttrType `enum:"3"` //`enum:"特殊攻击"`
SpecialDefense EnumAttrType `enum:"4"` //`enum:"特殊防御"`
Speed EnumAttrType `enum:"5"` //`enum:"速度"`
Accuracy EnumAttrType `enum:"6"` //`enum:"命中率"`
HP EnumAttrType `enum:"7"` //血量
}]()
// 属性封装结构Ext 存储临时血量增量key=状态IDvalue=增量值)
type Attribute struct {
//CanSet bool // 是否允许修改
originalValue int
Stat int //提升等级
//Ext map[string]interface{} // 例如:{"buff_hp_123": 200} 存储临时血量增量
}
func (a *Attribute) Value() int64 {
return calculateRealValue(int64(a.originalValue), a.Stat)
}
type BattlePetEntity struct {
model.PetInfo //通过偏移赋值
ctx context.Context
Capturable bool // 是否可捕获
statusConditions sync.Map // key: StatusCondition, value: int (剩余回合)
skills [4]*BattleSkillEntity // 技能槽最多4个技能
}
// calculateRealValue 计算实际属性值根据状态变化计算实际值
// value 基础属性值
// stat 状态变化值(可正可负)
// 返回// 返回计算后的实际属性值确保结果至少为1
func calculateRealValue(value int64, stat int) int64 {
if stat == 0 {
if value <= 0 {
return 1
}
return value
} else if stat > 0 {
r := int64(float64(value) * (float64(stat+2) / 2.0))
if r <= 0 {
return 1
}
return r
} else {
r := int64(float64(value) * (2.0 / float64(2-stat)))
if r <= 0 {
return 1
}
return r
}
}
// 新建一个宠物
func (u *BattlePetEntity) NewBattleSkillEntity(ctx context.Context, id, pp int) {
ret := CreateBattleSkillWithInfinity(id, pp) //创建PP
ctx = context.WithValue(ctx, "pet", &ret) //添加用户到上下文
ret.ctx = ctx
}
func (u *BattlePetEntity) Type() element.ElementType {
//todo 待实现获取精灵的类型
return element.ElementType(0)
}