fix(fight): 修复空变更提交问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/logic/service/fight/action"
|
||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
)
|
)
|
||||||
@@ -18,4 +19,5 @@ type FightI interface {
|
|||||||
UseItem(c PlayerI, cacthid, itemid uint32)
|
UseItem(c PlayerI, cacthid, itemid uint32)
|
||||||
CanEscape() bool
|
CanEscape() bool
|
||||||
IsFirst(c PlayerI) bool
|
IsFirst(c PlayerI) bool
|
||||||
|
GetActionChan() chan action.BattleActionI
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type FightC struct {
|
|||||||
|
|
||||||
rand *rand.Rand
|
rand *rand.Rand
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
actionChan chan action.BattleActionI // 所有操作统一从这里进入
|
ActionChan chan action.BattleActionI // 所有操作统一从这里进入
|
||||||
Round int //回合数
|
Round int //回合数
|
||||||
|
|
||||||
First *input.Input
|
First *input.Input
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (f *FightC) battleLoop() {
|
func (f *FightC) battleLoop() {
|
||||||
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)
|
||||||
|
|
||||||
ourID := f.Our.Player.GetInfo().UserID
|
ourID := f.Our.Player.GetInfo().UserID
|
||||||
@@ -30,7 +30,7 @@ func (f *FightC) battleLoop() {
|
|||||||
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
||||||
|
|
||||||
})
|
})
|
||||||
close(f.actionChan)
|
close(f.ActionChan)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat
|
|||||||
|
|
||||||
for len(actions) < 2 {
|
for len(actions) < 2 {
|
||||||
select {
|
select {
|
||||||
case paction, ok := <-f.actionChan:
|
case paction, ok := <-f.ActionChan:
|
||||||
if !ok || f.closefight {
|
if !ok || f.closefight {
|
||||||
return actions
|
return actions
|
||||||
}
|
}
|
||||||
@@ -245,3 +245,10 @@ func (f *FightC) getPlayerByID(id uint32) common.PlayerI {
|
|||||||
}
|
}
|
||||||
return f.Opp.Player
|
return f.Opp.Player
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据玩家ID返回对应对象
|
||||||
|
func (f *FightC) GetActionChan( ) chan action.BattleActionI {
|
||||||
|
|
||||||
|
return f.ActionChan
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,11 +2,13 @@ package fight
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/xmlres"
|
"blazing/common/data/xmlres"
|
||||||
|
"blazing/cool"
|
||||||
"blazing/logic/service/common"
|
"blazing/logic/service/common"
|
||||||
"blazing/logic/service/fight/action"
|
"blazing/logic/service/fight/action"
|
||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
"blazing/logic/service/fight/input"
|
"blazing/logic/service/fight/input"
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
|
"context"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
@@ -29,16 +31,24 @@ func (f *FightC) Compare(a, b action.BattleActionI) (action.BattleActionI, actio
|
|||||||
|
|
||||||
// 玩家逃跑/无响应/掉线
|
// 玩家逃跑/无响应/掉线
|
||||||
func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
||||||
|
if f.closefight {
|
||||||
|
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||||||
|
return
|
||||||
|
}
|
||||||
ret := &action.EscapeAction{
|
ret := &action.EscapeAction{
|
||||||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||||||
Reason: res,
|
Reason: res,
|
||||||
}
|
}
|
||||||
|
|
||||||
f.actionChan <- ret
|
f.ActionChan <- ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换精灵 主动和被驱逐
|
// 切换精灵 主动和被驱逐
|
||||||
func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||||||
|
if f.closefight {
|
||||||
|
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||||||
|
return
|
||||||
|
}
|
||||||
ret := &action.ActiveSwitchAction{
|
ret := &action.ActiveSwitchAction{
|
||||||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||||||
}
|
}
|
||||||
@@ -67,12 +77,15 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
f.actionChan <- ret
|
f.ActionChan <- ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// 玩家使用技能
|
// 玩家使用技能
|
||||||
func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
||||||
|
if f.closefight {
|
||||||
|
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||||||
|
return
|
||||||
|
}
|
||||||
ret := &action.SelectSkillAction{
|
ret := &action.SelectSkillAction{
|
||||||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||||||
}
|
}
|
||||||
@@ -85,18 +98,24 @@ func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
f.actionChan <- ret
|
f.ActionChan <- ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// 玩家使用技能
|
// 玩家使用技能
|
||||||
func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
||||||
|
if f.closefight {
|
||||||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}
|
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.ActionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) {
|
func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) {
|
||||||
|
if f.closefight {
|
||||||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}
|
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.ActionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 战斗准备
|
// 战斗准备
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ func (p *Player) Save() {
|
|||||||
}()
|
}()
|
||||||
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
||||||
}()
|
}()
|
||||||
|
<-p.FightC.GetActionChan() //等待结束
|
||||||
}
|
}
|
||||||
p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间
|
p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间
|
||||||
p.Onlinetime = uint32(time.Now().Unix())
|
p.Onlinetime = uint32(time.Now().Unix())
|
||||||
|
|||||||
Reference in New Issue
Block a user