修改战斗拷贝
This commit is contained in:
@@ -94,7 +94,9 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
}
|
||||
|
||||
ai := player.NewAI_player(moinfo)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_BOSS, c, ai)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_BOSS, c, ai, func(foi *info.FightOverInfo) {
|
||||
|
||||
})
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
@@ -121,7 +123,9 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_NPC, c, ai)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_NPC, c, ai, func(foi *info.FightOverInfo) {
|
||||
|
||||
})
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
||||
|
||||
t := space.GetSpace(c.Info.MapID).Can_ARENA(c)
|
||||
if t != nil {
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, t, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, t, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
@@ -20,7 +20,9 @@ func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Play
|
||||
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
|
||||
g := c.Pet_joinFight()
|
||||
if g != nil {
|
||||
fight.NewFight(info.BattleMode.PET_MELEE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(info.BattleMode.PET_MELEE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
|
||||
return
|
||||
@@ -44,9 +46,13 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
|
||||
if g != nil {
|
||||
switch data.Type {
|
||||
case 5:
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
case 6:
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ import (
|
||||
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
|
||||
fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, p1, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, p1, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func abs(x int8) int8 {
|
||||
|
||||
type BattlePetEntity struct {
|
||||
xmlres.PetInfo
|
||||
Info *model.PetInfo //通过偏移赋值
|
||||
Info model.PetInfo //通过偏移赋值
|
||||
//*input.Input
|
||||
//PType int
|
||||
statusConditions sync.Map // key: StatusCondition, value: int (剩余回合)
|
||||
@@ -37,7 +37,7 @@ type BattlePetEntity struct {
|
||||
}
|
||||
|
||||
// 创建精灵实例
|
||||
func CreateBattlePetEntity(info *model.PetInfo, rand *rand.Rand) *BattlePetEntity {
|
||||
func CreateBattlePetEntity(info model.PetInfo, rand *rand.Rand) *BattlePetEntity {
|
||||
ret := &BattlePetEntity{}
|
||||
|
||||
ret.PetInfo = xmlres.PetMAP[int(info.ID)] //注入精灵信息
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
)
|
||||
|
||||
type FightC struct {
|
||||
Info info.NoteReadyToFightInfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch []*action.ActiveSwitchAction
|
||||
runing bool
|
||||
Info info.NoteReadyToFightInfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch []*action.ActiveSwitchAction
|
||||
|
||||
rand *rand.Rand
|
||||
StartTime time.Time
|
||||
actionChan chan action.BattleActionI // 所有操作统一从这里进入
|
||||
@@ -35,6 +35,8 @@ type FightC struct {
|
||||
overl sync.Once
|
||||
waittime int
|
||||
info.FightOverInfo
|
||||
//战斗结束的插装
|
||||
callback func(*info.FightOverInfo)
|
||||
}
|
||||
|
||||
func (f *FightC) CanEscape() bool {
|
||||
@@ -111,7 +113,7 @@ func (f *FightC) initplayer(c common.PlayerI) *input.Input {
|
||||
in.AllPet = make([]*info.BattlePetEntity, 0)
|
||||
in.InitAttackValue()
|
||||
for i := 0; i < len(c.GetInfo().PetList); i++ {
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(&c.GetInfo().PetList[i], f.rand))
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(c.GetInfo().PetList[i], f.rand))
|
||||
|
||||
}
|
||||
|
||||
@@ -125,7 +127,7 @@ func (f *FightC) initplayer(c common.PlayerI) *input.Input {
|
||||
for _, v := range RandomElfIDs(3) {
|
||||
p := model.GenPetInfo(v, 24, -1, -1, -1, 100)
|
||||
p.CatchTime = uint32(v)
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(p, f.rand))
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(*p, f.rand))
|
||||
|
||||
}
|
||||
//in.AllPet = in.AllPet[:3]
|
||||
@@ -178,20 +180,20 @@ func initfightready(in *input.Input) (info.FightUserInfo, []info.ReadyFightPetIn
|
||||
}
|
||||
|
||||
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
|
||||
func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.PlayerI) *FightC {
|
||||
func NewFight(mode, status info.EnumBattleMode, p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC {
|
||||
f := &FightC{}
|
||||
f.ownerID = p1.GetInfo().UserID
|
||||
f.callback = fn
|
||||
f.quit = make(chan struct{})
|
||||
f.over = make(chan struct{})
|
||||
f.StartTime = time.Now()
|
||||
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
|
||||
f.rand = rand.New(rand.NewSource(seed))
|
||||
f.Info = info.NoteReadyToFightInfo{
|
||||
|
||||
Status: status,
|
||||
Mode: mode,
|
||||
}
|
||||
f.Info.Status = status //房主
|
||||
f.Info.Mode = mode
|
||||
|
||||
f.Our, f.Opp = f.initplayer(p1), f.initplayer(p2)
|
||||
|
||||
f.Info.OurInfo, f.Info.OurPetList = initfightready(f.Our)
|
||||
|
||||
@@ -116,7 +116,7 @@ func (our *Input) IS_Stat(v Effect) bool {
|
||||
|
||||
//
|
||||
|
||||
func (our *Input) GetCurrAttr(id int) *model.PetInfo {
|
||||
func (our *Input) GetCurrAttr(id int) model.PetInfo {
|
||||
|
||||
//todo 获取前GetEffect
|
||||
return our.CurrentPet.Info
|
||||
|
||||
@@ -2,6 +2,8 @@ package fight
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/cool"
|
||||
"context"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/action"
|
||||
@@ -19,7 +21,7 @@ import (
|
||||
func (f *FightC) battleLoop() {
|
||||
|
||||
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
|
||||
oppID := f.Opp.Player.GetInfo().UserID
|
||||
@@ -27,7 +29,7 @@ func (f *FightC) battleLoop() {
|
||||
for !f.closefight {
|
||||
|
||||
f.Round++
|
||||
fmt.Printf("—— 第 %d 回合开始 ——\n", f.Round)
|
||||
//fmt.Printf("—— 第 %d 回合开始 ——\n", f.Round)
|
||||
|
||||
actions := f.collectPlayerActions(ourID, oppID)
|
||||
if f.closefight {
|
||||
@@ -37,7 +39,10 @@ func (f *FightC) battleLoop() {
|
||||
f.resolveRound(actions[ourID], actions[oppID])
|
||||
|
||||
}
|
||||
if f.callback != nil {
|
||||
f.callback(&f.FightOverInfo) //先执行回调,再执行返回信息,在回调内修改战斗判断
|
||||
|
||||
}
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
|
||||
//todo 将血量和技能pp传回enterturn
|
||||
@@ -46,12 +51,25 @@ func (f *FightC) battleLoop() {
|
||||
tt.Alive(false) //将所有属性变化失效掉
|
||||
return true
|
||||
})
|
||||
if f.Info.Mode != info.BattleMode.PET_MELEE { //不是乱斗,传回血量
|
||||
for i := 0; i < len(ff.AllPet); i++ {
|
||||
for j := 0; j < len(ff.Player.GetInfo().PetList); j++ {
|
||||
if ff.Player.GetInfo().PetList[j].CatchTime == ff.AllPet[i].Info.CatchTime {
|
||||
|
||||
ff.Player.GetInfo().PetList[j].Hp = ff.AllPet[i].Info.Hp
|
||||
ff.Player.GetInfo().PetList[j].SkillList = ff.AllPet[i].Info.SkillList
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
||||
|
||||
})
|
||||
|
||||
close(f.actionChan)
|
||||
fmt.Println("战斗循环结束")
|
||||
//fmt.Println("战斗循环结束")
|
||||
close(f.over)
|
||||
|
||||
}
|
||||
@@ -61,7 +79,7 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat
|
||||
actions := make(map[uint32]action.BattleActionI)
|
||||
|
||||
waitr := time.Duration(f.waittime)*time.Millisecond*10 + 30*time.Second
|
||||
fmt.Println("开始收集玩家动作", waitr)
|
||||
//fmt.Println("开始收集玩家动作", waitr)
|
||||
timeout := time.After(waitr)
|
||||
for len(actions) < 2 {
|
||||
|
||||
@@ -122,12 +140,7 @@ func (f *FightC) handleTimeout(ourID, oppID uint32, actions map[uint32]action.Ba
|
||||
if _, exists := actions[pid]; exists {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("玩家%d 超时\n", pid)
|
||||
// player := f.GetInputByPlayer(f.getPlayerByID(pid), true).Player
|
||||
// if !f.GetInputByPlayer(f.getPlayerByID(pid), false).Finished {
|
||||
// fmt.Printf("玩家%d 加载超时\n", pid)
|
||||
// f.UseSkill(player, 0) //卡加载,给对方也一个action
|
||||
// }
|
||||
cool.Loger.Debug(context.Background(), "玩家%d 超时\n", pid)
|
||||
|
||||
f.Reason = info.BattleOverReason.PlayerOVerTime
|
||||
f.closefight = true
|
||||
@@ -140,11 +153,11 @@ func (f *FightC) handleTimeout(ourID, oppID uint32, actions map[uint32]action.Ba
|
||||
// 根据动作类型执行一回合结算
|
||||
func (f *FightC) resolveRound(p1Action, p2Action action.BattleActionI) {
|
||||
if p1Action == nil || p2Action == nil {
|
||||
fmt.Println("某方未选择动作,自动跳过结算")
|
||||
cool.Loger.Debug(context.Background(), "某方未选择动作,自动跳过结算")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("开始结算回合")
|
||||
// fmt.Println("开始结算回合")
|
||||
|
||||
// 动作优先级排序
|
||||
b1, b2 := f.Compare(p1Action, p2Action)
|
||||
@@ -207,7 +220,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
||||
ok, res := f.Our.Capture(f.Opp.CurrentPet, a.ItemID, -1)
|
||||
if ok {
|
||||
fmt.Println(res)
|
||||
our.Service.PetAdd(*f.Opp.CurrentPet.Info)
|
||||
our.Service.PetAdd(f.Opp.CurrentPet.Info)
|
||||
our.CatchPetInfo(info.CatchMonsterOutboundInfo{
|
||||
CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime),
|
||||
PetId: uint32(f.Opp.CurrentPet.ID),
|
||||
|
||||
Reference in New Issue
Block a user