feat(common): 升级 gf 框架版本至 v2.8.0 并优化模型时间字段
- 将 `github.com/gogf/gf/contrib/drivers/pgsql/v2` 和 redis 依赖从 v2.6.3 升级到 v2.8.0
- 使用 `*gtime.Time` 替代标准库 `time.Time` 以支持更灵活的时间处理
- 移除 Model 结构体中 CreateTime、UpdateTime 等字段的默认初始化逻辑
- 注释掉已弃用的 GDBM 函数,推荐使用 DBM
- 在 DBM 中添加 OnConflict("id") 配置以增强写入安全性
- 调整部分代码结构与调用方式以适配新版框架行为
```
133 lines
3.9 KiB
Go
133 lines
3.9 KiB
Go
package effect
|
||
|
||
import (
|
||
element "blazing/common/data/Element"
|
||
"blazing/logic/service/fight/action"
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/fight/input"
|
||
"blazing/logic/service/fight/node"
|
||
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
"github.com/shopspring/decimal"
|
||
)
|
||
|
||
// 修正拼写错误:BaseSataus -> BaseStatus
|
||
type BaseStatus struct {
|
||
node.EffectNode
|
||
Status info.EnumPetStatus // 状态类型枚举
|
||
}
|
||
|
||
// 重写切换事件:我方单位切换时清除状态
|
||
func (e *BaseStatus) Switch(in *input.Input, _ info.AttackValue, _ *info.BattlePetEntity) bool {
|
||
// 我方单位下场时,状态失效
|
||
if in == e.Ctx().Our {
|
||
e.Alive(false)
|
||
}
|
||
return true
|
||
}
|
||
|
||
// 不能出手的基础状态(如麻痹、疲惫等)
|
||
type StatusCannotAct struct {
|
||
BaseStatus
|
||
}
|
||
|
||
// 技能命中前拦截:阻止出手
|
||
func (e *StatusCannotAct) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||
return false
|
||
}
|
||
|
||
// 睡眠状态:受击后解除
|
||
type StatusSleep struct {
|
||
StatusCannotAct
|
||
hasTriedAct bool // 标记是否尝试过行动
|
||
}
|
||
|
||
// 尝试出手时标记状态
|
||
func (e *StatusSleep) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||
e.hasTriedAct = true
|
||
return e.StatusCannotAct.Skill_Hit_Pre(attacker, defender)
|
||
}
|
||
|
||
// 技能使用后处理:非状态类技能触发后解除睡眠
|
||
func (e *StatusSleep) Skill_Use_ex() bool {
|
||
if !e.hasTriedAct {
|
||
return true
|
||
}
|
||
// 技能实体存在且非状态类型技能,解除睡眠
|
||
if e.Ctx().SkillEntity != nil && e.Ctx().Category() != info.Category.STATUS {
|
||
e.Alive(false)
|
||
}
|
||
return true
|
||
}
|
||
|
||
// 持续伤害状态基类(中毒、冻伤、烧伤等)
|
||
type ContinuousDamage struct {
|
||
BaseStatus
|
||
}
|
||
|
||
// 技能命中前触发伤害(1/8最大生命值真实伤害)
|
||
func (e *ContinuousDamage) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||
damage := e.calculateDamage()
|
||
e.Ctx().Our.Damage(e.Input, &info.DamageZone{
|
||
Type: info.DamageType.True,
|
||
Damage: damage,
|
||
})
|
||
return true
|
||
}
|
||
|
||
// 计算伤害:最大生命值的1/8
|
||
func (e *ContinuousDamage) calculateDamage() decimal.Decimal {
|
||
return decimal.NewFromUint64(uint64(e.Ctx().Our.CurrentPet.Info.MaxHp)).
|
||
Div(decimal.NewFromInt(8))
|
||
}
|
||
|
||
// 寄生种子状态:扣血同时给对方回血
|
||
type ParasiticSeed struct {
|
||
BaseStatus
|
||
}
|
||
|
||
// 技能命中前触发寄生效果
|
||
func (e *ParasiticSeed) Skill_Hit_Pre_ex(attacker, defender *action.SelectSkillAction) bool {
|
||
// 过滤特定类型单位(假设1是植物类型,使用枚举替代魔法数字)
|
||
if gconv.Int(e.Ctx().Our.CurrentPet.Type) == int(element.ElementTypeGrass) {
|
||
return true
|
||
}
|
||
|
||
damage := decimal.NewFromUint64(uint64(e.Ctx().Our.CurrentPet.Info.MaxHp)).
|
||
Div(decimal.NewFromInt(8))
|
||
|
||
// 对我方造成真实伤害
|
||
e.Ctx().Our.Damage(e.Input, &info.DamageZone{
|
||
Type: info.DamageType.True,
|
||
Damage: damage,
|
||
})
|
||
|
||
// 给对方回血(不受回血限制影响)
|
||
e.Ctx().Opp.Heal(e.Ctx().Our, nil, damage)
|
||
return true
|
||
}
|
||
|
||
func init() {
|
||
// 注册持续伤害类状态
|
||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.DrainedHP), &ParasiticSeed{}) // 寄生种子
|
||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Poisoned), &ContinuousDamage{}) // 中毒
|
||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Frozen), &ContinuousDamage{}) // 冻伤
|
||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Burned), &ContinuousDamage{}) // 烧伤
|
||
|
||
// 批量注册不能行动的状态
|
||
nonActingStatuses := []info.EnumPetStatus{
|
||
info.PetStatus.Paralysis, // 麻痹
|
||
info.PetStatus.Tired, // 疲惫
|
||
info.PetStatus.Fear, // 害怕
|
||
info.PetStatus.Petrified, // 石化
|
||
}
|
||
for _, status := range nonActingStatuses {
|
||
effect := &StatusCannotAct{}
|
||
effect.Status = status
|
||
input.InitEffect(input.EffectType.Status, int(status), effect)
|
||
}
|
||
|
||
// 注册睡眠状态(使用枚举常量替代硬编码8)
|
||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Sleep), &StatusSleep{})
|
||
}
|