refactor: 重构战斗初始化传递宠物列表
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -99,7 +99,7 @@ func (Controller) PlayerFightBoss(data1 *fight.ChallengeBossInboundInfo, p *play
|
||||
|
||||
ai.Prop[0] = 2
|
||||
var fighc *fight.FightC
|
||||
fighc, _ = fight.NewFight(p, ai, func(foi model.FightOverInfo) {
|
||||
fighc, _ = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
if mdata.WinBonusID != 0 {
|
||||
if len(bosinfo[0].Rule) == 0 {
|
||||
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
|
||||
@@ -177,7 +177,7 @@ func (Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInf
|
||||
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC //打野怪
|
||||
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE //多人模式
|
||||
|
||||
fight.NewFight(p, ai, func(foi model.FightOverInfo) {
|
||||
fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
//p.Done.Exec(model.MilestoneMode.Moster, []uint32{p.Info.MapID, monsterInfo.PetList[0].ID, uint32(foi.Reason)}, nil)
|
||||
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID && p.CanGet() {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
@@ -16,9 +17,28 @@ func (h Controller) PetMelee(data *fight.StartPetWarInboundInfo, c *player.Playe
|
||||
|
||||
c.Fightinfo.Mode = info.BattleMode.PET_MELEE
|
||||
c.Fightinfo.Status = info.BattleMode.PET_MELEE
|
||||
var mepet []model.PetInfo
|
||||
|
||||
for i, v := range service.NewMELEEService().Def() {
|
||||
|
||||
if v.Lv == 0 {
|
||||
v.Lv = 100
|
||||
|
||||
}
|
||||
|
||||
pet := model.GenPetInfo(int(v.MonID), 24, int(v.Nature), int(v.Effect[0]), int(v.Lv), nil, 0)
|
||||
|
||||
pet.ConfigBoss(v)
|
||||
pet.CatchTime = c.GetInfo().UserID + uint32(i)*1000000
|
||||
pet.Cure()
|
||||
mepet = append(mepet, *pet)
|
||||
|
||||
}
|
||||
if len(mepet) < 6 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
err = c.JoinFight(func(p common.PlayerI) bool {
|
||||
_, err = fight.NewFight(p, c, func(foi model.FightOverInfo) {
|
||||
_, err = fight.NewFight(p, c, mepet[:3], mepet[3:], func(foi model.FightOverInfo) {
|
||||
if foi.Reason == 0 { //我放获胜
|
||||
|
||||
if foi.WinnerId == c.GetInfo().UserID {
|
||||
@@ -65,14 +85,21 @@ func (h Controller) PetKing(data *fight.PetKingJoinInboundInfo, c *player.Player
|
||||
// 按顺序:草、水、火、电、战斗、飞行、机械、地面、冰
|
||||
|
||||
//println("11", c.GetPetInfo()[0].Type(), ElementTypeNumbers[data.FightType-1])
|
||||
if c.GetPetInfo()[0].Type() != int(ElementTypeNumbers[data.FightType-1]) {
|
||||
if c.GetPetInfo(0)[0].Type() != int(ElementTypeNumbers[data.FightType-1]) {
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrVictoryConditionNotMet)
|
||||
}
|
||||
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
||||
c.Fightinfo.FightType = data.FightType
|
||||
}
|
||||
|
||||
err = c.JoinFight(func(p common.PlayerI) bool {
|
||||
_, err = fight.NewFight(p, c, func(foi model.FightOverInfo) {
|
||||
var u1, u2 []model.PetInfo
|
||||
if c.Fightinfo.Mode == info.BattleMode.SINGLE_MODE {
|
||||
u1, u2 = p.GetInfo().PetList[:1], c.GetInfo().PetList[:1]
|
||||
} else {
|
||||
u1, u2 = p.GetInfo().PetList, c.GetInfo().PetList
|
||||
}
|
||||
_, err = fight.NewFight(p, c, u1, u2, func(foi model.FightOverInfo) {
|
||||
if foi.Reason == 0 { //我放获胜
|
||||
switch data.Type {
|
||||
case 11:
|
||||
|
||||
@@ -55,7 +55,7 @@ func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInbou
|
||||
return
|
||||
}
|
||||
|
||||
_, err = fight.NewFight(v, c, func(foi model.FightOverInfo) {
|
||||
_, err = fight.NewFight(v, c, v.GetPetInfo(100), v.GetPetInfo(100), func(foi model.FightOverInfo) {
|
||||
|
||||
//println("好友对战测试", foi.Reason)
|
||||
|
||||
|
||||
@@ -187,7 +187,9 @@ func (h Controller) PetTawor(data *fight.StartTwarInboundInfo, c *player.Player)
|
||||
}
|
||||
|
||||
ai := player.NewAI_player(monsterInfo)
|
||||
_, err = fight.NewFight(c, ai, func(foi model.FightOverInfo) {
|
||||
|
||||
_, err = fight.NewFight(c, ai, c.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
|
||||
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID { //我放获胜
|
||||
switch data.Head.CMD {
|
||||
case 2429: //试炼之塔
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h Controller) ArenaFightOwner(data1 *fight.ARENA_FIGHT_OWENR, c *player.Pl
|
||||
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
||||
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
||||
|
||||
_, err = fight.NewFight(c, c.GetSpace().Owner.ARENA_Player, func(foi model.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||
_, err = fight.NewFight(c, c.GetSpace().Owner.ARENA_Player, c.Info.PetList[:1], c.GetSpace().Owner.ARENA_Player.GetInfo().PetList[:1], func(foi model.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||
|
||||
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
||||
|
||||
|
||||
@@ -19,4 +19,5 @@ type PlayerI interface {
|
||||
MessWin(bool)
|
||||
CanFight() errorcode.ErrorCode
|
||||
SendPackCmd(uint32, any)
|
||||
GetPetInfo(limitlevel uint32) []model.PetInfo
|
||||
}
|
||||
|
||||
@@ -3,14 +3,12 @@ package fight
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/utils"
|
||||
config "blazing/modules/config/model"
|
||||
"blazing/modules/player/model"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/user"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@@ -25,13 +23,13 @@ type FightC struct {
|
||||
ReadyInfo model.NoteReadyToFightInfo
|
||||
//开始战斗信息
|
||||
info.FightStartOutboundInfo
|
||||
Info info.Fightinfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch map[uint32]*action.ActiveSwitchAction
|
||||
Melee []config.PetBaseConfig
|
||||
Info info.Fightinfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch map[uint32]*action.ActiveSwitchAction
|
||||
|
||||
startl sync.Once
|
||||
rand *rand.Rand
|
||||
StartTime time.Time
|
||||
@@ -127,7 +125,7 @@ func (f *FightC) LoadPercent(c common.PlayerI, percent int32) {
|
||||
|
||||
var meetpet = make(map[int]model.PetInfo)
|
||||
|
||||
func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode) {
|
||||
func (f *FightC) initplayer(c common.PlayerI, b []model.PetInfo) (*input.Input, errorcode.ErrorCode) {
|
||||
r := c.CanFight()
|
||||
if c.CanFight() != 0 {
|
||||
return nil, r
|
||||
@@ -136,12 +134,9 @@ func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode
|
||||
in := input.NewInput(f, c)
|
||||
in.AllPet = make([]*info.BattlePetEntity, 0)
|
||||
in.InitAttackValue()
|
||||
for i := 0; i < len(c.GetInfo().PetList); i++ {
|
||||
for i := 0; i < len(b); i++ {
|
||||
//玩家精灵重置到100等级
|
||||
pet := c.GetInfo().PetList[i]
|
||||
if _, ok := c.(*player.Player); ok {
|
||||
pet.Level = utils.Min(pet.Level, 100)
|
||||
}
|
||||
pet := b[i]
|
||||
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(pet, f.rand))
|
||||
|
||||
@@ -152,40 +147,6 @@ func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode
|
||||
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||
}
|
||||
|
||||
switch f.Info.Mode {
|
||||
case info.BattleMode.SINGLE_MODE:
|
||||
in.AllPet = in.AllPet[:1]
|
||||
case info.BattleMode.PET_MELEE:
|
||||
in.AllPet = make([]*info.BattlePetEntity, 0)
|
||||
var meetpet []config.PetBaseConfig
|
||||
if len(f.Melee) < 6 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
if c.GetInfo().UserID == f.ownerID {
|
||||
meetpet = f.Melee[:3]
|
||||
} else {
|
||||
meetpet = f.Melee[3:]
|
||||
}
|
||||
|
||||
for i, v := range meetpet {
|
||||
|
||||
if v.Lv == 0 {
|
||||
v.Lv = 100
|
||||
|
||||
}
|
||||
|
||||
pet := model.GenPetInfo(int(v.MonID), 24, int(v.Nature), int(v.Effect[0]), int(v.Lv), nil, 0)
|
||||
|
||||
pet.ConfigBoss(v)
|
||||
pet.CatchTime = c.GetInfo().UserID + uint32(i)*1000000
|
||||
pet.Cure()
|
||||
in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(*pet, f.rand))
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
in.CurrentPet = in.AllPet[0]
|
||||
return in, 0
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
|
||||
func NewFight(p1, p2 common.PlayerI, fn func(model.FightOverInfo)) (*FightC, errorcode.ErrorCode) {
|
||||
func NewFight(p1, p2 common.PlayerI, b1, b2 []model.PetInfo, fn func(model.FightOverInfo)) (*FightC, errorcode.ErrorCode) {
|
||||
|
||||
// fmt.Println("NewFight", p1.GetInfo().UserID)
|
||||
f := &FightC{}
|
||||
@@ -33,17 +32,15 @@ func NewFight(p1, p2 common.PlayerI, fn func(model.FightOverInfo)) (*FightC, err
|
||||
//这里应该挪到玩家初始化执行
|
||||
|
||||
f.ReadyInfo.Status = f.Info.Status
|
||||
if f.Info.Mode == info.BattleMode.PET_MELEE {
|
||||
f.Melee = service.NewMELEEService().Def()
|
||||
}
|
||||
|
||||
var err errorcode.ErrorCode
|
||||
f.Our, err = f.initplayer(p1)
|
||||
f.Our, err = f.initplayer(p1, b1)
|
||||
if err > 0 {
|
||||
return nil, err
|
||||
|
||||
}
|
||||
|
||||
f.Opp, err = f.initplayer(p2)
|
||||
f.Opp, err = f.initplayer(p2, b2)
|
||||
if err > 0 {
|
||||
return nil, err
|
||||
|
||||
|
||||
@@ -39,6 +39,19 @@ func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
||||
return p.Info
|
||||
}
|
||||
|
||||
func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
|
||||
|
||||
var ret []model.PetInfo
|
||||
|
||||
for _, pet := range p.Info.PetList {
|
||||
if limitlevel > 0 {
|
||||
pet.Level = utils.Min(pet.Level, limitlevel)
|
||||
ret = append(ret, pet)
|
||||
}
|
||||
|
||||
}
|
||||
return ret
|
||||
}
|
||||
func (f *baseplayer) InvitePlayer(ff common.PlayerI) {
|
||||
|
||||
}
|
||||
@@ -82,10 +95,6 @@ func (f *baseplayer) SendPackCmd(_ uint32, _ any) {
|
||||
|
||||
}
|
||||
|
||||
func (p *baseplayer) GetPetInfo() []model.PetInfo {
|
||||
|
||||
return p.Info.PetList
|
||||
}
|
||||
func (p *baseplayer) ItemAdd(ItemId, ItemCnt int64) (result bool) {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user