```
refactor(fight): 修改技能拷贝逻辑并优化战斗循环结构 - 将 `copyskill` 方法的参数类型从 `*info.SkillEntity` 改为 `*action.SelectSkillAction` - 在 `copyskill` 中增加对 nil 的判断,避免空指针 panic - 调整 `battleLoop` 中 defer 逻辑,确保资源正确释放和战斗结束信息发送 - 移动 `SendFightEndInfo` 到 defer 中执行,简化主循环逻辑 - 将 `Fightpool` 类型由 `*ants.Pool` 改为 `*
This commit is contained in:
@@ -33,7 +33,7 @@ func PprofWeb() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func signalHandlerForMain(sig os.Signal) {
|
func signalHandlerForMain(sig os.Signal) {
|
||||||
fight.Fightpool.Release()
|
fight.Fightpool.Free()
|
||||||
|
|
||||||
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
||||||
value.Save()
|
value.Save()
|
||||||
|
|||||||
@@ -342,10 +342,14 @@ func IsNil(x interface{}) bool {
|
|||||||
rv := reflect.ValueOf(x)
|
rv := reflect.ValueOf(x)
|
||||||
return rv.Kind() == reflect.Ptr && rv.IsNil()
|
return rv.Kind() == reflect.Ptr && rv.IsNil()
|
||||||
}
|
}
|
||||||
func (f *FightC) copyskill(t *info.SkillEntity) *info.SkillEntity {
|
func (f *FightC) copyskill(t *action.SelectSkillAction) *info.SkillEntity {
|
||||||
|
if t.SkillEntity == nil {
|
||||||
|
return nil
|
||||||
|
|
||||||
oldskill, _ := deepcopy.Anything(t) //备份技能
|
}
|
||||||
oldskill.(*info.SkillEntity).Rand = f.rand //拷贝后随机数丢失
|
|
||||||
|
oldskill, _ := deepcopy.Anything(t.SkillEntity) //备份技能
|
||||||
|
oldskill.(*info.SkillEntity).Rand = f.rand //拷贝后随机数丢失
|
||||||
return oldskill.(*info.SkillEntity)
|
return oldskill.(*info.SkillEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,11 +433,11 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
|||||||
var currentskill *info.SkillEntity //当前技能
|
var currentskill *info.SkillEntity //当前技能
|
||||||
if i == 0 { //
|
if i == 0 { //
|
||||||
attacker, defender = f.First, f.Second
|
attacker, defender = f.First, f.Second
|
||||||
oldskill = f.copyskill(fattack.SkillEntity)
|
oldskill = f.copyskill(fattack)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
attacker, defender = f.Second, f.First
|
attacker, defender = f.Second, f.First
|
||||||
oldskill = f.copyskill(sattack.SkillEntity)
|
oldskill = f.copyskill(sattack)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (f *FightC) battleLoop() {
|
func (f *FightC) battleLoop() {
|
||||||
|
defer func() {
|
||||||
|
f.Broadcast(func(ff *input.Input) {
|
||||||
|
//todo 将血量和技能pp传回enterturn
|
||||||
|
//<-time.After(10000)
|
||||||
|
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
||||||
|
|
||||||
|
})
|
||||||
|
close(f.actionChan)
|
||||||
|
close(f.overchan)
|
||||||
|
}()
|
||||||
f.actionChan = make(chan action.BattleActionI, 2)
|
f.actionChan = make(chan action.BattleActionI, 2)
|
||||||
fmt.Println("战斗开始精灵", f.Our.Player.GetInfo().PetList[0].CatchTime)
|
fmt.Println("战斗开始精灵", f.Our.Player.GetInfo().PetList[0].CatchTime)
|
||||||
|
|
||||||
@@ -24,14 +34,6 @@ func (f *FightC) battleLoop() {
|
|||||||
for {
|
for {
|
||||||
if f.closefight {
|
if f.closefight {
|
||||||
|
|
||||||
f.Broadcast(func(ff *input.Input) {
|
|
||||||
//todo 将血量和技能pp传回enterturn
|
|
||||||
//<-time.After(10000)
|
|
||||||
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
|
||||||
|
|
||||||
})
|
|
||||||
close(f.actionChan)
|
|
||||||
close(f.overchan)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"blazing/logic/service/fight/input"
|
"blazing/logic/service/fight/input"
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
"context"
|
"context"
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
@@ -156,9 +155,9 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Fightpool *ants.Pool
|
var Fightpool *ants.MultiPool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Fightpool, _ = ants.NewPool(math.MaxInt32)
|
Fightpool, _ = ants.NewMultiPool(100, 10, ants.LeastTasks)
|
||||||
//defer p.Release()
|
//defer p.Release()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user