- 新增 AI_player 结构体和相关方法,用于创建和管理 AI 玩家 - 重构 FightC 结构体,增加 Input 结构体用于封装玩家输入 - 优化战斗流程,包括回合处理、技能使用、伤害计算等 - 改进广播机制,使用函数回调替代直接调用方法 - 优化玩家和 AI 的动作处理逻辑
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
|
|
"blazing/logic/service"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/modules/blazing/model"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
ttt := info.NoteReadyToFightInfo{
|
|
|
|
FightId: 3,
|
|
}
|
|
|
|
copier.Copy(&ttt.OurInfo, &c.Info)
|
|
len := len(c.Info.PetList)
|
|
ttt.OurPetList = make([]info.ReadyFightPetInfo, len)
|
|
for i := 0; i < len; i++ {
|
|
|
|
err := copier.CopyWithOption(&ttt.OurPetList[i], &c.Info.PetList[i], copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
ttt.OpponentInfo = info.FightUserInfo{UserID: 0}
|
|
refpet := c.OgreInfo.Data[data.Number]
|
|
if refpet.Id == 0 {
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
}
|
|
mo := model.GenPetInfo(
|
|
int(refpet.Id), []int{0, 31},
|
|
[]int{0, 24},
|
|
[]int{0}, //野怪没特性
|
|
[]int{int(refpet.Shiny)},
|
|
[]int{int(refpet.Lv)})
|
|
ttt.OpponentPetList = make([]info.ReadyFightPetInfo, 1)
|
|
|
|
err1 := copier.CopyWithOption(&ttt.OpponentPetList[0], &mo, copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
|
if err1 != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if c.FightC != nil {
|
|
return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight
|
|
}
|
|
ai := service.NewAI_player(*mo)
|
|
service.NewFight(ttt, c, ai)
|
|
|
|
c.FightC.OwnerID = c.Info.UserID
|
|
|
|
return nil, -1
|
|
}
|
|
|
|
// 准备战斗
|
|
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
c.FightC.ReadyFight(c)
|
|
return nil, -1
|
|
}
|
|
|
|
// 接收战斗或者取消战斗的包
|
|
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
return nil, -1
|
|
}
|
|
|
|
// 使用技能包
|
|
func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
c.FightC.UseSkill(c, int32(data.SkillId))
|
|
return nil, 0
|
|
}
|
|
|
|
// 战斗逃跑
|
|
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
c.FightC.Escape(c)
|
|
return nil, 0
|
|
}
|
|
|
|
// 切换精灵
|
|
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
c.FightC.ChangePet(c, int32(data.CatchTime))
|
|
return nil, 0
|
|
}
|